@gurge/sdk 0.3.27 → 0.3.28

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 +35 -46
  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 +43 -86
  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 +22 -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 +60 -67
  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/index.cjs +1 -1
  85. package/common/src/functions/utils/index.mjs +3 -3
  86. package/common/src/functions/web3/events/getInputUtxoAndBalance.cjs +1 -1
  87. package/common/src/functions/web3/events/getInputUtxoAndBalance.mjs +71 -122
  88. package/common/src/functions/web3/events/getShieldedBalance.cjs +1 -1
  89. package/common/src/functions/web3/events/getShieldedBalance.mjs +64 -64
  90. package/common/src/functions/web3/functionCalls/transactCallRelayer.cjs +1 -1
  91. package/common/src/functions/web3/functionCalls/transactCallRelayer.mjs +42 -42
  92. package/common/src/types/index.cjs +1 -1
  93. package/common/src/types/index.mjs +1 -1
  94. package/common/src/webworker/logError-D8yBaP96.js +2 -0
  95. package/common/src/webworker/package.json +1 -1
  96. package/common/src/webworker/performTaskWithWorker.cjs +1 -1
  97. package/common/src/webworker/performTaskWithWorker.mjs +17 -18
  98. package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.cjs +1 -1
  99. package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.mjs +1 -1
  100. package/common/src/webworker/utxoWorkerNode.cjs +1 -1
  101. package/common/src/webworker/viteWorkerURL.constant.cjs +3 -4
  102. package/common/src/webworker/viteWorkerURL.constant.d.ts +0 -1
  103. package/common/src/webworker/viteWorkerURL.constant.mjs +3 -4
  104. package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.cjs +1 -1
  105. package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.mjs +1 -1
  106. package/common/src/webworker/zkProofWorkerNode.cjs +1 -1
  107. package/package.json +1 -1
  108. package/react-native/HinkalWebViewWorker.cjs +4 -76
  109. package/react-native/HinkalWebViewWorker.mjs +49 -152
  110. package/react-native/bridge/HinkalRNWorker.cjs +1 -1
  111. package/react-native/bridge/HinkalRNWorker.d.ts +0 -1
  112. package/react-native/bridge/HinkalRNWorker.mjs +11 -16
  113. package/react-native/shims/circomlibjs-hinkal-fork.js +2 -2
  114. package/react-native/shims/circomlibjs.js +2 -2
  115. package/react-native/workerCDNUrls.cjs +1 -1
  116. package/react-native/workerCDNUrls.d.ts +0 -1
  117. package/react-native/workerCDNUrls.mjs +2 -2
  118. package/sdk/package.json.cjs +1 -1
  119. package/sdk/package.json.mjs +1 -1
  120. package/common/src/crypto/rnCryptoBridge.cjs +0 -1
  121. package/common/src/crypto/rnCryptoBridge.d.ts +0 -8
  122. package/common/src/crypto/rnCryptoBridge.mjs +0 -10
  123. package/common/src/crypto/rnUtxoCrypto.cjs +0 -1
  124. package/common/src/crypto/rnUtxoCrypto.d.ts +0 -25
  125. package/common/src/crypto/rnUtxoCrypto.mjs +0 -74
  126. package/common/src/functions/utils/hinkalTiming.utils.cjs +0 -1
  127. package/common/src/functions/utils/hinkalTiming.utils.d.ts +0 -11
  128. package/common/src/functions/utils/hinkalTiming.utils.mjs +0 -21
  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,73 +1,73 @@
1
1
  import { chainIds as e } from "../../constants/chains.constants.mjs";
2
2
  import { poseidonFunction as t } from "../../crypto/poseidon.mjs";
3
3
  import { randomBigInt as n } from "../web3/etherFunctions.mjs";
4
- import { takeOffHighestBit as ee } from "../utils/bit.operations.mjs";
5
- import { buildOutCommitments as r, calcAmountChanges as i, calcStealthAddressStructure as a, getUtxoCircuitH0Coords as o, getUtxoCircuitInRandomization as s } from "./common.snarkjs.mjs";
6
- import { formatMintAddress as c } from "../utils/solanaMint.utils.mjs";
7
- import { encodeToByte32Array as l } from "../pre-transaction/solana.mjs";
8
- import { computeSignedMessageHashSolana as u } from "./signedMessageHash.mjs";
4
+ import { formatMintAddress as r } from "../utils/solanaMint.utils.mjs";
5
+ import { takeOffHighestBit as i } from "../utils/bit.operations.mjs";
6
+ import { buildOutCommitments as a, calcAmountChanges as o, calcStealthAddressStructure as s, getUtxoCircuitH0Coords as c, getUtxoCircuitInRandomization as l } from "./common.snarkjs.mjs";
7
+ import { encodeToByte32Array as u } from "../pre-transaction/solana.mjs";
8
+ import { computeSignedMessageHashSolana as d } from "./signedMessageHash.mjs";
9
9
  import "../pre-transaction/index.mjs";
10
- import { generateMainAndCommitmentZkProof as d } from "./generateMainAndCommitmentZkProof.mjs";
10
+ import { generateMainAndCommitmentZkProof as f } from "./generateMainAndCommitmentZkProof.mjs";
11
11
  import "../utils/index.mjs";
12
- import { getDataFromWorkers as f } from "./getMerkleTreeSiblingsAndRootHashes.mjs";
13
- import { getSolanaCalldataHash as p } from "../pre-transaction/getSolanaCalldataHash.mjs";
12
+ import { getDataFromWorkers as p } from "./getMerkleTreeSiblingsAndRootHashes.mjs";
13
+ import { getSolanaCalldataHash as m } from "../pre-transaction/getSolanaCalldataHash.mjs";
14
14
  import "../web3/index.mjs";
15
- import { PublicKey as m } from "@solana/web3.js";
15
+ import { PublicKey as h } from "@solana/web3.js";
16
16
  //#region libs/shared/common/src/functions/snarkjs/constructSolanaZkProof.ts
