@hinkal/common 0.1.37 → 0.1.39

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 c=require("../../types/hinkal.types.cjs"),h=require("../../types/ethereum-network.types.cjs"),a=require("../../functions/web3/functionCalls/accessTokenCalls.cjs"),A=require("../../functions/web3/events/getShieldedBalance.cjs"),o=require("../crypto-keys/keys.cjs"),y=require("./hinkalActionBeefy.cjs"),C=require("./hinkalActionConvex.cjs"),P=require("./hinkalActionCurve.cjs"),w=require("./hinkalActionPendle.cjs"),d=require("./hinkalDeposit.cjs"),m=require("./hinkalSwap.cjs"),T=require("./hinkalWithdraw.cjs"),S=require("./resetMerkleTrees.cjs"),l=require("../merkle-tree/MerkleTree.cjs"),u=require("../../crypto/poseidon.cjs");require("circomlibjs");const q=require("../../constants/chains.constants.cjs"),g=require("../../error-handling/error-codes.constants.cjs"),f=require("../../API/callMonitor.cjs"),E=require("./hinkalActionLidoEth.cjs");require("../../constants/vite.constants.cjs");require("axios");require("../../constants/coingecko.constants.cjs");const F=require("../../API/getAxelarGasEstimate.cjs"),p=require("../../API/API.cjs");require("ethers");require("../../types/curve.types.cjs");require("../../constants/contracts.constants.cjs");const H=require("../../constants/kyc.constants.cjs");require("../../constants/axelar.constants.cjs");require("../../constants/rewards.constants.cjs");require("../../constants/reorg-depths.constants.cjs");const I=require("../transactions-manager/TransactionsManager.cjs");require("../../functions/utils/external-action.utils.cjs");require("../../types/circom-data.types.cjs");require("../../types/transactions.types.cjs");const M=require("../../functions/utils/reloadPage.cjs"),R=require("./hinkalActionVolatile.cjs"),k=require("./hinkalActionPendleLP.cjs"),L=require("../../API/getConnextReceiveFee.cjs"),W=require("./hinkalActionStake.cjs"),K=require("../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.cjs"),N=require("./hinkalPrivateWallet.cjs");class x{providerAdapter;userKeys;signingMessage="Login to Hinkal Protocol";merkleTreeHinkal;merkleTreeAccessToken;nullifiers;encryptedOutputs;commitmentsSnapshotService;nullifierSnapshotService;accessTokenSnapshotService;transactionsManager;utxoUtils=K.multiThreadedUtxoUtils;constructor(){this.userKeys=new o.UserKeys(void 0),this.merkleTreeHinkal=l.MerkleTree.create(u.poseidonFunction,25n,0n),this.merkleTreeAccessToken=l.MerkleTree.create(u.poseidonFunction,25n,0n),this.nullifiers=new Set,this.encryptedOutputs=[],this.transactionsManager=new I.TransactionsManager}async initProviderAdapter(e,t){await this.updateProviderAdapter(t),this.providerAdapter?.initConnector(e);const r=await this.connectAndPatchProvider(e);await t.init(r),await this.setListeners()}async initUserKeys(){this.userKeys=new o.UserKeys(await this.getProviderAdapter().signMessage(this.signingMessage))}async initUserKeysWithPassword(e){this.userKeys=new o.UserKeys(e)}async resetMerkle(){this.isSelectedNetworkSupported()&&await S.resetMerkleTrees(this)}getProviderAdapter(){if(!this.providerAdapter)throw new Error("ProviderAdapter is not initialized");return this.providerAdapter}async waitForTransaction(e,t=1){return!!await this.providerAdapter?.waitForTransaction(e,t)}getContractMetadata(e,t){return this.getProviderAdapter().getContractMetadata(e,t)}getContract(e,t=void 0,r){return this.getProviderAdapter().getContract(e,t,r)}async signMessage(e){return await this.getProviderAdapter().signMessage(e)}async signTypedData(e,t,r){return await this.getProviderAdapter().signTypedData(e,t,r)}getContractWithSigner(e,t=""){return this.getProviderAdapter().getContractWithSigner(e,t)}getContractWithFetcher(e,t=""){return this.getProviderAdapter().getContractWithFetcher(e,t)}getContractWithFetcherForEthereum(e,t){return this.getProviderAdapter().getContractWithFetcherForEthereum(e,t)}isSelectedNetworkSupported(){return!!q.networkRegistry[this.getCurrentChainId()]}async switchNetwork(e){try{await this.getProviderAdapter().switchNetwork(e)}catch{throw new Error(g.transactionErrorCodes.FAILED_TO_SWITCH_NETWORKS)}}getCurrentChainId(){const{chainId:e}=this.getProviderAdapter();if(!e)throw new Error("Illegal State: no chainId");return e}getSelectedNetwork(){return this.providerAdapter?.getSelectedNetwork()}isPermitterAvailable(){return this.getProviderAdapter().isPermitterAvailable()}async connectAndPatchProvider(e){return await this.getProviderAdapter().connectAndPatchProvider(e)}async disconnectFromConnector(){await this.getProviderAdapter().disconnectFromConnector()}async updateProviderAdapter(e){try{this.providerAdapter&&this.providerAdapter.release(),this.providerAdapter=e}catch(t){throw console.error(t),Error("updateProviderAdapter failed, please try again.")}}async setListeners(){this.providerAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}})}async onAccountChanged(){await this.getProviderAdapter().onAccountChanged();const e=c.EventType.AccountChanged;typeof document<"u"?document?.dispatchEvent(new Event(e)):process?.emit("message",e,void 0)}async onChainChanged(e){if(e){await this.getProviderAdapter().onChainChanged(e);const t=c.EventType.NetworkChange;typeof document<"u"?document.dispatchEvent(new Event(t)):process?.emit("message",t,void 0)}else await this.disconnectFromConnector(),M.reloadPage()}async monitorConnectedAddress(){f.monitor(await this.getEthereumAddress(),this.getCurrentChainId())}async getBalances(){return A.getShieldedBalance(this)}getSupportedPassportLinks(){return H.supportedPassportLinks}checkAccessToken(){return a.checkHinkalAccessToken(this)}async getAxelarEstimate(e,t,r,n){return F.getAxelarGasEstimate(e,t,r,n,this.userKeys.getAccessKey())}async getConnextReceiveFee(e,t){return L.getConnextReceiveFee(this.getCurrentChainId(),e,t)}async mintHinkalAccessToken(e){return a.mintAccessToken(this,e)}async mintHinkalAccessTokenCrossChain(e,t){return a.mintTokenCrossChain(this,e,t)}async getHinkalTreeRootHash(){return this.getContractWithFetcher(h.ContractType.HinkalContract).getRootHash()}async getAccessTokenTreeRootHash(){return this.getContractWithFetcher(h.ContractType.CrossChainAccessTokenContract).getRootHash()}async resetMerkleTreesIfNecessary(){if(!this.isSelectedNetworkSupported())throw new Error(g.transactionErrorCodes.UNSUPPORTED_NETWORK);const[e,t]=await Promise.all([this.getHinkalTreeRootHash(),this.getAccessTokenTreeRootHash()]);(e.toBigInt()!==this.merkleTreeHinkal.getRootHash()||t.toBigInt()!==this.merkleTreeAccessToken.getRootHash())&&await this.resetMerkle()}async getEventsFromHinkal(){await Promise.all([this.accessTokenSnapshotService?.retrieveEventsFromLatestBlock(),this.commitmentsSnapshotService?.retrieveEventsFromLatestBlock(),this.nullifierSnapshotService?.retrieveEventsFromLatestBlock()])}getEthereumAddress(){return this.getProviderAdapter().getAddress()}async getRandomRelay(){return(await p.API.getIdleRelay(this.getCurrentChainId())).relay}getGasPrice(){if(!this.providerAdapter?.chainId)throw new Error("Illegal State of providerAdapter in Hinkal: no chainId");return this.providerAdapter.getGasPrice()}getAPI(){return p.API}snapshotsClearInterval(){this.commitmentsSnapshotService?.intervalClear(),this.accessTokenSnapshotService?.intervalClear(),this.nullifierSnapshotService?.intervalClear()}async deposit(e,t){return d.hinkalDeposit(this,e,t)}async depositForOther(e,t,r){return d.hinkalDepositForOther(this,e,t,r)}async withdraw(e,t,r,n,i=!1){return T.hinkalWithdraw(this,e,t,r,n,i)}async swap(e,t,r,n,i=!1,s=!1){return m.hinkalSwap(this,e,t,r,n,i,s)}async actionCurve(e,t,r,n,i,s=!1){return P.hinkalActionCurve(this,e,t,r,n,i,s)}async actionConvex(e,t,r,n,i=!1){return C.hinkalActionConvex(this,e,t,r,n,i)}async actionBeefy(e,t,r,n,i,s,v=!1){return y.hinkalActionBeefy(this,e,t,r,n,i,s,v)}async actionLido(e,t,r,n,i,s=!1){return E.hinkalActionLido(this,e,t,r,n,i,s)}async actionPendle(e,t,r,n,i=!1){return w.hinkalActionPendle(this,e,t,r,n,i)}async actionPendleLP(e,t,r,n,i=!1){return k.hinkalActionPendleLP(this,e,t,r,n,i)}async actionVolatile(e,t,r,n=!1){return R.hinkalActionVolatile(this,e,t,r,n)}async actionStake(e,t,r,n){return W.hinkalActionStake(this,e,t,r,n)}async actionPrivateWallet(e,t,r,n=[],i,s=!1){return N.hinkalPrivateWallet(this,e,t,r,n,i,s)}async getPendleLPClaimableParams(e,t){return k.hinkalGetPendleLPClaimableParams(this,e,t)}}exports.Hinkal=x;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../../types/hinkal.types.cjs"),h=require("../../types/ethereum-network.types.cjs"),a=require("../../functions/web3/functionCalls/accessTokenCalls.cjs"),A=require("../../functions/web3/events/getShieldedBalance.cjs"),o=require("../crypto-keys/keys.cjs"),y=require("./hinkalActionBeefy.cjs"),C=require("./hinkalActionConvex.cjs"),P=require("./hinkalActionCurve.cjs"),w=require("./hinkalActionPendle.cjs"),d=require("./hinkalDeposit.cjs"),m=require("./hinkalSwap.cjs"),T=require("./hinkalWithdraw.cjs"),S=require("./resetMerkleTrees.cjs"),l=require("../merkle-tree/MerkleTree.cjs"),u=require("../../crypto/poseidon.cjs");require("circomlibjs");const q=require("../../constants/chains.constants.cjs"),g=require("../../error-handling/error-codes.constants.cjs"),f=require("../../API/callMonitor.cjs"),E=require("./hinkalActionLidoEth.cjs");require("../../constants/vite.constants.cjs");require("axios");require("../../constants/coingecko.constants.cjs");const M=require("../../API/getAxelarGasEstimate.cjs"),p=require("../../API/API.cjs");require("ethers");require("../../types/curve.types.cjs");require("../../constants/contracts.constants.cjs");const F=require("../../constants/kyc.constants.cjs");require("../../constants/axelar.constants.cjs");require("../../constants/rewards.constants.cjs");require("../../constants/reorg-depths.constants.cjs");const H=require("../transactions-manager/TransactionsManager.cjs");require("../../functions/utils/external-action.utils.cjs");require("../../types/circom-data.types.cjs");require("../../types/transactions.types.cjs");const I=require("../../functions/utils/reloadPage.cjs"),R=require("./hinkalActionVolatile.cjs"),k=require("./hinkalActionPendleLP.cjs"),L=require("../../API/getConnextReceiveFee.cjs"),W=require("./hinkalActionStake.cjs"),x=require("../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.cjs"),K=require("./hinkalPrivateWallet.cjs");class N{providerAdapter;userKeys;signingMessage="Login to Hinkal Protocol";merkleTreeHinkal;merkleTreeAccessToken;nullifiers;encryptedOutputs;commitmentsSnapshotService;nullifierSnapshotService;accessTokenSnapshotService;transactionsManager;utxoUtils;inMemoryCache;constructor(){this.userKeys=new o.UserKeys(void 0),this.merkleTreeHinkal=l.MerkleTree.create(u.poseidonFunction,25n,0n),this.merkleTreeAccessToken=l.MerkleTree.create(u.poseidonFunction,25n,0n),this.nullifiers=new Set,this.encryptedOutputs=[],this.transactionsManager=new H.TransactionsManager,this.utxoUtils=new x.MultiThreadedUtxoUtils,this.inMemoryCache=new Map}async initProviderAdapter(e,t){await this.updateProviderAdapter(t),this.providerAdapter?.initConnector(e);const r=await this.connectAndPatchProvider(e);await t.init(r),await this.setListeners()}async initUserKeys(){this.userKeys=new o.UserKeys(await this.getProviderAdapter().signMessage(this.signingMessage))}async initUserKeysWithPassword(e){this.userKeys=new o.UserKeys(e)}async resetMerkle(){this.isSelectedNetworkSupported()&&await S.resetMerkleTrees(this)}getProviderAdapter(){if(!this.providerAdapter)throw new Error("ProviderAdapter is not initialized");return this.providerAdapter}async waitForTransaction(e,t=1){return!!await this.providerAdapter?.waitForTransaction(e,t)}getContractMetadata(e,t){return this.getProviderAdapter().getContractMetadata(e,t)}getContract(e,t=void 0,r){return this.getProviderAdapter().getContract(e,t,r)}async signMessage(e){return await this.getProviderAdapter().signMessage(e)}async signTypedData(e,t,r){return await this.getProviderAdapter().signTypedData(e,t,r)}getContractWithSigner(e,t=""){return this.getProviderAdapter().getContractWithSigner(e,t)}getContractWithFetcher(e,t=""){return this.getProviderAdapter().getContractWithFetcher(e,t)}getContractWithFetcherForEthereum(e,t){return this.getProviderAdapter().getContractWithFetcherForEthereum(e,t)}isSelectedNetworkSupported(){return!!q.networkRegistry[this.getCurrentChainId()]}async switchNetwork(e){try{await this.getProviderAdapter().switchNetwork(e)}catch{throw new Error(g.transactionErrorCodes.FAILED_TO_SWITCH_NETWORKS)}}getCurrentChainId(){const{chainId:e}=this.getProviderAdapter();if(!e)throw new Error("Illegal State: no chainId");return e}getSelectedNetwork(){return this.providerAdapter?.getSelectedNetwork()}isPermitterAvailable(){return this.getProviderAdapter().isPermitterAvailable()}async connectAndPatchProvider(e){return await this.getProviderAdapter().connectAndPatchProvider(e)}async disconnectFromConnector(){await this.getProviderAdapter().disconnectFromConnector()}async updateProviderAdapter(e){try{this.providerAdapter&&this.providerAdapter.release(),this.providerAdapter=e}catch(t){throw console.error(t),Error("updateProviderAdapter failed, please try again.")}}async setListeners(){this.providerAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}})}async onAccountChanged(){await this.getProviderAdapter().onAccountChanged();const e=c.EventType.AccountChanged;typeof document<"u"?document?.dispatchEvent(new Event(e)):process?.emit("message",e,void 0)}async onChainChanged(e){if(e){await this.getProviderAdapter().onChainChanged(e);const t=c.EventType.NetworkChange;typeof document<"u"?document.dispatchEvent(new Event(t)):process?.emit("message",t,void 0)}else await this.disconnectFromConnector(),I.reloadPage()}async monitorConnectedAddress(){f.monitor(await this.getEthereumAddress(),this.getCurrentChainId())}async getBalances(){return A.getShieldedBalance(this)}getSupportedPassportLinks(){return F.supportedPassportLinks}checkAccessToken(){return a.checkHinkalAccessToken(this)}async getAxelarEstimate(e,t,r,n){return M.getAxelarGasEstimate(e,t,r,n,this.userKeys.getAccessKey())}async getConnextReceiveFee(e,t){return L.getConnextReceiveFee(this.getCurrentChainId(),e,t)}async mintHinkalAccessToken(e){return a.mintAccessToken(this,e)}async mintHinkalAccessTokenCrossChain(e,t){return a.mintTokenCrossChain(this,e,t)}async getHinkalTreeRootHash(){return this.getContractWithFetcher(h.ContractType.HinkalContract).getRootHash()}async getAccessTokenTreeRootHash(){return this.getContractWithFetcher(h.ContractType.CrossChainAccessTokenContract).getRootHash()}async resetMerkleTreesIfNecessary(){if(!this.isSelectedNetworkSupported())throw new Error(g.transactionErrorCodes.UNSUPPORTED_NETWORK);const[e,t]=await Promise.all([this.getHinkalTreeRootHash(),this.getAccessTokenTreeRootHash()]);(e.toBigInt()!==this.merkleTreeHinkal.getRootHash()||t.toBigInt()!==this.merkleTreeAccessToken.getRootHash())&&await this.resetMerkle()}async getEventsFromHinkal(){await Promise.all([this.accessTokenSnapshotService?.retrieveEventsFromLatestBlock(),this.commitmentsSnapshotService?.retrieveEventsFromLatestBlock(),this.nullifierSnapshotService?.retrieveEventsFromLatestBlock()])}getEthereumAddress(){return this.getProviderAdapter().getAddress()}async getRandomRelay(){return(await p.API.getIdleRelay(this.getCurrentChainId())).relay}getGasPrice(){if(!this.providerAdapter?.chainId)throw new Error("Illegal State of providerAdapter in Hinkal: no chainId");return this.providerAdapter.getGasPrice()}getAPI(){return p.API}snapshotsClearInterval(){this.commitmentsSnapshotService?.intervalClear(),this.accessTokenSnapshotService?.intervalClear(),this.nullifierSnapshotService?.intervalClear()}async deposit(e,t){return d.hinkalDeposit(this,e,t)}async depositForOther(e,t,r){return d.hinkalDepositForOther(this,e,t,r)}async withdraw(e,t,r,n,i=!1){return T.hinkalWithdraw(this,e,t,r,n,i)}async swap(e,t,r,n,i=!1,s=!1){return m.hinkalSwap(this,e,t,r,n,i,s)}async actionCurve(e,t,r,n,i,s=!1){return P.hinkalActionCurve(this,e,t,r,n,i,s)}async actionConvex(e,t,r,n,i=!1){return C.hinkalActionConvex(this,e,t,r,n,i)}async actionBeefy(e,t,r,n,i,s,v=!1){return y.hinkalActionBeefy(this,e,t,r,n,i,s,v)}async actionLido(e,t,r,n,i,s=!1){return E.hinkalActionLido(this,e,t,r,n,i,s)}async actionPendle(e,t,r,n,i=!1){return w.hinkalActionPendle(this,e,t,r,n,i)}async actionPendleLP(e,t,r,n,i=!1){return k.hinkalActionPendleLP(this,e,t,r,n,i)}async actionVolatile(e,t,r,n=!1){return R.hinkalActionVolatile(this,e,t,r,n)}async actionStake(e,t,r,n){return W.hinkalActionStake(this,e,t,r,n)}async actionPrivateWallet(e,t,r,n=[],i,s=!1){return K.hinkalPrivateWallet(this,e,t,r,n,i,s)}async getPendleLPClaimableParams(e,t){return k.hinkalGetPendleLPClaimableParams(this,e,t)}}exports.Hinkal=N;
@@ -32,6 +32,7 @@ export declare class Hinkal<ConnectorType> implements IHinkal {
32
32
  accessTokenSnapshotService?: ClientAccessTokenSnapshotService;
33
33
  transactionsManager: TransactionsManager;
34
34
  utxoUtils: IMultiThreadedUtxoUtils;
35
+ inMemoryCache: Map<string, string>;
35
36
  constructor();
36
37
  initProviderAdapter(connector: ConnectorType, providerAdapter: IProviderAdapter<ConnectorType>): Promise<void>;
37
38
  initUserKeys(): Promise<void>;
@@ -21,27 +21,27 @@ import { hinkalActionLido as I } from "./hinkalActionLidoEth.mjs";
21
21
  import "../../constants/vite.constants.mjs";
22
22
  import "axios";
23
23
  import "../../constants/coingecko.constants.mjs";
24
- import { getAxelarGasEstimate as R } from "../../API/getAxelarGasEstimate.mjs";
24
+ import { getAxelarGasEstimate as M } from "../../API/getAxelarGasEstimate.mjs";
25
25
  import { API as l } from "../../API/API.mjs";
26
26
  import "ethers";
27
27
  import "../../types/curve.types.mjs";
28
28
  import "../../constants/contracts.constants.mjs";
29
- import { supportedPassportLinks as L } from "../../constants/kyc.constants.mjs";
29
+ import { supportedPassportLinks as R } from "../../constants/kyc.constants.mjs";
30
30
  import "../../constants/axelar.constants.mjs";
31
31
  import "../../constants/rewards.constants.mjs";
32
32
  import "../../constants/reorg-depths.constants.mjs";
33
- import { TransactionsManager as M } from "../transactions-manager/TransactionsManager.mjs";
33
+ import { TransactionsManager as L } from "../transactions-manager/TransactionsManager.mjs";
34
34
  import "../../functions/utils/external-action.utils.mjs";
35
35
  import "../../types/circom-data.types.mjs";
36
36
  import "../../types/transactions.types.mjs";
37
37
  import { reloadPage as W } from "../../functions/utils/reloadPage.mjs";
38
38
  import { hinkalActionVolatile as N } from "./hinkalActionVolatile.mjs";
39
- import { hinkalActionPendleLP as K, hinkalGetPendleLPClaimableParams as O } from "./hinkalActionPendleLP.mjs";
40
- import { getConnextReceiveFee as x } from "../../API/getConnextReceiveFee.mjs";
39
+ import { hinkalActionPendleLP as K, hinkalGetPendleLPClaimableParams as x } from "./hinkalActionPendleLP.mjs";
40
+ import { getConnextReceiveFee as O } from "../../API/getConnextReceiveFee.mjs";
41
41
  import { hinkalActionStake as B } from "./hinkalActionStake.mjs";
42
- import { multiThreadedUtxoUtils as U } from "../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.mjs";
42
+ import { MultiThreadedUtxoUtils as U } from "../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.mjs";
43
43
  import { hinkalPrivateWallet as b } from "./hinkalPrivateWallet.mjs";
44
- class Le {
44
+ class Re {
45
45
  providerAdapter;
46
46
  userKeys;
47
47
  signingMessage = "Login to Hinkal Protocol";
@@ -53,9 +53,10 @@ class Le {
53
53
  nullifierSnapshotService;
54
54
  accessTokenSnapshotService;
55
55
  transactionsManager;
56
- utxoUtils = U;
56
+ utxoUtils;
57
+ inMemoryCache;
57
58
  constructor() {
58
- this.userKeys = new s(void 0), this.merkleTreeHinkal = h.create(d, 25n, 0n), this.merkleTreeAccessToken = h.create(d, 25n, 0n), this.nullifiers = /* @__PURE__ */ new Set(), this.encryptedOutputs = [], this.transactionsManager = new M();
59
+ this.userKeys = new s(void 0), this.merkleTreeHinkal = h.create(d, 25n, 0n), this.merkleTreeAccessToken = h.create(d, 25n, 0n), this.nullifiers = /* @__PURE__ */ new Set(), this.encryptedOutputs = [], this.transactionsManager = new L(), this.utxoUtils = new U(), this.inMemoryCache = /* @__PURE__ */ new Map();
59
60
  }
60
61
  async initProviderAdapter(e, t) {
61
62
  await this.updateProviderAdapter(t), this.providerAdapter?.initConnector(e);
@@ -165,13 +166,13 @@ class Le {
165
166
  return k(this);
166
167
  }
167
168
  getSupportedPassportLinks() {
168
- return L;
169
+ return R;
169
170
  }
170
171
  checkAccessToken() {
171
172
  return g(this);
172
173
  }
173
174
  async getAxelarEstimate(e, t, r, i) {
174
- return R(
175
+ return M(
175
176
  e,
176
177
  t,
177
178
  r,
@@ -180,7 +181,7 @@ class Le {
180
181
  );
181
182
  }
182
183
  async getConnextReceiveFee(e, t) {
183
- return x(this.getCurrentChainId(), e, t);
184
+ return O(this.getCurrentChainId(), e, t);
184
185
  }
185
186
  async mintHinkalAccessToken(e) {
186
187
  return u(this, e);
@@ -294,9 +295,9 @@ class Le {
294
295
  return b(this, e, t, r, i, n, a);
295
296
  }
296
297
  async getPendleLPClaimableParams(e, t) {
297
- return O(this, e, t);
298
+ return x(this, e, t);
298
299
  }
299
300
  }
300
301
  export {
301
- Le as Hinkal
302
+ Re as Hinkal
302
303
  };
@@ -31,6 +31,7 @@ export interface IHinkal<ConnectorType = unknown> {
31
31
  nullifierSnapshotService?: ClientNullifierSnapshotService;
32
32
  accessTokenSnapshotService?: ClientAccessTokenSnapshotService;
33
33
  transactionsManager: TransactionsManager;
34
+ inMemoryCache: Map<string, string>;
34
35
  getBalances(): Promise<TokenBalance[]>;
35
36
  getSupportedPassportLinks(): string[];
36
37
  checkAccessToken(): Promise<boolean>;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("../utxo/Utxo.cjs"),u=require("../../webworker/utxoWorker/utxoWorker.types.cjs"),d=require("../../webworker/performTaskWithWorker.cjs"),y=require("../../webworker/worker.registry.cjs"),m=require("../../constants/vite.constants.cjs");class U{NUM_WORKERS;NUM_WORKERS_BATCH_PROCESS;constructor(){m.isNode?(this.NUM_WORKERS=1,this.NUM_WORKERS_BATCH_PROCESS=1):(this.NUM_WORKERS=3,this.NUM_WORKERS_BATCH_PROCESS=Math.ceil(navigator.deviceMemory??4))}async createUtxoPromise(e){return await d.performTaskWithWorker({type:y.WorkerVariant.UTXO,payload:e})}async batchFilterUtxosWithNullifier(e,s){const i=this.sliceArrayIntoParts(e,this.NUM_WORKERS).map(t=>this.createUtxoPromise({type:u.UtxoWorkerActionType.BATCH_FILTER_UTXOS_WITH_NULLIFIER,data:{utxos:t.map(r=>r.getConstructableParams()),nullifiers:s}}));return(await Promise.all(i)).flat().map(t=>new p.Utxo(t))}async buildBatchProcess(e,s){const i=this.sliceArrayIntoParts(e,this.NUM_WORKERS).map(r=>this.createUtxoPromise({type:u.UtxoWorkerActionType.BUILD_UTXOS,data:{signature:s.getSignature(),encryptedOutputs:r}}));return(await Promise.all(i)).flat().map(r=>new p.Utxo(r))}sliceArrayIntoParts(e,s){const o=Math.ceil(e.length/s);return Array.from({length:s},(c,t)=>e.slice(o*t,o*(t+1)))}async batchProcess(e,s,o){const c=this.sliceArrayIntoParts(e,this.NUM_WORKERS_BATCH_PROCESS).map(a=>{const n={type:u.UtxoWorkerActionType.DECIPHER_OUTPUTS,data:{encryptedOutputs:a,lastOutput:s,signature:o.getSignature()}};return this.createUtxoPromise(n)}),t=await Promise.all(c),r=t.map(({additionalEncryptedOutputs:a})=>a).flat(),l=new Set,h=r.reduce((a,n)=>l.has(n.value)?a:(l.add(n.value),[...a,n]),[]),R=t.length?t[t.length-1]?.lastOutput:void 0;return{additionalEncryptedOutputs:h,lastOutput:R??s}}}const S=new U;exports.MultiThreadedUtxoUtils=U;exports.multiThreadedUtxoUtils=S;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("../utxo/Utxo.cjs"),u=require("../../webworker/utxoWorker/utxoWorker.types.cjs"),U=require("../../webworker/performTaskWithWorker.cjs"),y=require("../../webworker/worker.registry.cjs"),d=require("../../constants/vite.constants.cjs");class S{NUM_WORKERS;NUM_WORKERS_BATCH_PROCESS;constructor(){d.isNode?(this.NUM_WORKERS=1,this.NUM_WORKERS_BATCH_PROCESS=1):(this.NUM_WORKERS=3,this.NUM_WORKERS_BATCH_PROCESS=Math.ceil(navigator.deviceMemory??4))}async createUtxoPromise(e){return await U.performTaskWithWorker({type:y.WorkerVariant.UTXO,payload:e})}async batchFilterUtxosWithNullifier(e,s){const i=this.sliceArrayIntoParts(e,this.NUM_WORKERS).map(t=>this.createUtxoPromise({type:u.UtxoWorkerActionType.BATCH_FILTER_UTXOS_WITH_NULLIFIER,data:{utxos:t.map(r=>r.getConstructableParams()),nullifiers:s}}));return(await Promise.all(i)).flat().map(t=>new p.Utxo(t))}async buildBatchProcess(e,s){const i=this.sliceArrayIntoParts(e,this.NUM_WORKERS).map(r=>this.createUtxoPromise({type:u.UtxoWorkerActionType.BUILD_UTXOS,data:{signature:s.getSignature(),encryptedOutputs:r}}));return(await Promise.all(i)).flat().map(r=>new p.Utxo(r))}sliceArrayIntoParts(e,s){const o=Math.ceil(e.length/s);return Array.from({length:s},(c,t)=>e.slice(o*t,o*(t+1)))}async batchProcess(e,s,o){const c=this.sliceArrayIntoParts(e,this.NUM_WORKERS_BATCH_PROCESS).map(a=>{const n={type:u.UtxoWorkerActionType.DECIPHER_OUTPUTS,data:{encryptedOutputs:a,lastOutput:s,signature:o.getSignature()}};return this.createUtxoPromise(n)}),t=await Promise.all(c),r=t.map(({additionalEncryptedOutputs:a})=>a).flat(),l=new Set,R=r.reduce((a,n)=>l.has(n.value)?a:(l.add(n.value),[...a,n]),[]),h=t.length?t[t.length-1]?.lastOutput:void 0;return{additionalEncryptedOutputs:R,lastOutput:h??s}}}exports.MultiThreadedUtxoUtils=S;
@@ -17,4 +17,3 @@ export declare class MultiThreadedUtxoUtils implements IMultiThreadedUtxoUtils {
17
17
  sliceArrayIntoParts<T>(arr: T[], numberOfParts: number): T[][];
18
18
  batchProcess(encryptedOutputs: EncryptedOutputWithSign[], lastOutput: string, userKeys: UserKeys): Promise<OutputsWithSignAndLast<boolean>>;
19
19
  }
20
- export declare const multiThreadedUtxoUtils: MultiThreadedUtxoUtils;
@@ -1,17 +1,17 @@
1
1
  import { Utxo as p } from "../utxo/Utxo.mjs";
2
2
  import { UtxoWorkerActionType as u } from "../../webworker/utxoWorker/utxoWorker.types.mjs";
3
3
  import { performTaskWithWorker as h } from "../../webworker/performTaskWithWorker.mjs";
4
- import { WorkerVariant as U } from "../../webworker/worker.registry.mjs";
5
- import { isNode as d } from "../../constants/vite.constants.mjs";
6
- class S {
4
+ import { WorkerVariant as S } from "../../webworker/worker.registry.mjs";
5
+ import { isNode as U } from "../../constants/vite.constants.mjs";
6
+ class W {
7
7
  NUM_WORKERS;
8
8
  NUM_WORKERS_BATCH_PROCESS;
9
9
  constructor() {
10
- d ? (this.NUM_WORKERS = 1, this.NUM_WORKERS_BATCH_PROCESS = 1) : (this.NUM_WORKERS = 3, this.NUM_WORKERS_BATCH_PROCESS = Math.ceil(navigator.deviceMemory ?? 4));
10
+ U ? (this.NUM_WORKERS = 1, this.NUM_WORKERS_BATCH_PROCESS = 1) : (this.NUM_WORKERS = 3, this.NUM_WORKERS_BATCH_PROCESS = Math.ceil(navigator.deviceMemory ?? 4));
11
11
  }
12
12
  async createUtxoPromise(s) {
13
13
  return await h({
14
- type: U.UTXO,
14
+ type: S.UTXO,
15
15
  payload: s
16
16
  });
17
17
  }
@@ -63,8 +63,6 @@ class S {
63
63
  };
64
64
  }
65
65
  }
66
- const T = new S();
67
66
  export {
68
- S as MultiThreadedUtxoUtils,
69
- T as multiThreadedUtxoUtils
67
+ W as MultiThreadedUtxoUtils
70
68
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("./getDataFromTransaction.cjs"),C=require("idb-keyval"),u={encryptedOutputs:[],lastOutput:""},l=(e,t)=>{const s=e.substring(0,25),r=t.substring(0,25);return{shortPublicKey:s,shortHinkalAddress:r}},d=new Map,x=(e,t,s)=>{if(!e||!t||!s)throw Error("GetHinkalCache: incorrect arguments");const{shortPublicKey:r,shortHinkalAddress:a}=l(t,s);return JSON.parse(typeof localStorage<"u"?localStorage.getItem(`hinkalCache-${e}-${r}-${a}`)??JSON.stringify(u):d.get(`hinkalCache-${e}-${r}-${a}`)??JSON.stringify(u))},S=(e,t,s,r)=>{if(!t||!s||!r)throw Error("SetHinkalCache: incorrect arguments");const{shortPublicKey:a,shortHinkalAddress:o}=l(s,r);typeof localStorage<"u"?localStorage.setItem(`hinkalCache-${t}-${a}-${o}`,JSON.stringify(e)):d.set(`hinkalCache-${t}-${a}-${o}`,JSON.stringify(e))},H=(e,t,s)=>{S(u,e,t,s)},f=(e,t,s)=>`txsCache-${e}-${t}-${s}`,T=async(e,t,s,r,a)=>{if(!t||!s||!r)throw Error("saveTxsCache: incorrect arguments");const{shortPublicKey:o,shortHinkalAddress:n}=l(s,r),h=y.serializeDecodedTxs(e),c=f(t,o,n),g=JSON.stringify({serializedTxs:h,lastHash:a});try{await C.set(c,g)}catch{localStorage.setItem(c,g)}},m={serializedTxs:[],lastHash:""},$=async(e,t,s)=>{if(!e||!t||!s)throw Error("loadTxsCache: incorrect arguments");const{shortPublicKey:r,shortHinkalAddress:a}=l(t,s),o=f(e,r,a);let n;try{const i=await C.get(o);if(!i)throw new Error("Empty indexedDB cache");n=i}catch{n=localStorage.getItem(o)}const{serializedTxs:h,lastHash:c}=JSON.parse(n??JSON.stringify(m));return{decodedTxs:h.map(i=>y.deserializeDecodedTxs(i)),lastHash:c===""?void 0:c}};exports.getHinkalCache=x;exports.loadTxsCache=$;exports.resetCache=H;exports.saveTxsCache=T;exports.setHinkalCache=S;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../../types/ethereum-network.types.cjs"),y=require("./getDataFromTransaction.cjs"),C=require("idb-keyval"),g={encryptedOutputs:[],lastOutput:""},d=(e,t)=>{const s=e.substring(0,25),r=t.substring(0,25);return{shortPublicKey:s,shortHinkalAddress:r}},H=e=>{const t=e.getCurrentChainId(),s=e.getContract(u.ContractType.HinkalContract).address,r=e.userKeys.getShieldedPublicKey();if(!t||!r||!s)throw Error("GetHinkalCache: incorrect arguments");const{shortPublicKey:c,shortHinkalAddress:a}=d(r,s);return JSON.parse(typeof localStorage<"u"?localStorage.getItem(`hinkalCache-${t}-${c}-${a}`)??JSON.stringify(g):e.inMemoryCache.get(`hinkalCache-${t}-${c}-${a}`)??JSON.stringify(g))},S=(e,t)=>{const s=t.getCurrentChainId(),r=t.getContract(u.ContractType.HinkalContract).address,c=t.userKeys.getShieldedPublicKey();if(!s||!c||!r)throw Error("SetHinkalCache: incorrect arguments");const{shortPublicKey:a,shortHinkalAddress:n}=d(c,r);typeof localStorage<"u"?localStorage.setItem(`hinkalCache-${s}-${a}-${n}`,JSON.stringify(e)):t.inMemoryCache.set(`hinkalCache-${s}-${a}-${n}`,JSON.stringify(e))},T=e=>{S(g,e)},f=(e,t,s)=>`txsCache-${e}-${t}-${s}`,m=async(e,t,s,r,c)=>{if(!t||!s||!r)throw Error("saveTxsCache: incorrect arguments");const{shortPublicKey:a,shortHinkalAddress:n}=d(s,r),l=y.serializeDecodedTxs(e),o=f(t,a,n),h=JSON.stringify({serializedTxs:l,lastHash:c});try{await C.set(o,h)}catch{localStorage.setItem(o,h)}},x={serializedTxs:[],lastHash:""},p=async(e,t,s)=>{if(!e||!t||!s)throw Error("loadTxsCache: incorrect arguments");const{shortPublicKey:r,shortHinkalAddress:c}=d(t,s),a=f(e,r,c);let n;try{const i=await C.get(a);if(!i)throw new Error("Empty indexedDB cache");n=i}catch{n=localStorage.getItem(a)}const{serializedTxs:l,lastHash:o}=JSON.parse(n??JSON.stringify(x));return{decodedTxs:l.map(i=>y.deserializeDecodedTxs(i)),lastHash:o===""?void 0:o}};exports.getHinkalCache=H;exports.loadTxsCache=p;exports.resetCache=T;exports.saveTxsCache=m;exports.setHinkalCache=S;
@@ -1,14 +1,16 @@
1
- import { DecodedTx, EncryptedOutputWithSign } from '../../types';
1
+ import { IHinkal } from '../../data-structures';
2
+ import { EncryptedOutputWithSign } from '../../types/commitments.types';
3
+ import { DecodedTx } from '../../types/transactions.types';
2
4
  interface HinkalCacheInterface {
3
5
  encryptedOutputs: EncryptedOutputWithSign[];
4
6
  lastOutput: string;
5
7
  }
6
- export declare const getHinkalCache: (chainId: number, shieldedPublicKey: string, hinkalAddress: string) => HinkalCacheInterface;
7
- export declare const setHinkalCache: (hinkalCache: HinkalCacheInterface, chainId: number, shieldedPublicKey: string, hinkalAddress: string) => void;
8
- export declare const resetCache: (chainId: number, shieldedPublicKey: string, hinkalAddress: string) => void;
8
+ export declare const getHinkalCache: (hinkal: IHinkal) => HinkalCacheInterface;
9
+ export declare const setHinkalCache: (hinkalCache: HinkalCacheInterface, hinkal: IHinkal) => void;
10
+ export declare const resetCache: (hinkal: IHinkal) => void;
9
11
  export declare const saveTxsCache: (txs: DecodedTx[], chainId: number, shieldedPublicKey: string, hinkalAddress: string, lastHash: string) => Promise<void>;
10
12
  export declare const loadTxsCache: (chainId: number, shieldedPublicKey: string, hinkalAddress: string) => Promise<{
11
- decodedTxs: import('../../types/transactions.types').DecodedTxWithUtxos<bigint, import("ethers").BigNumber>[];
13
+ decodedTxs: import("../../types/transactions.types").DecodedTxWithUtxos<bigint, import("ethers").BigNumber>[];
12
14
  lastHash: string | undefined;
13
15
  }>;
14
16
  export {};
@@ -1,54 +1,60 @@
1
- import { serializeDecodedTxs as C, deserializeDecodedTxs as S } from "./getDataFromTransaction.mjs";
2
- import { set as d, get as m } from "idb-keyval";
3
- const y = {
1
+ import { ContractType as y } from "../../types/ethereum-network.types.mjs";
2
+ import { serializeDecodedTxs as C, deserializeDecodedTxs as f } from "./getDataFromTransaction.mjs";
3
+ import { set as m, get as S } from "idb-keyval";
4
+ const g = {
4
5
  encryptedOutputs: [],
5
6
  lastOutput: ""
6
- }, l = (e, t) => {
7
- const r = e.substring(0, 25), s = t.substring(0, 25);
8
- return { shortPublicKey: r, shortHinkalAddress: s };
9
- }, u = /* @__PURE__ */ new Map(), k = (e, t, r) => {
10
- if (!e || !t || !r)
7
+ }, d = (t, e) => {
8
+ const s = t.substring(0, 25), r = e.substring(0, 25);
9
+ return { shortPublicKey: s, shortHinkalAddress: r };
10
+ }, k = (t) => {
11
+ const e = t.getCurrentChainId(), s = t.getContract(y.HinkalContract).address, r = t.userKeys.getShieldedPublicKey();
12
+ if (!e || !r || !s)
11
13
  throw Error("GetHinkalCache: incorrect arguments");
12
- const { shortPublicKey: s, shortHinkalAddress: o } = l(t, r);
14
+ const { shortPublicKey: c, shortHinkalAddress: o } = d(r, s);
13
15
  return JSON.parse(
14
- typeof localStorage < "u" ? localStorage.getItem(`hinkalCache-${e}-${s}-${o}`) ?? JSON.stringify(y) : u.get(`hinkalCache-${e}-${s}-${o}`) ?? JSON.stringify(y)
16
+ typeof localStorage < "u" ? localStorage.getItem(`hinkalCache-${e}-${c}-${o}`) ?? JSON.stringify(g) : t.inMemoryCache.get(`hinkalCache-${e}-${c}-${o}`) ?? JSON.stringify(g)
15
17
  );
16
- }, p = (e, t, r, s) => {
17
- if (!t || !r || !s)
18
+ }, p = (t, e) => {
19
+ const s = e.getCurrentChainId(), r = e.getContract(y.HinkalContract).address, c = e.userKeys.getShieldedPublicKey();
20
+ if (!s || !c || !r)
18
21
  throw Error("SetHinkalCache: incorrect arguments");
19
- const { shortPublicKey: o, shortHinkalAddress: a } = l(r, s);
20
- typeof localStorage < "u" ? localStorage.setItem(`hinkalCache-${t}-${o}-${a}`, JSON.stringify(e)) : u.set(`hinkalCache-${t}-${o}-${a}`, JSON.stringify(e));
21
- }, T = (e, t, r) => {
22
- p(y, e, t, r);
23
- }, f = (e, t, r) => `txsCache-${e}-${t}-${r}`, O = async (e, t, r, s, o) => {
24
- if (!t || !r || !s)
22
+ const { shortPublicKey: o, shortHinkalAddress: n } = d(c, r);
23
+ typeof localStorage < "u" ? localStorage.setItem(`hinkalCache-${s}-${o}-${n}`, JSON.stringify(t)) : e.inMemoryCache.set(
24
+ `hinkalCache-${s}-${o}-${n}`,
25
+ JSON.stringify(t)
26
+ );
27
+ }, K = (t) => {
28
+ p(g, t);
29
+ }, u = (t, e, s) => `txsCache-${t}-${e}-${s}`, O = async (t, e, s, r, c) => {
30
+ if (!e || !s || !r)
25
31
  throw Error("saveTxsCache: incorrect arguments");
26
- const { shortPublicKey: a, shortHinkalAddress: n } = l(r, s), g = C(e), c = f(t, a, n), h = JSON.stringify({ serializedTxs: g, lastHash: o });
32
+ const { shortPublicKey: o, shortHinkalAddress: n } = d(s, r), l = C(t), a = u(e, o, n), h = JSON.stringify({ serializedTxs: l, lastHash: c });
27
33
  try {
28
- await d(c, h);
34
+ await m(a, h);
29
35
  } catch {
30
- localStorage.setItem(c, h);
36
+ localStorage.setItem(a, h);
31
37
  }
32
- }, x = { serializedTxs: [], lastHash: "" }, w = async (e, t, r) => {
33
- if (!e || !t || !r)
38
+ }, x = { serializedTxs: [], lastHash: "" }, b = async (t, e, s) => {
39
+ if (!t || !e || !s)
34
40
  throw Error("loadTxsCache: incorrect arguments");
35
- const { shortPublicKey: s, shortHinkalAddress: o } = l(t, r), a = f(e, s, o);
41
+ const { shortPublicKey: r, shortHinkalAddress: c } = d(e, s), o = u(t, r, c);
36
42
  let n;
37
43
  try {
38
- const i = await m(a);
44
+ const i = await S(o);
39
45
  if (!i)
40
46
  throw new Error("Empty indexedDB cache");
41
47
  n = i;
42
48
  } catch {
43
- n = localStorage.getItem(a);
49
+ n = localStorage.getItem(o);
44
50
  }
45
- const { serializedTxs: g, lastHash: c } = JSON.parse(n ?? JSON.stringify(x));
46
- return { decodedTxs: g.map((i) => S(i)), lastHash: c === "" ? void 0 : c };
51
+ const { serializedTxs: l, lastHash: a } = JSON.parse(n ?? JSON.stringify(x));
52
+ return { decodedTxs: l.map((i) => f(i)), lastHash: a === "" ? void 0 : a };
47
53
  };
48
54
  export {
49
55
  k as getHinkalCache,
50
- w as loadTxsCache,
51
- T as resetCache,
56
+ b as loadTxsCache,
57
+ K as resetCache,
52
58
  O as saveTxsCache,
53
59
  p as setHinkalCache
54
60
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("../../../data-structures/utxo/Utxo.cjs"),m=require("../../../types/ethereum-network.types.cjs"),w=require("../../utils/cacheFunctions.cjs"),C=async(e,r,i,n,u=0)=>(await e.utxoUtils.buildBatchProcess(r,i)).reduce((o,t)=>n&&u!==0?t.erc20TokenAddress.toLowerCase()===n.toLowerCase()&&t.tokenId===u?[...o,t]:o:n?t.erc20TokenAddress.toLowerCase()===n.toLowerCase()?[...o,t]:o:[...o,t],[]),I=async(e,r,i,n,u,a,o,t=0)=>{const s=await e.utxoUtils.batchFilterUtxosWithNullifier(r,i);if(o){for(s.sort((c,l)=>c.amount<=l.amount?1:-1);s.length<n||s.length>n&&s.length<6;)s.push(new b.Utxo({amount:0n,erc20TokenAddress:o,shieldedPrivateKey:a,tokenId:t}));if(u)for(;s.length>6;)s.splice(s.length-1)}return{inputUtxos:s}},P=async({hinkal:e,erc20TokenAddress:r=void 0,minInput:i=2,sliceIfMore6:n=!0,tokenId:u=0})=>{if(!e.getCurrentChainId||!e.getSelectedNetwork())return{inputUtxos:[]};const{encryptedOutputs:a,nullifiers:o,userKeys:t}=e,s=Array.from(a),c=e.getCurrentChainId(),l=e.getContract(m.ContractType.HinkalContract).address,x=t.getShieldedPublicKey(),f=t.getShieldedPrivateKey();let p=[],g=[],{encryptedOutputs:U,lastOutput:d}=w.getHinkalCache(c,x,l),y=s.findIndex(h=>h.value===d);if(y>-1||U.length===0){y+=1;const h=s.slice(y);({lastOutput:d,additionalEncryptedOutputs:g}=await e.utxoUtils.batchProcess(h,d,t)),p=[...U,...g],w.setHinkalCache({lastOutput:d,encryptedOutputs:p},c,x,l)}const O=await C(e,p,t,r,u);return await I(e,O,o,i,n,f,r,u)};exports.getInputUtxoAndBalance=P;exports.getInputUtxosFromEncryptedOutputs=C;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../../../data-structures/utxo/Utxo.cjs"),g=require("../../utils/cacheFunctions.cjs"),h=async(t,i,a,u,n=0)=>(await t.utxoUtils.buildBatchProcess(i,a)).reduce((o,e)=>u&&n!==0?e.erc20TokenAddress.toLowerCase()===u.toLowerCase()&&e.tokenId===n?[...o,e]:o:u?e.erc20TokenAddress.toLowerCase()===u.toLowerCase()?[...o,e]:o:[...o,e],[]),O=async(t,i,a,u,n,r,o,e=0)=>{const s=await t.utxoUtils.batchFilterUtxosWithNullifier(i,a);if(o){for(s.sort((d,l)=>d.amount<=l.amount?1:-1);s.length<u||s.length>u&&s.length<6;)s.push(new f.Utxo({amount:0n,erc20TokenAddress:o,shieldedPrivateKey:r,tokenId:e}));if(n)for(;s.length>6;)s.splice(s.length-1)}return{inputUtxos:s}},C=async({hinkal:t,erc20TokenAddress:i=void 0,minInput:a=2,sliceIfMore6:u=!0,tokenId:n=0})=>{if(!t.getCurrentChainId||!t.getSelectedNetwork())return{inputUtxos:[]};const{encryptedOutputs:r,nullifiers:o,userKeys:e}=t,s=Array.from(r),d=e.getShieldedPrivateKey();let l=[],U=[],{encryptedOutputs:y,lastOutput:c}=g.getHinkalCache(t),p=s.findIndex(x=>x.value===c);if(p>-1||y.length===0){p+=1;const x=s.slice(p);({lastOutput:c,additionalEncryptedOutputs:U}=await t.utxoUtils.batchProcess(x,c,e)),l=[...y,...U],g.setHinkalCache({lastOutput:c,encryptedOutputs:l},t)}const w=await h(t,l,e,i,n);return await O(t,w,o,a,u,d,i,n)};exports.getInputUtxoAndBalance=C;exports.getInputUtxosFromEncryptedOutputs=h;
@@ -1,69 +1,62 @@
1
- import { Utxo as C } from "../../../data-structures/utxo/Utxo.mjs";
2
- import { ContractType as m } from "../../../types/ethereum-network.types.mjs";
3
- import { getHinkalCache as O, setHinkalCache as P } from "../../utils/cacheFunctions.mjs";
4
- const b = async (e, u, r, n, i = 0) => (await e.utxoUtils.buildBatchProcess(u, r)).reduce((o, t) => n && i !== 0 ? t.erc20TokenAddress.toLowerCase() === n.toLowerCase() && t.tokenId === i ? [...o, t] : o : n ? t.erc20TokenAddress.toLowerCase() === n.toLowerCase() ? [...o, t] : o : [...o, t], []), I = async (e, u, r, n, i, a, o, t = 0) => {
5
- const s = await e.utxoUtils.batchFilterUtxosWithNullifier(u, r);
1
+ import { Utxo as y } from "../../../data-structures/utxo/Utxo.mjs";
2
+ import { getHinkalCache as h, setHinkalCache as g } from "../../utils/cacheFunctions.mjs";
3
+ const O = async (t, i, l, u, n = 0) => (await t.utxoUtils.buildBatchProcess(i, l)).reduce((o, e) => u && n !== 0 ? e.erc20TokenAddress.toLowerCase() === u.toLowerCase() && e.tokenId === n ? [...o, e] : o : u ? e.erc20TokenAddress.toLowerCase() === u.toLowerCase() ? [...o, e] : o : [...o, e], []), m = async (t, i, l, u, n, r, o, e = 0) => {
4
+ const s = await t.utxoUtils.batchFilterUtxosWithNullifier(i, l);
6
5
  if (o) {
7
- for (s.sort((l, c) => l.amount <= c.amount ? 1 : -1); s.length < n || s.length > n && s.length < 6; )
8
- s.push(new C({ amount: 0n, erc20TokenAddress: o, shieldedPrivateKey: a, tokenId: t }));
9
- if (i)
6
+ for (s.sort((p, a) => p.amount <= a.amount ? 1 : -1); s.length < u || s.length > u && s.length < 6; )
7
+ s.push(new y({ amount: 0n, erc20TokenAddress: o, shieldedPrivateKey: r, tokenId: e }));
8
+ if (n)
10
9
  for (; s.length > 6; )
11
10
  s.splice(s.length - 1);
12
11
  }
13
12
  return {
14
13
  inputUtxos: s
15
14
  };
16
- }, F = async ({
17
- hinkal: e,
18
- erc20TokenAddress: u = void 0,
19
- minInput: r = 2,
20
- sliceIfMore6: n = !0,
21
- tokenId: i = 0
15
+ }, P = async ({
16
+ hinkal: t,
17
+ erc20TokenAddress: i = void 0,
18
+ minInput: l = 2,
19
+ sliceIfMore6: u = !0,
20
+ tokenId: n = 0
22
21
  }) => {
23
- if (!e.getCurrentChainId || !e.getSelectedNetwork())
22
+ if (!t.getCurrentChainId || !t.getSelectedNetwork())
24
23
  return { inputUtxos: [] };
25
- const { encryptedOutputs: a, nullifiers: o, userKeys: t } = e, s = Array.from(a), l = e.getCurrentChainId(), c = e.getContract(m.HinkalContract).address, y = t.getShieldedPublicKey(), U = t.getShieldedPrivateKey();
26
- let p = [], f = [], { encryptedOutputs: g, lastOutput: d } = O(
27
- l,
28
- y,
29
- c
30
- ), h = s.findIndex((x) => x.value === d);
31
- if (h > -1 || g.length === 0) {
32
- h += 1;
33
- const x = s.slice(h);
34
- ({ lastOutput: d, additionalEncryptedOutputs: f } = await e.utxoUtils.batchProcess(
24
+ const { encryptedOutputs: r, nullifiers: o, userKeys: e } = t, s = Array.from(r), p = e.getShieldedPrivateKey();
25
+ let a = [], U = [], { encryptedOutputs: f, lastOutput: c } = h(t), d = s.findIndex((x) => x.value === c);
26
+ if (d > -1 || f.length === 0) {
27
+ d += 1;
28
+ const x = s.slice(d);
29
+ ({ lastOutput: c, additionalEncryptedOutputs: U } = await t.utxoUtils.batchProcess(
35
30
  x,
36
- d,
37
- t
38
- )), p = [...g, ...f], P(
31
+ c,
32
+ e
33
+ )), a = [...f, ...U], g(
39
34
  {
40
- lastOutput: d,
41
- encryptedOutputs: p
35
+ lastOutput: c,
36
+ encryptedOutputs: a
42
37
  },
43
- l,
44
- y,
45
- c
38
+ t
46
39
  );
47
40
  }
48
- const w = await b(
49
- e,
50
- p,
41
+ const w = await O(
51
42
  t,
52
- u,
53
- i
54
- );
55
- return await I(
43
+ a,
56
44
  e,
45
+ i,
46
+ n
47
+ );
48
+ return await m(
49
+ t,
57
50
  w,
58
51
  o,
59
- r,
60
- n,
61
- U,
52
+ l,
62
53
  u,
63
- i
54
+ p,
55
+ i,
56
+ n
64
57
  );
65
58
  };
66
59
  export {
67
- F as getInputUtxoAndBalance,
68
- b as getInputUtxosFromEncryptedOutputs
60
+ P as getInputUtxoAndBalance,
61
+ O as getInputUtxosFromEncryptedOutputs
69
62
  };