@hinkal/common 0.0.112 → 0.0.114

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 (269) hide show
  1. package/API/API.js +58 -0
  2. package/API/HinkalPointsCalls.js +38 -0
  3. package/API/callBeefyGraphAPI.js +37 -0
  4. package/API/callCurveAPI.js +156 -0
  5. package/API/callMonitor.js +30 -0
  6. package/API/callOdosAPI.js +44 -0
  7. package/API/callOneInchAPI.js +37 -0
  8. package/API/callRelayer.js +32 -0
  9. package/API/checkRisk.js +30 -0
  10. package/API/dataServerCalls.js +32 -0
  11. package/API/fetchCommitmentsCache.js +31 -0
  12. package/API/fetchNullifiers.js +30 -0
  13. package/API/getAxelarGasEstimate.js +37 -0
  14. package/API/getCoingeckoPrice.js +27 -0
  15. package/API/getConnextReceiveFee.js +30 -0
  16. package/API/getGasEstimates.js +38 -0
  17. package/API/getRelayerURL.js +32 -0
  18. package/API/getServerURL.js +67 -0
  19. package/API/getTokenPrice.js +41 -0
  20. package/API/kycCalls.js +32 -0
  21. package/API/passwordCalls.js +36 -0
  22. package/API/referralProgramCalls.js +58 -0
  23. package/API/relayCalls.js +30 -0
  24. package/API/restoreSnapshots.js +32 -0
  25. package/API/rewardsPointsCalls.js +40 -0
  26. package/API/userVerifyTransactions.js +45 -0
  27. package/assets/{snarkjsWorkerLauncher-fuD5h_j0.js → snarkjsWorkerLauncher-CaBCnle3.js} +283 -257
  28. package/assets/snarkjsWorkerLogic-BAbiO5gj.js +17935 -0
  29. package/assets/snarkjsWorkerLogic-wHJfYCfg.js +15636 -0
  30. package/assets/{utxoWorkerLogic-CtFLQiAX.js → utxoWorkerLogic-BGFm-Zl2.js} +2 -2
  31. package/assets/{zkProofWorkerLauncher-J3Ts5_Ba.js → zkProofWorkerLauncher-BteYxRBn.js} +1 -1
  32. package/assets/{zkProofWorkerLogic-CPNuu61R.js → zkProofWorkerLogic-DiLbAhAo.js} +8354 -8298
  33. package/constants/assets.constants.js +16 -0
  34. package/constants/axelar.constants.js +55 -0
  35. package/constants/backend.constants.js +18 -0
  36. package/constants/beefy.registry.js +24 -0
  37. package/constants/chains.constants.js +204 -0
  38. package/constants/coingecko.constants.js +53 -0
  39. package/constants/contracts.constants.js +276 -0
  40. package/constants/crvCvx.registry.js +636 -0
  41. package/constants/crvDynamic.registry.js +24 -0
  42. package/constants/deploy-data/deploy-data-arbMainnet.json.js +7415 -0
  43. package/constants/deploy-data/deploy-data-avalanche.json.js +7411 -0
  44. package/constants/deploy-data/deploy-data-axelar1.json.js +4329 -0
  45. package/constants/deploy-data/deploy-data-axelar2.json.js +4329 -0
  46. package/constants/deploy-data/deploy-data-base.json.js +8425 -0
  47. package/constants/deploy-data/deploy-data-blast.json.js +9600 -0
  48. package/constants/deploy-data/deploy-data-bnbMainnet.json.js +6877 -0
  49. package/constants/deploy-data/deploy-data-ethMainnet.json.js +11427 -0
  50. package/constants/deploy-data/deploy-data-localhost.json.js +13283 -0
  51. package/constants/deploy-data/deploy-data-optimism.json.js +7417 -0
  52. package/constants/deploy-data/deploy-data-polygon.json.js +7439 -0
  53. package/constants/fees.constants.js +57 -0
  54. package/constants/kyc.constants.js +118 -0
  55. package/constants/lido.constants.js +13 -0
  56. package/constants/pendle.registry.js +253 -0
  57. package/constants/protocol.constants.js +26 -0
  58. package/constants/reorg-depths.constants.js +15 -0
  59. package/constants/rewards.constants.js +27 -0
  60. package/constants/server.constants.js +157 -0
  61. package/constants/token-data/ERC20Registry.js +85 -0
  62. package/constants/token-data/arbMainnetRegistry.json.js +946 -0
  63. package/constants/token-data/arbMainnetRegistryFixed.json.js +856 -0
  64. package/constants/token-data/avalancheRegistry.json.js +591 -0
  65. package/constants/token-data/avalancheRegistryFixed.json.js +591 -0
  66. package/constants/token-data/baseRegistry.json.js +490 -0
  67. package/constants/token-data/baseRegistryFixed.json.js +463 -0
  68. package/constants/token-data/blastRegistry.json.js +137 -0
  69. package/constants/token-data/blastRegistryFixed.json.js +137 -0
  70. package/constants/token-data/bnbMainnetRegistry.json.js +973 -0
  71. package/constants/token-data/bnbMainnetRegistryFixed.json.js +973 -0
  72. package/constants/token-data/coingeckoRegistry.json.js +115623 -0
  73. package/constants/token-data/ethMainnetRegistry.json.js +2700 -0
  74. package/constants/token-data/ethMainnetRegistryFixed.json.js +2251 -0
  75. package/constants/token-data/index.js +6 -0
  76. package/constants/token-data/localhostRegistry.json.js +2768 -0
  77. package/constants/token-data/optimismRegistry.json.js +1455 -0
  78. package/constants/token-data/optimismRegistryFixed.json.js +1392 -0
  79. package/constants/token-data/polygonRegistry.json.js +1327 -0
  80. package/constants/token-data/polygonRegistryFixed.json.js +1255 -0
  81. package/constants/token-data/popularTokens.constants.js +14 -0
  82. package/constants/token-data/tokenPricing.consts.js +8 -0
  83. package/constants/vite.constants.js +29 -0
  84. package/crypto/babyJub.js +15 -0
  85. package/crypto/poseidon.js +26 -0
  86. package/crypto/preProcessing.js +9 -0
  87. package/data-structures/Hinkal/Hinkal.js +299 -0
  88. package/data-structures/Hinkal/hinkalActionBeefy.js +101 -0
  89. package/data-structures/Hinkal/hinkalActionConvex.js +83 -0
  90. package/data-structures/Hinkal/hinkalActionCurve.js +112 -0
  91. package/data-structures/Hinkal/hinkalActionLidoEth.js +91 -0
  92. package/data-structures/Hinkal/hinkalActionPendle.js +140 -0
  93. package/data-structures/Hinkal/hinkalActionPendleLP.js +96 -0
  94. package/data-structures/Hinkal/hinkalActionStake.js +138 -0
  95. package/data-structures/Hinkal/hinkalActionVolatile.js +112 -0
  96. package/data-structures/Hinkal/hinkalDeposit.js +95 -0
  97. package/data-structures/Hinkal/hinkalGetZkMeProvider.js +47 -0
  98. package/data-structures/Hinkal/hinkalPrivateWallet.js +66 -0
  99. package/data-structures/Hinkal/hinkalSwap.js +98 -0
  100. package/data-structures/Hinkal/hinkalTransfer.js +5 -0
  101. package/data-structures/Hinkal/hinkalWithdraw.js +91 -0
  102. package/data-structures/Hinkal/resetMerkleTrees.js +49 -0
  103. package/data-structures/MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.js +83 -0
  104. package/data-structures/ValueCache/ValueCache.js +25 -0
  105. package/data-structures/crypto-keys/decodeUTXO.js +40 -0
  106. package/data-structures/crypto-keys/encryptDecryptUtxo.js +41 -0
  107. package/data-structures/crypto-keys/keyUtils.js +10 -0
  108. package/data-structures/crypto-keys/keys.js +90 -0
  109. package/data-structures/custom-token-registry/CustomTokenRegistry.js +33 -0
  110. package/data-structures/event-service/AbstractAccessTokenSnapshotService.js +131 -0
  111. package/data-structures/event-service/AbstractCommitmentsSnapshotService.js +132 -0
  112. package/data-structures/event-service/AbstractEventService.js +118 -0
  113. package/data-structures/event-service/AbstractNullifierSnapshotService.js +59 -0
  114. package/data-structures/event-service/AbstractSnapshotService.js +35 -0
  115. package/data-structures/merkle-tree/MerkleTree.js +177 -0
  116. package/data-structures/merkle-tree/MerkleTreeIncompleteError.js +8 -0
  117. package/data-structures/snapshot/ClientAccessTokenSnapshotService.js +48 -0
  118. package/data-structures/snapshot/ClientCommitmentsSnapshotService.js +47 -0
  119. package/data-structures/snapshot/ClientNullifierSnapshotService.js +44 -0
  120. package/data-structures/token-price-fetcher/TokenChecker.js +29 -0
  121. package/data-structures/token-price-fetcher/TokenPriceFetcher.js +218 -0
  122. package/data-structures/transactions-manager/TransactionsManager.js +194 -0
  123. package/data-structures/transactions-manager/history/getBeefyData.js +68 -0
  124. package/data-structures/transactions-manager/history/getConvexData.js +57 -0
  125. package/data-structures/transactions-manager/history/getCurveData.js +97 -0
  126. package/data-structures/transactions-manager/history/getDepositData.js +36 -0
  127. package/data-structures/transactions-manager/history/getLidoData.js +44 -0
  128. package/data-structures/transactions-manager/history/getPendleData.js +59 -0
  129. package/data-structures/transactions-manager/history/getSwapData.js +43 -0
  130. package/data-structures/transactions-manager/history/getTxDetails.js +74 -0
  131. package/data-structures/transactions-manager/history/getVolatileData.js +75 -0
  132. package/data-structures/transactions-manager/history/history.types.js +62 -0
  133. package/data-structures/transactions-manager/history/history.utils.js +8 -0
  134. package/data-structures/utxo/Utxo.js +134 -0
  135. package/data-structures/volatile-helper/VolatileHelper.js +181 -0
  136. package/error-handling/customErrors/ErrorWithAmount.js +9 -0
  137. package/error-handling/customErrors/FeeOverTransactionValueError.js +9 -0
  138. package/error-handling/customErrors/customErrors.helpers.js +21 -0
  139. package/error-handling/error-codes.constants.js +184 -0
  140. package/error-handling/get-error.message.js +53 -0
  141. package/error-handling/handleErrorRestore.js +35 -0
  142. package/error-handling/logError.js +7 -0
  143. package/error-handling/types.js +4 -0
  144. package/externalABIs/BUSD.js +519 -0
  145. package/externalABIs/BabPassport.json.js +24 -0
  146. package/externalABIs/BeefyRouterAbi.json.js +1022 -0
  147. package/externalABIs/BeefyStrategyAbi.json.js +1423 -0
  148. package/externalABIs/BeefyVaultAbi.json.js +570 -0
  149. package/externalABIs/BeefyZapAbi.json.js +208 -0
  150. package/externalABIs/BeefyZapOneInchAbi.json.js +340 -0
  151. package/externalABIs/ConvexBoosterAbi.json.js +674 -0
  152. package/externalABIs/ConvexBoosterAbiMainnet.json.js +1002 -0
  153. package/externalABIs/ConvexRewardPoolAbi.json.js +883 -0
  154. package/externalABIs/CurveReadingWrapperAbi.json.js +1422 -0
  155. package/externalABIs/CurveWrappedMainPool.json.js +1136 -0
  156. package/externalABIs/CurveZap.json.js +262 -0
  157. package/externalABIs/CvxCrvUtilities.json.js +264 -0
  158. package/externalABIs/DAI.js +334 -0
  159. package/externalABIs/ERC20.json.js +291 -0
  160. package/externalABIs/GalxePassport.json.js +41 -0
  161. package/externalABIs/IQuoterV2.json.js +205 -0
  162. package/externalABIs/ISwapRouter.json.js +568 -0
  163. package/externalABIs/IUniswapV3Factory.json.js +201 -0
  164. package/externalABIs/IUniswapV3Pool.json.js +999 -0
  165. package/externalABIs/LidoStEthAbi.json.js +1603 -0
  166. package/externalABIs/LidoStMaticAbi.json.js +1764 -0
  167. package/externalABIs/LidoStakeManagerAbi.json.js +2082 -0
  168. package/externalABIs/LidoWithdrawalQueueERC721Abi.json.js +2030 -0
  169. package/externalABIs/LidoWstEthAbi.json.js +480 -0
  170. package/externalABIs/OptimismGasPriceOracle.json.js +206 -0
  171. package/externalABIs/PendleRouterAbi.json.js +173 -0
  172. package/externalABIs/PoLidoNftAbi.json.js +701 -0
  173. package/externalABIs/SanctionsList.js +89 -0
  174. package/externalABIs/USDC.js +721 -0
  175. package/externalABIs/USDR.js +346 -0
  176. package/externalABIs/USDR3CRV.js +542 -0
  177. package/externalABIs/USDT.js +393 -0
  178. package/externalABIs/UniswapV2PoolAbi.json.js +80 -0
  179. package/externalABIs/WETH.js +156 -0
  180. package/externalABIs/amToken.js +350 -0
  181. package/externalABIs/transactionsProver.json.js +39 -0
  182. package/functions/kyc/authentoHelper.js +42 -0
  183. package/functions/kyc/passportHelper.js +39 -0
  184. package/functions/kyc/zkMeHelper.js +56 -0
  185. package/functions/pre-transaction/getFlatFees.js +203 -0
  186. package/functions/pre-transaction/interaction-to-action.js +57 -0
  187. package/functions/pre-transaction/outputUtxoProcessing.js +45 -0
  188. package/functions/pre-transaction/process-gas-estimates.js +57 -0
  189. package/functions/pre-transaction/processAmountChanges.js +229 -0
  190. package/functions/private-wallet/emporium.helpers.js +19 -0
  191. package/functions/private-wallet/opProducer.js +24 -0
  192. package/functions/protocols/convex.protocols.js +41 -0
  193. package/functions/protocols/curve.protocols.js +45 -0
  194. package/functions/protocols/pendle.helpers.js +108 -0
  195. package/functions/snarkjs/common.snarkjs.js +96 -0
  196. package/functions/snarkjs/constant.js +211 -0
  197. package/functions/snarkjs/constructEmporiumProof.js +105 -0
  198. package/functions/snarkjs/constructGeneralZkProof.js +129 -0
  199. package/functions/snarkjs/generateCircomData.js +60 -0
  200. package/functions/snarkjs/generateZkProof.js +18 -0
  201. package/functions/snarkjs/getZKFiles.js +30 -0
  202. package/functions/staking/index.js +40 -0
  203. package/functions/utils/amounts.utils.js +70 -0
  204. package/functions/utils/axelar.utils.js +38 -0
  205. package/functions/utils/cacheFunctions.js +67 -0
  206. package/functions/utils/caseInsensitive.utils.js +6 -0
  207. package/functions/utils/convertIntegrationProviderToExternalActionId.js +16 -0
  208. package/functions/utils/create-provider.js +5 -0
  209. package/functions/utils/enum.utils.js +14 -0
  210. package/functions/utils/erc20tokenFunctions.js +20 -0
  211. package/functions/utils/evmNetworkFunctions.js +29 -0
  212. package/functions/utils/external-action.utils.js +61 -0
  213. package/functions/utils/getDataFromTransaction.js +105 -0
  214. package/functions/utils/memoize.utils.js +14 -0
  215. package/functions/utils/nickname.utils.js +7 -0
  216. package/functions/utils/process.utils.js +4 -0
  217. package/functions/utils/reloadPage.js +4 -0
  218. package/functions/utils/requireEnv.js +7 -0
  219. package/functions/utils/resolve-sync.utils.js +22 -0
  220. package/functions/utils/serialize.utils.js +4 -0
  221. package/functions/utils/string.utils.js +14 -0
  222. package/functions/utils/time.utils.js +8 -0
  223. package/functions/utils/userAgent.js +15 -0
  224. package/functions/utils/volatile-patcher.utils.js +40 -0
  225. package/functions/web3/etherFunctions.js +41 -0
  226. package/functions/web3/events/balanceChangedHandler.js +10 -0
  227. package/functions/web3/events/getInputUtxoAndBalance.js +72 -0
  228. package/functions/web3/events/getShieldedBalance.js +107 -0
  229. package/functions/web3/events/web3RetrieveEvents.js +9 -0
  230. package/functions/web3/functionCalls/accessTokenCalls.js +48 -0
  231. package/functions/web3/functionCalls/approveToken.js +153 -0
  232. package/functions/web3/functionCalls/estimateGasRelayer.js +18 -0
  233. package/functions/web3/functionCalls/transactCallDirect.js +60 -0
  234. package/functions/web3/functionCalls/transactCallRelayer.js +42 -0
  235. package/functions/web3/odosAPI.js +65 -0
  236. package/functions/web3/oneInchAPI.js +61 -0
  237. package/functions/web3/runContractFunction.js +95 -0
  238. package/functions/web3/uniswapAPI.js +97 -0
  239. package/index.js +642 -455
  240. package/package.json +2 -2
  241. package/types/beefy.types.js +21 -0
  242. package/types/circom-data.types.js +22 -0
  243. package/types/curve.types.js +25 -0
  244. package/types/ethereum-network.types.js +4 -0
  245. package/types/external-action.types.js +4 -0
  246. package/types/hinkal.stake.types.js +4 -0
  247. package/types/hinkal.types.js +15 -0
  248. package/types/kyc.types.js +13 -0
  249. package/types/pendle.types.js +15 -0
  250. package/types/rewards.types.js +27 -0
  251. package/types/slippage.types.js +15 -0
  252. package/types/time.types.js +58 -0
  253. package/types/token.types.js +4 -0
  254. package/types/transactions.types.js +36 -0
  255. package/webworker/performTaskWithWorker.js +62 -0
  256. package/webworker/snarkjsWorker/snarkjsWorker.types.js +4 -0
  257. package/{snarkjsWorkerLogic-CVna_BW9.mjs → webworker/snarkjsWorker/snarkjsWorkerLogic.js} +1 -1
  258. package/webworker/utxoWorker/utxoWorker.types.js +4 -0
  259. package/webworker/utxoWorker/utxoWorkerLogic.js +70 -0
  260. package/webworker/worker.registry.js +4 -0
  261. package/webworker/workerFactory.js +42 -0
  262. package/{workerProxy-BDj498Ht.mjs → webworker/workerProxy.js} +1 -1
  263. package/webworker/zkProofWorker/zkProofWorker.types.js +4 -0
  264. package/webworker/zkProofWorker/zkProofWorkerLogic.js +66 -0
  265. package/assets/snarkjsWorkerLogic-B6N4z_eM.js +0 -12136
  266. package/assets/snarkjsWorkerLogic-Fv0M38Mc.js +0 -12087
  267. package/index-DXElTGy9.mjs +0 -254449
  268. package/utxoWorkerLogic-B1Hh-bq4.mjs +0 -64
  269. package/zkProofWorkerLogic-D9rxuuiK.mjs +0 -60
