How to create a P2SH address which will be the hash of a redeemScript

How to create a P2SH address which will be the hash of a redeemScript

Suppose I have a redeemScript and I want to create a P2SH address corresponding to the hash of that redeemScript. How do I do it?

I was thinking of bitcore-lib but I'm not sure I am going in the right direction. Below is my staring point and I am not sure what to do next.

Also the scriptPubKey appears to be 0x04 and it has to be 0x05.

And how do I further generate my keys for this new address?

> var bitcore = require('bitcore-lib');
    undefined
    > var redeemScript = bitcore.Script.fromASM('OP_SHA256 001xxxxxxxxxxxxxxxxxxxx6 OP_EQUAL');
    undefined
    > var scriptPubKey = redeemScript.toScriptHashOut();
    undefined
    > scriptPubKey
    <Script: OP_HASH160 20 0x04xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx6 OP_EQUAL>
    > scriptPubKey.toAddress()
    3xxxxxxxxxxxx
    > scriptPubKey.toHex()
    a914xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx287

Another option will be to use this:

https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/addresses.js#L19

Thanks!

https://ift.tt/2HRLRip

Comments

Popular posts from this blog

bitcoin node: what is the difference between simnet and regtest?

How to check if Electrum is masking my IP with the Tor proxy?

Tor proxy on Electrum, what does Port: 9150 and 9050 mean?