-
Notifications
You must be signed in to change notification settings - Fork 49
/
amino.go
41 lines (34 loc) · 1.27 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
package cryptoAmino
import (
amino "github.com/tendermint/go-amino"
"github.com/cosmos/amino-js/go/lib/tendermint/tendermint/crypto"
"github.com/cosmos/amino-js/go/lib/tendermint/tendermint/crypto/ed25519"
"github.com/cosmos/amino-js/go/lib/tendermint/tendermint/crypto/multisig"
"github.com/cosmos/amino-js/go/lib/tendermint/tendermint/crypto/secp256k1"
)
var cdc = amino.NewCodec()
func init() {
RegisterAmino(cdc)
}
func RegisterAmino(cdc *amino.Codec) {
cdc.RegisterInterface((*crypto.PubKey)(nil), nil)
cdc.RegisterConcrete(ed25519.PubKeyEd25519{},
ed25519.PubKeyAminoName, nil)
cdc.RegisterConcrete(secp256k1.PubKeySecp256k1{},
secp256k1.PubKeyAminoName, nil)
cdc.RegisterConcrete(multisig.PubKeyMultisigThreshold{},
multisig.PubKeyMultisigThresholdAminoRoute, nil)
cdc.RegisterInterface((*crypto.PrivKey)(nil), nil)
cdc.RegisterConcrete(ed25519.PrivKeyEd25519{},
ed25519.PrivKeyAminoName, nil)
cdc.RegisterConcrete(secp256k1.PrivKeySecp256k1{},
secp256k1.PrivKeyAminoName, nil)
}
func PrivKeyFromBytes(privKeyBytes []byte) (privKey crypto.PrivKey, err error) {
err = cdc.UnmarshalBinaryBare(privKeyBytes, &privKey)
return
}
func PubKeyFromBytes(pubKeyBytes []byte) (pubKey crypto.PubKey, err error) {
err = cdc.UnmarshalBinaryBare(pubKeyBytes, &pubKey)
return
}