From 7e767e95485d0907a694057103ebc018660a6573 Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Wed, 20 Apr 2016 08:46:07 -0700 Subject: [PATCH] Secp256k1 pubkeys are 64 bytes. Strip btcec prefix byte --- priv_key.go | 4 ++-- pub_key.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/priv_key.go b/priv_key.go index 42f932ba1..8b7dc117f 100644 --- a/priv_key.go +++ b/priv_key.go @@ -123,8 +123,8 @@ func (privKey PrivKeySecp256k1) Sign(msg []byte) Signature { func (privKey PrivKeySecp256k1) PubKey() PubKey { _, pub__ := secp256k1.PrivKeyFromBytes(secp256k1.S256(), privKey[:]) - pub := [65]byte{} - copy(pub[:], pub__.SerializeUncompressed()) + pub := [64]byte{} + copy(pub[:], pub__.SerializeUncompressed()[1:]) return PubKeySecp256k1(pub) } diff --git a/pub_key.go b/pub_key.go index de56c8122..a3a259795 100644 --- a/pub_key.go +++ b/pub_key.go @@ -102,7 +102,7 @@ func (pubKey PubKeyEd25519) Equals(other PubKey) bool { //------------------------------------- // Implements PubKey -type PubKeySecp256k1 [65]byte +type PubKeySecp256k1 [64]byte func (pubKey PubKeySecp256k1) Address() []byte { w, n, err := new(bytes.Buffer), new(int), new(error) @@ -122,7 +122,7 @@ func (pubKey PubKeySecp256k1) Bytes() []byte { } func (pubKey PubKeySecp256k1) VerifyBytes(msg []byte, sig_ Signature) bool { - pub__, err := secp256k1.ParsePubKey(pubKey[:], secp256k1.S256()) + pub__, err := secp256k1.ParsePubKey(append([]byte{0x04}, pubKey[:]...), secp256k1.S256()) if err != nil { return false }