forked from oracleNetworkProtocol/plugchain-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
amino.go
59 lines (47 loc) · 2 KB
/
amino.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
package codec
import (
"github.com/tendermint/tendermint/crypto"
tmed25519 "github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/sr25519"
"plugchain-sdk-go/codec"
"plugchain-sdk-go/crypto/keys/ed25519"
kmultisig "plugchain-sdk-go/crypto/keys/multisig"
"plugchain-sdk-go/crypto/keys/secp256k1"
cryptotypes "plugchain-sdk-go/crypto/types"
)
var amino *codec.LegacyAmino
func init() {
amino = codec.NewLegacyAmino()
RegisterCrypto(amino)
}
// RegisterCrypto registers all crypto dependency types with the provided Amino codec.
func RegisterCrypto(cdc *codec.LegacyAmino) {
cdc.RegisterInterface((*crypto.PubKey)(nil), nil)
cdc.RegisterInterface((*cryptotypes.PubKey)(nil), nil)
cdc.RegisterConcrete(sr25519.PubKey{}, sr25519.PubKeyName, nil)
cdc.RegisterConcrete(tmed25519.PubKey{}, tmed25519.PubKeyName, nil)
cdc.RegisterConcrete(&ed25519.PubKey{}, ed25519.PubKeyName, nil)
cdc.RegisterConcrete(&secp256k1.PubKey{}, secp256k1.PubKeyName, nil)
cdc.RegisterConcrete(&kmultisig.LegacyAminoPubKey{}, kmultisig.PubKeyAminoRoute, nil)
cdc.RegisterInterface((*crypto.PrivKey)(nil), nil)
cdc.RegisterConcrete(sr25519.PrivKey{}, sr25519.PrivKeyName, nil)
cdc.RegisterConcrete(tmed25519.PrivKey{}, tmed25519.PrivKeyName, nil)
cdc.RegisterConcrete(&ed25519.PrivKey{}, ed25519.PrivKeyName, nil)
cdc.RegisterConcrete(&secp256k1.PrivKey{}, secp256k1.PrivKeyName, nil)
}
// PrivKeyFromBytes unmarshals private key bytes and returns a PrivKey
func PrivKeyFromBytes(privKeyBytes []byte) (privKey crypto.PrivKey, err error) {
err = amino.UnmarshalBinaryBare(privKeyBytes, &privKey)
return
}
// PubKeyFromBytes unmarshals public key bytes and returns a PubKey
func PubKeyFromBytes(pubKeyBytes []byte) (pubKey crypto.PubKey, err error) {
err = amino.UnmarshalBinaryBare(pubKeyBytes, &pubKey)
return
}
func MarshalPubkey(pubkey crypto.PubKey) []byte {
return amino.MustMarshalBinaryBare(pubkey)
}
func MarshalPrivKey(privKey crypto.PrivKey) []byte {
return amino.MustMarshalBinaryBare(privKey)
}