Creating an OP_CSV transaction with bitcoinjs I'm working on a tool for timelocked contract generation. My redeem script looks like so:

OP_HASH160 &lt;revocationHash&gt; OP_EQUAL
OP_IF
    &lt;bobPubKey&gt;
OP_ELSE
    &lt;timeDelay&gt; OP_CHECKSEQUENCEVERIFY OP_DROP
    &lt;alicePubKey&gt;
OP_ENDIF
OP_CHECKSIG


The goal is that Alice can spend the funds after a time delay, while Bob can spend them at any time by proving knowledge of the hash preimage.

Spending through the revocation hash is easy enough. However, I'm having trouble constructing a transaction that spends based on the timelock is proving more difficult. Essentially, my questions are:


What does the &lt;timeDelay&gt; value represent? How can I e.g. lock the funds for 2 blocks?
From what I've read, the sequence number on the spend transaction needs to be set. But what should it be set to?
How do I practically implement this using bitcoinjs-lib or another library?
In bitcoin-js you could do something like this

aliceToBobRedeemScript =  bitcoin.script.compile([,
bitcoin.opcodes.OP_IF,
  bitcoin.opcodes.OP_HASH160,
  aliceSecretHash,
  bitcoin.opcodes.OP_EQUALVERIFY,
  bobPrivKey.getPublicKeyBuffer(),
bitcoin.opcodes.OP_ELSE,
  bitcoin.script.number.encode(10),
  bitcoin.opcodes.OP_NOP3,
  bitcoin.opcodes.OP_DROP, 
  alicePrivKey.getPublicKeyBuffer(),
bitcoin.opcodes.OP_ENDIF,
bitcoin.opcodes.OP_CHECKSIG
]);


there is some sample code on an old atomicswap demo, it doesnt have csv but shows other things such as how to sign custom transactions etc

https://github.com/rubensayshi/counterparty-p2sh-demo/blob/master/atomic-swap.js#L163-L185