bitcoinjs-lib icon indicating copy to clipboard operation
bitcoinjs-lib copied to clipboard

Verify function changed ?

Open xorq opened this issue 9 years ago • 6 comments

I used to proceed like so in order to verify a specific input's signature : txb = Bitcoin.TransactionBuilder.fromTransaction(tx) Bitcoin.ECPair.fromPublicKeyBuffer(txb.inputs[0].pubKeys[0]).verify(tx.ins[0].hash, txb.inputs[0].signatures[0])

but now I get this error message : Expected property "1.r" of type BigInteger, got undefined" Is it broken or what should I change ? Thanks !

xorq avatar Aug 23 '17 06:08 xorq

From the Error:

Expected property "1.r" of type BigInteger, got undefined"

txb.inputs[0].signatures[0].r === undefined

dcousens avatar Aug 23 '17 07:08 dcousens

var signature = Bitcoin.ECSignature.parseScriptSignature(txb.inputs[0].signatures[0])
Bitcoin.ECPair.fromPublicKeyBuffer(txb.inputs[0].pubKeys[0])
  .verify(tx.ins[0].hash, signature)

dcousens avatar Aug 23 '17 07:08 dcousens

I wouldn't rely on TransactionBuilder internals, they should be private, maybe we need to encapsulate those internals strictly using a closure.

dcousens avatar Aug 23 '17 07:08 dcousens

I tried the above

var signature = Bitcoin.ECSignature.parseScriptSignature(txb.inputs[0].signatures[0]) Bitcoin.ECPair.fromPublicKeyBuffer(txb.inputs[0].pubKeys[0]) .verify(tx.ins[0].hash, signature)

and still get the error message : Expected property "1.r" of type BigInteger, got undefined"

Is there another way to check if a signature is valid ?

xorq avatar Aug 23 '17 11:08 xorq

Ok I found the problem,

.verify(tx.ins[0].hash, signature.signature)

Thanks for the help anyways !

xorq avatar Aug 23 '17 11:08 xorq

@xorq again, I wouldn't rely on those internals. They are going to be subject to change (and possibly soon).

dcousens avatar Aug 23 '17 22:08 dcousens