1515 indy_anoncred_onboard ,
1616)
1717from examples .util import (
18+ Settings ,
1819 anoncreds_issue_credential_v2 ,
1920 anoncreds_present_proof_v2 ,
2021 get_wallet_name ,
@@ -36,10 +37,17 @@ async def connect_agents_and_issue_credentials(
3637 inviter_cred_def ,
3738 fname : str ,
3839 lname : str ,
40+ inviter_conn = None ,
41+ invitee_conn = None ,
3942):
43+ is_inviter_anoncreds = (await inviter .get ("/settings" , response = Settings )).get (
44+ "wallet.type"
45+ ) == "askar-anoncreds"
46+
4047 # connect the 2 agents
41- print (">>> connecting agents ..." )
42- (inviter_conn , invitee_conn ) = await didexchange (inviter , invitee )
48+ if (not inviter_conn ) or (not invitee_conn ):
49+ print (">>> connecting agents ..." )
50+ (inviter_conn , invitee_conn ) = await didexchange (inviter , invitee )
4351
4452 # Issue a credential
4553 print (">>> issue credential ..." )
@@ -51,7 +59,6 @@ async def connect_agents_and_issue_credentials(
5159 inviter_cred_def .credential_definition_id ,
5260 {"firstname" : fname , "lastname" : lname },
5361 )
54- print (">>> cred_ex:" , inviter_cred_ex )
5562
5663 # Present the the credential's attributes
5764 print (">>> present proof ..." )
@@ -64,18 +71,32 @@ async def connect_agents_and_issue_credentials(
6471 )
6572
6673 # Revoke credential
67- await inviter .post (
68- url = "/revocation/revoke" ,
69- json = {
70- "connection_id" : inviter_conn .connection_id ,
71- "rev_reg_id" : inviter_cred_ex .details .rev_reg_id ,
72- "cred_rev_id" : inviter_cred_ex .details .cred_rev_id ,
73- "publish" : True ,
74- "notify" : True ,
75- "notify_version" : "v1_0" ,
76- },
77- )
78- await invitee .record (topic = "revocation-notification" )
74+ if is_inviter_anoncreds :
75+ await inviter .post (
76+ url = "/anoncreds/revocation/revoke" , # TODO need to check agent type (askar vs anoncreds)
77+ json = {
78+ "connection_id" : inviter_conn .connection_id ,
79+ "rev_reg_id" : inviter_cred_ex .details .rev_reg_id ,
80+ "cred_rev_id" : inviter_cred_ex .details .cred_rev_id ,
81+ "publish" : True ,
82+ "notify" : True ,
83+ "notify_version" : "v1_0" ,
84+ },
85+ )
86+ await invitee .record (topic = "revocation-notification" )
87+ else :
88+ await inviter .post (
89+ url = "/revocation/revoke" , # TODO need to check agent type (askar vs anoncreds)
90+ json = {
91+ "connection_id" : inviter_conn .connection_id ,
92+ "rev_reg_id" : inviter_cred_ex .details .rev_reg_id ,
93+ "cred_rev_id" : inviter_cred_ex .details .cred_rev_id ,
94+ "publish" : True ,
95+ "notify" : True ,
96+ "notify_version" : "v1_0" ,
97+ },
98+ )
99+ await invitee .record (topic = "revocation-notification" )
79100
80101 # Issue a second credential
81102 print (">>> issue credential ..." )
@@ -85,13 +106,111 @@ async def connect_agents_and_issue_credentials(
85106 inviter_conn .connection_id ,
86107 invitee_conn .connection_id ,
87108 inviter_cred_def .credential_definition_id ,
88- {"firstname" : "{fname}2" , "lastname" : "{lname}2" },
109+ {"firstname" : f "{ fname } 2" , "lastname" : f "{ lname } 2" },
89110 )
90111 print (">>> Done!" )
91112
92113 return (inviter_conn , invitee_conn )
93114
94115
116+ async def verify_schema_cred_def (issuer , schema_count , cred_def_count ):
117+ is_issuer_anoncreds = (await issuer .get ("/settings" , response = Settings )).get (
118+ "wallet.type"
119+ ) == "askar-anoncreds"
120+
121+ if is_issuer_anoncreds :
122+ schemas = await issuer .get ("/anoncreds/schemas" )
123+ assert schema_count == len (schemas ["schema_ids" ])
124+
125+ cred_defs = await issuer .get ("/anoncreds/credential-definitions" )
126+ assert cred_def_count == len (cred_defs ["credential_definition_ids" ])
127+ else :
128+ schemas = await issuer .get ("/schemas/created" )
129+ assert schema_count == len (schemas ["schema_ids" ])
130+
131+ cred_defs = await issuer .get ("/credential-definitions/created" )
132+ assert cred_def_count == len (cred_defs ["credential_definition_ids" ])
133+
134+
135+ async def verify_issued_credentials (issuer , issued_cred_count , revoked_cred_count ):
136+ is_issuer_anoncreds = (await issuer .get ("/settings" , response = Settings )).get (
137+ "wallet.type"
138+ ) == "askar-anoncreds"
139+
140+ cred_exch_recs = await issuer .get ("/issue-credential-2.0/records" )
141+ cred_exch_recs = cred_exch_recs ["results" ]
142+ assert len (cred_exch_recs ) == issued_cred_count
143+ registries = {}
144+ active_creds = 0
145+ revoked_creds = 0
146+ for cred_exch in cred_exch_recs :
147+ cred_type = (
148+ "indy"
149+ if "indy" in cred_exch
150+ and cred_exch ["indy" ]
151+ and "rev_reg_id" in cred_exch ["indy" ]
152+ else "anoncreds"
153+ )
154+ rev_reg_id = cred_exch [cred_type ]["rev_reg_id" ]
155+ cred_rev_id = cred_exch [cred_type ]["cred_rev_id" ]
156+ cred_rev_id = int (cred_rev_id )
157+ if not rev_reg_id in registries :
158+ if is_issuer_anoncreds :
159+ registries [rev_reg_id ] = await issuer .get (
160+ f"/anoncreds/revocation/registry/{ rev_reg_id } /issued/indy_recs" ,
161+ )
162+ else :
163+ registries [rev_reg_id ] = await issuer .get (
164+ f"/revocation/registry/{ rev_reg_id } /issued/indy_recs" ,
165+ )
166+ registry = registries [rev_reg_id ]
167+ if cred_rev_id in registry ["rev_reg_delta" ]["value" ]["revoked" ]:
168+ revoked_creds = revoked_creds + 1
169+ else :
170+ active_creds = active_creds + 1
171+ assert revoked_creds == revoked_cred_count
172+ assert (revoked_creds + active_creds ) == issued_cred_count
173+
174+
175+ async def verify_recd_credentials (holder , active_cred_count , revoked_cred_count ):
176+ is_holder_anoncreds = (await holder .get ("/settings" , response = Settings )).get (
177+ "wallet.type"
178+ ) == "askar-anoncreds"
179+
180+ credentials = await holder .get (f"/credentials" )
181+ credentials = credentials ["results" ]
182+ assert len (credentials ) == (active_cred_count + revoked_cred_count )
183+ registries = {}
184+ active_creds = 0
185+ revoked_creds = 0
186+ for credential in credentials :
187+ rev_reg_id = credential ["rev_reg_id" ]
188+ cred_rev_id = int (credential ["cred_rev_id" ])
189+ if not rev_reg_id in registries :
190+ if is_holder_anoncreds :
191+ registries [rev_reg_id ] = await holder .get (
192+ f"/anoncreds/revocation/registry/{ rev_reg_id } /issued/indy_recs" ,
193+ )
194+ else :
195+ registries [rev_reg_id ] = await holder .get (
196+ f"/revocation/registry/{ rev_reg_id } /issued/indy_recs" ,
197+ )
198+ registry = registries [rev_reg_id ]
199+ if cred_rev_id in registry ["rev_reg_delta" ]["value" ]["revoked" ]:
200+ revoked_creds = revoked_creds + 1
201+ else :
202+ active_creds = active_creds + 1
203+ assert revoked_creds == revoked_cred_count
204+ assert active_creds == active_cred_count
205+
206+
207+ async def verify_recd_presentations (verifier , recd_pres_count ):
208+ presentations = await verifier .get (f"/present-proof-2.0/records" )
209+ presentations = presentations ["results" ]
210+
211+ assert recd_pres_count == len (presentations )
212+
213+
95214async def upgrade_wallet_and_shutdown_container (
96215 client ,
97216 agent_controller ,
@@ -170,9 +289,15 @@ async def main():
170289 revocation_registry_size = 5 ,
171290 )
172291
292+ # confirm alice has 1 schema and 1 cred def
293+ await verify_schema_cred_def (alice , 1 , 1 )
294+
173295 alice_conns = {}
174296 bob_conns = {}
175- async with Controller (base_url = ALICE ) as alice , Controller (base_url = BOB_ASKAR ) as bob :
297+ async with (
298+ Controller (base_url = ALICE ) as alice ,
299+ Controller (base_url = BOB_ASKAR ) as bob ,
300+ ):
176301 # connect to Bob (Askar wallet) and issue (and revoke) some credentials
177302 (alice_conn , bob_conn ) = await connect_agents_and_issue_credentials (
178303 alice ,
@@ -183,6 +308,7 @@ async def main():
183308 )
184309 alice_conns ["askar" ] = alice_conn
185310 bob_conns ["askar" ] = bob_conn
311+ await verify_recd_credentials (bob , 1 , 1 )
186312
187313 async with (
188314 Controller (base_url = ALICE ) as alice ,
@@ -198,6 +324,7 @@ async def main():
198324 )
199325 alice_conns ["anoncreds" ] = alice_conn
200326 bob_conns ["anoncreds" ] = bob_conn
327+ await verify_recd_credentials (bob , 1 , 1 )
201328
202329 async with (
203330 Controller (base_url = ALICE ) as alice ,
@@ -213,8 +340,12 @@ async def main():
213340 )
214341 alice_conns ["askar-anon" ] = alice_conn
215342 bob_conns ["askar-anon" ] = bob_conn
343+ await verify_recd_credentials (bob , 1 , 1 )
344+ await verify_issued_credentials (alice , 6 , 3 )
345+ await verify_recd_presentations (alice , 3 )
216346
217347 # at this point alice has issued 6 credentials (revocation registry size is 5) and revoked 3
348+ # TODO verify counts of credentials, revocations etc for each agent
218349
219350 # play with docker - get a list of all our running containers
220351 client = docker .from_env ()
@@ -270,50 +401,89 @@ async def main():
270401 "bob-askar-anon" ,
271402 )
272403
404+ # TODO verify counts of credentials, revocations etc for each upgraded agent
405+ async with (
406+ Controller (base_url = ALICE ) as alice ,
407+ Controller (base_url = BOB_ASKAR_ANON ) as bob ,
408+ ):
409+ await verify_schema_cred_def (alice , 1 , 1 )
410+
273411 # run some more tests ... alice should still be connected to bob for example ...
274412 async with (
275413 Controller (base_url = ALICE ) as alice ,
276- Controller (base_url = BOB_ASKAR ) as bob ,
414+ Controller (base_url = BOB_ANONCREDS ) as bob ,
277415 ):
278416 # Present the the credential's attributes
279417 print (">>> present proof ... again ..." )
280418 await anoncreds_present_proof_v2 (
281419 bob ,
282420 alice ,
283- bob_conns ["askar " ].connection_id ,
284- alice_conns ["askar " ].connection_id ,
421+ bob_conns ["anoncreds " ].connection_id ,
422+ alice_conns ["anoncreds " ].connection_id ,
285423 requested_attributes = [{"name" : "firstname" }],
286424 )
425+ await connect_agents_and_issue_credentials (
426+ alice ,
427+ bob ,
428+ cred_def ,
429+ "Bob" ,
430+ "Anoncreds" ,
431+ inviter_conn = alice_conns ["anoncreds" ],
432+ invitee_conn = bob_conns ["anoncreds" ],
433+ )
434+ await verify_recd_credentials (bob , 2 , 2 )
287435 print (">>> Done! (again)" )
288436
289437 async with (
290438 Controller (base_url = ALICE ) as alice ,
291- Controller (base_url = BOB_ANONCREDS ) as bob ,
439+ Controller (base_url = BOB_ASKAR_ANON ) as bob ,
292440 ):
293441 # Present the the credential's attributes
294442 print (">>> present proof ... again ..." )
295443 await anoncreds_present_proof_v2 (
296444 bob ,
297445 alice ,
298- bob_conns ["anoncreds " ].connection_id ,
299- alice_conns ["anoncreds " ].connection_id ,
446+ bob_conns ["askar-anon " ].connection_id ,
447+ alice_conns ["askar-anon " ].connection_id ,
300448 requested_attributes = [{"name" : "firstname" }],
301449 )
450+ await connect_agents_and_issue_credentials (
451+ alice ,
452+ bob ,
453+ cred_def ,
454+ "Bob" ,
455+ "Askar_Anon" ,
456+ inviter_conn = alice_conns ["askar-anon" ],
457+ invitee_conn = bob_conns ["askar-anon" ],
458+ )
459+ await verify_recd_credentials (bob , 2 , 2 )
302460 print (">>> Done! (again)" )
303461
304462 async with (
305463 Controller (base_url = ALICE ) as alice ,
306- Controller (base_url = BOB_ASKAR_ANON ) as bob ,
464+ Controller (base_url = BOB_ASKAR ) as bob ,
307465 ):
308466 # Present the the credential's attributes
309467 print (">>> present proof ... again ..." )
310468 await anoncreds_present_proof_v2 (
311469 bob ,
312470 alice ,
313- bob_conns ["askar-anon " ].connection_id ,
314- alice_conns ["askar-anon " ].connection_id ,
471+ bob_conns ["askar" ].connection_id ,
472+ alice_conns ["askar" ].connection_id ,
315473 requested_attributes = [{"name" : "firstname" }],
316474 )
475+ await connect_agents_and_issue_credentials (
476+ alice ,
477+ bob ,
478+ cred_def ,
479+ "Bob" ,
480+ "Askar" ,
481+ inviter_conn = alice_conns ["askar" ],
482+ invitee_conn = bob_conns ["askar" ],
483+ )
484+ await verify_recd_credentials (bob , 2 , 2 )
485+ await verify_issued_credentials (alice , 12 , 6 )
486+ await verify_recd_presentations (alice , 9 )
317487 print (">>> Done! (again)" )
318488
319489 finally :
0 commit comments