Issue with ripemd160(sha256(script)) in locking script

I have written this and am running it in the browser:

function getScripts(){
    
    var Buffer = require('bitcore').Buffer;
    var Script = require('bitcore').Script;
    
    //create unlocking script
    unlockingScript = new Script();            
    unlockingScript.add(new bitcore.deps.Buffer("87Pmu6Sh7L8AGg7Ee3dn"));

    var lockingScript = new Script();
    lockingScript.add("OP_HASH160");
    lockingScript.add(new bitcore.deps.Buffer("87Pmu6Sh7L8AGg7Ee3dn"));        
    lockingScript.add("OP_HASH160");
    lockingScript.add("OP_EQUAL");
    
    //verify unlocking and locking script
    var verified = bitcore.Script.Interpreter().verify(unlockingScript, lockingScript);
    
}

verify() is returning true.

I want to replace:

lockingScript.add(new bitcore.deps.Buffer("87Pmu6Sh7L8AGg7Ee3dn"));        
lockingScript.add("OP_HASH160");

with ripemd160(sha256(87Pmu6Sh7L8AGg7Ee3dn)).

I tried replacing it with:

lockingScript.add(new bitcore.deps.Buffer("262683285a1ea2cc3ebf0081f078a89a8702a6eb"));

262683285a1ea2cc3ebf0081f078a89a8702a6eb is ripemd160(sha256(87Pmu6Sh7L8AGg7Ee3dn))
where sha256 was double checked to give
1773e64f9bd0f9f27d4f729697c518720a95a1f0a937f9e559fc6d6d37af4f7c
from:
http://www.xorbin.com/tools/sha256-hash-calculator
and
freeformatter.com/sha256-generator.html#ad-output

Then ripemd160 was double checked to give
262683285a1ea2cc3ebf0081f078a89a8702a6eb
from:
http://crypo.in.ua/tools/eng_ripemd.php
and
quickhash.com/

This did not work. verify() returned false.

Then I tried replacing:

var lockingScript = new Script();
lockingScript.add("OP_HASH160");
lockingScript.add(new bitcore.deps.Buffer("87Pmu6Sh7L8AGg7Ee3dn"));        
lockingScript.add("OP_HASH160");
lockingScript.add("OP_EQUAL");

with:

var lockingScript = unlockingScript.toScriptHashOut();

This also did not work. verify() returned false.

Any help with this would be appreciated. Thanks

I think the problem may be that you’re using the string buffer, and you probably want the buffer for that hexadecimal representation.

try:

lockingScript.add(new bitcore.deps.Buffer('262683285a1ea2cc3ebf0081f078a89a8702a6eb', 'hex'));

To clarify my point:

> Buffer('262683285a1ea2cc3ebf0081f078a89a8702a6eb').toString()
'262683285a1ea2cc3ebf0081f078a89a8702a6eb'
> Buffer('262683285a1ea2cc3ebf0081f078a89a8702a6eb', 'hex').toString()
'&&�(Z\u001e��>�\u0000��x���\u0002��'
>

Thanks for your reply.

When I try:

verify() returns false.

Any other ideas appreciated. Thanks

Did you change ALL your scripts?

Thanks for this suggestion:

I read the bip.

Here are gists for the code written two different ways to include a redeem script. The only thing changing is the getScripts() function. Each time verify() returns false for the scripts.

Gist 1: redeem script is string buffer and op_equal

The bip referred to the redeem script as the serialized script. I do not think Bitcore has a serialize function for Script. So I tried having the redeem script be hex of the previous redeem script in Gist1.

Gist 2: redeem script is hex of string buffer and op_equal

Help is appreciated. Thanks

For a wrapup on this and related posts see:
manual-creation-of-custom-p2sh-transaction