|
2 | 2 | "cells": [
|
3 | 3 | {
|
4 | 4 | "cell_type": "markdown",
|
5 |
| - "id": "assumed-cisco", |
| 5 | + "id": "transsexual-greeting", |
6 | 6 | "metadata": {},
|
7 | 7 | "source": [
|
8 | 8 | "# Establish Authenticated Connection's with Data Scientist's\n",
|
|
14 | 14 | },
|
15 | 15 | {
|
16 | 16 | "cell_type": "markdown",
|
17 |
| - "id": "vertical-expert", |
| 17 | + "id": "organic-agent", |
18 | 18 | "metadata": {},
|
19 | 19 | "source": [
|
20 | 20 | "## 1. Create a Data Owner class\n",
|
|
31 | 31 | {
|
32 | 32 | "cell_type": "code",
|
33 | 33 | "execution_count": 1,
|
34 |
| - "id": "metric-fifth", |
| 34 | + "id": "increased-daughter", |
35 | 35 | "metadata": {},
|
36 | 36 | "outputs": [
|
37 | 37 | {
|
|
47 | 47 | "import time\n",
|
48 | 48 | "import asyncio\n",
|
49 | 49 | "import json\n",
|
| 50 | + "from dataclasses import dataclass\n", |
50 | 51 | "# I think this is because jupyter notebook also runs an event loop\n",
|
51 | 52 | "import nest_asyncio\n",
|
52 | 53 | "nest_asyncio.apply()\n",
|
53 | 54 | "from termcolor import colored,cprint\n",
|
54 | 55 | "\n",
|
55 | 56 | "from aries_basic_controller.aries_controller import AriesAgentController\n",
|
56 | 57 | " \n",
|
57 |
| - "\n", |
| 58 | + "@dataclass(unsafe_hash=True)\n", |
58 | 59 | "class DataOwner(AriesAgentController):\n",
|
| 60 | + " \"\"\"The DataOwner Aries Agent Controller class\n", |
| 61 | + "\n", |
| 62 | + " Attributes:\n", |
| 63 | + " ----------\n", |
| 64 | + " webhook_host : str\n", |
| 65 | + " The url of the webhook host\n", |
| 66 | + " webhook_port : int\n", |
| 67 | + " The exposed port for webhooks on the host\n", |
| 68 | + " webhook_base : str\n", |
| 69 | + " The base url for webhooks (default is \"\")\n", |
| 70 | + " \"\"\"\n", |
59 | 71 | " \n",
|
60 |
| - " def __init__(self, webhook_host: str, webhook_port: int, admin_url: str, webhook_base: str = \"\"):\n", |
| 72 | + "\n", |
| 73 | + "\n", |
| 74 | + " admin_url: str = None\n", |
| 75 | + " webhook_host: str = None\n", |
| 76 | + " webhook_port: int = None\n", |
| 77 | + " webhook_base: str = \"\"\n", |
| 78 | + " \n", |
| 79 | + " def __post_init__(self):\n", |
61 | 80 | " # Call the AriesAgentController constructor\n",
|
62 |
| - " super().__init__(webhook_host, webhook_port, admin_url, webhook_base)\n", |
| 81 | + " super().__post_init__()\n", |
63 | 82 | " \n",
|
| 83 | + "\n", |
| 84 | + "\n", |
64 | 85 | " # Keep track of which connections the data owner trusts\n",
|
65 | 86 | " self.trusted_scientist_ids = []\n",
|
66 | 87 | " \n",
|
|
75 | 96 | " {\"topic\":\"present_proof\", \"handler\": self._proof_handler}]\n",
|
76 | 97 | " \n",
|
77 | 98 | " # Start webhook server in AriesAgentController\n",
|
| 99 | + " self.init_webhook_server(webhook_host=WEBHOOK_HOST, webhook_port=WEBHOOK_PORT,\n", |
| 100 | + " webhook_base=WEBHOOK_BASE)\n", |
78 | 101 | " loop = asyncio.get_event_loop()\n",
|
79 | 102 | " loop.run_until_complete(self.listen_webhooks())\n",
|
80 |
| - " \n", |
81 | 103 | " # Register listeners\n",
|
82 | 104 | " print(\"Register Listeners\")\n",
|
83 | 105 | " print(self.agent_listeners)\n",
|
|
259 | 281 | },
|
260 | 282 | {
|
261 | 283 | "cell_type": "markdown",
|
262 |
| - "id": "aware-indonesian", |
| 284 | + "id": "continued-lincoln", |
263 | 285 | "metadata": {},
|
264 | 286 | "source": [
|
265 | 287 | "## 2. Instantiate the Data Owner\n",
|
|
270 | 292 | {
|
271 | 293 | "cell_type": "code",
|
272 | 294 | "execution_count": 2,
|
273 |
| - "id": "governmental-abraham", |
| 295 | + "id": "sonic-cooper", |
274 | 296 | "metadata": {},
|
275 | 297 | "outputs": [
|
| 298 | + { |
| 299 | + "name": "stderr", |
| 300 | + "output_type": "stream", |
| 301 | + "text": [ |
| 302 | + "Adding webhooks listener failed! TypeError(\"unhashable type: 'DataOwner'\") occurred.\n", |
| 303 | + "Adding webhooks listener failed! TypeError(\"unhashable type: 'DataOwner'\") occurred.\n" |
| 304 | + ] |
| 305 | + }, |
276 | 306 | {
|
277 | 307 | "name": "stdout",
|
278 | 308 | "output_type": "stream",
|
279 | 309 | "text": [
|
280 | 310 | "Register Listeners\n",
|
281 |
| - "[{'topic': 'connections', 'handler': <bound method DataOwner._connections_handler of <__main__.DataOwner object at 0x7f8f90579dd0>>}, {'topic': 'present_proof', 'handler': <bound method DataOwner._proof_handler of <__main__.DataOwner object at 0x7f8f90579dd0>>}]\n" |
| 311 | + "[{'topic': 'connections', 'handler': <bound method DataOwner._connections_handler of DataOwner(admin_url='http://dataowner-agent:8051', api_key=None, is_multitenant=False, webhook_host='0.0.0.0', webhook_port=8052, webhook_base='')>}, {'topic': 'present_proof', 'handler': <bound method DataOwner._proof_handler of DataOwner(admin_url='http://dataowner-agent:8051', api_key=None, is_multitenant=False, webhook_host='0.0.0.0', webhook_port=8052, webhook_base='')>}]\n", |
| 312 | + "Subscribing too: connections\n", |
| 313 | + "Subscribing too: present_proof\n" |
282 | 314 | ]
|
283 | 315 | }
|
284 | 316 | ],
|
|
288 | 320 | "WEBHOOK_BASE = \"\"\n",
|
289 | 321 | "ADMIN_URL = \"http://dataowner-agent:8051\"\n",
|
290 | 322 | "\n",
|
291 |
| - "data_owner = DataOwner(WEBHOOK_HOST, WEBHOOK_PORT, ADMIN_URL, WEBHOOK_BASE)" |
| 323 | + "data_owner = DataOwner(webhook_host=WEBHOOK_HOST, webhook_port=WEBHOOK_PORT, admin_url=ADMIN_URL, webhook_base=WEBHOOK_BASE)\n" |
292 | 324 | ]
|
293 | 325 | },
|
294 | 326 | {
|
295 | 327 | "cell_type": "markdown",
|
296 |
| - "id": "beautiful-market", |
| 328 | + "id": "theoretical-briefing", |
297 | 329 | "metadata": {},
|
298 | 330 | "source": [
|
299 | 331 | "## 3 Set Authentication Policy\n",
|
|
305 | 337 | },
|
306 | 338 | {
|
307 | 339 | "cell_type": "code",
|
308 |
| - "execution_count": 3, |
309 |
| - "id": "swiss-throat", |
| 340 | + "execution_count": null, |
| 341 | + "id": "running-retention", |
310 | 342 | "metadata": {},
|
311 |
| - "outputs": [ |
312 |
| - { |
313 |
| - "name": "stdout", |
314 |
| - "output_type": "stream", |
315 |
| - "text": [ |
316 |
| - "{'name': 'Proof of Scientist', 'version': '1.0', 'requested_attributes': {'0_scope_uuid': {'name': 'scope', 'restrictions': [{'schema_id': 'Sgg1wREgfEwbEPCQn9xEuE:2:OM Data Scientist:0.0.1'}]}}, 'requested_predicates': {}}\n" |
317 |
| - ] |
318 |
| - } |
319 |
| - ], |
| 343 | + "outputs": [], |
320 | 344 | "source": [
|
321 | 345 | "# We add a constraint that the attribute must originate from this schema\n",
|
322 | 346 | "schema_id = \"Sgg1wREgfEwbEPCQn9xEuE:2:OM Data Scientist:0.0.1\"\n",
|
|
359 | 383 | },
|
360 | 384 | {
|
361 | 385 | "cell_type": "code",
|
362 |
| - "execution_count": 5, |
363 |
| - "id": "racial-thomas", |
| 386 | + "execution_count": null, |
| 387 | + "id": "middle-reynolds", |
364 | 388 | "metadata": {},
|
365 | 389 | "outputs": [],
|
366 | 390 | "source": [
|
|
371 | 395 | },
|
372 | 396 | {
|
373 | 397 | "cell_type": "markdown",
|
374 |
| - "id": "annoying-class", |
| 398 | + "id": "representative-transition", |
375 | 399 | "metadata": {},
|
376 | 400 | "source": [
|
377 | 401 | "## 4. Create Data Scientist Invite\n",
|
|
385 | 409 | },
|
386 | 410 | {
|
387 | 411 | "cell_type": "code",
|
388 |
| - "execution_count": 6, |
389 |
| - "id": "professional-receptor", |
| 412 | + "execution_count": null, |
| 413 | + "id": "economic-mixer", |
390 | 414 | "metadata": {},
|
391 |
| - "outputs": [ |
392 |
| - { |
393 |
| - "name": "stdout", |
394 |
| - "output_type": "stream", |
395 |
| - "text": [ |
396 |
| - "Connection Handler Called\n", |
397 |
| - "Connection fb7528b8-cee2-4938-ab1f-282c86fc05ce in State invitation\n", |
398 |
| - "\n", |
399 |
| - "♫♫♫ > STEP 1: Copy the aries invitation to the data scientist notebook 7.\n", |
400 |
| - "\n", |
401 |
| - "{\"@type\": \"did:sov:BzCbsNYhMrjHiqZDTUASHg;spec/connections/1.0/invitation\", \"@id\": \"bd5a48d8-11be-4e17-a880-74e4cea6a45a\", \"serviceEndpoint\": \"https://e695090e077b.ngrok.io\", \"recipientKeys\": [\"Agp992DQggeQLb17a7LPCn4w64WevuTDr7mkPtnAvn2c\"], \"label\": \"DATAOWNER\"}\n", |
402 |
| - "\n", |
403 |
| - "Establishing connection\n", |
404 |
| - "Connection Handler Called\n", |
405 |
| - "Connection fb7528b8-cee2-4938-ab1f-282c86fc05ce in State request\n", |
406 |
| - "Connection Handler Called\n", |
407 |
| - "Connection fb7528b8-cee2-4938-ab1f-282c86fc05ce in State response\n", |
408 |
| - "Connection Handler Called\n", |
409 |
| - "Connection fb7528b8-cee2-4938-ab1f-282c86fc05ce in State active\n", |
410 |
| - "Pending connection moved to active.\n", |
411 |
| - "\n", |
412 |
| - "Challenging with Auth Policy\n", |
413 |
| - "\n", |
414 |
| - "{'name': 'Proof of Scientist', 'version': '1.0', 'requested_attributes': {'0_scope_uuid': {'name': 'scope', 'restrictions': [{'schema_id': 'Sgg1wREgfEwbEPCQn9xEuE:2:OM Data Scientist:0.0.1'}]}}, 'requested_predicates': {}}\n", |
415 |
| - "\n", |
416 |
| - "---------------------------------------------------------------------\n", |
417 |
| - "\n", |
418 |
| - "Handle present-proof\n", |
419 |
| - "Connection ID : fb7528b8-cee2-4938-ab1f-282c86fc05ce\n", |
420 |
| - "Presentation Exchange ID : 9173b392-9e66-44f0-ada0-28a82e42567e\n", |
421 |
| - "Protocol State : request_sent\n", |
422 |
| - "Agent Role : verifier\n", |
423 |
| - "\n", |
424 |
| - "---------------------------------------------------------------------\n", |
425 |
| - "\n", |
426 |
| - "Connection is a pending scientist\n", |
427 |
| - "\n", |
428 |
| - "---------------------------------------------------------------------\n", |
429 |
| - "\n", |
430 |
| - "Handle present-proof\n", |
431 |
| - "Connection ID : fb7528b8-cee2-4938-ab1f-282c86fc05ce\n", |
432 |
| - "Presentation Exchange ID : 9173b392-9e66-44f0-ada0-28a82e42567e\n", |
433 |
| - "Protocol State : presentation_received\n", |
434 |
| - "Agent Role : verifier\n", |
435 |
| - "\n", |
436 |
| - "---------------------------------------------------------------------\n", |
437 |
| - "\n", |
438 |
| - "Connection is a pending scientist\n", |
439 |
| - "Verifying Presentation from Data Scientist\n", |
440 |
| - "\n", |
441 |
| - "---------------------------------------------------------------------\n", |
442 |
| - "\n", |
443 |
| - "Handle present-proof\n", |
444 |
| - "Connection ID : fb7528b8-cee2-4938-ab1f-282c86fc05ce\n", |
445 |
| - "Presentation Exchange ID : 9173b392-9e66-44f0-ada0-28a82e42567e\n", |
446 |
| - "Protocol State : verified\n", |
447 |
| - "Agent Role : verifier\n", |
448 |
| - "\n", |
449 |
| - "---------------------------------------------------------------------\n", |
450 |
| - "\n", |
451 |
| - "Connection is a pending scientist\n", |
452 |
| - "Trusted Research Connection Established - fb7528b8-cee2-4938-ab1f-282c86fc05ce\n", |
453 |
| - "\n", |
454 |
| - "--------------------------------------------------------------------\n", |
455 |
| - "\n", |
456 |
| - "\n", |
457 |
| - "--------------------------------------------------------------------\n", |
458 |
| - "\n", |
459 |
| - "\n", |
460 |
| - "\n", |
461 |
| - "\n", |
462 |
| - "\n", |
463 |
| - "---------------------------------------------------------------------\n", |
464 |
| - "\n", |
465 |
| - "Handle present-proof\n", |
466 |
| - "Connection ID : fb7528b8-cee2-4938-ab1f-282c86fc05ce\n", |
467 |
| - "Presentation Exchange ID : cab2088b-1134-426b-8577-e56c014afa90\n", |
468 |
| - "Protocol State : request_received\n", |
469 |
| - "Agent Role : prover\n", |
470 |
| - "\n", |
471 |
| - "---------------------------------------------------------------------\n", |
472 |
| - "\n", |
473 |
| - "Connection is a trusted scientist\n", |
474 |
| - "Received Authentication Challenge from Scientist\n", |
475 |
| - "Credentials stored that could be used to satisfy the request. In some situations you applications may have a choice which credential to reveal\n", |
476 |
| - "\n", |
477 |
| - "[{'cred_info': {'referent': '43080c1b-cabd-45ef-8cf4-4b1ff228d781', 'attrs': {'name': 'Will', 'domain': 'Health'}, 'schema_id': 'Sgg1wREgfEwbEPCQn9xEuE:2:OM Data Owner:0.0.1', 'cred_def_id': 'vrzjfm1MEN1g5o6QtHLfv:3:CL:188835:default', 'rev_reg_id': None, 'cred_rev_id': None}, 'interval': None, 'presentation_referents': ['0_domain_uuid', '0_name_uuid']}]\n", |
478 |
| - "\n", |
479 |
| - "Credential to reveal\n", |
480 |
| - " {'cred_info': {'referent': '43080c1b-cabd-45ef-8cf4-4b1ff228d781', 'attrs': {'name': 'Will', 'domain': 'Health'}, 'schema_id': 'Sgg1wREgfEwbEPCQn9xEuE:2:OM Data Owner:0.0.1', 'cred_def_id': 'vrzjfm1MEN1g5o6QtHLfv:3:CL:188835:default', 'rev_reg_id': None, 'cred_rev_id': None}, 'interval': None, 'presentation_referents': ['0_domain_uuid', '0_name_uuid']}\n", |
481 |
| - "\n", |
482 |
| - "Generate the proof\n", |
483 |
| - "{'requested_predicates': {}, 'requested_attributes': {'0_domain_uuid': {'cred_id': '43080c1b-cabd-45ef-8cf4-4b1ff228d781', 'revealed': True}, '0_name_uuid': {'cred_id': '43080c1b-cabd-45ef-8cf4-4b1ff228d781', 'revealed': True}}, 'self_attested_attributes': {}}\n", |
484 |
| - "\n", |
485 |
| - "XXX\n", |
486 |
| - "{}\n", |
487 |
| - "{'0_domain_uuid': {'cred_id': '43080c1b-cabd-45ef-8cf4-4b1ff228d781', 'revealed': True}, '0_name_uuid': {'cred_id': '43080c1b-cabd-45ef-8cf4-4b1ff228d781', 'revealed': True}}\n", |
488 |
| - "{}\n", |
489 |
| - "\n", |
490 |
| - "---------------------------------------------------------------------\n", |
491 |
| - "\n", |
492 |
| - "Handle present-proof\n", |
493 |
| - "Connection ID : fb7528b8-cee2-4938-ab1f-282c86fc05ce\n", |
494 |
| - "Presentation Exchange ID : cab2088b-1134-426b-8577-e56c014afa90\n", |
495 |
| - "Protocol State : presentation_sent\n", |
496 |
| - "Agent Role : prover\n", |
497 |
| - "\n", |
498 |
| - "---------------------------------------------------------------------\n", |
499 |
| - "\n", |
500 |
| - "Connection is a trusted scientist\n", |
501 |
| - "\n", |
502 |
| - "---------------------------------------------------------------------\n", |
503 |
| - "\n", |
504 |
| - "Handle present-proof\n", |
505 |
| - "Connection ID : fb7528b8-cee2-4938-ab1f-282c86fc05ce\n", |
506 |
| - "Presentation Exchange ID : cab2088b-1134-426b-8577-e56c014afa90\n", |
507 |
| - "Protocol State : presentation_sent\n", |
508 |
| - "Agent Role : prover\n", |
509 |
| - "\n", |
510 |
| - "---------------------------------------------------------------------\n", |
511 |
| - "\n", |
512 |
| - "Connection is a trusted scientist\n" |
513 |
| - ] |
514 |
| - } |
515 |
| - ], |
| 415 | + "outputs": [], |
516 | 416 | "source": [
|
517 | 417 | "data_owner.create_scientist_invite()"
|
518 | 418 | ]
|
519 | 419 | },
|
520 | 420 | {
|
521 | 421 | "cell_type": "markdown",
|
522 |
| - "id": "better-exercise", |
| 422 | + "id": "straight-brunswick", |
523 | 423 | "metadata": {},
|
524 | 424 | "source": [
|
525 | 425 | "## Continue with Data Scientist\n",
|
|
529 | 429 | },
|
530 | 430 | {
|
531 | 431 | "cell_type": "markdown",
|
532 |
| - "id": "derived-pioneer", |
| 432 | + "id": "breathing-access", |
533 | 433 | "metadata": {},
|
534 | 434 | "source": [
|
535 | 435 | "## End of Notebook\n",
|
|
539 | 439 | },
|
540 | 440 | {
|
541 | 441 | "cell_type": "code",
|
542 |
| - "execution_count": 7, |
543 |
| - "id": "complicated-nicaragua", |
| 442 | + "execution_count": null, |
| 443 | + "id": "threaded-triumph", |
544 | 444 | "metadata": {},
|
545 | 445 | "outputs": [],
|
546 | 446 | "source": [
|
|
549 | 449 | },
|
550 | 450 | {
|
551 | 451 | "cell_type": "markdown",
|
552 |
| - "id": "designing-baseline", |
| 452 | + "id": "genuine-bidder", |
553 | 453 | "metadata": {},
|
554 | 454 | "source": [
|
555 | 455 | "# Congratulations!!!!\n",
|
|
0 commit comments