-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
pubkey.go
63 lines (52 loc) · 1.38 KB
/
pubkey.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
package secp256r1
import (
"github.com/gogo/protobuf/proto"
tmcrypto "github.com/tendermint/tendermint/crypto"
ecdsa "github.com/cosmos/cosmos-sdk/crypto/keys/internal/ecdsa"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
)
// String implements proto.Message interface.
func (m *PubKey) String() string {
return m.Key.String(name)
}
// Bytes implements SDK PubKey interface.
func (m *PubKey) Bytes() []byte {
if m == nil {
return nil
}
return m.Key.Bytes()
}
// Equals implements SDK PubKey interface.
func (m *PubKey) Equals(other cryptotypes.PubKey) bool {
pk2, ok := other.(*PubKey)
if !ok {
return false
}
return m.Key.Equal(&pk2.Key.PublicKey)
}
// Address implements SDK PubKey interface.
func (m *PubKey) Address() tmcrypto.Address {
return m.Key.Address(proto.MessageName(m))
}
// Type returns key type name. Implements SDK PubKey interface.
func (m *PubKey) Type() string {
return name
}
// VerifySignature implements SDK PubKey interface.
func (m *PubKey) VerifySignature(msg []byte, sig []byte) bool {
return m.Key.VerifySignature(msg, sig)
}
type ecdsaPK struct {
ecdsa.PubKey
}
// Size implements proto.Marshaler interface
func (pk *ecdsaPK) Size() int {
if pk == nil {
return 0
}
return pubKeySize
}
// Unmarshal implements proto.Marshaler interface
func (pk *ecdsaPK) Unmarshal(bz []byte) error {
return pk.PubKey.Unmarshal(bz, secp256r1, pubKeySize)
}