h_test_1 0.0.4 → 0.0.5

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 F=require("../../error-handling/error-codes.constants.cjs"),L=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),M=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),H=require("../../functions/web3/events/getShieldedBalance.cjs"),K=require("../../functions/web3/functionCalls/estimateGasRelayer.cjs"),N=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),W=require("../../functions/pre-transaction/getFeeStructure.cjs"),B=require("../../functions/pre-transaction/merge-with-fee-structure.cjs"),b=require("../../types/external-action.types.cjs"),k=require("../../types/hinkal.types.cjs"),G=require("../../functions/pre-transaction/outputApprovalDataProcessing.cjs"),O=require("../../types/ethereum-network.types.cjs"),V=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs"),Z=require("../../functions/pre-transaction/getSignatureDataForTransact.cjs"),$=require("../../functions/pre-transaction/getExternalSwapAddress.cjs"),j=require("../../functions/utils/time.utils.cjs"),z=require("../../constants/protocol.constants.cjs");require("../../types/circom-data.types.cjs");require("../../types/activities.types.cjs");require("../../constants/server.constants.cjs");require("../../constants/chains.constants.cjs");require("../../constants/vite.constants.cjs");require("../http/HttpClient.cjs");require("axios");require("ethers");require("../../constants/token-data/index.cjs");require("../../API/getServerURL.cjs");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");require("../../constants/save-depths.cjs");require("../../constants/reorg-depths.constants.cjs");require("../../functions/utils/mutexes.utils.cjs");require("@coral-xyz/anchor");require("@solana/web3.js");require("../crypto-keys/keys.cjs");const Y=require("../../functions/pre-transaction/constructAdminData.cjs");require("@solana/spl-token");const J=async(e,c,t,i,x,T,S,m,u=!1,w=!1)=>{const s=c.map(r=>r.erc20TokenAddress),d=await e.getEthereumAddress(),g=S??await W.getFeeStructure(e.getCurrentChainId(),T,s,b.ExternalActionId.Transact,void 0,z.HINKAL_SWAP_VARIABLE_RATE);B.mergeWithFeeStructure(e.getCurrentChainId(),s,t,g);const f=$.getExternalSwapAddress(e,i),o={externalActionId:i,externalAddress:f,externalActionMetadata:x},a=[...await H.addPaddingToUtxos(e,s,t)],v=`swapperM${t.length.toString()}x${a[0].length}x1`,D=[!1,!0,!1].slice(0,t.length),q=[],n=k.defaultHinkalLogicArgs(t.length,e.userKeys),R=j.getCurrentTimeInSeconds().toString();for(let r=0;r<s.length;r+=1){const{outputUtxos:U}=L.outputUtxoProcessing(e.userKeys,a[r],t[r],R,void 0,!1);q.push(U);const{useApprovalUtxoData:y}=G.outputApprovalDataProcessing(e,a[r],t[r]);y&&(n.useApprovalUtxoData[r]=y,n.doPreTxApproval=!0)}const l=await e.getRandomRelay(!u);if(!l)throw Error(F.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const{patchAccessTokenMerkleTree:P,kycRequired:h,hasAccessToken:E}=await V.shouldPatchAccessTokenMerkleTree(e,s,t),I=await Z.getSignatureDataForTransact(e.getCurrentChainId(),d,e.userKeys,h,E),{zkCallData:p,circomData:A,dimData:C}=await M.constructZkProof("v1x1",e.merkleTreeHinkal,e.merkleTreeAccessToken,a,q,e.userKeys,v,o.externalActionId,o.externalAddress,o.externalActionMetadata,e.generateProofRemotely,l,e.getCurrentChainId(),D,void 0,void 0,P,n,void 0,g,e.getContractWithFetcher(O.ContractType.HinkalHelperContract),I);if(u)return await K.estimateGasRelayer(e,p,C,A);const _=Y.constructAdminData(m,e.getCurrentChainId(),s,t,d,c);return await N.transactCallRelayer(e.getCurrentChainId(),p,C,A,w,void 0,void 0,_)};exports.hinkalSwap=J;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("../../error-handling/error-codes.constants.cjs"),L=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),M=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),H=require("../../functions/web3/events/getShieldedBalance.cjs"),K=require("../../functions/web3/functionCalls/estimateGasRelayer.cjs"),N=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),W=require("../../functions/pre-transaction/getFeeStructure.cjs"),B=require("../../functions/pre-transaction/merge-with-fee-structure.cjs"),b=require("../../types/external-action.types.cjs"),G=require("../../types/hinkal.types.cjs"),O=require("../../functions/pre-transaction/outputApprovalDataProcessing.cjs"),V=require("../../types/ethereum-network.types.cjs"),Z=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs"),$=require("../../functions/pre-transaction/getSignatureDataForTransact.cjs"),j=require("../../functions/pre-transaction/getExternalSwapAddress.cjs"),z=require("../../functions/utils/time.utils.cjs"),Y=require("../../constants/protocol.constants.cjs");require("../../types/circom-data.types.cjs");require("../../types/activities.types.cjs");require("../../constants/server.constants.cjs");require("../../constants/chains.constants.cjs");require("../../constants/vite.constants.cjs");require("../http/HttpClient.cjs");require("axios");require("ethers");require("../../constants/token-data/index.cjs");require("../../API/getServerURL.cjs");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");require("../../constants/save-depths.cjs");require("../../constants/reorg-depths.constants.cjs");require("../../functions/utils/mutexes.utils.cjs");require("@coral-xyz/anchor");require("@solana/web3.js");require("../crypto-keys/keys.cjs");const J=require("../../functions/pre-transaction/constructAdminData.cjs");require("@solana/spl-token");const Q=async(e,c,t,i,A,C,k,x,l=!1,y=!1)=>{console.log("hinkalSwap 1");const o=c.map(r=>r.erc20TokenAddress);console.log("hinkalSwap 2");const u=await e.getEthereumAddress();console.log("hinkalSwap 3");const g=k??await W.getFeeStructure(e.getCurrentChainId(),C,o,b.ExternalActionId.Transact,void 0,Y.HINKAL_SWAP_VARIABLE_RATE);B.mergeWithFeeStructure(e.getCurrentChainId(),o,t,g),console.log("hinkalSwap 4");const T=j.getExternalSwapAddress(e,i),s={externalActionId:i,externalAddress:T,externalActionMetadata:A};console.log("hinkalSwap 5");const a=[...await H.addPaddingToUtxos(e,o,t)],m=`swapperM${t.length.toString()}x${a[0].length}x1`;console.log("hinkalSwap 6");const f=[!1,!0,!1].slice(0,t.length),p=[];console.log("hinkalSwap 7");const n=G.defaultHinkalLogicArgs(t.length,e.userKeys);console.log("hinkalSwap 8");const v=z.getCurrentTimeInSeconds().toString();for(let r=0;r<o.length;r+=1){console.log("hinkalSwap 9",{i:r});const{outputUtxos:U}=L.outputUtxoProcessing(e.userKeys,a[r],t[r],v,void 0,!1);console.log("hinkalSwap 10",{i:r}),p.push(U);const{useApprovalUtxoData:h}=O.outputApprovalDataProcessing(e,a[r],t[r]);console.log("hinkalSwap 11",{i:r}),h&&(n.useApprovalUtxoData[r]=h,n.doPreTxApproval=!0),console.log("hinkalSwap 12",{i:r})}console.log("hinkalSwap 13");const d=await e.getRandomRelay(!l);if(!d)throw Error(F.transactionErrorCodes.RELAYER_NOT_AVAILABLE);console.log("hinkalSwap 14");const{patchAccessTokenMerkleTree:D,kycRequired:P,hasAccessToken:R}=await Z.shouldPatchAccessTokenMerkleTree(e,o,t);console.log("hinkalSwap 15");const E=await $.getSignatureDataForTransact(e.getCurrentChainId(),u,e.userKeys,P,R);console.log("hinkalSwap 16");const{zkCallData:q,circomData:S,dimData:w}=await M.constructZkProof("v1x1",e.merkleTreeHinkal,e.merkleTreeAccessToken,a,p,e.userKeys,m,s.externalActionId,s.externalAddress,s.externalActionMetadata,e.generateProofRemotely,d,e.getCurrentChainId(),f,void 0,void 0,D,n,void 0,g,e.getContractWithFetcher(V.ContractType.HinkalHelperContract),E);if(console.log("hinkalSwap 17"),l)return await K.estimateGasRelayer(e,q,w,S);console.log("hinkalSwap 18");const I=J.constructAdminData(x,e.getCurrentChainId(),o,t,u,c);console.log("hinkalSwap 19");const _=await N.transactCallRelayer(e.getCurrentChainId(),q,w,S,y,void 0,void 0,I);return console.log("hinkalSwap 20"),_};exports.hinkalSwap=Q;
@@ -37,92 +37,115 @@ import "@solana/web3.js";
37
37
  import "../crypto-keys/keys.mjs";
