From 086813a5b20a97b9a635b4a85b9c7c40ca943328 Mon Sep 17 00:00:00 2001 From: Tasos Derisiotis <50984242+Eengineer1@users.noreply.github.com> Date: Mon, 13 Jan 2025 14:34:03 +0200 Subject: [PATCH 1/2] Loosened id ref --- x/did/types/diddoc_diddoc.go | 2 +- x/did/types/diddoc_diddoc_test.go | 4 ++-- x/did/types/validate.go | 8 ++++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/x/did/types/diddoc_diddoc.go b/x/did/types/diddoc_diddoc.go index ce1ff8202..96d60f3ab 100644 --- a/x/did/types/diddoc_diddoc.go +++ b/x/did/types/diddoc_diddoc.go @@ -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)), ), diff --git a/x/did/types/diddoc_diddoc_test.go b/x/did/types/diddoc_diddoc_test.go index c3ebd4e79..fbf963e3d 100644 --- a/x/did/types/diddoc_diddoc_test.go +++ b/x/did/types/diddoc_diddoc_test.go @@ -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 diff --git a/x/did/types/validate.go b/x/did/types/validate.go index 0e5407be6..8d1aa22b0 100644 --- a/x/did/types/validate.go +++ b/x/did/types/validate.go @@ -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 { @@ -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)), ) } @@ -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 From f0019e79cd17e173083dc3804106b9ee65f83253 Mon Sep 17 00:00:00 2001 From: Tasos Derisiotis <50984242+Eengineer1@users.noreply.github.com> Date: Mon, 13 Jan 2025 14:58:40 +0200 Subject: [PATCH 2/2] Removed redundant --- x/did/types/diddoc_diddoc_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/did/types/diddoc_diddoc_test.go b/x/did/types/diddoc_diddoc_test.go index fbf963e3d..519db3905 100644 --- a/x/did/types/diddoc_diddoc_test.go +++ b/x/did/types/diddoc_diddoc_test.go @@ -271,7 +271,7 @@ var _ = DescribeTable("DIDDoc Validation tests", func(testCase DIDDocTestCase) { VerificationMaterial: ValidEd25519VerificationKey2020VerificationMaterial, }, }, - AssertionMethod: []string{fmt.Sprintf("%s#fragment-1", ValidTestDID), func() string { + AssertionMethod: []string{fmt.Sprintf("%s#fragment", ValidTestDID), func() string { b, _ := json.Marshal(AssertionMethodJSONUnescaped{ Id: fmt.Sprintf("%s#fragment-1", ValidTestDID), Type: "Ed25519VerificationKey2018",