Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VCDI filter Schema #10

Closed
wants to merge 10 commits into from
Closed
2 changes: 2 additions & 0 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ jobs:
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,' -e 's/^docs-v//')
# Copy all of the root level md files into the docs folder for deployment, tweaking the relative paths
for i in *.md; do sed -e "s#docs/#./#g" $i >docs/$i; done
# Fix references in DevReadMe.md to moved files
sed -e "s#\.\./\.\./#../#" docs/features/DevReadMe.md >tmp.md; mv tmp.md docs/features/DevReadMe.md
# Populate overrides for the current version, and then remove to not apply if VERSION is main branch
OVERRIDE=overrides/main.html
echo -e "{% extends \"base.html\" %}\n\n{% block outdated %}\n You are viewing the documentation for ACA-Py Release $ALIAS.\n{% endblock %}" >$OVERRIDE
Expand Down
81 changes: 48 additions & 33 deletions CHANGELOG.md

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions aries_cloudagent/anoncreds/issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,3 +632,62 @@ async def create_credential(
raise AnonCredsIssuerError("Error creating credential") from err

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

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:
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

return credential.to_json()
200 changes: 199 additions & 1 deletion aries_cloudagent/indy/models/cred_abstract.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Cred abstract artifacts to attach to RFC 453 messages."""

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

from marshmallow import EXCLUDE, fields

Expand Down Expand Up @@ -152,3 +153,200 @@ 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_methods: 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_methods = binding_methods
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
Loading