"""Revocation artifacts."""
from typing import Sequence
from marshmallow import EXCLUDE, fields, validate
from ...messaging.models.base import BaseModel, BaseModelSchema
from ...messaging.valid import (
BASE58_SHA256_HASH_EXAMPLE,
BASE58_SHA256_HASH_VALIDATE,
INDY_CRED_DEF_ID_EXAMPLE,
INDY_CRED_DEF_ID_VALIDATE,
INDY_REV_REG_ID_EXAMPLE,
INDY_REV_REG_ID_VALIDATE,
INDY_VERSION_EXAMPLE,
INDY_VERSION_VALIDATE,
NATURAL_NUM_EXAMPLE,
NATURAL_NUM_VALIDATE,
)
[docs]class IndyRevRegDefValuePublicKeysAccumKey(BaseModel):
"""Indy revocation registry definition value public keys accum key."""
def __init__(self, z: str = None):
"""Initialize."""
self.z = z
[docs]class IndyRevRegDefValuePublicKeysAccumKeySchema(BaseModelSchema):
"""Indy revocation registry definition value public keys accum key schema."""
z = fields.Str(
metadata={
"description": "Value for z",
"example": "1 120F522F81E6B7 1 09F7A59005C4939854",
}
)
[docs]class IndyRevRegDefValuePublicKeys(BaseModel):
"""Indy revocation registry definition value public keys."""
def __init__(self, accum_key: IndyRevRegDefValuePublicKeysAccumKey = None):
"""Initialize."""
self.accum_key = accum_key
[docs]class IndyRevRegDefValuePublicKeysSchema(BaseModelSchema):
"""Indy revocation registry definition value public keys schema."""
accum_key = fields.Nested(
IndyRevRegDefValuePublicKeysAccumKeySchema(), data_key="accumKey"
)
[docs]class IndyRevRegDefValue(BaseModel):
"""Indy revocation registry definition value."""
def __init__(
self,
issuance_type: str = None,
max_cred_num: int = None,
public_keys: IndyRevRegDefValuePublicKeys = None,
tails_hash: str = None,
tails_location: str = None,
):
"""Initialize."""
self.issuance_type = issuance_type
self.max_cred_num = max_cred_num
self.public_keys = public_keys
self.tails_hash = tails_hash
self.tails_location = tails_location
[docs]class IndyRevRegDefValueSchema(BaseModelSchema):
"""Indy revocation registry definition value schema."""
issuance_type = fields.Str(
validate=validate.OneOf(["ISSUANCE_ON_DEMAND", "ISSUANCE_BY_DEFAULT"]),
data_key="issuanceType",
metadata={"description": "Issuance type"},
)
max_cred_num = fields.Int(
data_key="maxCredNum",
validate=NATURAL_NUM_VALIDATE,
metadata={
"description": "Maximum number of credentials; registry size",
"strict": True,
"example": NATURAL_NUM_EXAMPLE,
},
)
public_keys = fields.Nested(
IndyRevRegDefValuePublicKeysSchema(),
data_key="publicKeys",
metadata={"description": "Public keys"},
)
tails_hash = fields.Str(
data_key="tailsHash",
validate=BASE58_SHA256_HASH_VALIDATE,
metadata={
"description": "Tails hash value",
"example": BASE58_SHA256_HASH_EXAMPLE,
},
)
tails_location = fields.Str(
data_key="tailsLocation", metadata={"description": "Tails file location"}
)
[docs]class IndyRevRegDef(BaseModel):
"""Indy revocation registry definition."""
def __init__(
self,
ver: str = None,
id_: str = None,
revoc_def_type: str = None,
tag: str = None,
cred_def_id: str = None,
value: IndyRevRegDefValue = None,
):
"""Initialize."""
self.ver = ver
self.id_ = id_
self.revoc_def_type = revoc_def_type
self.tag = tag
self.cred_def_id = cred_def_id
self.value = value
[docs]class IndyRevRegDefSchema(BaseModelSchema):
"""Indy revocation registry definition schema."""
ver = fields.Str(
validate=INDY_VERSION_VALIDATE,
metadata={
"description": "Version of revocation registry definition",
"example": INDY_VERSION_EXAMPLE,
},
)
id_ = fields.Str(
data_key="id",
validate=INDY_REV_REG_ID_VALIDATE,
metadata={
"description": "Indy revocation registry identifier",
"example": INDY_REV_REG_ID_EXAMPLE,
},
)
revoc_def_type = fields.Str(
data_key="revocDefType",
validate=validate.Equal("CL_ACCUM"),
metadata={
"description": "Revocation registry type (specify CL_ACCUM)",
"example": "CL_ACCUM",
},
)
tag = fields.Str(metadata={"description": "Revocation registry tag"})
cred_def_id = fields.Str(
data_key="credDefId",
validate=INDY_CRED_DEF_ID_VALIDATE,
metadata={
"description": "Credential definition identifier",
"example": INDY_CRED_DEF_ID_EXAMPLE,
},
)
value = fields.Nested(
IndyRevRegDefValueSchema(),
metadata={"description": "Revocation registry definition value"},
)
[docs]class IndyRevRegEntryValue(BaseModel):
"""Indy revocation registry entry value."""
[docs] class Meta:
"""Model metadata."""
schema_class = "IndyRevRegEntryValueSchema"
def __init__(
self,
prev_accum: str = None,
accum: str = None,
revoked: Sequence[int] = None,
):
"""Initialize."""
self.prev_accum = prev_accum
self.accum = accum
self.revoked = revoked
[docs]class IndyRevRegEntryValueSchema(BaseModelSchema):
"""Indy revocation registry entry value schema."""
[docs] class Meta:
"""Schema metadata."""
model_class = "IndyRevRegEntryValue"
unknown = EXCLUDE
prev_accum = fields.Str(
data_key="prevAccum",
required=False,
metadata={
"description": "Previous accumulator value",
"example": "21 137AC810975E4 6 76F0384B6F23",
},
)
accum = fields.Str(
metadata={
"description": "Accumulator value",
"example": "21 11792B036AED0AAA12A4 4 298B2571FFC63A737",
}
)
revoked = fields.List(
fields.Int(metadata={"strict": True}),
required=False,
metadata={"description": "Revoked credential revocation identifiers"},
)
[docs]class IndyRevRegEntry(BaseModel):
"""Indy revocation registry entry."""
[docs] class Meta:
"""Model metadata."""
schema_class = "IndyRevRegEntrySchema"
def __init__(self, ver: str = None, value: IndyRevRegEntryValue = None):
"""Initialize."""
self.ver = ver
self.value = value
[docs]class IndyRevRegEntrySchema(BaseModelSchema):
"""Indy revocation registry entry schema."""
[docs] class Meta:
"""Schema metadata."""
model_class = IndyRevRegEntry
unknown = EXCLUDE
ver = fields.Str(
validate=INDY_VERSION_VALIDATE,
metadata={
"description": "Version of revocation registry entry",
"example": INDY_VERSION_EXAMPLE,
},
)
value = fields.Nested(
IndyRevRegEntryValueSchema(),
metadata={"description": "Revocation registry entry value"},
)