- ArbitrumL2BitcoinDepositor
- ArbitrumL2TBTCToken
- BaseL2BitcoinDepositor
- BaseL2TBTCToken
- BitcoinTxHash
- CrossChainDepositor
- Deposit
- DepositFunding
- DepositRefund
- DepositScript
- DepositsService
- ElectrumClient
- EthereumAddress
- EthereumBridge
- EthereumCrossChainExtraDataEncoder
- EthereumDepositorProxy
- EthereumL1BitcoinDepositor
- EthereumTBTCToken
- EthereumTBTCVault
- EthereumWalletRegistry
- Hex
- MaintenanceService
- OptimisticMinting
- RedemptionsService
- Spv
- TBTC
- WalletTx
- BitcoinClient
- BitcoinHeader
- BitcoinRawTx
- BitcoinRawTxVectors
- BitcoinSpvProof
- BitcoinTx
- BitcoinTxMerkleBranch
- BitcoinTxOutpoint
- BitcoinTxOutput
- Bridge
- ChainEvent
- ChainIdentifier
- CrossChainContractsLoader
- CrossChainExtraDataEncoder
- DepositReceipt
- DepositRequest
- DepositorProxy
- ElectrumCredentials
- EthereumContractConfig
- L1BitcoinDepositor
- L2BitcoinDepositor
- L2TBTCToken
- RedeemerProxy
- RedemptionRequest
- TBTCToken
- TBTCVault
- Wallet
- WalletRegistry
- BitcoinTxInput
- BitcoinUtxo
- ChainMapping
- CrossChainContracts
- CrossChainDepositorMode
- DepositRevealedEvent
- DkgResultApprovedEvent
- DkgResultChallengedEvent
- DkgResultSubmittedEvent
- ElectrumClientOptions
- ErrorMatcherFn
- EthereumSigner
- ExecutionLoggerFn
- L1CrossChainContracts
- L2Chain
- L2CrossChainContracts
- NewWalletRegisteredEvent
- OptimisticMintingCancelledEvent
- OptimisticMintingFinalizedEvent
- OptimisticMintingRequest
- OptimisticMintingRequestedEvent
- RedemptionRequestedEvent
- RetrierFn
- TBTCContracts
- BitcoinAddressConverter
- BitcoinCompactSizeUint
- BitcoinHashUtils
- BitcoinHeaderSerializer
- BitcoinLocktimeUtils
- BitcoinPrivateKeyUtils
- BitcoinPublicKeyUtils
- BitcoinScriptUtils
- BitcoinTargetConverter
- ChainMappings
- assembleBitcoinSpvProof
- backoffRetrier
- chainIdFromSigner
- computeElectrumScriptHash
- ethereumAddressFromSigner
- ethereumCrossChainContractsLoader
- extractBitcoinRawTxVectors
- loadArbitrumCrossChainContracts
- loadBaseCrossChainContracts
- loadEthereumCoreContracts
- packRevealDepositParameters
- 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.
Ƭ ChainMapping: Object
Type representing a mapping between specific L1 and L2 chains.
Name | Type | Description |
---|---|---|
arbitrum? |
Arbitrum |
Identifier of the Arbitrum L2 chain. |
base? |
Base |
Identifier of the Base L2 chain. |
ethereum? |
Ethereum |
Identifier of the Ethereum L1 chain. |
Ƭ CrossChainContracts: L2CrossChainContracts
& L1CrossChainContracts
Convenience type aggregating TBTC cross-chain contracts forming a connector between TBTC L1 ledger chain and a specific supported L2/side-chain.
lib/contracts/cross-chain.ts:12
Ƭ CrossChainDepositorMode: "L2Transaction"
| "L1Transaction"
Mode of operation for the cross-chain depositor proxy:
- [L2Transaction]: The proxy will reveal the deposit using a transaction on the L2 chain. The tBTC system is responsible for relaying the deposit to the tBTC L1 chain.
- [L1Transaction]: The proxy will directly reveal the deposit using a transaction on the tBTC L1 chain.
services/deposits/cross-chain.ts:19
Ƭ DepositRevealedEvent: DepositReceipt
& Pick
<DepositRequest
, "amount"
| "vault"
> & { fundingOutputIndex
: number
; fundingTxHash
: BitcoinTxHash
} & ChainEvent
Represents an event emitted on deposit reveal to the on-chain bridge.
Ƭ DkgResultApprovedEvent: { approver
: ChainIdentifier
; resultHash
: Hex
} & ChainEvent
Represents an event emitted when a DKG result is approved on the on-chain wallet registry.
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.
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.
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.
Ƭ 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
Ƭ L1CrossChainContracts: Object
Aggregates L1-specific TBTC cross-chain contracts.
Name | Type |
---|---|
l1BitcoinDepositor |
L1BitcoinDepositor |
lib/contracts/cross-chain.ts:25
Ƭ L2Chain: Exclude
<keyof typeof Chains
, "Ethereum"
>
Layer 2 chains supported by tBTC v2 contracts.
Ƭ L2CrossChainContracts: Object
Aggregates L2-specific TBTC cross-chain contracts.
Name | Type |
---|---|
l2BitcoinDepositor |
L2BitcoinDepositor |
l2TbtcToken |
L2TBTCToken |
lib/contracts/cross-chain.ts:17
Ƭ NewWalletRegisteredEvent: { ecdsaWalletID
: Hex
; walletPublicKeyHash
: Hex
} & ChainEvent
Represents an event emitted when new wallet is registered on the on-chain bridge.
Ƭ OptimisticMintingCancelledEvent: { depositKey
: Hex
; guardian
: ChainIdentifier
} & ChainEvent
Represents an event that is emitted when an optimistic minting request is cancelled on chain.
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.
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. |
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.
lib/contracts/tbtc-vault.ts:136
Ƭ RedemptionRequestedEvent: Omit
<RedemptionRequest
, "requestedAt"
> & { walletPublicKeyHash
: Hex
} & ChainEvent
Represents an event emitted on redemption request.
Ƭ 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 core contracts.
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 |
• 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 |
• Const
BitcoinPublicKeyUtils: Object
Utility functions allowing to perform operations on Bitcoin ECDSA public keys.
Name | Type |
---|---|
compressPublicKey |
(publicKey : Hex ) => string |
isCompressedPublicKey |
(publicKey : Hex ) => boolean |
• 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 |
• Const
ChainMappings: ChainMapping
[]
List of chain mappings supported by tBTC v2 contracts.
▸ 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.
▸ chainIdFromSigner(signer
): Promise
<string
>
Resolves the chain ID from the given signer.
Name | Type | Description |
---|---|---|
signer |
EthereumSigner |
The signer whose chain ID should be resolved. |
Promise
<string
>
Chain ID as a string.
▸ 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.
▸ 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.
▸ ethereumCrossChainContractsLoader(signer
, chainId
): Promise
<CrossChainContractsLoader
>
Creates the Ethereum implementation of tBTC cross-chain contracts loader. The provided signer is attached to loaded L1 contracts. The given Ethereum chain ID is used to load the L1 contracts and resolve the chain mapping that provides corresponding L2 chains IDs.
Name | Type | Description |
---|---|---|
signer |
EthereumSigner |
Ethereum L1 signer. |
chainId |
Ethereum |
Ethereum L1 chain ID. |
Promise
<CrossChainContractsLoader
>
Loader for tBTC cross-chain contracts.
Throws
Throws an error if the signer's Ethereum chain ID is other than the one used to construct the loader.
▸ 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.
▸ loadArbitrumCrossChainContracts(signer
, chainId
): Promise
<L2CrossChainContracts
>
Loads Arbitrum implementation of tBTC cross-chain contracts for the given Arbitrum chain ID and attaches the given signer there.
Name | Type | Description |
---|---|---|
signer |
EthereumSigner |
Signer that should be attached to the contracts. |
chainId |
Arbitrum |
Arbitrum chain ID. |
Promise
<L2CrossChainContracts
>
Handle to the contracts.
Throws
Throws an error if the signer's Arbitrum chain ID is other than the one used to load contracts.
▸ loadBaseCrossChainContracts(signer
, chainId
): Promise
<L2CrossChainContracts
>
Loads Base implementation of tBTC cross-chain contracts for the given Base chain ID and attaches the given signer there.
Name | Type | Description |
---|---|---|
signer |
EthereumSigner |
Signer that should be attached to the contracts. |
chainId |
Base |
Base chain ID. |
Promise
<L2CrossChainContracts
>
Handle to the contracts.
Throws
Throws an error if the signer's Base chain ID is other than the one used to load contracts.
▸ loadEthereumCoreContracts(signer
, chainId
): Promise
<TBTCContracts
>
Loads Ethereum implementation of tBTC core contracts for the given Ethereum chain ID and attaches the given signer there.
Name | Type | Description |
---|---|---|
signer |
EthereumSigner |
Signer that should be attached to tBTC contracts. |
chainId |
Ethereum |
Ethereum chain ID. |
Promise
<TBTCContracts
>
Handle to tBTC core contracts.
Throws
Throws an error if the signer's Ethereum chain ID is other than the one used to load tBTC contracts.
▸ packRevealDepositParameters(depositTx
, depositOutputIndex
, deposit
, vault?
): Object
Packs deposit parameters to match the ABI of the revealDeposit and revealDepositWithExtraData functions of the Ethereum Bridge contract.
Name | Type | Description |
---|---|---|
depositTx |
BitcoinRawTxVectors |
Deposit transaction data |
depositOutputIndex |
number |
Index of the deposit transaction output that funds the revealed deposit |
deposit |
DepositReceipt |
Data of the revealed deposit |
vault? |
ChainIdentifier |
Optional parameter denoting the vault the given deposit should be routed to |
Object
Packed parameters.
Name | Type |
---|---|
extraData |
undefined | string |
fundingTx |
{ inputVector : string ; locktime : string ; outputVector : string ; version : string } |
fundingTx.inputVector |
string |
fundingTx.locktime |
string |
fundingTx.outputVector |
string |
fundingTx.version |
string |
reveal |
{ blindingFactor : string ; fundingOutputIndex : number = depositOutputIndex; refundLocktime : string ; refundPubKeyHash : string ; vault : string ; walletPubKeyHash : string } |
reveal.blindingFactor |
string |
reveal.fundingOutputIndex |
number |
reveal.refundLocktime |
string |
reveal.refundPubKeyHash |
string |
reveal.vault |
string |
reveal.walletPubKeyHash |
string |
▸ 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.