@gurge/sdk 0.3.26 → 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 (106) 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/hinkalClaimUtxo.cjs +1 -1
  15. package/common/src/data-structures/Hinkal/hinkalClaimUtxo.mjs +1 -1
  16. package/common/src/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
  17. package/common/src/data-structures/Hinkal/hinkalDeposit.mjs +1 -1
  18. package/common/src/data-structures/Hinkal/hinkalPrivateWallet.cjs +1 -1
  19. package/common/src/data-structures/Hinkal/hinkalPrivateWallet.mjs +1 -1
  20. package/common/src/data-structures/Hinkal/hinkalSolanaSwap.cjs +1 -1
  21. package/common/src/data-structures/Hinkal/hinkalSolanaSwap.mjs +1 -1
  22. package/common/src/data-structures/Hinkal/hinkalSolanaTransfer.cjs +1 -1
  23. package/common/src/data-structures/Hinkal/hinkalSolanaTransfer.mjs +1 -1
  24. package/common/src/data-structures/Hinkal/hinkalSolanaWithdraw.cjs +1 -1
  25. package/common/src/data-structures/Hinkal/hinkalSolanaWithdraw.mjs +1 -1
  26. package/common/src/data-structures/Hinkal/hinkalSwap.cjs +1 -1
  27. package/common/src/data-structures/Hinkal/hinkalSwap.mjs +1 -1
  28. package/common/src/data-structures/Hinkal/hinkalTransfer.cjs +1 -1
  29. package/common/src/data-structures/Hinkal/hinkalTransfer.mjs +1 -1
  30. package/common/src/data-structures/Hinkal/hinkalWithdraw.cjs +1 -1
  31. package/common/src/data-structures/Hinkal/hinkalWithdraw.d.ts +3 -1
  32. package/common/src/data-structures/Hinkal/hinkalWithdraw.mjs +32 -43
  33. package/common/src/data-structures/Hinkal/hinkalWithdrawStuckUtxos.cjs +1 -1
  34. package/common/src/data-structures/Hinkal/hinkalWithdrawStuckUtxos.mjs +2 -2
  35. package/common/src/data-structures/Hinkal/prepareDepositOnChainUtxosZkProof.cjs +1 -1
  36. package/common/src/data-structures/Hinkal/prepareDepositOnChainUtxosZkProof.mjs +1 -1
  37. package/common/src/data-structures/MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.cjs +1 -1
  38. package/common/src/data-structures/MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.mjs +26 -42
  39. package/common/src/data-structures/utxo/Utxo.cjs +1 -1
  40. package/common/src/data-structures/utxo/Utxo.d.ts +0 -1
  41. package/common/src/data-structures/utxo/Utxo.mjs +6 -19
  42. package/common/src/functions/index.cjs +1 -1
  43. package/common/src/functions/index.mjs +1 -0
  44. package/common/src/functions/pre-transaction/buildCommitmentValidationData.cjs +1 -1
  45. package/common/src/functions/pre-transaction/buildCommitmentValidationData.mjs +43 -86
  46. package/common/src/functions/pre-transaction/outputUtxoProcessing.cjs +1 -1
  47. package/common/src/functions/pre-transaction/outputUtxoProcessing.d.ts +2 -2
  48. package/common/src/functions/pre-transaction/outputUtxoProcessing.mjs +22 -28
  49. package/common/src/functions/snarkjs/constructGeneralZkProof.cjs +1 -1
  50. package/common/src/functions/snarkjs/constructGeneralZkProof.mjs +43 -49
  51. package/common/src/functions/utils/bigint-math.utils.cjs +1 -1
  52. package/common/src/functions/utils/bigint-math.utils.d.ts +2 -0
  53. package/common/src/functions/utils/bigint-math.utils.mjs +18 -1
  54. package/common/src/functions/utils/index.cjs +1 -1
  55. package/common/src/functions/utils/index.mjs +1 -1
  56. package/common/src/functions/web3/events/getInputUtxoAndBalance.cjs +1 -1
  57. package/common/src/functions/web3/events/getInputUtxoAndBalance.mjs +44 -94
  58. package/common/src/functions/web3/events/getShieldedBalance.cjs +1 -1
  59. package/common/src/functions/web3/events/getShieldedBalance.mjs +64 -64
  60. package/common/src/webworker/logError-D8yBaP96.js +2 -0
  61. package/common/src/webworker/package.json +1 -1
  62. package/common/src/webworker/performTaskWithWorker.cjs +1 -1
  63. package/common/src/webworker/performTaskWithWorker.mjs +17 -18
  64. package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.cjs +1 -1
  65. package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.mjs +1 -1
  66. package/common/src/webworker/utxoWorkerNode.cjs +1 -1
  67. package/common/src/webworker/viteWorkerURL.constant.cjs +3 -4
  68. package/common/src/webworker/viteWorkerURL.constant.d.ts +0 -1
  69. package/common/src/webworker/viteWorkerURL.constant.mjs +3 -4
  70. package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.cjs +1 -1
  71. package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.mjs +1 -1
  72. package/common/src/webworker/zkProofWorkerNode.cjs +1 -1
  73. package/package.json +1 -1
  74. package/react-native/HinkalWebViewWorker.cjs +4 -76
  75. package/react-native/HinkalWebViewWorker.mjs +49 -152
  76. package/react-native/bridge/HinkalRNWorker.cjs +1 -1
  77. package/react-native/bridge/HinkalRNWorker.d.ts +0 -1
  78. package/react-native/bridge/HinkalRNWorker.mjs +11 -16
  79. package/react-native/shims/circomlibjs-hinkal-fork.js +2 -2
  80. package/react-native/shims/circomlibjs.js +2 -2
  81. package/react-native/workerCDNUrls.cjs +1 -1
  82. package/react-native/workerCDNUrls.d.ts +0 -1
  83. package/react-native/workerCDNUrls.mjs +2 -2
  84. package/sdk/package.json.cjs +1 -1
  85. package/sdk/package.json.mjs +1 -1
  86. package/common/src/crypto/rnCryptoBridge.cjs +0 -1
  87. package/common/src/crypto/rnCryptoBridge.d.ts +0 -8
  88. package/common/src/crypto/rnCryptoBridge.mjs +0 -10
  89. package/common/src/crypto/rnUtxoCrypto.cjs +0 -1
  90. package/common/src/crypto/rnUtxoCrypto.d.ts +0 -14
  91. package/common/src/crypto/rnUtxoCrypto.mjs +0 -40
  92. package/common/src/functions/utils/hinkalTiming.utils.cjs +0 -1
  93. package/common/src/functions/utils/hinkalTiming.utils.d.ts +0 -11
  94. package/common/src/functions/utils/hinkalTiming.utils.mjs +0 -21
  95. package/common/src/functions/utils/utxoPadding.utils.cjs +0 -1
  96. package/common/src/functions/utils/utxoPadding.utils.d.ts +0 -2
  97. package/common/src/functions/utils/utxoPadding.utils.mjs +0 -14
  98. package/common/src/webworker/cryptoWorker/cryptoWorker.types.cjs +0 -1
  99. package/common/src/webworker/cryptoWorker/cryptoWorker.types.d.ts +0 -49
  100. package/common/src/webworker/cryptoWorker/cryptoWorker.types.mjs +0 -6
  101. package/common/src/webworker/cryptoWorker/cryptoWorkerLauncher.d.ts +0 -1
  102. package/common/src/webworker/cryptoWorker/cryptoWorkerLogic.d.ts +0 -2
  103. package/common/src/webworker/logError-DFS-H2t0.js +0 -2
  104. package/react-native/bridge/RnWebViewCryptoBridge.cjs +0 -1
  105. package/react-native/bridge/RnWebViewCryptoBridge.d.ts +0 -7
  106. package/react-native/bridge/RnWebViewCryptoBridge.mjs +0 -49
