Skip to content

Commit 2e4413d

Browse files
committed
oob notebooks
1 parent ce1f803 commit 2e4413d

File tree

3 files changed

+300
-25
lines changed

3 files changed

+300
-25
lines changed

libs/aries-basic-controller/aries_basic_controller/controllers/oob.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ def default_handler(self, payload):
1414
logger.debug("Out of Band ", payload)
1515

1616
async def create_invitation(self, data):
17-
response = await self.admin_POST(f"/out-of-band/create-invitation", data = data)
17+
response = await self.admin_POST(f"/out-of-band/create-invitation", json_data = data)
1818
return response
1919

2020
async def receive_invitation(self, data):
21-
response = await self.admin_POST(f"/out-of-band/receive-invitation", data = data)
21+
response = await self.admin_POST(f"/out-of-band/receive-invitation", json_data = data)
2222
return response

tutorials/aries-basic-controller/notebooks/alice/Part 8 - Out of Band Protocol.ipynb

Lines changed: 119 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,34 @@
11
{
22
"cells": [
33
{
4-
"cell_type": "code",
5-
"execution_count": null,
4+
"cell_type": "markdown",
65
"metadata": {},
7-
"outputs": [],
86
"source": [
9-
"%autoawait\n",
10-
"import time\n",
11-
"import asyncio"
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"
1220
]
1321
},
1422
{
1523
"cell_type": "code",
16-
"execution_count": null,
24+
"execution_count": 2,
1725
"metadata": {},
1826
"outputs": [],
1927
"source": [
28+
"%autoawait\n",
29+
"import time\n",
30+
"import asyncio\n",
31+
"import json\n",
2032
"from aries_basic_controller.aries_controller import AriesAgentController\n",
2133
" \n",
2234
"WEBHOOK_HOST = \"0.0.0.0\"\n",
@@ -34,48 +46,132 @@
3446
]
3547
},
3648
{
37-
"cell_type": "code",
38-
"execution_count": null,
49+
"cell_type": "markdown",
3950
"metadata": {},
40-
"outputs": [],
4151
"source": [
42-
"\n",
43-
"loop = asyncio.get_event_loop()\n",
44-
"loop.create_task(agent_controller.listen_webhooks())\n",
45-
"\n",
46-
"agent_controller.register_listeners([], defaults=True)"
52+
"## 2. Configure Listeners for Connection Webhooks"
4753
]
4854
},
4955
{
5056
"cell_type": "code",
51-
"execution_count": null,
57+
"execution_count": 3,
5258
"metadata": {},
5359
"outputs": [],
54-
"source": []
60+
"source": [
61+
"loop = asyncio.get_event_loop()\n",
62+
"loop.create_task(agent_controller.listen_webhooks())\n",
63+
"\n",
64+
"def connections_handler(payload):\n",
65+
" print(\"Connection Webhook : \", payload)\n",
66+
" \n",
67+
"connections_listener = {\n",
68+
" \"topic\": \"connections\",\n",
69+
" \"handler\": connections_handler\n",
70+
"}\n",
71+
"\n",
72+
"\n",
73+
"agent_controller.register_listeners([connections_listener], defaults=True)"
74+
]
5575
},
5676
{
5777
"cell_type": "markdown",
5878
"metadata": {},
5979
"source": [
60-
"## 4a. Use the controller to create an out of band connection invitation"
80+
"## 3. Create an out of band connection invitation"
6181
]
6282
},
6383
{
6484
"cell_type": "code",
65-
"execution_count": null,
85+
"execution_count": 4,
6686
"metadata": {},
67-
"outputs": [],
87+
"outputs": [
88+
{
89+
"name": "stdout",
90+
"output_type": "stream",
91+
"text": [
92+
"{'@type': 'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/out-of-band/1.0/invitation', '@id': '4a611f31-396a-4e94-bdfb-820d81bde452', 'request~attach': [], 'handshake_protocols': ['https://didcomm.org/connections/1.0/invitation', 'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/connections/1.0/invitation'], 'label': 'Alice', 'service': [{'id': '#inline', 'type': 'did-communication', 'recipientKeys': ['did:key:z6MkuU5tbz5eQ5e5w2NCB1rHFWX5dbMvu8G1yoiY7M9Zd7cH'], 'routingKeys': [], 'serviceEndpoint': 'http://172.17.0.1:8020'}]}\n"
93+
]
94+
}
95+
],
6896
"source": [
6997
"payload = {\n",
7098
" \"include_handshake\": True,\n",
7199
" \"use_public_did\": False\n",
72100
"}\n",
73-
"print(json.dumps(payload))\n",
74101
"\n",
75102
"# Create an out of band Invitation\n",
76-
"oob_invite = await agent_controller.oob.create_invitation(json.dumps(payload))\n",
77-
"print(json.dumps(oob_invite))"
103+
"oob_invite = await agent_controller.oob.create_invitation(payload)\n",
104+
"print(oob_invite[\"invitation\"])"
105+
]
106+
},
107+
{
108+
"cell_type": "markdown",
109+
"metadata": {},
110+
"source": [
111+
"## 4. Copy Invitation Across to Bob's [Notebook](http://localhost:8889/notebooks/Part%208%20-%20Out%20of%20Band%20Protocol.ipynb)"
112+
]
113+
},
114+
{
115+
"cell_type": "markdown",
116+
"metadata": {},
117+
"source": [
118+
"## 10. Accept Connection Request for the OOB Connection"
119+
]
120+
},
121+
{
122+
"cell_type": "code",
123+
"execution_count": 8,
124+
"metadata": {},
125+
"outputs": [
126+
{
127+
"name": "stdout",
128+
"output_type": "stream",
129+
"text": [
130+
"{'created_at': '2020-10-30 11:18:20.340874Z', 'invitation_id': '5765c0f0-0618-4164-a88f-cfc43824bb59', 'trace': False, 'updated_at': '2020-10-30 11:18:20.340874Z', 'state': 'initial', 'invitation': {'@type': 'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/out-of-band/1.0/invitation', '@id': '4a611f31-396a-4e94-bdfb-820d81bde452', 'request~attach': [], 'handshake_protocols': ['https://didcomm.org/connections/1.0/invitation', 'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/connections/1.0/invitation'], 'label': 'Alice', 'service': [{'id': '#inline', 'type': 'did-communication', 'recipientKeys': ['did:key:z6MkuU5tbz5eQ5e5w2NCB1rHFWX5dbMvu8G1yoiY7M9Zd7cH'], 'routingKeys': [], 'serviceEndpoint': 'http://172.17.0.1:8020'}]}}\n"
131+
]
132+
}
133+
],
134+
"source": [
135+
"print(oob_invite)"
78136
]
137+
},
138+
{
139+
"cell_type": "code",
140+
"execution_count": 9,
141+
"metadata": {},
142+
"outputs": [
143+
{
144+
"data": {
145+
"text/plain": [
146+
"{'results': [{'routing_state': 'none',\n",
147+
" 'accept': 'auto',\n",
148+
" 'invitation_mode': 'once',\n",
149+
" 'my_did': '4J8kyCXH4mHE7UW3E6oqyt',\n",
150+
" 'created_at': '2020-10-30 11:18:20.316265Z',\n",
151+
" 'connection_id': '1e539413-8da2-4e2d-94cf-2620015e3ed5',\n",
152+
" 'initiator': 'self',\n",
153+
" 'updated_at': '2020-10-30 11:19:27.696692Z',\n",
154+
" 'their_label': 'Bob',\n",
155+
" 'their_did': 'p79aZieUZCrLJgxM7Kvkc',\n",
156+
" 'invitation_key': 'G1pr1jqD4Y9cpXXVVStSQQy5p265VF1fHnocH5BYhtpu',\n",
157+
" 'state': 'response'}]}"
158+
]
159+
},
160+
"execution_count": 9,
161+
"metadata": {},
162+
"output_type": "execute_result"
163+
}
164+
],
165+
"source": [
166+
"await agent_controller.connections.get_connections()"
167+
]
168+
},
169+
{
170+
"cell_type": "code",
171+
"execution_count": null,
172+
"metadata": {},
173+
"outputs": [],
174+
"source": []
79175
}
80176
],
81177
"metadata": {
Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Out of Band Protocol - Receiver\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+
"Begin in the [sender notebook](http://localhost:8888/notebooks/Part%208%20-%20Out%20of%20Band%20Protocol.ipynb)."
14+
]
15+
},
16+
{
17+
"cell_type": "markdown",
18+
"metadata": {},
19+
"source": [
20+
"## 5. Initialise the Controller"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": 2,
26+
"metadata": {},
27+
"outputs": [
28+
{
29+
"name": "stdout",
30+
"output_type": "stream",
31+
"text": [
32+
"IPython autoawait is `on`, and set to use `asyncio`\n"
33+
]
34+
}
35+
],
36+
"source": [
37+
"%autoawait\n",
38+
"import time\n",
39+
"import asyncio\n",
40+
"\n",
41+
"from aries_basic_controller.aries_controller import AriesAgentController\n",
42+
" \n",
43+
"WEBHOOK_HOST = \"0.0.0.0\"\n",
44+
"WEBHOOK_PORT = 8052\n",
45+
"WEBHOOK_BASE = \"\"\n",
46+
"ADMIN_URL = \"http://bob-agent:8051\"\n",
47+
"\n",
48+
"agent_controller = AriesAgentController(webhook_host=WEBHOOK_HOST, webhook_port=WEBHOOK_PORT,\n",
49+
" webhook_base=WEBHOOK_BASE, admin_url=ADMIN_URL, connections=True)"
50+
]
51+
},
52+
{
53+
"cell_type": "markdown",
54+
"metadata": {},
55+
"source": [
56+
"## 6. Configure Connection Listeners"
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": null,
62+
"metadata": {},
63+
"outputs": [],
64+
"source": [
65+
"loop = asyncio.get_event_loop()\n",
66+
"loop.create_task(agent_controller.listen_webhooks())\n",
67+
"\n",
68+
"def connections_handler(payload):\n",
69+
" print(\"Connection Webhook : \", payload)\n",
70+
" \n",
71+
"connections_listener = {\n",
72+
" \"topic\": \"connections\",\n",
73+
" \"handler\": connections_handler\n",
74+
"}\n",
75+
"\n",
76+
"\n",
77+
"agent_controller.register_listeners([connections_listener], defaults=True)"
78+
]
79+
},
80+
{
81+
"cell_type": "markdown",
82+
"metadata": {},
83+
"source": [
84+
"## 7. Receive Out of Band Invitation\n",
85+
"\n",
86+
"**You should have copied this from the Sender notebook (Step 3)**"
87+
]
88+
},
89+
{
90+
"cell_type": "code",
91+
"execution_count": 6,
92+
"metadata": {},
93+
"outputs": [
94+
{
95+
"name": "stdout",
96+
"output_type": "stream",
97+
"text": [
98+
"{'request_id': '54503fbb-0f20-475b-b014-e6f411e85dea', 'connection_id': '641c865f-0bfb-4ccd-bc26-e5328a1b3f05', 'their_label': 'Alice', 'accept': 'auto', 'created_at': '2020-10-30 11:28:20.655988Z', 'invitation_key': 'G1pr1jqD4Y9cpXXVVStSQQy5p265VF1fHnocH5BYhtpu', 'my_did': 'HdesGn1FTbpZjq3Sg2U8hQ', 'routing_state': 'none', 'updated_at': '2020-10-30 11:28:20.673566Z', 'initiator': 'external', 'state': 'request', 'invitation_mode': 'once'}\n"
99+
]
100+
}
101+
],
102+
"source": [
103+
"import json\n",
104+
"oob_invite = {'@type': 'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/out-of-band/1.0/invitation', '@id': '4a611f31-396a-4e94-bdfb-820d81bde452', 'request~attach': [], 'handshake_protocols': ['https://didcomm.org/connections/1.0/invitation', 'did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/connections/1.0/invitation'], 'label': 'Alice', 'service': [{'id': '#inline', 'type': 'did-communication', 'recipientKeys': ['did:key:z6MkuU5tbz5eQ5e5w2NCB1rHFWX5dbMvu8G1yoiY7M9Zd7cH'], 'routingKeys': [], 'serviceEndpoint': 'http://172.17.0.1:8020'}]}\n",
105+
"\n",
106+
"response = await agent_controller.oob.receive_invitation(oob_invite)\n",
107+
"print(response)"
108+
]
109+
},
110+
{
111+
"cell_type": "markdown",
112+
"metadata": {},
113+
"source": [
114+
"## 8. Get Connection"
115+
]
116+
},
117+
{
118+
"cell_type": "code",
119+
"execution_count": 8,
120+
"metadata": {},
121+
"outputs": [
122+
{
123+
"name": "stdout",
124+
"output_type": "stream",
125+
"text": [
126+
"641c865f-0bfb-4ccd-bc26-e5328a1b3f05\n",
127+
"{'request_id': '54503fbb-0f20-475b-b014-e6f411e85dea', 'connection_id': '641c865f-0bfb-4ccd-bc26-e5328a1b3f05', 'their_label': 'Alice', 'accept': 'auto', 'created_at': '2020-10-30 11:28:20.655988Z', 'invitation_key': 'G1pr1jqD4Y9cpXXVVStSQQy5p265VF1fHnocH5BYhtpu', 'my_did': 'HdesGn1FTbpZjq3Sg2U8hQ', 'routing_state': 'none', 'updated_at': '2020-10-30 11:28:20.673566Z', 'initiator': 'external', 'state': 'request', 'invitation_mode': 'once'}\n"
128+
]
129+
}
130+
],
131+
"source": [
132+
"connection_id = response[\"connection_id\"]\n",
133+
"print(connection_id)\n",
134+
"\n",
135+
"connection = await agent_controller.connections.get_connection(connection_id)\n",
136+
"\n",
137+
"print(connection)\n",
138+
"print(\"Connection State : \", connection[\"state\"])"
139+
]
140+
},
141+
{
142+
"cell_type": "markdown",
143+
"metadata": {},
144+
"source": [
145+
"## 9. Continue in the Sender [Notebook](http://localhost:8888/notebooks/Part%208%20-%20Out%20of%20Band%20Protocol.ipynb)\n",
146+
"\n",
147+
"You will need to accept the request and send a trust ping before this connection moves to the active state."
148+
]
149+
},
150+
{
151+
"cell_type": "code",
152+
"execution_count": null,
153+
"metadata": {},
154+
"outputs": [],
155+
"source": []
156+
}
157+
],
158+
"metadata": {
159+
"kernelspec": {
160+
"display_name": "Python 3",
161+
"language": "python",
162+
"name": "python3"
163+
},
164+
"language_info": {
165+
"codemirror_mode": {
166+
"name": "ipython",
167+
"version": 3
168+
},
169+
"file_extension": ".py",
170+
"mimetype": "text/x-python",
171+
"name": "python",
172+
"nbconvert_exporter": "python",
173+
"pygments_lexer": "ipython3",
174+
"version": "3.7.6"
175+
}
176+
},
177+
"nbformat": 4,
178+
"nbformat_minor": 4
179+
}

0 commit comments

Comments
 (0)