@gurge/sdk 0.3.27 → 0.3.29

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 (140) hide show
  1. package/common/src/crypto/BabyJubRN.cjs +1 -0
  2. package/common/src/crypto/BabyJubRN.d.ts +2 -0
  3. package/common/src/crypto/BabyJubRN.mjs +66 -0
  4. package/common/src/crypto/EddsaRN.cjs +1 -0
  5. package/common/src/crypto/EddsaRN.mjs +41 -0
  6. package/common/src/crypto/babyJub.cjs +1 -1
  7. package/common/src/crypto/babyJub.mjs +6 -12
  8. package/common/src/crypto/eddsa.cjs +1 -1
  9. package/common/src/crypto/eddsa.mjs +6 -12
  10. package/common/src/crypto/poseidon.cjs +1 -1
  11. package/common/src/crypto/poseidon.mjs +6 -12
  12. package/common/src/crypto/preProcessing.cjs +1 -1
  13. package/common/src/crypto/preProcessing.mjs +13 -23
  14. package/common/src/data-structures/Hinkal/handleAutoDepositBack.cjs +1 -1
  15. package/common/src/data-structures/Hinkal/handleAutoDepositBack.mjs +9 -9
  16. package/common/src/data-structures/Hinkal/hinkalClaimUtxo.cjs +1 -1
  17. package/common/src/data-structures/Hinkal/hinkalClaimUtxo.mjs +6 -6
  18. package/common/src/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
  19. package/common/src/data-structures/Hinkal/hinkalDeposit.mjs +1 -1
  20. package/common/src/data-structures/Hinkal/hinkalDepositAndBridge.cjs +1 -1
  21. package/common/src/data-structures/Hinkal/hinkalDepositAndBridge.mjs +18 -18
  22. package/common/src/data-structures/Hinkal/hinkalDepositAndWithdraw.cjs +1 -1
  23. package/common/src/data-structures/Hinkal/hinkalDepositAndWithdraw.mjs +17 -17
  24. package/common/src/data-structures/Hinkal/hinkalPrivateWallet.cjs +1 -1
  25. package/common/src/data-structures/Hinkal/hinkalPrivateWallet.mjs +13 -13
  26. package/common/src/data-structures/Hinkal/hinkalSolanaClaimUtxo.cjs +1 -1
  27. package/common/src/data-structures/Hinkal/hinkalSolanaClaimUtxo.mjs +11 -11
  28. package/common/src/data-structures/Hinkal/hinkalSolanaDeposit.cjs +1 -1
  29. package/common/src/data-structures/Hinkal/hinkalSolanaDeposit.mjs +14 -14
  30. package/common/src/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.cjs +1 -1
  31. package/common/src/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.mjs +51 -51
  32. package/common/src/data-structures/Hinkal/hinkalSolanaSwap.cjs +1 -1
  33. package/common/src/data-structures/Hinkal/hinkalSolanaSwap.mjs +51 -51
  34. package/common/src/data-structures/Hinkal/hinkalSolanaTransfer.cjs +1 -1
  35. package/common/src/data-structures/Hinkal/hinkalSolanaTransfer.mjs +20 -20
  36. package/common/src/data-structures/Hinkal/hinkalSolanaWithdraw.cjs +1 -1
  37. package/common/src/data-structures/Hinkal/hinkalSolanaWithdraw.mjs +19 -19
  38. package/common/src/data-structures/Hinkal/hinkalSwap.cjs +1 -1
  39. package/common/src/data-structures/Hinkal/hinkalSwap.mjs +1 -1
  40. package/common/src/data-structures/Hinkal/hinkalTransfer.cjs +1 -1
  41. package/common/src/data-structures/Hinkal/hinkalTransfer.mjs +9 -9
  42. package/common/src/data-structures/Hinkal/hinkalWithdraw.cjs +1 -1
  43. package/common/src/data-structures/Hinkal/hinkalWithdraw.d.ts +3 -1
  44. package/common/src/data-structures/Hinkal/hinkalWithdraw.mjs +29 -34
  45. package/common/src/data-structures/Hinkal/hinkalWithdrawStuckUtxos.cjs +1 -1
  46. package/common/src/data-structures/Hinkal/hinkalWithdrawStuckUtxos.mjs +33 -33
  47. package/common/src/data-structures/Hinkal/prepareDepositOnChainUtxosZkProof.cjs +1 -1
  48. package/common/src/data-structures/Hinkal/prepareDepositOnChainUtxosZkProof.mjs +1 -1
  49. package/common/src/data-structures/MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.cjs +1 -1
  50. package/common/src/data-structures/MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.mjs +26 -42
  51. package/common/src/data-structures/crypto-keys/decodeUTXO.cjs +1 -1
  52. package/common/src/data-structures/crypto-keys/decodeUTXO.mjs +7 -7
  53. package/common/src/data-structures/crypto-keys/encryptDecryptUtxo.cjs +1 -1
  54. package/common/src/data-structures/crypto-keys/encryptDecryptUtxo.mjs +1 -1
  55. package/common/src/data-structures/utxo/Utxo.cjs +1 -1
  56. package/common/src/data-structures/utxo/Utxo.d.ts +0 -1
  57. package/common/src/data-structures/utxo/Utxo.mjs +6 -19
  58. package/common/src/functions/index.cjs +1 -1
  59. package/common/src/functions/index.mjs +4 -3
  60. package/common/src/functions/pre-transaction/buildCommitmentValidationData.cjs +1 -1
  61. package/common/src/functions/pre-transaction/buildCommitmentValidationData.mjs +46 -87
  62. package/common/src/functions/pre-transaction/outputUtxoProcessing.cjs +1 -1
  63. package/common/src/functions/pre-transaction/outputUtxoProcessing.d.ts +2 -2
  64. package/common/src/functions/pre-transaction/outputUtxoProcessing.mjs +23 -28
  65. package/common/src/functions/private-wallet/emporium.swap.helpers.cjs +1 -1
  66. package/common/src/functions/private-wallet/emporium.swap.helpers.mjs +14 -14
  67. package/common/src/functions/snarkjs/common.snarkjs.cjs +1 -1
  68. package/common/src/functions/snarkjs/common.snarkjs.mjs +7 -7
  69. package/common/src/functions/snarkjs/constructGeneralZkProof.cjs +1 -1
  70. package/common/src/functions/snarkjs/constructGeneralZkProof.mjs +57 -61
  71. package/common/src/functions/snarkjs/constructSolanaZkProof.cjs +1 -1
  72. package/common/src/functions/snarkjs/constructSolanaZkProof.mjs +60 -60
  73. package/common/src/functions/snarkjs/verifyCommitmentValidationData.cjs +1 -1
  74. package/common/src/functions/snarkjs/verifyCommitmentValidationData.mjs +1 -1
  75. package/common/src/functions/utils/bigint-math.utils.cjs +1 -1
  76. package/common/src/functions/utils/bigint-math.utils.d.ts +2 -0
  77. package/common/src/functions/utils/bigint-math.utils.mjs +18 -1
  78. package/common/src/functions/utils/buildClaimableDepositPlan.cjs +1 -1
  79. package/common/src/functions/utils/buildClaimableDepositPlan.mjs +1 -1
  80. package/common/src/functions/utils/getUtxosFromReceipt.utils.cjs +1 -1
  81. package/common/src/functions/utils/getUtxosFromReceipt.utils.mjs +1 -1
  82. package/common/src/functions/utils/getUtxosFromReceiptSolana.cjs +1 -1
  83. package/common/src/functions/utils/getUtxosFromReceiptSolana.mjs +4 -4
  84. package/common/src/functions/utils/hinkalTiming.utils.cjs +1 -1
  85. package/common/src/functions/utils/hinkalTiming.utils.d.ts +3 -9
  86. package/common/src/functions/utils/hinkalTiming.utils.mjs +13 -18
  87. package/common/src/functions/utils/index.cjs +1 -1
  88. package/common/src/functions/utils/index.mjs +3 -3
  89. package/common/src/functions/web3/events/getInputUtxoAndBalance.cjs +1 -1
  90. package/common/src/functions/web3/events/getInputUtxoAndBalance.mjs +71 -122
  91. package/common/src/functions/web3/events/getShieldedBalance.cjs +1 -1
  92. package/common/src/functions/web3/events/getShieldedBalance.mjs +64 -64
  93. package/common/src/functions/web3/functionCalls/transactCallRelayer.cjs +1 -1
  94. package/common/src/functions/web3/functionCalls/transactCallRelayer.mjs +42 -42
  95. package/common/src/types/index.cjs +1 -1
  96. package/common/src/types/index.mjs +1 -1
  97. package/common/src/webworker/logError-D8yBaP96.js +2 -0
  98. package/common/src/webworker/package.json +1 -1
  99. package/common/src/webworker/performTaskWithWorker.cjs +1 -1
  100. package/common/src/webworker/performTaskWithWorker.mjs +17 -18
  101. package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.cjs +1 -1
  102. package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.mjs +1 -1
  103. package/common/src/webworker/utxoWorkerNode.cjs +1 -1
  104. package/common/src/webworker/viteWorkerURL.constant.cjs +3 -4
  105. package/common/src/webworker/viteWorkerURL.constant.d.ts +0 -1
  106. package/common/src/webworker/viteWorkerURL.constant.mjs +3 -4
  107. package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.cjs +1 -1
  108. package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.mjs +1 -1
  109. package/common/src/webworker/zkProofWorkerNode.cjs +1 -1
  110. package/package.json +1 -1
  111. package/react-native/HinkalWebViewWorker.cjs +4 -76
  112. package/react-native/HinkalWebViewWorker.mjs +49 -152
  113. package/react-native/bridge/HinkalRNWorker.cjs +1 -1
  114. package/react-native/bridge/HinkalRNWorker.d.ts +0 -1
  115. package/react-native/bridge/HinkalRNWorker.mjs +11 -16
  116. package/react-native/shims/circomlibjs-hinkal-fork.js +2 -2
  117. package/react-native/shims/circomlibjs.js +2 -2
  118. package/react-native/workerCDNUrls.cjs +1 -1
  119. package/react-native/workerCDNUrls.d.ts +0 -1
  120. package/react-native/workerCDNUrls.mjs +2 -2
  121. package/sdk/package.json.cjs +1 -1
  122. package/sdk/package.json.mjs +1 -1
  123. package/common/src/crypto/rnCryptoBridge.cjs +0 -1
  124. package/common/src/crypto/rnCryptoBridge.d.ts +0 -8
  125. package/common/src/crypto/rnCryptoBridge.mjs +0 -10
  126. package/common/src/crypto/rnUtxoCrypto.cjs +0 -1
  127. package/common/src/crypto/rnUtxoCrypto.d.ts +0 -25
  128. package/common/src/crypto/rnUtxoCrypto.mjs +0 -74
  129. package/common/src/functions/utils/utxoPadding.utils.cjs +0 -1
  130. package/common/src/functions/utils/utxoPadding.utils.d.ts +0 -2
  131. package/common/src/functions/utils/utxoPadding.utils.mjs +0 -14
  132. package/common/src/webworker/cryptoWorker/cryptoWorker.types.cjs +0 -1
  133. package/common/src/webworker/cryptoWorker/cryptoWorker.types.d.ts +0 -51
  134. package/common/src/webworker/cryptoWorker/cryptoWorker.types.mjs +0 -6
  135. package/common/src/webworker/cryptoWorker/cryptoWorkerLauncher.d.ts +0 -1
  136. package/common/src/webworker/cryptoWorker/cryptoWorkerLogic.d.ts +0 -2
  137. package/common/src/webworker/logError-Dy_GXEF5.js +0 -2
  138. package/react-native/bridge/RnWebViewCryptoBridge.cjs +0 -1
  139. package/react-native/bridge/RnWebViewCryptoBridge.d.ts +0 -7
  140. package/react-native/bridge/RnWebViewCryptoBridge.mjs +0 -49
