Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of non-revocable credential when timestamp is specified (askar/credx) #1847

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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