Skip to content

Commit

Permalink
updating the rebase with latest VC_DI changes
Browse files Browse the repository at this point in the history
Signed-off-by: Golda Velez <[email protected]>
  • Loading branch information
supersonicwisd1 authored and gvelez17 committed Mar 8, 2024
1 parent d5bc4fe commit b464fe5
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 112 deletions.
101 changes: 51 additions & 50 deletions aries_cloudagent/anoncreds/issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,60 +633,61 @@ async def create_credential(

return credential.to_json()

async def create_credential_vc_di(
self,
credential_offer: dict,
credential_request: dict,
credential_values: dict,
) -> str:
"""Create Credential."""
anoncreds_registry = self.profile.inject(AnonCredsRegistry)
schema_id = credential_offer["schema_id"]
schema_result = await anoncreds_registry.get_schema(self.profile, schema_id)
cred_def_id = credential_offer["cred_def_id"]
schema_attributes = schema_result.schema_value.attr_names

async def create_credential_vc_di(
self,
credential_offer: dict,
credential_request: dict,
credential_values: dict,
) -> str:
"""Create Credential."""
anoncreds_registry = self.profile.inject(AnonCredsRegistry)
schema_id = credential_offer["schema_id"]
schema_result = await anoncreds_registry.get_schema(self.profile, schema_id)
cred_def_id = credential_offer["cred_def_id"]
schema_attributes = schema_result.schema_value.attr_names

try:
async with self.profile.session() as session:
cred_def = await session.handle.fetch(CATEGORY_CRED_DEF, cred_def_id)
cred_def_private = await session.handle.fetch(
CATEGORY_CRED_DEF_PRIVATE, cred_def_id
)
except AskarError as err:
raise AnonCredsIssuerError("Error retrieving credential definition") from err

if not cred_def or not cred_def_private:
raise AnonCredsIssuerError(
"Credential definition not found for credential issuance"
)

raw_values = {}
for attribute in schema_attributes:
# Ensure every attribute present in schema to be set.
# Extraneous attribute names are ignored.
try:
credential_value = credential_values[attribute]
except KeyError:
async with self.profile.session() as session:
cred_def = await session.handle.fetch(CATEGORY_CRED_DEF, cred_def_id)
cred_def_private = await session.handle.fetch(
CATEGORY_CRED_DEF_PRIVATE, cred_def_id
)
except AskarError as err:
raise AnonCredsIssuerError(
"Provided credential values are missing a value "
f"for the schema attribute '{attribute}'"
"Error retrieving credential definition"
) from err

if not cred_def or not cred_def_private:
raise AnonCredsIssuerError(
"Credential definition not found for credential issuance"
)

raw_values[attribute] = str(credential_value)
raw_values = {}
for attribute in schema_attributes:
# Ensure every attribute present in schema to be set.
# Extraneous attribute names are ignored.
try:
credential_value = credential_values[attribute]
except KeyError:
raise AnonCredsIssuerError(
"Provided credential values are missing a value "
f"for the schema attribute '{attribute}'"
)

raw_values[attribute] = str(credential_value)

try:
credential = await asyncio.get_event_loop().run_in_executor(
None,
lambda: Credential.create(
cred_def.raw_value,
cred_def_private.raw_value,
credential_offer,
credential_request,
raw_values,
),
)
except AnoncredsError as err:
raise AnonCredsIssuerError("Error creating credential") from err
try:
credential = await asyncio.get_event_loop().run_in_executor(
None,
lambda: Credential.create(
cred_def.raw_value,
cred_def_private.raw_value,
credential_offer,
credential_request,
raw_values,
),
)
except AnoncredsError as err:
raise AnonCredsIssuerError("Error creating credential") from err

return credential.to_json()
return credential.to_json()
46 changes: 43 additions & 3 deletions aries_cloudagent/indy/models/cred_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ def __init__(
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,
Expand Down Expand Up @@ -230,6 +236,12 @@ def __init__(
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)
Expand All @@ -244,9 +256,35 @@ class DidcommSignedAttachmentSchema(BaseModelSchema):
)


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
Expand All @@ -263,7 +301,7 @@ class Meta:

def __init__(
self,
data_model_versions_supported: str = None,
data_model_versions_supported: Sequence[str] = None,
binding_required: str = None,
binding_methods: str = None,
credential: Union[dict, VerifiableCredential] = None,
Expand Down Expand Up @@ -294,7 +332,7 @@ class Meta:
unknown = EXCLUDE

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

binding_required = fields.Bool(
Expand All @@ -308,5 +346,7 @@ class Meta:
)

credential = fields.Nested(
CredentialSchema(), required=True, metadata={"description": "", "example": ""}
CredentialSchema(),
required=True,
metadata={"description": "", "example": ""},
)
84 changes: 79 additions & 5 deletions aries_cloudagent/indy/models/cred_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class Meta:
)


class BindingProof(BaseModel):
class AnoncredsLinkSecret(BaseModel):
"""Binding proof model."""

class Meta:
Expand All @@ -109,13 +109,13 @@ def __init__(
self.nonce = nonce


class BindingProofSchema(BaseModelSchema):
class AnoncredsLinkSecretSchema(BaseModelSchema):
"""VCDI credential request schema."""

class Meta:
"""VCDI credential request schema metadata."""

model_class = BindingProof
model_class = AnoncredsLinkSecret
unknown = EXCLUDE

entropy = fields.Str(
Expand Down Expand Up @@ -148,6 +148,76 @@ class Meta:
)


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

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

schema_class = "DidcommSignedAttachmentSchema"

def __init__(self, attachment_id: str = None, **kwargs):
"""Initialize DidcommSignedAttachment."""
super().__init__(**kwargs)
self.attachment_id = attachment_id


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

class Meta:
"""Didcomm Signed Attachment schema metadata."""

model_class = DidcommSignedAttachment
unknown = EXCLUDE

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


class BindingProof(BaseModel):
"""Binding Proof Model."""

class Meta:
"""Binding proof metadata."""

schema_class = "BindingProofSchema"

def __init__(
self,
anoncreds_link_secret: str = None,
didcomm_signed_attachment: str = None,
**kwargs,
):
"""Initialize binding proof."""
super().__init__(**kwargs)
self.anoncreds_link_secret = anoncreds_link_secret
self.didcomm_signed_attachment = didcomm_signed_attachment


class BindingProofSchema(BaseModelSchema):
"""Binding Proof Schema."""

class Meta:
"""Binding proof schema metadata."""

model_class = BindingProof
unknown = EXCLUDE

anoncreds_link_secret = fields.Nested(
AnoncredsLinkSecretSchema(),
required=True,
metadata={"description": "", "example": ""},
)

didcomm_signed_attachment = fields.Nested(
DidcommSignedAttachmentSchema(),
required=True,
metadata={"description": "", "example": ""},
)


class VCDICredRequest(BaseModel):
"""VCDI credential request model."""

Expand Down Expand Up @@ -177,8 +247,12 @@ class Meta:
model_class = VCDICredRequest
unknown = EXCLUDE

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

binding_proof = fields.str(required=True, metadata={"description": "", "example": ""})
binding_proof = fields.Nested(
BindingProofSchema(),
required=True,
metadata={"description": "", "example": ""},
)
46 changes: 0 additions & 46 deletions aries_cloudagent/protocols/issue_credential/v2_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,46 +213,6 @@ class V20CredFilterVCDISchema(OpenAPISchema):
)


class V20CredFilterVCDISchema(OpenAPISchema):
"""VCDI credential filtration criteria."""

cred_def_id = fields.Str(
required=False,
validate=INDY_CRED_DEF_ID_VALIDATE,
metadata={
"description": "Credential definition identifier",
"example": INDY_CRED_DEF_ID_EXAMPLE,
},
)
schema_id = fields.Str(
required=False,
validate=INDY_SCHEMA_ID_VALIDATE,
metadata={
"description": "Schema identifier",
"example": INDY_SCHEMA_ID_EXAMPLE,
},
)
schema_issuer_did = fields.Str(
required=False,
validate=INDY_DID_VALIDATE,
metadata={"description": "Schema issuer DID", "example": INDY_DID_EXAMPLE},
)
schema_name = fields.Str(
required=False,
metadata={"description": "Schema name", "example": "preferences"},
)
schema_version = fields.Str(
required=False,
validate=INDY_VERSION_VALIDATE,
metadata={"description": "Schema version", "example": INDY_VERSION_EXAMPLE},
)
issuer_did = fields.Str(
required=False,
validate=INDY_DID_VALIDATE,
metadata={"description": "Credential issuer DID", "example": INDY_DID_EXAMPLE},
)


class V20CredFilterSchema(OpenAPISchema):
"""Credential filtration criteria."""

Expand All @@ -273,12 +233,6 @@ class V20CredFilterSchema(OpenAPISchema):
metadata={"description": "Credential filter for vc_di"},
)

vc_di = fields.Nested(
V20CredFilterVCDISchema,
required=False,
metadata={"description": "Credential filter for vc_di"},
)

@validates_schema
def validate_fields(self, data, **kwargs):
"""Validate schema fields.
Expand Down
Loading

0 comments on commit b464fe5

Please sign in to comment.