Skip to content

Commit

Permalink
Logic fix plus some reformatting
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Costanzo <[email protected]>
  • Loading branch information
ianco committed Jan 8, 2025
1 parent 9348b97 commit ead669e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
27 changes: 19 additions & 8 deletions scenarios/examples/restart_anoncreds_upgrade/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ async def connect_agents_and_issue_credentials(
inviter_cred_def,
fname: str,
lname: str,
inviter_conn = None,
invitee_conn = None,
inviter_conn=None,
invitee_conn=None,
):
is_inviter_anoncreds = (await inviter.get("/settings", response=Settings)).get(
"wallet.type"
Expand Down Expand Up @@ -73,7 +73,7 @@ async def connect_agents_and_issue_credentials(
# Revoke credential
if is_inviter_anoncreds:
await inviter.post(
url="/anoncreds/revocation/revoke", # TODO need to check agent type (askar vs anoncreds)
url="/anoncreds/revocation/revoke", # TODO need to check agent type (askar vs anoncreds)
json={
"connection_id": inviter_conn.connection_id,
"rev_reg_id": inviter_cred_ex.details.rev_reg_id,
Expand All @@ -86,7 +86,7 @@ async def connect_agents_and_issue_credentials(
await invitee.record(topic="revocation-notification")
else:
await inviter.post(
url="/revocation/revoke", # TODO need to check agent type (askar vs anoncreds)
url="/revocation/revoke", # TODO need to check agent type (askar vs anoncreds)
json={
"connection_id": inviter_conn.connection_id,
"rev_reg_id": inviter_cred_ex.details.rev_reg_id,
Expand Down Expand Up @@ -144,8 +144,16 @@ async def verify_issued_credentials(issuer, issued_cred_count, revoked_cred_coun
active_creds = 0
revoked_creds = 0
for cred_exch in cred_exch_recs:
rev_reg_id = cred_exch["indy"]["rev_reg_id"] if "indy" in cred_exch else cred_exch["anoncreds"]["rev_reg_id"]
cred_rev_id = int(cred_exch["indy"]["cred_rev_id"])
cred_type = (
"indy"
if "indy" in cred_exch
and cred_exch["indy"]
and "rev_reg_id" in cred_exch["indy"]
else "anoncreds"
)
rev_reg_id = cred_exch[cred_type]["rev_reg_id"]
cred_rev_id = cred_exch[cred_type]["cred_rev_id"]
cred_rev_id = int(cred_rev_id)
if not rev_reg_id in registries:
if is_issuer_anoncreds:
registries[rev_reg_id] = await issuer.get(
Expand Down Expand Up @@ -286,7 +294,10 @@ async def main():

alice_conns = {}
bob_conns = {}
async with Controller(base_url=ALICE) as alice, Controller(base_url=BOB_ASKAR) as bob:
async with (
Controller(base_url=ALICE) as alice,
Controller(base_url=BOB_ASKAR) as bob,
):
# connect to Bob (Askar wallet) and issue (and revoke) some credentials
(alice_conn, bob_conn) = await connect_agents_and_issue_credentials(
alice,
Expand Down Expand Up @@ -472,7 +483,7 @@ async def main():
)
await verify_recd_credentials(bob, 2, 2)
await verify_issued_credentials(alice, 12, 6)
await verify_recd_presentations(alice, 6)
await verify_recd_presentations(alice, 9)
print(">>> Done! (again)")

finally:
Expand Down
26 changes: 16 additions & 10 deletions scenarios/examples/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ def anoncreds_presentation_summary(presentation: V20PresExRecord) -> str:
{
"state": presentation.state,
"verified": presentation.verified,
"presentation_request": request.model_dump(by_alias=True)
if request
else None,
"presentation_request": (
request.model_dump(by_alias=True) if request else None
),
},
indent=2,
sort_keys=True,
Expand Down Expand Up @@ -287,9 +287,11 @@ async def anoncreds_issue_credential_v2(
state="done",
)
issuer_indy_record = await issuer.event_with_values(
topic="issue_credential_v2_0_anoncreds"
if is_issuer_anoncreds
else "issue_credential_v2_0_indy",
topic=(
"issue_credential_v2_0_anoncreds"
if is_issuer_anoncreds
else "issue_credential_v2_0_indy"
),
event_type=V20CredExRecordIndy,
)

Expand All @@ -300,14 +302,18 @@ async def anoncreds_issue_credential_v2(
state="done",
)
holder_indy_record = await holder.event_with_values(
topic="issue_credential_v2_0_anoncreds"
if (is_holder_anoncreds or is_issuer_anoncreds)
else "issue_credential_v2_0_indy",
topic=(
"issue_credential_v2_0_anoncreds"
if (is_holder_anoncreds or is_issuer_anoncreds)
else "issue_credential_v2_0_indy"
),
event_type=V20CredExRecordIndy,
)

return (
V20CredExRecordDetail(cred_ex_record=issuer_cred_ex, details=issuer_indy_record),
V20CredExRecordDetail(
cred_ex_record=issuer_cred_ex, details=issuer_indy_record
),
V20CredExRecordDetail(
cred_ex_record=holder_cred_ex,
details=holder_indy_record,
Expand Down

0 comments on commit ead669e

Please sign in to comment.