diff --git a/.github/workflows/contracts-docs.yml b/.github/workflows/contracts-docs.yml index 6a713b8dd..6202106c1 100644 --- a/.github/workflows/contracts-docs.yml +++ b/.github/workflows/contracts-docs.yml @@ -78,7 +78,7 @@ jobs: addTOC: false verifyCommits: true destinationRepo: threshold-network/threshold - destinationFolder: ./docs/app-development/tbtc-v2/tbtc-v2-api + destinationFolder: ./docs/app-development/tbtc-v2/tbtc-contracts-api/tbtc-v2-api destinationBaseBranch: main userEmail: 38324465+thesis-valkyrie@users.noreply.github.com userName: Valkyrie diff --git a/.github/workflows/system-tests.yml b/.github/workflows/system-tests.yml index eb158f401..1f60ea09f 100644 --- a/.github/workflows/system-tests.yml +++ b/.github/workflows/system-tests.yml @@ -13,7 +13,7 @@ jobs: - uses: actions/setup-node@v3 with: - node-version: "14.x" + node-version: "18.x" cache: "yarn" cache-dependency-path: system-tests/yarn.lock @@ -28,8 +28,7 @@ jobs: working-directory: ./solidity run: | npx hardhat node --no-deploy & - HH_NODE_PID=$! - while ! lsof -n -Fn -p $HH_NODE_PID | grep -q '^n.*:8545$'; do sleep 10; done + while [[ -z $(lsof -i :8545 -t) ]]; do echo "Waiting for port 8545 to be open..."; sleep 10; done - name: Deploy contracts working-directory: ./solidity @@ -63,13 +62,14 @@ jobs: yarn test ./test/deposit-redemption.test.ts --network $ETH_NETWORK system-tests-minting-unminting: + needs: system-tests-deposit-redemption runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: "14.x" + node-version: "18.x" cache: "yarn" cache-dependency-path: system-tests/yarn.lock @@ -84,8 +84,7 @@ jobs: working-directory: ./solidity run: | npx hardhat node --no-deploy & - HH_NODE_PID=$! - while ! lsof -n -Fn -p $HH_NODE_PID | grep -q '^n.*:8545$'; do sleep 10; done + while [[ -z $(lsof -i :8545 -t) ]]; do echo "Waiting for port 8545 to be open..."; sleep 10; done - name: Deploy contracts working-directory: ./solidity diff --git a/.github/workflows/typescript.yml b/.github/workflows/typescript.yml index ae14b8a3f..59a4f6374 100644 --- a/.github/workflows/typescript.yml +++ b/.github/workflows/typescript.yml @@ -105,3 +105,36 @@ jobs: - name: Check formatting run: yarn format + + typescript-docs: + needs: typescript-detect-changes + if: | + github.event_name == 'push' + || needs.typescript-detect-changes.outputs.path-filter == 'true' + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./typescript + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version: "18.x" + cache: "yarn" + cache-dependency-path: typescript/yarn.lock + + - name: Configure git to don't use unauthenticated protocol + run: git config --global url."https://".insteadOf git:// + + - name: Install dependencies + run: yarn install + + - name: Build + run: yarn build + + - name: Generate docs + run: yarn docs + + - name: Check docs up to date + run: git diff --exit-code || exit 1 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f63f7acc3..b57092008 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -41,3 +41,9 @@ repos: files: "^cross-chain/arbitrum/" language: script description: "Checks cross-chain/arbitrum directory code according to the formatting configuration" + - id: typescript-docs + name: "Generate typescript API reference docs" + entry: /usr/bin/env bash -c "cd typescript && yarn docs" + files: "^typescript/" + language: script + description: "Generates typescript API reference docs according to the typedoc configuration" diff --git a/CONTRIBUTING.adoc b/CONTRIBUTING.adoc index a3d6a959b..d92c23f53 100644 --- a/CONTRIBUTING.adoc +++ b/CONTRIBUTING.adoc @@ -11,8 +11,8 @@ propose changes to this document in a pull request. 1. Fork https://github.com/keep-network/tbtc-v2[`keep-network/tbtc-v2`] 2. Clone your fork -3. Follow the - link:README.adoc#Installation[installation & build steps] in the README. +3. Each module has their own setup instructions. Follow the README of the + specific module you want to contribute to. 4. Set up the <>. 5. Open a PR against the `main` branch and describe the change you are intending to undertake in the PR description. diff --git a/README.adoc b/README.adoc index 47b109de5..92a6449a6 100644 --- a/README.adoc +++ b/README.adoc @@ -2,9 +2,9 @@ = TBTC v2 -https://github.com/keep-network/tbtc-v2/actions/workflows/contracts.yml[image:https://img.shields.io/github/actions/workflow/status/keep-network/tbtc-v2/contracts.yml?branch=main&event=push&label=TBTC%20contracts%20build[TBTC contracts build status]] -https://github.com/keep-network/tbtc-v2/actions/workflows/typescript.yml[image:https://img.shields.io/github/actions/workflow/status/keep-network/tbtc-v2/typescript.yml?branch=main&event=push&label=TypeScript%20bindings%20build[TypeScript bindings build status]] -https://github.com/keep-network/tbtc-v2/actions/workflows/yearn.yml[image:https://img.shields.io/github/actions/workflow/status/keep-network/tbtc-v2/yearn.yml?branch=main&vent=push&label=Yearn%20build[Yearn build status]] +https://github.com/keep-network/tbtc-v2/actions/workflows/contracts.yml[image:https://img.shields.io/github/actions/workflow/status/keep-network/tbtc-v2/contracts.yml?branch=main&event=push&label=Core%20contracts%20build[Core contracts build status]] +https://github.com/keep-network/tbtc-v2/actions/workflows/typescript.yml[image:https://img.shields.io/github/actions/workflow/status/keep-network/tbtc-v2/typescript.yml?branch=main&event=push&label=SDK%20build[SDK build status]] +https://github.com/keep-network/tbtc-v2/actions/workflows/yearn.yml[image:https://img.shields.io/github/actions/workflow/status/keep-network/tbtc-v2/yearn.yml?branch=main&vent=push&label=Yearn%20contracts%20build[Yearn contracts build status]] https://github.com/keep-network/tbtc-v2/actions/workflows/system-tests.yml[image:https://img.shields.io/github/actions/workflow/status/keep-network/tbtc-v2/system-tests.yml?branch=main&event=schedule&label=System%20tests[System tests status]] https://github.com/keep-network/tbtc-v2/actions/workflows/monitoring.yml[image:https://img.shields.io/github/actions/workflow/status/keep-network/tbtc-v2/monitoring.yml?branch=main&event=push&label=Monitoring%20build[Monitoring build status]] @@ -37,17 +37,7 @@ math, not hardware or people. Additionally, TBTC v2 is open and accessible to anyone. TBTC v2 allows anyone to use Bitcoin in the expanding DeFi and Web3 universe -without a third-party intermediary. - -This repository contains: - -- TBTC v2 link:solidity/[Solidity smart contracts], -- TBTC v2 link:typescript/[Typescript library], -- TBTC v2 link:system-tests/[System tests] -- TBTC v2 link:docs/[documentation], -- TBTC v2 Yearn vault link:yearn/[Solidity smart contracts], -- TBTC v2 link:monitoring/[monitoring tool], -- TBTC v2 Cross-chain link:cross-chain/[smart contracts]. +without a third-party intermediary. toc::[] @@ -64,41 +54,28 @@ Depositing Bitcoin into the tBTCv2 bridge grants a transferable Bank balance, wh can be used to mint a supply-pegged ERC-20: TBTC. For an in-depth explanation about the design, see link:docs/rfc/rfc-1.adoc[RFC 1: tBTCv2 Design]. -== Installation - -=== Prerequisites -* clone the repository -* link:https://nodejs.org/en/[Node.js] v14.21.2 -* yarn: `$ npm install -g yarn` -* configure git to use https - -``` -git config --global url."https://".insteadOf git:// -``` - -* Python 3.11.1 for `node-gyp`. It is - https://opensource.com/article/19/5/python-3-default-mac[suggested] to use - `pyenv` to manage multiple Python versions. -``` -brew install pyenv -pyenv install 3.11.1 -``` - -=== Install and Test Contracts - -``` -cd solidity -yarn install --frozen-lockfile -yarn build -yarn test -yarn test:integration -``` - -=== Install and Test TypeScript Library - -``` -cd typescript -yarn install --frozen-lockfile -yarn build -yarn test -``` +== Repository structure + +This repository contains the following modules: + +- link:solidity/[Core smart contracts], +- link:typescript/[SDK TypeScript library], +- link:system-tests/[System tests] +- link:docs/[Documentation], +- link:yearn/[Yearn vault smart contracts], +- link:monitoring/[Monitoring tool], +- link:cross-chain/[Cross-chain smart contracts]. + +Please refer module-level README for specific module's installation and +usage instructions. + +== Contributing + +Contributions are always welcome! Feel free to open any issue or send a +pull request. Please see link:CONTRIBUTING.adoc[CONTRIBUTING.adoc] to +learn more. + +== Security + +Please see link:SECURITY.adoc[SECURITY.adoc] to learn more about +tBTC v2 security policy. \ No newline at end of file diff --git a/solidity/hardhat.config.ts b/solidity/hardhat.config.ts index 149c67b16..6d04eb795 100644 --- a/solidity/hardhat.config.ts +++ b/solidity/hardhat.config.ts @@ -101,7 +101,7 @@ const config: HardhatUserConfig = { allowUnlimitedContractSize: process.env.TEST_USE_STUBS_TBTC === "true", }, system_tests: { - url: "http://localhost:8545", + url: "http://127.0.0.1:8545", tags: ["allowStubs"], }, development: { diff --git a/system-tests/hardhat.config.ts b/system-tests/hardhat.config.ts index 76df3a4e8..ae9fef757 100644 --- a/system-tests/hardhat.config.ts +++ b/system-tests/hardhat.config.ts @@ -8,10 +8,10 @@ import "hardhat-deploy" const config: HardhatUserConfig = { networks: { development: { - url: "http://localhost:8545", + url: "http://127.0.0.1:8545", }, system_tests: { - url: "http://localhost:8545", + url: "http://127.0.0.1:8545", }, }, diff --git a/system-tests/package.json b/system-tests/package.json index 01436b1b7..cef56ce98 100644 --- a/system-tests/package.json +++ b/system-tests/package.json @@ -12,14 +12,13 @@ "lint:fix:eslint": "eslint . --fix", "lint:config": "prettier --check '**/*.@(json|yaml)'", "lint:config:fix": "prettier --write '**/*.@(json|yaml)'", - "test": "hardhat test", - "postinstall": "npm rebuild" + "test": "hardhat test" }, "files": [ "test/**/*" ], "dependencies": { - "@keep-network/tbtc-v2.ts": "development", + "@keep-network/tbtc-v2.ts": "2.0.0-dev.0", "elliptic": "^6.5.4", "wif": "^2.0.6" }, @@ -42,7 +41,7 @@ "eslint-config-keep": "github:keep-network/eslint-config-keep", "ethereum-waffle": "4.0.0-alpha.25", "ethers": "^5.5.3", - "hardhat": "^2.8.3", + "hardhat": "^2.18.2", "hardhat-deploy": "^0.11.10", "mocha": "^9.0.2", "prettier": "^2.3.2", @@ -50,6 +49,6 @@ "typescript": "^4.3.5" }, "engines": { - "node": ">= 14.0.0" + "node": ">= 16" } } diff --git a/system-tests/test/deposit-redemption.test.ts b/system-tests/test/deposit-redemption.test.ts index f40c0c6d0..c5052fef7 100644 --- a/system-tests/test/deposit-redemption.test.ts +++ b/system-tests/test/deposit-redemption.test.ts @@ -4,8 +4,10 @@ import { ElectrumClient, EthereumBridge, BitcoinTransactionHash, + BitcoinNetwork, } from "@keep-network/tbtc-v2.ts/dist/src" -import { computeHash160 } from "@keep-network/tbtc-v2.ts/dist/src/bitcoin" +import { computeHash160, createAddressFromPublicKey } from "@keep-network/tbtc-v2.ts/dist/src/bitcoin" +import { Hex } from "@keep-network/tbtc-v2.ts/dist/src/hex" import { BigNumber, constants, Contract } from "ethers" import chai, { expect } from "chai" import { submitDepositTransaction } from "@keep-network/tbtc-v2.ts/dist/src/deposit" @@ -59,6 +61,7 @@ describe("System Test - Deposit and redemption", () => { const depositAmount = BigNumber.from(2000000) const depositSweepTxFee = BigNumber.from(10000) + const depositTxFee = BigNumber.from(1500) // Number of retries for Electrum requests. const ELECTRUM_RETRIES = 5 // Initial backoff step in milliseconds that will be increased exponentially for @@ -137,11 +140,22 @@ describe("System Test - Deposit and redemption", () => { Generated deposit data: ${JSON.stringify(deposit)} `) + + const depositorBitcoinAddress = createAddressFromPublicKey( + Hex.from(systemTestsContext.depositorBitcoinKeyPair.publicKey.compressed), + BitcoinNetwork.Testnet, + ) + const depositorUtxos = await electrumClient.findAllUnspentTransactionOutputs( + depositorBitcoinAddress + ) + ;({ depositUtxo } = await submitDepositTransaction( deposit, systemTestsContext.depositorBitcoinKeyPair.wif, electrumClient, - true + true, + depositorUtxos, + depositTxFee )) console.log(` @@ -408,11 +422,22 @@ describe("System Test - Deposit and redemption", () => { Generated deposit data: ${JSON.stringify(deposit)} `) + + const depositorBitcoinAddress = createAddressFromPublicKey( + Hex.from(systemTestsContext.depositorBitcoinKeyPair.publicKey.compressed), + BitcoinNetwork.Testnet, + ) + const depositorUtxos = await electrumClient.findAllUnspentTransactionOutputs( + depositorBitcoinAddress + ) + ;({ depositUtxo } = await submitDepositTransaction( deposit, systemTestsContext.depositorBitcoinKeyPair.wif, electrumClient, - true + true, + depositorUtxos, + depositTxFee )) console.log(` diff --git a/system-tests/test/minting-unminting.test.ts b/system-tests/test/minting-unminting.test.ts index bb6776add..865290db0 100644 --- a/system-tests/test/minting-unminting.test.ts +++ b/system-tests/test/minting-unminting.test.ts @@ -5,8 +5,10 @@ import { EthereumAddress, EthereumBridge, BitcoinTransactionHash, + BitcoinNetwork, } from "@keep-network/tbtc-v2.ts/dist/src" -import { computeHash160 } from "@keep-network/tbtc-v2.ts/dist/src/bitcoin" +import { computeHash160, createAddressFromPublicKey } from "@keep-network/tbtc-v2.ts/dist/src/bitcoin" +import { Hex } from "@keep-network/tbtc-v2.ts/dist/src/hex" import { BigNumber, constants, Contract, utils as ethersUtils } from "ethers" import chai, { expect } from "chai" import { submitDepositTransaction } from "@keep-network/tbtc-v2.ts/dist/src/deposit" @@ -62,6 +64,7 @@ describe("System Test - Minting and unminting", () => { const depositAmount = BigNumber.from(2000000) const depositSweepTxFee = BigNumber.from(10000) + const depositTxFee = BigNumber.from(1500) // Number of retries for Electrum requests. const ELECTRUM_RETRIES = 5 // Initial backoff step in milliseconds that will be increased exponentially for @@ -140,11 +143,22 @@ describe("System Test - Minting and unminting", () => { Generated deposit data: ${JSON.stringify(deposit)} `) + + const depositorBitcoinAddress = createAddressFromPublicKey( + Hex.from(systemTestsContext.depositorBitcoinKeyPair.publicKey.compressed), + BitcoinNetwork.Testnet, + ) + const depositorUtxos = await electrumClient.findAllUnspentTransactionOutputs( + depositorBitcoinAddress + ) + ;({ depositUtxo } = await submitDepositTransaction( deposit, systemTestsContext.depositorBitcoinKeyPair.wif, electrumClient, - true + true, + depositorUtxos, + depositTxFee )) console.log(` diff --git a/system-tests/yarn.lock b/system-tests/yarn.lock index 9d178326c..2b4efbd6b 100644 --- a/system-tests/yarn.lock +++ b/system-tests/yarn.lock @@ -180,6 +180,42 @@ eth-lib "^0.2.8" ethereumjs-util "^5.2.0" +"@chainsafe/as-sha256@^0.3.1": + version "0.3.1" + resolved "https://registry.yarnpkg.com/@chainsafe/as-sha256/-/as-sha256-0.3.1.tgz#3639df0e1435cab03f4d9870cc3ac079e57a6fc9" + integrity sha512-hldFFYuf49ed7DAakWVXSJODuq3pzJEguD8tQ7h+sGkM18vja+OFoJI9krnGmgzyuZC2ETX0NOIcCTy31v2Mtg== + +"@chainsafe/persistent-merkle-tree@^0.4.2": + version "0.4.2" + resolved "https://registry.yarnpkg.com/@chainsafe/persistent-merkle-tree/-/persistent-merkle-tree-0.4.2.tgz#4c9ee80cc57cd3be7208d98c40014ad38f36f7ff" + integrity sha512-lLO3ihKPngXLTus/L7WHKaw9PnNJWizlOF1H9NNzHP6Xvh82vzg9F2bzkXhYIFshMZ2gTCEz8tq6STe7r5NDfQ== + dependencies: + "@chainsafe/as-sha256" "^0.3.1" + +"@chainsafe/persistent-merkle-tree@^0.5.0": + version "0.5.0" + resolved "https://registry.yarnpkg.com/@chainsafe/persistent-merkle-tree/-/persistent-merkle-tree-0.5.0.tgz#2b4a62c9489a5739dedd197250d8d2f5427e9f63" + integrity sha512-l0V1b5clxA3iwQLXP40zYjyZYospQLZXzBVIhhr9kDg/1qHZfzzHw0jj4VPBijfYCArZDlPkRi1wZaV2POKeuw== + dependencies: + "@chainsafe/as-sha256" "^0.3.1" + +"@chainsafe/ssz@^0.10.0": + version "0.10.2" + resolved "https://registry.yarnpkg.com/@chainsafe/ssz/-/ssz-0.10.2.tgz#c782929e1bb25fec66ba72e75934b31fd087579e" + integrity sha512-/NL3Lh8K+0q7A3LsiFq09YXS9fPE+ead2rr7vM2QK8PLzrNsw3uqrif9bpRX5UxgeRjM+vYi+boCM3+GM4ovXg== + dependencies: + "@chainsafe/as-sha256" "^0.3.1" + "@chainsafe/persistent-merkle-tree" "^0.5.0" + +"@chainsafe/ssz@^0.9.2": + version "0.9.4" + resolved "https://registry.yarnpkg.com/@chainsafe/ssz/-/ssz-0.9.4.tgz#696a8db46d6975b600f8309ad3a12f7c0e310497" + integrity sha512-77Qtg2N1ayqs4Bg/wvnWfg5Bta7iy7IRh8XqXh7oNMeP2HBbBwx8m6yTpA8p0EHItWPEBkgZd5S5/LSlp3GXuQ== + dependencies: + "@chainsafe/as-sha256" "^0.3.1" + "@chainsafe/persistent-merkle-tree" "^0.4.2" + case "^1.6.3" + "@cspotcode/source-map-support@^0.8.0": version "0.8.1" resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz#00629c35a688e05a88b1cda684fb9d5e73f000a1" @@ -281,7 +317,7 @@ ethereumjs-util "^7.1.4" merkle-patricia-tree "^4.2.4" -"@ethereumjs/blockchain@^5.5.0", "@ethereumjs/blockchain@^5.5.2": +"@ethereumjs/blockchain@^5.5.0": version "5.5.2" resolved "https://registry.yarnpkg.com/@ethereumjs/blockchain/-/blockchain-5.5.2.tgz#1848abd9dc1ee56acf8cec4c84304d7f4667d027" integrity sha512-Jz26iJmmsQtngerW6r5BDFaew/f2mObLrRZo3rskLOx1lmtMZ8+TX/vJexmivrnWgmAsTdNWhlKUYY4thPhPig== @@ -303,7 +339,7 @@ crc-32 "^1.2.0" ethereumjs-util "^7.1.3" -"@ethereumjs/common@^2.6.0", "@ethereumjs/common@^2.6.3", "@ethereumjs/common@^2.6.4": +"@ethereumjs/common@^2.6.0", "@ethereumjs/common@^2.6.3": version "2.6.4" resolved "https://registry.yarnpkg.com/@ethereumjs/common/-/common-2.6.4.tgz#1b3cdd3aa4ee3b0ca366756fc35e4a03022a01cc" integrity sha512-RDJh/R/EAr+B7ZRg5LfJ0BIpf/1LydFgYdvZEuTraojCbVypO2sQ+QnpP5u2wJf9DASyooKqu8O4FJEWUV6NXw== @@ -356,24 +392,6 @@ merkle-patricia-tree "^4.2.2" rustbn.js "~0.2.0" -"@ethereumjs/vm@^5.9.0": - version "5.9.0" - resolved "https://registry.yarnpkg.com/@ethereumjs/vm/-/vm-5.9.0.tgz#54e485097c6dbb42554d541ef8d84d06b7ddf12f" - integrity sha512-0IRsj4IuF8lFDWVVLc4mFOImaSX8VWF8CGm3mXHG/LLlQ/Tryy/kKXMw/bU9D+Zw03CdteW+wCGqNFS6+mPjpg== - dependencies: - "@ethereumjs/block" "^3.6.2" - "@ethereumjs/blockchain" "^5.5.2" - "@ethereumjs/common" "^2.6.4" - "@ethereumjs/tx" "^3.5.1" - async-eventemitter "^0.2.4" - core-js-pure "^3.0.1" - debug "^4.3.3" - ethereumjs-util "^7.1.4" - functional-red-black-tree "^1.0.1" - mcl-wasm "^0.7.1" - merkle-patricia-tree "^4.2.4" - rustbn.js "~0.2.0" - "@ethersproject/abi@5.0.7": version "5.0.7" resolved "https://registry.yarnpkg.com/@ethersproject/abi/-/abi-5.0.7.tgz#79e52452bd3ca2956d0e1c964207a58ad1a0ee7b" @@ -992,7 +1010,7 @@ bech32 "1.1.4" ws "7.4.6" -"@ethersproject/providers@5.7.2": +"@ethersproject/providers@5.7.2", "@ethersproject/providers@^5.7.1", "@ethersproject/providers@^5.7.2": version "5.7.2" resolved "https://registry.yarnpkg.com/@ethersproject/providers/-/providers-5.7.2.tgz#f8b1a4f275d7ce58cf0a2eec222269a08beb18cb" integrity sha512-g34EWZ1WWAVgr4aptGlVBF8mhl3VWjv+8hoAnzStu8Ah22VHBsuGzP17eb6xDVRzw895G4W7vvx60lFFur/1Rg== @@ -1393,6 +1411,11 @@ "@ethersproject/properties" "^5.7.0" "@ethersproject/strings" "^5.7.0" +"@fastify/busboy@^2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@fastify/busboy/-/busboy-2.0.0.tgz#f22824caff3ae506b18207bad4126dbc6ccdb6b8" + integrity sha512-JUFJad5lv7jxj926GPgymrWQxxjPYuJNiNjNMzqT+HiuP6Vl3dk5xzG+8sTX96np0ZAluvaMzPsjhHZ5rNuNQQ== + "@ganache/ethereum-address@0.1.4": version "0.1.4" resolved "https://registry.yarnpkg.com/@ganache/ethereum-address/-/ethereum-address-0.1.4.tgz#0e6d66f4a24f64bf687cb3ff7358fb85b9d9005e" @@ -1503,6 +1526,17 @@ "@openzeppelin/contracts-upgradeable" "^4.6.0" "@threshold-network/solidity-contracts" "1.3.0-dev.6" +"@keep-network/ecdsa@2.1.0-dev.16": + version "2.1.0-dev.16" + resolved "https://registry.yarnpkg.com/@keep-network/ecdsa/-/ecdsa-2.1.0-dev.16.tgz#bd9d084b4f2b7bdda0a85a8f69200832d7c24fde" + integrity sha512-8k8XiPXneRtBN/4jVX+0qxqya8232cglRM/GrfYMv/niQkgvdolK2prXyd3LO7d4ot4WcyfLYU7uJfjjmc5rEw== + dependencies: + "@keep-network/random-beacon" "2.1.0-dev.16" + "@keep-network/sortition-pools" "^2.0.0-pre.16" + "@openzeppelin/contracts" "^4.6.0" + "@openzeppelin/contracts-upgradeable" "^4.6.0" + "@threshold-network/solidity-contracts" "1.3.0-dev.8" + "@keep-network/hardhat-helpers@^0.6.0-pre.7": version "0.6.0-pre.7" resolved "https://registry.yarnpkg.com/@keep-network/hardhat-helpers/-/hardhat-helpers-0.6.0-pre.7.tgz#0b8fbc7c8ee7248f0babbfe4f2f957f5ef3f8507" @@ -1573,19 +1607,20 @@ "@openzeppelin/contracts" "^4.3.2" "@thesis/solidity-contracts" "github:thesis/solidity-contracts#4985bcf" -"@keep-network/tbtc-v2.ts@development": - version "1.3.0-dev.5" - resolved "https://registry.yarnpkg.com/@keep-network/tbtc-v2.ts/-/tbtc-v2.ts-1.3.0-dev.5.tgz#f01516207ddeb40b33f1c9a64022de9b8a216915" - integrity sha512-UmZg56yflaWJWKk7UdXgndc4duK7crnOyBAfiHBdrMJQiFXb0qpNKkbZAsVbpfxD2P1n0VwWitczXTQAPyKNRQ== +"@keep-network/tbtc-v2.ts@2.0.0-dev.0": + version "2.0.0-dev.0" + resolved "https://registry.yarnpkg.com/@keep-network/tbtc-v2.ts/-/tbtc-v2.ts-2.0.0-dev.0.tgz#1e51d8b605a8c96c3bea9522595d3b3db4eb8214" + integrity sha512-kJJCiWTu0EoZW1Q2zQZ5fOM52PpXDPd7EHd/oTbETxKYIW7h/Qg/Fnqx9KNynIInMrQIdXwsIDTEjoxGmD1AiQ== dependencies: - "@keep-network/ecdsa" "2.1.0-dev.15" + "@keep-network/ecdsa" "2.1.0-dev.16" "@keep-network/tbtc-v2" "1.6.0-dev.0" - bcoin "git+https://github.com/keep-network/bcoin.git#5accd32c63e6025a0d35d67739c4a6e84095a1f8" - bcrypto "git+https://github.com/bcoin-org/bcrypto.git#semver:~5.5.0" + bitcoinjs-lib "^6.1.5" bufio "^1.0.6" + ecpair "^2.1.0" electrum-client-js "git+https://github.com/keep-network/electrum-client-js.git#v0.1.1" ethers "^5.5.2" p-timeout "^4.1.0" + tiny-secp256k1 "^2.2.3" wif "2.0.6" "@keep-network/tbtc-v2@1.6.0-dev.0": @@ -1671,6 +1706,21 @@ tweetnacl "^1.0.3" tweetnacl-util "^0.15.1" +"@noble/hashes@1.2.0", "@noble/hashes@~1.2.0": + version "1.2.0" + resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.2.0.tgz#a3150eeb09cc7ab207ebf6d7b9ad311a9bdbed12" + integrity sha512-FZfhjEDbT5GRswV3C6uvLPHMiVD6lQBmpoX5+eSiPaMTXte/IKqI5dykDxzZB/WBeK/CDuQRBWarPdi3FNY2zQ== + +"@noble/hashes@^1.2.0": + version "1.3.2" + resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.2.tgz#6f26dbc8fbc7205873ce3cee2f690eba0d421b39" + integrity sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ== + +"@noble/secp256k1@1.7.1", "@noble/secp256k1@~1.7.0": + version "1.7.1" + resolved "https://registry.yarnpkg.com/@noble/secp256k1/-/secp256k1-1.7.1.tgz#b251c70f824ce3ca7f8dc3df08d58f005cc0507c" + integrity sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw== + "@nodelib/fs.scandir@2.1.5": version "2.1.5" resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5" @@ -1692,6 +1742,206 @@ "@nodelib/fs.scandir" "2.1.5" fastq "^1.6.0" +"@nomicfoundation/ethereumjs-block@5.0.2": + version "5.0.2" + resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-block/-/ethereumjs-block-5.0.2.tgz#13a7968f5964f1697da941281b7f7943b0465d04" + integrity sha512-hSe6CuHI4SsSiWWjHDIzWhSiAVpzMUcDRpWYzN0T9l8/Rz7xNn3elwVOJ/tAyS0LqL6vitUD78Uk7lQDXZun7Q== + dependencies: + "@nomicfoundation/ethereumjs-common" "4.0.2" + "@nomicfoundation/ethereumjs-rlp" "5.0.2" + "@nomicfoundation/ethereumjs-trie" "6.0.2" + "@nomicfoundation/ethereumjs-tx" "5.0.2" + "@nomicfoundation/ethereumjs-util" "9.0.2" + ethereum-cryptography "0.1.3" + ethers "^5.7.1" + +"@nomicfoundation/ethereumjs-blockchain@7.0.2": + version "7.0.2" + resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-blockchain/-/ethereumjs-blockchain-7.0.2.tgz#45323b673b3d2fab6b5008535340d1b8fea7d446" + integrity sha512-8UUsSXJs+MFfIIAKdh3cG16iNmWzWC/91P40sazNvrqhhdR/RtGDlFk2iFTGbBAZPs2+klZVzhRX8m2wvuvz3w== + dependencies: + "@nomicfoundation/ethereumjs-block" "5.0.2" + "@nomicfoundation/ethereumjs-common" "4.0.2" + "@nomicfoundation/ethereumjs-ethash" "3.0.2" + "@nomicfoundation/ethereumjs-rlp" "5.0.2" + "@nomicfoundation/ethereumjs-trie" "6.0.2" + "@nomicfoundation/ethereumjs-tx" "5.0.2" + "@nomicfoundation/ethereumjs-util" "9.0.2" + abstract-level "^1.0.3" + debug "^4.3.3" + ethereum-cryptography "0.1.3" + level "^8.0.0" + lru-cache "^5.1.1" + memory-level "^1.0.0" + +"@nomicfoundation/ethereumjs-common@4.0.2": + version "4.0.2" + resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-common/-/ethereumjs-common-4.0.2.tgz#a15d1651ca36757588fdaf2a7d381a150662a3c3" + integrity sha512-I2WGP3HMGsOoycSdOTSqIaES0ughQTueOsddJ36aYVpI3SN8YSusgRFLwzDJwRFVIYDKx/iJz0sQ5kBHVgdDwg== + dependencies: + "@nomicfoundation/ethereumjs-util" "9.0.2" + crc-32 "^1.2.0" + +"@nomicfoundation/ethereumjs-ethash@3.0.2": + version "3.0.2" + resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-ethash/-/ethereumjs-ethash-3.0.2.tgz#da77147f806401ee996bfddfa6487500118addca" + integrity sha512-8PfoOQCcIcO9Pylq0Buijuq/O73tmMVURK0OqdjhwqcGHYC2PwhbajDh7GZ55ekB0Px197ajK3PQhpKoiI/UPg== + dependencies: + "@nomicfoundation/ethereumjs-block" "5.0.2" + "@nomicfoundation/ethereumjs-rlp" "5.0.2" + "@nomicfoundation/ethereumjs-util" "9.0.2" + abstract-level "^1.0.3" + bigint-crypto-utils "^3.0.23" + ethereum-cryptography "0.1.3" + +"@nomicfoundation/ethereumjs-evm@2.0.2": + version "2.0.2" + resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-evm/-/ethereumjs-evm-2.0.2.tgz#4c2f4b84c056047102a4fa41c127454e3f0cfcf6" + integrity sha512-rBLcUaUfANJxyOx9HIdMX6uXGin6lANCulIm/pjMgRqfiCRMZie3WKYxTSd8ZE/d+qT+zTedBF4+VHTdTSePmQ== + dependencies: + "@ethersproject/providers" "^5.7.1" + "@nomicfoundation/ethereumjs-common" "4.0.2" + "@nomicfoundation/ethereumjs-tx" "5.0.2" + "@nomicfoundation/ethereumjs-util" "9.0.2" + debug "^4.3.3" + ethereum-cryptography "0.1.3" + mcl-wasm "^0.7.1" + rustbn.js "~0.2.0" + +"@nomicfoundation/ethereumjs-rlp@5.0.2": + version "5.0.2" + resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-rlp/-/ethereumjs-rlp-5.0.2.tgz#4fee8dc58a53ac6ae87fb1fca7c15dc06c6b5dea" + integrity sha512-QwmemBc+MMsHJ1P1QvPl8R8p2aPvvVcKBbvHnQOKBpBztEo0omN0eaob6FeZS/e3y9NSe+mfu3nNFBHszqkjTA== + +"@nomicfoundation/ethereumjs-statemanager@2.0.2": + version "2.0.2" + resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-statemanager/-/ethereumjs-statemanager-2.0.2.tgz#3ba4253b29b1211cafe4f9265fee5a0d780976e0" + integrity sha512-dlKy5dIXLuDubx8Z74sipciZnJTRSV/uHG48RSijhgm1V7eXYFC567xgKtsKiVZB1ViTP9iFL4B6Je0xD6X2OA== + dependencies: + "@nomicfoundation/ethereumjs-common" "4.0.2" + "@nomicfoundation/ethereumjs-rlp" "5.0.2" + debug "^4.3.3" + ethereum-cryptography "0.1.3" + ethers "^5.7.1" + js-sdsl "^4.1.4" + +"@nomicfoundation/ethereumjs-trie@6.0.2": + version "6.0.2" + resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-trie/-/ethereumjs-trie-6.0.2.tgz#9a6dbd28482dca1bc162d12b3733acab8cd12835" + integrity sha512-yw8vg9hBeLYk4YNg5MrSJ5H55TLOv2FSWUTROtDtTMMmDGROsAu+0tBjiNGTnKRi400M6cEzoFfa89Fc5k8NTQ== + dependencies: + "@nomicfoundation/ethereumjs-rlp" "5.0.2" + "@nomicfoundation/ethereumjs-util" "9.0.2" + "@types/readable-stream" "^2.3.13" + ethereum-cryptography "0.1.3" + readable-stream "^3.6.0" + +"@nomicfoundation/ethereumjs-tx@5.0.2": + version "5.0.2" + resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-tx/-/ethereumjs-tx-5.0.2.tgz#117813b69c0fdc14dd0446698a64be6df71d7e56" + integrity sha512-T+l4/MmTp7VhJeNloMkM+lPU3YMUaXdcXgTGCf8+ZFvV9NYZTRLFekRwlG6/JMmVfIfbrW+dRRJ9A6H5Q/Z64g== + dependencies: + "@chainsafe/ssz" "^0.9.2" + "@ethersproject/providers" "^5.7.2" + "@nomicfoundation/ethereumjs-common" "4.0.2" + "@nomicfoundation/ethereumjs-rlp" "5.0.2" + "@nomicfoundation/ethereumjs-util" "9.0.2" + ethereum-cryptography "0.1.3" + +"@nomicfoundation/ethereumjs-util@9.0.2": + version "9.0.2" + resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-util/-/ethereumjs-util-9.0.2.tgz#16bdc1bb36f333b8a3559bbb4b17dac805ce904d" + integrity sha512-4Wu9D3LykbSBWZo8nJCnzVIYGvGCuyiYLIJa9XXNVt1q1jUzHdB+sJvx95VGCpPkCT+IbLecW6yfzy3E1bQrwQ== + dependencies: + "@chainsafe/ssz" "^0.10.0" + "@nomicfoundation/ethereumjs-rlp" "5.0.2" + ethereum-cryptography "0.1.3" + +"@nomicfoundation/ethereumjs-vm@7.0.2": + version "7.0.2" + resolved "https://registry.yarnpkg.com/@nomicfoundation/ethereumjs-vm/-/ethereumjs-vm-7.0.2.tgz#3b0852cb3584df0e18c182d0672a3596c9ca95e6" + integrity sha512-Bj3KZT64j54Tcwr7Qm/0jkeZXJMfdcAtRBedou+Hx0dPOSIgqaIr0vvLwP65TpHbak2DmAq+KJbW2KNtIoFwvA== + dependencies: + "@nomicfoundation/ethereumjs-block" "5.0.2" + "@nomicfoundation/ethereumjs-blockchain" "7.0.2" + "@nomicfoundation/ethereumjs-common" "4.0.2" + "@nomicfoundation/ethereumjs-evm" "2.0.2" + "@nomicfoundation/ethereumjs-rlp" "5.0.2" + "@nomicfoundation/ethereumjs-statemanager" "2.0.2" + "@nomicfoundation/ethereumjs-trie" "6.0.2" + "@nomicfoundation/ethereumjs-tx" "5.0.2" + "@nomicfoundation/ethereumjs-util" "9.0.2" + debug "^4.3.3" + ethereum-cryptography "0.1.3" + mcl-wasm "^0.7.1" + rustbn.js "~0.2.0" + +"@nomicfoundation/solidity-analyzer-darwin-arm64@0.1.1": + version "0.1.1" + resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-darwin-arm64/-/solidity-analyzer-darwin-arm64-0.1.1.tgz#4c858096b1c17fe58a474fe81b46815f93645c15" + integrity sha512-KcTodaQw8ivDZyF+D76FokN/HdpgGpfjc/gFCImdLUyqB6eSWVaZPazMbeAjmfhx3R0zm/NYVzxwAokFKgrc0w== + +"@nomicfoundation/solidity-analyzer-darwin-x64@0.1.1": + version "0.1.1" + resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-darwin-x64/-/solidity-analyzer-darwin-x64-0.1.1.tgz#6e25ccdf6e2d22389c35553b64fe6f3fdaec432c" + integrity sha512-XhQG4BaJE6cIbjAVtzGOGbK3sn1BO9W29uhk9J8y8fZF1DYz0Doj8QDMfpMu+A6TjPDs61lbsmeYodIDnfveSA== + +"@nomicfoundation/solidity-analyzer-freebsd-x64@0.1.1": + version "0.1.1" + resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-freebsd-x64/-/solidity-analyzer-freebsd-x64-0.1.1.tgz#0a224ea50317139caeebcdedd435c28a039d169c" + integrity sha512-GHF1VKRdHW3G8CndkwdaeLkVBi5A9u2jwtlS7SLhBc8b5U/GcoL39Q+1CSO3hYqePNP+eV5YI7Zgm0ea6kMHoA== + +"@nomicfoundation/solidity-analyzer-linux-arm64-gnu@0.1.1": + version "0.1.1" + resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-linux-arm64-gnu/-/solidity-analyzer-linux-arm64-gnu-0.1.1.tgz#dfa085d9ffab9efb2e7b383aed3f557f7687ac2b" + integrity sha512-g4Cv2fO37ZsUENQ2vwPnZc2zRenHyAxHcyBjKcjaSmmkKrFr64yvzeNO8S3GBFCo90rfochLs99wFVGT/0owpg== + +"@nomicfoundation/solidity-analyzer-linux-arm64-musl@0.1.1": + version "0.1.1" + resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-linux-arm64-musl/-/solidity-analyzer-linux-arm64-musl-0.1.1.tgz#c9e06b5d513dd3ab02a7ac069c160051675889a4" + integrity sha512-WJ3CE5Oek25OGE3WwzK7oaopY8xMw9Lhb0mlYuJl/maZVo+WtP36XoQTb7bW/i8aAdHW5Z+BqrHMux23pvxG3w== + +"@nomicfoundation/solidity-analyzer-linux-x64-gnu@0.1.1": + version "0.1.1" + resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-linux-x64-gnu/-/solidity-analyzer-linux-x64-gnu-0.1.1.tgz#8d328d16839e52571f72f2998c81e46bf320f893" + integrity sha512-5WN7leSr5fkUBBjE4f3wKENUy9HQStu7HmWqbtknfXkkil+eNWiBV275IOlpXku7v3uLsXTOKpnnGHJYI2qsdA== + +"@nomicfoundation/solidity-analyzer-linux-x64-musl@0.1.1": + version "0.1.1" + resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-linux-x64-musl/-/solidity-analyzer-linux-x64-musl-0.1.1.tgz#9b49d0634b5976bb5ed1604a1e1b736f390959bb" + integrity sha512-KdYMkJOq0SYPQMmErv/63CwGwMm5XHenEna9X9aB8mQmhDBrYrlAOSsIPgFCUSL0hjxE3xHP65/EPXR/InD2+w== + +"@nomicfoundation/solidity-analyzer-win32-arm64-msvc@0.1.1": + version "0.1.1" + resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-win32-arm64-msvc/-/solidity-analyzer-win32-arm64-msvc-0.1.1.tgz#e2867af7264ebbcc3131ef837878955dd6a3676f" + integrity sha512-VFZASBfl4qiBYwW5xeY20exWhmv6ww9sWu/krWSesv3q5hA0o1JuzmPHR4LPN6SUZj5vcqci0O6JOL8BPw+APg== + +"@nomicfoundation/solidity-analyzer-win32-ia32-msvc@0.1.1": + version "0.1.1" + resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-win32-ia32-msvc/-/solidity-analyzer-win32-ia32-msvc-0.1.1.tgz#0685f78608dd516c8cdfb4896ed451317e559585" + integrity sha512-JnFkYuyCSA70j6Si6cS1A9Gh1aHTEb8kOTBApp/c7NRTFGNMH8eaInKlyuuiIbvYFhlXW4LicqyYuWNNq9hkpQ== + +"@nomicfoundation/solidity-analyzer-win32-x64-msvc@0.1.1": + version "0.1.1" + resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer-win32-x64-msvc/-/solidity-analyzer-win32-x64-msvc-0.1.1.tgz#c9a44f7108646f083b82e851486e0f6aeb785836" + integrity sha512-HrVJr6+WjIXGnw3Q9u6KQcbZCtk0caVWhCdFADySvRyUxJ8PnzlaP+MhwNE8oyT8OZ6ejHBRrrgjSqDCFXGirw== + +"@nomicfoundation/solidity-analyzer@^0.1.0": + version "0.1.1" + resolved "https://registry.yarnpkg.com/@nomicfoundation/solidity-analyzer/-/solidity-analyzer-0.1.1.tgz#f5f4d36d3f66752f59a57e7208cd856f3ddf6f2d" + integrity sha512-1LMtXj1puAxyFusBgUIy5pZk3073cNXYnXUpuNKFghHbIit/xZgbk0AokpUADbNm3gyD6bFWl3LRFh3dhVdREg== + optionalDependencies: + "@nomicfoundation/solidity-analyzer-darwin-arm64" "0.1.1" + "@nomicfoundation/solidity-analyzer-darwin-x64" "0.1.1" + "@nomicfoundation/solidity-analyzer-freebsd-x64" "0.1.1" + "@nomicfoundation/solidity-analyzer-linux-arm64-gnu" "0.1.1" + "@nomicfoundation/solidity-analyzer-linux-arm64-musl" "0.1.1" + "@nomicfoundation/solidity-analyzer-linux-x64-gnu" "0.1.1" + "@nomicfoundation/solidity-analyzer-linux-x64-musl" "0.1.1" + "@nomicfoundation/solidity-analyzer-win32-arm64-msvc" "0.1.1" + "@nomicfoundation/solidity-analyzer-win32-ia32-msvc" "0.1.1" + "@nomicfoundation/solidity-analyzer-win32-x64-msvc" "0.1.1" + "@nomiclabs/hardhat-ethers@^2.0.6": version "2.0.6" resolved "https://registry.yarnpkg.com/@nomiclabs/hardhat-ethers/-/hardhat-ethers-2.0.6.tgz#1c695263d5b46a375dcda48c248c4fba9dfe2fc2" @@ -1850,6 +2100,28 @@ path-browserify "^1.0.0" url "^0.11.0" +"@scure/base@~1.1.0": + version "1.1.3" + resolved "https://registry.yarnpkg.com/@scure/base/-/base-1.1.3.tgz#8584115565228290a6c6c4961973e0903bb3df2f" + integrity sha512-/+SgoRjLq7Xlf0CWuLHq2LUZeL/w65kfzAPG5NH9pcmBhs+nunQTn4gvdwgMTIXnt9b2C/1SeL2XiysZEyIC9Q== + +"@scure/bip32@1.1.5": + version "1.1.5" + resolved "https://registry.yarnpkg.com/@scure/bip32/-/bip32-1.1.5.tgz#d2ccae16dcc2e75bc1d75f5ef3c66a338d1ba300" + integrity sha512-XyNh1rB0SkEqd3tXcXMi+Xe1fvg+kUIcoRIEujP1Jgv7DqW2r9lg3Ah0NkFaCs9sTkQAQA8kw7xiRXzENi9Rtw== + dependencies: + "@noble/hashes" "~1.2.0" + "@noble/secp256k1" "~1.7.0" + "@scure/base" "~1.1.0" + +"@scure/bip39@1.1.1": + version "1.1.1" + resolved "https://registry.yarnpkg.com/@scure/bip39/-/bip39-1.1.1.tgz#b54557b2e86214319405db819c4b6a370cf340c5" + integrity sha512-t+wDck2rVkh65Hmv280fYdVdY25J9YeEUIgn2LG1WM6gxFkGzcksoDiUkWVpVp3Oex9xGC68JU2dSbUfwZ2jPg== + dependencies: + "@noble/hashes" "~1.2.0" + "@scure/base" "~1.1.0" + "@sentry/core@5.30.0": version "5.30.0" resolved "https://registry.yarnpkg.com/@sentry/core/-/core-5.30.0.tgz#6b203664f69e75106ee8b5a2fe1d717379b331f3" @@ -2052,6 +2324,16 @@ "@openzeppelin/contracts-upgradeable" "~4.5.2" "@thesis/solidity-contracts" "github:thesis/solidity-contracts#4985bcf" +"@threshold-network/solidity-contracts@1.3.0-dev.8": + version "1.3.0-dev.8" + resolved "https://registry.yarnpkg.com/@threshold-network/solidity-contracts/-/solidity-contracts-1.3.0-dev.8.tgz#6de25dc6ce374cfbdf3b67c72097044631222f3a" + integrity sha512-s6SFZyf1xXgOdMK1zYnjsURnVz7Xxzf0z/34vH+hDg8n/G8L0jPR6Iz4laWSSL2y1P3ffFAFTUMvwfJMJitfVw== + dependencies: + "@keep-network/keep-core" ">1.8.1-dev <1.8.1-goerli" + "@openzeppelin/contracts" "~4.5.0" + "@openzeppelin/contracts-upgradeable" "~4.5.2" + "@thesis/solidity-contracts" "github:thesis/solidity-contracts#4985bcf" + "@trufflesuite/bigint-buffer@1.1.9": version "1.1.9" resolved "https://registry.yarnpkg.com/@trufflesuite/bigint-buffer/-/bigint-buffer-1.1.9.tgz#e2604d76e1e4747b74376d68f1312f9944d0d75d" @@ -2306,6 +2588,14 @@ dependencies: "@types/node" "*" +"@types/readable-stream@^2.3.13": + version "2.3.15" + resolved "https://registry.yarnpkg.com/@types/readable-stream/-/readable-stream-2.3.15.tgz#3d79c9ceb1b6a57d5f6e6976f489b9b5384321ae" + integrity sha512-oM5JSKQCcICF1wvGgmecmHldZ48OZamtMxcGGVICOJA8o8cahXC1zEVAif8iwoc5j8etxFaRFnf095+CDsuoFQ== + dependencies: + "@types/node" "*" + safe-buffer "~5.1.1" + "@types/responselike@^1.0.0": version "1.0.0" resolved "https://registry.yarnpkg.com/@types/responselike/-/responselike-1.0.0.tgz#251f4fe7d154d2bad125abe1b429b23afd262e29" @@ -2456,12 +2746,18 @@ typedarray-to-buffer "^3.1.5" yaeti "^0.0.6" -abort-controller@^3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/abort-controller/-/abort-controller-3.0.0.tgz#eaf54d53b62bae4138e809ca225c8439a6efb392" - integrity sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg== +abstract-level@^1.0.0, abstract-level@^1.0.2, abstract-level@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/abstract-level/-/abstract-level-1.0.3.tgz#78a67d3d84da55ee15201486ab44c09560070741" + integrity sha512-t6jv+xHy+VYwc4xqZMn2Pa9DjcdzvzZmQGRjTFc8spIbRGHgBrEKbPq+rYXc7CCo0lxgYvSgKVg9qZAhpVQSjA== dependencies: - event-target-shim "^5.0.0" + buffer "^6.0.3" + catering "^2.1.0" + is-buffer "^2.0.5" + level-supports "^4.0.0" + level-transcoder "^1.0.1" + module-error "^1.0.1" + queue-microtask "^1.2.3" abstract-leveldown@^6.2.1: version "6.3.0" @@ -2852,50 +3148,16 @@ base-x@^3.0.2, base-x@^3.0.8: dependencies: safe-buffer "^5.0.1" +base-x@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/base-x/-/base-x-4.0.0.tgz#d0e3b7753450c73f8ad2389b5c018a4af7b2224a" + integrity sha512-FuwxlW4H5kh37X/oW59pwTzzTKRzfrrQwhmyspRM7swOEZcHtDZSCt45U6oKgtuFE+WYPblePMVIPR4RZrh/hw== + base64-js@^1.3.1: version "1.5.1" resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.5.1.tgz#1b1b440160a5bf7ad40b650f095963481903930a" integrity sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA== -"bcfg@git+https://github.com/bcoin-org/bcfg.git#semver:~0.1.7": - version "0.1.8" - resolved "git+https://github.com/bcoin-org/bcfg.git#90e1aff3b040160cd73956a500765ffcc823f0c2" - dependencies: - bsert "~0.0.10" - -"bcoin@git+https://github.com/keep-network/bcoin.git#5accd32c63e6025a0d35d67739c4a6e84095a1f8": - version "2.2.0" - resolved "git+https://github.com/keep-network/bcoin.git#5accd32c63e6025a0d35d67739c4a6e84095a1f8" - dependencies: - bcfg "git+https://github.com/bcoin-org/bcfg.git#semver:~0.1.7" - bcrypto "git+https://github.com/bcoin-org/bcrypto.git#semver:~5.5.0" - bcurl "git+https://github.com/bcoin-org/bcurl.git#semver:^0.1.6" - bdb "git+https://github.com/bcoin-org/bdb.git#semver:~1.2.1" - bdns "git+https://github.com/bcoin-org/bdns.git#semver:~0.1.5" - bevent "git+https://github.com/bcoin-org/bevent.git#semver:~0.1.5" - bfile "git+https://github.com/bcoin-org/bfile.git#semver:~0.2.1" - bfilter "git+https://github.com/bcoin-org/bfilter.git#semver:~2.3.0" - bheep "git+https://github.com/bcoin-org/bheep.git#semver:~0.1.5" - binet "git+https://github.com/bcoin-org/binet.git#semver:~0.3.5" - blgr "git+https://github.com/bcoin-org/blgr.git#semver:~0.2.0" - blru "git+https://github.com/bcoin-org/blru.git#semver:~0.1.6" - blst "git+https://github.com/bcoin-org/blst.git#semver:~0.1.5" - bmutex "git+https://github.com/bcoin-org/bmutex.git#semver:~0.1.6" - brq "git+https://github.com/bcoin-org/brq.git#semver:~0.1.7" - bs32 "git+https://github.com/bcoin-org/bs32.git#semver:=0.1.6" - bsert "git+https://github.com/chjj/bsert.git#semver:~0.0.10" - bsock "git+https://github.com/bcoin-org/bsock.git#semver:~0.1.9" - bsocks "git+https://github.com/bcoin-org/bsocks.git#semver:~0.2.6" - btcp "git+https://github.com/bcoin-org/btcp.git#semver:~0.1.5" - buffer-map "git+https://github.com/chjj/buffer-map.git#semver:~0.0.7" - bufio "git+https://github.com/bcoin-org/bufio.git#semver:~1.0.6" - bupnp "git+https://github.com/bcoin-org/bupnp.git#semver:~0.2.6" - bval "git+https://github.com/bcoin-org/bval.git#semver:~0.1.6" - bweb "git+https://github.com/bcoin-org/bweb.git#semver:=0.1.9" - loady "git+https://github.com/chjj/loady.git#semver:~0.0.1" - n64 "git+https://github.com/chjj/n64.git#semver:~0.2.10" - nan "git+https://github.com/braydonf/nan.git#semver:=2.14.0" - bcrypt-pbkdf@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz#a4301d389b6a43f9b67ff3ca11a3f6637e360e9e" @@ -2903,63 +3165,15 @@ bcrypt-pbkdf@^1.0.0: dependencies: tweetnacl "^0.14.3" -"bcrypto@git+https://github.com/bcoin-org/bcrypto.git#semver:~5.5.0": - version "5.5.1" - resolved "git+https://github.com/bcoin-org/bcrypto.git#42bcbd52831042f08cdf178d2cf30eacb62a4446" - dependencies: - bufio "~1.0.7" - loady "~0.0.5" - -"bcurl@git+https://github.com/bcoin-org/bcurl.git#semver:^0.1.6": - version "0.1.10" - resolved "git+https://github.com/bcoin-org/bcurl.git#d7e088fad4c284fb5d6fd7205c6b903bd3e6bf83" - dependencies: - brq "~0.1.8" - bsert "~0.0.10" - bsock "~0.1.9" - -"bdb@git+https://github.com/bcoin-org/bdb.git#semver:~1.2.1": - version "1.2.2" - resolved "git+https://github.com/bcoin-org/bdb.git#2c8d48c8adca4b11260263472766cd4b7ae74ef7" - dependencies: - bsert "~0.0.10" - loady "~0.0.1" - -"bdns@git+https://github.com/bcoin-org/bdns.git#semver:~0.1.5": - version "0.1.5" - resolved "git+https://github.com/bcoin-org/bdns.git#cb0b62a0075f7e1259fc50fa723ba644e9a07d14" - dependencies: - bsert "~0.0.10" - bech32@1.1.4: version "1.1.4" resolved "https://registry.yarnpkg.com/bech32/-/bech32-1.1.4.tgz#e38c9f37bf179b8eb16ae3a772b40c356d4832e9" integrity sha512-s0IrSOzLlbvX7yp4WBfPITzpAU8sqQcpsmwXDiKwrG4r491vwCO/XpejasRNl0piBMe/DvP4Tz0mIS/X1DPJBQ== -"bevent@git+https://github.com/bcoin-org/bevent.git#semver:~0.1.5": - version "0.1.5" - resolved "git+https://github.com/bcoin-org/bevent.git#60fb503de3ea1292d29ce438bfba80f0bc5ccb60" - dependencies: - bsert "~0.0.10" - -"bfile@git+https://github.com/bcoin-org/bfile.git#semver:~0.2.1": - version "0.2.3" - resolved "git+https://github.com/bcoin-org/bfile.git#c13235d04974f0fa5a487fdbaf74611523e2f4e6" - -"bfilter@git+https://github.com/bcoin-org/bfilter.git#semver:~2.3.0": - version "2.3.0" - resolved "git+https://github.com/bcoin-org/bfilter.git#70e42125f877191d340e8838a1a90fabb750e680" - dependencies: - bcrypto "git+https://github.com/bcoin-org/bcrypto.git#semver:~5.5.0" - bsert "git+https://github.com/chjj/bsert.git#semver:~0.0.10" - bufio "git+https://github.com/bcoin-org/bufio.git#semver:~1.0.6" - loady "git+https://github.com/chjj/loady.git#semver:~0.0.1" - -"bheep@git+https://github.com/bcoin-org/bheep.git#semver:~0.1.5": - version "0.1.5" - resolved "git+https://github.com/bcoin-org/bheep.git#e59329d0a776ae71b2fb7a2876ee5b9fd3030fa2" - dependencies: - bsert "~0.0.10" +bech32@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/bech32/-/bech32-2.0.0.tgz#078d3686535075c8c79709f054b1b226a133b355" + integrity sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg== big-integer@^1.6.44: version "1.6.51" @@ -2971,6 +3185,11 @@ bigi@^1.1.0: resolved "https://registry.yarnpkg.com/bigi/-/bigi-1.4.2.tgz#9c665a95f88b8b08fc05cfd731f561859d725825" integrity sha512-ddkU+dFIuEIW8lE7ZwdIAf2UPoM90eaprg5m3YXAVVTmKlqV/9BX4A2M8BOK2yOq6/VgZFVhK6QAxJebhlbhzw== +bigint-crypto-utils@^3.0.23: + version "3.3.0" + resolved "https://registry.yarnpkg.com/bigint-crypto-utils/-/bigint-crypto-utils-3.3.0.tgz#72ad00ae91062cf07f2b1def9594006c279c1d77" + integrity sha512-jOTSb+drvEDxEq6OuUybOAv/xxoh3cuYRUIPyu8sSHQNKM303UQ2R1DAo45o1AkcIXw6fzbaFI1+xGGdaXs2lg== + bignumber.js@*, bignumber.js@^9.0.0, bignumber.js@^9.0.1: version "9.1.1" resolved "https://registry.yarnpkg.com/bignumber.js/-/bignumber.js-9.1.1.tgz#c4df7dc496bd849d4c9464344c1aa74228b4dac6" @@ -2993,12 +3212,10 @@ bindings@^1.3.0: dependencies: file-uri-to-path "1.0.0" -"binet@git+https://github.com/bcoin-org/binet.git#semver:~0.3.5", binet@~0.3.5: - version "0.3.7" - resolved "git+https://github.com/bcoin-org/binet.git#138bbd45f343a35259333ac7cc995c3542b6d7dc" - dependencies: - bs32 "~0.1.5" - bsert "~0.0.10" +bip174@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/bip174/-/bip174-2.1.1.tgz#ef3e968cf76de234a546962bcf572cc150982f9f" + integrity sha512-mdFV5+/v0XyNYXjBS6CQPLo9ekCx4gtKZFnJm5PMto7Fs9hTTDpkkzOB7/FtluRI6JbUUAu+snTYfJRgHLZbZQ== bip32@2.0.5: version "2.0.5" @@ -3042,6 +3259,18 @@ bip39@3.0.4: pbkdf2 "^3.0.9" randombytes "^2.0.1" +bitcoinjs-lib@^6.1.5: + version "6.1.5" + resolved "https://registry.yarnpkg.com/bitcoinjs-lib/-/bitcoinjs-lib-6.1.5.tgz#3b03509ae7ddd80a440f10fc38c4a97f0a028d8c" + integrity sha512-yuf6xs9QX/E8LWE2aMJPNd0IxGofwfuVOiYdNUESkc+2bHHVKjhJd8qewqapeoolh9fihzHGoDCB5Vkr57RZCQ== + dependencies: + "@noble/hashes" "^1.2.0" + bech32 "^2.0.0" + bip174 "^2.1.1" + bs58check "^3.0.1" + typeforce "^1.11.3" + varuint-bitcoin "^1.1.2" + bl@^1.0.0: version "1.2.3" resolved "https://registry.yarnpkg.com/bl/-/bl-1.2.3.tgz#1e8dd80142eac80d7158c9dccc047fb620e035e7" @@ -3055,18 +3284,6 @@ blakejs@^1.1.0: resolved "https://registry.yarnpkg.com/blakejs/-/blakejs-1.2.1.tgz#5057e4206eadb4a97f7c0b6e197a505042fc3814" integrity sha512-QXUSXI3QVc/gJME0dBpXrag1kbzOqCjCX8/b54ntNyW6sjtoqxqRk3LTmXzaJoh71zMsDCjM+47jS7XiwN/+fQ== -"blgr@git+https://github.com/bcoin-org/blgr.git#semver:~0.2.0": - version "0.2.0" - resolved "git+https://github.com/bcoin-org/blgr.git#050cbb587a1654a078468dbb92606330fdc4d120" - dependencies: - bsert "~0.0.10" - -"blru@git+https://github.com/bcoin-org/blru.git#semver:~0.1.6": - version "0.1.6" - resolved "git+https://github.com/bcoin-org/blru.git#c2c093e9475439333dfb87bfb2fdc3be6c98b080" - dependencies: - bsert "~0.0.10" - "bls12377js@https://github.com/celo-org/bls12377js#400bcaeec9e7620b040bfad833268f5289699cac": version "0.1.0" resolved "https://github.com/celo-org/bls12377js#400bcaeec9e7620b040bfad833268f5289699cac" @@ -3091,23 +3308,11 @@ blakejs@^1.1.0: ts-node "^8.4.1" typescript "^3.6.4" -"blst@git+https://github.com/bcoin-org/blst.git#semver:~0.1.5": - version "0.1.5" - resolved "git+https://github.com/bcoin-org/blst.git#d588403edb18e628899e05aeba8c3a98a5cdedff" - dependencies: - bsert "~0.0.10" - bluebird@^3.5.0, bluebird@^3.5.2: version "3.7.2" resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.7.2.tgz#9f229c15be272454ffa973ace0dbee79a1b0c36f" integrity sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg== -"bmutex@git+https://github.com/bcoin-org/bmutex.git#semver:~0.1.6": - version "0.1.6" - resolved "git+https://github.com/bcoin-org/bmutex.git#e50782323932a4946ecc05a74c6d45861adc2c25" - dependencies: - bsert "~0.0.10" - bn.js@4.11.6: version "4.11.6" resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.6.tgz#53344adb14617a13f6e8dd2ce28905d1c0ba3215" @@ -3172,6 +3377,13 @@ brace-expansion@^1.1.7: balanced-match "^1.0.0" concat-map "0.0.1" +brace-expansion@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae" + integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA== + dependencies: + balanced-match "^1.0.0" + braces@^3.0.2, braces@~3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107" @@ -3184,6 +3396,16 @@ brorand@^1.0.1, brorand@^1.1.0: resolved "https://registry.yarnpkg.com/brorand/-/brorand-1.1.0.tgz#12c25efe40a45e3c323eb8675a0a0ce57b22371f" integrity sha512-cKV8tMCEpQs4hK/ik71d6LrPOnpkpGBR0wzxqr68g2m/LB2GxVYQroAjMJZRVM1Y4BCjCKc3vAamxSzOY2RP+w== +browser-level@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/browser-level/-/browser-level-1.0.1.tgz#36e8c3183d0fe1c405239792faaab5f315871011" + integrity sha512-XECYKJ+Dbzw0lbydyQuJzwNXtOpbMSq737qxJN11sIRTErOMShvDpbzTlgju7orJKvx4epULolZAuJGLzCmWRQ== + dependencies: + abstract-level "^1.0.2" + catering "^2.1.1" + module-error "^1.0.2" + run-parallel-limit "^1.1.0" + browser-stdout@1.3.1: version "1.3.1" resolved "https://registry.yarnpkg.com/browser-stdout/-/browser-stdout-1.3.1.tgz#baa559ee14ced73452229bad7326467c61fabd60" @@ -3243,18 +3465,6 @@ browserify-sign@^4.0.0: readable-stream "^3.6.0" safe-buffer "^5.2.0" -"brq@git+https://github.com/bcoin-org/brq.git#semver:~0.1.7", brq@~0.1.7, brq@~0.1.8: - version "0.1.8" - resolved "git+https://github.com/bcoin-org/brq.git#534bb2c83fb366ba40ad80bc3de796a174503294" - dependencies: - bsert "~0.0.10" - -"bs32@git+https://github.com/bcoin-org/bs32.git#semver:=0.1.6", bs32@~0.1.5: - version "0.1.6" - resolved "git+https://github.com/bcoin-org/bs32.git#21cf9c724659dc15df722d2410548828c142f265" - dependencies: - bsert "~0.0.10" - bs58@^4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/bs58/-/bs58-4.0.1.tgz#be161e76c354f6f788ae4071f63f34e8c4f0a42a" @@ -3262,6 +3472,13 @@ bs58@^4.0.0: dependencies: base-x "^3.0.2" +bs58@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/bs58/-/bs58-5.0.0.tgz#865575b4d13c09ea2a84622df6c8cbeb54ffc279" + integrity sha512-r+ihvQJvahgYT50JD05dyJNKlmmSlMoOGwn1lCcEzanPglg7TxYjioQUYehQ9mAR/+hOSd2jRc/Z2y5UxBymvQ== + dependencies: + base-x "^4.0.0" + bs58check@<3.0.0, bs58check@^2.1.1, bs58check@^2.1.2: version "2.1.2" resolved "https://registry.yarnpkg.com/bs58check/-/bs58check-2.1.2.tgz#53b018291228d82a5aa08e7d796fdafda54aebfc" @@ -3271,31 +3488,13 @@ bs58check@<3.0.0, bs58check@^2.1.1, bs58check@^2.1.2: create-hash "^1.1.0" safe-buffer "^5.1.2" -"bsert@git+https://github.com/chjj/bsert.git#semver:~0.0.10": - version "0.0.10" - resolved "git+https://github.com/chjj/bsert.git#bd09d49eab8644bca08ae8259a3d8756e7d453fc" - -bsert@~0.0.10: - version "0.0.12" - resolved "https://registry.yarnpkg.com/bsert/-/bsert-0.0.12.tgz#157c6a6beb1548af3b14d484fcd2a78eb440599d" - integrity sha512-lUB0EMu4KhIf+VQ6RZJ7J3dFdohYSeta+gNgDi00Hi/t3k/W6xZlwm9PSSG0q7hJ2zW9Rsn5yaMPymETxroTRw== - -"bsock@git+https://github.com/bcoin-org/bsock.git#semver:~0.1.9", bsock@~0.1.8, bsock@~0.1.9: - version "0.1.9" - resolved "git+https://github.com/bcoin-org/bsock.git#7cf76b3021ae7929c023d1170f789811e91ae528" - dependencies: - bsert "~0.0.10" - -"bsocks@git+https://github.com/bcoin-org/bsocks.git#semver:~0.2.6": - version "0.2.6" - resolved "git+https://github.com/bcoin-org/bsocks.git#6a8eb764dc4408e7f47da4f84e1afb1b393117e8" +bs58check@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/bs58check/-/bs58check-3.0.1.tgz#2094d13720a28593de1cba1d8c4e48602fdd841c" + integrity sha512-hjuuJvoWEybo7Hn/0xOrczQKKEKD63WguEjlhLExYs2wUBcebDC1jDNK17eEAD2lYfw82d5ASC1d7K3SWszjaQ== dependencies: - binet "~0.3.5" - bsert "~0.0.10" - -"btcp@git+https://github.com/bcoin-org/btcp.git#semver:~0.1.5": - version "0.1.5" - resolved "git+https://github.com/bcoin-org/btcp.git#4ea7e1ce5a43cd5348152c007aff76a419190a3a" + "@noble/hashes" "^1.2.0" + bs58 "^5.0.0" buffer-alloc-unsafe@^1.1.0: version "1.1.0" @@ -3325,10 +3524,6 @@ buffer-from@^1.0.0: resolved "https://registry.yarnpkg.com/buffer-from/-/buffer-from-1.1.2.tgz#2b146a6fd72e80b4f55d255f35ed59a3a9a41bd5" integrity sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ== -"buffer-map@git+https://github.com/chjj/buffer-map.git#semver:~0.0.7": - version "0.0.7" - resolved "git+https://github.com/chjj/buffer-map.git#bad5863af9a520701937a17fc8fa2bd8ca8e73f3" - buffer-reverse@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/buffer-reverse/-/buffer-reverse-1.0.1.tgz#49283c8efa6f901bc01fa3304d06027971ae2f60" @@ -3386,36 +3581,6 @@ bufio@^1.0.6: resolved "https://registry.yarnpkg.com/bufio/-/bufio-1.2.0.tgz#b9ad1c06b0d9010363c387c39d2810a7086d143f" integrity sha512-UlFk8z/PwdhYQTXSQQagwGAdtRI83gib2n4uy4rQnenxUM2yQi8lBDzF230BNk+3wAoZDxYRoBwVVUPgHa9MCA== -"bufio@git+https://github.com/bcoin-org/bufio.git#semver:~1.0.6": - version "1.0.7" - resolved "git+https://github.com/bcoin-org/bufio.git#91ae6c93899ff9fad7d7cee9afd2a1c4933ca984" - -bufio@~1.0.7: - version "1.0.7" - resolved "https://registry.yarnpkg.com/bufio/-/bufio-1.0.7.tgz#b7f63a1369a0829ed64cc14edf0573b3e382a33e" - integrity sha512-bd1dDQhiC+bEbEfg56IdBv7faWa6OipMs/AFFFvtFnB3wAYjlwQpQRZ0pm6ZkgtfL0pILRXhKxOiQj6UzoMR7A== - -"bupnp@git+https://github.com/bcoin-org/bupnp.git#semver:~0.2.6": - version "0.2.6" - resolved "git+https://github.com/bcoin-org/bupnp.git#c44fa7356aa297c9de96e8ad094a6816939cd688" - dependencies: - binet "~0.3.5" - brq "~0.1.7" - bsert "~0.0.10" - -"bval@git+https://github.com/bcoin-org/bval.git#semver:~0.1.6": - version "0.1.8" - resolved "git+https://github.com/bcoin-org/bval.git#f9c44d510bbc5bcc13cbd4b67e9704a24cc5ec0e" - dependencies: - bsert "~0.0.10" - -"bweb@git+https://github.com/bcoin-org/bweb.git#semver:=0.1.9": - version "0.1.9" - resolved "git+https://github.com/bcoin-org/bweb.git#31ae94ec9e97079610394e91928fe070d312c39d" - dependencies: - bsert "~0.0.10" - bsock "~0.1.8" - bytes@3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.2.tgz#8b0beeb98605adf1b128fa4386403c009e0221a5" @@ -3480,12 +3645,17 @@ camelcase@^6.0.0: resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-6.3.0.tgz#5685b95eb209ac9c0c177467778c9c84df58ba9a" integrity sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA== +case@^1.6.3: + version "1.6.3" + resolved "https://registry.yarnpkg.com/case/-/case-1.6.3.tgz#0a4386e3e9825351ca2e6216c60467ff5f1ea1c9" + integrity sha512-mzDSXIPaFwVDvZAHqZ9VlbyF4yyXRuX6IvB06WvPYkqJVO24kX1PPhv9bfpKNFZyxYFmmgo03HUiD8iklmJYRQ== + caseless@~0.12.0: version "0.12.0" resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" integrity sha512-4tYFyifaFfGacoiObjJegolkwSU4xQNGbVgUiNYVUxbQ2x2lUsFvY4hVgVzGiIe6WLOPqycWXA40l+PWsxthUw== -catering@^2.0.0, catering@^2.1.0: +catering@^2.0.0, catering@^2.1.0, catering@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/catering/-/catering-2.1.1.tgz#66acba06ed5ee28d5286133982a927de9a04b510" integrity sha512-K7Qy8O9p76sL3/3m7/zLKbRkyOlSZAgzEaLhyj2mXS8PsCud2Eo4hAb8aLtZqHh0QGqLcb9dlJSu6lHRVENm1w== @@ -3611,6 +3781,17 @@ class-is@^1.1.0: resolved "https://registry.yarnpkg.com/class-is/-/class-is-1.1.0.tgz#9d3c0fba0440d211d843cec3dedfa48055005825" integrity sha512-rhjH9AG1fvabIDoGRVH587413LPjTZgmDF9fOFCbFJQV4yuocX1mHxxvXI4g3cGwbVY9wAYIoKlg1N79frJKQw== +classic-level@^1.2.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/classic-level/-/classic-level-1.3.0.tgz#5e36680e01dc6b271775c093f2150844c5edd5c8" + integrity sha512-iwFAJQYtqRTRM0F6L8h4JCt00ZSGdOyqh7yVrhhjrOpFhmBjNlRUey64MCiyo6UmQHMJ+No3c81nujPv+n9yrg== + dependencies: + abstract-level "^1.0.2" + catering "^2.1.0" + module-error "^1.0.1" + napi-macros "^2.2.2" + node-gyp-build "^4.3.0" + clean-stack@^2.0.0: version "2.2.0" resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-2.2.0.tgz#ee8472dbb129e727b31e8a10a427dee9dfe4008b" @@ -3946,7 +4127,7 @@ debug@3.2.6: dependencies: ms "^2.1.1" -debug@4, debug@^4.0.1, debug@^4.1.1, debug@^4.3.1, debug@^4.3.2, debug@^4.3.3, debug@^4.3.4: +debug@4, debug@4.3.4, debug@^4.0.1, debug@^4.1.1, debug@^4.3.1, debug@^4.3.2, debug@^4.3.3, debug@^4.3.4: version "4.3.4" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== @@ -4210,6 +4391,15 @@ ecc-jsbn@~0.1.1: jsbn "~0.1.0" safer-buffer "^2.1.0" +ecpair@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/ecpair/-/ecpair-2.1.0.tgz#673f826b1d80d5eb091b8e2010c6b588e8d2cb45" + integrity sha512-cL/mh3MtJutFOvFc27GPZE2pWL3a3k4YvzUWEOvilnfZVlH3Jwgx/7d6tlD7/75tNk8TG2m+7Kgtz0SI1tWcqw== + dependencies: + randombytes "^2.1.0" + typeforce "^1.18.0" + wif "^2.0.6" + ee-first@1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d" @@ -4821,7 +5011,7 @@ ethereum-bloom-filters@^1.0.6: dependencies: js-sha3 "^0.8.0" -ethereum-cryptography@^0.1.2, ethereum-cryptography@^0.1.3: +ethereum-cryptography@0.1.3, ethereum-cryptography@^0.1.3: version "0.1.3" resolved "https://registry.yarnpkg.com/ethereum-cryptography/-/ethereum-cryptography-0.1.3.tgz#8d6143cfc3d74bf79bbd8edecdf29e4ae20dd191" integrity sha512-w8/4x1SGGzc+tO97TASLja6SLd3fRIK2tLVcV2Gx4IB21hE19atll5Cq9o3d0ZmAYC/8aw0ipieTSiekAea4SQ== @@ -4842,6 +5032,16 @@ ethereum-cryptography@^0.1.2, ethereum-cryptography@^0.1.3: secp256k1 "^4.0.1" setimmediate "^1.0.5" +ethereum-cryptography@^1.0.3: + version "1.2.0" + resolved "https://registry.yarnpkg.com/ethereum-cryptography/-/ethereum-cryptography-1.2.0.tgz#5ccfa183e85fdaf9f9b299a79430c044268c9b3a" + integrity sha512-6yFQC9b5ug6/17CQpCyE3k9eKBMdhyVjzUy1WkiuY/E4vj/SXDBbCw8QEIaXqf0Mf2SnY6RmpDcwlUmBSS0EJw== + dependencies: + "@noble/hashes" "1.2.0" + "@noble/secp256k1" "1.7.1" + "@scure/bip32" "1.1.5" + "@scure/bip39" "1.1.1" + ethereum-waffle@4.0.0-alpha.25: version "4.0.0-alpha.25" resolved "https://registry.yarnpkg.com/ethereum-waffle/-/ethereum-waffle-4.0.0-alpha.25.tgz#c791887930767eecb15f9afe9ddb9c3ce586af0a" @@ -4991,7 +5191,7 @@ ethers@^4.0.20: uuid "2.0.1" xmlhttprequest "1.8.0" -ethers@^5.2.0, ethers@^5.5.2: +ethers@^5.2.0, ethers@^5.5.2, ethers@^5.7.1: version "5.7.2" resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.7.2.tgz#3a7deeabbb8c030d4126b24f84e525466145872e" integrity sha512-wswUsmWo1aOK8rR7DIKiWSw9DbLWe6x98Jrn8wcTflTVvaXhAMaB5zGAXy0GYQEQp9iO1iSHWVyARQm11zUtyg== @@ -5079,11 +5279,6 @@ ethjs-util@0.1.6, ethjs-util@^0.1.3, ethjs-util@^0.1.6: is-hex-prefixed "1.0.0" strip-hex-prefix "1.0.0" -event-target-shim@^5.0.0: - version "5.0.1" - resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789" - integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ== - eventemitter3@3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-3.1.2.tgz#2d3d48f9c346698fce83a85d7d664e98535df6e7" @@ -5795,23 +5990,27 @@ hardhat-deploy@^0.11.10: qs "^6.9.4" zksync-web3 "^0.4.0" -hardhat@^2.8.3: - version "2.9.6" - resolved "https://registry.yarnpkg.com/hardhat/-/hardhat-2.9.6.tgz#9b75d8efccdfc20bdea35ffb0fd4e6a3f3ecf3cf" - integrity sha512-Vnm1iDfhbavNjvLxArt47rt6G3vPIV4Q/+pNgFkh6sfQH8JVf8px5VxiEs5cj4rPxmU+DXGKoalY+pK8fAL4oA== +hardhat@^2.18.2: + version "2.18.2" + resolved "https://registry.yarnpkg.com/hardhat/-/hardhat-2.18.2.tgz#e82169bafc83c4b2af9b33ac38bae6da5603074e" + integrity sha512-lUVmJg7DsKcUCDpqv57CJl6vHqo/1PeHSfM3+WIa8UtRKmXyVTj1qQK01TDiuetkZBVg9Dn52qU+ZwaJQynaKA== dependencies: - "@ethereumjs/block" "^3.6.2" - "@ethereumjs/blockchain" "^5.5.2" - "@ethereumjs/common" "^2.6.4" - "@ethereumjs/tx" "^3.5.1" - "@ethereumjs/vm" "^5.9.0" "@ethersproject/abi" "^5.1.2" "@metamask/eth-sig-util" "^4.0.0" + "@nomicfoundation/ethereumjs-block" "5.0.2" + "@nomicfoundation/ethereumjs-blockchain" "7.0.2" + "@nomicfoundation/ethereumjs-common" "4.0.2" + "@nomicfoundation/ethereumjs-evm" "2.0.2" + "@nomicfoundation/ethereumjs-rlp" "5.0.2" + "@nomicfoundation/ethereumjs-statemanager" "2.0.2" + "@nomicfoundation/ethereumjs-trie" "6.0.2" + "@nomicfoundation/ethereumjs-tx" "5.0.2" + "@nomicfoundation/ethereumjs-util" "9.0.2" + "@nomicfoundation/ethereumjs-vm" "7.0.2" + "@nomicfoundation/solidity-analyzer" "^0.1.0" "@sentry/node" "^5.18.1" - "@solidity-parser/parser" "^0.14.1" "@types/bn.js" "^5.1.0" "@types/lru-cache" "^5.1.0" - abort-controller "^3.0.0" adm-zip "^0.4.16" aggregate-error "^3.0.0" ansi-escapes "^4.3.0" @@ -5821,31 +6020,27 @@ hardhat@^2.8.3: debug "^4.1.1" enquirer "^2.3.0" env-paths "^2.2.0" - ethereum-cryptography "^0.1.2" + ethereum-cryptography "^1.0.3" ethereumjs-abi "^0.6.8" - ethereumjs-util "^7.1.4" find-up "^2.1.0" fp-ts "1.19.3" fs-extra "^7.0.1" glob "7.2.0" immutable "^4.0.0-rc.12" io-ts "1.10.4" + keccak "^3.0.2" lodash "^4.17.11" - merkle-patricia-tree "^4.2.4" mnemonist "^0.38.0" - mocha "^9.2.0" + mocha "^10.0.0" p-map "^4.0.0" - qs "^6.7.0" raw-body "^2.4.1" resolve "1.17.0" semver "^6.3.0" - slash "^3.0.0" solc "0.7.3" source-map-support "^0.5.13" stacktrace-parser "^0.1.10" - "true-case-path" "^2.2.1" tsort "0.0.1" - undici "^4.14.1" + undici "^5.14.0" uuid "^8.3.2" ws "^7.4.6" @@ -6389,6 +6584,11 @@ isurl@^1.0.0-alpha5: has-to-string-tag-x "^1.2.0" is-object "^1.0.1" +js-sdsl@^4.1.4: + version "4.4.2" + resolved "https://registry.yarnpkg.com/js-sdsl/-/js-sdsl-4.4.2.tgz#2e3c031b1f47d3aca8b775532e3ebb0818e7f847" + integrity sha512-dwXFwByc/ajSV6m5bcKAPwe4yDDF6D614pxmIi5odytzxRlwqF6nwoiCek80Ixc7Cvma5awClxrzFtxCQvcM8w== + js-sha3@0.5.7, js-sha3@^0.5.7: version "0.5.7" resolved "https://registry.yarnpkg.com/js-sha3/-/js-sha3-0.5.7.tgz#0d4ffd8002d5333aabaf4a23eed2f6374c9f28e7" @@ -6644,6 +6844,11 @@ level-supports@^2.0.1: resolved "https://registry.yarnpkg.com/level-supports/-/level-supports-2.1.0.tgz#9af908d853597ecd592293b2fad124375be79c5f" integrity sha512-E486g1NCjW5cF78KGPrMDRBYzPuueMZ6VBXHT6gC7A8UYWGiM14fGgp+s/L1oFfDWSPV/+SFkYCmZ0SiESkRKA== +level-supports@^4.0.0: + version "4.0.1" + resolved "https://registry.yarnpkg.com/level-supports/-/level-supports-4.0.1.tgz#431546f9d81f10ff0fea0e74533a0e875c08c66a" + integrity sha512-PbXpve8rKeNcZ9C1mUicC9auIYFyGpkV9/i6g76tLgANwWhtG2v7I4xNBUlkn3lE2/dZF3Pi0ygYGtLc4RXXdA== + level-supports@~1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/level-supports/-/level-supports-1.0.1.tgz#2f530a596834c7301622521988e2c36bb77d122d" @@ -6651,6 +6856,14 @@ level-supports@~1.0.0: dependencies: xtend "^4.0.2" +level-transcoder@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/level-transcoder/-/level-transcoder-1.0.1.tgz#f8cef5990c4f1283d4c86d949e73631b0bc8ba9c" + integrity sha512-t7bFwFtsQeD8cl8NIoQ2iwxA0CL/9IFw7/9gAjOonH0PWTTiRfY7Hq+Ejbsxh86tXobDQ6IOiddjNYIfOBs06w== + dependencies: + buffer "^6.0.3" + module-error "^1.0.1" + level-ws@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/level-ws/-/level-ws-2.0.0.tgz#207a07bcd0164a0ec5d62c304b4615c54436d339" @@ -6660,6 +6873,14 @@ level-ws@^2.0.0: readable-stream "^3.1.0" xtend "^4.0.1" +level@^8.0.0: + version "8.0.0" + resolved "https://registry.yarnpkg.com/level/-/level-8.0.0.tgz#41b4c515dabe28212a3e881b61c161ffead14394" + integrity sha512-ypf0jjAk2BWI33yzEaaotpq7fkOPALKAgDBxggO6Q9HGX2MRXn0wbP1Jn/tJv1gtL867+YOjOB49WaUF3UoJNQ== + dependencies: + browser-level "^1.0.1" + classic-level "^1.2.0" + leveldown@6.1.0: version "6.1.0" resolved "https://registry.yarnpkg.com/leveldown/-/leveldown-6.1.0.tgz#7ab1297706f70c657d1a72b31b40323aa612b9ee" @@ -6699,15 +6920,6 @@ load-json-file@^1.0.0: pinkie-promise "^2.0.0" strip-bom "^2.0.0" -"loady@git+https://github.com/chjj/loady.git#semver:~0.0.1": - version "0.0.5" - resolved "git+https://github.com/chjj/loady.git#b94958b7ee061518f4b85ea6da380e7ee93222d5" - -loady@~0.0.1, loady@~0.0.5: - version "0.0.5" - resolved "https://registry.yarnpkg.com/loady/-/loady-0.0.5.tgz#b17adb52d2fb7e743f107b0928ba0b591da5d881" - integrity sha512-uxKD2HIj042/HBx77NBcmEPsD+hxCgAtjEWlYNScuUjIsh/62Uyu39GOR68TBR68v+jqDL9zfftCWoUo4y03sQ== - locate-path@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e" @@ -6867,6 +7079,15 @@ memdown@^5.0.0: ltgt "~2.2.0" safe-buffer "~5.2.0" +memory-level@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/memory-level/-/memory-level-1.0.0.tgz#7323c3fd368f9af2f71c3cd76ba403a17ac41692" + integrity sha512-UXzwewuWeHBz5krr7EvehKcmLFNoXxGcvuYhC41tRnkrTbJohtS7kVn9akmgirtRygg+f7Yjsfi8Uu5SGSQ4Og== + dependencies: + abstract-level "^1.0.0" + functional-red-black-tree "^1.0.1" + module-error "^1.0.1" + memorystream@^0.3.1: version "0.3.1" resolved "https://registry.yarnpkg.com/memorystream/-/memorystream-0.3.1.tgz#86d7090b30ce455d63fbae12dda51a47ddcaf9b2" @@ -6978,6 +7199,13 @@ minimatch@4.2.1: dependencies: brace-expansion "^1.1.7" +minimatch@5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-5.0.1.tgz#fb9022f7528125187c92bd9e9b6366be1cf3415b" + integrity sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g== + dependencies: + brace-expansion "^2.0.1" + minimatch@^3.0.4, minimatch@^3.1.1, minimatch@^3.1.2: version "3.1.2" resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.2.tgz#19cd194bfd3e428f049a70817c038d89ab4be35b" @@ -7053,6 +7281,33 @@ mnemonist@^0.38.0: dependencies: obliterator "^2.0.0" +mocha@^10.0.0: + version "10.2.0" + resolved "https://registry.yarnpkg.com/mocha/-/mocha-10.2.0.tgz#1fd4a7c32ba5ac372e03a17eef435bd00e5c68b8" + integrity sha512-IDY7fl/BecMwFHzoqF2sg/SHHANeBoMMXFlS9r0OXKDssYE1M5O43wUY/9BVPeIvfH2zmEbBfseqN9gBQZzXkg== + dependencies: + ansi-colors "4.1.1" + browser-stdout "1.3.1" + chokidar "3.5.3" + debug "4.3.4" + diff "5.0.0" + escape-string-regexp "4.0.0" + find-up "5.0.0" + glob "7.2.0" + he "1.2.0" + js-yaml "4.1.0" + log-symbols "4.1.0" + minimatch "5.0.1" + ms "2.1.3" + nanoid "3.3.3" + serialize-javascript "6.0.0" + strip-json-comments "3.1.1" + supports-color "8.1.1" + workerpool "6.2.1" + yargs "16.2.0" + yargs-parser "20.2.4" + yargs-unparser "2.0.0" + mocha@^6.2.2: version "6.2.3" resolved "https://registry.yarnpkg.com/mocha/-/mocha-6.2.3.tgz#e648432181d8b99393410212664450a4c1e31912" @@ -7082,7 +7337,7 @@ mocha@^6.2.2: yargs-parser "13.1.2" yargs-unparser "1.6.0" -mocha@^9.0.2, mocha@^9.2.0: +mocha@^9.0.2: version "9.2.2" resolved "https://registry.yarnpkg.com/mocha/-/mocha-9.2.2.tgz#d70db46bdb93ca57402c809333e5a84977a88fb9" integrity sha512-L6XC3EdwT6YrIk0yXpavvLkn8h+EU+Y5UcCHKECyMbdUIxyMuZj4bX4U9e1nvnvUUvQVsV2VHQr5zLdcUkhW/g== @@ -7117,6 +7372,11 @@ mock-fs@^4.1.0: resolved "https://registry.yarnpkg.com/mock-fs/-/mock-fs-4.14.0.tgz#ce5124d2c601421255985e6e94da80a7357b1b18" integrity sha512-qYvlv/exQ4+svI3UOvPUpLDF0OMX5euvUH0Ny4N5QyRyhNdgAgUrVH3iUINSzEPLvx0kbo/Bp28GJKIqvE7URw== +module-error@^1.0.1, module-error@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/module-error/-/module-error-1.0.2.tgz#8d1a48897ca883f47a45816d4fb3e3c6ba404d86" + integrity sha512-0yuvsqSCv8LbaOKhnsQ/T5JhyFlCYLPXK3U2sgV10zoKQwzs/MyfuQUOZQ1V/6OCOJsK/TRgNVrPuPDqtdMFtA== + ms@2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" @@ -7186,19 +7446,11 @@ murmur-128@^0.2.1: fmix "^0.1.0" imul "^1.0.0" -"n64@git+https://github.com/chjj/n64.git#semver:~0.2.10": - version "0.2.10" - resolved "git+https://github.com/chjj/n64.git#34f981f1441f569821d97a31f8cf21a3fc11b8f6" - nan@^2.13.2, nan@^2.14.0: version "2.17.0" resolved "https://registry.yarnpkg.com/nan/-/nan-2.17.0.tgz#c0150a2368a182f033e9aa5195ec76ea41a199cb" integrity sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ== -"nan@git+https://github.com/braydonf/nan.git#semver:=2.14.0": - version "2.14.0" - resolved "git+https://github.com/braydonf/nan.git#1dcc61bd06d84e389bfd5311b2b1492a14c74201" - nano-json-stream-parser@^0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/nano-json-stream-parser/-/nano-json-stream-parser-0.1.2.tgz#0cc8f6d0e2b622b479c40d499c46d64b755c6f5f" @@ -7209,6 +7461,16 @@ nanoid@3.3.1: resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.1.tgz#6347a18cac88af88f58af0b3594b723d5e99bb35" integrity sha512-n6Vs/3KGyxPQd6uO0eH4Bv0ojGSUvuLlIHtC3Y0kEO23YRge8H9x1GCzLn28YX0H66pMkxuaeESFq4tKISKwdw== +nanoid@3.3.3: + version "3.3.3" + resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.3.tgz#fd8e8b7aa761fe807dba2d1b98fb7241bb724a25" + integrity sha512-p1sjXuopFs0xg+fPASzQ28agW1oHD7xDsd9Xkf3T15H3c/cifrFHVwrh74PdoklAPi+i7MdRsE47vm2r6JoB+w== + +napi-macros@^2.2.2: + version "2.2.2" + resolved "https://registry.yarnpkg.com/napi-macros/-/napi-macros-2.2.2.tgz#817fef20c3e0e40a963fbf7b37d1600bd0201044" + integrity sha512-hmEVtAGYzVQpCKdbQea4skABsdXW4RUh5t5mJ2zzqowJS2OyXZTU1KhDVFhx+NlWZ4ap9mqR9TcDO3LTTttd+g== + napi-macros@~2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/napi-macros/-/napi-macros-2.0.0.tgz#2b6bae421e7b96eb687aa6c77a7858640670001b" @@ -7839,7 +8101,7 @@ qs@6.11.0: dependencies: side-channel "^1.0.4" -qs@^6.7.0, qs@^6.9.4: +qs@^6.9.4: version "6.10.3" resolved "https://registry.yarnpkg.com/qs/-/qs-6.10.3.tgz#d6cde1b2ffca87b5aa57889816c5f81535e22e8e" integrity sha512-wr7M2E0OFRfIfJZjKGieI8lBKb7fRCH4Fv5KNPEs7gJ8jadvotdsS08PzOKR7opXhZ/Xkjtt3WF9g38drmyRqQ== @@ -8143,6 +8405,13 @@ rlp@^2.0.0, rlp@^2.2.3, rlp@^2.2.4: dependencies: bn.js "^5.2.0" +run-parallel-limit@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/run-parallel-limit/-/run-parallel-limit-1.1.0.tgz#be80e936f5768623a38a963262d6bef8ff11e7ba" + integrity sha512-jJA7irRNM91jaKc3Hcl1npHsFLOXOoTkPCUL1JEa1R82O2miplXXRaGdjW/KM/98YQWDhJLiSs793CnXfblJUw== + dependencies: + queue-microtask "^1.2.2" + run-parallel@^1.1.9: version "1.2.0" resolved "https://registry.yarnpkg.com/run-parallel/-/run-parallel-1.2.0.tgz#66d1368da7bdf921eb9d95bd1a9229e7f21a43ee" @@ -8846,6 +9115,13 @@ tiny-secp256k1@^1.1.3: elliptic "^6.4.0" nan "^2.13.2" +tiny-secp256k1@^2.2.3: + version "2.2.3" + resolved "https://registry.yarnpkg.com/tiny-secp256k1/-/tiny-secp256k1-2.2.3.tgz#fe1dde11a64fcee2091157d4b78bcb300feb9b65" + integrity sha512-SGcL07SxcPN2nGKHTCvRMkQLYPSoeFcvArUSCYtjVARiFAWU44cCIqYS0mYAU6nY7XfvwURuTIGo2Omt3ZQr0Q== + dependencies: + uint8array-tools "0.0.7" + tmp@0.0.33: version "0.0.33" resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9" @@ -8888,11 +9164,6 @@ tr46@~0.0.3: resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw== -"true-case-path@^2.2.1": - version "2.2.1" - resolved "https://registry.yarnpkg.com/true-case-path/-/true-case-path-2.2.1.tgz#c5bf04a5bbec3fd118be4084461b3a27c4d796bf" - integrity sha512-0z3j8R7MCjy10kc/g+qg7Ln3alJTodw9aDuVWZa3uiWqfuBMKeAeP2ocWcxoyM3D73yz3Jt/Pu4qPr4wHSdB/Q== - truffle-flattener@^1.4.0: version "1.6.0" resolved "https://registry.yarnpkg.com/truffle-flattener/-/truffle-flattener-1.6.0.tgz#abb64488b711e6cca0a9d3e449f6a85e35964c5d" @@ -9075,7 +9346,7 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" -typeforce@^1.11.5: +typeforce@^1.11.3, typeforce@^1.11.5, typeforce@^1.18.0: version "1.18.0" resolved "https://registry.yarnpkg.com/typeforce/-/typeforce-1.18.0.tgz#d7416a2c5845e085034d70fcc5b6cc4a90edbfdc" integrity sha512-7uc1O8h1M1g0rArakJdf0uLRSSgFcYexrVoKo+bzJd32gd4gDy2L/Z+8/FjPnU9ydY3pEnVPtr9FyscYY60K1g== @@ -9100,6 +9371,11 @@ typical@^5.2.0: resolved "https://registry.yarnpkg.com/typical/-/typical-5.2.0.tgz#4daaac4f2b5315460804f0acf6cb69c52bb93066" integrity sha512-dvdQgNDNJo+8B2uBQoqdb11eUCE1JQXhvjC/CZtgvZseVd5TYMXnq0+vuUemXbd/Se29cTaUuPX3YIc2xgbvIg== +uint8array-tools@0.0.7: + version "0.0.7" + resolved "https://registry.yarnpkg.com/uint8array-tools/-/uint8array-tools-0.0.7.tgz#a7a2bb5d8836eae2fade68c771454e6a438b390d" + integrity sha512-vrrNZJiusLWoFWBqz5Y5KMCgP9W9hnjZHzZiZRT8oNAkq3d5Z5Oe76jAvVVSRh4U8GGR90N2X1dWtrhvx6L8UQ== + ultron@~1.1.0: version "1.1.1" resolved "https://registry.yarnpkg.com/ultron/-/ultron-1.1.1.tgz#9fe1536a10a664a65266a1e3ccf85fd36302bc9c" @@ -9138,10 +9414,12 @@ underscore@>1.4.4: resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.13.6.tgz#04786a1f589dc6c09f761fc5f45b89e935136441" integrity sha512-+A5Sja4HP1M08MaXya7p5LvjuM7K6q/2EaC0+iovj/wOcMsTzMvDFbasi/oSapiwOlt252IqsKqPjCl7huKS0A== -undici@^4.14.1: - version "4.16.0" - resolved "https://registry.yarnpkg.com/undici/-/undici-4.16.0.tgz#469bb87b3b918818d3d7843d91a1d08da357d5ff" - integrity sha512-tkZSECUYi+/T1i4u+4+lwZmQgLXd4BLGlrc7KZPcLIW7Jpq99+Xpc30ONv7nS6F5UNOxp/HBZSSL9MafUrvJbw== +undici@^5.14.0: + version "5.26.5" + resolved "https://registry.yarnpkg.com/undici/-/undici-5.26.5.tgz#f6dc8c565e3cad8c4475b187f51a13e505092838" + integrity sha512-cSb4bPFd5qgR7qr2jYAi0hlX9n5YKK2ONKkLFkxl+v/9BvC0sOpZjBHDBSXc5lWAf5ty9oZdRXytBIHzgUcerw== + dependencies: + "@fastify/busboy" "^2.0.0" universalify@^0.1.0: version "0.1.2" @@ -9280,6 +9558,13 @@ varint@^5.0.0: resolved "https://registry.yarnpkg.com/varint/-/varint-5.0.2.tgz#5b47f8a947eb668b848e034dcfa87d0ff8a7f7a4" integrity sha512-lKxKYG6H03yCZUpAGOPOsMcGxd1RHCu1iKvEHYDPmTyq2HueGhD73ssNBqqQWfvYs04G9iUFRvmAVLW20Jw6ow== +varuint-bitcoin@^1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/varuint-bitcoin/-/varuint-bitcoin-1.1.2.tgz#e76c138249d06138b480d4c5b40ef53693e24e92" + integrity sha512-4EVb+w4rx+YfVM32HQX42AbbT7/1f5zwAYhIujKXKk8NQK+JfRVl3pqT3hjNn/L+RstigmGGKVwHA/P0wgITZw== + dependencies: + safe-buffer "^5.1.1" + vary@^1, vary@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc" @@ -10148,6 +10433,11 @@ workerpool@6.2.0: resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.2.0.tgz#827d93c9ba23ee2019c3ffaff5c27fccea289e8b" integrity sha512-Rsk5qQHJ9eowMH28Jwhe8HEbmdYDX4lwoMWshiCXugjtHqMD9ZbiqSDLxcsfdqsETPzVUtX5s1Z5kStiIM6l4A== +workerpool@6.2.1: + version "6.2.1" + resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.2.1.tgz#46fc150c17d826b86a008e5a4508656777e9c343" + integrity sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw== + wrap-ansi@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85" diff --git a/typescript/.eslintignore b/typescript/.eslintignore index fc0895897..e6f28fa5e 100644 --- a/typescript/.eslintignore +++ b/typescript/.eslintignore @@ -1,3 +1,4 @@ dist/ node_modules/ typechain/ +api-reference/ diff --git a/typescript/.prettierignore b/typescript/.prettierignore index aa7f39fe5..ae167429d 100644 --- a/typescript/.prettierignore +++ b/typescript/.prettierignore @@ -1,3 +1,4 @@ dist/ external/ typechain/ +api-reference/ diff --git a/typescript/README.adoc b/typescript/README.adoc deleted file mode 100644 index 9d518ab76..000000000 --- a/typescript/README.adoc +++ /dev/null @@ -1,55 +0,0 @@ -:toc: macro - -= tBTC v2 TypeScript bindings - -https://github.com/keep-network/tbtc-v2/actions/workflows/typescript.yml[image:https://img.shields.io/github/actions/workflow/status/keep-network/tbtc-v2/typescript.yml?branch=main&event=push&label=TypeScript%20bindings%20build[TypeScript bindings build status]] - -This package provides TypeScript bindings to the tBTC v2 system. - -toc::[] - -== Build, test and deploy - -=== Prerequisites - -Please make sure you have the following prerequisites installed on your machine: - -- https://nodejs.org[Node.js] >=16 -- https://yarnpkg.com[Yarn] >=1.22.19 - -=== Install dependencies - -To install dependencies, run: -``` -yarn install -``` - -**NOTE:** The `@keep-network/tbtc.ts` package contains an indirect dependency to -`@summa-tx/relay-sol@2.0.2` package, which downloads one of its sub-dependencies -via unathenticated `git://` protocol. That protocol is no longer supported by -GitHub. This means that in certain situations installation of the package or -update of its dependencies using Yarn may result in `The unauthenticated git -protocol on port 9418 is no longer supported` or `fatal: unable to connect -to github.com` errors. - -As a workaround, we advise changing Git configuration to use `https://` protocol -instead of `git://` by executing: - -``` -git config --global url."https://".insteadOf git:// -``` - -=== Build - -To build the library, invoke: -``` -yarn build -``` -A `dist` directory containing the resulting artifacts will be created. - -=== Test - -To run unit tests, do: -``` -yarn test -``` \ No newline at end of file diff --git a/typescript/README.md b/typescript/README.md new file mode 100644 index 000000000..7f841306f --- /dev/null +++ b/typescript/README.md @@ -0,0 +1,155 @@ +# tBTC v2 SDK + +[![build](https://img.shields.io/github/actions/workflow/status/keep-network/tbtc-v2/typescript.yml?branch=main&event=push&label=build)](https://github.com/keep-network/tbtc-v2/actions/workflows/typescript.yml) +[![npm](https://img.shields.io/npm/v/%40keep-network%2Ftbtc-v2.ts)](https://www.npmjs.com/package/@keep-network/tbtc-v2.ts) +[![documentation](https://badgen.net/static/GitBook/Documentation/yellow)](https://docs.threshold.network/app-development/tbtc-v2/tbtc-sdk) + +tBTC SDK is a TypeScript library that provides effortless access to the +fundamental features of the tBTC Bitcoin bridge. The SDK allows developers +to integrate tBTC into their own applications and offer the power of +trustless tokenized Bitcoin to their users. + +**Table of contents:** + +- [Quickstart](#quickstart) + - [Installation](#installation) + - [Usage](#usage) +- [Contributing](#contributing) + - [Prerequisites](#prerequisites) + - [Install dependencies](#install-dependencies) + - [Build](#build) + - [Test](#test) + - [Format](#format) + - [Auto-generated API reference](#auto-generated-api-reference) +- [Documentation](#documentation) + +## Quickstart + +Here you can find instructions explaining how to use the SDK in your own +project. + +### Installation + +To install the tBTC SDK in your project using `yarn`, run: + +```bash +yarn add @keep-network/tbtc-v2.ts +``` + +If you prefer to use `npm`, do: + +```bash +npm i @keep-network/tbtc-v2.ts +``` + +Please note that you will also need to install the +[ethers v5](https://docs.ethers.org/v5) library to initialize +a signer or provider. To do so using `yarn`, invoke: + +```bash +yarn add ethers@legacy-v5 +``` + +To do the same using `npm`, run: + +```bash +npm i ethers@legacy-v5 +``` + +> The SDK depends on ethers v5. Proper support for newer ethers versions +> is not guaranteed right now. + +### Usage + +Here is a short example demonstrating SDK usage: + +```typescript +// Import SDK entrypoint component. +import { TBTC } from "@keep-network/tbtc-v2.ts" + +// Create an instance of ethers signer. +const signer = (...) + +// Initialize the SDK. +const sdk = await TBTC.initializeMainnet(signer) + +// Access SDK features. +sdk.deposits.(...) +sdk.redemptions.(...) + +// Access tBTC smart contracts directly. +sdk.tbtcContracts.(...) + +// Access Bitcoin client directly. +sdk.bitcoinClient.(...) +``` + +## Contributing + +Contributions are always welcome! Feel free to open any issue or send a pull request. +Please refer the repository-level +[CONTRIBUTING.adoc](https://github.com/keep-network/tbtc-v2/blob/main/CONTRIBUTING.adoc) +document for general contribution guidelines. Below, you can find how to set up +the SDK module for development. + +### Prerequisites + +Please make sure you have the following prerequisites installed on your machine: + +- [node.js](https://nodejs.org) >=16 +- [yarn](https://classic.yarnpkg.com) >=1.22 or [npm](https://github.com/npm/cli) >=8.11 + +> Although the below commands use `yarn` you can easily use `npm` instead. + +### Install dependencies + +To install dependencies, run: + +```bash +yarn install +``` + +### Build + +To build the library, invoke: + +```bash +yarn build +``` + +A `dist` directory containing the resulting artifacts will be created. + +### Test + +To run unit tests, do: + +```bash +yarn test +``` + +### Format + +To format code automatically, invoke: + +```bash +yarn format:fix +``` + +### Auto-generated API reference + +There is an auto-generated API reference documentation that must be +re-generated in case of modifications in the source code. This can be +done automatically using a pre-commit hook or manually using: + +```bash +yarn docs +``` + +Generated API reference in form of Markdown files is saved +to the [`api-reference`](./api-reference) directory. + +## Documentation + +This README provides just a basic guidance. Comprehensive documentation for +this SDK can be found on the +[Threshold Network Docs website](https://docs.threshold.network/app-development/tbtc-v2/tbtc-sdk). diff --git a/typescript/api-reference/README.md b/typescript/api-reference/README.md new file mode 100644 index 000000000..b5e639aa6 --- /dev/null +++ b/typescript/api-reference/README.md @@ -0,0 +1,986 @@ +# @keep-network/tbtc-v2.ts + +## Table of contents + +### Namespaces + +- [BitcoinNetwork](modules/BitcoinNetwork.md) +- [GetChainEvents](modules/GetChainEvents.md) +- [WalletState](modules/WalletState.md) + +### Enumerations + +- [BitcoinNetwork](enums/BitcoinNetwork-1.md) +- [WalletState](enums/WalletState-1.md) + +### Classes + +- [BitcoinTxHash](classes/BitcoinTxHash.md) +- [Deposit](classes/Deposit.md) +- [DepositFunding](classes/DepositFunding.md) +- [DepositRefund](classes/DepositRefund.md) +- [DepositScript](classes/DepositScript.md) +- [DepositsService](classes/DepositsService.md) +- [ElectrumClient](classes/ElectrumClient.md) +- [EthereumAddress](classes/EthereumAddress.md) +- [EthereumBridge](classes/EthereumBridge.md) +- [EthereumTBTCToken](classes/EthereumTBTCToken.md) +- [EthereumTBTCVault](classes/EthereumTBTCVault.md) +- [EthereumWalletRegistry](classes/EthereumWalletRegistry.md) +- [Hex](classes/Hex.md) +- [MaintenanceService](classes/MaintenanceService.md) +- [OptimisticMinting](classes/OptimisticMinting.md) +- [RedemptionsService](classes/RedemptionsService.md) +- [Spv](classes/Spv.md) +- [TBTC](classes/TBTC.md) +- [WalletTx](classes/WalletTx.md) + +### Interfaces + +- [BitcoinClient](interfaces/BitcoinClient.md) +- [BitcoinHeader](interfaces/BitcoinHeader.md) +- [BitcoinRawTx](interfaces/BitcoinRawTx.md) +- [BitcoinRawTxVectors](interfaces/BitcoinRawTxVectors.md) +- [BitcoinSpvProof](interfaces/BitcoinSpvProof.md) +- [BitcoinTx](interfaces/BitcoinTx.md) +- [BitcoinTxMerkleBranch](interfaces/BitcoinTxMerkleBranch.md) +- [BitcoinTxOutpoint](interfaces/BitcoinTxOutpoint.md) +- [BitcoinTxOutput](interfaces/BitcoinTxOutput.md) +- [Bridge](interfaces/Bridge.md) +- [ChainEvent](interfaces/ChainEvent.md) +- [ChainIdentifier](interfaces/ChainIdentifier.md) +- [DepositReceipt](interfaces/DepositReceipt.md) +- [DepositRequest](interfaces/DepositRequest.md) +- [ElectrumCredentials](interfaces/ElectrumCredentials.md) +- [EthereumContractConfig](interfaces/EthereumContractConfig.md) +- [RedemptionRequest](interfaces/RedemptionRequest.md) +- [TBTCToken](interfaces/TBTCToken.md) +- [TBTCVault](interfaces/TBTCVault.md) +- [Wallet](interfaces/Wallet.md) +- [WalletRegistry](interfaces/WalletRegistry.md) + +### Type Aliases + +- [BitcoinTxInput](README.md#bitcointxinput) +- [BitcoinUtxo](README.md#bitcoinutxo) +- [DepositRevealedEvent](README.md#depositrevealedevent) +- [DkgResultApprovedEvent](README.md#dkgresultapprovedevent) +- [DkgResultChallengedEvent](README.md#dkgresultchallengedevent) +- [DkgResultSubmittedEvent](README.md#dkgresultsubmittedevent) +- [ElectrumClientOptions](README.md#electrumclientoptions) +- [ErrorMatcherFn](README.md#errormatcherfn) +- [EthereumNetwork](README.md#ethereumnetwork) +- [EthereumSigner](README.md#ethereumsigner) +- [ExecutionLoggerFn](README.md#executionloggerfn) +- [NewWalletRegisteredEvent](README.md#newwalletregisteredevent) +- [OptimisticMintingCancelledEvent](README.md#optimisticmintingcancelledevent) +- [OptimisticMintingFinalizedEvent](README.md#optimisticmintingfinalizedevent) +- [OptimisticMintingRequest](README.md#optimisticmintingrequest) +- [OptimisticMintingRequestedEvent](README.md#optimisticmintingrequestedevent) +- [RedemptionRequestedEvent](README.md#redemptionrequestedevent) +- [RetrierFn](README.md#retrierfn) +- [TBTCContracts](README.md#tbtccontracts) + +### Variables + +- [BitcoinAddressConverter](README.md#bitcoinaddressconverter) +- [BitcoinCompactSizeUint](README.md#bitcoincompactsizeuint) +- [BitcoinHashUtils](README.md#bitcoinhashutils) +- [BitcoinHeaderSerializer](README.md#bitcoinheaderserializer) +- [BitcoinLocktimeUtils](README.md#bitcoinlocktimeutils) +- [BitcoinPrivateKeyUtils](README.md#bitcoinprivatekeyutils) +- [BitcoinPublicKeyUtils](README.md#bitcoinpublickeyutils) +- [BitcoinScriptUtils](README.md#bitcoinscriptutils) +- [BitcoinTargetConverter](README.md#bitcointargetconverter) + +### Functions + +- [assembleBitcoinSpvProof](README.md#assemblebitcoinspvproof) +- [backoffRetrier](README.md#backoffretrier) +- [computeElectrumScriptHash](README.md#computeelectrumscripthash) +- [ethereumAddressFromSigner](README.md#ethereumaddressfromsigner) +- [ethereumNetworkFromSigner](README.md#ethereumnetworkfromsigner) +- [extractBitcoinRawTxVectors](README.md#extractbitcoinrawtxvectors) +- [loadEthereumContracts](README.md#loadethereumcontracts) +- [retryAll](README.md#retryall) +- [skipRetryWhenMatched](README.md#skipretrywhenmatched) +- [toBitcoinJsLibNetwork](README.md#tobitcoinjslibnetwork) +- [validateBitcoinHeadersChain](README.md#validatebitcoinheaderschain) +- [validateBitcoinSpvProof](README.md#validatebitcoinspvproof) +- [validateDepositReceipt](README.md#validatedepositreceipt) + +## Type Aliases + +### BitcoinTxInput + +Ƭ **BitcoinTxInput**: [`BitcoinTxOutpoint`](interfaces/BitcoinTxOutpoint.md) & \{ `scriptSig`: [`Hex`](classes/Hex.md) } + +Data about a Bitcoin transaction input. + +#### Defined in + +[lib/bitcoin/tx.ts:63](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/tx.ts#L63) + +___ + +### BitcoinUtxo + +Ƭ **BitcoinUtxo**: [`BitcoinTxOutpoint`](interfaces/BitcoinTxOutpoint.md) & \{ `value`: `BigNumber` } + +Data about a Bitcoin unspent transaction output. + +#### Defined in + +[lib/bitcoin/tx.ts:93](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/tx.ts#L93) + +___ + +### DepositRevealedEvent + +Ƭ **DepositRevealedEvent**: [`DepositReceipt`](interfaces/DepositReceipt.md) & `Pick`\<[`DepositRequest`](interfaces/DepositRequest.md), ``"amount"`` \| ``"vault"``\> & \{ `fundingOutputIndex`: `number` ; `fundingTxHash`: [`BitcoinTxHash`](classes/BitcoinTxHash.md) } & [`ChainEvent`](interfaces/ChainEvent.md) + +Represents an event emitted on deposit reveal to the on-chain bridge. + +#### Defined in + +[lib/contracts/bridge.ts:283](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L283) + +___ + +### DkgResultApprovedEvent + +Ƭ **DkgResultApprovedEvent**: \{ `approver`: [`ChainIdentifier`](interfaces/ChainIdentifier.md) ; `resultHash`: [`Hex`](classes/Hex.md) } & [`ChainEvent`](interfaces/ChainEvent.md) + +Represents an event emitted when a DKG result is approved on the on-chain +wallet registry. + +#### Defined in + +[lib/contracts/wallet-registry.ts:64](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/wallet-registry.ts#L64) + +___ + +### DkgResultChallengedEvent + +Ƭ **DkgResultChallengedEvent**: \{ `challenger`: [`ChainIdentifier`](interfaces/ChainIdentifier.md) ; `reason`: `string` ; `resultHash`: [`Hex`](classes/Hex.md) } & [`ChainEvent`](interfaces/ChainEvent.md) + +Represents an event emitted when a DKG result is challenged on the on-chain +wallet registry. + +#### Defined in + +[lib/contracts/wallet-registry.ts:79](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/wallet-registry.ts#L79) + +___ + +### DkgResultSubmittedEvent + +Ƭ **DkgResultSubmittedEvent**: \{ `result`: `DkgResult` ; `resultHash`: [`Hex`](classes/Hex.md) ; `seed`: [`Hex`](classes/Hex.md) } & [`ChainEvent`](interfaces/ChainEvent.md) + +Represents an event emitted when a DKG result is submitted to the on-chain +wallet registry. + +#### Defined in + +[lib/contracts/wallet-registry.ts:45](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/wallet-registry.ts#L45) + +___ + +### ElectrumClientOptions + +Ƭ **ElectrumClientOptions**: `object` + +Additional options used by the Electrum server. + +#### Defined in + +[lib/electrum/client.ts:48](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L48) + +___ + +### ErrorMatcherFn + +Ƭ **ErrorMatcherFn**: (`err`: `unknown`) => `boolean` + +#### Type declaration + +▸ (`err`): `boolean` + +##### Parameters + +| Name | Type | +| :------ | :------ | +| `err` | `unknown` | + +##### Returns + +`boolean` + +True if the error matches, false otherwise. + +#### Defined in + +[lib/utils/backoff.ts:42](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/utils/backoff.ts#L42) + +___ + +### EthereumNetwork + +Ƭ **EthereumNetwork**: ``"local"`` \| ``"goerli"`` \| ``"mainnet"`` + +Supported Ethereum networks. + +#### Defined in + +[lib/ethereum/index.ts:74](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/index.ts#L74) + +___ + +### EthereumSigner + +Ƭ **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. + +#### Defined in + +[lib/ethereum/index.ts:25](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/index.ts#L25) + +___ + +### ExecutionLoggerFn + +Ƭ **ExecutionLoggerFn**: (`msg`: `string`) => `void` + +#### Type declaration + +▸ (`msg`): `void` + +A function that is called with execution status messages. + +##### Parameters + +| Name | Type | +| :------ | :------ | +| `msg` | `string` | + +##### Returns + +`void` + +#### Defined in + +[lib/utils/backoff.ts:56](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/utils/backoff.ts#L56) + +___ + +### NewWalletRegisteredEvent + +Ƭ **NewWalletRegisteredEvent**: \{ `ecdsaWalletID`: [`Hex`](classes/Hex.md) ; `walletPublicKeyHash`: [`Hex`](classes/Hex.md) } & [`ChainEvent`](interfaces/ChainEvent.md) + +Represents an event emitted when new wallet is registered on the on-chain bridge. + +#### Defined in + +[lib/contracts/bridge.ts:445](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L445) + +___ + +### OptimisticMintingCancelledEvent + +Ƭ **OptimisticMintingCancelledEvent**: \{ `depositKey`: [`Hex`](classes/Hex.md) ; `guardian`: [`ChainIdentifier`](interfaces/ChainIdentifier.md) } & [`ChainEvent`](interfaces/ChainEvent.md) + +Represents an event that is emitted when an optimistic minting request +is cancelled on chain. + +#### Defined in + +[lib/contracts/tbtc-vault.ts:170](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/tbtc-vault.ts#L170) + +___ + +### OptimisticMintingFinalizedEvent + +Ƭ **OptimisticMintingFinalizedEvent**: \{ `depositKey`: [`Hex`](classes/Hex.md) ; `depositor`: [`ChainIdentifier`](interfaces/ChainIdentifier.md) ; `minter`: [`ChainIdentifier`](interfaces/ChainIdentifier.md) ; `optimisticMintingDebt`: `BigNumber` } & [`ChainEvent`](interfaces/ChainEvent.md) + +Represents an event that is emitted when an optimistic minting request +is finalized on chain. + +#### Defined in + +[lib/contracts/tbtc-vault.ts:186](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/tbtc-vault.ts#L186) + +___ + +### OptimisticMintingRequest + +Ƭ **OptimisticMintingRequest**: `Object` + +Represents optimistic minting request for the given deposit revealed to the +Bridge. + +#### Type declaration + +| 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. | + +#### Defined in + +[lib/contracts/tbtc-vault.ts:120](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/tbtc-vault.ts#L120) + +___ + +### OptimisticMintingRequestedEvent + +Ƭ **OptimisticMintingRequestedEvent**: \{ `amount`: `BigNumber` ; `depositKey`: [`Hex`](classes/Hex.md) ; `depositor`: [`ChainIdentifier`](interfaces/ChainIdentifier.md) ; `fundingOutputIndex`: `number` ; `fundingTxHash`: [`BitcoinTxHash`](classes/BitcoinTxHash.md) ; `minter`: [`ChainIdentifier`](interfaces/ChainIdentifier.md) } & [`ChainEvent`](interfaces/ChainEvent.md) + +Represents an event that is emitted when a new optimistic minting is requested +on chain. + +#### Defined in + +[lib/contracts/tbtc-vault.ts:136](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/tbtc-vault.ts#L136) + +___ + +### RedemptionRequestedEvent + +Ƭ **RedemptionRequestedEvent**: `Omit`\<[`RedemptionRequest`](interfaces/RedemptionRequest.md), ``"requestedAt"``\> & \{ `walletPublicKeyHash`: [`Hex`](classes/Hex.md) } & [`ChainEvent`](interfaces/ChainEvent.md) + +Represents an event emitted on redemption request. + +#### Defined in + +[lib/contracts/bridge.ts:334](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L334) + +___ + +### RetrierFn + +Ƭ **RetrierFn**\<`T`\>: (`fn`: () => `Promise`\<`T`\>) => `Promise`\<`T`\> + +#### Type parameters + +| Name | +| :------ | +| `T` | + +#### Type declaration + +▸ (`fn`): `Promise`\<`T`\> + +##### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `fn` | () => `Promise`\<`T`\> | The function to be retried. | + +##### Returns + +`Promise`\<`T`\> + +#### Defined in + +[lib/utils/backoff.ts:51](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/utils/backoff.ts#L51) + +___ + +### TBTCContracts + +Ƭ **TBTCContracts**: `Object` + +Convenience type aggregating all TBTC contracts handles. + +#### Type declaration + +| Name | Type | +| :------ | :------ | +| `bridge` | [`Bridge`](interfaces/Bridge.md) | +| `tbtcToken` | [`TBTCToken`](interfaces/TBTCToken.md) | +| `tbtcVault` | [`TBTCVault`](interfaces/TBTCVault.md) | +| `walletRegistry` | [`WalletRegistry`](interfaces/WalletRegistry.md) | + +#### Defined in + +[lib/contracts/index.ts:16](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/index.ts#L16) + +## Variables + +### BitcoinAddressConverter + +• `Const` **BitcoinAddressConverter**: `Object` + +Utility functions allowing to perform Bitcoin address conversions. + +#### Type declaration + +| Name | Type | +| :------ | :------ | +| `addressToOutputScript` | (`address`: `string`, `bitcoinNetwork`: [`BitcoinNetwork`](enums/BitcoinNetwork-1.md)) => [`Hex`](classes/Hex.md) | +| `addressToPublicKeyHash` | (`address`: `string`, `bitcoinNetwork`: [`BitcoinNetwork`](enums/BitcoinNetwork-1.md)) => [`Hex`](classes/Hex.md) | +| `outputScriptToAddress` | (`script`: [`Hex`](classes/Hex.md), `bitcoinNetwork`: [`BitcoinNetwork`](enums/BitcoinNetwork-1.md)) => `string` | +| `publicKeyHashToAddress` | (`publicKeyHash`: [`Hex`](classes/Hex.md), `witness`: `boolean`, `bitcoinNetwork`: [`BitcoinNetwork`](enums/BitcoinNetwork-1.md)) => `string` | +| `publicKeyToAddress` | (`publicKey`: [`Hex`](classes/Hex.md), `bitcoinNetwork`: [`BitcoinNetwork`](enums/BitcoinNetwork-1.md), `witness`: `boolean`) => `string` | + +#### Defined in + +[lib/bitcoin/address.ts:112](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/address.ts#L112) + +___ + +### BitcoinCompactSizeUint + +• `Const` **BitcoinCompactSizeUint**: `Object` + +Utility functions allowing to deal with Bitcoin compact size uints. + +#### Type declaration + +| Name | Type | +| :------ | :------ | +| `read` | (`varLenData`: [`Hex`](classes/Hex.md)) => \{ `byteLength`: `number` ; `value`: `number` } | + +#### Defined in + +[lib/bitcoin/csuint.ts:50](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/csuint.ts#L50) + +___ + +### BitcoinHashUtils + +• `Const` **BitcoinHashUtils**: `Object` + +Utility functions allowing to deal with Bitcoin hashes. + +#### Type declaration + +| Name | Type | +| :------ | :------ | +| `computeHash160` | (`text`: [`Hex`](classes/Hex.md)) => [`Hex`](classes/Hex.md) | +| `computeHash256` | (`text`: [`Hex`](classes/Hex.md)) => [`Hex`](classes/Hex.md) | +| `computeSha256` | (`text`: [`Hex`](classes/Hex.md)) => [`Hex`](classes/Hex.md) | +| `hashLEToBigNumber` | (`hash`: [`Hex`](classes/Hex.md)) => `BigNumber` | + +#### Defined in + +[lib/bitcoin/hash.ts:52](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/hash.ts#L52) + +___ + +### BitcoinHeaderSerializer + +• `Const` **BitcoinHeaderSerializer**: `Object` + +Utility functions allowing to serialize and deserialize Bitcoin block headers. + +#### Type declaration + +| Name | Type | +| :------ | :------ | +| `deserializeHeader` | (`rawHeader`: [`Hex`](classes/Hex.md)) => [`BitcoinHeader`](interfaces/BitcoinHeader.md) | +| `deserializeHeadersChain` | (`rawHeadersChain`: [`Hex`](classes/Hex.md)) => [`BitcoinHeader`](interfaces/BitcoinHeader.md)[] | +| `serializeHeader` | (`header`: [`BitcoinHeader`](interfaces/BitcoinHeader.md)) => [`Hex`](classes/Hex.md) | + +#### Defined in + +[lib/bitcoin/header.ts:109](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/header.ts#L109) + +___ + +### BitcoinLocktimeUtils + +• `Const` **BitcoinLocktimeUtils**: `Object` + +Utility functions allowing to deal with Bitcoin locktime. + +#### Type declaration + +| Name | Type | +| :------ | :------ | +| `calculateLocktime` | (`locktimeStartedAt`: `number`, `locktimeDuration`: `number`) => [`Hex`](classes/Hex.md) | +| `locktimeToNumber` | (`locktimeLE`: `string` \| `Buffer`) => `number` | + +#### Defined in + +[lib/bitcoin/tx.ts:234](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/tx.ts#L234) + +___ + +### BitcoinPrivateKeyUtils + +• `Const` **BitcoinPrivateKeyUtils**: `Object` + +Utility functions allowing to perform operations on Bitcoin ECDSA private keys. + +#### Type declaration + +| Name | Type | +| :------ | :------ | +| `createKeyPair` | (`privateKey`: `string`, `bitcoinNetwork`: [`BitcoinNetwork`](enums/BitcoinNetwork-1.md)) => `ECPairInterface` | + +#### Defined in + +[lib/bitcoin/ecdsa-key.ts:77](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/ecdsa-key.ts#L77) + +___ + +### BitcoinPublicKeyUtils + +• `Const` **BitcoinPublicKeyUtils**: `Object` + +Utility functions allowing to perform operations on Bitcoin ECDSA public keys. + +#### Type declaration + +| Name | Type | +| :------ | :------ | +| `compressPublicKey` | (`publicKey`: [`Hex`](classes/Hex.md)) => `string` | +| `isCompressedPublicKey` | (`publicKey`: [`Hex`](classes/Hex.md)) => `boolean` | + +#### Defined in + +[lib/bitcoin/ecdsa-key.ts:51](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/ecdsa-key.ts#L51) + +___ + +### BitcoinScriptUtils + +• `Const` **BitcoinScriptUtils**: `Object` + +Utility functions allowing to deal with Bitcoin scripts. + +#### Type declaration + +| Name | Type | +| :------ | :------ | +| `isP2PKHScript` | (`script`: [`Hex`](classes/Hex.md)) => `boolean` | +| `isP2SHScript` | (`script`: [`Hex`](classes/Hex.md)) => `boolean` | +| `isP2WPKHScript` | (`script`: [`Hex`](classes/Hex.md)) => `boolean` | +| `isP2WSHScript` | (`script`: [`Hex`](classes/Hex.md)) => `boolean` | + +#### Defined in + +[lib/bitcoin/script.ts:63](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/script.ts#L63) + +___ + +### BitcoinTargetConverter + +• `Const` **BitcoinTargetConverter**: `Object` + +Utility functions allowing to perform Bitcoin target conversions. + +#### Type declaration + +| Name | Type | +| :------ | :------ | +| `bitsToTarget` | (`bits`: `number`) => `BigNumber` | +| `targetToDifficulty` | (`target`: `BigNumber`) => `BigNumber` | + +#### Defined in + +[lib/bitcoin/header.ts:268](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/header.ts#L268) + +## Functions + +### assembleBitcoinSpvProof + +▸ **assembleBitcoinSpvProof**(`transactionHash`, `requiredConfirmations`, `bitcoinClient`): `Promise`\<[`BitcoinTx`](interfaces/BitcoinTx.md) & [`BitcoinSpvProof`](interfaces/BitcoinSpvProof.md)\> + +Assembles a proof that a given transaction was included in the blockchain and +has accumulated the required number of confirmations. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `transactionHash` | [`BitcoinTxHash`](classes/BitcoinTxHash.md) | Hash of the transaction being proven. | +| `requiredConfirmations` | `number` | Required number of confirmations. | +| `bitcoinClient` | [`BitcoinClient`](interfaces/BitcoinClient.md) | Bitcoin client used to interact with the network. | + +#### Returns + +`Promise`\<[`BitcoinTx`](interfaces/BitcoinTx.md) & [`BitcoinSpvProof`](interfaces/BitcoinSpvProof.md)\> + +Bitcoin transaction along with the inclusion proof. + +#### Defined in + +[lib/bitcoin/spv.ts:64](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/spv.ts#L64) + +___ + +### backoffRetrier + +▸ **backoffRetrier**\<`T`\>(`retries`, `backoffStepMs?`, `logger?`, `errorMatcher?`): [`RetrierFn`](README.md#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")) + ) + +#### Type parameters + +| Name | +| :------ | +| `T` | + +#### Parameters + +| 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`](README.md#executionloggerfn) | `console.debug` | A logger function to pass execution messages. | +| `errorMatcher?` | [`ErrorMatcherFn`](README.md#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. | + +#### Returns + +[`RetrierFn`](README.md#retrierfn)\<`T`\> + +A function that can retry any function. + +#### Defined in + +[lib/utils/backoff.ts:89](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/utils/backoff.ts#L89) + +___ + +### computeElectrumScriptHash + +▸ **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](https://electrumx.readthedocs.io/en/stable/protocol-basics.html#script-hashes) + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `script` | [`Hex`](classes/Hex.md) | Bitcoin script as hex string | + +#### Returns + +`string` + +Electrum script hash as a hex string. + +#### Defined in + +[lib/electrum/client.ts:649](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L649) + +___ + +### ethereumAddressFromSigner + +▸ **ethereumAddressFromSigner**(`signer`): `Promise`\<[`EthereumAddress`](classes/EthereumAddress.md) \| `undefined`\> + +Resolves the Ethereum address tied to the given signer. The address +cannot be resolved for signers that works in the read-only mode + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `signer` | [`EthereumSigner`](README.md#ethereumsigner) | The signer whose address should be resolved. | + +#### Returns + +`Promise`\<[`EthereumAddress`](classes/EthereumAddress.md) \| `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. + +#### Defined in + +[lib/ethereum/index.ts:61](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/index.ts#L61) + +___ + +### ethereumNetworkFromSigner + +▸ **ethereumNetworkFromSigner**(`signer`): `Promise`\<[`EthereumNetwork`](README.md#ethereumnetwork)\> + +Resolves the Ethereum network the given signer is tied to. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `signer` | [`EthereumSigner`](README.md#ethereumsigner) | The signer whose network should be resolved. | + +#### Returns + +`Promise`\<[`EthereumNetwork`](README.md#ethereumnetwork)\> + +Ethereum network. + +#### Defined in + +[lib/ethereum/index.ts:32](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/index.ts#L32) + +___ + +### extractBitcoinRawTxVectors + +▸ **extractBitcoinRawTxVectors**(`rawTransaction`): [`BitcoinRawTxVectors`](interfaces/BitcoinRawTxVectors.md) + +Decomposes a transaction in the raw representation into version, vector of +inputs, vector of outputs and locktime. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `rawTransaction` | [`BitcoinRawTx`](interfaces/BitcoinRawTx.md) | Transaction in the raw format. | + +#### Returns + +[`BitcoinRawTxVectors`](interfaces/BitcoinRawTxVectors.md) + +Transaction data with fields represented as un-prefixed hex strings. + +#### Defined in + +[lib/bitcoin/tx.ts:133](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/tx.ts#L133) + +___ + +### loadEthereumContracts + +▸ **loadEthereumContracts**(`signer`, `network`): `Promise`\<[`TBTCContracts`](README.md#tbtccontracts)\> + +Loads Ethereum implementation of tBTC contracts for the given Ethereum +network and attaches the given signer there. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `signer` | [`EthereumSigner`](README.md#ethereumsigner) | Signer that should be attached to tBTC contracts. | +| `network` | [`EthereumNetwork`](README.md#ethereumnetwork) | Ethereum network. | + +#### Returns + +`Promise`\<[`TBTCContracts`](README.md#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. + +#### Defined in + +[lib/ethereum/index.ts:85](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/index.ts#L85) + +___ + +### retryAll + +▸ **retryAll**(`error`): ``true`` + +A convenience matcher for withBackoffRetries that retries irrespective of +the error. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `error` | `any` | The error to match against. Not necessarily an Error instance, since the retriable function may throw a non-Error. | + +#### Returns + +``true`` + +Always returns true. + +#### Defined in + +[lib/utils/backoff.ts:9](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/utils/backoff.ts#L9) + +___ + +### skipRetryWhenMatched + +▸ **skipRetryWhenMatched**(`matchers`): [`ErrorMatcherFn`](README.md#errormatcherfn) + +A matcher to specify list of error messages that should abort the retry loop +and throw immediately. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `matchers` | (`string` \| `RegExp`)[] | List of patterns for error matching. | + +#### Returns + +[`ErrorMatcherFn`](README.md#errormatcherfn) + +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 + +#### Defined in + +[lib/utils/backoff.ts:20](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/utils/backoff.ts#L20) + +___ + +### toBitcoinJsLibNetwork + +▸ **toBitcoinJsLibNetwork**(`bitcoinNetwork`): `networks.Network` + +Converts the provided [BitcoinNetwork](enums/BitcoinNetwork-1.md) enumeration to a format expected +by the `bitcoinjs-lib` library. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `bitcoinNetwork` | [`BitcoinNetwork`](enums/BitcoinNetwork-1.md) | Specified Bitcoin network. | + +#### Returns + +`networks.Network` + +Network representation compatible with the `bitcoinjs-lib` library. + +**`Throws`** + +An error if the network is not supported by `bitcoinjs-lib`. + +#### Defined in + +[lib/bitcoin/network.ts:55](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/network.ts#L55) + +___ + +### validateBitcoinHeadersChain + +▸ **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. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `headers` | [`BitcoinHeader`](interfaces/BitcoinHeader.md)[] | 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. | + +#### Returns + +`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. + +#### Defined in + +[lib/bitcoin/header.ts:132](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/header.ts#L132) + +___ + +### validateBitcoinSpvProof + +▸ **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. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `transactionHash` | [`BitcoinTxHash`](classes/BitcoinTxHash.md) | 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`](interfaces/BitcoinClient.md) | The client for interacting with the Bitcoin blockchain. | + +#### Returns + +`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. + +#### Defined in + +[lib/bitcoin/spv.ts:145](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/spv.ts#L145) + +___ + +### validateDepositReceipt + +▸ **validateDepositReceipt**(`receipt`): `void` + +Validates the given deposit receipt. Throws in case of a validation error. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `receipt` | [`DepositReceipt`](interfaces/DepositReceipt.md) | The validated deposit receipt. | + +#### Returns + +`void` + +**`Dev`** + +This function does not validate the depositor's identifier as its + validity is chain-specific. This parameter must be validated outside. + +#### Defined in + +[lib/contracts/bridge.ts:228](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L228) diff --git a/typescript/api-reference/classes/BitcoinTxHash.md b/typescript/api-reference/classes/BitcoinTxHash.md new file mode 100644 index 000000000..47deeb331 --- /dev/null +++ b/typescript/api-reference/classes/BitcoinTxHash.md @@ -0,0 +1,202 @@ +# Class: BitcoinTxHash + +Represents a Bitcoin transaction hash (or transaction ID) as an un-prefixed hex +string. This hash is supposed to have the same byte order as used by the +Bitcoin block explorers which is the opposite of the byte order used +by the Bitcoin protocol internally. That means the hash must be reversed in +the use cases that expect the Bitcoin internal byte order. + +## Hierarchy + +- [`Hex`](Hex.md) + + ↳ **`BitcoinTxHash`** + +## Table of contents + +### Constructors + +- [constructor](BitcoinTxHash.md#constructor) + +### Properties + +- [\_hex](BitcoinTxHash.md#_hex) + +### Methods + +- [equals](BitcoinTxHash.md#equals) +- [reverse](BitcoinTxHash.md#reverse) +- [toBuffer](BitcoinTxHash.md#tobuffer) +- [toPrefixedString](BitcoinTxHash.md#toprefixedstring) +- [toString](BitcoinTxHash.md#tostring) +- [from](BitcoinTxHash.md#from) + +## Constructors + +### constructor + +• **new BitcoinTxHash**(`value`): [`BitcoinTxHash`](BitcoinTxHash.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `value` | `string` \| `Buffer` | + +#### Returns + +[`BitcoinTxHash`](BitcoinTxHash.md) + +#### Inherited from + +[Hex](Hex.md).[constructor](Hex.md#constructor) + +#### Defined in + +[lib/utils/hex.ts:7](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/utils/hex.ts#L7) + +## Properties + +### \_hex + +• `Protected` `Readonly` **\_hex**: `Buffer` + +#### Inherited from + +[Hex](Hex.md).[_hex](Hex.md#_hex) + +#### Defined in + +[lib/utils/hex.ts:5](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/utils/hex.ts#L5) + +## Methods + +### equals + +▸ **equals**(`otherValue`): `boolean` + +Checks if other value equals the current value. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `otherValue` | [`Hex`](Hex.md) | Other value that will be compared to this value. | + +#### Returns + +`boolean` + +True if both values are equal, false otherwise. + +#### Inherited from + +[Hex](Hex.md).[equals](Hex.md#equals) + +#### Defined in + +[lib/utils/hex.ts:57](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/utils/hex.ts#L57) + +___ + +### reverse + +▸ **reverse**(): [`Hex`](Hex.md) + +#### Returns + +[`Hex`](Hex.md) + +Reversed hexadecimal value. + +#### Inherited from + +[Hex](Hex.md).[reverse](Hex.md#reverse) + +#### Defined in + +[lib/utils/hex.ts:64](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/utils/hex.ts#L64) + +___ + +### toBuffer + +▸ **toBuffer**(): `Buffer` + +#### Returns + +`Buffer` + +Hexadecimal value as a Buffer. + +#### Inherited from + +[Hex](Hex.md).[toBuffer](Hex.md#tobuffer) + +#### Defined in + +[lib/utils/hex.ts:32](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/utils/hex.ts#L32) + +___ + +### toPrefixedString + +▸ **toPrefixedString**(): `string` + +#### Returns + +`string` + +Hexadecimal string prefixed with '0x'. + +#### Inherited from + +[Hex](Hex.md).[toPrefixedString](Hex.md#toprefixedstring) + +#### Defined in + +[lib/utils/hex.ts:46](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/utils/hex.ts#L46) + +___ + +### toString + +▸ **toString**(): `string` + +#### Returns + +`string` + +Unprefixed hexadecimal string. + +#### Inherited from + +[Hex](Hex.md).[toString](Hex.md#tostring) + +#### Defined in + +[lib/utils/hex.ts:39](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/utils/hex.ts#L39) + +___ + +### from + +▸ **from**(`value`): [`Hex`](Hex.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `value` | `string` \| `Buffer` | + +#### Returns + +[`Hex`](Hex.md) + +#### Inherited from + +[Hex](Hex.md).[from](Hex.md#from) + +#### Defined in + +[lib/utils/hex.ts:25](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/utils/hex.ts#L25) diff --git a/typescript/api-reference/classes/Deposit.md b/typescript/api-reference/classes/Deposit.md new file mode 100644 index 000000000..522fa783b --- /dev/null +++ b/typescript/api-reference/classes/Deposit.md @@ -0,0 +1,215 @@ +# Class: Deposit + +Component representing an instance of the tBTC v2 deposit process. +Depositing is a complex process spanning both the Bitcoin and the target chain. +This component tries to abstract away that complexity. + +## Table of contents + +### Constructors + +- [constructor](Deposit.md#constructor) + +### Properties + +- [bitcoinClient](Deposit.md#bitcoinclient) +- [bitcoinNetwork](Deposit.md#bitcoinnetwork) +- [script](Deposit.md#script) +- [tbtcContracts](Deposit.md#tbtccontracts) + +### Methods + +- [detectFunding](Deposit.md#detectfunding) +- [getBitcoinAddress](Deposit.md#getbitcoinaddress) +- [getReceipt](Deposit.md#getreceipt) +- [initiateMinting](Deposit.md#initiateminting) +- [fromReceipt](Deposit.md#fromreceipt) + +## Constructors + +### constructor + +• **new Deposit**(`receipt`, `tbtcContracts`, `bitcoinClient`, `bitcoinNetwork`): [`Deposit`](Deposit.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `receipt` | [`DepositReceipt`](../interfaces/DepositReceipt.md) | +| `tbtcContracts` | [`TBTCContracts`](../README.md#tbtccontracts) | +| `bitcoinClient` | [`BitcoinClient`](../interfaces/BitcoinClient.md) | +| `bitcoinNetwork` | [`BitcoinNetwork`](../enums/BitcoinNetwork-1.md) | + +#### Returns + +[`Deposit`](Deposit.md) + +#### Defined in + +[services/deposits/deposit.ts:42](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposit.ts#L42) + +## Properties + +### bitcoinClient + +• `Private` `Readonly` **bitcoinClient**: [`BitcoinClient`](../interfaces/BitcoinClient.md) + +Bitcoin client handle. + +#### Defined in + +[services/deposits/deposit.ts:35](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposit.ts#L35) + +___ + +### bitcoinNetwork + +• `Readonly` **bitcoinNetwork**: [`BitcoinNetwork`](../enums/BitcoinNetwork-1.md) + +Bitcoin network the deposit is relevant for. Has an impact on the +generated deposit address. + +#### Defined in + +[services/deposits/deposit.ts:40](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposit.ts#L40) + +___ + +### script + +• `Private` `Readonly` **script**: [`DepositScript`](DepositScript.md) + +Bitcoin script corresponding to this deposit. + +#### Defined in + +[services/deposits/deposit.ts:27](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposit.ts#L27) + +___ + +### tbtcContracts + +• `Private` `Readonly` **tbtcContracts**: [`TBTCContracts`](../README.md#tbtccontracts) + +Handle to tBTC contracts. + +#### Defined in + +[services/deposits/deposit.ts:31](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposit.ts#L31) + +## Methods + +### detectFunding + +▸ **detectFunding**(): `Promise`\<[`BitcoinUtxo`](../README.md#bitcoinutxo)[]\> + +Detects Bitcoin funding transactions transferring BTC to this deposit. + +#### Returns + +`Promise`\<[`BitcoinUtxo`](../README.md#bitcoinutxo)[]\> + +Specific UTXOs targeting this deposit. Empty array in case + there are no UTXOs referring this deposit. + +#### Defined in + +[services/deposits/deposit.ts:84](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposit.ts#L84) + +___ + +### getBitcoinAddress + +▸ **getBitcoinAddress**(): `Promise`\<`string`\> + +#### Returns + +`Promise`\<`string`\> + +Bitcoin address corresponding to this deposit. + +#### Defined in + +[services/deposits/deposit.ts:74](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposit.ts#L74) + +___ + +### getReceipt + +▸ **getReceipt**(): [`DepositReceipt`](../interfaces/DepositReceipt.md) + +#### Returns + +[`DepositReceipt`](../interfaces/DepositReceipt.md) + +Receipt corresponding to this deposit. + +#### Defined in + +[services/deposits/deposit.ts:67](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposit.ts#L67) + +___ + +### initiateMinting + +▸ **initiateMinting**(`fundingOutpoint?`): `Promise`\<[`Hex`](Hex.md)\> + +Initiates minting of the TBTC token, based on the Bitcoin funding +transaction outpoint targeting this deposit. By default, it detects and +uses the outpoint of the recent Bitcoin funding transaction and throws if +such a transaction does not exist. This behavior can be changed by pointing +a funding transaction explicitly, using the fundingOutpoint parameter. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `fundingOutpoint?` | [`BitcoinTxOutpoint`](../interfaces/BitcoinTxOutpoint.md) | Optional parameter. Can be used to point the funding transaction's outpoint manually. | + +#### Returns + +`Promise`\<[`Hex`](Hex.md)\> + +Target chain hash of the initiate minting transaction. + +**`Throws`** + +Throws an error if there are no funding transactions while using + the default funding detection mode. + +**`Throws`** + +Throws an error if the provided funding outpoint does not + actually refer to this deposit while using the manual funding + provision mode. + +**`Throws`** + +Throws an error if the funding outpoint was already used to + initiate minting (both modes). + +#### Defined in + +[services/deposits/deposit.ts:114](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposit.ts#L114) + +___ + +### fromReceipt + +▸ **fromReceipt**(`receipt`, `tbtcContracts`, `bitcoinClient`): `Promise`\<[`Deposit`](Deposit.md)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `receipt` | [`DepositReceipt`](../interfaces/DepositReceipt.md) | +| `tbtcContracts` | [`TBTCContracts`](../README.md#tbtccontracts) | +| `bitcoinClient` | [`BitcoinClient`](../interfaces/BitcoinClient.md) | + +#### Returns + +`Promise`\<[`Deposit`](Deposit.md)\> + +#### Defined in + +[services/deposits/deposit.ts:54](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposit.ts#L54) diff --git a/typescript/api-reference/classes/DepositFunding.md b/typescript/api-reference/classes/DepositFunding.md new file mode 100644 index 000000000..7bf298e41 --- /dev/null +++ b/typescript/api-reference/classes/DepositFunding.md @@ -0,0 +1,174 @@ +# Class: DepositFunding + +Component allowing to craft and submit the Bitcoin funding transaction using +the given tBTC v2 deposit script. + + THIS IS EXPERIMENTAL CODE THAT CAN BE CHANGED OR REMOVED + IN FUTURE RELEASES. IT SHOULD BE USED ONLY FOR INTERNAL + PURPOSES AND EXTERNAL APPLICATIONS SHOULD NOT DEPEND ON IT. + +## Table of contents + +### Constructors + +- [constructor](DepositFunding.md#constructor) + +### Properties + +- [script](DepositFunding.md#script) + +### Methods + +- [assembleTransaction](DepositFunding.md#assembletransaction) +- [submitTransaction](DepositFunding.md#submittransaction) +- [fromScript](DepositFunding.md#fromscript) + +## Constructors + +### constructor + +• **new DepositFunding**(`script`): [`DepositFunding`](DepositFunding.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `script` | [`DepositScript`](DepositScript.md) | + +#### Returns + +[`DepositFunding`](DepositFunding.md) + +#### Defined in + +[services/deposits/funding.ts:30](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/funding.ts#L30) + +## Properties + +### script + +• `Readonly` **script**: [`DepositScript`](DepositScript.md) + +#### Defined in + +[services/deposits/funding.ts:28](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/funding.ts#L28) + +## Methods + +### assembleTransaction + +▸ **assembleTransaction**(`bitcoinNetwork`, `amount`, `inputUtxos`, `fee`, `depositorPrivateKey`): `Promise`\<\{ `depositUtxo`: [`BitcoinUtxo`](../README.md#bitcoinutxo) ; `rawTransaction`: [`BitcoinRawTx`](../interfaces/BitcoinRawTx.md) ; `transactionHash`: [`BitcoinTxHash`](BitcoinTxHash.md) }\> + +Assembles and signs the Bitcoin P2(W)SH funding transaction using +the underlying deposit script. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `bitcoinNetwork` | [`BitcoinNetwork`](../enums/BitcoinNetwork-1.md) | The target Bitcoin network. | +| `amount` | `BigNumber` | Deposit amount in satoshis. | +| `inputUtxos` | [`BitcoinTxOutpoint`](../interfaces/BitcoinTxOutpoint.md) & \{ `value`: `BigNumber` } & [`BitcoinRawTx`](../interfaces/BitcoinRawTx.md)[] | UTXOs to be used for funding the deposit transaction. So far only P2WPKH UTXO inputs are supported. | +| `fee` | `BigNumber` | Transaction fee to be subtracted from the sum of the UTXOs' values. | +| `depositorPrivateKey` | `string` | Bitcoin private key of the depositor. Must be able to unlock input UTXOs. | + +#### Returns + +`Promise`\<\{ `depositUtxo`: [`BitcoinUtxo`](../README.md#bitcoinutxo) ; `rawTransaction`: [`BitcoinRawTx`](../interfaces/BitcoinRawTx.md) ; `transactionHash`: [`BitcoinTxHash`](BitcoinTxHash.md) }\> + +The outcome consisting of: + - the deposit transaction hash, + - the deposit UTXO produced by this transaction. + - the deposit transaction in the raw format + +**`Dev`** + +It is up to the caller to ensure that input UTXOs are valid and + can be unlocked using the depositor's private key. It is also + caller's responsibility to ensure the given deposit is funded exactly + once. + +**`Dev`** + +UTXOs are selected for transaction funding based on their types. UTXOs + with unsupported types are skipped. The selection process stops once + the sum of the chosen UTXOs meets the required funding amount. + +**`Throws`** + +When the sum of the selected UTXOs is insufficient to cover + the deposit amount and transaction fee. + +#### Defined in + +[services/deposits/funding.ts:62](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/funding.ts#L62) + +___ + +### submitTransaction + +▸ **submitTransaction**(`amount`, `inputUtxos`, `fee`, `depositorPrivateKey`, `bitcoinClient`): `Promise`\<\{ `depositUtxo`: [`BitcoinUtxo`](../README.md#bitcoinutxo) ; `transactionHash`: [`BitcoinTxHash`](BitcoinTxHash.md) }\> + +Assembles, signs and submits the Bitcoin P2(W)SH funding transaction +using the underlying deposit script. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `amount` | `BigNumber` | Deposit amount in satoshis. | +| `inputUtxos` | [`BitcoinUtxo`](../README.md#bitcoinutxo)[] | UTXOs to be used for funding the deposit transaction. So far only P2WPKH UTXO inputs are supported. | +| `fee` | `BigNumber` | The value that should be subtracted from the sum of the UTXOs values and used as the transaction fee. | +| `depositorPrivateKey` | `string` | Bitcoin private key of the depositor. | +| `bitcoinClient` | [`BitcoinClient`](../interfaces/BitcoinClient.md) | Bitcoin client used to interact with the network. | + +#### Returns + +`Promise`\<\{ `depositUtxo`: [`BitcoinUtxo`](../README.md#bitcoinutxo) ; `transactionHash`: [`BitcoinTxHash`](BitcoinTxHash.md) }\> + +The outcome consisting of: + - the deposit transaction hash, + - the deposit UTXO produced by this transaction. + +**`Dev`** + +It is up to the caller to ensure that depositor's private key controls + some UTXOs that can be used as input. It is also caller's responsibility + to ensure the given deposit is funded exactly once. + +**`Dev`** + +UTXOs are selected for transaction funding based on their types. UTXOs + with unsupported types are skipped. The selection process stops once + the sum of the chosen UTXOs meets the required funding amount. + Be aware that the function will attempt to broadcast the transaction, + although successful broadcast is not guaranteed. + +**`Throws`** + +When the sum of the selected UTXOs is insufficient to cover + the deposit amount and transaction fee. + +#### Defined in + +[services/deposits/funding.ts:181](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/funding.ts#L181) + +___ + +### fromScript + +▸ **fromScript**(`script`): [`DepositFunding`](DepositFunding.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `script` | [`DepositScript`](DepositScript.md) | + +#### Returns + +[`DepositFunding`](DepositFunding.md) + +#### Defined in + +[services/deposits/funding.ts:34](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/funding.ts#L34) diff --git a/typescript/api-reference/classes/DepositRefund.md b/typescript/api-reference/classes/DepositRefund.md new file mode 100644 index 000000000..1bc726de0 --- /dev/null +++ b/typescript/api-reference/classes/DepositRefund.md @@ -0,0 +1,226 @@ +# Class: DepositRefund + +Component allowing to craft and submit the Bitcoin refund transaction using +the given tBTC v2 deposit script. + + THIS IS EXPERIMENTAL CODE THAT CAN BE CHANGED OR REMOVED + IN FUTURE RELEASES. IT SHOULD BE USED ONLY FOR INTERNAL + PURPOSES AND EXTERNAL APPLICATIONS SHOULD NOT DEPEND ON IT. + +## Table of contents + +### Constructors + +- [constructor](DepositRefund.md#constructor) + +### Properties + +- [script](DepositRefund.md#script) + +### Methods + +- [assembleTransaction](DepositRefund.md#assembletransaction) +- [prepareDepositScript](DepositRefund.md#preparedepositscript) +- [signP2SHDepositInput](DepositRefund.md#signp2shdepositinput) +- [signP2WSHDepositInput](DepositRefund.md#signp2wshdepositinput) +- [submitTransaction](DepositRefund.md#submittransaction) +- [fromScript](DepositRefund.md#fromscript) + +## Constructors + +### constructor + +• **new DepositRefund**(`script`): [`DepositRefund`](DepositRefund.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `script` | [`DepositScript`](DepositScript.md) | + +#### Returns + +[`DepositRefund`](DepositRefund.md) + +#### Defined in + +[services/deposits/refund.ts:37](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/refund.ts#L37) + +## Properties + +### script + +• `Readonly` **script**: [`DepositScript`](DepositScript.md) + +#### Defined in + +[services/deposits/refund.ts:35](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/refund.ts#L35) + +## Methods + +### assembleTransaction + +▸ **assembleTransaction**(`bitcoinNetwork`, `fee`, `utxo`, `refunderAddress`, `refunderPrivateKey`): `Promise`\<\{ `rawTransaction`: [`BitcoinRawTx`](../interfaces/BitcoinRawTx.md) ; `transactionHash`: [`BitcoinTxHash`](BitcoinTxHash.md) }\> + +Assembles a Bitcoin P2(W)PKH deposit refund transaction. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `bitcoinNetwork` | [`BitcoinNetwork`](../enums/BitcoinNetwork-1.md) | The target Bitcoin network. | +| `fee` | `BigNumber` | the value that will be subtracted from the deposit UTXO being refunded and used as the transaction fee. | +| `utxo` | [`BitcoinTxOutpoint`](../interfaces/BitcoinTxOutpoint.md) & \{ `value`: `BigNumber` } & [`BitcoinRawTx`](../interfaces/BitcoinRawTx.md) | UTXO that was created during depositing that needs be refunded. | +| `refunderAddress` | `string` | Recipient Bitcoin wallet address of the refunded deposit. | +| `refunderPrivateKey` | `string` | Bitcoin wallet private key of the refunder. It must correspond to the `refundPublicKeyHash` of the deposit script. | + +#### Returns + +`Promise`\<\{ `rawTransaction`: [`BitcoinRawTx`](../interfaces/BitcoinRawTx.md) ; `transactionHash`: [`BitcoinTxHash`](BitcoinTxHash.md) }\> + +The outcome consisting of: + - the deposit refund transaction hash, + - the refund transaction in the raw format. + +#### Defined in + +[services/deposits/refund.ts:111](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/refund.ts#L111) + +___ + +### prepareDepositScript + +▸ **prepareDepositScript**(`refunderKeyPair`): `Promise`\<`Buffer`\> + +Assembles the deposit script based on the given deposit details. Performs +validations on values and key formats. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `refunderKeyPair` | `Signer` | Signer object containing the refunder's key pair. | + +#### Returns + +`Promise`\<`Buffer`\> + +A Promise resolving to the assembled deposit script as a Buffer. + +**`Throws`** + +Error if there are discrepancies in values or key formats. + +#### Defined in + +[services/deposits/refund.ts:191](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/refund.ts#L191) + +___ + +### signP2SHDepositInput + +▸ **signP2SHDepositInput**(`transaction`, `inputIndex`, `refunderKeyPair`): `Promise`\<`void`\> + +Signs a P2SH deposit transaction input and sets the `scriptSig`. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `transaction` | `Transaction` | The transaction containing the input to be signed. | +| `inputIndex` | `number` | Index pointing to the input within the transaction. | +| `refunderKeyPair` | `Signer` | A Signer object with the refunder's public and private key pair. | + +#### Returns + +`Promise`\<`void`\> + +An empty promise upon successful signing. + +#### Defined in + +[services/deposits/refund.ts:219](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/refund.ts#L219) + +___ + +### signP2WSHDepositInput + +▸ **signP2WSHDepositInput**(`transaction`, `inputIndex`, `previousOutputValue`, `refunderKeyPair`): `Promise`\<`void`\> + +Signs a P2WSH deposit transaction input and sets the witness script. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `transaction` | `Transaction` | The transaction containing the input to be signed. | +| `inputIndex` | `number` | Index pointing to the input within the transaction. | +| `previousOutputValue` | `number` | The value from the previous transaction output. | +| `refunderKeyPair` | `Signer` | A Signer object with the refunder's public and private key pair. | + +#### Returns + +`Promise`\<`void`\> + +An empty promise upon successful signing. + +#### Defined in + +[services/deposits/refund.ts:256](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/refund.ts#L256) + +___ + +### submitTransaction + +▸ **submitTransaction**(`bitcoinClient`, `fee`, `utxo`, `refunderAddress`, `refunderPrivateKey`): `Promise`\<\{ `transactionHash`: [`BitcoinTxHash`](BitcoinTxHash.md) }\> + +Submits a deposit refund by creating and broadcasting a Bitcoin P2(W)PKH +deposit refund transaction. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `bitcoinClient` | [`BitcoinClient`](../interfaces/BitcoinClient.md) | Bitcoin client used to interact with the network. | +| `fee` | `BigNumber` | the value that will be subtracted from the deposit UTXO being refunded and used as the transaction fee. | +| `utxo` | [`BitcoinUtxo`](../README.md#bitcoinutxo) | UTXO that was created during depositing that needs be refunded. | +| `refunderAddress` | `string` | Recipient Bitcoin wallet address of the refunded deposit. | +| `refunderPrivateKey` | `string` | Bitcoin wallet private key of the refunder. It must correspond to the `refundPublicKeyHash` of the deposit script. | + +#### Returns + +`Promise`\<\{ `transactionHash`: [`BitcoinTxHash`](BitcoinTxHash.md) }\> + +The outcome is the deposit refund transaction hash. + +**`Dev`** + +This function should be called by the refunder after `refundLocktime` + passes plus 1 hour. The additional hour of waiting is the result of + adopting BIP113 which compares the transaction's locktime against the + median timestamp of the last 11 blocks. This median time lags + the current unix time by about 1 hour. + +#### Defined in + +[services/deposits/refund.ts:63](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/refund.ts#L63) + +___ + +### fromScript + +▸ **fromScript**(`script`): [`DepositRefund`](DepositRefund.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `script` | [`DepositScript`](DepositScript.md) | + +#### Returns + +[`DepositRefund`](DepositRefund.md) + +#### Defined in + +[services/deposits/refund.ts:41](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/refund.ts#L41) diff --git a/typescript/api-reference/classes/DepositScript.md b/typescript/api-reference/classes/DepositScript.md new file mode 100644 index 000000000..3e70aa76d --- /dev/null +++ b/typescript/api-reference/classes/DepositScript.md @@ -0,0 +1,149 @@ +# Class: DepositScript + +Represents a Bitcoin script corresponding to a tBTC v2 deposit. +On a high-level, the script is used to derive the Bitcoin address that is +used to fund the deposit with BTC. On a low-level, the script is used to +produce a properly locked funding transaction output that can be unlocked +by the target wallet during the deposit sweep process. + +## Table of contents + +### Constructors + +- [constructor](DepositScript.md#constructor) + +### Properties + +- [receipt](DepositScript.md#receipt) +- [witness](DepositScript.md#witness) + +### Methods + +- [deriveAddress](DepositScript.md#deriveaddress) +- [getHash](DepositScript.md#gethash) +- [getPlainText](DepositScript.md#getplaintext) +- [fromReceipt](DepositScript.md#fromreceipt) + +## Constructors + +### constructor + +• **new DepositScript**(`receipt`, `witness`): [`DepositScript`](DepositScript.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `receipt` | [`DepositReceipt`](../interfaces/DepositReceipt.md) | +| `witness` | `boolean` | + +#### Returns + +[`DepositScript`](DepositScript.md) + +#### Defined in + +[services/deposits/deposit.ts:166](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposit.ts#L166) + +## Properties + +### receipt + +• `Readonly` **receipt**: [`DepositReceipt`](../interfaces/DepositReceipt.md) + +Deposit receipt holding the most important information about the deposit +and allowing to build a unique deposit script (and address) on Bitcoin chain. + +#### Defined in + +[services/deposits/deposit.ts:159](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposit.ts#L159) + +___ + +### witness + +• `Readonly` **witness**: `boolean` + +Flag indicating whether the generated Bitcoin deposit script (and address) +should be a witness P2WSH one. If false, legacy P2SH will be used instead. + +#### Defined in + +[services/deposits/deposit.ts:164](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposit.ts#L164) + +## Methods + +### deriveAddress + +▸ **deriveAddress**(`bitcoinNetwork`): `Promise`\<`string`\> + +Derives a Bitcoin address for the given network for this deposit script. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `bitcoinNetwork` | [`BitcoinNetwork`](../enums/BitcoinNetwork-1.md) | Bitcoin network the address should be derived for. | + +#### Returns + +`Promise`\<`string`\> + +Bitcoin address corresponding to this deposit script. + +#### Defined in + +[services/deposits/deposit.ts:228](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposit.ts#L228) + +___ + +### getHash + +▸ **getHash**(): `Promise`\<`Buffer`\> + +#### Returns + +`Promise`\<`Buffer`\> + +Hashed deposit script as Buffer. + +#### Defined in + +[services/deposits/deposit.ts:183](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposit.ts#L183) + +___ + +### getPlainText + +▸ **getPlainText**(): `Promise`\<[`Hex`](Hex.md)\> + +#### Returns + +`Promise`\<[`Hex`](Hex.md)\> + +Plain-text deposit script as a hex string. + +#### Defined in + +[services/deposits/deposit.ts:195](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposit.ts#L195) + +___ + +### fromReceipt + +▸ **fromReceipt**(`receipt`, `witness?`): [`DepositScript`](DepositScript.md) + +#### Parameters + +| Name | Type | Default value | +| :------ | :------ | :------ | +| `receipt` | [`DepositReceipt`](../interfaces/DepositReceipt.md) | `undefined` | +| `witness` | `boolean` | `true` | + +#### Returns + +[`DepositScript`](DepositScript.md) + +#### Defined in + +[services/deposits/deposit.ts:173](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposit.ts#L173) diff --git a/typescript/api-reference/classes/DepositsService.md b/typescript/api-reference/classes/DepositsService.md new file mode 100644 index 000000000..cd237c9ab --- /dev/null +++ b/typescript/api-reference/classes/DepositsService.md @@ -0,0 +1,173 @@ +# Class: DepositsService + +Service exposing features related to tBTC v2 deposits. + +## Table of contents + +### Constructors + +- [constructor](DepositsService.md#constructor) + +### Properties + +- [bitcoinClient](DepositsService.md#bitcoinclient) +- [defaultDepositor](DepositsService.md#defaultdepositor) +- [depositRefundLocktimeDuration](DepositsService.md#depositrefundlocktimeduration) +- [tbtcContracts](DepositsService.md#tbtccontracts) + +### Methods + +- [generateDepositReceipt](DepositsService.md#generatedepositreceipt) +- [initiateDeposit](DepositsService.md#initiatedeposit) +- [setDefaultDepositor](DepositsService.md#setdefaultdepositor) + +## Constructors + +### constructor + +• **new DepositsService**(`tbtcContracts`, `bitcoinClient`): [`DepositsService`](DepositsService.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `tbtcContracts` | [`TBTCContracts`](../README.md#tbtccontracts) | +| `bitcoinClient` | [`BitcoinClient`](../interfaces/BitcoinClient.md) | + +#### Returns + +[`DepositsService`](DepositsService.md) + +#### Defined in + +[services/deposits/deposits-service.ts:40](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposits-service.ts#L40) + +## Properties + +### bitcoinClient + +• `Private` `Readonly` **bitcoinClient**: [`BitcoinClient`](../interfaces/BitcoinClient.md) + +Bitcoin client handle. + +#### Defined in + +[services/deposits/deposits-service.ts:33](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposits-service.ts#L33) + +___ + +### defaultDepositor + +• `Private` **defaultDepositor**: `undefined` \| [`ChainIdentifier`](../interfaces/ChainIdentifier.md) + +Chain-specific identifier of the default depositor used for deposits +initiated by this service. + +#### Defined in + +[services/deposits/deposits-service.ts:38](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposits-service.ts#L38) + +___ + +### depositRefundLocktimeDuration + +• `Private` `Readonly` **depositRefundLocktimeDuration**: ``23328000`` + +Deposit refund locktime duration in seconds. +This is 9 month in seconds assuming 1 month = 30 days + +#### Defined in + +[services/deposits/deposits-service.ts:25](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposits-service.ts#L25) + +___ + +### tbtcContracts + +• `Private` `Readonly` **tbtcContracts**: [`TBTCContracts`](../README.md#tbtccontracts) + +Handle to tBTC contracts. + +#### Defined in + +[services/deposits/deposits-service.ts:29](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposits-service.ts#L29) + +## Methods + +### generateDepositReceipt + +▸ **generateDepositReceipt**(`bitcoinRecoveryAddress`): `Promise`\<[`DepositReceipt`](../interfaces/DepositReceipt.md)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `bitcoinRecoveryAddress` | `string` | + +#### Returns + +`Promise`\<[`DepositReceipt`](../interfaces/DepositReceipt.md)\> + +#### Defined in + +[services/deposits/deposits-service.ts:62](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposits-service.ts#L62) + +___ + +### initiateDeposit + +▸ **initiateDeposit**(`bitcoinRecoveryAddress`): `Promise`\<[`Deposit`](Deposit.md)\> + +Initiates the tBTC v2 deposit process. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `bitcoinRecoveryAddress` | `string` | P2PKH or P2WPKH Bitcoin address that can be used for emergency recovery of the deposited funds. | + +#### Returns + +`Promise`\<[`Deposit`](Deposit.md)\> + +Handle to the initiated deposit process. + +**`Throws`** + +Throws an error if one of the following occurs: + - The default depositor is not set + - There are no active wallet in the Bridge contract + - The Bitcoin recovery address is not a valid P2(W)PKH + +#### Defined in + +[services/deposits/deposits-service.ts:57](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposits-service.ts#L57) + +___ + +### setDefaultDepositor + +▸ **setDefaultDepositor**(`defaultDepositor`): `void` + +Sets the default depositor used for deposits initiated by this service. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `defaultDepositor` | [`ChainIdentifier`](../interfaces/ChainIdentifier.md) | Chain-specific identifier of the default depositor. | + +#### Returns + +`void` + +**`Dev`** + +Typically, there is no need to use this method when DepositsService + is orchestrated automatically. However, there are some use cases + where setting the default depositor explicitly may be useful. + Make sure you know what you are doing while using this method. + +#### Defined in + +[services/deposits/deposits-service.ts:125](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/deposits/deposits-service.ts#L125) diff --git a/typescript/api-reference/classes/ElectrumClient.md b/typescript/api-reference/classes/ElectrumClient.md new file mode 100644 index 000000000..bef3ba335 --- /dev/null +++ b/typescript/api-reference/classes/ElectrumClient.md @@ -0,0 +1,523 @@ +# Class: ElectrumClient + +Electrum-based implementation of the Bitcoin client. + +## Implements + +- [`BitcoinClient`](../interfaces/BitcoinClient.md) + +## Table of contents + +### Constructors + +- [constructor](ElectrumClient.md#constructor) + +### Properties + +- [connectionTimeout](ElectrumClient.md#connectiontimeout) +- [credentials](ElectrumClient.md#credentials) +- [options](ElectrumClient.md#options) +- [retryBackoffStep](ElectrumClient.md#retrybackoffstep) +- [totalRetryAttempts](ElectrumClient.md#totalretryattempts) + +### Methods + +- [broadcast](ElectrumClient.md#broadcast) +- [findAllUnspentTransactionOutputs](ElectrumClient.md#findallunspenttransactionoutputs) +- [getHeadersChain](ElectrumClient.md#getheaderschain) +- [getNetwork](ElectrumClient.md#getnetwork) +- [getRawTransaction](ElectrumClient.md#getrawtransaction) +- [getTransaction](ElectrumClient.md#gettransaction) +- [getTransactionConfirmations](ElectrumClient.md#gettransactionconfirmations) +- [getTransactionHistory](ElectrumClient.md#gettransactionhistory) +- [getTransactionMerkle](ElectrumClient.md#gettransactionmerkle) +- [getTxHashesForPublicKeyHash](ElectrumClient.md#gettxhashesforpublickeyhash) +- [latestBlockHeight](ElectrumClient.md#latestblockheight) +- [withBackoffRetrier](ElectrumClient.md#withbackoffretrier) +- [withElectrum](ElectrumClient.md#withelectrum) +- [fromDefaultConfig](ElectrumClient.md#fromdefaultconfig) +- [fromUrl](ElectrumClient.md#fromurl) +- [parseElectrumCredentials](ElectrumClient.md#parseelectrumcredentials) + +## Constructors + +### constructor + +• **new ElectrumClient**(`credentials`, `options?`, `totalRetryAttempts?`, `retryBackoffStep?`, `connectionTimeout?`): [`ElectrumClient`](ElectrumClient.md) + +#### Parameters + +| Name | Type | Default value | +| :------ | :------ | :------ | +| `credentials` | [`ElectrumCredentials`](../interfaces/ElectrumCredentials.md)[] | `undefined` | +| `options?` | `object` | `undefined` | +| `totalRetryAttempts` | `number` | `3` | +| `retryBackoffStep` | `number` | `10000` | +| `connectionTimeout` | `number` | `20000` | + +#### Returns + +[`ElectrumClient`](ElectrumClient.md) + +#### Defined in + +[lib/electrum/client.ts:72](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L72) + +## Properties + +### connectionTimeout + +• `Private` **connectionTimeout**: `number` + +#### Defined in + +[lib/electrum/client.ts:70](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L70) + +___ + +### credentials + +• `Private` **credentials**: [`ElectrumCredentials`](../interfaces/ElectrumCredentials.md)[] + +#### Defined in + +[lib/electrum/client.ts:66](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L66) + +___ + +### options + +• `Private` `Optional` **options**: `object` + +#### Defined in + +[lib/electrum/client.ts:67](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L67) + +___ + +### retryBackoffStep + +• `Private` **retryBackoffStep**: `number` + +#### Defined in + +[lib/electrum/client.ts:69](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L69) + +___ + +### totalRetryAttempts + +• `Private` **totalRetryAttempts**: `number` + +#### Defined in + +[lib/electrum/client.ts:68](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L68) + +## Methods + +### broadcast + +▸ **broadcast**(`transaction`): `Promise`\<`void`\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `transaction` | [`BitcoinRawTx`](../interfaces/BitcoinRawTx.md) | + +#### Returns + +`Promise`\<`void`\> + +**`See`** + +#### Implementation of + +[BitcoinClient](../interfaces/BitcoinClient.md).[broadcast](../interfaces/BitcoinClient.md#broadcast) + +#### Defined in + +[lib/electrum/client.ts:632](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L632) + +___ + +### findAllUnspentTransactionOutputs + +▸ **findAllUnspentTransactionOutputs**(`address`): `Promise`\<[`BitcoinUtxo`](../README.md#bitcoinutxo)[]\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `address` | `string` | + +#### Returns + +`Promise`\<[`BitcoinUtxo`](../README.md#bitcoinutxo)[]\> + +**`See`** + +#### Implementation of + +[BitcoinClient](../interfaces/BitcoinClient.md).[findAllUnspentTransactionOutputs](../interfaces/BitcoinClient.md#findallunspenttransactionoutputs) + +#### Defined in + +[lib/electrum/client.ts:260](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L260) + +___ + +### getHeadersChain + +▸ **getHeadersChain**(`blockHeight`, `chainLength`): `Promise`\<[`Hex`](Hex.md)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `blockHeight` | `number` | +| `chainLength` | `number` | + +#### Returns + +`Promise`\<[`Hex`](Hex.md)\> + +**`See`** + +#### Implementation of + +[BitcoinClient](../interfaces/BitcoinClient.md).[getHeadersChain](../interfaces/BitcoinClient.md#getheaderschain) + +#### Defined in + +[lib/electrum/client.ts:582](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L582) + +___ + +### getNetwork + +▸ **getNetwork**(): `Promise`\<[`BitcoinNetwork`](../enums/BitcoinNetwork-1.md)\> + +#### Returns + +`Promise`\<[`BitcoinNetwork`](../enums/BitcoinNetwork-1.md)\> + +**`See`** + +#### Implementation of + +[BitcoinClient](../interfaces/BitcoinClient.md).[getNetwork](../interfaces/BitcoinClient.md#getnetwork) + +#### Defined in + +[lib/electrum/client.ts:238](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L238) + +___ + +### getRawTransaction + +▸ **getRawTransaction**(`transactionHash`): `Promise`\<[`BitcoinRawTx`](../interfaces/BitcoinRawTx.md)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `transactionHash` | [`BitcoinTxHash`](BitcoinTxHash.md) | + +#### Returns + +`Promise`\<[`BitcoinRawTx`](../interfaces/BitcoinRawTx.md)\> + +**`See`** + +#### Implementation of + +[BitcoinClient](../interfaces/BitcoinClient.md).[getRawTransaction](../interfaces/BitcoinClient.md#getrawtransaction) + +#### Defined in + +[lib/electrum/client.ts:395](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L395) + +___ + +### getTransaction + +▸ **getTransaction**(`transactionHash`): `Promise`\<[`BitcoinTx`](../interfaces/BitcoinTx.md)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `transactionHash` | [`BitcoinTxHash`](BitcoinTxHash.md) | + +#### Returns + +`Promise`\<[`BitcoinTx`](../interfaces/BitcoinTx.md)\> + +**`See`** + +#### Implementation of + +[BitcoinClient](../interfaces/BitcoinClient.md).[getTransaction](../interfaces/BitcoinClient.md#gettransaction) + +#### Defined in + +[lib/electrum/client.ts:345](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L345) + +___ + +### getTransactionConfirmations + +▸ **getTransactionConfirmations**(`transactionHash`): `Promise`\<`number`\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `transactionHash` | [`BitcoinTxHash`](BitcoinTxHash.md) | + +#### Returns + +`Promise`\<`number`\> + +**`See`** + +#### Implementation of + +[BitcoinClient](../interfaces/BitcoinClient.md).[getTransactionConfirmations](../interfaces/BitcoinClient.md#gettransactionconfirmations) + +#### Defined in + +[lib/electrum/client.ts:416](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L416) + +___ + +### getTransactionHistory + +▸ **getTransactionHistory**(`address`, `limit?`): `Promise`\<[`BitcoinTx`](../interfaces/BitcoinTx.md)[]\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `address` | `string` | +| `limit?` | `number` | + +#### Returns + +`Promise`\<[`BitcoinTx`](../interfaces/BitcoinTx.md)[]\> + +**`See`** + +#### Implementation of + +[BitcoinClient](../interfaces/BitcoinClient.md).[getTransactionHistory](../interfaces/BitcoinClient.md#gettransactionhistory) + +#### Defined in + +[lib/electrum/client.ts:291](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L291) + +___ + +### getTransactionMerkle + +▸ **getTransactionMerkle**(`transactionHash`, `blockHeight`): `Promise`\<[`BitcoinTxMerkleBranch`](../interfaces/BitcoinTxMerkleBranch.md)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `transactionHash` | [`BitcoinTxHash`](BitcoinTxHash.md) | +| `blockHeight` | `number` | + +#### Returns + +`Promise`\<[`BitcoinTxMerkleBranch`](../interfaces/BitcoinTxMerkleBranch.md)\> + +**`See`** + +#### Implementation of + +[BitcoinClient](../interfaces/BitcoinClient.md).[getTransactionMerkle](../interfaces/BitcoinClient.md#gettransactionmerkle) + +#### Defined in + +[lib/electrum/client.ts:601](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L601) + +___ + +### getTxHashesForPublicKeyHash + +▸ **getTxHashesForPublicKeyHash**(`publicKeyHash`): `Promise`\<[`BitcoinTxHash`](BitcoinTxHash.md)[]\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `publicKeyHash` | [`Hex`](Hex.md) | + +#### Returns + +`Promise`\<[`BitcoinTxHash`](BitcoinTxHash.md)[]\> + +**`See`** + +#### Implementation of + +[BitcoinClient](../interfaces/BitcoinClient.md).[getTxHashesForPublicKeyHash](../interfaces/BitcoinClient.md#gettxhashesforpublickeyhash) + +#### Defined in + +[lib/electrum/client.ts:508](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L508) + +___ + +### latestBlockHeight + +▸ **latestBlockHeight**(): `Promise`\<`number`\> + +#### Returns + +`Promise`\<`number`\> + +**`See`** + +#### Implementation of + +[BitcoinClient](../interfaces/BitcoinClient.md).[latestBlockHeight](../interfaces/BitcoinClient.md#latestblockheight) + +#### Defined in + +[lib/electrum/client.ts:566](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L566) + +___ + +### withBackoffRetrier + +▸ **withBackoffRetrier**\<`T`\>(): [`RetrierFn`](../README.md#retrierfn)\<`T`\> + +Initiates a backoff retrier. + +#### Type parameters + +| Name | +| :------ | +| `T` | + +#### Returns + +[`RetrierFn`](../README.md#retrierfn)\<`T`\> + +A function that can retry any function. + +#### Defined in + +[lib/electrum/client.ts:230](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L230) + +___ + +### withElectrum + +▸ **withElectrum**\<`T`\>(`action`): `Promise`\<`T`\> + +Initiates an Electrum connection and uses it to feed the given action. +Closes the connection regardless of the action outcome. + +#### Type parameters + +| Name | +| :------ | +| `T` | + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `action` | `ElectrumAction`\<`T`\> | Action that makes use of the Electrum connection. | + +#### Returns + +`Promise`\<`T`\> + +Promise holding the outcome. + +#### Defined in + +[lib/electrum/client.ts:168](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L168) + +___ + +### fromDefaultConfig + +▸ **fromDefaultConfig**(`network`): [`ElectrumClient`](ElectrumClient.md) + +Creates an Electrum client instance using a default config for the given +Bitcoin network. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `network` | [`BitcoinNetwork`](../enums/BitcoinNetwork-1.md) | Bitcoin network the instance should be created for. | + +#### Returns + +[`ElectrumClient`](ElectrumClient.md) + +Electrum client instance. + +#### Defined in + +[lib/electrum/client.ts:126](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L126) + +___ + +### fromUrl + +▸ **fromUrl**(`url`, `options?`, `totalRetryAttempts?`, `retryBackoffStep?`, `connectionTimeout?`): [`ElectrumClient`](ElectrumClient.md) + +Creates an Electrum client instance from a URL. + +#### Parameters + +| Name | Type | Default value | Description | +| :------ | :------ | :------ | :------ | +| `url` | `string` \| `string`[] | `undefined` | Connection URL or list of URLs. | +| `options?` | `object` | `undefined` | Additional options used by the Electrum server. | +| `totalRetryAttempts` | `number` | `3` | Number of retries for requests sent to Electrum server. | +| `retryBackoffStep` | `number` | `1000` | Initial backoff step in milliseconds that will be increased exponentially for subsequent retry attempts. | +| `connectionTimeout` | `number` | `20000` | Timeout for a single try of connection establishment. | + +#### Returns + +[`ElectrumClient`](ElectrumClient.md) + +Electrum client instance. + +#### Defined in + +[lib/electrum/client.ts:97](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L97) + +___ + +### parseElectrumCredentials + +▸ **parseElectrumCredentials**(`url`): [`ElectrumCredentials`](../interfaces/ElectrumCredentials.md) + +Create Electrum credentials by parsing an URL. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `url` | `string` | URL to be parsed. | + +#### Returns + +[`ElectrumCredentials`](../interfaces/ElectrumCredentials.md) + +Electrum credentials object. + +#### Defined in + +[lib/electrum/client.ts:147](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L147) diff --git a/typescript/api-reference/classes/EthereumAddress.md b/typescript/api-reference/classes/EthereumAddress.md new file mode 100644 index 000000000..7998fc4a6 --- /dev/null +++ b/typescript/api-reference/classes/EthereumAddress.md @@ -0,0 +1,104 @@ +# Class: EthereumAddress + +Represents an Ethereum address. + +## Implements + +- [`ChainIdentifier`](../interfaces/ChainIdentifier.md) + +## Table of contents + +### Constructors + +- [constructor](EthereumAddress.md#constructor) + +### Properties + +- [identifierHex](EthereumAddress.md#identifierhex) + +### Methods + +- [equals](EthereumAddress.md#equals) +- [from](EthereumAddress.md#from) + +## Constructors + +### constructor + +• **new EthereumAddress**(`address`): [`EthereumAddress`](EthereumAddress.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `address` | `string` | + +#### Returns + +[`EthereumAddress`](EthereumAddress.md) + +#### Defined in + +[lib/ethereum/address.ts:12](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/address.ts#L12) + +## Properties + +### identifierHex + +• `Readonly` **identifierHex**: `string` + +Identifier as an un-prefixed hex string. + +#### Implementation of + +[ChainIdentifier](../interfaces/ChainIdentifier.md).[identifierHex](../interfaces/ChainIdentifier.md#identifierhex) + +#### Defined in + +[lib/ethereum/address.ts:10](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/address.ts#L10) + +## Methods + +### equals + +▸ **equals**(`otherValue`): `boolean` + +Checks if two identifiers are equal. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `otherValue` | [`EthereumAddress`](EthereumAddress.md) | Another identifier | + +#### Returns + +`boolean` + +#### Implementation of + +[ChainIdentifier](../interfaces/ChainIdentifier.md).[equals](../interfaces/ChainIdentifier.md#equals) + +#### Defined in + +[lib/ethereum/address.ts:28](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/address.ts#L28) + +___ + +### from + +▸ **from**(`address`): [`EthereumAddress`](EthereumAddress.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `address` | `string` | + +#### Returns + +[`EthereumAddress`](EthereumAddress.md) + +#### Defined in + +[lib/ethereum/address.ts:24](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/address.ts#L24) diff --git a/typescript/api-reference/classes/EthereumBridge.md b/typescript/api-reference/classes/EthereumBridge.md new file mode 100644 index 000000000..dc55ab59e --- /dev/null +++ b/typescript/api-reference/classes/EthereumBridge.md @@ -0,0 +1,743 @@ +# Class: EthereumBridge + +Implementation of the Ethereum Bridge handle. + +**`See`** + +for reference. + +## Hierarchy + +- `EthersContractHandle`\<`BridgeTypechain`\> + + ↳ **`EthereumBridge`** + +## Implements + +- [`Bridge`](../interfaces/Bridge.md) + +## Table of contents + +### Constructors + +- [constructor](EthereumBridge.md#constructor) + +### Properties + +- [\_deployedAtBlockNumber](EthereumBridge.md#_deployedatblocknumber) +- [\_instance](EthereumBridge.md#_instance) +- [\_totalRetryAttempts](EthereumBridge.md#_totalretryattempts) + +### Methods + +- [activeWalletPublicKey](EthereumBridge.md#activewalletpublickey) +- [buildUtxoHash](EthereumBridge.md#buildutxohash) +- [deposits](EthereumBridge.md#deposits) +- [getAddress](EthereumBridge.md#getaddress) +- [getChainIdentifier](EthereumBridge.md#getchainidentifier) +- [getDepositRevealedEvents](EthereumBridge.md#getdepositrevealedevents) +- [getEvents](EthereumBridge.md#getevents) +- [getNewWalletRegisteredEvents](EthereumBridge.md#getnewwalletregisteredevents) +- [getRedemptionRequestedEvents](EthereumBridge.md#getredemptionrequestedevents) +- [getWalletCompressedPublicKey](EthereumBridge.md#getwalletcompressedpublickey) +- [parseDepositRequest](EthereumBridge.md#parsedepositrequest) +- [parseRedemptionRequest](EthereumBridge.md#parseredemptionrequest) +- [parseWalletDetails](EthereumBridge.md#parsewalletdetails) +- [pendingRedemptions](EthereumBridge.md#pendingredemptions) +- [requestRedemption](EthereumBridge.md#requestredemption) +- [revealDeposit](EthereumBridge.md#revealdeposit) +- [submitDepositSweepProof](EthereumBridge.md#submitdepositsweepproof) +- [submitRedemptionProof](EthereumBridge.md#submitredemptionproof) +- [timedOutRedemptions](EthereumBridge.md#timedoutredemptions) +- [txProofDifficultyFactor](EthereumBridge.md#txproofdifficultyfactor) +- [walletRegistry](EthereumBridge.md#walletregistry) +- [wallets](EthereumBridge.md#wallets) +- [buildDepositKey](EthereumBridge.md#builddepositkey) +- [buildRedemptionKey](EthereumBridge.md#buildredemptionkey) + +## Constructors + +### constructor + +• **new EthereumBridge**(`config`, `deploymentType?`): [`EthereumBridge`](EthereumBridge.md) + +#### Parameters + +| Name | Type | Default value | +| :------ | :------ | :------ | +| `config` | [`EthereumContractConfig`](../interfaces/EthereumContractConfig.md) | `undefined` | +| `deploymentType` | ``"local"`` \| ``"goerli"`` \| ``"mainnet"`` | `"local"` | + +#### Returns + +[`EthereumBridge`](EthereumBridge.md) + +#### Overrides + +EthersContractHandle\<BridgeTypechain\>.constructor + +#### Defined in + +[lib/ethereum/bridge.ts:59](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L59) + +## Properties + +### \_deployedAtBlockNumber + +• `Protected` `Readonly` **\_deployedAtBlockNumber**: `number` + +Number of a block within which the contract was deployed. Value is read from +the contract deployment artifact. It can be overwritten by setting a +[EthersContractConfig.deployedAtBlockNumber](../interfaces/EthereumContractConfig.md#deployedatblocknumber) property. + +#### Inherited from + +EthersContractHandle.\_deployedAtBlockNumber + +#### Defined in + +[lib/ethereum/adapter.ts:80](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L80) + +___ + +### \_instance + +• `Protected` `Readonly` **\_instance**: `Bridge` + +Ethers instance of the deployed contract. + +#### Inherited from + +EthersContractHandle.\_instance + +#### Defined in + +[lib/ethereum/adapter.ts:74](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L74) + +___ + +### \_totalRetryAttempts + +• `Protected` `Readonly` **\_totalRetryAttempts**: `number` + +Number of retries for ethereum requests. + +#### Inherited from + +EthersContractHandle.\_totalRetryAttempts + +#### Defined in + +[lib/ethereum/adapter.ts:84](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L84) + +## Methods + +### activeWalletPublicKey + +▸ **activeWalletPublicKey**(): `Promise`\<`undefined` \| [`Hex`](Hex.md)\> + +#### Returns + +`Promise`\<`undefined` \| [`Hex`](Hex.md)\> + +**`See`** + +#### Implementation of + +[Bridge](../interfaces/Bridge.md).[activeWalletPublicKey](../interfaces/Bridge.md#activewalletpublickey) + +#### Defined in + +[lib/ethereum/bridge.ts:490](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L490) + +___ + +### buildUtxoHash + +▸ **buildUtxoHash**(`utxo`): [`Hex`](Hex.md) + +Builds the UTXO hash based on the UTXO components. UTXO hash is computed as +`keccak256(txHash | txOutputIndex | txOutputValue)`. + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `utxo` | [`BitcoinUtxo`](../README.md#bitcoinutxo) | + +#### Returns + +[`Hex`](Hex.md) + +**`See`** + +#### Implementation of + +[Bridge](../interfaces/Bridge.md).[buildUtxoHash](../interfaces/Bridge.md#buildutxohash) + +#### Defined in + +[lib/ethereum/bridge.ts:614](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L614) + +___ + +### deposits + +▸ **deposits**(`depositTxHash`, `depositOutputIndex`): `Promise`\<[`DepositRequest`](../interfaces/DepositRequest.md)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `depositTxHash` | [`BitcoinTxHash`](BitcoinTxHash.md) | +| `depositOutputIndex` | `number` | + +#### Returns + +`Promise`\<[`DepositRequest`](../interfaces/DepositRequest.md)\> + +**`See`** + +#### Implementation of + +[Bridge](../interfaces/Bridge.md).[deposits](../interfaces/Bridge.md#deposits) + +#### Defined in + +[lib/ethereum/bridge.ts:425](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L425) + +___ + +### getAddress + +▸ **getAddress**(): [`EthereumAddress`](EthereumAddress.md) + +Get address of the contract instance. + +#### Returns + +[`EthereumAddress`](EthereumAddress.md) + +Address of this contract instance. + +#### Inherited from + +EthersContractHandle.getAddress + +#### Defined in + +[lib/ethereum/adapter.ts:112](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L112) + +___ + +### getChainIdentifier + +▸ **getChainIdentifier**(): [`ChainIdentifier`](../interfaces/ChainIdentifier.md) + +#### Returns + +[`ChainIdentifier`](../interfaces/ChainIdentifier.md) + +**`See`** + +#### Implementation of + +[Bridge](../interfaces/Bridge.md).[getChainIdentifier](../interfaces/Bridge.md#getchainidentifier) + +#### Defined in + +[lib/ethereum/bridge.ts:86](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L86) + +___ + +### getDepositRevealedEvents + +▸ **getDepositRevealedEvents**(`options?`, `...filterArgs`): `Promise`\<[`DepositRevealedEvent`](../README.md#depositrevealedevent)[]\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `options?` | [`Options`](../interfaces/GetChainEvents.Options.md) | +| `...filterArgs` | `unknown`[] | + +#### Returns + +`Promise`\<[`DepositRevealedEvent`](../README.md#depositrevealedevent)[]\> + +**`See`** + +#### Implementation of + +Bridge.getDepositRevealedEvents + +#### Defined in + +[lib/ethereum/bridge.ts:94](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L94) + +___ + +### getEvents + +▸ **getEvents**(`eventName`, `options?`, `...filterArgs`): `Promise`\<`Event`[]\> + +Get events emitted by the Ethereum contract. +It starts searching from provided block number. If the GetEvents.Options#fromBlock +option is missing it looks for a contract's defined property +[_deployedAtBlockNumber](EthereumBridge.md#_deployedatblocknumber). If the property is missing starts searching +from block `0`. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `eventName` | `string` | Name of the event. | +| `options?` | [`Options`](../interfaces/GetChainEvents.Options.md) | Options for events fetching. | +| `...filterArgs` | `unknown`[] | Arguments for events filtering. | + +#### Returns + +`Promise`\<`Event`[]\> + +Array of found events. + +#### Inherited from + +EthersContractHandle.getEvents + +#### Defined in + +[lib/ethereum/adapter.ts:127](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L127) + +___ + +### getNewWalletRegisteredEvents + +▸ **getNewWalletRegisteredEvents**(`options?`, `...filterArgs`): `Promise`\<[`NewWalletRegisteredEvent`](../README.md#newwalletregisteredevent)[]\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `options?` | [`Options`](../interfaces/GetChainEvents.Options.md) | +| `...filterArgs` | `unknown`[] | + +#### Returns + +`Promise`\<[`NewWalletRegisteredEvent`](../README.md#newwalletregisteredevent)[]\> + +**`See`** + +#### Implementation of + +Bridge.getNewWalletRegisteredEvents + +#### Defined in + +[lib/ethereum/bridge.ts:526](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L526) + +___ + +### getRedemptionRequestedEvents + +▸ **getRedemptionRequestedEvents**(`options?`, `...filterArgs`): `Promise`\<[`RedemptionRequestedEvent`](../README.md#redemptionrequestedevent)[]\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `options?` | [`Options`](../interfaces/GetChainEvents.Options.md) | +| `...filterArgs` | `unknown`[] | + +#### Returns + +`Promise`\<[`RedemptionRequestedEvent`](../README.md#redemptionrequestedevent)[]\> + +**`See`** + +#### Implementation of + +Bridge.getRedemptionRequestedEvents + +#### Defined in + +[lib/ethereum/bridge.ts:631](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L631) + +___ + +### getWalletCompressedPublicKey + +▸ **getWalletCompressedPublicKey**(`ecdsaWalletID`): `Promise`\<[`Hex`](Hex.md)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `ecdsaWalletID` | [`Hex`](Hex.md) | + +#### Returns + +`Promise`\<[`Hex`](Hex.md)\> + +#### Defined in + +[lib/ethereum/bridge.ts:511](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L511) + +___ + +### parseDepositRequest + +▸ **parseDepositRequest**(`deposit`): [`DepositRequest`](../interfaces/DepositRequest.md) + +Parses a deposit request using data fetched from the on-chain contract. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `deposit` | `DepositRequestStructOutput` | Data of the deposit request. | + +#### Returns + +[`DepositRequest`](../interfaces/DepositRequest.md) + +Parsed deposit request. + +#### Defined in + +[lib/ethereum/bridge.ts:470](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L470) + +___ + +### parseRedemptionRequest + +▸ **parseRedemptionRequest**(`request`, `redeemerOutputScript`): [`RedemptionRequest`](../interfaces/RedemptionRequest.md) + +Parses a redemption request using data fetched from the on-chain contract. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `request` | `RedemptionRequestStructOutput` | Data of the request. | +| `redeemerOutputScript` | [`Hex`](Hex.md) | The redeemer output script that identifies the pending redemption (along with the wallet public key hash). Must not be prepended with length. | + +#### Returns + +[`RedemptionRequest`](../interfaces/RedemptionRequest.md) + +Parsed redemption request. + +#### Defined in + +[lib/ethereum/bridge.ts:212](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L212) + +___ + +### parseWalletDetails + +▸ **parseWalletDetails**(`wallet`): `Promise`\<[`Wallet`](../interfaces/Wallet.md)\> + +Parses a wallet data using data fetched from the on-chain contract. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `wallet` | `WalletStructOutput` | Data of the wallet. | + +#### Returns + +`Promise`\<[`Wallet`](../interfaces/Wallet.md)\> + +Parsed wallet data. + +#### Defined in + +[lib/ethereum/bridge.ts:585](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L585) + +___ + +### pendingRedemptions + +▸ **pendingRedemptions**(`walletPublicKey`, `redeemerOutputScript`): `Promise`\<[`RedemptionRequest`](../interfaces/RedemptionRequest.md)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `walletPublicKey` | [`Hex`](Hex.md) | +| `redeemerOutputScript` | [`Hex`](Hex.md) | + +#### Returns + +`Promise`\<[`RedemptionRequest`](../interfaces/RedemptionRequest.md)\> + +**`See`** + +#### Implementation of + +[Bridge](../interfaces/Bridge.md).[pendingRedemptions](../interfaces/Bridge.md#pendingredemptions) + +#### Defined in + +[lib/ethereum/bridge.ts:131](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L131) + +___ + +### requestRedemption + +▸ **requestRedemption**(`walletPublicKey`, `mainUtxo`, `redeemerOutputScript`, `amount`): `Promise`\<[`Hex`](Hex.md)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `walletPublicKey` | [`Hex`](Hex.md) | +| `mainUtxo` | [`BitcoinUtxo`](../README.md#bitcoinutxo) | +| `redeemerOutputScript` | [`Hex`](Hex.md) | +| `amount` | `BigNumber` | + +#### Returns + +`Promise`\<[`Hex`](Hex.md)\> + +**`See`** + +#### Implementation of + +[Bridge](../interfaces/Bridge.md).[requestRedemption](../interfaces/Bridge.md#requestredemption) + +#### Defined in + +[lib/ethereum/bridge.ts:332](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L332) + +___ + +### revealDeposit + +▸ **revealDeposit**(`depositTx`, `depositOutputIndex`, `deposit`, `vault?`): `Promise`\<[`Hex`](Hex.md)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `depositTx` | [`BitcoinRawTxVectors`](../interfaces/BitcoinRawTxVectors.md) | +| `depositOutputIndex` | `number` | +| `deposit` | [`DepositReceipt`](../interfaces/DepositReceipt.md) | +| `vault?` | [`ChainIdentifier`](../interfaces/ChainIdentifier.md) | + +#### Returns + +`Promise`\<[`Hex`](Hex.md)\> + +**`See`** + +#### Implementation of + +[Bridge](../interfaces/Bridge.md).[revealDeposit](../interfaces/Bridge.md#revealdeposit) + +#### Defined in + +[lib/ethereum/bridge.ts:230](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L230) + +___ + +### submitDepositSweepProof + +▸ **submitDepositSweepProof**(`sweepTx`, `sweepProof`, `mainUtxo`, `vault?`): `Promise`\<[`Hex`](Hex.md)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `sweepTx` | [`BitcoinRawTxVectors`](../interfaces/BitcoinRawTxVectors.md) | +| `sweepProof` | [`BitcoinSpvProof`](../interfaces/BitcoinSpvProof.md) | +| `mainUtxo` | [`BitcoinUtxo`](../README.md#bitcoinutxo) | +| `vault?` | [`ChainIdentifier`](../interfaces/ChainIdentifier.md) | + +#### Returns + +`Promise`\<[`Hex`](Hex.md)\> + +**`See`** + +#### Implementation of + +[Bridge](../interfaces/Bridge.md).[submitDepositSweepProof](../interfaces/Bridge.md#submitdepositsweepproof) + +#### Defined in + +[lib/ethereum/bridge.ts:268](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L268) + +___ + +### submitRedemptionProof + +▸ **submitRedemptionProof**(`redemptionTx`, `redemptionProof`, `mainUtxo`, `walletPublicKey`): `Promise`\<[`Hex`](Hex.md)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `redemptionTx` | [`BitcoinRawTxVectors`](../interfaces/BitcoinRawTxVectors.md) | +| `redemptionProof` | [`BitcoinSpvProof`](../interfaces/BitcoinSpvProof.md) | +| `mainUtxo` | [`BitcoinUtxo`](../README.md#bitcoinutxo) | +| `walletPublicKey` | [`Hex`](Hex.md) | + +#### Returns + +`Promise`\<[`Hex`](Hex.md)\> + +**`See`** + +#### Implementation of + +[Bridge](../interfaces/Bridge.md).[submitRedemptionProof](../interfaces/Bridge.md#submitredemptionproof) + +#### Defined in + +[lib/ethereum/bridge.ts:376](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L376) + +___ + +### timedOutRedemptions + +▸ **timedOutRedemptions**(`walletPublicKey`, `redeemerOutputScript`): `Promise`\<[`RedemptionRequest`](../interfaces/RedemptionRequest.md)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `walletPublicKey` | [`Hex`](Hex.md) | +| `redeemerOutputScript` | [`Hex`](Hex.md) | + +#### Returns + +`Promise`\<[`RedemptionRequest`](../interfaces/RedemptionRequest.md)\> + +**`See`** + +#### Implementation of + +[Bridge](../interfaces/Bridge.md).[timedOutRedemptions](../interfaces/Bridge.md#timedoutredemptions) + +#### Defined in + +[lib/ethereum/bridge.ts:154](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L154) + +___ + +### txProofDifficultyFactor + +▸ **txProofDifficultyFactor**(): `Promise`\<`number`\> + +#### Returns + +`Promise`\<`number`\> + +**`See`** + +#### Implementation of + +[Bridge](../interfaces/Bridge.md).[txProofDifficultyFactor](../interfaces/Bridge.md#txproofdifficultyfactor) + +#### Defined in + +[lib/ethereum/bridge.ts:318](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L318) + +___ + +### walletRegistry + +▸ **walletRegistry**(): `Promise`\<[`WalletRegistry`](../interfaces/WalletRegistry.md)\> + +#### Returns + +`Promise`\<[`WalletRegistry`](../interfaces/WalletRegistry.md)\> + +**`See`** + +#### Implementation of + +[Bridge](../interfaces/Bridge.md).[walletRegistry](../interfaces/Bridge.md#walletregistry) + +#### Defined in + +[lib/ethereum/bridge.ts:551](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L551) + +___ + +### wallets + +▸ **wallets**(`walletPublicKeyHash`): `Promise`\<[`Wallet`](../interfaces/Wallet.md)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `walletPublicKeyHash` | [`Hex`](Hex.md) | + +#### Returns + +`Promise`\<[`Wallet`](../interfaces/Wallet.md)\> + +**`See`** + +#### Implementation of + +[Bridge](../interfaces/Bridge.md).[wallets](../interfaces/Bridge.md#wallets) + +#### Defined in + +[lib/ethereum/bridge.ts:568](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L568) + +___ + +### buildDepositKey + +▸ **buildDepositKey**(`depositTxHash`, `depositOutputIndex`): `string` + +Builds the deposit key required to refer a revealed deposit. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `depositTxHash` | [`BitcoinTxHash`](BitcoinTxHash.md) | The revealed deposit transaction's hash. | +| `depositOutputIndex` | `number` | Index of the deposit transaction output that funds the revealed deposit. | + +#### Returns + +`string` + +Deposit key. + +#### Defined in + +[lib/ethereum/bridge.ts:451](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L451) + +___ + +### buildRedemptionKey + +▸ **buildRedemptionKey**(`walletPublicKeyHash`, `redeemerOutputScript`): `string` + +Builds a redemption key required to refer a redemption request. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `walletPublicKeyHash` | [`Hex`](Hex.md) | The wallet public key hash that identifies the pending redemption (along with the redeemer output script). | +| `redeemerOutputScript` | [`Hex`](Hex.md) | The redeemer output script that identifies the pending redemption (along with the wallet public key hash). Must not be prepended with length. | + +#### Returns + +`string` + +The redemption key. + +#### Defined in + +[lib/ethereum/bridge.ts:182](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L182) diff --git a/typescript/api-reference/classes/EthereumTBTCToken.md b/typescript/api-reference/classes/EthereumTBTCToken.md new file mode 100644 index 000000000..1c5657ef8 --- /dev/null +++ b/typescript/api-reference/classes/EthereumTBTCToken.md @@ -0,0 +1,299 @@ +# Class: EthereumTBTCToken + +Implementation of the Ethereum TBTC v2 token handle. + +**`See`** + +for reference. + +## Hierarchy + +- `EthersContractHandle`\<`TBTCTypechain`\> + + ↳ **`EthereumTBTCToken`** + +## Implements + +- [`TBTCToken`](../interfaces/TBTCToken.md) + +## Table of contents + +### Constructors + +- [constructor](EthereumTBTCToken.md#constructor) + +### Properties + +- [\_deployedAtBlockNumber](EthereumTBTCToken.md#_deployedatblocknumber) +- [\_instance](EthereumTBTCToken.md#_instance) +- [\_totalRetryAttempts](EthereumTBTCToken.md#_totalretryattempts) + +### Methods + +- [buildBridgeRequestRedemptionData](EthereumTBTCToken.md#buildbridgerequestredemptiondata) +- [buildRequestRedemptionData](EthereumTBTCToken.md#buildrequestredemptiondata) +- [getAddress](EthereumTBTCToken.md#getaddress) +- [getChainIdentifier](EthereumTBTCToken.md#getchainidentifier) +- [getEvents](EthereumTBTCToken.md#getevents) +- [requestRedemption](EthereumTBTCToken.md#requestredemption) +- [totalSupply](EthereumTBTCToken.md#totalsupply) + +## Constructors + +### constructor + +• **new EthereumTBTCToken**(`config`, `deploymentType?`): [`EthereumTBTCToken`](EthereumTBTCToken.md) + +#### Parameters + +| Name | Type | Default value | +| :------ | :------ | :------ | +| `config` | [`EthereumContractConfig`](../interfaces/EthereumContractConfig.md) | `undefined` | +| `deploymentType` | ``"local"`` \| ``"goerli"`` \| ``"mainnet"`` | `"local"` | + +#### Returns + +[`EthereumTBTCToken`](EthereumTBTCToken.md) + +#### Overrides + +EthersContractHandle\<TBTCTypechain\>.constructor + +#### Defined in + +[lib/ethereum/tbtc-token.ts:26](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/tbtc-token.ts#L26) + +## Properties + +### \_deployedAtBlockNumber + +• `Protected` `Readonly` **\_deployedAtBlockNumber**: `number` + +Number of a block within which the contract was deployed. Value is read from +the contract deployment artifact. It can be overwritten by setting a +[EthersContractConfig.deployedAtBlockNumber](../interfaces/EthereumContractConfig.md#deployedatblocknumber) property. + +#### Inherited from + +EthersContractHandle.\_deployedAtBlockNumber + +#### Defined in + +[lib/ethereum/adapter.ts:80](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L80) + +___ + +### \_instance + +• `Protected` `Readonly` **\_instance**: `TBTC` + +Ethers instance of the deployed contract. + +#### Inherited from + +EthersContractHandle.\_instance + +#### Defined in + +[lib/ethereum/adapter.ts:74](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L74) + +___ + +### \_totalRetryAttempts + +• `Protected` `Readonly` **\_totalRetryAttempts**: `number` + +Number of retries for ethereum requests. + +#### Inherited from + +EthersContractHandle.\_totalRetryAttempts + +#### Defined in + +[lib/ethereum/adapter.ts:84](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L84) + +## Methods + +### buildBridgeRequestRedemptionData + +▸ **buildBridgeRequestRedemptionData**(`walletPublicKey`, `mainUtxo`, `redeemerOutputScript`): `Object` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `walletPublicKey` | [`Hex`](Hex.md) | +| `mainUtxo` | [`BitcoinUtxo`](../README.md#bitcoinutxo) | +| `redeemerOutputScript` | [`Hex`](Hex.md) | + +#### Returns + +`Object` + +| Name | Type | +| :------ | :------ | +| `mainUtxo` | \{ `txHash`: `string` ; `txOutputIndex`: `number` = mainUtxo.outputIndex; `txOutputValue`: `BigNumber` = mainUtxo.value } | +| `mainUtxo.txHash` | `string` | +| `mainUtxo.txOutputIndex` | `number` | +| `mainUtxo.txOutputValue` | `BigNumber` | +| `prefixedRawRedeemerOutputScript` | `string` | +| `walletPublicKeyHash` | `string` | + +#### Defined in + +[lib/ethereum/tbtc-token.ts:135](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/tbtc-token.ts#L135) + +___ + +### buildRequestRedemptionData + +▸ **buildRequestRedemptionData**(`redeemer`, `walletPublicKey`, `mainUtxo`, `redeemerOutputScript`): [`Hex`](Hex.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `redeemer` | [`EthereumAddress`](EthereumAddress.md) | +| `walletPublicKey` | [`Hex`](Hex.md) | +| `mainUtxo` | [`BitcoinUtxo`](../README.md#bitcoinutxo) | +| `redeemerOutputScript` | [`Hex`](Hex.md) | + +#### Returns + +[`Hex`](Hex.md) + +#### Defined in + +[lib/ethereum/tbtc-token.ts:104](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/tbtc-token.ts#L104) + +___ + +### getAddress + +▸ **getAddress**(): [`EthereumAddress`](EthereumAddress.md) + +Get address of the contract instance. + +#### Returns + +[`EthereumAddress`](EthereumAddress.md) + +Address of this contract instance. + +#### Inherited from + +EthersContractHandle.getAddress + +#### Defined in + +[lib/ethereum/adapter.ts:112](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L112) + +___ + +### getChainIdentifier + +▸ **getChainIdentifier**(): [`ChainIdentifier`](../interfaces/ChainIdentifier.md) + +#### Returns + +[`ChainIdentifier`](../interfaces/ChainIdentifier.md) + +**`See`** + +#### Implementation of + +[TBTCToken](../interfaces/TBTCToken.md).[getChainIdentifier](../interfaces/TBTCToken.md#getchainidentifier) + +#### Defined in + +[lib/ethereum/tbtc-token.ts:53](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/tbtc-token.ts#L53) + +___ + +### getEvents + +▸ **getEvents**(`eventName`, `options?`, `...filterArgs`): `Promise`\<`Event`[]\> + +Get events emitted by the Ethereum contract. +It starts searching from provided block number. If the GetEvents.Options#fromBlock +option is missing it looks for a contract's defined property +[_deployedAtBlockNumber](EthereumBridge.md#_deployedatblocknumber). If the property is missing starts searching +from block `0`. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `eventName` | `string` | Name of the event. | +| `options?` | [`Options`](../interfaces/GetChainEvents.Options.md) | Options for events fetching. | +| `...filterArgs` | `unknown`[] | Arguments for events filtering. | + +#### Returns + +`Promise`\<`Event`[]\> + +Array of found events. + +#### Inherited from + +EthersContractHandle.getEvents + +#### Defined in + +[lib/ethereum/adapter.ts:127](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L127) + +___ + +### requestRedemption + +▸ **requestRedemption**(`walletPublicKey`, `mainUtxo`, `redeemerOutputScript`, `amount`): `Promise`\<[`Hex`](Hex.md)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `walletPublicKey` | [`Hex`](Hex.md) | +| `mainUtxo` | [`BitcoinUtxo`](../README.md#bitcoinutxo) | +| `redeemerOutputScript` | [`Hex`](Hex.md) | +| `amount` | `BigNumber` | + +#### Returns + +`Promise`\<[`Hex`](Hex.md)\> + +**`See`** + +#### Implementation of + +[TBTCToken](../interfaces/TBTCToken.md).[requestRedemption](../interfaces/TBTCToken.md#requestredemption) + +#### Defined in + +[lib/ethereum/tbtc-token.ts:71](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/tbtc-token.ts#L71) + +___ + +### totalSupply + +▸ **totalSupply**(`blockNumber?`): `Promise`\<`BigNumber`\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `blockNumber?` | `number` | + +#### Returns + +`Promise`\<`BigNumber`\> + +**`See`** + +#### Implementation of + +[TBTCToken](../interfaces/TBTCToken.md).[totalSupply](../interfaces/TBTCToken.md#totalsupply) + +#### Defined in + +[lib/ethereum/tbtc-token.ts:61](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/tbtc-token.ts#L61) diff --git a/typescript/api-reference/classes/EthereumTBTCVault.md b/typescript/api-reference/classes/EthereumTBTCVault.md new file mode 100644 index 000000000..4e3bd636f --- /dev/null +++ b/typescript/api-reference/classes/EthereumTBTCVault.md @@ -0,0 +1,503 @@ +# Class: EthereumTBTCVault + +Implementation of the Ethereum TBTCVault handle. + +**`See`** + +for reference. + +## Hierarchy + +- `EthersContractHandle`\<`TBTCVaultTypechain`\> + + ↳ **`EthereumTBTCVault`** + +## Implements + +- [`TBTCVault`](../interfaces/TBTCVault.md) + +## Table of contents + +### Constructors + +- [constructor](EthereumTBTCVault.md#constructor) + +### Properties + +- [\_deployedAtBlockNumber](EthereumTBTCVault.md#_deployedatblocknumber) +- [\_instance](EthereumTBTCVault.md#_instance) +- [\_totalRetryAttempts](EthereumTBTCVault.md#_totalretryattempts) + +### Methods + +- [cancelOptimisticMint](EthereumTBTCVault.md#canceloptimisticmint) +- [finalizeOptimisticMint](EthereumTBTCVault.md#finalizeoptimisticmint) +- [getAddress](EthereumTBTCVault.md#getaddress) +- [getChainIdentifier](EthereumTBTCVault.md#getchainidentifier) +- [getEvents](EthereumTBTCVault.md#getevents) +- [getMinters](EthereumTBTCVault.md#getminters) +- [getOptimisticMintingCancelledEvents](EthereumTBTCVault.md#getoptimisticmintingcancelledevents) +- [getOptimisticMintingFinalizedEvents](EthereumTBTCVault.md#getoptimisticmintingfinalizedevents) +- [getOptimisticMintingRequestedEvents](EthereumTBTCVault.md#getoptimisticmintingrequestedevents) +- [isGuardian](EthereumTBTCVault.md#isguardian) +- [isMinter](EthereumTBTCVault.md#isminter) +- [optimisticMintingDelay](EthereumTBTCVault.md#optimisticmintingdelay) +- [optimisticMintingRequests](EthereumTBTCVault.md#optimisticmintingrequests) +- [parseOptimisticMintingRequest](EthereumTBTCVault.md#parseoptimisticmintingrequest) +- [requestOptimisticMint](EthereumTBTCVault.md#requestoptimisticmint) + +## Constructors + +### constructor + +• **new EthereumTBTCVault**(`config`, `deploymentType?`): [`EthereumTBTCVault`](EthereumTBTCVault.md) + +#### Parameters + +| Name | Type | Default value | +| :------ | :------ | :------ | +| `config` | [`EthereumContractConfig`](../interfaces/EthereumContractConfig.md) | `undefined` | +| `deploymentType` | ``"local"`` \| ``"goerli"`` \| ``"mainnet"`` | `"local"` | + +#### Returns + +[`EthereumTBTCVault`](EthereumTBTCVault.md) + +#### Overrides + +EthersContractHandle\<TBTCVaultTypechain\>.constructor + +#### Defined in + +[lib/ethereum/tbtc-vault.ts:40](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/tbtc-vault.ts#L40) + +## Properties + +### \_deployedAtBlockNumber + +• `Protected` `Readonly` **\_deployedAtBlockNumber**: `number` + +Number of a block within which the contract was deployed. Value is read from +the contract deployment artifact. It can be overwritten by setting a +[EthersContractConfig.deployedAtBlockNumber](../interfaces/EthereumContractConfig.md#deployedatblocknumber) property. + +#### Inherited from + +EthersContractHandle.\_deployedAtBlockNumber + +#### Defined in + +[lib/ethereum/adapter.ts:80](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L80) + +___ + +### \_instance + +• `Protected` `Readonly` **\_instance**: `TBTCVault` + +Ethers instance of the deployed contract. + +#### Inherited from + +EthersContractHandle.\_instance + +#### Defined in + +[lib/ethereum/adapter.ts:74](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L74) + +___ + +### \_totalRetryAttempts + +• `Protected` `Readonly` **\_totalRetryAttempts**: `number` + +Number of retries for ethereum requests. + +#### Inherited from + +EthersContractHandle.\_totalRetryAttempts + +#### Defined in + +[lib/ethereum/adapter.ts:84](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L84) + +## Methods + +### cancelOptimisticMint + +▸ **cancelOptimisticMint**(`depositTxHash`, `depositOutputIndex`): `Promise`\<[`Hex`](Hex.md)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `depositTxHash` | [`BitcoinTxHash`](BitcoinTxHash.md) | +| `depositOutputIndex` | `number` | + +#### Returns + +`Promise`\<[`Hex`](Hex.md)\> + +**`See`** + +#### Implementation of + +[TBTCVault](../interfaces/TBTCVault.md).[cancelOptimisticMint](../interfaces/TBTCVault.md#canceloptimisticmint) + +#### Defined in + +[lib/ethereum/tbtc-vault.ts:149](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/tbtc-vault.ts#L149) + +___ + +### finalizeOptimisticMint + +▸ **finalizeOptimisticMint**(`depositTxHash`, `depositOutputIndex`): `Promise`\<[`Hex`](Hex.md)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `depositTxHash` | [`BitcoinTxHash`](BitcoinTxHash.md) | +| `depositOutputIndex` | `number` | + +#### Returns + +`Promise`\<[`Hex`](Hex.md)\> + +**`See`** + +#### Implementation of + +[TBTCVault](../interfaces/TBTCVault.md).[finalizeOptimisticMint](../interfaces/TBTCVault.md#finalizeoptimisticmint) + +#### Defined in + +[lib/ethereum/tbtc-vault.ts:172](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/tbtc-vault.ts#L172) + +___ + +### getAddress + +▸ **getAddress**(): [`EthereumAddress`](EthereumAddress.md) + +Get address of the contract instance. + +#### Returns + +[`EthereumAddress`](EthereumAddress.md) + +Address of this contract instance. + +#### Inherited from + +EthersContractHandle.getAddress + +#### Defined in + +[lib/ethereum/adapter.ts:112](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L112) + +___ + +### getChainIdentifier + +▸ **getChainIdentifier**(): [`ChainIdentifier`](../interfaces/ChainIdentifier.md) + +#### Returns + +[`ChainIdentifier`](../interfaces/ChainIdentifier.md) + +**`See`** + +#### Implementation of + +[TBTCVault](../interfaces/TBTCVault.md).[getChainIdentifier](../interfaces/TBTCVault.md#getchainidentifier) + +#### Defined in + +[lib/ethereum/tbtc-vault.ts:67](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/tbtc-vault.ts#L67) + +___ + +### getEvents + +▸ **getEvents**(`eventName`, `options?`, `...filterArgs`): `Promise`\<`Event`[]\> + +Get events emitted by the Ethereum contract. +It starts searching from provided block number. If the GetEvents.Options#fromBlock +option is missing it looks for a contract's defined property +[_deployedAtBlockNumber](EthereumBridge.md#_deployedatblocknumber). If the property is missing starts searching +from block `0`. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `eventName` | `string` | Name of the event. | +| `options?` | [`Options`](../interfaces/GetChainEvents.Options.md) | Options for events fetching. | +| `...filterArgs` | `unknown`[] | Arguments for events filtering. | + +#### Returns + +`Promise`\<`Event`[]\> + +Array of found events. + +#### Inherited from + +EthersContractHandle.getEvents + +#### Defined in + +[lib/ethereum/adapter.ts:127](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L127) + +___ + +### getMinters + +▸ **getMinters**(): `Promise`\<[`EthereumAddress`](EthereumAddress.md)[]\> + +#### Returns + +`Promise`\<[`EthereumAddress`](EthereumAddress.md)[]\> + +**`See`** + +#### Implementation of + +[TBTCVault](../interfaces/TBTCVault.md).[getMinters](../interfaces/TBTCVault.md#getminters) + +#### Defined in + +[lib/ethereum/tbtc-vault.ts:89](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/tbtc-vault.ts#L89) + +___ + +### getOptimisticMintingCancelledEvents + +▸ **getOptimisticMintingCancelledEvents**(`options?`, `...filterArgs`): `Promise`\<[`OptimisticMintingCancelledEvent`](../README.md#optimisticmintingcancelledevent)[]\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `options?` | [`Options`](../interfaces/GetChainEvents.Options.md) | +| `...filterArgs` | `any`[] | + +#### Returns + +`Promise`\<[`OptimisticMintingCancelledEvent`](../README.md#optimisticmintingcancelledevent)[]\> + +**`See`** + +#### Implementation of + +TBTCVault.getOptimisticMintingCancelledEvents + +#### Defined in + +[lib/ethereum/tbtc-vault.ts:267](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/tbtc-vault.ts#L267) + +___ + +### getOptimisticMintingFinalizedEvents + +▸ **getOptimisticMintingFinalizedEvents**(`options?`, `...filterArgs`): `Promise`\<[`OptimisticMintingFinalizedEvent`](../README.md#optimisticmintingfinalizedevent)[]\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `options?` | [`Options`](../interfaces/GetChainEvents.Options.md) | +| `...filterArgs` | `any`[] | + +#### Returns + +`Promise`\<[`OptimisticMintingFinalizedEvent`](../README.md#optimisticmintingfinalizedevent)[]\> + +**`See`** + +#### Implementation of + +TBTCVault.getOptimisticMintingFinalizedEvents + +#### Defined in + +[lib/ethereum/tbtc-vault.ts:294](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/tbtc-vault.ts#L294) + +___ + +### getOptimisticMintingRequestedEvents + +▸ **getOptimisticMintingRequestedEvents**(`options?`, `...filterArgs`): `Promise`\<[`OptimisticMintingRequestedEvent`](../README.md#optimisticmintingrequestedevent)[]\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `options?` | [`Options`](../interfaces/GetChainEvents.Options.md) | +| `...filterArgs` | `any`[] | + +#### Returns + +`Promise`\<[`OptimisticMintingRequestedEvent`](../README.md#optimisticmintingrequestedevent)[]\> + +**`See`** + +#### Implementation of + +TBTCVault.getOptimisticMintingRequestedEvents + +#### Defined in + +[lib/ethereum/tbtc-vault.ts:234](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/tbtc-vault.ts#L234) + +___ + +### isGuardian + +▸ **isGuardian**(`address`): `Promise`\<`boolean`\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `address` | [`EthereumAddress`](EthereumAddress.md) | + +#### Returns + +`Promise`\<`boolean`\> + +**`See`** + +#### Implementation of + +[TBTCVault](../interfaces/TBTCVault.md).[isGuardian](../interfaces/TBTCVault.md#isguardian) + +#### Defined in + +[lib/ethereum/tbtc-vault.ts:113](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/tbtc-vault.ts#L113) + +___ + +### isMinter + +▸ **isMinter**(`address`): `Promise`\<`boolean`\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `address` | [`EthereumAddress`](EthereumAddress.md) | + +#### Returns + +`Promise`\<`boolean`\> + +**`See`** + +#### Implementation of + +[TBTCVault](../interfaces/TBTCVault.md).[isMinter](../interfaces/TBTCVault.md#isminter) + +#### Defined in + +[lib/ethereum/tbtc-vault.ts:103](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/tbtc-vault.ts#L103) + +___ + +### optimisticMintingDelay + +▸ **optimisticMintingDelay**(): `Promise`\<`number`\> + +#### Returns + +`Promise`\<`number`\> + +**`See`** + +#### Implementation of + +[TBTCVault](../interfaces/TBTCVault.md).[optimisticMintingDelay](../interfaces/TBTCVault.md#optimisticmintingdelay) + +#### Defined in + +[lib/ethereum/tbtc-vault.ts:75](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/tbtc-vault.ts#L75) + +___ + +### optimisticMintingRequests + +▸ **optimisticMintingRequests**(`depositTxHash`, `depositOutputIndex`): `Promise`\<[`OptimisticMintingRequest`](../README.md#optimisticmintingrequest)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `depositTxHash` | [`BitcoinTxHash`](BitcoinTxHash.md) | +| `depositOutputIndex` | `number` | + +#### Returns + +`Promise`\<[`OptimisticMintingRequest`](../README.md#optimisticmintingrequest)\> + +**`See`** + +#### Implementation of + +[TBTCVault](../interfaces/TBTCVault.md).[optimisticMintingRequests](../interfaces/TBTCVault.md#optimisticmintingrequests) + +#### Defined in + +[lib/ethereum/tbtc-vault.ts:198](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/tbtc-vault.ts#L198) + +___ + +### parseOptimisticMintingRequest + +▸ **parseOptimisticMintingRequest**(`request`): [`OptimisticMintingRequest`](../README.md#optimisticmintingrequest) + +Parses a optimistic minting request using data fetched from the on-chain contract. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `request` | `ContractOptimisticMintingRequest` | Data of the optimistic minting request. | + +#### Returns + +[`OptimisticMintingRequest`](../README.md#optimisticmintingrequest) + +Parsed optimistic minting request. + +#### Defined in + +[lib/ethereum/tbtc-vault.ts:221](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/tbtc-vault.ts#L221) + +___ + +### requestOptimisticMint + +▸ **requestOptimisticMint**(`depositTxHash`, `depositOutputIndex`): `Promise`\<[`Hex`](Hex.md)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `depositTxHash` | [`BitcoinTxHash`](BitcoinTxHash.md) | +| `depositOutputIndex` | `number` | + +#### Returns + +`Promise`\<[`Hex`](Hex.md)\> + +**`See`** + +#### Implementation of + +[TBTCVault](../interfaces/TBTCVault.md).[requestOptimisticMint](../interfaces/TBTCVault.md#requestoptimisticmint) + +#### Defined in + +[lib/ethereum/tbtc-vault.ts:123](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/tbtc-vault.ts#L123) diff --git a/typescript/api-reference/classes/EthereumWalletRegistry.md b/typescript/api-reference/classes/EthereumWalletRegistry.md new file mode 100644 index 000000000..7cab2bd60 --- /dev/null +++ b/typescript/api-reference/classes/EthereumWalletRegistry.md @@ -0,0 +1,297 @@ +# Class: EthereumWalletRegistry + +Implementation of the Ethereum WalletRegistry handle. + +**`See`** + +for reference. + +## Hierarchy + +- `EthersContractHandle`\<`WalletRegistryTypechain`\> + + ↳ **`EthereumWalletRegistry`** + +## Implements + +- [`WalletRegistry`](../interfaces/WalletRegistry.md) + +## Table of contents + +### Constructors + +- [constructor](EthereumWalletRegistry.md#constructor) + +### Properties + +- [\_deployedAtBlockNumber](EthereumWalletRegistry.md#_deployedatblocknumber) +- [\_instance](EthereumWalletRegistry.md#_instance) +- [\_totalRetryAttempts](EthereumWalletRegistry.md#_totalretryattempts) + +### Methods + +- [getAddress](EthereumWalletRegistry.md#getaddress) +- [getChainIdentifier](EthereumWalletRegistry.md#getchainidentifier) +- [getDkgResultApprovedEvents](EthereumWalletRegistry.md#getdkgresultapprovedevents) +- [getDkgResultChallengedEvents](EthereumWalletRegistry.md#getdkgresultchallengedevents) +- [getDkgResultSubmittedEvents](EthereumWalletRegistry.md#getdkgresultsubmittedevents) +- [getEvents](EthereumWalletRegistry.md#getevents) +- [getWalletPublicKey](EthereumWalletRegistry.md#getwalletpublickey) + +## Constructors + +### constructor + +• **new EthereumWalletRegistry**(`config`, `deploymentType?`): [`EthereumWalletRegistry`](EthereumWalletRegistry.md) + +#### Parameters + +| Name | Type | Default value | +| :------ | :------ | :------ | +| `config` | [`EthereumContractConfig`](../interfaces/EthereumContractConfig.md) | `undefined` | +| `deploymentType` | ``"local"`` \| ``"goerli"`` \| ``"mainnet"`` | `"local"` | + +#### Returns + +[`EthereumWalletRegistry`](EthereumWalletRegistry.md) + +#### Overrides + +EthersContractHandle\<WalletRegistryTypechain\>.constructor + +#### Defined in + +[lib/ethereum/wallet-registry.ts:32](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/wallet-registry.ts#L32) + +## Properties + +### \_deployedAtBlockNumber + +• `Protected` `Readonly` **\_deployedAtBlockNumber**: `number` + +Number of a block within which the contract was deployed. Value is read from +the contract deployment artifact. It can be overwritten by setting a +[EthersContractConfig.deployedAtBlockNumber](../interfaces/EthereumContractConfig.md#deployedatblocknumber) property. + +#### Inherited from + +EthersContractHandle.\_deployedAtBlockNumber + +#### Defined in + +[lib/ethereum/adapter.ts:80](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L80) + +___ + +### \_instance + +• `Protected` `Readonly` **\_instance**: `WalletRegistry` + +Ethers instance of the deployed contract. + +#### Inherited from + +EthersContractHandle.\_instance + +#### Defined in + +[lib/ethereum/adapter.ts:74](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L74) + +___ + +### \_totalRetryAttempts + +• `Protected` `Readonly` **\_totalRetryAttempts**: `number` + +Number of retries for ethereum requests. + +#### Inherited from + +EthersContractHandle.\_totalRetryAttempts + +#### Defined in + +[lib/ethereum/adapter.ts:84](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L84) + +## Methods + +### getAddress + +▸ **getAddress**(): [`EthereumAddress`](EthereumAddress.md) + +Get address of the contract instance. + +#### Returns + +[`EthereumAddress`](EthereumAddress.md) + +Address of this contract instance. + +#### Inherited from + +EthersContractHandle.getAddress + +#### Defined in + +[lib/ethereum/adapter.ts:112](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L112) + +___ + +### getChainIdentifier + +▸ **getChainIdentifier**(): [`ChainIdentifier`](../interfaces/ChainIdentifier.md) + +#### Returns + +[`ChainIdentifier`](../interfaces/ChainIdentifier.md) + +**`See`** + +#### Implementation of + +[WalletRegistry](../interfaces/WalletRegistry.md).[getChainIdentifier](../interfaces/WalletRegistry.md#getchainidentifier) + +#### Defined in + +[lib/ethereum/wallet-registry.ts:59](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/wallet-registry.ts#L59) + +___ + +### getDkgResultApprovedEvents + +▸ **getDkgResultApprovedEvents**(`options?`, `...filterArgs`): `Promise`\<[`DkgResultApprovedEvent`](../README.md#dkgresultapprovedevent)[]\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `options?` | [`Options`](../interfaces/GetChainEvents.Options.md) | +| `...filterArgs` | `unknown`[] | + +#### Returns + +`Promise`\<[`DkgResultApprovedEvent`](../README.md#dkgresultapprovedevent)[]\> + +**`See`** + +#### Implementation of + +WalletRegistry.getDkgResultApprovedEvents + +#### Defined in + +[lib/ethereum/wallet-registry.ts:125](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/wallet-registry.ts#L125) + +___ + +### getDkgResultChallengedEvents + +▸ **getDkgResultChallengedEvents**(`options?`, `...filterArgs`): `Promise`\<[`DkgResultChallengedEvent`](../README.md#dkgresultchallengedevent)[]\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `options?` | [`Options`](../interfaces/GetChainEvents.Options.md) | +| `...filterArgs` | `unknown`[] | + +#### Returns + +`Promise`\<[`DkgResultChallengedEvent`](../README.md#dkgresultchallengedevent)[]\> + +**`See`** + +#### Implementation of + +WalletRegistry.getDkgResultChallengedEvents + +#### Defined in + +[lib/ethereum/wallet-registry.ts:150](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/wallet-registry.ts#L150) + +___ + +### getDkgResultSubmittedEvents + +▸ **getDkgResultSubmittedEvents**(`options?`, `...filterArgs`): `Promise`\<[`DkgResultSubmittedEvent`](../README.md#dkgresultsubmittedevent)[]\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `options?` | [`Options`](../interfaces/GetChainEvents.Options.md) | +| `...filterArgs` | `unknown`[] | + +#### Returns + +`Promise`\<[`DkgResultSubmittedEvent`](../README.md#dkgresultsubmittedevent)[]\> + +**`See`** + +#### Implementation of + +WalletRegistry.getDkgResultSubmittedEvents + +#### Defined in + +[lib/ethereum/wallet-registry.ts:82](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/wallet-registry.ts#L82) + +___ + +### getEvents + +▸ **getEvents**(`eventName`, `options?`, `...filterArgs`): `Promise`\<`Event`[]\> + +Get events emitted by the Ethereum contract. +It starts searching from provided block number. If the GetEvents.Options#fromBlock +option is missing it looks for a contract's defined property +[_deployedAtBlockNumber](EthereumBridge.md#_deployedatblocknumber). If the property is missing starts searching +from block `0`. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `eventName` | `string` | Name of the event. | +| `options?` | [`Options`](../interfaces/GetChainEvents.Options.md) | Options for events fetching. | +| `...filterArgs` | `unknown`[] | Arguments for events filtering. | + +#### Returns + +`Promise`\<`Event`[]\> + +Array of found events. + +#### Inherited from + +EthersContractHandle.getEvents + +#### Defined in + +[lib/ethereum/adapter.ts:127](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L127) + +___ + +### getWalletPublicKey + +▸ **getWalletPublicKey**(`walletID`): `Promise`\<[`Hex`](Hex.md)\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `walletID` | [`Hex`](Hex.md) | + +#### Returns + +`Promise`\<[`Hex`](Hex.md)\> + +**`See`** + +#### Implementation of + +[WalletRegistry](../interfaces/WalletRegistry.md).[getWalletPublicKey](../interfaces/WalletRegistry.md#getwalletpublickey) + +#### Defined in + +[lib/ethereum/wallet-registry.ts:67](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/wallet-registry.ts#L67) diff --git a/typescript/api-reference/classes/Hex.md b/typescript/api-reference/classes/Hex.md new file mode 100644 index 000000000..9975b5248 --- /dev/null +++ b/typescript/api-reference/classes/Hex.md @@ -0,0 +1,166 @@ +# Class: Hex + +Represents a hexadecimal value. + +## Hierarchy + +- **`Hex`** + + ↳ [`BitcoinTxHash`](BitcoinTxHash.md) + +## Table of contents + +### Constructors + +- [constructor](Hex.md#constructor) + +### Properties + +- [\_hex](Hex.md#_hex) + +### Methods + +- [equals](Hex.md#equals) +- [reverse](Hex.md#reverse) +- [toBuffer](Hex.md#tobuffer) +- [toPrefixedString](Hex.md#toprefixedstring) +- [toString](Hex.md#tostring) +- [from](Hex.md#from) + +## Constructors + +### constructor + +• **new Hex**(`value`): [`Hex`](Hex.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `value` | `string` \| `Buffer` | + +#### Returns + +[`Hex`](Hex.md) + +#### Defined in + +[lib/utils/hex.ts:7](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/utils/hex.ts#L7) + +## Properties + +### \_hex + +• `Protected` `Readonly` **\_hex**: `Buffer` + +#### Defined in + +[lib/utils/hex.ts:5](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/utils/hex.ts#L5) + +## Methods + +### equals + +▸ **equals**(`otherValue`): `boolean` + +Checks if other value equals the current value. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `otherValue` | [`Hex`](Hex.md) | Other value that will be compared to this value. | + +#### Returns + +`boolean` + +True if both values are equal, false otherwise. + +#### Defined in + +[lib/utils/hex.ts:57](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/utils/hex.ts#L57) + +___ + +### reverse + +▸ **reverse**(): [`Hex`](Hex.md) + +#### Returns + +[`Hex`](Hex.md) + +Reversed hexadecimal value. + +#### Defined in + +[lib/utils/hex.ts:64](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/utils/hex.ts#L64) + +___ + +### toBuffer + +▸ **toBuffer**(): `Buffer` + +#### Returns + +`Buffer` + +Hexadecimal value as a Buffer. + +#### Defined in + +[lib/utils/hex.ts:32](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/utils/hex.ts#L32) + +___ + +### toPrefixedString + +▸ **toPrefixedString**(): `string` + +#### Returns + +`string` + +Hexadecimal string prefixed with '0x'. + +#### Defined in + +[lib/utils/hex.ts:46](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/utils/hex.ts#L46) + +___ + +### toString + +▸ **toString**(): `string` + +#### Returns + +`string` + +Unprefixed hexadecimal string. + +#### Defined in + +[lib/utils/hex.ts:39](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/utils/hex.ts#L39) + +___ + +### from + +▸ **from**(`value`): [`Hex`](Hex.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `value` | `string` \| `Buffer` | + +#### Returns + +[`Hex`](Hex.md) + +#### Defined in + +[lib/utils/hex.ts:25](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/utils/hex.ts#L25) diff --git a/typescript/api-reference/classes/MaintenanceService.md b/typescript/api-reference/classes/MaintenanceService.md new file mode 100644 index 000000000..22efdffb5 --- /dev/null +++ b/typescript/api-reference/classes/MaintenanceService.md @@ -0,0 +1,60 @@ +# Class: MaintenanceService + +Service exposing features relevant to authorized maintainers and +operators of the tBTC v2 system. + +## Table of contents + +### Constructors + +- [constructor](MaintenanceService.md#constructor) + +### Properties + +- [optimisticMinting](MaintenanceService.md#optimisticminting) +- [spv](MaintenanceService.md#spv) + +## Constructors + +### constructor + +• **new MaintenanceService**(`tbtcContracts`, `bitcoinClient`): [`MaintenanceService`](MaintenanceService.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `tbtcContracts` | [`TBTCContracts`](../README.md#tbtccontracts) | +| `bitcoinClient` | [`BitcoinClient`](../interfaces/BitcoinClient.md) | + +#### Returns + +[`MaintenanceService`](MaintenanceService.md) + +#### Defined in + +[services/maintenance/maintenance-service.ts:20](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/maintenance/maintenance-service.ts#L20) + +## Properties + +### optimisticMinting + +• `Readonly` **optimisticMinting**: [`OptimisticMinting`](OptimisticMinting.md) + +Features for optimistic minting maintainers. + +#### Defined in + +[services/maintenance/maintenance-service.ts:14](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/maintenance/maintenance-service.ts#L14) + +___ + +### spv + +• `Readonly` **spv**: [`Spv`](Spv.md) + +Features for SPV proof maintainers. + +#### Defined in + +[services/maintenance/maintenance-service.ts:18](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/maintenance/maintenance-service.ts#L18) diff --git a/typescript/api-reference/classes/OptimisticMinting.md b/typescript/api-reference/classes/OptimisticMinting.md new file mode 100644 index 000000000..4c5fe6b04 --- /dev/null +++ b/typescript/api-reference/classes/OptimisticMinting.md @@ -0,0 +1,148 @@ +# Class: OptimisticMinting + +## Table of contents + +### Constructors + +- [constructor](OptimisticMinting.md#constructor) + +### Properties + +- [tbtcContracts](OptimisticMinting.md#tbtccontracts) + +### Methods + +- [cancelMint](OptimisticMinting.md#cancelmint) +- [finalizeMint](OptimisticMinting.md#finalizemint) +- [getMintingRequest](OptimisticMinting.md#getmintingrequest) +- [requestMint](OptimisticMinting.md#requestmint) + +## Constructors + +### constructor + +• **new OptimisticMinting**(`tbtcContracts`): [`OptimisticMinting`](OptimisticMinting.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `tbtcContracts` | [`TBTCContracts`](../README.md#tbtccontracts) | + +#### Returns + +[`OptimisticMinting`](OptimisticMinting.md) + +#### Defined in + +[services/maintenance/optimistic-minting.ts:9](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/maintenance/optimistic-minting.ts#L9) + +## Properties + +### tbtcContracts + +• `Private` `Readonly` **tbtcContracts**: [`TBTCContracts`](../README.md#tbtccontracts) + +#### Defined in + +[services/maintenance/optimistic-minting.ts:7](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/maintenance/optimistic-minting.ts#L7) + +## Methods + +### cancelMint + +▸ **cancelMint**(`depositTxHash`, `depositOutputIndex`): `Promise`\<[`Hex`](Hex.md)\> + +Cancels optimistic minting for a deposit on chain. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `depositTxHash` | [`BitcoinTxHash`](BitcoinTxHash.md) | The revealed deposit transaction's hash. | +| `depositOutputIndex` | `number` | Index of the deposit transaction output that funds the revealed deposit. | + +#### Returns + +`Promise`\<[`Hex`](Hex.md)\> + +Transaction hash of the optimistic mint cancel transaction. + +#### Defined in + +[services/maintenance/optimistic-minting.ts:37](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/maintenance/optimistic-minting.ts#L37) + +___ + +### finalizeMint + +▸ **finalizeMint**(`depositTxHash`, `depositOutputIndex`): `Promise`\<[`Hex`](Hex.md)\> + +Finalizes optimistic minting for a deposit on chain. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `depositTxHash` | [`BitcoinTxHash`](BitcoinTxHash.md) | The revealed deposit transaction's hash. | +| `depositOutputIndex` | `number` | Index of the deposit transaction output that funds the revealed deposit. | + +#### Returns + +`Promise`\<[`Hex`](Hex.md)\> + +Transaction hash of the optimistic mint finalize transaction. + +#### Defined in + +[services/maintenance/optimistic-minting.ts:54](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/maintenance/optimistic-minting.ts#L54) + +___ + +### getMintingRequest + +▸ **getMintingRequest**(`depositTxHash`, `depositOutputIndex`): `Promise`\<[`OptimisticMintingRequest`](../README.md#optimisticmintingrequest)\> + +Gets optimistic minting request for a deposit from chain. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `depositTxHash` | [`BitcoinTxHash`](BitcoinTxHash.md) | The revealed deposit transaction's hash. | +| `depositOutputIndex` | `number` | Index of the deposit transaction output that funds the revealed deposit. | + +#### Returns + +`Promise`\<[`OptimisticMintingRequest`](../README.md#optimisticmintingrequest)\> + +Optimistic minting request. + +#### Defined in + +[services/maintenance/optimistic-minting.ts:71](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/maintenance/optimistic-minting.ts#L71) + +___ + +### requestMint + +▸ **requestMint**(`depositTxHash`, `depositOutputIndex`): `Promise`\<[`Hex`](Hex.md)\> + +Requests optimistic minting for a deposit on chain. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `depositTxHash` | [`BitcoinTxHash`](BitcoinTxHash.md) | The revealed deposit transaction's hash. | +| `depositOutputIndex` | `number` | Index of the deposit transaction output that funds the revealed deposit. | + +#### Returns + +`Promise`\<[`Hex`](Hex.md)\> + +Transaction hash of the optimistic mint request transaction. + +#### Defined in + +[services/maintenance/optimistic-minting.ts:20](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/maintenance/optimistic-minting.ts#L20) diff --git a/typescript/api-reference/classes/RedemptionsService.md b/typescript/api-reference/classes/RedemptionsService.md new file mode 100644 index 000000000..5a65618a0 --- /dev/null +++ b/typescript/api-reference/classes/RedemptionsService.md @@ -0,0 +1,179 @@ +# Class: RedemptionsService + +Service exposing features related to tBTC v2 redemptions. + +## Table of contents + +### Constructors + +- [constructor](RedemptionsService.md#constructor) + +### Properties + +- [bitcoinClient](RedemptionsService.md#bitcoinclient) +- [tbtcContracts](RedemptionsService.md#tbtccontracts) + +### Methods + +- [determineWalletMainUtxo](RedemptionsService.md#determinewalletmainutxo) +- [findWalletForRedemption](RedemptionsService.md#findwalletforredemption) +- [getRedemptionRequests](RedemptionsService.md#getredemptionrequests) +- [requestRedemption](RedemptionsService.md#requestredemption) + +## Constructors + +### constructor + +• **new RedemptionsService**(`tbtcContracts`, `bitcoinClient`): [`RedemptionsService`](RedemptionsService.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `tbtcContracts` | [`TBTCContracts`](../README.md#tbtccontracts) | +| `bitcoinClient` | [`BitcoinClient`](../interfaces/BitcoinClient.md) | + +#### Returns + +[`RedemptionsService`](RedemptionsService.md) + +#### Defined in + +[services/redemptions/redemptions-service.ts:30](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/redemptions/redemptions-service.ts#L30) + +## Properties + +### bitcoinClient + +• `Private` `Readonly` **bitcoinClient**: [`BitcoinClient`](../interfaces/BitcoinClient.md) + +Bitcoin client handle. + +#### Defined in + +[services/redemptions/redemptions-service.ts:28](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/redemptions/redemptions-service.ts#L28) + +___ + +### tbtcContracts + +• `Private` `Readonly` **tbtcContracts**: [`TBTCContracts`](../README.md#tbtccontracts) + +Handle to tBTC contracts. + +#### Defined in + +[services/redemptions/redemptions-service.ts:24](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/redemptions/redemptions-service.ts#L24) + +## Methods + +### determineWalletMainUtxo + +▸ **determineWalletMainUtxo**(`walletPublicKeyHash`, `bitcoinNetwork`): `Promise`\<`undefined` \| [`BitcoinUtxo`](../README.md#bitcoinutxo)\> + +Determines the plain-text wallet main UTXO currently registered in the +Bridge on-chain contract. The returned main UTXO can be undefined if the +wallet does not have a main UTXO registered in the Bridge at the moment. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `walletPublicKeyHash` | [`Hex`](Hex.md) | Public key hash of the wallet. | +| `bitcoinNetwork` | [`BitcoinNetwork`](../enums/BitcoinNetwork-1.md) | Bitcoin network. | + +#### Returns + +`Promise`\<`undefined` \| [`BitcoinUtxo`](../README.md#bitcoinutxo)\> + +Promise holding the wallet main UTXO or undefined value. + +#### Defined in + +[services/redemptions/redemptions-service.ts:215](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/redemptions/redemptions-service.ts#L215) + +___ + +### findWalletForRedemption + +▸ **findWalletForRedemption**(`redeemerOutputScript`, `amount`): `Promise`\<\{ `mainUtxo`: [`BitcoinUtxo`](../README.md#bitcoinutxo) ; `walletPublicKey`: [`Hex`](Hex.md) }\> + +Finds the oldest live wallet that has enough BTC to handle a redemption +request. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `redeemerOutputScript` | [`Hex`](Hex.md) | The redeemer output script the redeemed funds are supposed to be locked on. Must not be prepended with length. | +| `amount` | `BigNumber` | The amount to be redeemed in satoshis. | + +#### Returns + +`Promise`\<\{ `mainUtxo`: [`BitcoinUtxo`](../README.md#bitcoinutxo) ; `walletPublicKey`: [`Hex`](Hex.md) }\> + +Promise with the wallet details needed to request a redemption. + +#### Defined in + +[services/redemptions/redemptions-service.ts:96](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/redemptions/redemptions-service.ts#L96) + +___ + +### getRedemptionRequests + +▸ **getRedemptionRequests**(`bitcoinRedeemerAddress`, `walletPublicKey`, `type?`): `Promise`\<[`RedemptionRequest`](../interfaces/RedemptionRequest.md)\> + +Gets data of a registered redemption request from the Bridge contract. + +#### Parameters + +| Name | Type | Default value | Description | +| :------ | :------ | :------ | :------ | +| `bitcoinRedeemerAddress` | `string` | `undefined` | Bitcoin redeemer address used to request the redemption. | +| `walletPublicKey` | [`Hex`](Hex.md) | `undefined` | Bitcoin public key of the wallet handling the redemption. Must be in the compressed form (33 bytes long with 02 or 03 prefix). | +| `type` | ``"pending"`` \| ``"timedOut"`` | `"pending"` | Type of redemption requests the function will look for. Can be either `pending` or `timedOut`. By default, `pending` is used. | + +#### Returns + +`Promise`\<[`RedemptionRequest`](../interfaces/RedemptionRequest.md)\> + +Matching redemption requests. + +**`Throws`** + +Throws an error if no redemption request exists for the given + input parameters. + +#### Defined in + +[services/redemptions/redemptions-service.ts:327](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/redemptions/redemptions-service.ts#L327) + +___ + +### requestRedemption + +▸ **requestRedemption**(`bitcoinRedeemerAddress`, `amount`): `Promise`\<\{ `targetChainTxHash`: [`Hex`](Hex.md) ; `walletPublicKey`: [`Hex`](Hex.md) }\> + +Requests a redemption of TBTC v2 token into BTC. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `bitcoinRedeemerAddress` | `string` | Bitcoin address redeemed BTC should be sent to. Only P2PKH, P2WPKH, P2SH, and P2WSH address types are supported. | +| `amount` | `BigNumber` | The amount to be redeemed with the precision of the tBTC on-chain token contract. | + +#### Returns + +`Promise`\<\{ `targetChainTxHash`: [`Hex`](Hex.md) ; `walletPublicKey`: [`Hex`](Hex.md) }\> + +Object containing: + - Target chain hash of the request redemption transaction + (for example, Ethereum transaction hash) + - Bitcoin public key of the wallet asked to handle the redemption. + Presented in the compressed form (33 bytes long with 02 or 03 prefix). + +#### Defined in + +[services/redemptions/redemptions-service.ts:48](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/redemptions/redemptions-service.ts#L48) diff --git a/typescript/api-reference/classes/Spv.md b/typescript/api-reference/classes/Spv.md new file mode 100644 index 000000000..2fdf8ae10 --- /dev/null +++ b/typescript/api-reference/classes/Spv.md @@ -0,0 +1,116 @@ +# Class: Spv + +## Table of contents + +### Constructors + +- [constructor](Spv.md#constructor) + +### Properties + +- [bitcoinClient](Spv.md#bitcoinclient) +- [tbtcContracts](Spv.md#tbtccontracts) + +### Methods + +- [submitDepositSweepProof](Spv.md#submitdepositsweepproof) +- [submitRedemptionProof](Spv.md#submitredemptionproof) + +## Constructors + +### constructor + +• **new Spv**(`tbtcContracts`, `bitcoinClient`): [`Spv`](Spv.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `tbtcContracts` | [`TBTCContracts`](../README.md#tbtccontracts) | +| `bitcoinClient` | [`BitcoinClient`](../interfaces/BitcoinClient.md) | + +#### Returns + +[`Spv`](Spv.md) + +#### Defined in + +[services/maintenance/spv.ts:21](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/maintenance/spv.ts#L21) + +## Properties + +### bitcoinClient + +• `Private` `Readonly` **bitcoinClient**: [`BitcoinClient`](../interfaces/BitcoinClient.md) + +Bitcoin client handle. + +#### Defined in + +[services/maintenance/spv.ts:19](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/maintenance/spv.ts#L19) + +___ + +### tbtcContracts + +• `Private` `Readonly` **tbtcContracts**: [`TBTCContracts`](../README.md#tbtccontracts) + +Handle to tBTC contracts. + +#### Defined in + +[services/maintenance/spv.ts:15](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/maintenance/spv.ts#L15) + +## Methods + +### submitDepositSweepProof + +▸ **submitDepositSweepProof**(`transactionHash`, `mainUtxo`, `vault?`): `Promise`\<`void`\> + +Prepares the proof of a deposit sweep transaction and submits it to the +Bridge on-chain contract. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `transactionHash` | [`BitcoinTxHash`](BitcoinTxHash.md) | Hash of the transaction being proven. | +| `mainUtxo` | [`BitcoinUtxo`](../README.md#bitcoinutxo) | Recent main UTXO of the wallet as currently known on-chain. | +| `vault?` | [`ChainIdentifier`](../interfaces/ChainIdentifier.md) | (Optional) The vault pointed by swept deposits. | + +#### Returns + +`Promise`\<`void`\> + +Empty promise. + +#### Defined in + +[services/maintenance/spv.ts:34](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/maintenance/spv.ts#L34) + +___ + +### submitRedemptionProof + +▸ **submitRedemptionProof**(`transactionHash`, `mainUtxo`, `walletPublicKey`): `Promise`\<`void`\> + +Prepares the proof of a redemption transaction and submits it to the +Bridge on-chain contract. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `transactionHash` | [`BitcoinTxHash`](BitcoinTxHash.md) | Hash of the transaction being proven. | +| `mainUtxo` | [`BitcoinUtxo`](../README.md#bitcoinutxo) | Recent main UTXO of the wallet as currently known on-chain. | +| `walletPublicKey` | [`Hex`](Hex.md) | Bitcoin public key of the wallet. Must be in the compressed form (33 bytes long with 02 or 03 prefix). | + +#### Returns + +`Promise`\<`void`\> + +Empty promise. + +#### Defined in + +[services/maintenance/spv.ts:67](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/maintenance/spv.ts#L67) diff --git a/typescript/api-reference/classes/TBTC.md b/typescript/api-reference/classes/TBTC.md new file mode 100644 index 000000000..3317f5fde --- /dev/null +++ b/typescript/api-reference/classes/TBTC.md @@ -0,0 +1,233 @@ +# Class: TBTC + +Entrypoint component of the tBTC v2 SDK. + +## Table of contents + +### Constructors + +- [constructor](TBTC.md#constructor) + +### Properties + +- [bitcoinClient](TBTC.md#bitcoinclient) +- [deposits](TBTC.md#deposits) +- [maintenance](TBTC.md#maintenance) +- [redemptions](TBTC.md#redemptions) +- [tbtcContracts](TBTC.md#tbtccontracts) + +### Methods + +- [initializeCustom](TBTC.md#initializecustom) +- [initializeEthereum](TBTC.md#initializeethereum) +- [initializeGoerli](TBTC.md#initializegoerli) +- [initializeMainnet](TBTC.md#initializemainnet) + +## Constructors + +### constructor + +• **new TBTC**(`tbtcContracts`, `bitcoinClient`): [`TBTC`](TBTC.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `tbtcContracts` | [`TBTCContracts`](../README.md#tbtccontracts) | +| `bitcoinClient` | [`BitcoinClient`](../interfaces/BitcoinClient.md) | + +#### Returns + +[`TBTC`](TBTC.md) + +#### Defined in + +[services/tbtc.ts:40](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/tbtc.ts#L40) + +## Properties + +### bitcoinClient + +• `Readonly` **bitcoinClient**: [`BitcoinClient`](../interfaces/BitcoinClient.md) + +Bitcoin client handle for low-level access. + +#### Defined in + +[services/tbtc.ts:38](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/tbtc.ts#L38) + +___ + +### deposits + +• `Readonly` **deposits**: [`DepositsService`](DepositsService.md) + +Service supporting the tBTC v2 deposit flow. + +#### Defined in + +[services/tbtc.ts:21](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/tbtc.ts#L21) + +___ + +### maintenance + +• `Readonly` **maintenance**: [`MaintenanceService`](MaintenanceService.md) + +Service supporting authorized operations of tBTC v2 system maintainers +and operators. + +#### Defined in + +[services/tbtc.ts:26](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/tbtc.ts#L26) + +___ + +### redemptions + +• `Readonly` **redemptions**: [`RedemptionsService`](RedemptionsService.md) + +Service supporting the tBTC v2 redemption flow. + +#### Defined in + +[services/tbtc.ts:30](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/tbtc.ts#L30) + +___ + +### tbtcContracts + +• `Readonly` **tbtcContracts**: [`TBTCContracts`](../README.md#tbtccontracts) + +Handle to tBTC contracts for low-level access. + +#### Defined in + +[services/tbtc.ts:34](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/tbtc.ts#L34) + +## Methods + +### initializeCustom + +▸ **initializeCustom**(`tbtcContracts`, `bitcoinClient`): `Promise`\<[`TBTC`](TBTC.md)\> + +Initializes the tBTC v2 SDK entrypoint with custom tBTC contracts and +Bitcoin client. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `tbtcContracts` | [`TBTCContracts`](../README.md#tbtccontracts) | Custom tBTC contracts handle. | +| `bitcoinClient` | [`BitcoinClient`](../interfaces/BitcoinClient.md) | Custom Bitcoin client implementation. | + +#### Returns + +`Promise`\<[`TBTC`](TBTC.md)\> + +Initialized tBTC v2 SDK entrypoint. + +**`Dev`** + +This function is especially useful for local development as it gives + flexibility to combine different implementations of tBTC v2 contracts + with different Bitcoin networks. + +#### Defined in + +[services/tbtc.ts:117](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/tbtc.ts#L117) + +___ + +### initializeEthereum + +▸ **initializeEthereum**(`signer`, `ethereumNetwork`, `bitcoinNetwork`): `Promise`\<[`TBTC`](TBTC.md)\> + +Initializes the tBTC v2 SDK entrypoint for the given Ethereum network and Bitcoin network. +The initialized instance uses default Electrum servers to interact +with Bitcoin network. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `signer` | [`EthereumSigner`](../README.md#ethereumsigner) | Ethereum signer. | +| `ethereumNetwork` | [`EthereumNetwork`](../README.md#ethereumnetwork) | Ethereum network. | +| `bitcoinNetwork` | [`BitcoinNetwork`](../enums/BitcoinNetwork-1.md) | Bitcoin network. | + +#### Returns + +`Promise`\<[`TBTC`](TBTC.md)\> + +Initialized tBTC v2 SDK entrypoint. + +**`Throws`** + +Throws an error if the underlying signer's Ethereum network is + other than the given Ethereum network. + +#### Defined in + +[services/tbtc.ts:88](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/tbtc.ts#L88) + +___ + +### initializeGoerli + +▸ **initializeGoerli**(`signer`): `Promise`\<[`TBTC`](TBTC.md)\> + +Initializes the tBTC v2 SDK entrypoint for Ethereum goerli and Bitcoin testnet. +The initialized instance uses default Electrum servers to interact +with Bitcoin testnet + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `signer` | [`EthereumSigner`](../README.md#ethereumsigner) | Ethereum signer. | + +#### Returns + +`Promise`\<[`TBTC`](TBTC.md)\> + +Initialized tBTC v2 SDK entrypoint. + +**`Throws`** + +Throws an error if the signer's Ethereum network is other than + Ethereum mainnet. + +#### Defined in + +[services/tbtc.ts:73](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/tbtc.ts#L73) + +___ + +### initializeMainnet + +▸ **initializeMainnet**(`signer`): `Promise`\<[`TBTC`](TBTC.md)\> + +Initializes the tBTC v2 SDK entrypoint for Ethereum and Bitcoin mainnets. +The initialized instance uses default Electrum servers to interact +with Bitcoin mainnet + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `signer` | [`EthereumSigner`](../README.md#ethereumsigner) | Ethereum signer. | + +#### Returns + +`Promise`\<[`TBTC`](TBTC.md)\> + +Initialized tBTC v2 SDK entrypoint. + +**`Throws`** + +Throws an error if the signer's Ethereum network is other than + Ethereum mainnet. + +#### Defined in + +[services/tbtc.ts:60](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/tbtc.ts#L60) diff --git a/typescript/api-reference/classes/WalletTx.md b/typescript/api-reference/classes/WalletTx.md new file mode 100644 index 000000000..f3371bf4f --- /dev/null +++ b/typescript/api-reference/classes/WalletTx.md @@ -0,0 +1,63 @@ +# Class: WalletTx + +Wallet transactions builder. This feature set is supposed to be used only +for internal purposes like system tests. In real world, tBTC v2 wallets +are formed by peer-to-peer network participants that sign transactions +using threshold signature schemes. + + THIS IS EXPERIMENTAL CODE THAT CAN BE CHANGED OR REMOVED + IN FUTURE RELEASES. IT SHOULD BE USED ONLY FOR INTERNAL + PURPOSES AND EXTERNAL APPLICATIONS SHOULD NOT DEPEND ON IT. + +## Table of contents + +### Constructors + +- [constructor](WalletTx.md#constructor) + +### Properties + +- [depositSweep](WalletTx.md#depositsweep) +- [redemption](WalletTx.md#redemption) + +## Constructors + +### constructor + +• **new WalletTx**(`tbtcContracts`, `bitcoinClient`, `witness?`): [`WalletTx`](WalletTx.md) + +#### Parameters + +| Name | Type | Default value | +| :------ | :------ | :------ | +| `tbtcContracts` | [`TBTCContracts`](../README.md#tbtccontracts) | `undefined` | +| `bitcoinClient` | [`BitcoinClient`](../interfaces/BitcoinClient.md) | `undefined` | +| `witness` | `boolean` | `true` | + +#### Returns + +[`WalletTx`](WalletTx.md) + +#### Defined in + +[services/maintenance/wallet-tx.ts:48](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/maintenance/wallet-tx.ts#L48) + +## Properties + +### depositSweep + +• `Readonly` **depositSweep**: `DepositSweep` + +#### Defined in + +[services/maintenance/wallet-tx.ts:45](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/maintenance/wallet-tx.ts#L45) + +___ + +### redemption + +• `Readonly` **redemption**: `Redemption` + +#### Defined in + +[services/maintenance/wallet-tx.ts:46](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/services/maintenance/wallet-tx.ts#L46) diff --git a/typescript/api-reference/enums/BitcoinNetwork-1.md b/typescript/api-reference/enums/BitcoinNetwork-1.md new file mode 100644 index 000000000..0b7b11044 --- /dev/null +++ b/typescript/api-reference/enums/BitcoinNetwork-1.md @@ -0,0 +1,47 @@ +# Enumeration: BitcoinNetwork + +Bitcoin networks. + +## Table of contents + +### Enumeration Members + +- [Mainnet](BitcoinNetwork-1.md#mainnet) +- [Testnet](BitcoinNetwork-1.md#testnet) +- [Unknown](BitcoinNetwork-1.md#unknown) + +## Enumeration Members + +### Mainnet + +• **Mainnet** = ``"mainnet"`` + +Bitcoin Mainnet. + +#### Defined in + +[lib/bitcoin/network.ts:20](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/network.ts#L20) + +___ + +### Testnet + +• **Testnet** = ``"testnet"`` + +Bitcoin Testnet. + +#### Defined in + +[lib/bitcoin/network.ts:16](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/network.ts#L16) + +___ + +### Unknown + +• **Unknown** = ``"unknown"`` + +Unknown network. + +#### Defined in + +[lib/bitcoin/network.ts:12](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/network.ts#L12) diff --git a/typescript/api-reference/enums/WalletState-1.md b/typescript/api-reference/enums/WalletState-1.md new file mode 100644 index 000000000..f31266409 --- /dev/null +++ b/typescript/api-reference/enums/WalletState-1.md @@ -0,0 +1,93 @@ +# Enumeration: WalletState + +## Table of contents + +### Enumeration Members + +- [Closed](WalletState-1.md#closed) +- [Closing](WalletState-1.md#closing) +- [Live](WalletState-1.md#live) +- [MovingFunds](WalletState-1.md#movingfunds) +- [Terminated](WalletState-1.md#terminated) +- [Unknown](WalletState-1.md#unknown) + +## Enumeration Members + +### Closed + +• **Closed** = ``4`` + +The wallet finalized the closing period successfully and can no longer perform +any action in the Bridge. + +#### Defined in + +[lib/contracts/bridge.ts:371](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L371) + +___ + +### Closing + +• **Closing** = ``3`` + +The wallet moved or redeemed all their funds and is in the +losing period where it is still a subject of fraud challenges +and must defend against them. + +#### Defined in + +[lib/contracts/bridge.ts:366](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L366) + +___ + +### Live + +• **Live** = ``1`` + +The wallet can sweep deposits and accept redemption requests. + +#### Defined in + +[lib/contracts/bridge.ts:353](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L353) + +___ + +### MovingFunds + +• **MovingFunds** = ``2`` + +The wallet was deemed unhealthy and is expected to move their outstanding +funds to another wallet. The wallet can still fulfill their pending redemption +requests although new redemption requests and new deposit reveals are not +accepted. + +#### Defined in + +[lib/contracts/bridge.ts:360](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L360) + +___ + +### Terminated + +• **Terminated** = ``5`` + +The wallet committed a fraud that was reported, did not move funds to +another wallet before a timeout, or did not sweep funds moved to if from +another wallet before a timeout. The wallet is blocked and can not perform +any actions in the Bridge. + +#### Defined in + +[lib/contracts/bridge.ts:378](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L378) + +___ + +### Unknown + +• **Unknown** = ``0`` + +The wallet is unknown to the Bridge. + +#### Defined in + +[lib/contracts/bridge.ts:349](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L349) diff --git a/typescript/api-reference/interfaces/BitcoinClient.md b/typescript/api-reference/interfaces/BitcoinClient.md new file mode 100644 index 000000000..3afac0bdd --- /dev/null +++ b/typescript/api-reference/interfaces/BitcoinClient.md @@ -0,0 +1,284 @@ +# Interface: BitcoinClient + +Represents a Bitcoin client. + +## Implemented by + +- [`ElectrumClient`](../classes/ElectrumClient.md) + +## Table of contents + +### Methods + +- [broadcast](BitcoinClient.md#broadcast) +- [findAllUnspentTransactionOutputs](BitcoinClient.md#findallunspenttransactionoutputs) +- [getHeadersChain](BitcoinClient.md#getheaderschain) +- [getNetwork](BitcoinClient.md#getnetwork) +- [getRawTransaction](BitcoinClient.md#getrawtransaction) +- [getTransaction](BitcoinClient.md#gettransaction) +- [getTransactionConfirmations](BitcoinClient.md#gettransactionconfirmations) +- [getTransactionHistory](BitcoinClient.md#gettransactionhistory) +- [getTransactionMerkle](BitcoinClient.md#gettransactionmerkle) +- [getTxHashesForPublicKeyHash](BitcoinClient.md#gettxhashesforpublickeyhash) +- [latestBlockHeight](BitcoinClient.md#latestblockheight) + +## Methods + +### broadcast + +▸ **broadcast**(`transaction`): `Promise`\<`void`\> + +Broadcasts the given transaction over the network. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `transaction` | [`BitcoinRawTx`](BitcoinRawTx.md) | Transaction to broadcast. | + +#### Returns + +`Promise`\<`void`\> + +#### Defined in + +[lib/bitcoin/client.ts:101](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L101) + +___ + +### findAllUnspentTransactionOutputs + +▸ **findAllUnspentTransactionOutputs**(`address`): `Promise`\<[`BitcoinUtxo`](../README.md#bitcoinutxo)[]\> + +Finds all unspent transaction outputs (UTXOs) for given Bitcoin address. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `address` | `string` | Bitcoin address UTXOs should be determined for. | + +#### Returns + +`Promise`\<[`BitcoinUtxo`](../README.md#bitcoinutxo)[]\> + +List of UTXOs. + +#### Defined in + +[lib/bitcoin/client.ts:21](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L21) + +___ + +### getHeadersChain + +▸ **getHeadersChain**(`blockHeight`, `chainLength`): `Promise`\<[`Hex`](../classes/Hex.md)\> + +Gets concatenated chunk of block headers built on a starting block. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `blockHeight` | `number` | Starting block height. | +| `chainLength` | `number` | Number of subsequent blocks built on the starting block. | + +#### Returns + +`Promise`\<[`Hex`](../classes/Hex.md)\> + +Concatenation of block headers in a hexadecimal format. + +#### Defined in + +[lib/bitcoin/client.ts:84](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L84) + +___ + +### getNetwork + +▸ **getNetwork**(): `Promise`\<[`BitcoinNetwork`](../enums/BitcoinNetwork-1.md)\> + +Gets the network supported by the server the client connected to. + +#### Returns + +`Promise`\<[`BitcoinNetwork`](../enums/BitcoinNetwork-1.md)\> + +Bitcoin network. + +#### Defined in + +[lib/bitcoin/client.ts:14](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L14) + +___ + +### getRawTransaction + +▸ **getRawTransaction**(`transactionHash`): `Promise`\<[`BitcoinRawTx`](BitcoinRawTx.md)\> + +Gets the raw transaction data for given transaction hash. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `transactionHash` | [`BitcoinTxHash`](../classes/BitcoinTxHash.md) | Hash of the transaction. | + +#### Returns + +`Promise`\<[`BitcoinRawTx`](BitcoinRawTx.md)\> + +Raw transaction. + +#### Defined in + +[lib/bitcoin/client.ts:47](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L47) + +___ + +### getTransaction + +▸ **getTransaction**(`transactionHash`): `Promise`\<[`BitcoinTx`](BitcoinTx.md)\> + +Gets the full transaction object for given transaction hash. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `transactionHash` | [`BitcoinTxHash`](../classes/BitcoinTxHash.md) | Hash of the transaction. | + +#### Returns + +`Promise`\<[`BitcoinTx`](BitcoinTx.md)\> + +Transaction object. + +#### Defined in + +[lib/bitcoin/client.ts:40](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L40) + +___ + +### getTransactionConfirmations + +▸ **getTransactionConfirmations**(`transactionHash`): `Promise`\<`number`\> + +Gets the number of confirmations that a given transaction has accumulated +so far. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `transactionHash` | [`BitcoinTxHash`](../classes/BitcoinTxHash.md) | Hash of the transaction. | + +#### Returns + +`Promise`\<`number`\> + +The number of confirmations. + +#### Defined in + +[lib/bitcoin/client.ts:55](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L55) + +___ + +### getTransactionHistory + +▸ **getTransactionHistory**(`address`, `limit?`): `Promise`\<[`BitcoinTx`](BitcoinTx.md)[]\> + +Gets the history of confirmed transactions for given Bitcoin address. +Returned transactions are sorted from oldest to newest. The returned +result does not contain unconfirmed transactions living in the mempool +at the moment of request. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `address` | `string` | Bitcoin address transaction history should be determined for. | +| `limit?` | `number` | Optional parameter that can limit the resulting list to a specific number of last transaction. For example, limit = 5 will return only the last 5 transactions for the given address. | + +#### Returns + +`Promise`\<[`BitcoinTx`](BitcoinTx.md)[]\> + +#### Defined in + +[lib/bitcoin/client.ts:33](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L33) + +___ + +### getTransactionMerkle + +▸ **getTransactionMerkle**(`transactionHash`, `blockHeight`): `Promise`\<[`BitcoinTxMerkleBranch`](BitcoinTxMerkleBranch.md)\> + +Get Merkle branch for a given transaction. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `transactionHash` | [`BitcoinTxHash`](../classes/BitcoinTxHash.md) | Hash of a transaction. | +| `blockHeight` | `number` | Height of the block where transaction was confirmed. | + +#### Returns + +`Promise`\<[`BitcoinTxMerkleBranch`](BitcoinTxMerkleBranch.md)\> + +Merkle branch. + +#### Defined in + +[lib/bitcoin/client.ts:92](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L92) + +___ + +### getTxHashesForPublicKeyHash + +▸ **getTxHashesForPublicKeyHash**(`publicKeyHash`): `Promise`\<[`BitcoinTxHash`](../classes/BitcoinTxHash.md)[]\> + +Gets hashes of confirmed transactions that pay the given public key hash +using either a P2PKH or P2WPKH script. The returned transactions hashes are +ordered by block height in the ascending order, i.e. the latest transaction +hash is at the end of the list. The returned list does not contain +unconfirmed transactions hashes living in the mempool at the moment of +request. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `publicKeyHash` | [`Hex`](../classes/Hex.md) | Hash of the public key for which to find corresponding transaction hashes. | + +#### Returns + +`Promise`\<[`BitcoinTxHash`](../classes/BitcoinTxHash.md)[]\> + +Array of confirmed transaction hashes related to the provided + public key hash. + +#### Defined in + +[lib/bitcoin/client.ts:69](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L69) + +___ + +### latestBlockHeight + +▸ **latestBlockHeight**(): `Promise`\<`number`\> + +Gets height of the latest mined block. + +#### Returns + +`Promise`\<`number`\> + +Height of the last mined block. + +#### Defined in + +[lib/bitcoin/client.ts:75](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/client.ts#L75) diff --git a/typescript/api-reference/interfaces/BitcoinHeader.md b/typescript/api-reference/interfaces/BitcoinHeader.md new file mode 100644 index 000000000..731675c74 --- /dev/null +++ b/typescript/api-reference/interfaces/BitcoinHeader.md @@ -0,0 +1,93 @@ +# Interface: BitcoinHeader + +BitcoinHeader represents the header of a Bitcoin block. For reference, see: +https://developer.bitcoin.org/reference/block_chain.html#block-headers. + +## Table of contents + +### Properties + +- [bits](BitcoinHeader.md#bits) +- [merkleRootHash](BitcoinHeader.md#merkleroothash) +- [nonce](BitcoinHeader.md#nonce) +- [previousBlockHeaderHash](BitcoinHeader.md#previousblockheaderhash) +- [time](BitcoinHeader.md#time) +- [version](BitcoinHeader.md#version) + +## Properties + +### bits + +• **bits**: `number` + +Bits that determine the target threshold this block's header hash must be +less than or equal to. The field is 4-byte long. + +#### Defined in + +[lib/bitcoin/header.ts:37](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/header.ts#L37) + +___ + +### merkleRootHash + +• **merkleRootHash**: [`Hex`](../classes/Hex.md) + +The hash derived from the hashes of all transactions included in this block. +The field is 32-byte long. + +#### Defined in + +[lib/bitcoin/header.ts:25](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/header.ts#L25) + +___ + +### nonce + +• **nonce**: `number` + +An arbitrary number miners change to modify the header hash in order to +produce a hash less than or equal to the target threshold. The field is +4-byte long. + +#### Defined in + +[lib/bitcoin/header.ts:44](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/header.ts#L44) + +___ + +### previousBlockHeaderHash + +• **previousBlockHeaderHash**: [`Hex`](../classes/Hex.md) + +The hash of the previous block's header. The field is 32-byte long. + +#### Defined in + +[lib/bitcoin/header.ts:19](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/header.ts#L19) + +___ + +### time + +• **time**: `number` + +The Unix epoch time when the miner started hashing the header. The field is +4-byte long. + +#### Defined in + +[lib/bitcoin/header.ts:31](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/header.ts#L31) + +___ + +### version + +• **version**: `number` + +The block version number that indicates which set of block validation rules +to follow. The field is 4-byte long. + +#### Defined in + +[lib/bitcoin/header.ts:14](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/header.ts#L14) diff --git a/typescript/api-reference/interfaces/BitcoinRawTx.md b/typescript/api-reference/interfaces/BitcoinRawTx.md new file mode 100644 index 000000000..f1b4f45b1 --- /dev/null +++ b/typescript/api-reference/interfaces/BitcoinRawTx.md @@ -0,0 +1,21 @@ +# Interface: BitcoinRawTx + +Represents a raw Bitcoin transaction. + +## Table of contents + +### Properties + +- [transactionHex](BitcoinRawTx.md#transactionhex) + +## Properties + +### transactionHex + +• **transactionHex**: `string` + +The full transaction payload as an un-prefixed hex string. + +#### Defined in + +[lib/bitcoin/tx.ts:22](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/tx.ts#L22) diff --git a/typescript/api-reference/interfaces/BitcoinRawTxVectors.md b/typescript/api-reference/interfaces/BitcoinRawTxVectors.md new file mode 100644 index 000000000..a541515d1 --- /dev/null +++ b/typescript/api-reference/interfaces/BitcoinRawTxVectors.md @@ -0,0 +1,62 @@ +# Interface: BitcoinRawTxVectors + +Represents a raw Bitcoin transaction decomposed into specific vectors. + +## Table of contents + +### Properties + +- [inputs](BitcoinRawTxVectors.md#inputs) +- [locktime](BitcoinRawTxVectors.md#locktime) +- [outputs](BitcoinRawTxVectors.md#outputs) +- [version](BitcoinRawTxVectors.md#version) + +## Properties + +### inputs + +• **inputs**: [`Hex`](../classes/Hex.md) + +All transaction's inputs prepended by the number of transaction inputs, +as a hex string. + +#### Defined in + +[lib/bitcoin/tx.ts:113](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/tx.ts#L113) + +___ + +### locktime + +• **locktime**: [`Hex`](../classes/Hex.md) + +Transaction locktime as a hex string. + +#### Defined in + +[lib/bitcoin/tx.ts:124](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/tx.ts#L124) + +___ + +### outputs + +• **outputs**: [`Hex`](../classes/Hex.md) + +All transaction's outputs prepended by the number of transaction outputs, +as a hex string. + +#### Defined in + +[lib/bitcoin/tx.ts:119](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/tx.ts#L119) + +___ + +### version + +• **version**: [`Hex`](../classes/Hex.md) + +Transaction version as a hex string. + +#### Defined in + +[lib/bitcoin/tx.ts:107](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/tx.ts#L107) diff --git a/typescript/api-reference/interfaces/BitcoinSpvProof.md b/typescript/api-reference/interfaces/BitcoinSpvProof.md new file mode 100644 index 000000000..7c06b4549 --- /dev/null +++ b/typescript/api-reference/interfaces/BitcoinSpvProof.md @@ -0,0 +1,49 @@ +# Interface: BitcoinSpvProof + +Data required to perform a proof that a given transaction was included in +the Bitcoin blockchain. + +## Table of contents + +### Properties + +- [bitcoinHeaders](BitcoinSpvProof.md#bitcoinheaders) +- [merkleProof](BitcoinSpvProof.md#merkleproof) +- [txIndexInBlock](BitcoinSpvProof.md#txindexinblock) + +## Properties + +### bitcoinHeaders + +• **bitcoinHeaders**: [`Hex`](../classes/Hex.md) + +Concatenated block headers in hexadecimal format. Each block header is +80-byte-long. The block header with the lowest height is first. + +#### Defined in + +[lib/bitcoin/spv.ts:31](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/spv.ts#L31) + +___ + +### merkleProof + +• **merkleProof**: [`Hex`](../classes/Hex.md) + +The merkle proof of transaction inclusion in a block. + +#### Defined in + +[lib/bitcoin/spv.ts:20](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/spv.ts#L20) + +___ + +### txIndexInBlock + +• **txIndexInBlock**: `number` + +Transaction index in the block (0-indexed). + +#### Defined in + +[lib/bitcoin/spv.ts:25](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/spv.ts#L25) diff --git a/typescript/api-reference/interfaces/BitcoinTx.md b/typescript/api-reference/interfaces/BitcoinTx.md new file mode 100644 index 000000000..aad847f53 --- /dev/null +++ b/typescript/api-reference/interfaces/BitcoinTx.md @@ -0,0 +1,47 @@ +# Interface: BitcoinTx + +Data about a Bitcoin transaction. + +## Table of contents + +### Properties + +- [inputs](BitcoinTx.md#inputs) +- [outputs](BitcoinTx.md#outputs) +- [transactionHash](BitcoinTx.md#transactionhash) + +## Properties + +### inputs + +• **inputs**: [`BitcoinTxInput`](../README.md#bitcointxinput)[] + +The vector of transaction inputs. + +#### Defined in + +[lib/bitcoin/tx.ts:37](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/tx.ts#L37) + +___ + +### outputs + +• **outputs**: [`BitcoinTxOutput`](BitcoinTxOutput.md)[] + +The vector of transaction outputs. + +#### Defined in + +[lib/bitcoin/tx.ts:42](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/tx.ts#L42) + +___ + +### transactionHash + +• **transactionHash**: [`BitcoinTxHash`](../classes/BitcoinTxHash.md) + +The transaction hash (or transaction ID) as an un-prefixed hex string. + +#### Defined in + +[lib/bitcoin/tx.ts:32](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/tx.ts#L32) diff --git a/typescript/api-reference/interfaces/BitcoinTxMerkleBranch.md b/typescript/api-reference/interfaces/BitcoinTxMerkleBranch.md new file mode 100644 index 000000000..df3aac29e --- /dev/null +++ b/typescript/api-reference/interfaces/BitcoinTxMerkleBranch.md @@ -0,0 +1,49 @@ +# Interface: BitcoinTxMerkleBranch + +Information about the merkle branch to a confirmed transaction. + +## Table of contents + +### Properties + +- [blockHeight](BitcoinTxMerkleBranch.md#blockheight) +- [merkle](BitcoinTxMerkleBranch.md#merkle) +- [position](BitcoinTxMerkleBranch.md#position) + +## Properties + +### blockHeight + +• **blockHeight**: `number` + +The height of the block the transaction was confirmed in. + +#### Defined in + +[lib/bitcoin/spv.ts:41](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/spv.ts#L41) + +___ + +### merkle + +• **merkle**: [`Hex`](../classes/Hex.md)[] + +A list of transaction hashes the current hash is paired with, recursively, +in order to trace up to obtain the merkle root of the including block, +the deepest pairing first. Each hash is an unprefixed hex string. + +#### Defined in + +[lib/bitcoin/spv.ts:48](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/spv.ts#L48) + +___ + +### position + +• **position**: `number` + +The 0-based index of the transaction's position in the block. + +#### Defined in + +[lib/bitcoin/spv.ts:53](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/spv.ts#L53) diff --git a/typescript/api-reference/interfaces/BitcoinTxOutpoint.md b/typescript/api-reference/interfaces/BitcoinTxOutpoint.md new file mode 100644 index 000000000..e6bff27c7 --- /dev/null +++ b/typescript/api-reference/interfaces/BitcoinTxOutpoint.md @@ -0,0 +1,34 @@ +# Interface: BitcoinTxOutpoint + +Data about a Bitcoin transaction outpoint. + +## Table of contents + +### Properties + +- [outputIndex](BitcoinTxOutpoint.md#outputindex) +- [transactionHash](BitcoinTxOutpoint.md#transactionhash) + +## Properties + +### outputIndex + +• **outputIndex**: `number` + +The zero-based index of the output from the specified transaction. + +#### Defined in + +[lib/bitcoin/tx.ts:57](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/tx.ts#L57) + +___ + +### transactionHash + +• **transactionHash**: [`BitcoinTxHash`](../classes/BitcoinTxHash.md) + +The hash of the transaction the outpoint belongs to. + +#### Defined in + +[lib/bitcoin/tx.ts:52](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/tx.ts#L52) diff --git a/typescript/api-reference/interfaces/BitcoinTxOutput.md b/typescript/api-reference/interfaces/BitcoinTxOutput.md new file mode 100644 index 000000000..d364b1206 --- /dev/null +++ b/typescript/api-reference/interfaces/BitcoinTxOutput.md @@ -0,0 +1,47 @@ +# Interface: BitcoinTxOutput + +Data about a Bitcoin transaction output. + +## Table of contents + +### Properties + +- [outputIndex](BitcoinTxOutput.md#outputindex) +- [scriptPubKey](BitcoinTxOutput.md#scriptpubkey) +- [value](BitcoinTxOutput.md#value) + +## Properties + +### outputIndex + +• **outputIndex**: `number` + +The 0-based index of the output. + +#### Defined in + +[lib/bitcoin/tx.ts:77](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/tx.ts#L77) + +___ + +### scriptPubKey + +• **scriptPubKey**: [`Hex`](../classes/Hex.md) + +The receiving scriptPubKey. + +#### Defined in + +[lib/bitcoin/tx.ts:87](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/tx.ts#L87) + +___ + +### value + +• **value**: `BigNumber` + +The value of the output in satoshis. + +#### Defined in + +[lib/bitcoin/tx.ts:82](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/tx.ts#L82) diff --git a/typescript/api-reference/interfaces/Bridge.md b/typescript/api-reference/interfaces/Bridge.md new file mode 100644 index 000000000..1282c848f --- /dev/null +++ b/typescript/api-reference/interfaces/Bridge.md @@ -0,0 +1,385 @@ +# Interface: Bridge + +Interface for communication with the Bridge on-chain contract. + +## Implemented by + +- [`EthereumBridge`](../classes/EthereumBridge.md) + +## Table of contents + +### Properties + +- [getDepositRevealedEvents](Bridge.md#getdepositrevealedevents) +- [getNewWalletRegisteredEvents](Bridge.md#getnewwalletregisteredevents) +- [getRedemptionRequestedEvents](Bridge.md#getredemptionrequestedevents) + +### Methods + +- [activeWalletPublicKey](Bridge.md#activewalletpublickey) +- [buildUtxoHash](Bridge.md#buildutxohash) +- [deposits](Bridge.md#deposits) +- [getChainIdentifier](Bridge.md#getchainidentifier) +- [pendingRedemptions](Bridge.md#pendingredemptions) +- [requestRedemption](Bridge.md#requestredemption) +- [revealDeposit](Bridge.md#revealdeposit) +- [submitDepositSweepProof](Bridge.md#submitdepositsweepproof) +- [submitRedemptionProof](Bridge.md#submitredemptionproof) +- [timedOutRedemptions](Bridge.md#timedoutredemptions) +- [txProofDifficultyFactor](Bridge.md#txproofdifficultyfactor) +- [walletRegistry](Bridge.md#walletregistry) +- [wallets](Bridge.md#wallets) + +## Properties + +### getDepositRevealedEvents + +• **getDepositRevealedEvents**: [`Function`](GetChainEvents.Function.md)\<[`DepositRevealedEvent`](../README.md#depositrevealedevent)\> + +Get emitted DepositRevealed events. + +**`See`** + +GetEventsFunction + +#### Defined in + +[lib/contracts/bridge.ts:26](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L26) + +___ + +### getNewWalletRegisteredEvents + +• **getNewWalletRegisteredEvents**: [`Function`](GetChainEvents.Function.md)\<[`NewWalletRegisteredEvent`](../README.md#newwalletregisteredevent)\> + +Get emitted NewWalletRegisteredEvent events. + +**`See`** + +GetEventsFunction + +#### Defined in + +[lib/contracts/bridge.ts:155](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L155) + +___ + +### getRedemptionRequestedEvents + +• **getRedemptionRequestedEvents**: [`Function`](GetChainEvents.Function.md)\<[`RedemptionRequestedEvent`](../README.md#redemptionrequestedevent)\> + +Get emitted RedemptionRequested events. + +**`See`** + +GetEventsFunction + +#### Defined in + +[lib/contracts/bridge.ts:181](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L181) + +## Methods + +### activeWalletPublicKey + +▸ **activeWalletPublicKey**(): `Promise`\<`undefined` \| [`Hex`](../classes/Hex.md)\> + +Gets the public key of the current active wallet. + +#### Returns + +`Promise`\<`undefined` \| [`Hex`](../classes/Hex.md)\> + +Compressed (33 bytes long with 02 or 03 prefix) active wallet's + public key. If there is no active wallet at the moment, undefined + is returned. + +#### Defined in + +[lib/contracts/bridge.ts:149](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L149) + +___ + +### buildUtxoHash + +▸ **buildUtxoHash**(`utxo`): [`Hex`](../classes/Hex.md) + +Builds the UTXO hash based on the UTXO components. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `utxo` | [`BitcoinUtxo`](../README.md#bitcoinutxo) | UTXO components. | + +#### Returns + +[`Hex`](../classes/Hex.md) + +The hash of the UTXO. + +#### Defined in + +[lib/contracts/bridge.ts:175](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L175) + +___ + +### deposits + +▸ **deposits**(`depositTxHash`, `depositOutputIndex`): `Promise`\<[`DepositRequest`](DepositRequest.md)\> + +Gets a revealed deposit from the on-chain contract. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `depositTxHash` | [`BitcoinTxHash`](../classes/BitcoinTxHash.md) | The revealed deposit transaction's hash. | +| `depositOutputIndex` | `number` | Index of the deposit transaction output that funds the revealed deposit. | + +#### Returns + +`Promise`\<[`DepositRequest`](DepositRequest.md)\> + +Revealed deposit data. + +#### Defined in + +[lib/contracts/bridge.ts:68](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L68) + +___ + +### getChainIdentifier + +▸ **getChainIdentifier**(): [`ChainIdentifier`](ChainIdentifier.md) + +Gets the chain-specific identifier of this contract. + +#### Returns + +[`ChainIdentifier`](ChainIdentifier.md) + +#### Defined in + +[lib/contracts/bridge.ts:20](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L20) + +___ + +### pendingRedemptions + +▸ **pendingRedemptions**(`walletPublicKey`, `redeemerOutputScript`): `Promise`\<[`RedemptionRequest`](RedemptionRequest.md)\> + +Gets a pending redemption from the on-chain contract. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `walletPublicKey` | [`Hex`](../classes/Hex.md) | Bitcoin public key of the wallet the request is targeted to. Must be in the compressed form (33 bytes long with 02 or 03 prefix). | +| `redeemerOutputScript` | [`Hex`](../classes/Hex.md) | The redeemer output script the redeemed funds are supposed to be locked on. Must not be prepended with length. | + +#### Returns + +`Promise`\<[`RedemptionRequest`](RedemptionRequest.md)\> + +Promise with the pending redemption. + +#### Defined in + +[lib/contracts/bridge.ts:124](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L124) + +___ + +### requestRedemption + +▸ **requestRedemption**(`walletPublicKey`, `mainUtxo`, `redeemerOutputScript`, `amount`): `Promise`\<[`Hex`](../classes/Hex.md)\> + +Requests a redemption from the on-chain contract. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `walletPublicKey` | [`Hex`](../classes/Hex.md) | The Bitcoin public key of the wallet. Must be in the compressed form (33 bytes long with 02 or 03 prefix). | +| `mainUtxo` | [`BitcoinUtxo`](../README.md#bitcoinutxo) | The main UTXO of the wallet. Must match the main UTXO held by the on-chain contract. | +| `redeemerOutputScript` | [`Hex`](../classes/Hex.md) | The output script that the redeemed funds will be locked to. Must not be prepended with length. | +| `amount` | `BigNumber` | The amount to be redeemed in satoshis. | + +#### Returns + +`Promise`\<[`Hex`](../classes/Hex.md)\> + +Transaction hash of the request redemption transaction. + +#### Defined in + +[lib/contracts/bridge.ts:84](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L84) + +___ + +### revealDeposit + +▸ **revealDeposit**(`depositTx`, `depositOutputIndex`, `deposit`, `vault?`): `Promise`\<[`Hex`](../classes/Hex.md)\> + +Reveals a given deposit to the on-chain contract. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `depositTx` | [`BitcoinRawTxVectors`](BitcoinRawTxVectors.md) | Deposit transaction data | +| `depositOutputIndex` | `number` | Index of the deposit transaction output that funds the revealed deposit | +| `deposit` | [`DepositReceipt`](DepositReceipt.md) | Data of the revealed deposit | +| `vault?` | [`ChainIdentifier`](ChainIdentifier.md) | Optional parameter denoting the vault the given deposit should be routed to | + +#### Returns + +`Promise`\<[`Hex`](../classes/Hex.md)\> + +Transaction hash of the reveal deposit transaction. + +#### Defined in + +[lib/contracts/bridge.ts:54](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L54) + +___ + +### submitDepositSweepProof + +▸ **submitDepositSweepProof**(`sweepTx`, `sweepProof`, `mainUtxo`, `vault?`): `Promise`\<[`Hex`](../classes/Hex.md)\> + +Submits a deposit sweep transaction proof to the on-chain contract. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `sweepTx` | [`BitcoinRawTxVectors`](BitcoinRawTxVectors.md) | Sweep transaction data. | +| `sweepProof` | [`BitcoinSpvProof`](BitcoinSpvProof.md) | Sweep proof data. | +| `mainUtxo` | [`BitcoinUtxo`](../README.md#bitcoinutxo) | Data of the wallet's main UTXO. | +| `vault?` | [`ChainIdentifier`](ChainIdentifier.md) | Optional identifier of the vault the swept deposits should be routed in. | + +#### Returns + +`Promise`\<[`Hex`](../classes/Hex.md)\> + +Transaction hash of the submit deposit sweep proof transaction. + +#### Defined in + +[lib/contracts/bridge.ts:37](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L37) + +___ + +### submitRedemptionProof + +▸ **submitRedemptionProof**(`redemptionTx`, `redemptionProof`, `mainUtxo`, `walletPublicKey`): `Promise`\<[`Hex`](../classes/Hex.md)\> + +Submits a redemption transaction proof to the on-chain contract. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `redemptionTx` | [`BitcoinRawTxVectors`](BitcoinRawTxVectors.md) | Redemption transaction data | +| `redemptionProof` | [`BitcoinSpvProof`](BitcoinSpvProof.md) | Redemption proof data | +| `mainUtxo` | [`BitcoinUtxo`](../README.md#bitcoinutxo) | Data of the wallet's main UTXO | +| `walletPublicKey` | [`Hex`](../classes/Hex.md) | Bitcoin public key of the wallet. Must be in the compressed form (33 bytes long with 02 or 03 prefix). | + +#### Returns + +`Promise`\<[`Hex`](../classes/Hex.md)\> + +Transaction hash of the submit redemption proof transaction. + +#### Defined in + +[lib/contracts/bridge.ts:100](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L100) + +___ + +### timedOutRedemptions + +▸ **timedOutRedemptions**(`walletPublicKey`, `redeemerOutputScript`): `Promise`\<[`RedemptionRequest`](RedemptionRequest.md)\> + +Gets a timed-out redemption from the on-chain contract. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `walletPublicKey` | [`Hex`](../classes/Hex.md) | Bitcoin public key of the wallet the request is targeted to. Must be in the compressed form (33 bytes long with 02 or 03 prefix). | +| `redeemerOutputScript` | [`Hex`](../classes/Hex.md) | The redeemer output script the redeemed funds are supposed to be locked on. Must not be prepended with length. | + +#### Returns + +`Promise`\<[`RedemptionRequest`](RedemptionRequest.md)\> + +Promise with the pending redemption. + +#### Defined in + +[lib/contracts/bridge.ts:138](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L138) + +___ + +### txProofDifficultyFactor + +▸ **txProofDifficultyFactor**(): `Promise`\<`number`\> + +Gets transaction proof difficulty factor from the on-chain contract. + +#### Returns + +`Promise`\<`number`\> + +Proof difficulty factor. + +**`Dev`** + +This number signifies how many confirmations a transaction has to + accumulate before it can be proven on-chain. + +#### Defined in + +[lib/contracts/bridge.ts:113](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L113) + +___ + +### walletRegistry + +▸ **walletRegistry**(): `Promise`\<[`WalletRegistry`](WalletRegistry.md)\> + +Returns the attached WalletRegistry instance. + +#### Returns + +`Promise`\<[`WalletRegistry`](WalletRegistry.md)\> + +#### Defined in + +[lib/contracts/bridge.ts:160](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L160) + +___ + +### wallets + +▸ **wallets**(`walletPublicKeyHash`): `Promise`\<[`Wallet`](Wallet.md)\> + +Gets details about a registered wallet. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `walletPublicKeyHash` | [`Hex`](../classes/Hex.md) | The 20-byte wallet public key hash (computed using Bitcoin HASH160 over the compressed ECDSA public key). | + +#### Returns + +`Promise`\<[`Wallet`](Wallet.md)\> + +Promise with the wallet details. + +#### Defined in + +[lib/contracts/bridge.ts:168](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L168) diff --git a/typescript/api-reference/interfaces/ChainEvent.md b/typescript/api-reference/interfaces/ChainEvent.md new file mode 100644 index 000000000..afc8f0b7a --- /dev/null +++ b/typescript/api-reference/interfaces/ChainEvent.md @@ -0,0 +1,47 @@ +# Interface: ChainEvent + +Represents a generic chain event. + +## Table of contents + +### Properties + +- [blockHash](ChainEvent.md#blockhash) +- [blockNumber](ChainEvent.md#blocknumber) +- [transactionHash](ChainEvent.md#transactionhash) + +## Properties + +### blockHash + +• **blockHash**: [`Hex`](../classes/Hex.md) + +Block hash of the event emission. + +#### Defined in + +[lib/contracts/chain-event.ts:14](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/chain-event.ts#L14) + +___ + +### blockNumber + +• **blockNumber**: `number` + +Block number of the event emission. + +#### Defined in + +[lib/contracts/chain-event.ts:10](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/chain-event.ts#L10) + +___ + +### transactionHash + +• **transactionHash**: [`Hex`](../classes/Hex.md) + +Transaction hash within which the event was emitted. + +#### Defined in + +[lib/contracts/chain-event.ts:18](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/chain-event.ts#L18) diff --git a/typescript/api-reference/interfaces/ChainIdentifier.md b/typescript/api-reference/interfaces/ChainIdentifier.md new file mode 100644 index 000000000..a5a08597a --- /dev/null +++ b/typescript/api-reference/interfaces/ChainIdentifier.md @@ -0,0 +1,51 @@ +# Interface: ChainIdentifier + +Represents a generic chain identifier. + +## Implemented by + +- [`EthereumAddress`](../classes/EthereumAddress.md) + +## Table of contents + +### Properties + +- [identifierHex](ChainIdentifier.md#identifierhex) + +### Methods + +- [equals](ChainIdentifier.md#equals) + +## Properties + +### identifierHex + +• **identifierHex**: `string` + +Identifier as an un-prefixed hex string. + +#### Defined in + +[lib/contracts/chain-identifier.ts:8](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/chain-identifier.ts#L8) + +## Methods + +### equals + +▸ **equals**(`identifier`): `boolean` + +Checks if two identifiers are equal. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `identifier` | [`ChainIdentifier`](ChainIdentifier.md) | Another identifier | + +#### Returns + +`boolean` + +#### Defined in + +[lib/contracts/chain-identifier.ts:14](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/chain-identifier.ts#L14) diff --git a/typescript/api-reference/interfaces/DepositReceipt.md b/typescript/api-reference/interfaces/DepositReceipt.md new file mode 100644 index 000000000..85f12c732 --- /dev/null +++ b/typescript/api-reference/interfaces/DepositReceipt.md @@ -0,0 +1,80 @@ +# Interface: DepositReceipt + +Represents a deposit receipt. The receipt holds all information required +to build a unique deposit address on Bitcoin chain. + +## Table of contents + +### Properties + +- [blindingFactor](DepositReceipt.md#blindingfactor) +- [depositor](DepositReceipt.md#depositor) +- [refundLocktime](DepositReceipt.md#refundlocktime) +- [refundPublicKeyHash](DepositReceipt.md#refundpublickeyhash) +- [walletPublicKeyHash](DepositReceipt.md#walletpublickeyhash) + +## Properties + +### blindingFactor + +• **blindingFactor**: [`Hex`](../classes/Hex.md) + +An 8-byte blinding factor. Must be unique for the given depositor, wallet +public key and refund public key. + +#### Defined in + +[lib/contracts/bridge.ts:198](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L198) + +___ + +### depositor + +• **depositor**: [`ChainIdentifier`](ChainIdentifier.md) + +Depositor's chain identifier. + +#### Defined in + +[lib/contracts/bridge.ts:192](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L192) + +___ + +### refundLocktime + +• **refundLocktime**: [`Hex`](../classes/Hex.md) + +A 4-byte little-endian refund locktime. + +#### Defined in + +[lib/contracts/bridge.ts:218](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L218) + +___ + +### refundPublicKeyHash + +• **refundPublicKeyHash**: [`Hex`](../classes/Hex.md) + +Public key hash that is meant to be used during deposit refund after the +locktime passes. + +You can use `computeHash160` function to get the hash from a public key. + +#### Defined in + +[lib/contracts/bridge.ts:213](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L213) + +___ + +### walletPublicKeyHash + +• **walletPublicKeyHash**: [`Hex`](../classes/Hex.md) + +Public key hash of the wallet that is meant to receive the deposit. + +You can use `computeHash160` function to get the hash from a public key. + +#### Defined in + +[lib/contracts/bridge.ts:205](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L205) diff --git a/typescript/api-reference/interfaces/DepositRequest.md b/typescript/api-reference/interfaces/DepositRequest.md new file mode 100644 index 000000000..89b9d6ea2 --- /dev/null +++ b/typescript/api-reference/interfaces/DepositRequest.md @@ -0,0 +1,88 @@ +# Interface: DepositRequest + +Represents a deposit request revealed to the on-chain bridge. + +## Table of contents + +### Properties + +- [amount](DepositRequest.md#amount) +- [depositor](DepositRequest.md#depositor) +- [revealedAt](DepositRequest.md#revealedat) +- [sweptAt](DepositRequest.md#sweptat) +- [treasuryFee](DepositRequest.md#treasuryfee) +- [vault](DepositRequest.md#vault) + +## Properties + +### amount + +• **amount**: `BigNumber` + +Deposit amount in satoshis. + +#### Defined in + +[lib/contracts/bridge.ts:257](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L257) + +___ + +### depositor + +• **depositor**: [`ChainIdentifier`](ChainIdentifier.md) + +Depositor's chain identifier. + +#### Defined in + +[lib/contracts/bridge.ts:252](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L252) + +___ + +### revealedAt + +• **revealedAt**: `number` + +UNIX timestamp the deposit was revealed at. + +#### Defined in + +[lib/contracts/bridge.ts:267](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L267) + +___ + +### sweptAt + +• **sweptAt**: `number` + +UNIX timestamp the request was swept at. If not swept yet, this parameter +should have zero as value. + +#### Defined in + +[lib/contracts/bridge.ts:272](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L272) + +___ + +### treasuryFee + +• **treasuryFee**: `BigNumber` + +Value of the treasury fee calculated for this revealed deposit. +Denominated in satoshi. + +#### Defined in + +[lib/contracts/bridge.ts:277](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L277) + +___ + +### vault + +• `Optional` **vault**: [`ChainIdentifier`](ChainIdentifier.md) + +Optional identifier of the vault the deposit should be routed in. + +#### Defined in + +[lib/contracts/bridge.ts:262](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L262) diff --git a/typescript/api-reference/interfaces/ElectrumCredentials.md b/typescript/api-reference/interfaces/ElectrumCredentials.md new file mode 100644 index 000000000..d72c5c2d4 --- /dev/null +++ b/typescript/api-reference/interfaces/ElectrumCredentials.md @@ -0,0 +1,47 @@ +# Interface: ElectrumCredentials + +Represents a set of credentials required to establish an Electrum connection. + +## Table of contents + +### Properties + +- [host](ElectrumCredentials.md#host) +- [port](ElectrumCredentials.md#port) +- [protocol](ElectrumCredentials.md#protocol) + +## Properties + +### host + +• **host**: `string` + +Host pointing to the Electrum server. + +#### Defined in + +[lib/electrum/client.ts:34](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L34) + +___ + +### port + +• **port**: `number` + +Port the Electrum server listens on. + +#### Defined in + +[lib/electrum/client.ts:38](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L38) + +___ + +### protocol + +• **protocol**: ``"tcp"`` \| ``"tls"`` \| ``"ssl"`` \| ``"ws"`` \| ``"wss"`` + +Protocol used by the Electrum server. + +#### Defined in + +[lib/electrum/client.ts:42](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/electrum/client.ts#L42) diff --git a/typescript/api-reference/interfaces/EthereumContractConfig.md b/typescript/api-reference/interfaces/EthereumContractConfig.md new file mode 100644 index 000000000..49b8d1b50 --- /dev/null +++ b/typescript/api-reference/interfaces/EthereumContractConfig.md @@ -0,0 +1,52 @@ +# Interface: EthereumContractConfig + +Represents a config set required to connect an Ethereum contract. + +## Table of contents + +### Properties + +- [address](EthereumContractConfig.md#address) +- [deployedAtBlockNumber](EthereumContractConfig.md#deployedatblocknumber) +- [signerOrProvider](EthereumContractConfig.md#signerorprovider) + +## Properties + +### address + +• `Optional` **address**: `string` + +Address of the Ethereum contract as a 0x-prefixed hex string. +Optional parameter, if not provided the value will be resolved from the +contract artifact. + +#### Defined in + +[lib/ethereum/adapter.ts:53](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L53) + +___ + +### deployedAtBlockNumber + +• `Optional` **deployedAtBlockNumber**: `number` + +Number of a block in which the contract was deployed. +Optional parameter, if not provided the value will be resolved from the +contract artifact. + +#### Defined in + +[lib/ethereum/adapter.ts:64](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L64) + +___ + +### signerOrProvider + +• **signerOrProvider**: `Signer` \| `Provider` + +Signer - will return a Contract which will act on behalf of that signer. The signer will sign all contract transactions. +Provider - will return a downgraded Contract which only has read-only access (i.e. constant calls) + +#### Defined in + +[lib/ethereum/adapter.ts:58](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/adapter.ts#L58) diff --git a/typescript/api-reference/interfaces/GetChainEvents.Function.md b/typescript/api-reference/interfaces/GetChainEvents.Function.md new file mode 100644 index 000000000..10c90d30d --- /dev/null +++ b/typescript/api-reference/interfaces/GetChainEvents.Function.md @@ -0,0 +1,36 @@ +# Interface: Function\ + +[GetChainEvents](../modules/GetChainEvents.md).Function + +Represents a generic function to get events emitted on the chain. + +## Type parameters + +| Name | Type | +| :------ | :------ | +| `T` | extends [`ChainEvent`](ChainEvent.md) | + +## Callable + +### Function + +▸ **Function**(`options?`, `...filterArgs`): `Promise`\<`T`[]\> + +Get emitted events. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `options?` | [`Options`](GetChainEvents.Options.md) | Options for getting events. | +| `...filterArgs` | `any`[] | Arguments for events filtering. | + +#### Returns + +`Promise`\<`T`[]\> + +Array of found events. + +#### Defined in + +[lib/contracts/chain-event.ts:60](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/chain-event.ts#L60) diff --git a/typescript/api-reference/interfaces/GetChainEvents.Options.md b/typescript/api-reference/interfaces/GetChainEvents.Options.md new file mode 100644 index 000000000..eb17d6ac7 --- /dev/null +++ b/typescript/api-reference/interfaces/GetChainEvents.Options.md @@ -0,0 +1,77 @@ +# Interface: Options + +[GetChainEvents](../modules/GetChainEvents.md).Options + +Represents generic options used for getting events from the chain. + +## Table of contents + +### Properties + +- [batchedQueryBlockInterval](GetChainEvents.Options.md#batchedqueryblockinterval) +- [fromBlock](GetChainEvents.Options.md#fromblock) +- [logger](GetChainEvents.Options.md#logger) +- [retries](GetChainEvents.Options.md#retries) +- [toBlock](GetChainEvents.Options.md#toblock) + +## Properties + +### batchedQueryBlockInterval + +• `Optional` **batchedQueryBlockInterval**: `number` + +Number of blocks for interval length in partial events pulls. + +#### Defined in + +[lib/contracts/chain-event.ts:43](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/chain-event.ts#L43) + +___ + +### fromBlock + +• `Optional` **fromBlock**: `number` + +Block number from which events should be queried. +If not defined a block number of a contract deployment is used. + +#### Defined in + +[lib/contracts/chain-event.ts:30](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/chain-event.ts#L30) + +___ + +### logger + +• `Optional` **logger**: [`ExecutionLoggerFn`](../README.md#executionloggerfn) + +A logger function to pass execution messages. + +#### Defined in + +[lib/contracts/chain-event.ts:47](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/chain-event.ts#L47) + +___ + +### retries + +• `Optional` **retries**: `number` + +Number of retries in case of an error getting the events. + +#### Defined in + +[lib/contracts/chain-event.ts:39](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/chain-event.ts#L39) + +___ + +### toBlock + +• `Optional` **toBlock**: `number` + +Block number to which events should be queried. +If not defined the latest block number will be used. + +#### Defined in + +[lib/contracts/chain-event.ts:35](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/chain-event.ts#L35) diff --git a/typescript/api-reference/interfaces/RedemptionRequest.md b/typescript/api-reference/interfaces/RedemptionRequest.md new file mode 100644 index 000000000..5202c498e --- /dev/null +++ b/typescript/api-reference/interfaces/RedemptionRequest.md @@ -0,0 +1,93 @@ +# Interface: RedemptionRequest + +Represents a redemption request. + +## Table of contents + +### Properties + +- [redeemer](RedemptionRequest.md#redeemer) +- [redeemerOutputScript](RedemptionRequest.md#redeemeroutputscript) +- [requestedAmount](RedemptionRequest.md#requestedamount) +- [requestedAt](RedemptionRequest.md#requestedat) +- [treasuryFee](RedemptionRequest.md#treasuryfee) +- [txMaxFee](RedemptionRequest.md#txmaxfee) + +## Properties + +### redeemer + +• **redeemer**: [`ChainIdentifier`](ChainIdentifier.md) + +On-chain identifier of the redeemer. + +#### Defined in + +[lib/contracts/bridge.ts:296](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L296) + +___ + +### redeemerOutputScript + +• **redeemerOutputScript**: [`Hex`](../classes/Hex.md) + +The output script the redeemed Bitcoin funds are locked to. It is not +prepended with length. + +#### Defined in + +[lib/contracts/bridge.ts:302](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L302) + +___ + +### requestedAmount + +• **requestedAmount**: `BigNumber` + +The amount of Bitcoins in satoshis that is requested to be redeemed. +The actual value of the output in the Bitcoin transaction will be decreased +by the sum of the fee share and the treasury fee for this particular output. + +#### Defined in + +[lib/contracts/bridge.ts:309](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L309) + +___ + +### requestedAt + +• **requestedAt**: `number` + +UNIX timestamp the request was created at. + +#### Defined in + +[lib/contracts/bridge.ts:328](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L328) + +___ + +### treasuryFee + +• **treasuryFee**: `BigNumber` + +The amount of Bitcoins in satoshis that is subtracted from the amount of +the redemption request and used to pay the treasury fee. +The value should be exactly equal to the value of treasury fee in the Bridge +on-chain contract at the time the redemption request was made. + +#### Defined in + +[lib/contracts/bridge.ts:317](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L317) + +___ + +### txMaxFee + +• **txMaxFee**: `BigNumber` + +The maximum amount of Bitcoins in satoshis that can be subtracted from the +redemption's `requestedAmount` to pay the transaction network fee. + +#### Defined in + +[lib/contracts/bridge.ts:323](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L323) diff --git a/typescript/api-reference/interfaces/TBTCToken.md b/typescript/api-reference/interfaces/TBTCToken.md new file mode 100644 index 000000000..3c8e0a182 --- /dev/null +++ b/typescript/api-reference/interfaces/TBTCToken.md @@ -0,0 +1,85 @@ +# Interface: TBTCToken + +Interface for communication with the TBTC v2 token on-chain contract. + +## Implemented by + +- [`EthereumTBTCToken`](../classes/EthereumTBTCToken.md) + +## Table of contents + +### Methods + +- [getChainIdentifier](TBTCToken.md#getchainidentifier) +- [requestRedemption](TBTCToken.md#requestredemption) +- [totalSupply](TBTCToken.md#totalsupply) + +## Methods + +### getChainIdentifier + +▸ **getChainIdentifier**(): [`ChainIdentifier`](ChainIdentifier.md) + +Gets the chain-specific identifier of this contract. + +#### Returns + +[`ChainIdentifier`](ChainIdentifier.md) + +#### Defined in + +[lib/contracts/tbtc-token.ts:13](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/tbtc-token.ts#L13) + +___ + +### requestRedemption + +▸ **requestRedemption**(`walletPublicKey`, `mainUtxo`, `redeemerOutputScript`, `amount`): `Promise`\<[`Hex`](../classes/Hex.md)\> + +Requests redemption in one transaction using the `approveAndCall` function +from the tBTC on-chain token contract. Then the tBTC token contract calls +the `receiveApproval` function from the `TBTCVault` contract which burns +tBTC tokens and requests redemption. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `walletPublicKey` | [`Hex`](../classes/Hex.md) | The Bitcoin public key of the wallet. Must be in the compressed form (33 bytes long with 02 or 03 prefix). | +| `mainUtxo` | [`BitcoinUtxo`](../README.md#bitcoinutxo) | The main UTXO of the wallet. Must match the main UTXO held by the on-chain Bridge contract. | +| `redeemerOutputScript` | [`Hex`](../classes/Hex.md) | The output script that the redeemed funds will be locked to. Must not be prepended with length. | +| `amount` | `BigNumber` | The amount to be redeemed with the precision of the tBTC on-chain token contract. | + +#### Returns + +`Promise`\<[`Hex`](../classes/Hex.md)\> + +Transaction hash of the approve and call transaction. + +#### Defined in + +[lib/contracts/tbtc-token.ts:40](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/tbtc-token.ts#L40) + +___ + +### totalSupply + +▸ **totalSupply**(`blockNumber?`): `Promise`\<`BigNumber`\> + +Gets the total supply of the TBTC v2 token. The returned value is in +ERC 1e18 precision, it has to be converted before using as Bitcoin value +with 1e8 precision in satoshi. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `blockNumber?` | `number` | Optional parameter determining the block the total supply should be fetched for. If this parameter is not set, the total supply is taken for the latest block. | + +#### Returns + +`Promise`\<`BigNumber`\> + +#### Defined in + +[lib/contracts/tbtc-token.ts:23](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/tbtc-token.ts#L23) diff --git a/typescript/api-reference/interfaces/TBTCVault.md b/typescript/api-reference/interfaces/TBTCVault.md new file mode 100644 index 000000000..c7bead2a0 --- /dev/null +++ b/typescript/api-reference/interfaces/TBTCVault.md @@ -0,0 +1,274 @@ +# Interface: TBTCVault + +Interface for communication with the TBTCVault on-chain contract. + +## Implemented by + +- [`EthereumTBTCVault`](../classes/EthereumTBTCVault.md) + +## Table of contents + +### Properties + +- [getOptimisticMintingCancelledEvents](TBTCVault.md#getoptimisticmintingcancelledevents) +- [getOptimisticMintingFinalizedEvents](TBTCVault.md#getoptimisticmintingfinalizedevents) +- [getOptimisticMintingRequestedEvents](TBTCVault.md#getoptimisticmintingrequestedevents) + +### Methods + +- [cancelOptimisticMint](TBTCVault.md#canceloptimisticmint) +- [finalizeOptimisticMint](TBTCVault.md#finalizeoptimisticmint) +- [getChainIdentifier](TBTCVault.md#getchainidentifier) +- [getMinters](TBTCVault.md#getminters) +- [isGuardian](TBTCVault.md#isguardian) +- [isMinter](TBTCVault.md#isminter) +- [optimisticMintingDelay](TBTCVault.md#optimisticmintingdelay) +- [optimisticMintingRequests](TBTCVault.md#optimisticmintingrequests) +- [requestOptimisticMint](TBTCVault.md#requestoptimisticmint) + +## Properties + +### getOptimisticMintingCancelledEvents + +• **getOptimisticMintingCancelledEvents**: [`Function`](GetChainEvents.Function.md)\<[`OptimisticMintingCancelledEvent`](../README.md#optimisticmintingcancelledevent)\> + +Get emitted OptimisticMintingCancelled events. + +**`See`** + +GetEventsFunction + +#### Defined in + +[lib/contracts/tbtc-vault.ts:107](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/tbtc-vault.ts#L107) + +___ + +### getOptimisticMintingFinalizedEvents + +• **getOptimisticMintingFinalizedEvents**: [`Function`](GetChainEvents.Function.md)\<[`OptimisticMintingFinalizedEvent`](../README.md#optimisticmintingfinalizedevent)\> + +Get emitted OptimisticMintingFinalized events. + +**`See`** + +GetEventsFunction + +#### Defined in + +[lib/contracts/tbtc-vault.ts:113](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/tbtc-vault.ts#L113) + +___ + +### getOptimisticMintingRequestedEvents + +• **getOptimisticMintingRequestedEvents**: [`Function`](GetChainEvents.Function.md)\<[`OptimisticMintingRequestedEvent`](../README.md#optimisticmintingrequestedevent)\> + +Get emitted OptimisticMintingRequested events. + +**`See`** + +GetEventsFunction + +#### Defined in + +[lib/contracts/tbtc-vault.ts:101](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/tbtc-vault.ts#L101) + +## Methods + +### cancelOptimisticMint + +▸ **cancelOptimisticMint**(`depositTxHash`, `depositOutputIndex`): `Promise`\<[`Hex`](../classes/Hex.md)\> + +Cancels optimistic minting for a deposit in an on-chain contract. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `depositTxHash` | [`BitcoinTxHash`](../classes/BitcoinTxHash.md) | The revealed deposit transaction's hash. | +| `depositOutputIndex` | `number` | Index of the deposit transaction output that funds the revealed deposit. | + +#### Returns + +`Promise`\<[`Hex`](../classes/Hex.md)\> + +Transaction hash of the optimistic mint cancel transaction. + +#### Defined in + +[lib/contracts/tbtc-vault.ts:67](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/tbtc-vault.ts#L67) + +___ + +### finalizeOptimisticMint + +▸ **finalizeOptimisticMint**(`depositTxHash`, `depositOutputIndex`): `Promise`\<[`Hex`](../classes/Hex.md)\> + +Finalizes optimistic minting for a deposit in an on-chain contract. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `depositTxHash` | [`BitcoinTxHash`](../classes/BitcoinTxHash.md) | The revealed deposit transaction's hash. | +| `depositOutputIndex` | `number` | Index of the deposit transaction output that funds the revealed deposit. | + +#### Returns + +`Promise`\<[`Hex`](../classes/Hex.md)\> + +Transaction hash of the optimistic mint finalize transaction. + +#### Defined in + +[lib/contracts/tbtc-vault.ts:80](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/tbtc-vault.ts#L80) + +___ + +### getChainIdentifier + +▸ **getChainIdentifier**(): [`ChainIdentifier`](ChainIdentifier.md) + +Gets the chain-specific identifier of this contract. + +#### Returns + +[`ChainIdentifier`](ChainIdentifier.md) + +#### Defined in + +[lib/contracts/tbtc-vault.ts:14](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/tbtc-vault.ts#L14) + +___ + +### getMinters + +▸ **getMinters**(): `Promise`\<[`ChainIdentifier`](ChainIdentifier.md)[]\> + +Gets currently registered minters. + +#### Returns + +`Promise`\<[`ChainIdentifier`](ChainIdentifier.md)[]\> + +Array containing identifiers of all currently registered minters. + +#### Defined in + +[lib/contracts/tbtc-vault.ts:30](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/tbtc-vault.ts#L30) + +___ + +### isGuardian + +▸ **isGuardian**(`identifier`): `Promise`\<`boolean`\> + +Checks if given identifier is registered as guardian. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `identifier` | [`ChainIdentifier`](ChainIdentifier.md) | Chain identifier to check. | + +#### Returns + +`Promise`\<`boolean`\> + +#### Defined in + +[lib/contracts/tbtc-vault.ts:44](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/tbtc-vault.ts#L44) + +___ + +### isMinter + +▸ **isMinter**(`identifier`): `Promise`\<`boolean`\> + +Checks if given identifier is registered as minter. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `identifier` | [`ChainIdentifier`](ChainIdentifier.md) | Chain identifier to check. | + +#### Returns + +`Promise`\<`boolean`\> + +#### Defined in + +[lib/contracts/tbtc-vault.ts:37](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/tbtc-vault.ts#L37) + +___ + +### optimisticMintingDelay + +▸ **optimisticMintingDelay**(): `Promise`\<`number`\> + +Gets optimistic minting delay. + +The time that needs to pass between the moment the optimistic minting is +requested and the moment optimistic minting is finalized with minting TBTC. + +#### Returns + +`Promise`\<`number`\> + +Optimistic Minting Delay in seconds. + +#### Defined in + +[lib/contracts/tbtc-vault.ts:23](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/tbtc-vault.ts#L23) + +___ + +### optimisticMintingRequests + +▸ **optimisticMintingRequests**(`depositTxHash`, `depositOutputIndex`): `Promise`\<[`OptimisticMintingRequest`](../README.md#optimisticmintingrequest)\> + +Gets optimistic minting request for a deposit. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `depositTxHash` | [`BitcoinTxHash`](../classes/BitcoinTxHash.md) | The revealed deposit transaction's hash. | +| `depositOutputIndex` | `number` | Index of the deposit transaction output that funds the revealed deposit. | + +#### Returns + +`Promise`\<[`OptimisticMintingRequest`](../README.md#optimisticmintingrequest)\> + +Optimistic minting request. + +#### Defined in + +[lib/contracts/tbtc-vault.ts:92](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/tbtc-vault.ts#L92) + +___ + +### requestOptimisticMint + +▸ **requestOptimisticMint**(`depositTxHash`, `depositOutputIndex`): `Promise`\<[`Hex`](../classes/Hex.md)\> + +Requests optimistic minting for a deposit in an on-chain contract. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `depositTxHash` | [`BitcoinTxHash`](../classes/BitcoinTxHash.md) | The revealed deposit transaction's hash. | +| `depositOutputIndex` | `number` | Index of the deposit transaction output that funds the revealed deposit. | + +#### Returns + +`Promise`\<[`Hex`](../classes/Hex.md)\> + +Transaction hash of the optimistic mint request transaction. + +#### Defined in + +[lib/contracts/tbtc-vault.ts:54](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/tbtc-vault.ts#L54) diff --git a/typescript/api-reference/interfaces/Wallet.md b/typescript/api-reference/interfaces/Wallet.md new file mode 100644 index 000000000..38cb250d1 --- /dev/null +++ b/typescript/api-reference/interfaces/Wallet.md @@ -0,0 +1,139 @@ +# Interface: Wallet + +Represents a deposit. + +## Table of contents + +### Properties + +- [closingStartedAt](Wallet.md#closingstartedat) +- [createdAt](Wallet.md#createdat) +- [ecdsaWalletID](Wallet.md#ecdsawalletid) +- [mainUtxoHash](Wallet.md#mainutxohash) +- [movingFundsRequestedAt](Wallet.md#movingfundsrequestedat) +- [movingFundsTargetWalletsCommitmentHash](Wallet.md#movingfundstargetwalletscommitmenthash) +- [pendingMovedFundsSweepRequestsCount](Wallet.md#pendingmovedfundssweeprequestscount) +- [pendingRedemptionsValue](Wallet.md#pendingredemptionsvalue) +- [state](Wallet.md#state) +- [walletPublicKey](Wallet.md#walletpublickey) + +## Properties + +### closingStartedAt + +• **closingStartedAt**: `number` + +UNIX timestamp indicating the moment the wallet's closing period started. + +#### Defined in + +[lib/contracts/bridge.ts:427](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L427) + +___ + +### createdAt + +• **createdAt**: `number` + +UNIX timestamp the wallet was created at. + +#### Defined in + +[lib/contracts/bridge.ts:418](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L418) + +___ + +### ecdsaWalletID + +• **ecdsaWalletID**: [`Hex`](../classes/Hex.md) + +Identifier of a ECDSA Wallet registered in the ECDSA Wallet Registry. + +#### Defined in + +[lib/contracts/bridge.ts:402](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L402) + +___ + +### mainUtxoHash + +• **mainUtxoHash**: [`Hex`](../classes/Hex.md) + +Latest wallet's main UTXO hash. + +#### Defined in + +[lib/contracts/bridge.ts:410](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L410) + +___ + +### movingFundsRequestedAt + +• **movingFundsRequestedAt**: `number` + +UNIX timestamp indicating the moment the wallet was requested to move their +funds. + +#### Defined in + +[lib/contracts/bridge.ts:423](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L423) + +___ + +### movingFundsTargetWalletsCommitmentHash + +• **movingFundsTargetWalletsCommitmentHash**: [`Hex`](../classes/Hex.md) + +Moving funds target wallet commitment submitted by the wallet. + +#### Defined in + +[lib/contracts/bridge.ts:439](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L439) + +___ + +### pendingMovedFundsSweepRequestsCount + +• **pendingMovedFundsSweepRequestsCount**: `number` + +Total count of pending moved funds sweep requests targeting this wallet. + +#### Defined in + +[lib/contracts/bridge.ts:431](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L431) + +___ + +### pendingRedemptionsValue + +• **pendingRedemptionsValue**: `BigNumber` + +The total redeemable value of pending redemption requests targeting that wallet. + +#### Defined in + +[lib/contracts/bridge.ts:414](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L414) + +___ + +### state + +• **state**: [`WalletState`](../enums/WalletState-1.md) + +Current state of the wallet. + +#### Defined in + +[lib/contracts/bridge.ts:435](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L435) + +___ + +### walletPublicKey + +• **walletPublicKey**: [`Hex`](../classes/Hex.md) + +Compressed public key of the ECDSA Wallet. + +#### Defined in + +[lib/contracts/bridge.ts:406](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L406) diff --git a/typescript/api-reference/interfaces/WalletRegistry.md b/typescript/api-reference/interfaces/WalletRegistry.md new file mode 100644 index 000000000..2fb0500fc --- /dev/null +++ b/typescript/api-reference/interfaces/WalletRegistry.md @@ -0,0 +1,108 @@ +# Interface: WalletRegistry + +Interface for communication with the WalletRegistry on-chain contract. + +## Implemented by + +- [`EthereumWalletRegistry`](../classes/EthereumWalletRegistry.md) + +## Table of contents + +### Properties + +- [getDkgResultApprovedEvents](WalletRegistry.md#getdkgresultapprovedevents) +- [getDkgResultChallengedEvents](WalletRegistry.md#getdkgresultchallengedevents) +- [getDkgResultSubmittedEvents](WalletRegistry.md#getdkgresultsubmittedevents) + +### Methods + +- [getChainIdentifier](WalletRegistry.md#getchainidentifier) +- [getWalletPublicKey](WalletRegistry.md#getwalletpublickey) + +## Properties + +### getDkgResultApprovedEvents + +• **getDkgResultApprovedEvents**: [`Function`](GetChainEvents.Function.md)\<[`DkgResultApprovedEvent`](../README.md#dkgresultapprovedevent)\> + +Get emitted DkgResultApprovedEvent events. + +**`See`** + +GetEventsFunction + +#### Defined in + +[lib/contracts/wallet-registry.ts:32](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/wallet-registry.ts#L32) + +___ + +### getDkgResultChallengedEvents + +• **getDkgResultChallengedEvents**: [`Function`](GetChainEvents.Function.md)\<[`DkgResultChallengedEvent`](../README.md#dkgresultchallengedevent)\> + +Get emitted DkgResultChallengedEvent events. + +**`See`** + +GetEventsFunction + +#### Defined in + +[lib/contracts/wallet-registry.ts:38](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/wallet-registry.ts#L38) + +___ + +### getDkgResultSubmittedEvents + +• **getDkgResultSubmittedEvents**: [`Function`](GetChainEvents.Function.md)\<[`DkgResultSubmittedEvent`](../README.md#dkgresultsubmittedevent)\> + +Get emitted DkgResultSubmittedEvent events. + +**`See`** + +GetEventsFunction + +#### Defined in + +[lib/contracts/wallet-registry.ts:26](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/wallet-registry.ts#L26) + +## Methods + +### getChainIdentifier + +▸ **getChainIdentifier**(): [`ChainIdentifier`](ChainIdentifier.md) + +Gets the chain-specific identifier of this contract. + +#### Returns + +[`ChainIdentifier`](ChainIdentifier.md) + +#### Defined in + +[lib/contracts/wallet-registry.ts:13](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/wallet-registry.ts#L13) + +___ + +### getWalletPublicKey + +▸ **getWalletPublicKey**(`walletID`): `Promise`\<[`Hex`](../classes/Hex.md)\> + +Gets the public key for the given wallet. + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `walletID` | [`Hex`](../classes/Hex.md) | ID of the wallet. | + +#### Returns + +`Promise`\<[`Hex`](../classes/Hex.md)\> + +Uncompressed public key without the 04 prefix. + +#### Defined in + +[lib/contracts/wallet-registry.ts:20](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/wallet-registry.ts#L20) diff --git a/typescript/api-reference/modules/BitcoinNetwork.md b/typescript/api-reference/modules/BitcoinNetwork.md new file mode 100644 index 000000000..369c84e00 --- /dev/null +++ b/typescript/api-reference/modules/BitcoinNetwork.md @@ -0,0 +1,33 @@ +# Namespace: BitcoinNetwork + +## Table of contents + +### Functions + +- [fromGenesisHash](BitcoinNetwork.md#fromgenesishash) + +## Functions + +### fromGenesisHash + +▸ **fromGenesisHash**(`hash`): [`BitcoinNetwork`](../enums/BitcoinNetwork-1.md) + +Gets Bitcoin Network type by comparing a provided hash to known +[genesis block hashes](https://en.bitcoin.it/wiki/Genesis_block). +Returns [BitcoinNetwork.Unknown](../enums/BitcoinNetwork-1.md#unknown) + +#### Parameters + +| Name | Type | Description | +| :------ | :------ | :------ | +| `hash` | [`Hex`](../classes/Hex.md) | Hash of a block. | + +#### Returns + +[`BitcoinNetwork`](../enums/BitcoinNetwork-1.md) + +Bitcoin Network. + +#### Defined in + +[lib/bitcoin/network.ts:33](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/bitcoin/network.ts#L33) diff --git a/typescript/api-reference/modules/GetChainEvents.md b/typescript/api-reference/modules/GetChainEvents.md new file mode 100644 index 000000000..6291419e5 --- /dev/null +++ b/typescript/api-reference/modules/GetChainEvents.md @@ -0,0 +1,8 @@ +# Namespace: GetChainEvents + +## Table of contents + +### Interfaces + +- [Function](../interfaces/GetChainEvents.Function.md) +- [Options](../interfaces/GetChainEvents.Options.md) diff --git a/typescript/api-reference/modules/WalletState.md b/typescript/api-reference/modules/WalletState.md new file mode 100644 index 000000000..9a940a1b9 --- /dev/null +++ b/typescript/api-reference/modules/WalletState.md @@ -0,0 +1,27 @@ +# Namespace: WalletState + +## Table of contents + +### Functions + +- [parse](WalletState.md#parse) + +## Functions + +### parse + +▸ **parse**(`val`): [`WalletState`](../enums/WalletState-1.md) + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `val` | `number` | + +#### Returns + +[`WalletState`](../enums/WalletState-1.md) + +#### Defined in + +[lib/contracts/bridge.ts:384](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L384) diff --git a/typescript/package.json b/typescript/package.json index 31c54ba3e..d0d068e1b 100644 --- a/typescript/package.json +++ b/typescript/package.json @@ -1,6 +1,6 @@ { "name": "@keep-network/tbtc-v2.ts", - "version": "2.1.0-dev", + "version": "2.3.0-dev", "license": "MIT", "main": "dist/src/index.js", "types": "dist/src/index.d.ts", @@ -13,7 +13,8 @@ "test": "mocha --exit --recursive 'test/**/*.test.ts'", "typechain": "rm -rf ./typechain && for i in $npm_package_config_contracts; do typechain --target ethers-v5 --out-dir ./typechain $i; done && rm ./typechain/index.ts", "build": "npm run typechain && tsc --project tsconfig.build.json", - "dev": "tsc --project tsconfig.build.json --watch" + "dev": "tsc --project tsconfig.build.json --watch", + "docs": "typedoc --options typedoc.json" }, "files": [ "dist/", @@ -24,6 +25,7 @@ "contracts": "./node_modules/@keep-network/ecdsa/artifacts/WalletRegistry.json ./node_modules/@keep-network/tbtc-v2/artifacts/{Bridge,TBTCVault,TBTC}.json" }, "dependencies": { + "@bitcoinerlab/secp256k1": "^1.0.5", "@keep-network/ecdsa": "development", "@keep-network/tbtc-v2": "development", "bitcoinjs-lib": "^6.1.5", @@ -32,7 +34,6 @@ "electrum-client-js": "git+https://github.com/keep-network/electrum-client-js.git#v0.1.1", "ethers": "^5.5.2", "p-timeout": "^4.1.0", - "tiny-secp256k1": "^2.2.3", "wif": "2.0.6" }, "devDependencies": { @@ -42,7 +43,7 @@ "@types/chai": "^4.2.21", "@types/chai-as-promised": "^7.1.4", "@types/mocha": "^8.2.3", - "@types/node": "^16.3.1", + "@types/node": "^16.4.0", "@typescript-eslint/eslint-plugin": "^4.28.3", "@typescript-eslint/parser": "^4.28.3", "chai": "^4.3.4", @@ -53,11 +54,18 @@ "ethereum-waffle": "4.0.0-alpha.25", "mocha": "^9.0.2", "prettier": "^2.3.2", - "ts-node": "^10.1.0", + "ts-node": "^10.8.0", "typechain": "^8.1.1", - "typescript": "^4.3.5" + "typedoc": "^0.25.3", + "typedoc-plugin-markdown": "^3.17.0", + "typescript": "^4.6.0" }, "engines": { "node": ">=16" + }, + "repository": { + "type": "git", + "url": "https://github.com/keep-network/tbtc-v2.git", + "directory": "typescript" } } diff --git a/typescript/scripts/refund.ts b/typescript/scripts/refund.ts index 11931b978..27a941b04 100644 --- a/typescript/scripts/refund.ts +++ b/typescript/scripts/refund.ts @@ -9,6 +9,7 @@ import { DepositScript, ElectrumClient, ElectrumCredentials, + Hex, } from "../src" program @@ -60,15 +61,15 @@ const depositJson = JSON.parse(fs.readFileSync(depositJsonPath, "utf-8")) const deposit: DepositReceipt = { depositor: depositJson.depositor, - walletPublicKeyHash: depositJson.walletPublicKeyHash, - refundPublicKeyHash: depositJson.refundPublicKeyHash, - blindingFactor: depositJson.blindingFactor, - refundLocktime: depositJson.refundLocktime, + walletPublicKeyHash: Hex.from(depositJson.walletPublicKeyHash), + refundPublicKeyHash: Hex.from(depositJson.refundPublicKeyHash), + blindingFactor: Hex.from(depositJson.blindingFactor), + refundLocktime: Hex.from(depositJson.refundLocktime), } const recoveryAddress = depositJson.btcRecoveryAddress console.log("======= refund provided data ========") -console.log("deposit JSON: ", deposit) +console.log("deposit JSON: ", depositJson) console.log("deposit recovery amount: ", refundAmount) console.log("deposit transaction ID: ", transactionId) console.log("deposit transaction index: ", transactionIndex) diff --git a/typescript/src/index.ts b/typescript/src/index.ts index 628275200..2ee4bcafd 100644 --- a/typescript/src/index.ts +++ b/typescript/src/index.ts @@ -12,6 +12,3 @@ export * from "./services/redemptions" // Export the entrypoint module. export * from "./services/tbtc" - -// TODO: Replace all properties that are expected to be un-prefixed hexadecimal -// strings with a Hex type to increase API consistency. diff --git a/typescript/src/lib/bitcoin/address.ts b/typescript/src/lib/bitcoin/address.ts index 36f660ba2..e8dd25c5a 100644 --- a/typescript/src/lib/bitcoin/address.ts +++ b/typescript/src/lib/bitcoin/address.ts @@ -29,20 +29,19 @@ function publicKeyToAddress( /** * Converts a public key hash into a P2PKH/P2WPKH address. - * @param publicKeyHash Public key hash that will be encoded. Must be an - * unprefixed hex string (without 0x prefix). + * @param publicKeyHash Public key hash that will be encoded. * @param witness If true, a witness public key hash will be encoded and * P2WPKH address will be returned. Returns P2PKH address otherwise * @param bitcoinNetwork Network the address should be encoded for. - * @returns P2PKH or P2WPKH address encoded from the given public key hash + * @returns P2PKH or P2WPKH address encoded from the given public key hash. * @throws Throws an error if network is not supported. */ function publicKeyHashToAddress( - publicKeyHash: string, + publicKeyHash: Hex, witness: boolean, bitcoinNetwork: BitcoinNetwork ): string { - const hash = Buffer.from(publicKeyHash, "hex") + const hash = publicKeyHash.toBuffer() const network = toBitcoinJsLibNetwork(bitcoinNetwork) return witness ? payments.p2wpkh({ hash, network }).address! @@ -54,27 +53,25 @@ function publicKeyHashToAddress( * provided address is not PKH-based. * @param address P2PKH or P2WPKH address that will be decoded. * @param bitcoinNetwork Network the address should be decoded for. - * @returns Public key hash decoded from the address. This will be an unprefixed - * hex string (without 0x prefix). + * @returns Public key hash decoded from the address. */ function addressToPublicKeyHash( address: string, bitcoinNetwork: BitcoinNetwork -): string { +): Hex { const network = toBitcoinJsLibNetwork(bitcoinNetwork) try { // Try extracting hash from P2PKH address. - const hash = payments.p2pkh({ address: address, network }).hash! - return hash.toString("hex") + return Hex.from(payments.p2pkh({ address: address, network }).hash!) } catch (err) {} try { // Try extracting hash from P2WPKH address. - const hash = payments.p2wpkh({ address: address, network }).hash! - return hash.toString("hex") + return Hex.from(payments.p2wpkh({ address: address, network }).hash!) } catch (err) {} + // If neither of them succeeded, throw an error. throw new Error("Address must be P2PKH or P2WPKH valid for given network") } @@ -82,7 +79,7 @@ function addressToPublicKeyHash( * Converts an address to the respective output script. * @param address BTC address. * @param bitcoinNetwork Bitcoin network corresponding to the address. - * @returns The un-prefixed and not prepended with length output script. + * @returns The output script not prepended with length. */ function addressToOutputScript( address: string, @@ -95,7 +92,7 @@ function addressToOutputScript( /** * Converts an output script to the respective network-specific address. - * @param script The unprefixed and not prepended with length output script. + * @param script The output script not prepended with length. * @param bitcoinNetwork Bitcoin network the address should be produced for. * @returns The Bitcoin address. */ diff --git a/typescript/src/lib/bitcoin/client.ts b/typescript/src/lib/bitcoin/client.ts index 6e3d512fe..483563d5f 100644 --- a/typescript/src/lib/bitcoin/client.ts +++ b/typescript/src/lib/bitcoin/client.ts @@ -1,6 +1,7 @@ import { BitcoinNetwork } from "./network" import { BitcoinRawTx, BitcoinTx, BitcoinTxHash, BitcoinUtxo } from "./tx" import { BitcoinTxMerkleBranch } from "./spv" +import { Hex } from "../../lib/utils" /** * Represents a Bitcoin client. @@ -53,6 +54,20 @@ export interface BitcoinClient { */ getTransactionConfirmations(transactionHash: BitcoinTxHash): Promise + /** + * Gets hashes of confirmed transactions that pay the given public key hash + * using either a P2PKH or P2WPKH script. The returned transactions hashes are + * ordered by block height in the ascending order, i.e. the latest transaction + * hash is at the end of the list. The returned list does not contain + * unconfirmed transactions hashes living in the mempool at the moment of + * request. + * @param publicKeyHash - Hash of the public key for which to find + * corresponding transaction hashes. + * @returns Array of confirmed transaction hashes related to the provided + * public key hash. + */ + getTxHashesForPublicKeyHash(publicKeyHash: Hex): Promise + /** * Gets height of the latest mined block. * @return Height of the last mined block. @@ -66,7 +81,7 @@ export interface BitcoinClient { * block. * @return Concatenation of block headers in a hexadecimal format. */ - getHeadersChain(blockHeight: number, chainLength: number): Promise + getHeadersChain(blockHeight: number, chainLength: number): Promise /** * Get Merkle branch for a given transaction. diff --git a/typescript/src/lib/bitcoin/ecdsa-key.ts b/typescript/src/lib/bitcoin/ecdsa-key.ts index f622490be..43d374dd5 100644 --- a/typescript/src/lib/bitcoin/ecdsa-key.ts +++ b/typescript/src/lib/bitcoin/ecdsa-key.ts @@ -1,7 +1,7 @@ import { BigNumber } from "ethers" import { Hex } from "../utils" import { ECPairFactory, ECPairInterface } from "ecpair" -import * as tinysecp from "tiny-secp256k1" +import * as tinysecp from "@bitcoinerlab/secp256k1" import { BitcoinNetwork, toBitcoinJsLibNetwork } from "./network" /** @@ -9,37 +9,36 @@ import { BitcoinNetwork, toBitcoinJsLibNetwork } from "./network" * @param publicKey - Public key that should be checked. * @returns True if the key is a compressed Bitcoin public key, false otherwise. */ -function isCompressedPublicKey(publicKey: string): boolean { +function isCompressedPublicKey(publicKey: Hex): boolean { + const publicKeyStr = publicKey.toString() + // Must have 33 bytes and 02 or 03 prefix. return ( - publicKey.length == 66 && - (publicKey.substring(0, 2) == "02" || publicKey.substring(0, 2) == "03") + publicKeyStr.length == 66 && + (publicKeyStr.substring(0, 2) == "02" || + publicKeyStr.substring(0, 2) == "03") ) } /** * Compresses the given uncompressed Bitcoin public key. - * @param publicKey Uncompressed 64-byte public key as an unprefixed hex string. + * @param publicKey Uncompressed 64-byte public key. * @returns Compressed 33-byte public key prefixed with 02 or 03. */ -function compressPublicKey(publicKey: string | Hex): string { - if (typeof publicKey === "string") { - publicKey = Hex.from(publicKey) - } - - publicKey = publicKey.toString() +function compressPublicKey(publicKey: Hex): string { + const publicKeyStr = publicKey.toString() // Must have 64 bytes and no prefix. - if (publicKey.length != 128) { + if (publicKeyStr.length != 128) { throw new Error( "The public key parameter must be 64-byte. Neither 0x nor 04 prefix is allowed" ) } // The X coordinate is the first 32 bytes. - const publicKeyX = publicKey.substring(0, 64) + const publicKeyX = publicKeyStr.substring(0, 64) // The Y coordinate is the next 32 bytes. - const publicKeyY = publicKey.substring(64) + const publicKeyY = publicKeyStr.substring(64) const prefix = BigNumber.from(`0x${publicKeyY}`).mod(2).eq(0) ? "02" : "03" @@ -59,7 +58,7 @@ export const BitcoinPublicKeyUtils = { * @param privateKey Private key that should be used to create the key pair. * Should be passed in the WIF format. * @param bitcoinNetwork Bitcoin network the given key pair is relevant for. - * @returns Bitcoin key ring. + * @returns Bitcoin key pair. */ function createKeyPair( privateKey: string, diff --git a/typescript/src/lib/bitcoin/hash.ts b/typescript/src/lib/bitcoin/hash.ts index 876e69888..12bfa698f 100644 --- a/typescript/src/lib/bitcoin/hash.ts +++ b/typescript/src/lib/bitcoin/hash.ts @@ -4,21 +4,19 @@ import { Hex } from "../utils" /** * Computes the HASH160 (i.e. RIPEMD160(SHA256(text))) for the given text. * @param text Text the HASH160 is computed for. - * @returns Hash as a 20-byte un-prefixed hex string. + * @returns 20-byte-long hash. */ -function computeHash160(text: string): string { - const sha256Hash = utils.sha256( - Hex.from(Buffer.from(text, "hex")).toPrefixedString() - ) +function computeHash160(text: Hex): Hex { + const sha256Hash = utils.sha256(text.toPrefixedString()) const hash160 = utils.ripemd160(sha256Hash) - return Hex.from(hash160).toString() + return Hex.from(hash160) } /** * Computes the double SHA256 for the given text. * @param text Text the double SHA256 is computed for. - * @returns Hash as a 32-byte un-prefixed hex string. + * @returns 32-byte-long hash. * @dev Do not confuse it with computeSha256 which computes single SHA256. */ function computeHash256(text: Hex): Hex { @@ -40,7 +38,7 @@ function hashLEToBigNumber(hash: Hex): BigNumber { /** * Computes the single SHA256 for the given text. * @param text Text the single SHA256 is computed for. - * @returns Hash as a 32-byte un-prefixed hex string. + * @returns 32-byte-long hash. * @dev Do not confuse it with computeHash256 which computes double SHA256. */ function computeSha256(text: Hex): Hex { diff --git a/typescript/src/lib/bitcoin/header.ts b/typescript/src/lib/bitcoin/header.ts index 99faa237a..99f8f10cf 100644 --- a/typescript/src/lib/bitcoin/header.ts +++ b/typescript/src/lib/bitcoin/header.ts @@ -89,16 +89,15 @@ function deserializeHeader(rawHeader: Hex): BitcoinHeader { * @param rawHeadersChain - Raw Bitcoin block headers chain. * @returns Deserialized Bitcoin block headers. */ -function deserializeHeadersChain(rawHeadersChain: string): BitcoinHeader[] { - if (rawHeadersChain.length % 160 !== 0) { +function deserializeHeadersChain(rawHeadersChain: Hex): BitcoinHeader[] { + const headersChain = rawHeadersChain.toString() + if (headersChain.length % 160 !== 0) { throw new Error("Incorrect length of Bitcoin headers") } const result: BitcoinHeader[] = [] - for (let i = 0; i < rawHeadersChain.length; i += 160) { - result.push( - deserializeHeader(Hex.from(rawHeadersChain.substring(i, i + 160))) - ) + for (let i = 0; i < headersChain.length; i += 160) { + result.push(deserializeHeader(Hex.from(headersChain.substring(i, i + 160)))) } return result diff --git a/typescript/src/lib/bitcoin/script.ts b/typescript/src/lib/bitcoin/script.ts index a66c39305..a514bddbe 100644 --- a/typescript/src/lib/bitcoin/script.ts +++ b/typescript/src/lib/bitcoin/script.ts @@ -1,3 +1,4 @@ +import { Hex } from "../utils" import { payments } from "bitcoinjs-lib" /** @@ -5,9 +6,9 @@ import { payments } from "bitcoinjs-lib" * @param script The script to be checked. * @returns True if the script is P2PKH, false otherwise. */ -function isP2PKHScript(script: Buffer): boolean { +function isP2PKHScript(script: Hex): boolean { try { - payments.p2pkh({ output: script }) + payments.p2pkh({ output: script.toBuffer() }) return true } catch (err) { return false @@ -19,9 +20,9 @@ function isP2PKHScript(script: Buffer): boolean { * @param script The script to be checked. * @returns True if the script is P2WPKH, false otherwise. */ -function isP2WPKHScript(script: Buffer): boolean { +function isP2WPKHScript(script: Hex): boolean { try { - payments.p2wpkh({ output: script }) + payments.p2wpkh({ output: script.toBuffer() }) return true } catch (err) { return false @@ -33,9 +34,9 @@ function isP2WPKHScript(script: Buffer): boolean { * @param script The script to be checked. * @returns True if the script is P2SH, false otherwise. */ -function isP2SHScript(script: Buffer): boolean { +function isP2SHScript(script: Hex): boolean { try { - payments.p2sh({ output: script }) + payments.p2sh({ output: script.toBuffer() }) return true } catch (err) { return false @@ -47,9 +48,9 @@ function isP2SHScript(script: Buffer): boolean { * @param script The script to be checked. * @returns True if the script is P2WSH, false otherwise. */ -function isP2WSHScript(script: Buffer): boolean { +function isP2WSHScript(script: Hex): boolean { try { - payments.p2wsh({ output: script }) + payments.p2wsh({ output: script.toBuffer() }) return true } catch (err) { return false diff --git a/typescript/src/lib/bitcoin/spv.ts b/typescript/src/lib/bitcoin/spv.ts index 4deb1cec4..596fd4056 100644 --- a/typescript/src/lib/bitcoin/spv.ts +++ b/typescript/src/lib/bitcoin/spv.ts @@ -15,10 +15,9 @@ import { BitcoinHashUtils } from "./hash" */ export interface BitcoinSpvProof { /** - * The merkle proof of transaction inclusion in a block, as an un-prefixed - * hex string. + * The merkle proof of transaction inclusion in a block. */ - merkleProof: string + merkleProof: Hex /** * Transaction index in the block (0-indexed). @@ -26,10 +25,10 @@ export interface BitcoinSpvProof { txIndexInBlock: number /** - * Single byte-string of 80-byte block headers, lowest height first, as an - * un-prefixed hex string. + * Concatenated block headers in hexadecimal format. Each block header is + * 80-byte-long. The block header with the lowest height is first. */ - bitcoinHeaders: string + bitcoinHeaders: Hex } /** @@ -46,7 +45,7 @@ export interface BitcoinTxMerkleBranch { * in order to trace up to obtain the merkle root of the including block, * the deepest pairing first. Each hash is an unprefixed hex string. */ - merkle: string[] + merkle: Hex[] /** * The 0-based index of the transaction's position in the block. @@ -117,12 +116,12 @@ export async function assembleBitcoinSpvProof( * @param txMerkleBranch - Branch of a Merkle tree leading to a transaction. * @returns Transaction inclusion proof in hexadecimal form. */ -function createMerkleProof(txMerkleBranch: BitcoinTxMerkleBranch): string { +function createMerkleProof(txMerkleBranch: BitcoinTxMerkleBranch): Hex { let proof = Buffer.from("") txMerkleBranch.merkle.forEach(function (item) { - proof = Buffer.concat([proof, Buffer.from(item, "hex").reverse()]) + proof = Buffer.concat([proof, item.toBuffer().reverse()]) }) - return proof.toString("hex") + return Hex.from(proof) } /** @@ -315,19 +314,21 @@ function validateMerkleTreeHashes( } /** - * Splits a given Merkle proof string into an array of intermediate node hashes. - * @param merkleProof A string representation of the Merkle proof. + * Splits a given concatenated Merkle proof into an array of intermediate node + * hashes. + * @param merkleProof A concatenated representation of the Merkle proof. * @returns An array of intermediate node hashes. * @throws {Error} If the length of the Merkle proof is not a multiple of 64. */ -function splitMerkleProof(merkleProof: string): Hex[] { - if (merkleProof.length % 64 != 0) { +function splitMerkleProof(merkleProof: Hex): Hex[] { + const merkleProofStr = merkleProof.toString() + if (merkleProofStr.length % 64 != 0) { throw new Error("Incorrect length of Merkle proof") } const intermediateNodeHashes: Hex[] = [] - for (let i = 0; i < merkleProof.length; i += 64) { - intermediateNodeHashes.push(Hex.from(merkleProof.slice(i, i + 64))) + for (let i = 0; i < merkleProofStr.length; i += 64) { + intermediateNodeHashes.push(Hex.from(merkleProofStr.slice(i, i + 64))) } return intermediateNodeHashes diff --git a/typescript/src/lib/bitcoin/tx.ts b/typescript/src/lib/bitcoin/tx.ts index 3593ddfe6..da76eae56 100644 --- a/typescript/src/lib/bitcoin/tx.ts +++ b/typescript/src/lib/bitcoin/tx.ts @@ -102,26 +102,26 @@ export type BitcoinUtxo = BitcoinTxOutpoint & { */ export interface BitcoinRawTxVectors { /** - * Transaction version as an un-prefixed hex string. + * Transaction version as a hex string. */ - version: string + version: Hex /** * All transaction's inputs prepended by the number of transaction inputs, - * as an un-prefixed hex string. + * as a hex string. */ - inputs: string + inputs: Hex /** * All transaction's outputs prepended by the number of transaction outputs, - * as an un-prefixed hex string. + * as a hex string. */ - outputs: string + outputs: Hex /** - * Transaction locktime as an un-prefixed hex string. + * Transaction locktime as a hex string. */ - locktime: string + locktime: Hex } /** @@ -133,11 +133,11 @@ export interface BitcoinRawTxVectors { export function extractBitcoinRawTxVectors( rawTransaction: BitcoinRawTx ): BitcoinRawTxVectors { - const toHex = (bufferWriter: any): string => { - return bufferWriter.render().toString("hex") + const toHex = (bufferWriter: any): Hex => { + return Hex.from(bufferWriter.render()) } - const getTxInputVector = (tx: Tx): string => { + const getTxInputVector = (tx: Tx): Hex => { const buffer = bufio.write() buffer.writeVarint(tx.ins.length) tx.ins.forEach((input) => { @@ -149,7 +149,7 @@ export function extractBitcoinRawTxVectors( return toHex(buffer) } - const getTxOutputVector = (tx: Tx): string => { + const getTxOutputVector = (tx: Tx): Hex => { const buffer = bufio.write() buffer.writeVarint(tx.outs.length) tx.outs.forEach((output) => { @@ -159,13 +159,13 @@ export function extractBitcoinRawTxVectors( return toHex(buffer) } - const getTxVersion = (tx: Tx): string => { + const getTxVersion = (tx: Tx): Hex => { const buffer = bufio.write() buffer.writeU32(tx.version) return toHex(buffer) } - const getTxLocktime = (tx: Tx): string => { + const getTxLocktime = (tx: Tx): Hex => { const buffer = bufio.write() buffer.writeU32(tx.locktime) return toHex(buffer) @@ -207,12 +207,12 @@ function locktimeToNumber(locktimeLE: Buffer | string): number { * @param locktimeStartedAt - Unix timestamp in seconds determining the moment * of the locktime start. * @param locktimeDuration Locktime duration in seconds. - * @returns A 4-byte little-endian locktime as an un-prefixed hex string. + * @returns A 4-byte little-endian locktime. */ function calculateLocktime( locktimeStartedAt: number, locktimeDuration: number -): string { +): Hex { // Locktime is a Unix timestamp in seconds, computed as locktime start // timestamp plus locktime duration. const locktime = BigNumber.from(locktimeStartedAt + locktimeDuration) @@ -225,7 +225,7 @@ function calculateLocktime( // Bitcoin locktime is interpreted as little-endian integer, so we must // adhere to that convention by converting the locktime accordingly. - return locktimeHex.reverse().toString() + return locktimeHex.reverse() } /** diff --git a/typescript/src/lib/contracts/bridge.ts b/typescript/src/lib/contracts/bridge.ts index 0e26c1587..ebf9f1bec 100644 --- a/typescript/src/lib/contracts/bridge.ts +++ b/typescript/src/lib/contracts/bridge.ts @@ -32,13 +32,14 @@ export interface Bridge { * @param mainUtxo - Data of the wallet's main UTXO. * @param vault - Optional identifier of the vault the swept deposits should * be routed in. + * @returns Transaction hash of the submit deposit sweep proof transaction. */ submitDepositSweepProof( sweepTx: BitcoinRawTxVectors, sweepProof: BitcoinSpvProof, mainUtxo: BitcoinUtxo, vault?: ChainIdentifier - ): Promise + ): Promise /** * Reveals a given deposit to the on-chain contract. @@ -48,14 +49,14 @@ export interface Bridge { * @param deposit - Data of the revealed deposit * @param vault - Optional parameter denoting the vault the given deposit * should be routed to - * @returns Transaction hash of the reveal deposit transaction as string + * @returns Transaction hash of the reveal deposit transaction. */ revealDeposit( depositTx: BitcoinRawTxVectors, depositOutputIndex: number, deposit: DepositReceipt, vault?: ChainIdentifier - ): Promise + ): Promise /** * Gets a revealed deposit from the on-chain contract. @@ -76,16 +77,16 @@ export interface Bridge { * @param mainUtxo - The main UTXO of the wallet. Must match the main UTXO * held by the on-chain contract. * @param redeemerOutputScript - The output script that the redeemed funds will - * be locked to. Must be un-prefixed and not prepended with length. + * be locked to. Must not be prepended with length. * @param amount - The amount to be redeemed in satoshis. - * @returns Empty promise. + * @returns Transaction hash of the request redemption transaction. */ requestRedemption( - walletPublicKey: string, + walletPublicKey: Hex, mainUtxo: BitcoinUtxo, - redeemerOutputScript: string, + redeemerOutputScript: Hex, amount: BigNumber - ): Promise + ): Promise /** * Submits a redemption transaction proof to the on-chain contract. @@ -94,13 +95,14 @@ export interface Bridge { * @param mainUtxo - Data of the wallet's main UTXO * @param walletPublicKey - Bitcoin public key of the wallet. Must be in the * compressed form (33 bytes long with 02 or 03 prefix). + * @returns Transaction hash of the submit redemption proof transaction. */ submitRedemptionProof( redemptionTx: BitcoinRawTxVectors, redemptionProof: BitcoinSpvProof, mainUtxo: BitcoinUtxo, - walletPublicKey: string - ): Promise + walletPublicKey: Hex + ): Promise /** * Gets transaction proof difficulty factor from the on-chain contract. @@ -116,13 +118,12 @@ export interface Bridge { * targeted to. Must be in the compressed form (33 bytes long with 02 * or 03 prefix). * @param redeemerOutputScript The redeemer output script the redeemed funds - * are supposed to be locked on. Must be un-prefixed and not prepended - * with length. + * are supposed to be locked on. Must not be prepended with length. * @returns Promise with the pending redemption. */ pendingRedemptions( - walletPublicKey: string, - redeemerOutputScript: string + walletPublicKey: Hex, + redeemerOutputScript: Hex ): Promise /** @@ -131,13 +132,12 @@ export interface Bridge { * targeted to. Must be in the compressed form (33 bytes long with 02 * or 03 prefix). * @param redeemerOutputScript The redeemer output script the redeemed funds - * are supposed to be locked on. Must be un-prefixed and not prepended - * with length. + * are supposed to be locked on. Must not be prepended with length. * @returns Promise with the pending redemption. */ timedOutRedemptions( - walletPublicKey: string, - redeemerOutputScript: string + walletPublicKey: Hex, + redeemerOutputScript: Hex ): Promise /** @@ -146,7 +146,7 @@ export interface Bridge { * public key. If there is no active wallet at the moment, undefined * is returned. */ - activeWalletPublicKey(): Promise + activeWalletPublicKey(): Promise /** * Get emitted NewWalletRegisteredEvent events. @@ -192,31 +192,30 @@ export interface DepositReceipt { depositor: ChainIdentifier /** - * An 8-byte blinding factor as an un-prefixed hex string. Must be unique - * for the given depositor, wallet public key and refund public key. + * An 8-byte blinding factor. Must be unique for the given depositor, wallet + * public key and refund public key. */ - blindingFactor: string + blindingFactor: Hex /** - * Public key hash of the wallet that is meant to receive the deposit. Must - * be an unprefixed hex string (without 0x prefix). + * Public key hash of the wallet that is meant to receive the deposit. * - * You can use `computeHash160` function to get the hash from a plain text public key. + * You can use `computeHash160` function to get the hash from a public key. */ - walletPublicKeyHash: string + walletPublicKeyHash: Hex /** * Public key hash that is meant to be used during deposit refund after the - * locktime passes. Must be an unprefixed hex string (without 0x prefix). + * locktime passes. * - * You can use `computeHash160` function to get the hash from a plain text public key. + * You can use `computeHash160` function to get the hash from a public key. */ - refundPublicKeyHash: string + refundPublicKeyHash: Hex /** - * A 4-byte little-endian refund locktime as an un-prefixed hex string. + * A 4-byte little-endian refund locktime. */ - refundLocktime: string + refundLocktime: Hex } // eslint-disable-next-line valid-jsdoc @@ -227,18 +226,18 @@ export interface DepositReceipt { * validity is chain-specific. This parameter must be validated outside. */ export function validateDepositReceipt(receipt: DepositReceipt) { - if (receipt.blindingFactor.length != 16) { + if (receipt.blindingFactor.toString().length != 16) { throw new Error("Blinding factor must be an 8-byte number") } - if (receipt.walletPublicKeyHash.length != 40) { + if (receipt.walletPublicKeyHash.toString().length != 40) { throw new Error("Invalid wallet public key hash") } - if (receipt.refundPublicKeyHash.length != 40) { + if (receipt.refundPublicKeyHash.toString().length != 40) { throw new Error("Invalid refund public key hash") } - if (receipt.refundLocktime.length != 8) { + if (receipt.refundLocktime.toString().length != 8) { throw new Error("Refund locktime must be a 4-byte number") } } @@ -297,10 +296,10 @@ export interface RedemptionRequest { redeemer: ChainIdentifier /** - * The output script the redeemed Bitcoin funds are locked to. It is un-prefixed - * and is not prepended with length. + * The output script the redeemed Bitcoin funds are locked to. It is not + * prepended with length. */ - redeemerOutputScript: string + redeemerOutputScript: Hex /** * The amount of Bitcoins in satoshis that is requested to be redeemed. @@ -337,10 +336,9 @@ export type RedemptionRequestedEvent = Omit< "requestedAt" > & { /** - * Public key hash of the wallet that is meant to handle the redemption. Must - * be an unprefixed hex string (without 0x prefix). + * Public key hash of the wallet that is meant to handle the redemption. */ - walletPublicKeyHash: string + walletPublicKeyHash: Hex } & ChainEvent /* eslint-disable no-unused-vars */ diff --git a/typescript/src/lib/contracts/tbtc-token.ts b/typescript/src/lib/contracts/tbtc-token.ts index 596c88ddb..01ea195fe 100644 --- a/typescript/src/lib/contracts/tbtc-token.ts +++ b/typescript/src/lib/contracts/tbtc-token.ts @@ -32,16 +32,15 @@ export interface TBTCToken { * @param mainUtxo - The main UTXO of the wallet. Must match the main UTXO * held by the on-chain Bridge contract. * @param redeemerOutputScript - The output script that the redeemed funds - * will be locked to. Must be un-prefixed and not prepended with - * length. + * will be locked to. Must not be prepended with length. * @param amount - The amount to be redeemed with the precision of the tBTC * on-chain token contract. * @returns Transaction hash of the approve and call transaction. */ requestRedemption( - walletPublicKey: string, + walletPublicKey: Hex, mainUtxo: BitcoinUtxo, - redeemerOutputScript: string, + redeemerOutputScript: Hex, amount: BigNumber ): Promise } diff --git a/typescript/src/lib/electrum/client.ts b/typescript/src/lib/electrum/client.ts index d4dbb57c8..a773cb86f 100644 --- a/typescript/src/lib/electrum/client.ts +++ b/typescript/src/lib/electrum/client.ts @@ -14,13 +14,16 @@ import { BitcoinHashUtils, } from "../bitcoin" import Electrum from "electrum-client-js" -import { BigNumber, utils } from "ethers" -import { URL } from "url" +import { BigNumber } from "ethers" +import { URL as nodeURL } from "url" import { backoffRetrier, Hex, RetrierFn } from "../utils" import MainnetElectrumUrls from "./urls/mainnet.json" import TestnetElectrumUrls from "./urls/testnet.json" +const browserURL = typeof window !== "undefined" && window.URL +const URL = nodeURL ?? browserURL + /** * Represents a set of credentials required to establish an Electrum connection. */ @@ -261,7 +264,7 @@ export class ElectrumClient implements BitcoinClient { const script = BitcoinAddressConverter.addressToOutputScript( address, bitcoinNetwork - ).toString() + ) // eslint-disable-next-line camelcase type UnspentOutput = { tx_pos: number; value: number; tx_hash: string } @@ -292,7 +295,7 @@ export class ElectrumClient implements BitcoinClient { const script = BitcoinAddressConverter.addressToOutputScript( address, bitcoinNetwork - ).toString() + ) // eslint-disable-next-line camelcase type HistoryItem = { height: number; tx_hash: string } @@ -498,6 +501,64 @@ export class ElectrumClient implements BitcoinClient { }) } + // eslint-disable-next-line valid-jsdoc + /** + * @see {BitcoinClient#getTxHashesForPublicKeyHash} + */ + getTxHashesForPublicKeyHash(publicKeyHash: Hex): Promise { + return this.withElectrum(async (electrum: Electrum) => { + const bitcoinNetwork = await this.getNetwork() + + // eslint-disable-next-line camelcase + type HistoryItem = { height: number; tx_hash: string } + + const getConfirmedHistory = async ( + witnessAddress: boolean + ): Promise => { + const address = BitcoinAddressConverter.publicKeyHashToAddress( + publicKeyHash, + witnessAddress, + bitcoinNetwork + ) + + const script = BitcoinAddressConverter.addressToOutputScript( + address, + bitcoinNetwork + ) + + let historyItems: HistoryItem[] = await this.withBackoffRetrier< + HistoryItem[] + >()(async () => { + return await electrum.blockchain_scripthash_getHistory( + computeElectrumScriptHash(script) + ) + }) + + // According to https://electrumx.readthedocs.io/en/latest/protocol-methods.html#blockchain-scripthash-get-history + // unconfirmed items living in the mempool are appended at the end of the + // returned list and their height value is either -1 or 0. That means + // we need to take all items with height >0 to obtain a confirmed txs + // history. + historyItems = historyItems.filter((item) => item.height > 0) + + // The list returned from blockchain.scripthash.get_history is sorted by + // the block height in the ascending order though we are sorting it + // again just in case (e.g. API contract changes). + historyItems = historyItems.sort((a, b) => a.height - b.height) + + return historyItems + } + + const p2pkhItems = await getConfirmedHistory(false) + const p2wpkhItems = await getConfirmedHistory(true) + + const items = [...p2pkhItems, ...p2wpkhItems] + items.sort((a, b) => a.height - b.height) + + return items.map((item) => BitcoinTxHash.from(item.tx_hash)) + }) + } + // eslint-disable-next-line valid-jsdoc /** * @see {BitcoinClient#latestBlockHeight} @@ -518,8 +579,8 @@ export class ElectrumClient implements BitcoinClient { /** * @see {BitcoinClient#getHeadersChain} */ - getHeadersChain(blockHeight: number, chainLength: number): Promise { - return this.withElectrum(async (electrum: Electrum) => { + getHeadersChain(blockHeight: number, chainLength: number): Promise { + return this.withElectrum(async (electrum: Electrum) => { const { hex } = await this.withBackoffRetrier<{ hex: string }>()(async () => { @@ -529,7 +590,7 @@ export class ElectrumClient implements BitcoinClient { ) }) - return hex + return Hex.from(hex) }) } @@ -557,7 +618,7 @@ export class ElectrumClient implements BitcoinClient { return { blockHeight: merkle.block_height, - merkle: merkle.merkle, + merkle: merkle.merkle.map((m) => Hex.from(m)), position: merkle.pos, } } @@ -585,9 +646,6 @@ export class ElectrumClient implements BitcoinClient { * @param script - Bitcoin script as hex string * @returns Electrum script hash as a hex string. */ -export function computeElectrumScriptHash(script: string): string { - const _script = Hex.from(Buffer.from(script, "hex")).toPrefixedString() - const hash256 = utils.sha256(_script) - - return Hex.from(hash256).reverse().toString() +export function computeElectrumScriptHash(script: Hex): string { + return BitcoinHashUtils.computeSha256(script).reverse().toString() } diff --git a/typescript/src/lib/ethereum/artifacts/goerli/TBTCToken.json b/typescript/src/lib/ethereum/artifacts/goerli/TBTC.json similarity index 100% rename from typescript/src/lib/ethereum/artifacts/goerli/TBTCToken.json rename to typescript/src/lib/ethereum/artifacts/goerli/TBTC.json diff --git a/typescript/src/lib/ethereum/artifacts/mainnet/TBTCToken.json b/typescript/src/lib/ethereum/artifacts/mainnet/TBTC.json similarity index 100% rename from typescript/src/lib/ethereum/artifacts/mainnet/TBTCToken.json rename to typescript/src/lib/ethereum/artifacts/mainnet/TBTC.json diff --git a/typescript/src/lib/ethereum/bridge.ts b/typescript/src/lib/ethereum/bridge.ts index fecf0fe25..91c266265 100644 --- a/typescript/src/lib/ethereum/bridge.ts +++ b/typescript/src/lib/ethereum/bridge.ts @@ -112,10 +112,10 @@ export class EthereumBridge ).toNumber(), depositor: EthereumAddress.from(event.args!.depositor), amount: BigNumber.from(event.args!.amount), - blindingFactor: Hex.from(event.args!.blindingFactor).toString(), - walletPublicKeyHash: Hex.from(event.args!.walletPubKeyHash).toString(), - refundPublicKeyHash: Hex.from(event.args!.refundPubKeyHash).toString(), - refundLocktime: Hex.from(event.args!.refundLocktime).toString(), + blindingFactor: Hex.from(event.args!.blindingFactor), + walletPublicKeyHash: Hex.from(event.args!.walletPubKeyHash), + refundPublicKeyHash: Hex.from(event.args!.refundPubKeyHash), + refundLocktime: Hex.from(event.args!.refundLocktime), vault: event.args!.vault === constants.AddressZero ? undefined @@ -129,8 +129,8 @@ export class EthereumBridge * @see {Bridge#pendingRedemptions} */ async pendingRedemptions( - walletPublicKey: string, - redeemerOutputScript: string + walletPublicKey: Hex, + redeemerOutputScript: Hex ): Promise { const redemptionKey = EthereumBridge.buildRedemptionKey( BitcoinHashUtils.computeHash160(walletPublicKey), @@ -152,8 +152,8 @@ export class EthereumBridge * @see {Bridge#timedOutRedemptions} */ async timedOutRedemptions( - walletPublicKey: string, - redeemerOutputScript: string + walletPublicKey: Hex, + redeemerOutputScript: Hex ): Promise { const redemptionKey = EthereumBridge.buildRedemptionKey( BitcoinHashUtils.computeHash160(walletPublicKey), @@ -173,19 +173,18 @@ export class EthereumBridge /** * Builds a redemption key required to refer a redemption request. * @param walletPublicKeyHash The wallet public key hash that identifies the - * pending redemption (along with the redeemer output script). Must be - * unprefixed. + * pending redemption (along with the redeemer output script). * @param redeemerOutputScript The redeemer output script that identifies the - * pending redemption (along with the wallet public key hash). Must be - * un-prefixed and not prepended with length. + * pending redemption (along with the wallet public key hash). Must not + * be prepended with length. * @returns The redemption key. */ static buildRedemptionKey( - walletPublicKeyHash: string, - redeemerOutputScript: string + walletPublicKeyHash: Hex, + redeemerOutputScript: Hex ): string { // Convert the output script to raw bytes buffer. - const rawRedeemerOutputScript = Buffer.from(redeemerOutputScript, "hex") + const rawRedeemerOutputScript = redeemerOutputScript.toBuffer() // Prefix the output script bytes buffer with 0x and its own length. const prefixedRawRedeemerOutputScript = `0x${Buffer.concat([ Buffer.from([rawRedeemerOutputScript.length]), @@ -197,7 +196,7 @@ export class EthereumBridge ["bytes32", "bytes20"], [ utils.solidityKeccak256(["bytes"], [prefixedRawRedeemerOutputScript]), - `0x${walletPublicKeyHash}`, + `0x${walletPublicKeyHash.toString()}`, ] ) } @@ -206,13 +205,13 @@ export class EthereumBridge * Parses a redemption request using data fetched from the on-chain contract. * @param request Data of the request. * @param redeemerOutputScript The redeemer output script that identifies the - * pending redemption (along with the wallet public key hash). Must be - * un-prefixed and not prepended with length. + * pending redemption (along with the wallet public key hash). Must not + * be prepended with length. * @returns Parsed redemption request. */ private parseRedemptionRequest( request: RedemptionRequestTypechain, - redeemerOutputScript: string + redeemerOutputScript: Hex ): RedemptionRequest { return { redeemer: EthereumAddress.from(request.redeemer), @@ -233,20 +232,20 @@ export class EthereumBridge depositOutputIndex: number, deposit: DepositReceipt, vault?: ChainIdentifier - ): Promise { + ): Promise { const depositTxParam = { - version: `0x${depositTx.version}`, - inputVector: `0x${depositTx.inputs}`, - outputVector: `0x${depositTx.outputs}`, - locktime: `0x${depositTx.locktime}`, + version: depositTx.version.toPrefixedString(), + inputVector: depositTx.inputs.toPrefixedString(), + outputVector: depositTx.outputs.toPrefixedString(), + locktime: depositTx.locktime.toPrefixedString(), } const revealParam = { fundingOutputIndex: depositOutputIndex, - blindingFactor: `0x${deposit.blindingFactor}`, - walletPubKeyHash: `0x${deposit.walletPublicKeyHash}`, - refundPubKeyHash: `0x${deposit.refundPublicKeyHash}`, - refundLocktime: `0x${deposit.refundLocktime}`, + blindingFactor: deposit.blindingFactor.toPrefixedString(), + walletPubKeyHash: deposit.walletPublicKeyHash.toPrefixedString(), + refundPubKeyHash: deposit.refundPublicKeyHash.toPrefixedString(), + refundLocktime: deposit.refundLocktime.toPrefixedString(), vault: vault ? `0x${vault.identifierHex}` : constants.AddressZero, } @@ -259,7 +258,7 @@ export class EthereumBridge ["Deposit already revealed"] ) - return tx.hash + return Hex.from(tx.hash) } // eslint-disable-next-line valid-jsdoc @@ -271,7 +270,7 @@ export class EthereumBridge sweepProof: BitcoinSpvProof, mainUtxo: BitcoinUtxo, vault?: ChainIdentifier - ): Promise { + ): Promise { const sweepTxParam = { version: `0x${sweepTx.version}`, inputVector: `0x${sweepTx.inputs}`, @@ -280,9 +279,9 @@ export class EthereumBridge } const sweepProofParam = { - merkleProof: `0x${sweepProof.merkleProof}`, + merkleProof: sweepProof.merkleProof.toPrefixedString(), txIndexInBlock: sweepProof.txIndexInBlock, - bitcoinHeaders: `0x${sweepProof.bitcoinHeaders}`, + bitcoinHeaders: sweepProof.bitcoinHeaders.toPrefixedString(), } const mainUtxoParam = { @@ -297,7 +296,7 @@ export class EthereumBridge ? `0x${vault.identifierHex}` : constants.AddressZero - await EthersTransactionUtils.sendWithRetry( + const tx = await EthersTransactionUtils.sendWithRetry( async () => { return await this._instance.submitDepositSweepProof( sweepTxParam, @@ -308,6 +307,8 @@ export class EthereumBridge }, this._totalRetryAttempts ) + + return Hex.from(tx.hash) } // eslint-disable-next-line valid-jsdoc @@ -329,14 +330,13 @@ export class EthereumBridge * @see {Bridge#requestRedemption} */ async requestRedemption( - walletPublicKey: string, + walletPublicKey: Hex, mainUtxo: BitcoinUtxo, - redeemerOutputScript: string, + redeemerOutputScript: Hex, amount: BigNumber - ): Promise { - const walletPublicKeyHash = `0x${BitcoinHashUtils.computeHash160( - walletPublicKey - )}` + ): Promise { + const walletPublicKeyHash = + BitcoinHashUtils.computeHash160(walletPublicKey).toPrefixedString() const mainUtxoParam = { // The Ethereum Bridge expects this hash to be in the Bitcoin internal @@ -347,14 +347,14 @@ export class EthereumBridge } // Convert the output script to raw bytes buffer. - const rawRedeemerOutputScript = Buffer.from(redeemerOutputScript, "hex") + const rawRedeemerOutputScript = redeemerOutputScript.toBuffer() // Prefix the output script bytes buffer with 0x and its own length. const prefixedRawRedeemerOutputScript = `0x${Buffer.concat([ Buffer.from([rawRedeemerOutputScript.length]), rawRedeemerOutputScript, ]).toString("hex")}` - await EthersTransactionUtils.sendWithRetry( + const tx = await EthersTransactionUtils.sendWithRetry( async () => { return await this._instance.requestRedemption( walletPublicKeyHash, @@ -365,6 +365,8 @@ export class EthereumBridge }, this._totalRetryAttempts ) + + return Hex.from(tx.hash) } // eslint-disable-next-line valid-jsdoc @@ -375,8 +377,8 @@ export class EthereumBridge redemptionTx: BitcoinRawTxVectors, redemptionProof: BitcoinSpvProof, mainUtxo: BitcoinUtxo, - walletPublicKey: string - ): Promise { + walletPublicKey: Hex + ): Promise { const redemptionTxParam = { version: `0x${redemptionTx.version}`, inputVector: `0x${redemptionTx.inputs}`, @@ -398,11 +400,10 @@ export class EthereumBridge txOutputValue: mainUtxo.value, } - const walletPublicKeyHash = `0x${BitcoinHashUtils.computeHash160( - walletPublicKey - )}` + const walletPublicKeyHash = + BitcoinHashUtils.computeHash160(walletPublicKey).toPrefixedString() - await EthersTransactionUtils.sendWithRetry( + const tx = await EthersTransactionUtils.sendWithRetry( async () => { return await this._instance.submitRedemptionProof( redemptionTxParam, @@ -413,6 +414,8 @@ export class EthereumBridge }, this._totalRetryAttempts ) + + return Hex.from(tx.hash) } // eslint-disable-next-line valid-jsdoc @@ -484,7 +487,7 @@ export class EthereumBridge /** * @see {Bridge#activeWalletPublicKey} */ - async activeWalletPublicKey(): Promise { + async activeWalletPublicKey(): Promise { const activeWalletPublicKeyHash: string = await backoffRetrier( this._totalRetryAttempts )(async () => { @@ -502,7 +505,7 @@ export class EthereumBridge Hex.from(activeWalletPublicKeyHash) ) - return walletPublicKey.toString() + return walletPublicKey } private async getWalletCompressedPublicKey(ecdsaWalletID: Hex): Promise { @@ -656,9 +659,9 @@ export class EthereumBridge blockNumber: BigNumber.from(event.blockNumber).toNumber(), blockHash: Hex.from(event.blockHash), transactionHash: Hex.from(event.transactionHash), - walletPublicKeyHash: Hex.from(event.args!.walletPubKeyHash).toString(), + walletPublicKeyHash: Hex.from(event.args!.walletPubKeyHash), redeemer: EthereumAddress.from(event.args!.redeemer), - redeemerOutputScript: redeemerOutputScript, + redeemerOutputScript: Hex.from(redeemerOutputScript), requestedAmount: BigNumber.from(event.args!.requestedAmount), treasuryFee: BigNumber.from(event.args!.treasuryFee), txMaxFee: BigNumber.from(event.args!.txMaxFee), diff --git a/typescript/src/lib/ethereum/index.ts b/typescript/src/lib/ethereum/index.ts index d61c7eaad..e39fcc5c9 100644 --- a/typescript/src/lib/ethereum/index.ts +++ b/typescript/src/lib/ethereum/index.ts @@ -33,7 +33,7 @@ export async function ethereumNetworkFromSigner( signer: EthereumSigner ): Promise { let chainId: number - if (signer instanceof Signer) { + if (Signer.isSigner(signer)) { chainId = await signer.getChainId() } else { const network = await signer.getNetwork() @@ -61,7 +61,7 @@ export async function ethereumNetworkFromSigner( export async function ethereumAddressFromSigner( signer: EthereumSigner ): Promise { - if (signer instanceof Signer) { + if (Signer.isSigner(signer)) { return EthereumAddress.from(await signer.getAddress()) } else { return undefined @@ -96,7 +96,7 @@ export async function loadEthereumContracts( const tbtcVault = new EthereumTBTCVault({ signerOrProvider: signer }, network) const walletRegistry = new EthereumWalletRegistry( { signerOrProvider: signer }, - "mainnet" + network ) const bridgeWalletRegistry = await bridge.walletRegistry() diff --git a/typescript/src/lib/ethereum/tbtc-token.ts b/typescript/src/lib/ethereum/tbtc-token.ts index c100473cb..74fc49617 100644 --- a/typescript/src/lib/ethereum/tbtc-token.ts +++ b/typescript/src/lib/ethereum/tbtc-token.ts @@ -11,9 +11,9 @@ import { } from "./adapter" import { EthereumAddress } from "./address" -import MainnetTBTCTokenDeployment from "./artifacts/mainnet/TBTCToken.json" -import GoerliTBTCTokenDeployment from "./artifacts/goerli/TBTCToken.json" -import LocalTBTCTokenDeployment from "@keep-network/tbtc-v2/artifacts/TBTCToken.json" +import MainnetTBTCTokenDeployment from "./artifacts/mainnet/TBTC.json" +import GoerliTBTCTokenDeployment from "./artifacts/goerli/TBTC.json" +import LocalTBTCTokenDeployment from "@keep-network/tbtc-v2/artifacts/TBTC.json" /** * Implementation of the Ethereum TBTC v2 token handle. @@ -69,9 +69,9 @@ export class EthereumTBTCToken * @see {TBTCToken#requestRedemption} */ async requestRedemption( - walletPublicKey: string, + walletPublicKey: Hex, mainUtxo: BitcoinUtxo, - redeemerOutputScript: string, + redeemerOutputScript: Hex, amount: BigNumber ): Promise { const redeemer = await this._instance?.signer?.getAddress() @@ -103,9 +103,9 @@ export class EthereumTBTCToken private buildRequestRedemptionData( redeemer: EthereumAddress, - walletPublicKey: string, + walletPublicKey: Hex, mainUtxo: BitcoinUtxo, - redeemerOutputScript: string + redeemerOutputScript: Hex ): Hex { const { walletPublicKeyHash, @@ -133,13 +133,12 @@ export class EthereumTBTCToken } private buildBridgeRequestRedemptionData( - walletPublicKey: string, + walletPublicKey: Hex, mainUtxo: BitcoinUtxo, - redeemerOutputScript: string + redeemerOutputScript: Hex ) { - const walletPublicKeyHash = `0x${BitcoinHashUtils.computeHash160( - walletPublicKey - )}` + const walletPublicKeyHash = + BitcoinHashUtils.computeHash160(walletPublicKey).toPrefixedString() const mainUtxoParam = { // The Ethereum Bridge expects this hash to be in the Bitcoin internal @@ -150,7 +149,7 @@ export class EthereumTBTCToken } // Convert the output script to raw bytes buffer. - const rawRedeemerOutputScript = Buffer.from(redeemerOutputScript, "hex") + const rawRedeemerOutputScript = redeemerOutputScript.toBuffer() // Prefix the output script bytes buffer with 0x and its own length. const prefixedRawRedeemerOutputScript = `0x${Buffer.concat([ Buffer.from([rawRedeemerOutputScript.length]), diff --git a/typescript/src/services/deposits/deposit.ts b/typescript/src/services/deposits/deposit.ts index ed93eff73..71ed02467 100644 --- a/typescript/src/services/deposits/deposit.ts +++ b/typescript/src/services/deposits/deposit.ts @@ -111,7 +111,7 @@ export class Deposit { * initiate minting (both modes). */ // TODO: Cover auto funding outpoint detection with unit tests. - async initiateMinting(fundingOutpoint?: BitcoinTxOutpoint): Promise { + async initiateMinting(fundingOutpoint?: BitcoinTxOutpoint): Promise { let resolvedFundingOutpoint: BitcoinTxOutpoint if (typeof fundingOutpoint !== "undefined") { @@ -185,39 +185,39 @@ export class DepositScript { // If witness script hash should be produced, SHA256 should be used. // Legacy script hash needs HASH160. return this.witness - ? BitcoinHashUtils.computeSha256(Hex.from(script)).toBuffer() - : Buffer.from(BitcoinHashUtils.computeHash160(script), "hex") + ? BitcoinHashUtils.computeSha256(script).toBuffer() + : BitcoinHashUtils.computeHash160(script).toBuffer() } /** - * @returns Plain-text deposit script as an un-prefixed hex string. + * @returns Plain-text deposit script as a hex string. */ - async getPlainText(): Promise { + async getPlainText(): Promise { const chunks: Stack = [] // All HEXes pushed to the script must be un-prefixed chunks.push(Buffer.from(this.receipt.depositor.identifierHex, "hex")) chunks.push(opcodes.OP_DROP) - chunks.push(Buffer.from(this.receipt.blindingFactor, "hex")) + chunks.push(this.receipt.blindingFactor.toBuffer()) chunks.push(opcodes.OP_DROP) chunks.push(opcodes.OP_DUP) chunks.push(opcodes.OP_HASH160) - chunks.push(Buffer.from(this.receipt.walletPublicKeyHash, "hex")) + chunks.push(this.receipt.walletPublicKeyHash.toBuffer()) chunks.push(opcodes.OP_EQUAL) chunks.push(opcodes.OP_IF) chunks.push(opcodes.OP_CHECKSIG) chunks.push(opcodes.OP_ELSE) chunks.push(opcodes.OP_DUP) chunks.push(opcodes.OP_HASH160) - chunks.push(Buffer.from(this.receipt.refundPublicKeyHash, "hex")) + chunks.push(this.receipt.refundPublicKeyHash.toBuffer()) chunks.push(opcodes.OP_EQUALVERIFY) - chunks.push(Buffer.from(this.receipt.refundLocktime, "hex")) + chunks.push(this.receipt.refundLocktime.toBuffer()) chunks.push(opcodes.OP_CHECKLOCKTIMEVERIFY) chunks.push(opcodes.OP_DROP) chunks.push(opcodes.OP_CHECKSIG) chunks.push(opcodes.OP_ENDIF) - return script.compile(chunks).toString("hex") + return Hex.from(script.compile(chunks)) } /** diff --git a/typescript/src/services/deposits/deposits-service.ts b/typescript/src/services/deposits/deposits-service.ts index e04048d29..1c1591afc 100644 --- a/typescript/src/services/deposits/deposits-service.ts +++ b/typescript/src/services/deposits/deposits-service.ts @@ -8,7 +8,9 @@ import { BitcoinClient, BitcoinHashUtils, BitcoinLocktimeUtils, + BitcoinScriptUtils, } from "../../lib/bitcoin" +import { Hex } from "../../lib/utils" import { Deposit } from "./deposit" import * as crypto from "crypto" @@ -66,7 +68,7 @@ export class DepositsService { ) } - const blindingFactor = crypto.randomBytes(8).toString("hex") + const blindingFactor = Hex.from(crypto.randomBytes(8)) const walletPublicKey = await this.tbtcContracts.bridge.activeWalletPublicKey() @@ -79,9 +81,17 @@ export class DepositsService { const bitcoinNetwork = await this.bitcoinClient.getNetwork() - // TODO: Only P2(W)PKH addresses can be used for recovery. The below conversion - // function ensures that but, it would be good to check it here as well - // in case the converter implementation changes. + const recoveryOutputScript = BitcoinAddressConverter.addressToOutputScript( + bitcoinRecoveryAddress, + bitcoinNetwork + ) + if ( + !BitcoinScriptUtils.isP2PKHScript(recoveryOutputScript) && + !BitcoinScriptUtils.isP2WPKHScript(recoveryOutputScript) + ) { + throw new Error("Bitcoin recovery address must be P2PKH or P2WPKH") + } + const refundPublicKeyHash = BitcoinAddressConverter.addressToPublicKeyHash( bitcoinRecoveryAddress, bitcoinNetwork diff --git a/typescript/src/services/deposits/funding.ts b/typescript/src/services/deposits/funding.ts index c520f5e83..a3f9d8f7e 100644 --- a/typescript/src/services/deposits/funding.ts +++ b/typescript/src/services/deposits/funding.ts @@ -92,7 +92,7 @@ export class DepositFunding { // TODO: Add support for other utxo types along with unit tests for the // given type. - if (BitcoinScriptUtils.isP2WPKHScript(previousOutputScript)) { + if (BitcoinScriptUtils.isP2WPKHScript(Hex.from(previousOutputScript))) { psbt.addInput({ hash: utxo.transactionHash.reverse().toBuffer(), index: utxo.outputIndex, diff --git a/typescript/src/services/deposits/refund.ts b/typescript/src/services/deposits/refund.ts index d4ad401fb..ef9a4227b 100644 --- a/typescript/src/services/deposits/refund.ts +++ b/typescript/src/services/deposits/refund.ts @@ -12,6 +12,7 @@ import { BitcoinUtxo, } from "../../lib/bitcoin" import { validateDepositReceipt } from "../../lib/contracts" +import { Hex } from "../../lib/utils" import { DepositScript } from "./" import { Signer, @@ -153,7 +154,7 @@ export class DepositRefund { utxo.outputIndex ] const previousOutputValue = previousOutput.value - const previousOutputScript = previousOutput.script + const previousOutputScript = Hex.from(previousOutput.script) if (BitcoinScriptUtils.isP2SHScript(previousOutputScript)) { // P2SH deposit UTXO @@ -188,11 +189,12 @@ export class DepositRefund { * @throws Error if there are discrepancies in values or key formats. */ private async prepareDepositScript(refunderKeyPair: Signer): Promise { - const refunderPublicKey = refunderKeyPair.publicKey.toString("hex") + const refunderPublicKey = Hex.from(refunderKeyPair.publicKey) if ( - BitcoinHashUtils.computeHash160(refunderPublicKey) != - this.script.receipt.refundPublicKeyHash + !BitcoinHashUtils.computeHash160(refunderPublicKey).equals( + this.script.receipt.refundPublicKeyHash + ) ) { throw new Error( "Refund public key does not correspond to wallet private key" @@ -203,7 +205,7 @@ export class DepositRefund { throw new Error("Refunder public key must be compressed") } - return Buffer.from(await this.script.getPlainText(), "hex") + return (await this.script.getPlainText()).toBuffer() } /** @@ -288,10 +290,7 @@ export class DepositRefund { * @param locktime - Locktime as a little endian hexstring. * @returns Locktime as a Unix timestamp. */ -function locktimeToUnixTimestamp(locktime: string): number { - const bigEndianLocktime = Buffer.from(locktime, "hex") - .reverse() - .toString("hex") - +function locktimeToUnixTimestamp(locktime: Hex): number { + const bigEndianLocktime = locktime.reverse().toString() return parseInt(bigEndianLocktime, 16) } diff --git a/typescript/src/services/maintenance/spv.ts b/typescript/src/services/maintenance/spv.ts index c00d690db..3dbd8341e 100644 --- a/typescript/src/services/maintenance/spv.ts +++ b/typescript/src/services/maintenance/spv.ts @@ -5,6 +5,7 @@ import { BitcoinUtxo, extractBitcoinRawTxVectors, } from "../../lib/bitcoin" +import { Hex } from "../../lib/utils" import { ChainIdentifier, TBTCContracts } from "../../lib/contracts" export class Spv { @@ -66,7 +67,7 @@ export class Spv { async submitRedemptionProof( transactionHash: BitcoinTxHash, mainUtxo: BitcoinUtxo, - walletPublicKey: string + walletPublicKey: Hex ): Promise { const confirmations = await this.tbtcContracts.bridge.txProofDifficultyFactor() diff --git a/typescript/src/services/maintenance/wallet-tx.ts b/typescript/src/services/maintenance/wallet-tx.ts index dda223671..595a19171 100644 --- a/typescript/src/services/maintenance/wallet-tx.ts +++ b/typescript/src/services/maintenance/wallet-tx.ts @@ -249,7 +249,7 @@ class DepositSweep { utxo.outputIndex ] const previousOutputValue = previousOutput.value - const previousOutputScript = previousOutput.script + const previousOutputScript = Hex.from(previousOutput.script) const deposit = deposits[depositIndex] @@ -309,10 +309,13 @@ class DepositSweep { previousOutput: TxOutput, walletKeyPair: Signer ) { + const previousOutputScript = Hex.from(previousOutput.script) + const previousOutputValue = previousOutput.value + if ( !this.canSpendOutput( Hex.from(walletKeyPair.publicKey), - previousOutput.script + previousOutputScript ) ) { throw new Error("UTXO does not belong to the wallet") @@ -320,11 +323,11 @@ class DepositSweep { const sigHashType = Transaction.SIGHASH_ALL - if (BitcoinScriptUtils.isP2PKHScript(previousOutput.script)) { + if (BitcoinScriptUtils.isP2PKHScript(previousOutputScript)) { // P2PKH const sigHash = transaction.hashForSignature( inputIndex, - previousOutput.script, + previousOutputScript.toBuffer(), sigHashType ) @@ -339,16 +342,17 @@ class DepositSweep { }).input! transaction.ins[inputIndex].script = scriptSig - } else if (BitcoinScriptUtils.isP2WPKHScript(previousOutput.script)) { + } else if (BitcoinScriptUtils.isP2WPKHScript(previousOutputScript)) { // P2WPKH - const publicKeyHash = payments.p2wpkh({ output: previousOutput.script }) - .hash! + const publicKeyHash = payments.p2wpkh({ + output: previousOutputScript.toBuffer(), + }).hash! const p2pkhScript = payments.p2pkh({ hash: publicKeyHash }).output! const sigHash = transaction.hashForWitnessV0( inputIndex, p2pkhScript, - previousOutput.value, + previousOutputValue, sigHashType ) @@ -466,11 +470,12 @@ class DepositSweep { previousOutputValue: number, walletKeyPair: Signer ): Promise { - const walletPublicKey = walletKeyPair.publicKey.toString("hex") + const walletPublicKey = Hex.from(walletKeyPair.publicKey) if ( - BitcoinHashUtils.computeHash160(walletPublicKey) != - deposit.walletPublicKeyHash + !BitcoinHashUtils.computeHash160(walletPublicKey).equals( + deposit.walletPublicKeyHash + ) ) { throw new Error( "Wallet public key does not correspond to wallet private key" @@ -481,10 +486,7 @@ class DepositSweep { throw new Error("Wallet public key must be compressed") } - return Buffer.from( - await DepositScript.fromReceipt(deposit).getPlainText(), - "hex" - ) + return (await DepositScript.fromReceipt(deposit).getPlainText()).toBuffer() } /** @@ -496,10 +498,14 @@ class DepositSweep { * @returns True if the provided output script matches the P2PKH or P2WPKH * output scripts derived from the given public key. False otherwise. */ - private canSpendOutput(publicKey: Hex, outputScript: Buffer): boolean { + private canSpendOutput(publicKey: Hex, outputScript: Hex): boolean { const pubkeyBuffer = publicKey.toBuffer() - const p2pkhOutput = payments.p2pkh({ pubkey: pubkeyBuffer }).output! - const p2wpkhOutput = payments.p2wpkh({ pubkey: pubkeyBuffer }).output! + const p2pkhOutput = Hex.from( + payments.p2pkh({ pubkey: pubkeyBuffer }).output! + ) + const p2wpkhOutput = Hex.from( + payments.p2wpkh({ pubkey: pubkeyBuffer }).output! + ) return outputScript.equals(p2pkhOutput) || outputScript.equals(p2wpkhOutput) } @@ -541,8 +547,8 @@ class Redemption { * @param mainUtxo - The main UTXO of the wallet. Must match the main UTXO * held by the on-chain Bridge contract * @param redeemerOutputScripts - The list of output scripts that the redeemed - * funds will be locked to. The output scripts must be un-prefixed and - * not prepended with length + * funds will be locked to. The output scripts must not be prepended + * with length * @returns The outcome consisting of: * - the redemption transaction hash, * - the optional new wallet's main UTXO produced by this transaction. @@ -550,7 +556,7 @@ class Redemption { async submitTransaction( walletPrivateKey: string, mainUtxo: BitcoinUtxo, - redeemerOutputScripts: string[] + redeemerOutputScripts: Hex[] ): Promise<{ transactionHash: BitcoinTxHash newMainUtxo?: BitcoinUtxo @@ -571,7 +577,7 @@ class Redemption { bitcoinNetwork ) - const walletPublicKey = walletKeyPair.publicKey.toString("hex") + const walletPublicKey = Hex.from(walletKeyPair.publicKey) const redemptionRequests: RedemptionRequest[] = [] @@ -588,7 +594,7 @@ class Redemption { redemptionRequests.push({ ...redemptionRequest, - redeemerOutputScript: redeemerOutputScript, + redeemerOutputScript, }) } @@ -661,7 +667,7 @@ class Redemption { const previousOutput = Transaction.fromHex(mainUtxo.transactionHex).outs[ mainUtxo.outputIndex ] - const previousOutputScript = previousOutput.script + const previousOutputScript = Hex.from(previousOutput.script) const previousOutputValue = previousOutput.value if (BitcoinScriptUtils.isP2PKHScript(previousOutputScript)) { @@ -675,7 +681,7 @@ class Redemption { hash: mainUtxo.transactionHash.reverse().toBuffer(), index: mainUtxo.outputIndex, witnessUtxo: { - script: previousOutputScript, + script: previousOutputScript.toBuffer(), value: previousOutputValue, }, }) @@ -701,7 +707,7 @@ class Redemption { txTotalFee = txTotalFee.add(request.txMaxFee) psbt.addOutput({ - script: Buffer.from(request.redeemerOutputScript, "hex"), + script: request.redeemerOutputScript.toBuffer(), value: outputValue.toNumber(), }) } diff --git a/typescript/src/services/redemptions/redemptions-service.ts b/typescript/src/services/redemptions/redemptions-service.ts index f3fd5f49c..3e8e6f5c8 100644 --- a/typescript/src/services/redemptions/redemptions-service.ts +++ b/typescript/src/services/redemptions/redemptions-service.ts @@ -7,6 +7,7 @@ import { BitcoinAddressConverter, BitcoinClient, BitcoinNetwork, + BitcoinScriptUtils, BitcoinTxOutput, BitcoinUtxo, } from "../../lib/bitcoin" @@ -49,16 +50,22 @@ export class RedemptionsService { amount: BigNumber ): Promise<{ targetChainTxHash: Hex - walletPublicKey: string + walletPublicKey: Hex }> { const bitcoinNetwork = await this.bitcoinClient.getNetwork() const redeemerOutputScript = BitcoinAddressConverter.addressToOutputScript( bitcoinRedeemerAddress, bitcoinNetwork - ).toString() - - // TODO: Validate the given script is supported for redemption. + ) + if ( + !BitcoinScriptUtils.isP2PKHScript(redeemerOutputScript) && + !BitcoinScriptUtils.isP2WPKHScript(redeemerOutputScript) && + !BitcoinScriptUtils.isP2SHScript(redeemerOutputScript) && + !BitcoinScriptUtils.isP2WSHScript(redeemerOutputScript) + ) { + throw new Error("Redeemer output script must be of standard type") + } const { walletPublicKey, mainUtxo } = await this.findWalletForRedemption( redeemerOutputScript, @@ -82,16 +89,15 @@ export class RedemptionsService { * Finds the oldest live wallet that has enough BTC to handle a redemption * request. * @param redeemerOutputScript The redeemer output script the redeemed funds are - * supposed to be locked on. Must be un-prefixed and not prepended with - * length. + * supposed to be locked on. Must not be prepended with length. * @param amount The amount to be redeemed in satoshis. * @returns Promise with the wallet details needed to request a redemption. */ protected async findWalletForRedemption( - redeemerOutputScript: string, + redeemerOutputScript: Hex, amount: BigNumber ): Promise<{ - walletPublicKey: string + walletPublicKey: Hex mainUtxo: BitcoinUtxo }> { const wallets = @@ -99,7 +105,7 @@ export class RedemptionsService { let walletData: | { - walletPublicKey: string + walletPublicKey: Hex mainUtxo: BitcoinUtxo } | undefined = undefined @@ -140,7 +146,7 @@ export class RedemptionsService { const pendingRedemption = await this.tbtcContracts.bridge.pendingRedemptions( - walletPublicKey.toString(), + walletPublicKey, redeemerOutputScript ) @@ -149,7 +155,7 @@ export class RedemptionsService { `There is a pending redemption request from this wallet to the ` + `same Bitcoin address. Given wallet public key hash` + `(${walletPublicKeyHash.toString()}) and redeemer output script ` + - `(${redeemerOutputScript}) pair can be used for only one ` + + `(${redeemerOutputScript.toString()}) pair can be used for only one ` + `pending request at the same time. ` + `Continue the loop execution to the next wallet...` ) @@ -163,7 +169,7 @@ export class RedemptionsService { if (walletBTCBalance.gte(amount)) { walletData = { - walletPublicKey: walletPublicKey.toString(), + walletPublicKey, mainUtxo, } @@ -202,12 +208,6 @@ export class RedemptionsService { * Determines the plain-text wallet main UTXO currently registered in the * Bridge on-chain contract. The returned main UTXO can be undefined if the * wallet does not have a main UTXO registered in the Bridge at the moment. - * - * WARNING: THIS FUNCTION CANNOT DETERMINE THE MAIN UTXO IF IT COMES FROM A - * BITCOIN TRANSACTION THAT IS NOT ONE OF THE LATEST FIVE TRANSACTIONS - * TARGETING THE GIVEN WALLET PUBLIC KEY HASH. HOWEVER, SUCH A CASE IS - * VERY UNLIKELY. - * * @param walletPublicKeyHash - Public key hash of the wallet. * @param bitcoinNetwork - Bitcoin network. * @returns Promise holding the wallet main UTXO or undefined value. @@ -232,87 +232,83 @@ export class RedemptionsService { return undefined } - // Declare a helper function that will try to determine the main UTXO for - // the given wallet address type. - const determine = async ( - witnessAddress: boolean - ): Promise => { - // Build the wallet Bitcoin address based on its public key hash. - const walletAddress = BitcoinAddressConverter.publicKeyHashToAddress( - walletPublicKeyHash.toString(), - witnessAddress, + // The wallet main UTXO registered in the Bridge almost always comes + // from the latest BTC transaction made by the wallet. However, there may + // be cases where the BTC transaction was made but their SPV proof is + // not yet submitted to the Bridge thus the registered main UTXO points + // to the second last BTC transaction. In theory, such a gap between + // the actual latest BTC transaction and the registered main UTXO in + // the Bridge may be even wider. To cover the worst possible cases, we + // must rely on the full transaction history. Due to performance reasons, + // we are first taking just the transactions hashes (fast call) and then + // fetch full transaction data (time-consuming calls) starting from + // the most recent transactions as there is a high chance the main UTXO + // comes from there. + const walletTxHashes = await this.bitcoinClient.getTxHashesForPublicKeyHash( + walletPublicKeyHash + ) + + const getOutputScript = (witness: boolean): Hex => { + const address = BitcoinAddressConverter.publicKeyHashToAddress( + walletPublicKeyHash, + witness, bitcoinNetwork ) - - // Get the wallet transaction history. The wallet main UTXO registered in the - // Bridge almost always comes from the latest BTC transaction made by the wallet. - // However, there may be cases where the BTC transaction was made but their - // SPV proof is not yet submitted to the Bridge thus the registered main UTXO - // points to the second last BTC transaction. In theory, such a gap between - // the actual latest BTC transaction and the registered main UTXO in the - // Bridge may be even wider. The exact behavior is a wallet implementation - // detail and not a protocol invariant so, it may be subject of changes. - // To cover the worst possible cases, we always take the five latest - // transactions made by the wallet for consideration. - const walletTransactions = await this.bitcoinClient.getTransactionHistory( - walletAddress, - 5 + return BitcoinAddressConverter.addressToOutputScript( + address, + bitcoinNetwork ) + } - // Get the wallet script based on the wallet address. This is required - // to find transaction outputs that lock funds on the wallet. - const walletScript = BitcoinAddressConverter.addressToOutputScript( - walletAddress, - bitcoinNetwork + const walletP2PKH = getOutputScript(false) + const walletP2WPKH = getOutputScript(true) + + const isWalletOutput = (output: BitcoinTxOutput) => + walletP2PKH.equals(output.scriptPubKey) || + walletP2WPKH.equals(output.scriptPubKey) + + // Start iterating from the latest transaction as the chance it matches + // the wallet main UTXO is the highest. + for (let i = walletTxHashes.length - 1; i >= 0; i--) { + const walletTxHash = walletTxHashes[i] + const walletTransaction = await this.bitcoinClient.getTransaction( + walletTxHash ) - const isWalletOutput = (output: BitcoinTxOutput) => - walletScript.equals(output.scriptPubKey) - - // Start iterating from the latest transaction as the chance it matches - // the wallet main UTXO is the highest. - for (let i = walletTransactions.length - 1; i >= 0; i--) { - const walletTransaction = walletTransactions[i] - - // Find the output that locks the funds on the wallet. Only such an output - // can be a wallet main UTXO. - const outputIndex = walletTransaction.outputs.findIndex(isWalletOutput) - - // Should never happen as all transactions come from wallet history. Just - // in case check whether the wallet output was actually found. - if (outputIndex < 0) { - console.error( - `wallet output for transaction ${walletTransaction.transactionHash.toString()} not found` - ) - continue - } - // Build a candidate UTXO instance based on the detected output. - const utxo: BitcoinUtxo = { - transactionHash: walletTransaction.transactionHash, - outputIndex: outputIndex, - value: walletTransaction.outputs[outputIndex].value, - } + // Find the output that locks the funds on the wallet. Only such an output + // can be a wallet main UTXO. + const outputIndex = walletTransaction.outputs.findIndex(isWalletOutput) - // Check whether the candidate UTXO hash matches the main UTXO hash stored - // on the Bridge. - if ( - mainUtxoHash.equals(this.tbtcContracts.bridge.buildUtxoHash(utxo)) - ) { - return utxo - } + // Should never happen as all transactions come from wallet history. Just + // in case check whether the wallet output was actually found. + if (outputIndex < 0) { + console.error( + `wallet output for transaction ${walletTransaction.transactionHash.toString()} not found` + ) + continue } - return undefined - } + // Build a candidate UTXO instance based on the detected output. + const utxo: BitcoinUtxo = { + transactionHash: walletTransaction.transactionHash, + outputIndex: outputIndex, + value: walletTransaction.outputs[outputIndex].value, + } - // The most common case is that the wallet uses a witness address for all - // operations. Try to determine the main UTXO for that address first as the - // chance for success is the highest here. - const mainUtxo = await determine(true) + // Check whether the candidate UTXO hash matches the main UTXO hash stored + // on the Bridge. + if (mainUtxoHash.equals(this.tbtcContracts.bridge.buildUtxoHash(utxo))) { + return utxo + } + } - // In case the main UTXO was not found for witness address, there is still - // a chance it exists for the legacy wallet address. - return mainUtxo ?? (await determine(false)) + // Should never happen if the wallet has the main UTXO registered in the + // Bridge. It could only happen due to some serious error, e.g. wrong main + // UTXO hash stored in the Bridge or Bitcoin blockchain data corruption. + console.error( + `main UTXO with hash ${mainUtxoHash.toPrefixedString()} not found for wallet ${walletPublicKeyHash.toString()}` + ) + return undefined } /** @@ -330,7 +326,7 @@ export class RedemptionsService { */ async getRedemptionRequests( bitcoinRedeemerAddress: string, - walletPublicKey: string, + walletPublicKey: Hex, type: "pending" | "timedOut" = "pending" ): Promise { const bitcoinNetwork = await this.bitcoinClient.getNetwork() @@ -338,7 +334,7 @@ export class RedemptionsService { const redeemerOutputScript = BitcoinAddressConverter.addressToOutputScript( bitcoinRedeemerAddress, bitcoinNetwork - ).toString() + ) let redemptionRequest: RedemptionRequest | undefined = undefined diff --git a/typescript/test/data/deposit-refund.ts b/typescript/test/data/deposit-refund.ts index ff0782a2a..45dfb3699 100644 --- a/typescript/test/data/deposit-refund.ts +++ b/typescript/test/data/deposit-refund.ts @@ -1,4 +1,5 @@ import { BigNumber } from "ethers" +import { Hex } from "../../src/lib/utils" import { BitcoinRawTx, BitcoinUtxo, @@ -59,9 +60,13 @@ export const depositRefundOfWitnessDepositAndWitnessRefunderAddress: DepositRefu depositor: EthereumAddress.from( "934b98637ca318a4d6e7ca6ffd1690b8e77df637" ), - walletPublicKeyHash: "8db50eb52063ea9d98b3eac91489a90f738986f6", - refundPublicKeyHash: "1b67f27537c7b30a23d8ccefb96a4cacfc72d9a1", - blindingFactor: "f9f0c90d00039523", + walletPublicKeyHash: Hex.from( + "8db50eb52063ea9d98b3eac91489a90f738986f6" + ), + refundPublicKeyHash: Hex.from( + "1b67f27537c7b30a23d8ccefb96a4cacfc72d9a1" + ), + blindingFactor: Hex.from("f9f0c90d00039523"), refundLocktime: BitcoinLocktimeUtils.calculateLocktime( 1674820800, 3600 @@ -116,9 +121,13 @@ export const depositRefundOfNonWitnessDepositAndWitnessRefunderAddress: DepositR depositor: EthereumAddress.from( "934b98637ca318a4d6e7ca6ffd1690b8e77df637" ), - walletPublicKeyHash: "8db50eb52063ea9d98b3eac91489a90f738986f6", - refundPublicKeyHash: "1b67f27537c7b30a23d8ccefb96a4cacfc72d9a1", - blindingFactor: "f9f0c90d00039523", + walletPublicKeyHash: Hex.from( + "8db50eb52063ea9d98b3eac91489a90f738986f6" + ), + refundPublicKeyHash: Hex.from( + "1b67f27537c7b30a23d8ccefb96a4cacfc72d9a1" + ), + blindingFactor: Hex.from("f9f0c90d00039523"), refundLocktime: BitcoinLocktimeUtils.calculateLocktime( 1674820800, 3600 @@ -173,9 +182,13 @@ export const depositRefundOfWitnessDepositAndNonWitnessRefunderAddress: DepositR depositor: EthereumAddress.from( "934b98637ca318a4d6e7ca6ffd1690b8e77df637" ), - walletPublicKeyHash: "8db50eb52063ea9d98b3eac91489a90f738986f6", - refundPublicKeyHash: "1b67f27537c7b30a23d8ccefb96a4cacfc72d9a1", - blindingFactor: "f9f0c90d00039523", + walletPublicKeyHash: Hex.from( + "8db50eb52063ea9d98b3eac91489a90f738986f6" + ), + refundPublicKeyHash: Hex.from( + "1b67f27537c7b30a23d8ccefb96a4cacfc72d9a1" + ), + blindingFactor: Hex.from("f9f0c90d00039523"), refundLocktime: BitcoinLocktimeUtils.calculateLocktime( 1674820800, 3600 diff --git a/typescript/test/data/deposit-sweep.ts b/typescript/test/data/deposit-sweep.ts index 0ba6ffee6..35b551e43 100644 --- a/typescript/test/data/deposit-sweep.ts +++ b/typescript/test/data/deposit-sweep.ts @@ -65,10 +65,14 @@ export const depositSweepWithNoMainUtxoAndWitnessOutput: DepositSweepTestData = "934b98637ca318a4d6e7ca6ffd1690b8e77df637" ), // HASH160 of 03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9. - walletPublicKeyHash: "8db50eb52063ea9d98b3eac91489a90f738986f6", + walletPublicKeyHash: Hex.from( + "8db50eb52063ea9d98b3eac91489a90f738986f6" + ), // HASH160 of 039d61d62dcd048d3f8550d22eb90b4af908db60231d117aeede04e7bc11907bfa. - refundPublicKeyHash: "e257eccafbc07c381642ce6e7e55120fb077fbed", - blindingFactor: "f9f0c90d00039523", + refundPublicKeyHash: Hex.from( + "e257eccafbc07c381642ce6e7e55120fb077fbed" + ), + blindingFactor: Hex.from("f9f0c90d00039523"), refundLocktime: BitcoinLocktimeUtils.calculateLocktime( 1641650400, 2592000 @@ -96,10 +100,14 @@ export const depositSweepWithNoMainUtxoAndWitnessOutput: DepositSweepTestData = "934b98637ca318a4d6e7ca6ffd1690b8e77df637" ), // HASH160 of 03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9. - walletPublicKeyHash: "8db50eb52063ea9d98b3eac91489a90f738986f6", + walletPublicKeyHash: Hex.from( + "8db50eb52063ea9d98b3eac91489a90f738986f6" + ), // HASH160 of 039d61d62dcd048d3f8550d22eb90b4af908db60231d117aeede04e7bc11907bfa. - refundPublicKeyHash: "e257eccafbc07c381642ce6e7e55120fb077fbed", - blindingFactor: "f9f0c90d00039523", + refundPublicKeyHash: Hex.from( + "e257eccafbc07c381642ce6e7e55120fb077fbed" + ), + blindingFactor: Hex.from("f9f0c90d00039523"), refundLocktime: BitcoinLocktimeUtils.calculateLocktime( 1641650400, 2592000 @@ -158,10 +166,14 @@ export const depositSweepWithNoMainUtxoAndNonWitnessOutput: DepositSweepTestData "934b98637ca318a4d6e7ca6ffd1690b8e77df637" ), // HASH160 of 03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9. - walletPublicKeyHash: "8db50eb52063ea9d98b3eac91489a90f738986f6", + walletPublicKeyHash: Hex.from( + "8db50eb52063ea9d98b3eac91489a90f738986f6" + ), // HASH160 of 039d61d62dcd048d3f8550d22eb90b4af908db60231d117aeede04e7bc11907bfa. - refundPublicKeyHash: "e257eccafbc07c381642ce6e7e55120fb077fbed", - blindingFactor: "f9f0c90d00039523", + refundPublicKeyHash: Hex.from( + "e257eccafbc07c381642ce6e7e55120fb077fbed" + ), + blindingFactor: Hex.from("f9f0c90d00039523"), refundLocktime: BitcoinLocktimeUtils.calculateLocktime( 1653302600, 2592000 @@ -213,10 +225,14 @@ export const depositSweepWithWitnessMainUtxoAndWitnessOutput: DepositSweepTestDa "934b98637ca318a4d6e7ca6ffd1690b8e77df637" ), // HASH160 of 03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9. - walletPublicKeyHash: "8db50eb52063ea9d98b3eac91489a90f738986f6", + walletPublicKeyHash: Hex.from( + "8db50eb52063ea9d98b3eac91489a90f738986f6" + ), // HASH160 of 039d61d62dcd048d3f8550d22eb90b4af908db60231d117aeede04e7bc11907bfa. - refundPublicKeyHash: "e257eccafbc07c381642ce6e7e55120fb077fbed", - blindingFactor: "f9f0c90d00039523", + refundPublicKeyHash: Hex.from( + "e257eccafbc07c381642ce6e7e55120fb077fbed" + ), + blindingFactor: Hex.from("f9f0c90d00039523"), refundLocktime: BitcoinLocktimeUtils.calculateLocktime( 1641650400, 2592000 @@ -245,10 +261,14 @@ export const depositSweepWithWitnessMainUtxoAndWitnessOutput: DepositSweepTestDa "934b98637ca318a4d6e7ca6ffd1690b8e77df637" ), // HASH160 of 03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9. - walletPublicKeyHash: "8db50eb52063ea9d98b3eac91489a90f738986f6", + walletPublicKeyHash: Hex.from( + "8db50eb52063ea9d98b3eac91489a90f738986f6" + ), // HASH160 of 039d61d62dcd048d3f8550d22eb90b4af908db60231d117aeede04e7bc11907bfa. - refundPublicKeyHash: "e257eccafbc07c381642ce6e7e55120fb077fbed", - blindingFactor: "f9f0c90d00039523", + refundPublicKeyHash: Hex.from( + "e257eccafbc07c381642ce6e7e55120fb077fbed" + ), + blindingFactor: Hex.from("f9f0c90d00039523"), refundLocktime: BitcoinLocktimeUtils.calculateLocktime( 1641650400, 2592000 @@ -343,10 +363,14 @@ export const depositSweepWithNonWitnessMainUtxoAndWitnessOutput: DepositSweepTes "934b98637ca318a4d6e7ca6ffd1690b8e77df637" ), // HASH160 of 03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9. - walletPublicKeyHash: "8db50eb52063ea9d98b3eac91489a90f738986f6", + walletPublicKeyHash: Hex.from( + "8db50eb52063ea9d98b3eac91489a90f738986f6" + ), // HASH160 of 039d61d62dcd048d3f8550d22eb90b4af908db60231d117aeede04e7bc11907bfa. - refundPublicKeyHash: "e257eccafbc07c381642ce6e7e55120fb077fbed", - blindingFactor: "f9f0c90d00039523", + refundPublicKeyHash: Hex.from( + "e257eccafbc07c381642ce6e7e55120fb077fbed" + ), + blindingFactor: Hex.from("f9f0c90d00039523"), refundLocktime: BitcoinLocktimeUtils.calculateLocktime( 1653302600, 2592000 @@ -404,7 +428,7 @@ export interface DepositSweepProofTestData { rawTransaction: BitcoinRawTx accumulatedTxConfirmations: number latestBlockHeight: number - headersChain: string + headersChain: Hex transactionMerkleBranch: BitcoinTxMerkleBranch } expectedSweepProof: { @@ -498,82 +522,97 @@ export const depositSweepProof: DepositSweepProofTestData = { "120fb077fbed8804e0250162b175ac6800000000", }, latestBlockHeight: 2164335, - headersChain: + headersChain: Hex.from( "04000020642125b3910fdaead521b57955e28893d89f8ce7fd3ba1dd6d0100000" + - "0000000f9e17a266a2267ee02d5ab82a75a76805db821a13abd2e80e0950d8833" + - "11e5355dc21c62ed3e031adefc02c4040000205b6de55e069be71b21a62cd140d" + - "c7031225f7258dc758f19ea01000000000000139966d27d9ed0c0c1ed9162c2fe" + - "a2ccf0ba212706f6bc421d0a2b6211de040d1ac41c62ed3e031a4726538f04e00" + - "0208475e15e0314635d32abf04c761fee528d6a3f2db3b3d13798000000000000" + - "002a3fa06fecd9dd4bf2e25e22a95d4f65435d5c5b42bcf498b4e756f9f4ea67c" + - "ea1c51c62ed3e031a9d7bf3ac000000203f16d450c51853a4cd9569d225028aa0" + - "8ab6139eee31f4f67a010000000000004cda79bc48b970de2fb29c3f38626eb9d" + - "70d8bae7b92aad09f2a0ad2d2f334d35bca1c62ffff001d048fc2170000002068" + - "7e487acbf5eb375c631a15127fbf7d80ca084461e7f26f92c509b6000000006fa" + - "d33bd7c8d651bd6dc86c286f0a99340b668f019b9e97a59fd392c36c4f46910cf" + - "1c62ffff001d407facaa0400002040f4c65610f26f06c4365305b956934501713" + - "e01c2fc08b919e0bc1b00000000e401a6a884ba015e83c6fe2cd363e877ef0398" + - "2e81eaff4e2c95af1e23a670f407d41c62ffff001d58c64d180400002038854bd" + - "62f802e1de14653eceeb7a80290f5e99b8e9db517e36f000000000000a494b803" + - "4039e7855b75563ab83c9410dd67e89bb58e6cd93b85290a885dd749f4d61c62e" + - "d3e031ad9a83746", + "0000000f9e17a266a2267ee02d5ab82a75a76805db821a13abd2e80e0950d8833" + + "11e5355dc21c62ed3e031adefc02c4040000205b6de55e069be71b21a62cd140d" + + "c7031225f7258dc758f19ea01000000000000139966d27d9ed0c0c1ed9162c2fe" + + "a2ccf0ba212706f6bc421d0a2b6211de040d1ac41c62ed3e031a4726538f04e00" + + "0208475e15e0314635d32abf04c761fee528d6a3f2db3b3d13798000000000000" + + "002a3fa06fecd9dd4bf2e25e22a95d4f65435d5c5b42bcf498b4e756f9f4ea67c" + + "ea1c51c62ed3e031a9d7bf3ac000000203f16d450c51853a4cd9569d225028aa0" + + "8ab6139eee31f4f67a010000000000004cda79bc48b970de2fb29c3f38626eb9d" + + "70d8bae7b92aad09f2a0ad2d2f334d35bca1c62ffff001d048fc2170000002068" + + "7e487acbf5eb375c631a15127fbf7d80ca084461e7f26f92c509b6000000006fa" + + "d33bd7c8d651bd6dc86c286f0a99340b668f019b9e97a59fd392c36c4f46910cf" + + "1c62ffff001d407facaa0400002040f4c65610f26f06c4365305b956934501713" + + "e01c2fc08b919e0bc1b00000000e401a6a884ba015e83c6fe2cd363e877ef0398" + + "2e81eaff4e2c95af1e23a670f407d41c62ffff001d58c64d180400002038854bd" + + "62f802e1de14653eceeb7a80290f5e99b8e9db517e36f000000000000a494b803" + + "4039e7855b75563ab83c9410dd67e89bb58e6cd93b85290a885dd749f4d61c62e" + + "d3e031ad9a83746" + ), transactionMerkleBranch: { blockHeight: 2164155, merkle: [ - "322cfdf3ca53cf597b6f08e93489b9a1cfa1f5958c3657474b0d8f5efb5ca92e", - "82aedffef6c9670375effee25740fecce143d21f8abf98307235b7ebd31ad4d1", - "837fa041b9a8f5b42353fdf8981e3b7a78c61858852e43058bfe6cacf9eab5a3", - "a51612d3f3f857e95803a4d86aa6dbbe2e756dc2ed6cc0e04630e8baf597e377", - "a00501650e0c4f8a1e07a5d6d5bc5e75e4c75de61a65f0410cce354bbae78686", + Hex.from( + "322cfdf3ca53cf597b6f08e93489b9a1cfa1f5958c3657474b0d8f5efb5ca92e" + ), + Hex.from( + "82aedffef6c9670375effee25740fecce143d21f8abf98307235b7ebd31ad4d1" + ), + Hex.from( + "837fa041b9a8f5b42353fdf8981e3b7a78c61858852e43058bfe6cacf9eab5a3" + ), + Hex.from( + "a51612d3f3f857e95803a4d86aa6dbbe2e756dc2ed6cc0e04630e8baf597e377" + ), + Hex.from( + "a00501650e0c4f8a1e07a5d6d5bc5e75e4c75de61a65f0410cce354bbae78686" + ), ], position: 6, }, }, expectedSweepProof: { sweepTx: { - version: "01000000", - inputs: + version: Hex.from("01000000"), + inputs: Hex.from( "048f99b22593afdc4e3c08c7821151e801b2e9a16bf307c087a1b8c1f8459e4dea0" + - "0000000c9483045022100bb54f2717647b2f2c5370b5f12b55e27f97a6e2009dcd2" + - "1fca08527df949e1fd022058bc3cd1dd739b89b9e4cda43b13bc59cfb15663b80cb" + - "fa3edb4539107bba35d012103989d253b17a6a0f41838b84ff0d20e8898f9d7b1a9" + - "8f2564da4cc29dcf8581d94c5c14934b98637ca318a4d6e7ca6ffd1690b8e77df63" + - "77508f9f0c90d000395237576a9148db50eb52063ea9d98b3eac91489a90f738986" + - "f68763ac6776a914e257eccafbc07c381642ce6e7e55120fb077fbed8804e025016" + - "2b175ac68fffffffffd337f1abd32f17566e17a3606714d981bb8982339805ebb84" + - "c881174cff44c80000000000ffffffff73a486cf5ca706f513b6bf170ed0e7465d5" + - "bbe2968b4c2a9a207ac0ebc68c5440000000000ffffffff78439e510ac6b659b529" + - "a608611a77ca05f00ca050648212e16447460ec048f50000000000ffffffff", - outputs: - "01789b0000000000001600148db50eb52063ea9d98b3eac91489a90f738986f6", - locktime: "00000000", + "0000000c9483045022100bb54f2717647b2f2c5370b5f12b55e27f97a6e2009dcd2" + + "1fca08527df949e1fd022058bc3cd1dd739b89b9e4cda43b13bc59cfb15663b80cb" + + "fa3edb4539107bba35d012103989d253b17a6a0f41838b84ff0d20e8898f9d7b1a9" + + "8f2564da4cc29dcf8581d94c5c14934b98637ca318a4d6e7ca6ffd1690b8e77df63" + + "77508f9f0c90d000395237576a9148db50eb52063ea9d98b3eac91489a90f738986" + + "f68763ac6776a914e257eccafbc07c381642ce6e7e55120fb077fbed8804e025016" + + "2b175ac68fffffffffd337f1abd32f17566e17a3606714d981bb8982339805ebb84" + + "c881174cff44c80000000000ffffffff73a486cf5ca706f513b6bf170ed0e7465d5" + + "bbe2968b4c2a9a207ac0ebc68c5440000000000ffffffff78439e510ac6b659b529" + + "a608611a77ca05f00ca050648212e16447460ec048f50000000000ffffffff" + ), + outputs: Hex.from( + "01789b0000000000001600148db50eb52063ea9d98b3eac91489a90f738986f6" + ), + locktime: Hex.from("00000000"), }, sweepProof: { - merkleProof: + merkleProof: Hex.from( "2ea95cfb5e8f0d4b4757368c95f5a1cfa1b98934e9086f7b59cf53caf3fd2c32d1d" + - "41ad3ebb735723098bf8a1fd243e1ccfe4057e2feef750367c9f6fedfae82a3b5ea" + - "f9ac6cfe8b05432e855818c6787a3b1e98f8fd5323b4f5a8b941a07f8377e397f5b" + - "ae83046e0c06cedc26d752ebedba66ad8a40358e957f8f3d31216a58686e7ba4b35" + - "ce0c41f0651ae65dc7e4755ebcd5d6a5071e8a4f0c0e650105a0", + "41ad3ebb735723098bf8a1fd243e1ccfe4057e2feef750367c9f6fedfae82a3b5ea" + + "f9ac6cfe8b05432e855818c6787a3b1e98f8fd5323b4f5a8b941a07f8377e397f5b" + + "ae83046e0c06cedc26d752ebedba66ad8a40358e957f8f3d31216a58686e7ba4b35" + + "ce0c41f0651ae65dc7e4755ebcd5d6a5071e8a4f0c0e650105a0" + ), txIndexInBlock: 6, - bitcoinHeaders: + bitcoinHeaders: Hex.from( "04000020642125b3910fdaead521b57955e28893d89f8ce7fd3ba1dd6d010000000" + - "00000f9e17a266a2267ee02d5ab82a75a76805db821a13abd2e80e0950d883311e5" + - "355dc21c62ed3e031adefc02c4040000205b6de55e069be71b21a62cd140dc70312" + - "25f7258dc758f19ea01000000000000139966d27d9ed0c0c1ed9162c2fea2ccf0ba" + - "212706f6bc421d0a2b6211de040d1ac41c62ed3e031a4726538f04e000208475e15" + - "e0314635d32abf04c761fee528d6a3f2db3b3d13798000000000000002a3fa06fec" + - "d9dd4bf2e25e22a95d4f65435d5c5b42bcf498b4e756f9f4ea67cea1c51c62ed3e0" + - "31a9d7bf3ac000000203f16d450c51853a4cd9569d225028aa08ab6139eee31f4f6" + - "7a010000000000004cda79bc48b970de2fb29c3f38626eb9d70d8bae7b92aad09f2" + - "a0ad2d2f334d35bca1c62ffff001d048fc21700000020687e487acbf5eb375c631a" + - "15127fbf7d80ca084461e7f26f92c509b6000000006fad33bd7c8d651bd6dc86c28" + - "6f0a99340b668f019b9e97a59fd392c36c4f46910cf1c62ffff001d407facaa0400" + - "002040f4c65610f26f06c4365305b956934501713e01c2fc08b919e0bc1b0000000" + - "0e401a6a884ba015e83c6fe2cd363e877ef03982e81eaff4e2c95af1e23a670f407" + - "d41c62ffff001d58c64d180400002038854bd62f802e1de14653eceeb7a80290f5e" + - "99b8e9db517e36f000000000000a494b8034039e7855b75563ab83c9410dd67e89b" + - "b58e6cd93b85290a885dd749f4d61c62ed3e031ad9a83746", + "00000f9e17a266a2267ee02d5ab82a75a76805db821a13abd2e80e0950d883311e5" + + "355dc21c62ed3e031adefc02c4040000205b6de55e069be71b21a62cd140dc70312" + + "25f7258dc758f19ea01000000000000139966d27d9ed0c0c1ed9162c2fea2ccf0ba" + + "212706f6bc421d0a2b6211de040d1ac41c62ed3e031a4726538f04e000208475e15" + + "e0314635d32abf04c761fee528d6a3f2db3b3d13798000000000000002a3fa06fec" + + "d9dd4bf2e25e22a95d4f65435d5c5b42bcf498b4e756f9f4ea67cea1c51c62ed3e0" + + "31a9d7bf3ac000000203f16d450c51853a4cd9569d225028aa08ab6139eee31f4f6" + + "7a010000000000004cda79bc48b970de2fb29c3f38626eb9d70d8bae7b92aad09f2" + + "a0ad2d2f334d35bca1c62ffff001d048fc21700000020687e487acbf5eb375c631a" + + "15127fbf7d80ca084461e7f26f92c509b6000000006fad33bd7c8d651bd6dc86c28" + + "6f0a99340b668f019b9e97a59fd392c36c4f46910cf1c62ffff001d407facaa0400" + + "002040f4c65610f26f06c4365305b956934501713e01c2fc08b919e0bc1b0000000" + + "0e401a6a884ba015e83c6fe2cd363e877ef03982e81eaff4e2c95af1e23a670f407" + + "d41c62ffff001d58c64d180400002038854bd62f802e1de14653eceeb7a80290f5e" + + "99b8e9db517e36f000000000000a494b8034039e7855b75563ab83c9410dd67e89b" + + "b58e6cd93b85290a885dd749f4d61c62ed3e031ad9a83746" + ), }, mainUtxo: NO_MAIN_UTXO, }, diff --git a/typescript/test/data/electrum.ts b/typescript/test/data/electrum.ts index 22d930672..3782d755e 100644 --- a/typescript/test/data/electrum.ts +++ b/typescript/test/data/electrum.ts @@ -75,23 +75,24 @@ export const testnetUTXO: BitcoinUtxo = { export const testnetHeadersChain = { blockHeight: 1569342, headersChainLength: 6, - headersChain: + headersChain: Hex.from( "00000020a114bf2d1e930390044cc4e00dd2f490a36dcecb4b6bb702b50200000000000" + - "0583b7a45472123fac1003384cc60fce2129c8d7364969dfa35021ab26c0b0449bccc2e" + - "5dffff001d061013a10000ff3f3210404a744c3170cdd6ad7fc901194c913004faa87f2" + - "91cd3faac2b00000000ecc1620341eeee4881423cab631e6e4a0b003c05ffc2dfc132a2" + - "a902a45df2c573d02e5d148c031af7358d5f00e0ff3fd83c1e679a4766043e3dbc62287" + - "0e64ba4c2cacfa2f45563210100000000000071d244c45daecf0abf15c5f4e47f123109" + - "12918ca56b89c3dfb68103371ae6bf98d42e5d148c031aca5d525e00000020d2a6ad530" + - "4a5bbe4948666fd6775dc2cde9c0cef7060a471fe01000000000000597701d1165c140f" + - "471f2684f1f6b3e97765ee5492619582af5e6d192895e7d34cd92e5dffff001dbb34c42" + - "400000020b9b3fcbb515c899b10bf3889d432ca2782cfad01f9c2cf329fb60e00000000" + - "0048d580fbe9ccf1cadaffe0e780eab57ea401f6260f38bd459d32cc3eef6cbd33ffd92" + - "e5d148c031a3c4277f40000002024af4d64067c20a1ed5cb9fbd432a98fe659e3653378" + - "e6b9ed00000000000000fea85a41c80b307f9cdfd22ac52521ba89ea6467769206d8988" + - "9663cb7742e7358db2e5d148c031a7d30031a0000ff3f6418122efc0ddf2416189b01c0" + - "d98ab7e5072fe1e99c3e275401000000000000496c06f87b8d442db7c6bd36ff05e3a7a" + - "0edb3e0124d26c61d44c584ba1f8ff86bdc2e5d148c031a411e00ae", + "0583b7a45472123fac1003384cc60fce2129c8d7364969dfa35021ab26c0b0449bccc2e" + + "5dffff001d061013a10000ff3f3210404a744c3170cdd6ad7fc901194c913004faa87f2" + + "91cd3faac2b00000000ecc1620341eeee4881423cab631e6e4a0b003c05ffc2dfc132a2" + + "a902a45df2c573d02e5d148c031af7358d5f00e0ff3fd83c1e679a4766043e3dbc62287" + + "0e64ba4c2cacfa2f45563210100000000000071d244c45daecf0abf15c5f4e47f123109" + + "12918ca56b89c3dfb68103371ae6bf98d42e5d148c031aca5d525e00000020d2a6ad530" + + "4a5bbe4948666fd6775dc2cde9c0cef7060a471fe01000000000000597701d1165c140f" + + "471f2684f1f6b3e97765ee5492619582af5e6d192895e7d34cd92e5dffff001dbb34c42" + + "400000020b9b3fcbb515c899b10bf3889d432ca2782cfad01f9c2cf329fb60e00000000" + + "0048d580fbe9ccf1cadaffe0e780eab57ea401f6260f38bd459d32cc3eef6cbd33ffd92" + + "e5d148c031a3c4277f40000002024af4d64067c20a1ed5cb9fbd432a98fe659e3653378" + + "e6b9ed00000000000000fea85a41c80b307f9cdfd22ac52521ba89ea6467769206d8988" + + "9663cb7742e7358db2e5d148c031a7d30031a0000ff3f6418122efc0ddf2416189b01c0" + + "d98ab7e5072fe1e99c3e275401000000000000496c06f87b8d442db7c6bd36ff05e3a7a" + + "0edb3e0124d26c61d44c584ba1f8ff86bdc2e5d148c031a411e00ae" + ), } /** @@ -100,15 +101,61 @@ export const testnetHeadersChain = { export const testnetTransactionMerkleBranch: BitcoinTxMerkleBranch = { blockHeight: 1569342, merkle: [ - "8b5bbb5bdf6727bf70fad4f46fe4eaab04c98119ffbd2d95c29adf32d26f8452", - "53637bacb07965e4a8220836861d1b16c6da29f10ea9ab53fc4eca73074f98b9", - "0267e738108d094ceb05217e2942e9c2a4c6389ac47f476f572c9a319ce4dfbc", - "34e00deec50c48d99678ca2b52b82d6d5432326159c69e7233d0dde0924874b4", - "7a53435e6c86a3620cdbae510901f17958f0540314214379197874ed8ed7a913", - "6315dbb7ce350ceaa16cd4c35c5a147005e8b38ca1e9531bd7320629e8d17f5b", - "40380cdadc0206646208871e952af9dcfdff2f104305ce463aed5eeaf7725d2f", - "5d74bae6a71fd1cff2416865460583319a40343650bd4bb89de0a6ae82097037", - "296ddccfc659e0009aad117c8ed15fb6ff81c2bade73fbc89666a22708d233f9", + Hex.from( + "8b5bbb5bdf6727bf70fad4f46fe4eaab04c98119ffbd2d95c29adf32d26f8452" + ), + Hex.from( + "53637bacb07965e4a8220836861d1b16c6da29f10ea9ab53fc4eca73074f98b9" + ), + Hex.from( + "0267e738108d094ceb05217e2942e9c2a4c6389ac47f476f572c9a319ce4dfbc" + ), + Hex.from( + "34e00deec50c48d99678ca2b52b82d6d5432326159c69e7233d0dde0924874b4" + ), + Hex.from( + "7a53435e6c86a3620cdbae510901f17958f0540314214379197874ed8ed7a913" + ), + Hex.from( + "6315dbb7ce350ceaa16cd4c35c5a147005e8b38ca1e9531bd7320629e8d17f5b" + ), + Hex.from( + "40380cdadc0206646208871e952af9dcfdff2f104305ce463aed5eeaf7725d2f" + ), + Hex.from( + "5d74bae6a71fd1cff2416865460583319a40343650bd4bb89de0a6ae82097037" + ), + Hex.from( + "296ddccfc659e0009aad117c8ed15fb6ff81c2bade73fbc89666a22708d233f9" + ), ], position: 176, } + +/** + * Public key hash that has associated transactions locking funds to it. + */ +export const testnetPublicKeyHash = Hex.from( + "e6f9d74726b19b75f16fe1e9feaec048aa4fa1d0" +) + +/** + * Transaction hashes corresponding to {@link testnetPublicKeyHash} + */ +export const testnetTxHashes: BitcoinTxHash[] = [ + BitcoinTxHash.from( + "f65bc5029251f0042aedb37f90dbb2bfb63a2e81694beef9cae5ec62e954c22e" + ), + BitcoinTxHash.from( + "44863a79ce2b8fec9792403d5048506e50ffa7338191db0e6c30d3d3358ea2f6" + ), + BitcoinTxHash.from( + "4c6b33b7c0550e0e536a5d119ac7189d71e1296fcb0c258e0c115356895bc0e6" + ), + BitcoinTxHash.from( + "605edd75ae0b4fa7cfc7aae8f1399119e9d7ecc212e6253156b60d60f4925d44" + ), + BitcoinTxHash.from( + "4f9affc5b418385d5aa61e23caa0b55156bf0682d5fedf2d905446f3f88aec6c" + ), +] diff --git a/typescript/test/data/proof.ts b/typescript/test/data/proof.ts index bbd94a853..6d3e114c0 100644 --- a/typescript/test/data/proof.ts +++ b/typescript/test/data/proof.ts @@ -18,7 +18,7 @@ export interface ProofTestData { rawTransaction: BitcoinRawTx accumulatedTxConfirmations: number latestBlockHeight: number - headersChain: string + headersChain: Hex transactionMerkleBranch: BitcoinTxMerkleBranch } expectedProof: BitcoinSpvProof & BitcoinTx @@ -68,35 +68,50 @@ export const singleInputProofTestData: ProofTestData = { }, accumulatedTxConfirmations: 50, latestBlockHeight: 2164335, - headersChain: + headersChain: Hex.from( "04e00020732d33ea35d62f9488cff5d64c0d702afd5d88092230ddfcc45f00000" + - "0000000196283ba24a3f5bad91ef95338aa6d214c934f2c1392e39a0447377fe5" + - "b0a04be7c01c62ffff001df0be0a27040000206c318b23e5c42e86ef3edd080e5" + - "0c9c233b9f0b6d186bd57e41300000000000021fb8cda200bff4fec1338d85a1e" + - "005bb4d729d908a7c5c232ecd0713231d0445ec11c62ed3e031a7b43466e04e00" + - "020f416898d79d4a46fa6c54f190ad3d502bad8aa3afdec0714aa000000000000" + - "000603a5cc15e5906cb4eac9f747869fdc9be856e76a110b4f87da90db20f9fbe" + - "28fc11c62ed3e031a15dfc3db04000020642125b3910fdaead521b57955e28893" + - "d89f8ce7fd3ba1dd6d01000000000000f9e17a266a2267ee02d5ab82a75a76805" + - "db821a13abd2e80e0950d883311e5355dc21c62ed3e031adefc02c4040000205b" + - "6de55e069be71b21a62cd140dc7031225f7258dc758f19ea01000000000000139" + - "966d27d9ed0c0c1ed9162c2fea2ccf0ba212706f6bc421d0a2b6211de040d1ac4" + - "1c62ed3e031a4726538f04e000208475e15e0314635d32abf04c761fee528d6a3" + - "f2db3b3d13798000000000000002a3fa06fecd9dd4bf2e25e22a95d4f65435d5c" + - "5b42bcf498b4e756f9f4ea67cea1c51c62ed3e031a9d7bf3ac000000203f16d45" + - "0c51853a4cd9569d225028aa08ab6139eee31f4f67a010000000000004cda79bc" + - "48b970de2fb29c3f38626eb9d70d8bae7b92aad09f2a0ad2d2f334d35bca1c62f" + - "fff001d048fc217", + "0000000196283ba24a3f5bad91ef95338aa6d214c934f2c1392e39a0447377fe5" + + "b0a04be7c01c62ffff001df0be0a27040000206c318b23e5c42e86ef3edd080e5" + + "0c9c233b9f0b6d186bd57e41300000000000021fb8cda200bff4fec1338d85a1e" + + "005bb4d729d908a7c5c232ecd0713231d0445ec11c62ed3e031a7b43466e04e00" + + "020f416898d79d4a46fa6c54f190ad3d502bad8aa3afdec0714aa000000000000" + + "000603a5cc15e5906cb4eac9f747869fdc9be856e76a110b4f87da90db20f9fbe" + + "28fc11c62ed3e031a15dfc3db04000020642125b3910fdaead521b57955e28893" + + "d89f8ce7fd3ba1dd6d01000000000000f9e17a266a2267ee02d5ab82a75a76805" + + "db821a13abd2e80e0950d883311e5355dc21c62ed3e031adefc02c4040000205b" + + "6de55e069be71b21a62cd140dc7031225f7258dc758f19ea01000000000000139" + + "966d27d9ed0c0c1ed9162c2fea2ccf0ba212706f6bc421d0a2b6211de040d1ac4" + + "1c62ed3e031a4726538f04e000208475e15e0314635d32abf04c761fee528d6a3" + + "f2db3b3d13798000000000000002a3fa06fecd9dd4bf2e25e22a95d4f65435d5c" + + "5b42bcf498b4e756f9f4ea67cea1c51c62ed3e031a9d7bf3ac000000203f16d45" + + "0c51853a4cd9569d225028aa08ab6139eee31f4f67a010000000000004cda79bc" + + "48b970de2fb29c3f38626eb9d70d8bae7b92aad09f2a0ad2d2f334d35bca1c62f" + + "fff001d048fc217" + ), transactionMerkleBranch: { blockHeight: 2164152, merkle: [ - "7bffaff2c61291861276da41cf6c3842fad555af97dd1ff98ce41c61a0072b12", - "7a5876ddee8e553ff0650c739b2ec66e192d8afe5fc0ce763bf810457aea330c", - "2d17b67d5519bc39fbef8650afd3fe11fdfb3f471434a5b551cfa9a41441901f", - "1376d102b677591ce2fa62553e2a57ab5919022b03036521facfce93a0338026", - "43ad3aadad675e398c59eb846a8e037cf7de8ba3b38f3388175f25d84b777c80", - "6969c227128793b3c9e99c05f20fb9b91fdb73458fd53151b5fe29d30c10cf9a", - "0a76bc4d8c3d532357be4d188ba89e9ae364a7d3c365e690e3cb07359b86129c", + Hex.from( + "7bffaff2c61291861276da41cf6c3842fad555af97dd1ff98ce41c61a0072b12" + ), + Hex.from( + "7a5876ddee8e553ff0650c739b2ec66e192d8afe5fc0ce763bf810457aea330c" + ), + Hex.from( + "2d17b67d5519bc39fbef8650afd3fe11fdfb3f471434a5b551cfa9a41441901f" + ), + Hex.from( + "1376d102b677591ce2fa62553e2a57ab5919022b03036521facfce93a0338026" + ), + Hex.from( + "43ad3aadad675e398c59eb846a8e037cf7de8ba3b38f3388175f25d84b777c80" + ), + Hex.from( + "6969c227128793b3c9e99c05f20fb9b91fdb73458fd53151b5fe29d30c10cf9a" + ), + Hex.from( + "0a76bc4d8c3d532357be4d188ba89e9ae364a7d3c365e690e3cb07359b86129c" + ), ], position: 11, }, @@ -121,33 +136,35 @@ export const singleInputProofTestData: ProofTestData = { scriptPubKey: Hex.from("00148db50eb52063ea9d98b3eac91489a90f738986f6"), }, ], - merkleProof: + merkleProof: Hex.from( "122b07a0611ce48cf91fdd97af55d5fa42386ccf41da7612869112c6f2afff7b0c" + - "33ea7a4510f83b76cec05ffe8a2d196ec62e9b730c65f03f558eeedd76587a1f90" + - "4114a4a9cf51b5a53414473ffbfd11fed3af5086effb39bc19557db6172d268033" + - "a093cecffa216503032b021959ab572a3e5562fae21c5977b602d17613807c774b" + - "d8255f1788338fb3a38bdef77c038e6a84eb598c395e67adad3aad439acf100cd3" + - "29feb55131d58f4573db1fb9b90ff2059ce9c9b393871227c269699c12869b3507" + - "cbe390e665c3d3a764e39a9ea88b184dbe5723533d8c4dbc760a", + "33ea7a4510f83b76cec05ffe8a2d196ec62e9b730c65f03f558eeedd76587a1f90" + + "4114a4a9cf51b5a53414473ffbfd11fed3af5086effb39bc19557db6172d268033" + + "a093cecffa216503032b021959ab572a3e5562fae21c5977b602d17613807c774b" + + "d8255f1788338fb3a38bdef77c038e6a84eb598c395e67adad3aad439acf100cd3" + + "29feb55131d58f4573db1fb9b90ff2059ce9c9b393871227c269699c12869b3507" + + "cbe390e665c3d3a764e39a9ea88b184dbe5723533d8c4dbc760a" + ), txIndexInBlock: 11, - bitcoinHeaders: + bitcoinHeaders: Hex.from( "04e00020732d33ea35d62f9488cff5d64c0d702afd5d88092230ddfcc45f000000" + - "000000196283ba24a3f5bad91ef95338aa6d214c934f2c1392e39a0447377fe5b0" + - "a04be7c01c62ffff001df0be0a27040000206c318b23e5c42e86ef3edd080e50c9" + - "c233b9f0b6d186bd57e41300000000000021fb8cda200bff4fec1338d85a1e005b" + - "b4d729d908a7c5c232ecd0713231d0445ec11c62ed3e031a7b43466e04e00020f4" + - "16898d79d4a46fa6c54f190ad3d502bad8aa3afdec0714aa000000000000000603" + - "a5cc15e5906cb4eac9f747869fdc9be856e76a110b4f87da90db20f9fbe28fc11c" + - "62ed3e031a15dfc3db04000020642125b3910fdaead521b57955e28893d89f8ce7" + - "fd3ba1dd6d01000000000000f9e17a266a2267ee02d5ab82a75a76805db821a13a" + - "bd2e80e0950d883311e5355dc21c62ed3e031adefc02c4040000205b6de55e069b" + - "e71b21a62cd140dc7031225f7258dc758f19ea01000000000000139966d27d9ed0" + - "c0c1ed9162c2fea2ccf0ba212706f6bc421d0a2b6211de040d1ac41c62ed3e031a" + - "4726538f04e000208475e15e0314635d32abf04c761fee528d6a3f2db3b3d13798" + - "000000000000002a3fa06fecd9dd4bf2e25e22a95d4f65435d5c5b42bcf498b4e7" + - "56f9f4ea67cea1c51c62ed3e031a9d7bf3ac000000203f16d450c51853a4cd9569" + - "d225028aa08ab6139eee31f4f67a010000000000004cda79bc48b970de2fb29c3f" + - "38626eb9d70d8bae7b92aad09f2a0ad2d2f334d35bca1c62ffff001d048fc217", + "000000196283ba24a3f5bad91ef95338aa6d214c934f2c1392e39a0447377fe5b0" + + "a04be7c01c62ffff001df0be0a27040000206c318b23e5c42e86ef3edd080e50c9" + + "c233b9f0b6d186bd57e41300000000000021fb8cda200bff4fec1338d85a1e005b" + + "b4d729d908a7c5c232ecd0713231d0445ec11c62ed3e031a7b43466e04e00020f4" + + "16898d79d4a46fa6c54f190ad3d502bad8aa3afdec0714aa000000000000000603" + + "a5cc15e5906cb4eac9f747869fdc9be856e76a110b4f87da90db20f9fbe28fc11c" + + "62ed3e031a15dfc3db04000020642125b3910fdaead521b57955e28893d89f8ce7" + + "fd3ba1dd6d01000000000000f9e17a266a2267ee02d5ab82a75a76805db821a13a" + + "bd2e80e0950d883311e5355dc21c62ed3e031adefc02c4040000205b6de55e069b" + + "e71b21a62cd140dc7031225f7258dc758f19ea01000000000000139966d27d9ed0" + + "c0c1ed9162c2fea2ccf0ba212706f6bc421d0a2b6211de040d1ac41c62ed3e031a" + + "4726538f04e000208475e15e0314635d32abf04c761fee528d6a3f2db3b3d13798" + + "000000000000002a3fa06fecd9dd4bf2e25e22a95d4f65435d5c5b42bcf498b4e7" + + "56f9f4ea67cea1c51c62ed3e031a9d7bf3ac000000203f16d450c51853a4cd9569" + + "d225028aa08ab6139eee31f4f67a010000000000004cda79bc48b970de2fb29c3f" + + "38626eb9d70d8bae7b92aad09f2a0ad2d2f334d35bca1c62ffff001d048fc217" + ), }, } @@ -237,33 +254,44 @@ export const multipleInputsProofTestData: ProofTestData = { "120fb077fbed8804e0250162b175ac6800000000", }, latestBlockHeight: 2164335, - headersChain: + headersChain: Hex.from( "04000020642125b3910fdaead521b57955e28893d89f8ce7fd3ba1dd6d0100000" + - "0000000f9e17a266a2267ee02d5ab82a75a76805db821a13abd2e80e0950d8833" + - "11e5355dc21c62ed3e031adefc02c4040000205b6de55e069be71b21a62cd140d" + - "c7031225f7258dc758f19ea01000000000000139966d27d9ed0c0c1ed9162c2fe" + - "a2ccf0ba212706f6bc421d0a2b6211de040d1ac41c62ed3e031a4726538f04e00" + - "0208475e15e0314635d32abf04c761fee528d6a3f2db3b3d13798000000000000" + - "002a3fa06fecd9dd4bf2e25e22a95d4f65435d5c5b42bcf498b4e756f9f4ea67c" + - "ea1c51c62ed3e031a9d7bf3ac000000203f16d450c51853a4cd9569d225028aa0" + - "8ab6139eee31f4f67a010000000000004cda79bc48b970de2fb29c3f38626eb9d" + - "70d8bae7b92aad09f2a0ad2d2f334d35bca1c62ffff001d048fc2170000002068" + - "7e487acbf5eb375c631a15127fbf7d80ca084461e7f26f92c509b6000000006fa" + - "d33bd7c8d651bd6dc86c286f0a99340b668f019b9e97a59fd392c36c4f46910cf" + - "1c62ffff001d407facaa0400002040f4c65610f26f06c4365305b956934501713" + - "e01c2fc08b919e0bc1b00000000e401a6a884ba015e83c6fe2cd363e877ef0398" + - "2e81eaff4e2c95af1e23a670f407d41c62ffff001d58c64d180400002038854bd" + - "62f802e1de14653eceeb7a80290f5e99b8e9db517e36f000000000000a494b803" + - "4039e7855b75563ab83c9410dd67e89bb58e6cd93b85290a885dd749f4d61c62e" + - "d3e031ad9a83746", + "0000000f9e17a266a2267ee02d5ab82a75a76805db821a13abd2e80e0950d8833" + + "11e5355dc21c62ed3e031adefc02c4040000205b6de55e069be71b21a62cd140d" + + "c7031225f7258dc758f19ea01000000000000139966d27d9ed0c0c1ed9162c2fe" + + "a2ccf0ba212706f6bc421d0a2b6211de040d1ac41c62ed3e031a4726538f04e00" + + "0208475e15e0314635d32abf04c761fee528d6a3f2db3b3d13798000000000000" + + "002a3fa06fecd9dd4bf2e25e22a95d4f65435d5c5b42bcf498b4e756f9f4ea67c" + + "ea1c51c62ed3e031a9d7bf3ac000000203f16d450c51853a4cd9569d225028aa0" + + "8ab6139eee31f4f67a010000000000004cda79bc48b970de2fb29c3f38626eb9d" + + "70d8bae7b92aad09f2a0ad2d2f334d35bca1c62ffff001d048fc2170000002068" + + "7e487acbf5eb375c631a15127fbf7d80ca084461e7f26f92c509b6000000006fa" + + "d33bd7c8d651bd6dc86c286f0a99340b668f019b9e97a59fd392c36c4f46910cf" + + "1c62ffff001d407facaa0400002040f4c65610f26f06c4365305b956934501713" + + "e01c2fc08b919e0bc1b00000000e401a6a884ba015e83c6fe2cd363e877ef0398" + + "2e81eaff4e2c95af1e23a670f407d41c62ffff001d58c64d180400002038854bd" + + "62f802e1de14653eceeb7a80290f5e99b8e9db517e36f000000000000a494b803" + + "4039e7855b75563ab83c9410dd67e89bb58e6cd93b85290a885dd749f4d61c62e" + + "d3e031ad9a83746" + ), transactionMerkleBranch: { blockHeight: 2164155, merkle: [ - "322cfdf3ca53cf597b6f08e93489b9a1cfa1f5958c3657474b0d8f5efb5ca92e", - "82aedffef6c9670375effee25740fecce143d21f8abf98307235b7ebd31ad4d1", - "837fa041b9a8f5b42353fdf8981e3b7a78c61858852e43058bfe6cacf9eab5a3", - "a51612d3f3f857e95803a4d86aa6dbbe2e756dc2ed6cc0e04630e8baf597e377", - "a00501650e0c4f8a1e07a5d6d5bc5e75e4c75de61a65f0410cce354bbae78686", + Hex.from( + "322cfdf3ca53cf597b6f08e93489b9a1cfa1f5958c3657474b0d8f5efb5ca92e" + ), + Hex.from( + "82aedffef6c9670375effee25740fecce143d21f8abf98307235b7ebd31ad4d1" + ), + Hex.from( + "837fa041b9a8f5b42353fdf8981e3b7a78c61858852e43058bfe6cacf9eab5a3" + ), + Hex.from( + "a51612d3f3f857e95803a4d86aa6dbbe2e756dc2ed6cc0e04630e8baf597e377" + ), + Hex.from( + "a00501650e0c4f8a1e07a5d6d5bc5e75e4c75de61a65f0410cce354bbae78686" + ), ], position: 6, }, @@ -309,31 +337,33 @@ export const multipleInputsProofTestData: ProofTestData = { scriptPubKey: Hex.from("00148db50eb52063ea9d98b3eac91489a90f738986f6"), }, ], - merkleProof: + merkleProof: Hex.from( "2ea95cfb5e8f0d4b4757368c95f5a1cfa1b98934e9086f7b59cf53caf3fd2c32d1d" + - "41ad3ebb735723098bf8a1fd243e1ccfe4057e2feef750367c9f6fedfae82a3b5ea" + - "f9ac6cfe8b05432e855818c6787a3b1e98f8fd5323b4f5a8b941a07f8377e397f5b" + - "ae83046e0c06cedc26d752ebedba66ad8a40358e957f8f3d31216a58686e7ba4b35" + - "ce0c41f0651ae65dc7e4755ebcd5d6a5071e8a4f0c0e650105a0", + "41ad3ebb735723098bf8a1fd243e1ccfe4057e2feef750367c9f6fedfae82a3b5ea" + + "f9ac6cfe8b05432e855818c6787a3b1e98f8fd5323b4f5a8b941a07f8377e397f5b" + + "ae83046e0c06cedc26d752ebedba66ad8a40358e957f8f3d31216a58686e7ba4b35" + + "ce0c41f0651ae65dc7e4755ebcd5d6a5071e8a4f0c0e650105a0" + ), txIndexInBlock: 6, - bitcoinHeaders: + bitcoinHeaders: Hex.from( "04000020642125b3910fdaead521b57955e28893d89f8ce7fd3ba1dd6d010000000" + - "00000f9e17a266a2267ee02d5ab82a75a76805db821a13abd2e80e0950d883311e5" + - "355dc21c62ed3e031adefc02c4040000205b6de55e069be71b21a62cd140dc70312" + - "25f7258dc758f19ea01000000000000139966d27d9ed0c0c1ed9162c2fea2ccf0ba" + - "212706f6bc421d0a2b6211de040d1ac41c62ed3e031a4726538f04e000208475e15" + - "e0314635d32abf04c761fee528d6a3f2db3b3d13798000000000000002a3fa06fec" + - "d9dd4bf2e25e22a95d4f65435d5c5b42bcf498b4e756f9f4ea67cea1c51c62ed3e0" + - "31a9d7bf3ac000000203f16d450c51853a4cd9569d225028aa08ab6139eee31f4f6" + - "7a010000000000004cda79bc48b970de2fb29c3f38626eb9d70d8bae7b92aad09f2" + - "a0ad2d2f334d35bca1c62ffff001d048fc21700000020687e487acbf5eb375c631a" + - "15127fbf7d80ca084461e7f26f92c509b6000000006fad33bd7c8d651bd6dc86c28" + - "6f0a99340b668f019b9e97a59fd392c36c4f46910cf1c62ffff001d407facaa0400" + - "002040f4c65610f26f06c4365305b956934501713e01c2fc08b919e0bc1b0000000" + - "0e401a6a884ba015e83c6fe2cd363e877ef03982e81eaff4e2c95af1e23a670f407" + - "d41c62ffff001d58c64d180400002038854bd62f802e1de14653eceeb7a80290f5e" + - "99b8e9db517e36f000000000000a494b8034039e7855b75563ab83c9410dd67e89b" + - "b58e6cd93b85290a885dd749f4d61c62ed3e031ad9a83746", + "00000f9e17a266a2267ee02d5ab82a75a76805db821a13abd2e80e0950d883311e5" + + "355dc21c62ed3e031adefc02c4040000205b6de55e069be71b21a62cd140dc70312" + + "25f7258dc758f19ea01000000000000139966d27d9ed0c0c1ed9162c2fea2ccf0ba" + + "212706f6bc421d0a2b6211de040d1ac41c62ed3e031a4726538f04e000208475e15" + + "e0314635d32abf04c761fee528d6a3f2db3b3d13798000000000000002a3fa06fec" + + "d9dd4bf2e25e22a95d4f65435d5c5b42bcf498b4e756f9f4ea67cea1c51c62ed3e0" + + "31a9d7bf3ac000000203f16d450c51853a4cd9569d225028aa08ab6139eee31f4f6" + + "7a010000000000004cda79bc48b970de2fb29c3f38626eb9d70d8bae7b92aad09f2" + + "a0ad2d2f334d35bca1c62ffff001d048fc21700000020687e487acbf5eb375c631a" + + "15127fbf7d80ca084461e7f26f92c509b6000000006fad33bd7c8d651bd6dc86c28" + + "6f0a99340b668f019b9e97a59fd392c36c4f46910cf1c62ffff001d407facaa0400" + + "002040f4c65610f26f06c4365305b956934501713e01c2fc08b919e0bc1b0000000" + + "0e401a6a884ba015e83c6fe2cd363e877ef03982e81eaff4e2c95af1e23a670f407" + + "d41c62ffff001d58c64d180400002038854bd62f802e1de14653eceeb7a80290f5e" + + "99b8e9db517e36f000000000000a494b8034039e7855b75563ab83c9410dd67e89b" + + "b58e6cd93b85290a885dd749f4d61c62ed3e031ad9a83746" + ), }, } @@ -346,7 +376,7 @@ export interface TransactionProofData { transaction: BitcoinTx accumulatedTxConfirmations: number latestBlockHeight: number - headersChain: string + headersChain: Hex transactionMerkleBranch: BitcoinTxMerkleBranch previousDifficulty: BigNumber currentDifficulty: BigNumber @@ -414,35 +444,58 @@ export const transactionConfirmationsInOneEpochData: TransactionProofData = { }, accumulatedTxConfirmations: 1798, latestBlockHeight: 777963, - headersChain: + headersChain: Hex.from( "00e0ff2f5ad9c09e1d8aae777a58bf29c41621eb629032598f7900000000000000000" + - "0004dea17724c3b7e67d4cf1ac41a4c7527b884f7406575eaf5b8efaf2fb12572ecb1" + - "ace86339300717760098100000ff3fd3ab40174610c286e569edd20fa713bd98bab53" + - "bee83050000000000000000002345f5ef807cf75de7b30ccfe493c46c6e07aca044aa" + - "2aa106141637f1bb8500a6ade863393007177fbbd4b300800120646d493817f0ac988" + - "6a0a194ca3a957f70c3eb642ffd05000000000000000000d95674b737f097f042eebe" + - "b970c09b274df7e72a9c202ff2292ed72b056ee90967aee863393007172e2bb92e006" + - "03b27a391d248c258ef628dfb8c710ce44c8017667a07941402000000000000000000" + - "35214e58eb018dea1efa7eaf1b7f19ff2d6f0310c122be6dc8c0258d9524ae9382aee" + - "863393007173e82b2000000002003c7003ff9a79f16d956fc764b43b35080efe3a820" + - "af050000000000000000007808e96809cd46d5898d86faabc8f28a8b6572eb8399796" + - "70b2851d78fc1f75f17b3e86339300717450f17650400e020fb9b6a28bb2e9cea36d3" + - "40588f19ffa4e944b050e73f03000000000000000000bbd7534f2550ee99f31efcd77" + - "564f1b5b3f3966a76847896a8d9f9ee964d670ba2b4e8633930071777b10cfc", + "0004dea17724c3b7e67d4cf1ac41a4c7527b884f7406575eaf5b8efaf2fb12572ecb1" + + "ace86339300717760098100000ff3fd3ab40174610c286e569edd20fa713bd98bab53" + + "bee83050000000000000000002345f5ef807cf75de7b30ccfe493c46c6e07aca044aa" + + "2aa106141637f1bb8500a6ade863393007177fbbd4b300800120646d493817f0ac988" + + "6a0a194ca3a957f70c3eb642ffd05000000000000000000d95674b737f097f042eebe" + + "b970c09b274df7e72a9c202ff2292ed72b056ee90967aee863393007172e2bb92e006" + + "03b27a391d248c258ef628dfb8c710ce44c8017667a07941402000000000000000000" + + "35214e58eb018dea1efa7eaf1b7f19ff2d6f0310c122be6dc8c0258d9524ae9382aee" + + "863393007173e82b2000000002003c7003ff9a79f16d956fc764b43b35080efe3a820" + + "af050000000000000000007808e96809cd46d5898d86faabc8f28a8b6572eb8399796" + + "70b2851d78fc1f75f17b3e86339300717450f17650400e020fb9b6a28bb2e9cea36d3" + + "40588f19ffa4e944b050e73f03000000000000000000bbd7534f2550ee99f31efcd77" + + "564f1b5b3f3966a76847896a8d9f9ee964d670ba2b4e8633930071777b10cfc" + ), transactionMerkleBranch: { blockHeight: 776166, merkle: [ - "f6ce0e34cc5b2a4b8cd4fd02a65d7cf62013206969e8e5cf1df18f994abcf1ff", - "08899ec43299b324583722f3e7d0938446a1f31a6ab34c8e24cb4ea9ba6cd384", - "9677b6075dfa2da8bcc98aa10ae7d30f81e6506215eadd3f3739a5d987e62b35", - "aa6712d8820c06ec8ce99f9c19d580ab54bb45f69b426935153b81e7d412ddba", - "b38be47e1dd9a7324ad81a395a133f26fc88cb736a4998dbba6cbabca10629a8", - "13bdefbf92421aa7861528e16e7046b569d25ee0f4b7649492e42e9ea2331c39", - "df429494c5eef971a7ab80c8a0f7f9cdfa30148afef706f07923bd93d5a7e22a", - "c8a3f1bc73146bd4a1a0e848f2b0b4a21be86e4930f239d856af8e9646014236", - "1f514df87fe2c400e508e01cd8967657ef76db9681f65dc82b0bc6d4004b575f", - "e463950c8efd9114237189f07ddf1cfdb72658bad23bce667c269652bd0ade3c", - "3d7ae6df787807320fdc397a7055e86c932a7c36ab1d1f942b92c53bf2a1d2f9", + Hex.from( + "f6ce0e34cc5b2a4b8cd4fd02a65d7cf62013206969e8e5cf1df18f994abcf1ff" + ), + Hex.from( + "08899ec43299b324583722f3e7d0938446a1f31a6ab34c8e24cb4ea9ba6cd384" + ), + Hex.from( + "9677b6075dfa2da8bcc98aa10ae7d30f81e6506215eadd3f3739a5d987e62b35" + ), + Hex.from( + "aa6712d8820c06ec8ce99f9c19d580ab54bb45f69b426935153b81e7d412ddba" + ), + Hex.from( + "b38be47e1dd9a7324ad81a395a133f26fc88cb736a4998dbba6cbabca10629a8" + ), + Hex.from( + "13bdefbf92421aa7861528e16e7046b569d25ee0f4b7649492e42e9ea2331c39" + ), + Hex.from( + "df429494c5eef971a7ab80c8a0f7f9cdfa30148afef706f07923bd93d5a7e22a" + ), + Hex.from( + "c8a3f1bc73146bd4a1a0e848f2b0b4a21be86e4930f239d856af8e9646014236" + ), + Hex.from( + "1f514df87fe2c400e508e01cd8967657ef76db9681f65dc82b0bc6d4004b575f" + ), + Hex.from( + "e463950c8efd9114237189f07ddf1cfdb72658bad23bce667c269652bd0ade3c" + ), + Hex.from( + "3d7ae6df787807320fdc397a7055e86c932a7c36ab1d1f942b92c53bf2a1d2f9" + ), ], position: 17, }, @@ -491,34 +544,55 @@ export const transactionConfirmationsInTwoEpochsData: TransactionProofData = { }, accumulatedTxConfirmations: 3838, latestBlockHeight: 777979, - headersChain: + headersChain: Hex.from( "0040f224871a401b605e02c475e05e147bd418e5e2ae9eb599e200000000000000000" + - "000193dc07aea4388a163ed0e3e5234ef54594cfc046bce727d2d6b3445d3ce0e8c44" + - "0dd663e27c07170c0d54de00e0682c9c27df3b2a1b011753c986c290ce22c60d09a05" + - "3707100000000000000000000ddf3b023ed6368bdac8578bd55d0c3fad7f234ae971b" + - "902b155bee7318bf0919b30dd663e27c0717be025f2b00000020514a9bd87c51caedd" + - "45a20c495f0ba1983b6f3f51639050000000000000000001f4c60a97f4127b4f90fbb" + - "7a6a1041881b10d4f7351340b6770301f62b36725ce10dd66320270717c11c5e7b002" + - "0002043e99cc906d52209796ecb37b252e4514f197d727ea701000000000000000000" + - "274ecaf37779be81c23748d33ef4a0cad36a8abd935a11f0e0a71640c6dd1deaf10dd" + - "66320270717846927aa0000c02090a4a88ab1ad55e235932fe0adc7b4c822b4322f58" + - "9305000000000000000000decc945dc9cdf595715ffeee3bffc0ec0c8c5ff77e43b8e" + - "91213e21a9975c99ddc10d663202707179f93251000203229e618c1eb9274a1acbb74" + - "d44bfe9a4ecfae236ea35e8b0300000000000000000029a9f7b4f6671dec5d6ba05ac" + - "b060fcd2ffc6e46a992189c6f60d770d9c5a5cda31cd66320270717542691a2", + "000193dc07aea4388a163ed0e3e5234ef54594cfc046bce727d2d6b3445d3ce0e8c44" + + "0dd663e27c07170c0d54de00e0682c9c27df3b2a1b011753c986c290ce22c60d09a05" + + "3707100000000000000000000ddf3b023ed6368bdac8578bd55d0c3fad7f234ae971b" + + "902b155bee7318bf0919b30dd663e27c0717be025f2b00000020514a9bd87c51caedd" + + "45a20c495f0ba1983b6f3f51639050000000000000000001f4c60a97f4127b4f90fbb" + + "7a6a1041881b10d4f7351340b6770301f62b36725ce10dd66320270717c11c5e7b002" + + "0002043e99cc906d52209796ecb37b252e4514f197d727ea701000000000000000000" + + "274ecaf37779be81c23748d33ef4a0cad36a8abd935a11f0e0a71640c6dd1deaf10dd" + + "66320270717846927aa0000c02090a4a88ab1ad55e235932fe0adc7b4c822b4322f58" + + "9305000000000000000000decc945dc9cdf595715ffeee3bffc0ec0c8c5ff77e43b8e" + + "91213e21a9975c99ddc10d663202707179f93251000203229e618c1eb9274a1acbb74" + + "d44bfe9a4ecfae236ea35e8b0300000000000000000029a9f7b4f6671dec5d6ba05ac" + + "b060fcd2ffc6e46a992189c6f60d770d9c5a5cda31cd66320270717542691a2" + ), transactionMerkleBranch: { blockHeight: 774142, merkle: [ - "e80f706f53d5abd77070ea6c8a60c141748400e09fc9b373d5cdb0129cbce5ec", - "20d22506199cf00caf2e32e240c77a23c226d5a74de4dc9150ccd6f5200b4dd7", - "8b446693fadaae7479725f0e98430c24f8bf8936f5a5cab7c725692cd78e61e3", - "93e61f1ac82cf6a66e321c60410ae4bdfcc0ab45b7efd50353d7b08104758403", - "1dc52561092701978f1e48a10bc4da5464e668f0f4b3a940853c941474ee52de", - "84aca5ec5b339b69a50b93d35c2fd7b146c037842ca76b33cbf835b9e6c86f0c", - "ebcd1bb7039d40ac0d477af58964b4582c6741d1c901ab4a2b0de15e600cba69", - "38d458a70805902a52342cfc552d374bdb217cd389e9550adfc4f86df6fdce82", - "07781ff50552aefea962f0f4972fe882cb38a281ebdd533c2886d5137b80fbeb", - "e7e530e181683d272293f19fe18a33f1dc05eded12ec27945b49311b2e14ee42", + Hex.from( + "e80f706f53d5abd77070ea6c8a60c141748400e09fc9b373d5cdb0129cbce5ec" + ), + Hex.from( + "20d22506199cf00caf2e32e240c77a23c226d5a74de4dc9150ccd6f5200b4dd7" + ), + Hex.from( + "8b446693fadaae7479725f0e98430c24f8bf8936f5a5cab7c725692cd78e61e3" + ), + Hex.from( + "93e61f1ac82cf6a66e321c60410ae4bdfcc0ab45b7efd50353d7b08104758403" + ), + Hex.from( + "1dc52561092701978f1e48a10bc4da5464e668f0f4b3a940853c941474ee52de" + ), + Hex.from( + "84aca5ec5b339b69a50b93d35c2fd7b146c037842ca76b33cbf835b9e6c86f0c" + ), + Hex.from( + "ebcd1bb7039d40ac0d477af58964b4582c6741d1c901ab4a2b0de15e600cba69" + ), + Hex.from( + "38d458a70805902a52342cfc552d374bdb217cd389e9550adfc4f86df6fdce82" + ), + Hex.from( + "07781ff50552aefea962f0f4972fe882cb38a281ebdd533c2886d5137b80fbeb" + ), + Hex.from( + "e7e530e181683d272293f19fe18a33f1dc05eded12ec27945b49311b2e14ee42" + ), ], position: 262, }, @@ -566,31 +640,46 @@ export const testnetTransactionData: TransactionProofData = { }, accumulatedTxConfirmations: 18, latestBlockHeight: 2421198, - headersChain: + headersChain: Hex.from( "000000203528cf6e8112d970a1adeb9743937d2e980afb43cb8ce3600100000000000" + - "0007bacd9aa2249c74fdba75dd651a16755e9b4dc3c1953f2baa01d657f317e3eb936" + - "62f763ffff001d7045e837000040207184a40ae97e64b2bce8fed41f967eac210e036" + - "9a66855bd2b37c86200000000fe261c184d19c15c7b66c284d5f65e79595f65d576cc" + - "40f20cccf0fcbae3c063a866f7639cde2c193ed763b904e000209885f5bb4bc96f8ff" + - "ed3bf31c6f526f1f71fc6dd3f9bb0ed0200000000000000720c67b13ee8805763110f" + - "b345cbfb5369836344e6a990e4ac0c363211362b2c6168f7639cde2c19294a1006000" + - "040200aafa9b9e947a9bd6fe2e9f04dece7753863d59b11e5c63b1500000000000000" + - "7a63f980ffc1f993c0d7dbe0670e71be2eeae8710a7906f758d3b400dd6a1e6b3c69f" + - "7639cde2c1940a3735000008020ba335b0d58de55cf227fdd35ba380a4a288d4f7926" + - "8be6a01800000000000000ffdc211cb41a97249e18a54aa4861a77f43093d6716995a" + - "9f659370ee1cf8aea406af7639cde2c19254197450000002069b318d3a7c7c154651f" + - "23ac4c3a51c7ec5158f40a62783c0400000000000000f452ef784d467c9f541331552" + - "32d005bdd0f2d323933646976ef2b7275206d7ff96ef763ffff001db18d224b", + "0007bacd9aa2249c74fdba75dd651a16755e9b4dc3c1953f2baa01d657f317e3eb936" + + "62f763ffff001d7045e837000040207184a40ae97e64b2bce8fed41f967eac210e036" + + "9a66855bd2b37c86200000000fe261c184d19c15c7b66c284d5f65e79595f65d576cc" + + "40f20cccf0fcbae3c063a866f7639cde2c193ed763b904e000209885f5bb4bc96f8ff" + + "ed3bf31c6f526f1f71fc6dd3f9bb0ed0200000000000000720c67b13ee8805763110f" + + "b345cbfb5369836344e6a990e4ac0c363211362b2c6168f7639cde2c19294a1006000" + + "040200aafa9b9e947a9bd6fe2e9f04dece7753863d59b11e5c63b1500000000000000" + + "7a63f980ffc1f993c0d7dbe0670e71be2eeae8710a7906f758d3b400dd6a1e6b3c69f" + + "7639cde2c1940a3735000008020ba335b0d58de55cf227fdd35ba380a4a288d4f7926" + + "8be6a01800000000000000ffdc211cb41a97249e18a54aa4861a77f43093d6716995a" + + "9f659370ee1cf8aea406af7639cde2c19254197450000002069b318d3a7c7c154651f" + + "23ac4c3a51c7ec5158f40a62783c0400000000000000f452ef784d467c9f541331552" + + "32d005bdd0f2d323933646976ef2b7275206d7ff96ef763ffff001db18d224b" + ), transactionMerkleBranch: { blockHeight: 2421181, merkle: [ - "33610df4f460e1338d9f6a055de18d5c694edf590722211b6feeec77a9479846", - "0fd7e0afdde99bdfbfdc0d0e6f5ccda4cd1873eee315bb989622fd58bd5c4446", - "2d4ab6c53cedc1a447e21ad2f38c6d9d0d9c761426975a65f83fe10f12e3c9e0", - "0eebd6daa03f6db4a27541a91bcf86612c97d100bc37c3eb321d64d943adb2a5", - "b25854f31fc046eb0f53cddbf2b6de3d54d52710acd79a796c78c3be235f031a", - "1fc5ab77039f59ac2494791fc05c75fb53e2dacf57a20f67e7d6727b38778825", - "5b0acfdbb89af64a583a88e92252b8634bd4da06ee102ecd34c2662955e9f1c7", + Hex.from( + "33610df4f460e1338d9f6a055de18d5c694edf590722211b6feeec77a9479846" + ), + Hex.from( + "0fd7e0afdde99bdfbfdc0d0e6f5ccda4cd1873eee315bb989622fd58bd5c4446" + ), + Hex.from( + "2d4ab6c53cedc1a447e21ad2f38c6d9d0d9c761426975a65f83fe10f12e3c9e0" + ), + Hex.from( + "0eebd6daa03f6db4a27541a91bcf86612c97d100bc37c3eb321d64d943adb2a5" + ), + Hex.from( + "b25854f31fc046eb0f53cddbf2b6de3d54d52710acd79a796c78c3be235f031a" + ), + Hex.from( + "1fc5ab77039f59ac2494791fc05c75fb53e2dacf57a20f67e7d6727b38778825" + ), + Hex.from( + "5b0acfdbb89af64a583a88e92252b8634bd4da06ee102ecd34c2662955e9f1c7" + ), ], position: 4, }, diff --git a/typescript/test/data/redemption.ts b/typescript/test/data/redemption.ts index f840e2b6a..deeea11a3 100644 --- a/typescript/test/data/redemption.ts +++ b/typescript/test/data/redemption.ts @@ -25,8 +25,9 @@ export const walletPrivateKey = * Public key of the wallet in the compressed form corresponding to * walletPrivateKey. */ -export const walletPublicKey = +export const walletPublicKey = Hex.from( "03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9" +) /** * P2PKH address corresponding to walletPrivateKey. @@ -84,8 +85,9 @@ export const singleP2PKHRedemptionWithWitnessChange: RedemptionTestData = { "82883a4c7a8dd73ef165deb402d432613615ced4" ), // script for testnet P2PKH address mmTeMR8RKu6QzMGTG4ipA71uewm3EuJng5 - redeemerOutputScript: - "76a9144130879211c54df460e484ddf9aac009cb38ee7488ac", + redeemerOutputScript: Hex.from( + "76a9144130879211c54df460e484ddf9aac009cb38ee7488ac" + ), requestedAmount: BigNumber.from(10000), treasuryFee: BigNumber.from(1000), txMaxFee: BigNumber.from(1600), @@ -141,7 +143,9 @@ export const singleP2WPKHRedemptionWithWitnessChange: RedemptionTestData = { "82883a4c7a8dd73ef165deb402d432613615ced4" ), // script for testnet P2WPKH address tb1qgycg0ys3c4xlgc8ysnwln2kqp89n3mn5ts7z3l - redeemerOutputScript: "00144130879211c54df460e484ddf9aac009cb38ee74", + redeemerOutputScript: Hex.from( + "00144130879211c54df460e484ddf9aac009cb38ee74" + ), requestedAmount: BigNumber.from(15000), treasuryFee: BigNumber.from(1100), txMaxFee: BigNumber.from(1700), @@ -197,7 +201,9 @@ export const singleP2SHRedemptionWithWitnessChange: RedemptionTestData = { "82883a4c7a8dd73ef165deb402d432613615ced4" ), // script for testnet P2SH address 2Mxy76sc1qAxiJ1fXMXDXqHvVcPLh6Lf12C - redeemerOutputScript: "a9143ec459d0f3c29286ae5df5fcc421e2786024277e87", + redeemerOutputScript: Hex.from( + "a9143ec459d0f3c29286ae5df5fcc421e2786024277e87" + ), requestedAmount: BigNumber.from(13000), treasuryFee: BigNumber.from(800), txMaxFee: BigNumber.from(1700), @@ -253,8 +259,9 @@ export const singleP2WSHRedemptionWithWitnessChange: RedemptionTestData = { "82883a4c7a8dd73ef165deb402d432613615ced4" ), // script for testnet P2WSH address tb1qs63s8nwjut4tr5t8nudgzwp4m3dpkefjzpmumn90pruce0cye2tq2jkq0y - redeemerOutputScript: - "002086a303cdd2e2eab1d1679f1a813835dc5a1b65321077cdccaf08f98cbf04ca96", + redeemerOutputScript: Hex.from( + "002086a303cdd2e2eab1d1679f1a813835dc5a1b65321077cdccaf08f98cbf04ca96" + ), requestedAmount: BigNumber.from(18000), treasuryFee: BigNumber.from(1000), txMaxFee: BigNumber.from(1400), @@ -310,8 +317,9 @@ export const multipleRedemptionsWithWitnessChange: RedemptionTestData = { "82883a4c7a8dd73ef165deb402d432613615ced4" ), // script for testnet P2PKH address mmTeMR8RKu6QzMGTG4ipA71uewm3EuJng5 - redeemerOutputScript: - "76a9144130879211c54df460e484ddf9aac009cb38ee7488ac", + redeemerOutputScript: Hex.from( + "76a9144130879211c54df460e484ddf9aac009cb38ee7488ac" + ), requestedAmount: BigNumber.from(18000), treasuryFee: BigNumber.from(1000), txMaxFee: BigNumber.from(1100), @@ -326,7 +334,9 @@ export const multipleRedemptionsWithWitnessChange: RedemptionTestData = { "82883a4c7a8dd73ef165deb402d432613615ced4" ), // script for testnet P2WPKH address tb1qgycg0ys3c4xlgc8ysnwln2kqp89n3mn5ts7z3l - redeemerOutputScript: "00144130879211c54df460e484ddf9aac009cb38ee74", + redeemerOutputScript: Hex.from( + "00144130879211c54df460e484ddf9aac009cb38ee74" + ), requestedAmount: BigNumber.from(13000), treasuryFee: BigNumber.from(800), txMaxFee: BigNumber.from(900), @@ -341,7 +351,9 @@ export const multipleRedemptionsWithWitnessChange: RedemptionTestData = { "82883a4c7a8dd73ef165deb402d432613615ced4" ), // script for testnet P2SH address 2Mxy76sc1qAxiJ1fXMXDXqHvVcPLh6Lf12C - redeemerOutputScript: "a9143ec459d0f3c29286ae5df5fcc421e2786024277e87", + redeemerOutputScript: Hex.from( + "a9143ec459d0f3c29286ae5df5fcc421e2786024277e87" + ), requestedAmount: BigNumber.from(12000), treasuryFee: BigNumber.from(1100), txMaxFee: BigNumber.from(1000), @@ -356,8 +368,9 @@ export const multipleRedemptionsWithWitnessChange: RedemptionTestData = { "82883a4c7a8dd73ef165deb402d432613615ced4" ), // script for testnet P2WSH address tb1qs63s8nwjut4tr5t8nudgzwp4m3dpkefjzpmumn90pruce0cye2tq2jkq0y - redeemerOutputScript: - "002086a303cdd2e2eab1d1679f1a813835dc5a1b65321077cdccaf08f98cbf04ca96", + redeemerOutputScript: Hex.from( + "002086a303cdd2e2eab1d1679f1a813835dc5a1b65321077cdccaf08f98cbf04ca96" + ), requestedAmount: BigNumber.from(15000), treasuryFee: BigNumber.from(700), txMaxFee: BigNumber.from(1400), @@ -416,8 +429,9 @@ export const multipleRedemptionsWithoutChange: RedemptionTestData = { "82883a4c7a8dd73ef165deb402d432613615ced4" ), // script for testnet P2PKH address mmTeMR8RKu6QzMGTG4ipA71uewm3EuJng5 - redeemerOutputScript: - "76a9144130879211c54df460e484ddf9aac009cb38ee7488ac", + redeemerOutputScript: Hex.from( + "76a9144130879211c54df460e484ddf9aac009cb38ee7488ac" + ), requestedAmount: BigNumber.from(6000), treasuryFee: BigNumber.from(0), txMaxFee: BigNumber.from(800), @@ -432,7 +446,9 @@ export const multipleRedemptionsWithoutChange: RedemptionTestData = { "82883a4c7a8dd73ef165deb402d432613615ced4" ), // script for testnet P2WPKH address tb1qf0ulldawp79s7knz9v254j5zjyn0demfx2d0xx - redeemerOutputScript: "00144bf9ffb7ae0f8b0f5a622b154aca829126f6e769", + redeemerOutputScript: Hex.from( + "00144bf9ffb7ae0f8b0f5a622b154aca829126f6e769" + ), requestedAmount: BigNumber.from(4000), treasuryFee: BigNumber.from(0), txMaxFee: BigNumber.from(900), @@ -491,7 +507,9 @@ export const singleP2SHRedemptionWithNonWitnessChange: RedemptionTestData = { "82883a4c7a8dd73ef165deb402d432613615ced4" ), // script for testnet P2SH address 2Mxy76sc1qAxiJ1fXMXDXqHvVcPLh6Lf12C - redeemerOutputScript: "a9143ec459d0f3c29286ae5df5fcc421e2786024277e87", + redeemerOutputScript: Hex.from( + "a9143ec459d0f3c29286ae5df5fcc421e2786024277e87" + ), requestedAmount: BigNumber.from(12000), treasuryFee: BigNumber.from(1000), txMaxFee: BigNumber.from(1200), @@ -526,14 +544,14 @@ export interface RedemptionProofTestData { rawTransaction: BitcoinRawTx accumulatedTxConfirmations: number latestBlockHeight: number - headersChain: string + headersChain: Hex transactionMerkleBranch: BitcoinTxMerkleBranch } expectedRedemptionProof: { redemptionTx: BitcoinRawTxVectors redemptionProof: BitcoinSpvProof mainUtxo: BitcoinUtxo - walletPublicKey: string + walletPublicKey: Hex } } @@ -609,76 +627,91 @@ export const redemptionProof: RedemptionProofTestData = { "b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d900000000", }, latestBlockHeight: 2226015, - headersChain: + headersChain: Hex.from( "04e000203d93e4b82b59ccaae5aff315b9319248c1119f8f848e421516000000000000" + - "00f28145109cd15498a2c4264dcda1c3d40d1ab1117f6365cc345e5bab9eb8e5a2f990" + - "5e62341f5c19adebd9480000c020a33f8505bae0c529af29b00741e2828e4b4ef2cf4d" + - "a2af790d00000000000000f1dad96fa7c65ae0b2582268ebf6e47b1af887ae9b5af064" + - "ff87b361259f9bb212915e62341f5c19913d8a790000002074ac47fe867411f520786b" + - "bb056d33cc5e412799355f22541600000000000000e428a225d38073c8e8584cf162b4" + - "cdc17eaf766f2fc1beae23f0ebac8b29964ec4955e62ffff001d5ec11e770000a020bc" + - "1e329ea2658a4e0dfe27cb80e2f9712d78e02c5428eb86db93c7e3000000006381e8dd" + - "f3245ddd74afb580b6d1e508273673d14b3620c098bde4c50bdbf65de1975e62341f5c" + - "195a29773400006020e7fc1afb505baced47a255d8a14cb7162b6f94d6aea6a89f4300" + - "000000000000ad26d482c0f48d0aeb1e1d9a8189df9f8dae693203c117a777c6c15522" + - "2da759ef975e62341f5c19595dff820000802004bdf8678a1fd09fd50987f884793410" + - "62e7f2ad11098bd00800000000000000add66b467729d264031adec83bc06e30781153" + - "0b98f49b095bd4c1fee2472e841d995e62341f5c19945d657200004020f8228183708c" + - "5f703e673f381ecee895a8642eed9f700b9c2b00000000000000465ec2f30447552a4a" + - "30ee63964aaebcb040649269eab449fb51823d58835a4aed9a5e62341f5c192fd94baa", + "00f28145109cd15498a2c4264dcda1c3d40d1ab1117f6365cc345e5bab9eb8e5a2f990" + + "5e62341f5c19adebd9480000c020a33f8505bae0c529af29b00741e2828e4b4ef2cf4d" + + "a2af790d00000000000000f1dad96fa7c65ae0b2582268ebf6e47b1af887ae9b5af064" + + "ff87b361259f9bb212915e62341f5c19913d8a790000002074ac47fe867411f520786b" + + "bb056d33cc5e412799355f22541600000000000000e428a225d38073c8e8584cf162b4" + + "cdc17eaf766f2fc1beae23f0ebac8b29964ec4955e62ffff001d5ec11e770000a020bc" + + "1e329ea2658a4e0dfe27cb80e2f9712d78e02c5428eb86db93c7e3000000006381e8dd" + + "f3245ddd74afb580b6d1e508273673d14b3620c098bde4c50bdbf65de1975e62341f5c" + + "195a29773400006020e7fc1afb505baced47a255d8a14cb7162b6f94d6aea6a89f4300" + + "000000000000ad26d482c0f48d0aeb1e1d9a8189df9f8dae693203c117a777c6c15522" + + "2da759ef975e62341f5c19595dff820000802004bdf8678a1fd09fd50987f884793410" + + "62e7f2ad11098bd00800000000000000add66b467729d264031adec83bc06e30781153" + + "0b98f49b095bd4c1fee2472e841d995e62341f5c19945d657200004020f8228183708c" + + "5f703e673f381ecee895a8642eed9f700b9c2b00000000000000465ec2f30447552a4a" + + "30ee63964aaebcb040649269eab449fb51823d58835a4aed9a5e62341f5c192fd94baa" + ), transactionMerkleBranch: { blockHeight: 2196313, merkle: [ - "2e89760feb82c022f9b6757c0a758f8fea953ffce9051cbe5a7cc20e0603c940", - "ad1cae6d060b5dac5d7ff1a933680f15dac822f52316c89e95363856b8a742ae", - "acf6ecc3da4654362678ac2bf0abf82aba1f2071e143718df2b079124e88fec7", - "65ea59172f35ee6db6e4194227bea23daedbda8299bea94710f21c97f3e9cc17", - "8c5b4ce089d0c450bf6125e7d342114246802bf4c9638d222aa9fcbe8e06024e", + Hex.from( + "2e89760feb82c022f9b6757c0a758f8fea953ffce9051cbe5a7cc20e0603c940" + ), + Hex.from( + "ad1cae6d060b5dac5d7ff1a933680f15dac822f52316c89e95363856b8a742ae" + ), + Hex.from( + "acf6ecc3da4654362678ac2bf0abf82aba1f2071e143718df2b079124e88fec7" + ), + Hex.from( + "65ea59172f35ee6db6e4194227bea23daedbda8299bea94710f21c97f3e9cc17" + ), + Hex.from( + "8c5b4ce089d0c450bf6125e7d342114246802bf4c9638d222aa9fcbe8e06024e" + ), ], position: 4, }, }, expectedRedemptionProof: { redemptionTx: { - version: "01000000", - inputs: + version: Hex.from("01000000"), + inputs: Hex.from( "01e30b907d077893bd0ed819c66644027b1dd30e4d3f68bc51da7933f75bbb283d0" + - "100000000ffffffff", - outputs: + "100000000ffffffff" + ), + outputs: Hex.from( "051c3e0000000000001976a9144130879211c54df460e484ddf9aac009cb38ee748" + - "8ac242c0000000000001600144130879211c54df460e484ddf9aac009cb38ee74ac" + - "2600000000000017a9143ec459d0f3c29286ae5df5fcc421e2786024277e8764320" + - "0000000000022002086a303cdd2e2eab1d1679f1a813835dc5a1b65321077cdccaf" + - "08f98cbf04ca96ccfb1400000000001600148db50eb52063ea9d98b3eac91489a90" + - "f738986f6", - locktime: "00000000", + "8ac242c0000000000001600144130879211c54df460e484ddf9aac009cb38ee74ac" + + "2600000000000017a9143ec459d0f3c29286ae5df5fcc421e2786024277e8764320" + + "0000000000022002086a303cdd2e2eab1d1679f1a813835dc5a1b65321077cdccaf" + + "08f98cbf04ca96ccfb1400000000001600148db50eb52063ea9d98b3eac91489a90" + + "f738986f6" + ), + locktime: Hex.from("00000000"), }, redemptionProof: { - merkleProof: + merkleProof: Hex.from( "40c903060ec27c5abe1c05e9fc3f95ea8f8f750a7c75b6f922c082eb0f76892eae4" + - "2a7b8563836959ec81623f522c8da150f6833a9f17f5dac5d0b066dae1cadc7fe88" + - "4e1279b0f28d7143e171201fba2af8abf02bac7826365446dac3ecf6ac17cce9f39" + - "71cf21047a9be9982dadbae3da2be274219e4b66dee352f1759ea654e02068ebefc" + - "a92a228d63c9f42b8046421142d3e72561bf50c4d089e04c5b8c", + "2a7b8563836959ec81623f522c8da150f6833a9f17f5dac5d0b066dae1cadc7fe88" + + "4e1279b0f28d7143e171201fba2af8abf02bac7826365446dac3ecf6ac17cce9f39" + + "71cf21047a9be9982dadbae3da2be274219e4b66dee352f1759ea654e02068ebefc" + + "a92a228d63c9f42b8046421142d3e72561bf50c4d089e04c5b8c" + ), txIndexInBlock: 4, - bitcoinHeaders: + bitcoinHeaders: Hex.from( "04e000203d93e4b82b59ccaae5aff315b9319248c1119f8f848e421516000000000" + - "00000f28145109cd15498a2c4264dcda1c3d40d1ab1117f6365cc345e5bab9eb8e5" + - "a2f9905e62341f5c19adebd9480000c020a33f8505bae0c529af29b00741e2828e4" + - "b4ef2cf4da2af790d00000000000000f1dad96fa7c65ae0b2582268ebf6e47b1af8" + - "87ae9b5af064ff87b361259f9bb212915e62341f5c19913d8a790000002074ac47f" + - "e867411f520786bbb056d33cc5e412799355f22541600000000000000e428a225d3" + - "8073c8e8584cf162b4cdc17eaf766f2fc1beae23f0ebac8b29964ec4955e62ffff0" + - "01d5ec11e770000a020bc1e329ea2658a4e0dfe27cb80e2f9712d78e02c5428eb86" + - "db93c7e3000000006381e8ddf3245ddd74afb580b6d1e508273673d14b3620c098b" + - "de4c50bdbf65de1975e62341f5c195a29773400006020e7fc1afb505baced47a255" + - "d8a14cb7162b6f94d6aea6a89f4300000000000000ad26d482c0f48d0aeb1e1d9a8" + - "189df9f8dae693203c117a777c6c155222da759ef975e62341f5c19595dff820000" + - "802004bdf8678a1fd09fd50987f88479341062e7f2ad11098bd0080000000000000" + - "0add66b467729d264031adec83bc06e307811530b98f49b095bd4c1fee2472e841d" + - "995e62341f5c19945d657200004020f8228183708c5f703e673f381ecee895a8642" + - "eed9f700b9c2b00000000000000465ec2f30447552a4a30ee63964aaebcb0406492" + - "69eab449fb51823d58835a4aed9a5e62341f5c192fd94baa", + "00000f28145109cd15498a2c4264dcda1c3d40d1ab1117f6365cc345e5bab9eb8e5" + + "a2f9905e62341f5c19adebd9480000c020a33f8505bae0c529af29b00741e2828e4" + + "b4ef2cf4da2af790d00000000000000f1dad96fa7c65ae0b2582268ebf6e47b1af8" + + "87ae9b5af064ff87b361259f9bb212915e62341f5c19913d8a790000002074ac47f" + + "e867411f520786bbb056d33cc5e412799355f22541600000000000000e428a225d3" + + "8073c8e8584cf162b4cdc17eaf766f2fc1beae23f0ebac8b29964ec4955e62ffff0" + + "01d5ec11e770000a020bc1e329ea2658a4e0dfe27cb80e2f9712d78e02c5428eb86" + + "db93c7e3000000006381e8ddf3245ddd74afb580b6d1e508273673d14b3620c098b" + + "de4c50bdbf65de1975e62341f5c195a29773400006020e7fc1afb505baced47a255" + + "d8a14cb7162b6f94d6aea6a89f4300000000000000ad26d482c0f48d0aeb1e1d9a8" + + "189df9f8dae693203c117a777c6c155222da759ef975e62341f5c19595dff820000" + + "802004bdf8678a1fd09fd50987f88479341062e7f2ad11098bd0080000000000000" + + "0add66b467729d264031adec83bc06e307811530b98f49b095bd4c1fee2472e841d" + + "995e62341f5c19945d657200004020f8228183708c5f703e673f381ecee895a8642" + + "eed9f700b9c2b00000000000000465ec2f30447552a4a30ee63964aaebcb0406492" + + "69eab449fb51823d58835a4aed9a5e62341f5c192fd94baa" + ), }, mainUtxo: { transactionHash: BitcoinTxHash.from( @@ -687,8 +720,9 @@ export const redemptionProof: RedemptionProofTestData = { outputIndex: 1, value: BigNumber.from(1429580), }, - walletPublicKey: - "03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9", + walletPublicKey: Hex.from( + "03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9" + ), }, } @@ -902,7 +936,9 @@ export const findWalletForRedemptionData: { "0xeb9af8E66869902476347a4eFe59a527a57240ED" ), // script for testnet P2PKH address mjc2zGWypwpNyDi4ZxGbBNnUA84bfgiwYc - redeemerOutputScript: "76a9142cd680318747b720d67bf4246eb7403b476adb3488ac", + redeemerOutputScript: Hex.from( + "76a9142cd680318747b720d67bf4246eb7403b476adb3488ac" + ), requestedAmount: BigNumber.from(1000000), treasuryFee: BigNumber.from(20000), txMaxFee: BigNumber.from(20000), diff --git a/typescript/test/lib/bitcoin.test.ts b/typescript/test/lib/bitcoin.test.ts index 80e1212c3..11dacfaac 100644 --- a/typescript/test/lib/bitcoin.test.ts +++ b/typescript/test/lib/bitcoin.test.ts @@ -106,9 +106,10 @@ describe("Bitcoin", () => { context("when public key parameter has a correct length", () => { context("when the Y coordinate is divisible by 2", () => { it("should compress the public key correctly", () => { - const uncompressedPublicKey = + const uncompressedPublicKey = Hex.from( "ff6e1857db52d6dba2bd4239fba722655622bc520709d38011f9adac8ea3477b" + - "45ae275b657f7bac7c1e3d146a564051aee1356895f01e4f29f333502416fa4a" + "45ae275b657f7bac7c1e3d146a564051aee1356895f01e4f29f333502416fa4a" + ) const compressedPublicKey = "02ff6e1857db52d6dba2bd4239fba722655622bc520709d38011f9adac8ea3477b" @@ -120,9 +121,10 @@ describe("Bitcoin", () => { context("when the Y coordinate is not divisible by 2", () => { it("should compress the public key correctly", () => { - const uncompressedPublicKey = + const uncompressedPublicKey = Hex.from( "474444cca71c678f5019d16782b6522735717a94602085b4adf707b465c36ca8" + - "7b5dff055ee1cc3a1fff4715dea2858ca4dd5bba0af30abcd881a6bda4fb70af" + "7b5dff055ee1cc3a1fff4715dea2858ca4dd5bba0af30abcd881a6bda4fb70af" + ) const compressedPublicKey = "03474444cca71c678f5019d16782b6522735717a94602085b4adf707b465c36ca8" @@ -135,10 +137,10 @@ describe("Bitcoin", () => { context("when public key parameter has an incorrect length", () => { it("should throw", () => { - const uncompressedPublicKey = + const uncompressedPublicKey = Hex.from( "04474444cca71c678f5019d16782b6522735717a94602085b4adf707b465c36ca8" + - "7b5dff055ee1cc3a1fff4715dea2858ca4dd5bba0af30abcd881a6bda4fb70af" - + "7b5dff055ee1cc3a1fff4715dea2858ca4dd5bba0af30abcd881a6bda4fb70af" + ) expect(() => compressPublicKey(uncompressedPublicKey)).to.throw( "The public key parameter must be 64-byte. Neither 0x nor 04 prefix is allowed" ) @@ -153,11 +155,14 @@ describe("Bitcoin", () => { describe("computeHash160", () => { it("should compute hash160 correctly", () => { - const compressedPublicKey = + const compressedPublicKey = Hex.from( "03474444cca71c678f5019d16782b6522735717a94602085b4adf707b465c36ca8" + ) const expectedHash160 = "3e1dfbd72483fb3964ca828ee71cf3270cafdc65" - expect(computeHash160(compressedPublicKey)).to.be.equal(expectedHash160) + expect(computeHash160(compressedPublicKey).toString()).to.be.equal( + expectedHash160 + ) }) }) @@ -205,7 +210,7 @@ describe("Bitcoin", () => { }) describe("BitcoinAddressConverter", () => { - const publicKeyHash = "3a38d44d6a0c8d0bb84e0232cc632b7e48c72e0e" + const publicKeyHash = Hex.from("3a38d44d6a0c8d0bb84e0232cc632b7e48c72e0e") const P2WPKHAddress = "bc1q8gudgnt2pjxshwzwqgevccet0eyvwtswt03nuy" const P2PKHAddress = "16JrGhLx5bcBSA34kew9V6Mufa4aXhFe9X" const P2WPKHAddressTestnet = "tb1q8gudgnt2pjxshwzwqgevccet0eyvwtswpf2q8h" @@ -260,7 +265,9 @@ describe("Bitcoin", () => { context("when wrong public key hash is provided", () => { it("should throw", () => { - const wrongPublicKeyHash = "02" + publicKeyHash + const wrongPublicKeyHash = Hex.from( + "02" + publicKeyHash.toString() + ) expect(() => publicKeyHashToAddress( @@ -290,7 +297,9 @@ describe("Bitcoin", () => { context("when wrong public key hash is provided", () => { it("should throw", () => { - const wrongPublicKeyHash = "02" + publicKeyHash + const wrongPublicKeyHash = Hex.from( + "02" + publicKeyHash.toString() + ) expect(() => publicKeyHashToAddress( @@ -322,7 +331,9 @@ describe("Bitcoin", () => { context("when wrong public key hash is provided", () => { it("should throw", () => { - const wrongPublicKeyHash = "02" + publicKeyHash + const wrongPublicKeyHash = Hex.from( + "02" + publicKeyHash.toString() + ) expect(() => publicKeyHashToAddress( @@ -352,7 +363,9 @@ describe("Bitcoin", () => { context("when wrong public key hash is provided", () => { it("should throw", () => { - const wrongPublicKeyHash = "02" + publicKeyHash + const wrongPublicKeyHash = Hex.from( + "02" + publicKeyHash.toString() + ) expect(() => publicKeyHashToAddress( @@ -383,7 +396,7 @@ describe("Bitcoin", () => { it("should decode P2WPKH adress correctly", () => { expect( addressToPublicKeyHash(P2WPKHAddress, BitcoinNetwork.Mainnet) - ).to.be.equal(publicKeyHash) + ).to.be.deep.equal(publicKeyHash) }) }) @@ -391,7 +404,7 @@ describe("Bitcoin", () => { it("should decode P2PKH address correctly", () => { expect( addressToPublicKeyHash(P2PKHAddress, BitcoinNetwork.Mainnet) - ).to.be.equal(publicKeyHash) + ).to.be.deep.equal(publicKeyHash) }) }) @@ -455,7 +468,7 @@ describe("Bitcoin", () => { P2WPKHAddressTestnet, BitcoinNetwork.Testnet ) - ).to.be.equal(publicKeyHash) + ).to.be.deep.equal(publicKeyHash) }) }) @@ -466,7 +479,7 @@ describe("Bitcoin", () => { P2PKHAddressTestnet, BitcoinNetwork.Testnet ) - ).to.be.equal(publicKeyHash) + ).to.be.deep.equal(publicKeyHash) }) }) @@ -585,12 +598,12 @@ describe("Bitcoin", () => { const testData = [ { contextName: "when locktime is a block height", - unprefixedHex: "ede80600", + unprefixedHex: Hex.from("ede80600"), expectedLocktime: 452845, }, { contextName: "when locktime is a timestamp", - unprefixedHex: "06241559", + unprefixedHex: Hex.from("06241559"), expectedLocktime: 1494557702, }, { @@ -604,24 +617,24 @@ describe("Bitcoin", () => { context(test.contextName, () => { context("when input is non-prefixed hex string", () => { it("should return the locktime in seconds", async () => { - expect(locktimeToNumber(test.unprefixedHex)).to.be.equal( - test.expectedLocktime - ) + expect( + locktimeToNumber(test.unprefixedHex.toString()) + ).to.be.equal(test.expectedLocktime) }) }) context("when input is 0x prefixed hex string", () => { it("should return the locktime in seconds", async () => { - expect(locktimeToNumber("0x" + test.unprefixedHex)).to.be.equal( - test.expectedLocktime - ) + expect( + locktimeToNumber(test.unprefixedHex.toPrefixedString()) + ).to.be.equal(test.expectedLocktime) }) }) context("when input is Buffer object", () => { it("should return the locktime in seconds", async () => { expect( - locktimeToNumber(Buffer.from(test.unprefixedHex, "hex")) + locktimeToNumber(test.unprefixedHex.toBuffer()) ).to.be.equal(test.expectedLocktime) }) }) @@ -657,7 +670,7 @@ describe("Bitcoin", () => { // The start timestamp is 1652776752 and locktime duration 2592000 (30 days). // So, the locktime timestamp is 1652776752 + 2592000 = 1655368752 which // is represented as 30ecaa62 hex in the little-endian format. - expect(locktime).to.be.equal("30ecaa62") + expect(locktime.toString()).to.be.equal("30ecaa62") }) }) }) @@ -818,33 +831,27 @@ describe("Bitcoin", () => { const testData = [ { testFunction: isP2PKHScript, - validScript: Buffer.from( - "76a9148db50eb52063ea9d98b3eac91489a90f738986f688ac", - "hex" + validScript: Hex.from( + "76a9148db50eb52063ea9d98b3eac91489a90f738986f688ac" ), name: "P2PKH", }, { testFunction: isP2WPKHScript, - validScript: Buffer.from( - "00148db50eb52063ea9d98b3eac91489a90f738986f6", - "hex" - ), + validScript: Hex.from("00148db50eb52063ea9d98b3eac91489a90f738986f6"), name: "P2WPKH", }, { testFunction: isP2SHScript, - validScript: Buffer.from( - "a914a9a5f97d5d3c4687a52e90718168270005b369c487", - "hex" + validScript: Hex.from( + "a914a9a5f97d5d3c4687a52e90718168270005b369c487" ), name: "P2SH", }, { testFunction: isP2WSHScript, - validScript: Buffer.from( - "0020b1f83e226979dc9fe74e87f6d303dbb08a27a1c7ce91664033f34c7f2d214cd7", - "hex" + validScript: Hex.from( + "0020b1f83e226979dc9fe74e87f6d303dbb08a27a1c7ce91664033f34c7f2d214cd7" ), name: "P2WSH", }, @@ -874,8 +881,8 @@ describe("Bitcoin", () => { depositSweepWithNoMainUtxoAndWitnessOutput.expectedSweep.transaction const decomposedTransaction = extractBitcoinRawTxVectors(rawTransaction) - expect(decomposedTransaction.version).to.be.equal("01000000") - expect(decomposedTransaction.inputs).to.be.equal( + expect(decomposedTransaction.version.toString()).to.be.equal("01000000") + expect(decomposedTransaction.inputs.toString()).to.be.equal( "02bc187be612bc3db8cfcdec56b75e9bc0262ab6eacfe27cc1a699bacd53e3d07400" + "000000c948304502210089a89aaf3fec97ac9ffa91cdff59829f0cb3ef852a468153" + "e2c0e2b473466d2e022072902bb923ef016ac52e941ced78f816bf27991c2b73211e" + @@ -886,14 +893,14 @@ describe("Bitcoin", () => { "68ffffffffdc557e737b6688c5712649b86f7757a722dc3d42786f23b2fa826394df" + "ec545c0000000000ffffffff" ) - expect(decomposedTransaction.outputs).to.be.equal( + expect(decomposedTransaction.outputs.toString()).to.be.equal( "01488a0000000000001600148db50eb52063ea9d98b3eac91489a90f738986f6" ) - expect(decomposedTransaction.locktime).to.be.equal("00000000") + expect(decomposedTransaction.locktime.toString()).to.be.equal("00000000") }) }) - describe("assembleTransactionProof", () => { + describe("assembleBitcoinSpvProof", () => { let bitcoinClient: MockBitcoinClient beforeEach(async () => { @@ -914,9 +921,9 @@ describe("Bitcoin", () => { ) expect(proof.inputs).to.deep.equal(expectedProof.inputs) expect(proof.outputs).to.deep.equal(expectedProof.outputs) - expect(proof.merkleProof).to.equal(expectedProof.merkleProof) + expect(proof.merkleProof).to.deep.equal(expectedProof.merkleProof) expect(proof.txIndexInBlock).to.equal(expectedProof.txIndexInBlock) - expect(proof.bitcoinHeaders).to.equal(expectedProof.bitcoinHeaders) + expect(proof.bitcoinHeaders).to.deep.equal(expectedProof.bitcoinHeaders) }) }) @@ -934,9 +941,9 @@ describe("Bitcoin", () => { ) expect(proof.inputs).to.deep.equal(expectedProof.inputs) expect(proof.outputs).to.deep.equal(expectedProof.outputs) - expect(proof.merkleProof).to.equal(expectedProof.merkleProof) + expect(proof.merkleProof).to.deep.equal(expectedProof.merkleProof) expect(proof.txIndexInBlock).to.equal(expectedProof.txIndexInBlock) - expect(proof.bitcoinHeaders).to.equal(expectedProof.bitcoinHeaders) + expect(proof.bitcoinHeaders).to.deep.equal(expectedProof.bitcoinHeaders) }) }) @@ -1037,9 +1044,10 @@ describe("Bitcoin", () => { ...transactionConfirmationsInOneEpochData, bitcoinChainData: { ...transactionConfirmationsInOneEpochData.bitcoinChainData, - headersChain: - transactionConfirmationsInOneEpochData.bitcoinChainData - .headersChain + "ff", + headersChain: Hex.from( + transactionConfirmationsInOneEpochData.bitcoinChainData.headersChain.toString() + + "ff" + ), }, } await expect( @@ -1057,9 +1065,10 @@ describe("Bitcoin", () => { ...transactionConfirmationsInOneEpochData, bitcoinChainData: { ...transactionConfirmationsInOneEpochData.bitcoinChainData, - headersChain: - transactionConfirmationsInOneEpochData.bitcoinChainData - .headersChain + "f".repeat(160), + headersChain: Hex.from( + transactionConfirmationsInOneEpochData.bitcoinChainData.headersChain.toString() + + "f".repeat(160) + ), }, } await expect( @@ -1076,7 +1085,9 @@ describe("Bitcoin", () => { ...transactionConfirmationsInOneEpochData.bitcoinChainData .transactionMerkleBranch.merkle, ] - merkle[merkle.length - 1] += "ff" + merkle[merkle.length - 1] = Hex.from( + merkle[merkle.length - 1].toString() + "ff" + ) const corruptedProofData: TransactionProofData = { ...transactionConfirmationsInOneEpochData, @@ -1126,7 +1137,7 @@ describe("Bitcoin", () => { .transactionMerkleBranch.merkle, ] - merkle[3] = "ff" + merkle[3].slice(2) + merkle[3] = Hex.from("ff" + merkle[3].toString().slice(2)) const corruptedProofData: TransactionProofData = { ...transactionConfirmationsInOneEpochData, @@ -1168,7 +1179,7 @@ describe("Bitcoin", () => { ...transactionConfirmationsInOneEpochData, bitcoinChainData: { ...transactionConfirmationsInOneEpochData.bitcoinChainData, - headersChain: corruptedHeadersChain, + headersChain: Hex.from(corruptedHeadersChain), }, } @@ -1196,7 +1207,7 @@ describe("Bitcoin", () => { ...transactionConfirmationsInOneEpochData, bitcoinChainData: { ...transactionConfirmationsInOneEpochData.bitcoinChainData, - headersChain: corruptedHeadersChain, + headersChain: Hex.from(corruptedHeadersChain), }, } diff --git a/typescript/test/lib/electrum.test.ts b/typescript/test/lib/electrum.test.ts index 76f521fc0..673db9a01 100644 --- a/typescript/test/lib/electrum.test.ts +++ b/typescript/test/lib/electrum.test.ts @@ -3,13 +3,17 @@ import { ElectrumCredentials, ElectrumClient, computeElectrumScriptHash, + Hex, + BitcoinTxHash, } from "../../src" import { testnetAddress, testnetHeadersChain, + testnetPublicKeyHash, testnetRawTransaction, testnetTransaction, testnetTransactionMerkleBranch, + testnetTxHashes, testnetUTXO, } from "../data/electrum" import { expect } from "chai" @@ -179,6 +183,29 @@ describe("Electrum", () => { }) }) + describe("getTxHashesForPublicKeyHash", () => { + let actualHashes: BitcoinTxHash[] + + before(async () => { + actualHashes = await electrumClient.getTxHashesForPublicKeyHash( + testnetPublicKeyHash + ) + }) + + it("should return proper transaction hashes", async () => { + const expectedHashes = testnetTxHashes + // If the actual hashes set is greater than the expected set, we + // need to adjust them to the same length to make a comparison that + // makes sense. + if (actualHashes.length > expectedHashes.length) { + actualHashes = actualHashes.slice( + actualHashes.length - expectedHashes.length + ) + } + expect(actualHashes).to.be.deep.equal(expectedHashes) + }) + }) + describe("latestBlockHeight", () => { let result: number @@ -224,7 +251,9 @@ describe("Electrum", () => { describe("computeElectrumScriptHash", () => { it("should convert Bitcoin script to an Electrum script hash correctly", () => { - const script = "00144b47c798d12edd17dfb4ea98e5447926f664731c" + const script = Hex.from( + "00144b47c798d12edd17dfb4ea98e5447926f664731c" + ) const expectedScriptHash = "cabdea0bfc10fb3521721dde503487dd1f0e41dd6609da228066757563f292ab" diff --git a/typescript/test/lib/ethereum.test.ts b/typescript/test/lib/ethereum.test.ts index 727c273b3..0cda5f971 100644 --- a/typescript/test/lib/ethereum.test.ts +++ b/typescript/test/lib/ethereum.test.ts @@ -4,6 +4,8 @@ import { EthereumAddress, EthereumBridge, EthereumTBTCToken, + ethereumAddressFromSigner, + ethereumNetworkFromSigner, Hex, } from "../../src" import { @@ -11,7 +13,7 @@ import { MockContract, } from "@ethereum-waffle/mock-contract" import chai, { assert, expect } from "chai" -import { BigNumber, Wallet, constants, utils } from "ethers" +import { BigNumber, Wallet, constants, getDefaultProvider, utils } from "ethers" import { abi as BridgeABI } from "@keep-network/tbtc-v2/artifacts/Bridge.json" import { abi as TBTCTokenABI } from "@keep-network/tbtc-v2/artifacts/TBTC.json" import { abi as WalletRegistryABI } from "@keep-network/ecdsa/artifacts/WalletRegistry.json" @@ -74,15 +76,18 @@ describe("Ethereum", () => { it("should return the pending redemption", async () => { expect( await bridgeHandle.pendingRedemptions( - "03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9", - "a9143ec459d0f3c29286ae5df5fcc421e2786024277e87" + Hex.from( + "03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9" + ), + Hex.from("a9143ec459d0f3c29286ae5df5fcc421e2786024277e87") ) ).to.be.eql({ redeemer: EthereumAddress.from( "f39fd6e51aad88f6f4ce6ab8827279cfffb92266" ), - redeemerOutputScript: - "a9143ec459d0f3c29286ae5df5fcc421e2786024277e87", + redeemerOutputScript: Hex.from( + "a9143ec459d0f3c29286ae5df5fcc421e2786024277e87" + ), requestedAmount: BigNumber.from(10000), treasuryFee: BigNumber.from(100), txMaxFee: BigNumber.from(50), @@ -113,15 +118,18 @@ describe("Ethereum", () => { it("should return the timed-out redemption", async () => { expect( await bridgeHandle.timedOutRedemptions( - "03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9", - "a9143ec459d0f3c29286ae5df5fcc421e2786024277e87" + Hex.from( + "03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9" + ), + Hex.from("a9143ec459d0f3c29286ae5df5fcc421e2786024277e87") ) ).to.be.eql({ redeemer: EthereumAddress.from( "f39fd6e51aad88f6f4ce6ab8827279cfffb92266" ), - redeemerOutputScript: - "a9143ec459d0f3c29286ae5df5fcc421e2786024277e87", + redeemerOutputScript: Hex.from( + "a9143ec459d0f3c29286ae5df5fcc421e2786024277e87" + ), requestedAmount: BigNumber.from(10000), treasuryFee: BigNumber.from(100), txMaxFee: BigNumber.from(50), @@ -137,20 +145,24 @@ describe("Ethereum", () => { await bridgeHandle.revealDeposit( // Just short byte strings for clarity. { - version: "00000000", - inputs: "11111111", - outputs: "22222222", - locktime: "33333333", + version: Hex.from("00000000"), + inputs: Hex.from("11111111"), + outputs: Hex.from("22222222"), + locktime: Hex.from("33333333"), }, 2, { depositor: EthereumAddress.from( "934b98637ca318a4d6e7ca6ffd1690b8e77df637" ), - walletPublicKeyHash: "8db50eb52063ea9d98b3eac91489a90f738986f6", - refundPublicKeyHash: "28e081f285138ccbe389c1eb8985716230129f89", - blindingFactor: "f9f0c90d00039523", - refundLocktime: "60bcea61", + walletPublicKeyHash: Hex.from( + "8db50eb52063ea9d98b3eac91489a90f738986f6" + ), + refundPublicKeyHash: Hex.from( + "28e081f285138ccbe389c1eb8985716230129f89" + ), + blindingFactor: Hex.from("f9f0c90d00039523"), + refundLocktime: Hex.from("60bcea61"), }, EthereumAddress.from("82883a4c7a8dd73ef165deb402d432613615ced4") ) @@ -182,15 +194,15 @@ describe("Ethereum", () => { await bridgeHandle.submitDepositSweepProof( { - version: "00000000", - inputs: "11111111", - outputs: "22222222", - locktime: "33333333", + version: Hex.from("00000000"), + inputs: Hex.from("11111111"), + outputs: Hex.from("22222222"), + locktime: Hex.from("33333333"), }, { - merkleProof: "44444444", + merkleProof: Hex.from("44444444"), txIndexInBlock: 5, - bitcoinHeaders: "66666666", + bitcoinHeaders: Hex.from("66666666"), }, { transactionHash: BitcoinTxHash.from( @@ -244,7 +256,9 @@ describe("Ethereum", () => { await bridgeContract.mock.requestRedemption.returns() await bridgeHandle.requestRedemption( - "03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9", + Hex.from( + "03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9" + ), { transactionHash: BitcoinTxHash.from( "f8eaf242a55ea15e602f9f990e33f67f99dfbe25d1802bbde63cc1caabf99668" @@ -252,7 +266,7 @@ describe("Ethereum", () => { outputIndex: 8, value: BigNumber.from(9999), }, - "a9143ec459d0f3c29286ae5df5fcc421e2786024277e87", + Hex.from("a9143ec459d0f3c29286ae5df5fcc421e2786024277e87"), BigNumber.from(10000) ) }) @@ -278,15 +292,15 @@ describe("Ethereum", () => { await bridgeHandle.submitRedemptionProof( { - version: "00000000", - inputs: "11111111", - outputs: "22222222", - locktime: "33333333", + version: Hex.from("00000000"), + inputs: Hex.from("11111111"), + outputs: Hex.from("22222222"), + locktime: Hex.from("33333333"), }, { - merkleProof: "44444444", + merkleProof: Hex.from("44444444"), txIndexInBlock: 5, - bitcoinHeaders: "66666666", + bitcoinHeaders: Hex.from("66666666"), }, { transactionHash: BitcoinTxHash.from( @@ -295,7 +309,9 @@ describe("Ethereum", () => { outputIndex: 8, value: BigNumber.from(9999), }, - "03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9" + Hex.from( + "03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9" + ) ) }) @@ -441,7 +457,9 @@ describe("Ethereum", () => { }) it("should return the active wallet's public key", async () => { - expect(await bridgeHandle.activeWalletPublicKey()).to.be.equal( + expect( + (await bridgeHandle.activeWalletPublicKey())?.toString() + ).to.be.equal( "03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9" ) }) @@ -512,8 +530,9 @@ describe("Ethereum", () => { vault: EthereumAddress.from( "0x24BE35e7C04E2e0a628614Ce0Ed58805e1C894F7" ), - walletPublicKey: - "03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9", + walletPublicKey: Hex.from( + "03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9" + ), mainUtxo: { transactionHash: BitcoinTxHash.from( "f8eaf242a55ea15e602f9f990e33f67f99dfbe25d1802bbde63cc1caabf99668" @@ -524,10 +543,12 @@ describe("Ethereum", () => { redeemer: EthereumAddress.from(signer.address), amount: BigNumber.from(10000), redeemerOutputScript: { - unprefixed: - "0020cdbf909e935c855d3e8d1b61aeb9c5e3c03ae8021b286839b1a72f2e48fdba70", - prefixed: - "0x220020cdbf909e935c855d3e8d1b61aeb9c5e3c03ae8021b286839b1a72f2e48fdba70", + unprefixed: Hex.from( + "0020cdbf909e935c855d3e8d1b61aeb9c5e3c03ae8021b286839b1a72f2e48fdba70" + ), + prefixed: Hex.from( + "220020cdbf909e935c855d3e8d1b61aeb9c5e3c03ae8021b286839b1a72f2e48fdba70" + ), }, } @@ -556,13 +577,11 @@ describe("Ethereum", () => { ["address", "bytes20", "bytes32", "uint32", "uint64", "bytes"], [ redeemer.identifierHex, - Hex.from( - BitcoinHashUtils.computeHash160(walletPublicKey) - ).toPrefixedString(), + BitcoinHashUtils.computeHash160(walletPublicKey).toPrefixedString(), mainUtxo.transactionHash.reverse().toPrefixedString(), mainUtxo.outputIndex, mainUtxo.value, - redeemerOutputScript.prefixed, + redeemerOutputScript.prefixed.toPrefixedString(), ] ) @@ -574,4 +593,40 @@ describe("Ethereum", () => { }) }) }) + + describe("ethereumAddressFromSigner", () => { + context("when the signer is a wallet", () => { + const [mockSigner] = new MockProvider().getWallets() + it("should return the signer's address", async () => { + expect(await ethereumAddressFromSigner(mockSigner)).to.be.eql( + EthereumAddress.from(mockSigner.address) + ) + }) + }) + + context("when the signer is a provider", () => { + const mockProvider = getDefaultProvider() + it("should return undefined", async () => { + expect(await ethereumAddressFromSigner(mockProvider)).to.be.undefined + }) + }) + }) + + describe("ethereumNetworkFromSigner", () => { + context("when the signer is a wallet", () => { + const [mockSigner] = new MockProvider().getWallets() + it("should return the signer's network", async () => { + expect(await ethereumNetworkFromSigner(mockSigner)).to.be.eql("local") + }) + }) + + context("when the signer is a provider", () => { + const mockProvider = getDefaultProvider() + it("should return the signer's network", async () => { + expect(await ethereumNetworkFromSigner(mockProvider)).to.be.eql( + "mainnet" + ) + }) + }) + }) }) diff --git a/typescript/test/services/deposits.test.ts b/typescript/test/services/deposits.test.ts index 821228f8c..43b0e8561 100644 --- a/typescript/test/services/deposits.test.ts +++ b/typescript/test/services/deposits.test.ts @@ -23,6 +23,7 @@ import { } from "../../src" import { MockBitcoinClient } from "../utils/mock-bitcoin-client" import { MockTBTCContracts } from "../utils/mock-tbtc-contracts" +import { Hex } from "../../src/lib/utils" import { txToJSON } from "../utils/helpers" import { depositRefundOfNonWitnessDepositAndWitnessRefunderAddress, @@ -40,10 +41,10 @@ describe("Deposits", () => { const deposit: DepositReceipt = { depositor: EthereumAddress.from("934b98637ca318a4d6e7ca6ffd1690b8e77df637"), // HASH160 of 03989d253b17a6a0f41838b84ff0d20e8898f9d7b1a98f2564da4cc29dcf8581d9. - walletPublicKeyHash: "8db50eb52063ea9d98b3eac91489a90f738986f6", + walletPublicKeyHash: Hex.from("8db50eb52063ea9d98b3eac91489a90f738986f6"), // HASH160 of 0300d6f28a2f6bf9836f57fcda5d284c9a8f849316119779f0d6090830d97763a9. - refundPublicKeyHash: "28e081f285138ccbe389c1eb8985716230129f89", - blindingFactor: "f9f0c90d00039523", + refundPublicKeyHash: Hex.from("28e081f285138ccbe389c1eb8985716230129f89"), + blindingFactor: Hex.from("f9f0c90d00039523"), refundLocktime: BitcoinLocktimeUtils.calculateLocktime( depositCreatedAt, depositRefundLocktimeDuration @@ -139,7 +140,9 @@ describe("Deposits", () => { // The first byte (0x08) before the blinding factor is this byte length. // In this case it's 8 bytes. expect(script.substring(44, 46)).to.be.equal("08") - expect(script.substring(46, 62)).to.be.equal(deposit.blindingFactor) + expect(script.substring(46, 62)).to.be.equal( + deposit.blindingFactor.toString() + ) // OP_DROP opcode is 0x75. expect(script.substring(62, 64)).to.be.equal("75") @@ -154,7 +157,9 @@ describe("Deposits", () => { // The first byte (0x14) before the public key is this byte length. // In this case it's 20 bytes which is a correct length for a HASH160. expect(script.substring(68, 70)).to.be.equal("14") - expect(script.substring(70, 110)).to.be.equal(deposit.walletPublicKeyHash) + expect(script.substring(70, 110)).to.be.equal( + deposit.walletPublicKeyHash.toString() + ) // OP_EQUAL opcode is 0x87. expect(script.substring(110, 112)).to.be.equal("87") @@ -178,7 +183,9 @@ describe("Deposits", () => { // The first byte (0x14) before the public key is this byte length. // In this case it's 20 bytes which is a correct length for a HASH160. expect(script.substring(122, 124)).to.be.equal("14") - expect(script.substring(124, 164)).to.be.equal(deposit.refundPublicKeyHash) + expect(script.substring(124, 164)).to.be.equal( + deposit.refundPublicKeyHash.toString() + ) // OP_EQUALVERIFY opcode is 0x88. expect(script.substring(164, 166)).to.be.equal("88") @@ -530,14 +537,14 @@ describe("Deposits", () => { describe("DepositScript", () => { describe("getPlainText", () => { - let script: string + let script: Hex beforeEach(async () => { script = await DepositScript.fromReceipt(deposit).getPlainText() }) it("should return script with proper structure", async () => { - assertValidDepositScript(script) + assertValidDepositScript(script.toString()) }) }) diff --git a/typescript/test/services/maintenance.test.ts b/typescript/test/services/maintenance.test.ts index cbca52a78..8b0f3d7bd 100644 --- a/typescript/test/services/maintenance.test.ts +++ b/typescript/test/services/maintenance.test.ts @@ -2541,7 +2541,7 @@ describe("Maintenance", () => { const bridgeLog = tbtcContracts.bridge.redemptionProofLog expect(bridgeLog.length).to.equal(1) expect(bridgeLog[0].mainUtxo).to.equal(mainUtxo) - expect(bridgeLog[0].walletPublicKey).to.equal( + expect(bridgeLog[0].walletPublicKey).to.deep.equal( redemptionProof.expectedRedemptionProof.walletPublicKey ) expect(bridgeLog[0].redemptionTx).to.deep.equal( diff --git a/typescript/test/services/redemptions.test.ts b/typescript/test/services/redemptions.test.ts index 1b9a82e24..3b36489ed 100644 --- a/typescript/test/services/redemptions.test.ts +++ b/typescript/test/services/redemptions.test.ts @@ -53,50 +53,59 @@ describe("Redemptions", () => { tbtcContracts = new MockTBTCContracts() bitcoinClient = new MockBitcoinClient() - const walletPublicKeyHash = Hex.from( + const walletPublicKeyHash = BitcoinHashUtils.computeHash160(walletPublicKey) - ) // Prepare NewWalletRegisteredEvent history. Set only relevant fields. tbtcContracts.bridge.newWalletRegisteredEvents = [ { - walletPublicKeyHash: walletPublicKeyHash, + walletPublicKeyHash, } as NewWalletRegisteredEvent, ] // Prepare wallet data in the Bridge. Set only relevant fields. tbtcContracts.bridge.setWallet(walletPublicKeyHash.toPrefixedString(), { state: WalletState.Live, - walletPublicKey: Hex.from(walletPublicKey), + walletPublicKey, pendingRedemptionsValue: BigNumber.from(0), mainUtxoHash: tbtcContracts.bridge.buildUtxoHash(mainUtxo), } as Wallet) const walletAddress = BitcoinAddressConverter.publicKeyHashToAddress( - walletPublicKeyHash.toString(), + walletPublicKeyHash, true, BitcoinNetwork.Testnet ) // Prepare wallet transaction history for main UTXO lookup. // Set only relevant fields. - const transactionHistory = new Map() - transactionHistory.set(walletAddress, [ - { - transactionHash: mainUtxo.transactionHash, - outputs: [ - { - outputIndex: mainUtxo.outputIndex, - value: mainUtxo.value, - scriptPubKey: BitcoinAddressConverter.addressToOutputScript( - walletAddress, - BitcoinNetwork.Testnet - ), - }, - ], - } as BitcoinTx, + + const transaction = { + transactionHash: mainUtxo.transactionHash, + outputs: [ + { + outputIndex: mainUtxo.outputIndex, + value: mainUtxo.value, + scriptPubKey: BitcoinAddressConverter.addressToOutputScript( + walletAddress, + BitcoinNetwork.Testnet + ), + }, + ], + } + + const walletTransactions = new Map() + walletTransactions.set( + transaction.transactionHash.toString(), + transaction as BitcoinTx + ) + bitcoinClient.transactions = walletTransactions + + const walletTransactionHashes = new Map() + walletTransactionHashes.set(walletPublicKeyHash.toString(), [ + transaction.transactionHash, ]) - bitcoinClient.transactionHistory = transactionHistory + bitcoinClient.transactionHashes = walletTransactionHashes const redemptionsService = new RedemptionsService( tbtcContracts, @@ -105,7 +114,7 @@ describe("Redemptions", () => { await redemptionsService.requestRedemption( BitcoinAddressConverter.outputScriptToAddress( - Hex.from(redeemerOutputScript), + redeemerOutputScript, BitcoinNetwork.Testnet ), amount @@ -153,7 +162,7 @@ describe("Redemptions", () => { const actualRedemptionRequest = await redemptionsService.getRedemptionRequests( BitcoinAddressConverter.outputScriptToAddress( - Hex.from(redemptionRequest.redeemerOutputScript), + redemptionRequest.redeemerOutputScript, BitcoinNetwork.Testnet ), walletPublicKey, @@ -191,7 +200,7 @@ describe("Redemptions", () => { const actualRedemptionRequest = await redemptionsService.getRedemptionRequests( BitcoinAddressConverter.outputScriptToAddress( - Hex.from(redemptionRequest.redeemerOutputScript), + redemptionRequest.redeemerOutputScript, BitcoinNetwork.Testnet ), walletPublicKey, @@ -206,10 +215,10 @@ describe("Redemptions", () => { describe("findWalletForRedemption", () => { class TestRedemptionsService extends RedemptionsService { public async findWalletForRedemption( - redeemerOutputScript: string, + redeemerOutputScript: Hex, amount: BigNumber ): Promise<{ - walletPublicKey: string + walletPublicKey: Hex mainUtxo: BitcoinUtxo }> { return super.findWalletForRedemption(redeemerOutputScript, amount) @@ -221,8 +230,9 @@ describe("Redemptions", () => { let redemptionsService: TestRedemptionsService // script for testnet P2WSH address // tb1qau95mxzh2249aa3y8exx76ltc2sq0e7kw8hj04936rdcmnynhswqqz02vv - const redeemerOutputScript = + const redeemerOutputScript = Hex.from( "0x220020ef0b4d985752aa5ef6243e4c6f6bebc2a007e7d671ef27d4b1d0db8dcc93bc1c" + ) context( "when there are no wallets in the network that can handle redemption", @@ -268,19 +278,27 @@ describe("Redemptions", () => { (wallet) => wallet.event ) - const walletsTransactionHistory = new Map() + const walletTransactions = new Map() + const walletTransactionHashes = new Map() walletsOrder.forEach((wallet) => { const { state, mainUtxoHash, walletPublicKey, - btcAddress, transactions, pendingRedemptionsValue, } = wallet.data - walletsTransactionHistory.set(btcAddress, transactions) + transactions.forEach((tx) => { + walletTransactions.set(tx.transactionHash.toString(), tx) + }) + + walletTransactionHashes.set( + wallet.event.walletPublicKeyHash.toString(), + transactions.map((tx) => tx.transactionHash) + ) + tbtcContracts.bridge.setWallet( wallet.event.walletPublicKeyHash.toPrefixedString(), { @@ -292,7 +310,8 @@ describe("Redemptions", () => { ) }) - bitcoinClient.transactionHistory = walletsTransactionHistory + bitcoinClient.transactions = walletTransactions + bitcoinClient.transactionHashes = walletTransactionHashes redemptionsService = new TestRedemptionsService( tbtcContracts, @@ -327,7 +346,7 @@ describe("Redemptions", () => { findWalletForRedemptionData.walletWithPendingRedemption.data expect(result).to.deep.eq({ - walletPublicKey: expectedWalletData.walletPublicKey.toString(), + walletPublicKey: expectedWalletData.walletPublicKey, mainUtxo: expectedWalletData.mainUtxo, }) }) @@ -376,7 +395,7 @@ describe("Redemptions", () => { >() const key = MockBridge.buildRedemptionKey( - walletPublicKeyHash.toString(), + walletPublicKeyHash, redeemerOutputScript ) @@ -408,7 +427,7 @@ describe("Redemptions", () => { findWalletForRedemptionData.liveWallet.data expect(result).to.deep.eq({ - walletPublicKey: expectedWalletData.walletPublicKey.toString(), + walletPublicKey: expectedWalletData.walletPublicKey, mainUtxo: expectedWalletData.mainUtxo, }) }) @@ -440,7 +459,7 @@ describe("Redemptions", () => { findWalletForRedemptionData.liveWallet.data expect(result).to.deep.eq({ - walletPublicKey: expectedWalletData.walletPublicKey.toString(), + walletPublicKey: expectedWalletData.walletPublicKey, mainUtxo: expectedWalletData.mainUtxo, }) }) @@ -465,12 +484,13 @@ describe("Redemptions", () => { >() const pendingRedemption1 = MockBridge.buildRedemptionKey( - walletPublicKeyHash.toString(), + walletPublicKeyHash, redeemerOutputScript ) const pendingRedemption2 = MockBridge.buildRedemptionKey( - findWalletForRedemptionData.liveWallet.event.walletPublicKeyHash.toString(), + findWalletForRedemptionData.liveWallet.event + .walletPublicKeyHash, redeemerOutputScript ) @@ -537,9 +557,10 @@ describe("Redemptions", () => { } } - // Create a fake wallet witness transaction history that consists of 6 transactions. - const walletWitnessTransactionHistory: BitcoinTx[] = [ + // Create a fake wallet transaction history. + const walletTransactionHistory: BitcoinTx[] = [ mockTransaction( + // Witness transaction "3ca4ae3f8ee3b48949192bc7a146c8d9862267816258c85e02a44678364551e1", { "0014e6f9d74726b19b75f16fe1e9feaec048aa4fa1d0": 100000, // wallet witness output @@ -547,6 +568,7 @@ describe("Redemptions", () => { } ), mockTransaction( + // Witness transaction "4c6b33b7c0550e0e536a5d119ac7189d71e1296fcb0c258e0c115356895bc0e6", { "00140000000000000000000000000000000000000001": 100000, @@ -554,6 +576,7 @@ describe("Redemptions", () => { } ), mockTransaction( + // Witness transaction "44863a79ce2b8fec9792403d5048506e50ffa7338191db0e6c30d3d3358ea2f6", { "00140000000000000000000000000000000000000001": 100000, @@ -562,6 +585,7 @@ describe("Redemptions", () => { } ), mockTransaction( + // Witness transaction "f65bc5029251f0042aedb37f90dbb2bfb63a2e81694beef9cae5ec62e954c22e", { "0014e6f9d74726b19b75f16fe1e9feaec048aa4fa1d0": 100000, // wallet witness output @@ -569,6 +593,7 @@ describe("Redemptions", () => { } ), mockTransaction( + // Witness transaction "2724545276df61f43f1e92c4b9f1dd3c9109595c022dbd9dc003efbad8ded38b", { "0014e6f9d74726b19b75f16fe1e9feaec048aa4fa1d0": 100000, // wallet witness output @@ -576,17 +601,15 @@ describe("Redemptions", () => { } ), mockTransaction( + // Witness transaction "ea374ab6842723c647c3fc0ab281ca0641eaa768576cf9df695ca5b827140214", { "00140000000000000000000000000000000000000001": 100000, "0014e6f9d74726b19b75f16fe1e9feaec048aa4fa1d0": 200000, // wallet witness output } ), - ] - - // Create a fake wallet legacy transaction history that consists of 6 transactions. - const walletLegacyTransactionHistory: BitcoinTx[] = [ mockTransaction( + // Legacy transaction "230a19d8867ff3f5b409e924d9dd6413188e215f9bb52f1c47de6154dac42267", { "00140000000000000000000000000000000000000001": 100000, @@ -594,6 +617,7 @@ describe("Redemptions", () => { } ), mockTransaction( + // Legacy transaction "b11bfc481b95769b8488bd661d5f61a35f7c3c757160494d63f6e04e532dfcb9", { "00140000000000000000000000000000000000000001": 100000, @@ -602,6 +626,7 @@ describe("Redemptions", () => { } ), mockTransaction( + // Legacy transaction "7e91580d989f8541489a37431381ff9babd596111232f1bc7a1a1ba503c27dee", { "76a914e6f9d74726b19b75f16fe1e9feaec048aa4fa1d088ac": 100000, // wallet legacy output @@ -609,6 +634,7 @@ describe("Redemptions", () => { } ), mockTransaction( + // Legacy transaction "5404e339ba82e6e52fcc24cb40029bed8425baa4c7f869626ef9de956186f910", { "76a914e6f9d74726b19b75f16fe1e9feaec048aa4fa1d088ac": 100000, // wallet legacy output @@ -616,6 +642,7 @@ describe("Redemptions", () => { } ), mockTransaction( + // Legacy transaction "05dabb0291c0a6aa522de5ded5cb6d14ee2159e7ff109d3ef0f21de128b56b94", { "76a914e6f9d74726b19b75f16fe1e9feaec048aa4fa1d088ac": 100000, // wallet legacy output @@ -623,6 +650,7 @@ describe("Redemptions", () => { } ), mockTransaction( + // Legacy transaction "00cc0cd13fc4de7a15cb41ab6d58f8b31c75b6b9b4194958c381441a67d09b08", { "00140000000000000000000000000000000000000001": 100000, @@ -668,134 +696,143 @@ describe("Redemptions", () => { }) context("when wallet main UTXO is set in the Bridge", () => { - const tests = [ - { - testName: "recent witness transaction", - // Set the main UTXO hash based on the latest transaction from walletWitnessTransactionHistory. - actualMainUtxo: { - transactionHash: Hex.from( - "ea374ab6842723c647c3fc0ab281ca0641eaa768576cf9df695ca5b827140214" - ), - outputIndex: 1, - value: BigNumber.from(200000), - }, - expectedMainUtxo: { - transactionHash: Hex.from( - "ea374ab6842723c647c3fc0ab281ca0641eaa768576cf9df695ca5b827140214" - ), - outputIndex: 1, - value: BigNumber.from(200000), - }, - }, - { - testName: "recent legacy transaction", - // Set the main UTXO hash based on the second last transaction from walletLegacyTransactionHistory. - actualMainUtxo: { - transactionHash: Hex.from( - "05dabb0291c0a6aa522de5ded5cb6d14ee2159e7ff109d3ef0f21de128b56b94" - ), - outputIndex: 0, - value: BigNumber.from(100000), - }, - expectedMainUtxo: { - transactionHash: Hex.from( - "05dabb0291c0a6aa522de5ded5cb6d14ee2159e7ff109d3ef0f21de128b56b94" - ), - outputIndex: 0, - value: BigNumber.from(100000), - }, - }, - { - testName: "old witness transaction", - // Set the main UTXO hash based on the oldest transaction from walletWitnessTransactionHistory. - actualMainUtxo: { - transactionHash: Hex.from( - "3ca4ae3f8ee3b48949192bc7a146c8d9862267816258c85e02a44678364551e1" - ), - outputIndex: 0, - value: BigNumber.from(100000), - }, - expectedMainUtxo: undefined, - }, - { - testName: "old legacy transaction", - // Set the main UTXO hash based on the oldest transaction from walletLegacyTransactionHistory. - actualMainUtxo: { - transactionHash: Hex.from( - "230a19d8867ff3f5b409e924d9dd6413188e215f9bb52f1c47de6154dac42267" - ), - outputIndex: 1, - value: BigNumber.from(200000), - }, - expectedMainUtxo: undefined, - }, - ] + context( + "when the transaction representing main UTXO could not be found", + () => { + // This scenario should never happen. It could only happen due to some + // serious error. + beforeEach(async () => { + tbtcContracts.bridge.setWallet( + walletPublicKeyHash.toPrefixedString(), + { + // Set main UTXO hash to some non-zero-filled hash. + mainUtxoHash: Hex.from( + "0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + ), + } as Wallet + ) + }) + + it("should return undefined", async () => { + const mainUtxo = await redemptionsService.determineWalletMainUtxo( + walletPublicKeyHash, + BitcoinNetwork.Testnet + ) + + expect(mainUtxo).to.be.undefined + }) + } + ) - tests.forEach(({ testName, actualMainUtxo, expectedMainUtxo }) => { - context(`with main UTXO coming from ${testName}`, () => { - const networkTests = [ + context( + "when the transaction representing main UTXO could be found", + () => { + const tests = [ + { + testName: "recent witness transaction", + // Set the main UTXO hash based on the latest transaction from walletWitnessTransactionHistory. + mainUtxo: { + transactionHash: Hex.from( + "ea374ab6842723c647c3fc0ab281ca0641eaa768576cf9df695ca5b827140214" + ), + outputIndex: 1, + value: BigNumber.from(200000), + }, + }, + { + testName: "recent legacy transaction", + // Set the main UTXO hash based on the second last transaction from walletLegacyTransactionHistory. + mainUtxo: { + transactionHash: Hex.from( + "05dabb0291c0a6aa522de5ded5cb6d14ee2159e7ff109d3ef0f21de128b56b94" + ), + outputIndex: 0, + value: BigNumber.from(100000), + }, + }, { - networkTestName: "bitcoin testnet", - network: BitcoinNetwork.Testnet, + testName: "old witness transaction", + // Set the main UTXO hash based on the oldest transaction from walletWitnessTransactionHistory. + mainUtxo: { + transactionHash: Hex.from( + "3ca4ae3f8ee3b48949192bc7a146c8d9862267816258c85e02a44678364551e1" + ), + outputIndex: 0, + value: BigNumber.from(100000), + }, }, { - networkTestName: "bitcoin mainnet", - network: BitcoinNetwork.Mainnet, + testName: "old legacy transaction", + // Set the main UTXO hash based on the oldest transaction from walletLegacyTransactionHistory. + mainUtxo: { + transactionHash: Hex.from( + "230a19d8867ff3f5b409e924d9dd6413188e215f9bb52f1c47de6154dac42267" + ), + outputIndex: 1, + value: BigNumber.from(200000), + }, }, ] - networkTests.forEach(({ networkTestName, network }) => { - context(`with ${networkTestName} network`, () => { - beforeEach(async () => { - bitcoinNetwork = network - - const walletWitnessAddress = - BitcoinAddressConverter.publicKeyHashToAddress( - walletPublicKeyHash.toString(), - true, - bitcoinNetwork - ) - const walletLegacyAddress = - BitcoinAddressConverter.publicKeyHashToAddress( - walletPublicKeyHash.toString(), - false, - bitcoinNetwork - ) - - // Record the fake transaction history for both address types. - const transactionHistory = new Map() - transactionHistory.set( - walletWitnessAddress, - walletWitnessTransactionHistory - ) - transactionHistory.set( - walletLegacyAddress, - walletLegacyTransactionHistory - ) - bitcoinClient.transactionHistory = transactionHistory - - tbtcContracts.bridge.setWallet( - walletPublicKeyHash.toPrefixedString(), - { - mainUtxoHash: - tbtcContracts.bridge.buildUtxoHash(actualMainUtxo), - } as Wallet - ) - }) - - it("should return the expected main UTXO", async () => { - const mainUtxo = - await redemptionsService.determineWalletMainUtxo( - walletPublicKeyHash, - bitcoinNetwork - ) - - expect(mainUtxo).to.be.eql(expectedMainUtxo) + tests.forEach(({ testName, mainUtxo }) => { + context(`with main UTXO coming from ${testName}`, () => { + const networkTests = [ + { + networkTestName: "bitcoin testnet", + network: BitcoinNetwork.Testnet, + }, + { + networkTestName: "bitcoin mainnet", + network: BitcoinNetwork.Mainnet, + }, + ] + + networkTests.forEach(({ networkTestName, network }) => { + context(`with ${networkTestName} network`, () => { + beforeEach(async () => { + bitcoinNetwork = network + + // Record transaction and transaction hashes. + const transactions = new Map() + walletTransactionHistory.forEach((tx) => { + transactions.set(tx.transactionHash.toString(), tx) + }) + bitcoinClient.transactions = transactions + + const transactionHashes = new Map< + string, + BitcoinTxHash[] + >() + transactionHashes.set( + walletPublicKeyHash.toString(), + walletTransactionHistory.map((tx) => tx.transactionHash) + ) + bitcoinClient.transactionHashes = transactionHashes + + tbtcContracts.bridge.setWallet( + walletPublicKeyHash.toPrefixedString(), + { + mainUtxoHash: + tbtcContracts.bridge.buildUtxoHash(mainUtxo), + } as Wallet + ) + }) + + it("should return the expected main UTXO", async () => { + const mainUtxo = + await redemptionsService.determineWalletMainUtxo( + walletPublicKeyHash, + bitcoinNetwork + ) + + expect(mainUtxo).to.be.eql(mainUtxo) + }) + }) }) }) }) - }) - }) + } + ) }) }) }) diff --git a/typescript/test/utils/mock-bitcoin-client.ts b/typescript/test/utils/mock-bitcoin-client.ts index 96b01b249..2463bee87 100644 --- a/typescript/test/utils/mock-bitcoin-client.ts +++ b/typescript/test/utils/mock-bitcoin-client.ts @@ -7,6 +7,7 @@ import { BitcoinTx, BitcoinTxHash, } from "../../src/lib/bitcoin" +import { Hex } from "../../src/lib/utils" /** * Mock Bitcoin client used for test purposes. @@ -16,8 +17,9 @@ export class MockBitcoinClient implements BitcoinClient { private _rawTransactions = new Map() private _transactions = new Map() private _confirmations = new Map() + private _transactionHashes = new Map() private _latestHeight = 0 - private _headersChain = "" + private _headersChain = Hex.from("") private _transactionMerkle: BitcoinTxMerkleBranch = { blockHeight: 0, merkle: [], @@ -42,11 +44,15 @@ export class MockBitcoinClient implements BitcoinClient { this._confirmations = value } + set transactionHashes(value: Map) { + this._transactionHashes = value + } + set latestHeight(value: number) { this._latestHeight = value } - set headersChain(value: string) { + set headersChain(value: Hex) { this._headersChain = value } @@ -110,14 +116,25 @@ export class MockBitcoinClient implements BitcoinClient { }) } + getTxHashesForPublicKeyHash(publicKeyHash: Hex): Promise { + return new Promise((resolve, _) => { + const hashes = this._transactionHashes.get(publicKeyHash.toString()) + if (hashes) { + resolve(hashes) + } else { + resolve([]) + } + }) + } + latestBlockHeight(): Promise { return new Promise((resolve, _) => { resolve(this._latestHeight) }) } - getHeadersChain(blockHeight: number, chainLength: number): Promise { - return new Promise((resolve, _) => { + getHeadersChain(blockHeight: number, chainLength: number): Promise { + return new Promise((resolve, _) => { resolve(this._headersChain) }) } diff --git a/typescript/test/utils/mock-bridge.ts b/typescript/test/utils/mock-bridge.ts index f6fbd0757..a1340a892 100644 --- a/typescript/test/utils/mock-bridge.ts +++ b/typescript/test/utils/mock-bridge.ts @@ -36,9 +36,9 @@ interface RevealDepositLogEntry { } interface RequestRedemptionLogEntry { - walletPublicKey: string + walletPublicKey: Hex mainUtxo: BitcoinUtxo - redeemerOutputScript: string + redeemerOutputScript: Hex amount: BigNumber } @@ -46,7 +46,7 @@ interface RedemptionProofLogEntry { redemptionTx: BitcoinRawTxVectors redemptionProof: BitcoinSpvProof mainUtxo: BitcoinUtxo - walletPublicKey: string + walletPublicKey: Hex } interface NewWalletRegisteredEventsLog { @@ -55,7 +55,7 @@ interface NewWalletRegisteredEventsLog { } interface WalletLog { - walletPublicKeyHash: string + walletPublicKeyHash: Hex } /** @@ -70,7 +70,7 @@ export class MockBridge implements Bridge { private _requestRedemptionLog: RequestRedemptionLogEntry[] = [] private _redemptionProofLog: RedemptionProofLogEntry[] = [] private _deposits = new Map() - private _activeWalletPublicKey: string | undefined + private _activeWalletPublicKey: Hex | undefined private _newWalletRegisteredEvents: NewWalletRegisteredEvent[] = [] private _newWalletRegisteredEventsLog: NewWalletRegisteredEventsLog[] = [] private _wallets = new Map() @@ -120,7 +120,7 @@ export class MockBridge implements Bridge { this._deposits = value } - setActiveWalletPublicKey(activeWalletPublicKey: string) { + setActiveWalletPublicKey(activeWalletPublicKey: Hex) { this._activeWalletPublicKey = activeWalletPublicKey } @@ -159,10 +159,14 @@ export class MockBridge implements Bridge { sweepProof: BitcoinSpvProof, mainUtxo: BitcoinUtxo, vault?: ChainIdentifier - ): Promise { + ): Promise { this._depositSweepProofLog.push({ sweepTx, sweepProof, mainUtxo }) - return new Promise((resolve, _) => { - resolve() + return new Promise((resolve, _) => { + resolve( + Hex.from( + "01ee2a0061b6bd68b6f478c48b9625fac89a4401e73b49d3ee258f9a60c5e65f" + ) + ) }) } @@ -170,12 +174,14 @@ export class MockBridge implements Bridge { depositTx: BitcoinRawTxVectors, depositOutputIndex: number, deposit: DepositReceipt - ): Promise { + ): Promise { this._revealDepositLog.push({ depositTx, depositOutputIndex, deposit }) - return new Promise((resolve, _) => { + return new Promise((resolve, _) => { // random transaction hash resolve( - "2f952bdc206bf51bb745b967cb7166149becada878d3191ffe341155ebcd4883" + Hex.from( + "2f952bdc206bf51bb745b967cb7166149becada878d3191ffe341155ebcd4883" + ) ) }) } @@ -223,33 +229,43 @@ export class MockBridge implements Bridge { redemptionTx: BitcoinRawTxVectors, redemptionProof: BitcoinSpvProof, mainUtxo: BitcoinUtxo, - walletPublicKey: string - ): Promise { + walletPublicKey: Hex + ): Promise { this._redemptionProofLog.push({ redemptionTx, redemptionProof, mainUtxo, walletPublicKey, }) - return new Promise((resolve, _) => { - resolve() + return new Promise((resolve, _) => { + // random transaction hash + resolve( + Hex.from( + "4f6ce6af47d547bb9821d28c21261026f21b72e52d506d17ab81502b8021537d" + ) + ) }) } requestRedemption( - walletPublicKey: string, + walletPublicKey: Hex, mainUtxo: BitcoinUtxo, - redeemerOutputScript: string, + redeemerOutputScript: Hex, amount: BigNumber - ) { + ): Promise { this._requestRedemptionLog.push({ walletPublicKey, mainUtxo, redeemerOutputScript, amount, }) - return new Promise((resolve, _) => { - resolve() + return new Promise((resolve, _) => { + // random transaction hash + resolve( + Hex.from( + "bcbef136592feabdebcc68eb4222a49369a9cfeb7fc5f5ec84583313249025fd" + ) + ) }) } @@ -260,8 +276,8 @@ export class MockBridge implements Bridge { } pendingRedemptions( - walletPublicKey: string, - redeemerOutputScript: string + walletPublicKey: Hex, + redeemerOutputScript: Hex ): Promise { return new Promise((resolve, _) => { resolve( @@ -275,8 +291,8 @@ export class MockBridge implements Bridge { } timedOutRedemptions( - walletPublicKey: string, - redeemerOutputScript: string + walletPublicKey: Hex, + redeemerOutputScript: Hex ): Promise { return new Promise((resolve, _) => { resolve( @@ -290,8 +306,8 @@ export class MockBridge implements Bridge { } private redemptions( - walletPublicKey: string, - redeemerOutputScript: string, + walletPublicKey: Hex, + redeemerOutputScript: Hex, redemptionsMap: Map ): RedemptionRequest { const redemptionKey = MockBridge.buildRedemptionKey( @@ -305,7 +321,7 @@ export class MockBridge implements Bridge { ? (redemptionsMap.get(redemptionKey) as RedemptionRequest) : { redeemer: EthereumAddress.from(constants.AddressZero), - redeemerOutputScript: "", + redeemerOutputScript: Hex.from(""), requestedAmount: BigNumber.from(0), treasuryFee: BigNumber.from(0), txMaxFee: BigNumber.from(0), @@ -314,12 +330,12 @@ export class MockBridge implements Bridge { } static buildRedemptionKey( - walletPublicKeyHash: string, - redeemerOutputScript: string + walletPublicKeyHash: Hex, + redeemerOutputScript: Hex ): string { - const prefixedWalletPublicKeyHash = `0x${walletPublicKeyHash}` + const prefixedWalletPublicKeyHash = walletPublicKeyHash.toPrefixedString() - const rawOutputScript = Buffer.from(redeemerOutputScript, "hex") + const rawOutputScript = redeemerOutputScript.toBuffer() const prefixedOutputScript = `0x${Buffer.concat([ Buffer.from([rawOutputScript.length]), @@ -335,7 +351,7 @@ export class MockBridge implements Bridge { ) } - async activeWalletPublicKey(): Promise { + async activeWalletPublicKey(): Promise { return this._activeWalletPublicKey } @@ -353,7 +369,7 @@ export class MockBridge implements Bridge { async wallets(walletPublicKeyHash: Hex): Promise { this._walletsLog.push({ - walletPublicKeyHash: walletPublicKeyHash.toPrefixedString(), + walletPublicKeyHash, }) const wallet = this._wallets.get(walletPublicKeyHash.toPrefixedString()) return wallet! diff --git a/typescript/test/utils/mock-tbtc-token.ts b/typescript/test/utils/mock-tbtc-token.ts index b2238f550..ba7fdc08d 100644 --- a/typescript/test/utils/mock-tbtc-token.ts +++ b/typescript/test/utils/mock-tbtc-token.ts @@ -5,9 +5,9 @@ import { BitcoinUtxo } from "../../src/lib/bitcoin" import { EthereumAddress } from "../../src" interface RequestRedemptionLog { - walletPublicKey: string + walletPublicKey: Hex mainUtxo: BitcoinUtxo - redeemerOutputScript: string + redeemerOutputScript: Hex amount: BigNumber } @@ -23,9 +23,9 @@ export class MockTBTCToken implements TBTCToken { } async requestRedemption( - walletPublicKey: string, + walletPublicKey: Hex, mainUtxo: BitcoinUtxo, - redeemerOutputScript: string, + redeemerOutputScript: Hex, amount: BigNumber ): Promise { this._requestRedemptionLog.push({ diff --git a/typescript/tsconfig.json b/typescript/tsconfig.json index 8584d28ba..8f75788d7 100644 --- a/typescript/tsconfig.json +++ b/typescript/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "target": "ES2017", "module": "commonjs", - "lib": ["es2020"], + "lib": ["es2020", "dom"], "declaration": true, "declarationMap": true, "sourceMap": true, diff --git a/typescript/typedoc.json b/typescript/typedoc.json new file mode 100644 index 000000000..99e9f6f49 --- /dev/null +++ b/typescript/typedoc.json @@ -0,0 +1,13 @@ +{ + "$schema": "https://typedoc.org/schema.json", + "entryPoints": ["src/index.ts"], + "out": "./api-reference", + "plugin": ["typedoc-plugin-markdown"], + "githubPages": false, + "readme": "none", + "gitRevision": "main", + "hideBreadcrumbs": true, + "compilerOptions": { + "skipLibCheck": true + } +} diff --git a/typescript/yarn.lock b/typescript/yarn.lock index 08928f090..584329aed 100644 --- a/typescript/yarn.lock +++ b/typescript/yarn.lock @@ -23,6 +23,14 @@ chalk "^2.0.0" js-tokens "^4.0.0" +"@bitcoinerlab/secp256k1@^1.0.5": + version "1.0.5" + resolved "https://registry.yarnpkg.com/@bitcoinerlab/secp256k1/-/secp256k1-1.0.5.tgz#4643ba73619c24c7c455cc63c6338c69c2cf187c" + integrity sha512-8gT+ukTCFN2rTxn4hD9Jq3k+UJwcprgYjfK/SQUSLgznXoIgsBnlPuARMkyyuEjycQK9VvnPiejKdszVTflh+w== + dependencies: + "@noble/hashes" "^1.1.5" + "@noble/secp256k1" "^1.7.1" + "@celo/base@1.5.2": version "1.5.2" resolved "https://registry.yarnpkg.com/@celo/base/-/base-1.5.2.tgz#168ab5e4e30b374079d8d139fafc52ca6bfd4100" @@ -165,17 +173,12 @@ eth-lib "^0.2.8" ethereumjs-util "^5.2.0" -"@cspotcode/source-map-consumer@0.8.0": - version "0.8.0" - resolved "https://registry.yarnpkg.com/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz#33bf4b7b39c178821606f669bbc447a6a629786b" - integrity sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg== - -"@cspotcode/source-map-support@0.7.0": - version "0.7.0" - resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz#4789840aa859e46d2f3173727ab707c66bf344f5" - integrity sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA== +"@cspotcode/source-map-support@^0.8.0": + version "0.8.1" + resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz#00629c35a688e05a88b1cda684fb9d5e73f000a1" + integrity sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw== dependencies: - "@cspotcode/source-map-consumer" "0.8.0" + "@jridgewell/trace-mapping" "0.3.9" "@ensdomains/ens@^0.4.4": version "0.4.5" @@ -1490,6 +1493,24 @@ resolved "https://registry.yarnpkg.com/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz#b520529ec21d8e5945a1851dfd1c32e94e39ff45" integrity sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA== +"@jridgewell/resolve-uri@^3.0.3": + version "3.1.1" + resolved "https://registry.yarnpkg.com/@jridgewell/resolve-uri/-/resolve-uri-3.1.1.tgz#c08679063f279615a3326583ba3a90d1d82cc721" + integrity sha512-dSYZh7HhCDtCKm4QakX0xFpsRDqjjtZf/kjI/v3T3Nwt5r8/qz/M19F9ySyOqU94SXBmeG9ttTul+YnR4LOxFA== + +"@jridgewell/sourcemap-codec@^1.4.10": + version "1.4.15" + resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz#d7c6e6755c78567a951e04ab52ef0fd26de59f32" + integrity sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg== + +"@jridgewell/trace-mapping@0.3.9": + version "0.3.9" + resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz#6534fd5933a53ba7cbf3a17615e273a0d1273ff9" + integrity sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ== + dependencies: + "@jridgewell/resolve-uri" "^3.0.3" + "@jridgewell/sourcemap-codec" "^1.4.10" + "@keep-network/bitcoin-spv-sol@3.4.0-solc-0.8": version "3.4.0-solc-0.8" resolved "https://registry.yarnpkg.com/@keep-network/bitcoin-spv-sol/-/bitcoin-spv-sol-3.4.0-solc-0.8.tgz#8b44c246ffab8ea993efe196f6bf385b1a3b84dc" @@ -1643,11 +1664,16 @@ resolved "https://registry.yarnpkg.com/@ledgerhq/logs/-/logs-5.50.0.tgz#29c6419e8379d496ab6d0426eadf3c4d100cd186" integrity sha512-swKHYCOZUGyVt4ge0u8a7AwNcA//h4nx5wIi0sruGye1IJ5Cva0GyK9L2/WdX+kWVTKp92ZiEo1df31lrWGPgA== -"@noble/hashes@^1.2.0": +"@noble/hashes@^1.1.5", "@noble/hashes@^1.2.0": version "1.3.2" resolved "https://registry.yarnpkg.com/@noble/hashes/-/hashes-1.3.2.tgz#6f26dbc8fbc7205873ce3cee2f690eba0d421b39" integrity sha512-MVC8EAQp7MvEcm30KWENFjgR+Mkmf+D189XJTkFIlwohU5hcBbn1ZkKq7KVTi2Hme3PMGF390DaL52beVrIihQ== +"@noble/secp256k1@^1.7.1": + version "1.7.1" + resolved "https://registry.yarnpkg.com/@noble/secp256k1/-/secp256k1-1.7.1.tgz#b251c70f824ce3ca7f8dc3df08d58f005cc0507c" + integrity sha512-hOUk6AyBFmqVrv7k5WAw/LpszxVbj9gGN4JRkIX52fdFAj1UA61KXmZDvqVEm+pOyec3+fIeZB02LYa/pWOArw== + "@nodelib/fs.scandir@2.1.5": version "2.1.5" resolved "https://registry.yarnpkg.com/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz#7619c2eb21b25483f6d167548b4cfd5a7488c3d5" @@ -2085,10 +2111,10 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-12.20.52.tgz#2fd2dc6bfa185601b15457398d4ba1ef27f81251" integrity sha512-cfkwWw72849SNYp3Zx0IcIs25vABmFh73xicxhCkTcvtZQeIez15PpwQN8fY3RD7gv1Wrxlc9MEtfMORZDEsGw== -"@types/node@^16.3.1": - version "16.11.14" - resolved "https://registry.yarnpkg.com/@types/node/-/node-16.11.14.tgz#4939fb42e5b0ffb3ea7e193c28244fe7414977a6" - integrity sha512-mK6BKLpL0bG6v2CxHbm0ed6RcZrAtTHBTd/ZpnlVPVa3HkumsqLE4BC4u6TQ8D7pnrRbOU0am6epuALs+Ncnzw== +"@types/node@^16.4.0": + version "16.18.60" + resolved "https://registry.yarnpkg.com/@types/node/-/node-16.18.60.tgz#0b0f4316906f1bd0e03b640363f67bd4e86958bd" + integrity sha512-ZUGPWx5vKfN+G2/yN7pcSNLkIkXEvlwNaJEd4e0ppX7W2S8XAkdc/37hM4OUNJB9sa0p12AOvGvxL4JCPiz9DA== "@types/pbkdf2@^3.0.0": version "3.1.0" @@ -2336,6 +2362,11 @@ ansi-regex@^5.0.1: resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304" integrity sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ== +ansi-sequence-parser@^1.1.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/ansi-sequence-parser/-/ansi-sequence-parser-1.1.1.tgz#e0aa1cdcbc8f8bb0b5bca625aac41f5f056973cf" + integrity sha512-vJXt3yiaUL4UU546s3rPXlsry/RnM730G1+HkpKE012AN0sx1eOrxSu95oKDIonskeLTijMgqWZ3uDEe3NFvyg== + ansi-styles@^3.2.0, ansi-styles@^3.2.1: version "3.2.1" resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.1.tgz#41fbb20243e50b12be0f04b8dedbf07520ce841d" @@ -2707,6 +2738,13 @@ brace-expansion@^1.1.7: balanced-match "^1.0.0" concat-map "0.0.1" +brace-expansion@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-2.0.1.tgz#1edc459e0f0c548486ecf9fc99f2221364b9a0ae" + integrity sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA== + dependencies: + balanced-match "^1.0.0" + braces@^3.0.1, braces@~3.0.2: version "3.0.2" resolved "https://registry.yarnpkg.com/braces/-/braces-3.0.2.tgz#3454e1a462ee8d599e236df336cd9ea4f8afe107" @@ -4828,6 +4866,18 @@ growl@1.10.5: resolved "https://registry.yarnpkg.com/growl/-/growl-1.10.5.tgz#f2735dc2283674fa67478b10181059355c369e5e" integrity sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA== +handlebars@^4.7.7: + version "4.7.8" + resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.7.8.tgz#41c42c18b1be2365439188c77c6afae71c0cd9e9" + integrity sha512-vafaFqs8MZkRrSX7sFVUdo3ap/eNiLnb4IakshzvP56X5Nr1iGKAIqdX6tMlm6HcNRIkr6AxO5jFEoJzzpT8aQ== + dependencies: + minimist "^1.2.5" + neo-async "^2.6.2" + source-map "^0.6.1" + wordwrap "^1.0.0" + optionalDependencies: + uglify-js "^3.1.4" + har-schema@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-2.0.0.tgz#a94c2224ebcac04782a0d9035521f24735b7ec92" @@ -5386,6 +5436,11 @@ json-text-sequence@^0.1: dependencies: delimit-stream "0.1.0" +jsonc-parser@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/jsonc-parser/-/jsonc-parser-3.2.0.tgz#31ff3f4c2b9793f89c67212627c51c6394f88e76" + integrity sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w== + jsonfile@^2.1.0: version "2.4.0" resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-2.4.0.tgz#3736a2b428b87bbda0cc83b53fa3d633a35c2ae8" @@ -5674,6 +5729,11 @@ ltgt@~2.2.0: resolved "https://registry.yarnpkg.com/ltgt/-/ltgt-2.2.1.tgz#f35ca91c493f7b73da0e07495304f17b31f87ee5" integrity sha1-81ypHEk/e3PaDgdJUwTxezH4fuU= +lunr@^2.3.9: + version "2.3.9" + resolved "https://registry.yarnpkg.com/lunr/-/lunr-2.3.9.tgz#18b123142832337dd6e964df1a5a7707b25d35e1" + integrity sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow== + make-dir@^1.0.0: version "1.3.0" resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-1.3.0.tgz#79c1033b80515bd6d24ec9933e860ca75ee27f0c" @@ -5686,6 +5746,11 @@ make-error@^1.1.1: resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.6.tgz#2eb2e37ea9b67c4891f684a1394799af484cf7a2" integrity sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw== +marked@^4.3.0: + version "4.3.0" + resolved "https://registry.yarnpkg.com/marked/-/marked-4.3.0.tgz#796362821b019f734054582038b116481b456cf3" + integrity sha512-PRsaiG84bK+AMvxziE/lCFss8juXjNaWzVbN5tXAm4XjeaS9NAHhop+PjQxz2A9h8Q4M/xGmzP8vqNwy6JeK0A== + mcl-wasm@^0.7.1: version "0.7.9" resolved "https://registry.yarnpkg.com/mcl-wasm/-/mcl-wasm-0.7.9.tgz#c1588ce90042a8700c3b60e40efb339fc07ab87f" @@ -5816,6 +5881,13 @@ minimatch@3.0.4, minimatch@^3.0.4: dependencies: brace-expansion "^1.1.7" +minimatch@^9.0.3: + version "9.0.3" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-9.0.3.tgz#a6e00c3de44c3a542bfaae70abfc22420a6da825" + integrity sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg== + dependencies: + brace-expansion "^2.0.1" + minimist@^1.2.5, minimist@^1.2.6: version "1.2.6" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44" @@ -6016,6 +6088,11 @@ negotiator@0.6.3: resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.3.tgz#58e323a72fedc0d6f9cd4d31fe49f51479590ccd" integrity sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg== +neo-async@^2.6.2: + version "2.6.2" + resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f" + integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw== + next-tick@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/next-tick/-/next-tick-1.1.0.tgz#1836ee30ad56d67ef281b22bd199f709449b35eb" @@ -6987,6 +7064,16 @@ shebang-regex@^3.0.0: resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172" integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== +shiki@^0.14.1: + version "0.14.5" + resolved "https://registry.yarnpkg.com/shiki/-/shiki-0.14.5.tgz#375dd214e57eccb04f0daf35a32aa615861deb93" + integrity sha512-1gCAYOcmCFONmErGTrS1fjzJLA7MGZmKzrBNX7apqSwhyITJg2O102uFzXUeBxNnEkDA9vHIKLyeKq0V083vIw== + dependencies: + ansi-sequence-parser "^1.1.0" + jsonc-parser "^3.2.0" + vscode-oniguruma "^1.7.0" + vscode-textmate "^8.0.0" + side-channel@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/side-channel/-/side-channel-1.0.4.tgz#efce5c8fdc104ee751b25c58d4290011fa5ea2cf" @@ -7062,7 +7149,7 @@ source-map-support@^0.5.17: buffer-from "^1.0.0" source-map "^0.6.0" -source-map@^0.6.0: +source-map@^0.6.0, source-map@^0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263" integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g== @@ -7409,13 +7496,6 @@ tiny-secp256k1@^1.1.3: elliptic "^6.4.0" nan "^2.13.2" -tiny-secp256k1@^2.2.3: - version "2.2.3" - resolved "https://registry.yarnpkg.com/tiny-secp256k1/-/tiny-secp256k1-2.2.3.tgz#fe1dde11a64fcee2091157d4b78bcb300feb9b65" - integrity sha512-SGcL07SxcPN2nGKHTCvRMkQLYPSoeFcvArUSCYtjVARiFAWU44cCIqYS0mYAU6nY7XfvwURuTIGo2Omt3ZQr0Q== - dependencies: - uint8array-tools "0.0.7" - tmp@0.0.33: version "0.0.33" resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9" @@ -7484,12 +7564,12 @@ ts-essentials@^7.0.1: resolved "https://registry.yarnpkg.com/ts-essentials/-/ts-essentials-7.0.3.tgz#686fd155a02133eedcc5362dc8b5056cde3e5a38" integrity sha512-8+gr5+lqO3G84KdiTSMRLtuyJ+nTBVRKuCrK4lidMPdVeEp0uqC875uE5NMcaA7YYMN7XsNiFQuMvasF8HT/xQ== -ts-node@^10.1.0: - version "10.4.0" - resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.4.0.tgz#680f88945885f4e6cf450e7f0d6223dd404895f7" - integrity sha512-g0FlPvvCXSIO1JDF6S232P5jPYqBkRL9qly81ZgAOSU7rwI0stphCgd2kLiCrU9DjQCrJMWEqcNSjQL02s6d8A== +ts-node@^10.8.0: + version "10.9.1" + resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.9.1.tgz#e73de9102958af9e1f0b168a6ff320e25adcff4b" + integrity sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw== dependencies: - "@cspotcode/source-map-support" "0.7.0" + "@cspotcode/source-map-support" "^0.8.0" "@tsconfig/node10" "^1.0.7" "@tsconfig/node12" "^1.0.7" "@tsconfig/node14" "^1.0.0" @@ -7500,6 +7580,7 @@ ts-node@^10.1.0: create-require "^1.1.0" diff "^4.0.1" make-error "^1.1.1" + v8-compile-cache-lib "^3.0.1" yn "3.1.1" ts-node@^8.4.1: @@ -7616,6 +7697,23 @@ typedarray-to-buffer@^3.1.5: dependencies: is-typedarray "^1.0.0" +typedoc-plugin-markdown@^3.17.0: + version "3.17.0" + resolved "https://registry.yarnpkg.com/typedoc-plugin-markdown/-/typedoc-plugin-markdown-3.17.0.tgz#f4820efadcac80d0e04c2d3eb67a8cf616477923" + integrity sha512-+uh5fHNfNSGdUxae0FWOuJ8Xu9Sl08jkdshOg6dilAqN/ZXmYsUFFDKw70fYfiGxdCLvpUuyr9FYO+WAa2lHeA== + dependencies: + handlebars "^4.7.7" + +typedoc@^0.25.3: + version "0.25.3" + resolved "https://registry.yarnpkg.com/typedoc/-/typedoc-0.25.3.tgz#53c6d668e1001b3d488e9a750fcdfb05433554c0" + integrity sha512-Ow8Bo7uY1Lwy7GTmphRIMEo6IOZ+yYUyrc8n5KXIZg1svpqhZSWgni2ZrDhe+wLosFS8yswowUzljTAV/3jmWw== + dependencies: + lunr "^2.3.9" + marked "^4.3.0" + minimatch "^9.0.3" + shiki "^0.14.1" + typeforce@^1.11.3, typeforce@^1.11.5, typeforce@^1.18.0: version "1.18.0" resolved "https://registry.yarnpkg.com/typeforce/-/typeforce-1.18.0.tgz#d7416a2c5845e085034d70fcc5b6cc4a90edbfdc" @@ -7626,10 +7724,10 @@ typescript@^3.6.4: resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.10.tgz#70f3910ac7a51ed6bef79da7800690b19bf778b8" integrity sha512-w6fIxVE/H1PkLKcCPsFqKE7Kv7QUwhU8qQY2MueZXWx5cPZdwFupLgKK3vntcK98BtNHZtAF4LA/yl2a7k8R6Q== -typescript@^4.3.5: - version "4.5.4" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.4.tgz#a17d3a0263bf5c8723b9c52f43c5084edf13c2e8" - integrity sha512-VgYs2A2QIRuGphtzFV7aQJduJ2gyfTljngLzjpfW9FoYZF6xuw1W0vW9ghCKLfcWrCFxK81CSGRAvS1pn4fIUg== +typescript@^4.6.0: + version "4.9.5" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.9.5.tgz#095979f9bcc0d09da324d58d03ce8f8374cbe65a" + integrity sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g== typical@^4.0.0: version "4.0.0" @@ -7641,10 +7739,10 @@ typical@^5.2.0: resolved "https://registry.yarnpkg.com/typical/-/typical-5.2.0.tgz#4daaac4f2b5315460804f0acf6cb69c52bb93066" integrity sha512-dvdQgNDNJo+8B2uBQoqdb11eUCE1JQXhvjC/CZtgvZseVd5TYMXnq0+vuUemXbd/Se29cTaUuPX3YIc2xgbvIg== -uint8array-tools@0.0.7: - version "0.0.7" - resolved "https://registry.yarnpkg.com/uint8array-tools/-/uint8array-tools-0.0.7.tgz#a7a2bb5d8836eae2fade68c771454e6a438b390d" - integrity sha512-vrrNZJiusLWoFWBqz5Y5KMCgP9W9hnjZHzZiZRT8oNAkq3d5Z5Oe76jAvVVSRh4U8GGR90N2X1dWtrhvx6L8UQ== +uglify-js@^3.1.4: + version "3.17.4" + resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-3.17.4.tgz#61678cf5fa3f5b7eb789bb345df29afb8257c22c" + integrity sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g== ultron@~1.1.0: version "1.1.1" @@ -7789,6 +7887,11 @@ uuid@^3.3.2: resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee" integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A== +v8-compile-cache-lib@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf" + integrity sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg== + v8-compile-cache@^2.0.3: version "2.3.0" resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee" @@ -7828,6 +7931,16 @@ verror@1.10.0: core-util-is "1.0.2" extsprintf "^1.2.0" +vscode-oniguruma@^1.7.0: + version "1.7.0" + resolved "https://registry.yarnpkg.com/vscode-oniguruma/-/vscode-oniguruma-1.7.0.tgz#439bfad8fe71abd7798338d1cd3dc53a8beea94b" + integrity sha512-L9WMGRfrjOhgHSdOYgCt/yRMsXzLDJSL7BPrOZt73gU0iWO4mpqzqQzOz5srxqTvMBaR0XZTSrVWo4j55Rc6cA== + +vscode-textmate@^8.0.0: + version "8.0.0" + resolved "https://registry.yarnpkg.com/vscode-textmate/-/vscode-textmate-8.0.0.tgz#2c7a3b1163ef0441097e0b5d6389cd5504b59e5d" + integrity sha512-AFbieoL7a5LMqcnOF04ji+rpXadgOXnZsxQr//r83kLPr7biP7am3g9zbaZIaBGwBRWeSvoMD4mgPdX3e4NWBg== + web3-bzz@1.2.2: version "1.2.2" resolved "https://registry.yarnpkg.com/web3-bzz/-/web3-bzz-1.2.2.tgz#a3b9f613c49fd3e120e0997088a73557d5adb724" @@ -8669,6 +8782,11 @@ word-wrap@^1.2.3: resolved "https://registry.yarnpkg.com/word-wrap/-/word-wrap-1.2.3.tgz#610636f6b1f703891bd34771ccb17fb93b47079c" integrity sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ== +wordwrap@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" + integrity sha512-gvVzJFlPycKc5dZN4yPkP8w7Dc37BtP1yczEneOb4uq34pXZcvrtRTmWV8W+Ume+XCxKgbjM+nevkyFPMybd4Q== + wordwrapjs@^4.0.0: version "4.0.1" resolved "https://registry.yarnpkg.com/wordwrapjs/-/wordwrapjs-4.0.1.tgz#d9790bccfb110a0fc7836b5ebce0937b37a8b98f"