Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions btcec/pubkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
package btcec

import (
"bytes"

"github.com/btcsuite/btcd/btcec/v2/schnorr"
secp "github.com/decred/dcrd/dcrec/secp256k1/v4"
)

Expand Down Expand Up @@ -52,6 +55,17 @@ func NewPublicKey(x, y *FieldVal) *PublicKey {
return secp.NewPublicKey(x, y)
}

// IsEquivalentPubKeys reports whether two public keys are equivalent when
// compared in their BIP340-serialized form. This avoids issues with multiple
// encodings of the same elliptic curve point, since BIP340 serialization
// provides a unique, canonical byte representation.
func IsEquivalentPubKeys(a, b *PublicKey) bool {
return bytes.Equal(
schnorr.SerializePubKey(a),
schnorr.SerializePubKey(b),
)
}

// SerializedKey is a type for representing a public key in its compressed
// serialized form.
//
Expand Down
Loading