@@ -1,109 +1,58 @@
1
1
  import { isSolanaLike as e, isTronLike as t } from "../../../constants/chains.constants.mjs";
2
2
  import { caseInsensitiveEqual as n } from "../../utils/caseInsensitive.utils.mjs";
3
- import { getSpendingPublicKeyForRn as r } from "../../../crypto/rnUtxoCrypto.mjs";
4
- import { createPaddingUtxos as i } from "../../utils/utxoPadding.utils.mjs";
5
- import { checkAddressNotUpdated as a } from "../../utils/upToDateState.mjs";
6
- import { getHinkalCache as o, resetCache as s, setHinkalCache as c } from "../../utils/cacheFunctions.mjs";
7
- import { encodeTokenWithId as l } from "../../utils/encodeTokenWithId.mjs";
8
- import { formatMintAddress as u } from "../../utils/solanaMint.utils.mjs";
9
- import { getInputUtxosEnclave as d } from "./getInputUtxosEnclave.mjs";
10
- import { hashEthereumAddress as f } from "../../utils/addresses.mjs";
11
- import { getScheduledTransactionsNullifierIndexes as p } from "../../../API/scheduled-transactions-calls.mjs";
12
- import { addressToHexFormat as m } from "../../utils/tron.utils.mjs";
13
- import { createRnDeltaTiming as h } from "../../utils/hinkalTiming.utils.mjs";
14
- import { Mutex as g } from "async-mutex";
3
+ import { Utxo as r } from "../../../data-structures/utxo/Utxo.mjs";
4
+ import { checkAddressNotUpdated as i } from "../../utils/upToDateState.mjs";
5
+ import { getHinkalCache as a, resetCache as o, setHinkalCache as s } from "../../utils/cacheFunctions.mjs";
6
+ import { encodeTokenWithId as c } from "../../utils/encodeTokenWithId.mjs";
7
+ import { formatMintAddress as l } from "../../utils/solanaMint.utils.mjs";
8
+ import { getInputUtxosEnclave as u } from "./getInputUtxosEnclave.mjs";
9
+ import { hashEthereumAddress as d } from "../../utils/addresses.mjs";
10
+ import { getScheduledTransactionsNullifierIndexes as f } from "../../../API/scheduled-transactions-calls.mjs";
11
+ import { addressToHexFormat as p } from "../../utils/tron.utils.mjs";
12
+ import { Mutex as m } from "async-mutex";
15
13
  //#region libs/shared/common/src/functions/web3/events/getInputUtxoAndBalance.ts
