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

Can I using this signature for psbt reedem script?

Open peter-jim opened this issue 9 months ago • 0 comments

In bitcoinjs-lib I can easy using alice.sign(signatureHash) to sign after broadcast. If I convert the signature result for hex string it like this d2ffa12c2191ab1197a318b9c90d2007c66c5157b0a1d0238a4ced93116d3b085d5b20e4c54453d85ca0c747c84f73b3449292456a26d2c8354a24c4b26a5359 it is 64 byte buffer , but If I using bitcoinjs-Message I got like this
1f6407f716337d301b7439ff52e37e829f2d35b51589632e575f203bce9ba4cb526a656faf826a417557753a14b397a8d696520b4dd13cd8e1258ec04e2625ddcb ,when I convert to hex string . it is 65 byte buffer, and then I .slice(1) I got 6407f716337d301b7439ff52e37e829f2d35b51589632e575f203bce9ba4cb526a656faf826a417557753a14b397a8d696520b4dd13cd8e1258ec04e2625ddcb it different.

when I broadcast the .slice(1) result buffer I got error withError: mandatory-script-verify-flag-failed (Non-canonical DER signature)

here is my code

const hashType = bitcoin.Transaction.SIGHASH_ALL;
var privateKey = alice.privateKey
var message = '0948924b208d78cdde843cfebf72fdb32f9093f5671b4e09dc8d9371aaa0314f'
var derSignature = bitcoinMessage.sign(message, privateKey, alice.compressed)
console.log('derSignature',derSignature.toString('hex'))

const signatureHash = redeemTx.hashForSignature(0,lockingScript, hashType);  // is 0948924b208d78cdde843cfebf72fdb32f9093f5671b4e09dc8d9371aaa0314f
const signature_bitcoinjs = bitcoin.script.signature.encode(alice.sign(signatureHash), hashType);

const signature_message = bitcoin.script.signature.encode(derSignature.slice(1), hashType);

Can you tell me what reason and how to fix it ? thank you

peter-jim avatar May 06 '24 08:05 peter-jim