mirror of
https://github.com/tendermint/tendermint.git
synced 2026-06-04 21:32:36 +00:00
Add and test serialization of ledger privkey
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
ledger "github.com/ethanfrey/ledger"
|
||||
|
||||
crypto "github.com/tendermint/go-crypto"
|
||||
wire "github.com/tendermint/go-wire"
|
||||
)
|
||||
|
||||
var device *ledger.Ledger
|
||||
@@ -62,9 +63,9 @@ func NewPrivKeyLedger() (crypto.PrivKey, error) {
|
||||
// AssertIsPrivKeyInner fulfils PrivKey Interface
|
||||
func (pk *PrivKeyLedger) AssertIsPrivKeyInner() {}
|
||||
|
||||
// Bytes fulfils pk Interface - not supported
|
||||
// Bytes fulfils pk Interface - no data, just type info
|
||||
func (pk *PrivKeyLedger) Bytes() []byte {
|
||||
return nil
|
||||
return wire.BinaryBytes(pk.Wrap())
|
||||
}
|
||||
|
||||
// Sign calls the ledger and stores the pk for future use
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
crypto "github.com/tendermint/go-crypto"
|
||||
)
|
||||
|
||||
func TestLedgerKeys(t *testing.T) {
|
||||
@@ -88,4 +89,19 @@ func TestRealLedger(t *testing.T) {
|
||||
|
||||
valid := pub.VerifyBytes(msg, sig)
|
||||
assert.True(valid)
|
||||
|
||||
// now, let's serialize the key and make sure it still works
|
||||
bs := priv.Bytes()
|
||||
priv2, err := crypto.PrivKeyFromBytes(bs)
|
||||
require.Nil(err, "%+v", err)
|
||||
|
||||
// make sure we get the same pubkey when we load from disk
|
||||
pub2 := priv2.PubKey()
|
||||
require.Equal(pub, pub2)
|
||||
|
||||
// signing with the loaded key should match the original pubkey
|
||||
sig = priv2.Sign(msg)
|
||||
valid = pub.VerifyBytes(msg, sig)
|
||||
assert.True(valid)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user