|
|
@ -12,6 +12,7 @@ import ( |
|
|
|
wire "github.com/tendermint/go-wire" |
|
|
|
) |
|
|
|
|
|
|
|
//nolint
|
|
|
|
const ( |
|
|
|
NameLedgerEd25519 = "ledger" |
|
|
|
TypeLedgerEd25519 = 0x10 |
|
|
@ -132,16 +133,23 @@ func (pk *PrivKeyLedger) PubKey() crypto.PubKey { |
|
|
|
func (pk *PrivKeyLedger) getPubKey() (key crypto.PubKey, err error) { |
|
|
|
// if we have no pubkey, set it
|
|
|
|
if pk.CachedPubKey.Empty() { |
|
|
|
dev, err := getLedger() |
|
|
|
if err != nil { |
|
|
|
return key, errors.WithMessage(err, "Can't connect to ledger") |
|
|
|
} |
|
|
|
pk.CachedPubKey, _, err = signLedger(dev, []byte{0}) |
|
|
|
if err != nil { |
|
|
|
return key, errors.WithMessage(err, "Can't sign with app") |
|
|
|
} |
|
|
|
pk.CachedPubKey, err = pk.forceGetPubKey() |
|
|
|
} |
|
|
|
return pk.CachedPubKey, nil |
|
|
|
return pk.CachedPubKey, err |
|
|
|
} |
|
|
|
|
|
|
|
// forceGetPubKey is like getPubKey but ignores any cached key
|
|
|
|
// and ensures we get it from the ledger itself.
|
|
|
|
func (pk *PrivKeyLedger) forceGetPubKey() (key crypto.PubKey, err error) { |
|
|
|
dev, err := getLedger() |
|
|
|
if err != nil { |
|
|
|
return key, errors.New("Can't connect to ledger device") |
|
|
|
} |
|
|
|
key, _, err = signLedger(dev, []byte{0}) |
|
|
|
if err != nil { |
|
|
|
return key, errors.New("Please open cosmos app on the ledger") |
|
|
|
} |
|
|
|
return key, err |
|
|
|
} |
|
|
|
|
|
|
|
// Equals fulfils PrivKey Interface
|
|
|
@ -229,6 +237,11 @@ func PubKeyLedgerFromBytes(key [32]byte) crypto.PubKey { |
|
|
|
return PubKeyLedger{crypto.PubKeyEd25519(key)}.Wrap() |
|
|
|
} |
|
|
|
|
|
|
|
// Bytes fulfils pk Interface - no data, just type info
|
|
|
|
func (pk PubKeyLedger) Bytes() []byte { |
|
|
|
return wire.BinaryBytes(pk.Wrap()) |
|
|
|
} |
|
|
|
|
|
|
|
// VerifyBytes uses the normal Ed25519 algorithm but a sha512 hash beforehand
|
|
|
|
func (pk PubKeyLedger) VerifyBytes(msg []byte, sig crypto.Signature) bool { |
|
|
|
hmsg := hashMsg(msg) |
|
|
|