|
|
@ -6,6 +6,7 @@ import ( |
|
|
|
"github.com/stretchr/testify/assert" |
|
|
|
"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" |
|
|
|
) |
|
|
@ -18,6 +19,7 @@ func TestKeyManagement(t *testing.T) { |
|
|
|
cstore := cryptostore.New( |
|
|
|
cryptostore.SecretBox, |
|
|
|
memstorage.New(), |
|
|
|
keys.MustLoadCodec("english"), |
|
|
|
) |
|
|
|
|
|
|
|
algo := crypto.NameEd25519 |
|
|
@ -154,6 +156,7 @@ func TestAdvancedKeyManagement(t *testing.T) { |
|
|
|
cstore := cryptostore.New( |
|
|
|
cryptostore.SecretBox, |
|
|
|
memstorage.New(), |
|
|
|
keys.MustLoadCodec("english"), |
|
|
|
) |
|
|
|
|
|
|
|
algo := crypto.NameSecp256k1 |
|
|
@ -199,6 +202,41 @@ func TestAdvancedKeyManagement(t *testing.T) { |
|
|
|
assertPassword(assert, cstore, n2, p3, pt) |
|
|
|
} |
|
|
|
|
|
|
|
// TestSeedPhrase verifies restoring from a seed phrase
|
|
|
|
func TestSeedPhrase(t *testing.T) { |
|
|
|
assert, require := assert.New(t), require.New(t) |
|
|
|
|
|
|
|
// make the storage with reasonable defaults
|
|
|
|
cstore := cryptostore.New( |
|
|
|
cryptostore.SecretBox, |
|
|
|
memstorage.New(), |
|
|
|
keys.MustLoadCodec("english"), |
|
|
|
) |
|
|
|
|
|
|
|
algo := crypto.NameEd25519 |
|
|
|
n1, n2 := "lost-key", "found-again" |
|
|
|
p1, p2 := "1234", "foobar" |
|
|
|
|
|
|
|
// make sure key works with initial password
|
|
|
|
info, seed, err := cstore.Create(n1, p1, algo) |
|
|
|
require.Nil(err, "%+v", err) |
|
|
|
assert.Equal(n1, info.Name) |
|
|
|
assert.NotEmpty(seed) |
|
|
|
|
|
|
|
// now, let us delete this key
|
|
|
|
err = cstore.Delete(n1, p1) |
|
|
|
require.Nil(err, "%+v", err) |
|
|
|
_, err = cstore.Get(n1) |
|
|
|
require.NotNil(err) |
|
|
|
|
|
|
|
// let us re-create it from the seed-phrase
|
|
|
|
newInfo, err := cstore.Recover(n2, p2, seed) |
|
|
|
require.Nil(err, "%+v", err) |
|
|
|
assert.Equal(n2, newInfo.Name) |
|
|
|
assert.Equal(info.Address, newInfo.Address) |
|
|
|
assert.Equal(info.PubKey, newInfo.PubKey) |
|
|
|
} |
|
|
|
|
|
|
|
// func ExampleStore() {
|
|
|
|
// // Select the encryption and storage for your cryptostore
|
|
|
|
// cstore := cryptostore.New(
|
|
|
|