-
Notifications
You must be signed in to change notification settings - Fork 42
/
tx_msg_update_did_doc_payload.go
78 lines (65 loc) · 2.22 KB
/
tx_msg_update_did_doc_payload.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package types
import (
"github.com/cheqd/cheqd-node/x/did/utils"
validation "github.com/go-ozzo/ozzo-validation/v4"
)
var _ IdentityMsg = &MsgUpdateDidDocPayload{}
func (msg *MsgUpdateDidDocPayload) GetSignBytes() []byte {
bytes, err := msg.Marshal()
if err != nil {
panic(err)
}
return bytes
}
func (msg *MsgUpdateDidDocPayload) ToDidDoc() DidDoc {
return DidDoc{
Context: msg.Context,
Id: msg.Id,
Controller: msg.Controller,
VerificationMethod: msg.VerificationMethod,
Authentication: msg.Authentication,
AssertionMethod: msg.AssertionMethod,
CapabilityInvocation: msg.CapabilityInvocation,
CapabilityDelegation: msg.CapabilityDelegation,
KeyAgreement: msg.KeyAgreement,
AlsoKnownAs: msg.AlsoKnownAs,
Service: msg.Service,
}
}
// Validation
func (msg MsgUpdateDidDocPayload) Validate(allowedNamespaces []string) error {
err := msg.ToDidDoc().Validate(allowedNamespaces)
if err != nil {
return err
}
return validation.ValidateStruct(&msg,
validation.Field(&msg.VersionId, validation.Required),
)
}
func ValidMsgUpdateDidPayloadRule(allowedNamespaces []string) *CustomErrorRule {
return NewCustomErrorRule(func(value interface{}) error {
casted, ok := value.(*MsgUpdateDidDocPayload)
if !ok {
panic("ValidMsgUpdateDidPayloadRule must be only applied on MsgUpdateDidPayload properties")
}
return casted.Validate(allowedNamespaces)
})
}
// Normalize
func (msg *MsgUpdateDidDocPayload) Normalize() {
msg.Id = utils.NormalizeDID(msg.Id)
for _, vm := range msg.VerificationMethod {
vm.Controller = utils.NormalizeDID(vm.Controller)
vm.Id = utils.NormalizeDIDUrl(vm.Id)
}
for _, s := range msg.Service {
s.Id = utils.NormalizeDIDUrl(s.Id)
}
msg.Controller = utils.NormalizeDIDList(msg.Controller)
msg.Authentication = utils.NormalizeDIDUrlList(msg.Authentication)
msg.AssertionMethod = utils.NormalizeDIDUrlList(msg.AssertionMethod)
msg.CapabilityInvocation = utils.NormalizeDIDUrlList(msg.CapabilityInvocation)
msg.CapabilityDelegation = utils.NormalizeDIDUrlList(msg.CapabilityDelegation)
msg.KeyAgreement = utils.NormalizeDIDUrlList(msg.KeyAgreement)
msg.VersionId = utils.NormalizeUUID(msg.VersionId)
}