Skip to content

Commit

Permalink
Merge pull request #23 from andrewwhitehead/fix/python-types
Browse files Browse the repository at this point in the history
Fix python type hints
  • Loading branch information
andrewwhitehead authored Jan 23, 2023
2 parents 1038c3a + 802ab1d commit 6af1e93
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 43 deletions.
15 changes: 8 additions & 7 deletions wrappers/python/indy_credx/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
)
from ctypes.util import find_library
from io import BytesIO
from typing import Optional, Mapping, Sequence, Union
from typing import Optional, Mapping, Sequence, Tuple, Union

from .error import CredxError, CredxErrorCode

Expand Down Expand Up @@ -365,6 +365,7 @@ def _load_library(lib_name: str) -> CDLL:
def do_call(fn_name, *args):
"""Perform a synchronous library function call."""
lib_fn = getattr(get_library(), fn_name)
lib_fn.restype = c_int64
result = lib_fn(*args)
if result:
raise get_current_error(True)
Expand Down Expand Up @@ -505,7 +506,7 @@ def create_credential_definition(
tag: str,
signature_type: str,
support_revocation: bool,
) -> (ObjectHandle, ObjectHandle, ObjectHandle):
) -> Tuple[ObjectHandle, ObjectHandle, ObjectHandle]:
cred_def, cred_def_pvt, key_proof = ObjectHandle(), ObjectHandle(), ObjectHandle()
do_call(
"credx_create_credential_definition",
Expand All @@ -529,7 +530,7 @@ def create_credential(
attr_raw_values: Mapping[str, str],
attr_enc_values: Optional[Mapping[str, str]],
revocation_config: Optional[RevocationConfig],
) -> (ObjectHandle, ObjectHandle, ObjectHandle):
) -> Tuple[ObjectHandle, ObjectHandle, ObjectHandle]:
cred = ObjectHandle()
rev_reg = ObjectHandle()
rev_delta = ObjectHandle()
Expand Down Expand Up @@ -597,7 +598,7 @@ def revoke_credential(
rev_reg: ObjectHandle,
cred_rev_idx: int,
tails_path: str,
) -> (ObjectHandle, ObjectHandle):
) -> Tuple[ObjectHandle, ObjectHandle]:
upd_rev_reg = ObjectHandle()
rev_delta = ObjectHandle()
do_call(
Expand Down Expand Up @@ -632,7 +633,7 @@ def create_credential_request(
master_secret: ObjectHandle,
master_secret_id: str,
cred_offer: ObjectHandle,
) -> (ObjectHandle, ObjectHandle):
) -> Tuple[ObjectHandle, ObjectHandle]:
cred_req, cred_req_metadata = ObjectHandle(), ObjectHandle()
do_call(
"credx_create_credential_request",
Expand Down Expand Up @@ -721,7 +722,7 @@ def create_revocation_registry(
issuance_type: Optional[str],
max_cred_num: int,
tails_dir_path: Optional[str],
) -> (ObjectHandle, ObjectHandle, ObjectHandle, ObjectHandle):
) -> Tuple[ObjectHandle, ObjectHandle, ObjectHandle, ObjectHandle]:
reg_def = ObjectHandle()
reg_def_private = ObjectHandle()
reg_entry = ObjectHandle()
Expand Down Expand Up @@ -749,7 +750,7 @@ def update_revocation_registry(
issued: Sequence[int],
revoked: Sequence[int],
tails_path: str,
) -> (ObjectHandle, ObjectHandle):
) -> Tuple[ObjectHandle, ObjectHandle]:
upd_rev_reg = ObjectHandle()
rev_delta = ObjectHandle()
do_call(
Expand Down
74 changes: 38 additions & 36 deletions wrappers/python/indy_credx/types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Mapping, Optional, Sequence, Union
from typing import Mapping, Optional, Sequence, Tuple, Union

from . import bindings

Expand All @@ -10,12 +10,14 @@ class CredentialDefinition(bindings.IndyObject):
def create(
cls,
origin_did: str,
schema: [str, "Schema"],
schema: Union[str, "Schema"],
signature_type: str,
tag: str,
*,
support_revocation: bool = False,
) -> ("CredentialDefinition", "CredentialDefinitionPrivate", "KeyCorrectnessProof"):
) -> Tuple[
"CredentialDefinition", "CredentialDefinitionPrivate", "KeyCorrectnessProof"
]:
if not isinstance(schema, bindings.IndyObject):
schema = Schema.load(schema)
cred_def, cred_def_pvt, key_proof = bindings.create_credential_definition(
Expand Down Expand Up @@ -79,8 +81,8 @@ class CredentialOffer(bindings.IndyObject):
def create(
cls,
schema_id: str,
cred_def: [str, CredentialDefinition],
key_proof: [str, KeyCorrectnessProof],
cred_def: Union[str, CredentialDefinition],
key_proof: Union[str, KeyCorrectnessProof],
) -> "CredentialOffer":
if not isinstance(cred_def, bindings.IndyObject):
cred_def = CredentialDefinition.load(cred_def)
Expand All @@ -104,11 +106,11 @@ class CredentialRequest(bindings.IndyObject):
def create(
cls,
prover_did: str,
cred_def: [str, CredentialDefinition],
master_secret: [str, "MasterSecret"],
cred_def: Union[str, CredentialDefinition],
master_secret: Union[str, "MasterSecret"],
master_secret_id: str,
cred_offer: [str, CredentialOffer],
) -> ("CredentialRequest", "CredentialRequestMetadata"):
cred_offer: Union[str, CredentialOffer],
) -> Tuple["CredentialRequest", "CredentialRequestMetadata"]:
if not isinstance(cred_def, bindings.IndyObject):
cred_def = CredentialDefinition.load(cred_def)
if not isinstance(master_secret, bindings.IndyObject):
Expand Down Expand Up @@ -193,18 +195,18 @@ class Credential(bindings.IndyObject):
@classmethod
def create(
cls,
cred_def: [str, CredentialDefinition],
cred_def_private: [str, CredentialDefinitionPrivate],
cred_offer: [str, CredentialOffer],
cred_request: [str, CredentialRequest],
cred_def: Union[str, CredentialDefinition],
cred_def_private: Union[str, CredentialDefinitionPrivate],
cred_offer: Union[str, CredentialOffer],
cred_request: Union[str, CredentialRequest],
attr_raw_values: Mapping[str, str],
attr_enc_values: Mapping[str, str] = None,
revocation_config: "CredentialRevocationConfig" = None,
) -> (
) -> Tuple[
"Credential",
Optional["RevocationRegistry"],
Optional["RevocationRegistryDelta"],
):
]:
if not isinstance(cred_def, bindings.IndyObject):
cred_def = CredentialDefinition.load(cred_def)
if not isinstance(cred_def_private, bindings.IndyObject):
Expand All @@ -230,9 +232,9 @@ def create(

def process(
self,
cred_req_metadata: [str, CredentialRequestMetadata],
master_secret: [str, MasterSecret],
cred_def: [str, CredentialDefinition],
cred_req_metadata: Union[str, CredentialRequestMetadata],
master_secret: Union[str, MasterSecret],
cred_def: Union[str, CredentialDefinition],
rev_reg_def: Optional[Union[str, "RevocationRegistryDefinition"]] = None,
) -> "Credential":
if not isinstance(cred_req_metadata, bindings.IndyObject):
Expand Down Expand Up @@ -338,7 +340,7 @@ def add_attributes(
*referents: Sequence[str],
reveal: bool = True,
timestamp: int = None,
rev_state: [str, "CredentialRevocationState"] = None,
rev_state: Union[str, "CredentialRevocationState"] = None,
):
if not referents:
return
Expand All @@ -351,7 +353,7 @@ def add_predicates(
cred: Credential,
*referents: Sequence[str],
timestamp: int = None,
rev_state: [str, "CredentialRevocationState"] = None,
rev_state: Union[str, "CredentialRevocationState"] = None,
):
if not referents:
return
Expand All @@ -364,10 +366,10 @@ class Presentation(bindings.IndyObject):
@classmethod
def create(
cls,
pres_req: [str, PresentationRequest],
pres_req: Union[str, PresentationRequest],
present_creds: PresentCredentials,
self_attest: Optional[Mapping[str, str]],
master_secret: [str, MasterSecret],
master_secret: Union[str, MasterSecret],
schemas: Sequence[Union[str, Schema]],
cred_defs: Sequence[Union[str, CredentialDefinition]],
) -> "Presentation":
Expand Down Expand Up @@ -425,7 +427,7 @@ def load(cls, value: Union[dict, str, bytes, memoryview]) -> "Presentation":

def verify(
self,
pres_req: [str, PresentationRequest],
pres_req: Union[str, PresentationRequest],
schemas: Sequence[Union[str, Schema]],
cred_defs: Sequence[Union[str, CredentialDefinition]],
rev_reg_defs: Sequence[Union[str, "RevocationRegistryDefinition"]] = None,
Expand Down Expand Up @@ -481,19 +483,19 @@ class RevocationRegistryDefinition(bindings.IndyObject):
def create(
cls,
origin_did: str,
cred_def: [str, CredentialDefinition],
cred_def: Union[str, CredentialDefinition],
tag: str,
registry_type: str,
max_cred_num: int,
*,
issuance_type: str = None,
tails_dir_path: str = None,
) -> (
) -> Tuple[
"RevocationRegistryDefinition",
"RevocationRegistryDefinitionPrivate",
"RevocationRegistry",
"RevocationRegistryDelta",
):
]:
if not isinstance(cred_def, bindings.IndyObject):
cred_def = CredentialDefinition.load(cred_def)
(
Expand Down Expand Up @@ -591,7 +593,7 @@ def load(cls, value: Union[dict, str, bytes, memoryview]) -> "RevocationRegistry

def revoke_credential(
self,
rev_reg_def: [str, RevocationRegistryDefinition],
rev_reg_def: Union[str, RevocationRegistryDefinition],
cred_rev_idx: int,
tails_path: str,
) -> "RevocationRegistryDelta":
Expand All @@ -604,7 +606,7 @@ def revoke_credential(

def update(
self,
rev_reg_def: [str, RevocationRegistryDefinition],
rev_reg_def: Union[str, RevocationRegistryDefinition],
issued: Sequence[int],
revoked: Sequence[int],
tails_path: str,
Expand All @@ -629,7 +631,7 @@ def load(
)

def update_with(
self, next_delta: [str, "RevocationRegistryDelta"]
self, next_delta: Union[str, "RevocationRegistryDelta"]
) -> "RevocationRegistryDelta":
if not isinstance(next_delta, bindings.IndyObject):
next_delta = RevocationRegistryDelta.load(next_delta)
Expand All @@ -641,9 +643,9 @@ def update_with(
class CredentialRevocationConfig:
def __init__(
self,
rev_reg_def: [str, "RevocationRegistryDefinition"] = None,
rev_reg_def_private: [str, "RevocationRegistryDefinitionPrivate"] = None,
rev_reg: [str, "RevocationRegistry"] = None,
rev_reg_def: Union[str, "RevocationRegistryDefinition"] = None,
rev_reg_def_private: Union[str, "RevocationRegistryDefinitionPrivate"] = None,
rev_reg: Union[str, "RevocationRegistry"] = None,
rev_reg_index: int = None,
rev_reg_used: Sequence[int] = None,
tails_path: str = None,
Expand Down Expand Up @@ -679,8 +681,8 @@ class CredentialRevocationState(bindings.IndyObject):
@classmethod
def create(
cls,
rev_reg_def: [str, RevocationRegistryDefinition],
rev_reg_delta: [str, RevocationRegistryDelta],
rev_reg_def: Union[str, RevocationRegistryDefinition],
rev_reg_delta: Union[str, RevocationRegistryDelta],
cred_rev_id: int,
timestamp: int,
tails_path: str,
Expand Down Expand Up @@ -710,8 +712,8 @@ def load(

def update(
self,
rev_reg_def: [str, RevocationRegistryDefinition],
rev_reg_delta: [str, RevocationRegistryDelta],
rev_reg_def: Union[str, RevocationRegistryDefinition],
rev_reg_delta: Union[str, RevocationRegistryDelta],
rev_reg_index: int,
timestamp: int,
tails_path: str,
Expand Down

0 comments on commit 6af1e93

Please sign in to comment.