Skip to content

Commit

Permalink
Merge pull request #34 from Whats-Cookin/type-checking-restructure
Browse files Browse the repository at this point in the history
Resolve comments & restructure vc_di models
  • Loading branch information
sarthakvijayvergiya authored Apr 3, 2024
2 parents 713cdee + 3aad781 commit 88a7094
Show file tree
Hide file tree
Showing 13 changed files with 589 additions and 694 deletions.
1 change: 1 addition & 0 deletions aries_cloudagent/anoncreds/holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ async def store_credential_w3c(
credential_definition,
rev_reg_def,
)
# TODO
cred_recvd = Credential.from_w3c(cred_w3c)
except AnoncredsError as err:
raise AnonCredsHolderError("Error processing received credential") from err
Expand Down
39 changes: 0 additions & 39 deletions aries_cloudagent/indy/models/cred.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,42 +155,3 @@ class Meta:
witness = fields.Dict(
allow_none=True, metadata={"description": "Witness for revocation proof"}
)


class VCDIIndyCredential(BaseModel):
"""VCDI Indy credential."""

class Meta:
"""VCDI Indy credential metadata."""

schema_class = "VCDIIndyCredentialSchema"

def __init__(
self,
credential: dict = None,
**kwargs,
):
"""Initialize vcdi cred abstract object.
Args:
data_model_versions_supported: supported versions for data model
binding_required: boolean value
binding_methods: required if binding_required is true
credential: credential object
"""
super().__init__(**kwargs)
self.credential = credential


class VCDIIndyCredentialSchema(BaseModelSchema):
"""VCDI Indy credential schema."""

class Meta:
"""VCDI Indy credential schemametadata."""

model_class = VCDIIndyCredential
unknown = EXCLUDE

credential = fields.Dict(
fields.Str(), required=True, metadata={"description": "", "example": ""}
)
200 changes: 1 addition & 199 deletions aries_cloudagent/indy/models/cred_abstract.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Cred abstract artifacts to attach to RFC 453 messages."""

from typing import Sequence, Union
from ...vc.vc_ld.models.credential import CredentialSchema, VerifiableCredential
from typing import Sequence

from marshmallow import EXCLUDE, fields

Expand Down Expand Up @@ -153,200 +152,3 @@ class Meta:
required=True,
metadata={"description": "Key correctness proof"},
)


class AnoncredsLinkSecret(BaseModel):
"""Anoncreds Link Secret Model."""

class Meta:
"""AnoncredsLinkSecret metadata."""

schema_class = "AnoncredsLinkSecretSchema"

def __init__(
self,
nonce: str = None,
cred_def_id: str = None,
key_correctness_proof: str = None,
**kwargs,
):
"""Initialize values for AnoncredsLinkSecret."""
super().__init__(**kwargs)
self.nonce = nonce
self.cred_def_id = cred_def_id
self.key_correctness_proof = key_correctness_proof


class AnoncredsLinkSecretSchema(BaseModelSchema):
"""Anoncreds Link Secret Schema."""

class Meta:
"""AnoncredsLinkSecret schema metadata."""

model_class = AnoncredsLinkSecret
unknown = EXCLUDE

nonce = fields.Str(
required=True,
validate=NUM_STR_WHOLE_VALIDATE,
metadata={
"description": "Nonce in credential abstract",
"example": NUM_STR_WHOLE_EXAMPLE,
},
)

cred_def_id = fields.Str(
required=True,
validate=INDY_CRED_DEF_ID_VALIDATE,
metadata={
"description": "Credential definition identifier",
"example": INDY_CRED_DEF_ID_EXAMPLE,
},
)

key_correctness_proof = fields.Nested(
IndyKeyCorrectnessProofSchema(),
required=True,
metadata={"description": "Key correctness proof"},
)


class DidcommSignedAttachment(BaseModel):
"""Didcomm Signed Attachment Model."""

class Meta:
"""DidcommSignedAttachment metadata."""

schema_class = "DidcommSignedAttachmentSchema"

def __init__(
self,
algs_supported: Sequence[str] = None,
did_methods_supported: Sequence[str] = None,
nonce: str = None,
**kwargs,
):
"""Initialize values for DidcommSignedAttachment."""
super().__init__(**kwargs)
self.algs_supported = algs_supported
self.did_methods_supported = did_methods_supported
self.nonce = nonce


class DidcommSignedAttachmentSchema(BaseModelSchema):
"""Didcomm Signed Attachment Schema."""

class Meta:
"""Didcomm signed attachment schema metadata."""

model_class = DidcommSignedAttachment
unknown = EXCLUDE

algs_supported = fields.List(fields.Str(), required=True)

did_methods_supported = fields.List(fields.Str(), required=True)

nonce = fields.Str(
required=True,
validate=NUM_STR_WHOLE_VALIDATE,
metadata={
"description": "Nonce in credential abstract",
"example": NUM_STR_WHOLE_EXAMPLE,
},
)


class BindingMethod(BaseModel):
"""Binding Method Model."""

class Meta:
"""Binding method metadata."""

schema_class = "BindingMethodSchema"

def __init__(
self,
anoncreds_link_secret: Union[dict, AnoncredsLinkSecret] = None,
didcomm_signed_attachment: Union[dict, DidcommSignedAttachment] = None,
**kwargs,
):
"""Initialize values for DidcommSignedAttachment."""
super().__init__(**kwargs)
self.anoncreds_link_secret = anoncreds_link_secret
self.didcomm_signed_attachment = didcomm_signed_attachment


class BindingMethodSchema(BaseModelSchema):
"""VCDI Binding Method Schema."""

class Meta:
"""VCDI binding method schema metadata."""

model_class = BindingMethod
unknown = EXCLUDE

anoncreds_link_secret = fields.Nested(AnoncredsLinkSecretSchema, required=False)
didcomm_signed_attachment = fields.Nested(
DidcommSignedAttachmentSchema, required=True
)


class VCDICredAbstract(BaseModel):
"""VCDI Credential Abstract."""

class Meta:
"""VCDI credential abstract metadata."""

schema_class = "VCDICredAbstractSchema"

def __init__(
self,
data_model_versions_supported: Sequence[str] = None,
binding_required: str = None,
binding_method: str = None,
credential: Union[dict, VerifiableCredential] = None,
**kwargs,
):
"""Initialize vcdi cred abstract object.
Args:
data_model_versions_supported: supported versions for data model
binding_required: boolean value
binding_methods: required if binding_required is true
credential: credential object
"""
super().__init__(**kwargs)
self.data_model_versions_supported = data_model_versions_supported
self.binding_required = binding_required
self.binding_method = binding_method
self.credential = credential


class VCDICredAbstractSchema(BaseModelSchema):
"""VCDI Credential Abstract Schema."""

class Meta:
"""VCDICredAbstractSchema metadata."""

model_class = VCDICredAbstract
unknown = EXCLUDE

data_model_versions_supported = fields.List(
fields.Str(), required=True, metadata={"description": "", "example": ""}
)

binding_required = fields.Bool(
required=False, metadata={"description": "", "example": ""}
)

binding_method = fields.Nested(
BindingMethodSchema(),
required=binding_required,
metadata={"description": "", "example": ""},
)

credential = fields.Nested(
CredentialSchema(),
required=True,
metadata={"description": "", "example": ""},
)
Loading

0 comments on commit 88a7094

Please sign in to comment.