do pubkey parsing and signature parsing directly in VerifySignature for brevity instead of calling up to tons of unnecessary upstream libraries.

This commit is contained in:
fiatjaf
2026-01-13 14:50:02 -03:00
parent 8af7042f95
commit 39c55cd938

View File

@@ -7,6 +7,7 @@ import (
"github.com/btcsuite/btcd/btcec/v2" "github.com/btcsuite/btcd/btcec/v2"
"github.com/btcsuite/btcd/btcec/v2/schnorr" "github.com/btcsuite/btcd/btcec/v2/schnorr"
"github.com/decred/dcrd/dcrec/secp256k1/v4"
) )
// Verify checks if the event signature is valid for the given event. // Verify checks if the event signature is valid for the given event.
@@ -14,16 +15,23 @@ import (
// Returns true if the signature is valid, false otherwise. // Returns true if the signature is valid, false otherwise.
func (evt Event) VerifySignature() bool { func (evt Event) VerifySignature() bool {
// read and check pubkey // read and check pubkey
pubkey, err := schnorr.ParsePubKey(evt.PubKey[:]) var x, y secp256k1.FieldVal
if err != nil { if overflow := x.SetByteSlice(evt.PubKey[0:32]); overflow {
return false return false
} }
if !secp256k1.DecompressY(&x, false, &y) {
return false
}
pubkey := secp256k1.NewPublicKey(&x, &y)
// read signature // read signature
sig, err := schnorr.ParseSignature(evt.Sig[:]) var r btcec.FieldVal
if err != nil { if overflow := r.SetByteSlice(evt.Sig[0:32]); overflow {
return false return false
} }
var s btcec.ModNScalar
s.SetByteSlice(evt.Sig[32:64])
sig := schnorr.NewSignature(&r, &s)
// check signature // check signature
hash := sha256.Sum256(evt.Serialize()) hash := sha256.Sum256(evt.Serialize())