@teleportdao/bitcoin 1.6.0 → 1.7.0

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 (129) hide show
  1. package/.tmp/psbt/sign-transaction.ts +9 -3
  2. package/dist/bitcoin-interface-ordinal.d.ts +104 -0
  3. package/dist/bitcoin-interface-ordinal.d.ts.map +1 -0
  4. package/dist/bitcoin-interface-ordinal.js +113 -0
  5. package/dist/bitcoin-interface-ordinal.js.map +1 -0
  6. package/dist/bitcoin-interface-teleswap.d.ts +148 -0
  7. package/dist/bitcoin-interface-teleswap.d.ts.map +1 -0
  8. package/dist/bitcoin-interface-teleswap.js +179 -0
  9. package/dist/bitcoin-interface-teleswap.js.map +1 -0
  10. package/dist/bitcoin-interface.d.ts +45 -333
  11. package/dist/bitcoin-interface.d.ts.map +1 -1
  12. package/dist/bitcoin-interface.js +68 -202
  13. package/dist/bitcoin-interface.js.map +1 -1
  14. package/dist/bitcoin-utils.d.ts +6 -53
  15. package/dist/bitcoin-utils.d.ts.map +1 -1
  16. package/dist/bitcoin-utils.js +4 -4
  17. package/dist/bitcoin-utils.js.map +1 -1
  18. package/dist/{bitcoin-base.d.ts → bitcoin-wallet-base.d.ts} +8 -8
  19. package/dist/bitcoin-wallet-base.d.ts.map +1 -0
  20. package/dist/{bitcoin-base.js → bitcoin-wallet-base.js} +12 -11
  21. package/dist/bitcoin-wallet-base.js.map +1 -0
  22. package/dist/helper/brc20-helper.d.ts +43 -0
  23. package/dist/helper/brc20-helper.d.ts.map +1 -0
  24. package/dist/helper/brc20-helper.js +129 -0
  25. package/dist/helper/brc20-helper.js.map +1 -0
  26. package/dist/helper/index.d.ts +4 -0
  27. package/dist/helper/index.d.ts.map +1 -0
  28. package/dist/helper/index.js +30 -0
  29. package/dist/helper/index.js.map +1 -0
  30. package/dist/helper/ordinal-helper.d.ts +13 -0
  31. package/dist/helper/ordinal-helper.d.ts.map +1 -0
  32. package/dist/helper/ordinal-helper.js +127 -0
  33. package/dist/helper/ordinal-helper.js.map +1 -0
  34. package/dist/helper/teleswap-helper.d.ts +84 -0
  35. package/dist/helper/teleswap-helper.d.ts.map +1 -0
  36. package/dist/helper/teleswap-helper.js +181 -0
  37. package/dist/helper/teleswap-helper.js.map +1 -0
  38. package/dist/index.d.ts +10 -3
  39. package/dist/index.d.ts.map +1 -1
  40. package/dist/index.js +10 -3
  41. package/dist/index.js.map +1 -1
  42. package/dist/ordinal-wallet.d.ts +536 -0
  43. package/dist/ordinal-wallet.d.ts.map +1 -0
  44. package/dist/ordinal-wallet.js +446 -0
  45. package/dist/ordinal-wallet.js.map +1 -0
  46. package/dist/sign/index.d.ts +2 -0
  47. package/dist/sign/index.d.ts.map +1 -0
  48. package/dist/sign/index.js +9 -0
  49. package/dist/sign/index.js.map +1 -0
  50. package/dist/sign/sign-transaction.d.ts +2 -1
  51. package/dist/sign/sign-transaction.d.ts.map +1 -1
  52. package/dist/sign/sign-transaction.js +14 -33
  53. package/dist/sign/sign-transaction.js.map +1 -1
  54. package/dist/teleswap-wallet.d.ts +54 -0
  55. package/dist/teleswap-wallet.d.ts.map +1 -0
  56. package/dist/teleswap-wallet.js +87 -0
  57. package/dist/teleswap-wallet.js.map +1 -0
  58. package/dist/transaction-builder/bitcoin-transaction-builder.d.ts +3 -21
  59. package/dist/transaction-builder/bitcoin-transaction-builder.d.ts.map +1 -1
  60. package/dist/transaction-builder/bitcoin-transaction-builder.js +7 -9
  61. package/dist/transaction-builder/bitcoin-transaction-builder.js.map +1 -1
  62. package/dist/transaction-builder/index.d.ts +4 -0
  63. package/dist/transaction-builder/index.d.ts.map +1 -0
  64. package/dist/transaction-builder/index.js +20 -0
  65. package/dist/transaction-builder/index.js.map +1 -0
  66. package/dist/transaction-builder/ordinal-transaction-builder.d.ts +63 -0
  67. package/dist/transaction-builder/ordinal-transaction-builder.d.ts.map +1 -0
  68. package/dist/transaction-builder/ordinal-transaction-builder.js +131 -0
  69. package/dist/transaction-builder/ordinal-transaction-builder.js.map +1 -0
  70. package/dist/transaction-builder/transaction-builder.d.ts +32 -5
  71. package/dist/transaction-builder/transaction-builder.d.ts.map +1 -1
  72. package/dist/transaction-builder/transaction-builder.js +65 -49
  73. package/dist/transaction-builder/transaction-builder.js.map +1 -1
  74. package/dist/type.d.ts +43 -0
  75. package/dist/type.d.ts.map +1 -0
  76. package/dist/type.js +3 -0
  77. package/dist/type.js.map +1 -0
  78. package/dist/utils/tools.d.ts +4 -4
  79. package/dist/utils/tools.d.ts.map +1 -1
  80. package/dist/utils/tools.js +8 -5
  81. package/dist/utils/tools.js.map +1 -1
  82. package/package.json +6 -8
  83. package/src/bitcoin-interface-ordinal.ts +128 -0
  84. package/src/bitcoin-interface-teleswap.ts +255 -0
  85. package/src/bitcoin-interface.ts +99 -303
  86. package/src/bitcoin-utils.ts +6 -32
  87. package/src/{bitcoin-base.ts → bitcoin-wallet-base.ts} +20 -14
  88. package/src/helper/brc20-helper.ts +181 -0
  89. package/src/helper/index.ts +3 -0
  90. package/src/helper/ordinal-helper.ts +118 -0
  91. package/src/helper/teleswap-helper.ts +300 -0
  92. package/src/index.ts +13 -3
  93. package/src/ordinal-wallet.ts +738 -0
  94. package/src/sign/index.ts +1 -0
  95. package/src/sign/sign-transaction.ts +20 -9
  96. package/src/teleswap-wallet.ts +155 -0
  97. package/src/transaction-builder/bitcoin-transaction-builder.ts +8 -25
  98. package/src/transaction-builder/index.ts +3 -0
  99. package/src/transaction-builder/ordinal-transaction-builder.ts +147 -0
  100. package/src/transaction-builder/transaction-builder.ts +117 -60
  101. package/src/type.ts +43 -0
  102. package/src/utils/tools.ts +17 -11
  103. package/tsconfig.json +1 -2
  104. package/dist/bitcoin-base.d.ts.map +0 -1
  105. package/dist/bitcoin-base.js.map +0 -1
  106. package/dist/bitcoin-utils-2.d.ts +0 -2
  107. package/dist/bitcoin-utils-2.d.ts.map +0 -1
  108. package/dist/bitcoin-utils-2.js +0 -13
  109. package/dist/bitcoin-utils-2.js.map +0 -1
  110. package/dist/bundle.js +0 -17
  111. package/dist/helper/burn-request-helper.d.ts +0 -7
  112. package/dist/helper/burn-request-helper.d.ts.map +0 -1
  113. package/dist/helper/burn-request-helper.js +0 -26
  114. package/dist/helper/burn-request-helper.js.map +0 -1
  115. package/dist/helper/teleport-request-helper.d.ts +0 -47
  116. package/dist/helper/teleport-request-helper.d.ts.map +0 -1
  117. package/dist/helper/teleport-request-helper.js +0 -146
  118. package/dist/helper/teleport-request-helper.js.map +0 -1
  119. package/dist/mempool-space.d.ts +0 -69
  120. package/dist/mempool-space.d.ts.map +0 -1
  121. package/dist/mempool-space.js +0 -266
  122. package/dist/mempool-space.js.map +0 -1
  123. package/dist/teleport-dao-payments.d.ts +0 -76
  124. package/dist/teleport-dao-payments.d.ts.map +0 -1
  125. package/dist/teleport-dao-payments.js +0 -217
  126. package/dist/teleport-dao-payments.js.map +0 -1
  127. package/src/helper/burn-request-helper.js +0 -27
  128. package/src/helper/teleport-request-helper.js +0 -181
  129. package/src/teleport-dao-payments.ts +0 -347
