From ca1d0bc73a506c890fb33412c1f430ec941e2afb Mon Sep 17 00:00:00 2001 From: Daniel Bluhm Date: Mon, 30 Sep 2024 14:10:09 -0400 Subject: [PATCH] feat: add mediation with public did example Signed-off-by: Daniel Bluhm --- .../mediation-public-did/docker-compose.yml | 108 ++++++++++++++++++ examples/mediation-public-did/example.py | 57 +++++++++ 2 files changed, 165 insertions(+) create mode 100644 examples/mediation-public-did/docker-compose.yml create mode 100644 examples/mediation-public-did/example.py diff --git a/examples/mediation-public-did/docker-compose.yml b/examples/mediation-public-did/docker-compose.yml new file mode 100644 index 0000000..f73a64c --- /dev/null +++ b/examples/mediation-public-did/docker-compose.yml @@ -0,0 +1,108 @@ +version: "3" +services: + alice: + #image: ghcr.io/hyperledger/aries-cloudagent-python:py3.9-0.12.1 + image: acapy-test + ports: + - "3001:3001" + environment: + RUST_LOG: warn + command: > + start + --label Alice + --inbound-transport http 0.0.0.0 3000 + --outbound-transport http + --endpoint http://alice:3000 + --admin 0.0.0.0 3001 + --admin-insecure-mode + --wallet-type askar + --wallet-name alice + --wallet-key insecure + --auto-provision + --log-level debug + --debug-webhooks + --genesis-url https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_testnet_genesis + healthcheck: + test: curl -s -o /dev/null -w '%{http_code}' "http://localhost:3001/status/live" | grep "200" > /dev/null + start_period: 30s + interval: 7s + timeout: 5s + retries: 5 + + bob: + image: ghcr.io/hyperledger/aries-cloudagent-python:py3.9-0.12.1 + ports: + - "3002:3001" + environment: + RUST_LOG: warn + command: > + start + --label Bob + --inbound-transport http 0.0.0.0 3000 + --outbound-transport http + --endpoint http://bob:3000 + --admin 0.0.0.0 3001 + --admin-insecure-mode + --no-ledger + --wallet-type askar + --wallet-name bob + --wallet-key insecure + --auto-provision + --log-level debug + --debug-webhooks + --monitor-revocation-notification + healthcheck: + test: curl -s -o /dev/null -w '%{http_code}' "http://localhost:3001/status/live" | grep "200" > /dev/null + start_period: 30s + interval: 7s + timeout: 5s + retries: 5 + + mediator: + image: ghcr.io/hyperledger/aries-cloudagent-python:py3.9-0.12.1 + ports: + - "3003:3001" + environment: + RUST_LOG: warn + command: > + start + --label Mediator + --inbound-transport http 0.0.0.0 3000 + --outbound-transport http + --endpoint http://mediator:3000 + --admin 0.0.0.0 3001 + --admin-insecure-mode + --no-ledger + --wallet-type askar + --wallet-name mediator + --wallet-key insecure + --auto-provision + --log-level debug + --debug-webhooks + --enable-undelivered-queue + healthcheck: + test: curl -s -o /dev/null -w '%{http_code}' "http://localhost:3001/status/live" | grep "200" > /dev/null + start_period: 30s + interval: 7s + timeout: 5s + retries: 5 + + example: + container_name: controller + build: + context: ../.. + environment: + - ALICE=http://alice:3001 + - BOB=http://bob:3001 + - MEDIATOR=http://mediator:3001 + volumes: + - ../../acapy_controller:/usr/src/app/acapy_controller:z + - ./example.py:/usr/src/app/example.py:ro,z + command: python -m example + depends_on: + alice: + condition: service_healthy + bob: + condition: service_healthy + mediator: + condition: service_healthy diff --git a/examples/mediation-public-did/example.py b/examples/mediation-public-did/example.py new file mode 100644 index 0000000..3e31ce2 --- /dev/null +++ b/examples/mediation-public-did/example.py @@ -0,0 +1,57 @@ +"""Minimal reproducible example script. + +This script is for you to use to reproduce a bug or demonstrate a feature. +""" + +import asyncio +from os import getenv + +from acapy_controller import Controller +from acapy_controller.logging import logging_to_stdout +from acapy_controller.protocols import ( + connection, + didexchange, + indy_anoncred_onboard, + request_mediation_v1, + trustping, +) + +ALICE = getenv("ALICE", "http://alice:3001") +BOB = getenv("BOB", "http://bob:3001") +MEDIATOR = getenv("MEDIATOR", "http://mediator:3001") + + +async def main(): + """Test Controller protocols.""" + alice = Controller(base_url=ALICE) + bob = Controller(base_url=BOB) + mediator = Controller(base_url=MEDIATOR) + + async with alice, bob, mediator: + public_did = await indy_anoncred_onboard(alice) + # await alice.get(f"/resolver/resolve/did:sov:{public_did.did}") + ma, am = await didexchange(mediator, alice) + mam, amm = await request_mediation_v1( + mediator, alice, ma.connection_id, am.connection_id + ) + await alice.put(f"/mediation/{amm.mediation_id}/default-mediator") + await alice.post( + "/wallet/set-did-endpoint", + json={ + "did": public_did.did, + "mediation_id": amm.mediation_id, + }, + ) + await alice.get(f"/resolver/resolve/did:sov:{public_did.did}") + return + + ab, ba = await didexchange(alice, bob) + await trustping(alice, ab) + + ab, ba = await connection(alice, bob) + await trustping(alice, ab) + + +if __name__ == "__main__": + logging_to_stdout() + asyncio.run(main())