Skip to content

crypto: allow importing compact secp256k1 pubkey through recovery#27

Merged
MichaelMure merged 1 commit intomasterfrom
secp256k1-recovery
Mar 24, 2026
Merged

crypto: allow importing compact secp256k1 pubkey through recovery#27
MichaelMure merged 1 commit intomasterfrom
secp256k1-recovery

Conversation

@MichaelMure
Copy link
Collaborator

@MichaelMure MichaelMure commented Mar 24, 2026

Note

Medium Risk
Adds new public-key recovery API based on ECDSA compact signatures; main risk is misuse or accepting malformed inputs if callers pass non-hash data or wrong signature formats.

Overview
Adds PublicKeyFromCompactRecovery, allowing secp256k1 public keys to be derived from a 65-byte compact signature (recovery flag + R/S) and the message hash via ecdsa.RecoverCompact, with explicit length validation and wrapped errors.

Extends the secp256k1 test suite with a new unit test that signs a SHA-256 hash using ecdsa.SignCompact and verifies the recovered key matches the original.

Written by Cursor Bugbot for commit 46d6ce9. This will update automatically on new commits. Configure here.

if len(signature) != 65 {
return nil, fmt.Errorf("secp256k1: invalid compact signature length: expected 65 bytes, got %d", len(signature))
}
pub, _, err := ecdsa.RecoverCompact(signature, hash)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting - doing the same thing with the go-ethereum library requires adding 27 and maybe 4 but this is waaaay cleaner (ref: https://pkg.go.dev/github.com/decred/dcrd/dcrec/secp256k1/v4@v4.4.1/ecdsa#SignCompact)

@MichaelMure MichaelMure merged commit bd389c8 into master Mar 24, 2026
7 checks passed
@MichaelMure MichaelMure deleted the secp256k1-recovery branch March 24, 2026 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants