Skip to content

Commit

Permalink
fix: Added key id ref bypass on strict validation (#837)
Browse files Browse the repository at this point in the history
* Loosened id ref

* Removed redundant
  • Loading branch information
Eengineer1 authored Jan 13, 2025
1 parent 6babe91 commit 5f68c5d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
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

0 comments on commit 5f68c5d

Please sign in to comment.