@teleportdao/bitcoin 1.7.2 → 1.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/bitcoin-base.d.ts +93 -0
  2. package/dist/bitcoin-base.d.ts.map +1 -0
  3. package/dist/bitcoin-base.js +236 -0
  4. package/dist/bitcoin-base.js.map +1 -0
  5. package/dist/bitcoin-interface-teleswap.d.ts +6 -1
  6. package/dist/bitcoin-interface-teleswap.d.ts.map +1 -1
  7. package/dist/bitcoin-interface-teleswap.js +2 -4
  8. package/dist/bitcoin-interface-teleswap.js.map +1 -1
  9. package/dist/helper/burn-request-helper.d.ts +7 -0
  10. package/dist/helper/burn-request-helper.d.ts.map +1 -0
  11. package/dist/helper/burn-request-helper.js +26 -0
  12. package/dist/helper/burn-request-helper.js.map +1 -0
  13. package/dist/helper/teleport-request-helper.d.ts +47 -0
  14. package/dist/helper/teleport-request-helper.d.ts.map +1 -0
  15. package/dist/helper/teleport-request-helper.js +146 -0
  16. package/dist/helper/teleport-request-helper.js.map +1 -0
  17. package/dist/helper/teleswap-helper.d.ts +20 -8
  18. package/dist/helper/teleswap-helper.d.ts.map +1 -1
  19. package/dist/helper/teleswap-helper.js +55 -50
  20. package/dist/helper/teleswap-helper.js.map +1 -1
  21. package/dist/teleport-dao-payments.d.ts +76 -0
  22. package/dist/teleport-dao-payments.d.ts.map +1 -0
  23. package/dist/teleport-dao-payments.js +217 -0
  24. package/dist/teleport-dao-payments.js.map +1 -0
  25. package/dist/teleswap-wallet.d.ts +4 -6
  26. package/dist/teleswap-wallet.d.ts.map +1 -1
  27. package/dist/teleswap-wallet.js +7 -8
  28. package/dist/teleswap-wallet.js.map +1 -1
  29. package/package.json +5 -5
  30. package/src/bitcoin-interface-ordinal.ts +181 -181
  31. package/src/bitcoin-interface-teleswap.ts +252 -255
  32. package/src/bitcoin-interface-utils.ts +59 -59
  33. package/src/bitcoin-interface.ts +247 -247
  34. package/src/bitcoin-utils.ts +591 -591
  35. package/src/bitcoin-wallet-base.ts +314 -314
  36. package/src/helper/brc20-helper.ts +181 -181
  37. package/src/helper/ordinal-helper.ts +118 -118
  38. package/src/helper/teleswap-helper.ts +77 -101
  39. package/src/index.ts +15 -15
  40. package/src/ordinal-wallet.ts +738 -738
  41. package/src/sign/index.ts +1 -1
  42. package/src/sign/sign-transaction.ts +108 -108
  43. package/src/teleswap-wallet.ts +152 -155
  44. package/src/transaction-builder/bitcoin-transaction-builder.ts +44 -44
  45. package/src/transaction-builder/index.ts +3 -3
  46. package/src/transaction-builder/ordinal-transaction-builder.ts +147 -147
  47. package/src/transaction-builder/transaction-builder.ts +705 -705
  48. package/src/type.ts +43 -43
  49. package/src/utils/networks.ts +33 -33
  50. package/src/utils/tools.ts +89 -89
  51. package/tsconfig.json +9 -9
  52. package/webpack.config.js +16 -16
