Below I have created a minimal self-contained example of an error I am getting in my project, namely:
buffer.js:705
throw TypeError(‘value is out of bounds’);
^
TypeError: value is out of bounds
at TypeError ()
at checkInt (buffer.js:705:11)
at Buffer.writeUInt8 (buffer.js:715:5)
at BufferWriter.writeUInt8 (c:\Users\Sindre\Documents\GitHub\BitSwaprjs\node_modules\bitcore\lib\encoding\bufferwriter.js:42:7)
at Script.toBuffer (c:\Users\Sindre\Documents\GitHub\BitSwaprjs\node_modules\bitcore\lib\script\script.js:110:8)
at Interpreter.evaluate (c:\Users\Sindre\Documents\GitHub\BitSwaprjs\node_modules\bitcore\lib\script\interpreter.js:283:19)
at Interpreter.verify (c:\Users\Sindre\Documents\GitHub\BitSwaprjs\node_modules\bitcore\lib\script\interpreter.js:72:13)
at Object. (c:\Users\Sindre\Documents\GitHub\BitSwaprjs\test\plain.js:51:37)
at Module._compile (module.js:456:26)
at Object.Module._extensions…js (module.js:474:10)
In the example I am separately computing multisig signatures and checking their validity, which is important for my project
// Create keys
var sk1 = new PrivateKey();
var sk2 = new PrivateKey();
var sk3 = new PrivateKey();
var pubkeys = [new PublicKey(sk1), new PublicKey(sk2)];
// Build multisig redeem script which checks for 2 signatures matching 2 keys
var redeemScript = Script.buildMultisigOut(pubkeys, 2, { noSorting : true });
// Build p2sh output script based on this redeem script
var scriptPubKey = Script.buildScriptHashOut(redeemScript);
// Create spending transaction
var tx = new Transaction();
// FAKE outpoint funding tx
tx.from(Transaction.UnspentOutput({
txId: 'a0a08e397203df68392ee95b3f08b0b3b3e2401410a38d46ae0874f74846f2e9',
outputIndex: 0,
scriptPubKey: Script.empty(), // place holder
satoshis: 20000000
}));
tx.to(new Address(new PublicKey(sk3), Networks.testnet), 20000000);
// Create signatures
var sig1 = sighash.sign(tx, sk1, crypto.Signature.SIGHASH_SINGLE, 0, scriptPubKey);
var sig2 = sighash.sign(tx, sk2, crypto.Signature.SIGHASH_SINGLE, 0, scriptPubKey);
// Create scriptSig
var scriptSig = Script.buildP2SHMultisigIn(pubkeys, 2, [sig1, sig2], { noSorting : true, cachedMultisig : scriptPubKey });
// Check signatures
var flags = Script.Interpreter.SCRIPT_VERIFY_P2SH | Script.Interpreter.SCRIPT_VERIFY_STRICTENC;
var validity = Script.Interpreter().verify(scriptSig, scriptPubKey, tx, 0, flags);