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

🎨 Update regex validators for AnonCreds models #3519

Open
ff137 opened this issue Feb 13, 2025 · 1 comment · May be fixed by #3520
Open

🎨 Update regex validators for AnonCreds models #3519

ff137 opened this issue Feb 13, 2025 · 1 comment · May be fixed by #3520

Comments

@ff137
Copy link
Contributor

ff137 commented Feb 13, 2025

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

ff137 added a commit to didx-xyz/acapy that referenced this issue Feb 13, 2025
@ff137 ff137 linked a pull request Feb 13, 2025 that will close this issue
@jamshale
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants