transactions – Recovered bitcoin public keys don’t confirm the signature

0
63


I must get well public keys on the bitcoin chain for a undertaking, my present circulation is like this:

Get hash + signature from bigquery -> Use nodeJS secp256k1 module (native bindings) to import signature from DER signature -> get well public key from signature and hash-> confirm public key towards signature and hash.

The issue is, solely about half of the general public keys confirm. Initially I assumed it is both y-coordinate points or points with the recid quantity, however so far as I can inform, neither is the case.

Oddities that I’ve discovered:
Irrespective of whether or not I put 0 or 1 as recid, both each (completely different) recovered public keys confirm, or neither do.
DER Signatures with a 144 hex size (72 bytes) by no means have their recovered public keys confirm, whereas shorter signatures turn out to be more and more extra more likely to accurately confirm.

My code:

    var uintsig = Uint8Array.from(Buffer.from(textasm, 'hex'));
    var uinthash = Uint8Array.from(Buffer.from(texthash, 'hex'));
    var sig = secp256k1.signatureImport(uintsig)

    var pubk = secp256k1.ecdsaRecover(sig, 1, uinthash)
    var ver = secp256k1.ecdsaVerify(sig, uinthash, pubk)

Pattern information, one fails one goes accurately:

Doesn't confirm:
{
  sig: '3045022074e221c10f7d1baeadc8f4f22b6c738997bf5864027787ac337b18ab3ad89488022100adcefaf4182096e06bd3e57756e4029dfd598c755a0885499a178043d1ef6766',
  hash: '6aa7a48970a9f1609583701848b30ec622c1efc7eb11c57652254c4c44637475'
}
--------
Does confirm:
{
  sig: '30440220773971d9aeb4e02bf41e978621a5dc110e1f91f1b7c773b774d37dea98a89074022061000945e5852ed4b9cc17dc39f7ddaa68c235b1f826fc68fcad913662b59a68',
  hash: '642a77be5a9203209b1136a5df685a645fddd3a81785b19a7d3910a2d5d77955'
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here