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

fix: Added key id ref bypass on strict validation #837

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion x/did/types/diddoc_diddoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (didDoc DidDoc) Validate(allowedNamespaces []string) error {
IsUniqueStrList(), validation.Each(IsDIDUrl(allowedNamespaces, Empty, Empty, Required), HasPrefix(didDoc.Id)),
),
validation.Field(&didDoc.AssertionMethod,
IsUniqueStrList(), validation.Each(IsAssertionMethod(allowedNamespaces, didDoc))),
IsUniqueStrList(), validation.Each(IsAssertionMethod(allowedNamespaces, didDoc, false))),
validation.Field(&didDoc.CapabilityInvocation,
IsUniqueStrList(), validation.Each(IsDIDUrl(allowedNamespaces, Empty, Empty, Required), HasPrefix(didDoc.Id)),
),
Expand Down
2 changes: 1 addition & 1 deletion x/did/types/diddoc_diddoc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ var _ = DescribeTable("DIDDoc Validation tests", func(testCase DIDDocTestCase) {
},
AssertionMethod: []string{fmt.Sprintf("%s#fragment", ValidTestDID), func() string {
b, _ := json.Marshal(AssertionMethodJSONUnescaped{
Id: fmt.Sprintf("%s#fragment", ValidTestDID),
Id: fmt.Sprintf("%s#fragment-1", ValidTestDID),
Type: "Ed25519VerificationKey2018",
Controller: ValidTestDID,
PublicKeyBase58: &ValidEd25519VerificationKey2018VerificationMaterial, // arbitrarily chosen, loosely validated
Expand Down
8 changes: 6 additions & 2 deletions x/did/types/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func IsDIDUrl(allowedNamespaces []string, pathRule, queryRule, fragmentRule Vali
})
}

func IsAssertionMethod(allowedNamespaces []string, didDoc DidDoc) *CustomErrorRule {
func IsAssertionMethod(allowedNamespaces []string, didDoc DidDoc, bypass bool) *CustomErrorRule {
return NewCustomErrorRule(func(value interface{}) error {
casted, ok := value.(string)
if !ok {
Expand All @@ -126,7 +126,7 @@ func IsAssertionMethod(allowedNamespaces []string, didDoc DidDoc) *CustomErrorRu
}

return validation.ValidateStruct(&result,
validation.Field(&result.Id, validation.Required, IsAssertionMethod(allowedNamespaces, didDoc)),
validation.Field(&result.Id, validation.Required, IsAssertionMethod(allowedNamespaces, didDoc, true)),
validation.Field(&result.Controller, validation.Required, IsDID(allowedNamespaces)),
)
}
Expand All @@ -136,6 +136,10 @@ func IsAssertionMethod(allowedNamespaces []string, didDoc DidDoc) *CustomErrorRu
return errors.New("assertionMethod should be a valid DIDUrl or an Escaped JSON string with id, type and controller values")
}

if bypass {
return nil
}

for _, v := range didDoc.VerificationMethod {
if v.Id == casted {
return nil
Expand Down
Loading