h_test_1 0.0.27 → 0.0.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.mjs +4 -2
- package/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
- package/data-structures/Hinkal/hinkalDeposit.mjs +57 -61
- package/data-structures/provider-adapter/IProviderAdapter.d.ts +1 -0
- package/functions/pre-transaction/getKycAndSignatureData.cjs +1 -1
- package/functions/pre-transaction/getKycAndSignatureData.mjs +12 -14
- package/functions/snarkjs/constructGeneralZkProof.cjs +1 -1
- package/functions/snarkjs/constructGeneralZkProof.mjs +99 -105
- package/functions/snarkjs/generateZkProof.cjs +1 -1
- package/functions/snarkjs/generateZkProof.mjs +9 -9
- package/package.json +1 -1
- package/providers/EthersProviderAdapter.cjs +1 -1
- package/providers/EthersProviderAdapter.d.ts +1 -0
- package/providers/EthersProviderAdapter.mjs +9 -6
- package/providers/SolanaProviderAdapter.cjs +1 -1
- package/providers/SolanaProviderAdapter.d.ts +1 -0
- package/providers/SolanaProviderAdapter.mjs +9 -6
- package/providers/TronProviderAdapter.cjs +1 -1
- package/providers/TronProviderAdapter.d.ts +1 -0
- package/providers/TronProviderAdapter.mjs +3 -0
- package/providers/WagmiProviderAdapter.cjs +1 -1
- package/providers/WagmiProviderAdapter.d.ts +2 -1
- package/providers/WagmiProviderAdapter.mjs +3 -0
- package/webworker/snarkjsWorker/snarkjsWorkerLauncher.cjs +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLauncher.mjs +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLogic.cjs +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLogic.mjs +26 -28
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("ethers"),k=require("../../types/hinkal.types.cjs"),S=require("../../types/ethereum-network.types.cjs"),U=require("./hinkalCheckSolanaTokenRegistry.cjs"),I=require("../../functions/web3/functionCalls/accessTokenCalls.cjs"),K=require("../../functions/web3/events/getShieldedBalance.cjs"),y=require("../crypto-keys/keys.cjs"),T=require("./hinkalDeposit.cjs"),W=require("./hinkalDepositAndWithdraw.cjs"),m=require("./hinkalSolanaDeposit.cjs"),x=require("./hinkalSwap.cjs"),F=require("./hinkalWithdraw.cjs"),N=require("./resetMerkleTrees.cjs"),M=require("../merkle-tree/MerkleTree.cjs"),_=require("../../error-handling/error-codes.constants.cjs"),R=require("../../crypto/poseidon.cjs"),o=require("../../constants/chains.constants.cjs");require("../../API/getServerURL.cjs");require("axios");require("../../constants/coingecko.constants.cjs");require("../../constants/server.constants.cjs");require("../http/HttpClient.cjs");const C=require("../../API/API.cjs");require("../../API/tenderly.api.cjs");require("../../constants/token-data/index.cjs");require("../../constants/contracts.constants.cjs");const O=require("../../constants/kyc.constants.cjs"),G=require("../../constants/vite.constants.cjs");require("../../constants/reorg-depths.constants.cjs");require("../../constants/addresses.constants.cjs");require("../../constants/token.limits.constants.cjs");require("../../constants/presale.constants.cjs");require("../../constants/activity.constants.cjs");require("../../constants/tasks.constants.cjs");require("../../constants/events.constants.cjs");require("../../constants/schedule.constants.cjs");require("../../constants/tokens.constants.cjs");const z=require("../../functions/utils/reloadPage.cjs"),j=require("../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.cjs"),$=require("./hinkalPrivateWallet.cjs"),J=require("../../functions/utils/cacheDevice.utils.cjs"),V=require("../../functions/web3/getContractMetadata.cjs"),Q=require("./hinkalGetRecipientInfo.cjs"),w=require("../../functions/web3/events/getApprovedBalance.cjs"),X=require("./hinkalSignSubAccount.cjs"),B=require("./hinkalCheckTokenRegistry.cjs"),Y=require("./hinkalActionReceive.cjs"),Z=require("../TokenDBs/PrivateTokensDB.cjs");require("idb-keyval");const ee=require("../../functions/utils/erc20tokenFunctions.cjs");require("multiformats");const P=require("@solana/web3.js");require("@solana/spl-token");require("tronweb");const d=require("../../functions/utils/token-check.utils.cjs");require("async-mutex");require("../../functions/utils/convertIntegrationProviderToExternalActionId.cjs");require("../../types/circom-data.types.cjs");require("../../types/activities.types.cjs");const L=require("../../functions/pre-transaction/solana.cjs");require("tweetnacl");require("bs58");require("@coral-xyz/anchor");require("buffer");require("libsodium-wrappers");require("lodash");require("../../functions/utils/userAgent.cjs");require("circomlibjs-hinkal-fork");require("process");require("../../providers/EthersProviderAdapter.cjs");const re=require("../../providers/SolanaProviderAdapter.cjs");require("node-forge");require("../../API/enclaveUtxoCalls.cjs");require("../../functions/web3/events/getInputUtxoAndBalance.cjs");require("../../functions/web3/getTokenHolder.cjs");const te=require("../../functions/private-wallet/emporium.helpers.cjs"),ie=require("./hinkalProoflessDeposit.cjs"),ae=require("./hinkalProxySwap.cjs"),ne=require("./hinkalMultiSend.cjs"),se=require("./hinkalTransfer.cjs"),oe=require("./hinkalProxyToPrivate.cjs"),E=require("../../providers/TronProviderAdapter.cjs"),he=require("./hinkalSolanaDepositAndWithdraw.cjs"),le=require("./hinkalSolanaWithdraw.cjs"),ce=require("./hinkalSolanaTransfer.cjs"),de=require("./hinkalSolanaSwap.cjs"),ue=require("./hinkalSolanaProxySend.cjs"),pe=require("./hinkalSolanaProxySwap.cjs"),H=require("./hinkalSolanaProxyShield.cjs"),D=require("../../functions/web3/fetchSolanaMerkleTreeRootHash.cjs"),ge=require("./hinkalDepositAndBridge.cjs"),ke=require("./hinkalClaimUtxo.cjs"),Pe=require("./hinkalSolanaProoflessDeposit.cjs"),ve=require("./hinkalSolanaClaimUtxo.cjs"),ye=require("./hinkalWithdrawStuckUtxos.cjs");class Ae{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;cacheDevice;generateProofRemotely;disableMerkleTreeUpdates;constructor(e){this.userKeys=new y.UserKeys(void 0),o.HINKAL_SUPPORTED_CHAINS.forEach(r=>{this.merkleTreeHinkalByChain[r]=M.MerkleTree.create(R.poseidonFunction,0n),this.merkleTreeAccessTokenByChain[r]=M.MerkleTree.create(R.poseidonFunction,0n),this.nullifiersByChain[r]=new Set,this.encryptedOutputsByChain[r]=[],this.approvalsByChain[r]=new Map}),this.generateProofRemotely=e?.generateProofRemotely??!0,this.utxoUtils=new j.MultiThreadedUtxoUtils,this.cacheDevice=J.createCacheDevice(e),this.disableMerkleTreeUpdates=e?.disableMerkleTreeUpdates??!1}async initProviderAdapter(e,r){const t=r instanceof re.SolanaProviderAdapter,i=r instanceof E.TronProviderAdapter;let a=o.chainIds.ethMainnet;t?a=o.chainIds.solanaMainnet:i&&(a=o.chainIds.tronMainnet),await this.updateProviderAdapter(a,r),t?this.solanaProviderAdapter?.initConnector(e):i?this.tronProviderAdapter?.initConnector(e):this.ethereumProviderAdapter?.initConnector(e);let n;t?n=await this.connectAndPatchProvider(!0,e):i?n=await r.connectAndPatchProvider(e):n=await this.connectAndPatchProvider(!1,e),await r.init(n),await this.setListeners()}getSigningMessage(e=k.LoginMessageMode.PROTOCOL){switch(e){case k.LoginMessageMode.PRIVATE_TRANSFER:return this.privateTransferSigningMessage;case k.LoginMessageMode.PROTOCOL:default:return this.signingMessage}}async initUserKeys(e=k.LoginMessageMode.PROTOCOL){const r=this.getSigningMessage(e);this.userKeys=new y.UserKeys(await this.getProviderAdapter().signMessage(r))}initUserKeysWithSignature(e){this.userKeys=new y.UserKeys(e)}async initUserKeysFromSeedPhrases(e){const r=e.join(" "),t=q.ethers.toUtf8Bytes(r),i=q.ethers.keccak256(t);this.userKeys=new y.UserKeys(i)}async resetMerkle(e){if(this.disableMerkleTreeUpdates)return;(e?.every(t=>this.isSelectedNetworkSupported(t))??!0)&&await N.resetMerkleTrees(this,e)}getProviderAdapter(e){let r=e,t;if(r||(this.ethereumProviderAdapter?r=o.chainIds.ethMainnet:this.solanaProviderAdapter?r=o.chainIds.solanaMainnet:r=o.chainIds.tronMainnet),o.isSolanaLike(r)?t=this.solanaProviderAdapter:o.isTronLike(r)?t=this.tronProviderAdapter:t=this.ethereumProviderAdapter,!t)throw new Error("ProviderAdapter is not initialized");return t}getTronWeb(){const e=this.tronProviderAdapter;if(!e)throw new Error("Tron provider adapter not initialized");if(!(e instanceof E.TronProviderAdapter))throw new Error("Tron provider adapter is not a TronProviderAdapter");const r=e.getTronWeb();if(!r)throw new Error("TronWeb not available");return r}getSupportedChains(){return this.ethereumProviderAdapter&&this.solanaProviderAdapter?o.WALLET_SUPPORTED_CHAINS:this.ethereumProviderAdapter?o.HINKAL_SUPPORTED_CHAINS.filter(e=>!o.isSolanaLike(e)&&!o.isTronLike(e)):this.solanaProviderAdapter?o.HINKAL_SUPPORTED_CHAINS.filter(e=>o.isSolanaLike(e)):this.tronProviderAdapter?o.HINKAL_SUPPORTED_CHAINS.filter(e=>o.isTronLike(e)):[]}async waitForTransaction(e,r,t=1){return!!await this.getProviderAdapter(e).waitForTransaction(e,r,t)}getContract(e,r,t=void 0){return this.getProviderAdapter(e).getContract(e,r,t)}getContractWithFetcherByChainId(e,r,t=void 0){return V.getContractWithFetcherByChainId(e,r,t)}async signMessage(e){return await this.getProviderAdapter().signMessage(e)}async signTypedData(e,r,t){return await this.getProviderAdapter().signTypedData(e,r,t)}async signWithSubAccount(e,r,t,i){return X.hinkalSignSubAccount(e,r,t,i)}getContractWithSigner(e,r,t=""){return this.getProviderAdapter(e).getContractWithSigner(e,r,t)}getContractWithFetcher(e,r,t=""){return this.getProviderAdapter(e).getContractWithFetcher(e,r,t)}isSelectedNetworkSupported(e){return!!o.networkRegistry[e]}async switchNetwork(e){try{await this.getProviderAdapter().switchNetwork(e)}catch{throw new Error(_.transactionErrorCodes.FAILED_TO_SWITCH_NETWORKS)}}isPermitterAvailable(e){return this.getProviderAdapter(e).isPermitterAvailable()}async connectAndPatchProvider(e,r){return await this.getProviderAdapter(e?o.chainIds.solanaMainnet:o.chainIds.ethMainnet).connectAndPatchProvider(r)}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,r){try{o.isSolanaLike(e)?(this.solanaProviderAdapter&&this.solanaProviderAdapter.release(),this.solanaProviderAdapter=r):o.isTronLike(e)?(this.tronProviderAdapter&&this.tronProviderAdapter.release(),this.tronProviderAdapter=r):(this.ethereumProviderAdapter&&this.ethereumProviderAdapter.release(),this.ethereumProviderAdapter=r)}catch(t){throw console.error(t),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();const e=k.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(),z.reloadPage())}async monitorConnectedAddress(e){await C.API.monitor(await this.getEthereumAddressByChain(e))}async getBalances(e,r,t,i,a=!1,n,s=!1){return K.getShieldedBalance(this,e,r,t,i,a,this.generateProofRemotely,n,s)}async getApprovedBalances(e,r=!1,t=!1){return w.getApprovedBalance(this,e,r,t)}async getTotalBalance(e,r,t,i=!1,a,n=!1){const s=t??await this.getEthereumAddressByChain(e),h=r??this.userKeys,l=await this.getBalances(e,h.getShieldedPrivateKey(),h.getShieldedPublicKey(),s,i,a,n),u=!o.isSolanaLike(e)&&!n?await this.getApprovedBalances(e,i,a):new Map,p=G.isExtension?await Z.privateTokensDB.getPrivateTokens(e,s):ee.getErc20TokensForChain(e),c=[];return p.forEach(g=>{const v=g.erc20TokenAddress.toLowerCase(),A=l.get(v),f=u.get(v),b={token:g,balance:(A?.balance??0n)+(f?.balance??0n),timestamp:A?.timestamp||f?.timestamp||"0",nfts:A?.nfts||[]};c.push(b)}),c}async getStuckShieldedBalances(e,r,t){return(await this.getTotalBalance(e,r,t,!1,!1,!0)).filter(a=>a.balance>0n)}getSupportedPassportLinks(){return O.supportedPassportLinks}checkAccessToken(e,r){return I.checkHinkalAccessToken(this,e,r)}async getHinkalTreeRootHash(e){if(o.isSolanaLike(e)){const{hinkalIdl:t,hinkalAddress:i,originalDeployer:a}=o.networkRegistry[e].contractData;if(!t||!i||!a)throw new Error(`Missing Solana configuration for chain ${e}`);const n=new P.PublicKey(a),s=new P.PublicKey(i),h=L.getMerkleAccountPublicKey(s,n),l=this.getSolanaProgram(t);return D.fetchSolanaMerkleTreeRootHash(l,h)}return this.getContractWithFetcherByChainId(e,S.ContractType.HinkalContract).getRootHash()}async getAccessTokenTreeRootHash(e){if(o.isSolanaLike(e)){const{hinkalIdl:t,hinkalAddress:i,originalDeployer:a}=o.networkRegistry[e].contractData;if(!t||!i||!a)throw new Error(`Missing Solana configuration for chain ${e}`);const n=new P.PublicKey(a),s=new P.PublicKey(i),h=L.getAccessTokenMerkleAccountPublicKey(s,n),l=this.getSolanaProgram(t);return D.fetchSolanaMerkleTreeRootHash(l,h)}return this.getContractWithFetcherByChainId(e,S.ContractType.AccessTokenContract).getRootHash()}async resetMerkleTreesIfNecessary(e){const t=(await Promise.all((e??this.getSupportedChains()).map(async i=>{const[a,n]=await Promise.all([this.getHinkalTreeRootHash(i),this.getAccessTokenTreeRootHash(i)]),s=BigInt(a)!==this.merkleTreeHinkalByChain[i].getRootHash()||BigInt(n)!==this.merkleTreeAccessTokenByChain[i].getRootHash();return{chainId:i,needsReset:s}}))).filter(i=>i.needsReset).map(i=>i.chainId);t.length>0&&(console.log("resetting merkle tree in resetMerkleTreesIfNecessary for chains:",t),await this.resetMerkle(t))}async getEthereumAddress(){const e=this.ethereumProviderAdapter??this.solanaProviderAdapter??this.tronProviderAdapter;if(!e)throw new Error("No provider adapter initialized");return e.getAddress()}getEthereumAddressByChain(e){return this.getProviderAdapter(e).getAddress()}async getRandomRelay(e,r=!1){return(await C.API.getIdleRelay(e,r)).relay}getGasPrice(e){const r=this.getProviderAdapter(e);if(!r)throw new Error("Illegal State of providerAdapter in Hinkal: no providerAdapter initialized");return r.getGasPrice(e)}getAPI(){return C.API}snapshotsClearInterval(){this.getSupportedChains().forEach(e=>{this.commitmentsSnapshotServiceByChain[e]?.intervalClear(),this.accessTokenSnapshotServiceByChain[e]?.intervalClear(),this.nullifierSnapshotServiceByChain[e]?.intervalClear(),this.approvalsSnapshotServiceByChain[e]?.intervalClear()})}checkTokenRegistry(e,r,t){if(o.isSolanaLike(e)){const{hinkalIdl:a,hinkalAddress:n,originalDeployer:s}=o.networkRegistry[e].contractData;if(!a||!n||!s)throw new Error("missing solana data");const h=this.getSolanaProgram(a),l=new P.PublicKey(s);return U.hinkalCheckSolanaTokenRegistry(h,l,r,t)}if(o.isTronLike(e))return B.hinkalCheckTronTokenRegistry(r,t,e);const i=this.getContractWithFetcher(e,S.ContractType.HinkalHelperContract);return B.hinkalCheckTokenRegistry(i,r,t)}getRecipientInfo(){return Q.getRecipientInfo(this)}getApprovedUtxos(e,r=!1){return w.getApprovedUtxos(this,e,r)}getApprovedUtxosForToken(e,r,t=!1){return w.getApprovedUtxosForToken(this,e,r,t)}async deposit(e,r,t=!0,i=!1){return T.hinkalDeposit(this,e,r,t,i)}async depositSolana(e,r){return m.hinkalSolanaDeposit(this,e,r)}async depositForOther(e,r,t,i=!0,a=!1){return T.hinkalDepositForOther(this,e,r,t,i,a)}async depositSolanaForOther(e,r,t){return m.hinkalSolanaDepositForOther(this,e,r,t)}async depositAndWithdraw(e,r,t,i,a,n,s,h=!0){const l=d.validateAndGetChainId([e]);return o.isSolanaLike(l)?he.hinkalSolanaDepositAndWithdraw(this,e,r,t,i,a,n,s):W.hinkalDepositAndWithdraw(this,e,r,t,i,a,n,s,h)}async claimUtxo(e,r,t,i){const a=d.validateAndGetChainId([e]);return o.isSolanaLike(a)?ve.hinkalSolanaClaimUtxo(this,e,r,t,i):ke.hinkalClaimUtxo(this,e,r,t,i)}async depositAndBridge(e,r,t,i,a,n,s=!0){return ge.hinkalDepositAndBridge(this,e,r,t,i,a,n,s)}async prooflessDeposit(e,r,t,i){const a=d.validateAndGetChainId(e);return o.isSolanaLike(a)?Pe.hinkalSolanaProoflessDeposit(this,e,r,t,i):ie.hinkalProoflessDeposit(this,e,r,t,i)}getSolanaProgram(e){if(!this.solanaProviderAdapter)throw new Error("No provider adapter initialized");if(!("getSolanaProgram"in this.solanaProviderAdapter))throw new Error("Current provider adapter is not a Solana provider adapter");return this.solanaProviderAdapter.getSolanaProgram(e)}getSolanaPublicKey(){if(!this.solanaProviderAdapter)throw new Error("No provider adapter initialized");if(!("getSolanaPublicKey"in this.solanaProviderAdapter))throw new Error("Current provider adapter is not a Solana provider adapter");return this.solanaProviderAdapter.getSolanaPublicKey()}async transfer(e,r,t,i,a,n){const s=d.validateAndGetChainId(e);return o.isSolanaLike(s)?ce.hinkalSolanaTransfer(this,e,r,t,i,a,n):se.hinkalTransfer(this,e,r,t,i,a,n)}async withdraw(e,r,t,i,a,n,s){const h=d.validateAndGetChainId(e);return o.isSolanaLike(h)?le.hinkalSolanaWithdraw(this,e,r,t,a,n,s):F.hinkalWithdraw(this,e,r,t,i,a,n,s)}async withdrawStuckUtxos(e,r){return ye.hinkalWithdrawStuckUtxos(this,e,r)}async swap(e,r,t,i,a,n,s){const h=d.validateAndGetChainId(e);return o.isSolanaLike(h)?this.swapSolana(e,r,i,a,n):x.hinkalSwap(this,e,r,t,i,a,n,s)}async swapSolana(e,r,t,i,a){const n=JSON.parse(t),s=BigInt(n.swapperAccountSalt),{instructionLists:h,addressLookupTableAccount:l}=n.data;return de.hinkalSolanaSwap(this,e,r,s,h,l,i,a)}async actionReceive(e,r,t,i,a,n){if(!a)throw new Error("subAccount is required");const s=d.validateAndGetChainId(e);return o.isSolanaLike(s)?H.hinkalSolanaProxyShield(this,e[0],r[0],a,void 0,n):Y.hinkalActionReceive(this,e,r,t,i,a,n)}async actionPrivateWallet(e,r,t,i,a,n,s,h,l,u,p=!1,c,g,v){return $.hinkalPrivateWallet(this,e,r,t,i,a,n,s,h,l,u,p,c,g,v)}async proxySwap(e,r,t,i,a,n,s,h,l=!1,u,p){const c=d.validateAndGetChainId(e);return o.isSolanaLike(c)?pe.hinkalSolanaProxySwap(this,e,r,i,n,s,h):ae.hinkalProxySwap(this,e,r,t,i,a,n,s,h,l,u,p)}async proxyToPrivate(e,r,t,i,a,n,s){const h=d.validateAndGetChainId(e);return o.isSolanaLike(h)?H.hinkalSolanaProxyShield(this,e[0],r[0],t,i,s):oe.hinkalProxyToPrivate(this,e,r,i,a,n,t,s)}async proxySend(e,r,t,i,a,n,s){const h=d.validateAndGetChainId(e);if(o.isSolanaLike(h))return ue.hinkalSolanaProxySend(this,e[0],r[0],t,i,s);const l=te.createTransaferEmporiumOpsBatch(this,h,e.map(c=>c.erc20TokenAddress),r,i),u=e.map((c,g)=>({token:c,amount:-1n*r[g]}));return await this.actionPrivateWallet(h,[],[],[],l,u,t,a,n,void 0,void 0,void 0,s,void 0)}async multiSendPrivateRecipients(e,r,t){return ne.hinkalMultiSendPrivateRecipients(this,e,r,t)}areMerkleTreeUpdatesDisabled(){return this.disableMerkleTreeUpdates}updateMerkleTreeUpdates(e){this.disableMerkleTreeUpdates=e}}exports.Hinkal=Ae;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("ethers"),k=require("../../types/hinkal.types.cjs"),S=require("../../types/ethereum-network.types.cjs"),U=require("./hinkalCheckSolanaTokenRegistry.cjs"),I=require("../../functions/web3/functionCalls/accessTokenCalls.cjs"),K=require("../../functions/web3/events/getShieldedBalance.cjs"),y=require("../crypto-keys/keys.cjs"),T=require("./hinkalDeposit.cjs"),W=require("./hinkalDepositAndWithdraw.cjs"),m=require("./hinkalSolanaDeposit.cjs"),x=require("./hinkalSwap.cjs"),F=require("./hinkalWithdraw.cjs"),N=require("./resetMerkleTrees.cjs"),M=require("../merkle-tree/MerkleTree.cjs"),_=require("../../error-handling/error-codes.constants.cjs"),R=require("../../crypto/poseidon.cjs"),o=require("../../constants/chains.constants.cjs");require("../../API/getServerURL.cjs");require("axios");require("../../constants/coingecko.constants.cjs");require("../../constants/server.constants.cjs");require("../http/HttpClient.cjs");const C=require("../../API/API.cjs");require("../../API/tenderly.api.cjs");require("../../constants/token-data/index.cjs");require("../../constants/contracts.constants.cjs");const O=require("../../constants/kyc.constants.cjs"),G=require("../../constants/vite.constants.cjs");require("../../constants/reorg-depths.constants.cjs");require("../../constants/addresses.constants.cjs");require("../../constants/token.limits.constants.cjs");require("../../constants/presale.constants.cjs");require("../../constants/activity.constants.cjs");require("../../constants/tasks.constants.cjs");require("../../constants/events.constants.cjs");require("../../constants/schedule.constants.cjs");require("../../constants/tokens.constants.cjs");const z=require("../../functions/utils/reloadPage.cjs"),j=require("../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.cjs"),$=require("./hinkalPrivateWallet.cjs"),J=require("../../functions/utils/cacheDevice.utils.cjs"),V=require("../../functions/web3/getContractMetadata.cjs"),Q=require("./hinkalGetRecipientInfo.cjs"),w=require("../../functions/web3/events/getApprovedBalance.cjs"),X=require("./hinkalSignSubAccount.cjs"),B=require("./hinkalCheckTokenRegistry.cjs"),Y=require("./hinkalActionReceive.cjs"),Z=require("../TokenDBs/PrivateTokensDB.cjs");require("idb-keyval");const ee=require("../../functions/utils/erc20tokenFunctions.cjs");require("multiformats");const P=require("@solana/web3.js");require("@solana/spl-token");require("tronweb");const d=require("../../functions/utils/token-check.utils.cjs");require("async-mutex");require("../../functions/utils/convertIntegrationProviderToExternalActionId.cjs");require("../../types/circom-data.types.cjs");require("../../types/activities.types.cjs");const L=require("../../functions/pre-transaction/solana.cjs");require("tweetnacl");require("bs58");require("@coral-xyz/anchor");require("buffer");require("libsodium-wrappers");require("lodash");require("../../functions/utils/userAgent.cjs");require("circomlibjs-hinkal-fork");require("process");require("../../providers/EthersProviderAdapter.cjs");const re=require("../../providers/SolanaProviderAdapter.cjs");require("node-forge");require("../../API/enclaveUtxoCalls.cjs");require("../../functions/web3/events/getInputUtxoAndBalance.cjs");require("../../functions/web3/getTokenHolder.cjs");const te=require("../../functions/private-wallet/emporium.helpers.cjs"),ie=require("./hinkalProoflessDeposit.cjs"),ae=require("./hinkalProxySwap.cjs"),ne=require("./hinkalMultiSend.cjs"),se=require("./hinkalTransfer.cjs"),oe=require("./hinkalProxyToPrivate.cjs"),E=require("../../providers/TronProviderAdapter.cjs"),he=require("./hinkalSolanaDepositAndWithdraw.cjs"),le=require("./hinkalSolanaWithdraw.cjs"),ce=require("./hinkalSolanaTransfer.cjs"),de=require("./hinkalSolanaSwap.cjs"),ue=require("./hinkalSolanaProxySend.cjs"),pe=require("./hinkalSolanaProxySwap.cjs"),H=require("./hinkalSolanaProxyShield.cjs"),D=require("../../functions/web3/fetchSolanaMerkleTreeRootHash.cjs"),ge=require("./hinkalDepositAndBridge.cjs"),ke=require("./hinkalClaimUtxo.cjs"),Pe=require("./hinkalSolanaProoflessDeposit.cjs"),ve=require("./hinkalSolanaClaimUtxo.cjs"),ye=require("./hinkalWithdrawStuckUtxos.cjs");class Ae{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;cacheDevice;generateProofRemotely;disableMerkleTreeUpdates;constructor(e){this.userKeys=new y.UserKeys(void 0),o.HINKAL_SUPPORTED_CHAINS.forEach(r=>{this.merkleTreeHinkalByChain[r]=M.MerkleTree.create(R.poseidonFunction,0n),this.merkleTreeAccessTokenByChain[r]=M.MerkleTree.create(R.poseidonFunction,0n),this.nullifiersByChain[r]=new Set,this.encryptedOutputsByChain[r]=[],this.approvalsByChain[r]=new Map}),this.generateProofRemotely=e?.generateProofRemotely??!0,this.utxoUtils=new j.MultiThreadedUtxoUtils,this.cacheDevice=J.createCacheDevice(e),this.disableMerkleTreeUpdates=e?.disableMerkleTreeUpdates??!1}async initProviderAdapter(e,r){const t=r instanceof re.SolanaProviderAdapter,i=r instanceof E.TronProviderAdapter;let a=o.chainIds.ethMainnet;t?a=o.chainIds.solanaMainnet:i&&(a=o.chainIds.tronMainnet),await this.updateProviderAdapter(a,r),t?this.solanaProviderAdapter?.initConnector(e):i?this.tronProviderAdapter?.initConnector(e):this.ethereumProviderAdapter?.initConnector(e);let n;t?n=await this.connectAndPatchProvider(!0,e):i?n=await r.connectAndPatchProvider(e):n=await this.connectAndPatchProvider(!1,e),await r.init(n),await this.setListeners()}getSigningMessage(e=k.LoginMessageMode.PROTOCOL){switch(e){case k.LoginMessageMode.PRIVATE_TRANSFER:return this.privateTransferSigningMessage;case k.LoginMessageMode.PROTOCOL:default:return this.signingMessage}}async initUserKeys(e=k.LoginMessageMode.PROTOCOL){const r=this.getSigningMessage(e);this.userKeys=new y.UserKeys(await this.getProviderAdapter().signMessage(r))}initUserKeysWithSignature(e){this.userKeys=new y.UserKeys(e)}async initUserKeysFromSeedPhrases(e){const r=e.join(" "),t=q.ethers.toUtf8Bytes(r),i=q.ethers.keccak256(t);this.userKeys=new y.UserKeys(i)}async resetMerkle(e){if(this.disableMerkleTreeUpdates)return;(e?.every(t=>this.isSelectedNetworkSupported(t))??!0)&&await N.resetMerkleTrees(this,e)}getProviderAdapter(e){let r=e;r||(this.ethereumProviderAdapter?r=o.chainIds.ethMainnet:this.solanaProviderAdapter?r=o.chainIds.solanaMainnet:r=o.chainIds.tronMainnet);let t;if(o.isSolanaLike(r)?t=this.solanaProviderAdapter:o.isTronLike(r)?t=this.tronProviderAdapter:t=this.ethereumProviderAdapter,!t)throw new Error("ProviderAdapter is not initialized");return t}getTronWeb(){const e=this.tronProviderAdapter;if(!e)throw new Error("Tron provider adapter not initialized");if(!(e instanceof E.TronProviderAdapter))throw new Error("Tron provider adapter is not a TronProviderAdapter");const r=e.getTronWeb();if(!r)throw new Error("TronWeb not available");return r}getSupportedChains(){return this.ethereumProviderAdapter&&this.solanaProviderAdapter?o.WALLET_SUPPORTED_CHAINS:this.ethereumProviderAdapter?o.HINKAL_SUPPORTED_CHAINS.filter(e=>!o.isSolanaLike(e)&&!o.isTronLike(e)):this.solanaProviderAdapter?o.HINKAL_SUPPORTED_CHAINS.filter(e=>o.isSolanaLike(e)):this.tronProviderAdapter?o.HINKAL_SUPPORTED_CHAINS.filter(e=>o.isTronLike(e)):[]}async waitForTransaction(e,r,t=1){return!!await this.getProviderAdapter(e).waitForTransaction(e,r,t)}getContract(e,r,t=void 0){return this.getProviderAdapter(e).getContract(e,r,t)}getContractWithFetcherByChainId(e,r,t=void 0){return V.getContractWithFetcherByChainId(e,r,t)}async signMessage(e){return await this.getProviderAdapter().signMessage(e)}async signTypedData(e,r,t){return await this.getProviderAdapter().signTypedData(e,r,t)}async signWithSubAccount(e,r,t,i){return X.hinkalSignSubAccount(e,r,t,i)}getContractWithSigner(e,r,t=""){return this.getProviderAdapter(e).getContractWithSigner(e,r,t)}getContractWithFetcher(e,r,t=""){return this.getProviderAdapter(e).getContractWithFetcher(e,r,t)}isSelectedNetworkSupported(e){return!!o.networkRegistry[e]}async switchNetwork(e){try{await this.getProviderAdapter().switchNetwork(e)}catch{throw new Error(_.transactionErrorCodes.FAILED_TO_SWITCH_NETWORKS)}}isPermitterAvailable(e){return this.getProviderAdapter(e).isPermitterAvailable()}async connectAndPatchProvider(e,r){return await this.getProviderAdapter(e?o.chainIds.solanaMainnet:o.chainIds.ethMainnet).connectAndPatchProvider(r)}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,r){try{o.isSolanaLike(e)?(this.solanaProviderAdapter&&this.solanaProviderAdapter.release(),this.solanaProviderAdapter=r):o.isTronLike(e)?(this.tronProviderAdapter&&this.tronProviderAdapter.release(),this.tronProviderAdapter=r):(this.ethereumProviderAdapter&&this.ethereumProviderAdapter.release(),this.ethereumProviderAdapter=r)}catch(t){throw console.error(t),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();const e=k.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(),z.reloadPage())}async monitorConnectedAddress(e){await C.API.monitor(await this.getEthereumAddressByChain(e))}async getBalances(e,r,t,i,a=!1,n,s=!1){return K.getShieldedBalance(this,e,r,t,i,a,this.generateProofRemotely,n,s)}async getApprovedBalances(e,r=!1,t=!1){return w.getApprovedBalance(this,e,r,t)}async getTotalBalance(e,r,t,i=!1,a,n=!1){const s=t??await this.getEthereumAddressByChain(e),h=r??this.userKeys,l=await this.getBalances(e,h.getShieldedPrivateKey(),h.getShieldedPublicKey(),s,i,a,n),u=!o.isSolanaLike(e)&&!n?await this.getApprovedBalances(e,i,a):new Map,p=G.isExtension?await Z.privateTokensDB.getPrivateTokens(e,s):ee.getErc20TokensForChain(e),c=[];return p.forEach(g=>{const v=g.erc20TokenAddress.toLowerCase(),A=l.get(v),f=u.get(v),b={token:g,balance:(A?.balance??0n)+(f?.balance??0n),timestamp:A?.timestamp||f?.timestamp||"0",nfts:A?.nfts||[]};c.push(b)}),c}async getStuckShieldedBalances(e,r,t){return(await this.getTotalBalance(e,r,t,!1,!1,!0)).filter(a=>a.balance>0n)}getSupportedPassportLinks(){return O.supportedPassportLinks}checkAccessToken(e,r){return I.checkHinkalAccessToken(this,e,r)}async getHinkalTreeRootHash(e){if(o.isSolanaLike(e)){const{hinkalIdl:t,hinkalAddress:i,originalDeployer:a}=o.networkRegistry[e].contractData;if(!t||!i||!a)throw new Error(`Missing Solana configuration for chain ${e}`);const n=new P.PublicKey(a),s=new P.PublicKey(i),h=L.getMerkleAccountPublicKey(s,n),l=this.getSolanaProgram(t);return D.fetchSolanaMerkleTreeRootHash(l,h)}return this.getContractWithFetcherByChainId(e,S.ContractType.HinkalContract).getRootHash()}async getAccessTokenTreeRootHash(e){if(o.isSolanaLike(e)){const{hinkalIdl:t,hinkalAddress:i,originalDeployer:a}=o.networkRegistry[e].contractData;if(!t||!i||!a)throw new Error(`Missing Solana configuration for chain ${e}`);const n=new P.PublicKey(a),s=new P.PublicKey(i),h=L.getAccessTokenMerkleAccountPublicKey(s,n),l=this.getSolanaProgram(t);return D.fetchSolanaMerkleTreeRootHash(l,h)}return this.getContractWithFetcherByChainId(e,S.ContractType.AccessTokenContract).getRootHash()}async resetMerkleTreesIfNecessary(e){const t=(await Promise.all((e??this.getSupportedChains()).map(async i=>{const[a,n]=await Promise.all([this.getHinkalTreeRootHash(i),this.getAccessTokenTreeRootHash(i)]),s=BigInt(a)!==this.merkleTreeHinkalByChain[i].getRootHash()||BigInt(n)!==this.merkleTreeAccessTokenByChain[i].getRootHash();return{chainId:i,needsReset:s}}))).filter(i=>i.needsReset).map(i=>i.chainId);t.length>0&&(console.log("resetting merkle tree in resetMerkleTreesIfNecessary for chains:",t),await this.resetMerkle(t))}async getEthereumAddress(){const e=this.ethereumProviderAdapter??this.solanaProviderAdapter??this.tronProviderAdapter;if(!e)throw new Error("No provider adapter initialized");return e.getAddress()}getEthereumAddressByChain(e){return this.getProviderAdapter(e).getAddress()}async getRandomRelay(e,r=!1){return(await C.API.getIdleRelay(e,r)).relay}getGasPrice(e){const r=this.getProviderAdapter(e);if(!r)throw new Error("Illegal State of providerAdapter in Hinkal: no providerAdapter initialized");return r.getGasPrice(e)}getAPI(){return C.API}snapshotsClearInterval(){this.getSupportedChains().forEach(e=>{this.commitmentsSnapshotServiceByChain[e]?.intervalClear(),this.accessTokenSnapshotServiceByChain[e]?.intervalClear(),this.nullifierSnapshotServiceByChain[e]?.intervalClear(),this.approvalsSnapshotServiceByChain[e]?.intervalClear()})}checkTokenRegistry(e,r,t){if(o.isSolanaLike(e)){const{hinkalIdl:a,hinkalAddress:n,originalDeployer:s}=o.networkRegistry[e].contractData;if(!a||!n||!s)throw new Error("missing solana data");const h=this.getSolanaProgram(a),l=new P.PublicKey(s);return U.hinkalCheckSolanaTokenRegistry(h,l,r,t)}if(o.isTronLike(e))return B.hinkalCheckTronTokenRegistry(r,t,e);const i=this.getContractWithFetcher(e,S.ContractType.HinkalHelperContract);return B.hinkalCheckTokenRegistry(i,r,t)}getRecipientInfo(){return Q.getRecipientInfo(this)}getApprovedUtxos(e,r=!1){return w.getApprovedUtxos(this,e,r)}getApprovedUtxosForToken(e,r,t=!1){return w.getApprovedUtxosForToken(this,e,r,t)}async deposit(e,r,t=!0,i=!1){return T.hinkalDeposit(this,e,r,t,i)}async depositSolana(e,r){return m.hinkalSolanaDeposit(this,e,r)}async depositForOther(e,r,t,i=!0,a=!1){return T.hinkalDepositForOther(this,e,r,t,i,a)}async depositSolanaForOther(e,r,t){return m.hinkalSolanaDepositForOther(this,e,r,t)}async depositAndWithdraw(e,r,t,i,a,n,s,h=!0){const l=d.validateAndGetChainId([e]);return o.isSolanaLike(l)?he.hinkalSolanaDepositAndWithdraw(this,e,r,t,i,a,n,s):W.hinkalDepositAndWithdraw(this,e,r,t,i,a,n,s,h)}async claimUtxo(e,r,t,i){const a=d.validateAndGetChainId([e]);return o.isSolanaLike(a)?ve.hinkalSolanaClaimUtxo(this,e,r,t,i):ke.hinkalClaimUtxo(this,e,r,t,i)}async depositAndBridge(e,r,t,i,a,n,s=!0){return ge.hinkalDepositAndBridge(this,e,r,t,i,a,n,s)}async prooflessDeposit(e,r,t,i){const a=d.validateAndGetChainId(e);return o.isSolanaLike(a)?Pe.hinkalSolanaProoflessDeposit(this,e,r,t,i):ie.hinkalProoflessDeposit(this,e,r,t,i)}getSolanaProgram(e){if(!this.solanaProviderAdapter)throw new Error("No provider adapter initialized");if(!("getSolanaProgram"in this.solanaProviderAdapter))throw new Error("Current provider adapter is not a Solana provider adapter");return this.solanaProviderAdapter.getSolanaProgram(e)}getSolanaPublicKey(){if(!this.solanaProviderAdapter)throw new Error("No provider adapter initialized");if(!("getSolanaPublicKey"in this.solanaProviderAdapter))throw new Error("Current provider adapter is not a Solana provider adapter");return this.solanaProviderAdapter.getSolanaPublicKey()}async transfer(e,r,t,i,a,n){const s=d.validateAndGetChainId(e);return o.isSolanaLike(s)?ce.hinkalSolanaTransfer(this,e,r,t,i,a,n):se.hinkalTransfer(this,e,r,t,i,a,n)}async withdraw(e,r,t,i,a,n,s){const h=d.validateAndGetChainId(e);return o.isSolanaLike(h)?le.hinkalSolanaWithdraw(this,e,r,t,a,n,s):F.hinkalWithdraw(this,e,r,t,i,a,n,s)}async withdrawStuckUtxos(e,r){return ye.hinkalWithdrawStuckUtxos(this,e,r)}async swap(e,r,t,i,a,n,s){const h=d.validateAndGetChainId(e);return o.isSolanaLike(h)?this.swapSolana(e,r,i,a,n):x.hinkalSwap(this,e,r,t,i,a,n,s)}async swapSolana(e,r,t,i,a){const n=JSON.parse(t),s=BigInt(n.swapperAccountSalt),{instructionLists:h,addressLookupTableAccount:l}=n.data;return de.hinkalSolanaSwap(this,e,r,s,h,l,i,a)}async actionReceive(e,r,t,i,a,n){if(!a)throw new Error("subAccount is required");const s=d.validateAndGetChainId(e);return o.isSolanaLike(s)?H.hinkalSolanaProxyShield(this,e[0],r[0],a,void 0,n):Y.hinkalActionReceive(this,e,r,t,i,a,n)}async actionPrivateWallet(e,r,t,i,a,n,s,h,l,u,p=!1,c,g,v){return $.hinkalPrivateWallet(this,e,r,t,i,a,n,s,h,l,u,p,c,g,v)}async proxySwap(e,r,t,i,a,n,s,h,l=!1,u,p){const c=d.validateAndGetChainId(e);return o.isSolanaLike(c)?pe.hinkalSolanaProxySwap(this,e,r,i,n,s,h):ae.hinkalProxySwap(this,e,r,t,i,a,n,s,h,l,u,p)}async proxyToPrivate(e,r,t,i,a,n,s){const h=d.validateAndGetChainId(e);return o.isSolanaLike(h)?H.hinkalSolanaProxyShield(this,e[0],r[0],t,i,s):oe.hinkalProxyToPrivate(this,e,r,i,a,n,t,s)}async proxySend(e,r,t,i,a,n,s){const h=d.validateAndGetChainId(e);if(o.isSolanaLike(h))return ue.hinkalSolanaProxySend(this,e[0],r[0],t,i,s);const l=te.createTransaferEmporiumOpsBatch(this,h,e.map(c=>c.erc20TokenAddress),r,i),u=e.map((c,g)=>({token:c,amount:-1n*r[g]}));return await this.actionPrivateWallet(h,[],[],[],l,u,t,a,n,void 0,void 0,void 0,s,void 0)}async multiSendPrivateRecipients(e,r,t){return ne.hinkalMultiSendPrivateRecipients(this,e,r,t)}areMerkleTreeUpdatesDisabled(){return this.disableMerkleTreeUpdates}updateMerkleTreeUpdates(e){this.disableMerkleTreeUpdates=e}}exports.Hinkal=Ae;
|
|
@@ -152,8 +152,10 @@ class Pr {
|
|
|
152
152
|
}
|
|
153
153
|
// If chainId is not provided, use the ethereum provider, if it is initialized. In other case, use the solana provider.
|
|
154
154
|
getProviderAdapter(e) {
|
|
155
|
-
let t = e
|
|
156
|
-
|
|
155
|
+
let t = e;
|
|
156
|
+
t || (this.ethereumProviderAdapter ? t = c.ethMainnet : this.solanaProviderAdapter ? t = c.solanaMainnet : t = c.tronMainnet);
|
|
157
|
+
let r;
|
|
158
|
+
if (h(t) ? r = this.solanaProviderAdapter : v(t) ? r = this.tronProviderAdapter : r = this.ethereumProviderAdapter, !r)
|
|
157
159
|
throw new Error("ProviderAdapter is not initialized");
|
|
158
160
|
return r;
|
|
159
161
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("../../constants/protocol.constants.cjs"),B=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),C=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),O=require("../../functions/web3/events/getShieldedBalance.cjs"),U=require("../../functions/web3/functionCalls/transactCallDirect.cjs"),q=require("../utxo/Utxo.cjs"),z=require("../../error-handling/error-codes.constants.cjs");require("../../types/circom-data.types.cjs");const h=require("../../types/ethereum-network.types.cjs");require("../../constants/chains.constants.cjs");const K=require("../../types/admin.types.cjs");require("../../types/activities.types.cjs");const H=require("../../functions/utils/addresses.cjs"),R=require("../../functions/pre-transaction/getKycAndSignatureData.cjs"),b=require("../../functions/utils/time.utils.cjs"),S=require("../../API/admin-calls.cjs"),I=require("../../functions/pre-transaction/constructAdminData.cjs"),M=require("../../functions/utils/token-check.utils.cjs"),f=async(t,n,e,s)=>{const c=await t.getEthereumAddressByChain(n),{patchAccessTokenMerkleTree:
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("../../constants/protocol.constants.cjs"),B=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),C=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),O=require("../../functions/web3/events/getShieldedBalance.cjs"),U=require("../../functions/web3/functionCalls/transactCallDirect.cjs"),q=require("../utxo/Utxo.cjs"),z=require("../../error-handling/error-codes.constants.cjs");require("../../types/circom-data.types.cjs");const h=require("../../types/ethereum-network.types.cjs");require("../../constants/chains.constants.cjs");const K=require("../../types/admin.types.cjs");require("../../types/activities.types.cjs");const H=require("../../functions/utils/addresses.cjs"),R=require("../../functions/pre-transaction/getKycAndSignatureData.cjs"),b=require("../../functions/utils/time.utils.cjs"),S=require("../../API/admin-calls.cjs"),I=require("../../functions/pre-transaction/constructAdminData.cjs"),M=require("../../functions/utils/token-check.utils.cjs"),f=async(t,n,e,s)=>{const c=await t.getEthereumAddressByChain(n),{patchAccessTokenMerkleTree:a,signatureData:o}=await R.getKycAndSignatureData(t,n,e,s,c),r=void 0;return{signatureData:o,externalActionData:{externalActionId:0n,externalAddress:c,externalActionMetadata:"0x00"},contractTransaction:r,contractToApprove:r,patchAccessTokenMerkleTree:a}},F=async(t,n,e,s)=>{const c=[...await O.addPaddingToUtxos(t,n,e,s)],a=[],o=b.getCurrentTimeInSeconds().toString();for(let r=0;r<e.length;r+=1){const{outputUtxos:i}=B.outputUtxoProcessing(t.userKeys,c[r],s[r],o);a.push(i)}return{inputUtxosArray:c,outputUtxosArray:a}},N=async(t,n,e,s=!0,c=!1)=>{const a=M.validateAndGetChainId(n),o=n.map(P=>P.erc20TokenAddress),[{externalActionData:r,contractTransaction:i,contractToApprove:p,patchAccessTokenMerkleTree:x,signatureData:l},{inputUtxosArray:A,outputUtxosArray:y}]=await Promise.all([f(t,a,o,e),F(t,a,o,e)]),u=`swapperM${e.length.toString()}x${A[0].length}x1`,{zkCallData:m,circomData:T,dimData:D}=await C.constructZkProof("v1x1",t.merkleTreeHinkalByChain[a],t.merkleTreeAccessTokenByChain[a],A,y,t.userKeys,u,r.externalActionId,r.externalAddress,r.externalActionMetadata,t.generateProofRemotely,w.zeroAddress,a,void 0,void 0,void 0,x,void 0,void 0,void 0,t.getContractWithFetcher(a,h.ContractType.HinkalHelperContract),l),v=await U.transactCallDirect(t,a,e,n,m,T,D,p,i,s,c),g=I.constructAdminData(K.AdminTransactionType.Onboarding,a,o,e,await t.getEthereumAddress());return S.emitTxPublicData(g),v},$=async(t,n,e,s,c=!0,a=!1)=>{const o=M.validateAndGetChainId(n),r=n.map(d=>d.erc20TokenAddress),[i,p,x]=s.split(",");if(!H.isValidPrivateAddress(s))throw Error(z.transactionErrorCodes.RECIPIENT_FORMAT_INCORRECT);const l=r.map(d=>[new q.Utxo({amount:0n,erc20TokenAddress:d,shieldedPrivateKey:t.userKeys.getShieldedPrivateKey()}),new q.Utxo({amount:0n,erc20TokenAddress:d,shieldedPrivateKey:t.userKeys.getShieldedPrivateKey()})]),A=`swapperM${e.length.toString()}x${l[0].length}x1`,y=r.map((d,k)=>[new q.Utxo({amount:e[k],erc20TokenAddress:d,randomization:BigInt(i),stealthAddress:p,encryptionKey:x})]),{externalActionData:u,contractTransaction:m,contractToApprove:T,patchAccessTokenMerkleTree:D}=await f(t,o,r,e),{zkCallData:v,circomData:g,dimData:P}=await C.constructZkProof("v1x1",t.merkleTreeHinkalByChain[o],t.merkleTreeAccessTokenByChain[o],l,y,t.userKeys,A,u.externalActionId,u.externalAddress,u.externalActionMetadata,t.generateProofRemotely,w.zeroAddress,o,void 0,void 0,void 0,D,void 0,void 0,void 0,t.getContractWithFetcher(o,h.ContractType.HinkalHelperContract)),E=await U.transactCallDirect(t,o,e,n,v,g,P,T,m,c,a),_=I.constructAdminData(K.AdminTransactionType.PaymentLink,o,r,e,await t.getEthereumAddress());return S.emitTxPublicData(_),E};exports.hinkalDeposit=N;exports.hinkalDepositForOther=$;
|
|
@@ -16,116 +16,112 @@ import { getCurrentTimeInSeconds as b } from "../../functions/utils/time.utils.m
|
|
|
16
16
|
import { emitTxPublicData as M } from "../../API/admin-calls.mjs";
|
|
17
17
|
import { constructAdminData as E } from "../../functions/pre-transaction/constructAdminData.mjs";
|
|
18
18
|
import { validateAndGetChainId as S } from "../../functions/utils/token-check.utils.mjs";
|
|
19
|
-
const
|
|
20
|
-
const s = await t.getEthereumAddressByChain(n), { patchAccessTokenMerkleTree:
|
|
19
|
+
const B = async (t, n, e, i) => {
|
|
20
|
+
const s = await t.getEthereumAddressByChain(n), { patchAccessTokenMerkleTree: o, signatureData: a } = await $(
|
|
21
21
|
t,
|
|
22
22
|
n,
|
|
23
23
|
e,
|
|
24
24
|
i,
|
|
25
25
|
s
|
|
26
|
-
);
|
|
27
|
-
console.log("hinkalDeposit s1", { patchAccessTokenMerkleTree: r, signatureData: o });
|
|
28
|
-
const a = void 0;
|
|
26
|
+
), r = void 0;
|
|
29
27
|
return {
|
|
30
|
-
signatureData:
|
|
28
|
+
signatureData: a,
|
|
31
29
|
externalActionData: {
|
|
32
30
|
externalActionId: 0n,
|
|
33
31
|
externalAddress: s,
|
|
34
32
|
externalActionMetadata: "0x00"
|
|
35
33
|
},
|
|
36
|
-
contractTransaction:
|
|
37
|
-
contractToApprove:
|
|
38
|
-
patchAccessTokenMerkleTree:
|
|
34
|
+
contractTransaction: r,
|
|
35
|
+
contractToApprove: r,
|
|
36
|
+
patchAccessTokenMerkleTree: o
|
|
39
37
|
};
|
|
40
|
-
},
|
|
41
|
-
const s = [...await O(t, n, e, i)],
|
|
42
|
-
for (let
|
|
43
|
-
const { outputUtxos: c } = z(t.userKeys, s[
|
|
44
|
-
|
|
38
|
+
}, W = async (t, n, e, i) => {
|
|
39
|
+
const s = [...await O(t, n, e, i)], o = [], a = b().toString();
|
|
40
|
+
for (let r = 0; r < e.length; r += 1) {
|
|
41
|
+
const { outputUtxos: c } = z(t.userKeys, s[r], i[r], a);
|
|
42
|
+
o.push(c);
|
|
45
43
|
}
|
|
46
|
-
return { inputUtxosArray: s, outputUtxosArray:
|
|
44
|
+
return { inputUtxosArray: s, outputUtxosArray: o };
|
|
47
45
|
}, it = async (t, n, e, i = !0, s = !1) => {
|
|
48
|
-
const
|
|
49
|
-
{ externalActionData:
|
|
46
|
+
const o = S(n), a = n.map((g) => g.erc20TokenAddress), [
|
|
47
|
+
{ externalActionData: r, contractTransaction: c, contractToApprove: l, patchAccessTokenMerkleTree: u, signatureData: p },
|
|
50
48
|
{ inputUtxosArray: A, outputUtxosArray: x }
|
|
51
49
|
] = await Promise.all([
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
])
|
|
55
|
-
console.log("hinkalDeposit a1", { patchAccessTokenMerkleTree: l, signatureData: m });
|
|
56
|
-
const p = `swapperM${e.length.toString()}x${A[0].length}x1`, { zkCallData: y, circomData: T, dimData: v } = await K(
|
|
50
|
+
B(t, o, a, e),
|
|
51
|
+
W(t, o, a, e)
|
|
52
|
+
]), m = `swapperM${e.length.toString()}x${A[0].length}x1`, { zkCallData: y, circomData: T, dimData: v } = await K(
|
|
57
53
|
"v1x1",
|
|
58
|
-
t.merkleTreeHinkalByChain[
|
|
59
|
-
t.merkleTreeAccessTokenByChain[
|
|
54
|
+
t.merkleTreeHinkalByChain[o],
|
|
55
|
+
t.merkleTreeAccessTokenByChain[o],
|
|
60
56
|
A,
|
|
61
57
|
x,
|
|
62
58
|
t.userKeys,
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
59
|
+
m,
|
|
60
|
+
r.externalActionId,
|
|
61
|
+
r.externalAddress,
|
|
62
|
+
r.externalActionMetadata,
|
|
67
63
|
t.generateProofRemotely,
|
|
68
64
|
P,
|
|
69
|
-
|
|
65
|
+
o,
|
|
70
66
|
void 0,
|
|
71
67
|
void 0,
|
|
72
68
|
void 0,
|
|
73
|
-
|
|
69
|
+
u,
|
|
74
70
|
void 0,
|
|
75
71
|
void 0,
|
|
76
72
|
void 0,
|
|
77
|
-
t.getContractWithFetcher(
|
|
78
|
-
|
|
79
|
-
),
|
|
73
|
+
t.getContractWithFetcher(o, C.HinkalHelperContract),
|
|
74
|
+
p
|
|
75
|
+
), f = await U(
|
|
80
76
|
t,
|
|
81
|
-
|
|
77
|
+
o,
|
|
82
78
|
e,
|
|
83
79
|
// for volotile tokens: amountChanges != amountOfTokenToApprove
|
|
84
80
|
n,
|
|
85
81
|
y,
|
|
86
82
|
T,
|
|
87
83
|
v,
|
|
88
|
-
|
|
84
|
+
l,
|
|
89
85
|
c,
|
|
90
86
|
i,
|
|
91
87
|
s
|
|
92
|
-
),
|
|
88
|
+
), D = E(
|
|
93
89
|
I.Onboarding,
|
|
94
|
-
r,
|
|
95
90
|
o,
|
|
91
|
+
a,
|
|
96
92
|
e,
|
|
97
93
|
await t.getEthereumAddress()
|
|
98
94
|
);
|
|
99
|
-
return M(
|
|
100
|
-
}, st = async (t, n, e, i, s = !0,
|
|
101
|
-
const
|
|
95
|
+
return M(D), f;
|
|
96
|
+
}, st = async (t, n, e, i, s = !0, o = !1) => {
|
|
97
|
+
const a = S(n), r = n.map((d) => d.erc20TokenAddress), [c, l, u] = i.split(",");
|
|
102
98
|
if (!N(i))
|
|
103
99
|
throw Error(F.RECIPIENT_FORMAT_INCORRECT);
|
|
104
|
-
const
|
|
100
|
+
const p = r.map((d) => [
|
|
105
101
|
new w({ amount: 0n, erc20TokenAddress: d, shieldedPrivateKey: t.userKeys.getShieldedPrivateKey() }),
|
|
106
102
|
new w({ amount: 0n, erc20TokenAddress: d, shieldedPrivateKey: t.userKeys.getShieldedPrivateKey() })
|
|
107
|
-
]), A = `swapperM${e.length.toString()}x${
|
|
103
|
+
]), A = `swapperM${e.length.toString()}x${p[0].length}x1`, x = r.map((d, h) => [
|
|
108
104
|
new w({
|
|
109
|
-
amount: e[
|
|
105
|
+
amount: e[h],
|
|
110
106
|
erc20TokenAddress: d,
|
|
111
107
|
randomization: BigInt(c),
|
|
112
|
-
stealthAddress:
|
|
113
|
-
encryptionKey:
|
|
108
|
+
stealthAddress: l,
|
|
109
|
+
encryptionKey: u
|
|
114
110
|
})
|
|
115
|
-
]), { externalActionData:
|
|
111
|
+
]), { externalActionData: m, contractTransaction: y, contractToApprove: T, patchAccessTokenMerkleTree: v } = await B(t, a, r, e), { zkCallData: f, circomData: D, dimData: g } = await K(
|
|
116
112
|
"v1x1",
|
|
117
|
-
t.merkleTreeHinkalByChain[
|
|
118
|
-
t.merkleTreeAccessTokenByChain[
|
|
119
|
-
|
|
113
|
+
t.merkleTreeHinkalByChain[a],
|
|
114
|
+
t.merkleTreeAccessTokenByChain[a],
|
|
115
|
+
p,
|
|
120
116
|
x,
|
|
121
117
|
t.userKeys,
|
|
122
118
|
A,
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
119
|
+
m.externalActionId,
|
|
120
|
+
m.externalAddress,
|
|
121
|
+
m.externalActionMetadata,
|
|
126
122
|
t.generateProofRemotely,
|
|
127
123
|
P,
|
|
128
|
-
|
|
124
|
+
a,
|
|
129
125
|
void 0,
|
|
130
126
|
void 0,
|
|
131
127
|
void 0,
|
|
@@ -133,27 +129,27 @@ const h = async (t, n, e, i) => {
|
|
|
133
129
|
void 0,
|
|
134
130
|
void 0,
|
|
135
131
|
void 0,
|
|
136
|
-
t.getContractWithFetcher(
|
|
137
|
-
),
|
|
132
|
+
t.getContractWithFetcher(a, C.HinkalHelperContract)
|
|
133
|
+
), H = await U(
|
|
138
134
|
t,
|
|
139
|
-
|
|
135
|
+
a,
|
|
140
136
|
e,
|
|
141
137
|
n,
|
|
142
|
-
D,
|
|
143
138
|
f,
|
|
139
|
+
D,
|
|
144
140
|
g,
|
|
145
141
|
T,
|
|
146
142
|
y,
|
|
147
143
|
s,
|
|
148
|
-
|
|
149
|
-
),
|
|
144
|
+
o
|
|
145
|
+
), R = E(
|
|
150
146
|
I.PaymentLink,
|
|
151
|
-
o,
|
|
152
147
|
a,
|
|
148
|
+
r,
|
|
153
149
|
e,
|
|
154
150
|
await t.getEthereumAddress()
|
|
155
151
|
);
|
|
156
|
-
return M(
|
|
152
|
+
return M(R), H;
|
|
157
153
|
};
|
|
158
154
|
export {
|
|
159
155
|
it as hinkalDeposit,
|
|
@@ -13,6 +13,7 @@ export interface IProviderAdapter<ConnectorType = unknown> {
|
|
|
13
13
|
connectToConnector(connector: ConnectorType): Promise<number>;
|
|
14
14
|
disconnectFromConnector(): Promise<void>;
|
|
15
15
|
connectAndPatchProvider(connector: ConnectorType): Promise<number>;
|
|
16
|
+
getChainId(): number | undefined;
|
|
16
17
|
waitForTransaction(chainId: number, transactionHash: string, confirmations: number): Promise<boolean>;
|
|
17
18
|
signMessage(message: string | Uint8Array): Promise<string>;
|
|
18
19
|
getAddress(): Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("./shouldPatchAccessTokenMerkleTree.cjs"),i=require("./getSignatureDataForTransact.cjs"),T=async(e,t,a,r,s)=>{const{patchAccessTokenMerkleTree:c,kycRequired:n,hasAccessToken:o}=await g.shouldPatchAccessTokenMerkleTree(e,t,a,r),u=await i.getSignatureDataForTransact(t,s,e.userKeys,n,o);return{patchAccessTokenMerkleTree:c,signatureData:u}};exports.getKycAndSignatureData=T;
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
import { shouldPatchAccessTokenMerkleTree as
|
|
2
|
-
import { getSignatureDataForTransact as
|
|
3
|
-
const
|
|
4
|
-
const { patchAccessTokenMerkleTree:
|
|
1
|
+
import { shouldPatchAccessTokenMerkleTree as i } from "./shouldPatchAccessTokenMerkleTree.mjs";
|
|
2
|
+
import { getSignatureDataForTransact as T } from "./getSignatureDataForTransact.mjs";
|
|
3
|
+
const m = async (e, t, r, a, s) => {
|
|
4
|
+
const { patchAccessTokenMerkleTree: c, kycRequired: o, hasAccessToken: n } = await i(
|
|
5
5
|
e,
|
|
6
6
|
t,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
)
|
|
10
|
-
console.log("hinkalDeposit x1", { patchAccessTokenMerkleTree: a, kycRequired: r, hasAccessToken: s });
|
|
11
|
-
const i = await g(
|
|
7
|
+
r,
|
|
8
|
+
a
|
|
9
|
+
), u = await T(
|
|
12
10
|
t,
|
|
13
|
-
|
|
11
|
+
s,
|
|
14
12
|
e.userKeys,
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
o,
|
|
14
|
+
n
|
|
17
15
|
);
|
|
18
|
-
return { patchAccessTokenMerkleTree:
|
|
16
|
+
return { patchAccessTokenMerkleTree: c, signatureData: u };
|
|
19
17
|
};
|
|
20
18
|
export {
|
|
21
|
-
|
|
19
|
+
m as getKycAndSignatureData
|
|
22
20
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const H=require("../../constants/chains.constants.cjs"),c=require("../../constants/protocol.constants.cjs"),ee=require("../../data-structures/utxo/Utxo.cjs"),te=require("../web3/etherFunctions.cjs"),o=require("./common.snarkjs.cjs"),ne=require("./generateCircomData.cjs"),ae=require("./generateZkProof.cjs"),se=require("../../types/hinkal.types.cjs"),re=require("../utils/fees.utils.cjs"),T=require("../../data-structures/Hinkal/hinkalCheckTokenRegistry.cjs"),oe=require("../../error-handling/logger.cjs"),ce=require("./getMerkleTreeSiblingsAndRootHashes.cjs"),ie=async(d,N,M,t,a,m,b,q,l,z,W,P=c.zeroAddress,i=H.chainIds.localhost,k=t.map(()=>!1),y=t.map(()=>0n),D=void 0,R=!1,s=void 0,u,g=void 0,G,v=c.defaultSignatureData,w)=>{const p=o.calcAmountChanges(t,a),A=t.map(e=>e[0].erc20TokenAddress),h=o.calcEncryptedOutputs(a),f=m.getShieldedPrivateKey(),_=ee.Utxo.findCorrectRandomization(te.randomBigInt(31),f),O=H.isTronLike(i)?await T.hinkalCheckTronTokenRegistry(A,o.calcAmountChanges(t,a,!0),i):await T.hinkalCheckTokenRegistry(G??T.createHinkalHelperFromData(i),A,o.calcAmountChanges(t,a,!0)),J=H.isTronLike(i)?R||O:R,Q=t.map(e=>e.map(n=>n.getConstructableParams())),{inCommitmentSiblings:X,inCommitmentSiblingSides:Y,accessTokenSiblings:$,accessTokenSiblingSides:K,rootHashHinkal:Z,rootHashAccessToken:B,inNullifiers:F}=await ce.getDataFromWorkers(i,N,M,m,Q,J,O,k,d),I=o.buildOutCommitments(d,a,k),r={rootHashHinkal:Z,shieldedPrivateKey:f,erc20TokenAddresses:A,inAmounts:t.map(e=>e.map(n=>n.amount.toString())),inTimeStamps:t.map(e=>e.map(n=>n.timeStamp)),inRandomizations:t.map(e=>e.map(n=>n.randomization)),inNullifiers:F,inCommitmentSiblings:X,inCommitmentSiblingSides:Y,outAmounts:a.map(e=>e.map(n=>n.amount.toString())),outTimeStamp:BigInt(a[0][0].timeStamp),outPublicKeys:a.map(e=>e.map(n=>n.getStealthAddress())),extraRandomization:_,amountChanges:p,outCommitments:I,rootHashAccessToken:B,accessTokenSiblings:$,accessTokenSiblingSides:K,calldataHash:0n},S=t.map(e=>e[0].tokenId??0),j=S.reduce((e,n)=>e+n,0)>0?S.length:0;j>0&&(r.tokenIds=S);const C=o.calcPublicSignalCount(b,r.erc20TokenAddresses,r.amountChanges,r.inNullifiers,r.outCommitments,j);if(!s){s=se.defaultHinkalLogicArgs(p.length,m),s.interactionAddress=l??c.zeroAddress;const e=m.getInHinkalAddress(s.interactionAddress);s.inHinkalAddress=e}if(d==="v1x1"){if(r.interactionAddress=s?.interactionAddress??l??c.zeroAddress,m.getInHinkalAddress(r.interactionAddress)!==s.inHinkalAddress)throw new Error("inHinkalAddress mismatch");r.externalApprovalAddresses=s.useApprovalUtxoData?.map(({externalApprovalAddresses:e})=>e)??[c.zeroAddress,c.zeroAddress,c.zeroAddress]}g||(g=re.generateFeeStructure(y,t.map(e=>e[0].erc20TokenAddress)));const E=o.calcAmountChanges(t,a,!0);u||(u=o.getSlippageValues(E,s)),oe.Logger.log({publicSignalCount:C}),r.calldataHash=o.createCallDataHash(d,C,P,l,q,z,h,y,D,u,k,s,g,v,w);const{zkCallData:L}=await ae.generateZkProof(d,i,b,r,W),V=o.calcStealthAddressStructure(_,f),U=ne.generateCircomData(I,F,Z,B,E,A,a,h,C,q,l,z,P,r.calldataHash,S,V,k,D,void 0,s,u,g,v,w),x={tokenNumber:t.length,nullifierAmount:t[0].length,outputAmount:a[0].length};return{zkCallData:L,circomData:U,dimData:x,encryptedOutputs:h}};exports.constructZkProof=ie;
|
|
@@ -1,140 +1,134 @@
|
|
|
1
|
-
import { isTronLike as
|
|
2
|
-
import { zeroAddress as
|
|
3
|
-
import { Utxo as
|
|
4
|
-
import { randomBigInt as
|
|
5
|
-
import { calcAmountChanges as
|
|
6
|
-
import { generateCircomData as
|
|
7
|
-
import { generateZkProof as
|
|
8
|
-
import { defaultHinkalLogicArgs as
|
|
9
|
-
import { generateFeeStructure as
|
|
10
|
-
import { hinkalCheckTronTokenRegistry as
|
|
11
|
-
import { Logger as
|
|
12
|
-
import { getDataFromWorkers as
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
),
|
|
19
|
-
console.log("hinkalDeposit sa1", { userKeys: i });
|
|
20
|
-
const {
|
|
1
|
+
import { isTronLike as q, chainIds as x } from "../../constants/chains.constants.mjs";
|
|
2
|
+
import { zeroAddress as i, defaultSignatureData as ee } from "../../constants/protocol.constants.mjs";
|
|
3
|
+
import { Utxo as te } from "../../data-structures/utxo/Utxo.mjs";
|
|
4
|
+
import { randomBigInt as ae } from "../web3/etherFunctions.mjs";
|
|
5
|
+
import { calcAmountChanges as p, calcEncryptedOutputs as me, buildOutCommitments as ne, calcPublicSignalCount as oe, getSlippageValues as re, createCallDataHash as ie, calcStealthAddressStructure as de } from "./common.snarkjs.mjs";
|
|
6
|
+
import { generateCircomData as se } from "./generateCircomData.mjs";
|
|
7
|
+
import { generateZkProof as ce } from "./generateZkProof.mjs";
|
|
8
|
+
import { defaultHinkalLogicArgs as le } from "../../types/hinkal.types.mjs";
|
|
9
|
+
import { generateFeeStructure as fe } from "../utils/fees.utils.mjs";
|
|
10
|
+
import { hinkalCheckTronTokenRegistry as ke, hinkalCheckTokenRegistry as Se, createHinkalHelperFromData as He } from "../../data-structures/Hinkal/hinkalCheckTokenRegistry.mjs";
|
|
11
|
+
import { Logger as pe } from "../../error-handling/logger.mjs";
|
|
12
|
+
import { getDataFromWorkers as Ae } from "./getMerkleTreeSiblingsAndRootHashes.mjs";
|
|
13
|
+
const ye = async (d, W, j, t, m, s, C, b, c, h, G, P = i, r = x.localhost, l = t.map(() => !1), z = t.map(() => 0n), D = void 0, v = !1, n = void 0, f, k = void 0, J, w = ee, R) => {
|
|
14
|
+
const u = p(t, m), S = t.map((e) => e[0].erc20TokenAddress), A = me(m), g = s.getShieldedPrivateKey(), y = te.findCorrectRandomization(ae(31), g), B = q(r) ? await ke(S, p(t, m, !0), r) : await Se(
|
|
15
|
+
J ?? He(r),
|
|
16
|
+
S,
|
|
17
|
+
p(t, m, !0)
|
|
18
|
+
), Q = q(r) ? v || B : v, X = t.map((e) => e.map((a) => a.getConstructableParams())), {
|
|
21
19
|
inCommitmentSiblings: Y,
|
|
22
20
|
inCommitmentSiblingSides: _,
|
|
23
21
|
accessTokenSiblings: $,
|
|
24
|
-
accessTokenSiblingSides:
|
|
25
|
-
rootHashHinkal:
|
|
26
|
-
rootHashAccessToken:
|
|
27
|
-
inNullifiers:
|
|
28
|
-
} = await
|
|
22
|
+
accessTokenSiblingSides: K,
|
|
23
|
+
rootHashHinkal: I,
|
|
24
|
+
rootHashAccessToken: O,
|
|
25
|
+
inNullifiers: E
|
|
26
|
+
} = await Ae(
|
|
29
27
|
r,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
W,
|
|
29
|
+
j,
|
|
30
|
+
s,
|
|
33
31
|
X,
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
Q,
|
|
33
|
+
B,
|
|
36
34
|
l,
|
|
37
35
|
d
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
inRandomizations: a.map((t) => t.map((e) => e.randomization)),
|
|
47
|
-
inNullifiers: N,
|
|
36
|
+
), F = ne(d, m, l), o = {
|
|
37
|
+
rootHashHinkal: I,
|
|
38
|
+
shieldedPrivateKey: g,
|
|
39
|
+
erc20TokenAddresses: S,
|
|
40
|
+
inAmounts: t.map((e) => e.map((a) => a.amount.toString())),
|
|
41
|
+
inTimeStamps: t.map((e) => e.map((a) => a.timeStamp)),
|
|
42
|
+
inRandomizations: t.map((e) => e.map((a) => a.randomization)),
|
|
43
|
+
inNullifiers: E,
|
|
48
44
|
inCommitmentSiblings: Y,
|
|
49
45
|
inCommitmentSiblingSides: _,
|
|
50
|
-
outAmounts:
|
|
51
|
-
outTimeStamp: BigInt(
|
|
52
|
-
outPublicKeys:
|
|
53
|
-
extraRandomization:
|
|
54
|
-
amountChanges:
|
|
55
|
-
outCommitments:
|
|
56
|
-
rootHashAccessToken:
|
|
46
|
+
outAmounts: m.map((e) => e.map((a) => a.amount.toString())),
|
|
47
|
+
outTimeStamp: BigInt(m[0][0].timeStamp),
|
|
48
|
+
outPublicKeys: m.map((e) => e.map((a) => a.getStealthAddress())),
|
|
49
|
+
extraRandomization: y,
|
|
50
|
+
amountChanges: u,
|
|
51
|
+
outCommitments: F,
|
|
52
|
+
rootHashAccessToken: O,
|
|
57
53
|
accessTokenSiblings: $,
|
|
58
|
-
accessTokenSiblingSides:
|
|
54
|
+
accessTokenSiblingSides: K,
|
|
59
55
|
calldataHash: 0n
|
|
60
|
-
},
|
|
61
|
-
|
|
62
|
-
const T =
|
|
56
|
+
}, H = t.map((e) => e[0].tokenId ?? 0), N = H.reduce((e, a) => e + a, 0) > 0 ? H.length : 0;
|
|
57
|
+
N > 0 && (o.tokenIds = H);
|
|
58
|
+
const T = oe(
|
|
63
59
|
C,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
60
|
+
o.erc20TokenAddresses,
|
|
61
|
+
o.amountChanges,
|
|
62
|
+
o.inNullifiers,
|
|
63
|
+
o.outCommitments,
|
|
64
|
+
N
|
|
69
65
|
);
|
|
70
|
-
if (!
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
66
|
+
if (!n) {
|
|
67
|
+
n = le(u.length, s), n.interactionAddress = c ?? i;
|
|
68
|
+
const e = s.getInHinkalAddress(n.interactionAddress);
|
|
69
|
+
n.inHinkalAddress = e;
|
|
74
70
|
}
|
|
75
71
|
if (d === "v1x1") {
|
|
76
|
-
if (
|
|
72
|
+
if (o.interactionAddress = n?.interactionAddress ?? c ?? i, s.getInHinkalAddress(o.interactionAddress) !== n.inHinkalAddress)
|
|
77
73
|
throw new Error("inHinkalAddress mismatch");
|
|
78
|
-
|
|
79
|
-
({ externalApprovalAddresses:
|
|
80
|
-
) ?? [
|
|
74
|
+
o.externalApprovalAddresses = n.useApprovalUtxoData?.map(
|
|
75
|
+
({ externalApprovalAddresses: e }) => e
|
|
76
|
+
) ?? [i, i, i];
|
|
81
77
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
78
|
+
k || (k = fe(
|
|
79
|
+
z,
|
|
80
|
+
t.map((e) => e[0].erc20TokenAddress)
|
|
85
81
|
));
|
|
86
|
-
const
|
|
87
|
-
|
|
82
|
+
const Z = p(t, m, !0);
|
|
83
|
+
f || (f = re(Z, n)), pe.log({ publicSignalCount: T }), o.calldataHash = ie(
|
|
88
84
|
d,
|
|
89
85
|
T,
|
|
90
|
-
|
|
86
|
+
P,
|
|
91
87
|
c,
|
|
92
|
-
D,
|
|
93
88
|
b,
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
l,
|
|
99
|
-
m,
|
|
89
|
+
h,
|
|
90
|
+
A,
|
|
91
|
+
z,
|
|
92
|
+
D,
|
|
100
93
|
f,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
N,
|
|
109
|
-
E,
|
|
94
|
+
l,
|
|
95
|
+
n,
|
|
96
|
+
k,
|
|
97
|
+
w,
|
|
98
|
+
R
|
|
99
|
+
);
|
|
100
|
+
const { zkCallData: M } = await ce(d, r, C, o, G), V = de(y, g), L = se(
|
|
110
101
|
F,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
102
|
+
E,
|
|
103
|
+
I,
|
|
104
|
+
O,
|
|
105
|
+
Z,
|
|
106
|
+
S,
|
|
107
|
+
m,
|
|
108
|
+
A,
|
|
115
109
|
T,
|
|
116
|
-
D,
|
|
117
|
-
c,
|
|
118
110
|
b,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
111
|
+
c,
|
|
112
|
+
h,
|
|
113
|
+
P,
|
|
114
|
+
o.calldataHash,
|
|
115
|
+
H,
|
|
122
116
|
V,
|
|
123
117
|
l,
|
|
124
|
-
|
|
118
|
+
D,
|
|
125
119
|
void 0,
|
|
126
|
-
|
|
127
|
-
k,
|
|
120
|
+
n,
|
|
128
121
|
f,
|
|
129
|
-
|
|
130
|
-
|
|
122
|
+
k,
|
|
123
|
+
w,
|
|
124
|
+
R
|
|
131
125
|
), U = {
|
|
132
|
-
tokenNumber:
|
|
133
|
-
nullifierAmount:
|
|
134
|
-
outputAmount:
|
|
126
|
+
tokenNumber: t.length,
|
|
127
|
+
nullifierAmount: t[0].length,
|
|
128
|
+
outputAmount: m[0].length
|
|
135
129
|
};
|
|
136
|
-
return { zkCallData:
|
|
130
|
+
return { zkCallData: M, circomData: L, dimData: U, encryptedOutputs: A };
|
|
137
131
|
};
|
|
138
132
|
export {
|
|
139
|
-
|
|
133
|
+
ye as constructZkProof
|
|
140
134
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("../../error-handling/logger.cjs"),c=require("./generateZkProofEnclave.cjs"),f=require("./generateZkProofSelf.cjs"),l=async(e,r,o,t,n)=>{if(n)try{return await c.generateZkProofEnclave(e,r,o,t)}catch(a){g.Logger.error("enclave proof error",a)}return f.generateZkProofSelf(e,r,o,t)};exports.generateZkProof=l;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { Logger as n } from "../../error-handling/logger.mjs";
|
|
2
|
-
import { generateZkProofEnclave as
|
|
3
|
-
import { generateZkProofSelf as
|
|
4
|
-
const
|
|
5
|
-
if (
|
|
2
|
+
import { generateZkProofEnclave as c } from "./generateZkProofEnclave.mjs";
|
|
3
|
+
import { generateZkProofSelf as g } from "./generateZkProofSelf.mjs";
|
|
4
|
+
const p = async (r, o, e, t, f) => {
|
|
5
|
+
if (f)
|
|
6
6
|
try {
|
|
7
|
-
return await
|
|
8
|
-
} catch (
|
|
9
|
-
|
|
7
|
+
return await c(r, o, e, t);
|
|
8
|
+
} catch (a) {
|
|
9
|
+
n.error("enclave proof error", a);
|
|
10
10
|
}
|
|
11
|
-
return
|
|
11
|
+
return g(r, o, e, t);
|
|
12
12
|
};
|
|
13
13
|
export {
|
|
14
|
-
|
|
14
|
+
p as generateZkProof
|
|
15
15
|
};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("../constants/chains.constants.cjs"),n=require("../error-handling/error-codes.constants.cjs"),a=require("ethers"),c=require("../functions/web3/getContractMetadata.cjs"),h=require("../functions/utils/create-provider.cjs");class s{signer;chainId;fetchProviders={};chainEventListener;constructor(){i.HINKAL_SUPPORTED_CHAINS.forEach(r=>{!i.isSolanaLike(r)&&!i.isTronLike(r)&&(this.fetchProviders[r]=h.createCustomRpcProvider(r))})}initConnector(){}initSigner(r){this.signer=r}async init(r){if(r&&(this.chainId=r),!this.chainId)throw Error("No Chain Id In Provider Adapter")}async disconnectFromConnector(){}async connectToConnector(){return 0}async waitForTransaction(r,e,t){if((await this.fetchProviders[r]?.waitForTransaction(e,t))?.status)return!0;throw Error(n.transactionErrorCodes.TRANSACTION_NOT_CONFIRMED)}async signMessage(r){if(!this.signer)throw new Error("IllegalState: no signer");const e=await this.signer.signMessage(r);if(!e)throw new Error(n.transactionErrorCodes.SIGNING_FAILED);if(e.includes("error"))throw new Error(n.transactionErrorCodes.SIGNATURE_UNSUPPORTED_PERSONAL_SIGN);return e}async signTypedData(r,e,t){return this.signer.signTypedData(r,e,t)}async switchNetwork(r){const e=this.fetchProviders[r.chainId];if(!e)throw new Error("switchNetwork illegal state: no provider");this.signer=this.signer?.connect(e),this.chainEventListener?.onChainChanged(r.chainId)}async getAddress(){if(!this.signer)throw new Error("IllegalState: no signer");const r=await this.signer.getAddress();if(!r)throw new Error("IllegalState");return a.ethers.getAddress(r)}setChainEventListener(r){this.chainEventListener=r}onAccountChanged(){return this.init()}onChainChanged(r){return this.init(r)}release(){this.removeListeners()}removeListeners(){this.chainEventListener=void 0}getContract(r,e,t=void 0,o){return c.getContract(e,r,t,o)}getContractWithSigner(r,e,t=void 0){if(!this.signer)throw new Error("IllegalState: no signer");return this.getContract(r,e,t,this.signer)}getContractWithFetcher(r,e,t=void 0){if(!this.fetchProviders[r])throw new Error("fetchProvider not initialized");return this.getContract(r,e,t,this.fetchProviders[r])}async sendTransaction(r){if(!this.signer)throw new Error("IllegalState: no signer");return await this.signer.sendTransaction(r)}async connectAndPatchProvider(){if(!this.signer)throw new Error("IllegalState: no signer");const{chainId:r}=await this.signer.provider.getNetwork();return Number(r)}isPermitterAvailable(){return!1}async getGasPrice(r){const e=(await this.fetchProviders[r]?.getFeeData())?.gasPrice;if(!e)throw Error("Could not fetch gas price in getGasPrice");return e}}const d=new s,g=()=>new s;exports.EthersProviderAdapter=s;exports.default=g;exports.ethersProvierAdapter=d;
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("../constants/chains.constants.cjs"),n=require("../error-handling/error-codes.constants.cjs"),a=require("ethers"),c=require("../functions/web3/getContractMetadata.cjs"),h=require("../functions/utils/create-provider.cjs");class s{signer;chainId;fetchProviders={};chainEventListener;constructor(){i.HINKAL_SUPPORTED_CHAINS.forEach(r=>{!i.isSolanaLike(r)&&!i.isTronLike(r)&&(this.fetchProviders[r]=h.createCustomRpcProvider(r))})}initConnector(){}initSigner(r){this.signer=r}async init(r){if(r&&(this.chainId=r),!this.chainId)throw Error("No Chain Id In Provider Adapter")}async disconnectFromConnector(){}async connectToConnector(){return 0}async waitForTransaction(r,e,t){if((await this.fetchProviders[r]?.waitForTransaction(e,t))?.status)return!0;throw Error(n.transactionErrorCodes.TRANSACTION_NOT_CONFIRMED)}async signMessage(r){if(!this.signer)throw new Error("IllegalState: no signer");const e=await this.signer.signMessage(r);if(!e)throw new Error(n.transactionErrorCodes.SIGNING_FAILED);if(e.includes("error"))throw new Error(n.transactionErrorCodes.SIGNATURE_UNSUPPORTED_PERSONAL_SIGN);return e}async signTypedData(r,e,t){return this.signer.signTypedData(r,e,t)}async switchNetwork(r){const e=this.fetchProviders[r.chainId];if(!e)throw new Error("switchNetwork illegal state: no provider");this.signer=this.signer?.connect(e),this.chainEventListener?.onChainChanged(r.chainId)}async getAddress(){if(!this.signer)throw new Error("IllegalState: no signer");const r=await this.signer.getAddress();if(!r)throw new Error("IllegalState");return a.ethers.getAddress(r)}setChainEventListener(r){this.chainEventListener=r}onAccountChanged(){return this.init()}onChainChanged(r){return this.init(r)}release(){this.removeListeners()}removeListeners(){this.chainEventListener=void 0}getContract(r,e,t=void 0,o){return c.getContract(e,r,t,o)}getContractWithSigner(r,e,t=void 0){if(!this.signer)throw new Error("IllegalState: no signer");return this.getContract(r,e,t,this.signer)}getContractWithFetcher(r,e,t=void 0){if(!this.fetchProviders[r])throw new Error("fetchProvider not initialized");return this.getContract(r,e,t,this.fetchProviders[r])}async sendTransaction(r){if(!this.signer)throw new Error("IllegalState: no signer");return await this.signer.sendTransaction(r)}async connectAndPatchProvider(){if(!this.signer)throw new Error("IllegalState: no signer");const{chainId:r}=await this.signer.provider.getNetwork();return Number(r)}getChainId(){return this.chainId}isPermitterAvailable(){return!1}async getGasPrice(r){const e=(await this.fetchProviders[r]?.getFeeData())?.gasPrice;if(!e)throw Error("Could not fetch gas price in getGasPrice");return e}}const d=new s,g=()=>new s;exports.EthersProviderAdapter=s;exports.default=g;exports.ethersProvierAdapter=d;
|
|
@@ -27,6 +27,7 @@ export declare class EthersProviderAdapter implements IProviderAdapter<ethers.Si
|
|
|
27
27
|
getContractWithFetcher(chainId: number, contract: ContractType, contractAddress?: undefined): ethers.Contract;
|
|
28
28
|
sendTransaction(tx: ethers.TransactionRequest): Promise<ethers.TransactionResponse>;
|
|
29
29
|
connectAndPatchProvider(): Promise<number>;
|
|
30
|
+
getChainId(): number | undefined;
|
|
30
31
|
isPermitterAvailable(): boolean;
|
|
31
32
|
getGasPrice(chainId: number): Promise<bigint>;
|
|
32
33
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { HINKAL_SUPPORTED_CHAINS as o, isSolanaLike as a, isTronLike as
|
|
1
|
+
import { HINKAL_SUPPORTED_CHAINS as o, isSolanaLike as a, isTronLike as h } from "../constants/chains.constants.mjs";
|
|
2
2
|
import { transactionErrorCodes as i } from "../error-handling/error-codes.constants.mjs";
|
|
3
|
-
import { ethers as
|
|
3
|
+
import { ethers as c } from "ethers";
|
|
4
4
|
import { getContract as g } from "../functions/web3/getContractMetadata.mjs";
|
|
5
5
|
import { createCustomRpcProvider as d } from "../functions/utils/create-provider.mjs";
|
|
6
6
|
class s {
|
|
@@ -10,7 +10,7 @@ class s {
|
|
|
10
10
|
chainEventListener;
|
|
11
11
|
constructor() {
|
|
12
12
|
o.forEach((r) => {
|
|
13
|
-
!a(r) && !
|
|
13
|
+
!a(r) && !h(r) && (this.fetchProviders[r] = d(r));
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
initConnector() {
|
|
@@ -57,7 +57,7 @@ class s {
|
|
|
57
57
|
const r = await this.signer.getAddress();
|
|
58
58
|
if (!r)
|
|
59
59
|
throw new Error("IllegalState");
|
|
60
|
-
return
|
|
60
|
+
return c.getAddress(r);
|
|
61
61
|
}
|
|
62
62
|
setChainEventListener(r) {
|
|
63
63
|
this.chainEventListener = r;
|
|
@@ -98,6 +98,9 @@ class s {
|
|
|
98
98
|
const { chainId: r } = await this.signer.provider.getNetwork();
|
|
99
99
|
return Number(r);
|
|
100
100
|
}
|
|
101
|
+
getChainId() {
|
|
102
|
+
return this.chainId;
|
|
103
|
+
}
|
|
101
104
|
isPermitterAvailable() {
|
|
102
105
|
return !1;
|
|
103
106
|
}
|
|
@@ -108,9 +111,9 @@ class s {
|
|
|
108
111
|
return t;
|
|
109
112
|
}
|
|
110
113
|
}
|
|
111
|
-
const
|
|
114
|
+
const P = new s(), C = () => new s();
|
|
112
115
|
export {
|
|
113
116
|
s as EthersProviderAdapter,
|
|
114
117
|
C as default,
|
|
115
|
-
|
|
118
|
+
P as ethersProvierAdapter
|
|
116
119
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../error-handling/error-codes.constants.cjs"),i=require("@coral-xyz/anchor");class a{chainId;connection;wallet;ethereumAddress;chainEventListener;anchorProvider;constructor(r,e,
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("../error-handling/error-codes.constants.cjs"),i=require("@coral-xyz/anchor");class a{chainId;connection;wallet;ethereumAddress;chainEventListener;anchorProvider;constructor(r,t,e,n){this.connection=r,this.chainId=t,this.wallet=e,this.ethereumAddress=n,this.initializeAnchorProvider()}initConnector(r){this.wallet=r}async init(r){r&&(this.chainId=r)}async connectToConnector(){return 0}async disconnectFromConnector(){}async connectAndPatchProvider(){if(!this.chainId)throw new Error("No Chain Id In Provider Adapter");return this.chainId}getChainId(){return this.chainId}async waitForTransaction(r,t,e){try{return(await this.connection.confirmTransaction(t,"confirmed")).value.err===null}catch{throw Error(o.transactionErrorCodes.TRANSACTION_NOT_CONFIRMED)}}async signMessage(r){if(!this.wallet?.signMessage)throw new Error(o.transactionErrorCodes.SIGNING_FAILED);const t=typeof r=="string"?new TextEncoder().encode(r):r,{signature:e}=await this.wallet.signMessage(t,"utf8");if(!e)throw new Error(o.transactionErrorCodes.SIGNING_FAILED);return`0x${Buffer.from(e).toString("hex")}`}async getAddress(){const r=this.ethereumAddress??this.wallet?.publicKey.toString();if(!r)throw new Error("IllegalState");return r}setChainEventListener(r){this.chainEventListener=r}async switchNetwork(r){this.chainEventListener?.onChainChanged(r.chainId)}async signTypedData(r,t,e){throw new Error("Typed data signing not supported on Solana")}async onAccountChanged(){return this.init()}async onChainChanged(r){return this.init(r)}release(){this.chainEventListener=void 0}getContract(r,t,e,n){throw new Error("Not implemented from SolanaProviderAdapter")}getContractWithSigner(r,t,e){throw new Error("Not implemented from SolanaProviderAdapter")}getContractWithFetcher(r,t,e){throw new Error("Not implemented from SolanaProviderAdapter")}async sendTransaction(r){throw new Error("Not implemented from SolanaProviderAdapter")}async getGasPrice(r){throw new Error("Not implemented from SolanaProviderAdapter")}isPermitterAvailable(){return!1}getConnection(){return this.connection}initializeAnchorProvider(){if(!this.wallet)throw new Error("No wallet provided");return this.anchorProvider=new i.AnchorProvider(this.connection,this.wallet,{}),this.anchorProvider}getAnchorProvider(){return this.anchorProvider??this.initializeAnchorProvider()}getSolanaProgram(r){return new i.Program(r,this.getAnchorProvider())}getSolanaPublicKey(){if(!this.wallet)throw new Error("No wallet provided");return this.wallet.publicKey}}exports.SolanaProviderAdapter=a;
|
|
@@ -17,6 +17,7 @@ export declare class SolanaProviderAdapter implements IProviderAdapter<SolanaWal
|
|
|
17
17
|
connectToConnector(): Promise<number>;
|
|
18
18
|
disconnectFromConnector(): Promise<void>;
|
|
19
19
|
connectAndPatchProvider(): Promise<number>;
|
|
20
|
+
getChainId(): number | undefined;
|
|
20
21
|
waitForTransaction(_chainId: number, transactionHash: string, _confirmations: number): Promise<boolean>;
|
|
21
22
|
signMessage(message: string | Uint8Array): Promise<string>;
|
|
22
23
|
getAddress(): Promise<string>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { transactionErrorCodes as
|
|
2
|
-
import { AnchorProvider as
|
|
1
|
+
import { transactionErrorCodes as i } from "../error-handling/error-codes.constants.mjs";
|
|
2
|
+
import { AnchorProvider as o, Program as a } from "@coral-xyz/anchor";
|
|
3
3
|
class d {
|
|
4
4
|
chainId;
|
|
5
5
|
connection;
|
|
@@ -27,19 +27,22 @@ class d {
|
|
|
27
27
|
throw new Error("No Chain Id In Provider Adapter");
|
|
28
28
|
return this.chainId;
|
|
29
29
|
}
|
|
30
|
+
getChainId() {
|
|
31
|
+
return this.chainId;
|
|
32
|
+
}
|
|
30
33
|
async waitForTransaction(r, t, e) {
|
|
31
34
|
try {
|
|
32
35
|
return (await this.connection.confirmTransaction(t, "confirmed")).value.err === null;
|
|
33
36
|
} catch {
|
|
34
|
-
throw Error(
|
|
37
|
+
throw Error(i.TRANSACTION_NOT_CONFIRMED);
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
40
|
async signMessage(r) {
|
|
38
41
|
if (!this.wallet?.signMessage)
|
|
39
|
-
throw new Error(
|
|
42
|
+
throw new Error(i.SIGNING_FAILED);
|
|
40
43
|
const t = typeof r == "string" ? new TextEncoder().encode(r) : r, { signature: e } = await this.wallet.signMessage(t, "utf8");
|
|
41
44
|
if (!e)
|
|
42
|
-
throw new Error(
|
|
45
|
+
throw new Error(i.SIGNING_FAILED);
|
|
43
46
|
return `0x${Buffer.from(e).toString("hex")}`;
|
|
44
47
|
}
|
|
45
48
|
async getAddress() {
|
|
@@ -91,7 +94,7 @@ class d {
|
|
|
91
94
|
initializeAnchorProvider() {
|
|
92
95
|
if (!this.wallet)
|
|
93
96
|
throw new Error("No wallet provided");
|
|
94
|
-
return this.anchorProvider = new
|
|
97
|
+
return this.anchorProvider = new o(this.connection, this.wallet, {}), this.anchorProvider;
|
|
95
98
|
}
|
|
96
99
|
getAnchorProvider() {
|
|
97
100
|
return this.anchorProvider ?? this.initializeAnchorProvider();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../error-handling/error-codes.constants.cjs");require("../types/circom-data.types.cjs");require("../constants/chains.constants.cjs");require("../types/activities.types.cjs");require("@coral-xyz/anchor");require("@solana/web3.js");require("ethers");require("circomlibjs-hinkal-fork");require("../constants/kyc.constants.cjs");require("idb-keyval");const s=require("../functions/utils/create-provider.cjs");require("../constants/token-data/index.cjs");require("../constants/tokens.constants.cjs");require("../functions/utils/convertIntegrationProviderToExternalActionId.cjs");require("../data-structures/crypto-keys/keys.cjs");require("../constants/server.constants.cjs");require("../API/getServerURL.cjs");require("../data-structures/http/HttpClient.cjs");require("axios");require("../constants/vite.constants.cjs");require("tronweb");require("@solana/spl-token");require("tweetnacl");require("bs58");require("buffer");require("libsodium-wrappers");require("lodash");require("../API/enclaveUtxoCalls.cjs");require("../constants/contracts.constants.cjs");require("../constants/coingecko.constants.cjs");require("../constants/reorg-depths.constants.cjs");require("../constants/addresses.constants.cjs");require("../constants/token.limits.constants.cjs");require("../constants/presale.constants.cjs");require("../constants/activity.constants.cjs");require("../constants/tasks.constants.cjs");require("../constants/events.constants.cjs");require("../constants/schedule.constants.cjs");require("../functions/utils/userAgent.cjs");require("multiformats");require("async-mutex");require("process");require("./EthersProviderAdapter.cjs");require("node-forge");const a=require("../functions/utils/tron.utils.cjs");require("../functions/web3/events/getInputUtxoAndBalance.cjs");require("../functions/web3/events/getApprovedBalance.cjs");const o=require("../functions/web3/getContractMetadata.cjs");require("../functions/web3/getTokenHolder.cjs");class d{chainId;tronWeb;address;signerAdapter;chainEventListener;accountsChangedHandler;constructor(e,r){this.chainId=r,this.address=e.address,this.signerAdapter=e.signerAdapter,this.tronWeb=this.createSignableTronWeb(r,e.address)}initConnector(e){this.address=e.address,this.signerAdapter=e.signerAdapter,this.chainId&&(this.tronWeb=this.createSignableTronWeb(this.chainId,e.address))}async init(e){e&&(this.chainId=e,this.address&&(this.tronWeb=this.createSignableTronWeb(e,this.address)))}createSignableTronWeb=(e,r)=>{const t=a.createTronWeb(e);return t.setAddress(r),t.trx.sign=async n=>this.signerAdapter.signTransaction(n),t};async connectToConnector(){return 0}async disconnectFromConnector(){}async connectAndPatchProvider(){if(!this.chainId)throw new Error("No Chain Id In Provider Adapter");return this.chainId}async waitForTransaction(e,r,t){const n=r.startsWith("0x")?r:`0x${r}`;if((await s.createCustomRpcProvider(e).waitForTransaction(n,t))?.status===1)return!0;throw new Error(i.transactionErrorCodes.TRANSACTION_NOT_CONFIRMED)}async signMessage(e){const r=typeof e=="string"?e:new TextDecoder().decode(e),t=await this.signerAdapter.signMessage(r);if(!t)throw new Error(i.transactionErrorCodes.SIGNING_FAILED);return t}async getAddress(){if(!this.address)throw new Error("IllegalState");return this.address}setChainEventListener(e){this.chainEventListener=e,this.accountsChangedHandler&&this.signerAdapter.off("accountsChanged",this.accountsChangedHandler),this.accountsChangedHandler=r=>{this.chainEventListener&&(this.address=r,this.tronWeb?.setAddress(r),this.chainEventListener.onAccountChanged())},this.signerAdapter.on("accountsChanged",this.accountsChangedHandler)}async switchNetwork(e){this.chainEventListener?.onChainChanged(e.chainId)}async signTypedData(e,r,t){throw new Error("Typed data signing not supported on Tron")}async onAccountChanged(){return Promise.resolve()}async onChainChanged(e){return this.init(e)}release(){this.chainEventListener=void 0,this.accountsChangedHandler&&(this.signerAdapter.off("accountsChanged",this.accountsChangedHandler),this.accountsChangedHandler=void 0)}getContract(e,r,t,n){return o.getContract(r,e,t,n)}getContractWithSigner(e,r,t){throw new Error("Not implemented from TronProviderAdapter")}getContractWithFetcher(e,r,t){const n=s.createCustomRpcProvider(e);return this.getContract(e,r,t,n)}async sendTransaction(e){throw new Error("Not implemented from TronProviderAdapter")}async getGasPrice(e){throw new Error("Not implemented from TronProviderAdapter")}isPermitterAvailable(){return!1}getTronWeb(){return this.tronWeb}}exports.TronProviderAdapter=d;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../error-handling/error-codes.constants.cjs");require("../types/circom-data.types.cjs");require("../constants/chains.constants.cjs");require("../types/activities.types.cjs");require("@coral-xyz/anchor");require("@solana/web3.js");require("ethers");require("circomlibjs-hinkal-fork");require("../constants/kyc.constants.cjs");require("idb-keyval");const s=require("../functions/utils/create-provider.cjs");require("../constants/token-data/index.cjs");require("../constants/tokens.constants.cjs");require("../functions/utils/convertIntegrationProviderToExternalActionId.cjs");require("../data-structures/crypto-keys/keys.cjs");require("../constants/server.constants.cjs");require("../API/getServerURL.cjs");require("../data-structures/http/HttpClient.cjs");require("axios");require("../constants/vite.constants.cjs");require("tronweb");require("@solana/spl-token");require("tweetnacl");require("bs58");require("buffer");require("libsodium-wrappers");require("lodash");require("../API/enclaveUtxoCalls.cjs");require("../constants/contracts.constants.cjs");require("../constants/coingecko.constants.cjs");require("../constants/reorg-depths.constants.cjs");require("../constants/addresses.constants.cjs");require("../constants/token.limits.constants.cjs");require("../constants/presale.constants.cjs");require("../constants/activity.constants.cjs");require("../constants/tasks.constants.cjs");require("../constants/events.constants.cjs");require("../constants/schedule.constants.cjs");require("../functions/utils/userAgent.cjs");require("multiformats");require("async-mutex");require("process");require("./EthersProviderAdapter.cjs");require("node-forge");const a=require("../functions/utils/tron.utils.cjs");require("../functions/web3/events/getInputUtxoAndBalance.cjs");require("../functions/web3/events/getApprovedBalance.cjs");const o=require("../functions/web3/getContractMetadata.cjs");require("../functions/web3/getTokenHolder.cjs");class d{chainId;tronWeb;address;signerAdapter;chainEventListener;accountsChangedHandler;constructor(e,r){this.chainId=r,this.address=e.address,this.signerAdapter=e.signerAdapter,this.tronWeb=this.createSignableTronWeb(r,e.address)}initConnector(e){this.address=e.address,this.signerAdapter=e.signerAdapter,this.chainId&&(this.tronWeb=this.createSignableTronWeb(this.chainId,e.address))}async init(e){e&&(this.chainId=e,this.address&&(this.tronWeb=this.createSignableTronWeb(e,this.address)))}createSignableTronWeb=(e,r)=>{const t=a.createTronWeb(e);return t.setAddress(r),t.trx.sign=async n=>this.signerAdapter.signTransaction(n),t};async connectToConnector(){return 0}async disconnectFromConnector(){}async connectAndPatchProvider(){if(!this.chainId)throw new Error("No Chain Id In Provider Adapter");return this.chainId}getChainId(){return this.chainId}async waitForTransaction(e,r,t){const n=r.startsWith("0x")?r:`0x${r}`;if((await s.createCustomRpcProvider(e).waitForTransaction(n,t))?.status===1)return!0;throw new Error(i.transactionErrorCodes.TRANSACTION_NOT_CONFIRMED)}async signMessage(e){const r=typeof e=="string"?e:new TextDecoder().decode(e),t=await this.signerAdapter.signMessage(r);if(!t)throw new Error(i.transactionErrorCodes.SIGNING_FAILED);return t}async getAddress(){if(!this.address)throw new Error("IllegalState");return this.address}setChainEventListener(e){this.chainEventListener=e,this.accountsChangedHandler&&this.signerAdapter.off("accountsChanged",this.accountsChangedHandler),this.accountsChangedHandler=r=>{this.chainEventListener&&(this.address=r,this.tronWeb?.setAddress(r),this.chainEventListener.onAccountChanged())},this.signerAdapter.on("accountsChanged",this.accountsChangedHandler)}async switchNetwork(e){this.chainEventListener?.onChainChanged(e.chainId)}async signTypedData(e,r,t){throw new Error("Typed data signing not supported on Tron")}async onAccountChanged(){return Promise.resolve()}async onChainChanged(e){return this.init(e)}release(){this.chainEventListener=void 0,this.accountsChangedHandler&&(this.signerAdapter.off("accountsChanged",this.accountsChangedHandler),this.accountsChangedHandler=void 0)}getContract(e,r,t,n){return o.getContract(r,e,t,n)}getContractWithSigner(e,r,t){throw new Error("Not implemented from TronProviderAdapter")}getContractWithFetcher(e,r,t){const n=s.createCustomRpcProvider(e);return this.getContract(e,r,t,n)}async sendTransaction(e){throw new Error("Not implemented from TronProviderAdapter")}async getGasPrice(e){throw new Error("Not implemented from TronProviderAdapter")}isPermitterAvailable(){return!1}getTronWeb(){return this.tronWeb}}exports.TronProviderAdapter=d;
|
|
@@ -17,6 +17,7 @@ export declare class TronProviderAdapter implements IProviderAdapter<TronWallet>
|
|
|
17
17
|
connectToConnector(): Promise<number>;
|
|
18
18
|
disconnectFromConnector(): Promise<void>;
|
|
19
19
|
connectAndPatchProvider(): Promise<number>;
|
|
20
|
+
getChainId(): number | undefined;
|
|
20
21
|
waitForTransaction(_chainId: number, transactionHash: string, confirmations: number): Promise<boolean>;
|
|
21
22
|
signMessage(message: string | Uint8Array): Promise<string>;
|
|
22
23
|
getAddress(): Promise<string>;
|
|
@@ -77,6 +77,9 @@ class sr {
|
|
|
77
77
|
throw new Error("No Chain Id In Provider Adapter");
|
|
78
78
|
return this.chainId;
|
|
79
79
|
}
|
|
80
|
+
getChainId() {
|
|
81
|
+
return this.chainId;
|
|
82
|
+
}
|
|
80
83
|
async waitForTransaction(r, t, e) {
|
|
81
84
|
const n = t.startsWith("0x") ? t : `0x${t}`;
|
|
82
85
|
if ((await o(r).waitForTransaction(n, e))?.status === 1)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const h=require("../constants/chains.constants.cjs"),a=require("../error-handling/error-codes.constants.cjs"),c=require("ethers"),v=require("wagmi"),o=require("wagmi/actions"),C=require("../functions/web3/getContractMetadata.cjs"),d=require("../types/eip5792.types.cjs"),P=require("../error-handling/logger.cjs");class
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const h=require("../constants/chains.constants.cjs"),a=require("../error-handling/error-codes.constants.cjs"),c=require("ethers"),v=require("wagmi"),o=require("wagmi/actions"),C=require("../functions/web3/getContractMetadata.cjs"),d=require("../types/eip5792.types.cjs"),P=require("../error-handling/logger.cjs");class u{connector;chainId;originalProvider;fetchProviders={};signer;chainEventListener;config;unsubscribeFns=[];constructor(){h.HINKAL_SUPPORTED_CHAINS.forEach(t=>{if(h.isSolanaLike(t))return;const{fetchRpcUrl:r}=h.networkRegistry[t];if(!r)throw Error("No Fetch RPC URL In Provider Adapter");this.fetchProviders[t]=r.includes("wss")?new c.ethers.WebSocketProvider(r):new c.ethers.JsonRpcProvider(r,void 0,{staticNetwork:!0})})}initConnector(t){this.connector=t}initConfig(t){this.config=t}async init(t){if(!this.connector)throw Error("No Connector In Provider Adapter");if(t&&(this.chainId=t),!this.chainId)throw Error("No Chain Id In Provider Adapter");const r=await this.connector.getProvider();this.originalProvider=new c.ethers.BrowserProvider(r);const i=(await this.connector.getAccounts())?.[0];if(!i){this.chainEventListener&&this.chainEventListener.onChainChanged();return}this.signer=await this.walletClientToSigner({transport:r,account:i},this.chainId)}async disconnectFromConnector(){if(!this.config)throw new Error("No Config In Provider Adapter");this.release(),await o.disconnect(this.config)}async connectToConnector(t){if(!this.config)throw new Error("No Config In Provider Adapter");if(t.id==="walletConnect")try{await o.reconnect(this.config,{connectors:[t]}),await o.disconnect(this.config)}catch{}try{return(await o.connect(this.config,{connector:t})).chainId}catch(r){if(r instanceof v.ConnectorAlreadyConnectedError)return t.getChainId();let e=a.transactionErrorCodes.CONNECTION_FAILED;throw r?.code===4001&&(e=a.UserFriendlyErrorCodes.YOU_CANCELED_REQUEST),new Error(e)}}getChainId(){return this.chainId}async waitForTransaction(t,r,e){if((await this.fetchProviders[t]?.waitForTransaction(r,e))?.status)return!0;throw Error(a.transactionErrorCodes.TRANSACTION_NOT_CONFIRMED)}async signMessage(t){if(!this.config)throw new Error("No Config In Provider Adapter");const r=await o.signMessage(this.config,{message:t});if(!r)throw new Error(a.transactionErrorCodes.SIGNING_FAILED);if(r.includes("error"))throw new Error(a.transactionErrorCodes.SIGNATURE_UNSUPPORTED_PERSONAL_SIGN);return r}async signTypedData(t,r,e){return this.signer.signTypedData(t,r,e)}async switchNetwork(t){if(!this.config)throw new Error("No Config In Provider Adapter");return o.switchChain(this.config,{chainId:t.chainId})}async getAddress(){if(!this.config)throw new Error("No Config In Provider Adapter");const{address:t}=o.getAccount(this.config);if(!t)throw new Error("IllegalState");return c.ethers.getAddress(t)}setChainEventListener(t){if(!this.config)throw new Error("No Config In Provider Adapter");this.chainEventListener=t,this.chainEventListener&&(this.unsubscribeFns.push(o.watchAccount(this.config,{onChange:({address:r},{address:e})=>{this.chainEventListener&&r!==e&&this.chainEventListener.onAccountChanged()}})),this.unsubscribeFns.push(o.watchChainId(this.config,{onChange:r=>{this.chainEventListener&&this.chainEventListener.onChainChanged(r)}})))}onAccountChanged(){return this.init()}onChainChanged(t){return this.init(t)}release(){this.removeListeners()}removeListeners(){this.unsubscribeFns.forEach(t=>t()),this.unsubscribeFns=[]}getContract(t,r,e=void 0,i){return C.getContract(r,t,e,i)}getContractWithSigner(t,r,e=void 0){if(!this.signer)throw new Error("IllegalState: no signer");return this.getContract(t,r,e,this.signer)}getContractWithFetcher(t,r,e=void 0){const i=this.fetchProviders[t];if(!i)throw new Error("fetchProvider not initialized");return this.getContract(t,r,e,i)}async sendTransaction(t){if(!this.signer)throw new Error("IllegalState: no signer");return await this.signer.sendTransaction(t)}async connectAndPatchProvider(t){return await this.connectToConnector(t)}isPermitterAvailable(){if(!this.chainId)throw new Error("Illegal state: no chainId");return!!h.networkRegistry[this.chainId]?.contractData?.permitterAddress}async getGasPrice(t){const e=(await this.fetchProviders[t]?.getFeeData())?.gasPrice;if(!e)throw Error("Could not fetch gas price in getGasPrice");return e}async walletClientToSigner(t,r){const{account:e,transport:i}=t;return new c.ethers.BrowserProvider(i).getSigner(e)}async supportsBatchCall(t){if(!this.originalProvider)return!1;try{const r=await this.getAddress(),e=`0x${t.toString(16)}`,i=await this.originalProvider.send("wallet_getCapabilities",[r,[e]]),n=i?.[e]||i?.["0x0"];if(!n?.atomic)return!1;const s=typeof n.atomic=="string"?n.atomic:n.atomic?.status;return s==="supported"||s==="ready"}catch{return!1}}async waitForBatchTransactionStatus(t){if(!this.originalProvider)throw new Error("WagmiProviderAdapter: Provider not initialized");const r=1e3,e=60;for(let i=0;i<e;i+=1){await new Promise(n=>{setTimeout(()=>n(),r)});try{const n=await this.originalProvider.send("wallet_getCallsStatus",[t]);if(n.status===d.CallsStatus.Confirmed&&n.receipts?.[0]?.transactionHash)return n.receipts[0].transactionHash;if(n.status===d.CallsStatus.OffchainFailure||n.status===d.CallsStatus.ChainFailure||n.status===d.CallsStatus.PartialFailure)break}catch(n){P.Logger.log("waitForBatchTransactionStatus:",n)}}throw new Error("Batch transaction timed out or failed")}async sendBatchCallsTransaction(t,r){if(!this.fetchProviders[t])throw new Error("WagmiProviderAdapter: fetchProvider not initialized");if(!this.originalProvider)throw new Error("WagmiProviderAdapter: Provider not initialized");const i=await this.getAddress(),s={version:"2.0.0",chainId:`0x${t.toString(16)}`,from:i,atomicRequired:!0,calls:r},l=await this.originalProvider.send("wallet_sendCalls",[s]),g=l?.id||l;if(!g||typeof g!="string")throw new Error("Invalid batch ID received from wallet_sendCalls");const f=await this.waitForBatchTransactionStatus(g),w=await this.fetchProviders[t].getTransaction(f);if(!w)throw new Error("Transaction not found");return w}}const E=new u,p=()=>new u;exports.WagmiProviderAdapter=u;exports.default=p;exports.wagmiProviderAdapter=E;
|
|
@@ -5,7 +5,7 @@ import { type Connector } from 'wagmi';
|
|
|
5
5
|
import { Call } from '../types/eip5792.types';
|
|
6
6
|
export declare class WagmiProviderAdapter implements IProviderAdapter<Connector> {
|
|
7
7
|
private connector;
|
|
8
|
-
chainId
|
|
8
|
+
private chainId;
|
|
9
9
|
private originalProvider;
|
|
10
10
|
private fetchProviders;
|
|
11
11
|
private signer;
|
|
@@ -18,6 +18,7 @@ export declare class WagmiProviderAdapter implements IProviderAdapter<Connector>
|
|
|
18
18
|
init(chainId?: number): Promise<void>;
|
|
19
19
|
disconnectFromConnector(): Promise<void>;
|
|
20
20
|
connectToConnector(connector: Connector): Promise<number>;
|
|
21
|
+
getChainId(): number | undefined;
|
|
21
22
|
waitForTransaction(chainId: number, transactionHash: string, confirmations: number): Promise<boolean>;
|
|
22
23
|
signMessage(message: string): Promise<string>;
|
|
23
24
|
signTypedData(domain: ethers.TypedDataDomain, types: Record<string, ethers.TypedDataField[]>, value: Record<string, unknown>): Promise<string>;
|
|
@@ -69,6 +69,9 @@ class l {
|
|
|
69
69
|
throw r?.code === 4001 && (i = P.YOU_CANCELED_REQUEST), new Error(i);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
+
getChainId() {
|
|
73
|
+
return this.chainId;
|
|
74
|
+
}
|
|
72
75
|
async waitForTransaction(t, r, i) {
|
|
73
76
|
if ((await this.fetchProviders[t]?.waitForTransaction(r, i))?.status)
|
|
74
77
|
return !0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/../../assets/snarkjsWorkerLauncher-
|
|
1
|
+
"use strict";const e=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/../../assets/snarkjsWorkerLauncher-BaRacf89.js").href:new URL("../../assets/snarkjsWorkerLauncher-BaRacf89.js",document.currentScript&&document.currentScript.src||document.baseURI).href);module.exports=e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const M=require("../workerProxy.cjs"),i=require("../../constants/vite.constants.cjs"),O=require("snarkjs"),F=require("../../data-structures/http/HttpClient.cjs");require("axios");const b=require("../../constants/chains.constants.cjs");function S(e){const a=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(a,t,r.get?r:{enumerable:!0,get:()=>e[t]})}}return a.default=e,Object.freeze(a)}const w=S(O),c=new M.WorkerProxy,k=async e=>new Uint8Array(await F.httpClient.get(e,{responseType:"arraybuffer"})),$=async e=>{try{const{input:a,wasmFilePath:t,zKeyFilePath:r,chainId:n}=e.payload.data,{hostLocation:{origin:u},constants:{isDevelopment:v,chains:{chainIds:l}}}=e.metadata;let s=t,o=r,d,h;const f=s.startsWith("https://");if(i.isNode&&!f){i.isWebpack?(s=`libs/hardhat/test/circuits/${t}`,o=`libs/hardhat/test/circuits/${r}`):!i.isWebpack&&v&&(n===b.chainIds.solanaLocalnet?(s=`tests/circuits/${t}`,o=`tests/circuits/${r}`):(s=`test/circuits/${t}`,o=`test/circuits/${r}`));const g=require("path");s=g.resolve(s),o=g.resolve(o)}i.isNode&&f?(d=await k(s),h=await k(o)):(n===l.localhost||n===b.chainIds.solanaLocalnet||n===l.tronLocalnet)&&!i.isNode&&(s=`${u}/${t}`,o=`${u}/${r}`);const{proof:p,publicSignals:y}=await w.groth16.fullProve(a,d??s,h??o,void 0,void 0,i.isNode&&n===l.tronLocalnet?{singleThread:!0}:void 0),P=await w.groth16.exportSolidityCallData(p,y),m=JSON.parse(`[${P}]`);c.postMessageToMainThread({zkCallData:m,proof:p,publicSignals:y})}catch(a){console.error(a),c.postErrorToMainThread(a)}};c.attachWorkerSideOnMessage($);exports.default=c;exports.onWorkerMessage=$;
|
|
@@ -1,44 +1,42 @@
|
|
|
1
1
|
import { WorkerProxy as T } from "../workerProxy.mjs";
|
|
2
|
-
import { isNode as
|
|
3
|
-
import * as
|
|
2
|
+
import { isNode as n, isWebpack as w } from "../../constants/vite.constants.mjs";
|
|
3
|
+
import * as $ from "snarkjs";
|
|
4
4
|
import { httpClient as b } from "../../data-structures/http/HttpClient.mjs";
|
|
5
5
|
import "axios";
|
|
6
|
-
import { chainIds as
|
|
7
|
-
const
|
|
6
|
+
import { chainIds as g } from "../../constants/chains.constants.mjs";
|
|
7
|
+
const c = new T(), k = async (o) => new Uint8Array(await b.get(o, { responseType: "arraybuffer" })), z = async (o) => {
|
|
8
8
|
try {
|
|
9
|
-
const { input:
|
|
10
|
-
hostLocation: { origin:
|
|
9
|
+
const { input: i, wasmFilePath: e, zKeyFilePath: s, chainId: r } = o.payload.data, {
|
|
10
|
+
hostLocation: { origin: h },
|
|
11
11
|
constants: {
|
|
12
12
|
isDevelopment: F,
|
|
13
|
-
chains: { chainIds:
|
|
13
|
+
chains: { chainIds: l }
|
|
14
14
|
}
|
|
15
|
-
} =
|
|
16
|
-
let t =
|
|
17
|
-
const
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
t =
|
|
15
|
+
} = o.metadata;
|
|
16
|
+
let t = e, a = s, p, f;
|
|
17
|
+
const d = t.startsWith("https://");
|
|
18
|
+
if (n && !d) {
|
|
19
|
+
w ? (t = `libs/hardhat/test/circuits/${e}`, a = `libs/hardhat/test/circuits/${s}`) : !w && F && (r === g.solanaLocalnet ? (t = `tests/circuits/${e}`, a = `tests/circuits/${s}`) : (t = `test/circuits/${e}`, a = `test/circuits/${s}`));
|
|
20
|
+
const y = require("path");
|
|
21
|
+
t = y.resolve(t), a = y.resolve(a);
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
const { proof:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
23
|
+
n && d ? (p = await k(t), f = await k(a)) : (r === l.localhost || r === g.solanaLocalnet || r === l.tronLocalnet) && !n && (t = `${h}/${e}`, a = `${h}/${s}`);
|
|
24
|
+
const { proof: u, publicSignals: m } = await $.groth16.fullProve(
|
|
25
|
+
i,
|
|
26
|
+
p ?? t,
|
|
27
|
+
f ?? a,
|
|
28
28
|
void 0,
|
|
29
29
|
void 0,
|
|
30
|
-
|
|
30
|
+
n && r === l.tronLocalnet ? { singleThread: !0 } : void 0
|
|
31
31
|
// snarkjs hangs in tronbox enviroment if singleThread: true is not provided, which is weird, since if incorrect input is provided it will error out
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
} catch (l) {
|
|
37
|
-
console.error("snarkjs worker logic error", l), d.postErrorToMainThread(l);
|
|
32
|
+
), v = await $.groth16.exportSolidityCallData(u, m), P = JSON.parse(`[${v}]`);
|
|
33
|
+
c.postMessageToMainThread({ zkCallData: P, proof: u, publicSignals: m });
|
|
34
|
+
} catch (i) {
|
|
35
|
+
console.error(i), c.postErrorToMainThread(i);
|
|
38
36
|
}
|
|
39
37
|
};
|
|
40
|
-
|
|
38
|
+
c.attachWorkerSideOnMessage(z);
|
|
41
39
|
export {
|
|
42
|
-
|
|
40
|
+
c as default,
|
|
43
41
|
z as onWorkerMessage
|
|
44
42
|
};
|