Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

General revamp of the typescript library #705

Merged
merged 44 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
26ec1f0
Transform `bitcoin.ts` file to `lib/bitcoin` shared lib
lukasz-zimnoch Sep 22, 2023
7e6c619
Transform `chain.ts` file to `lib/contracts` shared lib
lukasz-zimnoch Sep 22, 2023
97cfb7e
Transform `electrum.ts` file to `lib/electrum` shared lib
lukasz-zimnoch Sep 22, 2023
c09233f
Transform `ethereum.ts` file to `lib/ethereum` shared lib
lukasz-zimnoch Sep 22, 2023
b3e99a1
Transform `backoff.ts` and `hex.ts` files to `lib/utils` shared lib
lukasz-zimnoch Sep 25, 2023
0052915
Move chain types from `wallet.ts` to `lib/contracts`
lukasz-zimnoch Sep 25, 2023
3a1a92c
Move chain types from `redemption.ts` to `lib/contracts`
lukasz-zimnoch Sep 25, 2023
b3390d8
Move chain types from `optimistic-minting.ts` to `lib/contracts`
lukasz-zimnoch Sep 25, 2023
dcba2df
Move chain types from `deposit.ts` to `lib/contracts`
lukasz-zimnoch Sep 25, 2023
a4160bd
Move `proof.ts` to `lib/bitcoin`
lukasz-zimnoch Sep 25, 2023
6c637d1
Final iteration on `lib/bitcoin`
lukasz-zimnoch Sep 26, 2023
955788d
Final iteration on `lib/contracts`
lukasz-zimnoch Sep 26, 2023
d730878
Final iteration on `lib/electrum`
lukasz-zimnoch Sep 26, 2023
7478d3f
Final iteration on `lib/ethereum`
lukasz-zimnoch Sep 26, 2023
2016d5e
Rework deposit domain objects
lukasz-zimnoch Sep 26, 2023
dbfe946
Implement the `./services/deposits` feature module
lukasz-zimnoch Sep 28, 2023
40b990c
Move `deposit-refund.ts` to the `./services/deposits` feature module
lukasz-zimnoch Sep 28, 2023
8ec25d6
Add some TODOs around deposits
lukasz-zimnoch Sep 29, 2023
14ecaef
Move part of `redemption.ts` to the `./services/redemptions` feature …
lukasz-zimnoch Sep 29, 2023
f0f7c15
Move remaining code to the `./services/maintenance` feature module
lukasz-zimnoch Sep 29, 2023
550486d
Skip Electrum test suite
lukasz-zimnoch Sep 29, 2023
6628c09
Add `TBTC` entrypoint component and embed chain configs
lukasz-zimnoch Sep 29, 2023
5c74ca6
Facilitate deposit initiation
lukasz-zimnoch Oct 4, 2023
64ea539
Remove `src` and `typechain` from result package
lukasz-zimnoch Oct 5, 2023
cc3d85a
Sort out and update TODOs
lukasz-zimnoch Oct 5, 2023
66cbee1
Add `bitcoinjs-lib` and friends
lukasz-zimnoch Oct 9, 2023
1b21713
Integrate `bitcoinjs-lib` changes around deposit sweeps
lukasz-zimnoch Oct 9, 2023
6647d69
Integrate `bitcoinjs-lib` changes around deposits
lukasz-zimnoch Oct 10, 2023
3dfad7a
Integrate `bitcoinjs-lib` changes around redemptions
lukasz-zimnoch Oct 10, 2023
162ce25
Integrate `bitcoinjs-lib` changes around deposit refund
lukasz-zimnoch Oct 10, 2023
3987887
Remove `bcoin` completely
lukasz-zimnoch Oct 10, 2023
b362840
Update `bitcoinjs-lib` and supported `node` version
lukasz-zimnoch Oct 10, 2023
747c1d1
Re-format `package.json` file
lukasz-zimnoch Oct 10, 2023
876af0c
Rework unit tests structure
lukasz-zimnoch Oct 11, 2023
3d0e38b
Adjust refund.ts script
lukasz-zimnoch Oct 11, 2023
4f766f3
Merge branch 'main' into ts-api-revamp
lukasz-zimnoch Oct 16, 2023
4d4f45c
Make `BitcoinCompactSizeUint.read` throw on empty varlen data
lukasz-zimnoch Oct 16, 2023
2343c83
Fix some typos around SDK functions
lukasz-zimnoch Oct 16, 2023
c359fef
Use ternary operator in `BitcoinPublicKeyUtils.compressPublicKey` fun…
lukasz-zimnoch Oct 16, 2023
ad51b2e
Improvements around SDK functions docstrings
lukasz-zimnoch Oct 16, 2023
cb80637
Include `src` and `typechain` in the resulting npm package
lukasz-zimnoch Oct 16, 2023
e063022
Do not export `publicKeyToAddress` directly
lukasz-zimnoch Oct 16, 2023
62ac608
Add header index to error message thrown by `validateBitcoinHeadersCh…
lukasz-zimnoch Oct 16, 2023
4bdc2a1
Update supported Node.js and Yarn versions in READMEs
lukasz-zimnoch Oct 16, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions typescript/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ toc::[]

Please make sure you have the following prerequisites installed on your machine:

- https://nodejs.org[Node.js] >14.17.4
- https://yarnpkg.com[Yarn] >1.22.10
- https://nodejs.org[Node.js] >=16
- https://yarnpkg.com[Yarn] >=1.22.19

=== Install dependencies

Expand Down
4 changes: 2 additions & 2 deletions typescript/scripts/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ toc::[]

Please make sure you have the following prerequisites installed on your machine:

- https://nodejs.org[Node.js] >14.18.0
- https://yarnpkg.com[Yarn] >1.22.19
- https://nodejs.org[Node.js] >=16
- https://yarnpkg.com[Yarn] >=1.22.19

tBTCv2 system prerequisite is that you can refund your BTC only if it was not used
for minting tBTC and after `refundLocktime` has passed.
Expand Down
32 changes: 19 additions & 13 deletions typescript/scripts/refund.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { BigNumber } from "ethers"
import { Deposit } from "../src/deposit"
import { submitDepositRefundTransaction } from "../src/deposit-refund"
import { TransactionHash, UnspentTransactionOutput } from "../src/bitcoin"
import { Client as ElectrumClient } from "../src/electrum"
import { program } from "commander"
import fs from "fs"
import * as fs from "fs"
import {
BitcoinTxHash,
BitcoinUtxo,
DepositReceipt,
DepositRefund,
DepositScript,
ElectrumClient,
ElectrumCredentials,
} from "../src"

program
.version("0.0.1")
Expand Down Expand Up @@ -49,13 +54,12 @@ const electrumCredentials = {
host: options.host,
port: options.port,
protocol: options.protocol,
}
} as ElectrumCredentials

const depositJson = JSON.parse(fs.readFileSync(depositJsonPath, "utf-8"))

const deposit: Deposit = {
const deposit: DepositReceipt = {
depositor: depositJson.depositor,
amount: BigNumber.from(refundAmount),
walletPublicKeyHash: depositJson.walletPublicKeyHash,
refundPublicKeyHash: depositJson.refundPublicKeyHash,
blindingFactor: depositJson.blindingFactor,
Expand All @@ -73,19 +77,21 @@ console.log("electrum credentials:", electrumCredentials)
console.log("=====================================")

async function run(): Promise<void> {
const client = new ElectrumClient(electrumCredentials)
const client = new ElectrumClient([electrumCredentials])

const depositUtxo: UnspentTransactionOutput = {
transactionHash: TransactionHash.from(transactionId),
const depositUtxo: BitcoinUtxo = {
transactionHash: BitcoinTxHash.from(transactionId),
outputIndex: Number(transactionIndex),
value: BigNumber.from(refundAmount),
}

const refundTxHash = await submitDepositRefundTransaction(
const depositScript = DepositScript.fromReceipt(deposit)
const depositRefund = DepositRefund.fromScript(depositScript)

const refundTxHash = await depositRefund.submitTransaction(
client,
BigNumber.from(fee),
depositUtxo,
deposit,
recoveryAddress,
refunderPrivateKey
)
Expand Down
Loading