Skip to content

Commit

Permalink
fix handling of non-revocable credential when timestamp is specified …
Browse files Browse the repository at this point in the history
…(credx)

Signed-off-by: Andrew Whitehead <[email protected]>
  • Loading branch information
andrewwhitehead committed Jun 29, 2022
1 parent 47dbb28 commit be27d36
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions aries_cloudagent/indy/credx/holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import re
import uuid

from typing import Sequence, Tuple, Union
from typing import Dict, Sequence, Tuple, Union

from aries_askar import AskarError, AskarErrorCode
from indy_credx import (
Expand Down Expand Up @@ -471,27 +471,26 @@ async def create_presentation(
"""

creds = {}

def get_rev_state(cred_id, timestamp):
reg_id = creds[cred_id].rev_reg_id
if not reg_id:
raise IndyHolderError(
f"Cannot prove credential '{cred_id}' for "
"specific timestamp, credential has no rev_reg_id"
)
if not rev_states or reg_id not in rev_states:
raise IndyHolderError(
f"No revocation states provided for credential '{cred_id}'"
f"with rev_reg_id '{reg_id}'"
)
state = rev_states[reg_id].get(timestamp)
if not state:
raise IndyHolderError(
f"No revocation states provided for credential '{cred_id}'"
f"with rev_reg_id '{reg_id}' at timestamp {timestamp}"
)
return state
creds: Dict[str, Credential] = {}

def get_rev_state(cred_id: str, detail: dict):
cred = creds[cred_id]
rev_reg_id = cred.rev_reg_id
timestamp = detail.get("timestamp") if rev_reg_id else None
rev_state = None
if timestamp:
if not rev_states or rev_reg_id not in rev_states:
raise IndyHolderError(
f"No revocation states provided for credential '{cred_id}' "
f"with rev_reg_id '{rev_reg_id}'"
)
rev_state = rev_states[rev_reg_id].get(timestamp)
if not rev_state:
raise IndyHolderError(
f"No revocation states provided for credential '{cred_id}' "
f"with rev_reg_id '{rev_reg_id}' at timestamp {timestamp}"
)
return timestamp, rev_state

self_attest = requested_credentials.get("self_attested_attributes") or {}
present_creds = PresentCredentials()
Expand All @@ -501,25 +500,26 @@ def get_rev_state(cred_id, timestamp):
if cred_id not in creds:
# NOTE: could be optimized if multiple creds are requested
creds[cred_id] = await self._get_credential(cred_id)
timestamp = detail.get("timestamp")
timestamp, rev_state = get_rev_state(cred_id, detail)
present_creds.add_attributes(
creds[cred_id],
reft,
reveal=detail["revealed"],
timestamp=timestamp,
rev_state=get_rev_state(cred_id, timestamp) if timestamp else None,
rev_state=rev_state,
)
req_preds = requested_credentials.get("requested_predicates") or {}
for reft, detail in req_preds.items():
cred_id = detail["cred_id"]
if cred_id not in creds:
# NOTE: could be optimized if multiple creds are requested
creds[cred_id] = await self._get_credential(cred_id)
timestamp = detail.get("timestamp")
timestamp, rev_state = get_rev_state(cred_id, detail)
present_creds.add_predicates(
creds[cred_id],
reft,
timestamp=timestamp,
rev_state=get_rev_state(cred_id, timestamp) if timestamp else None,
rev_state=rev_state,
)

try:
Expand Down

0 comments on commit be27d36

Please sign in to comment.