Skip to content

Commit 694a5cd

Browse files
committed
refactor tutorial 5
1 parent 079e337 commit 694a5cd

12 files changed

+601
-909
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async def listen_webhooks(self):
6262
try:
6363
await self.webhook_server.listen_webhooks()
6464
except AttributeError:
65-
logger.warning("Missing webhook listener.")
65+
logger.warning("Webhook server not initialised.")
6666
except Exception as exc:
6767
logger.warning(
6868
f"Listening webhooks failed! {exc!r} occurred.")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async def _receive_webhook(self, request: ClientRequest):
7272
wallet_id = None
7373
if self.is_multitenant:
7474
wallet_id = request.match_info["wallet_id"]
75-
print("wallet", wallet_id)
75+
logger.info(f"Received webhook from wallet id: {wallet_id}")
7676
try:
7777
payload = await request.json()
7878
await self._handle_webhook(wallet_id, topic, payload)

tutorials/5. OM FoPC Course - Public Key Infrastructures/notebooks/dataowner/6. Onboarding as a Data Owner.ipynb

Lines changed: 78 additions & 62 deletions
Large diffs are not rendered by default.

tutorials/5. OM FoPC Course - Public Key Infrastructures/notebooks/dataowner/7. Establish Authenticated Connection with a Data Scientist.ipynb

Lines changed: 58 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "markdown",
5-
"id": "assumed-cisco",
5+
"id": "transsexual-greeting",
66
"metadata": {},
77
"source": [
88
"# Establish Authenticated Connection's with Data Scientist's\n",
@@ -14,7 +14,7 @@
1414
},
1515
{
1616
"cell_type": "markdown",
17-
"id": "vertical-expert",
17+
"id": "organic-agent",
1818
"metadata": {},
1919
"source": [
2020
"## 1. Create a Data Owner class\n",
@@ -31,7 +31,7 @@
3131
{
3232
"cell_type": "code",
3333
"execution_count": 1,
34-
"id": "metric-fifth",
34+
"id": "increased-daughter",
3535
"metadata": {},
3636
"outputs": [
3737
{
@@ -47,20 +47,41 @@
4747
"import time\n",
4848
"import asyncio\n",
4949
"import json\n",
50+
"from dataclasses import dataclass\n",
5051
"# I think this is because jupyter notebook also runs an event loop\n",
5152
"import nest_asyncio\n",
5253
"nest_asyncio.apply()\n",
5354
"from termcolor import colored,cprint\n",
5455
"\n",
5556
"from aries_basic_controller.aries_controller import AriesAgentController\n",
5657
" \n",
57-
"\n",
58+
"@dataclass(unsafe_hash=True)\n",
5859
"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",
5971
" \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",
6180
" # Call the AriesAgentController constructor\n",
62-
" super().__init__(webhook_host, webhook_port, admin_url, webhook_base)\n",
81+
" super().__post_init__()\n",
6382
" \n",
83+
"\n",
84+
"\n",
6485
" # Keep track of which connections the data owner trusts\n",
6586
" self.trusted_scientist_ids = []\n",
6687
" \n",
@@ -75,9 +96,10 @@
7596
" {\"topic\":\"present_proof\", \"handler\": self._proof_handler}]\n",
7697
" \n",
7798
" # 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",
78101
" loop = asyncio.get_event_loop()\n",
79102
" loop.run_until_complete(self.listen_webhooks())\n",
80-
" \n",
81103
" # Register listeners\n",
82104
" print(\"Register Listeners\")\n",
83105
" print(self.agent_listeners)\n",
@@ -259,7 +281,7 @@
259281
},
260282
{
261283
"cell_type": "markdown",
262-
"id": "aware-indonesian",
284+
"id": "continued-lincoln",
263285
"metadata": {},
264286
"source": [
265287
"## 2. Instantiate the Data Owner\n",
@@ -270,15 +292,25 @@
270292
{
271293
"cell_type": "code",
272294
"execution_count": 2,
273-
"id": "governmental-abraham",
295+
"id": "sonic-cooper",
274296
"metadata": {},
275297
"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+
},
276306
{
277307
"name": "stdout",
278308
"output_type": "stream",
279309
"text": [
280310
"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"
282314
]
283315
}
284316
],
@@ -288,12 +320,12 @@
288320
"WEBHOOK_BASE = \"\"\n",
289321
"ADMIN_URL = \"http://dataowner-agent:8051\"\n",
290322
"\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"
292324
]
293325
},
294326
{
295327
"cell_type": "markdown",
296-
"id": "beautiful-market",
328+
"id": "theoretical-briefing",
297329
"metadata": {},
298330
"source": [
299331
"## 3 Set Authentication Policy\n",
@@ -305,18 +337,10 @@
305337
},
306338
{
307339
"cell_type": "code",
308-
"execution_count": 3,
309-
"id": "swiss-throat",
340+
"execution_count": null,
341+
"id": "running-retention",
310342
"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": [],
320344
"source": [
321345
"# We add a constraint that the attribute must originate from this schema\n",
322346
"schema_id = \"Sgg1wREgfEwbEPCQn9xEuE:2:OM Data Scientist:0.0.1\"\n",
@@ -359,8 +383,8 @@
359383
},
360384
{
361385
"cell_type": "code",
362-
"execution_count": 5,
363-
"id": "racial-thomas",
386+
"execution_count": null,
387+
"id": "middle-reynolds",
364388
"metadata": {},
365389
"outputs": [],
366390
"source": [
@@ -371,7 +395,7 @@
371395
},
372396
{
373397
"cell_type": "markdown",
374-
"id": "annoying-class",
398+
"id": "representative-transition",
375399
"metadata": {},
376400
"source": [
377401
"## 4. Create Data Scientist Invite\n",
@@ -385,141 +409,17 @@
385409
},
386410
{
387411
"cell_type": "code",
388-
"execution_count": 6,
389-
"id": "professional-receptor",
412+
"execution_count": null,
413+
"id": "economic-mixer",
390414
"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": [],
516416
"source": [
517417
"data_owner.create_scientist_invite()"
518418
]
519419
},
520420
{
521421
"cell_type": "markdown",
522-
"id": "better-exercise",
422+
"id": "straight-brunswick",
523423
"metadata": {},
524424
"source": [
525425
"## Continue with Data Scientist\n",
@@ -529,7 +429,7 @@
529429
},
530430
{
531431
"cell_type": "markdown",
532-
"id": "derived-pioneer",
432+
"id": "breathing-access",
533433
"metadata": {},
534434
"source": [
535435
"## End of Notebook\n",
@@ -539,8 +439,8 @@
539439
},
540440
{
541441
"cell_type": "code",
542-
"execution_count": 7,
543-
"id": "complicated-nicaragua",
442+
"execution_count": null,
443+
"id": "threaded-triumph",
544444
"metadata": {},
545445
"outputs": [],
546446
"source": [
@@ -549,7 +449,7 @@
549449
},
550450
{
551451
"cell_type": "markdown",
552-
"id": "designing-baseline",
452+
"id": "genuine-bidder",
553453
"metadata": {},
554454
"source": [
555455
"# Congratulations!!!!\n",

0 commit comments

Comments
 (0)