Skip to content

Commit

Permalink
Loosened id ref
Browse files Browse the repository at this point in the history
  • Loading branch information
Eengineer1 committed Jan 13, 2025
1 parent 6babe91 commit 086813a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 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
4 changes: 2 additions & 2 deletions x/did/types/diddoc_diddoc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ var _ = DescribeTable("DIDDoc Validation tests", func(testCase DIDDocTestCase) {
VerificationMaterial: ValidEd25519VerificationKey2020VerificationMaterial,
},
},
AssertionMethod: []string{fmt.Sprintf("%s#fragment", ValidTestDID), func() string {
AssertionMethod: []string{fmt.Sprintf("%s#fragment-1", 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 086813a

Please sign in to comment.