Skip to content

Commit bb265a8

Browse files
authored
Merge pull request #42 from OpenMined/feature/acapy056
Feature/acapy056
2 parents 2b3c657 + 7af00b4 commit bb265a8

File tree

8 files changed

+477
-11
lines changed

8 files changed

+477
-11
lines changed

libs/aries-basic-controller/aries_basic_controller/aries_controller.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
from .controllers.ledger import LedgerController
1616
from .controllers.credential import CredentialController
1717
from .controllers.server import ServerController
18+
from .controllers.oob import OOBController
1819

1920
import logging
2021

@@ -52,6 +53,8 @@ def __init__(self, webhook_host: str, webhook_port: int, admin_url: str, webhook
5253
self.ledger = LedgerController(self.admin_url, self.client_session)
5354
self.credentials = CredentialController(self.admin_url, self.client_session)
5455
self.server = ServerController(self.admin_url, self.client_session)
56+
self.oob = OOBController(self.admin_url, self.client_session)
57+
5558
if issuer:
5659
self.schema = SchemaController(self.admin_url, self.client_session)
5760
self.wallet = WalletController(self.admin_url, self.client_session)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from .base import BaseController
2+
from aiohttp import ClientSession
3+
import logging
4+
5+
logger = logging.getLogger("aries_controller.out-of-band")
6+
7+
class OOBController(BaseController):
8+
9+
def __init__(self, admin_url: str, client_session: ClientSession):
10+
super().__init__(admin_url, client_session)
11+
12+
13+
def default_handler(self, payload):
14+
logger.debug("Out of Band ", payload)
15+
16+
async def create_invitation(self, data):
17+
response = await self.admin_POST(f"/out-of-band/create-invitation", json_data = data)
18+
return response
19+
20+
async def receive_invitation(self, data):
21+
response = await self.admin_POST(f"/out-of-band/receive-invitation", json_data = data)
22+
return response
6.88 KB
Loading

tutorials/aries-basic-controller/docker-compose.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "3"
22
services:
33
bob-agent:
4-
image: bcgovimages/aries-cloudagent:py36-1.14-1_0.5.1
4+
image: bcgovimages/aries-cloudagent:py36-1.15-0_0.5.6
55
ports:
66
- ${BOB_HTTP_PORT}:${BOB_HTTP_PORT}
77
- ${BOB_ADMIN_PORT}:${BOB_ADMIN_PORT}
@@ -22,15 +22,17 @@ services:
2222
--endpoint ${BOB_AGENT_ENDPOINT} \
2323
--webhook-url ${BOB_WEBHOOK_URL} \
2424
--wallet-type 'indy' \
25+
--wallet-name '${BOB_WALLET_NAME}' \
26+
--wallet-key ${BOB_WALLET_KEY} \
2527
--seed '${BOB_WALLET_SEED}' \
2628
--admin '0.0.0.0' ${BOB_ADMIN_PORT} \
2729
--admin-insecure-mode \
2830
--log-level info \
29-
--genesis-url '${LEDGER_URL}/genesis'
31+
--genesis-url '${LEDGER_URL}/genesis' \
3032
--label ${BOB_AGENT_NAME}",
3133
]
3234
alice-agent:
33-
image: bcgovimages/aries-cloudagent:py36-1.14-1_0.5.1
35+
image: bcgovimages/aries-cloudagent:py36-1.15-0_0.5.6
3436
ports:
3537
- ${ALICE_HTTP_PORT}:${ALICE_HTTP_PORT}
3638
- ${ALICE_ADMIN_PORT}:${ALICE_ADMIN_PORT}
@@ -53,11 +55,13 @@ services:
5355
--endpoint ${ALICE_AGENT_ENDPOINT} \
5456
--webhook-url ${ALICE_WEBHOOK_URL} \
5557
--wallet-type 'indy' \
58+
--wallet-name '${ALICE_WALLET_NAME}' \
59+
--wallet-key ${ALICE_WALLET_KEY} \
5660
--seed '${ALICE_WALLET_SEED}' \
5761
--admin '0.0.0.0' ${ALICE_ADMIN_PORT} \
5862
--admin-api-key ${ALICE_API_KEY} \
5963
--log-level info \
60-
--genesis-url '${LEDGER_URL}/genesis'
64+
--genesis-url '${LEDGER_URL}/genesis' \
6165
--label ${ALICE_AGENT_NAME}",
6266
]
6367
setup:

