Skip to content

Commit 448728b

Browse files
committed
secp256k1: add constants for compact signature size
1 parent 42ad037 commit 448728b

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

crypto/secp256k1/key.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ const (
1313
PrivateKeyBytesSize = secp256k1.PrivKeyBytesLen
1414
// SignatureBytesSize is the size, in bytes, of signatures in raw bytes.
1515
SignatureBytesSize = 64
16+
// SignatureCompactBytesSize is the size, in bytes, of "compact" signatures.
17+
// The term "compact" is misleading and refers to the fact that the extra byte
18+
// allows reconstructing the public key from the signature and therefore avoids
19+
// having to transmit the public key. The signature itself is slightly bigger.
20+
SignatureCompactBytesSize = 65
1621

1722
MultibaseCode = uint64(0xe7)
1823

crypto/secp256k1/public.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ func PublicKeyFromXY(x, y []byte) (*PublicKey, error) {
5757
// The hash must be 32 bytes long and be the one used for that signature.
5858
// Returns an error if recovery fails or the signature is malformed.
5959
func PublicKeyFromRecovery(signature []byte, hash []byte) (*PublicKey, error) {
60-
if len(signature) != 65 {
61-
return nil, fmt.Errorf("secp256k1: invalid compact signature length: expected 65 bytes, got %d", len(signature))
60+
if len(signature) != SignatureCompactBytesSize {
61+
return nil, fmt.Errorf("secp256k1: invalid compact signature length: expected %d bytes, got %d", SignatureCompactBytesSize, len(signature))
6262
}
6363
if len(hash) != 32 {
6464
return nil, fmt.Errorf("secp256k1: invalid hash length: expected 32 bytes, got %d", len(hash))

0 commit comments

Comments
 (0)