-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add config from application.conf and docker-compose and an exam…
…ple (#10) Signed-off-by: Fabio Pinheiro <[email protected]> Signed-off-by: Shailesh Patil <[email protected]>
- Loading branch information
1 parent
c524e89
commit 350bc4d
Showing
5 changed files
with
181 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
mediator = { | ||
identity = { | ||
keyAgreement = { | ||
kty = "OKP" | ||
crv = "X25519" | ||
d = "Z6D8LduZgZ6LnrOHPrMTS6uU2u5Btsrk1SGs4fn8M7c" | ||
d = ${?KEY_AGREEMENT_D} | ||
x = "Sr4SkIskjN_VdKTn0zkjYbhGTWArdUNE4j_DmUpnQGw" | ||
x = ${?KEY_AGREEMENT_X} | ||
} | ||
keyAuthentication = { | ||
kty = "OKP" | ||
crv = "Ed25519" | ||
d = "INXCnxFEl0atLIIQYruHzGd5sUivMRyQOzu87qVerug" | ||
d = ${?KEY_AUTHENTICATION_D} | ||
x = "MBjnXZxkMcoQVVL21hahWAw43RuAG-i64ipbeKKqwoA" | ||
x = ${?KEY_AUTHENTICATION_X} | ||
} | ||
endpoint = "https://k8s-int.atalaprism.io/mediator" | ||
endpoint = ${?SERVICE_ENDPOINT} | ||
} | ||
server.http.port = 8080 | ||
# server.http.port = ${?PORT} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
version: '3.9' | ||
|
||
services: | ||
# mongo: | ||
# image: mongo:5.0 | ||
# ports: | ||
# - 27017:27017 | ||
# #volumes: | ||
# # - ./tmp/mongo:/data/db | ||
# environment: | ||
# - MONGO_INITDB_ROOT_USERNAME=admin | ||
# - MONGO_INITDB_ROOT_PASSWORD=admin | ||
|
||
atalaprism-mediator: | ||
image: ghcr.io/input-output-hk/mediator:0.1.1-SNAPSHOT | ||
ports: | ||
- 8080:8080 | ||
network_mode: host | ||
environment: | ||
# Creates the identity: "did:peer:2.Ez6LSghwSE437wnDE1pt3X6hVDUQzSjsHzinpX3XFvMjRAm7y.Vz6Mkhh1e5CEYYq6JBUcTZ6Cp2ranCWRrv7Yax3Le4N59R6dd.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9rOHMtaW50LmF0YWxhcHJpc20uaW8vbWVkaWF0b3IiLCJyIjpbXSwiYSI6WyJkaWRjb21tL3YyIl19" | ||
- KEY_AGREEMENT_D=Z6D8LduZgZ6LnrOHPrMTS6uU2u5Btsrk1SGs4fn8M7c | ||
- KEY_AGREEMENT_X=Sr4SkIskjN_VdKTn0zkjYbhGTWArdUNE4j_DmUpnQGw | ||
- KEY_AUTHENTICATION_D=INXCnxFEl0atLIIQYruHzGd5sUivMRyQOzu87qVerug | ||
- KEY_AUTHENTICATION_X=MBjnXZxkMcoQVVL21hahWAw43RuAG-i64ipbeKKqwoA | ||
- SERVICE_ENDPOINT=https://k8s-int.atalaprism.io/mediator | ||
# Config storage | ||
#- DB_URL=mongodb://admin:admin@mongo:27017 | ||
#- MONGODB_USER=admin | ||
#- MONGODB_PASSWORD=admin | ||
# depends_on: | ||
# - "mongo" | ||
|
||
|
||
# RUN | ||
# docker-compose up -d | ||
# docker-compose ps | ||
# docker-compose exec mongo /bin/sh | ||
# docker exec -it mongo-1 bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
|
||
# Test Mediator (Trust Ping) | ||
|
||
## Compile and Run the Mediator on docker | ||
|
||
```shell | ||
docker:publishLocal # Compile and create the mediator image | ||
docker-compose up #docker run -p 8080:8080 ghcr.io/input-output-hk/mediator:0.1.0-SNAPSHOT | ||
``` | ||
|
||
## Run the client | ||
|
||
```shell | ||
scala-cli repl \ | ||
--dependency app.fmgp::did::0.1.0-M2 \ | ||
--dependency app.fmgp::did-imp::0.1.0-M2 \ | ||
--dependency app.fmgp::did-method-peer::0.1.0-M2 \ | ||
--repo https://oss.sonatype.org/content/repositories/releases | ||
``` | ||
|
||
|
||
```scala | ||
import zio._ | ||
import zio.json._ | ||
import fmgp.crypto._ | ||
import fmgp.did._ | ||
import fmgp.did.comm._ | ||
import fmgp.did.comm.protocol.trustping2._ | ||
import fmgp.did.method.peer._ | ||
|
||
val agent = DIDPeer2.makeAgent( | ||
Seq( | ||
OKPPrivateKey(// keyAgreement | ||
kty = KTY.OKP, | ||
crv = Curve.X25519, | ||
d = "Z6D8LduZgZ6LnrOHPrMTS6uU2u5Btsrk1SGs4fn8M7c", | ||
x = "Sr4SkIskjN_VdKTn0zkjYbhGTWArdUNE4j_DmUpnQGw", | ||
kid = None | ||
), | ||
OKPPrivateKey(//keyAuthentication | ||
kty = KTY.OKP, | ||
crv = Curve.Ed25519, | ||
d = "INXCnxFEl0atLIIQYruHzGd5sUivMRyQOzu87qVerug", | ||
x = "MBjnXZxkMcoQVVL21hahWAw43RuAG-i64ipbeKKqwoA", | ||
kid = None | ||
) | ||
), | ||
Seq(DIDPeerServiceEncoded(s = "http://localhost:5000/")) | ||
) | ||
|
||
val mediator = "did:peer:2.Ez6LSghwSE437wnDE1pt3X6hVDUQzSjsHzinpX3XFvMjRAm7y.Vz6Mkhh1e5CEYYq6JBUcTZ6Cp2ranCWRrv7Yax3Le4N59R6dd.SeyJ0IjoiZG0iLCJzIjoiaHR0cHM6Ly9rOHMtaW50LmF0YWxhcHJpc20uaW8vbWVkaWF0b3IiLCJyIjpbXSwiYSI6WyJkaWRjb21tL3YyIl19" | ||
|
||
val ping = TrustPingWithRequestedResponse(from = agent.id, to = TO(mediator)) | ||
|
||
val program = for { | ||
msg <- Operations.authEncrypt(ping.toPlaintextMessage) | ||
_ <- Console.printLine(msg.toJson) | ||
} yield () | ||
|
||
Unsafe.unsafe { implicit unsafe => // Run side efect | ||
Runtime.default.unsafe | ||
.run(program.provide(Operations.layerDefault ++ DidPeerResolver.layer ++ ZLayer.succeed(agent))) | ||
.getOrThrowFiberFailure() | ||
} | ||
``` | ||
|
||
To send the trust ping you can do a request with curl `curl -X POST http://localhost:8080 -H 'content-type: application/didcomm-encrypted+json' -d'...'` (replace `...` with the encrypted DID Comm message you get from the code above). | ||
|
||
To receive the reply you can have netcat running like `nc -nl -p 5000`. | ||
|
||
Then you can decrypt reply with the follow code: | ||
|
||
```scala | ||
|
||
val reply = """{"ciphertext":"863YmjDPR5mYlJtTEfTUFW11wpCKxsVKpDeEWtQPAqbPlECVIDKaCkh0j_tjpSQomgQL93MjrtjuTo3OnIU2EfHDX8t2mkf84muUSmeQtfMnN_ZmRYPxKw3WG_XUGrE25m8zAcce3RClm13TK9Y3XHeM4vrrExfOBYFcIIUoT9yWPIWb6Y39fRNyvlbNuYcEbsPR3RfvecOcBQJ3YaTlpzVjdgXaICZ4oC_5aVRX3EXsIhmEfjt6lBOGmstGT3zPAsLoP8mjb9GbwOIwpbj4u2BczjMDkUsezuzHsyCeilMGziG5Zr7D64Cjbt8Pg2F11vx4sLW11U3hfjRJ0gnShyBzSAOZmrR_TVBWGaP2KOELRtY4Inp8SzP4-YG89Ie2Cu9ZJesZr4eHYe5qFbI7IZg5lALazTtKodoehFuUDk9YklW8xip5_4-yIWKvj0_j79VBoTf3NiEyRz6CmPiW3Mtx5QJwt56Gb1DkLIkgy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qVkZvMlEzQXljbUZ1UTFkU2NuWTNXV0Y0TTB4bE5FNDFPVkkyWkdRdVUyVjVTakJKYW05cFdrY3dhVXhEU25wSmFtOXBZVWhTTUdOSVRUWk1lVGx5VDBoTmRHRlhOVEJNYlVZd1dWZDRhR05JU25Cak1qQjFZVmM0ZG1KWFZtdGhWMFl3WWpOSmFVeERTbmxKYW5CaVdGTjNhVmxUU1RaWGVVcHJZVmRTYW1JeU1YUk1NMWw1U1d3eE9TTTJURk5uYUhkVFJUUXpOM2R1UkVVeGNIUXpXRFpvVmtSVlVYcFRhbk5JZW1sdWNGZ3pXRVoyVFdwU1FXMDNlUSIsInR5cCI6ImFwcGxpY2F0aW9uL2RpZGNvbW0tZW5jcnlwdGVkK2pzb24iLCJlbmMiOiJBMjU2Q0JDLUhTNTEyIiwiYWxnIjoiRUNESC0xUFUrQTI1NktXIn0","recipients":[{"encrypted_key":"yhqQA2n2QRm5e8m15hVsRWoL4BcEooLBlROwAYenUIOOwc90jK-9uDO2qAiV8eamgU9GQZ0dNYFM2oyaRQaewnIbCIyM6nwg","header":{"kid":"did:peer:2.Ez6LSghwSE437wnDE1pt3X6hVDUQzSjsHzinpX3XFvMjRAm7y.Vz6Mkhh1e5CEYYq6JBUcTZ6Cp2ranCWRrv7Yax3Le4N59R6dd.SeyJ0IjoiZG0iLCJzIjoiaHR0cDovL2xvY2FsaG9zdDo1MDAwLyIsInIiOltdLCJhIjpbImRpZGNvbW0vdjIiXX0#6LSghwSE437wnDE1pt3X6hVDUQzSjsHzinpX3XFvMjRAm7y"}}],"tag":"Xm_uDGCkZVjgWc8d0dr_N2L5gN8ll_rPvLyexiiImlM","iv":"46H81iydYSwZColseMrf-g"}""" | ||
.fromJson[EncryptedMessage] | ||
.getOrElse(???) | ||
|
||
val program2 = for { | ||
msg <- Operations.anonDecrypt(reply) | ||
_ <- Console.printLine(msg.toJson) | ||
} yield () | ||
|
||
Unsafe.unsafe { implicit unsafe => // Run side efect | ||
Runtime.default.unsafe | ||
.run(program2.provide(Operations.layerDefault ++ DidPeerResolver.layer ++ ZLayer.succeed(agent))) | ||
.getOrThrowFiberFailure() | ||
} | ||
``` |