tutorials/aries-basic-controller/manage

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ configureEnvironment() {
125125
export BOB_AGENT_ENDPOINT=${BOB_AGENT_ENDPOINT:-http://$DOCKERHOST:$BOB_HTTP_PORT}
126126
export BOB_WALLET_SEED="bob_seed_00000000000000000000000"
127127
export BOB_JUPYTER_PORT="8889"
128+
export BOB_WALLET_NAME="Bob Wallet"
129+
export BOB_WALLET_KEY="bob_key_00000000000000000000000"
128130

129131

130132
# alice-agent
@@ -137,6 +139,8 @@ configureEnvironment() {
137139
export ALICE_AGENT_ENDPOINT=${ALICE_AGENT_ENDPOINT:-http://$DOCKERHOST:$ALICE_HTTP_PORT}
138140
export ALICE_WALLET_SEED="alice_seed_000000000000000000000"
139141
export ALICE_JUPYTER_PORT="8888"
142+
export ALICE_WALLET_NAME="Alice Wallet"
143+
export ALICE_WALLET_KEY="alice_key_00000000000000000000000"
140144

141145

142146
}

tutorials/aries-basic-controller/notebooks/alice/Part 3 - Establishing a Connection.ipynb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
},
4646
{
4747
"cell_type": "code",
48-
"execution_count": 1,
48+
"execution_count": 2,
4949
"metadata": {},
5050
"outputs": [
5151
{
@@ -77,7 +77,7 @@
7777
},
7878
{
7979
"cell_type": "code",
80-
"execution_count": 2,
80+
"execution_count": 3,
8181
"metadata": {},
8282
"outputs": [],
8383
"source": [
@@ -112,7 +112,7 @@
112112
},
113113
{
114114
"cell_type": "code",
115-
"execution_count": 3,
115+
"execution_count": 4,
116116
"metadata": {},
117117
"outputs": [],
118118
"source": [
@@ -138,23 +138,24 @@
138138
},
139139
{
140140
"cell_type": "code",
141-
"execution_count": 4,
141+
"execution_count": 13,
142142
"metadata": {},
143143
"outputs": [
144144
{
145145
"name": "stdout",
146146
"output_type": "stream",
147147
"text": [
148-
"Connection ID c62331ca-bc95-4f7a-93dd-043f501cb21a\n",
148+
"Connection ID f06d9c62-3f3c-4b54-8df2-297fa6c7760b\n",
149149
"Invitation\n",
150-
"{'connection_id': 'c62331ca-bc95-4f7a-93dd-043f501cb21a', 'invitation': {'@type': 'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/connections/1.0/invitation', '@id': '916e944d-cb7e-4e69-99c6-34aac5bea636', 'serviceEndpoint': 'http://172.17.0.1:8020', 'label': 'Alice', 'recipientKeys': ['AGQrdCLtBbPPs5vX8K8RJrns9UyZLzvW5rvszNWrzq1V']}, 'invitation_url': 'http://172.17.0.1:8020?c_i=eyJAdHlwZSI6ICJkaWQ6c292OkJ6Q2JzTlloTXJqSGlxWkRUVUFTSGc7c3BlYy9jb25uZWN0aW9ucy8xLjAvaW52aXRhdGlvbiIsICJAaWQiOiAiOTE2ZTk0NGQtY2I3ZS00ZTY5LTk5YzYtMzRhYWM1YmVhNjM2IiwgInNlcnZpY2VFbmRwb2ludCI6ICJodHRwOi8vMTcyLjE3LjAuMTo4MDIwIiwgImxhYmVsIjogIkFsaWNlIiwgInJlY2lwaWVudEtleXMiOiBbIkFHUXJkQ0x0QmJQUHM1dlg4SzhSSnJuczlVeVpMenZXNXJ2c3pOV3J6cTFWIl19'}\n"
150+
"{'connection_id': 'f06d9c62-3f3c-4b54-8df2-297fa6c7760b', 'invitation': {'@type': 'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/connections/1.0/invitation', '@id': '64cad920-7ca3-4b52-9ab9-a9d1f32abde5', 'serviceEndpoint': 'http://192.168.65.3:8020', 'recipientKeys': ['3VX9fa6Z1Sa1wJmsE2GZNvdtFGRqm81bL4BqbWRsc4Sn'], 'label': 'Alice'}, 'invitation_url': 'http://192.168.65.3:8020?c_i=eyJAdHlwZSI6ICJkaWQ6c292OkJ6Q2JzTlloTXJqSGlxWkRUVUFTSGc7c3BlYy9jb25uZWN0aW9ucy8xLjAvaW52aXRhdGlvbiIsICJAaWQiOiAiNjRjYWQ5MjAtN2NhMy00YjUyLTlhYjktYTlkMWYzMmFiZGU1IiwgInNlcnZpY2VFbmRwb2ludCI6ICJodHRwOi8vMTkyLjE2OC42NS4zOjgwMjAiLCAicmVjaXBpZW50S2V5cyI6IFsiM1ZYOWZhNloxU2Exd0ptc0UyR1pOdmR0RkdScW04MWJMNEJxYldSc2M0U24iXSwgImxhYmVsIjogIkFsaWNlIn0='}\n"
151151
]
152152
}
153153
],
154154
"source": [
155155
"# Create Invitation\n",
156156
"invite = await agent_controller.connections.create_invitation()\n",
157157
"connection_id = invite[\"connection_id\"]\n",
158+
"invite_message = invite['invitation']\n",
158159
"print(\"Connection ID\", connection_id)\n",
159160
"print(\"Invitation\")\n",
160161
"print(invite)"
@@ -291,7 +292,7 @@
291292
},
292293
{
293294
"cell_type": "code",
294-
"execution_count": 8,
295+
"execution_count": 30,
295296
"metadata": {},
296297
"outputs": [
297298
{
Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Out of Band Protocol - Sender\n",
8+
"\n",
9+
"The out of band protocol allows agents to exchange messages without requiring a DIDComm channel. This can be used to establish a connection, request a presentation or issue a credential. \n",
10+
"\n",
11+
"The RFC is described [here](https://github.com/hyperledger/aries-rfcs/tree/master/features/0434-outofband)\n",
12+
"\n"
13+
]
14+
},
15+
{
16+
"cell_type": "markdown",
17+
"metadata": {},
18+
"source": [
19+
"## 1. Initialise the Controller"
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": 1,
25+
"metadata": {},
26+
"outputs": [
27+
{
28+
"name": "stdout",
29+
"output_type": "stream",
30+
"text": [
31+
"IPython autoawait is `on`, and set to use `asyncio`\n"
32+
]
33+
}
34+
],
35+
"source": [
36+
"%autoawait\n",
37+
"import time\n",
38+
"import asyncio\n",
39+
"import json\n",
40+
"from aries_basic_controller.aries_controller import AriesAgentController\n",
41+
" \n",
42+
"WEBHOOK_HOST = \"0.0.0.0\"\n",
43+
"WEBHOOK_PORT = 8022\n",
44+
"WEBHOOK_BASE = \"\"\n",
45+
"ADMIN_URL = \"http://alice-agent:8021\"\n",
46+
"\n",
47+
"# WARNING: You should use environment variables for this\n",
48+
"# TODO: Make env variables accessible through juypter notebooks\n",
49+
"API_KEY = \"alice_api_123456789\"\n",
50+
"\n",
51+
"# Based on the aca-py agent you wish to control\n",
52+
"agent_controller = AriesAgentController(webhook_host=WEBHOOK_HOST, webhook_port=WEBHOOK_PORT,\n",
53+
" webhook_base=WEBHOOK_BASE, admin_url=ADMIN_URL, api_key=API_KEY)\n"
54+
]
55+
},
56+
{
57+
"cell_type": "markdown",
58+
"metadata": {},
59+
"source": [
60+
"## 2. Configure Listeners for Connection Webhooks"
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": 2,
66+
"metadata": {},
67+
"outputs": [],
68+
"source": [
69+
"loop = asyncio.get_event_loop()\n",
70+
"loop.create_task(agent_controller.listen_webhooks())\n",
71+
"\n",
72+
"def connections_handler(payload):\n",
73+
" print(\"Connection Webhook : \", payload)\n",
74+
" \n",
75+
"connections_listener = {\n",
76+
" \"topic\": \"connections\",\n",
77+
" \"handler\": connections_handler\n",
78+
"}\n",
79+
"\n",
80+
"\n",
81+
"agent_controller.register_listeners([connections_listener], defaults=True)"
82+
]
83+
},
84+
{
85+
"cell_type": "markdown",
86+
"metadata": {},
87+
"source": [
88+
"## 3. Create an out of band connection invitation"
89+
]
90+
},
91+
{
92+
"cell_type": "code",
93+
"execution_count": 6,
94+
"metadata": {},
95+
"outputs": [
96+
{
97+
"name": "stdout",
98+
"output_type": "stream",
99+
"text": [
100+
"Connection Webhook : {'state': 'invitation', 'created_at': '2020-10-30 12:48:46.878516Z', 'initiator': 'self', 'invitation_key': '8egq2Lysck4b9HpLKez4bZcDnwZqgVNFMeuSUBaGdLW1', 'routing_state': 'none', 'updated_at': '2020-10-30 12:48:46.878516Z', 'invitation_mode': 'once', 'connection_id': '3b715fb1-8c0f-4535-8575-37347af9c1c6', 'accept': 'auto'}\n",
101+
"{'@type': 'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/out-of-band/1.0/invitation', '@id': 'e536ed97-2e32-4133-bf20-7ce998739267', 'label': 'Alice', 'handshake_protocols': ['https://didcomm.org/connections/1.0/invitation', 'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/connections/1.0/invitation'], 'request~attach': [], 'service': [{'id': '#inline', 'type': 'did-communication', 'recipientKeys': ['did:key:z6Mkn6wscbEJxHZ4Fnf31DwuSfADcWqh6Ncc3fpNJTYHYZHP'], 'routingKeys': [], 'serviceEndpoint': 'http://172.17.0.1:8020'}]}\n"
102+
]
103+
}
104+
],
105+
"source": [
106+
"payload = {\n",
107+
" \"include_handshake\": True,\n",
108+
" \"use_public_did\": False\n",
109+
"}\n",
110+
"\n",
111+
"# Create an out of band Invitation\n",
112+
"oob_invite = await agent_controller.oob.create_invitation(payload)\n",
113+
"print(\"COPY OOB INVITE\")\n",
114+
"print(oob_invite[\"invitation\"])"
115+
]
116+
},
117+
{
118+
"cell_type": "markdown",
119+
"metadata": {},
120+
"source": [
121+
"## 4. Copy Invitation Across to Bob's [Notebook](http://localhost:8889/notebooks/Part%208%20-%20Out%20of%20Band%20Protocol.ipynb)"
122+
]
123+
},
124+
{
125+
"cell_type": "markdown",
126+
"metadata": {},
127+
"source": [
128+
"## 10. Connection Should Now Be Active"
129+
]
130+
},
131+
{
132+
"cell_type": "code",
133+
"execution_count": 8,
134+
"metadata": {},
135+
"outputs": [
136+
{
137+
"data": {
138+
"text/plain": [
139+
"{'results': [{'their_label': 'Bob',\n",
140+
" 'state': 'active',\n",
141+
" 'created_at': '2020-10-30 12:48:46.878516Z',\n",
142+
" 'their_did': '3oyc4duyVFbKq6wKLhqfv5',\n",
143+
" 'initiator': 'self',\n",
144+
" 'invitation_key': '8egq2Lysck4b9HpLKez4bZcDnwZqgVNFMeuSUBaGdLW1',\n",
145+
" 'routing_state': 'none',\n",
146+
" 'updated_at': '2020-10-30 12:52:25.926105Z',\n",
147+
" 'invitation_mode': 'once',\n",
148+
" 'connection_id': '3b715fb1-8c0f-4535-8575-37347af9c1c6',\n",
149+
" 'accept': 'auto',\n",
150+
" 'my_did': '6RoJMQnJikyY2Em2pz7p8Q'}]}"
151+
]
152+
},
153+
"execution_count": 8,
154+
"metadata": {},
155+
"output_type": "execute_result"
156+
}
157+
],
158+
"source": [
159+
"await agent_controller.connections.get_connections()"
160+
]
161+
},
162+
{
163+
"cell_type": "markdown",
164+
"metadata": {},
165+
"source": [
166+
"## End of Tutorial"
167+
]
168+
},
169+
{
170+
"cell_type": "code",
171+
"execution_count": 9,
172+
"metadata": {},
173+
"outputs": [],
174+
"source": [
175+
"await agent_controller.terminate()"
176+
]
177+
},
178+
{
179+
"cell_type": "code",
180+
"execution_count": null,
181+
"metadata": {},
182+
"outputs": [],
183+
"source": []
184+
}
185+
],
186+
"metadata": {
187+
"kernelspec": {
188+
"display_name": "Python 3",
189+
"language": "python",
190+
"name": "python3"
191+
},
192+
"language_info": {
193+
"codemirror_mode": {
194+
"name": "ipython",
195+
"version": 3
196+
},
197+
"file_extension": ".py",
198+
"mimetype": "text/x-python",
199+
"name": "python",
200+
"nbconvert_exporter": "python",
201+
"pygments_lexer": "ipython3",
202+
"version": "3.7.6"
203+
}
204+
},
205+
"nbformat": 4,
206+
"nbformat_minor": 4
207+
}

0 commit comments

Comments
 (0)