-
Notifications
You must be signed in to change notification settings - Fork 23
/
message_create_did.go
108 lines (88 loc) · 2.43 KB
/
message_create_did.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
const TypeMsgCreateDID = "create_did"
var _ sdk.Msg = &MsgCreateDID{}
func NewMsgCreateDID(did string, didDocString *DidDocStructCreateDID) *MsgCreateDID {
return &MsgCreateDID{
DidDocString: didDocString,
}
}
func (msg *MsgCreateDID) Route() string {
return RouterKey
}
func (msg *MsgCreateDID) Type() string {
return TypeMsgCreateDID
}
// TODO: Implement the following without the field Creator
// func accAddrByKeyRef(keyring keyring.Keyring, keyRef string) (sdk.AccAddress, error) {
// // Firstly check if the keyref is a key name of a key registered in a keyring
// info, err := keyring.Key(keyRef)
// if err == nil {
// return info.GetAddress(), nil
// }
// if !sdkerr.IsOf(err, sdkerr.ErrIO, sdkerr.ErrKeyNotFound) {
// return nil, err
// }
// // Fallback: convert keyref to address
// return sdk.AccAddressFromBech32(keyRef)
// }
// func (msg *MsgCreateDID) GetSigners() []sdk.AccAddress {
// ctx := client
// signerAccAddr, err := accAddrByKeyRef(ctx.Keyring, ctx.From)
// if err != nil {
// panic(err)
// }
// return []sdk.AccAddress{signerAccAddr}
// }
func (msg *MsgCreateDID) GetSigners() []sdk.AccAddress {
creator, err := sdk.AccAddressFromBech32(msg.Creator)
if err != nil {
panic(err)
}
return []sdk.AccAddress{creator}
}
func (msg *DidDocStructCreateDID) GetSigners() []Signer {
// TODO: Implemt this when working on the updated DidDoc standard
// if len(msg.Controller) > 0 {
// result := make([]Signer, len(msg.Controller))
// for i, controller := range msg.Controller {
// if controller == msg.Id {
// result[i] = Signer{
// Signer: controller,
// Authentication: msg.Authentication,
// VerificationMethod: msg.VerificationMethod,
// }
// } else {
// result[i] = Signer{
// Signer: controller,
// }
// }
// }
// return result
// }
if len(msg.Authentication) > 0 {
return []Signer{
{
Signer: msg.Id,
Authentication: msg.Authentication,
PublicKeyStruct: msg.PublicKey,
},
}
}
return []Signer{}
}
func (msg *MsgCreateDID) GetSignBytes() []byte {
return ModuleCdc.MustMarshal(msg)
}
func (msg *DidDocStructCreateDID) GetSignBytes() []byte {
return ModuleCdc.MustMarshal(msg)
}
func (msg *MsgCreateDID) ValidateBasic() error {
did := msg.GetDidDocString().GetId()
if did == "" {
return ErrBadRequestIsRequired.Wrap("DID")
}
return nil
}