17
- var h = async (h, g, _, v, y, b, x, S, C, w, T, E, te, D = e.solanaLocalnet, O = [], k = [], A = 0n) => {
18
- let j = new m(w), M = new m(T), N = _.getShieldedPrivateKey(), { pubSpendingBJJPoint: P } = _.getSpendingKeyPair(), F = a(x, N, _.getSpendingKeyPair().pubSpendingBJJPoint), I = n(31), L = t(I), R = t(A), z = v.map((e) => c(e)), B = z.map((e) => e.mintAccountPart1), V = z.map((e) => e.mintAccountPart2), H = p(E, j, M, te, S, C, O, k), ne = `${E.tokenNumber}x${E.nullifierAmount}x${E.outputAmount}`, U = i(y, b), { inCommitmentSiblings: W, inCommitmentSiblingSides: G, rootHashHinkal: K, inNullifiers: q } = await f(D, g, y.map((e) => e.map((e) => e.getConstructableParams()))), J = r(b), Y = ee(F.extraRandomization), X = F.H0, Z = u({
19
- rootHashHinkal: K,
20
- mintAccountPart1: B,
21
- mintAccountPart2: V,
22
- amountChanges: U,
23
- outTimeStamp: BigInt(b[0][0].timeStamp),
24
- inNullifiers: q,
25
- outCommitments: J,
26
- calldataHash: H,
27
- message: L,
28
- swapperAccountAdditionalSeed: R,
29
- outH1Ay: F.H1,
30
- H0Ax: Y,
31
- H0Ay: X
32
- }), { R8: Q, S: re } = _.signEddsa(Z), ie = {
33
- rootHashHinkal: K,
34
- spendingPublicKey: P,
17
+ var g = async (g, _, v, y, b, x, S, C, w, T, E, D, ee, O = e.solanaLocalnet, k = [], A = [], j = 0n) => {
18
+ let M = new h(T), N = new h(E), P = v.getShieldedPrivateKey(), { pubSpendingBJJPoint: F } = v.getSpendingKeyPair(), I = s(S, P, v.getSpendingKeyPair().pubSpendingBJJPoint), L = n(31), R = t(L), z = t(j), B = y.map((e) => r(e)), V = B.map((e) => e.mintAccountPart1), H = B.map((e) => e.mintAccountPart2), U = m(D, M, N, ee, C, w, k, A), te = `${D.tokenNumber}x${D.nullifierAmount}x${D.outputAmount}`, W = o(b, x), { inCommitmentSiblings: G, inCommitmentSiblingSides: K, rootHashHinkal: q, inNullifiers: J } = await p(O, _, b.map((e) => e.map((e) => e.getConstructableParams()))), Y = a(x), X = i(I.extraRandomization), Z = I.H0, Q = d({
19
+ rootHashHinkal: q,
20
+ mintAccountPart1: V,
21
+ mintAccountPart2: H,
22
+ amountChanges: W,
23
+ outTimeStamp: BigInt(x[0][0].timeStamp),
24
+ inNullifiers: J,
25
+ outCommitments: Y,
26
+ calldataHash: U,
27
+ message: R,
28
+ swapperAccountAdditionalSeed: z,
29
+ outH1Ay: I.H1,
30
+ H0Ax: X,
31
+ H0Ay: Z
32
+ }), { R8: $, S: ne } = v.signEddsa(Q), re = {
33
+ rootHashHinkal: q,
34
+ spendingPublicKey: F,
35
35
  eddsaSignature: [
36
- Q[0],
37
- Q[1],
38
- re
36
+ $[0],
37
+ $[1],
38
+ ne
39
39
  ],
40
- signedMessageHash: Z,
41
- nullifyingPrivateKey: N,
42
- mintAccountPart1: B,
43
- mintAccountPart2: V,
44
- amountChanges: U,
45
- inAmounts: y.map((e) => e.map((e) => e.amount.toString())),
46
- inRandomizations: y.map((e) => e.map((e) => s(e))),
47
- inH0Ax: y.map((e) => e.map((e) => o(e)[0].toString())),
48
- inH0Ay: y.map((e) => e.map((e) => o(e)[1].toString())),
49
- isNewStyle: y.map((e) => e.map((e) => !!e.isNewStyle)),
50
- inTimeStamps: y.map((e) => e.map((e) => e.timeStamp)),
51
- inNullifiers: q,
52
- inCommitmentSiblings: W,
53
- inCommitmentSiblingSides: G,
54
- outAmounts: b.map((e) => e.map((e) => e.amount.toString())),
55
- outTimeStamp: BigInt(b[0][0].timeStamp),
56
- outPublicKeys: b.map((e) => e.map((e) => e.getStealthAddress())),
57
- outCommitments: J,
58
- calldataHash: H,
59
- messageSeed: I,
60
- swapperAccountSalt: A,
61
- H0Ax: Y,
62
- H0Ay: X
63
- }, { zkCallData: ae, publicSignals: oe, commitmentValidationData: $ } = await d(D, _, v, y, `mainSolanaCircuit${ne}`, ie, h), [se, ce, le] = ae;
40
+ signedMessageHash: Q,
41
+ nullifyingPrivateKey: P,
42
+ mintAccountPart1: V,
43
+ mintAccountPart2: H,
44
+ amountChanges: W,
45
+ inAmounts: b.map((e) => e.map((e) => e.amount.toString())),
46
+ inRandomizations: b.map((e) => e.map((e) => l(e))),
47
+ inH0Ax: b.map((e) => e.map((e) => c(e)[0].toString())),
48
+ inH0Ay: b.map((e) => e.map((e) => c(e)[1].toString())),
49
+ isNewStyle: b.map((e) => e.map((e) => !!e.isNewStyle)),
50
+ inTimeStamps: b.map((e) => e.map((e) => e.timeStamp)),
51
+ inNullifiers: J,
52
+ inCommitmentSiblings: G,
53
+ inCommitmentSiblingSides: K,
54
+ outAmounts: x.map((e) => e.map((e) => e.amount.toString())),
55
+ outTimeStamp: BigInt(x[0][0].timeStamp),
56
+ outPublicKeys: x.map((e) => e.map((e) => e.getStealthAddress())),
57
+ outCommitments: Y,
58
+ calldataHash: U,
59
+ messageSeed: L,
60
+ swapperAccountSalt: j,
61
+ H0Ax: X,
62
+ H0Ay: Z
63
+ }, { zkCallData: ie, publicSignals: ae, commitmentValidationData: oe } = await f(O, v, y, b, `mainSolanaCircuit${te}`, re, g), [se, ce, le] = ie;
64
64
  return {
65
- proofAArr: se.map(BigInt).map(l).flat(),
66
- proofBArr: ce.flat().map(BigInt).map(l).flat(),
67
- proofCArr: le.map(BigInt).map(l).flat(),
68
- publicInputsArr: oe.map(BigInt).map(l),
69
- commitmentValidationData: $
65
+ proofAArr: se.map(BigInt).map(u).flat(),
66
+ proofBArr: ce.flat().map(BigInt).map(u).flat(),
67
+ proofCArr: le.map(BigInt).map(u).flat(),
68
+ publicInputsArr: ae.map(BigInt).map(u),
69
+ commitmentValidationData: oe
70
70
  };
71
71
  };
72
72
  //#endregion
73
- export { h as constructSolanaZkProof };
73
+ export { g as constructSolanaZkProof };
@@ -1 +1 @@
1
- require(`../../../../_virtual/_rolldown/runtime.cjs`),require(`./common.snarkjs.cjs`),require(`../../data-structures/http/HttpClient.cjs`),require(`../utils/bytes32.utils.cjs`),require(`./getZKFiles.cjs`),require(`ethers`),require(`snarkjs`);
1
+ require(`../../../../_virtual/_rolldown/runtime.cjs`),require(`../../data-structures/http/HttpClient.cjs`),require(`./common.snarkjs.cjs`),require(`../utils/bytes32.utils.cjs`),require(`./getZKFiles.cjs`),require(`ethers`),require(`snarkjs`);
@@ -1,5 +1,5 @@
1
- import "./common.snarkjs.mjs";
2
1
  import "../../data-structures/http/HttpClient.mjs";
2
+ import "./common.snarkjs.mjs";
3
3
  import "../utils/bytes32.utils.mjs";
4
4
  import "./getZKFiles.mjs";
5
5
  import "ethers";
@@ -1 +1 @@
1
- require(`../../constants/protocol.constants.cjs`);
1
+ const e=require(`../../constants/protocol.constants.cjs`);var t=(t,n=e.CIRCOM_P)=>{let r=t%n;return r>=0n?r:r+n},n=(n,r=e.CIRCOM_P)=>{let i=1n,a=0n,o=t(n,r),s=r;if(o===0n)throw Error(`Division by zero`);for(;o>1n;){let e=s%o,t=s/o;s=o,o=e;let n=a-i*t;a=i,i=n}return i<0n?i+r:i};exports.mod=t,exports.modInverse=n;
@@ -1,2 +1,4 @@
1
1
  export declare const mod: (value: bigint, m?: bigint) => bigint;
2
2
  export declare const modpow: (b: bigint, e: bigint, m: bigint) => bigint;
3
+ /** Modular inverse via extended Euclidean algorithm (much faster than Fermat modpow on RN). */
4
+ export declare const modInverse: (value: bigint, m?: bigint) => bigint;
@@ -1 +1,18 @@
1
- import "../../constants/protocol.constants.mjs";
1
+ import { CIRCOM_P as e } from "../../constants/protocol.constants.mjs";
2
+ //#region libs/shared/common/src/functions/utils/bigint-math.utils.ts
3
+ var t = (t, n = e) => {
4
+ let r = t % n;
5
+ return r >= 0n ? r : r + n;
6
+ }, n = (n, r = e) => {
7
+ let i = 1n, a = 0n, o = t(n, r), s = r;
8
+ if (o === 0n) throw Error("Division by zero");
9
+ for (; o > 1n;) {
10
+ let e = s % o, t = s / o;
11
+ s = o, o = e;
12
+ let n = a - i * t;
13
+ a = i, i = n;
14
+ }
15
+ return i < 0n ? i + r : i;
16
+ };
17
+ //#endregion
18
+ export { t as mod, n as modInverse };
@@ -1 +1 @@
1
- require(`../web3/etherFunctions.cjs`),require(`../../data-structures/crypto-keys/keys.cjs`),require(`../snarkjs/common.snarkjs.cjs`),require(`../../data-structures/utxo/Utxo.cjs`),require(`./addresses.cjs`);
1
+ require(`../web3/etherFunctions.cjs`),require(`../../data-structures/crypto-keys/keys.cjs`),require(`../../data-structures/utxo/Utxo.cjs`),require(`./addresses.cjs`),require(`../snarkjs/common.snarkjs.cjs`);
@@ -1,5 +1,5 @@
1
1
  import "../web3/etherFunctions.mjs";
2
2
  import "../../data-structures/crypto-keys/keys.mjs";
3
- import "../snarkjs/common.snarkjs.mjs";
4
3
  import "../../data-structures/utxo/Utxo.mjs";
5
4
  import "./addresses.mjs";
5
+ import "../snarkjs/common.snarkjs.mjs";
@@ -1 +1 @@
1
- require(`../../constants/chains.constants.cjs`);const e=require(`./caseInsensitive.utils.cjs`),t=require(`./amounts.utils.cjs`);require(`../../data-structures/crypto-keys/keys.cjs`),require(`../../data-structures/crypto-keys/encryptDecryptUtxo.cjs`);const n=require(`../../types/ethereum-network.types.cjs`);require(`../../types/index.cjs`);const r=require(`../../data-structures/crypto-keys/decodeUTXO.cjs`),i=require(`./getContractAddress.cjs`);require(`ethers`);var a=(a,o,s,c)=>{let l=o.getContractWithFetcher(s,n.ContractType.HinkalContract),u=l.interface,d=o.userKeys.getShieldedPrivateKey(),f=i.getContractAddress(l);return a.logs.filter(t=>e.caseInsensitiveEqual(t.address,f)).map(n=>{try{let i=u.parseLog(n);if(i?.name===`NewCommitment`){let{encryptedOutput:n,index:a}=i.args;if(t.toBigInt(a)<0n){let t=r.decodeUtxo(n,d,s);if(e.caseInsensitiveEqual(t.erc20TokenAddress,c))return t}}}catch{return null}return null}).filter(e=>e!==null)};exports.getOnChainUtxosFromReceipt=a;
1
+ require(`../../constants/chains.constants.cjs`);const e=require(`./caseInsensitive.utils.cjs`),t=require(`./amounts.utils.cjs`);require(`../../data-structures/crypto-keys/keys.cjs`);const n=require(`../../types/ethereum-network.types.cjs`);require(`../../types/index.cjs`),require(`../../data-structures/crypto-keys/encryptDecryptUtxo.cjs`);const r=require(`../../data-structures/crypto-keys/decodeUTXO.cjs`),i=require(`./getContractAddress.cjs`);require(`ethers`);var a=(a,o,s,c)=>{let l=o.getContractWithFetcher(s,n.ContractType.HinkalContract),u=l.interface,d=o.userKeys.getShieldedPrivateKey(),f=i.getContractAddress(l);return a.logs.filter(t=>e.caseInsensitiveEqual(t.address,f)).map(n=>{try{let i=u.parseLog(n);if(i?.name===`NewCommitment`){let{encryptedOutput:n,index:a}=i.args;if(t.toBigInt(a)<0n){let t=r.decodeUtxo(n,d,s);if(e.caseInsensitiveEqual(t.erc20TokenAddress,c))return t}}}catch{return null}return null}).filter(e=>e!==null)};exports.getOnChainUtxosFromReceipt=a;
@@ -2,9 +2,9 @@ import "../../constants/chains.constants.mjs";
2
2
  import { caseInsensitiveEqual as e } from "./caseInsensitive.utils.mjs";
3
3
  import { toBigInt as t } from "./amounts.utils.mjs";
4
4
  import "../../data-structures/crypto-keys/keys.mjs";
5
- import "../../data-structures/crypto-keys/encryptDecryptUtxo.mjs";
6
5
  import { ContractType as n } from "../../types/ethereum-network.types.mjs";
7
6
  import "../../types/index.mjs";
7
+ import "../../data-structures/crypto-keys/encryptDecryptUtxo.mjs";
8
8
  import { decodeUtxo as r } from "../../data-structures/crypto-keys/decodeUTXO.mjs";
9
9
  import { getContractAddress as i } from "./getContractAddress.mjs";
10
10
  import "ethers";
@@ -1 +1 @@
1
- require(`../../../../_virtual/_rolldown/runtime.cjs`),require(`../../constants/chains.constants.cjs`);const e=require(`./caseInsensitive.utils.cjs`),t=require(`../../crypto/poseidon.cjs`);require(`../../data-structures/crypto-keys/encryptDecryptUtxo.cjs`);const n=require(`./bit.operations.cjs`),r=require(`../../data-structures/utxo/Utxo.cjs`),i=require(`./bytes32.utils.cjs`);let a=require(`ethers`),o=require(`@solana/web3.js`),s=require(`@coral-xyz/anchor`);var c=(c,l,u,d)=>[...new s.EventParser(l.programId,new s.BorshCoder(l.idl)).parseLogs(c.meta?.logMessages??[])].filter(({name:t})=>e.caseInsensitiveEqual(t,`newCommitment`)).filter(({data:e})=>e.encryptedOutput.length===0).map(e=>{let{onChainData:s}=e.data,[c,l,d,f,p,m,,h]=s.map(i.convertBytes32ToBigInt),[,g,_]=s,v=new o.PublicKey([...g.slice(16),..._.slice(16)]),y=t.poseidonHash(l,d),b=n.extractHighestBit(f)===1n,x=new r.Utxo({amount:c,timeStamp:h.toString(),nullifyingKey:u.getShieldedPrivateKey(),mintAddress:v.toBase58(),erc20TokenAddress:y,stealthAddress:a.ethers.toBeHex(p),isNewStyle:b,...b?{H0:[n.takeOffHighestBit(f),m]}:{randomization:f}});return x.getStealthAddress(),x}).filter(t=>e.caseInsensitiveEqual(t.erc20TokenAddress,d));exports.getOnChainUtxosFromReceiptSolana=c;
1
+ require(`../../../../_virtual/_rolldown/runtime.cjs`),require(`../../constants/chains.constants.cjs`);const e=require(`./caseInsensitive.utils.cjs`),t=require(`../../crypto/poseidon.cjs`),n=require(`../../data-structures/utxo/Utxo.cjs`);require(`../../data-structures/crypto-keys/encryptDecryptUtxo.cjs`);const r=require(`./bit.operations.cjs`),i=require(`./bytes32.utils.cjs`);let a=require(`ethers`),o=require(`@solana/web3.js`),s=require(`@coral-xyz/anchor`);var c=(c,l,u,d)=>[...new s.EventParser(l.programId,new s.BorshCoder(l.idl)).parseLogs(c.meta?.logMessages??[])].filter(({name:t})=>e.caseInsensitiveEqual(t,`newCommitment`)).filter(({data:e})=>e.encryptedOutput.length===0).map(e=>{let{onChainData:s}=e.data,[c,l,d,f,p,m,,h]=s.map(i.convertBytes32ToBigInt),[,g,_]=s,v=new o.PublicKey([...g.slice(16),..._.slice(16)]),y=t.poseidonHash(l,d),b=r.extractHighestBit(f)===1n,x=new n.Utxo({amount:c,timeStamp:h.toString(),nullifyingKey:u.getShieldedPrivateKey(),mintAddress:v.toBase58(),erc20TokenAddress:y,stealthAddress:a.ethers.toBeHex(p),isNewStyle:b,...b?{H0:[r.takeOffHighestBit(f),m]}:{randomization:f}});return x.getStealthAddress(),x}).filter(t=>e.caseInsensitiveEqual(t.erc20TokenAddress,d));exports.getOnChainUtxosFromReceiptSolana=c;
@@ -1,16 +1,16 @@
1
1
  import "../../constants/chains.constants.mjs";
2
2
  import { caseInsensitiveEqual as e } from "./caseInsensitive.utils.mjs";
3
3
  import { poseidonHash as t } from "../../crypto/poseidon.mjs";
4
+ import { Utxo as n } from "../../data-structures/utxo/Utxo.mjs";
4
5
  import "../../data-structures/crypto-keys/encryptDecryptUtxo.mjs";
5
- import { extractHighestBit as n, takeOffHighestBit as r } from "./bit.operations.mjs";
6
- import { Utxo as i } from "../../data-structures/utxo/Utxo.mjs";
6
+ import { extractHighestBit as r, takeOffHighestBit as i } from "./bit.operations.mjs";
7
7
  import { convertBytes32ToBigInt as a } from "./bytes32.utils.mjs";
8
8
  import { ethers as o } from "ethers";
9
9
  import { PublicKey as s } from "@solana/web3.js";
10
10
  import { BorshCoder as c, EventParser as l } from "@coral-xyz/anchor";
11
11
  //#region libs/shared/common/src/functions/utils/getUtxosFromReceiptSolana.ts
12
12
  var u = (u, d, f, p) => [...new l(d.programId, new c(d.idl)).parseLogs(u.meta?.logMessages ?? [])].filter(({ name: t }) => e(t, "newCommitment")).filter(({ data: e }) => e.encryptedOutput.length === 0).map((e) => {
13
- let { onChainData: c } = e.data, [l, u, d, p, m, h, , g] = c.map(a), [, _, v] = c, y = new s([..._.slice(16), ...v.slice(16)]), b = t(u, d), x = n(p) === 1n, S = new i({
13
+ let { onChainData: c } = e.data, [l, u, d, p, m, h, , g] = c.map(a), [, _, v] = c, y = new s([..._.slice(16), ...v.slice(16)]), b = t(u, d), x = r(p) === 1n, S = new n({
14
14
  amount: l,
15
15
  timeStamp: g.toString(),
16
16
  nullifyingKey: f.getShieldedPrivateKey(),
@@ -18,7 +18,7 @@ var u = (u, d, f, p) => [...new l(d.programId, new c(d.idl)).parseLogs(u.meta?.l
18
18
  erc20TokenAddress: b,
19
19
  stealthAddress: o.toBeHex(m),
20
20
  isNewStyle: x,
21
- ...x ? { H0: [r(p), h] } : { randomization: p }
21
+ ...x ? { H0: [i(p), h] } : { randomization: p }
22
22
  });
23
23
  return S.getStealthAddress(), S;
24
24
  }).filter((t) => e(t.erc20TokenAddress, p));
@@ -1 +1 @@
1
- require(`./abi.utils.cjs`),require(`./serialize.utils.cjs`),require(`./caseInsensitive.utils.cjs`),require(`./amounts.utils.cjs`),require(`./external-action.utils.cjs`),require(`./bit.operations.cjs`),require(`./time.utils.cjs`),require(`./upToDateState.cjs`),require(`./cacheFunctions.cjs`),require(`./enclaveHandshakeService.cjs`),require(`./encryptInputForEnclave.cjs`),require(`./solanaMint.utils.cjs`),require(`./customEnclaveFunctionsRegister.cjs`),require(`./addresses.cjs`),require(`./tron.utils.cjs`),require(`./get-signature-header.cjs`),require(`./auth.utils.cjs`),require(`./string.utils.cjs`),require(`./token-check.utils.cjs`),require(`./map.utils.cjs`),require(`./mutexes.utils.cjs`),require(`./erc20tokenFunctions.cjs`),require(`../pre-transaction/outputUtxoProcessing.cjs`),require(`../pre-transaction/solana.cjs`),require(`../pre-transaction/process-gas-estimates.cjs`),require(`../pre-transaction/getVolatileTransferAmount.cjs`),require(`../pre-transaction/constructAdminData.cjs`),require(`./create-provider.cjs`),require(`../pre-transaction/convert-okx-instructions.cjs`),require(`./process.utils.cjs`),require(`../pre-transaction/sendV0Transaction.cjs`),require(`./bytes32.utils.cjs`),require(`../pre-transaction/recipientUtxoProcessing.cjs`),require(`../pre-transaction/ensureAmountChanges.cjs`),require(`../pre-transaction/getFeeStructure.cjs`),require(`../pre-transaction/waitForDepositedUtxosInMerkleTree.cjs`),require(`../pre-transaction/buildCommitmentValidationData.cjs`),require(`../pre-transaction/index.cjs`),require(`./serialize-utxos.utils.cjs`),require(`./bigint-math.utils.cjs`),require(`./resolve-sync.utils.cjs`),require(`./convertIntegrationProviderToExternalActionId.cjs`),require(`./evmNetworkFunctions.cjs`),require(`./userAgent.cjs`),require(`./reloadPage.cjs`),require(`./cacheDevice.utils.cjs`),require(`./getBlockExplorerUrl.cjs`),require(`./involves-permit2-op.cjs`),require(`./convertEmporiumOpToCallInfo.cjs`),require(`./getRecipientInfoFromUserKeys.cjs`),require(`./publicBalance.utils.cjs`),require(`./rpc-int-encode.cjs`),require(`./walletBalances.utils.cjs`),require(`./nftTokenFunctions.cjs`),require(`./inLogicMetadata.cjs`),require(`./networks.utils.cjs`),require(`./postToOffscreen.cjs`),require(`./solanaSendPreflight.utils.cjs`),require(`./prepareHinkal.cjs`),require(`./getContractAddress.cjs`),require(`./getUtxosFromReceipt.utils.cjs`),require(`./getUtxosFromReceiptSolana.cjs`),require(`./fees.utils.cjs`),require(`./enclave-utxo-storage.cjs`),require(`./enclave-signature-storage.cjs`),require(`./tx-confirmation.utils.cjs`),require(`./buildClaimableDepositPlan.cjs`),require(`./formatter.cjs`),require(`./tronSimulation.utils.cjs`),require(`./getSignerFromContract.cjs`),require(`./deposit-claimable.utils.cjs`),require(`./transfer-claimable.utils.cjs`),require(`./dispatchBalanceRefreshes.cjs`),require(`./lifi.utils.cjs`),require(`./enclave-recipient-info-storage.cjs`),require(`./solana-memo.cjs`),require(`./mnemonics.cjs`),require(`./nearIntents.utils.cjs`);
1
+ require(`./abi.utils.cjs`),require(`./serialize.utils.cjs`),require(`./caseInsensitive.utils.cjs`),require(`./amounts.utils.cjs`),require(`./bigint-math.utils.cjs`),require(`./time.utils.cjs`),require(`./upToDateState.cjs`),require(`./cacheFunctions.cjs`),require(`./enclaveHandshakeService.cjs`),require(`./encryptInputForEnclave.cjs`),require(`./solanaMint.utils.cjs`),require(`./customEnclaveFunctionsRegister.cjs`),require(`./addresses.cjs`),require(`./tron.utils.cjs`),require(`./get-signature-header.cjs`),require(`./auth.utils.cjs`),require(`./string.utils.cjs`),require(`./token-check.utils.cjs`),require(`./map.utils.cjs`),require(`./mutexes.utils.cjs`),require(`./erc20tokenFunctions.cjs`),require(`../pre-transaction/outputUtxoProcessing.cjs`),require(`./external-action.utils.cjs`),require(`./bit.operations.cjs`),require(`../pre-transaction/solana.cjs`),require(`../pre-transaction/process-gas-estimates.cjs`),require(`../pre-transaction/getVolatileTransferAmount.cjs`),require(`../pre-transaction/constructAdminData.cjs`),require(`./create-provider.cjs`),require(`../pre-transaction/convert-okx-instructions.cjs`),require(`./process.utils.cjs`),require(`../pre-transaction/sendV0Transaction.cjs`),require(`./bytes32.utils.cjs`),require(`../pre-transaction/recipientUtxoProcessing.cjs`),require(`../pre-transaction/ensureAmountChanges.cjs`),require(`../pre-transaction/getFeeStructure.cjs`),require(`../pre-transaction/waitForDepositedUtxosInMerkleTree.cjs`),require(`../pre-transaction/buildCommitmentValidationData.cjs`),require(`../pre-transaction/index.cjs`),require(`./serialize-utxos.utils.cjs`),require(`./resolve-sync.utils.cjs`),require(`./convertIntegrationProviderToExternalActionId.cjs`),require(`./evmNetworkFunctions.cjs`),require(`./userAgent.cjs`),require(`./reloadPage.cjs`),require(`./cacheDevice.utils.cjs`),require(`./getBlockExplorerUrl.cjs`),require(`./involves-permit2-op.cjs`),require(`./convertEmporiumOpToCallInfo.cjs`),require(`./getRecipientInfoFromUserKeys.cjs`),require(`./publicBalance.utils.cjs`),require(`./rpc-int-encode.cjs`),require(`./walletBalances.utils.cjs`),require(`./nftTokenFunctions.cjs`),require(`./inLogicMetadata.cjs`),require(`./networks.utils.cjs`),require(`./postToOffscreen.cjs`),require(`./solanaSendPreflight.utils.cjs`),require(`./prepareHinkal.cjs`),require(`./getContractAddress.cjs`),require(`./getUtxosFromReceipt.utils.cjs`),require(`./getUtxosFromReceiptSolana.cjs`),require(`./fees.utils.cjs`),require(`./enclave-utxo-storage.cjs`),require(`./enclave-signature-storage.cjs`),require(`./tx-confirmation.utils.cjs`),require(`./buildClaimableDepositPlan.cjs`),require(`./formatter.cjs`),require(`./tronSimulation.utils.cjs`),require(`./getSignerFromContract.cjs`),require(`./deposit-claimable.utils.cjs`),require(`./transfer-claimable.utils.cjs`),require(`./dispatchBalanceRefreshes.cjs`),require(`./lifi.utils.cjs`),require(`./enclave-recipient-info-storage.cjs`),require(`./solana-memo.cjs`),require(`./mnemonics.cjs`),require(`./nearIntents.utils.cjs`);
@@ -2,8 +2,7 @@ import "./abi.utils.mjs";
2
2
  import "./serialize.utils.mjs";
3
3
  import "./caseInsensitive.utils.mjs";
4
4
  import "./amounts.utils.mjs";
5
- import "./external-action.utils.mjs";
6
- import "./bit.operations.mjs";
5
+ import "./bigint-math.utils.mjs";
7
6
  import "./time.utils.mjs";
8
7
  import "./upToDateState.mjs";
9
8
  import "./cacheFunctions.mjs";
@@ -21,6 +20,8 @@ import "./map.utils.mjs";
21
20
  import "./mutexes.utils.mjs";
22
21
  import "./erc20tokenFunctions.mjs";
23
22
  import "../pre-transaction/outputUtxoProcessing.mjs";
23
+ import "./external-action.utils.mjs";
24
+ import "./bit.operations.mjs";
24
25
  import "../pre-transaction/solana.mjs";
25
26
  import "../pre-transaction/process-gas-estimates.mjs";
26
27
  import "../pre-transaction/getVolatileTransferAmount.mjs";
@@ -37,7 +38,6 @@ import "../pre-transaction/waitForDepositedUtxosInMerkleTree.mjs";
37
38
  import "../pre-transaction/buildCommitmentValidationData.mjs";
38
39
  import "../pre-transaction/index.mjs";
39
40
  import "./serialize-utxos.utils.mjs";
40
- import "./bigint-math.utils.mjs";
41
41
  import "./resolve-sync.utils.mjs";
42
42
  import "./convertIntegrationProviderToExternalActionId.mjs";
43
43
  import "./evmNetworkFunctions.mjs";
@@ -1 +1 @@
1
- require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../utils/caseInsensitive.utils.cjs`),n=require(`../../../crypto/rnUtxoCrypto.cjs`),r=require(`../../utils/utxoPadding.utils.cjs`),i=require(`../../utils/upToDateState.cjs`),a=require(`../../utils/cacheFunctions.cjs`),o=require(`../../utils/encodeTokenWithId.cjs`),s=require(`../../utils/solanaMint.utils.cjs`),c=require(`./getInputUtxosEnclave.cjs`),l=require(`../../utils/addresses.cjs`),u=require(`../../../API/scheduled-transactions-calls.cjs`),d=require(`../../utils/tron.utils.cjs`),f=require(`../../utils/hinkalTiming.utils.cjs`);var p=new(require(`async-mutex`)).Mutex,m=async(e,t)=>{if(e.allowParallelBalanceLocalDecryption)return t();let n=f.createRnDeltaTiming(`utxoPrep.mutex`);return p.isLocked()&&n.log(`waiting-for-lock`),p.runExclusive(async()=>{n.log(`lock-acquired`);try{return await t()}finally{n.log(`lock-released`)}})},h=async(e,t,n,r,o,s,c,l,u)=>m(e,async()=>{let d=f.createRnDeltaTiming(`utxoPrep.decrypt`);u+=1;let p=s.slice(u);d.log(`batchProcess-start`,{outputsSlice:p.length,cached:c.length});let{lastOutput:m,additionalEncryptedOutputs:h}=await e.utxoUtils.batchProcess(p,l,t,n);d.log(`batchProcess-done`,{additionalEncryptedOutputs:h.length});let g=[...c,...h],_=f.createRnDeltaTiming(`wallet.checkAddress`);await i.checkAddressNotUpdated(e,r),_.log(`during-decrypt`),a.setHinkalCache({lastOutput:m,encryptedOutputs:g},e,n,o),d.log(`cache-write`,{encryptedOutputs:g.length});let v=await e.utxoUtils.buildBatchProcess(g,t,n);return d.log(`buildBatchProcess-done`,{utxoCount:v.length}),v}),g=async(e,t,n,r)=>{let{utxos:i,encryptedOutputs:o,lastOutput:s}=await c.getInputUtxosEnclave(e,n,t);return a.setHinkalCache({encryptedOutputs:o,lastOutput:s},e,n,r),i},_=async(e,t,n,r,i,a,o,s,c)=>{try{return await g(e,t,n,i)}catch{return h(e,t,n,r,i,a,o,s,c)}},v=e=>{if(Array.isArray(e))return e;if(e!==void 0)return[e]},y=async(e,t,n)=>await e.utxoUtils.batchFilterUtxosWithNullifier(t,n),b=async(e,t,n,i,a,o,s,c)=>{for(e.sort((e,t)=>e.amount<=t.amount?1:-1);e.length<t||e.length>t&&e.length<6;){let[t]=await r.createPaddingUtxos(1,{amount:0n,erc20TokenAddress:o,mintAddress:c,nullifyingKey:i,spendingPublicKey:a,isNewStyle:!0});if(e.push(t),n)for(;e.length>6;)e.splice(e.length-1)}},x=async({hinkal:e,chainId:t,passedShieldedPublicKey:n=void 0,ethAddress:r=void 0,resetCacheBefore:o=!1,allowRemoteDecryption:s=!1,useBlockedUtxos:c=!1})=>{let l=f.createRnDeltaTiming(`utxoPrep`);l.log(`start`);let u=r;u?l.log(`wallet.getEthereumAddress-skipped`,{ethAddressPassed:!0}):(u=await e.getEthereumAddress(),l.log(`wallet.getEthereumAddress`));let d=n??e.userKeys.getShieldedPublicKey(),{userKeys:p}=e,m=e.encryptedOutputsByChain[t],g=e.nullifiersByChain[t],v=Array.from(m);o&&a.resetCache(e,t,d);let{encryptedOutputs:b,lastOutput:x}=a.getHinkalCache(e,t,d);l.log(`cache.read`,{cachedEncryptedOutputs:b.length});let S=f.createRnDeltaTiming(`wallet.checkAddress`);await i.checkAddressNotUpdated(e,u),S.log(`before-decrypt`);let C=x!==``,w=v.findIndex(e=>e.value===x);l.log(`findLastOutputIndex`,{hinkalOutputs:v.length,lastOutputIndex:w});let T=w>-1,E=!C&&w===-1,D=e.areMerkleTreeUpdatesDisabled(),O=!D&&(T||!s&&E),k=!D&&s&&E,A=!O&&!k;l.log(`branch`,{decryptLocally:O,decryptRemotely:k,useCache:A,outputsSlice:w>-1?v.length-(w+1):0});let j=[];O?(j=await h(e,p,t,u,d,v,b,x,w),l.log(`decryptLocally-done`,{utxoCount:j.length})):k?(j=await _(e,p,t,u,d,v,b,x,w),l.log(`decryptRemotely-done`,{utxoCount:j.length})):A&&(j=await e.utxoUtils.buildBatchProcess(b,p,t),l.log(`useCache-buildBatchProcess-done`,{utxoCount:j.length}));let M=f.createRnDeltaTiming(`wallet.checkAddress`);await i.checkAddressNotUpdated(e,u),M.log(`after-decrypt`);let N=await y(e,j,g);l.log(`filterSpentUtxos`,{allUtxos:j.length,inputUtxos:N.length});let P=c?N.filter(e=>e.isBlocked):N.filter(e=>!e.isBlocked);return l.log(`done`,{inputUtxos:P.length}),{inputUtxos:P}},S=async({hinkal:t,chainId:n,passedShieldedPublicKey:r=void 0,ethAddress:i=void 0,resetCacheBefore:a=!1,allowRemoteDecryption:o=!1})=>{let s=i??await t.getEthereumAddressByChain(n),c=l.hashEthereumAddress(e.isTronLike(n)?d.addressToHexFormat(s):s),{inputUtxos:f}=await x({hinkal:t,chainId:n,passedShieldedPublicKey:r,ethAddress:s,resetCacheBefore:a,allowRemoteDecryption:o,useBlockedUtxos:!0});if(!f.length)return{inputUtxos:[]};let{indexes:p}=await u.getScheduledTransactionsNullifierIndexes({hashedEthereumAddress:c,nullifiers:f.map(e=>e.getNullifier())});return{inputUtxos:p.map(e=>f[e]).filter(e=>!!e)}},C=async({hinkal:r,tokenWithId:i,minInput:a=2,sliceIfMore6:c=!0,chainId:l,passedShieldedPrivateKey:u=void 0,passedShieldedPublicKey:d=void 0,ethAddress:f=void 0,resetCacheBefore:p=!1,ensuredTokensWithId:m,allowRemoteDecryption:h=!1,useBlockedUtxos:g=!1})=>{let _=u??r.userKeys.getShieldedPrivateKey(),y=await n.getSpendingPublicKeyForRn(r.userKeys),{inputUtxos:C}=g?await S({hinkal:r,chainId:l,ethAddress:f,passedShieldedPrivateKey:u,resetCacheBefore:p,allowRemoteDecryption:h}):await x({hinkal:r,tokenWithId:i,minInput:a,sliceIfMore6:c,chainId:l,passedShieldedPrivateKey:u,passedShieldedPublicKey:d,ethAddress:f,resetCacheBefore:p,allowRemoteDecryption:h}),w=v(i),T=new Map;C.forEach(e=>{let n=e.getTokenAddress(l);if(w&&!w.some(e=>t.caseInsensitiveEqual(e.erc20TokenAddress,n)))return;let r=o.encodeTokenWithId(l,{erc20TokenAddress:n,tokenId:0}),i=T.get(r)??[];T.set(r,[...i,e])}),m?.forEach(e=>{let t=o.encodeTokenWithId(l,{erc20TokenAddress:e.erc20TokenAddress,tokenId:0});T.set(t,T.get(t)??[])});for(let[t,n]of T){let r=t.split(`-`)[0],i=Number(t.split(`-`)[1]),o=e.isSolanaLike(l),u=o?r:void 0;await b(n,a,c,_,y,o?s.formatMintAddress(r).compressedAddress.toLowerCase():r.toLowerCase(),i,u)}return T};exports.attemptGetInputUtxosRemotely=_,exports.getInputUtxoAndBalance=x,exports.getInputUtxoAndBalanceOfStuckUtxos=S,exports.getInputUtxoAndBalancePerToken=C,exports.getInputUtxosRemotely=g;
1
+ require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../utils/caseInsensitive.utils.cjs`),n=require(`../../../data-structures/utxo/Utxo.cjs`),r=require(`../../utils/upToDateState.cjs`),i=require(`../../utils/cacheFunctions.cjs`),a=require(`../../utils/encodeTokenWithId.cjs`),o=require(`../../utils/solanaMint.utils.cjs`),s=require(`./getInputUtxosEnclave.cjs`),c=require(`../../utils/addresses.cjs`),l=require(`../../../API/scheduled-transactions-calls.cjs`),u=require(`../../utils/tron.utils.cjs`);var d=new(require(`async-mutex`)).Mutex,f=async(e,t)=>e.allowParallelBalanceLocalDecryption?t():d.runExclusive(t),p=async(e,t,n,a,o,s,c,l,u)=>f(e,async()=>{u+=1;let d=s.slice(u),{lastOutput:f,additionalEncryptedOutputs:p}=await e.utxoUtils.batchProcess(d,l,t,n),m=[...c,...p];return await r.checkAddressNotUpdated(e,a),i.setHinkalCache({lastOutput:f,encryptedOutputs:m},e,n,o),await e.utxoUtils.buildBatchProcess(m,t,n)}),m=async(e,t,n,r)=>{let{utxos:a,encryptedOutputs:o,lastOutput:c}=await s.getInputUtxosEnclave(e,n,t);return i.setHinkalCache({encryptedOutputs:o,lastOutput:c},e,n,r),a},h=async(e,t,n,r,i,a,o,s,c)=>{try{return await m(e,t,n,i)}catch{return p(e,t,n,r,i,a,o,s,c)}},g=e=>{if(Array.isArray(e))return e;if(e!==void 0)return[e]},_=async(e,t,n)=>await e.utxoUtils.batchFilterUtxosWithNullifier(t,n),v=(e,t,r,i,a,o,s,c)=>{for(e.sort((e,t)=>e.amount<=t.amount?1:-1);e.length<t||e.length>t&&e.length<6;)if(e.push(new n.Utxo({amount:0n,erc20TokenAddress:o,mintAddress:c,nullifyingKey:i,spendingPublicKey:a,isNewStyle:!0})),r)for(;e.length>6;)e.splice(e.length-1)},y=async({hinkal:e,chainId:t,passedShieldedPublicKey:n=void 0,ethAddress:a=void 0,resetCacheBefore:o=!1,allowRemoteDecryption:s=!1,useBlockedUtxos:c=!1})=>{let l=a??await e.getEthereumAddress(),u=n??e.userKeys.getShieldedPublicKey(),{userKeys:d}=e,f=e.encryptedOutputsByChain[t],m=e.nullifiersByChain[t],g=Array.from(f);o&&i.resetCache(e,t,u);let{encryptedOutputs:v,lastOutput:y}=i.getHinkalCache(e,t,u);await r.checkAddressNotUpdated(e,l);let b=y!==``,x=g.findIndex(e=>e.value===y),S=x>-1,C=!b&&x===-1,w=e.areMerkleTreeUpdatesDisabled(),T=!w&&(S||!s&&C),E=!w&&s&&C,D=!T&&!E,O=[];T?O=await p(e,d,t,l,u,g,v,y,x):E?O=await h(e,d,t,l,u,g,v,y,x):D&&(O=await e.utxoUtils.buildBatchProcess(v,d,t)),await r.checkAddressNotUpdated(e,l);let k=await _(e,O,m);return{inputUtxos:c?k.filter(e=>e.isBlocked):k.filter(e=>!e.isBlocked)}},b=async({hinkal:t,chainId:n,passedShieldedPublicKey:r=void 0,ethAddress:i=void 0,resetCacheBefore:a=!1,allowRemoteDecryption:o=!1})=>{let s=i??await t.getEthereumAddressByChain(n),d=c.hashEthereumAddress(e.isTronLike(n)?u.addressToHexFormat(s):s),{inputUtxos:f}=await y({hinkal:t,chainId:n,passedShieldedPublicKey:r,ethAddress:s,resetCacheBefore:a,allowRemoteDecryption:o,useBlockedUtxos:!0});if(!f.length)return{inputUtxos:[]};let{indexes:p}=await l.getScheduledTransactionsNullifierIndexes({hashedEthereumAddress:d,nullifiers:f.map(e=>e.getNullifier())});return{inputUtxos:p.map(e=>f[e]).filter(e=>!!e)}},x=async({hinkal:n,tokenWithId:r,minInput:i=2,sliceIfMore6:s=!0,chainId:c,passedShieldedPrivateKey:l=void 0,passedShieldedPublicKey:u=void 0,ethAddress:d=void 0,resetCacheBefore:f=!1,ensuredTokensWithId:p,allowRemoteDecryption:m=!1,useBlockedUtxos:h=!1})=>{let _=l??n.userKeys.getShieldedPrivateKey(),x=n.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,{inputUtxos:S}=h?await b({hinkal:n,chainId:c,ethAddress:d,passedShieldedPrivateKey:l,resetCacheBefore:f,allowRemoteDecryption:m}):await y({hinkal:n,tokenWithId:r,minInput:i,sliceIfMore6:s,chainId:c,passedShieldedPrivateKey:l,passedShieldedPublicKey:u,ethAddress:d,resetCacheBefore:f,allowRemoteDecryption:m}),C=g(r),w=new Map;S.forEach(e=>{let n=e.getTokenAddress(c);if(C&&!C.some(e=>t.caseInsensitiveEqual(e.erc20TokenAddress,n)))return;let r=a.encodeTokenWithId(c,{erc20TokenAddress:n,tokenId:0}),i=w.get(r)??[];w.set(r,[...i,e])}),p?.forEach(e=>{let t=a.encodeTokenWithId(c,{erc20TokenAddress:e.erc20TokenAddress,tokenId:0});w.set(t,w.get(t)??[])});for(let[t,n]of w){let r=t.split(`-`)[0],a=Number(t.split(`-`)[1]),l=e.isSolanaLike(c),u=l?r:void 0;v(n,i,s,_,x,l?o.formatMintAddress(r).compressedAddress.toLowerCase():r.toLowerCase(),a,u)}return w};exports.attemptGetInputUtxosRemotely=h,exports.getInputUtxoAndBalance=y,exports.getInputUtxoAndBalanceOfStuckUtxos=b,exports.getInputUtxoAndBalancePerToken=x,exports.getInputUtxosRemotely=m;
@@ -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;