mainnet-js 3.1.7 → 4.0.0-next.10

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 (267) hide show
  1. package/dist/module/cache/IndexedDbCache.d.ts +1 -1
  2. package/dist/module/cache/IndexedDbCache.d.ts.map +1 -1
  3. package/dist/module/cache/MemoryCache.d.ts +1 -1
  4. package/dist/module/cache/MemoryCache.d.ts.map +1 -1
  5. package/dist/module/cache/WebStorageCache.d.ts +1 -1
  6. package/dist/module/cache/WebStorageCache.d.ts.map +1 -1
  7. package/dist/module/cache/walletCache.d.ts +16 -6
  8. package/dist/module/cache/walletCache.d.ts.map +1 -1
  9. package/dist/module/cache/walletCache.js +92 -34
  10. package/dist/module/cache/walletCache.js.map +1 -1
  11. package/dist/module/cli.js +1 -2
  12. package/dist/module/cli.js.map +1 -1
  13. package/dist/module/db/index.d.ts +1 -1
  14. package/dist/module/db/index.d.ts.map +1 -1
  15. package/dist/module/db/index.js +1 -1
  16. package/dist/module/db/index.js.map +1 -1
  17. package/dist/module/enum.d.ts +1 -1
  18. package/dist/module/enum.d.ts.map +1 -1
  19. package/dist/module/history/getHistory.d.ts +1 -1
  20. package/dist/module/history/getHistory.d.ts.map +1 -1
  21. package/dist/module/history/getHistory.js +3 -3
  22. package/dist/module/history/getHistory.js.map +1 -1
  23. package/dist/module/index.d.ts +25 -22
  24. package/dist/module/index.d.ts.map +1 -1
  25. package/dist/module/index.js +33 -26
  26. package/dist/module/index.js.map +1 -1
  27. package/dist/module/interface.d.ts +12 -2
  28. package/dist/module/interface.d.ts.map +1 -1
  29. package/dist/module/interface.js.map +1 -1
  30. package/dist/module/libauth.d.ts +1 -1
  31. package/dist/module/libauth.d.ts.map +1 -1
  32. package/dist/module/libauth.js +1 -1
  33. package/dist/module/libauth.js.map +1 -1
  34. package/dist/module/mine/mine.d.ts +2 -7
  35. package/dist/module/mine/mine.d.ts.map +1 -1
  36. package/dist/module/mine/mine.js +6 -27
  37. package/dist/module/mine/mine.js.map +1 -1
  38. package/dist/module/network/Connection.d.ts +1 -12
  39. package/dist/module/network/Connection.d.ts.map +1 -1
  40. package/dist/module/network/Connection.js +24 -33
  41. package/dist/module/network/Connection.js.map +1 -1
  42. package/dist/module/network/ElectrumNetworkProvider.d.ts +16 -17
  43. package/dist/module/network/ElectrumNetworkProvider.d.ts.map +1 -1
  44. package/dist/module/network/ElectrumNetworkProvider.js +91 -93
  45. package/dist/module/network/ElectrumNetworkProvider.js.map +1 -1
  46. package/dist/module/network/MockNetworkProvider.d.ts +28 -0
  47. package/dist/module/network/MockNetworkProvider.d.ts.map +1 -0
  48. package/dist/module/network/MockNetworkProvider.js +74 -0
  49. package/dist/module/network/MockNetworkProvider.js.map +1 -0
  50. package/dist/module/network/NetworkProvider.d.ts +9 -2
  51. package/dist/module/network/NetworkProvider.d.ts.map +1 -1
  52. package/dist/module/network/configuration.d.ts +2 -4
  53. package/dist/module/network/configuration.d.ts.map +1 -1
  54. package/dist/module/network/configuration.js +25 -50
  55. package/dist/module/network/configuration.js.map +1 -1
  56. package/dist/module/network/constant.d.ts +7 -7
  57. package/dist/module/network/constant.d.ts.map +1 -1
  58. package/dist/module/network/constant.js +21 -24
  59. package/dist/module/network/constant.js.map +1 -1
  60. package/dist/module/network/default.d.ts +5 -3
  61. package/dist/module/network/default.d.ts.map +1 -1
  62. package/dist/module/network/default.js +29 -51
  63. package/dist/module/network/default.js.map +1 -1
  64. package/dist/module/network/index.d.ts +4 -4
  65. package/dist/module/network/index.d.ts.map +1 -1
  66. package/dist/module/network/index.js +2 -2
  67. package/dist/module/network/index.js.map +1 -1
  68. package/dist/module/network/interface.d.ts +0 -6
  69. package/dist/module/network/interface.d.ts.map +1 -1
  70. package/dist/module/rate/ExchangeRate.d.ts +1 -1
  71. package/dist/module/rate/ExchangeRate.d.ts.map +1 -1
  72. package/dist/module/rate/ExchangeRate.js +13 -7
  73. package/dist/module/rate/ExchangeRate.js.map +1 -1
  74. package/dist/module/transaction/Wif.d.ts +3 -3
  75. package/dist/module/transaction/Wif.d.ts.map +1 -1
  76. package/dist/module/transaction/Wif.js +4 -4
  77. package/dist/module/transaction/Wif.js.map +1 -1
  78. package/dist/module/transaction/allocateFee.d.ts +1 -1
  79. package/dist/module/transaction/allocateFee.d.ts.map +1 -1
  80. package/dist/module/transaction/allocateFee.js +2 -2
  81. package/dist/module/transaction/allocateFee.js.map +1 -1
  82. package/dist/module/util/deriveCashaddr.js.map +1 -1
  83. package/dist/module/util/deriveNetwork.js +1 -1
  84. package/dist/module/util/deriveNetwork.js.map +1 -1
  85. package/dist/module/util/getAddrsByXpubKey.js +1 -1
  86. package/dist/module/util/getAddrsByXpubKey.js.map +1 -1
  87. package/dist/module/util/getXPubKey.js +1 -1
  88. package/dist/module/util/getXPubKey.js.map +1 -1
  89. package/dist/module/util/hd.d.ts +2 -0
  90. package/dist/module/util/hd.d.ts.map +1 -1
  91. package/dist/module/util/hd.js +41 -0
  92. package/dist/module/util/hd.js.map +1 -1
  93. package/dist/module/util/index.d.ts +7 -9
  94. package/dist/module/util/index.d.ts.map +1 -1
  95. package/dist/module/util/index.js +7 -9
  96. package/dist/module/util/index.js.map +1 -1
  97. package/dist/module/util/transaction.js +1 -1
  98. package/dist/module/util/transaction.js.map +1 -1
  99. package/dist/module/wallet/Base.d.ts +13 -9
  100. package/dist/module/wallet/Base.d.ts.map +1 -1
  101. package/dist/module/wallet/Base.js +54 -58
  102. package/dist/module/wallet/Base.js.map +1 -1
  103. package/dist/module/wallet/HDWallet.d.ts.map +1 -1
  104. package/dist/module/wallet/HDWallet.js +19 -38
  105. package/dist/module/wallet/HDWallet.js.map +1 -1
  106. package/dist/module/wallet/Util.d.ts +4 -22
  107. package/dist/module/wallet/Util.d.ts.map +1 -1
  108. package/dist/module/wallet/Util.js +75 -102
  109. package/dist/module/wallet/Util.js.map +1 -1
  110. package/dist/module/wallet/Watch.d.ts +24 -5
  111. package/dist/module/wallet/Watch.d.ts.map +1 -1
  112. package/dist/module/wallet/Watch.js +141 -17
  113. package/dist/module/wallet/Watch.js.map +1 -1
  114. package/dist/module/wallet/Wif.d.ts +2 -6
  115. package/dist/module/wallet/Wif.d.ts.map +1 -1
  116. package/dist/module/wallet/Wif.js +3 -69
  117. package/dist/module/wallet/Wif.js.map +1 -1
  118. package/dist/module/wallet/createWallet.d.ts +1 -1
  119. package/dist/module/wallet/createWallet.d.ts.map +1 -1
  120. package/dist/module/wallet/createWallet.js +2 -1
  121. package/dist/module/wallet/createWallet.js.map +1 -1
  122. package/dist/module/wallet/interface.d.ts +3 -2
  123. package/dist/module/wallet/interface.d.ts.map +1 -1
  124. package/dist/module/wallet/model.d.ts +2 -1
  125. package/dist/module/wallet/model.d.ts.map +1 -1
  126. package/dist/module/wallet/model.js +1 -1
  127. package/dist/module/wallet/model.js.map +1 -1
  128. package/package.json +17 -29
  129. package/dist/index.html +0 -9
  130. package/dist/mainnet-3.1.7.js +0 -2066
  131. package/dist/module/network/util.d.ts +0 -3
  132. package/dist/module/network/util.d.ts.map +0 -1
  133. package/dist/module/network/util.js +0 -27
  134. package/dist/module/network/util.js.map +0 -1
  135. package/dist/module/test/expect.d.ts +0 -12
  136. package/dist/module/test/expect.d.ts.map +0 -1
  137. package/dist/module/test/expect.js +0 -47
  138. package/dist/module/test/expect.js.map +0 -1
  139. package/dist/module/test/fetch.d.ts +0 -3
  140. package/dist/module/test/fetch.d.ts.map +0 -1
  141. package/dist/module/test/fetch.js +0 -32
  142. package/dist/module/test/fetch.js.map +0 -1
  143. package/dist/module/util/randomBytes.d.ts +0 -2
  144. package/dist/module/util/randomBytes.d.ts.map +0 -1
  145. package/dist/module/util/randomBytes.js +0 -13
  146. package/dist/module/util/randomBytes.js.map +0 -1
  147. package/dist/tsconfig.tsbuildinfo +0 -1
  148. package/src/cache/IndexedDbCache.test.ts +0 -15
  149. package/src/cache/IndexedDbCache.ts +0 -172
  150. package/src/cache/MemoryCache.test.ts +0 -15
  151. package/src/cache/MemoryCache.ts +0 -32
  152. package/src/cache/WebStorageCache.test.ts +0 -15
  153. package/src/cache/WebStorageCache.ts +0 -38
  154. package/src/cache/index.ts +0 -2
  155. package/src/cache/interface.ts +0 -9
  156. package/src/cache/walletCache.ts +0 -254
  157. package/src/chain.ts +0 -3
  158. package/src/cli.ts +0 -32
  159. package/src/config.ts +0 -23
  160. package/src/constant.ts +0 -27
  161. package/src/db/ExchangeRateProvider.ts +0 -28
  162. package/src/db/StorageProvider.ts +0 -64
  163. package/src/db/index.ts +0 -2
  164. package/src/db/interface.ts +0 -11
  165. package/src/enum.ts +0 -34
  166. package/src/history/getHistory.test.ts +0 -290
  167. package/src/history/getHistory.ts +0 -411
  168. package/src/history/interface.ts +0 -24
  169. package/src/index.ts +0 -48
  170. package/src/interface.ts +0 -72
  171. package/src/libauth.ts +0 -11
  172. package/src/message/index.ts +0 -2
  173. package/src/message/interface.ts +0 -40
  174. package/src/message/signed.test.ts +0 -309
  175. package/src/message/signed.ts +0 -201
  176. package/src/mine/index.ts +0 -1
  177. package/src/mine/mine.test.ts +0 -10
  178. package/src/mine/mine.ts +0 -42
  179. package/src/network/Connection.test.ts +0 -51
  180. package/src/network/Connection.ts +0 -73
  181. package/src/network/ElectrumNetworkProvider.ts +0 -657
  182. package/src/network/NetworkProvider.ts +0 -180
  183. package/src/network/Rpc.test.ts +0 -130
  184. package/src/network/configuration.test.ts +0 -59
  185. package/src/network/configuration.ts +0 -72
  186. package/src/network/constant.ts +0 -43
  187. package/src/network/default.ts +0 -120
  188. package/src/network/electrum.test.ts +0 -28
  189. package/src/network/getRelayFeeCache.test.ts +0 -15
  190. package/src/network/getRelayFeeCache.ts +0 -23
  191. package/src/network/index.ts +0 -14
  192. package/src/network/interface.ts +0 -80
  193. package/src/network/util.test.ts +0 -24
  194. package/src/network/util.ts +0 -30
  195. package/src/rate/ExchangeRate.test.headless.js +0 -35
  196. package/src/rate/ExchangeRate.test.ts +0 -51
  197. package/src/rate/ExchangeRate.ts +0 -142
  198. package/src/test/expect.ts +0 -59
  199. package/src/test/fetch.ts +0 -39
  200. package/src/test/json.test.ts +0 -13
  201. package/src/transaction/Wif.ts +0 -680
  202. package/src/transaction/allocateFee.test.ts +0 -298
  203. package/src/transaction/allocateFee.ts +0 -149
  204. package/src/util/amountInSatoshi.test.ts +0 -27
  205. package/src/util/amountInSatoshi.ts +0 -33
  206. package/src/util/asSendRequestObject.ts +0 -81
  207. package/src/util/base64.test.ts +0 -39
  208. package/src/util/base64.ts +0 -12
  209. package/src/util/browserNotSupported.ts +0 -7
  210. package/src/util/checkForEmptySeed.ts +0 -9
  211. package/src/util/checkUtxos.ts +0 -29
  212. package/src/util/checkWifNetwork.ts +0 -24
  213. package/src/util/convert.test.ts +0 -46
  214. package/src/util/convert.ts +0 -50
  215. package/src/util/delay.ts +0 -3
  216. package/src/util/deriveCashaddr.test.ts +0 -164
  217. package/src/util/deriveCashaddr.ts +0 -143
  218. package/src/util/deriveLockscript.ts +0 -16
  219. package/src/util/deriveNetwork.ts +0 -19
  220. package/src/util/derivePublicKeyHash.test.ts +0 -55
  221. package/src/util/derivePublicKeyHash.ts +0 -64
  222. package/src/util/floor.test.ts +0 -21
  223. package/src/util/floor.ts +0 -4
  224. package/src/util/getAddrsByXpubKey.test.ts +0 -115
  225. package/src/util/getAddrsByXpubKey.ts +0 -86
  226. package/src/util/getRuntimePlatform.test.headless.js +0 -40
  227. package/src/util/getRuntimePlatform.test.ts +0 -5
  228. package/src/util/getRuntimePlatform.ts +0 -31
  229. package/src/util/getUsdRate.ts +0 -5
  230. package/src/util/getXPubKey.ts +0 -39
  231. package/src/util/hash160.test.ts +0 -18
  232. package/src/util/hash160.ts +0 -12
  233. package/src/util/hd.ts +0 -16
  234. package/src/util/header.test.ts +0 -34
  235. package/src/util/header.ts +0 -26
  236. package/src/util/index.ts +0 -33
  237. package/src/util/randomBytes.ts +0 -13
  238. package/src/util/randomInt.test.ts +0 -15
  239. package/src/util/randomInt.ts +0 -4
  240. package/src/util/sanitizeAddress.ts +0 -10
  241. package/src/util/sanitizeUnit.ts +0 -11
  242. package/src/util/satoshiToAmount.test.ts +0 -6
  243. package/src/util/satoshiToAmount.ts +0 -33
  244. package/src/util/sumSendRequestAmounts.ts +0 -34
  245. package/src/util/sumUtxoValue.ts +0 -27
  246. package/src/util/transaction.ts +0 -10
  247. package/src/wallet/Base.ts +0 -1563
  248. package/src/wallet/Cashtokens.test.headless.js +0 -730
  249. package/src/wallet/Cashtokens.test.ts +0 -1411
  250. package/src/wallet/HDWallet.test.ts +0 -1086
  251. package/src/wallet/HDWallet.ts +0 -992
  252. package/src/wallet/Util.test.ts +0 -134
  253. package/src/wallet/Util.ts +0 -191
  254. package/src/wallet/WalletCache.test.ts +0 -45
  255. package/src/wallet/Watch.ts +0 -441
  256. package/src/wallet/Wif.bip39.test.ts +0 -48
  257. package/src/wallet/Wif.test.ts +0 -1189
  258. package/src/wallet/Wif.ts +0 -687
  259. package/src/wallet/Wif.watchOnly.test.ts +0 -58
  260. package/src/wallet/createWallet.ts +0 -238
  261. package/src/wallet/enum.ts +0 -18
  262. package/src/wallet/interface.ts +0 -102
  263. package/src/wallet/model.test.ts +0 -24
  264. package/src/wallet/model.ts +0 -352
  265. package/tsconfig.browser.json +0 -11
  266. package/tsconfig.json +0 -33
  267. package/webpack.config.cjs +0 -132