@@ -1,39 +1,33 @@
1
1
  import { bigintMax as e, countTotalAmountInUtxos as t } from "../utils/amounts.utils.mjs";
2
2
  import { transactionErrorCodes as n } from "../../error-handling/error-codes.constants.mjs";
3
- import { getSpendingPublicKeyForRn as r } from "../../crypto/rnUtxoCrypto.mjs";
4
- import { Utxo as i } from "../../data-structures/utxo/Utxo.mjs";
5
- import { createRnDeltaTiming as a } from "../utils/hinkalTiming.utils.mjs";
3
+ import { Utxo as r } from "../../data-structures/utxo/Utxo.mjs";
6
4
  //#region libs/shared/common/src/functions/pre-transaction/outputUtxoProcessing.ts
7
- var o = async (o, s, c, l, u = !0, d, f) => {
8
- let p = a("mainThread.outputUtxo"), m = t(s), { erc20TokenAddress: h, mintAddress: g } = s[0];
9
- if (u && c < 0n && m + c < 0n) throw Error(n.INSUFFICIENT_FUNDS_TO_TRANSACT);
10
- p.log("sumInputs");
11
- let _ = await r(o), v = [await i.createAsync({
12
- amount: e(m + c, 0n),
13
- erc20TokenAddress: h,
14
- mintAddress: g,
15
- nullifyingKey: o.getShieldedPrivateKey(),
16
- timeStamp: l,
17
- spendingPublicKey: _,
5
+ var i = (i, a, o, s, c = !0, l, u) => {
6
+ let d = t(a), { erc20TokenAddress: f, mintAddress: p } = a[0];
7
+ if (c && o < 0n && d + o < 0n) throw Error(n.INSUFFICIENT_FUNDS_TO_TRANSACT);
8
+ let m = [new r({
9
+ amount: e(d + o, 0n),
10
+ erc20TokenAddress: f,
11
+ mintAddress: p,
12
+ nullifyingKey: i.getShieldedPrivateKey(),
13
+ timeStamp: s,
14
+ spendingPublicKey: i.getSpendingKeyPair().pubSpendingBJJPoint,
18
15
  isNewStyle: !0
19
16
  })];
20
- if (p.log("newUtxo-change", {
21
- randomization: !!v[0].randomization,
22
- h0: !!v[0].H0
23
- }), d !== void 0 && f !== void 0) {
24
- let [e, t, n, , r] = d.split(",");
25
- v.push(new i({
26
- amount: f,
27
- erc20TokenAddress: h,
28
- mintAddress: g,
17
+ if (l !== void 0 && u !== void 0) {
18
+ let [e, t, n, , i] = l.split(",");
19
+ m.push(new r({
20
+ amount: u,
21
+ erc20TokenAddress: f,
22
+ mintAddress: p,
29
23
  H0: [BigInt(t), BigInt(n)],
30
24
  stealthAddress: e,
31
- encryptionKey: r,
32
- timeStamp: l,
25
+ encryptionKey: i,
26
+ timeStamp: s,
33
27
  isNewStyle: !0
34
- })), p.log("newUtxo-recipient");
28
+ }));
35
29
  }
36
- return p.log("done", { outputCount: v.length }), { outputUtxos: v };
30
+ return { outputUtxos: m };
37
31
  };
38
32
  //#endregion
39
- export { o as outputUtxoProcessing };
33
+ export { i as outputUtxoProcessing };
@@ -1 +1 @@
1
- const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../crypto/poseidon.cjs`),r=require(`../web3/etherFunctions.cjs`),i=require(`../../data-structures/crypto-keys/keys.cjs`),a=require(`../utils/time.utils.cjs`),o=require(`../../types/external-action.types.cjs`),s=require(`../../error-handling/logger.cjs`),c=require(`../utils/hinkalTiming.utils.cjs`),l=require(`../utils/bit.operations.cjs`),u=require(`./common.snarkjs.cjs`),d=require(`./signedMessageHash.cjs`),ee=require(`./generateCircomData.cjs`),te=require(`../../data-structures/AccountActions/AccountActions.cjs`),f=require(`./generateMainAndCommitmentZkProof.cjs`),p=require(`./getMerkleTreeSiblingsAndRootHashes.cjs`),m=require(`../private-wallet/emporium.helpers.cjs`);var h=async(h,g,_,v,y,b,x,ne,S,C=t.zeroAddress,w=e.chainIds.localhost,T=g.map(()=>!1),E=void 0,D,O)=>{let k=c.createRnDeltaTiming(`webView.getDataFromWorkers`),A=u.getZkProofVerifierName(g,_),j=u.calcAmountChanges(g,_),M=g.map(e=>e[0].erc20TokenAddress),N=u.calcEncryptedOutputs(_),P=t.defaultSignatureData,F=v.getShieldedPrivateKey(),{pubSpendingBJJPoint:I}=v.getSpendingKeyPair(),L=u.calcStealthAddressStructure(i.UserKeys.findCorrectRandomization(r.randomBigInt(31),F),F,v.getSpendingKeyPair().pubSpendingBJJPoint),{inCommitmentSiblings:re,inCommitmentSiblingSides:R,rootHashHinkal:z,inNullifiers:B}=await p.getDataFromWorkers(w,h,g.map(e=>e.map(e=>e.getConstructableParams())));k.log(`done`,{verifierName:A,chainId:w});let V=u.buildOutCommitments(_),H=r.randomBigInt(31),U=n.poseidonFunction(H),W=BigInt(_.length>0?_[0][0].timeStamp:a.getCurrentTimeInSeconds()),G={rootHashHinkal:z,spendingPublicKey:I,nullifyingPrivateKey:F,erc20TokenAddresses:M,amountChanges:j,inAmounts:g.map(e=>e.map(e=>e.amount.toString())),inRandomizations:g.map(e=>e.map(e=>u.getUtxoCircuitInRandomization(e))),inH0Ax:g.map(e=>e.map(e=>u.getUtxoCircuitH0Coords(e)[0].toString())),inH0Ay:g.map(e=>e.map(e=>u.getUtxoCircuitH0Coords(e)[1].toString())),isNewStyle:g.map(e=>e.map(e=>!!e.isNewStyle)),inTimeStamps:g.map(e=>e.map(e=>e.timeStamp)),inNullifiers:B,inCommitmentSiblings:re,inCommitmentSiblingSides:R,outAmounts:_.map(e=>e.map(e=>e.amount.toString())),outTimeStamp:W,outPublicKeys:_.map(e=>e.map(e=>e.getStealthAddress())),outCommitments:V,calldataHash:0n,messageSeed:H,H0Ax:l.takeOffHighestBit(L.extraRandomization),H0Ay:L.H0},K=u.calcPublicSignalCount(A,G.erc20TokenAddresses,G.amountChanges,G.inNullifiers,G.outCommitments),q=u.calcAmountChanges(g,_,!0),J=u.getSlippageValues(q);s.Logger.log({publicSignalCount:K});let Y=Array.isArray(x)?x:[x],ie=e.getOnchainChainId(w),ae=O?te.AccountActions.getSignerAddressFromPrivateKey(ie,O):void 0,X=y===o.ExternalActionId.Emporium?await m.encodeEmporiumMetadata(w,b??t.zeroAddress,O,Y,U,ae):await m.encodeEmporiumMetadata(w,t.zeroAddress,void 0,y===0n?[]:Y,U,t.zeroAddress);G.calldataHash=u.createCallDataHash(K,C,b,y,X,N,E,J,T,S,P,D);let Z=d.computeSignedMessageHashEvm({rootHashHinkal:z,erc20TokenAddresses:M,amountChanges:j,outTimeStamp:W,inNullifiers:B,outCommitments:V,calldataHash:G.calldataHash,message:U,outH1Ay:L.H1,H0Ax:G.H0Ax,H0Ay:L.H0}),{R8:Q,S:oe}=v.signEddsa(Z);G.eddsaSignature=[Q[0],Q[1],oe],G.signedMessageHash=Z;let $=A.startsWith(`mainEVMCircuitMin0`),se={outTimeStamp:W,calldataHash:G.calldataHash,messageSeed:H},{zkCallData:ce,commitmentValidationData:le}=await f.generateMainAndCommitmentZkProof(w,v,M,g,A,$?se:G,ne);return{zkCallData:ce,circomData:ee.generateCircomData(V,B,z,q,M,_,N,K,y,b,X,C,G.calldataHash,L,T,E,$?Number(W):void 0,J,S,P,D),dimData:{tokenNumber:g.length,nullifierAmount:g.length>0?g[0].length:0,outputAmount:_.length>0?_[0].length:0},encryptedOutputs:N,commitmentValidationData:le}};exports.constructZkProof=h;
1
+ const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../crypto/poseidon.cjs`),r=require(`../web3/etherFunctions.cjs`),i=require(`../../data-structures/crypto-keys/keys.cjs`),a=require(`../utils/time.utils.cjs`),o=require(`../../types/external-action.types.cjs`),s=require(`../../error-handling/logger.cjs`),c=require(`../utils/bit.operations.cjs`),l=require(`./common.snarkjs.cjs`),ee=require(`./signedMessageHash.cjs`),u=require(`./generateCircomData.cjs`),te=require(`../../data-structures/AccountActions/AccountActions.cjs`),d=require(`./generateMainAndCommitmentZkProof.cjs`),f=require(`./getMerkleTreeSiblingsAndRootHashes.cjs`),p=require(`../private-wallet/emporium.helpers.cjs`);var m=async(m,h,g,_,v,y,b,x,S,C=t.zeroAddress,w=e.chainIds.localhost,T=h.map(()=>!1),E=void 0,D,O)=>{let k=l.getZkProofVerifierName(h,g),A=l.calcAmountChanges(h,g),j=h.map(e=>e[0].erc20TokenAddress),M=l.calcEncryptedOutputs(g),N=t.defaultSignatureData,P=_.getShieldedPrivateKey(),{pubSpendingBJJPoint:F}=_.getSpendingKeyPair(),I=l.calcStealthAddressStructure(i.UserKeys.findCorrectRandomization(r.randomBigInt(31),P),P,_.getSpendingKeyPair().pubSpendingBJJPoint),{inCommitmentSiblings:ne,inCommitmentSiblingSides:re,rootHashHinkal:L,inNullifiers:R}=await f.getDataFromWorkers(w,m,h.map(e=>e.map(e=>e.getConstructableParams()))),z=l.buildOutCommitments(g),B=r.randomBigInt(31),V=n.poseidonFunction(B),H=BigInt(g.length>0?g[0][0].timeStamp:a.getCurrentTimeInSeconds()),U={rootHashHinkal:L,spendingPublicKey:F,nullifyingPrivateKey:P,erc20TokenAddresses:j,amountChanges:A,inAmounts:h.map(e=>e.map(e=>e.amount.toString())),inRandomizations:h.map(e=>e.map(e=>l.getUtxoCircuitInRandomization(e))),inH0Ax:h.map(e=>e.map(e=>l.getUtxoCircuitH0Coords(e)[0].toString())),inH0Ay:h.map(e=>e.map(e=>l.getUtxoCircuitH0Coords(e)[1].toString())),isNewStyle:h.map(e=>e.map(e=>!!e.isNewStyle)),inTimeStamps:h.map(e=>e.map(e=>e.timeStamp)),inNullifiers:R,inCommitmentSiblings:ne,inCommitmentSiblingSides:re,outAmounts:g.map(e=>e.map(e=>e.amount.toString())),outTimeStamp:H,outPublicKeys:g.map(e=>e.map(e=>e.getStealthAddress())),outCommitments:z,calldataHash:0n,messageSeed:B,H0Ax:c.takeOffHighestBit(I.extraRandomization),H0Ay:I.H0},W=l.calcPublicSignalCount(k,U.erc20TokenAddresses,U.amountChanges,U.inNullifiers,U.outCommitments),G=l.calcAmountChanges(h,g,!0),K=l.getSlippageValues(G);s.Logger.log({publicSignalCount:W});let q=Array.isArray(b)?b:[b],J=e.getOnchainChainId(w),Y=O?te.AccountActions.getSignerAddressFromPrivateKey(J,O):void 0,X=v===o.ExternalActionId.Emporium?await p.encodeEmporiumMetadata(w,y??t.zeroAddress,O,q,V,Y):await p.encodeEmporiumMetadata(w,t.zeroAddress,void 0,v===0n?[]:q,V,t.zeroAddress);U.calldataHash=l.createCallDataHash(W,C,y,v,X,M,E,K,T,S,N,D);let Z=ee.computeSignedMessageHashEvm({rootHashHinkal:L,erc20TokenAddresses:j,amountChanges:A,outTimeStamp:H,inNullifiers:R,outCommitments:z,calldataHash:U.calldataHash,message:V,outH1Ay:I.H1,H0Ax:U.H0Ax,H0Ay:I.H0}),{R8:Q,S:ie}=_.signEddsa(Z);U.eddsaSignature=[Q[0],Q[1],ie],U.signedMessageHash=Z;let $=k.startsWith(`mainEVMCircuitMin0`),ae={outTimeStamp:H,calldataHash:U.calldataHash,messageSeed:B},{zkCallData:oe,commitmentValidationData:se}=await d.generateMainAndCommitmentZkProof(w,_,j,h,k,$?ae:U,x);return{zkCallData:oe,circomData:u.generateCircomData(z,R,L,G,j,g,M,W,v,y,X,C,U.calldataHash,I,T,E,$?Number(H):void 0,K,S,N,D),dimData:{tokenNumber:h.length,nullifierAmount:h.length>0?h[0].length:0,outputAmount:g.length>0?g[0].length:0},encryptedOutputs:M,commitmentValidationData:se}};exports.constructZkProof=m;
@@ -1,55 +1,49 @@
1
- import { chainIds as e, getOnchainChainId as ee } from "../../constants/chains.constants.mjs";
2
- import { defaultSignatureData as te, zeroAddress as t } from "../../constants/protocol.constants.mjs";
3
- import { poseidonFunction as ne } from "../../crypto/poseidon.mjs";
4
- import { randomBigInt as n } from "../web3/etherFunctions.mjs";
5
- import { UserKeys as re } from "../../data-structures/crypto-keys/keys.mjs";
6
- import { getCurrentTimeInSeconds as r } from "../utils/time.utils.mjs";
7
- import { ExternalActionId as i } from "../../types/external-action.types.mjs";
8
- import { Logger as ie } from "../../error-handling/logger.mjs";
9
- import { createRnDeltaTiming as ae } from "../utils/hinkalTiming.utils.mjs";
10
- import { takeOffHighestBit as oe } from "../utils/bit.operations.mjs";
11
- import { buildOutCommitments as a, calcAmountChanges as o, calcEncryptedOutputs as s, calcPublicSignalCount as c, calcStealthAddressStructure as l, createCallDataHash as se, getSlippageValues as ce, getUtxoCircuitH0Coords as u, getUtxoCircuitInRandomization as le, getZkProofVerifierName as ue } from "./common.snarkjs.mjs";
1
+ import { chainIds as e, getOnchainChainId as t } from "../../constants/chains.constants.mjs";
2
+ import { defaultSignatureData as ee, zeroAddress as n } from "../../constants/protocol.constants.mjs";
3
+ import { poseidonFunction as te } from "../../crypto/poseidon.mjs";
4
+ import { randomBigInt as r } from "../web3/etherFunctions.mjs";
5
+ import { UserKeys as i } from "../../data-structures/crypto-keys/keys.mjs";
6
+ import { getCurrentTimeInSeconds as a } from "../utils/time.utils.mjs";
7
+ import { ExternalActionId as o } from "../../types/external-action.types.mjs";
8
+ import { Logger as s } from "../../error-handling/logger.mjs";
9
+ import { takeOffHighestBit as ne } from "../utils/bit.operations.mjs";
10
+ import { buildOutCommitments as re, calcAmountChanges as c, calcEncryptedOutputs as ie, calcPublicSignalCount as ae, calcStealthAddressStructure as oe, createCallDataHash as se, getSlippageValues as ce, getUtxoCircuitH0Coords as l, getUtxoCircuitInRandomization as le, getZkProofVerifierName as ue } from "./common.snarkjs.mjs";
12
11
  import { computeSignedMessageHashEvm as de } from "./signedMessageHash.mjs";
13
12
  import { generateCircomData as fe } from "./generateCircomData.mjs";
14
- import { AccountActions as pe } from "../../data-structures/AccountActions/AccountActions.mjs";
13
+ import { AccountActions as u } from "../../data-structures/AccountActions/AccountActions.mjs";
15
14
  import { generateMainAndCommitmentZkProof as d } from "./generateMainAndCommitmentZkProof.mjs";
16
- import { getDataFromWorkers as me } from "./getMerkleTreeSiblingsAndRootHashes.mjs";
17
- import { encodeEmporiumMetadata as f } from "../private-wallet/emporium.helpers.mjs";
15
+ import { getDataFromWorkers as f } from "./getMerkleTreeSiblingsAndRootHashes.mjs";
16
+ import { encodeEmporiumMetadata as p } from "../private-wallet/emporium.helpers.mjs";
18
17
  //#region libs/shared/common/src/functions/snarkjs/constructGeneralZkProof.ts
19
- var p = async (p, m, h, g, _, v, y, b, x, S = t, C = e.localhost, w = m.map(() => !1), T = void 0, E, D) => {
20
- let he = ae("webView.getDataFromWorkers"), O = ue(m, h), k = o(m, h), A = m.map((e) => e[0].erc20TokenAddress), j = s(h), M = te, N = g.getShieldedPrivateKey(), { pubSpendingBJJPoint: P } = g.getSpendingKeyPair(), F = l(re.findCorrectRandomization(n(31), N), N, g.getSpendingKeyPair().pubSpendingBJJPoint), { inCommitmentSiblings: I, inCommitmentSiblingSides: L, rootHashHinkal: R, inNullifiers: z } = await me(C, p, m.map((e) => e.map((e) => e.getConstructableParams())));
21
- he.log("done", {
22
- verifierName: O,
23
- chainId: C
24
- });
25
- let B = a(h), V = n(31), H = ne(V), U = BigInt(h.length > 0 ? h[0][0].timeStamp : r()), W = {
18
+ var m = async (m, h, g, _, v, y, b, pe, x, S = n, C = e.localhost, w = h.map(() => !1), T = void 0, E, D) => {
19
+ let O = ue(h, g), k = c(h, g), A = h.map((e) => e[0].erc20TokenAddress), j = ie(g), M = ee, N = _.getShieldedPrivateKey(), { pubSpendingBJJPoint: P } = _.getSpendingKeyPair(), F = oe(i.findCorrectRandomization(r(31), N), N, _.getSpendingKeyPair().pubSpendingBJJPoint), { inCommitmentSiblings: I, inCommitmentSiblingSides: L, rootHashHinkal: R, inNullifiers: z } = await f(C, m, h.map((e) => e.map((e) => e.getConstructableParams()))), B = re(g), V = r(31), H = te(V), U = BigInt(g.length > 0 ? g[0][0].timeStamp : a()), W = {
26
20
  rootHashHinkal: R,
27
21
  spendingPublicKey: P,
28
22
  nullifyingPrivateKey: N,
29
23
  erc20TokenAddresses: A,
30
24
  amountChanges: k,
31
- inAmounts: m.map((e) => e.map((e) => e.amount.toString())),
32
- inRandomizations: m.map((e) => e.map((e) => le(e))),
33
- inH0Ax: m.map((e) => e.map((e) => u(e)[0].toString())),
34
- inH0Ay: m.map((e) => e.map((e) => u(e)[1].toString())),
35
- isNewStyle: m.map((e) => e.map((e) => !!e.isNewStyle)),
36
- inTimeStamps: m.map((e) => e.map((e) => e.timeStamp)),
25
+ inAmounts: h.map((e) => e.map((e) => e.amount.toString())),
26
+ inRandomizations: h.map((e) => e.map((e) => le(e))),
27
+ inH0Ax: h.map((e) => e.map((e) => l(e)[0].toString())),
28
+ inH0Ay: h.map((e) => e.map((e) => l(e)[1].toString())),
29
+ isNewStyle: h.map((e) => e.map((e) => !!e.isNewStyle)),
30
+ inTimeStamps: h.map((e) => e.map((e) => e.timeStamp)),
37
31
  inNullifiers: z,
38
32
  inCommitmentSiblings: I,
39
33
  inCommitmentSiblingSides: L,
40
- outAmounts: h.map((e) => e.map((e) => e.amount.toString())),
34
+ outAmounts: g.map((e) => e.map((e) => e.amount.toString())),
41
35
  outTimeStamp: U,
42
- outPublicKeys: h.map((e) => e.map((e) => e.getStealthAddress())),
36
+ outPublicKeys: g.map((e) => e.map((e) => e.getStealthAddress())),
43
37
  outCommitments: B,
44
38
  calldataHash: 0n,
45
39
  messageSeed: V,
46
- H0Ax: oe(F.extraRandomization),
40
+ H0Ax: ne(F.extraRandomization),
47
41
  H0Ay: F.H0
48
- }, G = c(O, W.erc20TokenAddresses, W.amountChanges, W.inNullifiers, W.outCommitments), K = o(m, h, !0), q = ce(K);
49
- ie.log({ publicSignalCount: G });
50
- let J = Array.isArray(y) ? y : [y], ge = ee(C), Y = D ? pe.getSignerAddressFromPrivateKey(ge, D) : void 0, X = _ === i.Emporium ? await f(C, v ?? t, D, J, H, Y) : await f(C, t, void 0, _ === 0n ? [] : J, H, t);
51
- W.calldataHash = se(G, S, v, _, X, j, T, q, w, x, M, E);
52
- let Z = de({
42
+ }, G = ae(O, W.erc20TokenAddresses, W.amountChanges, W.inNullifiers, W.outCommitments), K = c(h, g, !0), q = ce(K);
43
+ s.log({ publicSignalCount: G });
44
+ let J = Array.isArray(b) ? b : [b], me = t(C), he = D ? u.getSignerAddressFromPrivateKey(me, D) : void 0, Y = v === o.Emporium ? await p(C, y ?? n, D, J, H, he) : await p(C, n, void 0, v === 0n ? [] : J, H, n);
45
+ W.calldataHash = se(G, S, y, v, Y, j, T, q, w, x, M, E);
46
+ let X = de({
53
47
  rootHashHinkal: R,
54
48
  erc20TokenAddresses: A,
55
49
  amountChanges: k,
@@ -61,28 +55,28 @@ var p = async (p, m, h, g, _, v, y, b, x, S = t, C = e.localhost, w = m.map(() =
61
55
  outH1Ay: F.H1,
62
56
  H0Ax: W.H0Ax,
63
57
  H0Ay: F.H0
64
- }), { R8: Q, S: _e } = g.signEddsa(Z);
58
+ }), { R8: Z, S: ge } = _.signEddsa(X);
65
59
  W.eddsaSignature = [
66
- Q[0],
67
- Q[1],
68
- _e
69
- ], W.signedMessageHash = Z;
70
- let $ = O.startsWith("mainEVMCircuitMin0"), ve = {
60
+ Z[0],
61
+ Z[1],
62
+ ge
63
+ ], W.signedMessageHash = X;
64
+ let Q = O.startsWith("mainEVMCircuitMin0"), $ = {
71
65
  outTimeStamp: U,
72
66
  calldataHash: W.calldataHash,
73
67
  messageSeed: V
74
- }, { zkCallData: ye, commitmentValidationData: be } = await d(C, g, A, m, O, $ ? ve : W, b);
68
+ }, { zkCallData: _e, commitmentValidationData: ve } = await d(C, _, A, h, O, Q ? $ : W, pe);
75
69
  return {
76
- zkCallData: ye,
77
- circomData: fe(B, z, R, K, A, h, j, G, _, v, X, S, W.calldataHash, F, w, T, $ ? Number(U) : void 0, q, x, M, E),
70
+ zkCallData: _e,
71
+ circomData: fe(B, z, R, K, A, g, j, G, v, y, Y, S, W.calldataHash, F, w, T, Q ? Number(U) : void 0, q, x, M, E),
78
72
  dimData: {
79
- tokenNumber: m.length,
80
- nullifierAmount: m.length > 0 ? m[0].length : 0,
81
- outputAmount: h.length > 0 ? h[0].length : 0
73
+ tokenNumber: h.length,
74
+ nullifierAmount: h.length > 0 ? h[0].length : 0,
75
+ outputAmount: g.length > 0 ? g[0].length : 0
82
76
  },
83
77
  encryptedOutputs: j,
84
- commitmentValidationData: be
78
+ commitmentValidationData: ve
85
79
  };
86
80
  };
87
81
  //#endregion
88
- export { p as constructZkProof };
82
+ export { m as constructZkProof };
@@ -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(`./abi.utils.cjs`),require(`./serialize.utils.cjs`),require(`./caseInsensitive.utils.cjs`),require(`./amounts.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(`./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,6 +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 "./bigint-math.utils.mjs";
5
6
  import "./time.utils.mjs";
6
7
  import "./upToDateState.mjs";
7
8
  import "./cacheFunctions.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(`../../utils/utxoPadding.utils.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`),d=require(`../../utils/hinkalTiming.utils.cjs`);var f=new(require(`async-mutex`)).Mutex,p=async(e,t)=>{if(e.allowParallelBalanceLocalDecryption)return t();let n=d.createRnDeltaTiming(`utxoPrep.mutex`);return f.isLocked()&&n.log(`waiting-for-lock`),f.runExclusive(async()=>{n.log(`lock-acquired`);try{return await t()}finally{n.log(`lock-released`)}})},m=async(e,t,n,a,o,s,c,l,u)=>p(e,async()=>{let f=d.createRnDeltaTiming(`utxoPrep.decrypt`);u+=1;let p=s.slice(u);f.log(`batchProcess-start`,{outputsSlice:p.length,cached:c.length});let{lastOutput:m,additionalEncryptedOutputs:h}=await e.utxoUtils.batchProcess(p,l,t,n);f.log(`batchProcess-done`,{additionalEncryptedOutputs:h.length});let g=[...c,...h],_=d.createRnDeltaTiming(`wallet.checkAddress`);await r.checkAddressNotUpdated(e,a),_.log(`during-decrypt`),i.setHinkalCache({lastOutput:m,encryptedOutputs:g},e,n,o),f.log(`cache-write`,{encryptedOutputs:g.length});let v=await e.utxoUtils.buildBatchProcess(g,t,n);return f.log(`buildBatchProcess-done`,{utxoCount:v.length}),v}),h=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},g=async(e,t,n,r,i,a,o,s,c)=>{try{return await h(e,t,n,i)}catch{return m(e,t,n,r,i,a,o,s,c)}},_=e=>{if(Array.isArray(e))return e;if(e!==void 0)return[e]},v=async(e,t,n)=>await e.utxoUtils.batchFilterUtxosWithNullifier(t,n),y=async(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;){let[t]=await n.createPaddingUtxos(1,{amount:0n,erc20TokenAddress:o,mintAddress:c,nullifyingKey:i,spendingPublicKey:a,isNewStyle:!0});if(e.push(t),r)for(;e.length>6;)e.splice(e.length-1)}},b=async({hinkal:e,chainId:t,passedShieldedPublicKey:n=void 0,ethAddress:a=void 0,resetCacheBefore:o=!1,allowRemoteDecryption:s=!1,useBlockedUtxos:c=!1})=>{let l=d.createRnDeltaTiming(`utxoPrep`);l.log(`start`);let u=a;u?l.log(`wallet.getEthereumAddress-skipped`,{ethAddressPassed:!0}):(u=await e.getEthereumAddress(),l.log(`wallet.getEthereumAddress`));let f=n??e.userKeys.getShieldedPublicKey(),{userKeys:p}=e,h=e.encryptedOutputsByChain[t],_=e.nullifiersByChain[t],y=Array.from(h);o&&i.resetCache(e,t,f);let{encryptedOutputs:b,lastOutput:x}=i.getHinkalCache(e,t,f);l.log(`cache.read`,{cachedEncryptedOutputs:b.length});let S=d.createRnDeltaTiming(`wallet.checkAddress`);await r.checkAddressNotUpdated(e,u),S.log(`before-decrypt`);let C=x!==``,w=y.findIndex(e=>e.value===x);l.log(`findLastOutputIndex`,{hinkalOutputs:y.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?y.length-(w+1):0});let j=[];O?(j=await m(e,p,t,u,f,y,b,x,w),l.log(`decryptLocally-done`,{utxoCount:j.length})):k?(j=await g(e,p,t,u,f,y,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=d.createRnDeltaTiming(`wallet.checkAddress`);await r.checkAddressNotUpdated(e,u),M.log(`after-decrypt`);let N=await v(e,j,_);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}},x=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 b({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)}},S=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 g=l??n.userKeys.getShieldedPrivateKey(),v=n.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,{inputUtxos:S}=h?await x({hinkal:n,chainId:c,ethAddress:d,passedShieldedPrivateKey:l,resetCacheBefore:f,allowRemoteDecryption:m}):await b({hinkal:n,tokenWithId:r,minInput:i,sliceIfMore6:s,chainId:c,passedShieldedPrivateKey:l,passedShieldedPublicKey:u,ethAddress:d,resetCacheBefore:f,allowRemoteDecryption:m}),C=_(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;await y(n,i,s,g,v,l?o.formatMintAddress(r).compressedAddress.toLowerCase():r.toLowerCase(),a,u)}return w};exports.attemptGetInputUtxosRemotely=g,exports.getInputUtxoAndBalance=b,exports.getInputUtxoAndBalanceOfStuckUtxos=x,exports.getInputUtxoAndBalancePerToken=S,exports.getInputUtxosRemotely=h;
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,6 +1,6 @@
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 { createPaddingUtxos as r } from "../../utils/utxoPadding.utils.mjs";
3
+ import { Utxo as r } from "../../../data-structures/utxo/Utxo.mjs";
4
4
  import { checkAddressNotUpdated as i } from "../../utils/upToDateState.mjs";
5
5
  import { getHinkalCache as a, resetCache as o, setHinkalCache as s } from "../../utils/cacheFunctions.mjs";
6
6
  import { encodeTokenWithId as c } from "../../utils/encodeTokenWithId.mjs";
@@ -9,100 +9,50 @@ import { getInputUtxosEnclave as u } from "./getInputUtxosEnclave.mjs";
9
9
  import { hashEthereumAddress as d } from "../../utils/addresses.mjs";
10
10
  import { getScheduledTransactionsNullifierIndexes as f } from "../../../API/scheduled-transactions-calls.mjs";
11
11
  import { addressToHexFormat as p } from "../../utils/tron.utils.mjs";
12
- import { createRnDeltaTiming as m } from "../../utils/hinkalTiming.utils.mjs";
13
- import { Mutex as h } from "async-mutex";
12
+ import { Mutex as m } from "async-mutex";
14
13
  //#region libs/shared/common/src/functions/web3/events/getInputUtxoAndBalance.ts
15
- var g = new h(), _ = async (e, t) => {
16
- if (e.allowParallelBalanceLocalDecryption) return t();
17
- let n = m("utxoPrep.mutex");
18
- return g.isLocked() && n.log("waiting-for-lock"), g.runExclusive(async () => {
19
- n.log("lock-acquired");
20
- try {
21
- return await t();
22
- } finally {
23
- n.log("lock-released");
24
- }
25
- });
26
- }, v = async (e, t, n, r, a, o, c, l, u) => _(e, async () => {
27
- let d = m("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 () => {
28
15
  u += 1;
29
- let f = o.slice(u);
30
- d.log("batchProcess-start", {
31
- outputsSlice: f.length,
32
- cached: c.length
33
- });
34
- let { lastOutput: p, additionalEncryptedOutputs: h } = await e.utxoUtils.batchProcess(f, l, t, n);
35
- d.log("batchProcess-done", { additionalEncryptedOutputs: h.length });
36
- let g = [...c, ...h], _ = m("wallet.checkAddress");
37
- await i(e, r), _.log("during-decrypt"), s({
38
- lastOutput: p,
39
- encryptedOutputs: g
40
- }, e, n, a), d.log("cache-write", { encryptedOutputs: g.length });
41
- let v = await e.utxoUtils.buildBatchProcess(g, t, n);
42
- return d.log("buildBatchProcess-done", { utxoCount: v.length }), v;
43
- }), y = async (e, t, n, r) => {
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) => {
44
22
  let { utxos: i, encryptedOutputs: a, lastOutput: o } = await u(e, n, t);
45
23
  return s({
46
24
  encryptedOutputs: a,
47
25
  lastOutput: o
48
26
  }, e, n, r), i;
49
- }, b = async (e, t, n, r, i, a, o, s, c) => {
27
+ }, y = async (e, t, n, r, i, a, o, s, c) => {
50
28
  try {
51
- return await y(e, t, n, i);
29
+ return await v(e, t, n, i);
52
30
  } catch {
53
- return v(e, t, n, r, i, a, o, s, c);
31
+ return _(e, t, n, r, i, a, o, s, c);
54
32
  }
55
- }, x = (e) => {
33
+ }, b = (e) => {
56
34
  if (Array.isArray(e)) return e;
57
35
  if (e !== void 0) return [e];
58
- }, S = async (e, t, n) => await e.utxoUtils.batchFilterUtxosWithNullifier(t, n), C = async (e, t, n, i, a, o, s, c) => {
59
- for (e.sort((e, t) => e.amount <= t.amount ? 1 : -1); e.length < t || e.length > t && e.length < 6;) {
60
- let [t] = await r(1, {
61
- amount: 0n,
62
- erc20TokenAddress: o,
63
- mintAddress: c,
64
- nullifyingKey: i,
65
- spendingPublicKey: a,
66
- isNewStyle: !0
67
- });
68
- if (e.push(t), n) for (; e.length > 6;) e.splice(e.length - 1);
69
- }
70
- }, w = async ({ hinkal: e, chainId: t, passedShieldedPublicKey: n = void 0, ethAddress: r = void 0, resetCacheBefore: s = !1, allowRemoteDecryption: c = !1, useBlockedUtxos: l = !1 }) => {
71
- let u = m("utxoPrep");
72
- u.log("start");
73
- let d = r;
74
- d ? u.log("wallet.getEthereumAddress-skipped", { ethAddressPassed: !0 }) : (d = await e.getEthereumAddress(), u.log("wallet.getEthereumAddress"));
75
- let f = n ?? e.userKeys.getShieldedPublicKey(), { userKeys: p } = e, h = e.encryptedOutputsByChain[t], g = e.nullifiersByChain[t], _ = Array.from(h);
76
- s && o(e, t, f);
77
- let { encryptedOutputs: y, lastOutput: x } = a(e, t, f);
78
- u.log("cache.read", { cachedEncryptedOutputs: y.length });
79
- let C = m("wallet.checkAddress");
80
- await i(e, d), C.log("before-decrypt");
81
- let w = x !== "", T = _.findIndex((e) => e.value === x);
82
- u.log("findLastOutputIndex", {
83
- hinkalOutputs: _.length,
84
- lastOutputIndex: T
85
- });
86
- let E = T > -1, D = !w && T === -1, O = e.areMerkleTreeUpdatesDisabled(), k = !O && (E || !c && D), A = !O && c && D, j = !k && !A;
87
- u.log("branch", {
88
- decryptLocally: k,
89
- decryptRemotely: A,
90
- useCache: j,
91
- outputsSlice: T > -1 ? _.length - (T + 1) : 0
92
- });
93
- let M = [];
94
- k ? (M = await v(e, p, t, d, f, _, y, x, T), u.log("decryptLocally-done", { utxoCount: M.length })) : A ? (M = await b(e, p, t, d, f, _, y, x, T), u.log("decryptRemotely-done", { utxoCount: M.length })) : j && (M = await e.utxoUtils.buildBatchProcess(y, p, t), u.log("useCache-buildBatchProcess-done", { utxoCount: M.length }));
95
- let N = m("wallet.checkAddress");
96
- await i(e, d), N.log("after-decrypt");
97
- let P = await S(e, M, g);
98
- u.log("filterSpentUtxos", {
99
- allUtxos: M.length,
100
- inputUtxos: P.length
101
- });
102
- let F = l ? P.filter((e) => e.isBlocked) : P.filter((e) => !e.isBlocked);
103
- return u.log("done", { inputUtxos: F.length }), { inputUtxos: F };
104
- }, T = async ({ hinkal: e, chainId: n, passedShieldedPublicKey: r = void 0, ethAddress: i = void 0, resetCacheBefore: a = !1, allowRemoteDecryption: o = !1 }) => {
105
- let s = i ?? await e.getEthereumAddressByChain(n), c = d(t(n) ? p(s) : s), { inputUtxos: l } = await w({
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({
106
56
  hinkal: e,
107
57
  chainId: n,
108
58
  passedShieldedPublicKey: r,
@@ -117,15 +67,15 @@ var g = new h(), _ = async (e, t) => {
117
67
  nullifiers: l.map((e) => e.getNullifier())
118
68
  });
119
69
  return { inputUtxos: u.map((e) => l[e]).filter((e) => !!e) };
120
- }, E = 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 }) => {
121
- let g = s ?? t.userKeys.getShieldedPrivateKey(), _ = t.userKeys.getSpendingKeyPair().pubSpendingBJJPoint, { inputUtxos: v } = h ? await T({
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({
122
72
  hinkal: t,
123
73
  chainId: o,
124
74
  ethAddress: d,
125
75
  passedShieldedPrivateKey: s,
126
76
  resetCacheBefore: f,
127
77
  allowRemoteDecryption: m
128
- }) : await w({
78
+ }) : await C({
129
79
  hinkal: t,
130
80
  tokenWithId: r,
131
81
  minInput: i,
@@ -136,27 +86,27 @@ var g = new h(), _ = async (e, t) => {
136
86
  ethAddress: d,
137
87
  resetCacheBefore: f,
138
88
  allowRemoteDecryption: m
139
- }), y = x(r), b = /* @__PURE__ */ new Map();
89
+ }), y = b(r), x = /* @__PURE__ */ new Map();
140
90
  v.forEach((e) => {
141
91
  let t = e.getTokenAddress(o);
142
92
  if (y && !y.some((e) => n(e.erc20TokenAddress, t))) return;
143
93
  let r = c(o, {
144
94
  erc20TokenAddress: t,
145
95
  tokenId: 0
146
- }), i = b.get(r) ?? [];
147
- b.set(r, [...i, e]);
96
+ }), i = x.get(r) ?? [];
97
+ x.set(r, [...i, e]);
148
98
  }), p?.forEach((e) => {
149
99
  let t = c(o, {
150
100
  erc20TokenAddress: e.erc20TokenAddress,
151
101
  tokenId: 0
152
102
  });
153
- b.set(t, b.get(t) ?? []);
103
+ x.set(t, x.get(t) ?? []);
154
104
  });
155
- for (let [t, n] of b) {
105
+ for (let [t, n] of x) {
156
106
  let r = t.split("-")[0], s = Number(t.split("-")[1]), c = e(o), u = c ? r : void 0;
157
- await C(n, i, a, g, _, c ? l(r).compressedAddress.toLowerCase() : r.toLowerCase(), s, u);
107
+ S(n, i, a, g, _, c ? l(r).compressedAddress.toLowerCase() : r.toLowerCase(), s, u);
158
108
  }
159
- return b;
109
+ return x;
160
110
  };
161
111
  //#endregion
162
- export { b as attemptGetInputUtxosRemotely, w as getInputUtxoAndBalance, T as getInputUtxoAndBalanceOfStuckUtxos, E as getInputUtxoAndBalancePerToken, y 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;