Skip to content

Commit 3099727

Browse files
committed
[fix]: id checking while register with namespace=""
1 parent 601953f commit 3099727

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

testutil/keeper/ssi.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func SsiKeeper(t testing.TB) (*keeper.Keeper, sdk.Context) {
3636
memStoreKey,
3737
"SsiParams",
3838
)
39+
paramsSubspace = paramsSubspace.WithKeyTable(types.ParamKeyTable())
3940
k := keeper.NewKeeper(
4041
cdc,
4142
storeKey,

x/ssi/verification/common_document_checks.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func documentIdentifier(docType string) string {
2020
}
2121

2222
func returnVersionNumIdx(namespace string) int {
23-
if namespace == "mainnet" {
23+
if namespace == "" {
2424
return 3
2525
} else {
2626
return 4
@@ -71,18 +71,32 @@ func IsValidID(Id string, namespace string, docType string) error {
7171

7272
// Mainnet Chain namespace check. If the document is registered on the mainnet chain,
7373
// the namespace should be empty
74+
var expectedLength int
7475
if namespace == "" {
75-
if len(docElements) != 3 {
76-
return fmt.Errorf("expected number of did id elements for mainnet to be 3, got %s", fmt.Sprint(len(docElements)))
76+
if docIdentifier == "sch" {
77+
expectedLength = 4
78+
} else {
79+
expectedLength = 3
7780
}
7881
docMethodSpecificId = 2
7982
} else {
83+
if docIdentifier == "sch" {
84+
expectedLength = 5
85+
} else {
86+
expectedLength = 4
87+
}
88+
docMethodSpecificId = 3
89+
8090
docNamespace := docElements[docNamespaceIndex]
8191
if namespace != docNamespace {
8292
return fmt.Errorf("expected did namespace %s, got %s", namespace, docNamespace)
8393
}
8494
}
8595

96+
if len(docElements) != expectedLength {
97+
return fmt.Errorf("expected %s id elements, got %s", fmt.Sprintf("%d", expectedLength), fmt.Sprintf("%d", len(docElements)))
98+
}
99+
86100
// Check if method-specific-id string is alphanumeric and
87101
// has the minimum required character length of 32
88102
isProperMethodSpecificId, err := regexp.MatchString(

0 commit comments

Comments
 (0)