@hinkal/common 0.2.39 → 0.2.40
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.
- package/functions/web3/events/getInputUtxoAndBalance.cjs +1 -1
- package/functions/web3/events/getInputUtxoAndBalance.mjs +27 -27
- package/package.json +1 -1
- package/webworker/{logError-CU_5hb0O.js → logError-D7s4G7mb.js} +15 -15
- package/webworker/package.json +1 -1
- package/webworker/snarkjsWorkerNode.cjs +2 -2
- package/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.mjs +1 -1
- package/webworker/utxoWorkerNode.cjs +1 -1
- package/webworker/viteWorkerURL.constant.cjs +3 -3
- package/webworker/viteWorkerURL.constant.mjs +3 -3
- package/webworker/workerProxy-C8hF6v0v.js +128 -0
- package/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.cjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.mjs +1 -1
- package/webworker/zkProofWorkerNode.cjs +1 -1
- package/webworker/workerProxy-JYVsEgnC.js +0 -128
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../utils/caseInsensitive.utils.cjs`),n=require(`../../utils/addresses.cjs`),r=require(`../../../API/scheduled-transactions-calls.cjs`),i=require(`../../../data-structures/utxo/Utxo.cjs`),a=require(`../../utils/upToDateState.cjs`),o=require(`../../utils/cacheFunctions.cjs`),s=require(`../../utils/encodeTokenWithId.cjs`),c=require(`../../utils/solanaMint.utils.cjs`),l=require(`./getInputUtxosEnclave.cjs`),u=require(`../../utils/tron.utils.cjs`);var d=new(require(`async-mutex`)).Mutex,f=async(e,t,n,r,i,s,c,l,u)=>d.runExclusive(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 a.checkAddressNotUpdated(e,r),o.setHinkalCache({lastOutput:f,encryptedOutputs:m},e,n,i),await e.utxoUtils.buildBatchProcess(m,t,n)}),
|
|
1
|
+
require(`../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../utils/caseInsensitive.utils.cjs`),n=require(`../../utils/addresses.cjs`),r=require(`../../../API/scheduled-transactions-calls.cjs`),i=require(`../../../data-structures/utxo/Utxo.cjs`),a=require(`../../utils/upToDateState.cjs`),o=require(`../../utils/cacheFunctions.cjs`),s=require(`../../utils/encodeTokenWithId.cjs`),c=require(`../../utils/solanaMint.utils.cjs`),l=require(`./getInputUtxosEnclave.cjs`),u=require(`../../utils/tron.utils.cjs`);var d=new(require(`async-mutex`)).Mutex,f=e=>e?.[0]===0n&&e?.[1]===1n,p=async(e,t,n,r,i,s,c,l,u)=>d.runExclusive(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 a.checkAddressNotUpdated(e,r),o.setHinkalCache({lastOutput:f,encryptedOutputs:m},e,n,i),await e.utxoUtils.buildBatchProcess(m,t,n)}),m=async(e,t,n,r)=>{let{utxos:i,encryptedOutputs:a,lastOutput:s}=await l.getInputUtxosEnclave(e,n,t);return o.setHinkalCache({encryptedOutputs:a,lastOutput:s},e,n,r),i},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,n,r,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 i.Utxo({amount:0n,erc20TokenAddress:o,mintAddress:c,nullifyingKey:r,spendingPublicKey:a,isNewStyle:!0})),n)for(;e.length>6;)e.splice(e.length-1)},y=async({hinkal:e,chainId:t,passedShieldedPublicKey:n=void 0,ethAddress:r=void 0,resetCacheBefore:i=!1,allowRemoteDecryption:s=!1,useBlockedUtxos:c=!1})=>{let l=r??await e.getEthereumAddress(),u=n??e.userKeys.getShieldedPublicKey(),{userKeys:d}=e,m=e.encryptedOutputsByChain[t],g=e.nullifiersByChain[t],v=Array.from(m);i&&o.resetCache(e,t,u);let{encryptedOutputs:y,lastOutput:b}=o.getHinkalCache(e,t,u);await a.checkAddressNotUpdated(e,l);let x=b!==``,S=v.findIndex(e=>e.value===b),C=S>-1,w=!x&&S===-1,T=e.areMerkleTreeUpdatesDisabled(),E=!T&&(C||!s&&w),D=!T&&s&&w,O=!E&&!D,k=[];E?k=await p(e,d,t,l,u,v,y,b,S):D?k=await h(e,d,t,l,u,v,y,b,S):O&&(k=await e.utxoUtils.buildBatchProcess(y,d,t)),await a.checkAddressNotUpdated(e,l);let A=await _(e,k,g);return{inputUtxos:(c?A.filter(e=>e.isBlocked):A.filter(e=>!e.isBlocked)).filter(e=>!f(e.H0))}},b=async({hinkal:t,chainId:i,passedShieldedPublicKey:a=void 0,ethAddress:o=void 0,resetCacheBefore:s=!1,allowRemoteDecryption:c=!1})=>{let l=o??await t.getEthereumAddressByChain(i),d=n.hashEthereumAddress(e.isTronLike(i)?u.addressToHexFormat(l):l),{inputUtxos:f}=await y({hinkal:t,chainId:i,passedShieldedPublicKey:a,ethAddress:l,resetCacheBefore:s,allowRemoteDecryption:c,useBlockedUtxos:!0});if(!f.length)return{inputUtxos:[]};let{indexes:p}=await r.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:a=!0,chainId:o,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:o,ethAddress:d,passedShieldedPrivateKey:l,resetCacheBefore:f,allowRemoteDecryption:m}):await y({hinkal:n,tokenWithId:r,minInput:i,sliceIfMore6:a,chainId:o,passedShieldedPrivateKey:l,passedShieldedPublicKey:u,ethAddress:d,resetCacheBefore:f,allowRemoteDecryption:m}),C=g(r),w=new Map;S.forEach(e=>{let n=e.getTokenAddress(o);if(C&&!C.some(e=>t.caseInsensitiveEqual(e.erc20TokenAddress,n)))return;let r=s.encodeTokenWithId(o,{erc20TokenAddress:n,tokenId:0}),i=w.get(r)??[];w.set(r,[...i,e])}),p?.forEach(e=>{let t=s.encodeTokenWithId(o,{erc20TokenAddress:e.erc20TokenAddress,tokenId:0});w.set(t,w.get(t)??[])});for(let[t,n]of w){let r=t.split(`-`)[0],s=Number(t.split(`-`)[1]),l=e.isSolanaLike(o),u=l?r:void 0;v(n,i,a,_,x,l?c.formatMintAddress(r).compressedAddress.toLowerCase():r.toLowerCase(),s,u)}return w};exports.attemptGetInputUtxosRemotely=h,exports.getInputUtxoAndBalance=y,exports.getInputUtxoAndBalanceOfStuckUtxos=b,exports.getInputUtxoAndBalancePerToken=x,exports.getInputUtxosRemotely=m;
|
|
@@ -11,29 +11,29 @@ import { getInputUtxosEnclave as f } from "./getInputUtxosEnclave.mjs";
|
|
|
11
11
|
import { addressToHexFormat as p } from "../../utils/tron.utils.mjs";
|
|
12
12
|
import { Mutex as m } from "async-mutex";
|
|
13
13
|
//#region libs/shared/common/src/functions/web3/events/getInputUtxoAndBalance.ts
|
|
14
|
-
var h = new m(), g = async (e, t, n, r, i, a, s, c, u) => h.runExclusive(async () => {
|
|
14
|
+
var h = new m(), g = (e) => e?.[0] === 0n && e?.[1] === 1n, _ = async (e, t, n, r, i, a, s, c, u) => h.runExclusive(async () => {
|
|
15
15
|
u += 1;
|
|
16
16
|
let d = a.slice(u), { lastOutput: f, additionalEncryptedOutputs: p } = await e.utxoUtils.batchProcess(d, c, t, n), m = [...s, ...p];
|
|
17
17
|
return await o(e, r), l({
|
|
18
18
|
lastOutput: f,
|
|
19
19
|
encryptedOutputs: m
|
|
20
20
|
}, e, n, i), await e.utxoUtils.buildBatchProcess(m, t, n);
|
|
21
|
-
}),
|
|
21
|
+
}), v = async (e, t, n, r) => {
|
|
22
22
|
let { utxos: i, encryptedOutputs: a, lastOutput: o } = await f(e, n, t);
|
|
23
23
|
return l({
|
|
24
24
|
encryptedOutputs: a,
|
|
25
25
|
lastOutput: o
|
|
26
26
|
}, e, n, r), i;
|
|
27
|
-
},
|
|
27
|
+
}, y = async (e, t, n, r, i, a, o, s, c) => {
|
|
28
28
|
try {
|
|
29
|
-
return await
|
|
29
|
+
return await v(e, t, n, i);
|
|
30
30
|
} catch {
|
|
31
|
-
return
|
|
31
|
+
return _(e, t, n, r, i, a, o, s, c);
|
|
32
32
|
}
|
|
33
|
-
},
|
|
33
|
+
}, b = (e) => {
|
|
34
34
|
if (Array.isArray(e)) return e;
|
|
35
35
|
if (e !== void 0) return [e];
|
|
36
|
-
},
|
|
36
|
+
}, x = async (e, t, n) => await e.utxoUtils.batchFilterUtxosWithNullifier(t, n), S = (e, t, n, r, i, o, s, c) => {
|
|
37
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 a({
|
|
38
38
|
amount: 0n,
|
|
39
39
|
erc20TokenAddress: o,
|
|
@@ -42,17 +42,17 @@ var h = new m(), g = async (e, t, n, r, i, a, s, c, u) => h.runExclusive(async (
|
|
|
42
42
|
spendingPublicKey: i,
|
|
43
43
|
isNewStyle: !0
|
|
44
44
|
})), n) for (; e.length > 6;) e.splice(e.length - 1);
|
|
45
|
-
},
|
|
45
|
+
}, C = async ({ hinkal: e, chainId: t, passedShieldedPublicKey: n = void 0, ethAddress: r = void 0, resetCacheBefore: i = !1, allowRemoteDecryption: a = !1, useBlockedUtxos: l = !1 }) => {
|
|
46
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
47
|
i && c(e, t, d);
|
|
48
|
-
let { encryptedOutputs:
|
|
48
|
+
let { encryptedOutputs: v, lastOutput: b } = s(e, t, d);
|
|
49
49
|
await o(e, u);
|
|
50
|
-
let
|
|
51
|
-
|
|
52
|
-
let
|
|
53
|
-
return { inputUtxos: l ?
|
|
54
|
-
},
|
|
55
|
-
let l = o ?? await e.getEthereumAddressByChain(n), u = r(t(n) ? p(l) : l), { inputUtxos: d } = await
|
|
50
|
+
let S = b !== "", C = h.findIndex((e) => e.value === b), w = C > -1, T = !S && C === -1, E = e.areMerkleTreeUpdatesDisabled(), D = !E && (w || !a && T), O = !E && a && T, k = !D && !O, A = [];
|
|
51
|
+
D ? A = await _(e, f, t, u, d, h, v, b, C) : O ? A = await y(e, f, t, u, d, h, v, b, C) : k && (A = await e.utxoUtils.buildBatchProcess(v, f, t)), await o(e, u);
|
|
52
|
+
let j = await x(e, A, m);
|
|
53
|
+
return { inputUtxos: (l ? j.filter((e) => e.isBlocked) : j.filter((e) => !e.isBlocked)).filter((e) => !g(e.H0)) };
|
|
54
|
+
}, w = async ({ hinkal: e, chainId: n, passedShieldedPublicKey: a = void 0, ethAddress: o = void 0, resetCacheBefore: s = !1, allowRemoteDecryption: c = !1 }) => {
|
|
55
|
+
let l = o ?? await e.getEthereumAddressByChain(n), u = r(t(n) ? p(l) : l), { inputUtxos: d } = await C({
|
|
56
56
|
hinkal: e,
|
|
57
57
|
chainId: n,
|
|
58
58
|
passedShieldedPublicKey: a,
|
|
@@ -67,15 +67,15 @@ var h = new m(), g = async (e, t, n, r, i, a, s, c, u) => h.runExclusive(async (
|
|
|
67
67
|
nullifiers: d.map((e) => e.getNullifier())
|
|
68
68
|
});
|
|
69
69
|
return { inputUtxos: f.map((e) => d[e]).filter((e) => !!e) };
|
|
70
|
-
},
|
|
71
|
-
let g = s ?? t.userKeys.getShieldedPrivateKey(), _ = t.userKeys.getSpendingKeyPair().pubSpendingBJJPoint, { inputUtxos: v } = h ? await
|
|
70
|
+
}, T = async ({ hinkal: t, tokenWithId: r, minInput: i = 2, sliceIfMore6: a = !0, chainId: o, passedShieldedPrivateKey: s = void 0, passedShieldedPublicKey: c = void 0, ethAddress: l = 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({
|
|
72
72
|
hinkal: t,
|
|
73
73
|
chainId: o,
|
|
74
74
|
ethAddress: l,
|
|
75
75
|
passedShieldedPrivateKey: s,
|
|
76
76
|
resetCacheBefore: f,
|
|
77
77
|
allowRemoteDecryption: m
|
|
78
|
-
}) : await
|
|
78
|
+
}) : await C({
|
|
79
79
|
hinkal: t,
|
|
80
80
|
tokenWithId: r,
|
|
81
81
|
minInput: i,
|
|
@@ -86,27 +86,27 @@ var h = new m(), g = async (e, t, n, r, i, a, s, c, u) => h.runExclusive(async (
|
|
|
86
86
|
ethAddress: l,
|
|
87
87
|
resetCacheBefore: f,
|
|
88
88
|
allowRemoteDecryption: m
|
|
89
|
-
}),
|
|
89
|
+
}), y = b(r), x = /* @__PURE__ */ new Map();
|
|
90
90
|
v.forEach((e) => {
|
|
91
91
|
let t = e.getTokenAddress(o);
|
|
92
|
-
if (
|
|
92
|
+
if (y && !y.some((e) => n(e.erc20TokenAddress, t))) return;
|
|
93
93
|
let r = u(o, {
|
|
94
94
|
erc20TokenAddress: t,
|
|
95
95
|
tokenId: 0
|
|
96
|
-
}), i =
|
|
97
|
-
|
|
96
|
+
}), i = x.get(r) ?? [];
|
|
97
|
+
x.set(r, [...i, e]);
|
|
98
98
|
}), p?.forEach((e) => {
|
|
99
99
|
let t = u(o, {
|
|
100
100
|
erc20TokenAddress: e.erc20TokenAddress,
|
|
101
101
|
tokenId: 0
|
|
102
102
|
});
|
|
103
|
-
|
|
103
|
+
x.set(t, x.get(t) ?? []);
|
|
104
104
|
});
|
|
105
|
-
for (let [t, n] of
|
|
105
|
+
for (let [t, n] of x) {
|
|
106
106
|
let r = t.split("-")[0], s = Number(t.split("-")[1]), c = e(o), l = c ? r : void 0;
|
|
107
|
-
|
|
107
|
+
S(n, i, a, g, _, c ? d(r).compressedAddress.toLowerCase() : r.toLowerCase(), s, l);
|
|
108
108
|
}
|
|
109
|
-
return
|
|
109
|
+
return x;
|
|
110
110
|
};
|
|
111
111
|
//#endregion
|
|
112
|
-
export {
|
|
112
|
+
export { y as attemptGetInputUtxosRemotely, C as getInputUtxoAndBalance, w as getInputUtxoAndBalanceOfStuckUtxos, T as getInputUtxoAndBalancePerToken, v as getInputUtxosRemotely };
|