|
| 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