Is there an example of how to make HTLC contract?
https://github.com/bitcoin/bips/blob/master/bip-0199.mediawiki
Not at this time, but I intend to add some examples soon, probably in https://github.com/bitcoinjs/bitcoinjs-lib/pull/944
PRs accepted!
It works for me! Next steps: build and try to execute redeem tx, write bitcoinjs tests
var keyPair = bitcoin.ECPair.fromWIF('cRgnQe9MUu1JznntrLaoQpB476M8PURvXVQB5R2eqms5tXnzNsrr',bitcoin.networks.testnet)
var pubKeyWi = keyPair.getPublicKeyBuffer()
document.querySelector("#myAddr").innerHTML = keyPair.getAddress();
var hodlDate = Math.floor(Date.now() / 1000) + (3600 * 48)
var hodlLockTimeBuffer = new Buffer(4)
hodlLockTimeBuffer.writeInt32LE(hodlDate | 0, 0);
var witnessScript = bitcoin.script.compile([].concat(
OPS.OP_IF,
OPS.OP_RIPEMD160,
Buffer.from("db018259bba932f6ede72154601e581c5f581c76", 'hex'),
OPS.OP_EQUALVERIFY,
OPS.OP_DUP,
OPS.OP_HASH160,
pubKeyWi,
OPS.OP_ELSE,
hodlLockTimeBuffer,
OPS.OP_CHECKLOCKTIMEVERIFY,
OPS.OP_DROP,
OPS.OP_DUP,
OPS.OP_HASH160,
pubKeyWi,
OPS.OP_ENDIF,
OPS.OP_EQUALVERIFY,
OPS.OP_CHECKSIG,
))
var redeemScript = bitcoin.script.compile([OPS.OP_0, bitcoin.crypto.sha256(witnessScript)]); //not sure about this
var scriptPubKey = bitcoin.script.compile([OPS.OP_HASH160, bitcoin.crypto.hash160(redeemScript), OPS.OP_EQUAL])
var address = bitcoin.address.fromOutputScript(scriptPubKey,bitcoin.networks.testnet)
@noxonsu I think you're lock time Buffer is wrong.
Please see https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/integration/cltv.js#L18
Closing in favour of #944