@gurge/sdk 0.3.24 → 0.3.25

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 (41) hide show
  1. package/common/src/data-structures/Hinkal/hinkalWithdraw.cjs +1 -1
  2. package/common/src/data-structures/Hinkal/hinkalWithdraw.d.ts +1 -3
  3. package/common/src/data-structures/Hinkal/hinkalWithdraw.mjs +21 -34
  4. package/common/src/data-structures/MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.cjs +1 -1
  5. package/common/src/data-structures/MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.mjs +4 -4
  6. package/common/src/functions/pre-transaction/buildCommitmentValidationData.cjs +1 -1
  7. package/common/src/functions/pre-transaction/buildCommitmentValidationData.mjs +27 -20
  8. package/common/src/functions/pre-transaction/outputUtxoProcessing.cjs +1 -1
  9. package/common/src/functions/pre-transaction/outputUtxoProcessing.mjs +25 -20
  10. package/common/src/functions/snarkjs/constructGeneralZkProof.cjs +1 -1
  11. package/common/src/functions/snarkjs/constructGeneralZkProof.mjs +60 -65
  12. package/common/src/functions/snarkjs/generateMainAndCommitmentZkProof.cjs +1 -1
  13. package/common/src/functions/snarkjs/generateMainAndCommitmentZkProof.mjs +10 -21
  14. package/common/src/functions/snarkjs/generateZkProof.cjs +1 -1
  15. package/common/src/functions/snarkjs/generateZkProof.mjs +13 -24
  16. package/common/src/functions/snarkjs/generateZkProofEnclave.cjs +1 -1
  17. package/common/src/functions/snarkjs/generateZkProofEnclave.mjs +11 -14
  18. package/common/src/functions/snarkjs/generateZkProofSelf.cjs +1 -1
  19. package/common/src/functions/snarkjs/generateZkProofSelf.mjs +16 -22
  20. package/common/src/functions/utils/hinkalTiming.utils.cjs +1 -1
  21. package/common/src/functions/utils/hinkalTiming.utils.d.ts +4 -2
  22. package/common/src/functions/utils/hinkalTiming.utils.mjs +13 -10
  23. package/common/src/functions/web3/events/getInputUtxoAndBalance.cjs +1 -1
  24. package/common/src/functions/web3/events/getInputUtxoAndBalance.mjs +58 -42
  25. package/common/src/functions/web3/events/getInputUtxosEnclave.cjs +1 -1
  26. package/common/src/functions/web3/events/getInputUtxosEnclave.mjs +20 -21
  27. package/common/src/functions/web3/events/getShieldedBalance.cjs +1 -1
  28. package/common/src/functions/web3/events/getShieldedBalance.mjs +53 -56
  29. package/common/src/webworker/package.json +1 -1
  30. package/common/src/webworker/performTaskWithWorker.cjs +1 -1
  31. package/common/src/webworker/performTaskWithWorker.mjs +6 -6
  32. package/common/src/webworker/viteWorkerURL.constant.cjs +3 -3
  33. package/common/src/webworker/viteWorkerURL.constant.mjs +3 -3
  34. package/package.json +1 -1
  35. package/react-native/HinkalWebViewWorker.cjs +16 -4
  36. package/react-native/HinkalWebViewWorker.mjs +69 -49
  37. package/react-native/bridge/HinkalRNWorker.cjs +1 -1
  38. package/react-native/bridge/HinkalRNWorker.d.ts +1 -0
  39. package/react-native/bridge/HinkalRNWorker.mjs +16 -11
  40. package/sdk/package.json.cjs +1 -1
  41. package/sdk/package.json.mjs +1 -1
@@ -1,31 +1,20 @@
1
1
  import { getCustomProofGenerator as e } from "../utils/customEnclaveFunctionsRegister.mjs";
2
- import { createHinkalTiming as t } from "../utils/hinkalTiming.utils.mjs";
3
- import { Logger as n } from "../../error-handling/logger.mjs";
4
- import { getWASMFile as r, getZKeyFile as i } from "./getZKFiles.mjs";
5
- import { generateZkProofEnclave as a } from "./generateZkProofEnclave.mjs";
6
- import { generateZkProofSelf as o } from "./generateZkProofSelf.mjs";
2
+ import { Logger as t } from "../../error-handling/logger.mjs";
3
+ import { getWASMFile as n, getZKeyFile as r } from "./getZKFiles.mjs";
4
+ import { generateZkProofEnclave as i } from "./generateZkProofEnclave.mjs";
5
+ import { generateZkProofSelf as a } from "./generateZkProofSelf.mjs";
7
6
  //#region libs/shared/common/src/functions/snarkjs/generateZkProof.ts
