Skip to content

Commit

Permalink
address method signature mismatches
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Whitehead <[email protected]>
  • Loading branch information
andrewwhitehead committed Mar 4, 2020
1 parent 3be1d9b commit 75fd1be
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 60 deletions.
44 changes: 22 additions & 22 deletions aries_cloudagent/holder/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Base holder class."""

from abc import ABC, ABCMeta, abstractmethod
from typing import Union


class BaseHolder(ABC, metaclass=ABCMeta):
Expand All @@ -17,29 +18,29 @@ 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.
Args:
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.
Args:
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).
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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
31 changes: 14 additions & 17 deletions aries_cloudagent/holder/indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ 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.
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
Expand All @@ -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,
Expand All @@ -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.
Expand All @@ -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
"""
Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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...
Expand All @@ -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)

Expand Down Expand Up @@ -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:
Expand All @@ -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).
Expand All @@ -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
Expand All @@ -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.
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions aries_cloudagent/issuer/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
34 changes: 17 additions & 17 deletions aries_cloudagent/ledger/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -130,36 +133,33 @@ 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.
Args:
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.
Args:
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
4 changes: 3 additions & 1 deletion aries_cloudagent/ledger/indy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit 75fd1be

Please sign in to comment.