Skip to content

Instantly share code, notes, and snippets.

@takuto-h
Last active November 5, 2018 01:19
Show Gist options
  • Save takuto-h/735712d586ce81f51195860128aadfee to your computer and use it in GitHub Desktop.
Save takuto-h/735712d586ce81f51195860128aadfee to your computer and use it in GitHub Desktop.
anyone-can-spend P2SH address
'use strict';
import bitcore from 'bitcore-lib-cash';
const Script = bitcore.Script;
const Networks = bitcore.Networks;
const Interpreter = Script.Interpreter;
const redeemScript = Script('OP_TRUE');
const scriptSig = Script().add(redeemScript.toBuffer());
const scriptPubKey = redeemScript.toScriptHashOut();
const address = scriptPubKey.toAddress(Networks.regtest);
console.log("redeem script: " + redeemScript.toString());
console.log("scriptSig: " + scriptSig.toString());
console.log("scriptPubKey: " + scriptPubKey.toString());
console.log("address (regtest): " + address);
console.log("Verification result: " + Interpreter().verify(scriptSig, scriptPubKey));
/*
[Output]
redeem script: OP_1
scriptSig: 1 0x51
scriptPubKey: OP_HASH160 20 0xda1745e9b549bd0bfa1a569971c77eba30cd5a4b OP_EQUAL
address (regtest): bchreg:prdpw30fk4ym6zl6rftfjuw806arpn26fveknc0qmt
Verification result: true
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment