-
Notifications
You must be signed in to change notification settings - Fork 210
/
keys.go
48 lines (40 loc) · 1.07 KB
/
keys.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
package testutil
import (
"testing"
"github.com/ovrclk/akash/txutil"
"github.com/stretchr/testify/require"
crypto "github.com/tendermint/go-crypto"
"github.com/tendermint/go-crypto/keys"
"github.com/tendermint/go-crypto/keys/cryptostore"
"github.com/tendermint/go-crypto/keys/storage/memstorage"
)
const (
KeyPasswd = "0123456789"
KeyAlgo = "ed25519"
KeyName = "test"
)
func KeyManager(t *testing.T) cryptostore.Manager {
codec, err := keys.LoadCodec("english")
require.NoError(t, err)
return cryptostore.New(
cryptostore.SecretBox,
memstorage.New(),
codec,
)
}
func PrivateKey(t *testing.T) crypto.PrivKey {
secret := crypto.CRandBytes(16)
key, err := cryptostore.GenEd25519.Generate(secret)
require.NoError(t, err)
return key
}
func PrivateKeySigner(t *testing.T) (txutil.Signer, crypto.PrivKey) {
key := PrivateKey(t)
return txutil.NewPrivateKeySigner(key), key
}
func NewNamedKey(t *testing.T) (keys.Info, cryptostore.Manager) {
kmgr := KeyManager(t)
info, _, err := kmgr.Create(KeyName, KeyPasswd, KeyAlgo)
require.NoError(t, err)
return info, kmgr
}