- BitcoinTxHash
- Deposit
- DepositFunding
- DepositRefund
- DepositScript
- DepositsService
- ElectrumClient
- EthereumAddress
- EthereumBridge
- EthereumTBTCToken
- EthereumTBTCVault
- EthereumWalletRegistry
- Hex
- LedgerLiveEthereumSigner
- MaintenanceService
- OptimisticMinting
- RedemptionsService
- Spv
- TBTC
- WalletTx
- BitcoinClient
- BitcoinHeader
- BitcoinRawTx
- BitcoinRawTxVectors
- BitcoinSpvProof
- BitcoinTx
- BitcoinTxMerkleBranch
- BitcoinTxOutpoint
- BitcoinTxOutput
- Bridge
- ChainEvent
- ChainIdentifier
- DepositReceipt
- DepositRequest
- ElectrumCredentials
- EthereumContractConfig
- RedemptionRequest
- TBTCToken
- TBTCVault
- Wallet
- WalletRegistry
- BitcoinTxInput
- BitcoinUtxo
- DepositRevealedEvent
- DkgResultApprovedEvent
- DkgResultChallengedEvent
- DkgResultSubmittedEvent
- ElectrumClientOptions
- ErrorMatcherFn
- EthereumNetwork
- EthereumSigner
- ExecutionLoggerFn
- NewWalletRegisteredEvent
- OptimisticMintingCancelledEvent
- OptimisticMintingFinalizedEvent
- OptimisticMintingRequest
- OptimisticMintingRequestedEvent
- RedemptionRequestedEvent
- RetrierFn
- TBTCContracts
- BitcoinAddressConverter
- BitcoinCompactSizeUint
- BitcoinHashUtils
- BitcoinHeaderSerializer
- BitcoinLocktimeUtils
- BitcoinPrivateKeyUtils
- BitcoinPublicKeyUtils
- BitcoinScriptUtils
- BitcoinTargetConverter
- assembleBitcoinSpvProof
- backoffRetrier
- computeElectrumScriptHash
- ethereumAddressFromSigner
- ethereumNetworkFromSigner
- extractBitcoinRawTxVectors
- loadEthereumContracts
- retryAll
- skipRetryWhenMatched
- toBitcoinJsLibNetwork
- validateBitcoinHeadersChain
- validateBitcoinSpvProof
- validateDepositReceipt
Ƭ BitcoinTxInput: BitcoinTxOutpoint
& { scriptSig
: Hex
}
Data about a Bitcoin transaction input.
Ƭ BitcoinUtxo: BitcoinTxOutpoint
& { value
: BigNumber
}
Data about a Bitcoin unspent transaction output.
Ƭ DepositRevealedEvent: DepositReceipt
& Pick
<DepositRequest
, "amount"
| "vault"
> & { fundingOutputIndex
: number
; fundingTxHash
: BitcoinTxHash
} & ChainEvent
Represents an event emitted on deposit reveal to the on-chain bridge.
src/lib/contracts/bridge.ts:283
Ƭ DkgResultApprovedEvent: { approver
: ChainIdentifier
; resultHash
: Hex
} & ChainEvent
Represents an event emitted when a DKG result is approved on the on-chain wallet registry.
src/lib/contracts/wallet-registry.ts:64
Ƭ DkgResultChallengedEvent: { challenger
: ChainIdentifier
; reason
: string
; resultHash
: Hex
} & ChainEvent
Represents an event emitted when a DKG result is challenged on the on-chain wallet registry.
src/lib/contracts/wallet-registry.ts:79
Ƭ DkgResultSubmittedEvent: { result
: DkgResult
; resultHash
: Hex
; seed
: Hex
} & ChainEvent
Represents an event emitted when a DKG result is submitted to the on-chain wallet registry.
src/lib/contracts/wallet-registry.ts:45
Ƭ ElectrumClientOptions: object
Additional options used by the Electrum server.
Ƭ ErrorMatcherFn: (err
: unknown
) => boolean
▸ (err
): boolean
Name | Type |
---|---|
err |
unknown |
boolean
True if the error matches, false otherwise.
Ƭ EthereumNetwork: "local"
| "goerli"
| "sepolia"
| "mainnet"
Supported Ethereum networks.
Ƭ EthereumSigner: Signer
| providers.Provider
Represents an Ethereum signer. This type is a wrapper for Ethers-specific types and can be either a Signer that can make write transactions or a Provider that works only in the read-only mode.
Ƭ ExecutionLoggerFn: (msg
: string
) => void
▸ (msg
): void
A function that is called with execution status messages.
Name | Type |
---|---|
msg |
string |
void
Ƭ NewWalletRegisteredEvent: { ecdsaWalletID
: Hex
; walletPublicKeyHash
: Hex
} & ChainEvent
Represents an event emitted when new wallet is registered on the on-chain bridge.
src/lib/contracts/bridge.ts:445
Ƭ OptimisticMintingCancelledEvent: { depositKey
: Hex
; guardian
: ChainIdentifier
} & ChainEvent
Represents an event that is emitted when an optimistic minting request is cancelled on chain.
src/lib/contracts/tbtc-vault.ts:170
Ƭ OptimisticMintingFinalizedEvent: { depositKey
: Hex
; depositor
: ChainIdentifier
; minter
: ChainIdentifier
; optimisticMintingDebt
: BigNumber
} & ChainEvent
Represents an event that is emitted when an optimistic minting request is finalized on chain.
src/lib/contracts/tbtc-vault.ts:186
Ƭ OptimisticMintingRequest: Object
Represents optimistic minting request for the given deposit revealed to the Bridge.
Name | Type | Description |
---|---|---|
finalizedAt |
number |
UNIX timestamp at which the optimistic minting was finalized. 0 if not yet finalized. |
requestedAt |
number |
UNIX timestamp at which the optimistic minting was requested. |
src/lib/contracts/tbtc-vault.ts:120
Ƭ OptimisticMintingRequestedEvent: { amount
: BigNumber
; depositKey
: Hex
; depositor
: ChainIdentifier
; fundingOutputIndex
: number
; fundingTxHash
: BitcoinTxHash
; minter
: ChainIdentifier
} & ChainEvent
Represents an event that is emitted when a new optimistic minting is requested on chain.
src/lib/contracts/tbtc-vault.ts:136
Ƭ RedemptionRequestedEvent: Omit
<RedemptionRequest
, "requestedAt"
> & { walletPublicKeyHash
: Hex
} & ChainEvent
Represents an event emitted on redemption request.
src/lib/contracts/bridge.ts:334
Ƭ RetrierFn<T
>: (fn
: () => Promise
<T
>) => Promise
<T
>
Name |
---|
T |
▸ (fn
): Promise
<T
>
Name | Type | Description |
---|---|---|
fn |
() => Promise <T > |
The function to be retried. |
Promise
<T
>
Ƭ TBTCContracts: Object
Convenience type aggregating all TBTC contracts handles.
Name | Type |
---|---|
bridge |
Bridge |
tbtcToken |
TBTCToken |
tbtcVault |
TBTCVault |
walletRegistry |
WalletRegistry |
• Const
BitcoinAddressConverter: Object
Utility functions allowing to perform Bitcoin address conversions.
Name | Type |
---|---|
addressToOutputScript |
(address : string , bitcoinNetwork : BitcoinNetwork ) => Hex |
addressToPublicKeyHash |
(address : string , bitcoinNetwork : BitcoinNetwork ) => Hex |
outputScriptToAddress |
(script : Hex , bitcoinNetwork : BitcoinNetwork ) => string |
publicKeyHashToAddress |
(publicKeyHash : Hex , witness : boolean , bitcoinNetwork : BitcoinNetwork ) => string |
publicKeyToAddress |
(publicKey : Hex , bitcoinNetwork : BitcoinNetwork , witness : boolean ) => string |
src/lib/bitcoin/address.ts:112
• Const
BitcoinCompactSizeUint: Object
Utility functions allowing to deal with Bitcoin compact size uints.
Name | Type |
---|---|
read |
(varLenData : Hex ) => { byteLength : number ; value : number } |
• Const
BitcoinHashUtils: Object
Utility functions allowing to deal with Bitcoin hashes.
Name | Type |
---|---|
computeHash160 |
(text : Hex ) => Hex |
computeHash256 |
(text : Hex ) => Hex |
computeSha256 |
(text : Hex ) => Hex |
hashLEToBigNumber |
(hash : Hex ) => BigNumber |
• Const
BitcoinHeaderSerializer: Object
Utility functions allowing to serialize and deserialize Bitcoin block headers.
Name | Type |
---|---|
deserializeHeader |
(rawHeader : Hex ) => BitcoinHeader |
deserializeHeadersChain |
(rawHeadersChain : Hex ) => BitcoinHeader [] |
serializeHeader |
(header : BitcoinHeader ) => Hex |
• Const
BitcoinLocktimeUtils: Object
Utility functions allowing to deal with Bitcoin locktime.
Name | Type |
---|---|
calculateLocktime |
(locktimeStartedAt : number , locktimeDuration : number ) => Hex |
locktimeToNumber |
(locktimeLE : string | Buffer ) => number |
• Const
BitcoinPrivateKeyUtils: Object
Utility functions allowing to perform operations on Bitcoin ECDSA private keys.
Name | Type |
---|---|
createKeyPair |
(privateKey : string , bitcoinNetwork : BitcoinNetwork ) => ECPairInterface |
src/lib/bitcoin/ecdsa-key.ts:77
• Const
BitcoinPublicKeyUtils: Object
Utility functions allowing to perform operations on Bitcoin ECDSA public keys.
Name | Type |
---|---|
compressPublicKey |
(publicKey : Hex ) => string |
isCompressedPublicKey |
(publicKey : Hex ) => boolean |
src/lib/bitcoin/ecdsa-key.ts:51
• Const
BitcoinScriptUtils: Object
Utility functions allowing to deal with Bitcoin scripts.
Name | Type |
---|---|
isP2PKHScript |
(script : Hex ) => boolean |
isP2SHScript |
(script : Hex ) => boolean |
isP2WPKHScript |
(script : Hex ) => boolean |
isP2WSHScript |
(script : Hex ) => boolean |
• Const
BitcoinTargetConverter: Object
Utility functions allowing to perform Bitcoin target conversions.
Name | Type |
---|---|
bitsToTarget |
(bits : number ) => BigNumber |
targetToDifficulty |
(target : BigNumber ) => BigNumber |
▸ assembleBitcoinSpvProof(transactionHash
, requiredConfirmations
, bitcoinClient
): Promise
<BitcoinTx
& BitcoinSpvProof
>
Assembles a proof that a given transaction was included in the blockchain and has accumulated the required number of confirmations.
Name | Type | Description |
---|---|---|
transactionHash |
BitcoinTxHash |
Hash of the transaction being proven. |
requiredConfirmations |
number |
Required number of confirmations. |
bitcoinClient |
BitcoinClient |
Bitcoin client used to interact with the network. |
Promise
<BitcoinTx
& BitcoinSpvProof
>
Bitcoin transaction along with the inclusion proof.
▸ backoffRetrier<T
>(retries
, backoffStepMs?
, logger?
, errorMatcher?
): RetrierFn
<T
>
Returns a retrier that can be passed a function to be retried retries
number of times, with exponential backoff. The result will return the
function's return value if no exceptions are thrown. It will only retry if
the function throws an exception matched by matcher
; {@see retryAll} can
be used to retry no matter the exception, though this is not necessarily
recommended in production.
Example usage:
await url.get("https://example.com/") // may transiently fail
// Retries 3 times with exponential backoff, no matter what error is
// reported by `url.get`.
backoffRetrier(3)(async () => url.get("https://example.com"))
// Retries 3 times with exponential backoff, but only if the error
// message includes "server unavailable".
backoffRetrier(3, (_) => _.message.includes('server unavailable'))(
async () => url.get("https://example.com"))
)
Name |
---|
T |
Name | Type | Default value | Description |
---|---|---|---|
retries |
number |
undefined |
The number of retries to perform before bubbling the failure out. |
backoffStepMs |
number |
1000 |
Initial backoff step in milliseconds that will be increased exponentially for subsequent retry attempts. (default = 1000 ms) |
logger |
ExecutionLoggerFn |
console.debug |
A logger function to pass execution messages. |
errorMatcher? |
ErrorMatcherFn |
retryAll |
A matcher function that receives the error when an exception is thrown, and returns true if the error should lead to a retry. A false return will rethrow the error and terminate the retry loop. |
RetrierFn
<T
>
A function that can retry any function.
▸ computeElectrumScriptHash(script
): string
Converts a Bitcoin script to an Electrum script hash. See [Electrum protocol]https://electrumx.readthedocs.io/en/stable/protocol-basics.html#script-hashes
Name | Type | Description |
---|---|---|
script |
Hex |
Bitcoin script as hex string |
string
Electrum script hash as a hex string.
src/lib/electrum/client.ts:649
▸ ethereumAddressFromSigner(signer
): Promise
<EthereumAddress
| undefined
>
Resolves the Ethereum address tied to the given signer. The address cannot be resolved for signers that works in the read-only mode
Name | Type | Description |
---|---|---|
signer |
EthereumSigner |
The signer whose address should be resolved. |
Promise
<EthereumAddress
| undefined
>
Ethereum address or undefined for read-only signers.
Throws
Throws an error if the address of the signer is not a proper Ethereum address.
▸ ethereumNetworkFromSigner(signer
): Promise
<EthereumNetwork
>
Resolves the Ethereum network the given signer is tied to.
Name | Type | Description |
---|---|---|
signer |
EthereumSigner |
The signer whose network should be resolved. |
Promise
<EthereumNetwork
>
Ethereum network.
▸ extractBitcoinRawTxVectors(rawTransaction
): BitcoinRawTxVectors
Decomposes a transaction in the raw representation into version, vector of inputs, vector of outputs and locktime.
Name | Type | Description |
---|---|---|
rawTransaction |
BitcoinRawTx |
Transaction in the raw format. |
Transaction data with fields represented as un-prefixed hex strings.
▸ loadEthereumContracts(signer
, network
): Promise
<TBTCContracts
>
Loads Ethereum implementation of tBTC contracts for the given Ethereum network and attaches the given signer there.
Name | Type | Description |
---|---|---|
signer |
EthereumSigner |
Signer that should be attached to tBTC contracts. |
network |
EthereumNetwork |
Ethereum network. |
Promise
<TBTCContracts
>
Handle to tBTC contracts.
Throws
Throws an error if the signer's Ethereum network is other than the one used to load tBTC contracts.
▸ retryAll(error
): true
A convenience matcher for withBackoffRetries that retries irrespective of the error.
Name | Type | Description |
---|---|---|
error |
any |
The error to match against. Not necessarily an Error instance, since the retriable function may throw a non-Error. |
true
Always returns true.
▸ skipRetryWhenMatched(matchers
): ErrorMatcherFn
A matcher to specify list of error messages that should abort the retry loop and throw immediately.
Name | Type | Description |
---|---|---|
matchers |
(string | RegExp )[] |
List of patterns for error matching. |
Matcher function that returns false if error matches one of the patterns. True is returned if no matches are found and retry loop should continue
▸ toBitcoinJsLibNetwork(bitcoinNetwork
): networks.Network
Converts the provided BitcoinNetwork enumeration to a format expected
by the bitcoinjs-lib
library.
Name | Type | Description |
---|---|---|
bitcoinNetwork |
BitcoinNetwork |
Specified Bitcoin network. |
networks.Network
Network representation compatible with the bitcoinjs-lib
library.
Throws
An error if the network is not supported by bitcoinjs-lib
.
▸ validateBitcoinHeadersChain(headers
, previousEpochDifficulty
, currentEpochDifficulty
): void
Validates a chain of consecutive block headers by checking each header's difficulty, hash, and continuity with the previous header. This function can be used to validate a series of Bitcoin block headers for their validity.
Name | Type | Description |
---|---|---|
headers |
BitcoinHeader [] |
An array of block headers that form the chain to be validated. |
previousEpochDifficulty |
BigNumber |
The difficulty of the previous Bitcoin epoch. |
currentEpochDifficulty |
BigNumber |
The difficulty of the current Bitcoin epoch. |
void
An empty return value.
Dev
The block headers must come from Bitcoin epochs with difficulties marked by the previous and current difficulties. If a Bitcoin difficulty relay is used to provide these values and the relay is up-to-date, only the recent block headers will pass validation. Block headers older than the current and previous Bitcoin epochs will fail.
Throws
If any of the block headers are invalid, or if the block header chain is not continuous.
▸ validateBitcoinSpvProof(transactionHash
, requiredConfirmations
, previousDifficulty
, currentDifficulty
, bitcoinClient
): Promise
<void
>
Proves that a transaction with the given hash is included in the Bitcoin blockchain by validating the transaction's inclusion in the Merkle tree and verifying that the block containing the transaction has enough confirmations.
Name | Type | Description |
---|---|---|
transactionHash |
BitcoinTxHash |
The hash of the transaction to be validated. |
requiredConfirmations |
number |
The number of confirmations required for the transaction to be considered valid. The transaction has 1 confirmation when it is in the block at the current blockchain tip. Every subsequent block added to the blockchain is one additional confirmation. |
previousDifficulty |
BigNumber |
The difficulty of the previous Bitcoin epoch. |
currentDifficulty |
BigNumber |
The difficulty of the current Bitcoin epoch. |
bitcoinClient |
BitcoinClient |
The client for interacting with the Bitcoin blockchain. |
Promise
<void
>
An empty return value.
Throws
If the transaction is not included in the Bitcoin blockchain or if the block containing the transaction does not have enough confirmations.
Dev
The function should be used within a try-catch block.
▸ validateDepositReceipt(receipt
): void
Validates the given deposit receipt. Throws in case of a validation error.
Name | Type | Description |
---|---|---|
receipt |
DepositReceipt |
The validated deposit receipt. |
void
Dev
This function does not validate the depositor's identifier as its validity is chain-specific. This parameter must be validated outside.