package/src/sign/index.ts CHANGED
@@ -1 +1 @@
1
- export { default as BaseBitcoinSigner } from "./sign-transaction"
1
+ export { default as BaseBitcoinSigner } from "./sign-transaction"
@@ -1,108 +1,108 @@
1
- import { Psbt, crypto, Network } from "bitcoinjs-lib"
2
- // import BIP32Factory from "bip32"
3
- import ecc from "@bitcoinerlab/secp256k1"
4
- import ECPairFactory from "ecpair"
5
-
6
- const ECPair = ECPairFactory(ecc)
7
-
8
- function tapTweakHash(pubKey: Buffer, h?: Buffer) {
9
- return crypto.taggedHash("TapTweak", Buffer.concat(h ? [pubKey, h] : [pubKey]))
10
- }
11
-
12
- function tweakSigner(
13
- privateKey: Buffer,
14
- network: Network,
15
- opts = {} as {
16
- [key: string]: Buffer
17
- },
18
- ) {
19
- let newPrv = privateKey
20
- let keyPair = ECPair.fromPrivateKey(privateKey, {
21
- network,
22
- compressed: true,
23
- })
24
-
25
- if (!keyPair.privateKey) throw new Error("private key not exist")
26
-
27
- if (keyPair.publicKey.toString("hex").startsWith("03")) {
28
- newPrv = ecc.privateNegate(keyPair.privateKey) as Buffer
29
- }
30
-
31
- const tweakedPrivateKey = ecc.privateAdd(
32
- newPrv,
33
- tapTweakHash(Buffer.from(keyPair.publicKey.toString("hex").slice(2), "hex"), opts?.tweakHash),
34
- )
35
- if (!tweakedPrivateKey) {
36
- throw new Error("Invalid tweaked private key!")
37
- }
38
-
39
- return ECPair.fromPrivateKey(Buffer.from(tweakedPrivateKey), {
40
- network,
41
- })
42
- }
43
-
44
- class BitcoinLikeSignTransaction {
45
- network: Network
46
-
47
- constructor(network: Network) {
48
- this.network = network
49
- }
50
-
51
- async signPsbt(
52
- unsignedPsbt: {
53
- unsignedTransaction: string
54
- inputsToSign?: number[]
55
- },
56
- privateKey: Buffer,
57
- sighashTypes?: any[],
58
- usingTweakSignerIfNeeded = true,
59
- ) {
60
- const { network } = this
61
- const keyPair = ECPair.fromPrivateKey(privateKey, {
62
- network,
63
- compressed: true,
64
- })
65
- const psbt = Psbt.fromBase64(unsignedPsbt.unsignedTransaction, {
66
- network,
67
- })
68
-
69
- let numberOfInputs = psbt.inputCount
70
-
71
- for (let i = 0; i < numberOfInputs; i += 1) {
72
- if (unsignedPsbt.inputsToSign && !unsignedPsbt.inputsToSign.includes(i)) {
73
- // eslint-disable-next-line no-continue
74
- continue
75
- }
76
- let type = psbt.getInputType(i)
77
-
78
- if (usingTweakSignerIfNeeded && type === "nonstandard") {
79
- console.log("using tweak signer")
80
- let a = tweakSigner(privateKey, this.network)
81
- await psbt.signInputAsync(i, a, sighashTypes)
82
- } else {
83
- await psbt.signInputAsync(i, keyPair, sighashTypes)
84
- }
85
- }
86
-
87
- // psbt.signAllInputs(keyPair)
88
- const partialSigendPsbt = psbt.toBase64()
89
- return partialSigendPsbt
90
- }
91
-
92
- finalizePsbts(psbtsBase64: string[] = []) {
93
- const finals = psbtsBase64.map((psbtBase64) =>
94
- Psbt.fromBase64(psbtBase64, { network: this.network }),
95
- )
96
- const psbt =
97
- finals.length === 1 ? finals[0] : new Psbt({ network: this.network }).combine(...finals)
98
-
99
- psbt.finalizeAllInputs()
100
-
101
- let finalizeTx = psbt.extractTransaction()
102
- // const rawTx = finalizeTx.toBuffer()
103
- // const hex = rawTx.toString("hex")
104
- return finalizeTx.toHex()
105
- }
106
- }
107
-
108
- export default BitcoinLikeSignTransaction
1
+ import { Psbt, crypto, Network } from "bitcoinjs-lib"
2
+ // import BIP32Factory from "bip32"
3
+ import ecc from "@bitcoinerlab/secp256k1"
4
+ import ECPairFactory from "ecpair"
5
+
6
+ const ECPair = ECPairFactory(ecc)
7
+
8
+ function tapTweakHash(pubKey: Buffer, h?: Buffer) {
9
+ return crypto.taggedHash("TapTweak", Buffer.concat(h ? [pubKey, h] : [pubKey]))
10
+ }
11
+
12
+ function tweakSigner(
13
+ privateKey: Buffer,
14
+ network: Network,
15
+ opts = {} as {
16
+ [key: string]: Buffer
17
+ },
18
+ ) {
19
+ let newPrv = privateKey
20
+ let keyPair = ECPair.fromPrivateKey(privateKey, {
21
+ network,
22
+ compressed: true,
23
+ })
24
+
25
+ if (!keyPair.privateKey) throw new Error("private key not exist")
26
+
27
+ if (keyPair.publicKey.toString("hex").startsWith("03")) {
28
+ newPrv = ecc.privateNegate(keyPair.privateKey) as Buffer
29
+ }
30
+
31
+ const tweakedPrivateKey = ecc.privateAdd(
32
+ newPrv,
33
+ tapTweakHash(Buffer.from(keyPair.publicKey.toString("hex").slice(2), "hex"), opts?.tweakHash),
34
+ )
35
+ if (!tweakedPrivateKey) {
36
+ throw new Error("Invalid tweaked private key!")
37
+ }
38
+
39
+ return ECPair.fromPrivateKey(Buffer.from(tweakedPrivateKey), {
40
+ network,
41
+ })
42
+ }
43
+
44
+ class BitcoinLikeSignTransaction {
45
+ network: Network
46
+
47
+ constructor(network: Network) {
48
+ this.network = network
49
+ }
50
+
51
+ async signPsbt(
52
+ unsignedPsbt: {
53
+ unsignedTransaction: string
54
+ inputsToSign?: number[]
55
+ },
56
+ privateKey: Buffer,
57
+ sighashTypes?: any[],
58
+ usingTweakSignerIfNeeded = true,
59
+ ) {
60
+ const { network } = this
61
+ const keyPair = ECPair.fromPrivateKey(privateKey, {
62
+ network,
63
+ compressed: true,
64
+ })
65
+ const psbt = Psbt.fromBase64(unsignedPsbt.unsignedTransaction, {
66
+ network,
67
+ })
68
+
69
+ let numberOfInputs = psbt.inputCount
70
+
71
+ for (let i = 0; i < numberOfInputs; i += 1) {
72
+ if (unsignedPsbt.inputsToSign && !unsignedPsbt.inputsToSign.includes(i)) {
73
+ // eslint-disable-next-line no-continue
74
+ continue
75
+ }
76
+ let type = psbt.getInputType(i)
77
+
78
+ if (usingTweakSignerIfNeeded && type === "nonstandard") {
79
+ console.log("using tweak signer")
80
+ let a = tweakSigner(privateKey, this.network)
81
+ await psbt.signInputAsync(i, a, sighashTypes)
82
+ } else {
83
+ await psbt.signInputAsync(i, keyPair, sighashTypes)
84
+ }
85
+ }
86
+
87
+ // psbt.signAllInputs(keyPair)
88
+ const partialSigendPsbt = psbt.toBase64()
89
+ return partialSigendPsbt
90
+ }
91
+
92
+ finalizePsbts(psbtsBase64: string[] = []) {
93
+ const finals = psbtsBase64.map((psbtBase64) =>
94
+ Psbt.fromBase64(psbtBase64, { network: this.network }),
95
+ )
96
+ const psbt =
97
+ finals.length === 1 ? finals[0] : new Psbt({ network: this.network }).combine(...finals)
98
+
99
+ psbt.finalizeAllInputs()
100
+
101
+ let finalizeTx = psbt.extractTransaction()
102
+ // const rawTx = finalizeTx.toBuffer()
103
+ // const hex = rawTx.toString("hex")
104
+ return finalizeTx.toHex()
105
+ }
106
+ }
107
+
108
+ export default BitcoinLikeSignTransaction
@@ -1,155 +1,152 @@
1
- import type {
2
- ExtendedUtxo,
3
- SignerInfo,
4
- TargetAddress,
5
- } from "./transaction-builder/transaction-builder"
6
- import { BitcoinBaseWallet } from "./bitcoin-wallet-base"
7
- import { generateWrapOpReturn } from "./helper/teleswap-helper"
8
-
9
- export type TransferRequest = {
10
- changeAddress?: string
11
- lockerAddress: string
12
- amount: number
13
- fullAmount?: boolean
14
- //-----------
15
- chainId: number
16
- appId: number
17
- recipientAddress: string // 20 bytes
18
- percentageFee: number // 2 bytes in satoshi
19
- speed?: number | boolean // 1 byte
20
- isExchange?: boolean
21
- exchangeTokenAddress?: string // 20 bytes
22
- outputAmount?: number // 28 bytes
23
- deadline?: number // 4 bytes
24
- isFixedToken?: boolean // 1 byte
25
- feeSpeed?: "normal" | "fast" | "slow"
26
- staticFeeRate?: number
27
- }
28
-
29
- export class TeleswapWallet extends BitcoinBaseWallet {
30
- // payment
31
- async sendToMultipleAddress(
32
- receivers: TargetAddress[],
33
- feeSpeed: "normal" | "fast" | "slow" = "normal",
34
- ) {
35
- if (!this.signerInfo || !this.privateKey) {
36
- throw new Error("account not initialized")
37
- }
38
- let extendedUtxo = await this.getExtendedUtxo(this.signerInfo)
39
- let feeRate = await this.transactionBuilder._getFeeRate(feeSpeed)
40
- let unsignedTx = await this.transactionBuilder.processUnsignedTransaction({
41
- extendedUtxo,
42
- targets: receivers,
43
- changeAddress: this.currentAccount,
44
- feeRate,
45
- fullAmount: false,
46
- })
47
- let signedPsbt = await this.signer.signPsbt(unsignedTx, this.privateKey)
48
- let signedTx = this.signer.finalizePsbts([signedPsbt])
49
- let txId = await this.transactionBuilder.sendTx(signedTx)
50
- return txId
51
- }
52
-
53
- // send
54
-
55
- async wrapUnsigned(
56
- recipientAddress: string,
57
- amount: number,
58
- percentageFee: number,
59
- signer: SignerInfo,
60
- lockerAddress: string,
61
- exchange?: {
62
- outputToken: string
63
- outputAmount: string
64
- deadline: string
65
- isFixedToken?: boolean
66
- },
67
- {
68
- chainId = 137, // 80001
69
- appId = exchange ? 1 : 0,
70
- } = {},
71
- fullAmount = false,
72
- staticExtendedUtxo?: ExtendedUtxo[],
73
- staticFeeRate?: number,
74
- changeAddress?: string,
75
- ) {
76
- const dataHex = generateWrapOpReturn({
77
- chainId,
78
- appId,
79
- recipientAddress,
80
- percentageFee,
81
- speed: false,
82
- isExchange: !!exchange,
83
- outputAmount: exchange?.outputAmount,
84
- outputToken: exchange?.outputToken,
85
- deadline: exchange?.deadline,
86
- isFixedToken: exchange?.isFixedToken || false,
87
- })
88
- let extendedUtxo = staticExtendedUtxo || (await this.getExtendedUtxo(signer))
89
- let feeRate = staticFeeRate || (await this.transactionBuilder._getFeeRate("normal"))
90
-
91
- const targets = fullAmount
92
- ? [this.transactionBuilder.getOpReturnTarget(dataHex)]
93
- : [
94
- {
95
- address: lockerAddress,
96
- value: amount,
97
- },
98
- this.transactionBuilder.getOpReturnTarget(dataHex),
99
- ]
100
-
101
- const unsignedTx = this.transactionBuilder.processUnsignedTransaction({
102
- extendedUtxo,
103
- feeRate,
104
- targets,
105
- changeAddress: changeAddress || signer.address,
106
- fullAmount,
107
- })
108
-
109
- return unsignedTx
110
- }
111
-
112
- async wrap(
113
- recipientAddress: string,
114
- amount: number,
115
- percentageFee: number,
116
- lockerAddress: string,
117
- exchange?: {
118
- outputToken: string
119
- outputAmount: string
120
- deadline: string
121
- isFixedToken?: boolean
122
- },
123
- {
124
- chainId = 137, // 80001
125
- appId = exchange ? 1 : 0,
126
- } = {},
127
- fullAmount = false,
128
- staticExtendedUtxo?: ExtendedUtxo[],
129
- staticFeeRate?: number,
130
- changeAddress?: string,
131
- ) {
132
- if (!this.signerInfo || !this.privateKey) {
133
- throw new Error("account not initialized")
134
- }
135
- let unsignedTransaction = await this.wrapUnsigned(
136
- recipientAddress,
137
- amount,
138
- percentageFee,
139
- this.signerInfo,
140
- lockerAddress,
141
- exchange,
142
- {
143
- chainId,
144
- appId,
145
- },
146
- fullAmount,
147
- staticExtendedUtxo,
148
- staticFeeRate,
149
- changeAddress,
150
- )
151
- let signedPsbt = await this.signer.signPsbt(unsignedTransaction, this.privateKey)
152
- return this.sendSignedPsbt(signedPsbt)
153
- }
154
- }
155
- export default TeleswapWallet
1
+ import type {
2
+ ExtendedUtxo,
3
+ SignerInfo,
4
+ TargetAddress,
5
+ } from "./transaction-builder/transaction-builder"
6
+ import { BitcoinBaseWallet } from "./bitcoin-wallet-base"
7
+ import { generateWrapOpReturn } from "./helper/teleswap-helper"
8
+
9
+ export type TransferRequest = {
10
+ changeAddress?: string
11
+ lockerAddress: string
12
+ amount: number
13
+ fullAmount?: boolean
14
+ //-----------
15
+ chainId: number
16
+ appId: number
17
+ recipientAddress: string // 20 bytes
18
+ percentageFee: number // 2 bytes in satoshi
19
+ speed?: number | boolean // 1 byte
20
+ isExchange?: boolean
21
+ exchangeTokenAddress?: string // 20 bytes
22
+ outputAmount?: number // 28 bytes
23
+ deadline?: number // 4 bytes
24
+ isFixedToken?: boolean // 1 byte
25
+ feeSpeed?: "normal" | "fast" | "slow"
26
+ staticFeeRate?: number
27
+ }
28
+
29
+ export class TeleswapWallet extends BitcoinBaseWallet {
30
+ // payment
31
+ async sendToMultipleAddress(
32
+ receivers: TargetAddress[],
33
+ feeSpeed: "normal" | "fast" | "slow" = "normal",
34
+ ) {
35
+ if (!this.signerInfo || !this.privateKey) {
36
+ throw new Error("account not initialized")
37
+ }
38
+ let extendedUtxo = await this.getExtendedUtxo(this.signerInfo)
39
+ let feeRate = await this.transactionBuilder._getFeeRate(feeSpeed)
40
+ let unsignedTx = await this.transactionBuilder.processUnsignedTransaction({
41
+ extendedUtxo,
42
+ targets: receivers,
43
+ changeAddress: this.currentAccount,
44
+ feeRate,
45
+ fullAmount: false,
46
+ })
47
+ let signedPsbt = await this.signer.signPsbt(unsignedTx, this.privateKey)
48
+ let signedTx = this.signer.finalizePsbts([signedPsbt])
49
+ let txId = await this.transactionBuilder.sendTx(signedTx)
50
+ return txId
51
+ }
52
+
53
+ // send
54
+
55
+ async wrapUnsigned(
56
+ recipientAddress: string,
57
+ amount: string,
58
+ networkFee: string,
59
+ signer: SignerInfo,
60
+ lockerAddress: string,
61
+ exchange?: {
62
+ outputToken: string
63
+ outputAmount: string
64
+ bridgePercentageFee?: number
65
+ },
66
+ {
67
+ chainId = 137, // 80001
68
+ appId = exchange ? 1 : 0,
69
+ } = {},
70
+ fullAmount = false,
71
+ staticExtendedUtxo?: ExtendedUtxo[],
72
+ staticFeeRate?: number,
73
+ changeAddress?: string,
74
+ ) {
75
+ const dataHex = generateWrapOpReturn({
76
+ chainId,
77
+ appId,
78
+ recipientAddress,
79
+ networkFee,
80
+ speed: false,
81
+ isExchange: !!exchange,
82
+ outputAmount: exchange?.outputAmount,
83
+ outputToken: exchange?.outputToken,
84
+ bridgePercentageFee: exchange?.bridgePercentageFee,
85
+ })
86
+ let extendedUtxo = staticExtendedUtxo || (await this.getExtendedUtxo(signer))
87
+ let feeRate = staticFeeRate || (await this.btcInterface.getFeeRate("normal"))
88
+
89
+ const targets = fullAmount
90
+ ? [this.transactionBuilder.getOpReturnTarget(dataHex)]
91
+ : [
92
+ {
93
+ address: lockerAddress,
94
+ value: +amount,
95
+ },
96
+ this.transactionBuilder.getOpReturnTarget(dataHex),
97
+ ]
98
+
99
+ const unsignedTx = this.transactionBuilder.processUnsignedTransaction({
100
+ extendedUtxo,
101
+ feeRate,
102
+ targets,
103
+ changeAddress: changeAddress || signer.address,
104
+ fullAmount,
105
+ })
106
+
107
+ return unsignedTx
108
+ }
109
+
110
+ async wrap(
111
+ recipientAddress: string,
112
+ amount: string,
113
+ networkFee: string,
114
+ lockerAddress: string,
115
+ exchange?: {
116
+ outputToken: string
117
+ outputAmount: string
118
+ bridgePercentageFee?: number
119
+ },
120
+ {
121
+ chainId = 137, // 80001
122
+ appId = exchange ? 1 : 0,
123
+ } = {},
124
+ fullAmount = false,
125
+ staticExtendedUtxo?: ExtendedUtxo[],
126
+ staticFeeRate?: number,
127
+ changeAddress?: string,
128
+ ) {
129
+ if (!this.signerInfo || !this.privateKey) {
130
+ throw new Error("account not initialized")
131
+ }
132
+ let unsignedTransaction = await this.wrapUnsigned(
133
+ recipientAddress,
134
+ amount,
135
+ networkFee,
136
+ this.signerInfo,
137
+ lockerAddress,
138
+ exchange,
139
+ {
140
+ chainId,
141
+ appId,
142
+ },
143
+ fullAmount,
144
+ staticExtendedUtxo,
145
+ staticFeeRate,
146
+ changeAddress,
147
+ )
148
+ let signedPsbt = await this.signer.signPsbt(unsignedTransaction, this.privateKey)
149
+ return this.sendSignedPsbt(signedPsbt)
150
+ }
151
+ }
152
+ export default TeleswapWallet
@@ -1,44 +1,44 @@
1
- import { BaseTransactionBuilder } from "./transaction-builder"
2
- import { BitcoinInterface } from "../bitcoin-interface"
3
- import * as bitcoin from "bitcoinjs-lib"
4
- import { BitcoinConnectionInfo } from "../type"
5
-
6
- export class BitcoinTransactionBuilder extends BaseTransactionBuilder {
7
- btcInterface: BitcoinInterface
8
- constructor(
9
- connectionInfo: BitcoinConnectionInfo,
10
- networkName: string,
11
- network = bitcoin.networks.bitcoin,
12
- ) {
13
- super({
14
- network,
15
- testnet: networkName?.includes("_testnet"),
16
- dustLimit: 1000,
17
- })
18
- this.btcInterface = new BitcoinInterface(connectionInfo, networkName)
19
- }
20
-
21
- async _getUtxo(userAddress: string) {
22
- let utxos = await this.btcInterface.getUtxo(userAddress)
23
- return utxos.map((tx) => ({
24
- hash: tx.txId as string,
25
- value: +tx.value,
26
- index: +tx.index,
27
- }))
28
- }
29
-
30
- async _getFeeRate(speed: "normal" | "slow" | "fast" = "normal") {
31
- return this.btcInterface.getFeeRate(speed)
32
- }
33
-
34
- async _getTransactionHex(transactionId: string): Promise<string> {
35
- return this.btcInterface.getRawTransaction(transactionId)
36
- }
37
-
38
- async sendTx(txHex: string): Promise<string> {
39
- let txId = await (
40
- this.btcInterface.rpcProvider || this.btcInterface.apiProvider
41
- ).sendRawTransaction(txHex)
42
- return txId
43
- }
44
- }
1
+ import { BaseTransactionBuilder } from "./transaction-builder"
2
+ import { BitcoinInterface } from "../bitcoin-interface"
3
+ import * as bitcoin from "bitcoinjs-lib"
4
+ import { BitcoinConnectionInfo } from "../type"
5
+
6
+ export class BitcoinTransactionBuilder extends BaseTransactionBuilder {
7
+ btcInterface: BitcoinInterface
8
+ constructor(
9
+ connectionInfo: BitcoinConnectionInfo,
10
+ networkName: string,
11
+ network = bitcoin.networks.bitcoin,
12
+ ) {
13
+ super({
14
+ network,
15
+ testnet: networkName?.includes("_testnet"),
16
+ dustLimit: 1000,
17
+ })
18
+ this.btcInterface = new BitcoinInterface(connectionInfo, networkName)
19
+ }
20
+
21
+ async _getUtxo(userAddress: string) {
22
+ let utxos = await this.btcInterface.getUtxo(userAddress)
23
+ return utxos.map((tx) => ({
24
+ hash: tx.txId as string,
25
+ value: +tx.value,
26
+ index: +tx.index,
27
+ }))
28
+ }
29
+
30
+ async _getFeeRate(speed: "normal" | "slow" | "fast" = "normal") {
31
+ return this.btcInterface.getFeeRate(speed)
32
+ }
33
+
34
+ async _getTransactionHex(transactionId: string): Promise<string> {
35
+ return this.btcInterface.getRawTransaction(transactionId)
36
+ }
37
+
38
+ async sendTx(txHex: string): Promise<string> {
39
+ let txId = await (
40
+ this.btcInterface.rpcProvider || this.btcInterface.apiProvider
41
+ ).sendRawTransaction(txHex)
42
+ return txId
43
+ }
44
+ }
@@ -1,3 +1,3 @@
1
- export * from "./bitcoin-transaction-builder"
2
- export * from "./ordinal-transaction-builder"
3
- export * from "./transaction-builder"
1
+ export * from "./bitcoin-transaction-builder"
2
+ export * from "./ordinal-transaction-builder"
3
+ export * from "./transaction-builder"