h_test_1 0.0.1 → 0.0.2
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("../../../data-structures/utxo/Utxo.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("../../../data-structures/utxo/Utxo.cjs"),C=require("../../utils/upToDateState.cjs"),O=require("../../utils/cacheFunctions.cjs"),K=require("../../utils/caseInsensitive.utils.cjs"),b=require("../../utils/encodeTokenWithId.cjs"),M=require("./getInputUtxosEnclave.cjs"),F=require("../../../error-handling/logger.cjs"),H=require("../../utils/solanaMint.utils.cjs"),_=require("../../../constants/chains.constants.cjs"),j=require("../../utils/addresses.cjs"),G=require("../../../API/scheduled-transactions-calls.cjs"),q=async(t,o,e,n,c,r,u,a,s)=>{s+=1;const l=r.slice(s),{lastOutput:f,additionalEncryptedOutputs:y}=await t.utxoUtils.batchProcess(l,a,o,e),i=[...u,...y];return await C.checkChainOrAddressNotUpdated(t,e,n),O.setHinkalCache({lastOutput:f,encryptedOutputs:i},t,e,c),await t.utxoUtils.buildBatchProcess(i,o,e)},S=async(t,o,e,n)=>{const{utxos:c,encryptedOutputs:r,lastOutput:u}=await M.getInputUtxosEnclave(t,e,o);return O.setHinkalCache({encryptedOutputs:r,lastOutput:u},t,e,n),c},N=async(t,o,e,n,c,r,u,a,s)=>{try{return await S(t,o,e,c)}catch{return q(t,o,e,n,c,r,u,a,s)}},D=t=>{if(Array.isArray(t))return t;if(t!==void 0)return[t]},J=async(t,o,e)=>await t.utxoUtils.batchFilterUtxosWithNullifier(o,e),W=(t,o,e,n,c,r,u)=>{for(t.sort((a,s)=>a.amount<=s.amount?1:-1),console.log("sorted utxos");t.length<o||t.length>o&&t.length<6;)if(console.log("before pushing"),console.log("aaa",c,u,n,r),t.push(new R.Utxo({amount:0n,erc20TokenAddress:c,mintAddress:u,shieldedPrivateKey:n,tokenId:r,enableLogs:!0})),console.log("after pushing"),e)for(;t.length>6;)t.splice(t.length-1);console.log("completed sorting utxos")},E=async({hinkal:t,chainId:o=void 0,passedShieldedPublicKey:e=void 0,ethAddress:n=void 0,resetCacheBefore:c=!1,allowRemoteDecryption:r=!1,useBlockedUtxos:u=!1})=>{if(!t.getCurrentChainId||!t.getSelectedNetwork())return F.Logger.log("returning empty balance"),{inputUtxos:[]};const a=n??await t.getEthereumAddress(),s=o??t.getCurrentChainId(),l=e??t.userKeys.getShieldedPublicKey(),{encryptedOutputs:f,nullifiers:y,userKeys:i}=t,g=Array.from(f);console.log("getInputUtxoAndBalance 1",{encryptedOutputs:f}),c&&O.resetCache(t,s,l);let{encryptedOutputs:h,lastOutput:x}=O.getHinkalCache(t,s,l);console.log("getInputUtxoAndBalance 2"),await C.checkChainOrAddressNotUpdated(t,s,a),console.log("getInputUtxoAndBalance 3");const p=x!=="",d=g.findIndex(k=>k.value===x);console.log("getInputUtxoAndBalance 4");const I=d>-1,T=!p&&d===-1;console.log("getInputUtxoAndBalance 5");const w=t.areMerkleTreeUpdatesDisabled();console.log("getInputUtxoAndBalance 6");const v=!w&&(I||!r&&T),B=!w&&r&&T,A=!v&&!B;let U=[];v?U=await q(t,i,s,a,l,g,h,x,d):B?U=await N(t,i,s,a,l,g,h,x,d):A&&(U=await t.utxoUtils.buildBatchProcess(h,i,s)),console.log("getInputUtxoAndBalance 7",{allUtxos:U}),await C.checkChainOrAddressNotUpdated(t,s,a);const m=await J(t,U,y);console.log("getInputUtxoAndBalance 8",{inputUtxos:m});const P=u?m:m.filter(k=>!k.isBlocked);return console.log("getInputUtxoAndBalance 9",{filteredInputUtxos:P}),console.trace(),{inputUtxos:P}},L=async({hinkal:t,chainId:o=void 0,passedShieldedPublicKey:e=void 0,ethAddress:n=void 0,resetCacheBefore:c=!1,allowRemoteDecryption:r=!1})=>{const u=o??t.getCurrentChainId(),a=n??await t.getEthereumAddress(),s=j.hashEthereumAddress(a),{inputUtxos:l}=await E({hinkal:t,chainId:u,passedShieldedPublicKey:e,ethAddress:a,resetCacheBefore:c,allowRemoteDecryption:r,useBlockedUtxos:!0});if(!l.length)return{inputUtxos:[]};const f=l.map(g=>g.getNullifier()),{indexes:y}=await G.getScheduledTransactionsNullifierIndexes(u,{hashedEthereumAddress:s,nullifiers:f});return{inputUtxos:y.map(g=>l[g]).filter(g=>!!g)}},z=async({hinkal:t,tokenWithId:o,minInput:e=2,sliceIfMore6:n=!0,chainId:c=void 0,passedShieldedPrivateKey:r=void 0,passedShieldedPublicKey:u=void 0,ethAddress:a=void 0,resetCacheBefore:s=!1,ensuredTokensWithId:l,useBlockedUtxos:f=!1})=>{const y=r??t.userKeys.getShieldedPrivateKey(),i=c??t.getCurrentChainId();console.log("getInputUtxoAndBalancePerToken 1");const{inputUtxos:g}=f?await L({hinkal:t,chainId:c,ethAddress:a,passedShieldedPrivateKey:r,resetCacheBefore:s}):await E({hinkal:t,tokenWithId:o,minInput:e,sliceIfMore6:n,chainId:c,passedShieldedPrivateKey:r,passedShieldedPublicKey:u,ethAddress:a,resetCacheBefore:s});console.log("getInputUtxoAndBalancePerToken 2");const h=D(o),x=new Map;console.log("getInputUtxoAndBalancePerToken 3"),g.forEach(p=>{const d=p.getTokenAddress(i);if(h&&!h.some(w=>K.caseInsensitiveEqual(w.erc20TokenAddress,d)&&w.tokenId===p.tokenId))return;const I=b.encodeTokenWithId(i,{erc20TokenAddress:d,tokenId:p.tokenId}),T=x.get(I)??[];x.set(I,[...T,p])}),console.log("getInputUtxoAndBalancePerToken 4"),l?.forEach(p=>{const d=b.encodeTokenWithId(i,{erc20TokenAddress:p.erc20TokenAddress,tokenId:p.tokenId});x.set(d,x.get(d)??[])}),console.log("getInputUtxoAndBalancePerToken 5");for(const[p,d]of x){const I=p.split("-")[0],T=Number(p.split("-")[1]),w=_.isSolanaLike(i),v=w?I:void 0,B=w?H.formatMintAddress(I).compressedAddress.toLowerCase():I.toLowerCase(),A=U=>U===null?"null":typeof U!="object"?typeof U:U.constructor.name;console.log("types",JSON.stringify({value:A(d),minInput:A(e),sliceIfMore6:A(n),shieldedPrivateKey:A(y),modifiedErc20TokenAddress:A(B),tokenId:A(T),mintAddress:A(v)})),console.log("started padding"),W(d,e,n,y,B,T,v),console.log("done padding")}return console.log("getInputUtxoAndBalancePerToken 6"),x};exports.attemptGetInputUtxosRemotely=N;exports.getInputUtxoAndBalance=E;exports.getInputUtxoAndBalanceOfStuckUtxos=L;exports.getInputUtxoAndBalancePerToken=z;exports.getInputUtxosRemotely=S;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import { Utxo as S } from "../../../data-structures/utxo/Utxo.mjs";
|
|
2
|
-
import { checkChainOrAddressNotUpdated as
|
|
3
|
-
import { setHinkalCache as
|
|
2
|
+
import { checkChainOrAddressNotUpdated as E } from "../../utils/upToDateState.mjs";
|
|
3
|
+
import { setHinkalCache as b, resetCache as L, getHinkalCache as K } from "../../utils/cacheFunctions.mjs";
|
|
4
4
|
import { caseInsensitiveEqual as R } from "../../utils/caseInsensitive.utils.mjs";
|
|
5
|
-
import { encodeTokenWithId as
|
|
5
|
+
import { encodeTokenWithId as C } from "../../utils/encodeTokenWithId.mjs";
|
|
6
6
|
import { getInputUtxosEnclave as F } from "./getInputUtxosEnclave.mjs";
|
|
7
7
|
import { Logger as H } from "../../../error-handling/logger.mjs";
|
|
8
8
|
import { formatMintAddress as M } from "../../utils/solanaMint.utils.mjs";
|
|
9
9
|
import { isSolanaLike as j } from "../../../constants/chains.constants.mjs";
|
|
10
10
|
import { hashEthereumAddress as q } from "../../utils/addresses.mjs";
|
|
11
11
|
import { getScheduledTransactionsNullifierIndexes as G } from "../../../API/scheduled-transactions-calls.mjs";
|
|
12
|
-
const
|
|
12
|
+
const k = async (t, o, e, n, r, c, l, a, s) => {
|
|
13
13
|
s += 1;
|
|
14
|
-
const u = c.slice(s), { lastOutput:
|
|
14
|
+
const u = c.slice(s), { lastOutput: A, additionalEncryptedOutputs: m } = await t.utxoUtils.batchProcess(
|
|
15
15
|
u,
|
|
16
16
|
a,
|
|
17
17
|
o,
|
|
18
18
|
e
|
|
19
|
-
), i = [...l, ...
|
|
20
|
-
return await
|
|
19
|
+
), i = [...l, ...m];
|
|
20
|
+
return await E(t, e, n), b(
|
|
21
21
|
{
|
|
22
|
-
lastOutput:
|
|
22
|
+
lastOutput: A,
|
|
23
23
|
encryptedOutputs: i
|
|
24
24
|
},
|
|
25
25
|
t,
|
|
@@ -32,7 +32,7 @@ const b = async (t, o, e, n, r, c, l, a, s) => {
|
|
|
32
32
|
encryptedOutputs: c,
|
|
33
33
|
lastOutput: l
|
|
34
34
|
} = await F(t, e, o);
|
|
35
|
-
return
|
|
35
|
+
return b(
|
|
36
36
|
{
|
|
37
37
|
encryptedOutputs: c,
|
|
38
38
|
lastOutput: l
|
|
@@ -45,7 +45,7 @@ const b = async (t, o, e, n, r, c, l, a, s) => {
|
|
|
45
45
|
try {
|
|
46
46
|
return await J(t, o, e, r);
|
|
47
47
|
} catch {
|
|
48
|
-
return
|
|
48
|
+
return k(
|
|
49
49
|
t,
|
|
50
50
|
o,
|
|
51
51
|
e,
|
|
@@ -70,7 +70,7 @@ const b = async (t, o, e, n, r, c, l, a, s) => {
|
|
|
70
70
|
for (; t.length > 6; )
|
|
71
71
|
t.splice(t.length - 1);
|
|
72
72
|
console.log("completed sorting utxos");
|
|
73
|
-
},
|
|
73
|
+
}, N = async ({
|
|
74
74
|
hinkal: t,
|
|
75
75
|
chainId: o = void 0,
|
|
76
76
|
passedShieldedPublicKey: e = void 0,
|
|
@@ -81,23 +81,23 @@ const b = async (t, o, e, n, r, c, l, a, s) => {
|
|
|
81
81
|
}) => {
|
|
82
82
|
if (!t.getCurrentChainId || !t.getSelectedNetwork())
|
|
83
83
|
return H.log("returning empty balance"), { inputUtxos: [] };
|
|
84
|
-
const a = n ?? await t.getEthereumAddress(), s = o ?? t.getCurrentChainId(), u = e ?? t.userKeys.getShieldedPublicKey(), { encryptedOutputs:
|
|
85
|
-
console.log("getInputUtxoAndBalance 1"), r && L(t, s, u);
|
|
84
|
+
const a = n ?? await t.getEthereumAddress(), s = o ?? t.getCurrentChainId(), u = e ?? t.userKeys.getShieldedPublicKey(), { encryptedOutputs: A, nullifiers: m, userKeys: i } = t, p = Array.from(A);
|
|
85
|
+
console.log("getInputUtxoAndBalance 1", { encryptedOutputs: A }), r && L(t, s, u);
|
|
86
86
|
let { encryptedOutputs: v, lastOutput: f } = K(
|
|
87
87
|
t,
|
|
88
88
|
s,
|
|
89
89
|
u
|
|
90
90
|
);
|
|
91
|
-
console.log("getInputUtxoAndBalance 2"), await
|
|
92
|
-
const g = f !== "", d = p.findIndex((
|
|
91
|
+
console.log("getInputUtxoAndBalance 2"), await E(t, s, a), console.log("getInputUtxoAndBalance 3");
|
|
92
|
+
const g = f !== "", d = p.findIndex((h) => h.value === f);
|
|
93
93
|
console.log("getInputUtxoAndBalance 4");
|
|
94
|
-
const
|
|
94
|
+
const y = d > -1, w = !g && d === -1;
|
|
95
95
|
console.log("getInputUtxoAndBalance 5");
|
|
96
|
-
const
|
|
96
|
+
const I = t.areMerkleTreeUpdatesDisabled();
|
|
97
97
|
console.log("getInputUtxoAndBalance 6");
|
|
98
|
-
const B = !
|
|
99
|
-
let
|
|
100
|
-
B ?
|
|
98
|
+
const B = !I && (y || !c && w), T = !I && c && w, U = !B && !T;
|
|
99
|
+
let x = [];
|
|
100
|
+
B ? x = await k(
|
|
101
101
|
t,
|
|
102
102
|
i,
|
|
103
103
|
s,
|
|
@@ -107,7 +107,7 @@ const b = async (t, o, e, n, r, c, l, a, s) => {
|
|
|
107
107
|
v,
|
|
108
108
|
f,
|
|
109
109
|
d
|
|
110
|
-
) : T ?
|
|
110
|
+
) : T ? x = await z(
|
|
111
111
|
t,
|
|
112
112
|
i,
|
|
113
113
|
s,
|
|
@@ -117,11 +117,11 @@ const b = async (t, o, e, n, r, c, l, a, s) => {
|
|
|
117
117
|
v,
|
|
118
118
|
f,
|
|
119
119
|
d
|
|
120
|
-
) :
|
|
121
|
-
const
|
|
122
|
-
console.log("getInputUtxoAndBalance 8");
|
|
123
|
-
const
|
|
124
|
-
return console.log("getInputUtxoAndBalance 9"), console.trace(), { inputUtxos:
|
|
120
|
+
) : U && (x = await t.utxoUtils.buildBatchProcess(v, i, s)), console.log("getInputUtxoAndBalance 7", { allUtxos: x }), await E(t, s, a);
|
|
121
|
+
const O = await Q(t, x, m);
|
|
122
|
+
console.log("getInputUtxoAndBalance 8", { inputUtxos: O });
|
|
123
|
+
const P = l ? O : O.filter((h) => !h.isBlocked);
|
|
124
|
+
return console.log("getInputUtxoAndBalance 9", { filteredInputUtxos: P }), console.trace(), { inputUtxos: P };
|
|
125
125
|
}, X = async ({
|
|
126
126
|
hinkal: t,
|
|
127
127
|
chainId: o = void 0,
|
|
@@ -130,7 +130,7 @@ const b = async (t, o, e, n, r, c, l, a, s) => {
|
|
|
130
130
|
resetCacheBefore: r = !1,
|
|
131
131
|
allowRemoteDecryption: c = !1
|
|
132
132
|
}) => {
|
|
133
|
-
const l = o ?? t.getCurrentChainId(), a = n ?? await t.getEthereumAddress(), s = q(a), { inputUtxos: u } = await
|
|
133
|
+
const l = o ?? t.getCurrentChainId(), a = n ?? await t.getEthereumAddress(), s = q(a), { inputUtxos: u } = await N({
|
|
134
134
|
hinkal: t,
|
|
135
135
|
chainId: l,
|
|
136
136
|
passedShieldedPublicKey: e,
|
|
@@ -141,11 +141,11 @@ const b = async (t, o, e, n, r, c, l, a, s) => {
|
|
|
141
141
|
});
|
|
142
142
|
if (!u.length)
|
|
143
143
|
return { inputUtxos: [] };
|
|
144
|
-
const
|
|
144
|
+
const A = u.map((p) => p.getNullifier()), { indexes: m } = await G(l, {
|
|
145
145
|
hashedEthereumAddress: s,
|
|
146
|
-
nullifiers:
|
|
146
|
+
nullifiers: A
|
|
147
147
|
});
|
|
148
|
-
return { inputUtxos:
|
|
148
|
+
return { inputUtxos: m.map((p) => u[p]).filter((p) => !!p) };
|
|
149
149
|
}, ct = async ({
|
|
150
150
|
hinkal: t,
|
|
151
151
|
tokenWithId: o,
|
|
@@ -157,17 +157,17 @@ const b = async (t, o, e, n, r, c, l, a, s) => {
|
|
|
157
157
|
ethAddress: a = void 0,
|
|
158
158
|
resetCacheBefore: s = !1,
|
|
159
159
|
ensuredTokensWithId: u,
|
|
160
|
-
useBlockedUtxos:
|
|
160
|
+
useBlockedUtxos: A = !1
|
|
161
161
|
}) => {
|
|
162
|
-
const
|
|
162
|
+
const m = c ?? t.userKeys.getShieldedPrivateKey(), i = r ?? t.getCurrentChainId();
|
|
163
163
|
console.log("getInputUtxoAndBalancePerToken 1");
|
|
164
|
-
const { inputUtxos: p } =
|
|
164
|
+
const { inputUtxos: p } = A ? await X({
|
|
165
165
|
hinkal: t,
|
|
166
166
|
chainId: r,
|
|
167
167
|
ethAddress: a,
|
|
168
168
|
passedShieldedPrivateKey: c,
|
|
169
169
|
resetCacheBefore: s
|
|
170
|
-
}) : await
|
|
170
|
+
}) : await N({
|
|
171
171
|
hinkal: t,
|
|
172
172
|
tokenWithId: o,
|
|
173
173
|
minInput: e,
|
|
@@ -183,38 +183,38 @@ const b = async (t, o, e, n, r, c, l, a, s) => {
|
|
|
183
183
|
console.log("getInputUtxoAndBalancePerToken 3"), p.forEach((g) => {
|
|
184
184
|
const d = g.getTokenAddress(i);
|
|
185
185
|
if (v && !v.some(
|
|
186
|
-
(
|
|
186
|
+
(I) => R(I.erc20TokenAddress, d) && I.tokenId === g.tokenId
|
|
187
187
|
))
|
|
188
188
|
return;
|
|
189
|
-
const
|
|
190
|
-
f.set(
|
|
189
|
+
const y = C(i, { erc20TokenAddress: d, tokenId: g.tokenId }), w = f.get(y) ?? [];
|
|
190
|
+
f.set(y, [...w, g]);
|
|
191
191
|
}), console.log("getInputUtxoAndBalancePerToken 4"), u?.forEach((g) => {
|
|
192
|
-
const d =
|
|
192
|
+
const d = C(i, {
|
|
193
193
|
erc20TokenAddress: g.erc20TokenAddress,
|
|
194
194
|
tokenId: g.tokenId
|
|
195
195
|
});
|
|
196
196
|
f.set(d, f.get(d) ?? []);
|
|
197
197
|
}), console.log("getInputUtxoAndBalancePerToken 5");
|
|
198
198
|
for (const [g, d] of f) {
|
|
199
|
-
const
|
|
199
|
+
const y = g.split("-")[0], w = Number(g.split("-")[1]), I = j(i), B = I ? y : void 0, T = I ? M(y).compressedAddress.toLowerCase() : y.toLowerCase(), U = (x) => x === null ? "null" : typeof x != "object" ? typeof x : x.constructor.name;
|
|
200
200
|
console.log(
|
|
201
201
|
"types",
|
|
202
202
|
JSON.stringify({
|
|
203
|
-
value:
|
|
204
|
-
minInput:
|
|
205
|
-
sliceIfMore6:
|
|
206
|
-
shieldedPrivateKey:
|
|
207
|
-
modifiedErc20TokenAddress:
|
|
208
|
-
tokenId:
|
|
209
|
-
mintAddress:
|
|
203
|
+
value: U(d),
|
|
204
|
+
minInput: U(e),
|
|
205
|
+
sliceIfMore6: U(n),
|
|
206
|
+
shieldedPrivateKey: U(m),
|
|
207
|
+
modifiedErc20TokenAddress: U(T),
|
|
208
|
+
tokenId: U(w),
|
|
209
|
+
mintAddress: U(B)
|
|
210
210
|
})
|
|
211
|
-
), console.log("started padding"), V(d, e, n,
|
|
211
|
+
), console.log("started padding"), V(d, e, n, m, T, w, B), console.log("done padding");
|
|
212
212
|
}
|
|
213
213
|
return console.log("getInputUtxoAndBalancePerToken 6"), f;
|
|
214
214
|
};
|
|
215
215
|
export {
|
|
216
216
|
z as attemptGetInputUtxosRemotely,
|
|
217
|
-
|
|
217
|
+
N as getInputUtxoAndBalance,
|
|
218
218
|
X as getInputUtxoAndBalanceOfStuckUtxos,
|
|
219
219
|
ct as getInputUtxoAndBalancePerToken,
|
|
220
220
|
J as getInputUtxosRemotely
|