@@ -0,0 +1,40 @@
1
+ import { ethers as m } from "ethers";
2
+ import { Utxo as g } from "../utxo/Utxo.js";
3
+ import { UserKeys as x } from "./keys.js";
4
+ const c = (o) => {
5
+ const t = m.utils.defaultAbiCoder.decode(
6
+ ["uint256", "address", "tuple(uint256, uint256, uint256, uint256)", "uint256", "uint256"],
7
+ o
8
+ ), e = t[0].toBigInt(), r = t[1], s = t[2][0].toBigInt(), n = t[2][1].toHexString(), i = t[2][2].toBigInt(), d = t[2][3].toBigInt(), u = t[3].toString(), a = t[4].toNumber();
9
+ return {
10
+ amount: e,
11
+ erc20TokenAddress: r,
12
+ randomization: s,
13
+ stealthAddress: n,
14
+ H0: i,
15
+ H1: d,
16
+ timeStamp: u,
17
+ tokenId: a
18
+ };
19
+ }, U = (o, t) => {
20
+ const { amount: e, erc20TokenAddress: r, timeStamp: s, tokenId: n, randomization: i } = c(o);
21
+ return {
22
+ amount: e,
23
+ erc20TokenAddress: r,
24
+ timeStamp: s,
25
+ tokenId: n,
26
+ randomization: i,
27
+ shieldedPrivateKey: t
28
+ };
29
+ }, k = (o, t) => new g(U(o, t)), I = (o, t) => {
30
+ const { randomization: e, H0: r, H1: s } = c(o), n = x.checkSignature(e, r, s, t);
31
+ if (!n)
32
+ throw new Error("UTXO doesn't belong to user");
33
+ return n;
34
+ };
35
+ export {
36
+ c as abiDecodeUtxo,
37
+ I as checkUtxoSignature,
38
+ k as decodeUtxo,
39
+ U as decodeUtxoConstructorArgs
40
+ };
@@ -0,0 +1,41 @@
1
+ import { ethers as t } from "ethers";
2
+ import a from "libsodium-wrappers";
3
+ import { Utxo as d } from "../utxo/Utxo.js";
4
+ import { UserKeys as l } from "./keys.js";
5
+ (async () => await a.ready)();
6
+ const B = (e, i) => {
7
+ const o = [
8
+ Buffer.from(t.utils.hexlify(i ? 0n : e.amount)),
9
+ Buffer.from(t.utils.hexlify(e.erc20TokenAddress)),
10
+ Buffer.from(t.utils.hexlify(e.randomization)),
11
+ Buffer.from(e.getStealthAddress()),
12
+ Buffer.from(t.utils.hexlify(BigInt(e.timeStamp)))
13
+ ];
14
+ e.tokenId > 0 && o.push(Buffer.from(t.utils.hexlify(e.tokenId)));
15
+ const n = Buffer.concat(o);
16
+ return a.crypto_box_seal(n, t.utils.arrayify(e.getEncryptionKey()));
17
+ }, m = (e, i) => {
18
+ const { publicKey: o, privateKey: n } = l.getEncryptionKeyPair(i.getShieldedPrivateKey()), y = a.crypto_box_seal_open(
19
+ e,
20
+ t.utils.arrayify(o),
21
+ t.utils.arrayify(n)
22
+ ), r = Buffer.from(y).toString("utf-8").split("0x").filter((f) => f.length !== 0).map((f, c) => {
23
+ let s;
24
+ return [0, 2, 4, 5].includes(c) ? s = BigInt(`0x${f}`) : [1, 3].includes(c) && (s = `0x${f}`), s;
25
+ });
26
+ return {
27
+ amount: r[0],
28
+ erc20TokenAddress: r[1],
29
+ randomization: r[2],
30
+ stealthAddress: r[3],
31
+ shieldedPrivateKey: i.getShieldedPrivateKey(),
32
+ timeStamp: r[4].toString(),
33
+ tokenId: r[5] ? Number(r[5]) : 0
34
+ // tokenId
35
+ };
36
+ }, x = (e, i) => new d(m(e, i));
37
+ export {
38
+ x as decryptUtxo,
39
+ m as decryptUtxoConstructorArgs,
40
+ B as encryptUtxo
41
+ };
@@ -0,0 +1,10 @@
1
+ import { CIRCOM_P as o, CIRCOM_P_HALF as t } from "../../constants/protocol.constants.js";
2
+ const e = (r) => {
3
+ if (r < 0n || r >= o)
4
+ throw new RangeError();
5
+ return r > t;
6
+ }, n = (r) => e(r) ? 1n : 0n;
7
+ export {
8
+ n as getCircomSign,
9
+ e as isCircomNegative
10
+ };
@@ -0,0 +1,90 @@
1
+ import { utils as S, ethers as o } from "ethers";
2
+ import d from "libsodium-wrappers";
3
+ import { CIRCOM_P as h } from "../../constants/protocol.constants.js";
4
+ import { babyJubInstance as m } from "../../crypto/babyJub.js";
5
+ import { poseidonHash as u } from "../../crypto/poseidon.js";
6
+ import { memoizeFunc as c } from "../../functions/utils/memoize.utils.js";
7
+ import { getCircomSign as g } from "./keyUtils.js";
8
+ (async () => await d.ready)();
9
+ const q = {
10
+ privateKey: "",
11
+ publicKey: ""
12
+ };
13
+ class H {
14
+ signature;
15
+ constructor(t) {
16
+ this.signature = t;
17
+ }
18
+ getSignature() {
19
+ return this.requireSignature(), this.signature;
20
+ }
21
+ setSignature(t) {
22
+ this.signature = t;
23
+ }
24
+ requireSignature() {
25
+ if (!this.signature)
26
+ throw Error("No signature provided");
27
+ }
28
+ verifyMessage(t) {
29
+ return this.requireSignature(), S.verifyMessage(t, this.signature);
30
+ }
31
+ /**
32
+ * get shielded private key from message signature used to login to the application,
33
+ * this private key is used to generate encryption keypairs as well as public key
34
+ * @retuns 0x-prefixed shielded private key
35
+ */
36
+ getShieldedPrivateKey = () => (this.requireSignature(), o.utils.keccak256(this.signature));
37
+ /**
38
+ * generate shielded public key from private key
39
+ * @param privateKey the key used to generate the shielded public key, this should be the signature
40
+ * that the user provided
41
+ * @retuns shielded public key in hexstring with 0x prefixed
42
+ */
43
+ getShieldedPublicKey = () => (this.requireSignature(), u(this.getShieldedPrivateKey()));
44
+ /**
45
+ * generate access token, this accessKey is what should be sent to the server for signing
46
+ * @returns accessKey in hexstring with 0x prefixed
47
+ */
48
+ getAccessKey = () => (this.requireSignature(), u(this.getShieldedPrivateKey(), this.getShieldedPublicKey()));
49
+ getWalletSalt = (t) => (this.requireSignature(), u(this.getShieldedPublicKey(), this.getShieldedPrivateKey(), t));
50
+ /**
51
+ * generate backend token, which is used for access control on backend
52
+ * @returns accessKey in hexstring with 0x prefixed
53
+ */
54
+ getBackendToken = () => (this.requireSignature(), u(this.getAccessKey(), this.getShieldedPublicKey()));
55
+ static getRandomizedStealthPair = c(
56
+ (t, i) => {
57
+ const e = m(), r = BigInt(i) % h, n = t * r % h, s = e.mulPointEscalar(e.Base8, t), a = e.mulPointEscalar(e.Base8, n), l = [BigInt(e.F.toString(s[0])), BigInt(e.F.toString(s[1]))], y = [BigInt(e.F.toString(a[0])), BigInt(e.F.toString(a[1]))];
58
+ return { H0: l, H1: y };
59
+ }
60
+ );
61
+ static getStealthAddressCompressedPoints = (t, i) => {
62
+ const { H0: e, H1: r } = this.getRandomizedStealthPair(t, i), [n, s] = [e, r].map((a) => BigInt(a[1]) + 2n ** 255n * g(a[0]));
63
+ return { h0: n, h1: s };
64
+ };
65
+ static getStealthAddress = c((t, i) => {
66
+ const { H0: e, H1: r } = this.getRandomizedStealthPair(t, i), s = [2n * g(e[0]) + g(r[0]), e[1], r[1]];
67
+ return u(...s);
68
+ });
69
+ static getStealthAddressWithEKey = (t, i) => ({ stealthAddress: this.getStealthAddress(t, i), encryptionKey: this.getEncryptionKeyPair(i).publicKey });
70
+ static checkSignature = (t, i, e, r) => {
71
+ const { h0: n, h1: s } = this.getStealthAddressCompressedPoints(t, r);
72
+ return i === n && e === s;
73
+ };
74
+ /**
75
+ * generate private and public keypair
76
+ * @param seed seed to use to deterministically generate key, must be in DataHexString format
77
+ * and must correspond to 32 bytes
78
+ */
79
+ static getEncryptionKeyPair = (t) => {
80
+ const i = d.crypto_box_seed_keypair(o.utils.arrayify(t));
81
+ return {
82
+ privateKey: o.utils.hexlify(i.privateKey),
83
+ publicKey: o.utils.hexlify(i.publicKey)
84
+ };
85
+ };
86
+ }
87
+ export {
88
+ q as EncryptionKeyPairDefaultValue,
89
+ H as UserKeys
90
+ };
@@ -0,0 +1,33 @@
1
+ class o {
2
+ localStorageKey = "tokenRegistry";
3
+ tokenRegistry;
4
+ constructor() {
5
+ if (this.tokenRegistry = [], typeof localStorage < "u") {
6
+ const t = localStorage.getItem(this.localStorageKey);
7
+ t && (this.tokenRegistry = JSON.parse(t));
8
+ }
9
+ }
10
+ persistRegistry() {
11
+ typeof localStorage < "u" && localStorage.setItem(this.localStorageKey, JSON.stringify(this.tokenRegistry));
12
+ }
13
+ getCustomTokens(t) {
14
+ return this.tokenRegistry.filter((s) => s.chainId === t);
15
+ }
16
+ tokenExists(t, s) {
17
+ return t.find(
18
+ (e) => e.erc20TokenAddress === s.erc20TokenAddress || e.symbol === s.symbol || e.name === s.name
19
+ );
20
+ }
21
+ addCustomToken(t) {
22
+ const { chainId: s } = t, e = this.getCustomTokens(s);
23
+ this.tokenExists(e, t) || this.tokenRegistry.push(t), this.persistRegistry();
24
+ }
25
+ removeCustomToken(t) {
26
+ const { chainId: s } = t, r = this.getCustomTokens(s).filter((i) => i.erc20TokenAddress !== t.erc20TokenAddress);
27
+ this.tokenRegistry = r, this.persistRegistry();
28
+ }
29
+ }
30
+ const g = new o();
31
+ export {
32
+ g as customTokenRegistry
33
+ };
@@ -0,0 +1,131 @@
1
+ import "../../constants/chains.constants.js";
2
+ import "../../types/circom-data.types.js";
3
+ import "../../types/transactions.types.js";
4
+ import "../../types/curve.types.js";
5
+ import "ethers";
6
+ import { zeroAddress as i } from "../../constants/protocol.constants.js";
7
+ import { poseidonFunction as m } from "../../crypto/poseidon.js";
8
+ import "../crypto-keys/keys.js";
9
+ import { toBigInt as t } from "../../functions/utils/amounts.utils.js";
10
+ import "axios";
11
+ import "../crypto-keys/encryptDecryptUtxo.js";
12
+ import "../../functions/web3/events/getShieldedBalance.js";
13
+ import "../../webworker/workerFactory.js";
14
+ import "../../functions/utils/external-action.utils.js";
15
+ import "../custom-token-registry/CustomTokenRegistry.js";
16
+ import "../../functions/utils/convertIntegrationProviderToExternalActionId.js";
17
+ import "../../constants/coingecko.constants.js";
18
+ import "../../constants/vite.constants.js";
19
+ import "../../functions/utils/userAgent.js";
20
+ import "circomlibjs";
21
+ import { MerkleTree as o } from "../merkle-tree/MerkleTree.js";
22
+ import { AbstractSnapshotService as c } from "./AbstractSnapshotService.js";
23
+ import "../../constants/reorg-depths.constants.js";
24
+ import "../../constants/kyc.constants.js";
25
+ import "../volatile-helper/VolatileHelper.js";
26
+ import "libsodium-wrappers";
27
+ import "../../constants/contracts.constants.js";
28
+ import "../../constants/axelar.constants.js";
29
+ import "../../constants/rewards.constants.js";
30
+ class G extends c {
31
+ constructor(e, s, r, d) {
32
+ super(
33
+ e,
34
+ {
35
+ name: "NewAccessKeyAdded",
36
+ args: ["accessKey", "index", "senderAddress"]
37
+ },
38
+ s,
39
+ r,
40
+ d
41
+ );
42
+ }
43
+ _merkleTree;
44
+ _senderAddresses;
45
+ _senderAddressIndexMap;
46
+ get merkleTree() {
47
+ return this._merkleTree;
48
+ }
49
+ get senderAddresses() {
50
+ return this._senderAddresses;
51
+ }
52
+ get senderAddressIndexMap() {
53
+ return this._senderAddressIndexMap;
54
+ }
55
+ serializeSnapshot(e) {
56
+ return {
57
+ merkleTree: e.payload.merkleTree.toJSON(),
58
+ senderAddresses: Array.from(e.payload.senderAddresses),
59
+ latestBlockNumber: e.latestBlockNumber,
60
+ reserveBlockNumber: e.reserveBlockNumber,
61
+ senderAddressIndexMap: Array.from(e.payload.senderAddressIndexMap).map(([s, r]) => ({
62
+ address: s,
63
+ index: r
64
+ }))
65
+ };
66
+ }
67
+ deserializeSnapshot(e) {
68
+ let s, r;
69
+ if (e.latestBlockNumber && e.merkleTree) {
70
+ const d = new Map(
71
+ Object.entries(e.merkleTree.tree).map(([n, p]) => [
72
+ BigInt(n),
73
+ BigInt(p)
74
+ ])
75
+ );
76
+ s = o.createWithData(
77
+ d,
78
+ t(e.merkleTree.index),
79
+ t(e.merkleTree.count),
80
+ m,
81
+ 25n,
82
+ 0n
83
+ );
84
+ } else
85
+ s = o.create(m, 25n, 0n);
86
+ return e.latestBlockNumber && e.senderAddressIndexMap ? r = new Map(
87
+ e.senderAddressIndexMap.map(({ address: d, index: n }) => [d, n])
88
+ ) : r = /* @__PURE__ */ new Map(), {
89
+ latestBlockNumber: e.latestBlockNumber ?? 0,
90
+ reserveBlockNumber: e.reserveBlockNumber ?? 0,
91
+ payload: {
92
+ merkleTree: s,
93
+ senderAddresses: e.senderAddresses ?? [],
94
+ senderAddressIndexMap: r
95
+ }
96
+ };
97
+ }
98
+ acceptEvent(e, s) {
99
+ try {
100
+ return this._merkleTree.insert(e.accessKey, e.index), this._senderAddressIndexMap.set(
101
+ e.senderAddress,
102
+ Math.max(Number(e.index), this._senderAddressIndexMap.get(e.senderAddress) ?? 0)
103
+ ), this._senderAddresses.includes(e.senderAddress) || this._senderAddresses.push(e.senderAddress), e.accessKey === 0n && e.senderAddress === i && this._merkleTree.remove(e.index), !0;
104
+ } catch (r) {
105
+ return console.error(r), !1;
106
+ }
107
+ }
108
+ mapEvent(e) {
109
+ const { accessKey: s, index: r, senderAddress: d } = e;
110
+ return {
111
+ accessKey: t(s),
112
+ index: t(r),
113
+ senderAddress: d
114
+ };
115
+ }
116
+ getSnapshotPayload() {
117
+ return {
118
+ merkleTree: this._merkleTree,
119
+ senderAddresses: this._senderAddresses,
120
+ senderAddressIndexMap: this._senderAddressIndexMap
121
+ };
122
+ }
123
+ populateSnapshot({
124
+ payload: { merkleTree: e, senderAddresses: s, senderAddressIndexMap: r }
125
+ }) {
126
+ this._merkleTree = e, this._senderAddresses = s, this._senderAddressIndexMap = r;
127
+ }
128
+ }
129
+ export {
130
+ G as AbstractAccessTokenSnapshotService
131
+ };
@@ -0,0 +1,132 @@
1
+ import { poseidonFunction as o } from "../../crypto/poseidon.js";
2
+ import "circomlibjs";
3
+ import { MerkleTree as p } from "../merkle-tree/MerkleTree.js";
4
+ import { toBigInt as i } from "../../functions/utils/amounts.utils.js";
5
+ import "ethers";
6
+ import "axios";
7
+ import "../../constants/chains.constants.js";
8
+ import "../../types/circom-data.types.js";
9
+ import "../../types/transactions.types.js";
10
+ import "../../types/curve.types.js";
11
+ import "../crypto-keys/keys.js";
12
+ import "../../functions/web3/events/getShieldedBalance.js";
13
+ import "../../webworker/workerFactory.js";
14
+ import "../crypto-keys/encryptDecryptUtxo.js";
15
+ import "../../functions/utils/external-action.utils.js";
16
+ import "../../constants/coingecko.constants.js";
17
+ import "../../constants/vite.constants.js";
18
+ import "libsodium-wrappers";
19
+ import { AbstractSnapshotService as c } from "./AbstractSnapshotService.js";
20
+ import "../../constants/reorg-depths.constants.js";
21
+ import "../../constants/kyc.constants.js";
22
+ import "../volatile-helper/VolatileHelper.js";
23
+ import "../custom-token-registry/CustomTokenRegistry.js";
24
+ import "../../constants/contracts.constants.js";
25
+ import "../../constants/axelar.constants.js";
26
+ import "../../constants/rewards.constants.js";
27
+ import "../../functions/utils/convertIntegrationProviderToExternalActionId.js";
28
+ import "../../functions/utils/userAgent.js";
29
+ class D extends c {
30
+ constructor(e, t, m, r) {
31
+ super(
32
+ e,
33
+ {
34
+ name: "NewCommitment",
35
+ args: ["commitment", "index", "encryptedOutput"]
36
+ },
37
+ t,
38
+ m,
39
+ r
40
+ );
41
+ }
42
+ _merkleTree;
43
+ _encryptedOutputs;
44
+ get merkleTree() {
45
+ return this._merkleTree;
46
+ }
47
+ get encryptedOutputs() {
48
+ return this._encryptedOutputs;
49
+ }
50
+ serializeSnapshot(e) {
51
+ return {
52
+ merkleTree: e.payload.merkleTree.toJSON(),
53
+ latestBlockNumber: e.latestBlockNumber,
54
+ reserveBlockNumber: e.reserveBlockNumber,
55
+ encryptedOutputs: e.payload.encryptedOutputs.map((t) => ({
56
+ value: t.value,
57
+ isPositive: String(t.isPositive)
58
+ }))
59
+ };
60
+ }
61
+ deserializeSnapshot(e) {
62
+ let t;
63
+ if (e.latestBlockNumber && e.merkleTree) {
64
+ const r = new Map(
65
+ Object.entries(e.merkleTree.tree).map(([u, n]) => [
66
+ BigInt(u),
67
+ BigInt(n)
68
+ ])
69
+ );
70
+ t = p.createWithData(
71
+ r,
72
+ i(e.merkleTree.index),
73
+ i(e.merkleTree.count),
74
+ o,
75
+ 25n,
76
+ 0n
77
+ );
78
+ } else
79
+ t = p.create(o, 25n, 0n);
80
+ const m = e.encryptedOutputs?.map((r) => ({
81
+ value: r.value,
82
+ isPositive: JSON.parse(r.isPositive)
83
+ }));
84
+ return {
85
+ latestBlockNumber: e.latestBlockNumber ?? 0,
86
+ reserveBlockNumber: e.reserveBlockNumber ?? 0,
87
+ payload: {
88
+ merkleTree: t,
89
+ encryptedOutputs: m || []
90
+ }
91
+ };
92
+ }
93
+ getSnapshotPayload() {
94
+ return {
95
+ merkleTree: this._merkleTree,
96
+ encryptedOutputs: this._encryptedOutputs
97
+ };
98
+ }
99
+ populateSnapshot({
100
+ payload: { merkleTree: e, encryptedOutputs: t }
101
+ }) {
102
+ this._merkleTree = e, this._encryptedOutputs = t;
103
+ }
104
+ mapEvent(e) {
105
+ const { commitment: t, index: m, encryptedOutput: r } = e;
106
+ return {
107
+ commitment: i(t),
108
+ index: i(m),
109
+ encryptedOutput: r
110
+ };
111
+ }
112
+ acceptEvent(e, t) {
113
+ if (!this.encryptedOutputs.map((m) => m.value).includes(e.encryptedOutput)) {
114
+ if (this.isServer && console.log(
115
+ `Adding commitment to file ${e.commitment} at index ${e.index} for encrypted output ${e.encryptedOutput}. Block Number: ${t}
116
+
117
+
118
+ `
119
+ ), !this._merkleTree.insert(e.commitment, e.index >= 0 ? e.index : -1n * e.index))
120
+ return console.log(`Could not add ${e.commitment} at index ${e.index} `), !1;
121
+ const r = {
122
+ value: e.encryptedOutput,
123
+ isPositive: e.index >= 0n
124
+ };
125
+ return this._encryptedOutputs.push(r), !0;
126
+ }
127
+ return !1;
128
+ }
129
+ }
130
+ export {
131
+ D as AbstractCommitmentsSnapshotService
132
+ };
@@ -0,0 +1,118 @@
1
+ import { blockReorgDepth as v } from "../../constants/reorg-depths.constants.js";
2
+ import "ethers";
3
+ import "axios";
4
+ import "../../constants/chains.constants.js";
5
+ import "../../types/circom-data.types.js";
6
+ import "../../types/transactions.types.js";
7
+ import "../../types/curve.types.js";
8
+ import "circomlibjs";
9
+ import "../crypto-keys/keys.js";
10
+ import "../../functions/web3/events/getShieldedBalance.js";
11
+ import "../../webworker/workerFactory.js";
12
+ import "../crypto-keys/encryptDecryptUtxo.js";
13
+ import "../../functions/utils/external-action.utils.js";
14
+ import "../../constants/coingecko.constants.js";
15
+ import "../../constants/vite.constants.js";
16
+ import "libsodium-wrappers";
17
+ import { getSequence as m, resolveSync as c } from "../../functions/utils/resolve-sync.utils.js";
18
+ import "../../constants/kyc.constants.js";
19
+ import "../volatile-helper/VolatileHelper.js";
20
+ import "../custom-token-registry/CustomTokenRegistry.js";
21
+ import "../../constants/contracts.constants.js";
22
+ import "../../constants/axelar.constants.js";
23
+ import "../../constants/rewards.constants.js";
24
+ import "../../functions/utils/convertIntegrationProviderToExternalActionId.js";
25
+ import "../../functions/utils/userAgent.js";
26
+ class M {
27
+ contract;
28
+ eventConfig;
29
+ _latestBlockNumber;
30
+ maxPageSize;
31
+ isReady = !1;
32
+ _onNewEvent;
33
+ isServer;
34
+ intervalId;
35
+ inProgress;
36
+ // to remove race conditions
37
+ constructor(t, r, e, s, n) {
38
+ this.contract = t, this.eventConfig = r, this._latestBlockNumber = e, this.maxPageSize = n, this.isServer = s, this.inProgress = !1;
39
+ }
40
+ get latestBlockNumber() {
41
+ return this._latestBlockNumber;
42
+ }
43
+ set onNewEvent(t) {
44
+ this._onNewEvent = t;
45
+ }
46
+ intervalClear() {
47
+ this.isReady = !1, this._onNewEvent = void 0, clearInterval(this.intervalId);
48
+ }
49
+ async init() {
50
+ if (this.isReady)
51
+ throw new Error("Already initialized");
52
+ this.isReady = !0, await this.retrieveEvents(this._latestBlockNumber + 1), this.intervalId = setInterval(async () => {
53
+ await this.retrieveEvents(this.latestBlockNumber);
54
+ }, 3500);
55
+ }
56
+ requireReady() {
57
+ if (!this.isReady)
58
+ throw new Error("Not ready");
59
+ }
60
+ emitNewEvent(t) {
61
+ this._onNewEvent?.(t);
62
+ }
63
+ getLastBlockNumberForEventRequest = async () => {
64
+ const t = await this.contract.provider.getBlockNumber();
65
+ if (!this.isServer)
66
+ return t;
67
+ const { chainId: r } = await this.contract.provider.getNetwork();
68
+ return Math.max(this.latestBlockNumber, t - v[r] + 1);
69
+ };
70
+ async retrieveEvents(t, r = !1) {
71
+ try {
72
+ if (this.requireReady(), this.inProgress && !r)
73
+ return !1;
74
+ this.inProgress = !0;
75
+ const e = await this.getLastBlockNumberForEventRequest();
76
+ if (e < t)
77
+ return this.inProgress = !1, !1;
78
+ const s = m(t, e, this.maxPageSize);
79
+ return await c(
80
+ s.map(({ from: n, to: i }) => async () => {
81
+ const o = await this.contract.queryFilter(
82
+ this.contract.filters[this.eventConfig.name](),
83
+ n,
84
+ i
85
+ );
86
+ let a = [];
87
+ o.length > 0 && (a = await this.processEventsPage(o)), this._latestBlockNumber = i, await this.afterEventsAccepted(), a.length > 0 && this.emitNewEvent();
88
+ })
89
+ ), this.inProgress = !1, !0;
90
+ } catch (e) {
91
+ return console.log("retrieveEvents error:", { err: e }), this.inProgress = !1, !1;
92
+ }
93
+ }
94
+ async processEventsPage(t) {
95
+ const r = [];
96
+ return await c(
97
+ t.map((e) => async () => {
98
+ const { args: s, blockNumber: n } = e;
99
+ if (!s)
100
+ throw new Error("Wrong event structure");
101
+ const i = this.mapEvent(s);
102
+ await this.acceptEvent(i, n) && r.push(i);
103
+ })
104
+ ), r;
105
+ }
106
+ handleEvent = async (...t) => {
107
+ const { args: r } = this.eventConfig, { blockNumber: e } = t[t.length - 1], s = t.slice(0, r.length), n = r.reduce((a, h, l) => (a[h] = s[l], a), {});
108
+ if (!e)
109
+ throw new Error("Wrong event structure");
110
+ const i = this.mapEvent(n);
111
+ if (!await this.acceptEvent(i, e))
112
+ throw new Error("Failed to retrieve events");
113
+ this._latestBlockNumber = e, await this.afterEventsAccepted(), this.emitNewEvent(i);
114
+ };
115
+ }
116
+ export {
117
+ M as AbstractEventService
118
+ };
@@ -0,0 +1,59 @@
1
+ import { AbstractSnapshotService as i } from "./AbstractSnapshotService.js";
2
+ class s extends i {
3
+ constructor(e, r, l, t) {
4
+ super(
5
+ e,
6
+ {
7
+ name: "Nullified",
8
+ args: ["nullifier"]
9
+ },
10
+ r,
11
+ l,
12
+ t
13
+ );
14
+ }
15
+ _nullifiers;
16
+ get nullifiers() {
17
+ return this._nullifiers;
18
+ }
19
+ serializeSnapshot(e) {
20
+ return {
21
+ nullifiers: Array.from(e.payload.nullifiers).map((r) => r.toString()),
22
+ latestBlockNumber: e.latestBlockNumber,
23
+ reserveBlockNumber: e.reserveBlockNumber
24
+ };
25
+ }
26
+ deserializeSnapshot(e) {
27
+ return {
28
+ latestBlockNumber: e.latestBlockNumber ?? 0,
29
+ reserveBlockNumber: e.reserveBlockNumber ?? 0,
30
+ payload: {
31
+ nullifiers: new Set(e.nullifiers ?? [])
32
+ }
33
+ };
34
+ }
35
+ acceptEvent(e, r) {
36
+ try {
37
+ return this._nullifiers.add(e.nullifier), !0;
38
+ } catch (l) {
39
+ return console.error(l), !1;
40
+ }
41
+ }
42
+ mapEvent(e) {
43
+ const { nullifier: r } = e;
44
+ return {
45
+ nullifier: r.toHexString()
46
+ };
47
+ }
48
+ getSnapshotPayload() {
49
+ return {
50
+ nullifiers: this._nullifiers
51
+ };
52
+ }
53
+ populateSnapshot({ payload: { nullifiers: e } }) {
54
+ this._nullifiers = e;
55
+ }
56
+ }
57
+ export {
58
+ s as AbstractNullifierSnapshotService
59
+ };
@@ -0,0 +1,35 @@
1
+ import { AbstractEventService as o } from "./AbstractEventService.js";
2
+ class h extends o {
3
+ reserveBlockNumber;
4
+ constructor(t, e, s, r, a) {
5
+ super(t, e, s, r, a), this.reserveBlockNumber = s;
6
+ }
7
+ async init() {
8
+ await this.loadSnapshot(), await super.init();
9
+ }
10
+ async retrieveEventsFromLatestBlock() {
11
+ await super.retrieveEvents(this._latestBlockNumber);
12
+ }
13
+ async restoreSnapshotState() {
14
+ await this.retrieveEvents(this.reserveBlockNumber, !0) && (this.reserveBlockNumber = this.latestBlockNumber, await this.afterEventsAccepted());
15
+ }
16
+ async loadSnapshot() {
17
+ const t = await this.fetchSnapshot(), e = this.deserializeSnapshot(t);
18
+ this.populateSnapshot(e), this._latestBlockNumber = e.latestBlockNumber, this.reserveBlockNumber = e.reserveBlockNumber;
19
+ }
20
+ saveSnapshot() {
21
+ return this.persistSnapshot(
22
+ this.serializeSnapshot({
23
+ latestBlockNumber: this._latestBlockNumber,
24
+ reserveBlockNumber: this.reserveBlockNumber,
25
+ payload: this.getSnapshotPayload()
26
+ })
27
+ );
28
+ }
29
+ afterEventsAccepted() {
30
+ return this.saveSnapshot();
31
+ }
32
+ }
33
+ export {
34
+ h as AbstractSnapshotService
35
+ };