:art: Update regex validators for AnonCreds models
There are 3 AnonCreds model validators:
class AnoncredsCredDefId(Regexp):
"""Validate value against anoncreds credential definition identifier specification."""
EXAMPLE = "did:(method):3:CL:20:tag"
PATTERN = r"^(.+$)"
def __init__(self):
"""Initialize the instance."""
super().__init__(
AnoncredsCredDefId.PATTERN,
error="Value {input} is not an anoncreds credential definition identifier",
)
class AnoncredsRevRegId(Regexp):
"""Validate value against anoncreds revocation registry identifier specification."""
EXAMPLE = "did:(method):4:did:<method>:3:CL:20:tag:CL_ACCUM:0"
PATTERN = r"^(.+$)"
def __init__(self):
"""Initialize the instance."""
super().__init__(
AnoncredsRevRegId.PATTERN,
error="Value {input} is not an anoncreds revocation registry identifier",
)
class AnoncredsSchemaId(Regexp):
"""Validate value against indy schema identifier specification."""
EXAMPLE = "did:(method):2:schema_name:1.0"
PATTERN = r"^(.+$)"
def __init__(self):
"""Initialize the instance."""
super().__init__(
AnoncredsSchemaId.PATTERN,
error="Value {input} is not an anoncreds schema identifier",
)
These patterns (^(.+$)) are just matching on non-empty strings.
There should be a to-do assigned to defining these validation patterns, with some tests asserting that they pass on expected values, and fail on bad ones.
Potentially what the patterns should be, as generated for me by GPT:
class AnoncredsCredDefId(Regexp):
"""Validate value against anoncreds credential definition identifier specification."""
EXAMPLE = "did:(method):3:CL:20:tag"
PATTERN = r"^did:(?P<method>[a-zA-Z0-9]+):3:CL:(?P<schema_id>\d+):(?P<tag>[a-zA-Z0-9_-]+)$"
class AnoncredsRevRegId(Regexp):
"""Validate value against anoncreds revocation registry identifier specification."""
EXAMPLE = "did:(method):4:did:<method>:3:CL:20:tag:CL_ACCUM:0"
PATTERN = r"^did:(?P<method>[a-zA-Z0-9]+):4:did:(?P<method>[a-zA-Z0-9]+):3:CL:(?P<schema_id>\d+):(?P<tag>[a-zA-Z0-9_-]+):CL_ACCUM:(.+)$"
class AnoncredsSchemaId(Regexp):
"""Validate value against indy schema identifier specification."""
EXAMPLE = "did:(method):2:schema_name:1.0"
PATTERN = r"^did:(?P<method>[a-zA-Z0-9]+):2:(?P<schema_name>[a-zA-Z0-9_-]+):(?P<version>[0-9.]+)$"
I would just need assistance / input with regards to these pattern. If someone can provide a range of possible, valid values for these, then we can write some tests too
I was trying to just allow anything here because I didn't know what type of pattern we could use. I don't think we can have the numbers :2,:3,:4 in the validators. Really any method can have their own patterns for the schema id's, cred_def_id's etc.
I think we could have a pattern did:<any-string only letters>:<any string> for any did method.