Sunday, December 22, 2024

javascript – bitcoinjs – mandatory-script-verify-flag-failed (Signature have to be zero for failed CHECK(MULTI)SIG operation)

enter image description here

I am attempting to observe the beneath transaction instance by magic eden and prolong it to assist a number of consumers and vendor (in pink). Nevertheless I’m having difficulties after I add a couple of signature from one other celebration (with one vendor it broadcasts okay). The transaction builds and indicators fantastic however when I attempt to broadcast it to the community it ends in the error mandatory-script-verify-flag-failed (Signature have to be zero for failed CHECK(MULTI)SIG operation). Utilizing native segwit addresses for this (no-tr).

What am I lacking or doing mistaken?

Utilizing the bitcoinjs library here’s what I’ve to date (solely the pink):

Vendor signing:

let psbt = new bitcoin.Psbt({ community });

const [ordinalUtxoTxId, ordinalUtxoVout] = ordinalOutput.cut up(":");
const tx = bitcoin.Transaction.fromHex(await getTxHexById(ordinalUtxoTxId));

attempt {
    tx.setWitness(parseInt(ordinalUtxoVout), []);
} catch {}

const enter = 
    bitcoin.Transaction.SIGHASH_ANYONECANPAY,
;

psbt.addInput(enter);

psbt.addOutput({
  tackle: paymentAddress,
  worth: value,
});

Purchaser Signing (ignoring padding inputs and outputs):

// Add inscriptions inputs and outputs
for (const signedPsbt of sellerSignedPsbts) {
    // Add inscription output
    psbt.addOutput({
        tackle: receiverAddress,
        worth: signedPsbt.knowledge.inputs[0].witnessUtxo.worth,
    });

    // Add payer signed enter
    psbt.addInput({
        ...signedPsbt.knowledge.globalMap.unsignedTx.tx.ins[0],
        // ...signedPsbt.knowledge.inputs[0],
        witnessUtxo: signedPsbt.knowledge.inputs[0].witnessUtxo,
        nonWitnessUtxo: signedPsbt.knowledge.inputs[0].nonWitnessUtxo,
        // finalScriptWitness: signedPsbt.knowledge.inputs[0].finalScriptWitness,
    });

    enter++;
}

// Add vendor cost outputs for payee
for (const signedPsbt of sellerSignedPsbts) {
    // Add payer output
    psbt.addOutput({
        ...signedPsbt.knowledge.globalMap.unsignedTx.tx.outs[0],
    });
}

Merge vendor and purchaser signed psbts:

const buyerSignedPsbt = bitcoin.Psbt.fromBase64(signedBuyingPSBTBase64);

for (let index = 0; index < signedListingsPSBTBase64.size; index++) {
    const sellerSignedPsbt = bitcoin.Psbt.fromBase64(signedListingsPSBTBase64[index]);

    buyerSignedPsbt.knowledge.globalMap.unsignedTx.tx.ins[BUYING_PSBT_SELLER_SIGNATURE_INDEX + index] = sellerSignedPsbt.knowledge.globalMap.unsignedTx.tx.ins[0];
    buyerSignedPsbt.knowledge.inputs[BUYING_PSBT_SELLER_SIGNATURE_INDEX + index] = sellerSignedPsbt.knowledge.inputs[0];
}

// broadcast buyerSignedPsbt

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles