beignet 0.0.1

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 (329) hide show
  1. package/.eslintignore +4 -0
  2. package/.eslintrc +40 -0
  3. package/.prettierrc +9 -0
  4. package/LICENSE +21 -0
  5. package/README.md +166 -0
  6. package/dist/electrum/constants.js +31 -0
  7. package/dist/electrum/constants.js.map +1 -0
  8. package/dist/electrum/index.js +552 -0
  9. package/dist/electrum/index.js.map +1 -0
  10. package/dist/index.js +23 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/shapes/electrum.js +14 -0
  13. package/dist/shapes/electrum.js.map +1 -0
  14. package/dist/shapes/index.js +19 -0
  15. package/dist/shapes/index.js.map +1 -0
  16. package/dist/shapes/wallet.js +115 -0
  17. package/dist/shapes/wallet.js.map +1 -0
  18. package/dist/transaction/index.js +692 -0
  19. package/dist/transaction/index.js.map +1 -0
  20. package/dist/types/electrum/constants.d.ts +7 -0
  21. package/dist/types/electrum/index.d.ts +85 -0
  22. package/dist/types/electrum.js +9 -0
  23. package/dist/types/electrum.js.map +1 -0
  24. package/dist/types/index.d.ts +6 -0
  25. package/dist/types/index.js +20 -0
  26. package/dist/types/index.js.map +1 -0
  27. package/dist/types/shapes/electrum.d.ts +5 -0
  28. package/dist/types/shapes/index.d.ts +2 -0
  29. package/dist/types/shapes/wallet.d.ts +10 -0
  30. package/dist/types/transaction/index.d.ts +92 -0
  31. package/dist/types/transaction.js +12 -0
  32. package/dist/types/transaction.js.map +1 -0
  33. package/dist/types/types/electrum.d.ts +113 -0
  34. package/dist/types/types/index.d.ts +3 -0
  35. package/dist/types/types/transaction.d.ts +51 -0
  36. package/dist/types/types/wallet.d.ts +400 -0
  37. package/dist/types/utils/conversion.d.ts +10 -0
  38. package/dist/types/utils/derivation-path.d.ts +19 -0
  39. package/dist/types/utils/electrum.d.ts +10 -0
  40. package/dist/types/utils/exchange-rate.d.ts +30 -0
  41. package/dist/types/utils/helpers.d.ts +23 -0
  42. package/dist/types/utils/index.d.ts +7 -0
  43. package/dist/types/utils/result.d.ts +16 -0
  44. package/dist/types/utils/transaction.d.ts +21 -0
  45. package/dist/types/utils/wallet.d.ts +47 -0
  46. package/dist/types/wallet/constants.d.ts +12 -0
  47. package/dist/types/wallet/index.d.ts +214 -0
  48. package/dist/types/wallet.js +36 -0
  49. package/dist/types/wallet.js.map +1 -0
  50. package/dist/utils/conversion.js +52 -0
  51. package/dist/utils/conversion.js.map +1 -0
  52. package/dist/utils/derivation-path.js +104 -0
  53. package/dist/utils/derivation-path.js.map +1 -0
  54. package/dist/utils/electrum.js +149 -0
  55. package/dist/utils/electrum.js.map +1 -0
  56. package/dist/utils/exchange-rate.js +49 -0
  57. package/dist/utils/exchange-rate.js.map +1 -0
  58. package/dist/utils/helpers.js +137 -0
  59. package/dist/utils/helpers.js.map +1 -0
  60. package/dist/utils/index.js +24 -0
  61. package/dist/utils/index.js.map +1 -0
  62. package/dist/utils/result.js +36 -0
  63. package/dist/utils/result.js.map +1 -0
  64. package/dist/utils/transaction.js +327 -0
  65. package/dist/utils/transaction.js.map +1 -0
  66. package/dist/utils/wallet.js +227 -0
  67. package/dist/utils/wallet.js.map +1 -0
  68. package/dist/wallet/constants.js +15 -0
  69. package/dist/wallet/constants.js.map +1 -0
  70. package/dist/wallet/index.js +2113 -0
  71. package/dist/wallet/index.js.map +1 -0
  72. package/docs/html/.nojekyll +1 -0
  73. package/docs/html/assets/highlight.css +22 -0
  74. package/docs/html/assets/main.js +58 -0
  75. package/docs/html/assets/search.js +1 -0
  76. package/docs/html/assets/style.css +1367 -0
  77. package/docs/html/classes/Electrum.html +812 -0
  78. package/docs/html/classes/Transaction.html +687 -0
  79. package/docs/html/classes/Wallet.html +2030 -0
  80. package/docs/html/enums/EAddressType.html +227 -0
  81. package/docs/html/enums/EAvailableNetworks.html +255 -0
  82. package/docs/html/enums/EBoostType.html +220 -0
  83. package/docs/html/enums/EFeeId.html +241 -0
  84. package/docs/html/enums/EPaymentType.html +220 -0
  85. package/docs/html/enums/EProtocol.html +220 -0
  86. package/docs/html/enums/EUnit.html +227 -0
  87. package/docs/html/functions/availableNetworks.html +200 -0
  88. package/docs/html/functions/constructByteCountParam.html +210 -0
  89. package/docs/html/functions/decodeOpReturnMessage.html +202 -0
  90. package/docs/html/functions/decodeRawTransaction.html +210 -0
  91. package/docs/html/functions/err.html +214 -0
  92. package/docs/html/functions/formatKeyDerivationPath.html +219 -0
  93. package/docs/html/functions/formatPeerData.html +207 -0
  94. package/docs/html/functions/generateMnemonic.html +223 -0
  95. package/docs/html/functions/generateWalletId.html +202 -0
  96. package/docs/html/functions/getAddressFromScriptPubKey.html +209 -0
  97. package/docs/html/functions/getAddressTypeFromPath.html +206 -0
  98. package/docs/html/functions/getByteCount.html +206 -0
  99. package/docs/html/functions/getDataFallback.html +207 -0
  100. package/docs/html/functions/getDefaultPort.html +209 -0
  101. package/docs/html/functions/getDefaultWalletData.html +200 -0
  102. package/docs/html/functions/getDefaultWalletDataKeys.html +200 -0
  103. package/docs/html/functions/getExchangeRates.html +200 -0
  104. package/docs/html/functions/getHighestUsedIndexFromTxHashes.html +216 -0
  105. package/docs/html/functions/getKeyDerivationPath.html +211 -0
  106. package/docs/html/functions/getKeyDerivationPathObject.html +216 -0
  107. package/docs/html/functions/getKeyDerivationPathString.html +220 -0
  108. package/docs/html/functions/getKeyValue.html +206 -0
  109. package/docs/html/functions/getPeers.html +211 -0
  110. package/docs/html/functions/getProtocolForPort.html +209 -0
  111. package/docs/html/functions/getScriptHash.html +210 -0
  112. package/docs/html/functions/getSeed.html +209 -0
  113. package/docs/html/functions/getSeedHash.html +206 -0
  114. package/docs/html/functions/getSha256.html +206 -0
  115. package/docs/html/functions/getStorageKeyValues.html +209 -0
  116. package/docs/html/functions/getTxFee.html +210 -0
  117. package/docs/html/functions/getWalletDataStorageKey.html +206 -0
  118. package/docs/html/functions/isValidBech32mEncodedString.html +211 -0
  119. package/docs/html/functions/objectKeys-1.html +211 -0
  120. package/docs/html/functions/objectsMatch.html +210 -0
  121. package/docs/html/functions/ok.html +214 -0
  122. package/docs/html/functions/parseOnChainPaymentRequest.html +204 -0
  123. package/docs/html/functions/reduceValue.html +215 -0
  124. package/docs/html/functions/removeDustOutputs.html +206 -0
  125. package/docs/html/functions/setReplaceByFee.html +210 -0
  126. package/docs/html/functions/shuffleArray.html +211 -0
  127. package/docs/html/functions/validateAddress.html +216 -0
  128. package/docs/html/functions/validateMnemonic.html +206 -0
  129. package/docs/html/functions/validateTransaction.html +206 -0
  130. package/docs/html/index.html +360 -0
  131. package/docs/html/interfaces/IAddInput.html +231 -0
  132. package/docs/html/interfaces/IAddress.html +247 -0
  133. package/docs/html/interfaces/IAddressData.html +231 -0
  134. package/docs/html/interfaces/IAddressType.html +199 -0
  135. package/docs/html/interfaces/IAddressTypeData.html +252 -0
  136. package/docs/html/interfaces/IAddresses.html +199 -0
  137. package/docs/html/interfaces/IBoostedTransaction.html +238 -0
  138. package/docs/html/interfaces/IBoostedTransactions.html +199 -0
  139. package/docs/html/interfaces/ICreateTransaction.html +224 -0
  140. package/docs/html/interfaces/ICustomGetAddress.html +231 -0
  141. package/docs/html/interfaces/ICustomGetScriptHash.html +224 -0
  142. package/docs/html/interfaces/IElectrumGetAddressBalanceRes.html +235 -0
  143. package/docs/html/interfaces/IExchangeRates.html +210 -0
  144. package/docs/html/interfaces/IFormattedPeerData.html +245 -0
  145. package/docs/html/interfaces/IFormattedTransaction.html +343 -0
  146. package/docs/html/interfaces/IFormattedTransactions.html +199 -0
  147. package/docs/html/interfaces/IGenerateAddresses.html +252 -0
  148. package/docs/html/interfaces/IGenerateAddressesResponse.html +224 -0
  149. package/docs/html/interfaces/IGetAddress.html +231 -0
  150. package/docs/html/interfaces/IGetAddressBalanceRes.html +226 -0
  151. package/docs/html/interfaces/IGetAddressByPath.html +224 -0
  152. package/docs/html/interfaces/IGetAddressHistoryResponse.html +269 -0
  153. package/docs/html/interfaces/IGetAddressResponse.html +231 -0
  154. package/docs/html/interfaces/IGetAddressScriptHashesHistoryResponse.html +245 -0
  155. package/docs/html/interfaces/IGetDerivationPath.html +259 -0
  156. package/docs/html/interfaces/IGetFeeEstimatesResponse.html +238 -0
  157. package/docs/html/interfaces/IGetHeaderResponse.html +245 -0
  158. package/docs/html/interfaces/IGetNextAvailableAddressResponse.html +238 -0
  159. package/docs/html/interfaces/IGetTransactions.html +245 -0
  160. package/docs/html/interfaces/IGetTransactionsFromInputs.html +245 -0
  161. package/docs/html/interfaces/IGetUtxosResponse.html +224 -0
  162. package/docs/html/interfaces/IHeader.html +231 -0
  163. package/docs/html/interfaces/IIndexes.html +238 -0
  164. package/docs/html/interfaces/IKeyDerivationPath.html +247 -0
  165. package/docs/html/interfaces/IKeyDerivationPathData.html +224 -0
  166. package/docs/html/interfaces/INewBlock.html +224 -0
  167. package/docs/html/interfaces/IOnchainFees.html +245 -0
  168. package/docs/html/interfaces/IOutput.html +231 -0
  169. package/docs/html/interfaces/IPeerData.html +231 -0
  170. package/docs/html/interfaces/IRbfData.html +252 -0
  171. package/docs/html/interfaces/ISend.html +224 -0
  172. package/docs/html/interfaces/ISendTransaction.html +322 -0
  173. package/docs/html/interfaces/ISendTx.html +231 -0
  174. package/docs/html/interfaces/ISetupTransaction.html +238 -0
  175. package/docs/html/interfaces/ISubscribeToAddress.html +247 -0
  176. package/docs/html/interfaces/ISubscribeToHeader.html +245 -0
  177. package/docs/html/interfaces/ITargets.html +238 -0
  178. package/docs/html/interfaces/ITransaction.html +281 -0
  179. package/docs/html/interfaces/ITxHash.html +217 -0
  180. package/docs/html/interfaces/ITxHashes.html +235 -0
  181. package/docs/html/interfaces/IUtxo.html +275 -0
  182. package/docs/html/interfaces/IVin.html +252 -0
  183. package/docs/html/interfaces/IVout.html +246 -0
  184. package/docs/html/interfaces/IWallet.html +350 -0
  185. package/docs/html/interfaces/IWalletData.html +343 -0
  186. package/docs/html/types/ElectrumConnectionPubSub.html +233 -0
  187. package/docs/html/types/ElectrumConnectionSubscription.html +204 -0
  188. package/docs/html/types/InputData.html +203 -0
  189. package/docs/html/types/ObjectKeys.html +198 -0
  190. package/docs/html/types/Result.html +201 -0
  191. package/docs/html/types/TAddressIndexInfo.html +204 -0
  192. package/docs/html/types/TAddressLabel.html +193 -0
  193. package/docs/html/types/TAddressType.html +193 -0
  194. package/docs/html/types/TAddressTypeContent.html +198 -0
  195. package/docs/html/types/TAddressTypes.html +193 -0
  196. package/docs/html/types/TAvailableNetworks.html +193 -0
  197. package/docs/html/types/TConnectToElectrumRes.html +193 -0
  198. package/docs/html/types/TDecodeRawTx.html +214 -0
  199. package/docs/html/types/TElectrumNetworks.html +193 -0
  200. package/docs/html/types/TGetAddressHistory.html +200 -0
  201. package/docs/html/types/TGetByteCountInput.html +193 -0
  202. package/docs/html/types/TGetByteCountInputs.html +193 -0
  203. package/docs/html/types/TGetByteCountOutput.html +193 -0
  204. package/docs/html/types/TGetByteCountOutputs.html +193 -0
  205. package/docs/html/types/TGetData.html +211 -0
  206. package/docs/html/types/TGetTotalFeeObj.html +204 -0
  207. package/docs/html/types/TKeyDerivationAccount.html +193 -0
  208. package/docs/html/types/TKeyDerivationChange.html +193 -0
  209. package/docs/html/types/TKeyDerivationCoinType.html +193 -0
  210. package/docs/html/types/TKeyDerivationIndex.html +193 -0
  211. package/docs/html/types/TKeyDerivationPurpose.html +193 -0
  212. package/docs/html/types/TMessageDataMap.html +210 -0
  213. package/docs/html/types/TMessageKeys.html +193 -0
  214. package/docs/html/types/TOnMessage.html +213 -0
  215. package/docs/html/types/TProcessUnconfirmedTransactions.html +202 -0
  216. package/docs/html/types/TProtocol.html +193 -0
  217. package/docs/html/types/TServer.html +204 -0
  218. package/docs/html/types/TSetData.html +213 -0
  219. package/docs/html/types/TSetupTransactionResponse.html +193 -0
  220. package/docs/html/types/TStorage.html +200 -0
  221. package/docs/html/types/TSubscribedReceive.html +193 -0
  222. package/docs/html/types/TTransactionMessage.html +198 -0
  223. package/docs/html/types/TTxResponse.html +206 -0
  224. package/docs/html/types/TTxResult.html +200 -0
  225. package/docs/html/types/TUnspentAddressScriptHashData.html +198 -0
  226. package/docs/html/types/TWalletDataKeys.html +193 -0
  227. package/docs/html/variables/defaultElectrumPorts.html +193 -0
  228. package/docs/html/variables/electrumConnection.html +199 -0
  229. package/docs/html/variables/mostUsedExchangeTickers.html +241 -0
  230. package/docs/markdown/.nojekyll +1 -0
  231. package/docs/markdown/README.md +1875 -0
  232. package/docs/markdown/classes/Electrum.md +718 -0
  233. package/docs/markdown/classes/Transaction.md +536 -0
  234. package/docs/markdown/classes/Wallet.md +2189 -0
  235. package/docs/markdown/enums/EAddressType.md +41 -0
  236. package/docs/markdown/enums/EAvailableNetworks.md +85 -0
  237. package/docs/markdown/enums/EBoostType.md +30 -0
  238. package/docs/markdown/enums/EFeeId.md +63 -0
  239. package/docs/markdown/enums/EPaymentType.md +30 -0
  240. package/docs/markdown/enums/EProtocol.md +30 -0
  241. package/docs/markdown/enums/EUnit.md +41 -0
  242. package/docs/markdown/interfaces/IAddInput.md +41 -0
  243. package/docs/markdown/interfaces/IAddress.md +69 -0
  244. package/docs/markdown/interfaces/IAddressData.md +41 -0
  245. package/docs/markdown/interfaces/IAddressType.md +7 -0
  246. package/docs/markdown/interfaces/IAddressTypeData.md +74 -0
  247. package/docs/markdown/interfaces/IAddresses.md +7 -0
  248. package/docs/markdown/interfaces/IBoostedTransaction.md +52 -0
  249. package/docs/markdown/interfaces/IBoostedTransactions.md +7 -0
  250. package/docs/markdown/interfaces/ICreateTransaction.md +30 -0
  251. package/docs/markdown/interfaces/ICustomGetAddress.md +41 -0
  252. package/docs/markdown/interfaces/ICustomGetScriptHash.md +30 -0
  253. package/docs/markdown/interfaces/IElectrumGetAddressBalanceRes.md +55 -0
  254. package/docs/markdown/interfaces/IExchangeRates.md +7 -0
  255. package/docs/markdown/interfaces/IFormattedPeerData.md +63 -0
  256. package/docs/markdown/interfaces/IFormattedTransaction.md +217 -0
  257. package/docs/markdown/interfaces/IFormattedTransactions.md +7 -0
  258. package/docs/markdown/interfaces/IGenerateAddresses.md +74 -0
  259. package/docs/markdown/interfaces/IGenerateAddressesResponse.md +30 -0
  260. package/docs/markdown/interfaces/IGetAddress.md +41 -0
  261. package/docs/markdown/interfaces/IGetAddressBalanceRes.md +36 -0
  262. package/docs/markdown/interfaces/IGetAddressByPath.md +30 -0
  263. package/docs/markdown/interfaces/IGetAddressHistoryResponse.md +121 -0
  264. package/docs/markdown/interfaces/IGetAddressResponse.md +41 -0
  265. package/docs/markdown/interfaces/IGetAddressScriptHashesHistoryResponse.md +63 -0
  266. package/docs/markdown/interfaces/IGetDerivationPath.md +100 -0
  267. package/docs/markdown/interfaces/IGetFeeEstimatesResponse.md +52 -0
  268. package/docs/markdown/interfaces/IGetHeaderResponse.md +63 -0
  269. package/docs/markdown/interfaces/IGetNextAvailableAddressResponse.md +52 -0
  270. package/docs/markdown/interfaces/IGetTransactions.md +63 -0
  271. package/docs/markdown/interfaces/IGetTransactionsFromInputs.md +63 -0
  272. package/docs/markdown/interfaces/IGetUtxosResponse.md +30 -0
  273. package/docs/markdown/interfaces/IHeader.md +41 -0
  274. package/docs/markdown/interfaces/IIndexes.md +52 -0
  275. package/docs/markdown/interfaces/IKeyDerivationPath.md +69 -0
  276. package/docs/markdown/interfaces/IKeyDerivationPathData.md +30 -0
  277. package/docs/markdown/interfaces/INewBlock.md +30 -0
  278. package/docs/markdown/interfaces/IOnchainFees.md +63 -0
  279. package/docs/markdown/interfaces/IOutput.md +41 -0
  280. package/docs/markdown/interfaces/IPeerData.md +41 -0
  281. package/docs/markdown/interfaces/IRbfData.md +74 -0
  282. package/docs/markdown/interfaces/ISend.md +30 -0
  283. package/docs/markdown/interfaces/ISendTransaction.md +184 -0
  284. package/docs/markdown/interfaces/ISendTx.md +41 -0
  285. package/docs/markdown/interfaces/ISetupTransaction.md +52 -0
  286. package/docs/markdown/interfaces/ISubscribeToAddress.md +60 -0
  287. package/docs/markdown/interfaces/ISubscribeToHeader.md +59 -0
  288. package/docs/markdown/interfaces/ITargets.md +52 -0
  289. package/docs/markdown/interfaces/ITransaction.md +88 -0
  290. package/docs/markdown/interfaces/ITxHash.md +19 -0
  291. package/docs/markdown/interfaces/ITxHashes.md +55 -0
  292. package/docs/markdown/interfaces/IUtxo.md +112 -0
  293. package/docs/markdown/interfaces/IVin.md +70 -0
  294. package/docs/markdown/interfaces/IVout.md +52 -0
  295. package/docs/markdown/interfaces/IWallet.md +209 -0
  296. package/docs/markdown/interfaces/IWalletData.md +217 -0
  297. package/example/helpers.ts +76 -0
  298. package/example/index.ts +77 -0
  299. package/package.json +69 -0
  300. package/src/electrum/constants.ts +28 -0
  301. package/src/electrum/index.ts +838 -0
  302. package/src/index.ts +6 -0
  303. package/src/shapes/electrum.ts +13 -0
  304. package/src/shapes/index.ts +2 -0
  305. package/src/shapes/wallet.ts +133 -0
  306. package/src/transaction/index.ts +1078 -0
  307. package/src/types/electrum.ts +139 -0
  308. package/src/types/index.ts +3 -0
  309. package/src/types/transaction.ts +58 -0
  310. package/src/types/wallet.ts +503 -0
  311. package/src/utils/conversion.ts +88 -0
  312. package/src/utils/derivation-path.ts +171 -0
  313. package/src/utils/electrum.ts +188 -0
  314. package/src/utils/exchange-rate.ts +70 -0
  315. package/src/utils/helpers.ts +191 -0
  316. package/src/utils/index.ts +7 -0
  317. package/src/utils/result.ts +79 -0
  318. package/src/utils/transaction.ts +417 -0
  319. package/src/utils/wallet.ts +351 -0
  320. package/src/wallet/constants.ts +24 -0
  321. package/src/wallet/index.ts +3304 -0
  322. package/tests/constants.ts +9 -0
  323. package/tests/derivation.test.ts +146 -0
  324. package/tests/electrum.test.ts +137 -0
  325. package/tests/storage.test.ts +222 -0
  326. package/tests/transaction.test.ts +187 -0
  327. package/tests/wallet.test.ts +307 -0
  328. package/tsconfig.json +32 -0
  329. package/typedoc.json +5 -0
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.objectsMatch = exports.validateMnemonic = exports.generateMnemonic = exports.getScriptHash = exports.getKeyDerivationPath = exports.validateAddress = exports.getSha256 = exports.getAddressFromScriptPubKey = void 0;
27
+ const types_1 = require("../types");
28
+ const bitcoinjs_lib_1 = require("bitcoinjs-lib");
29
+ const bip39 = require("bip39");
30
+ const bitcoin = __importStar(require("bitcoinjs-lib"));
31
+ const wallet_1 = require("./wallet");
32
+ const result_1 = require("./result");
33
+ const shapes_1 = require("../shapes");
34
+ const derivation_path_1 = require("./derivation-path");
35
+ const getAddressFromScriptPubKey = (scriptPubKey, selectedNetwork) => {
36
+ const network = bitcoinjs_lib_1.networks[selectedNetwork];
37
+ return bitcoin.address.fromOutputScript(Buffer.from(scriptPubKey, 'hex'), network);
38
+ };
39
+ exports.getAddressFromScriptPubKey = getAddressFromScriptPubKey;
40
+ const getSha256 = (str) => {
41
+ const buffer = Buffer.from(str, 'utf8');
42
+ const hash = bitcoin.crypto.sha256(buffer);
43
+ return hash.toString('hex');
44
+ };
45
+ exports.getSha256 = getSha256;
46
+ const validateAddress = ({ address, network }) => {
47
+ try {
48
+ let isValid = false;
49
+ const availableNetworksList = (0, wallet_1.availableNetworks)();
50
+ if (network !== undefined) {
51
+ try {
52
+ bitcoinjs_lib_1.address.toOutputScript(address, bitcoinjs_lib_1.networks[network]);
53
+ return { isValid: true, network };
54
+ }
55
+ catch (_a) {
56
+ const taprootRes = (0, wallet_1.isValidBech32mEncodedString)(address);
57
+ if (taprootRes.isValid && taprootRes.network === network) {
58
+ return { isValid: taprootRes.isValid, network: taprootRes.network };
59
+ }
60
+ }
61
+ return { isValid: false, network };
62
+ }
63
+ for (let i = 0; i < availableNetworksList.length; i++) {
64
+ const validateRes = (0, exports.validateAddress)({
65
+ address,
66
+ network: availableNetworksList[i]
67
+ });
68
+ if (validateRes.isValid) {
69
+ isValid = validateRes.isValid;
70
+ network = validateRes.network;
71
+ break;
72
+ }
73
+ }
74
+ return { isValid, network: network !== null && network !== void 0 ? network : types_1.EAvailableNetworks.bitcoin };
75
+ }
76
+ catch (_b) {
77
+ return { isValid: false, network: types_1.EAvailableNetworks.bitcoin };
78
+ }
79
+ };
80
+ exports.validateAddress = validateAddress;
81
+ const getKeyDerivationPath = ({ addressType, network }) => {
82
+ try {
83
+ const keyDerivationPathResponse = (0, derivation_path_1.getKeyDerivationPathObject)({
84
+ network,
85
+ path: shapes_1.addressTypes[addressType].path
86
+ });
87
+ if (keyDerivationPathResponse.isErr()) {
88
+ return (0, result_1.err)(keyDerivationPathResponse.error.message);
89
+ }
90
+ return (0, result_1.ok)(keyDerivationPathResponse.value);
91
+ }
92
+ catch (e) {
93
+ return (0, result_1.err)(e);
94
+ }
95
+ };
96
+ exports.getKeyDerivationPath = getKeyDerivationPath;
97
+ const getScriptHash = ({ address, network }) => {
98
+ try {
99
+ const _network = bitcoin.networks[network];
100
+ const script = bitcoin.address.toOutputScript(address, _network);
101
+ const hash = bitcoin.crypto.sha256(script);
102
+ const reversedHash = Buffer.from(hash.reverse());
103
+ return reversedHash.toString('hex');
104
+ }
105
+ catch (_a) {
106
+ return '';
107
+ }
108
+ };
109
+ exports.getScriptHash = getScriptHash;
110
+ const generateMnemonic = (strength, rng, wordlist) => {
111
+ return bip39.generateMnemonic(strength, rng, wordlist);
112
+ };
113
+ exports.generateMnemonic = generateMnemonic;
114
+ const validateMnemonic = (mnemonic = '') => {
115
+ try {
116
+ return bip39.validateMnemonic(mnemonic);
117
+ }
118
+ catch (_a) {
119
+ return false;
120
+ }
121
+ };
122
+ exports.validateMnemonic = validateMnemonic;
123
+ const objectsMatch = (obj1, obj2) => {
124
+ if (!obj1 || !obj2) {
125
+ return false;
126
+ }
127
+ const obj1Length = Object.keys(obj1).length;
128
+ const obj2Length = Object.keys(obj2).length;
129
+ if (obj1Length === obj2Length) {
130
+ return Object.keys(obj1).every((key) => key in obj2 && obj2[key] === obj1[key]);
131
+ }
132
+ else {
133
+ return false;
134
+ }
135
+ };
136
+ exports.objectsMatch = objectsMatch;
137
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAAgF;AAChF,iDAA+E;AAC/E,+BAAgC;AAChC,uDAAyC;AACzC,qCAA0E;AAC1E,qCAA2C;AAC3C,sCAAyC;AACzC,uDAA+D;AAQxD,MAAM,0BAA0B,GAAG,CACzC,YAAoB,EACpB,eAAmC,EAC1B,EAAE;IACX,MAAM,OAAO,GAAG,wBAAQ,CAAC,eAAe,CAAC,CAAC;IAC1C,OAAO,OAAO,CAAC,OAAO,CAAC,gBAAgB,CACtC,MAAM,CAAC,IAAI,CAAC,YAAY,EAAE,KAAK,CAAC,EAChC,OAAO,CACP,CAAC;AACH,CAAC,CAAC;AATW,QAAA,0BAA0B,8BASrC;AAOK,MAAM,SAAS,GAAG,CAAC,GAAW,EAAU,EA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Y,gBAcvB"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./wallet"), exports);
18
+ __exportStar(require("./helpers"), exports);
19
+ __exportStar(require("./exchange-rate"), exports);
20
+ __exportStar(require("./electrum"), exports);
21
+ __exportStar(require("./derivation-path"), exports);
22
+ __exportStar(require("./transaction"), exports);
23
+ __exportStar(require("./result"), exports);
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,4CAA0B;AAC1B,kDAAgC;AAChC,6CAA2B;AAC3B,oDAAkC;AAClC,gDAA8B;AAC9B,2CAAyB"}
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.err = exports.ok = void 0;
4
+ class Ok {
5
+ constructor(value) {
6
+ this.value = value;
7
+ }
8
+ isOk() {
9
+ return true;
10
+ }
11
+ isErr() {
12
+ return false;
13
+ }
14
+ }
15
+ class Err {
16
+ constructor(error) {
17
+ this.error = error;
18
+ console.log(error);
19
+ }
20
+ isOk() {
21
+ return false;
22
+ }
23
+ isErr() {
24
+ return true;
25
+ }
26
+ }
27
+ const ok = (value) => new Ok(value);
28
+ exports.ok = ok;
29
+ const err = (error) => {
30
+ if (typeof error === 'string') {
31
+ return new Err(new Error(error));
32
+ }
33
+ return new Err(error);
34
+ };
35
+ exports.err = err;
36
+ //# sourceMappingURL=result.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/utils/result.ts"],"names":[],"mappings":";;;AAQA,MAAM,EAAE;IAKP,YAAmC,KAAQ;QAAR,UAAK,GAAL,KAAK,CAAG;IAAG,CAAC;IAMxC,IAAI;QACV,OAAO,IAAI,CAAC;IACb,CAAC;IAMM,KAAK;QACX,OAAO,KAAK,CAAC;IACd,CAAC;CACD;AAKD,MAAM,GAAG;IAKR,YAAmC,KAAY;QAAZ,UAAK,GAAL,KAAK,CAAO;QAC9C,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAMM,IAAI;QACV,OAAO,KAAK,CAAC;IACd,CAAC;IAMM,KAAK;QACX,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAOM,MAAM,EAAE,GAAG,CAAI,KAAQ,EAAS,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC;AAA3C,QAAA,EAAE,MAAyC;AAOjD,MAAM,GAAG,GAAG,CAAI,KAAqB,EAAU,EAAE;IACvD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC9B,OAAO,IAAI,GAAG,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;KACjC;IACD,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC,CAAC;AALW,QAAA,GAAG,OAKd"}
@@ -0,0 +1,327 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.decodeRawTransaction = exports.validateTransaction = exports.removeDustOutputs = exports.getByteCount = exports.constructByteCountParam = exports.parseOnChainPaymentRequest = exports.setReplaceByFee = void 0;
27
+ const bitcoin = __importStar(require("bitcoinjs-lib"));
28
+ const bitcoinjs_lib_1 = require("bitcoinjs-lib");
29
+ const result_1 = require("./result");
30
+ const wallet_1 = require("./wallet");
31
+ const bitcoin_address_validation_1 = __importStar(require("bitcoin-address-validation"));
32
+ const bip21 = __importStar(require("bip21"));
33
+ const constants_1 = require("../wallet/constants");
34
+ const helpers_1 = require("./helpers");
35
+ const conversion_1 = require("./conversion");
36
+ const setReplaceByFee = ({ psbt, setRbf = true }) => {
37
+ try {
38
+ const defaultSequence = bitcoin.Transaction.DEFAULT_SEQUENCE;
39
+ const ins = psbt.data.globalMap.unsignedTx.tx.ins;
40
+ if (ins.length !== 0) {
41
+ ins.forEach((x) => {
42
+ if (setRbf) {
43
+ if (x.sequence >= defaultSequence - 1) {
44
+ x.sequence = 0;
45
+ }
46
+ }
47
+ else {
48
+ if (x.sequence < defaultSequence - 1) {
49
+ x.sequence = defaultSequence;
50
+ }
51
+ }
52
+ });
53
+ }
54
+ }
55
+ catch (_a) { }
56
+ };
57
+ exports.setReplaceByFee = setReplaceByFee;
58
+ const parseOnChainPaymentRequest = (data, network) => {
59
+ try {
60
+ if (!data) {
61
+ return (0, result_1.err)('No data provided to parseOnChainPaymentRequest.');
62
+ }
63
+ let validateAddressResult = (0, helpers_1.validateAddress)({ address: data, network });
64
+ if (validateAddressResult.isValid &&
65
+ !data.includes(':' || '?' || '&' || '//')) {
66
+ return (0, result_1.ok)({
67
+ address: data,
68
+ network: validateAddressResult.network,
69
+ sats: 0,
70
+ message: ''
71
+ });
72
+ }
73
+ if (data.includes(':' || '?' || '&' || '//')) {
74
+ try {
75
+ if (data.includes('//')) {
76
+ data = data.replace('//', '');
77
+ }
78
+ if (data.includes(':')) {
79
+ data = data.substring(data.indexOf(':') + 1);
80
+ data = `bitcoin:${data}`;
81
+ }
82
+ const result = bip21.decode(data);
83
+ const address = result.address;
84
+ validateAddressResult = (0, helpers_1.validateAddress)({ address, network });
85
+ if (!validateAddressResult.isValid) {
86
+ return (0, result_1.err)(`Invalid address: ${data}`);
87
+ }
88
+ let amount = 0;
89
+ let message = '';
90
+ try {
91
+ amount = Number(result.options.amount) || 0;
92
+ }
93
+ catch (e) { }
94
+ try {
95
+ message = result.options.message || '';
96
+ }
97
+ catch (e) { }
98
+ return (0, result_1.ok)({
99
+ address,
100
+ network: validateAddressResult.network,
101
+ sats: (0, conversion_1.btcToSats)(amount),
102
+ message
103
+ });
104
+ }
105
+ catch (_a) {
106
+ return (0, result_1.err)(data);
107
+ }
108
+ }
109
+ return (0, result_1.err)(data);
110
+ }
111
+ catch (_b) {
112
+ return (0, result_1.err)(data);
113
+ }
114
+ };
115
+ exports.parseOnChainPaymentRequest = parseOnChainPaymentRequest;
116
+ const constructByteCountParam = (addresses, increaseAddressCount = []) => {
117
+ try {
118
+ if (addresses.length <= 0) {
119
+ return { P2WPKH: 0 };
120
+ }
121
+ const param = {};
122
+ addresses.map((address) => {
123
+ if ((0, bitcoin_address_validation_1.default)(address)) {
124
+ const addressType = (0, bitcoin_address_validation_1.getAddressInfo)(address).type.toUpperCase();
125
+ param[addressType] = param[addressType] ? param[addressType] + 1 : 1;
126
+ }
127
+ });
128
+ increaseAddressCount.forEach(({ addrType, count }) => {
129
+ var _a;
130
+ param[addrType] = ((_a = param[addrType]) !== null && _a !== void 0 ? _a : 0) + count;
131
+ });
132
+ return param;
133
+ }
134
+ catch (_a) {
135
+ return { P2WPKH: 0 };
136
+ }
137
+ };
138
+ exports.constructByteCountParam = constructByteCountParam;
139
+ const getByteCount = (inputs, outputs, message) => {
140
+ try {
141
+ let totalWeight = 40;
142
+ let hasWitness = false;
143
+ const types = {
144
+ inputs: {
145
+ P2WPKH: 108 + 41 * 4,
146
+ p2wpkh: 108 + 41 * 4 + 1,
147
+ P2PKH: 148 * 4,
148
+ p2pkh: 148 * 4 + 1,
149
+ P2SH: 108 + 64 * 4,
150
+ p2sh: 108 + 64 * 4 + 1,
151
+ 'P2SH-P2WPKH': 108 + 64 * 4,
152
+ P2TR: 57.5 * 4,
153
+ p2tr: 57.5 * 4 + 1
154
+ },
155
+ multiSigInputs: {
156
+ 'MULTISIG-P2SH': 49 * 4,
157
+ 'MULTISIG-P2WSH': 6 + 41 * 4,
158
+ 'MULTISIG-P2SH-P2WSH': 6 + 76 * 4
159
+ },
160
+ outputs: {
161
+ P2SH: 32 * 4,
162
+ P2PKH: 34 * 4,
163
+ P2WPKH: 31 * 4,
164
+ P2WSH: 43 * 4,
165
+ p2wpkh: 31 * 4 + 1,
166
+ p2sh: 32 * 4 + 1,
167
+ p2pkh: 34 * 4 + 1,
168
+ P2TR: 43 * 4,
169
+ p2tr: 43 * 4 + 1
170
+ }
171
+ };
172
+ const checkUInt53 = (n) => {
173
+ if (n < 0 || n > Number.MAX_SAFE_INTEGER || n % 1 !== 0) {
174
+ throw new RangeError('value out of range');
175
+ }
176
+ };
177
+ const inputKeys = (0, wallet_1.objectKeys)(inputs);
178
+ inputKeys.forEach(function (key) {
179
+ const input = inputs[key];
180
+ checkUInt53(input);
181
+ const addressTypeCount = input || 1;
182
+ if (key.slice(0, 8) === 'MULTISIG') {
183
+ const keyParts = key.split(':');
184
+ if (keyParts.length !== 2) {
185
+ throw new Error('invalid input: ' + key);
186
+ }
187
+ const newKey = keyParts[0];
188
+ const mAndN = keyParts[1].split('-').map((item) => parseInt(item, 10));
189
+ totalWeight += types.multiSigInputs[newKey] * addressTypeCount;
190
+ const multiplyer = newKey === 'MULTISIG-P2SH' ? 4 : 1;
191
+ totalWeight +=
192
+ (73 * mAndN[0] + 34 * mAndN[1]) * multiplyer * addressTypeCount;
193
+ }
194
+ else {
195
+ totalWeight += types.inputs[key] * addressTypeCount;
196
+ }
197
+ if (['p2sh', 'P2SH', 'P2SH-P2WPKH', 'p2wpkh', 'P2WPKH'].includes(key)) {
198
+ hasWitness = true;
199
+ }
200
+ });
201
+ const outputKeys = (0, wallet_1.objectKeys)(outputs);
202
+ outputKeys.forEach(function (key) {
203
+ const output = outputs[key];
204
+ checkUInt53(output);
205
+ totalWeight += types.outputs[key] * output;
206
+ });
207
+ if (hasWitness) {
208
+ totalWeight += 2;
209
+ }
210
+ if (message === null || message === void 0 ? void 0 : message.length) {
211
+ totalWeight += message.length * 2;
212
+ }
213
+ return Math.ceil(totalWeight / 4);
214
+ }
215
+ catch (_a) {
216
+ return constants_1.TRANSACTION_DEFAULTS.recommendedBaseFee;
217
+ }
218
+ };
219
+ exports.getByteCount = getByteCount;
220
+ const removeDustOutputs = (outputs) => {
221
+ return outputs.filter((output) => {
222
+ return output.value > constants_1.TRANSACTION_DEFAULTS.dustLimit;
223
+ });
224
+ };
225
+ exports.removeDustOutputs = removeDustOutputs;
226
+ const validateTransaction = (transaction) => {
227
+ var _a, _b, _c, _d;
228
+ const baseFee = constants_1.TRANSACTION_DEFAULTS.recommendedBaseFee;
229
+ try {
230
+ if (!transaction.fee) {
231
+ return (0, result_1.err)('No transaction fee provided.');
232
+ }
233
+ if (transaction.outputs.length < 1 || !transaction.outputs[0].address) {
234
+ return (0, result_1.err)('Please provide an address to send funds to.');
235
+ }
236
+ if (transaction.outputs.length > 0 && !transaction.outputs[0].value) {
237
+ return (0, result_1.err)('Please provide an amount to send.');
238
+ }
239
+ const inputs = transaction.inputs;
240
+ const outputs = transaction.outputs;
241
+ for (let i = 0; i < outputs.length; i++) {
242
+ const address = (_b = (_a = outputs[i]) === null || _a === void 0 ? void 0 : _a.address) !== null && _b !== void 0 ? _b : '';
243
+ const value = (_d = (_c = outputs[i]) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : 0;
244
+ const { isValid } = (0, helpers_1.validateAddress)({ address });
245
+ if (!isValid) {
246
+ return (0, result_1.err)(`Invalid Address: ${address}`);
247
+ }
248
+ if (value < baseFee) {
249
+ return (0, result_1.err)(`Output value for ${address} must be greater than or equal to ${baseFee} sats`);
250
+ }
251
+ if (!Number.isInteger(value)) {
252
+ return (0, result_1.err)(`Output value for ${address} should be an integer`);
253
+ }
254
+ }
255
+ const inputsReduce = (0, wallet_1.reduceValue)({
256
+ arr: inputs,
257
+ value: 'value'
258
+ });
259
+ if (inputsReduce.isErr()) {
260
+ return (0, result_1.err)(inputsReduce.error.message);
261
+ }
262
+ let filteredOutputs = outputs;
263
+ if (transaction.changeAddress) {
264
+ filteredOutputs = outputs.filter((output) => {
265
+ return output.address !== transaction.changeAddress;
266
+ });
267
+ }
268
+ const outputsReduce = (0, wallet_1.reduceValue)({
269
+ arr: filteredOutputs,
270
+ value: 'value'
271
+ });
272
+ if (outputsReduce.isErr()) {
273
+ return (0, result_1.err)(outputsReduce.error.message);
274
+ }
275
+ return (0, result_1.ok)('Transaction is valid.');
276
+ }
277
+ catch (e) {
278
+ return (0, result_1.err)(e);
279
+ }
280
+ };
281
+ exports.validateTransaction = validateTransaction;
282
+ const decodeRawTransaction = (hex, _network) => {
283
+ try {
284
+ const network = bitcoinjs_lib_1.networks[_network];
285
+ const tx = bitcoin.Transaction.fromHex(hex);
286
+ return (0, result_1.ok)({
287
+ txid: tx.getId(),
288
+ tx_hash: tx.getHash(true).toString('hex'),
289
+ size: tx.byteLength(),
290
+ vsize: tx.virtualSize(),
291
+ weight: tx.weight(),
292
+ version: tx.version,
293
+ locktime: tx.locktime,
294
+ vin: tx.ins.map((input) => ({
295
+ txid: Buffer.from(input.hash).reverse().toString('hex'),
296
+ vout: input.index,
297
+ scriptSig: {
298
+ asm: bitcoin.script.toASM(input.script),
299
+ hex: input.script.toString('hex')
300
+ },
301
+ txinwitness: input.witness.map((b) => b.toString('hex')),
302
+ sequence: input.sequence
303
+ })),
304
+ vout: tx.outs.map((output, i) => {
305
+ let address;
306
+ try {
307
+ address = bitcoin.address.fromOutputScript(output.script, network);
308
+ }
309
+ catch (e) { }
310
+ return {
311
+ value: output.value,
312
+ n: i,
313
+ scriptPubKey: {
314
+ asm: bitcoin.script.toASM(output.script),
315
+ hex: output.script.toString('hex'),
316
+ address
317
+ }
318
+ };
319
+ })
320
+ });
321
+ }
322
+ catch (e) {
323
+ return (0, result_1.err)(e);
324
+ }
325
+ };
326
+ exports.decodeRawTransaction = decodeRawTransaction;
327
+ //# sourceMappingURL=transaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uDAAyC;AACzC,iDAA+C;AAC/C,qCAA2C;AAY3C,qCAAmD;AACnD,yFAAsE;AACtE,6CAA+B;AAC/B,mDAA2D;AAC3D,uCAA4C;AAC5C,6CAAyC;AAQlC,MAAM,eAAe,GAAG,CAAC,EAC/B,IAAI,EACJ,MAAM,GAAG,IAAI,EAIb,EAAQ,EAAE;IACV,IAAI;QACH,MAAM,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC,gBAAgB,CAAC;QAI7D,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CA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