0
OP_IF
OP_SHA256
<hash of secret>
OP_EQUALVERIFY
<pubKey of swap>
OP_CHECKSIG
OP_ELSE
<relative locktime>
OP_CHECKSEQUENCEVERIFY
OP_DROP
<pubKey of refund>
OP_CHECKSIG
OP_ENDIF
Actual code which i am using for the above script is
const script = this.app.env.bitcoin.script.compile([
hashOpcode,
Buffer.from(secretHash, "hex"),
this.app.env.bitcoin.opcodes.OP_EQUALVERIFY,
Buffer.from(recipientPublicKey, "hex"),
this.app.env.bitcoin.opcodes.OP_EQUAL,
this.app.env.bitcoin.opcodes.OP_IF,
Buffer.from(recipientPublicKey, "hex"),
this.app.env.bitcoin.opcodes.OP_CHECKSIG,
this.app.env.bitcoin.opcodes.OP_ELSE,
this.app.env.bitcoin.script.number.encode(lockTime),
this.app.env.bitcoin.opcodes.OP_CHECKSEQUENCEVERIFY,
this.app.env.bitcoin.opcodes.OP_DROP,
Buffer.from(ownerPublicKey, "hex"),
this.app.env.bitcoin.opcodes.OP_CHECKSIG,
this.app.env.bitcoin.opcodes.OP_ENDIF
]);
As we see that this script has just one public key(pubKey of swap) to sign with. But i want to sign it with two public keys. I searched for it but found nothing, can anybody guide me?
I just want to follow this pattern
OP_0 [Sig 1] OP_1 [PK 1][PK 2] OP_2 OP_CHECKMULTISIG
Yes @Ugam Kamat you are actually right. I have edit my question please see it again..Actually the complication which i am facing is, how to provide these two public keys . Is it the right way? ``` var add=[recipientPublicKey,exchangePublicKey] Whereas Inside compile Buffer.from(add, "hex"), this.app.env.bitcoin.opcodes.OP_2, this.app.env.bitcoin.opcodes.CHECKMULTISIG, Is it correct? – Aqeel – 2019-06-11T11:11:17.123
@Aqeel You need to use a
OP_DATAopcode between them to indicate the bytes of data to push to stack. For example, to push hash_of_secret to stack you need to tell the program to push the next 32 bytes which is the reason we need0x20preceding that as shown in my edited answer – Ugam Kamat – 2019-06-11T11:47:13.203Thanks for reply. But Opcode you listed "OP_DATA" is not a valid opcode. I have printed the list of opcodes but that opcode is not in the list and therefor creating error – Aqeel – 2019-06-11T12:41:30.410
@Aqeel It's not exactly an opcode but a parameter that helps you indicate to the software how much data you want to push on the stack. For example, if you see my script i used
0x20before hash of secret. It indicates to the software to push the next 32 bytes (ox20 in hex) on the stack. Before the pubkey I used 0x21 to indicate pushing the next 33 bytes on the stack (assuming you are using compressed pub keys) – Ugam Kamat – 2019-06-11T13:17:24.033Can you provide me any helping material for 1-of-2 p2sh multisig script, which may helps me in writing script in desired format. – Aqeel – 2019-06-12T06:08:50.057
@Aqeel I don't think there is one specific to 1-of-2 p2sh multisig. Even if it is out there I'm oblivious to it – Ugam Kamat – 2019-06-12T06:17:01.757
actually the thing which i want to see is how can i pass list of pubkeys to apply OP_CHECKMULTISIG in desired code format... The ref repo is: https://github.com/swaponline/swap.core/blob/97d1d5b6afffee97869302443924bef79ce42763/src/swap.swaps/BtcSwap.js#L181 I am changing this piece of script to 1-of-2 p2sh multisig. Any guidance for me after seeing this script form above reference link?
– Aqeel – 2019-06-12T06:35:53.523@Aqeel I haven't gone through the code in detail, but maybe you can repeat
Buffer.from(recipientPublicKey, 'hex'),twice with different public key and then instead ofthis.app.env.bitcoin.opcodes.OP_CHECKSIGusethis.app.env.bitcoin.opcodes.OP_CHECKMULTISIG– Ugam Kamat – 2019-06-12T07:29:10.230