Skip to content

Commit 958be35

Browse files
authored
Merge branch 'main' into default-askar
2 parents 02b564e + 8038584 commit 958be35

1 file changed

Lines changed: 26 additions & 26 deletions

File tree

aries_cloudagent/indy/credx/holder.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import re
77
import uuid
88

9-
from typing import Sequence, Tuple, Union
9+
from typing import Dict, Sequence, Tuple, Union
1010

1111
from aries_askar import AskarError, AskarErrorCode
1212
from indy_credx import (
@@ -471,27 +471,26 @@ async def create_presentation(
471471
472472
"""
473473

474-
creds = {}
475-
476-
def get_rev_state(cred_id, timestamp):
477-
reg_id = creds[cred_id].rev_reg_id
478-
if not reg_id:
479-
raise IndyHolderError(
480-
f"Cannot prove credential '{cred_id}' for "
481-
"specific timestamp, credential has no rev_reg_id"
482-
)
483-
if not rev_states or reg_id not in rev_states:
484-
raise IndyHolderError(
485-
f"No revocation states provided for credential '{cred_id}'"
486-
f"with rev_reg_id '{reg_id}'"
487-
)
488-
state = rev_states[reg_id].get(timestamp)
489-
if not state:
490-
raise IndyHolderError(
491-
f"No revocation states provided for credential '{cred_id}'"
492-
f"with rev_reg_id '{reg_id}' at timestamp {timestamp}"
493-
)
494-
return state
474+
creds: Dict[str, Credential] = {}
475+
476+
def get_rev_state(cred_id: str, detail: dict):
477+
cred = creds[cred_id]
478+
rev_reg_id = cred.rev_reg_id
479+
timestamp = detail.get("timestamp") if rev_reg_id else None
480+
rev_state = None
481+
if timestamp:
482+
if not rev_states or rev_reg_id not in rev_states:
483+
raise IndyHolderError(
484+
f"No revocation states provided for credential '{cred_id}' "
485+
f"with rev_reg_id '{rev_reg_id}'"
486+
)
487+
rev_state = rev_states[rev_reg_id].get(timestamp)
488+
if not rev_state:
489+
raise IndyHolderError(
490+
f"No revocation states provided for credential '{cred_id}' "
491+
f"with rev_reg_id '{rev_reg_id}' at timestamp {timestamp}"
492+
)
493+
return timestamp, rev_state
495494

496495
self_attest = requested_credentials.get("self_attested_attributes") or {}
497496
present_creds = PresentCredentials()
@@ -501,25 +500,26 @@ def get_rev_state(cred_id, timestamp):
501500
if cred_id not in creds:
502501
# NOTE: could be optimized if multiple creds are requested
503502
creds[cred_id] = await self._get_credential(cred_id)
504-
timestamp = detail.get("timestamp")
503+
timestamp, rev_state = get_rev_state(cred_id, detail)
505504
present_creds.add_attributes(
506505
creds[cred_id],
507506
reft,
508507
reveal=detail["revealed"],
509508
timestamp=timestamp,
510-
rev_state=get_rev_state(cred_id, timestamp) if timestamp else None,
509+
rev_state=rev_state,
511510
)
512511
req_preds = requested_credentials.get("requested_predicates") or {}
513512
for reft, detail in req_preds.items():
513+
cred_id = detail["cred_id"]
514514
if cred_id not in creds:
515515
# NOTE: could be optimized if multiple creds are requested
516516
creds[cred_id] = await self._get_credential(cred_id)
517-
timestamp = detail.get("timestamp")
517+
timestamp, rev_state = get_rev_state(cred_id, detail)
518518
present_creds.add_predicates(
519519
creds[cred_id],
520520
reft,
521521
timestamp=timestamp,
522-
rev_state=get_rev_state(cred_id, timestamp) if timestamp else None,
522+
rev_state=rev_state,
523523
)
524524

525525
try:

0 commit comments

Comments
 (0)