Skip to content

Commit

Permalink
Merge pull request #1394 from andrewwhitehead/credx-test
Browse files Browse the repository at this point in the history
Implement get_credentials, credential_revoked for credx backend
  • Loading branch information
ianco authored Oct 20, 2021
2 parents b47f657 + 5afd63a commit 0c266fa
Show file tree
Hide file tree
Showing 11 changed files with 443 additions and 25 deletions.
35 changes: 29 additions & 6 deletions aries_cloudagent/indy/credx/holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,19 @@ async def get_credentials(self, start: int, count: int, wql: dict):
"""

pass # Not used anywhere currently
result = []

try:
rows = self._profile.store.scan(CATEGORY_CREDENTIAL, wql, start, count)
async for row in rows:
cred = Credential.load(row.raw_value)
result.append(_make_cred_info(row.name, cred))
except AskarError as err:
raise IndyHolderError("Error retrieving credentials") from err
except CredxError as err:
raise IndyHolderError("Error loading stored credential") from err

return result

async def get_credentials_for_presentation_request_by_referent(
self,
Expand All @@ -274,8 +286,6 @@ async def get_credentials_for_presentation_request_by_referent(
"""

# FIXME not using extra_query

if not referents:
referents = (
*presentation_request["requested_attributes"],
Expand Down Expand Up @@ -308,6 +318,8 @@ async def get_credentials_for_presentation_request_by_referent(
if restr:
# FIXME check if restr is a list or dict? validate WQL format
tag_filter = {"$and": [tag_filter] + restr}
if extra_query:
tag_filter = {"$and": [tag_filter, extra_query]}

rows = self._profile.store.scan(
CATEGORY_CREDENTIAL, tag_filter, start, count
Expand Down Expand Up @@ -369,8 +381,19 @@ async def credential_revoked(
credential_id: Credential id to check
"""
# FIXME
return False
cred = await self._get_credential(credential_id)
rev_reg_id = cred.rev_reg_id

if rev_reg_id:
cred_rev_id = cred.rev_reg_index
(rev_reg_delta, _) = await ledger.get_revoc_reg_delta(
rev_reg_id,
fro,
to,
)
return cred_rev_id in rev_reg_delta["value"].get("revoked", [])
else:
return False

async def delete_credential(self, credential_id: str):
"""
Expand Down Expand Up @@ -460,7 +483,7 @@ def get_rev_state(cred_id, timestamp):
)
return state

self_attest = requested_credentials.get("self_attested_attributes")
self_attest = requested_credentials.get("self_attested_attributes") or {}
present_creds = PresentCredentials()
req_attrs = requested_credentials.get("requested_attributes") or {}
for reft, detail in req_attrs.items():
Expand Down
16 changes: 16 additions & 0 deletions aries_cloudagent/indy/credx/issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
DEFAULT_CRED_DEF_TAG,
DEFAULT_SIGNATURE_TYPE,
)
from ...revocation.models.issuer_cred_rev_record import IssuerCredRevRecord


LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -318,6 +320,20 @@ async def create_credential(
await txn.handle.replace(
CATEGORY_REV_REG_INFO, revoc_reg_id, value_json=rev_info
)

issuer_cr_rec = IssuerCredRevRecord(
state=IssuerCredRevRecord.STATE_ISSUED,
cred_ex_id=cred_ex_id,
rev_reg_id=revoc_reg_id,
cred_rev_id=str(rev_reg_index),
)
await issuer_cr_rec.save(
txn,
reason=(
"Created issuer cred rev record for "
f"rev reg id {revoc_reg_id}, {rev_reg_index}"
),
)
await txn.commit()
except AskarError as err:
raise IndyIssuerError(
Expand Down
Loading

0 comments on commit 0c266fa

Please sign in to comment.