Skip to content

Commit

Permalink
feat(prism-agent): add connect/issue doc + allow local execution of m…
Browse files Browse the repository at this point in the history
…ultiple Prism Agent instances (#178)

* chore(prism-agent): do not link DIDComm service port variable to DIDComm service URL variable

* chore(infra): add docker-compose config for Connect + only expose th main http port

* chore(infra): add HAProxy config for DIDComm service endpoint

* chore(prism-agent): bump version number to 0.6.0-SNAPSHOT

* docs(prism-agent): add basic documentation on executing Connect and Issue flows

* docs(prism-agent): add links in main README.md
  • Loading branch information
bvoiturier committed Nov 29, 2022
1 parent 5981a77 commit dc8d86b
Show file tree
Hide file tree
Showing 7 changed files with 170 additions and 21 deletions.
48 changes: 33 additions & 15 deletions infrastructure/local/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ services:
POSTGRES_DB: castor
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
volumes:
- pg_data_castor_db:/var/lib/postgresql/data

Expand All @@ -36,8 +34,6 @@ services:
POSTGRES_DB: pollux
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5433:5432
volumes:
- pg_data_pollux_db:/var/lib/postgresql/data

Expand All @@ -49,6 +45,28 @@ services:
db_pollux:
condition: service_started

##########################
# Connect Database
##########################

db_connect:
image: postgres:13
restart: always
environment:
POSTGRES_DB: connect
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
- pg_data_connect_db:/var/lib/postgresql/data

# delay to ensure DB is up before applying migrations
db_connect_init_delay:
image: alpine:3
command: sleep 5
depends_on:
db_connect:
condition: service_started

##########################
# Iris Database
##########################
Expand All @@ -60,8 +78,6 @@ services:
POSTGRES_DB: iris
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5434:5432
volumes:
- pg_data_iris_db:/var/lib/postgresql/data

Expand All @@ -78,20 +94,18 @@ services:
# Services
##########################
mediator:
image: ghcr.io/input-output-hk/mercury-mediator:0.1.0-SNAPSHOT
image: ghcr.io/input-output-hk/mercury-mediator:0.2.0

iris:
image: ghcr.io/input-output-hk/iris-service:0.1.0-SNAPSHOT
ports:
- 8081:8081
image: ghcr.io/input-output-hk/iris-service:0.1.0
environment:
IRIS_DB_HOST: db_iris
IRIS_DB_PORT: 5432
IRIS_DB_NAME: iris
IRIS_DB_USER: postgres

prism-agent:
image: ghcr.io/input-output-hk/prism-agent:0.2.0-SNAPSHOT
image: ghcr.io/input-output-hk/prism-agent:0.6.0-SNAPSHOT
environment:
IRIS_HOST: iris
IRIS_PORT: 8081
Expand All @@ -105,9 +119,12 @@ services:
POLLUX_DB_NAME: pollux
POLLUX_DB_USER: postgres
POLLUX_DB_PASSWORD: postgres
ports:
- "8085:8085"
- "8080:8080"
CONNECT_DB_HOST: db_connect
CONNECT_DB_PORT: 5432
CONNECT_DB_NAME: connect
CONNECT_DB_USER: postgres
CONNECT_DB_PASSWORD: postgres
DIDCOMM_SERVICE_URL: http://host.docker.internal:${PORT}/didcomm/

swagger-ui:
image: swaggerapi/swagger-ui:v4.14.0
Expand All @@ -121,7 +138,7 @@ services:
haproxy:
image: haproxy:2.6.5
ports:
- "80:80" # Http
- "${PORT}:80" # Http
depends_on:
- mediator
- prism-agent
Expand All @@ -132,4 +149,5 @@ services:
volumes:
pg_data_castor_db:
pg_data_pollux_db:
pg_data_connect_db:
pg_data_iris_db:
16 changes: 12 additions & 4 deletions infrastructure/local/haproxy/haproxy.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ frontend https-in
option httplog
option logasap

use_backend mediator if { path_beg -i /mediator }
use_backend swagger-ui if { path_beg -i /apidocs }
use_backend prism-agent if { path_beg -i /prism-agent }
use_backend prism-agent-tapir if { path_beg -i /tapir }
use_backend mediator if { path_beg -i /mediator }
use_backend swagger-ui if { path_beg -i /apidocs }
use_backend prism-agent if { path_beg -i /prism-agent }
use_backend prism-agent-didcomm if { path_beg -i /didcomm }
use_backend prism-agent-tapir if { path_beg -i /tapir }

backend mediator
balance roundrobin
Expand All @@ -43,6 +44,13 @@ backend prism-agent
option forwardfor
server s1 prism-agent:8080 maxconn 32

backend prism-agent-didcomm
balance roundrobin
http-request set-uri %[url,regsub(^/didcomm,,)] if { path_beg /didcomm }
option httpclose
option forwardfor
server s1 prism-agent:8090 maxconn 32

backend prism-agent-tapir
balance roundrobin
http-request set-uri %[url,regsub(^/tapir,,)] if { path_beg /tapir }
Expand Down
7 changes: 7 additions & 0 deletions prism-agent/service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ Similar to [Indy Wallet SDK - secret API](https://github.com/hyperledger/indy-sd
*it does not expose a private-key* for external use, instead it provide functions to perform cryptographic actions using internally stored private-keys.

---
## Connect flow
Basic documentation on how to execute the Connect flow from command line can be found [here](./connect.md).

---
## Issue flow
Basic documentation on how to execute the Issue flow from the command line can be found [here](./issue.md).

---
## Known limitations

### Castor `worker` process embedded inside `prism-agent` runnable
Expand Down
51 changes: 51 additions & 0 deletions prism-agent/service/connect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
### Running multiple instances of Prism Agent
---

#### Starting an instance for `Inviter` on port `8080`

```bash
# From the root directory
PORT=8080 docker-compose -p inviter -f infrastructure/local/docker-compose.yml up
```

#### Starting an instance for `Invitee` on port `8090`

```bash
# From the root directory
PORT=8090 docker-compose -p invitee -f infrastructure/local/docker-compose.yml up
```

### Executing the `Connect` flow
---

- **Inviter** - Create a connection record containing the invitation
```bash
curl -X 'POST' \
'http://localhost:8080/prism-agent/connections' \
-H 'Content-Type: application/json' \
-d '{
"label": "Connect with Alice"
}' | jq
```

- **Inviter** - Retrieving the list of connections
```bash
curl -X 'GET' 'http://localhost:8080/prism-agent/connections' | jq
```

- **Invitee** - Accept OOB invitation

Replace `{RAW_INVITATION}` with the value of the '_oob' query string parameter from the invitation URL above
```bash
curl -X 'POST' \
'http://localhost:8090/prism-agent/connection-invitations' \
-H 'Content-Type: application/json' \
-d '{
"invitation": "{RAW_INVITATION}"
}' | jq
```

- **Invitee** - Retrieving the list of connections
```bash
curl -X 'GET' 'http://localhost:8090/prism-agent/connections' | jq
```
65 changes: 65 additions & 0 deletions prism-agent/service/issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
### Running multiple instances of Prism Agent
---

#### Starting an instance for `Issuer` on port `8080`

```bash
# From the root directory
PORT=8080 docker-compose -p issuer -f infrastructure/local/docker-compose.yml up
```

#### Starting an instance for `Holder` on port `8090`

```bash
# From the root directory
PORT=8090 docker-compose -p holder -f infrastructure/local/docker-compose.yml up
```

### Executing the `Issue` flow
---

- **Issuer** - Initiate a new issue credential flow

Replace `{SUBJECT_ID}` with the DID of the holder displayed at startup in the his Prism Agent console logs
```bash
curl -X 'POST' \
'http://localhost:8080/prism-agent/issue-credentials/credential-offers' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"schemaId": "schema:1234",
"subjectId": "{SUBJECT_ID}",
"validityPeriod": 3600,
"automaticIssuance": false,
"awaitConfirmation": false,
"claims": {
"firstname": "Alice",
"lastname": "Wonderland",
"birthdate": "01/01/2000"
}
}' | jq
```

- **Holder** - Retrieving the list of issue records
```bash
curl -X 'GET' 'http://localhost:8090/prism-agent/issue-credentials/records' | jq
```

- **Holder** - Accepting the credential offer

Replace `{RECORD_ID}` with the UUID of the record from the previous list
```bash
curl -X 'POST' 'http://localhost:8090/prism-agent/issue-credentials/records/{RECORD_ID}/accept-offer' | jq
```

- **Issuer** - Retrieving the list of issue records
```bash
curl -X 'GET' 'http://localhost:8080/prism-agent/issue-credentials/records' | jq
```

- **Issuer** - Issuing the credential

Replace `{RECORD_ID}` with the UUID of the record from the previous list
```bash
curl -X 'POST' 'http://localhost:8080/prism-agent/issue-credentials/records/{RECORD_ID}/issue-credential' | jq
```
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ object Main extends ZIOAppDefault {
.provide(RepoModule.connectDbConfigLayer >>> ConnectMigrations.layer)

agentDID <- for {
peer <- ZIO.succeed(PeerDID.makePeerDid(serviceEndpoint = Some(s"$didCommServiceUrl:$didCommServicePort")))
peer <- ZIO.succeed(PeerDID.makePeerDid(serviceEndpoint = Some(didCommServiceUrl)))
_ <- ZIO.logInfo(s"New DID: ${peer.did}") *>
ZIO.logInfo(s"JWK for KeyAgreement: ${peer.jwkForKeyAgreement.toJSONString}") *>
ZIO.logInfo(s"JWK for KeyAuthentication: ${peer.jwkForKeyAuthentication.toJSONString}")
Expand Down
2 changes: 1 addition & 1 deletion prism-agent/service/version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ThisBuild / version := "0.5.0-SNAPSHOT"
ThisBuild / version := "0.6.0-SNAPSHOT"

0 comments on commit dc8d86b

Please sign in to comment.