Skip to content

Commit

Permalink
Merge pull request #435 from andrewwhitehead/revoke-multiple
Browse files Browse the repository at this point in the history
revoke_credential -> revoke_credentials to allow more efficient implementation
  • Loading branch information
andrewwhitehead authored Apr 2, 2020
2 parents cb5c287 + d23f14d commit 109ec34
Show file tree
Hide file tree
Showing 10 changed files with 205 additions and 301 deletions.
12 changes: 6 additions & 6 deletions aries_cloudagent/holder/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,17 @@ async def create_presentation(
requested_credentials: dict,
schemas: dict,
credential_definitions: dict,
rev_states_json: dict = None,
rev_states: dict = None,
) -> str:
"""
Get credentials stored in the wallet.
Args:
presentation_request: Valid indy format presentation request
requested_credentials: Indy format requested_credentials
schemas: Indy formatted schemas_json
credential_definitions: Indy formatted schemas_json
rev_states_json: Indy format revocation states
requested_credentials: Indy format requested credentials
schemas: Indy formatted schemas JSON
credential_definitions: Indy formatted credential definitions JSON
rev_states: Indy format revocation states JSON
"""

@abstractmethod
Expand Down Expand Up @@ -134,7 +134,7 @@ async def create_revocation_state(
tails_file_path: str,
) -> str:
"""
Get credentials stored in the wallet.
Create current revocation state for a received credential.
Args:
cred_rev_id: credential revocation id in revocation registry
Expand Down
14 changes: 7 additions & 7 deletions aries_cloudagent/holder/indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,17 +317,17 @@ async def create_presentation(
requested_credentials: dict,
schemas: dict,
credential_definitions: dict,
rev_states_json: dict = None,
rev_states: dict = None,
) -> str:
"""
Get credentials stored in the wallet.
Args:
presentation_request: Valid indy format presentation request
requested_credentials: Indy format requested_credentials
schemas: Indy formatted schemas_json
credential_definitions: Indy formatted schemas_json
rev_states_json: Indy format revocation states
requested_credentials: Indy format requested credentials
schemas: Indy formatted schemas JSON
credential_definitions: Indy formatted credential definitions JSON
rev_states: Indy format revocation states JSON
"""

Expand All @@ -339,7 +339,7 @@ async def create_presentation(
self.wallet.master_secret_id,
json.dumps(schemas),
json.dumps(credential_definitions),
json.dumps(rev_states_json) if rev_states_json else "{}",
json.dumps(rev_states) if rev_states else "{}",
)

return presentation_json
Expand All @@ -353,7 +353,7 @@ async def create_revocation_state(
tails_file_path: str,
) -> str:
"""
Get credentials stored in the wallet.
Create current revocation state for a received credential.
Args:
cred_rev_id: credential revocation id in revocation registry
Expand Down
28 changes: 22 additions & 6 deletions aries_cloudagent/issuer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ async def create_and_store_credential_definition(
"""

@abstractmethod
def create_credential_offer(self, credential_definition_id) -> str:
async def create_credential_offer(self, credential_definition_id) -> str:
"""
Create a credential offer for the given credential definition id.
Expand Down Expand Up @@ -141,19 +141,19 @@ async def create_credential(
"""

@abstractmethod
def revoke_credential(
self, revoc_reg_id: str, tails_file_path: str, cred_revoc_id: str
async def revoke_credentials(
self, revoc_reg_id: str, tails_file_path: str, cred_revoc_ids: Sequence[str]
) -> str:
"""
Revoke a credential.
Revoke a set of credentials in a revocation registry.
Args:
revoc_reg_id: ID of the revocation registry
tails_file_path: path to the local tails file
cred_revoc_id: index of the credential in the revocation registry
cred_revoc_ids: sequences of credential indexes in the revocation registry
Returns:
the revocation delta
the combined revocation delta
"""

Expand Down Expand Up @@ -184,3 +184,19 @@ async def create_and_store_revocation_registry(
A tuple of the revocation registry ID, JSON, and entry JSON
"""

@abstractmethod
async def merge_revocation_registry_deltas(
self, fro_delta: str, to_delta: str
) -> str:
"""
Merge revocation registry deltas.
Args:
fro_delta: original delta in JSON format
to_delta: incoming delta in JSON format
Returns:
Merged delta in JSON format
"""
74 changes: 40 additions & 34 deletions aries_cloudagent/issuer/indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import json
import logging
from typing import Mapping, Sequence, Tuple
from typing import Sequence, Tuple

import indy.anoncreds
import indy.blob_storage
Expand Down Expand Up @@ -234,29 +234,57 @@ async def create_credential(

return credential_json, credential_revocation_id

async def revoke_credential(
self, revoc_reg_id: str, tails_file_path: str, cred_revoc_id: str
async def revoke_credentials(
self, revoc_reg_id: str, tails_file_path: str, cred_revoc_ids: Sequence[str]
) -> str:
"""
Revoke a credential.
Revoke a set of credentials in a revocation registry.
Args:
revoc_reg_id: ID of the revocation registry
tails_file_path: path to the local tails file
cred_revoc_id: index of the credential in the revocation registry
cred_revoc_ids: sequences of credential indexes in the revocation registry
Returns:
the revocation delta
the combined revocation delta
"""
tails_reader_handle = await create_tails_reader(tails_file_path)
with IndyErrorHandler("Exception when revoking credential", IssuerError):
revoc_reg_delta_json = await indy.anoncreds.issuer_revoke_credential(
self.wallet.handle, tails_reader_handle, revoc_reg_id, cred_revoc_id
)
# may throw AnoncredsInvalidUserRevocId if using ISSUANCE_ON_DEMAND

return revoc_reg_delta_json
result_json = None
for cred_revoc_id in cred_revoc_ids:
with IndyErrorHandler("Exception when revoking credential", IssuerError):
# may throw AnoncredsInvalidUserRevocId if using ISSUANCE_ON_DEMAND
delta_json = await indy.anoncreds.issuer_revoke_credential(
self.wallet.handle, tails_reader_handle, revoc_reg_id, cred_revoc_id
)
if not result_json:
result_json = delta_json
else:
result_json = await self.merge_revocation_registry_deltas(
result_json, delta_json
)

return result_json

async def merge_revocation_registry_deltas(
self, fro_delta: str, to_delta: str
) -> str:
"""
Merge revocation registry deltas.
Args:
fro_delta: original delta in JSON format
to_delta: incoming delta in JSON format
Returns:
Merged delta in JSON format
"""

return await indy.anoncreds.issuer_merge_revocation_registry_deltas(
fro_delta, to_delta
)

async def create_and_store_revocation_registry(
self,
Expand Down Expand Up @@ -309,25 +337,3 @@ async def create_and_store_revocation_registry(
tails_writer,
)
return (revoc_reg_id, revoc_reg_def_json, revoc_reg_entry_json)

async def merge_revocation_registry_deltas(
self,
fro_delta: dict,
to_delta: dict
) -> Mapping:
"""
Merge revocation registry deltas.
Args:
fro_delta: original delta
to_delta: incoming delta
Returns:
Merged delta.
"""

return json.loads(await indy.anoncreds.issuer_merge_revocation_registry_deltas(
json.dumps(fro_delta),
json.dumps(to_delta)
))
Loading

0 comments on commit 109ec34

Please sign in to comment.