Skip to content

Commit

Permalink
fix pydantic did document validation
Browse files Browse the repository at this point in the history
Signed-off-by: pstlouis <[email protected]>
  • Loading branch information
PatStLouis committed Jan 9, 2025
1 parent 2af5410 commit ca356fe
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions server/app/models/did_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ class VerificationMethod(BaseModel):
type: Union[str, List[str]] = Field()
controller: str = Field()

# @field_validator("id")
# @classmethod
# def verification_method_id_validator(cls, value):
# assert value.startswith(f"did:web:{settings.DOMAIN}")
# return value
@field_validator("id")
@classmethod
def verification_method_id_validator(cls, value):
assert value.startswith('did:')
return value

@field_validator("type")
@classmethod
Expand All @@ -39,12 +39,11 @@ def verification_method_type_validator(cls, value):
], "Expected type Multikey or JsonWebKey"
return value

# @field_validator("controller")
# @classmethod
# def verification_method_controller_validator(cls, value):
# assert DID_WEB_REGEX.match(value), "Expected controller to be a DID."
# assert value.startswith(f"did:web:{settings.DOMAIN}")
# return value
@field_validator("controller")
@classmethod
def verification_method_controller_validator(cls, value):
assert value.startswith('did:')
return value


class JsonWebKey(BaseModel):
Expand Down Expand Up @@ -81,11 +80,11 @@ class Service(BaseModel):
type: Union[str, List[str]] = Field()
serviceEndpoint: str = Field()

# @field_validator("id")
# @classmethod
# def service_id_validator(cls, value):
# assert value.startswith(f"did:web:{settings.DOMAIN}")
# return value
@field_validator("id")
@classmethod
def service_id_validator(cls, value):
assert value.startswith('did:')
return value

@field_validator("serviceEndpoint")
@classmethod
Expand Down Expand Up @@ -131,11 +130,11 @@ def context_validator(cls, value):
assert value[0] == "https://www.w3.org/ns/did/v1", "Invalid context."
return value

# @field_validator("id")
# @classmethod
# def id_validator(cls, value):
# assert DID_WEB_REGEX.match(value), "Expected id to be a DID."
# return value
@field_validator("id")
@classmethod
def id_validator(cls, value):
assert value.startswith('did:')
return value


class SecuredDidDocument(DidDocument):
Expand Down

0 comments on commit ca356fe

Please sign in to comment.