@@ -1,352 +0,0 @@
1
- import { NFTCapability, UtxoId } from "../interface.js";
2
- import { DELIMITER } from "../constant.js";
3
- import {
4
- Input,
5
- Output,
6
- binToNumberUint16LE,
7
- binToUtf8,
8
- hexToBin,
9
- utf8ToBin,
10
- } from "@bitauth/libauth";
11
- import { Config } from "../config.js";
12
- import { checkTokenaddr } from "../util/deriveCashaddr.js";
13
-
14
- // These are the minimal models used to provide types for the express server
15
- //
16
- // This file will be deprecated auto-generated file in the future
17
- // Any business logic contained here should be moved elsewhere in src/
18
-
19
- export type SendRequestType =
20
- | SendRequest
21
- | TokenSendRequest
22
- | OpReturnData
23
- | Array<SendRequest | TokenSendRequest | OpReturnData>
24
- | SendRequestArray[];
25
-
26
- export class SendRequest {
27
- cashaddr: string;
28
- value: bigint;
29
-
30
- constructor({ cashaddr, value }: { cashaddr: string; value: bigint }) {
31
- this.cashaddr = cashaddr;
32
- this.value = BigInt(value);
33
- }
34
- }
35
-
36
- export class TokenGenesisRequest {
37
- amount?: bigint; // fungible token amount
38
- nft?: {
39
- capability: NFTCapability;
40
- commitment: string;
41
- };
42
- cashaddr?: string;
43
- value?: bigint; // satoshi value
44
-
45
- constructor({
46
- amount,
47
- nft,
48
- cashaddr,
49
- value,
50
- }: {
51
- amount?: bigint;
52
- nft?: {
53
- capability: NFTCapability;
54
- commitment: string;
55
- };
56
- cashaddr?: string;
57
- value?: bigint;
58
- }) {
59
- this.amount = amount;
60
- this.nft = nft;
61
- this.cashaddr = cashaddr;
62
- this.value = value;
63
- }
64
- }
65
-
66
- export class TokenBurnRequest {
67
- category: string;
68
- amount?: bigint; // fungible token amount
69
- nft?: {
70
- capability: NFTCapability;
71
- commitment: string;
72
- };
73
- cashaddr?: string;
74
-
75
- constructor({
76
- category,
77
- amount,
78
- nft,
79
- cashaddr,
80
- }: {
81
- category: string;
82
- amount?: number | bigint;
83
- cashaddr?: string;
84
- nft?: {
85
- capability: NFTCapability;
86
- commitment: string;
87
- };
88
- }) {
89
- this.category = category;
90
- this.amount = amount ? BigInt(amount) : 0n;
91
- this.nft = nft;
92
- this.cashaddr = cashaddr;
93
- }
94
- }
95
-
96
- export class TokenSendRequest {
97
- cashaddr: string; // cashaddr or tokenaddr to send tokens to
98
- value?: bigint; // satoshi value
99
- amount: bigint; // fungible token amount
100
- category: string;
101
- nft?: {
102
- capability: NFTCapability;
103
- commitment: string;
104
- };
105
-
106
- constructor({
107
- cashaddr,
108
- value,
109
- amount,
110
- category,
111
- nft,
112
- }: {
113
- cashaddr: string;
114
- value?: bigint;
115
- amount?: bigint;
116
- category: string;
117
- nft?: {
118
- capability: NFTCapability;
119
- commitment: string;
120
- };
121
- }) {
122
- checkTokenaddr(cashaddr, Config.EnforceCashTokenReceiptAddresses);
123
-
124
- this.cashaddr = cashaddr;
125
- this.value = value;
126
- this.amount = amount ? BigInt(amount) : 0n;
127
- this.category = category;
128
- this.nft = nft;
129
- }
130
- }
131
-
132
- export class TokenMintRequest {
133
- nft?: {
134
- capability: NFTCapability;
135
- commitment: string;
136
- };
137
- cashaddr?: string;
138
- value?: bigint;
139
-
140
- constructor({
141
- nft,
142
- cashaddr,
143
- value,
144
- }: {
145
- nft?: {
146
- capability: NFTCapability;
147
- commitment: string;
148
- };
149
- cashaddr?: string;
150
- value?: bigint;
151
- }) {
152
- this.nft = nft;
153
- this.cashaddr = cashaddr;
154
- this.value = value;
155
- }
156
- }
157
-
158
- export class OpReturnData {
159
- buffer: Uint8Array;
160
-
161
- public constructor(buffer: Uint8Array) {
162
- this.buffer = Uint8Array.from(buffer);
163
- }
164
-
165
- /**
166
- * from - Construct OP_RETURN data from arbitrary data type
167
- *
168
- * @param string UTF-8 encoded string message to be converted to OP_RETURN data
169
- *
170
- * @returns class instance
171
- */
172
- public static from(data: string | Uint8Array) {
173
- return this.fromArray([data]);
174
- }
175
-
176
- /**
177
- * fromString - Accept data as a simple UTF-8 string message and append an OP_RETURN and PUSH_DATA1 opcodes to it
178
- *
179
- * @param string UTF-8 encoded string message to be converted to OP_RETURN data
180
- *
181
- * @returns class instance
182
- */
183
- public static fromString(string: string) {
184
- return this.fromArray([string]);
185
- }
186
-
187
- /**
188
- * buffer - Accept OP_RETURN data as a binary buffer.
189
- * If buffer lacks the OP_RETURN and OP_PUSHDATA opcodes, they will be prepended.
190
- *
191
- * @param buffer Data buffer to be assigned to the OP_RETURN outpit
192
- *
193
- * @returns class instance
194
- */
195
- public static fromUint8Array(uint8Array: Uint8Array) {
196
- if (uint8Array[0] !== 0x6a) {
197
- return this.fromArray([uint8Array]);
198
- }
199
- return new this(Uint8Array.from(uint8Array));
200
- }
201
-
202
- /**
203
- * fromArray - Accept array of data
204
- *
205
- * @param array Array of Uint8Array or UTF-8 encoded string messages to be converted to OP_RETURN data
206
- *
207
- * @returns class instance
208
- */
209
- public static fromArray(array: Array<string | Uint8Array>) {
210
- let data: Uint8Array = Uint8Array.from([0x6a]); // OP_RETURN
211
- for (const element of array) {
212
- let length: number;
213
- let elementData: Uint8Array;
214
- let lengthData: any;
215
- if (typeof element === "string") {
216
- elementData = utf8ToBin(element);
217
- length = elementData.length;
218
- } else if (element instanceof Uint8Array) {
219
- elementData = element;
220
- length = elementData.length;
221
- } else {
222
- throw new Error("Wrong data array element");
223
- }
224
-
225
- if (length < 76) {
226
- // OP_PUSHDATA_1
227
- lengthData = [length];
228
- } else if (length < 223) {
229
- // default max `-datacarriersize`
230
- lengthData = [0x4c, length];
231
- } else {
232
- throw new Error("OP_RETURN data can not exceed 220 bytes in size");
233
- }
234
-
235
- data = Uint8Array.from([...data, ...lengthData, ...elementData]);
236
- }
237
-
238
- if (data.length > 220) {
239
- throw new Error("OP_RETURN data can not exceed 220 bytes in size");
240
- }
241
-
242
- return new this(data);
243
- }
244
-
245
- /**
246
- * parseBinary - parse OP_RETURN data and return pushed chunks of binary data
247
- *
248
- * @param opReturn Raw OP_RETURN data
249
- *
250
- * @returns array of binary data chunks pushed
251
- */
252
- public static parseBinary(opReturn: Uint8Array): Uint8Array[] {
253
- const chunks: Uint8Array[] = [];
254
- let position = 1;
255
-
256
- // handle direct push, OP_PUSHDATA1, OP_PUSHDATA2;
257
- // OP_PUSHDATA4 is not supported in OP_RETURNs by consensus
258
- while (opReturn[position]) {
259
- let length = 0;
260
- if (opReturn[position] === 0x4c) {
261
- length = opReturn[position + 1];
262
- position += 2;
263
- } else if (opReturn[position] === 0x4d) {
264
- length = binToNumberUint16LE(
265
- opReturn.slice(position + 1, position + 3)
266
- );
267
- position += 3;
268
- } else {
269
- length = opReturn[position];
270
- position += 1;
271
- }
272
-
273
- chunks.push(opReturn.slice(position, position + length));
274
- position += length;
275
- }
276
-
277
- return chunks;
278
- }
279
-
280
- /**
281
- * parse - parse OP_RETURN hex data and return pushed chunks of binary data, converted to utf8 strings
282
- *
283
- * @param opReturn Raw OP_RETURN hex data
284
- *
285
- * @returns array of binary data chunks pushed, converted to utf8 strings
286
- */
287
- public static parse(opReturnHex: string): string[] {
288
- return this.parseBinary(hexToBin(opReturnHex)).map((val) => binToUtf8(val));
289
- }
290
- }
291
-
292
- export type SendRequestArray = Array<string | bigint | Uint8Array>;
293
-
294
- export type SourceOutput = Input & Output;
295
-
296
- export class SendResponse {
297
- txId?: string;
298
- balance?: bigint;
299
- explorerUrl?: string;
300
- categories?: string[];
301
- unsignedTransaction?: string; // unsigned transaction hex
302
- sourceOutputs?: SourceOutput[]; // source outputs for signing unsigned transactions
303
-
304
- constructor({
305
- txId,
306
- balance,
307
- explorerUrl,
308
- }: {
309
- txId?: string;
310
- balance?: any;
311
- explorerUrl?: string;
312
- }) {
313
- this.txId = txId;
314
- this.balance = balance;
315
- this.explorerUrl = explorerUrl;
316
- }
317
- }
318
-
319
- export class XPubKey {
320
- path: string;
321
- xPubKey: string;
322
-
323
- constructor({ path, xPubKey }: { path: string; xPubKey: string }) {
324
- this.path = path;
325
- this.xPubKey = xPubKey;
326
- }
327
-
328
- public async ready() {
329
- await this.xPubKey;
330
- return this.asObject();
331
- }
332
-
333
- public asObject() {
334
- return {
335
- path: this.path,
336
- xPubKey: this.xPubKey,
337
- };
338
- }
339
- }
340
-
341
- export const fromUtxoId = (utxoId: string): UtxoId => {
342
- const [txid, vout, satoshis] = utxoId.split(DELIMITER);
343
- return {
344
- satoshis: satoshis ? BigInt(parseInt(satoshis)) : 0n,
345
- vout: parseInt(vout),
346
- txid,
347
- } as UtxoId;
348
- };
349
-
350
- export const toUtxoId = (utxo: UtxoId): string => {
351
- return [utxo.txid, utxo.vout].join(DELIMITER).replace(/:+$/, "");
352
- };
@@ -1,11 +0,0 @@
1
- {
2
- "extends": "./tsconfig",
3
- "compilerOptions": {
4
- "baseUrl": "src",
5
- "paths": {
6
- "pg": ["false*"]
7
- }
8
- },
9
- "include": ["src/**/*.ts"],
10
- "exclude": ["node_modules/**", "dist/**", "src/**/*test.ts"]
11
- }
package/tsconfig.json DELETED
@@ -1,33 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "rootDir": "src",
5
- "esModuleInterop": true,
6
- "allowSyntheticDefaultImports": true,
7
- "strict": true,
8
- "forceConsistentCasingInFileNames": true,
9
- "downlevelIteration": true,
10
- "composite": true,
11
- "target": "esnext",
12
- "module": "esnext",
13
- "outDir": "./dist/module",
14
- "moduleResolution": "node",
15
- "resolveJsonModule": true,
16
- "typeRoots": [
17
- "node_modules/@types",
18
- "../../node_modules/@types",
19
- "./src/types"
20
- ],
21
- "types": ["node", "jest"],
22
- "allowJs": false,
23
- "declaration": true,
24
- "declarationMap": true,
25
- "sourceMap": true,
26
- "noEmit": false,
27
- "strictPropertyInitialization": false,
28
- "useDefineForClassFields": false
29
- },
30
- "include": ["src/**/*.ts"],
31
- "exclude": ["node_modules/**", "src/**/*test.ts"],
32
- "compileOnSave": false
33
- }
@@ -1,132 +0,0 @@
1
- const { merge } = require("webpack-merge");
2
- const packageJson = require("./package.json");
3
- const HtmlWebpackPlugin = require("html-webpack-plugin");
4
- const InjectBodyPlugin = require("inject-body-webpack-plugin").default;
5
- const CircularDependencyPlugin = require("circular-dependency-plugin");
6
- const __basedir = require("path").resolve(__dirname, "../../");
7
-
8
- const path = require("path");
9
- const webpack = require("webpack");
10
-
11
- const baseConfig = {
12
- mode: "development",
13
- resolve: {
14
- extensions: [".tsx", ".ts", ".js", ".wasm"],
15
- extensionAlias: {
16
- ".js": [".ts", ".js"],
17
- },
18
- },
19
- optimization: {
20
- minimize: false,
21
- mangleWasmImports: true,
22
- usedExports: true,
23
- },
24
- experiments: { topLevelAwait: true, outputModule: true },
25
- };
26
-
27
- const prodConfig = {
28
- mode: "production",
29
- optimization: {
30
- minimize: true,
31
- },
32
- };
33
-
34
- const browserConfig = {
35
- target: "web",
36
- entry: {
37
- mainnet: {
38
- import: "./src/index.ts",
39
- library: {
40
- name: "__mainnetPromise",
41
- type: "global",
42
- },
43
- },
44
- },
45
- module: {
46
- rules: [
47
- {
48
- test: /\.tsx?$/,
49
- use: [
50
- {
51
- loader: "ts-loader",
52
- options: {
53
- configFile: "tsconfig.browser.json",
54
- },
55
- },
56
- ],
57
- exclude: [/node_modules/],
58
- },
59
- ],
60
- },
61
- output: {
62
- filename: `[name]-${packageJson.version}.js`,
63
- path: __dirname + "/dist",
64
- libraryTarget: "umd",
65
- },
66
- plugins: [
67
- //new BundleAnalyzerPlugin(),
68
- new HtmlWebpackPlugin({
69
- title: "The Empty Mainnet App",
70
- }),
71
- new InjectBodyPlugin({
72
- content:
73
- '<script>document.addEventListener("DOMContentLoaded", async (event) => Object.assign(globalThis, await __mainnetPromise))</script>',
74
- }),
75
- new CircularDependencyPlugin({
76
- include: /src/,
77
- // exclude detection of files based on a RegExp
78
- exclude: /node_modules/,
79
- // add errors to webpack instead of warnings
80
- failOnError: false,
81
- // allow import cycles that include an asyncronous import,
82
- // e.g. via import(/* webpackMode: "weak" */ './file.js')
83
- allowAsyncCycles: false,
84
- // set the current working directory for displaying module paths
85
- cwd: process.cwd(),
86
- }),
87
- ],
88
- resolve: {
89
- alias: {
90
- crypto: false,
91
- child_process: false,
92
- },
93
- fallback: {},
94
- },
95
- };
96
-
97
- const webWorkerConfig = {
98
- target: "webworker",
99
- output: {
100
- filename: `mainnet-webworker-${packageJson.version}.js`,
101
- path: __dirname + "/dist",
102
- libraryTarget: "umd",
103
- },
104
- resolve: {
105
- alias: {
106
- crypto: false,
107
- child_process: false,
108
- },
109
- fallback: {},
110
- },
111
- };
112
-
113
- const browserTestDiff = {
114
- output: {
115
- filename: `[name].js`,
116
- path: __basedir + "/jest/playwright/",
117
- },
118
- };
119
-
120
- const browserTestConfig = merge(browserConfig, browserTestDiff);
121
-
122
- let config = baseConfig;
123
-
124
- if (process.env.NODE_ENV == "production") {
125
- console.log("Running webpack in production mode");
126
- config = merge(baseConfig, prodConfig);
127
- }
128
-
129
- // Join configurations with the base configuration
130
- module.exports = [browserConfig, browserTestConfig].map((c) =>
131
- merge(config, c)
132
- );