-
Notifications
You must be signed in to change notification settings - Fork 207
/
keys.go
49 lines (40 loc) · 1.12 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
49
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/words"
tmdb "github.com/tendermint/tmlibs/db"
)
const (
KeyPasswd = "0123456789"
KeyAlgo = "ed25519"
KeyName = "test"
)
func KeyManager(t *testing.T) keys.Keybase {
codec, err := words.LoadCodec("english")
require.NoError(t, err)
db := tmdb.NewMemDB()
return keys.New(db, codec)
}
func PrivateKey(t *testing.T) crypto.PrivKey {
return crypto.GenPrivKeyEd25519()
}
func PublicKey(t *testing.T) crypto.PubKey {
return PrivateKey(t).PubKey()
}
func PrivateKeySigner(t *testing.T) (txutil.Signer, crypto.PrivKey) {
key := PrivateKey(t)
return txutil.NewPrivateKeySigner(key), key
}
func NewNamedKey(t *testing.T) (keys.Info, keys.Keybase) {
kmgr := KeyManager(t)
info, _, err := kmgr.Create(KeyName, KeyPasswd, KeyAlgo)
require.NoError(t, err)
return info, kmgr
}
func Signer(t *testing.T, kmgr keys.Keybase) txutil.Signer {
return txutil.NewKeystoreSigner(kmgr, KeyName, KeyPasswd)
}