From e25a64fdf1e4aae53ad5e2780d0b4cc56eedaae6 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Mon, 30 Apr 2018 19:34:19 +0200 Subject: [PATCH] Fix testcases, all looks OK --- ledger.go | 9 ++++++--- signature.go | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ledger.go b/ledger.go index 0fe4b7d39..b2b06415d 100644 --- a/ledger.go +++ b/ledger.go @@ -3,7 +3,7 @@ package crypto import ( "github.com/pkg/errors" - // secp256k1 "github.com/btcsuite/btcd/btcec" + secp256k1 "github.com/btcsuite/btcd/btcec" ledger "github.com/zondax/ledger-goclient" ) @@ -23,13 +23,16 @@ func signLedger(device *ledger.Ledger, msg []byte) (pub PubKey, sig Signature, e if err != nil { return pub, sig, err } + sig = SignatureSecp256k1FromBytes(bsig) key, err := device.GetPublicKey() if err != nil { return pub, sig, err } var p PubKeySecp256k1 - copy(p[:], key) - return p, SignatureSecp256k1FromBytes(bsig), nil + // Reserialize in the 33-byte compressed format + cmp, err := secp256k1.ParsePubKey(key[:], secp256k1.S256()) + copy(p[:], cmp.SerializeCompressed()) + return p, sig, nil } // PrivKeyLedgerSecp256k1 implements PrivKey, calling the ledger nano diff --git a/signature.go b/signature.go index 8bf151b41..a364dc7fb 100644 --- a/signature.go +++ b/signature.go @@ -81,7 +81,7 @@ func (sig SignatureSecp256k1) Equals(other Signature) bool { } func SignatureSecp256k1FromBytes(data []byte) Signature { - var sig SignatureSecp256k1 + sig := make(SignatureSecp256k1, len(data)) copy(sig[:], data) return sig }