Skip to content

Commit

Permalink
draft: vcdi proposal format integration
Browse files Browse the repository at this point in the history
Signed-off-by: supersonicwisd1 <[email protected]>
  • Loading branch information
supersonicwisd1 committed Mar 6, 2024
1 parent 1535702 commit 7249eee
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 14 deletions.
73 changes: 73 additions & 0 deletions aries_cloudagent/messaging/credential_definitions/vcdi/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""Credential definition utilities."""

import re

from marshmallow import fields

from ....core.profile import Profile
from ...models.openapi import OpenAPISchema
from ...valid import (
VCDI_CRED_DEF_ID_EXAMPLE,
VCDI_CRED_DEF_ID_VALIDATE,
VCDI_DID_EXAMPLE,
VCDI_DID_VALIDATE,
VCDI_SCHEMA_ID_EXAMPLE,
VCDI_SCHEMA_ID_VALIDATE,
VCDI_VERSION_EXAMPLE,
VCDI_VERSION_VALIDATE,
)

CRED_DEF_SENT_RECORD_TYPE = "cred_def_sent"


class VCDICredDefQueryStringSchema(OpenAPISchema):
"""Query string parameters for credential definition searches."""

schema_id = fields.Str(
required=False,
validate=VCDI_SCHEMA_ID_VALIDATE,
metadata={
"description": "Schema identifier",
"example": VCDI_SCHEMA_ID_EXAMPLE,
},
)
schema_issuer_did = fields.Str(
required=False,
validate=VCDI_DID_VALIDATE,
metadata={"description": "Schema issuer DID", "example": VCDI_DID_EXAMPLE},
)
schema_name = fields.Str(
required=False, metadata={"description": "Schema name", "example": "membership"}
)
schema_version = fields.Str(
required=False,
validate=VCDI_VERSION_VALIDATE,
metadata={"description": "Schema version", "example": VCDI_VERSION_EXAMPLE},
)
issuer_did = fields.Str(
required=False,
validate=VCDI_DID_VALIDATE,
metadata={"description": "Issuer DID", "example": VCDI_DID_EXAMPLE},
)
cred_def_id = fields.Str(
required=False,
validate=VCDI_CRED_DEF_ID_VALIDATE,
metadata={
"description": "Credential definition id",
"example": VCDI_CRED_DEF_ID_EXAMPLE,
},
)


CRED_DEF_TAGS = list(vars(VCDICredDefQueryStringSchema).get("_declared_fields", []))

CRED_DEF_EVENT_PREFIX = "acapy::CRED_DEF::"
EVENT_LISTENER_PATTERN = re.compile(f"^{CRED_DEF_EVENT_PREFIX}(.*)?$")


async def notify_cred_def_event(profile: Profile, cred_def_id: str, meta_data: dict):
"""Send notification for a cred def post-process event."""
await profile.notify(
CRED_DEF_EVENT_PREFIX + cred_def_id,
meta_data,
)
73 changes: 73 additions & 0 deletions aries_cloudagent/messaging/valid.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,19 @@ def __init__(self):
error="Value {input} is not an indy decentralized identifier (DID)",
)

class VcdiDID(Regexp):
"""Validate value against vcdi DID."""

EXAMPLE = "WgWxqztrNooG92RXvxSTWv"
PATTERN = re.compile(rf"^(did:key:)?[{B58}]{{21,22}}$")

def __init__(self):
"""Initialize the instance."""

super().__init__(
VcdiDID.PATTERN,
error="Value {input} is not an vcdi decentralized identifier (DID)",
)

class DIDValidation(Regexp):
"""Validate value against any valid DID spec."""
Expand Down Expand Up @@ -444,6 +457,26 @@ def __init__(self):
error="Value {input} is not an indy credential definition identifier",
)

class VcdiCredDefId(Regexp):
"""Validate value against vcdi credential definition identifier specification."""

EXAMPLE = "WgWxqztrNooG92RXvxSTWv:3:CL:20:tag"
PATTERN = (
rf"^([{B58}]{{21,22}})" # issuer DID
f":3" # cred def id marker
f":CL" # sig alg
rf":(([1-9][0-9]*)|([{B58}]{{21,22}}:2:.+:[0-9.]+))" # schema txn / id
f":(.+)?$" # tag
)

def __init__(self):
"""Initialize the instance."""

super().__init__(
VcdiCredDefId.PATTERN,
error="Value {input} is not an vcdi credential definition identifier",
)


class IndyVersion(Regexp):
"""Validate value against indy version specification."""
Expand All @@ -459,6 +492,20 @@ def __init__(self):
error="Value {input} is not an indy version (use only digits and '.')",
)

class VcdiVersion(Regexp):
"""Validate value against vcdi version specification."""

EXAMPLE = "0.1"
PATTERN = r"^[0-9.]+$"

def __init__(self):
"""Initialize the instance."""

super().__init__(
VcdiVersion.PATTERN,
error="Value {input} is not an vcdi version (use only digits and '.')",
)


class IndySchemaId(Regexp):
"""Validate value against indy schema identifier specification."""
Expand All @@ -474,6 +521,20 @@ def __init__(self):
error="Value {input} is not an indy schema identifier",
)

class VcdiSchemaId(Regexp):
"""Validate value against vcdi schema identifier specification."""

EXAMPLE = "WgWxqztrNooG92RXvxSTWv:2:schema_name:1.0"
PATTERN = rf"^[{B58}]{{21,22}}:2:.+:[0-9.]+$"

def __init__(self):
"""Initialize the instance."""

super().__init__(
VcdiSchemaId.PATTERN,
error="Value {input} is not an vcdi schema identifier",
)


class IndyRevRegId(Regexp):
"""Validate value against indy revocation registry identifier specification."""
Expand Down Expand Up @@ -938,6 +999,9 @@ def __init__(
INDY_DID_VALIDATE = IndyDID()
INDY_DID_EXAMPLE = IndyDID.EXAMPLE

VCDI_DID_VALIDATE = VcdiDID()
VCDI_DID_EXAMPLE = VcdiDID.EXAMPLE

GENERIC_DID_VALIDATE = MaybeIndyDID()
GENERIC_DID_EXAMPLE = MaybeIndyDID.EXAMPLE

Expand All @@ -947,9 +1011,15 @@ def __init__(
INDY_SCHEMA_ID_VALIDATE = IndySchemaId()
INDY_SCHEMA_ID_EXAMPLE = IndySchemaId.EXAMPLE

VCDI_SCHEMA_ID_VALIDATE = VcdiSchemaId()
VCDI_SCHEMA_ID_EXAMPLE = VcdiSchemaId.EXAMPLE

INDY_CRED_DEF_ID_VALIDATE = IndyCredDefId()
INDY_CRED_DEF_ID_EXAMPLE = IndyCredDefId.EXAMPLE

VCDI_CRED_DEF_ID_VALIDATE = VcdiCredDefId()
VCDI_CRED_DEF_ID_EXAMPLE = VcdiCredDefId.EXAMPLE

INDY_REV_REG_ID_VALIDATE = IndyRevRegId()
INDY_REV_REG_ID_EXAMPLE = IndyRevRegId.EXAMPLE

Expand All @@ -959,6 +1029,9 @@ def __init__(
INDY_VERSION_VALIDATE = IndyVersion()
INDY_VERSION_EXAMPLE = IndyVersion.EXAMPLE

VCDI_VERSION_VALIDATE = VcdiVersion()
VCDI_VERSION_EXAMPLE = VcdiVersion.EXAMPLE

INDY_PREDICATE_VALIDATE = IndyPredicate()
INDY_PREDICATE_EXAMPLE = IndyPredicate.EXAMPLE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,8 @@
GET_CRED_DEF,
IndyLedgerRequestsExecutor,
)
from ......messaging.credential_definitions.util import (
CRED_DEF_SENT_RECORD_TYPE,
CredDefQueryStringSchema,
)
from ......messaging.credential_definitions.util import CRED_DEF_SENT_RECORD_TYPE
from ......messaging.credential_definitions.vcdi.util import VCDICredDefQueryStringSchema
from ......messaging.decorators.attach_decorator import AttachDecorator
from ......multitenant.base import BaseMultitenantManager
from ......revocation_anoncreds.models.issuer_cred_rev_record import IssuerCredRevRecord
Expand Down Expand Up @@ -94,7 +92,7 @@ def validate_fields(cls, message_type: str, attachment_data: Mapping):
"""
mapping = {
CRED_20_PROPOSAL: CredDefQueryStringSchema,
CRED_20_PROPOSAL: VCDICredDefQueryStringSchema,
CRED_20_OFFER: VCDICredAbstractSchema,
CRED_20_REQUEST: VCDICredRequestSchema,
CRED_20_ISSUE: VerifiableCredentialSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
CRED_20_PROPOSAL: {
V20CredFormat.Format.INDY.api: "hlindy/[email protected]",
V20CredFormat.Format.LD_PROOF.api: "aries/[email protected]",
V20CredFormat.Format.VC_DI.api: "didcomm/w3c-di-vc-offer@v0.1",
V20CredFormat.Format.VC_DI.api: "didcomm/[email protected]",
},
CRED_20_OFFER: {
V20CredFormat.Format.INDY.api: "hlindy/[email protected]",
Expand Down
24 changes: 16 additions & 8 deletions aries_cloudagent/protocols/issue_credential/v2_0/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@
INDY_SCHEMA_ID_VALIDATE,
INDY_VERSION_EXAMPLE,
INDY_VERSION_VALIDATE,
VCDI_CRED_DEF_ID_EXAMPLE,
VCDI_CRED_DEF_ID_VALIDATE,
VCDI_DID_EXAMPLE,
VCDI_DID_VALIDATE,
VCDI_SCHEMA_ID_EXAMPLE,
VCDI_SCHEMA_ID_VALIDATE,
VCDI_VERSION_EXAMPLE,
VCDI_VERSION_VALIDATE,
UUID4_EXAMPLE,
UUID4_VALIDATE,
)
Expand Down Expand Up @@ -181,35 +189,35 @@ class V20CredFilterVCDISchema(OpenAPISchema):
validate=INDY_CRED_DEF_ID_VALIDATE,
metadata={
"description": "Credential definition identifier",
"example": INDY_CRED_DEF_ID_EXAMPLE,
"example": VCDI_CRED_DEF_ID_EXAMPLE,
},
)
schema_id = fields.Str(
required=False,
validate=INDY_SCHEMA_ID_VALIDATE,
metadata={
"description": "Schema identifier",
"example": INDY_SCHEMA_ID_EXAMPLE,
"example": VCDI_SCHEMA_ID_EXAMPLE,
},
)
schema_issuer_did = fields.Str(
required=False,
validate=INDY_DID_VALIDATE,
metadata={"description": "Schema issuer DID", "example": INDY_DID_EXAMPLE},
validate=VCDI_DID_VALIDATE,
metadata={"description": "Schema issuer DID", "example": VCDI_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},
validate=VCDI_VERSION_VALIDATE,
metadata={"description": "Schema version", "example": VCDI_VERSION_EXAMPLE},
)
issuer_did = fields.Str(
required=False,
validate=INDY_DID_VALIDATE,
metadata={"description": "Credential issuer DID", "example": INDY_DID_EXAMPLE},
validate=VCDI_DID_VALIDATE,
metadata={"description": "Credential issuer DID", "example": VCDI_DID_EXAMPLE},
)


Expand Down

0 comments on commit 7249eee

Please sign in to comment.