-
Notifications
You must be signed in to change notification settings - Fork 39
/
ed25519.go
64 lines (52 loc) · 1.7 KB
/
ed25519.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
package ed25519
import (
"github.com/stratosnet/sds/utils/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
sdked25519 "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
)
func NewKey() []byte {
privKey := ed25519.GenPrivKey()
return privKey[:]
}
func PrivKeyBytesToPrivKey(privKey []byte) crypto.PrivKey {
var privKey2 [64]byte
copy(privKey2[:], privKey)
return ed25519.PrivKey(privKey2[:])
}
func PrivKeyBytesToPubKey(privKey []byte) crypto.PubKey {
pubKey := PrivKeyBytesToPrivKey(privKey).PubKey()
pubKey2 := pubKey.(ed25519.PubKey)
return pubKey2
}
func PrivKeyBytesToPubKeyBytes(privKey []byte) []byte {
pubKey := PrivKeyBytesToPrivKey(privKey).PubKey()
pubKey2 := pubKey.(ed25519.PubKey)
return pubKey2[:]
}
func PrivKeyBytesToAddress(privKey []byte) types.Address {
address := PrivKeyBytesToPrivKey(privKey).PubKey().Address()
return types.BytesToAddress(address)
}
func PubKeyBytesToPubKey(pubKey []byte) crypto.PubKey {
var pubKey2 [ed25519.PubKeySize]byte
copy(pubKey2[:], pubKey)
return ed25519.PubKey(pubKey2[:])
}
func PubKeyBytesToAddress(pubKey []byte) types.Address {
address := PubKeyBytesToPubKey(pubKey).Address()
return types.BytesToAddress(address)
}
func PrivKeyBytesToSdkPrivKey(privKey []byte) cryptotypes.PrivKey {
retPrivKey := sdked25519.PrivKey{Key: privKey} //nolint:staticcheck
return &retPrivKey
}
func PrivKeyBytesToSdkPubKey(privKey []byte) cryptotypes.PubKey {
pubKey := PrivKeyBytesToSdkPrivKey(privKey).PubKey()
return pubKey
}
func PubKeyBytesToSdkPubKey(pubKey []byte) cryptotypes.PubKey {
retPubKey := sdked25519.PubKey{Key: pubKey}
return &retPubKey
}