BitcoinHTLC
swapchain documentation › BitcoinHTLC
Handle creation, redemption and refunding of HTLCs on the bitcoin blockchain
Hierarchy
- BitcoinHTLC
Index
Constructors
Properties
Methods
- calculateFee
- create
- getFinalScriptsRedeem
- getFinalScriptsRefund
- getFundingTxBlockHeight
- getP2WSH
- getRedeemHex
- getRefundHex
- getWitnessPublicKeyHash
- redeem
- redeemScript
- sendToP2WSHAddress
Constructors
constructor
+ new BitcoinHTLC(network
: string, sender
: ECPairInterface, receiver
: ECPairInterface, priority
: number, BitcoinAPIConstructor
: BitcoinAPIConstructor): BitcoinHTLC
Defined in pkg/bitcoin/htlc/btcHTLC.ts:54
Creates an instance of BitcoinHTLC.
memberof
BitcoinHTLC
Parameters:
Name | Type | Default | Description |
---|---|---|---|
network | string | "testnet" | mainnet, testnet, or regtest. |
sender | ECPairInterface | - | Sender keypair. |
receiver | ECPairInterface | - | Receiver keypair. |
priority | number | - | The transaction priority (0 = high, 1 = medium, 2 = low) |
BitcoinAPIConstructor | BitcoinAPIConstructor | - | Bitcoin API to use for communication with the blockchain. |
Returns: BitcoinHTLC
Properties
Private
amountAfterFees
• amountAfterFees: number
Defined in pkg/bitcoin/htlc/btcHTLC.ts:53
bitcoinAPI
• bitcoinAPI: BitcoinAPI
Defined in pkg/bitcoin/htlc/btcHTLC.ts:54
Private
fundingTxBlockHeight
• fundingTxBlockHeight: number | undefined
Defined in pkg/bitcoin/htlc/btcHTLC.ts:51
Private
network
• network: Network
Defined in pkg/bitcoin/htlc/btcHTLC.ts:47
Private
preimage
• preimage: string
Defined in pkg/bitcoin/htlc/btcHTLC.ts:52
Private
priority
• priority: number
Defined in pkg/bitcoin/htlc/btcHTLC.ts:50
Private
receiver
• receiver: ECPairInterface
Defined in pkg/bitcoin/htlc/btcHTLC.ts:49
Private
sender
• sender: ECPairInterface
Defined in pkg/bitcoin/htlc/btcHTLC.ts:48
Methods
calculateFee
▸ calculateFee(): Promise‹object›
Defined in pkg/bitcoin/htlc/btcHTLC.ts:301
Get wanted and max fee.
memberof
BitcoinHTLC
Returns: Promise‹object›
A fee object with a max fee, which is the maximum fee the redeemer of the HTLC should accept and a want fee, which is the desired fee according to the selected priority.
create
▸ create(config
: HTLCConfigBTC): Promise‹string›
Defined in pkg/bitcoin/htlc/btcHTLC.ts:354
Creates an HTLC.
memberof
BitcoinHTLC
Parameters:
Name | Type | Description |
---|---|---|
config | HTLCConfigBTC | Configuration object for the HTLC. |
Returns: Promise‹string›
The hex for the refund transaction.
Private
getFinalScriptsRedeem
▸ getFinalScriptsRedeem(inputIndex
: number, input
: PsbtInput, script
: Buffer, isSegwit
: boolean, isP2SH
: boolean, isP2WSH
: boolean): object
Defined in pkg/bitcoin/htlc/btcHTLC.ts:173
Finalize an HTLC redeem transaction using PSBT.
Parameters:
Name | Type | Description |
---|---|---|
inputIndex | number | The index in the input array. |
input | PsbtInput | The array of transaction inputs. |
script | Buffer | P2WSH redeemscript. |
isSegwit | boolean | Included only for bitcoinjs-lib compatible reasons. |
isP2SH | boolean | Included only for bitcoinjs-lib compatible reasons. |
isP2WSH | boolean | Included only for bitcoinjs-lib compatible reasons. |
Returns: object
A function to finalize and serialize the scripts.
finalScriptSig: Buffer | undefined
finalScriptWitness: Buffer | undefined
Private
getFinalScriptsRefund
▸ getFinalScriptsRefund(inputIndex
: number, input
: PsbtInput, script
: Buffer, isSegwit
: boolean, isP2SH
: boolean, isP2WSH
: boolean): object
Defined in pkg/bitcoin/htlc/btcHTLC.ts:131
Finalize an HTLC refund transaction using PSBT.
Parameters:
Name | Type | Description |
---|---|---|
inputIndex | number | The index in the input array. |
input | PsbtInput | The array of transaction inputs. |
script | Buffer | P2WSH redeemscript. |
isSegwit | boolean | Included only for bitcoinjs-lib compatible reasons. |
isP2SH | boolean | Included only for bitcoinjs-lib compatible reasons. |
isP2WSH | boolean | Included only for bitcoinjs-lib compatible reasons. |
Returns: object
A function to finalize and serialize the scripts.
finalScriptSig: Buffer | undefined
finalScriptWitness: Buffer | undefined
getFundingTxBlockHeight
▸ getFundingTxBlockHeight(): number | undefined
Defined in pkg/bitcoin/htlc/btcHTLC.ts:88
Get block height of funding transaction
memberof
BitcoinHTLC
Returns: number | undefined
Blockheight of funding transaction or undefined if block is not mined/broadcasted yet.
getP2WSH
▸ getP2WSH(hash
: Buffer, sequence
: number): Payment
Defined in pkg/bitcoin/htlc/btcHTLC.ts:230
Calculate the p2wsh to send our money to before creating the timelock refund operation.
memberof
BitcoinHTLC
Parameters:
Name | Type | Description |
---|---|---|
hash | Buffer | SHA256 hash of the secret. |
sequence | number | How many blocks need to be mined before refund is possible. |
Returns: Payment
The pay-to-scripthash object.
Private
getRedeemHex
▸ getRedeemHex(transactionID
: string, p2wsh
: Payment): Promise‹string›
Defined in pkg/bitcoin/htlc/btcHTLC.ts:443
Redeems the HTLC.
memberof
BitcoinHTLC
Parameters:
Name | Type | Description |
---|---|---|
transactionID | string | The transaction id from the funding transaction. |
p2wsh | Payment | Pay-to-witness-script-hash object. |
Returns: Promise‹string›
A redeem hex.
Private
getRefundHex
▸ getRefundHex(transactionID
: string, sequence
: number, p2wsh
: Payment): Promise‹string›
Defined in pkg/bitcoin/htlc/btcHTLC.ts:406
Refunds the HTLC to sender.
memberof
BitcoinHTLC
Parameters:
Name | Type | Description |
---|---|---|
transactionID | string | The transaction id from the funding transaction. |
sequence | number | The timelock as number of blocks. |
p2wsh | Payment | Pay-to-witness-script-hash object. |
Returns: Promise‹string›
A refund hex.
Private
getWitnessPublicKeyHash
▸ getWitnessPublicKeyHash(keyPair
: ECPairInterface): Payment
Defined in pkg/bitcoin/htlc/btcHTLC.ts:216
Helperfunction to get the public key from an ECPair
memberof
BitcoinHTLC
Parameters:
Name | Type | Description |
---|---|---|
keyPair | ECPairInterface | A keyPair initialized as ECPair. |
Returns: Payment
A p2wpkh object.
redeem
▸ redeem(p2wsh
: Payment, amount
: number, secret
: Secret): Promise‹void›
Defined in pkg/bitcoin/htlc/btcHTLC.ts:325
Redeems an HTLC.
memberof
BitcoinHTLC
Parameters:
Name | Type | Description |
---|---|---|
p2wsh | Payment | The Pay-to-witness-script-hash object to redeem. |
amount | number | The amount of satoshi to exchange. |
secret | Secret | The secret object with the correct preimage inside. |
Returns: Promise‹void›
Private
redeemScript
▸ redeemScript(hash
: Buffer, sequence
: number): Buffer
Defined in pkg/bitcoin/htlc/btcHTLC.ts:101
Create the redeem script in bitcoin's scripting language.
memberof
BitcoinHTLC
Parameters:
Name | Type | Description |
---|---|---|
hash | Buffer | SHA256 hash of the secret. |
sequence | number | How many blocks need to be mined before refund is possible. |
Returns: Buffer
A bitcoin script.
Private
sendToP2WSHAddress
▸ sendToP2WSHAddress(p2wsh
: Payment, transactionID
: string, amount
: number): Promise‹string›
Defined in pkg/bitcoin/htlc/btcHTLC.ts:249
Send funds to a pay2witnessScripthash address to be used in the timelock refund operation.
memberof
BitcoinHTLC
Parameters:
Name | Type | Description |
---|---|---|
p2wsh | Payment | Pay-to-witness-script-hash object. |
transactionID | string | A Transaction id with unspent funds. |
amount | number | The amount of satoshi to exchange. |
Returns: Promise‹string›
The hex-coded transaction. This needs to be pushed to the chain using this.pushTX