8
- var s = async (s, c, l, u) => {
9
- let d = t("generateZkProof");
10
- if (d.log("start", {
11
- remotely: !!u,
12
- verifierNames: c
13
- }), u) try {
7
+ var o = async (o, s, c, l) => {
8
+ if (l) try {
14
9
  let t = e();
15
- if (t) {
16
- let e = await t(l, c.map((e) => r(e, s)), c.map((e) => i(e, s)));
17
- return d.log("customProofGenerator", { verifierNames: c }), e.map(({ zkCallData: e, publicSignals: t }) => ({
18
- zkCallData: e,
19
- publicSignals: t
20
- }));
21
- }
22
- let n = await a(s, c, l);
23
- return d.log("enclave", { verifierNames: c }), n;
10
+ return t ? (await t(c, s.map((e) => n(e, o)), s.map((e) => r(e, o)))).map(({ zkCallData: e, publicSignals: t }) => ({
11
+ zkCallData: e,
12
+ publicSignals: t
13
+ })) : await i(o, s, c);
24
14
  } catch (e) {
25
- n.error("enclave proof error", e), d.log("enclave-failed-fallback-self");
15
+ t.error("enclave proof error", e);
26
16
  }
27
- let f = await Promise.all(c.map((e, t) => o(s, e, l[t])));
28
- return d.log("self", { verifierNames: c }), f;
17
+ return Promise.all(s.map((e, t) => a(o, e, c[t])));
29
18
  };
30
19
  //#endregion
31
- export { s as generateZkProof };
20
+ export { o as generateZkProof };
@@ -1 +1 @@
1
- const e=require(`./constant.cjs`),t=require(`../../data-structures/http/HttpClient.cjs`);require(`../../data-structures/http/index.cjs`);const n=require(`../utils/encryptInputForEnclave.cjs`),r=require(`../utils/hinkalTiming.utils.cjs`),i=require(`./getZKFiles.cjs`);var a=e=>{if(e.startsWith(`http`)){let t=e.split(`/`).at(-1);if(!t)throw Error(`invalid verifierName`);return t}return e},o=async(o,s,c)=>{let l=r.createHinkalTiming(`generateZkProofEnclave`),u=s.map(e=>a(i.getWASMFile(e,o))),d=s.map(e=>a(i.getZKeyFile(e,o))),{keyCiphertext:f,inputCiphertext:p}=await n.makeEnclaveHandshakeAndEncryptInput(c);l.log(`handshake+encrypt`,{verifierNames:s});let m={circuit_wasms:u,circuit_zkeys:d,inputs:p,key:f},h=await t.httpClient.post(`${e.ENCLAVE_URL}/generate-proofs`,m);return l.log(`enclave-http`,{verifierNames:s}),h.map(({zk_calldata:e,public_signals:t})=>({zkCallData:e,publicSignals:t}))};exports.generateZkProofEnclave=o;
1
+ const e=require(`./constant.cjs`),t=require(`../../data-structures/http/HttpClient.cjs`);require(`../../data-structures/http/index.cjs`);const n=require(`../utils/encryptInputForEnclave.cjs`),r=require(`./getZKFiles.cjs`);var i=e=>{if(e.startsWith(`http`)){let t=e.split(`/`).at(-1);if(!t)throw Error(`invalid verifierName`);return t}return e},a=async(a,o,s)=>{let c=o.map(e=>i(r.getWASMFile(e,a))),l=o.map(e=>i(r.getZKeyFile(e,a))),{keyCiphertext:u,inputCiphertext:d}=await n.makeEnclaveHandshakeAndEncryptInput(s),f={circuit_wasms:c,circuit_zkeys:l,inputs:d,key:u};return(await t.httpClient.post(`${e.ENCLAVE_URL}/generate-proofs`,f)).map(({zk_calldata:e,public_signals:t})=>({zkCallData:e,publicSignals:t}))};exports.generateZkProofEnclave=a;
@@ -2,29 +2,26 @@ import { ENCLAVE_URL as e } from "./constant.mjs";
2
2
  import { httpClient as t } from "../../data-structures/http/HttpClient.mjs";
3
3
  import "../../data-structures/http/index.mjs";
4
4
  import { makeEnclaveHandshakeAndEncryptInput as n } from "../utils/encryptInputForEnclave.mjs";
5
- import { createHinkalTiming as r } from "../utils/hinkalTiming.utils.mjs";
6
- import { getWASMFile as i, getZKeyFile as a } from "./getZKFiles.mjs";
5
+ import { getWASMFile as r, getZKeyFile as i } from "./getZKFiles.mjs";
7
6
  //#region libs/shared/common/src/functions/snarkjs/generateZkProofEnclave.ts
8
- var o = (e) => {
7
+ var a = (e) => {
9
8
  if (e.startsWith("http")) {
10
9
  let t = e.split("/").at(-1);
11
10
  if (!t) throw Error("invalid verifierName");
12
11
  return t;
13
12
  }
14
13
  return e;
15
- }, s = async (s, c, l) => {
16
- let u = r("generateZkProofEnclave"), d = c.map((e) => o(i(e, s))), f = c.map((e) => o(a(e, s))), { keyCiphertext: p, inputCiphertext: m } = await n(l);
17
- u.log("handshake+encrypt", { verifierNames: c });
18
- let h = {
19
- circuit_wasms: d,
20
- circuit_zkeys: f,
21
- inputs: m,
22
- key: p
23
- }, g = await t.post(`${e}/generate-proofs`, h);
24
- return u.log("enclave-http", { verifierNames: c }), g.map(({ zk_calldata: e, public_signals: t }) => ({
14
+ }, o = async (o, s, c) => {
15
+ let l = s.map((e) => a(r(e, o))), u = s.map((e) => a(i(e, o))), { keyCiphertext: d, inputCiphertext: f } = await n(c), p = {
16
+ circuit_wasms: l,
17
+ circuit_zkeys: u,
18
+ inputs: f,
19
+ key: d
20
+ };
21
+ return (await t.post(`${e}/generate-proofs`, p)).map(({ zk_calldata: e, public_signals: t }) => ({
25
22
  zkCallData: e,
26
23
  publicSignals: t
27
24
  }));
28
25
  };
29
26
  //#endregion
30
- export { s as generateZkProofEnclave };
27
+ export { o as generateZkProofEnclave };
@@ -1 +1 @@
1
- const e=require(`../utils/hinkalTiming.utils.cjs`),t=require(`../../webworker/worker.registry.cjs`),n=require(`../../webworker/performTaskWithWorker.cjs`),r=require(`./getZKFiles.cjs`),i=require(`../../webworker/snarkjsWorker/snarkjsWorker.types.cjs`);var a=async(a,o,s)=>{let c=e.createHinkalTiming(`generateZkProofSelf:${o}`),l=r.getWASMFile(o,a),u=r.getZKeyFile(o,a);c.log(`start`,{chainId:a,wasmFilePath:l});let{publicSignals:d,zkCallData:f}=await n.performTaskWithWorker({type:t.WorkerVariant.SnarkJS,payload:{type:i.SnarkJSWorkerActionType.FULL_PROVE,data:{input:s,chainId:a,wasmFilePath:l,zKeyFilePath:u}}});return c.log(`worker-done`),{zkCallData:f,publicSignals:d}};exports.generateZkProofSelf=a;
1
+ const e=require(`../../webworker/worker.registry.cjs`),t=require(`../../webworker/performTaskWithWorker.cjs`),n=require(`./getZKFiles.cjs`),r=require(`../../webworker/snarkjsWorker/snarkjsWorker.types.cjs`);var i=async(i,a,o)=>{let s=n.getWASMFile(a,i),c=n.getZKeyFile(a,i),{publicSignals:l,zkCallData:u}=await t.performTaskWithWorker({type:e.WorkerVariant.SnarkJS,payload:{type:r.SnarkJSWorkerActionType.FULL_PROVE,data:{input:o,chainId:i,wasmFilePath:s,zKeyFilePath:c}}});return{zkCallData:u,publicSignals:l}};exports.generateZkProofSelf=i;
@@ -1,31 +1,25 @@
1
- import { createHinkalTiming as e } from "../utils/hinkalTiming.utils.mjs";
2
- import { WorkerVariant as t } from "../../webworker/worker.registry.mjs";
3
- import { performTaskWithWorker as n } from "../../webworker/performTaskWithWorker.mjs";
4
- import { getWASMFile as r, getZKeyFile as i } from "./getZKFiles.mjs";
5
- import { SnarkJSWorkerActionType as a } from "../../webworker/snarkjsWorker/snarkjsWorker.types.mjs";
1
+ import { WorkerVariant as e } from "../../webworker/worker.registry.mjs";
2
+ import { performTaskWithWorker as t } from "../../webworker/performTaskWithWorker.mjs";
3
+ import { getWASMFile as n, getZKeyFile as r } from "./getZKFiles.mjs";
4
+ import { SnarkJSWorkerActionType as i } from "../../webworker/snarkjsWorker/snarkjsWorker.types.mjs";
6
5
  //#region libs/shared/common/src/functions/snarkjs/generateZkProofSelf.ts
7
- var o = async (o, s, c) => {
8
- let l = e(`generateZkProofSelf:${s}`), u = r(s, o), d = i(s, o);
9
- l.log("start", {
10
- chainId: o,
11
- wasmFilePath: u
12
- });
13
- let { publicSignals: f, zkCallData: p } = await n({
14
- type: t.SnarkJS,
6
+ var a = async (a, o, s) => {
7
+ let c = n(o, a), l = r(o, a), { publicSignals: u, zkCallData: d } = await t({
8
+ type: e.SnarkJS,
15
9
  payload: {
16
- type: a.FULL_PROVE,
10
+ type: i.FULL_PROVE,
17
11
  data: {
18
- input: c,
19
- chainId: o,
20
- wasmFilePath: u,
21
- zKeyFilePath: d
12
+ input: s,
13
+ chainId: a,
14
+ wasmFilePath: c,
15
+ zKeyFilePath: l
22
16
  }
23
17
  }
24
18
  });
25
- return l.log("worker-done"), {
26
- zkCallData: p,
27
- publicSignals: f
19
+ return {
20
+ zkCallData: d,
21
+ publicSignals: u
28
22
  };
29
23
  };
30
24
  //#endregion
31
- export { o as generateZkProofSelf };
25
+ export { a as generateZkProofSelf };
@@ -1 +1 @@
1
- var e=`[HinkalTiming]`,t=(t,n,r,i)=>{let a=Date.now(),o=a-r.last,s=a-r.start;r.last=a;let c=i?` ${JSON.stringify(i)}`:``;console.log(`${e} [${t}] ${n} +${o}ms (total ${s}ms)${c}`)},n=e=>{let n={start:Date.now(),last:Date.now()};return{marks:n,log:(r,i)=>t(e,r,n,i)}};exports.createHinkalTiming=n;
1
+ var e=`[HinkalRnDelta]`,t=e=>`at=${e}`,n=(n,r,i,a)=>{let o=Date.now(),s=o-i.last,c=o-i.start;i.last=o;let l=a?` ${JSON.stringify(a)}`:``;console.log(`${e} ${t(o)} [${n}] ${r} +${s}ms (total ${c}ms)${l}`)},r=e=>{let t={start:Date.now(),last:Date.now()};return{marks:t,log:(r,i)=>n(e,r,t,i)}},i=(n,r,i)=>{let a=Date.now(),o=i?` ${JSON.stringify(i)}`:``;console.log(`${e} ${t(a)} [${n}] ${r}${o}`)};exports.createRnDeltaTiming=r,exports.logRnDeltaEvent=i;
@@ -2,8 +2,10 @@ export type HinkalTimingMarks = {
2
2
  start: number;
3
3
  last: number;
4
4
  };
5
- export declare const logHinkalTiming: (scope: string, phase: string, marks: HinkalTimingMarks, extra?: Record<string, unknown>) => void;
6
- export declare const createHinkalTiming: (scope: string) => {
5
+ export declare const logRnDelta: (scope: string, phase: string, marks: HinkalTimingMarks, extra?: Record<string, unknown>) => void;
6
+ export declare const createRnDeltaTiming: (scope: string) => {
7
7
  marks: HinkalTimingMarks;
8
8
  log: (phase: string, extra?: Record<string, unknown>) => void;
9
9
  };
10
+ /** One-off event (e.g. WebView sub-phase with its own clock). */
11
+ export declare const logRnDeltaEvent: (scope: string, phase: string, extra?: Record<string, unknown>) => void;
@@ -1,18 +1,21 @@
1
1
  //#region libs/shared/common/src/functions/utils/hinkalTiming.utils.ts
2
- var e = "[HinkalTiming]", t = (t, n, r, i) => {
3
- let a = Date.now(), o = a - r.last, s = a - r.start;
4
- r.last = a;
5
- let c = i ? ` ${JSON.stringify(i)}` : "";
6
- console.log(`${e} [${t}] ${n} +${o}ms (total ${s}ms)${c}`);
7
- }, n = (e) => {
8
- let n = {
2
+ var e = "[HinkalRnDelta]", t = (e) => `at=${e}`, n = (n, r, i, a) => {
3
+ let o = Date.now(), s = o - i.last, c = o - i.start;
4
+ i.last = o;
5
+ let l = a ? ` ${JSON.stringify(a)}` : "";
6
+ console.log(`${e} ${t(o)} [${n}] ${r} +${s}ms (total ${c}ms)${l}`);
7
+ }, r = (e) => {
8
+ let t = {
9
9
  start: Date.now(),
10
10
  last: Date.now()
11
11
  };
12
12
  return {
13
- marks: n,
14
- log: (r, i) => t(e, r, n, i)
13
+ marks: t,
14
+ log: (r, i) => n(e, r, t, i)
15
15
  };
16
+ }, i = (n, r, i) => {
17
+ let a = Date.now(), o = i ? ` ${JSON.stringify(i)}` : "";
18
+ console.log(`${e} ${t(a)} [${n}] ${r}${o}`);
16
19
  };
17
20
  //#endregion
18
- export { n as createHinkalTiming };
21
+ export { r as createRnDeltaTiming, i as logRnDeltaEvent };
@@ -1 +1 @@
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(`../../utils/hinkalTiming.utils.cjs`),c=require(`./getInputUtxosEnclave.cjs`),l=require(`../../utils/addresses.cjs`),u=require(`../../../API/scheduled-transactions-calls.cjs`),d=require(`../../utils/tron.utils.cjs`);var f=new(require(`async-mutex`)).Mutex,p=async(e,t)=>{if(e.allowParallelBalanceLocalDecryption)return t();let n=s.createHinkalTiming(`utxoDecrypt.mutex`);return f.isLocked()&&n.log(`waiting`),f.runExclusive(async()=>{n.log(`acquired`);try{return await t()}finally{n.log(`released`)}})},m=async(e,t,n,a,o,c,l,u,d)=>p(e,async()=>{let f=s.createHinkalTiming(`utxoDecrypt.local`);d+=1;let p=c.slice(d);f.log(`batchProcess-start`,{outputsSlice:p.length,lastOutputIndex:d});let{lastOutput:m,additionalEncryptedOutputs:h}=await e.utxoUtils.batchProcess(p,u,t,n);f.log(`batchProcess-done`,{additionalEncryptedOutputs:h.length});let g=[...l,...h];await r.checkAddressNotUpdated(e,a),i.setHinkalCache({lastOutput:m,encryptedOutputs:g},e,n,o),f.log(`cache-write`);let _=await e.utxoUtils.buildBatchProcess(g,t,n);return f.log(`buildBatchProcess-done`,{utxoCount:_.length}),_}),h=async(e,t,n,r)=>{let{utxos:a,encryptedOutputs:o,lastOutput:s}=await c.getInputUtxosEnclave(e,n,t);return i.setHinkalCache({encryptedOutputs:o,lastOutput:s},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=(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)},b=async({hinkal:e,chainId:t,passedShieldedPublicKey:n=void 0,ethAddress:a=void 0,resetCacheBefore:o=!1,allowRemoteDecryption:c=!1,useBlockedUtxos:l=!1})=>{let u=a??await e.getEthereumAddress(),d=n??e.userKeys.getShieldedPublicKey(),{userKeys:f}=e,p=e.encryptedOutputsByChain[t],h=e.nullifiersByChain[t],_=Array.from(p);o&&i.resetCache(e,t,d);let{encryptedOutputs:y,lastOutput:b}=i.getHinkalCache(e,t,d);await r.checkAddressNotUpdated(e,u);let x=b!==``,S=_.findIndex(e=>e.value===b),C=S>-1,w=!x&&S===-1,T=e.areMerkleTreeUpdatesDisabled(),E=!T&&(C||!c&&w),D=!T&&c&&w,O=!E&&!D,k=s.createHinkalTiming(`getInputUtxoAndBalance`);k.log(`branch`,{decryptLocally:E,decryptRemotely:D,useCache:O,hinkalOutputs:_.length,cachedEncryptedOutputs:y.length,lastOutputIndex:S});let A=[];E?(A=await m(e,f,t,u,d,_,y,b,S),k.log(`decryptLocally-done`,{utxoCount:A.length})):D?(A=await g(e,f,t,u,d,_,y,b,S),k.log(`decryptRemotely-done`,{utxoCount:A.length})):O&&(A=await e.utxoUtils.buildBatchProcess(y,f,t),k.log(`useCache-buildBatchProcess-done`,{utxoCount:A.length})),await r.checkAddressNotUpdated(e,u);let j=await v(e,A,h);return k.log(`filterSpentUtxos-done`,{inputUtxos:j.length}),{inputUtxos:l?j.filter(e=>e.isBlocked):j.filter(e=>!e.isBlocked)}},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),c=l.hashEthereumAddress(e.isTronLike(n)?d.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 u.getScheduledTransactionsNullifierIndexes({hashedEthereumAddress:c,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;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`),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=(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)},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;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;
@@ -5,43 +5,43 @@ 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";
7
7
  import { formatMintAddress as l } from "../../utils/solanaMint.utils.mjs";
8
- import { createHinkalTiming as u } from "../../utils/hinkalTiming.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";
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 { createRnDeltaTiming as m } from "../../utils/hinkalTiming.utils.mjs";
13
13
  import { Mutex as h } from "async-mutex";
14
14
  //#region libs/shared/common/src/functions/web3/events/getInputUtxoAndBalance.ts
15
15
  var g = new h(), _ = async (e, t) => {
16
16
  if (e.allowParallelBalanceLocalDecryption) return t();
17
- let n = u("utxoDecrypt.mutex");
18
- return g.isLocked() && n.log("waiting"), g.runExclusive(async () => {
19
- n.log("acquired");
17
+ let n = m("utxoPrep.mutex");
18
+ return g.isLocked() && n.log("waiting-for-lock"), g.runExclusive(async () => {
19
+ n.log("lock-acquired");
20
20
  try {
21
21
  return await t();
22
22
  } finally {
23
- n.log("released");
23
+ n.log("lock-released");
24
24
  }
25
25
  });
26
- }, v = async (e, t, n, r, a, o, c, l, d) => _(e, async () => {
27
- let f = u("utxoDecrypt.local");
28
- d += 1;
29
- let p = o.slice(d);
30
- f.log("batchProcess-start", {
31
- outputsSlice: p.length,
32
- lastOutputIndex: d
26
+ }, v = async (e, t, n, r, a, o, c, l, u) => _(e, async () => {
27
+ let d = m("utxoPrep.decrypt");
28
+ u += 1;
29
+ let f = o.slice(u);
30
+ d.log("batchProcess-start", {
31
+ outputsSlice: f.length,
32
+ cached: c.length
33
33
  });
34
- let { lastOutput: m, additionalEncryptedOutputs: h } = await e.utxoUtils.batchProcess(p, l, t, n);
35
- f.log("batchProcess-done", { additionalEncryptedOutputs: h.length });
36
- let g = [...c, ...h];
37
- await i(e, r), s({
38
- lastOutput: m,
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
39
  encryptedOutputs: g
40
- }, e, n, a), f.log("cache-write");
41
- let _ = await e.utxoUtils.buildBatchProcess(g, t, n);
42
- return f.log("buildBatchProcess-done", { utxoCount: _.length }), _;
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
43
  }), y = async (e, t, n, r) => {
44
- let { utxos: i, encryptedOutputs: a, lastOutput: o } = await d(e, n, t);
44
+ let { utxos: i, encryptedOutputs: a, lastOutput: o } = await u(e, n, t);
45
45
  return s({
46
46
  encryptedOutputs: a,
47
47
  lastOutput: o
@@ -65,25 +65,41 @@ var g = new h(), _ = async (e, t) => {
65
65
  isNewStyle: !0
66
66
  })), n) for (; e.length > 6;) e.splice(e.length - 1);
67
67
  }, w = async ({ hinkal: e, chainId: t, passedShieldedPublicKey: n = void 0, ethAddress: r = void 0, resetCacheBefore: s = !1, allowRemoteDecryption: c = !1, useBlockedUtxos: l = !1 }) => {
68
- let d = r ?? await e.getEthereumAddress(), f = n ?? e.userKeys.getShieldedPublicKey(), { userKeys: p } = e, m = e.encryptedOutputsByChain[t], h = e.nullifiersByChain[t], g = Array.from(m);
68
+ let u = m("utxoPrep");
69
+ u.log("start");
70
+ let d = r;
71
+ d ? u.log("wallet.getEthereumAddress-skipped", { ethAddressPassed: !0 }) : (d = await e.getEthereumAddress(), u.log("wallet.getEthereumAddress"));
72
+ let f = n ?? e.userKeys.getShieldedPublicKey(), { userKeys: p } = e, h = e.encryptedOutputsByChain[t], g = e.nullifiersByChain[t], _ = Array.from(h);
69
73
  s && o(e, t, f);
70
- let { encryptedOutputs: _, lastOutput: y } = a(e, t, f);
71
- await i(e, d);
72
- let x = y !== "", C = g.findIndex((e) => e.value === y), w = C > -1, T = !x && C === -1, E = e.areMerkleTreeUpdatesDisabled(), D = !E && (w || !c && T), O = !E && c && T, k = !D && !O, A = u("getInputUtxoAndBalance");
73
- A.log("branch", {
74
- decryptLocally: D,
75
- decryptRemotely: O,
76
- useCache: k,
77
- hinkalOutputs: g.length,
78
- cachedEncryptedOutputs: _.length,
79
- lastOutputIndex: C
74
+ let { encryptedOutputs: y, lastOutput: x } = a(e, t, f);
75
+ u.log("cache.read", { cachedEncryptedOutputs: y.length });
76
+ let C = m("wallet.checkAddress");
77
+ await i(e, d), C.log("before-decrypt");
78
+ let w = x !== "", T = _.findIndex((e) => e.value === x);
79
+ u.log("findLastOutputIndex", {
80
+ hinkalOutputs: _.length,
81
+ lastOutputIndex: T
80
82
  });
81
- let j = [];
82
- D ? (j = await v(e, p, t, d, f, g, _, y, C), A.log("decryptLocally-done", { utxoCount: j.length })) : O ? (j = await b(e, p, t, d, f, g, _, y, C), A.log("decryptRemotely-done", { utxoCount: j.length })) : k && (j = await e.utxoUtils.buildBatchProcess(_, p, t), A.log("useCache-buildBatchProcess-done", { utxoCount: j.length })), await i(e, d);
83
- let M = await S(e, j, h);
84
- return A.log("filterSpentUtxos-done", { inputUtxos: M.length }), { inputUtxos: l ? M.filter((e) => e.isBlocked) : M.filter((e) => !e.isBlocked) };
83
+ let E = T > -1, D = !w && T === -1, O = e.areMerkleTreeUpdatesDisabled(), k = !O && (E || !c && D), A = !O && c && D, j = !k && !A;
84
+ u.log("branch", {
85
+ decryptLocally: k,
86
+ decryptRemotely: A,
87
+ useCache: j,
88
+ outputsSlice: T > -1 ? _.length - (T + 1) : 0
89
+ });
90
+ let M = [];
91
+ 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 }));
92
+ let N = m("wallet.checkAddress");
93
+ await i(e, d), N.log("after-decrypt");
94
+ let P = await S(e, M, g);
95
+ u.log("filterSpentUtxos", {
96
+ allUtxos: M.length,
97
+ inputUtxos: P.length
98
+ });
99
+ let F = l ? P.filter((e) => e.isBlocked) : P.filter((e) => !e.isBlocked);
100
+ return u.log("done", { inputUtxos: F.length }), { inputUtxos: F };
85
101
  }, T = async ({ hinkal: e, chainId: n, passedShieldedPublicKey: r = void 0, ethAddress: i = void 0, resetCacheBefore: a = !1, allowRemoteDecryption: o = !1 }) => {
86
- let s = i ?? await e.getEthereumAddressByChain(n), c = f(t(n) ? m(s) : s), { inputUtxos: l } = await w({
102
+ let s = i ?? await e.getEthereumAddressByChain(n), c = d(t(n) ? p(s) : s), { inputUtxos: l } = await w({
87
103
  hinkal: e,
88
104
  chainId: n,
89
105
  passedShieldedPublicKey: r,
@@ -93,7 +109,7 @@ var g = new h(), _ = async (e, t) => {
93
109
  useBlockedUtxos: !0
94
110
  });
95
111
  if (!l.length) return { inputUtxos: [] };
96
- let { indexes: u } = await p({
112
+ let { indexes: u } = await f({
97
113
  hashedEthereumAddress: c,
98
114
  nullifiers: l.map((e) => e.getNullifier())
99
115
  });
@@ -1 +1 @@
1
- require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../../data-structures/crypto-keys/keys.cjs`),n=require(`../../../data-structures/utxo/Utxo.cjs`),r=require(`../../utils/encryptInputForEnclave.cjs`),i=require(`../../utils/solanaMint.utils.cjs`),a=require(`../../utils/customEnclaveFunctionsRegister.cjs`),o=require(`../../utils/hinkalTiming.utils.cjs`);let s=require(`ethers`),c=require(`@solana/web3.js`);var l=e=>{if(!e)return;let t=s.ethers.getBytes(e);if(t.length!==32)return;let n=new c.PublicKey(t),r=n.toBase58(),{compressedAddress:a}=i.formatMintAddress(n);return{mintBase58:r,compressedAddress:a}},u=async(e,t,n)=>{let{keyCiphertext:i,inputCiphertext:a}=await r.makeEnclaveHandshakeAndEncryptUint8Array(n);return e.getAPI().decryptUtxoEnclaveCall(t,i,a)},d=async(r,i,c)=>{let d=o.createHinkalTiming(`getInputUtxosEnclave`),f=c.getShieldedPrivateKey(),{privateKey:p,publicKey:m}=t.UserKeys.getEncryptionKeyPair(f),h=c.getSpendingKeyPair().pubSpendingBJJPoint,g=s.ethers.solidityPacked([`uint256`,`uint256`,`uint256`],[m,p,f]),_=s.ethers.getBytes(g),v=a.getCustomUtxoDecryptor(),{utxos:y,lastOutput:b,encryptedOutputs:x}=await(v?v(i,_):u(r,i,_));return d.log(`decrypt-call-done`,{utxoCount:y.length}),{utxos:y.map(t=>{let r=t;if(e.isSolanaLike(i)){let e=l(t.mintAddress);if(!e)throw Error(`Invalid mint address`);r={...r,erc20TokenAddress:e.compressedAddress,mintAddress:e.mintBase58}}return new n.Utxo({...r,amount:BigInt(r.amount),randomization:r.randomization?BigInt(r.randomization):void 0,nullifyingKey:f,spendingPublicKey:h,isNewStyle:r.isNewStyle,H0:r.H0?[BigInt(r.H0[0]),BigInt(r.H0[1])]:void 0})}),encryptedOutputs:x,lastOutput:b}};exports.getInputUtxosEnclave=d;
1
+ require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../../data-structures/crypto-keys/keys.cjs`),n=require(`../../../data-structures/utxo/Utxo.cjs`),r=require(`../../utils/encryptInputForEnclave.cjs`),i=require(`../../utils/solanaMint.utils.cjs`),a=require(`../../utils/customEnclaveFunctionsRegister.cjs`);let o=require(`ethers`),s=require(`@solana/web3.js`);var c=e=>{if(!e)return;let t=o.ethers.getBytes(e);if(t.length!==32)return;let n=new s.PublicKey(t),r=n.toBase58(),{compressedAddress:a}=i.formatMintAddress(n);return{mintBase58:r,compressedAddress:a}},l=async(e,t,n)=>{let{keyCiphertext:i,inputCiphertext:a}=await r.makeEnclaveHandshakeAndEncryptUint8Array(n);return e.getAPI().decryptUtxoEnclaveCall(t,i,a)},u=async(r,i,s)=>{let u=s.getShieldedPrivateKey(),{privateKey:d,publicKey:f}=t.UserKeys.getEncryptionKeyPair(u),p=s.getSpendingKeyPair().pubSpendingBJJPoint,m=o.ethers.solidityPacked([`uint256`,`uint256`,`uint256`],[f,d,u]),h=o.ethers.getBytes(m),g=a.getCustomUtxoDecryptor(),{utxos:_,lastOutput:v,encryptedOutputs:y}=await(g?g(i,h):l(r,i,h));return{utxos:_.map(t=>{let r=t;if(e.isSolanaLike(i)){let e=c(t.mintAddress);if(!e)throw Error(`Invalid mint address`);r={...r,erc20TokenAddress:e.compressedAddress,mintAddress:e.mintBase58}}return new n.Utxo({...r,amount:BigInt(r.amount),randomization:r.randomization?BigInt(r.randomization):void 0,nullifyingKey:u,spendingPublicKey:p,isNewStyle:r.isNewStyle,H0:r.H0?[BigInt(r.H0[0]),BigInt(r.H0[1])]:void 0})}),encryptedOutputs:y,lastOutput:v}};exports.getInputUtxosEnclave=u;
@@ -4,37 +4,36 @@ import { Utxo as n } from "../../../data-structures/utxo/Utxo.mjs";
4
4
  import { makeEnclaveHandshakeAndEncryptUint8Array as r } from "../../utils/encryptInputForEnclave.mjs";
5
5
  import { formatMintAddress as i } from "../../utils/solanaMint.utils.mjs";
6
6
  import { getCustomUtxoDecryptor as a } from "../../utils/customEnclaveFunctionsRegister.mjs";
7
- import { createHinkalTiming as o } from "../../utils/hinkalTiming.utils.mjs";
8
- import { ethers as s } from "ethers";
9
- import { PublicKey as c } from "@solana/web3.js";
7
+ import { ethers as o } from "ethers";
8
+ import { PublicKey as s } from "@solana/web3.js";
10
9
  //#region libs/shared/common/src/functions/web3/events/getInputUtxosEnclave.ts
11
- var l = (e) => {
10
+ var c = (e) => {
12
11
  if (!e) return;
13
- let t = s.getBytes(e);
12
+ let t = o.getBytes(e);
14
13
  if (t.length !== 32) return;
15
- let n = new c(t), r = n.toBase58(), { compressedAddress: a } = i(n);
14
+ let n = new s(t), r = n.toBase58(), { compressedAddress: a } = i(n);
16
15
  return {
17
16
  mintBase58: r,
18
17
  compressedAddress: a
19
18
  };
20
- }, u = async (e, t, n) => {
19
+ }, l = async (e, t, n) => {
21
20
  let { keyCiphertext: i, inputCiphertext: a } = await r(n);
22
21
  return e.getAPI().decryptUtxoEnclaveCall(t, i, a);
23
- }, d = async (r, i, c) => {
24
- let d = o("getInputUtxosEnclave"), f = c.getShieldedPrivateKey(), { privateKey: p, publicKey: m } = t.getEncryptionKeyPair(f), h = c.getSpendingKeyPair().pubSpendingBJJPoint, g = s.solidityPacked([
22
+ }, u = async (r, i, s) => {
23
+ let u = s.getShieldedPrivateKey(), { privateKey: d, publicKey: f } = t.getEncryptionKeyPair(u), p = s.getSpendingKeyPair().pubSpendingBJJPoint, m = o.solidityPacked([
25
24
  "uint256",
26
25
  "uint256",
27
26
  "uint256"
28
27
  ], [
29
- m,
30
- p,
31
- f
32
- ]), _ = s.getBytes(g), v = a(), { utxos: y, lastOutput: b, encryptedOutputs: x } = await (v ? v(i, _) : u(r, i, _));
33
- return d.log("decrypt-call-done", { utxoCount: y.length }), {
34
- utxos: y.map((t) => {
28
+ f,
29
+ d,
30
+ u
31
+ ]), h = o.getBytes(m), g = a(), { utxos: _, lastOutput: v, encryptedOutputs: y } = await (g ? g(i, h) : l(r, i, h));
32
+ return {
33
+ utxos: _.map((t) => {
35
34
  let r = t;
36
35
  if (e(i)) {
37
- let e = l(t.mintAddress);
36
+ let e = c(t.mintAddress);
38
37
  if (!e) throw Error("Invalid mint address");
39
38
  r = {
40
39
  ...r,
@@ -46,15 +45,15 @@ var l = (e) => {
46
45
  ...r,
47
46
  amount: BigInt(r.amount),
48
47
  randomization: r.randomization ? BigInt(r.randomization) : void 0,
49
- nullifyingKey: f,
50
- spendingPublicKey: h,
48
+ nullifyingKey: u,
49
+ spendingPublicKey: p,
51
50
  isNewStyle: r.isNewStyle,
52
51
  H0: r.H0 ? [BigInt(r.H0[0]), BigInt(r.H0[1])] : void 0
53
52
  });
54
53
  }),
55
- encryptedOutputs: x,
56
- lastOutput: b
54
+ encryptedOutputs: y,
55
+ lastOutput: v
57
56
  };
58
57
  };
59
58
  //#endregion
60
- export { d as getInputUtxosEnclave };
59
+ export { u as getInputUtxosEnclave };
@@ -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(`../../../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(`../../utils/hinkalTiming.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 v=l.createHinkalTiming(`addPaddingToUtxos`),{userKeys:y}=e,b=y.getSpendingKeyPair().pubSpendingBJJPoint,x=[],S=[];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,o=r?c.formatMintAddress(d[e]).compressedAddress:d[e];x.push(Array.from({length:p},()=>new a.Utxo({amount:0n,erc20TokenAddress:o,mintAddress:i,nullifyingKey:y.getShieldedPrivateKey(),spendingPublicKey:b,isNewStyle:!0})))}return x}let C=await u.getInputUtxoAndBalancePerToken({hinkal:e,sliceIfMore6:!1,ensuredTokensWithId:d.map((e,t)=>({erc20TokenAddress:d[t],tokenId:h[t]})),allowRemoteDecryption:e.generateProofRemotely,useBlockedUtxos:_,chainId:n});v.log(`getInputUtxoAndBalancePerToken`);let w=0;for(let e=0;e<d.length;e+=1){let t=C.get(s.encodeTokenWithId(n,{erc20TokenAddress:d[e],tokenId:h[e]}))??[];if(!t)throw Error(`Missing utxos for token`);w=Math.max(t.length,w),S.push(t)}if(w===2)return S;for(let[e,s]of S.entries())if(s.length>p){let t=s.slice(0,p),a=t.reduce((e,t)=>e+t.amount,0n);if(f[e]<0n&&a<-f[e]){let t=await m.getErc20TokenFromAPI(n,d[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.`)}x.push(t)}else if(s.length<=p){let r=[...s],i=p-s.length;for(;i>0;){--i;let o=t.isSolanaLike(n),s=o?d[e]:void 0,l=o?c.formatMintAddress(d[e]).compressedAddress:d[e];r.push(new a.Utxo({amount:0n,erc20TokenAddress:l,mintAddress:s,nullifyingKey:y.getShieldedPrivateKey(),spendingPublicKey:b,isNewStyle:!0}))}x.push(r)}return v.log(`padding-done`,{tokenCount:x.length}),x};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;