-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: changed namespace validation check
- Loading branch information
1 parent
cbaedc0
commit 2a41872
Showing
6 changed files
with
93 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
func chainNamespaceValidation(docId string, validChainNamespace string) error { | ||
documentChainNamespace := getDocumentChainNamespace(docId) | ||
if documentChainNamespace != validChainNamespace { | ||
return fmt.Errorf( | ||
"expected namespace for id %v to be %v, got %v", | ||
docId, | ||
validChainNamespace, | ||
documentChainNamespace, | ||
) | ||
} else { | ||
return nil | ||
} | ||
} | ||
|
||
// DidDocNamespaceValidation validates the namespace in Did Document | ||
func DidChainNamespaceValidation(didDoc *Did, validChainNamespace string) error { | ||
// Subject ID check | ||
if err := chainNamespaceValidation(didDoc.Id, validChainNamespace); err != nil { | ||
return err | ||
} | ||
|
||
// Controllers check | ||
for _, controller := range didDoc.Controller { | ||
if err := chainNamespaceValidation(controller, validChainNamespace); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
// Verification Method ID checks | ||
for _, vm := range didDoc.VerificationMethod { | ||
didId, _ := GetElementsFromDidUrl(vm.Id) | ||
if err := chainNamespaceValidation(didId, validChainNamespace); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
// Verification Relationships check | ||
vmRelationshipList := [][]string{ | ||
didDoc.Authentication, | ||
didDoc.AssertionMethod, | ||
didDoc.KeyAgreement, | ||
didDoc.CapabilityDelegation, | ||
didDoc.CapabilityInvocation, | ||
} | ||
|
||
for _, vmRelationship := range vmRelationshipList { | ||
// didUrl check and presence in verification methods | ||
for _, id := range vmRelationship { | ||
if err := chainNamespaceValidation(id, validChainNamespace); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters