h_test_1 0.0.36 → 0.0.38
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
|
-
require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../types/ethereum-network.types.cjs`),t=require(`../../functions/utils/serialize.utils.cjs`),n=require(`../../constants/vite.constants.cjs`),r=require(`../../constants/chains.constants.cjs`),i=require(`../../types/hinkal.types.cjs`),a=require(`../../API/API.cjs`),o=require(`../../constants/kyc.constants.cjs`),s=require(`../../error-handling/error-codes.constants.cjs`),c=require(`../../functions/utils/erc20tokenFunctions.cjs`);require(`../../API/index.cjs`);const l=require(`../../crypto/poseidon.cjs`),u=require(`../crypto-keys/keys.cjs`),d=require(`../../functions/pre-transaction/solana.cjs`),f=require(`./hinkalCheckSolanaTokenRegistry.cjs`),p=require(`../../functions/web3/functionCalls/accessTokenCalls.cjs`),m=require(`../../functions/utils/token-check.utils.cjs`),h=require(`../TokenDBs/PrivateTokensDB.cjs`),g=require(`../../functions/web3/events/getShieldedBalance.cjs`),ee=require(`../../functions/utils/reloadPage.cjs`),_=require(`../../functions/utils/cacheDevice.utils.cjs`),v=require(`../../functions/web3/getContractMetadata.cjs`),y=require(`../../providers/SolanaProviderAdapter.cjs`),b=require(`./hinkalCheckTokenRegistry.cjs`),x=require(`../merkle-tree/MerkleTree.cjs`);require(`../merkle-tree/index.cjs`);const S=require(`./hinkalDeposit.cjs`),te=require(`../../functions/private-wallet/emporium.helpers.cjs`),C=require(`../../functions/web3/events/getApprovedBalance.cjs`),ne=require(`../../functions/kyc/checkTokenLimitsUSD.cjs`),w=require(`./hinkalDepositAndWithdraw.cjs`),T=require(`./hinkalSolanaDeposit.cjs`),E=require(`./hinkalSwap.cjs`),D=require(`./hinkalWithdraw.cjs`),O=require(`./resetMerkleTrees.cjs`),k=require(`../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.cjs`),A=require(`./hinkalPrivateWallet.cjs`),j=require(`./hinkalGetRecipientInfo.cjs`),M=require(`./hinkalSignSubAccount.cjs`),N=require(`./hinkalActionReceive.cjs`);require(`../TokenDBs/index.cjs`);const P=require(`./hinkalProoflessDeposit.cjs`),F=require(`./hinkalProxySwap.cjs`),I=require(`./hinkalMultiSend.cjs`),L=require(`./hinkalTransfer.cjs`),R=require(`./hinkalProxyToPrivate.cjs`),z=require(`../../providers/TronProviderAdapter.cjs`),B=require(`./hinkalSolanaDepositAndWithdraw.cjs`),V=require(`./hinkalSolanaWithdraw.cjs`),H=require(`./hinkalSolanaTransfer.cjs`),U=require(`./hinkalSolanaSwap.cjs`),W=require(`./hinkalSolanaProxySend.cjs`),G=require(`./hinkalSolanaProxySwap.cjs`),K=require(`./hinkalSolanaProxyShield.cjs`),q=require(`../../functions/web3/fetchSolanaMerkleTreeRootHash.cjs`),J=require(`./hinkalDepositAndBridge.cjs`),Y=require(`./hinkalClaimUtxo.cjs`),X=require(`./hinkalSolanaProoflessDeposit.cjs`),Z=require(`./hinkalSolanaClaimUtxo.cjs`),re=require(`./hinkalWithdrawStuckUtxos.cjs`);let Q=require(`ethers`),$=require(`@solana/web3.js`);var ie=class{ethereumProviderAdapter;solanaProviderAdapter;tronProviderAdapter;userKeys;signingMessage=`Login to Hinkal Protocol`;privateTransferSigningMessage=`Login to Hinkal's Private Transfer App`;merkleTreeHinkalByChain={};merkleTreeAccessTokenByChain={};nullifiersByChain={};encryptedOutputsByChain={};approvalsByChain={};commitmentsSnapshotServiceByChain={};nullifierSnapshotServiceByChain={};accessTokenSnapshotServiceByChain={};approvalsSnapshotServiceByChain={};utxoUtils;lastCallState=new Map;cacheDevice;generateProofRemotely;disableMerkleTreeUpdates;constructor(e){this.userKeys=new u.UserKeys(void 0),r.HINKAL_SUPPORTED_CHAINS.forEach(e=>{this.merkleTreeHinkalByChain[e]=x.MerkleTree.create(l.poseidonFunction,0n),this.merkleTreeAccessTokenByChain[e]=x.MerkleTree.create(l.poseidonFunction,0n),this.nullifiersByChain[e]=new Set,this.encryptedOutputsByChain[e]=[],this.approvalsByChain[e]=new Map}),this.generateProofRemotely=e?.generateProofRemotely??!0,this.utxoUtils=new k.MultiThreadedUtxoUtils,this.cacheDevice=_.createCacheDevice(e),this.disableMerkleTreeUpdates=e?.disableMerkleTreeUpdates??!1}enforceRateLimit(e,n,r=1e3){let i=Date.now(),a=t.CustomJSONStringify(n),o=this.lastCallState.get(e);if(o&&o.argsKey===a&&i-o.timestamp<r)throw Error(`${e} was already called with the same arguments`);this.lastCallState.set(e,{timestamp:i,argsKey:a})}getProviderAdapter(e){let t=e;t||=this.ethereumProviderAdapter?r.chainIds.ethMainnet:this.solanaProviderAdapter?r.chainIds.solanaMainnet:r.chainIds.tronMainnet;let n;if(n=r.isSolanaLike(t)?this.solanaProviderAdapter:r.isTronLike(t)?this.tronProviderAdapter:this.ethereumProviderAdapter,!n)throw Error(`ProviderAdapter is not initialized`);return n}async initProviderAdapter(e,t){let n=r.chainIds.ethMainnet;t instanceof y.SolanaProviderAdapter?n=r.chainIds.solanaMainnet:t instanceof z.TronProviderAdapter&&(n=r.currentTronChainId),await this.updateProviderAdapter(n,t),t.initConnector(e);let i=await t.connectAndPatchProvider(e);await t.init(i),await this.setListeners()}getSigningMessage(e=i.LoginMessageMode.PROTOCOL){switch(e){case i.LoginMessageMode.PRIVATE_TRANSFER:return this.privateTransferSigningMessage;case i.LoginMessageMode.PROTOCOL:default:return this.signingMessage}}async initUserKeys(e=i.LoginMessageMode.PROTOCOL){let t=this.getSigningMessage(e);this.userKeys=new u.UserKeys(await this.getProviderAdapter().signMessage(t))}initUserKeysWithSignature(e){this.userKeys=new u.UserKeys(e)}async initUserKeysFromSeedPhrases(e){let t=e.join(` `),n=Q.ethers.toUtf8Bytes(t);this.userKeys=new u.UserKeys(Q.ethers.keccak256(n))}async resetMerkle(e){this.disableMerkleTreeUpdates||(e?.every(e=>this.isSelectedNetworkSupported(e))??!0)&&await O.resetMerkleTrees(this,e)}getTronWeb(){let e=this.tronProviderAdapter;if(!e)throw Error(`Tron provider adapter not initialized`);if(!(e instanceof z.TronProviderAdapter))throw Error(`Tron provider adapter is not a TronProviderAdapter`);let t=e.getTronWeb();if(!t)throw Error(`TronWeb not available`);return t}getSupportedChains(){return this.ethereumProviderAdapter&&this.solanaProviderAdapter?r.WALLET_SUPPORTED_CHAINS:this.ethereumProviderAdapter?r.HINKAL_SUPPORTED_CHAINS.filter(e=>!r.isSolanaLike(e)&&!r.isTronLike(e)):this.solanaProviderAdapter?r.HINKAL_SUPPORTED_CHAINS.filter(e=>r.isSolanaLike(e)):this.tronProviderAdapter?r.HINKAL_SUPPORTED_CHAINS.filter(e=>r.isTronLike(e)):[]}async waitForTransaction(e,t,n=1){return!!await this.getProviderAdapter(e).waitForTransaction(e,t,n)}getContract(e,t,n=void 0){return this.getProviderAdapter(e).getContract(e,t,n)}getContractWithFetcherByChainId(e,t,n=void 0){return v.getContractWithFetcherByChainId(e,t,n)}async signMessage(e){return await this.getProviderAdapter().signMessage(e)}async signTypedData(e,t,n){return await this.getProviderAdapter().signTypedData(e,t,n)}async signWithSubAccount(e,t,n,r){return M.hinkalSignSubAccount(e,t,n,r)}getContractWithSigner(e,t,n=``){return this.getProviderAdapter(e).getContractWithSigner(e,t,n)}getContractWithFetcher(e,t,n=``){return this.getProviderAdapter(e).getContractWithFetcher(e,t,n)}isSelectedNetworkSupported(e){return!!r.networkRegistry[e]}async switchNetwork(e){try{await this.getProviderAdapter().switchNetwork(e)}catch{throw Error(s.transactionErrorCodes.FAILED_TO_SWITCH_NETWORKS)}}isPermitterAvailable(e){return this.getProviderAdapter(e).isPermitterAvailable()}async disconnectFromConnector(){await this.ethereumProviderAdapter?.disconnectFromConnector(),await this.solanaProviderAdapter?.disconnectFromConnector(),await this.tronProviderAdapter?.disconnectFromConnector()}async resetProviderAdapters(){this.ethereumProviderAdapter=void 0,this.solanaProviderAdapter=void 0,this.tronProviderAdapter=void 0}async updateProviderAdapter(e,t){try{r.isSolanaLike(e)?(this.solanaProviderAdapter&&this.solanaProviderAdapter.release(),this.solanaProviderAdapter=t):r.isTronLike(e)?(this.tronProviderAdapter&&this.tronProviderAdapter.release(),this.tronProviderAdapter=t):(this.ethereumProviderAdapter&&this.ethereumProviderAdapter.release(),this.ethereumProviderAdapter=t)}catch(e){throw console.error(e),Error(`updateProviderAdapter failed, please try again.`)}}async setListeners(){this.ethereumProviderAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}}),this.solanaProviderAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}}),this.tronProviderAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}})}async onAccountChanged(){await this.ethereumProviderAdapter?.onAccountChanged(),await this.solanaProviderAdapter?.onAccountChanged(),await this.tronProviderAdapter?.onAccountChanged();let e=i.EventType.AccountChanged;typeof document<`u`?document?.dispatchEvent(new Event(e)):process?.emit(`message`,e,void 0)}async onChainChanged(e){e?await this.getProviderAdapter(e).onChainChanged(e):(await this.disconnectFromConnector(),ee.reloadPage())}async monitorConnectedAddress(e){await a.API.monitor(await this.getEthereumAddressByChain(e))}async getBalances(e,t,n,r,i=!1,a,o=!1){return g.getShieldedBalance(this,e,t,n,r,i,this.generateProofRemotely,a,o)}async getApprovedBalances(e,t=!1,n=!1){return C.getApprovedBalance(this,e,t,n)}async getTotalBalance(e,t,i,a=!1,o,s=!1){let l=i??await this.getEthereumAddressByChain(e),u=t??this.userKeys,d=await this.getBalances(e,u.getShieldedPrivateKey(),u.getShieldedPublicKey(),l,a,o,s),f=!r.isSolanaLike(e)&&!s?await this.getApprovedBalances(e,a,o):new Map,p=n.isExtension?await h.privateTokensDB.getPrivateTokens(e,l):c.getErc20TokensForChain(e),m=[];return p.forEach(e=>{let t=e.erc20TokenAddress.toLowerCase(),n=d.get(t),r=f.get(t),i={token:e,balance:(n?.balance??0n)+(r?.balance??0n),timestamp:n?.timestamp||r?.timestamp||`0`,nfts:n?.nfts||[]};m.push(i)}),m}async getStuckShieldedBalances(e,t,n){return(await this.getTotalBalance(e,t,n,!1,!1,!0)).filter(e=>e.balance>0n)}getSupportedPassportLinks(){return o.supportedPassportLinks}checkAccessToken(e,t){return p.checkHinkalAccessToken(this,e,t)}checkExternalTokenLimitsUSD(e,t,n){return ne.checkTokenLimitsUSD(e,t,n)}async getHinkalTreeRootHash(t){if(r.isSolanaLike(t)){let{hinkalIdl:e,hinkalAddress:n,originalDeployer:i}=r.networkRegistry[t].contractData;if(!e||!n||!i)throw Error(`Missing Solana configuration for chain ${t}`);let a=new $.PublicKey(i),o=d.getMerkleAccountPublicKey(new $.PublicKey(n),a);return q.fetchSolanaMerkleTreeRootHash(this.getSolanaProgram(e),o)}return this.getContractWithFetcherByChainId(t,e.ContractType.HinkalContract).getRootHash()}async getAccessTokenTreeRootHash(t){if(r.isSolanaLike(t)){let{hinkalIdl:e,hinkalAddress:n,originalDeployer:i}=r.networkRegistry[t].contractData;if(!e||!n||!i)throw Error(`Missing Solana configuration for chain ${t}`);let a=new $.PublicKey(i),o=d.getAccessTokenMerkleAccountPublicKey(new $.PublicKey(n),a);return q.fetchSolanaMerkleTreeRootHash(this.getSolanaProgram(e),o)}return this.getContractWithFetcherByChainId(t,e.ContractType.AccessTokenContract).getRootHash()}async resetMerkleTreesIfNecessary(e){let t=(await Promise.all((e??this.getSupportedChains()).map(async e=>{let[t,n]=await Promise.all([this.getHinkalTreeRootHash(e),this.getAccessTokenTreeRootHash(e)]);return{chainId:e,needsReset:BigInt(t)!==this.merkleTreeHinkalByChain[e].getRootHash()||BigInt(n)!==this.merkleTreeAccessTokenByChain[e].getRootHash()}}))).filter(e=>e.needsReset).map(e=>e.chainId);t.length>0&&(console.log(`resetting merkle tree in resetMerkleTreesIfNecessary for chains:`,t),await this.resetMerkle(t))}async getEthereumAddress(){let e=this.ethereumProviderAdapter??this.solanaProviderAdapter??this.tronProviderAdapter;if(!e)throw Error(`No provider adapter initialized`);return e.getAddress()}getEthereumAddressByChain(e){return this.getProviderAdapter(e).getAddress()}async getRandomRelay(e,t=!1){return(await a.API.getIdleRelay(e,t)).relay}getGasPrice(e){let t=this.getProviderAdapter(e);if(!t)throw Error(`Illegal State of providerAdapter in Hinkal: no providerAdapter initialized`);return t.getGasPrice(e)}getAPI(){return a.API}snapshotsClearInterval(){this.getSupportedChains().forEach(e=>{this.commitmentsSnapshotServiceByChain[e]?.intervalClear(),this.accessTokenSnapshotServiceByChain[e]?.intervalClear(),this.nullifierSnapshotServiceByChain[e]?.intervalClear(),this.approvalsSnapshotServiceByChain[e]?.intervalClear()})}checkTokenRegistry(t,n,i){if(r.isSolanaLike(t)){let{hinkalIdl:e,hinkalAddress:a,originalDeployer:o}=r.networkRegistry[t].contractData;if(!e||!a||!o)throw Error(`missing solana data`);return f.hinkalCheckSolanaTokenRegistry(this.getSolanaProgram(e),new $.PublicKey(o),n,i)}return r.isTronLike(t)?b.hinkalCheckTronTokenRegistry(n,i,t):b.hinkalCheckTokenRegistry(this.getContractWithFetcher(t,e.ContractType.HinkalHelperContract),n,i)}getRecipientInfo(){return j.getRecipientInfo(this)}getApprovedUtxos(e,t=!1){return C.getApprovedUtxos(this,e,t)}getApprovedUtxosForToken(e,t,n=!1){return C.getApprovedUtxosForToken(this,e,t,n)}async deposit(e,t,n=!0,r=!1){return S.hinkalDeposit(this,e,t,n,r)}async depositSolana(e,t){return T.hinkalSolanaDeposit(this,e,t)}async depositForOther(e,t,n,r=!0,i=!1){return this.enforceRateLimit(this.depositForOther.name,[e,t,n]),S.hinkalDepositForOther(this,e,t,n,r,i)}async depositSolanaForOther(e,t,n){return this.enforceRateLimit(this.depositSolanaForOther.name,[e,t,n]),T.hinkalSolanaDepositForOther(this,e,t,n)}async depositAndWithdraw(e,t,n,i,a,o,s,c=!0){return r.isSolanaLike(m.validateAndGetChainId([e]))?B.hinkalSolanaDepositAndWithdraw(this,e,t,n,i,a,o,s):w.hinkalDepositAndWithdraw(this,e,t,n,i,a,o,s,c)}async claimUtxo(e,t,n,i){return r.isSolanaLike(m.validateAndGetChainId([e]))?Z.hinkalSolanaClaimUtxo(this,e,t,n,i):Y.hinkalClaimUtxo(this,e,t,n,i)}async depositAndBridge(e,t,n,r,i,a,o=!0){return J.hinkalDepositAndBridge(this,e,t,n,r,i,a,o)}async prooflessDeposit(e,t,n,i){return r.isSolanaLike(m.validateAndGetChainId(e))?X.hinkalSolanaProoflessDeposit(this,e,t,n,i):P.hinkalProoflessDeposit(this,e,t,n,i)}getSolanaProgram(e){if(!this.solanaProviderAdapter)throw Error(`No provider adapter initialized`);if(!(`getSolanaProgram`in this.solanaProviderAdapter))throw Error(`Current provider adapter is not a Solana provider adapter`);return this.solanaProviderAdapter.getSolanaProgram(e)}getSolanaPublicKey(){if(!this.solanaProviderAdapter)throw Error(`No provider adapter initialized`);if(!(`getSolanaPublicKey`in this.solanaProviderAdapter))throw Error(`Current provider adapter is not a Solana provider adapter`);return this.solanaProviderAdapter.getSolanaPublicKey()}async transfer(e,t,n,i,a,o){return r.isSolanaLike(m.validateAndGetChainId(e))?H.hinkalSolanaTransfer(this,e,t,n,i,a,o):L.hinkalTransfer(this,e,t,n,i,a,o)}async withdraw(e,t,n,i,a,o,s){return r.isSolanaLike(m.validateAndGetChainId(e))?V.hinkalSolanaWithdraw(this,e,t,n,a,o,s):D.hinkalWithdraw(this,e,t,n,i,a,o,s)}async withdrawStuckUtxos(e,t){return re.hinkalWithdrawStuckUtxos(this,e,t)}async swap(e,t,n,i,a,o,s){return r.isSolanaLike(m.validateAndGetChainId(e))?this.swapSolana(e,t,i,a,o):E.hinkalSwap(this,e,t,n,i,a,o,s)}async swapSolana(e,t,n,r,i){let a=JSON.parse(n),o=BigInt(a.swapperAccountSalt),{instructionLists:s,addressLookupTableAccount:c}=a.data;return U.hinkalSolanaSwap(this,e,t,o,s,c,r,i)}async actionReceive(e,t,n,i,a,o){if(!a)throw Error(`subAccount is required`);return r.isSolanaLike(m.validateAndGetChainId(e))?K.hinkalSolanaProxyShield(this,e[0],t[0],a,void 0,o):N.hinkalActionReceive(this,e,t,n,i,a,o)}async actionPrivateWallet(e,t,n,r,i,a,o,s,c,l,u=!1,d,f,p){return this.enforceRateLimit(this.actionPrivateWallet.name,[e,t,n,r,i,a,o,s,c,p]),A.hinkalPrivateWallet(this,e,t,n,r,i,a,o,s,c,l,u,d,f,p)}async proxySwap(e,t,n,i,a,o,s,c,l=!1,u,d){return r.isSolanaLike(m.validateAndGetChainId(e))?G.hinkalSolanaProxySwap(this,e,t,i,o,s,c):F.hinkalProxySwap(this,e,t,n,i,a,o,s,c,l,u,d)}async proxyToPrivate(e,t,n,i,a,o,s){return r.isSolanaLike(m.validateAndGetChainId(e))?(this.enforceRateLimit(this.proxyToPrivate.name,[e[0],t[0],n,i]),K.hinkalSolanaProxyShield(this,e[0],t[0],n,i,s)):R.hinkalProxyToPrivate(this,e,t,i,a,o,n,s)}async proxySend(e,t,n,i,a,o,s){let c=m.validateAndGetChainId(e);if(r.isSolanaLike(c))return W.hinkalSolanaProxySend(this,e[0],t[0],n,i,s);let l=te.createTransaferEmporiumOpsBatch(this,c,e.map(e=>e.erc20TokenAddress),t,i),u=e.map((e,n)=>({token:e,amount:-1n*t[n]}));return await this.actionPrivateWallet(c,[],[],[],l,u,n,a,o,void 0,void 0,void 0,s,void 0)}async multiSendPrivateRecipients(e,t,n){return this.enforceRateLimit(this.multiSendPrivateRecipients.name,[e,t,n]),I.hinkalMultiSendPrivateRecipients(this,e,t,n)}areMerkleTreeUpdatesDisabled(){return this.disableMerkleTreeUpdates}updateMerkleTreeUpdates(e){this.disableMerkleTreeUpdates=e}};exports.Hinkal=ie;
|
|
1
|
+
require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../types/ethereum-network.types.cjs`),t=require(`../../functions/utils/serialize.utils.cjs`),n=require(`../../constants/vite.constants.cjs`),r=require(`../../constants/chains.constants.cjs`),i=require(`../../types/hinkal.types.cjs`),a=require(`../../API/API.cjs`),o=require(`../../constants/kyc.constants.cjs`),s=require(`../../error-handling/error-codes.constants.cjs`),c=require(`../../functions/utils/erc20tokenFunctions.cjs`);require(`../../API/index.cjs`);const l=require(`../../crypto/poseidon.cjs`),u=require(`../crypto-keys/keys.cjs`),d=require(`../../functions/pre-transaction/solana.cjs`),f=require(`./hinkalCheckSolanaTokenRegistry.cjs`),p=require(`../../functions/web3/functionCalls/accessTokenCalls.cjs`),m=require(`../../functions/utils/token-check.utils.cjs`),h=require(`../TokenDBs/PrivateTokensDB.cjs`),g=require(`../../functions/web3/events/getShieldedBalance.cjs`),ee=require(`../../functions/utils/reloadPage.cjs`),_=require(`../../functions/utils/cacheDevice.utils.cjs`),v=require(`../../functions/web3/getContractMetadata.cjs`),y=require(`../../providers/SolanaProviderAdapter.cjs`),b=require(`./hinkalCheckTokenRegistry.cjs`),x=require(`../merkle-tree/MerkleTree.cjs`);require(`../merkle-tree/index.cjs`);const S=require(`./hinkalDeposit.cjs`),te=require(`../../functions/private-wallet/emporium.helpers.cjs`),C=require(`../../functions/web3/events/getApprovedBalance.cjs`),ne=require(`../../functions/kyc/checkTokenLimitsUSD.cjs`),w=require(`./hinkalDepositAndWithdraw.cjs`),T=require(`./hinkalSolanaDeposit.cjs`),E=require(`./hinkalSwap.cjs`),D=require(`./hinkalWithdraw.cjs`),O=require(`./resetMerkleTrees.cjs`),k=require(`../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.cjs`),A=require(`./hinkalPrivateWallet.cjs`),j=require(`./hinkalGetRecipientInfo.cjs`),M=require(`./hinkalSignSubAccount.cjs`),N=require(`./hinkalActionReceive.cjs`);require(`../TokenDBs/index.cjs`);const P=require(`./hinkalProoflessDeposit.cjs`),F=require(`./hinkalProxySwap.cjs`),I=require(`./hinkalMultiSend.cjs`),L=require(`./hinkalTransfer.cjs`),R=require(`./hinkalProxyToPrivate.cjs`),z=require(`../../providers/TronProviderAdapter.cjs`),B=require(`./hinkalSolanaDepositAndWithdraw.cjs`),V=require(`./hinkalSolanaWithdraw.cjs`),H=require(`./hinkalSolanaTransfer.cjs`),U=require(`./hinkalSolanaSwap.cjs`),W=require(`./hinkalSolanaProxySend.cjs`),G=require(`./hinkalSolanaProxySwap.cjs`),K=require(`./hinkalSolanaProxyShield.cjs`),q=require(`../../functions/web3/fetchSolanaMerkleTreeRootHash.cjs`),J=require(`./hinkalDepositAndBridge.cjs`),Y=require(`./hinkalClaimUtxo.cjs`),X=require(`./hinkalSolanaProoflessDeposit.cjs`),Z=require(`./hinkalSolanaClaimUtxo.cjs`),re=require(`./hinkalWithdrawStuckUtxos.cjs`);let Q=require(`ethers`),$=require(`@solana/web3.js`);var ie=class{ethereumProviderAdapter;solanaProviderAdapter;tronProviderAdapter;userKeys;signingMessage=`Login to Hinkal Protocol`;privateTransferSigningMessage=`Login to Hinkal's Private Transfer App`;merkleTreeHinkalByChain={};merkleTreeAccessTokenByChain={};nullifiersByChain={};encryptedOutputsByChain={};approvalsByChain={};commitmentsSnapshotServiceByChain={};nullifierSnapshotServiceByChain={};accessTokenSnapshotServiceByChain={};approvalsSnapshotServiceByChain={};utxoUtils;lastCallState=new Map;cacheDevice;generateProofRemotely;disableMerkleTreeUpdates;constructor(e){this.userKeys=new u.UserKeys(void 0),r.HINKAL_SUPPORTED_CHAINS.forEach(e=>{this.merkleTreeHinkalByChain[e]=x.MerkleTree.create(l.poseidonFunction,0n),this.merkleTreeAccessTokenByChain[e]=x.MerkleTree.create(l.poseidonFunction,0n),this.nullifiersByChain[e]=new Set,this.encryptedOutputsByChain[e]=[],this.approvalsByChain[e]=new Map}),this.generateProofRemotely=e?.generateProofRemotely??!1,this.utxoUtils=new k.MultiThreadedUtxoUtils,this.cacheDevice=_.createCacheDevice(e),this.disableMerkleTreeUpdates=e?.disableMerkleTreeUpdates??!1}enforceRateLimit(e,n,r=1e3){let i=Date.now(),a=t.CustomJSONStringify(n),o=this.lastCallState.get(e);if(o&&o.argsKey===a&&i-o.timestamp<r)throw Error(`${e} was already called with the same arguments`);this.lastCallState.set(e,{timestamp:i,argsKey:a})}getProviderAdapter(e){let t=e;t||=this.ethereumProviderAdapter?r.chainIds.ethMainnet:this.solanaProviderAdapter?r.chainIds.solanaMainnet:r.chainIds.tronMainnet;let n;if(n=r.isSolanaLike(t)?this.solanaProviderAdapter:r.isTronLike(t)?this.tronProviderAdapter:this.ethereumProviderAdapter,!n)throw Error(`ProviderAdapter is not initialized`);return n}async initProviderAdapter(e,t){let n=r.chainIds.ethMainnet;t instanceof y.SolanaProviderAdapter?n=r.chainIds.solanaMainnet:t instanceof z.TronProviderAdapter&&(n=r.currentTronChainId),await this.updateProviderAdapter(n,t),t.initConnector(e);let i=await t.connectAndPatchProvider(e);await t.init(i),await this.setListeners()}getSigningMessage(e=i.LoginMessageMode.PROTOCOL){switch(e){case i.LoginMessageMode.PRIVATE_TRANSFER:return this.privateTransferSigningMessage;case i.LoginMessageMode.PROTOCOL:default:return this.signingMessage}}async initUserKeys(e=i.LoginMessageMode.PROTOCOL){let t=this.getSigningMessage(e);this.userKeys=new u.UserKeys(await this.getProviderAdapter().signMessage(t))}initUserKeysWithSignature(e){this.userKeys=new u.UserKeys(e)}async initUserKeysFromSeedPhrases(e){let t=e.join(` `),n=Q.ethers.toUtf8Bytes(t);this.userKeys=new u.UserKeys(Q.ethers.keccak256(n))}async resetMerkle(e){this.disableMerkleTreeUpdates||(e?.every(e=>this.isSelectedNetworkSupported(e))??!0)&&await O.resetMerkleTrees(this,e)}getTronWeb(){let e=this.tronProviderAdapter;if(!e)throw Error(`Tron provider adapter not initialized`);if(!(e instanceof z.TronProviderAdapter))throw Error(`Tron provider adapter is not a TronProviderAdapter`);let t=e.getTronWeb();if(!t)throw Error(`TronWeb not available`);return t}getSupportedChains(){return this.ethereumProviderAdapter&&this.solanaProviderAdapter?r.WALLET_SUPPORTED_CHAINS:this.ethereumProviderAdapter?r.HINKAL_SUPPORTED_CHAINS.filter(e=>!r.isSolanaLike(e)&&!r.isTronLike(e)):this.solanaProviderAdapter?r.HINKAL_SUPPORTED_CHAINS.filter(e=>r.isSolanaLike(e)):this.tronProviderAdapter?r.HINKAL_SUPPORTED_CHAINS.filter(e=>r.isTronLike(e)):[]}async waitForTransaction(e,t,n=1){return!!await this.getProviderAdapter(e).waitForTransaction(e,t,n)}getContract(e,t,n=void 0){return this.getProviderAdapter(e).getContract(e,t,n)}getContractWithFetcherByChainId(e,t,n=void 0){return v.getContractWithFetcherByChainId(e,t,n)}async signMessage(e){return await this.getProviderAdapter().signMessage(e)}async signTypedData(e,t,n){return await this.getProviderAdapter().signTypedData(e,t,n)}async signWithSubAccount(e,t,n,r){return M.hinkalSignSubAccount(e,t,n,r)}getContractWithSigner(e,t,n=``){return this.getProviderAdapter(e).getContractWithSigner(e,t,n)}getContractWithFetcher(e,t,n=``){return this.getProviderAdapter(e).getContractWithFetcher(e,t,n)}isSelectedNetworkSupported(e){return!!r.networkRegistry[e]}async switchNetwork(e){try{await this.getProviderAdapter().switchNetwork(e)}catch{throw Error(s.transactionErrorCodes.FAILED_TO_SWITCH_NETWORKS)}}isPermitterAvailable(e){return this.getProviderAdapter(e).isPermitterAvailable()}async disconnectFromConnector(){await this.ethereumProviderAdapter?.disconnectFromConnector(),await this.solanaProviderAdapter?.disconnectFromConnector(),await this.tronProviderAdapter?.disconnectFromConnector()}async resetProviderAdapters(){this.ethereumProviderAdapter=void 0,this.solanaProviderAdapter=void 0,this.tronProviderAdapter=void 0}async updateProviderAdapter(e,t){try{r.isSolanaLike(e)?(this.solanaProviderAdapter&&this.solanaProviderAdapter.release(),this.solanaProviderAdapter=t):r.isTronLike(e)?(this.tronProviderAdapter&&this.tronProviderAdapter.release(),this.tronProviderAdapter=t):(this.ethereumProviderAdapter&&this.ethereumProviderAdapter.release(),this.ethereumProviderAdapter=t)}catch(e){throw console.error(e),Error(`updateProviderAdapter failed, please try again.`)}}async setListeners(){this.ethereumProviderAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}}),this.solanaProviderAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}}),this.tronProviderAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}})}async onAccountChanged(){await this.ethereumProviderAdapter?.onAccountChanged(),await this.solanaProviderAdapter?.onAccountChanged(),await this.tronProviderAdapter?.onAccountChanged();let e=i.EventType.AccountChanged;typeof document<`u`?document?.dispatchEvent(new Event(e)):process?.emit(`message`,e,void 0)}async onChainChanged(e){e?await this.getProviderAdapter(e).onChainChanged(e):(await this.disconnectFromConnector(),ee.reloadPage())}async monitorConnectedAddress(e){await a.API.monitor(await this.getEthereumAddressByChain(e))}async getBalances(e,t,n,r,i=!1,a,o=!1){return g.getShieldedBalance(this,e,t,n,r,i,this.generateProofRemotely,a,o)}async getApprovedBalances(e,t=!1,n=!1){return C.getApprovedBalance(this,e,t,n)}async getTotalBalance(e,t,i,a=!1,o,s=!1){let l=i??await this.getEthereumAddressByChain(e),u=t??this.userKeys,d=await this.getBalances(e,u.getShieldedPrivateKey(),u.getShieldedPublicKey(),l,a,o,s),f=!r.isSolanaLike(e)&&!s?await this.getApprovedBalances(e,a,o):new Map,p=n.isExtension?await h.privateTokensDB.getPrivateTokens(e,l):c.getErc20TokensForChain(e),m=[];return p.forEach(e=>{let t=e.erc20TokenAddress.toLowerCase(),n=d.get(t),r=f.get(t),i={token:e,balance:(n?.balance??0n)+(r?.balance??0n),timestamp:n?.timestamp||r?.timestamp||`0`,nfts:n?.nfts||[]};m.push(i)}),m}async getStuckShieldedBalances(e,t,n){return(await this.getTotalBalance(e,t,n,!1,!1,!0)).filter(e=>e.balance>0n)}getSupportedPassportLinks(){return o.supportedPassportLinks}checkAccessToken(e,t){return p.checkHinkalAccessToken(this,e,t)}checkExternalTokenLimitsUSD(e,t,n){return ne.checkTokenLimitsUSD(e,t,n)}async getHinkalTreeRootHash(t){if(r.isSolanaLike(t)){let{hinkalIdl:e,hinkalAddress:n,originalDeployer:i}=r.networkRegistry[t].contractData;if(!e||!n||!i)throw Error(`Missing Solana configuration for chain ${t}`);let a=new $.PublicKey(i),o=d.getMerkleAccountPublicKey(new $.PublicKey(n),a);return q.fetchSolanaMerkleTreeRootHash(this.getSolanaProgram(e),o)}return this.getContractWithFetcherByChainId(t,e.ContractType.HinkalContract).getRootHash()}async getAccessTokenTreeRootHash(t){if(r.isSolanaLike(t)){let{hinkalIdl:e,hinkalAddress:n,originalDeployer:i}=r.networkRegistry[t].contractData;if(!e||!n||!i)throw Error(`Missing Solana configuration for chain ${t}`);let a=new $.PublicKey(i),o=d.getAccessTokenMerkleAccountPublicKey(new $.PublicKey(n),a);return q.fetchSolanaMerkleTreeRootHash(this.getSolanaProgram(e),o)}return this.getContractWithFetcherByChainId(t,e.ContractType.AccessTokenContract).getRootHash()}async resetMerkleTreesIfNecessary(e){let t=(await Promise.all((e??this.getSupportedChains()).map(async e=>{let[t,n]=await Promise.all([this.getHinkalTreeRootHash(e),this.getAccessTokenTreeRootHash(e)]);return{chainId:e,needsReset:BigInt(t)!==this.merkleTreeHinkalByChain[e].getRootHash()||BigInt(n)!==this.merkleTreeAccessTokenByChain[e].getRootHash()}}))).filter(e=>e.needsReset).map(e=>e.chainId);t.length>0&&(console.log(`resetting merkle tree in resetMerkleTreesIfNecessary for chains:`,t),await this.resetMerkle(t))}async getEthereumAddress(){let e=this.ethereumProviderAdapter??this.solanaProviderAdapter??this.tronProviderAdapter;if(!e)throw Error(`No provider adapter initialized`);return e.getAddress()}getEthereumAddressByChain(e){return this.getProviderAdapter(e).getAddress()}async getRandomRelay(e,t=!1){return(await a.API.getIdleRelay(e,t)).relay}getGasPrice(e){let t=this.getProviderAdapter(e);if(!t)throw Error(`Illegal State of providerAdapter in Hinkal: no providerAdapter initialized`);return t.getGasPrice(e)}getAPI(){return a.API}snapshotsClearInterval(){this.getSupportedChains().forEach(e=>{this.commitmentsSnapshotServiceByChain[e]?.intervalClear(),this.accessTokenSnapshotServiceByChain[e]?.intervalClear(),this.nullifierSnapshotServiceByChain[e]?.intervalClear(),this.approvalsSnapshotServiceByChain[e]?.intervalClear()})}checkTokenRegistry(t,n,i){if(r.isSolanaLike(t)){let{hinkalIdl:e,hinkalAddress:a,originalDeployer:o}=r.networkRegistry[t].contractData;if(!e||!a||!o)throw Error(`missing solana data`);return f.hinkalCheckSolanaTokenRegistry(this.getSolanaProgram(e),new $.PublicKey(o),n,i)}return r.isTronLike(t)?b.hinkalCheckTronTokenRegistry(n,i,t):b.hinkalCheckTokenRegistry(this.getContractWithFetcher(t,e.ContractType.HinkalHelperContract),n,i)}getRecipientInfo(){return j.getRecipientInfo(this)}getApprovedUtxos(e,t=!1){return C.getApprovedUtxos(this,e,t)}getApprovedUtxosForToken(e,t,n=!1){return C.getApprovedUtxosForToken(this,e,t,n)}async deposit(e,t,n=!0,r=!1){return S.hinkalDeposit(this,e,t,n,r)}async depositSolana(e,t){return T.hinkalSolanaDeposit(this,e,t)}async depositForOther(e,t,n,r=!0,i=!1){return this.enforceRateLimit(this.depositForOther.name,[e,t,n]),S.hinkalDepositForOther(this,e,t,n,r,i)}async depositSolanaForOther(e,t,n){return this.enforceRateLimit(this.depositSolanaForOther.name,[e,t,n]),T.hinkalSolanaDepositForOther(this,e,t,n)}async depositAndWithdraw(e,t,n,i,a,o,s,c=!0){return r.isSolanaLike(m.validateAndGetChainId([e]))?B.hinkalSolanaDepositAndWithdraw(this,e,t,n,i,a,o,s):w.hinkalDepositAndWithdraw(this,e,t,n,i,a,o,s,c)}async claimUtxo(e,t,n,i){return r.isSolanaLike(m.validateAndGetChainId([e]))?Z.hinkalSolanaClaimUtxo(this,e,t,n,i):Y.hinkalClaimUtxo(this,e,t,n,i)}async depositAndBridge(e,t,n,r,i,a,o=!0){return J.hinkalDepositAndBridge(this,e,t,n,r,i,a,o)}async prooflessDeposit(e,t,n,i){return r.isSolanaLike(m.validateAndGetChainId(e))?X.hinkalSolanaProoflessDeposit(this,e,t,n,i):P.hinkalProoflessDeposit(this,e,t,n,i)}getSolanaProgram(e){if(!this.solanaProviderAdapter)throw Error(`No provider adapter initialized`);if(!(`getSolanaProgram`in this.solanaProviderAdapter))throw Error(`Current provider adapter is not a Solana provider adapter`);return this.solanaProviderAdapter.getSolanaProgram(e)}getSolanaPublicKey(){if(!this.solanaProviderAdapter)throw Error(`No provider adapter initialized`);if(!(`getSolanaPublicKey`in this.solanaProviderAdapter))throw Error(`Current provider adapter is not a Solana provider adapter`);return this.solanaProviderAdapter.getSolanaPublicKey()}async transfer(e,t,n,i,a,o){return r.isSolanaLike(m.validateAndGetChainId(e))?H.hinkalSolanaTransfer(this,e,t,n,i,a,o):L.hinkalTransfer(this,e,t,n,i,a,o)}async withdraw(e,t,n,i,a,o,s){return r.isSolanaLike(m.validateAndGetChainId(e))?V.hinkalSolanaWithdraw(this,e,t,n,a,o,s):D.hinkalWithdraw(this,e,t,n,i,a,o,s)}async withdrawStuckUtxos(e,t){return re.hinkalWithdrawStuckUtxos(this,e,t)}async swap(e,t,n,i,a,o,s){return r.isSolanaLike(m.validateAndGetChainId(e))?this.swapSolana(e,t,i,a,o):E.hinkalSwap(this,e,t,n,i,a,o,s)}async swapSolana(e,t,n,r,i){let a=JSON.parse(n),o=BigInt(a.swapperAccountSalt),{instructionLists:s,addressLookupTableAccount:c}=a.data;return U.hinkalSolanaSwap(this,e,t,o,s,c,r,i)}async actionReceive(e,t,n,i,a,o){if(!a)throw Error(`subAccount is required`);return r.isSolanaLike(m.validateAndGetChainId(e))?K.hinkalSolanaProxyShield(this,e[0],t[0],a,void 0,o):N.hinkalActionReceive(this,e,t,n,i,a,o)}async actionPrivateWallet(e,t,n,r,i,a,o,s,c,l,u=!1,d,f,p){return this.enforceRateLimit(this.actionPrivateWallet.name,[e,t,n,r,i,a,o,s,c,p]),A.hinkalPrivateWallet(this,e,t,n,r,i,a,o,s,c,l,u,d,f,p)}async proxySwap(e,t,n,i,a,o,s,c,l=!1,u,d){return r.isSolanaLike(m.validateAndGetChainId(e))?G.hinkalSolanaProxySwap(this,e,t,i,o,s,c):F.hinkalProxySwap(this,e,t,n,i,a,o,s,c,l,u,d)}async proxyToPrivate(e,t,n,i,a,o,s){return r.isSolanaLike(m.validateAndGetChainId(e))?(this.enforceRateLimit(this.proxyToPrivate.name,[e[0],t[0],n,i]),K.hinkalSolanaProxyShield(this,e[0],t[0],n,i,s)):R.hinkalProxyToPrivate(this,e,t,i,a,o,n,s)}async proxySend(e,t,n,i,a,o,s){let c=m.validateAndGetChainId(e);if(r.isSolanaLike(c))return W.hinkalSolanaProxySend(this,e[0],t[0],n,i,s);let l=te.createTransaferEmporiumOpsBatch(this,c,e.map(e=>e.erc20TokenAddress),t,i),u=e.map((e,n)=>({token:e,amount:-1n*t[n]}));return await this.actionPrivateWallet(c,[],[],[],l,u,n,a,o,void 0,void 0,void 0,s,void 0)}async multiSendPrivateRecipients(e,t,n){return this.enforceRateLimit(this.multiSendPrivateRecipients.name,[e,t,n]),I.hinkalMultiSendPrivateRecipients(this,e,t,n)}areMerkleTreeUpdatesDisabled(){return this.disableMerkleTreeUpdates}updateMerkleTreeUpdates(e){this.disableMerkleTreeUpdates=e}};exports.Hinkal=ie;
|
|
@@ -84,7 +84,7 @@ var _e = class {
|
|
|
84
84
|
constructor(e) {
|
|
85
85
|
this.userKeys = new h(void 0), r.forEach((e) => {
|
|
86
86
|
this.merkleTreeHinkalByChain[e] = E.create(m, 0n), this.merkleTreeAccessTokenByChain[e] = E.create(m, 0n), this.nullifiersByChain[e] = /* @__PURE__ */ new Set(), this.encryptedOutputsByChain[e] = [], this.approvalsByChain[e] = /* @__PURE__ */ new Map();
|
|
87
|
-
}), this.generateProofRemotely = e?.generateProofRemotely ?? !
|
|
87
|
+
}), this.generateProofRemotely = e?.generateProofRemotely ?? !1, this.utxoUtils = new B(), this.cacheDevice = x(e), this.disableMerkleTreeUpdates = e?.disableMerkleTreeUpdates ?? !1;
|
|
88
88
|
}
|
|
89
89
|
enforceRateLimit(e, n, r = 1e3) {
|
|
90
90
|
let i = Date.now(), a = t(n), o = this.lastCallState.get(e);
|
package/package.json
CHANGED
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
var e = /* @__PURE__ */ ((r) => (r.ZKProof = "ZKProof", r.SnarkJS = "SnarkJS", r.UTXO = "UTXO", r))(e || {});
|
|
15
15
|
|
|
16
16
|
const n = async () => ({
|
|
17
|
-
[e.ZKProof]: await getWorkerURL(domain + '/0.2.
|
|
18
|
-
[e.SnarkJS]: await getWorkerURL(domain + '/0.2.
|
|
19
|
-
[e.UTXO]: await getWorkerURL(domain + '/0.2.
|
|
17
|
+
[e.ZKProof]: await getWorkerURL(domain + '/0.2.21/' + 'zkProofWorkerLauncher.js'),
|
|
18
|
+
[e.SnarkJS]: await getWorkerURL(domain + '/0.2.21/' + 'snarkjsWorkerLauncher.js'),
|
|
19
|
+
[e.UTXO]: await getWorkerURL(domain + '/0.2.21/' + 'utxoWorkerLauncher.js'),
|
|
20
20
|
});
|
|
21
21
|
exports.getWorkerViteURL = n;
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
var e = /* @__PURE__ */ ((r) => (r.ZKProof = "ZKProof", r.SnarkJS = "SnarkJS", r.UTXO = "UTXO", r))(e || {});
|
|
15
15
|
|
|
16
16
|
const n = async () => ({
|
|
17
|
-
[e.ZKProof]: await getWorkerURL(domain + '/0.2.
|
|
18
|
-
[e.SnarkJS]: await getWorkerURL(domain + '/0.2.
|
|
19
|
-
[e.UTXO]: await getWorkerURL(domain + '/0.2.
|
|
17
|
+
[e.ZKProof]: await getWorkerURL(domain + '/0.2.21/' + 'zkProofWorkerLauncher.js'),
|
|
18
|
+
[e.SnarkJS]: await getWorkerURL(domain + '/0.2.21/' + 'snarkjsWorkerLauncher.js'),
|
|
19
|
+
[e.UTXO]: await getWorkerURL(domain + '/0.2.21/' + 'utxoWorkerLauncher.js'),
|
|
20
20
|
});
|
|
21
21
|
export { n as getWorkerViteURL };
|