38
38
  import { constructAdminData as J } from "../../functions/pre-transaction/constructAdminData.mjs";
39
39
  import "@solana/spl-token";
40
- const Nt = async (t, m, e, p, l, T, y, w, c = !1, v = !1) => {
41
- const o = m.map((r) => r.erc20TokenAddress), n = await t.getEthereumAddress(), d = y ?? await B(
42
- t.getCurrentChainId(),
43
- T,
44
- o,
40
+ const No = async (o, s, r, p, h, A, C, x, c = !1, T = !1) => {
41
+ console.log("hinkalSwap 1");
42
+ const e = s.map((t) => t.erc20TokenAddress);
43
+ console.log("hinkalSwap 2");
44
+ const l = await o.getEthereumAddress();
45
+ console.log("hinkalSwap 3");
46
+ const m = C ?? await B(
47
+ o.getCurrentChainId(),
48
+ A,
49
+ e,
45
50
  $.Transact,
46
51
  void 0,
47
52
  G
48
53
  );
49
- V(t.getCurrentChainId(), o, e, d);
50
- const R = b(t, p), s = {
54
+ V(o.getCurrentChainId(), e, r, m), console.log("hinkalSwap 4");
55
+ const k = b(o, p), i = {
51
56
  externalActionId: p,
52
- externalAddress: R,
53
- externalActionMetadata: l
54
- }, a = [...await F(t, o, e)], D = `swapperM${e.length.toString()}x${a[0].length}x1`, E = [!1, !0, !1].slice(0, e.length), u = [], i = q(e.length, t.userKeys), I = j().toString();
55
- for (let r = 0; r < o.length; r += 1) {
57
+ externalAddress: k,
58
+ externalActionMetadata: h
59
+ };
60
+ console.log("hinkalSwap 5");
61
+ const a = [...await F(o, e, r)], y = `swapperM${r.length.toString()}x${a[0].length}x1`;
62
+ console.log("hinkalSwap 6");
63
+ const v = [!1, !0, !1].slice(0, r.length), g = [];
64
+ console.log("hinkalSwap 7");
65
+ const n = q(r.length, o.userKeys);
66
+ console.log("hinkalSwap 8");
67
+ const D = j().toString();
68
+ for (let t = 0; t < e.length; t += 1) {
69
+ console.log("hinkalSwap 9", { i: t });
56
70
  const { outputUtxos: H } = M(
57
- t.userKeys,
58
- a[r],
59
- e[r],
60
- I,
71
+ o.userKeys,
72
+ a[t],
73
+ r[t],
74
+ D,
61
75
  void 0,
62
76
  !1
63
77
  );
64
- u.push(H);
65
- const { useApprovalUtxoData: x } = z(t, a[r], e[r]);
66
- x && (i.useApprovalUtxoData[r] = x, i.doPreTxApproval = !0);
78
+ console.log("hinkalSwap 10", { i: t }), g.push(H);
79
+ const { useApprovalUtxoData: S } = z(o, a[t], r[t]);
80
+ console.log("hinkalSwap 11", { i: t }), S && (n.useApprovalUtxoData[t] = S, n.doPreTxApproval = !0), console.log("hinkalSwap 12", { i: t });
67
81
  }
68
- const g = await t.getRandomRelay(!c);
69
- if (!g)
82
+ console.log("hinkalSwap 13");
83
+ const d = await o.getRandomRelay(!c);
84
+ if (!d)
70
85
  throw Error(K.RELAYER_NOT_AVAILABLE);
71
- const { patchAccessTokenMerkleTree: S, kycRequired: P, hasAccessToken: L } = await Y(
72
- t,
86
+ console.log("hinkalSwap 14");
87
+ const { patchAccessTokenMerkleTree: E, kycRequired: I, hasAccessToken: R } = await Y(
73
88
  o,
74
- e
75
- ), U = await Z(
76
- t.getCurrentChainId(),
77
- n,
78
- t.userKeys,
79
- P,
80
- L
81
- ), { zkCallData: f, circomData: A, dimData: C } = await _(
89
+ e,
90
+ r
91
+ );
92
+ console.log("hinkalSwap 15");
93
+ const P = await Z(
94
+ o.getCurrentChainId(),
95
+ l,
96
+ o.userKeys,
97
+ I,
98
+ R
99
+ );
100
+ console.log("hinkalSwap 16");
101
+ const { zkCallData: u, circomData: w, dimData: f } = await _(
82
102
  "v1x1",
83
- t.merkleTreeHinkal,
84
- t.merkleTreeAccessToken,
103
+ o.merkleTreeHinkal,
104
+ o.merkleTreeAccessToken,
85
105
  a,
86
- u,
87
- t.userKeys,
88
- D,
89
- s.externalActionId,
90
- s.externalAddress,
91
- s.externalActionMetadata,
92
- t.generateProofRemotely,
93
106
  g,
94
- t.getCurrentChainId(),
95
- E,
107
+ o.userKeys,
108
+ y,
109
+ i.externalActionId,
110
+ i.externalAddress,
111
+ i.externalActionMetadata,
112
+ o.generateProofRemotely,
113
+ d,
114
+ o.getCurrentChainId(),
115
+ v,
96
116
  void 0,
97
117
  void 0,
98
- S,
99
- i,
118
+ E,
119
+ n,
100
120
  void 0,
101
- d,
102
- t.getContractWithFetcher(O.HinkalHelperContract),
103
- U
121
+ m,
122
+ o.getContractWithFetcher(O.HinkalHelperContract),
123
+ P
104
124
  );
105
- if (c)
106
- return await N(t, f, C, A);
107
- const h = J(
108
- w,
109
- t.getCurrentChainId(),
110
- o,
125
+ if (console.log("hinkalSwap 17"), c)
126
+ return await N(o, u, f, w);
127
+ console.log("hinkalSwap 18");
128
+ const L = J(
129
+ x,
130
+ o.getCurrentChainId(),
111
131
  e,
112
- n,
113
- m
132
+ r,
133
+ l,
134
+ s
114
135
  );
115
- return await W(
116
- t.getCurrentChainId(),
136
+ console.log("hinkalSwap 19");
137
+ const U = await W(
138
+ o.getCurrentChainId(),
139
+ u,
117
140
  f,
118
- C,
119
- A,
120
- v,
141
+ w,
142
+ T,
121
143
  void 0,
122
144
  void 0,
123
- h
145
+ L
124
146
  );
147
+ return console.log("hinkalSwap 20"), U;
125
148
  };
126
149
  export {
127
- Nt as hinkalSwap
150
+ No as hinkalSwap
128
151
  };
@@ -7,6 +7,7 @@ const K = (e) => {
7
7
  const r = [
8
8
  Buffer.from(o.toBeHex(e.amount)),
9
9
  Buffer.from(e.erc20TokenAddress),
10
+ // if it is zeroAddress toBeHex will return 0x00
10
11
  Buffer.from(o.toBeHex(e.randomization)),
11
12
  Buffer.from(e.getStealthAddress()),
12
13
  Buffer.from(o.toBeHex(BigInt(e.timeStamp))),
@@ -1 +1 @@
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
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const R=require("../../../data-structures/utxo/Utxo.cjs"),k=require("../../utils/upToDateState.cjs"),O=require("../../utils/cacheFunctions.cjs"),K=require("../../utils/caseInsensitive.utils.cjs"),P=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"),b=async(t,o,e,n,c,r,u,a,s)=>{s+=1;const l=r.slice(s),{lastOutput:w,additionalEncryptedOutputs:f}=await t.utxoUtils.batchProcess(l,a,o,e),i=[...u,...f];return await k.checkChainOrAddressNotUpdated(t,e,n),O.setHinkalCache({lastOutput:w,encryptedOutputs:i},t,e,c),await t.utxoUtils.buildBatchProcess(i,o,e)},q=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},S=async(t,o,e,n,c,r,u,a,s)=>{try{return await q(t,o,e,c)}catch{return b(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")},C=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:w,nullifiers:f,userKeys:i}=t,g=Array.from(w);console.log("getInputUtxoAndBalance 1"),c&&O.resetCache(t,s,l);let{encryptedOutputs:h,lastOutput:x}=O.getHinkalCache(t,s,l);console.log("getInputUtxoAndBalance 2"),await k.checkChainOrAddressNotUpdated(t,s,a),console.log("getInputUtxoAndBalance 3");const p=x!=="",d=g.findIndex(m=>m.value===x);console.log("getInputUtxoAndBalance 4");const y=d>-1,T=!p&&d===-1;console.log("getInputUtxoAndBalance 5");const I=t.areMerkleTreeUpdatesDisabled();console.log("getInputUtxoAndBalance 6");const v=!I&&(y||!r&&T),B=!I&&r&&T,U=!v&&!B;let A=[];v?A=await b(t,i,s,a,l,g,h,x,d):B?A=await S(t,i,s,a,l,g,h,x,d):U&&(A=await t.utxoUtils.buildBatchProcess(h,i,s)),console.log("getInputUtxoAndBalance 7"),await k.checkChainOrAddressNotUpdated(t,s,a);const E=await J(t,A,f);console.log("getInputUtxoAndBalance 8");const L=u?E:E.filter(m=>!m.isBlocked);return console.log("getInputUtxoAndBalance 9"),console.trace(),{inputUtxos:L}},N=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 C({hinkal:t,chainId:u,passedShieldedPublicKey:e,ethAddress:a,resetCacheBefore:c,allowRemoteDecryption:r,useBlockedUtxos:!0});if(!l.length)return{inputUtxos:[]};const w=l.map(g=>g.getNullifier()),{indexes:f}=await G.getScheduledTransactionsNullifierIndexes(u,{hashedEthereumAddress:s,nullifiers:w});return{inputUtxos:f.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:w=!1})=>{const f=r??t.userKeys.getShieldedPrivateKey(),i=c??t.getCurrentChainId();console.log("getInputUtxoAndBalancePerToken 1");const{inputUtxos:g}=w?await N({hinkal:t,chainId:c,ethAddress:a,passedShieldedPrivateKey:r,resetCacheBefore:s}):await C({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(I=>K.caseInsensitiveEqual(I.erc20TokenAddress,d)&&I.tokenId===p.tokenId))return;const y=P.encodeTokenWithId(i,{erc20TokenAddress:d,tokenId:p.tokenId}),T=x.get(y)??[];x.set(y,[...T,p])}),console.log("getInputUtxoAndBalancePerToken 4"),l?.forEach(p=>{const d=P.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 y=p.split("-")[0],T=Number(p.split("-")[1]),I=_.isSolanaLike(i),v=I?y:void 0,B=I?H.formatMintAddress(y).compressedAddress.toLowerCase():y.toLowerCase(),U=A=>A===null?"null":typeof A!="object"?typeof A:A.constructor.name;console.log("types",JSON.stringify({value:U(d),minInput:U(e),sliceIfMore6:U(n),shieldedPrivateKey:U(f),modifiedErc20TokenAddress:U(B),tokenId:U(T),mintAddress:U(v)})),console.log("started padding"),W(d,e,n,f,B,T,v),console.log("done padding")}return console.log("getInputUtxoAndBalancePerToken 6"),x};exports.attemptGetInputUtxosRemotely=S;exports.getInputUtxoAndBalance=C;exports.getInputUtxoAndBalanceOfStuckUtxos=N;exports.getInputUtxoAndBalancePerToken=z;exports.getInputUtxosRemotely=q;
@@ -1,25 +1,25 @@
1
1
  import { Utxo as S } from "../../../data-structures/utxo/Utxo.mjs";
2
- import { checkChainOrAddressNotUpdated as E } from "../../utils/upToDateState.mjs";
3
- import { setHinkalCache as b, resetCache as L, getHinkalCache as K } from "../../utils/cacheFunctions.mjs";
2
+ import { checkChainOrAddressNotUpdated as h } from "../../utils/upToDateState.mjs";
3
+ import { setHinkalCache as C, 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 C } from "../../utils/encodeTokenWithId.mjs";
5
+ import { encodeTokenWithId as P } 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 k = async (t, o, e, n, r, c, l, a, s) => {
12
+ const b = async (t, o, e, n, r, c, l, a, s) => {
13
13
  s += 1;
14
- const u = c.slice(s), { lastOutput: A, additionalEncryptedOutputs: m } = await t.utxoUtils.batchProcess(
14
+ const u = c.slice(s), { lastOutput: I, additionalEncryptedOutputs: A } = await t.utxoUtils.batchProcess(
15
15
  u,
16
16
  a,
17
17
  o,
18
18
  e
19
- ), i = [...l, ...m];
20
- return await E(t, e, n), b(
19
+ ), i = [...l, ...A];
20
+ return await h(t, e, n), C(
21
21
  {
22
- lastOutput: A,
22
+ lastOutput: I,
23
23
  encryptedOutputs: i
24
24
  },
25
25
  t,
@@ -32,7 +32,7 @@ const k = 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 b(
35
+ return C(
36
36
  {
37
37
  encryptedOutputs: c,
38
38
  lastOutput: l
@@ -45,7 +45,7 @@ const k = 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 k(
48
+ return b(
49
49
  t,
50
50
  o,
51
51
  e,
@@ -70,7 +70,7 @@ const k = 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
- }, N = async ({
73
+ }, k = async ({
74
74
  hinkal: t,
75
75
  chainId: o = void 0,
76
76
  passedShieldedPublicKey: e = void 0,
@@ -81,23 +81,23 @@ const k = 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: A, nullifiers: m, userKeys: i } = t, p = Array.from(A);
85
- console.log("getInputUtxoAndBalance 1", { encryptedOutputs: A }), r && L(t, s, u);
84
+ const a = n ?? await t.getEthereumAddress(), s = o ?? t.getCurrentChainId(), u = e ?? t.userKeys.getShieldedPublicKey(), { encryptedOutputs: I, nullifiers: A, userKeys: i } = t, p = Array.from(I);
85
+ console.log("getInputUtxoAndBalance 1"), 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 E(t, s, a), console.log("getInputUtxoAndBalance 3");
92
- const g = f !== "", d = p.findIndex((h) => h.value === f);
91
+ console.log("getInputUtxoAndBalance 2"), await h(t, s, a), console.log("getInputUtxoAndBalance 3");
92
+ const g = f !== "", d = p.findIndex((O) => O.value === f);
93
93
  console.log("getInputUtxoAndBalance 4");
94
- const y = d > -1, w = !g && d === -1;
94
+ const m = d > -1, w = !g && d === -1;
95
95
  console.log("getInputUtxoAndBalance 5");
96
- const I = t.areMerkleTreeUpdatesDisabled();
96
+ const y = t.areMerkleTreeUpdatesDisabled();
97
97
  console.log("getInputUtxoAndBalance 6");
98
- const B = !I && (y || !c && w), T = !I && c && w, U = !B && !T;
99
- let x = [];
100
- B ? x = await k(
98
+ const B = !y && (m || !c && w), T = !y && c && w, x = !B && !T;
99
+ let U = [];
100
+ B ? U = await b(
101
101
  t,
102
102
  i,
103
103
  s,
@@ -107,7 +107,7 @@ const k = async (t, o, e, n, r, c, l, a, s) => {
107
107
  v,
108
108
  f,
109
109
  d
110
- ) : T ? x = await z(
110
+ ) : T ? U = await z(
111
111
  t,
112
112
  i,
113
113
  s,
@@ -117,11 +117,11 @@ const k = async (t, o, e, n, r, c, l, a, s) => {
117
117
  v,
118
118
  f,
119
119
  d
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 };
120
+ ) : x && (U = await t.utxoUtils.buildBatchProcess(v, i, s)), console.log("getInputUtxoAndBalance 7"), await h(t, s, a);
121
+ const E = await Q(t, U, A);
122
+ console.log("getInputUtxoAndBalance 8");
123
+ const N = l ? E : E.filter((O) => !O.isBlocked);
124
+ return console.log("getInputUtxoAndBalance 9"), console.trace(), { inputUtxos: N };
125
125
  }, X = async ({
126
126
  hinkal: t,
127
127
  chainId: o = void 0,
@@ -130,7 +130,7 @@ const k = 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 N({
133
+ const l = o ?? t.getCurrentChainId(), a = n ?? await t.getEthereumAddress(), s = q(a), { inputUtxos: u } = await k({
134
134
  hinkal: t,
135
135
  chainId: l,
136
136
  passedShieldedPublicKey: e,
@@ -141,11 +141,11 @@ const k = async (t, o, e, n, r, c, l, a, s) => {
141
141
  });
142
142
  if (!u.length)
143
143
  return { inputUtxos: [] };
144
- const A = u.map((p) => p.getNullifier()), { indexes: m } = await G(l, {
144
+ const I = u.map((p) => p.getNullifier()), { indexes: A } = await G(l, {
145
145
  hashedEthereumAddress: s,
146
- nullifiers: A
146
+ nullifiers: I
147
147
  });
148
- return { inputUtxos: m.map((p) => u[p]).filter((p) => !!p) };
148
+ return { inputUtxos: A.map((p) => u[p]).filter((p) => !!p) };
149
149
  }, ct = async ({
150
150
  hinkal: t,
151
151
  tokenWithId: o,
@@ -157,17 +157,17 @@ const k = 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: A = !1
160
+ useBlockedUtxos: I = !1
161
161
  }) => {
162
- const m = c ?? t.userKeys.getShieldedPrivateKey(), i = r ?? t.getCurrentChainId();
162
+ const A = c ?? t.userKeys.getShieldedPrivateKey(), i = r ?? t.getCurrentChainId();
163
163
  console.log("getInputUtxoAndBalancePerToken 1");
164
- const { inputUtxos: p } = A ? await X({
164
+ const { inputUtxos: p } = I ? await X({
165
165
  hinkal: t,
166
166
  chainId: r,
167
167
  ethAddress: a,
168
168
  passedShieldedPrivateKey: c,
169
169
  resetCacheBefore: s
170
- }) : await N({
170
+ }) : await k({
171
171
  hinkal: t,
172
172
  tokenWithId: o,
173
173
  minInput: e,
@@ -183,38 +183,38 @@ const k = 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
- (I) => R(I.erc20TokenAddress, d) && I.tokenId === g.tokenId
186
+ (y) => R(y.erc20TokenAddress, d) && y.tokenId === g.tokenId
187
187
  ))
188
188
  return;
189
- const y = C(i, { erc20TokenAddress: d, tokenId: g.tokenId }), w = f.get(y) ?? [];
190
- f.set(y, [...w, g]);
189
+ const m = P(i, { erc20TokenAddress: d, tokenId: g.tokenId }), w = f.get(m) ?? [];
190
+ f.set(m, [...w, g]);
191
191
  }), console.log("getInputUtxoAndBalancePerToken 4"), u?.forEach((g) => {
192
- const d = C(i, {
192
+ const d = P(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 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;
199
+ const m = g.split("-")[0], w = Number(g.split("-")[1]), y = j(i), B = y ? m : void 0, T = y ? M(m).compressedAddress.toLowerCase() : m.toLowerCase(), x = (U) => U === null ? "null" : typeof U != "object" ? typeof U : U.constructor.name;
200
200
  console.log(
201
201
  "types",
202
202
  JSON.stringify({
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)
203
+ value: x(d),
204
+ minInput: x(e),
205
+ sliceIfMore6: x(n),
206
+ shieldedPrivateKey: x(A),
207
+ modifiedErc20TokenAddress: x(T),
208
+ tokenId: x(w),
209
+ mintAddress: x(B)
210
210
  })
211
- ), console.log("started padding"), V(d, e, n, m, T, w, B), console.log("done padding");
211
+ ), console.log("started padding"), V(d, e, n, A, 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
- N as getInputUtxoAndBalance,
217
+ k as getInputUtxoAndBalance,
218
218
  X as getInputUtxoAndBalanceOfStuckUtxos,
219
219
  ct as getInputUtxoAndBalancePerToken,
220
220
  J as getInputUtxosRemotely
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "h_test_1",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "homepage": "hinkal.io",
5
5
  "author": {
6
6
  "name": "Hinkal Protocol"