16
- var _ = new g(), v = async (e, t) => {
17
- if (e.allowParallelBalanceLocalDecryption) return t();
18
- let n = h("utxoPrep.mutex");
19
- return _.isLocked() && n.log("waiting-for-lock"), _.runExclusive(async () => {
20
- n.log("lock-acquired");
21
- try {
22
- return await t();
23
- } finally {
24
- n.log("lock-released");
25
- }
26
- });
27
- }, y = async (e, t, n, r, i, o, s, l, u) => v(e, async () => {
28
- let d = h("utxoPrep.decrypt");
14
+ var h = new m(), g = async (e, t) => e.allowParallelBalanceLocalDecryption ? t() : h.runExclusive(t), _ = async (e, t, n, r, a, o, c, l, u) => g(e, async () => {
29
15
  u += 1;
30
- let f = o.slice(u);
31
- d.log("batchProcess-start", {
32
- outputsSlice: f.length,
33
- cached: s.length
34
- });
35
- let { lastOutput: p, additionalEncryptedOutputs: m } = await e.utxoUtils.batchProcess(f, l, t, n);
36
- d.log("batchProcess-done", { additionalEncryptedOutputs: m.length });
37
- let g = [...s, ...m], _ = h("wallet.checkAddress");
38
- await a(e, r), _.log("during-decrypt"), c({
39
- lastOutput: p,
40
- encryptedOutputs: g
41
- }, e, n, i), d.log("cache-write", { encryptedOutputs: g.length });
42
- let v = await e.utxoUtils.buildBatchProcess(g, t, n);
43
- return d.log("buildBatchProcess-done", { utxoCount: v.length }), v;
44
- }), b = async (e, t, n, r) => {
45
- let { utxos: i, encryptedOutputs: a, lastOutput: o } = await d(e, n, t);
46
- return c({
16
+ let d = o.slice(u), { lastOutput: f, additionalEncryptedOutputs: p } = await e.utxoUtils.batchProcess(d, l, t, n), m = [...c, ...p];
17
+ return await i(e, r), s({
18
+ lastOutput: f,
19
+ encryptedOutputs: m
20
+ }, e, n, a), await e.utxoUtils.buildBatchProcess(m, t, n);
21
+ }), v = async (e, t, n, r) => {
22
+ let { utxos: i, encryptedOutputs: a, lastOutput: o } = await u(e, n, t);
23
+ return s({
47
24
  encryptedOutputs: a,
48
25
  lastOutput: o
49
26
  }, e, n, r), i;
50
- }, x = async (e, t, n, r, i, a, o, s, c) => {
27
+ }, y = async (e, t, n, r, i, a, o, s, c) => {
51
28
  try {
52
- return await b(e, t, n, i);
29
+ return await v(e, t, n, i);
53
30
  } catch {
54
- return y(e, t, n, r, i, a, o, s, c);
31
+ return _(e, t, n, r, i, a, o, s, c);
55
32
  }
56
- }, S = (e) => {
33
+ }, b = (e) => {
57
34
  if (Array.isArray(e)) return e;
58
35
  if (e !== void 0) return [e];
59
- }, C = async (e, t, n) => await e.utxoUtils.batchFilterUtxosWithNullifier(t, n), w = async (e, t, n, r, a, o, s, c) => {
60
- for (e.sort((e, t) => e.amount <= t.amount ? 1 : -1); e.length < t || e.length > t && e.length < 6;) {
61
- let [t] = await i(1, {
62
- amount: 0n,
63
- erc20TokenAddress: o,
64
- mintAddress: c,
65
- nullifyingKey: r,
66
- spendingPublicKey: a,
67
- isNewStyle: !0
68
- });
69
- if (e.push(t), n) for (; e.length > 6;) e.splice(e.length - 1);
70
- }
71
- }, T = async ({ hinkal: e, chainId: t, passedShieldedPublicKey: n = void 0, ethAddress: r = void 0, resetCacheBefore: i = !1, allowRemoteDecryption: c = !1, useBlockedUtxos: l = !1 }) => {
72
- let u = h("utxoPrep");
73
- u.log("start");
74
- let d = r;
75
- d ? u.log("wallet.getEthereumAddress-skipped", { ethAddressPassed: !0 }) : (d = await e.getEthereumAddress(), u.log("wallet.getEthereumAddress"));
76
- let f = n ?? e.userKeys.getShieldedPublicKey(), { userKeys: p } = e, m = e.encryptedOutputsByChain[t], g = e.nullifiersByChain[t], _ = Array.from(m);
77
- i && s(e, t, f);
78
- let { encryptedOutputs: v, lastOutput: b } = o(e, t, f);
79
- u.log("cache.read", { cachedEncryptedOutputs: v.length });
80
- let S = h("wallet.checkAddress");
81
- await a(e, d), S.log("before-decrypt");
82
- let w = b !== "", T = _.findIndex((e) => e.value === b);
83
- u.log("findLastOutputIndex", {
84
- hinkalOutputs: _.length,
85
- lastOutputIndex: T
86
- });
87
- let E = T > -1, D = !w && T === -1, O = e.areMerkleTreeUpdatesDisabled(), k = !O && (E || !c && D), A = !O && c && D, j = !k && !A;
88
- u.log("branch", {
89
- decryptLocally: k,
90
- decryptRemotely: A,
91
- useCache: j,
92
- outputsSlice: T > -1 ? _.length - (T + 1) : 0
93
- });
94
- let M = [];
95
- k ? (M = await y(e, p, t, d, f, _, v, b, T), u.log("decryptLocally-done", { utxoCount: M.length })) : A ? (M = await x(e, p, t, d, f, _, v, b, T), u.log("decryptRemotely-done", { utxoCount: M.length })) : j && (M = await e.utxoUtils.buildBatchProcess(v, p, t), u.log("useCache-buildBatchProcess-done", { utxoCount: M.length }));
96
- let N = h("wallet.checkAddress");
97
- await a(e, d), N.log("after-decrypt");
98
- let P = await C(e, M, g);
99
- u.log("filterSpentUtxos", {
100
- allUtxos: M.length,
101
- inputUtxos: P.length
102
- });
103
- let F = l ? P.filter((e) => e.isBlocked) : P.filter((e) => !e.isBlocked);
104
- return u.log("done", { inputUtxos: F.length }), { inputUtxos: F };
105
- }, E = async ({ hinkal: e, chainId: n, passedShieldedPublicKey: r = void 0, ethAddress: i = void 0, resetCacheBefore: a = !1, allowRemoteDecryption: o = !1 }) => {
106
- let s = i ?? await e.getEthereumAddressByChain(n), c = f(t(n) ? m(s) : s), { inputUtxos: l } = await T({
36
+ }, x = async (e, t, n) => await e.utxoUtils.batchFilterUtxosWithNullifier(t, n), S = (e, t, n, i, a, o, s, c) => {
37
+ for (e.sort((e, t) => e.amount <= t.amount ? 1 : -1); e.length < t || e.length > t && e.length < 6;) if (e.push(new r({
38
+ amount: 0n,
39
+ erc20TokenAddress: o,
40
+ mintAddress: c,
41
+ nullifyingKey: i,
42
+ spendingPublicKey: a,
43
+ isNewStyle: !0
44
+ })), n) for (; e.length > 6;) e.splice(e.length - 1);
45
+ }, C = async ({ hinkal: e, chainId: t, passedShieldedPublicKey: n = void 0, ethAddress: r = void 0, resetCacheBefore: s = !1, allowRemoteDecryption: c = !1, useBlockedUtxos: l = !1 }) => {
46
+ let u = r ?? await e.getEthereumAddress(), d = n ?? e.userKeys.getShieldedPublicKey(), { userKeys: f } = e, p = e.encryptedOutputsByChain[t], m = e.nullifiersByChain[t], h = Array.from(p);
47
+ s && o(e, t, d);
48
+ let { encryptedOutputs: g, lastOutput: v } = a(e, t, d);
49
+ await i(e, u);
50
+ let b = v !== "", S = h.findIndex((e) => e.value === v), C = S > -1, w = !b && S === -1, T = e.areMerkleTreeUpdatesDisabled(), E = !T && (C || !c && w), D = !T && c && w, O = !E && !D, k = [];
51
+ E ? k = await _(e, f, t, u, d, h, g, v, S) : D ? k = await y(e, f, t, u, d, h, g, v, S) : O && (k = await e.utxoUtils.buildBatchProcess(g, f, t)), await i(e, u);
52
+ let A = await x(e, k, m);
53
+ return { inputUtxos: l ? A.filter((e) => e.isBlocked) : A.filter((e) => !e.isBlocked) };
54
+ }, w = async ({ hinkal: e, chainId: n, passedShieldedPublicKey: r = void 0, ethAddress: i = void 0, resetCacheBefore: a = !1, allowRemoteDecryption: o = !1 }) => {
55
+ let s = i ?? await e.getEthereumAddressByChain(n), c = d(t(n) ? p(s) : s), { inputUtxos: l } = await C({
107
56
  hinkal: e,
108
57
  chainId: n,
109
58
  passedShieldedPublicKey: r,
@@ -113,51 +62,51 @@ var _ = new g(), v = async (e, t) => {
113
62
  useBlockedUtxos: !0
114
63
  });
115
64
  if (!l.length) return { inputUtxos: [] };
116
- let { indexes: u } = await p({
65
+ let { indexes: u } = await f({
117
66
  hashedEthereumAddress: c,
118
67
  nullifiers: l.map((e) => e.getNullifier())
119
68
  });
120
69
  return { inputUtxos: u.map((e) => l[e]).filter((e) => !!e) };
121
- }, D = async ({ hinkal: t, tokenWithId: i, minInput: a = 2, sliceIfMore6: o = !0, chainId: s, passedShieldedPrivateKey: c = void 0, passedShieldedPublicKey: d = void 0, ethAddress: f = void 0, resetCacheBefore: p = !1, ensuredTokensWithId: m, allowRemoteDecryption: h = !1, useBlockedUtxos: g = !1 }) => {
122
- let _ = c ?? t.userKeys.getShieldedPrivateKey(), v = await r(t.userKeys), { inputUtxos: y } = g ? await E({
70
+ }, T = async ({ hinkal: t, tokenWithId: r, minInput: i = 2, sliceIfMore6: a = !0, chainId: o, passedShieldedPrivateKey: s = void 0, passedShieldedPublicKey: u = void 0, ethAddress: d = void 0, resetCacheBefore: f = !1, ensuredTokensWithId: p, allowRemoteDecryption: m = !1, useBlockedUtxos: h = !1 }) => {
71
+ let g = s ?? t.userKeys.getShieldedPrivateKey(), _ = t.userKeys.getSpendingKeyPair().pubSpendingBJJPoint, { inputUtxos: v } = h ? await w({
123
72
  hinkal: t,
124
- chainId: s,
125
- ethAddress: f,
126
- passedShieldedPrivateKey: c,
127
- resetCacheBefore: p,
128
- allowRemoteDecryption: h
129
- }) : await T({
73
+ chainId: o,
74
+ ethAddress: d,
75
+ passedShieldedPrivateKey: s,
76
+ resetCacheBefore: f,
77
+ allowRemoteDecryption: m
78
+ }) : await C({
130
79
  hinkal: t,
131
- tokenWithId: i,
132
- minInput: a,
133
- sliceIfMore6: o,
134
- chainId: s,
135
- passedShieldedPrivateKey: c,
136
- passedShieldedPublicKey: d,
137
- ethAddress: f,
138
- resetCacheBefore: p,
139
- allowRemoteDecryption: h
140
- }), b = S(i), x = /* @__PURE__ */ new Map();
141
- y.forEach((e) => {
142
- let t = e.getTokenAddress(s);
143
- if (b && !b.some((e) => n(e.erc20TokenAddress, t))) return;
144
- let r = l(s, {
80
+ tokenWithId: r,
81
+ minInput: i,
82
+ sliceIfMore6: a,
83
+ chainId: o,
84
+ passedShieldedPrivateKey: s,
85
+ passedShieldedPublicKey: u,
86
+ ethAddress: d,
87
+ resetCacheBefore: f,
88
+ allowRemoteDecryption: m
89
+ }), y = b(r), x = /* @__PURE__ */ new Map();
90
+ v.forEach((e) => {
91
+ let t = e.getTokenAddress(o);
92
+ if (y && !y.some((e) => n(e.erc20TokenAddress, t))) return;
93
+ let r = c(o, {
145
94
  erc20TokenAddress: t,
146
95
  tokenId: 0
147
96
  }), i = x.get(r) ?? [];
148
97
  x.set(r, [...i, e]);
149
- }), m?.forEach((e) => {
150
- let t = l(s, {
98
+ }), p?.forEach((e) => {
99
+ let t = c(o, {
151
100
  erc20TokenAddress: e.erc20TokenAddress,
152
101
  tokenId: 0
153
102
  });
154
103
  x.set(t, x.get(t) ?? []);
155
104
  });
156
105
  for (let [t, n] of x) {
157
- let r = t.split("-")[0], i = Number(t.split("-")[1]), c = e(s), l = c ? r : void 0;
158
- await w(n, a, o, _, v, c ? u(r).compressedAddress.toLowerCase() : r.toLowerCase(), i, l);
106
+ let r = t.split("-")[0], s = Number(t.split("-")[1]), c = e(o), u = c ? r : void 0;
107
+ S(n, i, a, g, _, c ? l(r).compressedAddress.toLowerCase() : r.toLowerCase(), s, u);
159
108
  }
160
109
  return x;
161
110
  };
162
111
  //#endregion
163
- export { x as attemptGetInputUtxosRemotely, T as getInputUtxoAndBalance, E as getInputUtxoAndBalanceOfStuckUtxos, D as getInputUtxoAndBalancePerToken, b as getInputUtxosRemotely };
112
+ export { y as attemptGetInputUtxosRemotely, C as getInputUtxoAndBalance, w as getInputUtxoAndBalanceOfStuckUtxos, T as getInputUtxoAndBalancePerToken, v as getInputUtxosRemotely };
@@ -1 +1 @@
1
- require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/vite.constants.cjs`),t=require(`../../../constants/chains.constants.cjs`),n=require(`../../utils/caseInsensitive.utils.cjs`),r=require(`../../../error-handling/error-codes.constants.cjs`),i=require(`../etherFunctions.cjs`),a=require(`../../../crypto/rnUtxoCrypto.cjs`),o=require(`../../utils/utxoPadding.utils.cjs`),s=require(`../../../error-handling/customErrors/ErrorWithAmount.cjs`);require(`../../../error-handling/customErrors/index.cjs`);const c=require(`../../utils/encodeTokenWithId.cjs`),l=require(`../../utils/solanaMint.utils.cjs`),u=require(`./getInputUtxoAndBalance.cjs`),d=require(`../../../data-structures/TokenDBs/PrivateTokensDB.cjs`),f=require(`../../utils/map.utils.cjs`),p=require(`../../utils/mutexes.utils.cjs`),m=require(`../../utils/erc20tokenFunctions.cjs`);let h=require(`async-mutex`);var g=async(t,r,i,a,o,s=!1,c,l=!1,g=!1)=>f.getOrCreateMapValue(t.balanceFetchingMutexByChain,r,()=>new h.Mutex).runExclusive(async()=>p.getChainBalanceFetchingMutex(r).runShared(async()=>{let{inputUtxos:f}=g?await u.getInputUtxoAndBalanceOfStuckUtxos({hinkal:t,chainId:r,ethAddress:o,passedShieldedPrivateKey:i,resetCacheBefore:s,allowRemoteDecryption:c}):await u.getInputUtxoAndBalance({hinkal:t,sliceIfMore6:!1,chainId:r,passedShieldedPrivateKey:i,passedShieldedPublicKey:a,ethAddress:o,resetCacheBefore:s,allowRemoteDecryption:c});l&&e.isExtension&&await d.privateTokensDB.fetchAndUpdatePrivateTokens(f.map(e=>e.getTokenAddress(r)).filter(e=>e!==void 0),r,o);let p=(e.isExtension?await d.privateTokensDB.getPrivateTokens(r,o):await m.getErc20TokensForChainAPI(r)).map(e=>({token:e,balance:f.reduce((t,i)=>{let a=e.erc20TokenAddress;return n.caseInsensitiveEqual(a,i.getTokenAddress(r))?t+i.amount:t},0n),timestamp:f.filter(t=>n.caseInsensitiveEqual(t.getTokenAddress(r),e.erc20TokenAddress))[0]?.timeStamp,nfts:[]})),h=new Map;return p.forEach(e=>{h.set(e.token.erc20TokenAddress.toLowerCase(),e)}),h})),_=async(e,n,d,f,p=6,h=d.map(()=>0),g=!1,_=!1)=>{let{userKeys:v}=e,y=await a.getSpendingPublicKeyForRn(v),b=[],x=[];if(d.length===0)return[];if(g){for(let e=0;e<d.length;e+=1){let r=t.isSolanaLike(n),i=r?d[e]:void 0,a=r?l.formatMintAddress(d[e]).compressedAddress:d[e];b.push(await o.createPaddingUtxos(p,{amount:0n,erc20TokenAddress:a,mintAddress:i,nullifyingKey:v.getShieldedPrivateKey(),spendingPublicKey:y,isNewStyle:!0}))}return b}let S=await u.getInputUtxoAndBalancePerToken({hinkal:e,sliceIfMore6:!1,ensuredTokensWithId:d.map((e,t)=>({erc20TokenAddress:d[t],tokenId:h[t]})),allowRemoteDecryption:e.generateProofRemotely,useBlockedUtxos:_,chainId:n}),C=0;for(let e=0;e<d.length;e+=1){let t=S.get(c.encodeTokenWithId(n,{erc20TokenAddress:d[e],tokenId:h[e]}))??[];if(!t)throw Error(`Missing utxos for token`);C=Math.max(t.length,C),x.push(t)}if(C===2)return x;for(let[e,a]of x.entries())if(a.length>p){let t=a.slice(0,p),o=t.reduce((e,t)=>e+t.amount,0n);if(f[e]<0n&&o<-f[e]){let t=await m.getErc20TokenFromAPI(n,d[e]);if(!t)throw Error(`Token not found`);let a=t.decimals===18?6:2,c=Number(i.getAmountWithPrecision(o,t,a));throw new s.ErrorWithAmount(c,`${r.DIRECTLY_SHOW_MESSAGE_ERROR_CODES.UTXO_LIMITATIONS}. Please try again with ${c} ${t.symbol}, including gas fees.`)}b.push(t)}else if(a.length<=p){let r=[...a],i=p-a.length;if(i>0){let a=t.isSolanaLike(n),s=a?d[e]:void 0,c=a?l.formatMintAddress(d[e]).compressedAddress:d[e];r.push(...await o.createPaddingUtxos(i,{amount:0n,erc20TokenAddress:c,mintAddress:s,nullifyingKey:v.getShieldedPrivateKey(),spendingPublicKey:y,isNewStyle:!0}))}b.push(r)}return b};exports.addPaddingToUtxos=_,exports.getShieldedBalance=g;
1
+ require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/vite.constants.cjs`),t=require(`../../../constants/chains.constants.cjs`),n=require(`../../utils/caseInsensitive.utils.cjs`),r=require(`../../../error-handling/error-codes.constants.cjs`),i=require(`../etherFunctions.cjs`),a=require(`../../../data-structures/utxo/Utxo.cjs`),o=require(`../../../error-handling/customErrors/ErrorWithAmount.cjs`);require(`../../../error-handling/customErrors/index.cjs`);const s=require(`../../utils/encodeTokenWithId.cjs`),c=require(`../../utils/solanaMint.utils.cjs`),l=require(`./getInputUtxoAndBalance.cjs`),u=require(`../../../data-structures/TokenDBs/PrivateTokensDB.cjs`),d=require(`../../utils/map.utils.cjs`),f=require(`../../utils/mutexes.utils.cjs`),p=require(`../../utils/erc20tokenFunctions.cjs`);let m=require(`async-mutex`);var h=async(t,r,i,a,o,s=!1,c,h=!1,g=!1)=>d.getOrCreateMapValue(t.balanceFetchingMutexByChain,r,()=>new m.Mutex).runExclusive(async()=>f.getChainBalanceFetchingMutex(r).runShared(async()=>{let{inputUtxos:d}=g?await l.getInputUtxoAndBalanceOfStuckUtxos({hinkal:t,chainId:r,ethAddress:o,passedShieldedPrivateKey:i,resetCacheBefore:s,allowRemoteDecryption:c}):await l.getInputUtxoAndBalance({hinkal:t,sliceIfMore6:!1,chainId:r,passedShieldedPrivateKey:i,passedShieldedPublicKey:a,ethAddress:o,resetCacheBefore:s,allowRemoteDecryption:c});h&&e.isExtension&&await u.privateTokensDB.fetchAndUpdatePrivateTokens(d.map(e=>e.getTokenAddress(r)).filter(e=>e!==void 0),r,o);let f=(e.isExtension?await u.privateTokensDB.getPrivateTokens(r,o):await p.getErc20TokensForChainAPI(r)).map(e=>({token:e,balance:d.reduce((t,i)=>{let a=e.erc20TokenAddress;return n.caseInsensitiveEqual(a,i.getTokenAddress(r))?t+i.amount:t},0n),timestamp:d.filter(t=>n.caseInsensitiveEqual(t.getTokenAddress(r),e.erc20TokenAddress))[0]?.timeStamp,nfts:[]})),m=new Map;return f.forEach(e=>{m.set(e.token.erc20TokenAddress.toLowerCase(),e)}),m})),g=async(e,n,u,d,f=6,m=u.map(()=>0),h=!1,g=!1)=>{let{userKeys:_}=e,v=_.getSpendingKeyPair().pubSpendingBJJPoint,y=[],b=[];if(u.length===0)return[];if(h){for(let e=0;e<u.length;e+=1){let r=t.isSolanaLike(n),i=r?u[e]:void 0,o=r?c.formatMintAddress(u[e]).compressedAddress:u[e];y.push(Array.from({length:f},()=>new a.Utxo({amount:0n,erc20TokenAddress:o,mintAddress:i,nullifyingKey:_.getShieldedPrivateKey(),spendingPublicKey:v,isNewStyle:!0})))}return y}let x=await l.getInputUtxoAndBalancePerToken({hinkal:e,sliceIfMore6:!1,ensuredTokensWithId:u.map((e,t)=>({erc20TokenAddress:u[t],tokenId:m[t]})),allowRemoteDecryption:e.generateProofRemotely,useBlockedUtxos:g,chainId:n}),S=0;for(let e=0;e<u.length;e+=1){let t=x.get(s.encodeTokenWithId(n,{erc20TokenAddress:u[e],tokenId:m[e]}))??[];if(!t)throw Error(`Missing utxos for token`);S=Math.max(t.length,S),b.push(t)}if(S===2)return b;for(let[e,s]of b.entries())if(s.length>f){let t=s.slice(0,f),a=t.reduce((e,t)=>e+t.amount,0n);if(d[e]<0n&&a<-d[e]){let t=await p.getErc20TokenFromAPI(n,u[e]);if(!t)throw Error(`Token not found`);let s=t.decimals===18?6:2,c=Number(i.getAmountWithPrecision(a,t,s));throw new o.ErrorWithAmount(c,`${r.DIRECTLY_SHOW_MESSAGE_ERROR_CODES.UTXO_LIMITATIONS}. Please try again with ${c} ${t.symbol}, including gas fees.`)}y.push(t)}else if(s.length<=f){let r=[...s],i=f-s.length;for(;i>0;){--i;let o=t.isSolanaLike(n),s=o?u[e]:void 0,l=o?c.formatMintAddress(u[e]).compressedAddress:u[e];r.push(new a.Utxo({amount:0n,erc20TokenAddress:l,mintAddress:s,nullifyingKey:_.getShieldedPrivateKey(),spendingPublicKey:v,isNewStyle:!0}))}y.push(r)}return y};exports.addPaddingToUtxos=g,exports.getShieldedBalance=h;
@@ -3,28 +3,27 @@ import { isSolanaLike as t } from "../../../constants/chains.constants.mjs";
3
3
  import { caseInsensitiveEqual as n } from "../../utils/caseInsensitive.utils.mjs";
4
4
  import { DIRECTLY_SHOW_MESSAGE_ERROR_CODES as r } from "../../../error-handling/error-codes.constants.mjs";
5
5
  import { getAmountWithPrecision as i } from "../etherFunctions.mjs";
6
- import { getSpendingPublicKeyForRn as a } from "../../../crypto/rnUtxoCrypto.mjs";
7
- import { createPaddingUtxos as o } from "../../utils/utxoPadding.utils.mjs";
8
- import { ErrorWithAmount as s } from "../../../error-handling/customErrors/ErrorWithAmount.mjs";
6
+ import { Utxo as a } from "../../../data-structures/utxo/Utxo.mjs";
7
+ import { ErrorWithAmount as o } from "../../../error-handling/customErrors/ErrorWithAmount.mjs";
9
8
  import "../../../error-handling/customErrors/index.mjs";
10
- import { encodeTokenWithId as c } from "../../utils/encodeTokenWithId.mjs";
11
- import { formatMintAddress as l } from "../../utils/solanaMint.utils.mjs";
12
- import { getInputUtxoAndBalance as u, getInputUtxoAndBalanceOfStuckUtxos as d, getInputUtxoAndBalancePerToken as f } from "./getInputUtxoAndBalance.mjs";
13
- import { privateTokensDB as p } from "../../../data-structures/TokenDBs/PrivateTokensDB.mjs";
14
- import { getOrCreateMapValue as m } from "../../utils/map.utils.mjs";
15
- import { getChainBalanceFetchingMutex as h } from "../../utils/mutexes.utils.mjs";
16
- import { getErc20TokenFromAPI as g, getErc20TokensForChainAPI as _ } from "../../utils/erc20tokenFunctions.mjs";
17
- import { Mutex as v } from "async-mutex";
9
+ import { encodeTokenWithId as s } from "../../utils/encodeTokenWithId.mjs";
10
+ import { formatMintAddress as c } from "../../utils/solanaMint.utils.mjs";
11
+ import { getInputUtxoAndBalance as l, getInputUtxoAndBalanceOfStuckUtxos as u, getInputUtxoAndBalancePerToken as d } from "./getInputUtxoAndBalance.mjs";
12
+ import { privateTokensDB as f } from "../../../data-structures/TokenDBs/PrivateTokensDB.mjs";
13
+ import { getOrCreateMapValue as p } from "../../utils/map.utils.mjs";
14
+ import { getChainBalanceFetchingMutex as m } from "../../utils/mutexes.utils.mjs";
15
+ import { getErc20TokenFromAPI as h, getErc20TokensForChainAPI as g } from "../../utils/erc20tokenFunctions.mjs";
16
+ import { Mutex as _ } from "async-mutex";
18
17
  //#region libs/shared/common/src/functions/web3/events/getShieldedBalance.ts
19
- var y = async (t, r, i, a, o, s = !1, c, l = !1, f = !1) => m(t.balanceFetchingMutexByChain, r, () => new v()).runExclusive(async () => h(r).runShared(async () => {
20
- let { inputUtxos: m } = f ? await d({
18
+ var v = async (t, r, i, a, o, s = !1, c, d = !1, h = !1) => p(t.balanceFetchingMutexByChain, r, () => new _()).runExclusive(async () => m(r).runShared(async () => {
19
+ let { inputUtxos: p } = h ? await u({
21
20
  hinkal: t,
22
21
  chainId: r,
23
22
  ethAddress: o,
24
23
  passedShieldedPrivateKey: i,
25
24
  resetCacheBefore: s,
26
25
  allowRemoteDecryption: c
27
- }) : await u({
26
+ }) : await l({
28
27
  hinkal: t,
29
28
  sliceIfMore6: !1,
30
29
  chainId: r,
@@ -34,81 +33,82 @@ var y = async (t, r, i, a, o, s = !1, c, l = !1, f = !1) => m(t.balanceFetchingM
34
33
  resetCacheBefore: s,
35
34
  allowRemoteDecryption: c
36
35
  });
37
- l && e && await p.fetchAndUpdatePrivateTokens(m.map((e) => e.getTokenAddress(r)).filter((e) => e !== void 0), r, o);
38
- let h = (e ? await p.getPrivateTokens(r, o) : await _(r)).map((e) => ({
36
+ d && e && await f.fetchAndUpdatePrivateTokens(p.map((e) => e.getTokenAddress(r)).filter((e) => e !== void 0), r, o);
37
+ let m = (e ? await f.getPrivateTokens(r, o) : await g(r)).map((e) => ({
39
38
  token: e,
40
- balance: m.reduce((t, i) => {
39
+ balance: p.reduce((t, i) => {
41
40
  let a = e.erc20TokenAddress;
42
41
  return n(a, i.getTokenAddress(r)) ? t + i.amount : t;
43
42
  }, 0n),
44
- timestamp: m.filter((t) => n(t.getTokenAddress(r), e.erc20TokenAddress))[0]?.timeStamp,
43
+ timestamp: p.filter((t) => n(t.getTokenAddress(r), e.erc20TokenAddress))[0]?.timeStamp,
45
44
  nfts: []
46
- })), g = /* @__PURE__ */ new Map();
47
- return h.forEach((e) => {
48
- g.set(e.token.erc20TokenAddress.toLowerCase(), e);
49
- }), g;
50
- })), b = async (e, n, u, d, p = 6, m = u.map(() => 0), h = !1, _ = !1) => {
51
- let { userKeys: v } = e, y = await a(v), b = [], x = [];
52
- if (u.length === 0) return [];
53
- if (h) {
54
- for (let e = 0; e < u.length; e += 1) {
55
- let r = t(n), i = r ? u[e] : void 0, a = r ? l(u[e]).compressedAddress : u[e];
56
- b.push(await o(p, {
45
+ })), _ = /* @__PURE__ */ new Map();
46
+ return m.forEach((e) => {
47
+ _.set(e.token.erc20TokenAddress.toLowerCase(), e);
48
+ }), _;
49
+ })), y = async (e, n, l, u, f = 6, p = l.map(() => 0), m = !1, g = !1) => {
50
+ let { userKeys: _ } = e, v = _.getSpendingKeyPair().pubSpendingBJJPoint, y = [], b = [];
51
+ if (l.length === 0) return [];
52
+ if (m) {
53
+ for (let e = 0; e < l.length; e += 1) {
54
+ let r = t(n), i = r ? l[e] : void 0, o = r ? c(l[e]).compressedAddress : l[e];
55
+ y.push(Array.from({ length: f }, () => new a({
57
56
  amount: 0n,
58
- erc20TokenAddress: a,
57
+ erc20TokenAddress: o,
59
58
  mintAddress: i,
60
- nullifyingKey: v.getShieldedPrivateKey(),
61
- spendingPublicKey: y,
59
+ nullifyingKey: _.getShieldedPrivateKey(),
60
+ spendingPublicKey: v,
62
61
  isNewStyle: !0
63
- }));
62
+ })));
64
63
  }
65
- return b;
64
+ return y;
66
65
  }
67
- let S = await f({
66
+ let x = await d({
68
67
  hinkal: e,
69
68
  sliceIfMore6: !1,
70
- ensuredTokensWithId: u.map((e, t) => ({
71
- erc20TokenAddress: u[t],
72
- tokenId: m[t]
69
+ ensuredTokensWithId: l.map((e, t) => ({
70
+ erc20TokenAddress: l[t],
71
+ tokenId: p[t]
73
72
  })),
74
73
  allowRemoteDecryption: e.generateProofRemotely,
75
- useBlockedUtxos: _,
74
+ useBlockedUtxos: g,
76
75
  chainId: n
77
- }), C = 0;
78
- for (let e = 0; e < u.length; e += 1) {
79
- let t = S.get(c(n, {
80
- erc20TokenAddress: u[e],
81
- tokenId: m[e]
76
+ }), S = 0;
77
+ for (let e = 0; e < l.length; e += 1) {
78
+ let t = x.get(s(n, {
79
+ erc20TokenAddress: l[e],
80
+ tokenId: p[e]
82
81
  })) ?? [];
83
82
  if (!t) throw Error("Missing utxos for token");
84
- C = Math.max(t.length, C), x.push(t);
83
+ S = Math.max(t.length, S), b.push(t);
85
84
  }
86
- if (C === 2) return x;
87
- for (let [e, a] of x.entries()) if (a.length > p) {
88
- let t = a.slice(0, p), o = t.reduce((e, t) => e + t.amount, 0n);
89
- if (d[e] < 0n && o < -d[e]) {
90
- let t = await g(n, u[e]);
85
+ if (S === 2) return b;
86
+ for (let [e, s] of b.entries()) if (s.length > f) {
87
+ let t = s.slice(0, f), a = t.reduce((e, t) => e + t.amount, 0n);
88
+ if (u[e] < 0n && a < -u[e]) {
89
+ let t = await h(n, l[e]);
91
90
  if (!t) throw Error("Token not found");
92
- let a = t.decimals === 18 ? 6 : 2, c = Number(i(o, t, a));
93
- throw new s(c, `${r.UTXO_LIMITATIONS}. Please try again with ${c} ${t.symbol}, including gas fees.`);
91
+ let s = t.decimals === 18 ? 6 : 2, c = Number(i(a, t, s));
92
+ throw new o(c, `${r.UTXO_LIMITATIONS}. Please try again with ${c} ${t.symbol}, including gas fees.`);
94
93
  }
95
- b.push(t);
96
- } else if (a.length <= p) {
97
- let r = [...a], i = p - a.length;
98
- if (i > 0) {
99
- let a = t(n), s = a ? u[e] : void 0, c = a ? l(u[e]).compressedAddress : u[e];
100
- r.push(...await o(i, {
94
+ y.push(t);
95
+ } else if (s.length <= f) {
96
+ let r = [...s], i = f - s.length;
97
+ for (; i > 0;) {
98
+ --i;
99
+ let o = t(n), s = o ? l[e] : void 0, u = o ? c(l[e]).compressedAddress : l[e];
100
+ r.push(new a({
101
101
  amount: 0n,
102
- erc20TokenAddress: c,
102
+ erc20TokenAddress: u,
103
103
  mintAddress: s,
104
- nullifyingKey: v.getShieldedPrivateKey(),
105
- spendingPublicKey: y,
104
+ nullifyingKey: _.getShieldedPrivateKey(),
105
+ spendingPublicKey: v,
106
106
  isNewStyle: !0
107
107
  }));
108
108
  }
109
- b.push(r);
109
+ y.push(r);
110
110
  }
111
- return b;
111
+ return y;
112
112
  };
113
113
  //#endregion
114
- export { b as addPaddingToUtxos, y as getShieldedBalance };
114
+ export { y as addPaddingToUtxos, v as getShieldedBalance };
@@ -1 +1 @@
1
- const e=require(`../../snarkjs/common.snarkjs.cjs`),t=require(`../../../error-handling/customErrors/ErrorWithTx.cjs`),n=require(`../../../constants/server.constants.cjs`),r=require(`../../../API/getServerURL.cjs`),i=require(`../../../data-structures/http/HttpClient.cjs`),a=require(`../../../API/callRelayer.cjs`);require(`../../../error-handling/index.cjs`),require(`../../snarkjs/index.cjs`);var o=e=>{if(e.status===`success`)return e.message;throw e.message&&e.error?new t.ErrorWithRelayerTransaction(e.error,e.message):Error(e.error)},s=async(t,n,r,i,s,c,l,u,d)=>{let f=e.serializeCircomData(i);return o(await a.callRelayerTransactAPI({chainId:t,a:n[0],b:n[1],c:n[2],dimData:r,circomData:f,withUniswapWorkAround:c,authorizationData:l,adminData:u,tronProofSignature:d,commitmentValidationData:s}))},c=async e=>o(await i.httpClient.post(`${r.RELAYER_URL}${n.RELAYER_CONFIG.SOLANA_TRANSACT}`,e)),l=e=>{if(e.status===`success`)return e.message.scheduleId;throw Error(e.error||`Batch transaction failed`)},u=async(t,n,r,i,o,s)=>{let c=n.map(t=>e.serializeCircomData(t.circomData));return l(await a.callRelayerTransactBatchAPI({chainId:t,transactions:n.map((e,n)=>({chainId:t,a:e.zkCallData[0],b:e.zkCallData[1],c:e.zkCallData[2],dimData:e.dimData,circomData:c[n],commitmentValidationData:e.commitmentValidationData,withUniswapWorkAround:e.withUniswapWorkAround,authorizationData:e.authorizationData,adminData:e.adminData,recipientAddress:e.recipientAddress,tronProofSignature:e.tronProofSignature})),txCompletionTime:i,hashedEthereumAddress:r,ref:o,hashedDashboardAccountId:s}))},d=async(e,t,n,r,i,o)=>l(await a.callRelayerSolanaTransactBatchAPI({chainId:e,transactions:t,hashedEthereumAddress:n,txCompletionTime:r,ref:i,hashedDashboardAccountId:o}));exports.solanaTransactCallRelayer=c,exports.solanaTransactCallRelayerBatch=d,exports.transactCallRelayer=s,exports.transactCallRelayerBatch=u;
1
+ const e=require(`../../../error-handling/customErrors/ErrorWithTx.cjs`),t=require(`../../../constants/server.constants.cjs`),n=require(`../../../API/getServerURL.cjs`),r=require(`../../../data-structures/http/HttpClient.cjs`),i=require(`../../../API/callRelayer.cjs`),a=require(`../../snarkjs/common.snarkjs.cjs`);require(`../../../error-handling/index.cjs`),require(`../../snarkjs/index.cjs`);var o=t=>{if(t.status===`success`)return t.message;throw t.message&&t.error?new e.ErrorWithRelayerTransaction(t.error,t.message):Error(t.error)},s=async(e,t,n,r,s,c,l,u,d)=>{let f=a.serializeCircomData(r);return o(await i.callRelayerTransactAPI({chainId:e,a:t[0],b:t[1],c:t[2],dimData:n,circomData:f,withUniswapWorkAround:c,authorizationData:l,adminData:u,tronProofSignature:d,commitmentValidationData:s}))},c=async e=>o(await r.httpClient.post(`${n.RELAYER_URL}${t.RELAYER_CONFIG.SOLANA_TRANSACT}`,e)),l=e=>{if(e.status===`success`)return e.message.scheduleId;throw Error(e.error||`Batch transaction failed`)},u=async(e,t,n,r,o,s)=>{let c=t.map(e=>a.serializeCircomData(e.circomData));return l(await i.callRelayerTransactBatchAPI({chainId:e,transactions:t.map((t,n)=>({chainId:e,a:t.zkCallData[0],b:t.zkCallData[1],c:t.zkCallData[2],dimData:t.dimData,circomData:c[n],commitmentValidationData:t.commitmentValidationData,withUniswapWorkAround:t.withUniswapWorkAround,authorizationData:t.authorizationData,adminData:t.adminData,recipientAddress:t.recipientAddress,tronProofSignature:t.tronProofSignature})),txCompletionTime:r,hashedEthereumAddress:n,ref:o,hashedDashboardAccountId:s}))},d=async(e,t,n,r,a,o)=>l(await i.callRelayerSolanaTransactBatchAPI({chainId:e,transactions:t,hashedEthereumAddress:n,txCompletionTime:r,ref:a,hashedDashboardAccountId:o}));exports.solanaTransactCallRelayer=c,exports.solanaTransactCallRelayerBatch=d,exports.transactCallRelayer=s,exports.transactCallRelayerBatch=u;
@@ -1,62 +1,62 @@
1
- import { serializeCircomData as e } from "../../snarkjs/common.snarkjs.mjs";
2
- import { ErrorWithRelayerTransaction as t } from "../../../error-handling/customErrors/ErrorWithTx.mjs";
3
- import { RELAYER_CONFIG as n } from "../../../constants/server.constants.mjs";
4
- import { RELAYER_URL as r } from "../../../API/getServerURL.mjs";
5
- import { httpClient as i } from "../../../data-structures/http/HttpClient.mjs";
6
- import { callRelayerSolanaTransactBatchAPI as a, callRelayerTransactAPI as o, callRelayerTransactBatchAPI as s } from "../../../API/callRelayer.mjs";
1
+ import { ErrorWithRelayerTransaction as e } from "../../../error-handling/customErrors/ErrorWithTx.mjs";
2
+ import { RELAYER_CONFIG as t } from "../../../constants/server.constants.mjs";
3
+ import { RELAYER_URL as n } from "../../../API/getServerURL.mjs";
4
+ import { httpClient as r } from "../../../data-structures/http/HttpClient.mjs";
5
+ import { callRelayerSolanaTransactBatchAPI as i, callRelayerTransactAPI as a, callRelayerTransactBatchAPI as o } from "../../../API/callRelayer.mjs";
6
+ import { serializeCircomData as s } from "../../snarkjs/common.snarkjs.mjs";
7
7
  import "../../../error-handling/index.mjs";
8
8
  import "../../snarkjs/index.mjs";
9
9
  //#region libs/shared/common/src/functions/web3/functionCalls/transactCallRelayer.ts
10
- var c = (e) => {
11
- if (e.status === "success") return e.message;
12
- throw e.message && e.error ? new t(e.error, e.message) : Error(e.error);
13
- }, l = async (t, n, r, i, a, s, l, u, d) => {
14
- let f = e(i);
15
- return c(await o({
16
- chainId: t,
17
- a: n[0],
18
- b: n[1],
19
- c: n[2],
20
- dimData: r,
10
+ var c = (t) => {
11
+ if (t.status === "success") return t.message;
12
+ throw t.message && t.error ? new e(t.error, t.message) : Error(t.error);
13
+ }, l = async (e, t, n, r, i, o, l, u, d) => {
14
+ let f = s(r);
15
+ return c(await a({
16
+ chainId: e,
17
+ a: t[0],
18
+ b: t[1],
19
+ c: t[2],
20
+ dimData: n,
21
21
  circomData: f,
22
- withUniswapWorkAround: s,
22
+ withUniswapWorkAround: o,
23
23
  authorizationData: l,
24
24
  adminData: u,
25
25
  tronProofSignature: d,
26
- commitmentValidationData: a
26
+ commitmentValidationData: i
27
27
  }));
28
- }, u = async (e) => c(await i.post(`${r}${n.SOLANA_TRANSACT}`, e)), d = (e) => {
28
+ }, u = async (e) => c(await r.post(`${n}${t.SOLANA_TRANSACT}`, e)), d = (e) => {
29
29
  if (e.status === "success") return e.message.scheduleId;
30
30
  throw Error(e.error || "Batch transaction failed");
31
- }, f = async (t, n, r, i, a, o) => {
32
- let c = n.map((t) => e(t.circomData));
33
- return d(await s({
34
- chainId: t,
35
- transactions: n.map((e, n) => ({
36
- chainId: t,
37
- a: e.zkCallData[0],
38
- b: e.zkCallData[1],
39
- c: e.zkCallData[2],
40
- dimData: e.dimData,
31
+ }, f = async (e, t, n, r, i, a) => {
32
+ let c = t.map((e) => s(e.circomData));
33
+ return d(await o({
34
+ chainId: e,
35
+ transactions: t.map((t, n) => ({
36
+ chainId: e,
37
+ a: t.zkCallData[0],
38
+ b: t.zkCallData[1],
39
+ c: t.zkCallData[2],
40
+ dimData: t.dimData,
41
41
  circomData: c[n],
42
- commitmentValidationData: e.commitmentValidationData,
43
- withUniswapWorkAround: e.withUniswapWorkAround,
44
- authorizationData: e.authorizationData,
45
- adminData: e.adminData,
46
- recipientAddress: e.recipientAddress,
47
- tronProofSignature: e.tronProofSignature
42
+ commitmentValidationData: t.commitmentValidationData,
43
+ withUniswapWorkAround: t.withUniswapWorkAround,
44
+ authorizationData: t.authorizationData,
45
+ adminData: t.adminData,
46
+ recipientAddress: t.recipientAddress,
47
+ tronProofSignature: t.tronProofSignature
48
48
  })),
49
- txCompletionTime: i,
50
- hashedEthereumAddress: r,
51
- ref: a,
52
- hashedDashboardAccountId: o
49
+ txCompletionTime: r,
50
+ hashedEthereumAddress: n,
51
+ ref: i,
52
+ hashedDashboardAccountId: a
53
53
  }));
54
- }, p = async (e, t, n, r, i, o) => d(await a({
54
+ }, p = async (e, t, n, r, a, o) => d(await i({
55
55
  chainId: e,
56
56
  transactions: t,
57
57
  hashedEthereumAddress: n,
58
58
  txCompletionTime: r,
59
- ref: i,
59
+ ref: a,
60
60
  hashedDashboardAccountId: o
61
61
  }));
62
62
  //#endregion
@@ -1 +1 @@
1
- require(`./chains.types.cjs`),require(`./hinkal.types.cjs`),require(`./circom-data.types.cjs`),require(`./external-action.types.cjs`),require(`./ethereum-network.types.cjs`),require(`./token.types.cjs`),require(`./transactions.types.cjs`),require(`./admin.types.cjs`),require(`./activities.types.cjs`),require(`./transaction.types.cjs`),require(`./balances.types.cjs`),require(`./cache.types.cjs`),require(`./new-rewards.type.cjs`),require(`./eip5792.types.cjs`),require(`./offscreen.types.cjs`),require(`./scheduled-transactions.types.cjs`),require(`./events.types.cjs`),require(`./schedule.types.cjs`);
1
+ require(`./chains.types.cjs`),require(`./hinkal.types.cjs`),require(`./circom-data.types.cjs`),require(`./ethereum-network.types.cjs`),require(`./external-action.types.cjs`),require(`./token.types.cjs`),require(`./transactions.types.cjs`),require(`./admin.types.cjs`),require(`./activities.types.cjs`),require(`./transaction.types.cjs`),require(`./balances.types.cjs`),require(`./cache.types.cjs`),require(`./new-rewards.type.cjs`),require(`./eip5792.types.cjs`),require(`./offscreen.types.cjs`),require(`./scheduled-transactions.types.cjs`),require(`./events.types.cjs`),require(`./schedule.types.cjs`);
@@ -1,8 +1,8 @@
1
1
  import "./chains.types.mjs";
2
2
  import "./hinkal.types.mjs";
3
3
  import "./circom-data.types.mjs";
4
- import "./external-action.types.mjs";
5
4
  import "./ethereum-network.types.mjs";
5
+ import "./external-action.types.mjs";
6
6
  import "./token.types.mjs";
7
7
  import "./transactions.types.mjs";
8
8
  import "./admin.types.mjs";
@@ -0,0 +1,2 @@
1
+ const e=require(`./workerProxy-DPeuP2Mg.js`);let t=require(`buffer`),n=require(`process`);n=e.u(n);let r=require(`circomlibjs-hinkal-fork`),i=require(`@noble/hashes/blake1.js`),a=require(`ethers`),o=require(`poseidon-lite`);o=e.u(o);let s=require(`libsodium-wrappers`);s=e.u(s);let c=require(`@solana/web3.js`),l=require(`bs58`);l=e.u(l);let u=require(`tweetnacl`);u=e.u(u);let d=require(`tronweb`);`${`00`.repeat(20)}`;var f=21888242871839275222246405745257275088548364400416034343698204186575808495617n,p=f/2n,m=200n;`${`00`.repeat(32)}`;var h=(e,t=f)=>{let n=e%t;return n>=0n?n:n+t},g=(e,t=f)=>{let n=1n,r=0n,i=h(e,t),a=t;if(i===0n)throw Error(`Division by zero`);for(;i>1n;){let e=a%i,t=a/i;a=i,i=e;let o=r-n*t;r=n,n=o}return n<0n?n+t:n},_={p:f,zero:0n,one:1n,e:e=>h(BigInt(e)),add:(e,t)=>h(e+t),sub:(e,t)=>h(e-t),mul:(e,t)=>h(e*t),div:(e,t)=>{if(t===0n)throw Error(`Division by zero in BabyJub field`);return h(e*g(t))},toString:e=>h(e).toString()},v={X:_.zero,Y:_.one,Z:_.one,T:_.zero},y=e=>{let t=_.e(e[0]),n=_.e(e[1]);return{X:t,Y:n,Z:_.one,T:_.mul(t,n)}},b=e=>{let t=g(e.Z);return[_.mul(e.X,t),_.mul(e.Y,t)]},x=_.e(`168700`),S=_.e(`168696`),C=(e,t)=>{let n=_.mul(e.X,t.X),r=_.mul(e.Y,t.Y),i=_.mul(_.mul(e.T,t.T),S),a=_.mul(e.Z,t.Z),o=_.sub(_.mul(_.add(e.X,e.Y),_.add(t.X,t.Y)),_.add(n,r)),s=_.sub(a,i),c=_.add(a,i),l=_.sub(r,_.mul(x,n));return{X:_.mul(o,s),Y:_.mul(c,l),T:_.mul(o,l),Z:_.mul(s,c)}},ee=e=>{let t=_.mul(e.X,e.X),n=_.mul(e.Y,e.Y),r=_.mul(_.mul(e.Z,e.Z),2n),i=_.mul(x,t),a=_.sub(_.mul(_.add(e.X,e.Y),_.add(e.X,e.Y)),_.add(t,n)),o=_.add(i,n),s=_.sub(o,r),c=_.sub(i,n);return{X:_.mul(a,s),Y:_.mul(o,c),T:_.mul(a,c),Z:_.mul(s,o)}},w=class{static A=x;static D=S;F=_;A=x;D=S;Base8=[_.e(`5299619240641551281634865583518297030282874472190772894086521144482721001553`),_.e(`16950150798460657717958625567821834550301663161624707787222815936182638968203`)];addPoint(e,t){return b(C(y(e),y(t)))}mulPointEscalar(e,t){let n=v,r=y(e),i=BigInt(t);for(;i!==0n;)i%2n==1n&&(n=C(n,r)),r=ee(r),i/=2n;return b(n)}},T=new class{babyjub=void 0;async init(){this.babyjub||=e.o?new w:await(0,r.buildBabyjub)()}getJub(){return this.babyjub}},E=()=>T.getJub();function D(e){return typeof e==`object`&&`toBigInt`in e?e.toBigInt():BigInt(e)}var O=()=>{let e=e=>{let t=o[`poseidon${e.length}`];if(!t)throw Error(`Poseidon: arity ${e.length} not supported (1..16)`);return t(e.map(e=>BigInt(e)))};return e.F={toString:e=>BigInt(e).toString()},e},k=new class{poseidon=void 0;async init(){this.poseidon||=e.o?O():await(0,r.buildPoseidon)()}getPoseidon(){return this.poseidon}};function A(...e){let t=k.getPoseidon();return D(t.F.toString(t(e)))}var j=(...e)=>{let t=k.getPoseidon();return a.ethers.toBeHex(t.F.toString(t([...e])))},M=21888242871839275222246405745257275088614511777268538073601725287587578984328n/8n,N=(e,t=0,n=e.length-t)=>{let r=0n;for(let i=n-1;i>=0;--i)r=(r<<8n)+BigInt(e[t+i]);return r},P=(e,t,n,r)=>{let i=h(n);for(let n=0;n<r;n+=1)e[t+n]=Number(i&255n),i>>=8n},F=e=>h(e,M),I=e=>{let t=new Uint8Array(e);return t[0]&=248,t[31]&=127,t[31]|=64,t},te=class{constructor(e,t){this.babyJub=e,this.poseidon=t}prv2pub(e){let t=N(I((0,i.blake512)(e).slice(0,32)),0,32);return this.babyJub.mulPointEscalar(this.babyJub.Base8,t/8n)}signPoseidon(e,t){let n=I((0,i.blake512)(e)),r=N(n,0,32),a=this.babyJub.mulPointEscalar(this.babyJub.Base8,r/8n),o=new Uint8Array(64);o.set(n.slice(32),0),P(o,32,t,32);let s=F(N((0,i.blake512)(o),0,64)),c=this.babyJub.mulPointEscalar(this.babyJub.Base8,s),l=this.poseidon([c[0],c[1],a[0],a[1],t]);return{R8:c,S:F(s+F(h(BigInt(this.poseidon.F.toString(l)))*r))}}},ne=async()=>(await k.init(),await T.init(),new te(T.getJub(),k.getPoseidon())),L=new class{eddsa=void 0;async init(){this.eddsa||=e.o?await ne():await(0,r.buildEddsa)()}getEddsa(){return this.eddsa}},R=()=>L.getEddsa(),z=async(e=!1)=>{(typeof window<`u`||typeof self<`u`)&&(typeof window<`u`&&(window.global=window),globalThis.Buffer=t.Buffer,globalThis.process=n.default),await Promise.all([s.default.ready,k.init(),T.init(),...e?[]:[L.init()]])},B=class{inMemoryCache=new Map;constructor(e){e&&this.mergeWithSerialized(e)}getInMemory(e){return this.inMemoryCache.get(e)??void 0}setInMemory(e,t){this.inMemoryCache.set(e,t)}mergeWithSerialized(t){Object.entries(t).forEach(([t,n])=>{this.set(t,e.c(n))})}},V=class extends B{isAttached=!1;get(e){return this.getInMemory(e)}set(e,t){this.setInMemory(e,t)}serialize(){return Object.fromEntries([...this.inMemoryCache].map(([t,n])=>[t,e.l(n)]))}attach(t){if(this.isAttached)throw Error(`can't reattach cache device`);return this.isAttached=!0,(...n)=>{let r=e.l(n),i=this.get(r);if(i!==void 0)return i;let a=t(...n);return this.set(r,a),a}}},H=e=>{if(e<0n||e>=21888242871839275222246405745257275088548364400416034343698204186575808495617n)throw RangeError();return e>p},U=e=>H(e)?1n:0n,W=new V,G=new V,K=new V,q=class{signature;nullifyingKey;PREFIX_FOR_SPENDING_PAIR=`1`;PREFIX_FOR_NULLIFYING_PAIR=`2`;constructor(e,t){this.signature=e,this.nullifyingKey=t}getSignature(){return this.requireSignature(),this.signature}setSignature(e){this.signature=e}requireSignature(){if(!this.signature)throw Error(`No signature provided`)}requireKeyMaterial(){if(!this.signature&&!this.nullifyingKey)throw Error(`No signature or private key provided`)}verifyTronMessage(e,t){return this.requireSignature(),t===d.Trx.verifyMessageV2(e,this.signature)}getShieldedPrivateKey=()=>(this.requireKeyMaterial(),this.nullifyingKey||=a.ethers.keccak256(this.signature),this.nullifyingKey);getShieldedPublicKey=()=>(this.requireKeyMaterial(),j(this.getShieldedPrivateKey()));getSpendingKeyPair=()=>{this.requireSignature();let e=R(),t=E(),n=j(this.PREFIX_FOR_SPENDING_PAIR,this.getSignature()),r=Buffer.from(a.ethers.getBytes(n)),i=e.prv2pub(r);return{privSpendingKey:n,pubSpendingBJJPoint:[BigInt(t.F.toString(i[0])),BigInt(t.F.toString(i[1]))]}};signEddsa=e=>{this.requireSignature();let t=E(),n=R(),r=Buffer.from(a.ethers.getBytes(this.getSpendingKeyPair().privSpendingKey)),i=t.F.e(e),o=n.signPoseidon(r,i);return{R8:[BigInt(t.F.toString(o.R8[0])),BigInt(t.F.toString(o.R8[1]))],S:BigInt(o.S)}};getShieldedPrivateKeyFromNonce=e=>{this.requireKeyMaterial();let t=j(e,this.getShieldedPrivateKey(),this.getShieldedPublicKey());return a.ethers.keccak256(a.ethers.toUtf8Bytes(`hinkal-offchain-shielded-key:${t}`))};getClaimableSignatureFromNonce=e=>{this.requireKeyMaterial();let t=j(e,this.getShieldedPrivateKey(),this.getShieldedPublicKey());return a.ethers.keccak256(a.ethers.toUtf8Bytes(`hinkal-claimable-utxo-signature:${t}`))};getDerivedEthereumAddress=()=>(this.requireKeyMaterial(),new a.ethers.Wallet(this.getShieldedPrivateKey()).address);getDerivedSolanaPublicKey=()=>(this.requireKeyMaterial(),c.Keypair.fromSeed(a.ethers.getBytes(this.getShieldedPrivateKey())).publicKey.toBase58());getNearIntentsAccountId=()=>{this.requireKeyMaterial();let e=c.Keypair.fromSeed(a.ethers.getBytes(this.getShieldedPrivateKey()));return a.ethers.hexlify(e.publicKey.toBytes()).slice(2)};getNearIntentsKeyPairString=()=>{this.requireKeyMaterial();let e=c.Keypair.fromSeed(a.ethers.getBytes(this.getShieldedPrivateKey()));return`ed25519:${l.default.encode(e.secretKey)}`};getSignerPrivateKeyFromNonce=e=>{this.requireKeyMaterial();let t=j(e,this.getShieldedPrivateKey(),this.getShieldedPublicKey());return a.ethers.keccak256(a.ethers.toUtf8Bytes(t))};getSignerSolanaPrivateKeyFromNonce=e=>{let t=this.getSignerPrivateKeyFromNonce(e),n=a.ethers.getBytes(t),r=c.Keypair.fromSeed(n);return l.default.encode(r.secretKey)};verifyMessage(e){return this.requireSignature(),a.ethers.verifyMessage(e,this.signature)}verifySolanaMessage(e,t){this.requireSignature();let n=new TextEncoder().encode(e),r=a.ethers.getBytes(this.signature),i=new c.PublicKey(t).toBytes();return u.default.sign.detached.verify(n,r,i)}static getRandomizedStealthPairOld=G.attach((e,t)=>{let n=E(),r=e*(BigInt(t)%f)%f,i=n.mulPointEscalar(n.Base8,e),a=n.mulPointEscalar(n.Base8,r);return{H0:[BigInt(n.F.toString(i[0])),BigInt(n.F.toString(i[1]))],H1:[BigInt(n.F.toString(a[0])),BigInt(n.F.toString(a[1]))]}});static getRandomizedStealthPair=W.attach((e,t)=>{let n=E(),r=BigInt(t)%f,i=n.mulPointEscalar(n.Base8,e),a=n.mulPointEscalar(i,r);return{H0:[BigInt(n.F.toString(i[0])),BigInt(n.F.toString(i[1]))],H1:[BigInt(n.F.toString(a[0])),BigInt(n.F.toString(a[1]))]}});static getStealthAddressCompressedPoints=(e,t)=>{let{H0:n,H1:r}=this.getRandomizedStealthPairOld(e,t),[i,a]=[n,r].map(e=>BigInt(e[1])+2n**255n*U(e[0]));return{h0:i,h1:a}};static checkSignature=(e,t,n,r)=>{let{h0:i,h1:a}=this.getStealthAddressCompressedPoints(e,r);return t===i&&n===a};static getStealthAddress=K.attach((e,t)=>{let{H0:n,H1:r}=this.getRandomizedStealthPairOld(e,t);return j(2n*U(n[0])+U(r[0]),n[1],r[1])});static getH1FromH0=(e,t)=>{let n=E(),r=BigInt(t)%f,i=[n.F.e(e[0]),n.F.e(e[1])],a=n.mulPointEscalar(i,r);return[BigInt(n.F.toString(a[0])),BigInt(n.F.toString(a[1]))]};static verifyStealthPair=(e,t,n,r=!0)=>{let i=this.getH1FromH0(e,n);return r?i[1]===t[1]:i===t};static getStealthAddressNewStyle=(e,t,n)=>{if(n?.length!==2)throw Error(`Spending public key must be an array of 2 elements`);let r=this.getH1FromH0(e,t);return j(2n*U(e[0])+U(r[0]),e[1],r[1],n[0],n[1],t)};static findCorrectRandomization(e,t){if(!t)throw Error(`No Private Shielded Key Provided`);let n=BigInt(t)%f,r,i,a=0n;do r=e*10n**a%f,i=r*n%f,a+=1n;while(i>=2n**253n||r>=2n**253n);return r}static getH0FromRandomization=e=>{let t=E(),n=t.mulPointEscalar(t.Base8,e);return[BigInt(t.F.toString(n[0])),BigInt(t.F.toString(n[1]))]};static findH0(e,t){if(!t)return;let{H0:n}=this.getRandomizedStealthPair(e,t);return n}static getEncryptionKeyPair=e=>{let t=s.default.crypto_box_seed_keypair(a.ethers.getBytes(e));return{privateKey:a.ethers.hexlify(t.privateKey),publicKey:a.ethers.hexlify(t.publicKey)}};getAccessKey=()=>(this.requireKeyMaterial(),j(this.getShieldedPrivateKey(),this.getShieldedPublicKey()));getBackendToken=()=>(this.requireKeyMaterial(),j(this.getAccessKey(),this.getShieldedPublicKey()))},J={CANNOT_CERTIFY_FOR_PAST_WEEK:`Certification for the past week is not available`,CYCLICAL_REFERRALS_FORBIDDEN:`Cyclical referrals are forbidden`,USER_IS_UNRANKED:`Please certify transactions to see rank`},Y={WC_NO_MATCHING_KEY:`creating the transaction failed
2
+ version`,CONNECTION_PROBLEM:`Failed to connect wallet. Please try again.`,REQUEST_PENDING:`request of type 'wallet_requestpermissions' already pending for origin`},X={INSUFFICIENT_FUNDS:`Insufficient funds`,INSUFFICIENT_FUNDS_WITHDRAW:`Not enough funds to withdraw`,INSUFFICIENT_FUNDS_TRANSFER:`Not enough funds to transfer`,INSUFFICIENT_FUNDS_TO_TRANSACT:`Not enough funds to transact`,INSUFFICIENT_FUNDS_GAS:`Insufficient funds for gas * price`,INSUFFICIENT_TRON_BALANCE_FOR_FEE:`Insufficient TRX balance to cover transfer amount and transaction fee reserve`,INSUFFICIENT_SOL_BALANCE:`Insufficient SOL balance`},re={GAS_PRICE_EXCEEDS_AUTOSHIELD_LIMIT:`Skipped shielding due to gas fee exceeding your limit.`,AUTO_SHIELD_INSUFFICIENT_GAS:`Auto-Shield skipped due to insufficient gas.`};({...J,...Y,...X,...re});var ie=e=>BigInt(a.ethers.hexlify(a.ethers.randomBytes(e))),ae=()=>Math.floor(Date.now()/1e3),Z=class t{amount;erc20TokenAddress;mintAddress;timeStamp;nullifyingKey;spendingPublicKey;randomization;H0;stealthAddress;encryptionKey;commitment;nullifier;isBlocked;isNewStyle;constructor({amount:e,erc20TokenAddress:t,mintAddress:n,timeStamp:r,nullifyingKey:i,spendingPublicKey:a,randomization:o,H0:s,stealthAddress:c,encryptionKey:l,commitment:u=void 0,nullifier:d=void 0,isBlocked:f=!1,isNewStyle:p=!1}){this.amount=e,this.erc20TokenAddress=t,this.mintAddress=n,this.timeStamp=r??ae().toString(),this.nullifyingKey=i,this.spendingPublicKey=a,this.randomization=o??(i?q.findCorrectRandomization(ie(31),i):void 0),this.H0=s??(p&&this.randomization?q.findH0(this.randomization,i):void 0),this.stealthAddress=c,this.encryptionKey=l,this.commitment=u,this.nullifier=d,this.isBlocked=f,this.isNewStyle=p}static createFrom(e,n){return new t({...e.getConstructableParams(),nullifier:void 0,commitment:void 0,...n})}getConstructableParams(){return{amount:this.amount,erc20TokenAddress:this.erc20TokenAddress,mintAddress:this.mintAddress,timeStamp:this.timeStamp,nullifyingKey:this.nullifyingKey,spendingPublicKey:this.spendingPublicKey,randomization:this.randomization,H0:this.H0,stealthAddress:this.stealthAddress,encryptionKey:this.encryptionKey,commitment:this.commitment,nullifier:this.nullifier,isBlocked:this.isBlocked,isNewStyle:this.isNewStyle}}getBasicUtxoParams(){return{amount:this.amount,erc20TokenAddress:this.erc20TokenAddress,mintAddress:this.mintAddress,timeStamp:this.timeStamp,randomization:this.randomization,H0:this.H0,stealthAddress:this.stealthAddress,commitment:this.commitment,nullifier:this.nullifier,isBlocked:this.isBlocked,isNewStyle:this.isNewStyle}}getCommitment(){if(!this.commitment){let e=[this.amount,this.erc20TokenAddress,BigInt(this.getStealthAddress()),this.timeStamp];this.commitment=j(...e)}return this.commitment}getNullifier(){if(!this.nullifier){if(!this.nullifyingKey)throw Error(`No Nullifiers if private key is not provided`);let e=this.getCommitment(),t=j(this.nullifyingKey,e);this.nullifier=j(e,t)}return this.nullifier}getStealthAddress(){if(!this.stealthAddress){if(!this.nullifyingKey)throw Error(`No stealth address in UTXO if private key is not provided`);if(this.isNewStyle){if(!this.H0)throw Error(`No H0 point provided`);this.stealthAddress=q.getStealthAddressNewStyle(this.H0,this.nullifyingKey,this.spendingPublicKey)}else{if(!this.randomization)throw Error(`No randomization provided`);this.stealthAddress=q.getStealthAddress(this.randomization,this.nullifyingKey)}}return this.stealthAddress}getTokenAddress(t){let n=e.r(t)?this.mintAddress:this.erc20TokenAddress;if(!n)throw Error(`No token address provided`);return n}getEncryptionKey(){if(!this.nullifyingKey){if(!this.encryptionKey)throw Error(`No encryption key provided in UTXO`);return this.encryptionKey}return q.getEncryptionKeyPair(this.nullifyingKey).publicKey}},oe=()=>s.default.crypto_box_SEALBYTES+s.default.crypto_secretbox_KEYBYTES,Q=e=>{let t=s.default.crypto_secretbox_NONCEBYTES,n=oe(),r=0,i=e[r];r+=1;let a=e.slice(r,r+t);r+=t;let o=[];for(let t=0;t<i;t+=1)o.push(e.slice(r,r+n)),r+=n;return{nonce:a,sealedKeys:o,ciphertext:e.slice(r)}},se=(e,t,n,r)=>{let{nonce:i,sealedKeys:o,ciphertext:c}=Q(e),l=s.default.crypto_box_seal_open(o[r],a.ethers.getBytes(n),a.ethers.getBytes(t)),u=s.default.crypto_secretbox_open_easy(c,i,l);return Buffer.from(u)},ce=(e,t,n)=>{let r=s.default.crypto_box_seal_open(e,a.ethers.getBytes(n),a.ethers.getBytes(t));return Buffer.from(r)},le=54912,ue=2,de=e=>e[0]*256+e[1],$=(e,t)=>{let{privateKey:n,publicKey:r}=q.getEncryptionKeyPair(t.getShieldedPrivateKey()),i=de(e)===le?se(e.slice(ue),n,r,0):ce(e,n,r),a=Buffer.from(i).toString(`utf-8`).split(`0x`).filter(e=>e.length!==0),o=e=>BigInt(`0x${e}`),s=e=>`0x${e}`,l=a.length>=8,u=l&&o(a[5])===1n,d=l?8:6,f=a[d]?s(a[d]):void 0,p=f?new c.PublicKey(Buffer.from(f.slice(2),`hex`)).toString():void 0;return{amount:o(a[0]),erc20TokenAddress:s(a[1]),randomization:o(a[2]),stealthAddress:s(a[3]),nullifyingKey:t.getShieldedPrivateKey(),timeStamp:o(a[4]).toString(),isNewStyle:u,...u?{H0:[o(a[6]),o(a[7])]}:{},mintAddress:p}},fe=(e,t)=>new Z($(e,t)),pe=e=>e&2n**255n-1n,me=e=>e>>255n&1n,he=(...t)=>{e.a&&console.log(...t)};Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return $}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return fe}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return me}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return Z}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return pe}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return q}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return he}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return z}});