@@ -0,0 +1,255 @@
1
+ import { bitcoin } from "@teleportdao/providers"
2
+ import { parseBlockHeader } from "./bitcoin-utils"
3
+ import {
4
+ checkAndParseWrapRequest,
5
+ getBurnTransactionInfo,
6
+ UnwrapInfo,
7
+ WrapOpReturnWithType,
8
+ } from "./helper/teleswap-helper"
9
+ import BitcoinInterface from "./bitcoin-interface"
10
+ import { Transaction } from "./type"
11
+
12
+ export type ValidWrapRequest = {
13
+ transaction: bitcoin.Types.ConfirmedTransaction & {
14
+ address?: string
15
+ addressScript?: string
16
+ merkleProof?: Transaction["merkleProof"]
17
+ }
18
+ request: {
19
+ status: boolean
20
+ data: WrapOpReturnWithType
21
+ value: number
22
+ valueOutputIndex: number
23
+ }
24
+ lockerAddress: string
25
+ lockerLockingScript: string
26
+ }
27
+
28
+ export type InValidWrapRequest = {
29
+ transaction: bitcoin.Types.ConfirmedTransaction & {
30
+ address?: string
31
+ addressScript?: string
32
+ merkleProof?: Transaction["merkleProof"]
33
+ }
34
+ request: {
35
+ status: boolean
36
+ message: string
37
+ code: string
38
+ }
39
+ lockerAddress: string
40
+ lockerLockingScript: string
41
+ }
42
+
43
+ export type UnwrapRequest = {
44
+ burnInfo: UnwrapInfo | undefined
45
+ lockerAddress: string
46
+ lockerLockingScript: string
47
+ }
48
+
49
+ export class BitcoinInterfaceTeleswap extends BitcoinInterface {
50
+ // relayer
51
+ async getHexBlockHeaders(startBlockNumber: number, endBlockNumber: number) {
52
+ const blockHeaders = []
53
+ let difficulty = null
54
+ let hexBlockHeaders = ""
55
+
56
+ let fromBlockNumber = startBlockNumber
57
+ for (let blockNumber = startBlockNumber; blockNumber <= endBlockNumber; blockNumber += 1) {
58
+ let blockHeader = await this.getBlockHeaderHex(blockNumber)
59
+ console.log("block", blockNumber)
60
+ let parsedBlockHeader = parseBlockHeader(blockHeader)
61
+ if (difficulty && parsedBlockHeader.difficulty !== difficulty) {
62
+ blockHeaders.push({
63
+ hexBlockHeaders,
64
+ fromBlockNumber,
65
+ toBlockNumber: blockNumber - 1,
66
+ difficulty,
67
+ })
68
+ hexBlockHeaders = blockHeader
69
+ fromBlockNumber = blockNumber
70
+ } else {
71
+ hexBlockHeaders += blockHeader
72
+ }
73
+ difficulty = parsedBlockHeader.difficulty
74
+ }
75
+ if (hexBlockHeaders) {
76
+ blockHeaders.push({
77
+ hexBlockHeaders,
78
+ fromBlockNumber,
79
+ toBlockNumber: endBlockNumber,
80
+ difficulty,
81
+ })
82
+ }
83
+
84
+ return blockHeaders
85
+ }
86
+
87
+ async getWrapRequests(addresses: string[], startblockNumber: number, endBlockNumber: number) {
88
+ // transaction in StartBlock is not returned --> (startblockNumber,endBlockNumber]
89
+ let transactions = await this.getMultipleBlocksTransactions(
90
+ addresses,
91
+ startblockNumber,
92
+ endBlockNumber,
93
+ )
94
+
95
+ let requests: ValidWrapRequest[] = []
96
+ let invalidRequests: InValidWrapRequest[] = []
97
+
98
+ for (let inputTx of transactions) {
99
+ let { transaction, request, lockerAddress, lockerLockingScript } =
100
+ await this.getWrapRequestByTx(inputTx, inputTx.address)
101
+ if (request.status && "data" in request && request.data) {
102
+ requests.push({
103
+ transaction,
104
+ request,
105
+ lockerAddress,
106
+ lockerLockingScript,
107
+ })
108
+ } else if (request.code !== "NO_OP_RETURN") {
109
+ invalidRequests.push({ transaction, request, lockerAddress, lockerLockingScript })
110
+ }
111
+ }
112
+ return { requests, invalidRequests }
113
+ }
114
+
115
+ async getMempoolWrapRequests(addresses: string[]) {
116
+ // transaction in StartBlock is not returned --> (startblockNumber,endBlockNumber]
117
+ let transactions = await this.apiProvider.getMempoolTransactionHistoryForMultipleAddresses(
118
+ addresses,
119
+ )
120
+
121
+ let requests = []
122
+ let invalidRequests = []
123
+
124
+ for (let inputTx of transactions) {
125
+ let { transaction, request, lockerAddress, lockerLockingScript } =
126
+ await this.getWrapRequestByTx(inputTx, inputTx.address)
127
+ if (request.status) {
128
+ requests.push({ transaction, request, lockerAddress, lockerLockingScript })
129
+ } else if (request.code !== "NO_OP_RETURN") {
130
+ invalidRequests.push({ transaction, request, lockerAddress, lockerLockingScript })
131
+ }
132
+ }
133
+ return { requests, invalidRequests }
134
+ }
135
+
136
+ async getWrapRequestByTx(
137
+ inputTransaction:
138
+ | { txId: string }
139
+ | (bitcoin.Types.ConfirmedTransaction & {
140
+ address?: string
141
+ addressScript?: string
142
+ merkleProof?: Transaction["merkleProof"]
143
+ }),
144
+ lockerAddress: string,
145
+ minTeleporterFeeAmount = 0,
146
+ ) {
147
+ let transaction: bitcoin.Types.ConfirmedTransaction & {
148
+ address?: string
149
+ addressScript?: string
150
+ merkleProof?: Transaction["merkleProof"]
151
+ }
152
+ if ("vout" in inputTransaction && "blockNumber" in inputTransaction) {
153
+ transaction = inputTransaction
154
+ } else {
155
+ if (!inputTransaction.txId) throw new Error("txId not exist")
156
+ transaction = await this.getTransaction(inputTransaction.txId)
157
+ }
158
+
159
+ let vout = transaction.vout
160
+ let request = checkAndParseWrapRequest(vout!, lockerAddress, {
161
+ minTeleporterFeeAmount,
162
+ })
163
+ let lockerLockingScript: string =
164
+ transaction.addressScript ||
165
+ this.convertAddressToScript(lockerAddress).script!.toString("hex")
166
+
167
+ return {
168
+ transaction,
169
+ request,
170
+ lockerAddress,
171
+ lockerLockingScript,
172
+ }
173
+ }
174
+
175
+ async getLockersUnWrapTransactions(
176
+ addresses: string[],
177
+ startBlockNumber: number,
178
+ endBlockNumber: number,
179
+ ) {
180
+ let transactions = await this.getMultipleBlocksTransactions(
181
+ addresses,
182
+ startBlockNumber,
183
+ endBlockNumber,
184
+ )
185
+
186
+ let validTxs = []
187
+ for (let transaction of transactions) {
188
+ let address = transaction.address
189
+ // check if its a transaction to spend btc
190
+ let txBurnInfo = await this.getTransactionUnwrapInfoByTx(transaction, address)
191
+ if (txBurnInfo) {
192
+ const { burnInfo, lockerAddress, lockerLockingScript } = txBurnInfo
193
+ validTxs.push({
194
+ transaction,
195
+ burnInfo,
196
+ lockerAddress,
197
+ lockerLockingScript,
198
+ })
199
+ }
200
+ }
201
+ return validTxs
202
+ }
203
+
204
+ async getLockersUnwrapMEmpoolTransactions(
205
+ addresses: string[],
206
+ startBlockNumber: number,
207
+ endBlockNumber: number,
208
+ ) {
209
+ let transactions = await this.getMultipleBlocksTransactions(
210
+ addresses,
211
+ startBlockNumber,
212
+ endBlockNumber,
213
+ )
214
+
215
+ let validTxs = []
216
+ for (let transaction of transactions) {
217
+ let address = transaction.address
218
+ // check if its a transaction to spend btc
219
+ let txBurnInfo = await this.getTransactionUnwrapInfoByTx(transaction, address)
220
+ if (txBurnInfo) {
221
+ const { burnInfo, lockerAddress, lockerLockingScript } = txBurnInfo
222
+ validTxs.push({
223
+ transaction,
224
+ burnInfo,
225
+ lockerAddress,
226
+ lockerLockingScript,
227
+ })
228
+ }
229
+ }
230
+ return validTxs
231
+ }
232
+
233
+ async getTransactionUnwrapInfoByTx(
234
+ transaction: {
235
+ txId: any
236
+ vout?: any
237
+ vin?: any
238
+ addressScript?: any
239
+ },
240
+ lockerAddress: string,
241
+ ) {
242
+ if (!transaction.txId) throw new Error("txId not exist")
243
+ let vin = transaction.vin || (await this.getTransaction(transaction.txId)).vin
244
+ let burnInfo = getBurnTransactionInfo(lockerAddress, vin, transaction.vout)
245
+ if (!burnInfo) return
246
+ let lockerLockingScript: string =
247
+ transaction.addressScript ||
248
+ this.convertAddressToScript(lockerAddress).script!.toString("hex")
249
+ return {
250
+ burnInfo,
251
+ lockerAddress,
252
+ lockerLockingScript,
253
+ } as UnwrapRequest
254
+ }
255
+ }