From 75fd1be214d6af06cdcea318b3c318ae50afad6f Mon Sep 17 00:00:00 2001 From: Andrew Whitehead Date: Wed, 4 Mar 2020 08:46:11 -0800 Subject: [PATCH] address method signature mismatches Signed-off-by: Andrew Whitehead --- aries_cloudagent/holder/base.py | 44 ++++++++++++++++----------------- aries_cloudagent/holder/indy.py | 31 +++++++++++------------ aries_cloudagent/issuer/base.py | 6 ++--- aries_cloudagent/ledger/base.py | 34 ++++++++++++------------- aries_cloudagent/ledger/indy.py | 4 ++- 5 files changed, 59 insertions(+), 60 deletions(-) diff --git a/aries_cloudagent/holder/base.py b/aries_cloudagent/holder/base.py index a814f64a25..ed81df4878 100644 --- a/aries_cloudagent/holder/base.py +++ b/aries_cloudagent/holder/base.py @@ -1,6 +1,7 @@ """Base holder class.""" from abc import ABC, ABCMeta, abstractmethod +from typing import Union class BaseHolder(ABC, metaclass=ABCMeta): @@ -17,7 +18,7 @@ def __repr__(self) -> str: return "<{}>".format(self.__class__.__name__) @abstractmethod - def get_credential(self, credential_id): + async def get_credential(self, credential_id: str): """ Get a credential stored in the wallet. @@ -25,10 +26,9 @@ def get_credential(self, credential_id): credential_id: Credential id to retrieve """ - pass @abstractmethod - def delete_credential(self, credential_id): + async def delete_credential(self, credential_id: str): """ Remove a credential stored in the wallet. @@ -36,10 +36,11 @@ def delete_credential(self, credential_id): credential_id: Credential id to remove """ - pass @abstractmethod - def get_mime_type(self, credential_id, attr): + async def get_mime_type( + self, credential_id: str, attr: str = None + ) -> Union[dict, str]: """ Get MIME type per attribute (or for all attributes). @@ -51,16 +52,15 @@ def get_mime_type(self, credential_id, attr): attr_meta_json = all_meta.tags.get(attr) """ - pass @abstractmethod - def create_presentation( + async def create_presentation( self, - presentation_request, - requested_credentials, - schemas, - credential_definitions, - rev_states_json=None, + presentation_request: dict, + requested_credentials: dict, + schemas: dict, + credential_definitions: dict, + rev_states_json: dict = None, ): """ Get credentials stored in the wallet. @@ -72,32 +72,33 @@ def create_presentation( credential_definitions: Indy formatted schemas_json rev_states_json: Indy format revocation states """ - pass @abstractmethod - def create_credential_request(self, credential_offer, credential_definition, did): + async def create_credential_request( + self, credential_offer, credential_definition, holder_did: str + ): """ Create a credential offer for the given credential definition id. Args: credential_offer: The credential offer to create request for credential_definition: The credential definition to create an offer for + holder_did: the DID of the agent making the request Returns: A credential request """ - pass @abstractmethod - def store_credential( + async def store_credential( self, credential_definition, credential_data, credential_request_metadata, - credential_attr_mime_types, - credential_id, - rev_reg_def_json={}, + credential_attr_mime_types=None, + credential_id=None, + rev_reg_def_json=None, ): """ Store a credential in the wallet. @@ -109,8 +110,7 @@ def store_credential( by the issuer credential_attr_mime_types: dict mapping attribute names to (optional) MIME types to store as non-secret record, if specified - credential_id: credential id - rev_reg_def_json: revocation registry definition in json + credential_id: optionally override the stored credential id + rev_reg_def_json: optional revocation registry definition in json """ - pass diff --git a/aries_cloudagent/holder/indy.py b/aries_cloudagent/holder/indy.py index 81d326db8a..7ed4d6ad3a 100644 --- a/aries_cloudagent/holder/indy.py +++ b/aries_cloudagent/holder/indy.py @@ -35,7 +35,7 @@ def __init__(self, wallet): self.wallet = wallet async def create_credential_request( - self, credential_offer, credential_definition, did + self, credential_offer, credential_definition, holder_did: str ): """ Create a credential offer for the given credential definition id. @@ -43,6 +43,7 @@ async def create_credential_request( Args: credential_offer: The credential offer to create request for credential_definition: The credential definition to create an offer for + holder_did: the DID of the agent making the request Returns: A credential request @@ -54,7 +55,7 @@ async def create_credential_request( credential_request_metadata_json, ) = await indy.anoncreds.prover_create_credential_req( self.wallet.handle, - did, + holder_did, json.dumps(credential_offer), json.dumps(credential_definition), self.wallet.master_secret_id, @@ -78,7 +79,7 @@ async def store_credential( credential_request_metadata, credential_attr_mime_types=None, credential_id=None, - rev_reg_def_json=None + rev_reg_def_json=None, ): """ Store a credential in the wallet. @@ -90,7 +91,7 @@ async def store_credential( by the issuer credential_attr_mime_types: dict mapping attribute names to (optional) MIME types to store as non-secret record, if specified - credential_id: credential id + credential_id: optionally override the stored credential id rev_reg_def_json: revocation registry definition in json """ @@ -100,7 +101,7 @@ async def store_credential( cred_req_metadata_json=json.dumps(credential_request_metadata), cred_json=json.dumps(credential_data), cred_def_json=json.dumps(credential_definition), - rev_reg_def_json=json.dumps(rev_reg_def_json) if rev_reg_def_json else None + rev_reg_def_json=json.dumps(rev_reg_def_json) if rev_reg_def_json else None, ) if credential_attr_mime_types: @@ -114,7 +115,7 @@ async def store_credential( type=IndyHolder.RECORD_TYPE_MIME_TYPES, value=credential_id, tags=mime_types, - id=f"{IndyHolder.RECORD_TYPE_MIME_TYPES}::{credential_id}" + id=f"{IndyHolder.RECORD_TYPE_MIME_TYPES}::{credential_id}", ) indy_stor = IndyStorage(self.wallet) await indy_stor.add_record(record) @@ -132,8 +133,7 @@ async def get_credentials(self, start: int, count: int, wql: dict): """ search_handle, record_count = await indy.anoncreds.prover_search_credentials( - self.wallet.handle, - json.dumps(wql) + self.wallet.handle, json.dumps(wql) ) # We need to move the database cursor position manually... @@ -142,8 +142,7 @@ async def get_credentials(self, start: int, count: int, wql: dict): await indy.anoncreds.prover_fetch_credentials(search_handle, start) credentials_json = await indy.anoncreds.prover_fetch_credentials( - search_handle, - count + search_handle, count ) await indy.anoncreds.prover_close_credentials_search(search_handle) @@ -251,7 +250,7 @@ async def delete_credential(self, credential_id: str): indy_stor = IndyStorage(self.wallet) mime_types_record = await indy_stor.get_record( IndyHolder.RECORD_TYPE_MIME_TYPES, - f"{IndyHolder.RECORD_TYPE_MIME_TYPES}::{credential_id}" + f"{IndyHolder.RECORD_TYPE_MIME_TYPES}::{credential_id}", ) await indy_stor.delete_record(mime_types_record) except StorageNotFoundError: @@ -270,9 +269,7 @@ async def delete_credential(self, credential_id: str): raise async def get_mime_type( - self, - credential_id: str, - attr: str = None + self, credential_id: str, attr: str = None ) -> Union[dict, str]: """ Get MIME type per attribute (or for all attributes). @@ -288,7 +285,7 @@ async def get_mime_type( try: mime_types_record = await IndyStorage(self.wallet).get_record( IndyHolder.RECORD_TYPE_MIME_TYPES, - f"{IndyHolder.RECORD_TYPE_MIME_TYPES}::{credential_id}" + f"{IndyHolder.RECORD_TYPE_MIME_TYPES}::{credential_id}", ) except StorageError: return None # no MIME types: not an error @@ -301,7 +298,7 @@ async def create_presentation( requested_credentials: dict, schemas: dict, credential_definitions: dict, - rev_states_json: dict = None + rev_states_json: dict = None, ): """ Get credentials stored in the wallet. @@ -322,7 +319,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_json) if rev_states_json else "{}", ) presentation = json.loads(presentation_json) diff --git a/aries_cloudagent/issuer/base.py b/aries_cloudagent/issuer/base.py index 38035eff7a..3e51049ef5 100644 --- a/aries_cloudagent/issuer/base.py +++ b/aries_cloudagent/issuer/base.py @@ -31,14 +31,14 @@ def create_credential_offer(self, credential_definition_id): pass @abstractmethod - def create_credential( + async def create_credential( self, schema, credential_offer, credential_request, credential_values, - revoc_reg_id, - tails_reader_handle, + revoc_reg_id: str = None, + tails_reader_handle: int = None, ): """ Create a credential. diff --git a/aries_cloudagent/ledger/base.py b/aries_cloudagent/ledger/base.py index 3b3d356f40..e285c62c8b 100644 --- a/aries_cloudagent/ledger/base.py +++ b/aries_cloudagent/ledger/base.py @@ -103,24 +103,27 @@ async def create_and_send_schema( """ @abstractmethod - def get_revoc_reg_def(self, revoc_reg_id): + async def get_revoc_reg_def(self, revoc_reg_id: str) -> dict: """Look up a revocation registry definition by ID.""" - pass @abstractmethod - def send_revoc_reg_def(self, revoc_reg_def, issuer_did): + async def send_revoc_reg_def(self, revoc_reg_def: dict, issuer_did: str = None): """Publish a revocation registry definition to the ledger.""" - pass @abstractmethod - def send_revoc_reg_entry( - self, revoc_reg_id, revoc_def_type, revoc_reg_entry, issuer_did + async def send_revoc_reg_entry( + self, + revoc_reg_id: str, + revoc_def_type: str, + revoc_reg_entry: dict, + issuer_did: str = None, ): """Publish a revocation registry entry to the ledger.""" - pass @abstractmethod - def create_and_send_credential_definition(self, schema_id, tag, support_revocation): + async def create_and_send_credential_definition( + self, schema_id: str, tag: str = None, support_revocation: bool = False + ) -> Tuple[str, dict]: """ Send credential definition to ledger and store relevant key matter in wallet. @@ -130,10 +133,9 @@ def create_and_send_credential_definition(self, schema_id, tag, support_revocati support_revocation: Optional flag to enable revocation for this cred def """ - pass @abstractmethod - def get_credential_definition(self, credential_definition_id): + async def get_credential_definition(self, credential_definition_id: str) -> dict: """ Get a credential definition from the cache if available, otherwise the ledger. @@ -141,15 +143,15 @@ def get_credential_definition(self, credential_definition_id): credential_definition_id: The schema id of the schema to fetch cred def for """ - pass @abstractmethod - def get_revoc_reg_delta(self, revoc_reg_id, timestamp_from, timestamp_to): + async def get_revoc_reg_delta( + self, revoc_reg_id: str, timestamp_from=0, timestamp_to=None + ) -> (dict, int): """Look up a revocation registry delta by ID.""" - pass @abstractmethod - def get_schema(self, schema_id): + async def get_schema(self, schema_id: str) -> dict: """ Get a schema from the cache if available, otherwise fetch from the ledger. @@ -157,9 +159,7 @@ def get_schema(self, schema_id): schema_id: The schema id (or stringified sequence number) to retrieve """ - pass @abstractmethod - def get_revoc_reg_entry(self, revoc_reg_id, timestamp): + async def get_revoc_reg_entry(self, revoc_reg_id: str, timestamp: int): """Get revocation registry entry by revocation registry ID and timestamp.""" - pass diff --git a/aries_cloudagent/ledger/indy.py b/aries_cloudagent/ledger/indy.py index 883c8e213c..68dcb3d339 100644 --- a/aries_cloudagent/ledger/indy.py +++ b/aries_cloudagent/ledger/indy.py @@ -918,7 +918,7 @@ async def get_revoc_reg_entry(self, revoc_reg_id: str, timestamp: int): return json.loads(found_reg_json), timestamp2 async def get_revoc_reg_delta( - self, revoc_reg_id: str, timestamp_from=0, timestamp_to=int(time()) + self, revoc_reg_id: str, timestamp_from=0, timestamp_to=None ) -> (dict, int): """ Look up a revocation registry delta by ID. @@ -929,6 +929,8 @@ async def get_revoc_reg_delta( :returns delta response, delta timestamp """ + if timestamp_to is None: + timestamp_to = int(time()) public_info = await self.wallet.get_public_did() fetch_req = await indy.ledger.build_get_revoc_reg_delta_request( public_info and public_info.did, revoc_reg_id, timestamp_from, timestamp_to