Skip to content

Commit 5c45b6b

Browse files
authored
Fix issues with anoncreds upgrade (#3991)
* Fix issues with anoncreds upgrade Signed-off-by: jamshale <jamiehalebc@gmail.com> * Add additional test coverage for revocation after upgrade Signed-off-by: jamshale <jamiehalebc@gmail.com> --------- Signed-off-by: jamshale <jamiehalebc@gmail.com>
1 parent d752721 commit 5c45b6b

2 files changed

Lines changed: 124 additions & 110 deletions

File tree

acapy_agent/wallet/anoncreds_upgrade.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ async def get_rev_reg_def_upgrade_object(
253253
)
254254

255255
rev_reg_def = RevRegDef(
256-
issuer_id=askar_issuer_rev_reg_def.tags.get("issuer_did"),
256+
issuer_id=cred_def_upgrade_obj.cred_def.issuer_id,
257257
cred_def_id=cred_def_upgrade_obj.cred_def_id,
258258
tag=revoc_reg_def_values["tag"],
259259
type=revoc_reg_def_values["revoc_def_type"],
@@ -404,7 +404,6 @@ async def upgrade_and_delete_rev_entry_records(
404404
for cred_rev_record in rev_list_upgrade_obj.cred_rev_records:
405405
if int(cred_rev_record.tags.get("cred_rev_id")) > next_index:
406406
next_index = int(cred_rev_record.tags.get("cred_rev_id"))
407-
await txn.handle.remove(IssuerCredRevRecord.RECORD_TYPE, cred_rev_record.id)
408407

409408
await txn.handle.insert(
410409
CATEGORY_REV_LIST,

scenarios/examples/restart_anoncreds_upgrade/example.py

Lines changed: 123 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ async def connect_agents_and_issue_credentials(
110110
)
111111
print(">>> Done!")
112112

113-
return (inviter_conn, invitee_conn)
113+
return (inviter_conn, invitee_conn, inviter_cred_ex)
114114

115115

116116
async def verify_schema_cred_def(issuer, schema_count, cred_def_count):
@@ -219,7 +219,7 @@ async def upgrade_wallet_and_shutdown_container(
219219
agent_command = agent_container.attrs["Config"]["Cmd"]
220220

221221
# command is a List, find the wallet type and replace "askar" with "askar-anoncreds"
222-
correct_wallet_type = update_wallet_type(agent_command, "askar-anoncreds")
222+
update_wallet_type(agent_command, "askar-anoncreds")
223223
wallet_name = get_wallet_name(agent_command)
224224

225225
# call the wallet upgrade endpoint to upgrade to askar-anoncreds
@@ -299,7 +299,7 @@ async def main():
299299
Controller(base_url=BOB_ASKAR) as bob,
300300
):
301301
# connect to Bob (Askar wallet) and issue (and revoke) some credentials
302-
(alice_conn, bob_conn) = await connect_agents_and_issue_credentials(
302+
(alice_conn, bob_conn, _) = await connect_agents_and_issue_credentials(
303303
alice,
304304
bob,
305305
cred_def,
@@ -315,7 +315,7 @@ async def main():
315315
Controller(base_url=BOB_ANONCREDS) as bob,
316316
):
317317
# connect to Bob (AnonCreds wallet) and issue (and revoke) some credentials
318-
(alice_conn, bob_conn) = await connect_agents_and_issue_credentials(
318+
(alice_conn, bob_conn, _) = await connect_agents_and_issue_credentials(
319319
alice,
320320
bob,
321321
cred_def,
@@ -331,7 +331,11 @@ async def main():
331331
Controller(base_url=BOB_ASKAR_ANON) as bob,
332332
):
333333
# connect to Bob (Askar wallet which will be upgraded) and issue (and revoke) some credentials
334-
(alice_conn, bob_conn) = await connect_agents_and_issue_credentials(
334+
(
335+
alice_conn,
336+
bob_conn,
337+
pre_upgraded_cred_ex,
338+
) = await connect_agents_and_issue_credentials(
335339
alice,
336340
bob,
337341
cred_def,
@@ -386,113 +390,124 @@ async def main():
386390
alice_id = None
387391
new_bob_container = None
388392
bob_id = None
389-
try:
390-
(new_alice_container, alice_id) = start_new_container(
391-
client,
392-
alice_command,
393-
alice_container,
394-
"alice",
393+
394+
(new_alice_container, alice_id) = start_new_container(
395+
client,
396+
alice_command,
397+
alice_container,
398+
"alice",
399+
)
400+
401+
(new_bob_container, bob_id) = start_new_container(
402+
client,
403+
bob_command,
404+
bob_container,
405+
"bob-askar-anon",
406+
)
407+
408+
# TODO verify counts of credentials, revocations etc for each upgraded agent
409+
async with (
410+
Controller(base_url=ALICE) as alice,
411+
Controller(base_url=BOB_ASKAR_ANON) as bob,
412+
):
413+
await verify_schema_cred_def(alice, 1, 1)
414+
415+
# run some more tests ... alice should still be connected to bob for example ...
416+
async with (
417+
Controller(base_url=ALICE) as alice,
418+
Controller(base_url=BOB_ANONCREDS) as bob,
419+
):
420+
# Present the the credential's attributes
421+
print(">>> present proof ... again ...")
422+
await anoncreds_present_proof_v2(
423+
bob,
424+
alice,
425+
bob_conns["anoncreds"].connection_id,
426+
alice_conns["anoncreds"].connection_id,
427+
requested_attributes=[{"name": "firstname"}],
395428
)
429+
await connect_agents_and_issue_credentials(
430+
alice,
431+
bob,
432+
cred_def,
433+
"Bob",
434+
"AnonCreds",
435+
inviter_conn=alice_conns["anoncreds"],
436+
invitee_conn=bob_conns["anoncreds"],
437+
)
438+
await verify_recd_credentials(bob, 2, 2)
439+
print(">>> Done! (again)")
396440

397-
(new_bob_container, bob_id) = start_new_container(
398-
client,
399-
bob_command,
400-
bob_container,
401-
"bob-askar-anon",
441+
async with (
442+
Controller(base_url=ALICE) as alice,
443+
Controller(base_url=BOB_ASKAR_ANON) as bob,
444+
):
445+
# Present the the credential's attributes
446+
print(">>> present proof ... again ...")
447+
await anoncreds_present_proof_v2(
448+
bob,
449+
alice,
450+
bob_conns["askar-anon"].connection_id,
451+
alice_conns["askar-anon"].connection_id,
452+
requested_attributes=[{"name": "firstname"}],
453+
)
454+
await connect_agents_and_issue_credentials(
455+
alice,
456+
bob,
457+
cred_def,
458+
"Bob",
459+
"Askar_Anon",
460+
inviter_conn=alice_conns["askar-anon"],
461+
invitee_conn=bob_conns["askar-anon"],
462+
)
463+
await verify_recd_credentials(bob, 2, 2)
464+
print(">>> Done! (again)")
465+
466+
async with (
467+
Controller(base_url=ALICE) as alice,
468+
Controller(base_url=BOB_ASKAR) as bob,
469+
):
470+
# Present the the credential's attributes
471+
print(">>> present proof ... again ...")
472+
await anoncreds_present_proof_v2(
473+
bob,
474+
alice,
475+
bob_conns["askar"].connection_id,
476+
alice_conns["askar"].connection_id,
477+
requested_attributes=[{"name": "firstname"}],
478+
)
479+
await connect_agents_and_issue_credentials(
480+
alice,
481+
bob,
482+
cred_def,
483+
"Bob",
484+
"Askar",
485+
inviter_conn=alice_conns["askar"],
486+
invitee_conn=bob_conns["askar"],
487+
)
488+
await verify_recd_credentials(bob, 2, 2)
489+
await verify_issued_credentials(alice, 12, 6)
490+
await verify_recd_presentations(alice, 9)
491+
print(">>> Done! (again)")
492+
493+
# Revoke one more credential to test revocation post-upgrade
494+
print(
495+
">>> revoke one more credential created before the upgrade and with cred_ex_id..."
496+
)
497+
await alice.post(
498+
url="/anoncreds/revocation/revoke",
499+
json={
500+
"connection_id": alice_conns["askar"].connection_id,
501+
"cred_ex_id": pre_upgraded_cred_ex.details.cred_ex_id,
502+
"publish": True,
503+
"notify": True,
504+
"notify_version": "v1_0",
505+
},
402506
)
403507

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-
411-
# run some more tests ... alice should still be connected to bob for example ...
412-
async with (
413-
Controller(base_url=ALICE) as alice,
414-
Controller(base_url=BOB_ANONCREDS) as bob,
415-
):
416-
# Present the the credential's attributes
417-
print(">>> present proof ... again ...")
418-
await anoncreds_present_proof_v2(
419-
bob,
420-
alice,
421-
bob_conns["anoncreds"].connection_id,
422-
alice_conns["anoncreds"].connection_id,
423-
requested_attributes=[{"name": "firstname"}],
424-
)
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)
435-
print(">>> Done! (again)")
436-
437-
async with (
438-
Controller(base_url=ALICE) as alice,
439-
Controller(base_url=BOB_ASKAR_ANON) as bob,
440-
):
441-
# Present the the credential's attributes
442-
print(">>> present proof ... again ...")
443-
await anoncreds_present_proof_v2(
444-
bob,
445-
alice,
446-
bob_conns["askar-anon"].connection_id,
447-
alice_conns["askar-anon"].connection_id,
448-
requested_attributes=[{"name": "firstname"}],
449-
)
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)
460-
print(">>> Done! (again)")
461-
462-
async with (
463-
Controller(base_url=ALICE) as alice,
464-
Controller(base_url=BOB_ASKAR) as bob,
465-
):
466-
# Present the the credential's attributes
467-
print(">>> present proof ... again ...")
468-
await anoncreds_present_proof_v2(
469-
bob,
470-
alice,
471-
bob_conns["askar"].connection_id,
472-
alice_conns["askar"].connection_id,
473-
requested_attributes=[{"name": "firstname"}],
474-
)
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)
487-
print(">>> Done! (again)")
488-
489-
finally:
490-
if alice_id and new_alice_container:
491-
# cleanup - shut down alice agent (not part of docker compose)
492-
stop_and_remove_container(client, alice_id)
493-
if bob_id and new_bob_container:
494-
# cleanup - shut down bob agent (not part of docker compose)
495-
stop_and_remove_container(client, bob_id)
508+
# cleanup - shut down alice agent (not part of docker compose)
509+
stop_and_remove_container(client, alice_id)
510+
stop_and_remove_container(client, bob_id)
496511

497512

498513
if __name__ == "__main__":

0 commit comments

Comments
 (0)