@teleportdao/bitcoin 1.7.12 → 1.7.14

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 (51) 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-utils.d.ts.map +1 -1
  6. package/dist/bitcoin-interface-utils.js +2 -1
  7. package/dist/bitcoin-interface-utils.js.map +1 -1
  8. package/dist/helper/burn-request-helper.d.ts +7 -0
  9. package/dist/helper/burn-request-helper.d.ts.map +1 -0
  10. package/dist/helper/burn-request-helper.js +26 -0
  11. package/dist/helper/burn-request-helper.js.map +1 -0
  12. package/dist/helper/teleport-request-helper.d.ts +47 -0
  13. package/dist/helper/teleport-request-helper.d.ts.map +1 -0
  14. package/dist/helper/teleport-request-helper.js +146 -0
  15. package/dist/helper/teleport-request-helper.js.map +1 -0
  16. package/dist/helper/teleswap-helper.d.ts.map +1 -1
  17. package/dist/helper/teleswap-helper.js +1 -2
  18. package/dist/helper/teleswap-helper.js.map +1 -1
  19. package/dist/teleport-dao-payments.d.ts +76 -0
  20. package/dist/teleport-dao-payments.d.ts.map +1 -0
  21. package/dist/teleport-dao-payments.js +217 -0
  22. package/dist/teleport-dao-payments.js.map +1 -0
  23. package/dist/teleswap-wallet.d.ts.map +1 -1
  24. package/dist/teleswap-wallet.js +4 -1
  25. package/dist/teleswap-wallet.js.map +1 -1
  26. package/dist/utils/tools.d.ts.map +1 -1
  27. package/dist/utils/tools.js.map +1 -1
  28. package/package.json +4 -4
  29. package/src/bitcoin-interface-ordinal.ts +181 -181
  30. package/src/bitcoin-interface-teleswap.ts +252 -252
  31. package/src/bitcoin-interface-utils.ts +60 -59
  32. package/src/bitcoin-interface.ts +247 -247
  33. package/src/bitcoin-utils.ts +591 -591
  34. package/src/bitcoin-wallet-base.ts +310 -310
  35. package/src/helper/brc20-helper.ts +181 -181
  36. package/src/helper/ordinal-helper.ts +118 -118
  37. package/src/helper/teleswap-helper.ts +2 -4
  38. package/src/index.ts +15 -15
  39. package/src/ordinal-wallet.ts +738 -738
  40. package/src/sign/index.ts +1 -1
  41. package/src/sign/sign-transaction.ts +108 -108
  42. package/src/teleswap-wallet.ts +155 -152
  43. package/src/transaction-builder/bitcoin-transaction-builder.ts +44 -44
  44. package/src/transaction-builder/index.ts +3 -3
  45. package/src/transaction-builder/ordinal-transaction-builder.ts +147 -147
  46. package/src/transaction-builder/transaction-builder.ts +706 -706
  47. package/src/type.ts +43 -43
  48. package/src/utils/networks.ts +33 -33
  49. package/src/utils/tools.ts +90 -89
  50. package/tsconfig.json +9 -9
  51. 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,152 +1,155 @@
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
+ import { teleswap } from "@teleportdao/configs"
2
+ import type {
3
+ ExtendedUtxo,
4
+ SignerInfo,
5
+ TargetAddress,
6
+ } from "./transaction-builder/transaction-builder"
7
+ import { BitcoinBaseWallet } from "./bitcoin-wallet-base"
8
+ import { generateWrapOpReturn } from "./helper/teleswap-helper"
9
+
10
+ export type TransferRequest = {
11
+ changeAddress?: string
12
+ lockerAddress: string
13
+ amount: number
14
+ fullAmount?: boolean
15
+ //-----------
16
+ chainId: number
17
+ appId: number
18
+ recipientAddress: string // 20 bytes
19
+ percentageFee: number // 2 bytes in satoshi
20
+ speed?: number | boolean // 1 byte
21
+ isExchange?: boolean
22
+ exchangeTokenAddress?: string // 20 bytes
23
+ outputAmount?: number // 28 bytes
24
+ deadline?: number // 4 bytes
25
+ isFixedToken?: boolean // 1 byte
26
+ feeSpeed?: "normal" | "fast" | "slow"
27
+ staticFeeRate?: number
28
+ }
29
+
30
+ export class TeleswapWallet extends BitcoinBaseWallet {
31
+ // payment
32
+ async sendToMultipleAddress(
33
+ receivers: TargetAddress[],
34
+ feeSpeed: "normal" | "fast" | "slow" = "normal",
35
+ ) {
36
+ if (!this.signerInfo || !this.privateKey) {
37
+ throw new Error("account not initialized")
38
+ }
39
+ let extendedUtxo = await this.getExtendedUtxo(this.signerInfo)
40
+ let feeRate = await this.transactionBuilder._getFeeRate(feeSpeed)
41
+ let unsignedTx = await this.transactionBuilder.processUnsignedTransaction({
42
+ extendedUtxo,
43
+ targets: receivers,
44
+ changeAddress: this.currentAccount,
45
+ feeRate,
46
+ fullAmount: false,
47
+ })
48
+ let signedPsbt = await this.signer.signPsbt(unsignedTx, this.privateKey)
49
+ let signedTx = this.signer.finalizePsbts([signedPsbt])
50
+ let txId = await this.transactionBuilder.sendTx(signedTx)
51
+ return txId
52
+ }
53
+
54
+ // send
55
+
56
+ async wrapUnsigned(
57
+ recipientAddress: string,
58
+ amount: string,
59
+ networkFee: string,
60
+ signer: SignerInfo,
61
+ lockerAddress: string,
62
+ exchange?: {
63
+ outputToken: string
64
+ outputAmount: string
65
+ bridgePercentageFee?: number
66
+ },
67
+ {
68
+ chainId = 137, // 80001
69
+ appId = exchange
70
+ ? teleswap.requestAppId.WrapAndSwap.default
71
+ : teleswap.requestAppId.Wrap.default,
72
+ } = {},
73
+ fullAmount = false,
74
+ staticExtendedUtxo?: ExtendedUtxo[],
75
+ staticFeeRate?: number,
76
+ changeAddress?: string,
77
+ ) {
78
+ const dataHex = generateWrapOpReturn({
79
+ chainId,
80
+ appId,
81
+ recipientAddress,
82
+ networkFee,
83
+ speed: false,
84
+ isExchange: !!exchange,
85
+ outputAmount: exchange?.outputAmount,
86
+ outputToken: exchange?.outputToken,
87
+ bridgePercentageFee: exchange?.bridgePercentageFee,
88
+ })
89
+ let extendedUtxo = staticExtendedUtxo || (await this.getExtendedUtxo(signer))
90
+ let feeRate = staticFeeRate || (await this.btcInterface.getFeeRate("normal"))
91
+
92
+ const targets = fullAmount
93
+ ? [this.transactionBuilder.getOpReturnTarget(dataHex)]
94
+ : [
95
+ {
96
+ address: lockerAddress,
97
+ value: +amount,
98
+ },
99
+ this.transactionBuilder.getOpReturnTarget(dataHex),
100
+ ]
101
+
102
+ const unsignedTx = this.transactionBuilder.processUnsignedTransaction({
103
+ extendedUtxo,
104
+ feeRate,
105
+ targets,
106
+ changeAddress: changeAddress || signer.address,
107
+ fullAmount,
108
+ })
109
+
110
+ return unsignedTx
111
+ }
112
+
113
+ async wrap(
114
+ recipientAddress: string,
115
+ amount: string,
116
+ networkFee: string,
117
+ lockerAddress: string,
118
+ exchange?: {
119
+ outputToken: string
120
+ outputAmount: string
121
+ bridgePercentageFee?: number
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
+ networkFee,
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,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"