@kapa123456789/sdk 0.0.82 → 0.0.84
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/common/src/constants/chains.constants.cjs +1 -1
- package/common/src/constants/chains.constants.mjs +1 -1
- package/common/src/crypto/babyJub.cjs +1 -1
- package/common/src/crypto/babyJub.mjs +1 -1
- package/common/src/crypto/eddsa.cjs +1 -1
- package/common/src/crypto/eddsa.mjs +1 -1
- package/common/src/crypto/poseidon.cjs +1 -1
- package/common/src/crypto/poseidon.mjs +1 -1
- package/common/src/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/common/src/data-structures/Hinkal/Hinkal.mjs +4 -41
- package/common/src/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalDeposit.mjs +46 -73
- package/common/src/data-structures/Hinkal/hinkalTransfer.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalTransfer.mjs +16 -37
- package/common/src/data-structures/Hinkal/hinkalWithdraw.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalWithdraw.mjs +18 -47
- package/common/src/data-structures/crypto-keys/keys.cjs +1 -1
- package/common/src/data-structures/crypto-keys/keys.mjs +8 -2
- package/common/src/data-structures/token-price-fetcher/TokenChecker.cjs +1 -1
- package/common/src/data-structures/token-price-fetcher/TokenChecker.mjs +5 -5
- package/common/src/functions/pre-transaction/getFeeStructure.cjs +1 -1
- package/common/src/functions/pre-transaction/getFeeStructure.mjs +10 -21
- package/common/src/functions/snarkjs/constructGeneralZkProof.cjs +1 -1
- package/common/src/functions/snarkjs/constructGeneralZkProof.mjs +71 -89
- package/common/src/functions/snarkjs/generateMainAndCommitmentZkProof.cjs +1 -1
- package/common/src/functions/snarkjs/generateMainAndCommitmentZkProof.mjs +8 -17
- package/common/src/functions/snarkjs/generateZkProof.cjs +1 -1
- package/common/src/functions/snarkjs/generateZkProof.mjs +8 -26
- package/common/src/functions/utils/evmNetworkFunctions.cjs +1 -1
- package/common/src/functions/utils/evmNetworkFunctions.d.ts +1 -0
- package/common/src/functions/utils/evmNetworkFunctions.mjs +4 -0
- package/common/src/functions/utils/process.utils.cjs +1 -1
- package/common/src/functions/utils/process.utils.mjs +6 -10
- package/common/src/functions/web3/functionCalls/transactCallDirect.cjs +1 -1
- package/common/src/functions/web3/functionCalls/transactCallDirect.mjs +43 -61
- package/common/src/functions/web3/functionCalls/transactCallDirectTron.cjs +1 -1
- package/common/src/functions/web3/functionCalls/transactCallDirectTron.mjs +65 -73
- package/common/src/functions/web3/functionCalls/transactCallRelayer.cjs +1 -1
- package/common/src/functions/web3/functionCalls/transactCallRelayer.mjs +14 -22
- package/common/src/types/scheduled-transactions.types.d.ts +1 -0
- package/common/src/webworker/logError-F50ubgnd.js +2 -0
- package/common/src/webworker/package.json +1 -1
- package/common/src/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.cjs +1 -1
- package/common/src/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.mjs +1 -1
- package/common/src/webworker/snarkjsWorkerNode.cjs +1 -1
- package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.cjs +1 -1
- package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.mjs +1 -1
- package/common/src/webworker/utxoWorkerNode.cjs +1 -1
- package/common/src/webworker/viteWorkerURL.constant.cjs +3 -3
- package/common/src/webworker/viteWorkerURL.constant.mjs +3 -3
- package/common/src/webworker/{workerProxy-D22p2w2G.js → workerProxy-BP_AUL0j.js} +1 -1
- package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.cjs +1 -1
- package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.mjs +1 -1
- package/common/src/webworker/zkProofWorkerNode.cjs +1 -1
- package/functions/integrations/swapApi.cjs +1 -1
- package/functions/integrations/swapApi.mjs +4 -9
- package/package.json +1 -1
- package/services/Hinkal.cjs +1 -1
- package/services/Hinkal.mjs +3 -42
- package/common/src/webworker/logError-o9XP6THu.js +0 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../types/chains.types.cjs`),t=require(`./deploy-data/index.cjs`),n=require(`./vite.constants.cjs`);var r={polygon:137,arbMainnet:42161,ethMainnet:1,optimism:10,optimismTest:1010,base:8453,localhost:31337,arcTestnet:5042002,sepoliaTestnet:11155111,solanaMainnet:501,solanaLocalnet:102,tronNile:3448148188,tronLocalnet:103,tronMainnet:728126428,tempo:4217,bnbMainnet:56,avalanche:43114,cronos:25,monad:143,plasma:9745,ink:57073,hyperEvm:999},i=r.ethMainnet,a=e=>[r.localhost,r.tronLocalnet,r.solanaLocalnet].includes(e),o=e=>e?a(e)?i:e:i,s=e=>e===r.optimismTest?r.optimism:e,c=(e,t)=>s(e)===s(t),l=`X4IiEZsSzGOrJq8tzq7Y3`,u=n.isNotProduction?l:`XzUgeU8YiIIzkD7j2GWnTsFUck7wGgK9`,d=`https://mainnet.helius-rpc.com/?api-key=24718f72-c710-45d6-853e-d447cf530579`,f={[r.ethMainnet]:{name:`Ethereum`,chainId:r.ethMainnet,rpcUrl:`https://rpc.ankr.com/eth`,fetchRpcUrl:`https://eth-mainnet.g.alchemy.com/v2/${u}`,wsRpcUrl:`wss://eth-mainnet.g.alchemy.com/v2/${u}`,supported:!0,contractData:t.ethMainnetData,quoterV2Address:`0x61fFE014bA17989E743c5F6cB21bF9697530B21e`,uniswapV3FactoryAddress:`0x1F98431c8aD98523631AE4a59f267346ea31F984`,priority:1,maxPageSize:9e5},[r.arbMainnet]:{name:`Arbitrum`,chainId:r.arbMainnet,rpcUrl:`https://endpoints.omniatech.io/v1/arbitrum/one/public`,fetchRpcUrl:`https://arb-mainnet.g.alchemy.com/v2/${u}`,wsRpcUrl:`wss://arb-mainnet.g.alchemy.com/v2/${u}`,supported:!0,contractData:t.arbMainnetData,quoterV2Address:`0x61fFE014bA17989E743c5F6cB21bF9697530B21e`,uniswapV3FactoryAddress:`0x1F98431c8aD98523631AE4a59f267346ea31F984`,priority:2,maxPageSize:5e5},[r.optimism]:{name:`Optimism`,chainId:r.optimism,rpcUrl:`https://optimism-mainnet.infura.io/v3/c26b99456bb6464bb498926ff5162903`,fetchRpcUrl:`https://opt-mainnet.g.alchemy.com/v2/${u}`,wsRpcUrl:`wss://opt-mainnet.g.alchemy.com/v2/${u}`,supported:!0,contractData:t.optimismData,quoterV2Address:`0x61fFE014bA17989E743c5F6cB21bF9697530B21e`,uniswapV3FactoryAddress:`0x1F98431c8aD98523631AE4a59f267346ea31F984`,priority:3,maxPageSize:9e5},[r.optimismTest]:{name:`Optimism Test`,chainId:r.optimismTest,rpcUrl:`https://optimism-mainnet.infura.io/v3/c26b99456bb6464bb498926ff5162903`,fetchRpcUrl:`https://opt-mainnet.g.alchemy.com/v2/${u}`,wsRpcUrl:`wss://opt-mainnet.g.alchemy.com/v2/${u}`,supported:!0,contractData:t.optimismTestData,quoterV2Address:`0x61fFE014bA17989E743c5F6cB21bF9697530B21e`,uniswapV3FactoryAddress:`0x1F98431c8aD98523631AE4a59f267346ea31F984`,priority:3,maxPageSize:9e5},[r.polygon]:{name:`Polygon`,chainId:r.polygon,rpcUrl:`https://polygon-rpc.com`,fetchRpcUrl:`https://polygon-mainnet.g.alchemy.com/v2/${u}`,wsRpcUrl:`wss://polygon-mainnet.g.alchemy.com/v2/${u}`,supported:!0,contractData:t.polygonData,quoterV2Address:`0x61fFE014bA17989E743c5F6cB21bF9697530B21e`,uniswapV3FactoryAddress:`0x1F98431c8aD98523631AE4a59f267346ea31F984`,priority:4,maxPageSize:9e5},[r.base]:{name:`Base`,chainId:r.base,rpcUrl:`https://mainnet.base.org/`,fetchRpcUrl:`https://base-mainnet.g.alchemy.com/v2/${u}`,wsRpcUrl:`wss://base-mainnet.g.alchemy.com/v2/${u}`,supported:!0,contractData:t.baseData,quoterV2Address:`0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a`,uniswapV3FactoryAddress:`0x33128a8fC17869897dcE68Ed026d694621f6FDfD`,priority:7,maxPageSize:5e5},[r.arcTestnet]:{name:`Arc Testnet`,chainId:r.arcTestnet,rpcUrl:`https://arc-testnet.g.alchemy.com/v2/${u}`,fetchRpcUrl:`https://arc-testnet.g.alchemy.com/v2/${u}`,wsRpcUrl:`wss://arc-testnet.g.alchemy.com/v2/${u}`,supported:!0,contractData:t.arcTestnetData,priority:8,maxPageSize:9999},[r.solanaMainnet]:{name:`Solana`,chainId:r.solanaMainnet,rpcUrl:`https://api.mainnet-beta.solana.com`,fetchRpcUrl:`https://mainnet.helius-rpc.com/?api-key=54ad9ec9-dad6-41de-b961-e3e8ea7a7188`,supported:!0,contractData:t.solanaData,priority:8},[r.solanaLocalnet]:{name:`Solana Localnet`,chainId:r.solanaLocalnet,rpcUrl:`http://127.0.0.1:8899`,fetchRpcUrl:`http://127.0.0.1:8899`,supported:!0,contractData:t.solanaData,priority:9},[r.tronNile]:{name:`Tron Nile`,chainId:r.tronNile,rpcUrl:`https://tron-testnet.g.alchemy.com/v2/${u}`,fetchRpcUrl:`https://tron-testnet.g.alchemy.com/v2/${u}`,supported:!0,contractData:t.tronNileData,priority:9,maxPageSize:5e5},[r.tronMainnet]:{name:`Tron`,chainId:r.tronMainnet,rpcUrl:`https://tron-mainnet.g.alchemy.com/v2/${u}`,fetchRpcUrl:`https://tron-mainnet.g.alchemy.com/v2/${u}`,supported:!0,priority:10,contractData:t.tronMainnetData,maxPageSize:5e5},[r.sepoliaTestnet]:{name:`Sepolia Testnet`,chainId:r.sepoliaTestnet,rpcUrl:`https://eth-sepolia.g.alchemy.com/v2/${u}`,fetchRpcUrl:`https://eth-sepolia.g.alchemy.com/v2/${u}`,supported:!0,priority:11,contractData:t.sepoliaTestnetData,quoterV2Address:`0xEd1f6473345F45b75F8179591dd5bA1888cf2FB3`,uniswapV3FactoryAddress:`0x0227628f3F023bb0B980b67D528571c95c6DaC1c`,maxPageSize:9e5},[r.tempo]:{name:`Tempo`,chainId:r.tempo,rpcUrl:`https://rpc.tempo.xyz`,fetchRpcUrl:`https://rpc.tempo.xyz`,supported:!0,priority:12,contractData:t.tempoData,quoterV2Address:`0x53ab5d7a69db158f621b43ee70423da1e1403c2a`,uniswapV3FactoryAddress:`0x24a3d4757e330890a8b8978028c9e58e04611fd6`,maxPageSize:9999},[r.bnbMainnet]:{name:`BNB Chain`,chainId:r.bnbMainnet,rpcUrl:`https://bsc-dataseed.binance.org`,fetchRpcUrl:`https://bnb-mainnet.g.alchemy.com/v2/${u}`,wsRpcUrl:`wss://bnb-mainnet.g.alchemy.com/v2/${u}`,supported:!0,contractData:{},quoterV2Address:`0x78D78E420Da98ad378D7799bE8f4AF69033EB077`,uniswapV3FactoryAddress:`0xdB1d10011AD0Ff90774D0C6Bb92e5C5c8b4461F7`,priority:13},[r.avalanche]:{name:`Avalanche`,chainId:r.avalanche,rpcUrl:`https://api.avax.network/ext/bc/C/rpc`,fetchRpcUrl:`https://api.avax.network/ext/bc/C/rpc`,supported:!1,contractData:{},priority:14},[r.cronos]:{name:`Cronos`,chainId:r.cronos,rpcUrl:`https://evm.cronos.org`,fetchRpcUrl:`https://evm.cronos.org`,supported:!1,contractData:{},priority:15},[r.monad]:{name:`Monad`,chainId:r.monad,rpcUrl:`https://rpc.monad.xyz`,fetchRpcUrl:`https://rpc.monad.xyz`,supported:!1,contractData:{},priority:16},[r.plasma]:{name:`Plasma`,chainId:r.plasma,rpcUrl:`https://rpc.plasma.to`,fetchRpcUrl:`https://rpc.plasma.to`,supported:!1,contractData:{},priority:17},[r.ink]:{name:`Ink`,chainId:r.ink,rpcUrl:`https://rpc-gel.inkonchain.com`,fetchRpcUrl:`https://rpc-gel.inkonchain.com`,supported:!1,contractData:{},priority:18},[r.hyperEvm]:{name:`HyperEVM`,chainId:r.hyperEvm,rpcUrl:`https://rpc.hyperliquid.xyz/evm`,fetchRpcUrl:`https://rpc.hyperliquid.xyz/evm`,supported:!1,contractData:{},priority:19},...(n.isDevelopment,{})},p={name:`Localhost`,chainId:r.localhost,rpcUrl:`http://127.0.0.1:8545`,fetchRpcUrl:`http://127.0.0.1:8545`,supported:!0,contractData:t.localhostData,quoterV2Address:f[i].quoterV2Address,uniswapV3FactoryAddress:f[i].uniswapV3FactoryAddress,priority:7};n.isDevelopment&&(f[r.localhost]=p),e.EthereumNetworkType.Mainnet,r.polygon,r.arbMainnet,r.ethMainnet,r.bnbMainnet,r.optimism,r.base,r.tronMainnet,r.tempo,e.EthereumNetworkType.Testnet,n.isNotProduction?(r.arcTestnet,r.tronNile,r.sepoliaTestnet,r.optimismTest):(r.arcTestnet,r.sepoliaTestnet),e.EthereumNetworkType.Local,r.localhost;var m=[r.tronNile,r.tronMainnet,r.tronLocalnet],h=[r.solanaMainnet,r.solanaLocalnet],g=e=>h.includes(e),_=e=>m.includes(e),v=e=>e===r.sepoliaTestnet,y=e=>e===r.tempo,b=n.isNotProduction?r.tronNile:r.tronMainnet,x=r.solanaMainnet,S=[r.ethMainnet,r.optimism,r.base,r.polygon,r.arbMainnet,r.arcTestnet,x,r.sepoliaTestnet,r.tronMainnet,r.tronNile,r.tempo],C=[...S.filter(e=>!_(e)),b],w=e=>{let t=C.indexOf(b);t!==-1&&(C[t]=e),b=e},T=S.filter(e=>!_(e)&&!v(e)&&!y(e)),E=[r.sepoliaTestnet,r.tempo],D=C.filter(e=>!E.includes(e)),O=S.filter(e=>e!==r.arcTestnet&&!v(e)&&!(_(e)&&e!==r.tronMainnet)),k=[r.bnbMainnet,r.avalanche,r.cronos,r.monad,r.plasma,r.ink,r.hyperEvm],A=[...O,...k];S.filter(e=>!g(e)&&!_(e)),e.NetworkFilterType.Wallet,e.NetworkFilterType.Pay,e.NetworkFilterType.Bridge,e.NetworkFilterType.Dashboard,r.arcTestnet,r.arcTestnet,exports.ALCHEMY_API_KEY=u,exports.ALCHEMY_TEST_KEY=l,exports.BRIDGE_DESTINATION_CHAINS=A,exports.BRIDGE_DESTINATION_ONLY_CHAINS=k,exports.BRIDGE_SUPPORTED_CHAINS=O,exports.DASHBOARD_EXCLUDED_CHAIN_IDS=E,exports.DASHBOARD_SUPPORTED_CHAINS=D,exports.FRONT_END_SUPPORTED_CHAINS=C,exports.HELIUS_RPC_URL=d,exports.HINKAL_SUPPORTED_CHAINS=S,exports.SOLANA_CHAIN_IDS=h,exports.TRON_CHAIN_IDS=m,exports.WALLET_SUPPORTED_CHAINS=T,exports.chainIds=r,exports.currentSolanaChainId=x,Object.defineProperty(exports,`currentTronChainId`,{enumerable:!0,get:function(){return b}}),exports.getNonLocalhostChainId=o,exports.getOnchainChainId=s,exports.isLocalNetwork=a,exports.isSameOnchainNetwork=c,exports.isSepoliaTestnet=v,exports.isSolanaLike=g,exports.isTempo=y,exports.isTronLike=_,exports.localhostNetwork=i,exports.networkRegistry=f,exports.setHinkalTronChainId=w;
|
|
1
|
+
const e=require(`../types/chains.types.cjs`),t=require(`./deploy-data/index.cjs`),n=require(`./vite.constants.cjs`);var r={polygon:137,arbMainnet:42161,ethMainnet:1,optimism:10,optimismTest:1010,base:8453,localhost:31337,arcTestnet:5042002,sepoliaTestnet:11155111,solanaMainnet:501,solanaLocalnet:102,tronNile:3448148188,tronLocalnet:103,tronMainnet:728126428,tempo:4217,bnbMainnet:56,avalanche:43114,cronos:25,monad:143,plasma:9745,ink:57073,hyperEvm:999},i=r.ethMainnet,a=e=>[r.localhost,r.tronLocalnet,r.solanaLocalnet].includes(e),o=e=>e?a(e)?i:e:i,s=e=>e===r.optimismTest?r.optimism:e,c=(e,t)=>s(e)===s(t),l=`X4IiEZsSzGOrJq8tzq7Y3`,u=n.isNotProduction?l:`XzUgeU8YiIIzkD7j2GWnTsFUck7wGgK9`,d=`https://mainnet.helius-rpc.com/?api-key=24718f72-c710-45d6-853e-d447cf530579`,f={[r.ethMainnet]:{name:`Ethereum`,chainId:r.ethMainnet,rpcUrl:`https://rpc.ankr.com/eth`,fetchRpcUrl:`https://eth-mainnet.g.alchemy.com/v2/${u}`,wsRpcUrl:`wss://eth-mainnet.g.alchemy.com/v2/${u}`,supported:!0,contractData:t.ethMainnetData,quoterV2Address:`0x61fFE014bA17989E743c5F6cB21bF9697530B21e`,uniswapV3FactoryAddress:`0x1F98431c8aD98523631AE4a59f267346ea31F984`,priority:1,maxPageSize:9e5},[r.arbMainnet]:{name:`Arbitrum`,chainId:r.arbMainnet,rpcUrl:`https://endpoints.omniatech.io/v1/arbitrum/one/public`,fetchRpcUrl:`https://arb-mainnet.g.alchemy.com/v2/${u}`,wsRpcUrl:`wss://arb-mainnet.g.alchemy.com/v2/${u}`,supported:!0,contractData:t.arbMainnetData,quoterV2Address:`0x61fFE014bA17989E743c5F6cB21bF9697530B21e`,uniswapV3FactoryAddress:`0x1F98431c8aD98523631AE4a59f267346ea31F984`,priority:2,maxPageSize:5e5},[r.optimism]:{name:`Optimism`,chainId:r.optimism,rpcUrl:`https://optimism-mainnet.infura.io/v3/c26b99456bb6464bb498926ff5162903`,fetchRpcUrl:`https://opt-mainnet.g.alchemy.com/v2/${u}`,wsRpcUrl:`wss://opt-mainnet.g.alchemy.com/v2/${u}`,supported:!0,contractData:t.optimismData,quoterV2Address:`0x61fFE014bA17989E743c5F6cB21bF9697530B21e`,uniswapV3FactoryAddress:`0x1F98431c8aD98523631AE4a59f267346ea31F984`,priority:3,maxPageSize:9e5},[r.optimismTest]:{name:`Optimism Test`,chainId:r.optimismTest,rpcUrl:`https://optimism-mainnet.infura.io/v3/c26b99456bb6464bb498926ff5162903`,fetchRpcUrl:`https://opt-mainnet.g.alchemy.com/v2/${u}`,wsRpcUrl:`wss://opt-mainnet.g.alchemy.com/v2/${u}`,supported:!0,contractData:t.optimismTestData,quoterV2Address:`0x61fFE014bA17989E743c5F6cB21bF9697530B21e`,uniswapV3FactoryAddress:`0x1F98431c8aD98523631AE4a59f267346ea31F984`,priority:3,maxPageSize:9e5},[r.polygon]:{name:`Polygon`,chainId:r.polygon,rpcUrl:`https://polygon-rpc.com`,fetchRpcUrl:`https://polygon-mainnet.g.alchemy.com/v2/${u}`,wsRpcUrl:`wss://polygon-mainnet.g.alchemy.com/v2/${u}`,supported:!0,contractData:t.polygonData,quoterV2Address:`0x61fFE014bA17989E743c5F6cB21bF9697530B21e`,uniswapV3FactoryAddress:`0x1F98431c8aD98523631AE4a59f267346ea31F984`,priority:4,maxPageSize:9e5},[r.base]:{name:`Base`,chainId:r.base,rpcUrl:`https://mainnet.base.org/`,fetchRpcUrl:`https://base-mainnet.g.alchemy.com/v2/${u}`,wsRpcUrl:`wss://base-mainnet.g.alchemy.com/v2/${u}`,supported:!0,contractData:t.baseData,quoterV2Address:`0x3d4e44Eb1374240CE5F1B871ab261CD16335B76a`,uniswapV3FactoryAddress:`0x33128a8fC17869897dcE68Ed026d694621f6FDfD`,priority:7,maxPageSize:5e5},[r.arcTestnet]:{name:`Arc Testnet`,chainId:r.arcTestnet,rpcUrl:`https://arc-testnet.g.alchemy.com/v2/${u}`,fetchRpcUrl:`https://arc-testnet.g.alchemy.com/v2/${u}`,wsRpcUrl:`wss://arc-testnet.g.alchemy.com/v2/${u}`,supported:!0,contractData:t.arcTestnetData,priority:8,maxPageSize:9999},[r.solanaMainnet]:{name:`Solana`,chainId:r.solanaMainnet,rpcUrl:`https://api.mainnet-beta.solana.com`,fetchRpcUrl:`https://mainnet.helius-rpc.com/?api-key=54ad9ec9-dad6-41de-b961-e3e8ea7a7188`,supported:!0,contractData:t.solanaData,priority:8},[r.solanaLocalnet]:{name:`Solana Localnet`,chainId:r.solanaLocalnet,rpcUrl:`http://127.0.0.1:8899`,fetchRpcUrl:`http://127.0.0.1:8899`,supported:!0,contractData:t.solanaData,priority:9},[r.tronNile]:{name:`Tron Nile`,chainId:r.tronNile,rpcUrl:`https://tron-testnet.g.alchemy.com/v2/${u}`,fetchRpcUrl:`https://tron-testnet.g.alchemy.com/v2/${u}`,supported:!0,contractData:t.tronNileData,priority:9,maxPageSize:5e5},[r.tronMainnet]:{name:`Tron`,chainId:r.tronMainnet,rpcUrl:`https://tron-mainnet.g.alchemy.com/v2/${u}`,fetchRpcUrl:`https://tron-mainnet.g.alchemy.com/v2/${u}`,supported:!0,priority:10,contractData:t.tronMainnetData,maxPageSize:5e5},[r.sepoliaTestnet]:{name:`Sepolia Testnet`,chainId:r.sepoliaTestnet,rpcUrl:`https://eth-sepolia.g.alchemy.com/v2/${u}`,fetchRpcUrl:`https://eth-sepolia.g.alchemy.com/v2/${u}`,supported:!0,priority:11,contractData:t.sepoliaTestnetData,quoterV2Address:`0xEd1f6473345F45b75F8179591dd5bA1888cf2FB3`,uniswapV3FactoryAddress:`0x0227628f3F023bb0B980b67D528571c95c6DaC1c`,maxPageSize:9e5},[r.tempo]:{name:`Tempo`,chainId:r.tempo,rpcUrl:`https://rpc.tempo.xyz`,fetchRpcUrl:`https://rpc.tempo.xyz`,supported:!0,priority:12,contractData:t.tempoData,quoterV2Address:`0x53ab5d7a69db158f621b43ee70423da1e1403c2a`,uniswapV3FactoryAddress:`0x24a3d4757e330890a8b8978028c9e58e04611fd6`,maxPageSize:9999},[r.bnbMainnet]:{name:`BNB Chain`,chainId:r.bnbMainnet,rpcUrl:`https://bsc-dataseed.binance.org`,fetchRpcUrl:`https://bnb-mainnet.g.alchemy.com/v2/${u}`,wsRpcUrl:`wss://bnb-mainnet.g.alchemy.com/v2/${u}`,supported:!0,contractData:{},quoterV2Address:`0x78D78E420Da98ad378D7799bE8f4AF69033EB077`,uniswapV3FactoryAddress:`0xdB1d10011AD0Ff90774D0C6Bb92e5C5c8b4461F7`,priority:13},[r.avalanche]:{name:`Avalanche`,chainId:r.avalanche,rpcUrl:`https://api.avax.network/ext/bc/C/rpc`,fetchRpcUrl:`https://api.avax.network/ext/bc/C/rpc`,supported:!1,contractData:{},priority:14},[r.cronos]:{name:`Cronos`,chainId:r.cronos,rpcUrl:`https://evm.cronos.org`,fetchRpcUrl:`https://evm.cronos.org`,supported:!1,contractData:{},priority:15},[r.monad]:{name:`Monad`,chainId:r.monad,rpcUrl:`https://rpc.monad.xyz`,fetchRpcUrl:`https://rpc.monad.xyz`,supported:!1,contractData:{},priority:16},[r.plasma]:{name:`Plasma`,chainId:r.plasma,rpcUrl:`https://rpc.plasma.to`,fetchRpcUrl:`https://rpc.plasma.to`,supported:!1,contractData:{},priority:17},[r.ink]:{name:`Ink`,chainId:r.ink,rpcUrl:`https://rpc-gel.inkonchain.com`,fetchRpcUrl:`https://rpc-gel.inkonchain.com`,supported:!1,contractData:{},priority:18},[r.hyperEvm]:{name:`HyperEVM`,chainId:r.hyperEvm,rpcUrl:`https://rpc.hyperliquid.xyz/evm`,fetchRpcUrl:`https://rpc.hyperliquid.xyz/evm`,supported:!1,contractData:{},priority:19},...(n.isDevelopment,{})},p={name:`Localhost`,chainId:r.localhost,rpcUrl:`http://127.0.0.1:8545`,fetchRpcUrl:`http://127.0.0.1:8545`,supported:!0,contractData:t.localhostData,quoterV2Address:f[i].quoterV2Address,uniswapV3FactoryAddress:f[i].uniswapV3FactoryAddress,priority:7};n.isDevelopment&&(f[r.localhost]=p),e.EthereumNetworkType.Mainnet,r.polygon,r.arbMainnet,r.ethMainnet,r.bnbMainnet,r.optimism,r.base,r.tronMainnet,r.tempo,r.solanaMainnet,r.avalanche,r.cronos,r.monad,r.plasma,r.ink,r.hyperEvm,e.EthereumNetworkType.Testnet,n.isNotProduction?(r.arcTestnet,r.tronNile,r.sepoliaTestnet,r.optimismTest):(r.arcTestnet,r.sepoliaTestnet),e.EthereumNetworkType.Local,r.localhost,r.solanaLocalnet,r.tronLocalnet;var m=[r.tronNile,r.tronMainnet,r.tronLocalnet],h=[r.solanaMainnet,r.solanaLocalnet],g=e=>h.includes(e),_=e=>m.includes(e),v=e=>e===r.sepoliaTestnet,y=e=>e===r.tempo,b=n.isNotProduction?r.tronNile:r.tronMainnet,x=r.solanaMainnet,S=[r.ethMainnet,r.optimism,r.base,r.polygon,r.arbMainnet,r.arcTestnet,x,r.sepoliaTestnet,r.tronMainnet,r.tronNile,r.tempo],C=[...S.filter(e=>!_(e)),b],w=e=>{let t=C.indexOf(b);t!==-1&&(C[t]=e),b=e},T=S.filter(e=>!_(e)&&!v(e)&&!y(e)),E=[r.sepoliaTestnet,r.tempo],D=C.filter(e=>!E.includes(e)),O=S.filter(e=>e!==r.arcTestnet&&!v(e)&&!(_(e)&&e!==r.tronMainnet)),k=[r.bnbMainnet,r.avalanche,r.cronos,r.monad,r.plasma,r.ink,r.hyperEvm],A=[...O,...k];S.filter(e=>!g(e)&&!_(e)),e.NetworkFilterType.Wallet,e.NetworkFilterType.Pay,e.NetworkFilterType.Bridge,e.NetworkFilterType.Dashboard,r.arcTestnet,r.arcTestnet,exports.ALCHEMY_API_KEY=u,exports.ALCHEMY_TEST_KEY=l,exports.BRIDGE_DESTINATION_CHAINS=A,exports.BRIDGE_DESTINATION_ONLY_CHAINS=k,exports.BRIDGE_SUPPORTED_CHAINS=O,exports.DASHBOARD_EXCLUDED_CHAIN_IDS=E,exports.DASHBOARD_SUPPORTED_CHAINS=D,exports.FRONT_END_SUPPORTED_CHAINS=C,exports.HELIUS_RPC_URL=d,exports.HINKAL_SUPPORTED_CHAINS=S,exports.SOLANA_CHAIN_IDS=h,exports.TRON_CHAIN_IDS=m,exports.WALLET_SUPPORTED_CHAINS=T,exports.chainIds=r,exports.currentSolanaChainId=x,Object.defineProperty(exports,`currentTronChainId`,{enumerable:!0,get:function(){return b}}),exports.getNonLocalhostChainId=o,exports.getOnchainChainId=s,exports.isLocalNetwork=a,exports.isSameOnchainNetwork=c,exports.isSepoliaTestnet=v,exports.isSolanaLike=g,exports.isTempo=y,exports.isTronLike=_,exports.localhostNetwork=i,exports.networkRegistry=f,exports.setHinkalTronChainId=w;
|
|
@@ -258,7 +258,7 @@ var _ = {
|
|
|
258
258
|
uniswapV3FactoryAddress: E[v].uniswapV3FactoryAddress,
|
|
259
259
|
priority: 7
|
|
260
260
|
};
|
|
261
|
-
h && (E[_.localhost] = D), e.Mainnet, _.polygon, _.arbMainnet, _.ethMainnet, _.bnbMainnet, _.optimism, _.base, _.tronMainnet, _.tempo, e.Testnet, g ? (_.arcTestnet, _.tronNile, _.sepoliaTestnet, _.optimismTest) : (_.arcTestnet, _.sepoliaTestnet), e.Local, _.localhost;
|
|
261
|
+
h && (E[_.localhost] = D), e.Mainnet, _.polygon, _.arbMainnet, _.ethMainnet, _.bnbMainnet, _.optimism, _.base, _.tronMainnet, _.tempo, _.solanaMainnet, _.avalanche, _.cronos, _.monad, _.plasma, _.ink, _.hyperEvm, e.Testnet, g ? (_.arcTestnet, _.tronNile, _.sepoliaTestnet, _.optimismTest) : (_.arcTestnet, _.sepoliaTestnet), e.Local, _.localhost, _.solanaLocalnet, _.tronLocalnet;
|
|
262
262
|
var O = [
|
|
263
263
|
_.tronNile,
|
|
264
264
|
_.tronMainnet,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../../_virtual/_rolldown/runtime.cjs`);let e=require(
|
|
1
|
+
require(`../../../_virtual/_rolldown/runtime.cjs`);let e=require(`@kapa123456789/circomlibjs-hinkal-fork`);var t=new class{babyjub=void 0;async init(){this.babyjub||=await(0,e.buildBabyjub)()}getJub(){return this.babyjub}},n=()=>t.getJub();exports.babyJubInstance=n,exports.jubHolder=t;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../../_virtual/_rolldown/runtime.cjs`);let e=require(
|
|
1
|
+
require(`../../../_virtual/_rolldown/runtime.cjs`);let e=require(`@kapa123456789/circomlibjs-hinkal-fork`);var t=new class{eddsa=void 0;async init(){this.eddsa||=await(0,e.buildEddsa)()}getEddsa(){return this.eddsa}},n=()=>t.getEddsa();exports.eddsaHolder=t,exports.eddsaInstance=n;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../functions/utils/amounts.utils.cjs`);let t=require(`ethers`),n=require(
|
|
1
|
+
require(`../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../functions/utils/amounts.utils.cjs`);let t=require(`ethers`),n=require(`@kapa123456789/circomlibjs-hinkal-fork`);var r=new class{poseidon=void 0;async init(){this.poseidon||=await(0,n.buildPoseidon)()}getPoseidon(){return this.poseidon}};function i(...t){let n=r.getPoseidon();return e.toBigInt(n.F.toString(n(t)))}var a=(...e)=>{let n=r.getPoseidon();return t.ethers.toBeHex(n.F.toString(n([...e])))};exports.poseidonFunction=i,exports.poseidonHash=a,exports.poseidonHolder=r;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { toBigInt as e } from "../functions/utils/amounts.utils.mjs";
|
|
2
2
|
import { ethers as t } from "ethers";
|
|
3
|
-
import { buildPoseidon as n } from "circomlibjs-hinkal-fork";
|
|
3
|
+
import { buildPoseidon as n } from "@kapa123456789/circomlibjs-hinkal-fork";
|
|
4
4
|
var r = new class {
|
|
5
5
|
poseidon = void 0;
|
|
6
6
|
async init() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../functions/utils/serialize.utils.cjs`),t=require(`../../constants/vite.constants.cjs`),n=require(`../../constants/chains.constants.cjs`),r=require(`../../constants/protocol.constants.cjs`),i=require(`../../types/hinkal.types.cjs`),a=require(`../../types/ethereum-network.types.cjs`),o=require(`../../crypto/poseidon.cjs`),s=require(`../../error-handling/error-codes.constants.cjs`),c=require(`../crypto-keys/keys.cjs`),l=require(`../../API/scheduled-transactions-calls.cjs`),u=require(`../../API/API.cjs`),d=require(`../../functions/utils/token-check.utils.cjs`),f=require(`../TokenDBs/PrivateTokensDB.cjs`),p=require(`../../functions/utils/erc20tokenFunctions.cjs`),m=require(`../../functions/web3/events/getShieldedBalance.cjs`),h=require(`../../functions/pre-transaction/solana.cjs`),g=require(`../../functions/web3/getContractMetadata.cjs`),_=require(`../../functions/utils/reloadPage.cjs`),v=require(`../../functions/utils/cacheDevice.utils.cjs`),y=require(`../../providers/SolanaProviderAdapter.cjs`),ee=require(`../../functions/utils/enclave-signature-storage.cjs`),b=require(`../../functions/utils/mnemonics.cjs`),x=require(`../../functions/web3/fetchSolanaMerkleTreeRootHash.cjs`),S=require(`../../functions/private-wallet/emporium.helpers.cjs`),C=require(`./hinkalDeposit.cjs`);require(`../../functions/index.cjs`);const w=require(`./hinkalDepositAndWithdraw.cjs`),T=require(`./hinkalSolanaDeposit.cjs`),E=require(`./hinkalSwap.cjs`),D=require(`./hinkalWithdraw.cjs`),O=require(`../merkle-tree/MerkleTree.cjs`);require(`../merkle-tree/index.cjs`);const k=require(`./resetMerkleTrees.cjs`);require(`../../API/index.cjs`);const A=require(`../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.cjs`),j=require(`./hinkalPrivateWallet.cjs`),M=require(`./hinkalGetRecipientInfo.cjs`),N=require(`./hinkalSignSubAccount.cjs`),P=require(`./hinkalActionReceive.cjs`);require(`../TokenDBs/index.cjs`);const F=require(`./hinkalProoflessDeposit.cjs`),te=require(`./hinkalProxySwap.cjs`),I=require(`./hinkalMultiSend.cjs`),L=require(`./hinkalTransfer.cjs`),R=require(`./hinkalProxyToPrivate.cjs`),z=require(`../../providers/TronProviderAdapter.cjs`),B=require(`./hinkalSolanaDepositAndWithdraw.cjs`),V=require(`./hinkalSolanaWithdraw.cjs`),H=require(`./hinkalSolanaTransfer.cjs`),U=require(`./hinkalSolanaSwap.cjs`),W=require(`./hinkalSolanaProxySend.cjs`),G=require(`./hinkalSolanaProxySwap.cjs`),K=require(`./hinkalSolanaProxyShield.cjs`),q=require(`./hinkalDepositAndBridge.cjs`),J=require(`./hinkalNearDepositAndBridge.cjs`),Y=require(`./hinkalClaimUtxo.cjs`),X=require(`./hinkalSolanaProoflessDeposit.cjs`),Z=require(`./hinkalSolanaClaimUtxo.cjs`),Q=require(`./hinkalWithdrawStuckUtxos.cjs`),ne=require(`../private-balances/HinkalPrivateBalanceController.cjs`);require(`../private-balances/index.cjs`);let $=require(`@solana/web3.js`);var re=class{ethereumProviderAdapter;solanaProviderAdapter;tronProviderAdapter;userKeys;signingMessage=`Login to Hinkal Protocol`;privateTransferSigningMessage=`Login to Hinkal's Private Transfer App`;merkleTreeHinkalByChain={};nullifiersByChain={};encryptedOutputsByChain={};commitmentsSnapshotServiceByChain={};nullifierSnapshotServiceByChain={};utxoUtils;lastCallState=new Map;cacheDevice;generateProofRemotely;disableMerkleTreeUpdates;privateBalances=new ne.HinkalPrivateBalanceController(this);constructor(e){this.userKeys=new c.UserKeys(void 0),e?.tronChainOverride&&n.setHinkalTronChainId(e.tronChainOverride),n.HINKAL_SUPPORTED_CHAINS.forEach(e=>{this.merkleTreeHinkalByChain[e]=O.MerkleTree.create(o.poseidonFunction,0n),this.nullifiersByChain[e]=new Set,this.encryptedOutputsByChain[e]=[]}),this.generateProofRemotely=e?.generateProofRemotely??!0,this.utxoUtils=new A.MultiThreadedUtxoUtils,this.cacheDevice=v.createCacheDevice(e),this.disableMerkleTreeUpdates=e?.disableMerkleTreeUpdates??!1}enforceRateLimit(t,n,r=1e3){let i=Date.now(),a=e.CustomJSONStringify(n),o=this.lastCallState.get(t);if(o&&o.argsKey===a&&i-o.timestamp<r)throw Error(`${t} was already called with the same arguments`);this.lastCallState.set(t,{timestamp:i,argsKey:a})}getProviderAdapter(e){let t=e;t||=this.ethereumProviderAdapter?n.chainIds.ethMainnet:this.solanaProviderAdapter?n.currentSolanaChainId:n.chainIds.tronMainnet;let r;if(r=n.isSolanaLike(t)?this.solanaProviderAdapter:n.isTronLike(t)?this.tronProviderAdapter:this.ethereumProviderAdapter,!r)throw Error(`ProviderAdapter is not initialized`);return r}async initProviderAdapter(e,t){let r=n.chainIds.ethMainnet;t instanceof y.SolanaProviderAdapter?r=n.currentSolanaChainId:t instanceof z.TronProviderAdapter&&(r=n.currentTronChainId),await this.updateProviderAdapter(r,t),t.initConnector(e);let i=await t.connectAndPatchProvider(e);await t.init(i),await this.setListeners()}getSigningMessage(e=i.LoginMessageMode.PROTOCOL){switch(e){case i.LoginMessageMode.PRIVATE_TRANSFER:return this.privateTransferSigningMessage;case i.LoginMessageMode.PROTOCOL:default:return this.signingMessage}}async signHinkalMessage(e=i.LoginMessageMode.PROTOCOL){let t=this.getSigningMessage(e);return this.getProviderAdapter().signMessage(t)}async signSolanaLedgerMessage(){let e=new $.Transaction({blockhash:r.DETERMINISTIC_SOLANA_LEDGER_BLOCKHASH,lastValidBlockHeight:r.DETERMINISTIC_SOLANA_LEDGER_LAST_VALID_BLOCK_HEIGHT,feePayer:this.getSolanaPublicKey()}),t=await this.getProviderAdapter().signTransactionWithoutBroadcast?.(e);if(!t)throw Error(`Failed to sign transaction without broadcast`);return{signature:t.signature,txMessageForSolanaLedger:t.transactionMessageB64}}async initUserKeys(e=i.LoginMessageMode.PROTOCOL){this.userKeys=new c.UserKeys(await this.signHinkalMessage(e))}initUserKeysWithSignature(e){this.userKeys=new c.UserKeys(e)}async initUserKeysFromSeedPhrases(e){let t=b.generateHashFromSeedPhrases(e);this.userKeys=new c.UserKeys(t)}async storeAndGetInitialSignature(e,t=!1,n){let r=await this.getEthereumAddress();if(!r)throw Error(`Connected address not found`);return await ee.storeAndGetSignatureFromEnclave(r,e,t,n)}async resetMerkle(e){this.disableMerkleTreeUpdates||(e?.every(e=>this.isSelectedNetworkSupported(e))??!0)&&await k.resetMerkleTrees(this,e)}getTronWeb(){let e=this.tronProviderAdapter;if(!e)throw Error(`Tron provider adapter not initialized`);if(!(e instanceof z.TronProviderAdapter))throw Error(`Tron provider adapter is not a TronProviderAdapter`);let t=e.getTronWeb();if(!t)throw Error(`TronWeb not available`);return t}getSupportedChains(){return this.ethereumProviderAdapter&&this.solanaProviderAdapter?n.WALLET_SUPPORTED_CHAINS:this.ethereumProviderAdapter?n.HINKAL_SUPPORTED_CHAINS.filter(e=>!n.isSolanaLike(e)&&!n.isTronLike(e)):this.solanaProviderAdapter?n.HINKAL_SUPPORTED_CHAINS.filter(e=>n.isSolanaLike(e)):this.tronProviderAdapter?[n.currentTronChainId]:[]}async waitForTransaction(e,t,n=1){return!!await this.getProviderAdapter(e).waitForTransaction(e,t,n)}getContract(e,t,n=void 0){return this.getProviderAdapter(e).getContract(e,t,n)}getContractWithFetcherByChainId(e,t,n=void 0){return g.getContractWithFetcherByChainId(e,t,n)}async signMessage(e){return await this.getProviderAdapter().signMessage(e)}async signTypedData(e,t,n){return await this.getProviderAdapter().signTypedData(e,t,n)}async signWithSubAccount(e,t,n,r){return N.hinkalSignSubAccount(e,t,n,r)}getContractWithSigner(e,t,n=``){return this.getProviderAdapter(e).getContractWithSigner(e,t,n)}getContractWithFetcher(e,t,n=``){return this.getProviderAdapter(e).getContractWithFetcher(e,t,n)}isSelectedNetworkSupported(e){return!!n.networkRegistry[e]}async switchNetwork(e){let t=this.getProviderAdapter(),r=t.getChainId(),i=r!==void 0&&n.isSameOnchainNetwork(e.chainId,r);if(!(e.chainId===r||i))try{await t.switchNetwork(e)}catch{throw Error(s.transactionErrorCodes.FAILED_TO_SWITCH_NETWORKS)}}isPermitterAvailable(e){return this.getProviderAdapter(e).isPermitterAvailable()}async disconnectFromConnector(){await this.ethereumProviderAdapter?.disconnectFromConnector(),await this.solanaProviderAdapter?.disconnectFromConnector(),await this.tronProviderAdapter?.disconnectFromConnector()}async resetProviderAdapters(){this.ethereumProviderAdapter?.release(),this.solanaProviderAdapter?.release(),this.tronProviderAdapter?.release(),this.ethereumProviderAdapter=void 0,this.solanaProviderAdapter=void 0,this.tronProviderAdapter=void 0}async updateProviderAdapter(e,t){try{n.isSolanaLike(e)?(this.solanaProviderAdapter&&this.solanaProviderAdapter.release(),this.solanaProviderAdapter=t):n.isTronLike(e)?(this.tronProviderAdapter&&this.tronProviderAdapter.release(),this.tronProviderAdapter=t):(this.ethereumProviderAdapter&&this.ethereumProviderAdapter.release(),this.ethereumProviderAdapter=t)}catch(e){throw console.error(e),Error(`updateProviderAdapter failed, please try again.`)}}async setListeners(){this.ethereumProviderAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}}),this.solanaProviderAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}}),this.tronProviderAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}})}async onAccountChanged(){await this.ethereumProviderAdapter?.onAccountChanged(),await this.solanaProviderAdapter?.onAccountChanged(),await this.tronProviderAdapter?.onAccountChanged();let e=i.EventType.AccountChanged;typeof document<`u`?document?.dispatchEvent(new Event(e)):process?.emit(`message`,e,void 0)}async onChainChanged(e){e?await this.getProviderAdapter(e).onChainChanged(e):(await this.disconnectFromConnector(),_.reloadPage())}async monitorConnectedAddress(e){await u.API.monitor(await this.getEthereumAddressByChain(e))}async getBalances(e,t,n,r,i=!1,a,o=!1){return m.getShieldedBalance(this,e,t,n,r,i,this.generateProofRemotely,a,o)}async getTotalBalance(e,n,r,i=!1,a,o=!1){let s=r??await this.getEthereumAddressByChain(e),c=n??this.userKeys,l=await this.getBalances(e,c.getShieldedPrivateKey(),c.getShieldedPublicKey(),s,i,a,o),u=t.isExtension?await f.privateTokensDB.getPrivateTokens(e,s):await p.getErc20TokensForChainAPI(e),d=[];return u.forEach(e=>{let t=e.erc20TokenAddress.toLowerCase(),n=l.get(t),r={token:e,balance:n?.balance??0n,timestamp:n?.timestamp||`0`,nfts:n?.nfts||[]};d.push(r)}),d}async getStuckShieldedBalances(e,t,n,r=!1,i=!1){return(await this.getTotalBalance(e,t,n,r,i,!0)).filter(e=>e.balance>0n)}get privateBalancesWithUSD(){return this.privateBalances.getSnapshot()}onPrivateBalancesWithUSDChange(e){return this.privateBalances.onPrivateBalancesWithUSDChange(e)}async getHinkalTreeRootHash(e){if(n.isSolanaLike(e)){let{hinkalIdl:t,hinkalAddress:r,originalDeployer:i}=n.networkRegistry[e].contractData;if(!t||!r||!i)throw Error(`Missing Solana configuration for chain ${e}`);let a=new $.PublicKey(i),o=h.getMerkleAccountPublicKey(new $.PublicKey(r),a);return x.fetchSolanaMerkleTreeRootHash(this.getSolanaProgram(t),o)}return this.getContractWithFetcherByChainId(e,a.ContractType.HinkalContract).getRootHash()}async resetMerkleTreesIfNecessary(e){let t=(await Promise.all((e??this.getSupportedChains()).map(async e=>{let t=await this.getHinkalTreeRootHash(e);return{chainId:e,needsReset:BigInt(t)!==this.merkleTreeHinkalByChain[e].getRootHash()}}))).filter(e=>e.needsReset).map(e=>e.chainId);t.length>0&&(console.log(`resetting merkle tree in resetMerkleTreesIfNecessary for chains:`,t),await this.resetMerkle(t))}async getEthereumAddress(){let e=this.ethereumProviderAdapter??this.solanaProviderAdapter??this.tronProviderAdapter;if(!e)throw Error(`No provider adapter initialized`);return e.getAddress()}getEthereumAddressByChain(e){return this.getProviderAdapter(e).getAddress()}async getRandomRelay(e,t=!1){return(await u.API.getIdleRelay(e,t)).relay}getGasPrice(e){let t=this.getProviderAdapter(e);if(!t)throw Error(`Illegal State of providerAdapter in Hinkal: no providerAdapter initialized`);return t.getGasPrice(e)}getAPI(){return u.API}snapshotsClearInterval(){this.getSupportedChains().forEach(e=>{this.commitmentsSnapshotServiceByChain[e]?.intervalClear(),this.nullifierSnapshotServiceByChain[e]?.intervalClear()})}async destroy(){this.snapshotsClearInterval(),this.privateBalances.dispose(),await this.resetProviderAdapters()}getRecipientInfo(){return M.getRecipientInfo(this)}async deposit(e,t,n=!0,r=!1){console.log(`[Hinkal.deposit] start`,{amountChanges:t.map(String)});try{let i=await C.hinkalDeposit(this,e,t,n,r);return console.log(`[Hinkal.deposit] success`),i}catch(e){throw console.log(`[Hinkal.deposit] error`,e),e}}async depositSolana(e,t,n=!1){return T.hinkalSolanaDeposit(this,e,t,n)}async depositForOther(e,t,n,r=!0,i=!1,a){return this.enforceRateLimit(this.depositForOther.name,[e,t,n]),C.hinkalDepositForOther(this,e,t,n,r,i,a)}async depositSolanaForOther(e,t,n,r=!1,i){return this.enforceRateLimit(this.depositSolanaForOther.name,[e,t,n]),T.hinkalSolanaDepositForOther(this,e,t,n,r,i)}async depositAndWithdraw(e,t,r,i,a,o,s,c,l=!0){return n.isSolanaLike(d.validateAndGetChainId([e]))?B.hinkalSolanaDepositAndWithdraw(this,e,t,r,i,a,o,s,c):w.hinkalDepositAndWithdraw(this,e,t,r,i,a,o,s,c,l)}async claimUtxo(e,t,r,i){return n.isSolanaLike(d.validateAndGetChainId([e]))?Z.hinkalSolanaClaimUtxo(this,e,t,r,i):Y.hinkalClaimUtxo(this,e,t,r,i)}async depositAndBridge(e,t,n,r,i,a,o,s=!0){return q.hinkalDepositAndBridge(this,e,t,n,r,i,a,o,s)}async checkSendTransactionStatus(e){return l.getScheduledTransactionById(e)}async nearDepositAndBridge(e,t,n,r,i,a,o,s,c){return this.enforceRateLimit(this.nearDepositAndBridge.name,[e,t,n,r]),J.hinkalNearDepositAndBridge(this,e,t,n,r,i,a,o,s,c)}async prooflessDeposit(e,t,r,i,a=!1){return n.isSolanaLike(d.validateAndGetChainId(e))?X.hinkalSolanaProoflessDeposit(this,e,t,r,i,a):F.hinkalProoflessDeposit(this,e,t,r,i,a)}async prooflessDepositWithPublicFee(e,t,r,i,a){let o=d.validateAndGetChainId([e]);return n.isSolanaLike(o)?T.hinkalSolanaProoflessDepositWithPublicFee(this,e,t,r,i,a):F.hinkalProoflessDepositWithPublicFee(this,o,e,t,r,i,a)}getSolanaProgram(e){if(!this.solanaProviderAdapter)throw Error(`No provider adapter initialized`);if(!(`getSolanaProgram`in this.solanaProviderAdapter))throw Error(`Current provider adapter is not a Solana provider adapter`);return this.solanaProviderAdapter.getSolanaProgram(e)}getSolanaPublicKey(){if(!this.solanaProviderAdapter)throw Error(`No provider adapter initialized`);if(!(`getSolanaPublicKey`in this.solanaProviderAdapter))throw Error(`Current provider adapter is not a Solana provider adapter`);return this.solanaProviderAdapter.getSolanaPublicKey()}async transfer(e,t,r,i,a,o){console.log(`[Hinkal.transfer] start`,{recipientAddress:r,amountChanges:t.map(String)}),this.enforceRateLimit(this.transfer.name,[e,t,r]);let s=d.validateAndGetChainId(e);try{if(n.isSolanaLike(s)){console.log(`[Hinkal.transfer] hinkalSolanaTransfer`);let n=await H.hinkalSolanaTransfer(this,e,t,r,i,a,o);return console.log(`[Hinkal.transfer] success (solana)`,{result:n}),n}let c=await L.hinkalTransfer(this,e,t,r,i,a,o);return console.log(`[Hinkal.transfer] success`,{result:c}),c}catch(e){throw console.log(`[Hinkal.transfer] error`,e),e}}async withdraw(e,t,r,i,a,o,s){console.log(`[Hinkal.withdraw] start`,{recipientAddress:r,isRelayerOff:i,deltaAmounts:t.map(String)});let c=d.validateAndGetChainId(e);try{if(n.isSolanaLike(c)){console.log(`[Hinkal.withdraw] hinkalSolanaWithdraw`);let n=await V.hinkalSolanaWithdraw(this,e,t,r,a,o,s);return console.log(`[Hinkal.withdraw] success (solana)`,{result:n}),n}let l=await D.hinkalWithdraw(this,e,t,r,i,a,o,s);return console.log(`[Hinkal.withdraw] success`,{result:l}),l}catch(e){throw console.log(`[Hinkal.withdraw] error`,e),e}}async withdrawStuckUtxos(e,t){return Q.hinkalWithdrawStuckUtxos(this,e,t)}async swap(e,t,r,i,a,o,s){return n.isSolanaLike(d.validateAndGetChainId(e))?this.swapSolana(e,t,i,a,o,s):E.hinkalSwap(this,e,t,r,i,a,o,s)}async swapSolana(e,t,n,r,i,a){let o=JSON.parse(n),s=BigInt(o.swapperAccountSalt),{instructionLists:c,addressLookupTableAccount:l}=o.data;return U.hinkalSolanaSwap(this,e,t,s,c,l,r,i,a)}async actionReceive(e,t,r,i,a,o){if(!a)throw Error(`subAccount is required`);return n.isSolanaLike(d.validateAndGetChainId(e))?K.hinkalSolanaProxyShield(this,e[0],t[0],a,void 0,o):P.hinkalActionReceive(this,e,t,r,i,a,o)}async actionPrivateWallet(e,t,n,r,i,a,o,s,c,l,u=!1,d,f,p){return this.enforceRateLimit(this.actionPrivateWallet.name,[e,t,n,r,i,a,o,s,c,p]),j.hinkalPrivateWallet(this,e,t,n,r,i,a,o,s,c,l,u,d,f,p)}async proxySwap(e,t,r,i,a,o,s,c,l=!1,u,f){return n.isSolanaLike(d.validateAndGetChainId(e))?G.hinkalSolanaProxySwap(this,e,t,i,o,r,s,c,f):te.hinkalProxySwap(this,e,t,r,i,a,o,s,c,l,u,f)}async proxyToPrivate(e,t,r,i,a,o,s){return n.isSolanaLike(d.validateAndGetChainId(e))?(this.enforceRateLimit(this.proxyToPrivate.name,[e[0],t[0],r,i]),K.hinkalSolanaProxyShield(this,e[0],t[0],r,i,s)):R.hinkalProxyToPrivate(this,e,t,i,a,o,r,s)}async proxySend(e,t,r,i,a,o,s){let c=d.validateAndGetChainId(e);if(n.isSolanaLike(c))return W.hinkalSolanaProxySend(this,e[0],t[0],r,i,s);let l=S.createTransaferEmporiumOpsBatch(this,c,e.map(e=>e.erc20TokenAddress),t,i),u=e.map((e,n)=>({token:e,amount:-1n*t[n]}));return await this.actionPrivateWallet(c,[],[],[],l,u,r,a,o,void 0,void 0,void 0,s,void 0)}async multiSendPrivateRecipients(e,t,n){return this.enforceRateLimit(this.multiSendPrivateRecipients.name,[e,t,n]),I.hinkalMultiSendPrivateRecipients(this,e,t,n)}areMerkleTreeUpdatesDisabled(){return this.disableMerkleTreeUpdates}updateMerkleTreeUpdates(e){this.disableMerkleTreeUpdates=e}};exports.Hinkal=re;
|
|
1
|
+
require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../functions/utils/serialize.utils.cjs`),t=require(`../../constants/vite.constants.cjs`),n=require(`../../constants/chains.constants.cjs`),r=require(`../../constants/protocol.constants.cjs`),i=require(`../../types/hinkal.types.cjs`),a=require(`../../types/ethereum-network.types.cjs`),o=require(`../../crypto/poseidon.cjs`),s=require(`../../error-handling/error-codes.constants.cjs`),c=require(`../crypto-keys/keys.cjs`),l=require(`../../API/scheduled-transactions-calls.cjs`),u=require(`../../API/API.cjs`),d=require(`../../functions/utils/token-check.utils.cjs`),f=require(`../TokenDBs/PrivateTokensDB.cjs`),p=require(`../../functions/utils/erc20tokenFunctions.cjs`),m=require(`../../functions/web3/events/getShieldedBalance.cjs`),h=require(`../../functions/pre-transaction/solana.cjs`),g=require(`../../functions/web3/getContractMetadata.cjs`),_=require(`../../functions/utils/reloadPage.cjs`),v=require(`../../functions/utils/cacheDevice.utils.cjs`),y=require(`../../providers/SolanaProviderAdapter.cjs`),ee=require(`../../functions/utils/enclave-signature-storage.cjs`),b=require(`../../functions/utils/mnemonics.cjs`),x=require(`../../functions/web3/fetchSolanaMerkleTreeRootHash.cjs`),S=require(`../../functions/private-wallet/emporium.helpers.cjs`),C=require(`./hinkalDeposit.cjs`);require(`../../functions/index.cjs`);const w=require(`./hinkalDepositAndWithdraw.cjs`),T=require(`./hinkalSolanaDeposit.cjs`),E=require(`./hinkalSwap.cjs`),D=require(`./hinkalWithdraw.cjs`),O=require(`../merkle-tree/MerkleTree.cjs`);require(`../merkle-tree/index.cjs`);const k=require(`./resetMerkleTrees.cjs`);require(`../../API/index.cjs`);const A=require(`../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.cjs`),j=require(`./hinkalPrivateWallet.cjs`),M=require(`./hinkalGetRecipientInfo.cjs`),N=require(`./hinkalSignSubAccount.cjs`),P=require(`./hinkalActionReceive.cjs`);require(`../TokenDBs/index.cjs`);const F=require(`./hinkalProoflessDeposit.cjs`),te=require(`./hinkalProxySwap.cjs`),I=require(`./hinkalMultiSend.cjs`),L=require(`./hinkalTransfer.cjs`),R=require(`./hinkalProxyToPrivate.cjs`),z=require(`../../providers/TronProviderAdapter.cjs`),B=require(`./hinkalSolanaDepositAndWithdraw.cjs`),V=require(`./hinkalSolanaWithdraw.cjs`),H=require(`./hinkalSolanaTransfer.cjs`),U=require(`./hinkalSolanaSwap.cjs`),W=require(`./hinkalSolanaProxySend.cjs`),G=require(`./hinkalSolanaProxySwap.cjs`),K=require(`./hinkalSolanaProxyShield.cjs`),q=require(`./hinkalDepositAndBridge.cjs`),J=require(`./hinkalNearDepositAndBridge.cjs`),Y=require(`./hinkalClaimUtxo.cjs`),X=require(`./hinkalSolanaProoflessDeposit.cjs`),Z=require(`./hinkalSolanaClaimUtxo.cjs`),Q=require(`./hinkalWithdrawStuckUtxos.cjs`),ne=require(`../private-balances/HinkalPrivateBalanceController.cjs`);require(`../private-balances/index.cjs`);let $=require(`@solana/web3.js`);var re=class{ethereumProviderAdapter;solanaProviderAdapter;tronProviderAdapter;userKeys;signingMessage=`Login to Hinkal Protocol`;privateTransferSigningMessage=`Login to Hinkal's Private Transfer App`;merkleTreeHinkalByChain={};nullifiersByChain={};encryptedOutputsByChain={};commitmentsSnapshotServiceByChain={};nullifierSnapshotServiceByChain={};utxoUtils;lastCallState=new Map;cacheDevice;generateProofRemotely;disableMerkleTreeUpdates;privateBalances=new ne.HinkalPrivateBalanceController(this);constructor(e){this.userKeys=new c.UserKeys(void 0),e?.tronChainOverride&&n.setHinkalTronChainId(e.tronChainOverride),n.HINKAL_SUPPORTED_CHAINS.forEach(e=>{this.merkleTreeHinkalByChain[e]=O.MerkleTree.create(o.poseidonFunction,0n),this.nullifiersByChain[e]=new Set,this.encryptedOutputsByChain[e]=[]}),this.generateProofRemotely=e?.generateProofRemotely??!0,this.utxoUtils=new A.MultiThreadedUtxoUtils,this.cacheDevice=v.createCacheDevice(e),this.disableMerkleTreeUpdates=e?.disableMerkleTreeUpdates??!1}enforceRateLimit(t,n,r=1e3){let i=Date.now(),a=e.CustomJSONStringify(n),o=this.lastCallState.get(t);if(o&&o.argsKey===a&&i-o.timestamp<r)throw Error(`${t} was already called with the same arguments`);this.lastCallState.set(t,{timestamp:i,argsKey:a})}getProviderAdapter(e){let t=e;t||=this.ethereumProviderAdapter?n.chainIds.ethMainnet:this.solanaProviderAdapter?n.currentSolanaChainId:n.chainIds.tronMainnet;let r;if(r=n.isSolanaLike(t)?this.solanaProviderAdapter:n.isTronLike(t)?this.tronProviderAdapter:this.ethereumProviderAdapter,!r)throw Error(`ProviderAdapter is not initialized`);return r}async initProviderAdapter(e,t){let r=n.chainIds.ethMainnet;t instanceof y.SolanaProviderAdapter?r=n.currentSolanaChainId:t instanceof z.TronProviderAdapter&&(r=n.currentTronChainId),await this.updateProviderAdapter(r,t),t.initConnector(e);let i=await t.connectAndPatchProvider(e);await t.init(i),await this.setListeners()}getSigningMessage(e=i.LoginMessageMode.PROTOCOL){switch(e){case i.LoginMessageMode.PRIVATE_TRANSFER:return this.privateTransferSigningMessage;case i.LoginMessageMode.PROTOCOL:default:return this.signingMessage}}async signHinkalMessage(e=i.LoginMessageMode.PROTOCOL){let t=this.getSigningMessage(e);return this.getProviderAdapter().signMessage(t)}async signSolanaLedgerMessage(){let e=new $.Transaction({blockhash:r.DETERMINISTIC_SOLANA_LEDGER_BLOCKHASH,lastValidBlockHeight:r.DETERMINISTIC_SOLANA_LEDGER_LAST_VALID_BLOCK_HEIGHT,feePayer:this.getSolanaPublicKey()}),t=await this.getProviderAdapter().signTransactionWithoutBroadcast?.(e);if(!t)throw Error(`Failed to sign transaction without broadcast`);return{signature:t.signature,txMessageForSolanaLedger:t.transactionMessageB64}}async initUserKeys(e=i.LoginMessageMode.PROTOCOL){this.userKeys=new c.UserKeys(await this.signHinkalMessage(e))}initUserKeysWithSignature(e){this.userKeys=new c.UserKeys(e)}async initUserKeysFromSeedPhrases(e){let t=b.generateHashFromSeedPhrases(e);this.userKeys=new c.UserKeys(t)}async storeAndGetInitialSignature(e,t=!1,n){let r=await this.getEthereumAddress();if(!r)throw Error(`Connected address not found`);return await ee.storeAndGetSignatureFromEnclave(r,e,t,n)}async resetMerkle(e){this.disableMerkleTreeUpdates||(e?.every(e=>this.isSelectedNetworkSupported(e))??!0)&&await k.resetMerkleTrees(this,e)}getTronWeb(){let e=this.tronProviderAdapter;if(!e)throw Error(`Tron provider adapter not initialized`);if(!(e instanceof z.TronProviderAdapter))throw Error(`Tron provider adapter is not a TronProviderAdapter`);let t=e.getTronWeb();if(!t)throw Error(`TronWeb not available`);return t}getSupportedChains(){return this.ethereumProviderAdapter&&this.solanaProviderAdapter?n.WALLET_SUPPORTED_CHAINS:this.ethereumProviderAdapter?n.HINKAL_SUPPORTED_CHAINS.filter(e=>!n.isSolanaLike(e)&&!n.isTronLike(e)):this.solanaProviderAdapter?n.HINKAL_SUPPORTED_CHAINS.filter(e=>n.isSolanaLike(e)):this.tronProviderAdapter?[n.currentTronChainId]:[]}async waitForTransaction(e,t,n=1){return!!await this.getProviderAdapter(e).waitForTransaction(e,t,n)}getContract(e,t,n=void 0){return this.getProviderAdapter(e).getContract(e,t,n)}getContractWithFetcherByChainId(e,t,n=void 0){return g.getContractWithFetcherByChainId(e,t,n)}async signMessage(e){return await this.getProviderAdapter().signMessage(e)}async signTypedData(e,t,n){return await this.getProviderAdapter().signTypedData(e,t,n)}async signWithSubAccount(e,t,n,r){return N.hinkalSignSubAccount(e,t,n,r)}getContractWithSigner(e,t,n=``){return this.getProviderAdapter(e).getContractWithSigner(e,t,n)}getContractWithFetcher(e,t,n=``){return this.getProviderAdapter(e).getContractWithFetcher(e,t,n)}isSelectedNetworkSupported(e){return!!n.networkRegistry[e]}async switchNetwork(e){let t=this.getProviderAdapter(),r=t.getChainId(),i=r!==void 0&&n.isSameOnchainNetwork(e.chainId,r);if(!(e.chainId===r||i))try{await t.switchNetwork(e)}catch{throw Error(s.transactionErrorCodes.FAILED_TO_SWITCH_NETWORKS)}}isPermitterAvailable(e){return this.getProviderAdapter(e).isPermitterAvailable()}async disconnectFromConnector(){await this.ethereumProviderAdapter?.disconnectFromConnector(),await this.solanaProviderAdapter?.disconnectFromConnector(),await this.tronProviderAdapter?.disconnectFromConnector()}async resetProviderAdapters(){this.ethereumProviderAdapter?.release(),this.solanaProviderAdapter?.release(),this.tronProviderAdapter?.release(),this.ethereumProviderAdapter=void 0,this.solanaProviderAdapter=void 0,this.tronProviderAdapter=void 0}async updateProviderAdapter(e,t){try{n.isSolanaLike(e)?(this.solanaProviderAdapter&&this.solanaProviderAdapter.release(),this.solanaProviderAdapter=t):n.isTronLike(e)?(this.tronProviderAdapter&&this.tronProviderAdapter.release(),this.tronProviderAdapter=t):(this.ethereumProviderAdapter&&this.ethereumProviderAdapter.release(),this.ethereumProviderAdapter=t)}catch(e){throw console.error(e),Error(`updateProviderAdapter failed, please try again.`)}}async setListeners(){this.ethereumProviderAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}}),this.solanaProviderAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}}),this.tronProviderAdapter?.setChainEventListener({onAccountChanged:()=>{this.onAccountChanged()},onChainChanged:e=>{this.onChainChanged(e)}})}async onAccountChanged(){await this.ethereumProviderAdapter?.onAccountChanged(),await this.solanaProviderAdapter?.onAccountChanged(),await this.tronProviderAdapter?.onAccountChanged();let e=i.EventType.AccountChanged;typeof document<`u`?document?.dispatchEvent(new Event(e)):process?.emit(`message`,e,void 0)}async onChainChanged(e){e?await this.getProviderAdapter(e).onChainChanged(e):(await this.disconnectFromConnector(),_.reloadPage())}async monitorConnectedAddress(e){await u.API.monitor(await this.getEthereumAddressByChain(e))}async getBalances(e,t,n,r,i=!1,a,o=!1){return m.getShieldedBalance(this,e,t,n,r,i,this.generateProofRemotely,a,o)}async getTotalBalance(e,n,r,i=!1,a,o=!1){let s=r??await this.getEthereumAddressByChain(e),c=n??this.userKeys,l=await this.getBalances(e,c.getShieldedPrivateKey(),c.getShieldedPublicKey(),s,i,a,o),u=t.isExtension?await f.privateTokensDB.getPrivateTokens(e,s):await p.getErc20TokensForChainAPI(e),d=[];return u.forEach(e=>{let t=e.erc20TokenAddress.toLowerCase(),n=l.get(t),r={token:e,balance:n?.balance??0n,timestamp:n?.timestamp||`0`,nfts:n?.nfts||[]};d.push(r)}),d}async getStuckShieldedBalances(e,t,n,r=!1,i=!1){return(await this.getTotalBalance(e,t,n,r,i,!0)).filter(e=>e.balance>0n)}get privateBalancesWithUSD(){return this.privateBalances.getSnapshot()}onPrivateBalancesWithUSDChange(e){return this.privateBalances.onPrivateBalancesWithUSDChange(e)}async getHinkalTreeRootHash(e){if(n.isSolanaLike(e)){let{hinkalIdl:t,hinkalAddress:r,originalDeployer:i}=n.networkRegistry[e].contractData;if(!t||!r||!i)throw Error(`Missing Solana configuration for chain ${e}`);let a=new $.PublicKey(i),o=h.getMerkleAccountPublicKey(new $.PublicKey(r),a);return x.fetchSolanaMerkleTreeRootHash(this.getSolanaProgram(t),o)}return this.getContractWithFetcherByChainId(e,a.ContractType.HinkalContract).getRootHash()}async resetMerkleTreesIfNecessary(e){let t=(await Promise.all((e??this.getSupportedChains()).map(async e=>{let t=await this.getHinkalTreeRootHash(e);return{chainId:e,needsReset:BigInt(t)!==this.merkleTreeHinkalByChain[e].getRootHash()}}))).filter(e=>e.needsReset).map(e=>e.chainId);t.length>0&&(console.log(`resetting merkle tree in resetMerkleTreesIfNecessary for chains:`,t),await this.resetMerkle(t))}async getEthereumAddress(){let e=this.ethereumProviderAdapter??this.solanaProviderAdapter??this.tronProviderAdapter;if(!e)throw Error(`No provider adapter initialized`);return e.getAddress()}getEthereumAddressByChain(e){return this.getProviderAdapter(e).getAddress()}async getRandomRelay(e,t=!1){return(await u.API.getIdleRelay(e,t)).relay}getGasPrice(e){let t=this.getProviderAdapter(e);if(!t)throw Error(`Illegal State of providerAdapter in Hinkal: no providerAdapter initialized`);return t.getGasPrice(e)}getAPI(){return u.API}snapshotsClearInterval(){this.getSupportedChains().forEach(e=>{this.commitmentsSnapshotServiceByChain[e]?.intervalClear(),this.nullifierSnapshotServiceByChain[e]?.intervalClear()})}async destroy(){this.snapshotsClearInterval(),this.privateBalances.dispose(),await this.resetProviderAdapters()}getRecipientInfo(){return M.getRecipientInfo(this)}async deposit(e,t,n=!0,r=!1){return C.hinkalDeposit(this,e,t,n,r)}async depositSolana(e,t,n=!1){return T.hinkalSolanaDeposit(this,e,t,n)}async depositForOther(e,t,n,r=!0,i=!1,a){return this.enforceRateLimit(this.depositForOther.name,[e,t,n]),C.hinkalDepositForOther(this,e,t,n,r,i,a)}async depositSolanaForOther(e,t,n,r=!1,i){return this.enforceRateLimit(this.depositSolanaForOther.name,[e,t,n]),T.hinkalSolanaDepositForOther(this,e,t,n,r,i)}async depositAndWithdraw(e,t,r,i,a,o,s,c,l=!0){return n.isSolanaLike(d.validateAndGetChainId([e]))?B.hinkalSolanaDepositAndWithdraw(this,e,t,r,i,a,o,s,c):w.hinkalDepositAndWithdraw(this,e,t,r,i,a,o,s,c,l)}async claimUtxo(e,t,r,i){return n.isSolanaLike(d.validateAndGetChainId([e]))?Z.hinkalSolanaClaimUtxo(this,e,t,r,i):Y.hinkalClaimUtxo(this,e,t,r,i)}async depositAndBridge(e,t,n,r,i,a,o,s=!0){return q.hinkalDepositAndBridge(this,e,t,n,r,i,a,o,s)}async checkSendTransactionStatus(e){return l.getScheduledTransactionById(e)}async nearDepositAndBridge(e,t,n,r,i,a,o,s,c){return this.enforceRateLimit(this.nearDepositAndBridge.name,[e,t,n,r]),J.hinkalNearDepositAndBridge(this,e,t,n,r,i,a,o,s,c)}async prooflessDeposit(e,t,r,i,a=!1){return n.isSolanaLike(d.validateAndGetChainId(e))?X.hinkalSolanaProoflessDeposit(this,e,t,r,i,a):F.hinkalProoflessDeposit(this,e,t,r,i,a)}async prooflessDepositWithPublicFee(e,t,r,i,a){let o=d.validateAndGetChainId([e]);return n.isSolanaLike(o)?T.hinkalSolanaProoflessDepositWithPublicFee(this,e,t,r,i,a):F.hinkalProoflessDepositWithPublicFee(this,o,e,t,r,i,a)}getSolanaProgram(e){if(!this.solanaProviderAdapter)throw Error(`No provider adapter initialized`);if(!(`getSolanaProgram`in this.solanaProviderAdapter))throw Error(`Current provider adapter is not a Solana provider adapter`);return this.solanaProviderAdapter.getSolanaProgram(e)}getSolanaPublicKey(){if(!this.solanaProviderAdapter)throw Error(`No provider adapter initialized`);if(!(`getSolanaPublicKey`in this.solanaProviderAdapter))throw Error(`Current provider adapter is not a Solana provider adapter`);return this.solanaProviderAdapter.getSolanaPublicKey()}async transfer(e,t,r,i,a,o){return this.enforceRateLimit(this.transfer.name,[e,t,r]),n.isSolanaLike(d.validateAndGetChainId(e))?H.hinkalSolanaTransfer(this,e,t,r,i,a,o):L.hinkalTransfer(this,e,t,r,i,a,o)}async withdraw(e,t,r,i,a,o,s){return n.isSolanaLike(d.validateAndGetChainId(e))?V.hinkalSolanaWithdraw(this,e,t,r,a,o,s):D.hinkalWithdraw(this,e,t,r,i,a,o,s)}async withdrawStuckUtxos(e,t){return Q.hinkalWithdrawStuckUtxos(this,e,t)}async swap(e,t,r,i,a,o,s){return n.isSolanaLike(d.validateAndGetChainId(e))?this.swapSolana(e,t,i,a,o,s):E.hinkalSwap(this,e,t,r,i,a,o,s)}async swapSolana(e,t,n,r,i,a){let o=JSON.parse(n),s=BigInt(o.swapperAccountSalt),{instructionLists:c,addressLookupTableAccount:l}=o.data;return U.hinkalSolanaSwap(this,e,t,s,c,l,r,i,a)}async actionReceive(e,t,r,i,a,o){if(!a)throw Error(`subAccount is required`);return n.isSolanaLike(d.validateAndGetChainId(e))?K.hinkalSolanaProxyShield(this,e[0],t[0],a,void 0,o):P.hinkalActionReceive(this,e,t,r,i,a,o)}async actionPrivateWallet(e,t,n,r,i,a,o,s,c,l,u=!1,d,f,p){return this.enforceRateLimit(this.actionPrivateWallet.name,[e,t,n,r,i,a,o,s,c,p]),j.hinkalPrivateWallet(this,e,t,n,r,i,a,o,s,c,l,u,d,f,p)}async proxySwap(e,t,r,i,a,o,s,c,l=!1,u,f){return n.isSolanaLike(d.validateAndGetChainId(e))?G.hinkalSolanaProxySwap(this,e,t,i,o,r,s,c,f):te.hinkalProxySwap(this,e,t,r,i,a,o,s,c,l,u,f)}async proxyToPrivate(e,t,r,i,a,o,s){return n.isSolanaLike(d.validateAndGetChainId(e))?(this.enforceRateLimit(this.proxyToPrivate.name,[e[0],t[0],r,i]),K.hinkalSolanaProxyShield(this,e[0],t[0],r,i,s)):R.hinkalProxyToPrivate(this,e,t,i,a,o,r,s)}async proxySend(e,t,r,i,a,o,s){let c=d.validateAndGetChainId(e);if(n.isSolanaLike(c))return W.hinkalSolanaProxySend(this,e[0],t[0],r,i,s);let l=S.createTransaferEmporiumOpsBatch(this,c,e.map(e=>e.erc20TokenAddress),t,i),u=e.map((e,n)=>({token:e,amount:-1n*t[n]}));return await this.actionPrivateWallet(c,[],[],[],l,u,r,a,o,void 0,void 0,void 0,s,void 0)}async multiSendPrivateRecipients(e,t,n){return this.enforceRateLimit(this.multiSendPrivateRecipients.name,[e,t,n]),I.hinkalMultiSendPrivateRecipients(this,e,t,n)}areMerkleTreeUpdatesDisabled(){return this.disableMerkleTreeUpdates}updateMerkleTreeUpdates(e){this.disableMerkleTreeUpdates=e}};exports.Hinkal=re;
|
|
@@ -317,13 +317,7 @@ var ye = class {
|
|
|
317
317
|
return H(this);
|
|
318
318
|
}
|
|
319
319
|
async deposit(e, t, n = !0, r = !1) {
|
|
320
|
-
|
|
321
|
-
try {
|
|
322
|
-
let i = await j(this, e, t, n, r);
|
|
323
|
-
return console.log("[Hinkal.deposit] success"), i;
|
|
324
|
-
} catch (e) {
|
|
325
|
-
throw console.log("[Hinkal.deposit] error", e), e;
|
|
326
|
-
}
|
|
320
|
+
return j(this, e, t, n, r);
|
|
327
321
|
}
|
|
328
322
|
async depositSolana(e, t, n = !1) {
|
|
329
323
|
return P(this, e, t, n);
|
|
@@ -380,45 +374,14 @@ var ye = class {
|
|
|
380
374
|
return this.solanaProviderAdapter.getSolanaPublicKey();
|
|
381
375
|
}
|
|
382
376
|
async transfer(e, t, n, r, i, a) {
|
|
383
|
-
|
|
384
|
-
recipientAddress: n,
|
|
385
|
-
amountChanges: t.map(String)
|
|
386
|
-
}), this.enforceRateLimit(this.transfer.name, [
|
|
377
|
+
return this.enforceRateLimit(this.transfer.name, [
|
|
387
378
|
e,
|
|
388
379
|
t,
|
|
389
380
|
n
|
|
390
|
-
]);
|
|
391
|
-
let o = v(e);
|
|
392
|
-
try {
|
|
393
|
-
if (c(o)) {
|
|
394
|
-
console.log("[Hinkal.transfer] hinkalSolanaTransfer");
|
|
395
|
-
let o = await ce(this, e, t, n, r, i, a);
|
|
396
|
-
return console.log("[Hinkal.transfer] success (solana)", { result: o }), o;
|
|
397
|
-
}
|
|
398
|
-
let s = await Y(this, e, t, n, r, i, a);
|
|
399
|
-
return console.log("[Hinkal.transfer] success", { result: s }), s;
|
|
400
|
-
} catch (e) {
|
|
401
|
-
throw console.log("[Hinkal.transfer] error", e), e;
|
|
402
|
-
}
|
|
381
|
+
]), c(v(e)) ? ce(this, e, t, n, r, i, a) : Y(this, e, t, n, r, i, a);
|
|
403
382
|
}
|
|
404
383
|
async withdraw(e, t, n, r, i, a, o) {
|
|
405
|
-
|
|
406
|
-
recipientAddress: n,
|
|
407
|
-
isRelayerOff: r,
|
|
408
|
-
deltaAmounts: t.map(String)
|
|
409
|
-
});
|
|
410
|
-
let s = v(e);
|
|
411
|
-
try {
|
|
412
|
-
if (c(s)) {
|
|
413
|
-
console.log("[Hinkal.withdraw] hinkalSolanaWithdraw");
|
|
414
|
-
let r = await se(this, e, t, n, i, a, o);
|
|
415
|
-
return console.log("[Hinkal.withdraw] success (solana)", { result: r }), r;
|
|
416
|
-
}
|
|
417
|
-
let l = await R(this, e, t, n, r, i, a, o);
|
|
418
|
-
return console.log("[Hinkal.withdraw] success", { result: l }), l;
|
|
419
|
-
} catch (e) {
|
|
420
|
-
throw console.log("[Hinkal.withdraw] error", e), e;
|
|
421
|
-
}
|
|
384
|
+
return c(v(e)) ? se(this, e, t, n, i, a, o) : R(this, e, t, n, r, i, a, o);
|
|
422
385
|
}
|
|
423
386
|
async withdrawStuckUtxos(e, t) {
|
|
424
387
|
return _e(this, e, t);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../types/hinkal.types.cjs`),r=require(`../../error-handling/error-codes.constants.cjs`),i=require(`../../functions/utils/time.utils.cjs`),a=require(`../utxo/Utxo.cjs`),o=require(`../../functions/utils/addresses.cjs`),s=require(`../../functions/utils/tron.utils.cjs`),c=require(`../../functions/utils/token-check.utils.cjs`),l=require(`../../functions/web3/events/getShieldedBalance.cjs`),u=require(`../../functions/pre-transaction/outputUtxoProcessing.cjs`),d=require(`../../functions/pre-transaction/constructAdminData.cjs`),f=require(`../../functions/utils/tronSimulation.utils.cjs`),p=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),m=require(`../../functions/web3/functionCalls/waitForErc20Approvals.cjs`),h=require(`../../functions/web3/functionCalls/transactCallDirect.cjs`),g=require(`../../API/admin-calls.cjs`);var _=async(e,t)=>({externalActionData:{externalActionId:0n,externalAddress:s.addressToHexFormat(await e.getEthereumAddressByChain(t)),externalActionMetadata:`0x00`},contractTransaction:void 0,contractToApprove:void 0}),v=async(e,t,n,r)=>{let a=[...await l.addPaddingToUtxos(e,t,n,r)],o=[],s=i.getCurrentTimeInSeconds().toString();for(let t=0;t<n.length;t+=1){let{outputUtxos:n}=u.outputUtxoProcessing(e.userKeys,a[t],r[t],s);o.push(n)}return{inputUtxosArray:a,outputUtxosArray:o}},y=async(n,r,i,a,o,c,l,u=!0,d=!1)=>{
|
|
1
|
+
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../types/hinkal.types.cjs`),r=require(`../../error-handling/error-codes.constants.cjs`),i=require(`../../functions/utils/time.utils.cjs`),a=require(`../utxo/Utxo.cjs`),o=require(`../../functions/utils/addresses.cjs`),s=require(`../../functions/utils/tron.utils.cjs`),c=require(`../../functions/utils/token-check.utils.cjs`),l=require(`../../functions/web3/events/getShieldedBalance.cjs`),u=require(`../../functions/pre-transaction/outputUtxoProcessing.cjs`),d=require(`../../functions/pre-transaction/constructAdminData.cjs`),f=require(`../../functions/utils/tronSimulation.utils.cjs`),p=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),m=require(`../../functions/web3/functionCalls/waitForErc20Approvals.cjs`),h=require(`../../functions/web3/functionCalls/transactCallDirect.cjs`),g=require(`../../API/admin-calls.cjs`);var _=async(e,t)=>({externalActionData:{externalActionId:0n,externalAddress:s.addressToHexFormat(await e.getEthereumAddressByChain(t)),externalActionMetadata:`0x00`},contractTransaction:void 0,contractToApprove:void 0}),v=async(e,t,n,r)=>{let a=[...await l.addPaddingToUtxos(e,t,n,r)],o=[],s=i.getCurrentTimeInSeconds().toString();for(let t=0;t<n.length;t+=1){let{outputUtxos:n}=u.outputUtxoProcessing(e.userKeys,a[t],r[t],s);o.push(n)}return{inputUtxosArray:a,outputUtxosArray:o}},y=async(n,r,i,a,o,c,l,u=!0,d=!1)=>{let p=n.getTronWeb(),{hinkalAddress:h,hinkalABI:g}=e.networkRegistry[r].contractData;if(!g)throw Error(`Hinkal ABI not found`);let _=s.evmHexToTronBase58Address(h),v=await n.getEthereumAddressByChain(r),{totalTrxValue:y,tokensNeedingApproval:b}=s.splitTronTokensByNative(i,a),{a:x,b:S,c:C}=s.parseZkCalldata(o),w=await s.reorderZkCallData(!0,o,l,c,!1);if(!w)throw Error(`Tron proof signature not found`);let T=[w.v,w.r,w.s],E=[l.tokenNumber,l.nullifierAmount,l.outputAmount],D=s.circomDataToArray(c),O=y>0n?Number(y):0;if(d){let e=s.createTronCallData(g,`transact`,[T,x,S,C,E,D]),{transaction:n}=await p.transactionBuilder.triggerSmartContract(_,``,{feeLimit:t.TRON_DEFAULT_FEE_LIMIT_SUN,callValue:O,input:e},[],v);return n}await s.approveTronTokens(p,v,_,b),b.size>0&&await m.waitForTronErc20Approvals(p,v,_,Array.from(b.entries()).map(([e,t])=>({tokenAddress:e,requiredAmount:t}))),u&&(await f.simulateTronTransaction(r,_,`transact`,g,[T,x,S,C,E,D],v,y>0n?y:void 0),await s.assertTronSufficientBalance(p,r,_,v,s.createTronCallData(g,`transact`,[T,x,S,C,E,D]),y));let k=await p.contract(g,_).transact(T,x,S,C,E,D).send({feeLimit:t.TRON_DEFAULT_FEE_LIMIT_SUN,callValue:O}),A=typeof k==`string`?k:k?.txid??k?.transaction?.txID;if(!A)throw Error(`Tron deposit failed (missing txid)`);return A},b=async(r,i,a,o=!0,s=!1)=>{let l=c.validateAndGetChainId(i),u=e.isTronLike(l),d=i.map(e=>e.erc20TokenAddress),[{externalActionData:f,contractTransaction:m,contractToApprove:g},{inputUtxosArray:b,outputUtxosArray:x}]=await Promise.all([_(r,l),v(r,l,d,a)]),{zkCallData:S,circomData:C,dimData:w}=await p.constructZkProof(r.merkleTreeHinkalByChain[l],b,x,r.userKeys,f.externalActionId,f.externalAddress,f.externalActionMetadata,r.generateProofRemotely,n.zeroFeeStructure,t.zeroAddress,l);return u?await y(r,l,i,a,S,C,w,o,s):await h.transactCallDirect(r,l,a,i,S,C,w,g,m,o,s)},x=async(i,s,l,u,f=!0,m=!1,v)=>{let b=c.validateAndGetChainId(s),x=e.isTronLike(b),S=s.map(e=>e.erc20TokenAddress),[C,w,T,,E]=u.split(`,`);if(!o.isValidPrivateAddress(u))throw Error(r.transactionErrorCodes.RECIPIENT_FORMAT_INCORRECT);let D=S.map(e=>[new a.Utxo({amount:0n,erc20TokenAddress:e,nullifyingKey:i.userKeys.getShieldedPrivateKey(),spendingPublicKey:i.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,isNewStyle:!0}),new a.Utxo({amount:0n,erc20TokenAddress:e,nullifyingKey:i.userKeys.getShieldedPrivateKey(),spendingPublicKey:i.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,isNewStyle:!0})]),O=S.map((e,t)=>[new a.Utxo({amount:l[t],erc20TokenAddress:e,H0:[BigInt(w),BigInt(T)],stealthAddress:C,encryptionKey:E,isNewStyle:!0})]),{externalActionData:k,contractTransaction:A,contractToApprove:j}=await _(i,b),{zkCallData:M,circomData:N,dimData:P}=await p.constructZkProof(i.merkleTreeHinkalByChain[b],D,O,i.userKeys,k.externalActionId,k.externalAddress,k.externalActionMetadata,i.generateProofRemotely,n.zeroFeeStructure,t.zeroAddress,b);if(x)return await y(i,b,s,l,M,N,P,f,m);let F=await h.transactCallDirect(i,b,l,s,M,N,P,j,A,f,m);return g.emitTxPublicData(d.constructAdminData(v,b,S,l,await i.getEthereumAddress())),F};exports.hinkalDeposit=b,exports.hinkalDepositForOther=x;
|
|
@@ -35,88 +35,61 @@ var D = async (e, t) => ({
|
|
|
35
35
|
outputUtxosArray: a
|
|
36
36
|
};
|
|
37
37
|
}, k = async (e, r, i, a, o, s, c, l = !0, v = !1) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
c.outputAmount
|
|
54
|
-
], P = f(s), F = E > 0n ? Number(E) : 0;
|
|
55
|
-
if (v) {
|
|
56
|
-
console.log("[hinkalTronDeposit] returnTxData triggerSmartContract");
|
|
57
|
-
let e = p(x, "transact", [
|
|
58
|
-
M,
|
|
59
|
-
O,
|
|
60
|
-
k,
|
|
61
|
-
A,
|
|
62
|
-
N,
|
|
63
|
-
P
|
|
64
|
-
]), { transaction: t } = await y.transactionBuilder.triggerSmartContract(C, "", {
|
|
65
|
-
feeLimit: n,
|
|
66
|
-
callValue: F,
|
|
67
|
-
input: e
|
|
68
|
-
}, [], T);
|
|
69
|
-
return t;
|
|
70
|
-
}
|
|
71
|
-
console.log("[hinkalTronDeposit] approveTronTokens"), await u(y, T, C, D), D.size > 0 && (console.log("[hinkalTronDeposit] waitForTronErc20Approvals"), await w(y, T, C, Array.from(D.entries()).map(([e, t]) => ({
|
|
72
|
-
tokenAddress: e,
|
|
73
|
-
requiredAmount: t
|
|
74
|
-
})))), l && (console.log("[hinkalTronDeposit] simulateTronTransaction + assertTronSufficientBalance"), await S(r, C, "transact", x, [
|
|
38
|
+
let y = e.getTronWeb(), { hinkalAddress: b, hinkalABI: x } = t[r].contractData;
|
|
39
|
+
if (!x) throw Error("Hinkal ABI not found");
|
|
40
|
+
let C = m(b), T = await e.getEthereumAddressByChain(r), { totalTrxValue: E, tokensNeedingApproval: D } = _(i, a), { a: O, b: k, c: A } = h(o), j = await g(!0, o, c, s, !1);
|
|
41
|
+
if (!j) throw Error("Tron proof signature not found");
|
|
42
|
+
let M = [
|
|
43
|
+
j.v,
|
|
44
|
+
j.r,
|
|
45
|
+
j.s
|
|
46
|
+
], N = [
|
|
47
|
+
c.tokenNumber,
|
|
48
|
+
c.nullifierAmount,
|
|
49
|
+
c.outputAmount
|
|
50
|
+
], P = f(s), F = E > 0n ? Number(E) : 0;
|
|
51
|
+
if (v) {
|
|
52
|
+
let e = p(x, "transact", [
|
|
75
53
|
M,
|
|
76
54
|
O,
|
|
77
55
|
k,
|
|
78
56
|
A,
|
|
79
57
|
N,
|
|
80
58
|
P
|
|
81
|
-
],
|
|
82
|
-
M,
|
|
83
|
-
O,
|
|
84
|
-
k,
|
|
85
|
-
A,
|
|
86
|
-
N,
|
|
87
|
-
P
|
|
88
|
-
]), E)), console.log("[hinkalTronDeposit] contract.transact.send");
|
|
89
|
-
let I = await y.contract(x, C).transact(M, O, k, A, N, P).send({
|
|
59
|
+
]), { transaction: t } = await y.transactionBuilder.triggerSmartContract(C, "", {
|
|
90
60
|
feeLimit: n,
|
|
91
|
-
callValue: F
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return
|
|
95
|
-
} catch (e) {
|
|
96
|
-
throw console.log("[hinkalTronDeposit] error", e), e;
|
|
61
|
+
callValue: F,
|
|
62
|
+
input: e
|
|
63
|
+
}, [], T);
|
|
64
|
+
return t;
|
|
97
65
|
}
|
|
66
|
+
await u(y, T, C, D), D.size > 0 && await w(y, T, C, Array.from(D.entries()).map(([e, t]) => ({
|
|
67
|
+
tokenAddress: e,
|
|
68
|
+
requiredAmount: t
|
|
69
|
+
}))), l && (await S(r, C, "transact", x, [
|
|
70
|
+
M,
|
|
71
|
+
O,
|
|
72
|
+
k,
|
|
73
|
+
A,
|
|
74
|
+
N,
|
|
75
|
+
P
|
|
76
|
+
], T, E > 0n ? E : void 0), await d(y, r, C, T, p(x, "transact", [
|
|
77
|
+
M,
|
|
78
|
+
O,
|
|
79
|
+
k,
|
|
80
|
+
A,
|
|
81
|
+
N,
|
|
82
|
+
P
|
|
83
|
+
]), E));
|
|
84
|
+
let I = await y.contract(x, C).transact(M, O, k, A, N, P).send({
|
|
85
|
+
feeLimit: n,
|
|
86
|
+
callValue: F
|
|
87
|
+
}), L = typeof I == "string" ? I : I?.txid ?? I?.transaction?.txID;
|
|
88
|
+
if (!L) throw Error("Tron deposit failed (missing txid)");
|
|
89
|
+
return L;
|
|
98
90
|
}, A = async (t, n, a, o = !0, s = !1) => {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
let c = v(n), l = e(c), u = n.map((e) => e.erc20TokenAddress);
|
|
102
|
-
console.log("[hinkalDeposit] chainId", {
|
|
103
|
-
chainId: c,
|
|
104
|
-
isTron: l
|
|
105
|
-
}), console.log("[hinkalDeposit] getTransactionParameters + getInputAndOutputUtxos");
|
|
106
|
-
let [{ externalActionData: d, contractTransaction: f, contractToApprove: p }, { inputUtxosArray: m, outputUtxosArray: h }] = await Promise.all([D(t, c), O(t, c, u, a)]);
|
|
107
|
-
console.log("[hinkalDeposit] constructZkProof");
|
|
108
|
-
let { zkCallData: g, circomData: _, dimData: y } = await C(t.merkleTreeHinkalByChain[c], m, h, t.userKeys, d.externalActionId, d.externalAddress, d.externalActionMetadata, t.generateProofRemotely, i, r, c);
|
|
109
|
-
if (l) {
|
|
110
|
-
console.log("[hinkalDeposit] hinkalTronDeposit");
|
|
111
|
-
let e = await k(t, c, n, a, g, _, y, o, s);
|
|
112
|
-
return console.log("[hinkalDeposit] success (tron)", { tronResult: e }), e;
|
|
113
|
-
}
|
|
114
|
-
console.log("[hinkalDeposit] transactCallDirect");
|
|
115
|
-
let b = await T(t, c, a, n, g, _, y, p, f, o, s);
|
|
116
|
-
return console.log("[hinkalDeposit] success", { tx: b }), b;
|
|
117
|
-
} catch (e) {
|
|
118
|
-
throw console.log("[hinkalDeposit] error", e), e;
|
|
119
|
-
}
|
|
91
|
+
let c = v(n), l = e(c), u = n.map((e) => e.erc20TokenAddress), [{ externalActionData: d, contractTransaction: f, contractToApprove: p }, { inputUtxosArray: m, outputUtxosArray: h }] = await Promise.all([D(t, c), O(t, c, u, a)]), { zkCallData: g, circomData: _, dimData: y } = await C(t.merkleTreeHinkalByChain[c], m, h, t.userKeys, d.externalActionId, d.externalAddress, d.externalActionMetadata, t.generateProofRemotely, i, r, c);
|
|
92
|
+
return l ? await k(t, c, n, a, g, _, y, o, s) : await T(t, c, a, n, g, _, y, p, f, o, s);
|
|
120
93
|
}, j = async (t, n, o, l, u = !0, d = !1, f) => {
|
|
121
94
|
let p = v(n), m = e(p), h = n.map((e) => e.erc20TokenAddress), [g, _, y, , b] = l.split(",");
|
|
122
95
|
if (!c(l)) throw Error(a.RECIPIENT_FORMAT_INCORRECT);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../error-handling/error-codes.constants.cjs`),r=require(`../../functions/utils/time.utils.cjs`),i=require(`../../types/external-action.types.cjs`),a=require(`../../functions/utils/addresses.cjs`),o=require(`../../functions/utils/tron.utils.cjs`),s=require(`../../functions/utils/token-check.utils.cjs`),c=require(`../../functions/web3/events/getShieldedBalance.cjs`),l=require(`../../functions/pre-transaction/outputUtxoProcessing.cjs`),u=require(`../../functions/pre-transaction/getVolatileTransferAmount.cjs`),d=require(`../../functions/pre-transaction/constructAdminData.cjs`),f=require(`../../functions/pre-transaction/getFeeStructure.cjs`);require(`../../functions/pre-transaction/index.cjs`);const p=require(`../../functions/utils/fees.utils.cjs`),m=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),h=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`),g=require(`../../functions/pre-transaction/merge-with-fee-structure.cjs`);var _=async(e,t,n,i,a,o)=>{let s=[...await c.addPaddingToUtxos(e,t,n,i)],u=[],d=r.getCurrentTimeInSeconds().toString();for(let t=0;t<n.length;t+=1){let{outputUtxos:n}=l.outputUtxoProcessing(e.userKeys,s[t],i[t],d,!0,a,t===0?o:0n);u.push(n)}return{inputUtxosArray:s,outputUtxosArray:u}},v=async(r,c,l,v,y,b,x)=>{
|
|
1
|
+
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../error-handling/error-codes.constants.cjs`),r=require(`../../functions/utils/time.utils.cjs`),i=require(`../../types/external-action.types.cjs`),a=require(`../../functions/utils/addresses.cjs`),o=require(`../../functions/utils/tron.utils.cjs`),s=require(`../../functions/utils/token-check.utils.cjs`),c=require(`../../functions/web3/events/getShieldedBalance.cjs`),l=require(`../../functions/pre-transaction/outputUtxoProcessing.cjs`),u=require(`../../functions/pre-transaction/getVolatileTransferAmount.cjs`),d=require(`../../functions/pre-transaction/constructAdminData.cjs`),f=require(`../../functions/pre-transaction/getFeeStructure.cjs`);require(`../../functions/pre-transaction/index.cjs`);const p=require(`../../functions/utils/fees.utils.cjs`),m=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),h=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`),g=require(`../../functions/pre-transaction/merge-with-fee-structure.cjs`);var _=async(e,t,n,i,a,o)=>{let s=[...await c.addPaddingToUtxos(e,t,n,i)],u=[],d=r.getCurrentTimeInSeconds().toString();for(let t=0;t<n.length;t+=1){let{outputUtxos:n}=l.outputUtxoProcessing(e.userKeys,s[t],i[t],d,!0,a,t===0?o:0n);u.push(n)}return{inputUtxosArray:s,outputUtxosArray:u}},v=async(r,c,l,v,y,b,x)=>{let S=s.validateAndGetChainId(c),C=e.isTronLike(S);if(!a.isValidPrivateAddress(v))throw Error(n.transactionErrorCodes.RECIPIENT_FORMAT_INCORRECT);let w=o.addressToHexFormat(await r.getEthereumAddressByChain(S)),T=c.map(e=>e.erc20TokenAddress),E=await u.modifyVolatileTokenAmountChanges(S,c,l),D=b??await f.getFeeStructure(S,y,T,i.ExternalActionId.Transact,[],5n);D.variableRate||=t.HINKAL_PRIVATE_SEND_VARIABLE_RATE;let O=c[0];if(!O)throw Error(`Transfer Action: No Token Found`);let k=-E[0],A=await p.calculateModifiedFeeStructure(S,O,k,D);await g.mergeWithFeeStructure(S,T,E,A);let[j,{inputUtxosArray:M,outputUtxosArray:N}]=await Promise.all([r.getRandomRelay(S,!0),_(r,S,T,E,v,k)]);if(!j)throw Error(n.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let P={externalActionId:0n,externalAddress:j,externalActionMetadata:`0x00`},{zkCallData:F,circomData:I,dimData:L,commitmentValidationData:R}=await m.constructZkProof(r.merkleTreeHinkalByChain[S],M,N,r.userKeys,P.externalActionId,P.externalAddress,P.externalActionMetadata,r.generateProofRemotely,A,j,S),z=await o.reorderZkCallData(C,F,L,I);return await h.transactCallRelayer(S,F,L,I,R,void 0,void 0,d.constructAdminData(x,S,T,E,w),z)};exports.hinkalTransfer=v;
|
|
@@ -28,43 +28,22 @@ var v = async (e, t, n, i, a, o) => {
|
|
|
28
28
|
outputUtxosArray: c
|
|
29
29
|
};
|
|
30
30
|
}, y = async (r, l, u, y, b, x, S) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
let A = -D[0];
|
|
48
|
-
console.log("[hinkalTransfer] calculateModifiedFeeStructure + mergeWithFeeStructure");
|
|
49
|
-
let j = await m(C, k, A, O);
|
|
50
|
-
await _(C, E, D, j), console.log("[hinkalTransfer] getRandomRelay + getInputAndOutputUtxos");
|
|
51
|
-
let [M, { inputUtxosArray: N, outputUtxosArray: P }] = await Promise.all([r.getRandomRelay(C, !0), v(r, C, E, D, y, A)]);
|
|
52
|
-
if (!M) throw Error(n.RELAYER_NOT_AVAILABLE);
|
|
53
|
-
let F = {
|
|
54
|
-
externalActionId: 0n,
|
|
55
|
-
externalAddress: M,
|
|
56
|
-
externalActionMetadata: "0x00"
|
|
57
|
-
};
|
|
58
|
-
console.log("[hinkalTransfer] constructZkProof");
|
|
59
|
-
let { zkCallData: I, circomData: L, dimData: R, commitmentValidationData: z } = await h(r.merkleTreeHinkalByChain[C], N, P, r.userKeys, F.externalActionId, F.externalAddress, F.externalActionMetadata, r.generateProofRemotely, j, M, C);
|
|
60
|
-
console.log("[hinkalTransfer] reorderZkCallData");
|
|
61
|
-
let B = await s(w, I, R, L), V = f(S, C, E, D, T);
|
|
62
|
-
console.log("[hinkalTransfer] transactCallRelayer");
|
|
63
|
-
let H = await g(C, I, R, L, z, void 0, void 0, V, B);
|
|
64
|
-
return console.log("[hinkalTransfer] success", { txHash: H }), H;
|
|
65
|
-
} catch (e) {
|
|
66
|
-
throw console.log("[hinkalTransfer] error", e), e;
|
|
67
|
-
}
|
|
31
|
+
let C = c(l), w = e(C);
|
|
32
|
+
if (!a(y)) throw Error(n.RECIPIENT_FORMAT_INCORRECT);
|
|
33
|
+
let T = o(await r.getEthereumAddressByChain(C)), E = l.map((e) => e.erc20TokenAddress), D = await d(C, l, u), O = x ?? await p(C, b, E, i.Transact, [], 5n);
|
|
34
|
+
O.variableRate ||= t;
|
|
35
|
+
let k = l[0];
|
|
36
|
+
if (!k) throw Error("Transfer Action: No Token Found");
|
|
37
|
+
let A = -D[0], j = await m(C, k, A, O);
|
|
38
|
+
await _(C, E, D, j);
|
|
39
|
+
let [M, { inputUtxosArray: N, outputUtxosArray: P }] = await Promise.all([r.getRandomRelay(C, !0), v(r, C, E, D, y, A)]);
|
|
40
|
+
if (!M) throw Error(n.RELAYER_NOT_AVAILABLE);
|
|
41
|
+
let F = {
|
|
42
|
+
externalActionId: 0n,
|
|
43
|
+
externalAddress: M,
|
|
44
|
+
externalActionMetadata: "0x00"
|
|
45
|
+
}, { zkCallData: I, circomData: L, dimData: R, commitmentValidationData: z } = await h(r.merkleTreeHinkalByChain[C], N, P, r.userKeys, F.externalActionId, F.externalAddress, F.externalActionMetadata, r.generateProofRemotely, j, M, C), B = await s(w, I, R, L);
|
|
46
|
+
return await g(C, I, R, L, z, void 0, void 0, f(S, C, E, D, T), B);
|
|
68
47
|
};
|
|
69
48
|
//#endregion
|
|
70
49
|
export { y as hinkalTransfer };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../types/hinkal.types.cjs`),r=require(`../../error-handling/error-codes.constants.cjs`),i=require(`../../functions/utils/time.utils.cjs`),a=require(`../../types/external-action.types.cjs`),o=require(`../../functions/utils/tron.utils.cjs`),s=require(`../../functions/utils/token-check.utils.cjs`),c=require(`../../functions/web3/events/getShieldedBalance.cjs`),l=require(`../../functions/pre-transaction/outputUtxoProcessing.cjs`),u=require(`../../functions/pre-transaction/getVolatileTransferAmount.cjs`),d=require(`../../functions/pre-transaction/constructAdminData.cjs`),f=require(`../../functions/pre-transaction/getFeeStructure.cjs`);require(`../../functions/pre-transaction/index.cjs`);const p=require(`../../functions/utils/fees.utils.cjs`),m=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),h=require(`../../functions/web3/functionCalls/transactCallDirect.cjs`),g=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`),_=require(`../../functions/web3/functionCalls/transactCallDirectTron.cjs`),v=require(`../../functions/pre-transaction/merge-with-fee-structure.cjs`);var y=async(e,t,n,r)=>{let a=[...await c.addPaddingToUtxos(e,t,n,r)],o=[],s=i.getCurrentTimeInSeconds().toString();for(let t=0;t<n.length;t+=1){let{outputUtxos:n}=l.outputUtxoProcessing(e.userKeys,a[t],r[t],s);o.push(n)}return{inputUtxosArray:a,outputUtxosArray:o}},b=async(i,c,l,b,x,S,C,w)=>{
|
|
1
|
+
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../types/hinkal.types.cjs`),r=require(`../../error-handling/error-codes.constants.cjs`),i=require(`../../functions/utils/time.utils.cjs`),a=require(`../../types/external-action.types.cjs`),o=require(`../../functions/utils/tron.utils.cjs`),s=require(`../../functions/utils/token-check.utils.cjs`),c=require(`../../functions/web3/events/getShieldedBalance.cjs`),l=require(`../../functions/pre-transaction/outputUtxoProcessing.cjs`),u=require(`../../functions/pre-transaction/getVolatileTransferAmount.cjs`),d=require(`../../functions/pre-transaction/constructAdminData.cjs`),f=require(`../../functions/pre-transaction/getFeeStructure.cjs`);require(`../../functions/pre-transaction/index.cjs`);const p=require(`../../functions/utils/fees.utils.cjs`),m=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),h=require(`../../functions/web3/functionCalls/transactCallDirect.cjs`),g=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`),_=require(`../../functions/web3/functionCalls/transactCallDirectTron.cjs`),v=require(`../../functions/pre-transaction/merge-with-fee-structure.cjs`);var y=async(e,t,n,r)=>{let a=[...await c.addPaddingToUtxos(e,t,n,r)],o=[],s=i.getCurrentTimeInSeconds().toString();for(let t=0;t<n.length;t+=1){let{outputUtxos:n}=l.outputUtxoProcessing(e.userKeys,a[t],r[t],s);o.push(n)}return{inputUtxosArray:a,outputUtxosArray:o}},b=async(i,c,l,b,x,S,C,w)=>{let T=s.validateAndGetChainId(c),E=e.isTronLike(T),D=o.addressToHexFormat(await i.getEthereumAddressByChain(T)),O=c.map(e=>e.erc20TokenAddress),k=await u.modifyVolatileTokenAmountChanges(T,c,l),A=c[0];if(!A)throw Error(`Deposit Action: No Token Found`);let j;if(!x){let e=C??await f.getFeeStructure(T,S,O,a.ExternalActionId.Transact);j=await p.calculateModifiedFeeStructure(T,A,-k[0],e),await v.mergeWithFeeStructure(T,O,k,j)}let M={externalActionId:0n,externalAddress:o.addressToHexFormat(b),externalActionMetadata:`0x00`},[N,{inputUtxosArray:P,outputUtxosArray:F}]=await Promise.all([i.getRandomRelay(T,!0),y(i,T,O,k)]);if(!x&&!N)throw Error(r.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let{zkCallData:I,circomData:L,dimData:R,commitmentValidationData:z}=await m.constructZkProof(i.merkleTreeHinkalByChain[T],P,F,i.userKeys,M.externalActionId,M.externalAddress,M.externalActionMetadata,i.generateProofRemotely,j??n.zeroFeeStructure,x?t.zeroAddress:N,T,void 0,void 0,x?D:void 0),B=E&&x?void 0:await o.reorderZkCallData(E,I,R,L);if(x){if(!A)throw Error(`Withdraw Action: No Token Found`);return E?await _.transactCallDirectTron(i,T,k[0],A,I,L,R):await h.transactCallDirect(i,T,k[0],A,I,L,R)}return await g.transactCallRelayer(T,I,R,L,z,void 0,void 0,d.constructAdminData(w,T,O,k,D),B)};exports.hinkalWithdraw=b;
|
|
@@ -30,54 +30,25 @@ var b = async (e, t, n, r) => {
|
|
|
30
30
|
outputUtxosArray: o
|
|
31
31
|
};
|
|
32
32
|
}, x = async (i, l, u, x, S, C, w, T) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
let E = c(l), D = e(E);
|
|
40
|
-
console.log("[hinkalWithdraw] getEthereumAddressByChain");
|
|
41
|
-
let O = o(await i.getEthereumAddressByChain(E)), k = l.map((e) => e.erc20TokenAddress);
|
|
42
|
-
console.log("[hinkalWithdraw] modifyVolatileTokenAmountChanges");
|
|
43
|
-
let A = await d(E, l, u), j = l[0];
|
|
44
|
-
if (!j) throw Error("Deposit Action: No Token Found");
|
|
45
|
-
let M;
|
|
46
|
-
if (!S) {
|
|
47
|
-
console.log("[hinkalWithdraw] getFeeStructure + mergeWithFeeStructure");
|
|
48
|
-
let e = w ?? await p(E, C, k, a.Transact);
|
|
49
|
-
M = await m(E, j, -A[0], e), await y(E, k, A, M);
|
|
50
|
-
}
|
|
51
|
-
let N = {
|
|
52
|
-
externalActionId: 0n,
|
|
53
|
-
externalAddress: o(x),
|
|
54
|
-
externalActionMetadata: "0x00"
|
|
55
|
-
};
|
|
56
|
-
console.log("[hinkalWithdraw] getRandomRelay + getInputAndOutputUtxos");
|
|
57
|
-
let [P, { inputUtxosArray: F, outputUtxosArray: I }] = await Promise.all([i.getRandomRelay(E, !0), b(i, E, k, A)]);
|
|
58
|
-
if (!S && !P) throw Error(r.RELAYER_NOT_AVAILABLE);
|
|
59
|
-
console.log("[hinkalWithdraw] constructZkProof");
|
|
60
|
-
let { zkCallData: L, circomData: R, dimData: z, commitmentValidationData: B } = await h(i.merkleTreeHinkalByChain[E], F, I, i.userKeys, N.externalActionId, N.externalAddress, N.externalActionMetadata, i.generateProofRemotely, M ?? n, S ? t : P, E, void 0, void 0, S ? O : void 0);
|
|
61
|
-
console.log("[hinkalWithdraw] reorderZkCallData");
|
|
62
|
-
let V = D && S ? void 0 : await s(D, L, z, R);
|
|
63
|
-
if (S) {
|
|
64
|
-
if (!j) throw Error("Withdraw Action: No Token Found");
|
|
65
|
-
if (D) {
|
|
66
|
-
console.log("[hinkalWithdraw] transactCallDirectTron");
|
|
67
|
-
let e = await v(i, E, A[0], j, L, R, z);
|
|
68
|
-
return console.log("[hinkalWithdraw] success (tron direct)", { txid: e }), e;
|
|
69
|
-
}
|
|
70
|
-
console.log("[hinkalWithdraw] transactCallDirect");
|
|
71
|
-
let e = await g(i, E, A[0], j, L, R, z);
|
|
72
|
-
return console.log("[hinkalWithdraw] success (direct)", { tx: e }), e;
|
|
73
|
-
}
|
|
74
|
-
let H = f(T, E, k, A, O);
|
|
75
|
-
console.log("[hinkalWithdraw] transactCallRelayer");
|
|
76
|
-
let U = await _(E, L, z, R, B, void 0, void 0, H, V);
|
|
77
|
-
return console.log("[hinkalWithdraw] success (relayer)", { txHash: U }), U;
|
|
78
|
-
} catch (e) {
|
|
79
|
-
throw console.log("[hinkalWithdraw] error", e), e;
|
|
33
|
+
let E = c(l), D = e(E), O = o(await i.getEthereumAddressByChain(E)), k = l.map((e) => e.erc20TokenAddress), A = await d(E, l, u), j = l[0];
|
|
34
|
+
if (!j) throw Error("Deposit Action: No Token Found");
|
|
35
|
+
let M;
|
|
36
|
+
if (!S) {
|
|
37
|
+
let e = w ?? await p(E, C, k, a.Transact);
|
|
38
|
+
M = await m(E, j, -A[0], e), await y(E, k, A, M);
|
|
80
39
|
}
|
|
40
|
+
let N = {
|
|
41
|
+
externalActionId: 0n,
|
|
42
|
+
externalAddress: o(x),
|
|
43
|
+
externalActionMetadata: "0x00"
|
|
44
|
+
}, [P, { inputUtxosArray: F, outputUtxosArray: I }] = await Promise.all([i.getRandomRelay(E, !0), b(i, E, k, A)]);
|
|
45
|
+
if (!S && !P) throw Error(r.RELAYER_NOT_AVAILABLE);
|
|
46
|
+
let { zkCallData: L, circomData: R, dimData: z, commitmentValidationData: B } = await h(i.merkleTreeHinkalByChain[E], F, I, i.userKeys, N.externalActionId, N.externalAddress, N.externalActionMetadata, i.generateProofRemotely, M ?? n, S ? t : P, E, void 0, void 0, S ? O : void 0), V = D && S ? void 0 : await s(D, L, z, R);
|
|
47
|
+
if (S) {
|
|
48
|
+
if (!j) throw Error("Withdraw Action: No Token Found");
|
|
49
|
+
return D ? await v(i, E, A[0], j, L, R, z) : await g(i, E, A[0], j, L, R, z);
|
|
50
|
+
}
|
|
51
|
+
return await _(E, L, z, R, B, void 0, void 0, f(T, E, k, A, O), V);
|
|
81
52
|
};
|
|
82
53
|
//#endregion
|
|
83
54
|
export { x as hinkalWithdraw };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../../../_virtual/_rolldown/runtime.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../crypto/poseidon.cjs`),r=require(`../../crypto/babyJub.cjs`),i=require(`../../crypto/eddsa.cjs`),a=require(`../cacheDevices/AttachableMemoryCacheDevice.cjs`),o=require(`./keyUtils.cjs`);let s=require(`ethers`),c=require(`@solana/web3.js`),l=require(`bs58`);l=e.__toESM(l);let u=require(`libsodium-wrappers`);u=e.__toESM(u);let d=require(`tweetnacl`);d=e.__toESM(d);let f=require(`tronweb`);var p=new a.AttachableMemoryCacheDevice,m=new a.AttachableMemoryCacheDevice,h=new a.AttachableMemoryCacheDevice,g=class{signature;nullifyingKey;PREFIX_FOR_SPENDING_PAIR=`1`;PREFIX_FOR_NULLIFYING_PAIR=`2`;constructor(e,t){this.signature=e,this.nullifyingKey=t}getSignature(){return this.requireSignature(),this.signature}setSignature(e){this.signature=e}requireSignature(){if(!this.signature)throw Error(`No signature provided`)}requireKeyMaterial(){if(!this.signature&&!this.nullifyingKey)throw Error(`No signature or private key provided`)}verifyTronMessage(e,t){return this.requireSignature(),t===f.Trx.verifyMessageV2(e,this.signature)}getShieldedPrivateKey=()=>(this.requireKeyMaterial(),this.nullifyingKey||=s.ethers.keccak256(this.signature),this.nullifyingKey);getShieldedPublicKey=()=>(this.requireKeyMaterial(),n.poseidonHash(this.getShieldedPrivateKey()));getSpendingKeyPair=()=>{this.requireSignature();let e=i.eddsaInstance(),t=r.babyJubInstance(),a=n.poseidonHash(this.PREFIX_FOR_SPENDING_PAIR,this.getSignature()),o=Buffer.from(s.ethers.getBytes(a)),c=e.prv2pub(o);return{privSpendingKey:a,pubSpendingBJJPoint:[BigInt(t.F.toString(c[0])),BigInt(t.F.toString(c[1]))]}};signEddsa=e=>{this.requireSignature();let t=r.babyJubInstance(),n=i.eddsaInstance(),a=Buffer.from(s.ethers.getBytes(this.getSpendingKeyPair().privSpendingKey))
|
|
1
|
+
const e=require(`../../../../_virtual/_rolldown/runtime.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../crypto/poseidon.cjs`),r=require(`../../crypto/babyJub.cjs`),i=require(`../../crypto/eddsa.cjs`),a=require(`../cacheDevices/AttachableMemoryCacheDevice.cjs`),o=require(`./keyUtils.cjs`);let s=require(`ethers`),c=require(`@solana/web3.js`),l=require(`bs58`);l=e.__toESM(l);let u=require(`libsodium-wrappers`);u=e.__toESM(u);let d=require(`tweetnacl`);d=e.__toESM(d);let f=require(`tronweb`);var p=new a.AttachableMemoryCacheDevice,m=new a.AttachableMemoryCacheDevice,h=new a.AttachableMemoryCacheDevice,g=class{signature;nullifyingKey;PREFIX_FOR_SPENDING_PAIR=`1`;PREFIX_FOR_NULLIFYING_PAIR=`2`;constructor(e,t){this.signature=e,this.nullifyingKey=t}getSignature(){return this.requireSignature(),this.signature}setSignature(e){this.signature=e}requireSignature(){if(!this.signature)throw Error(`No signature provided`)}requireKeyMaterial(){if(!this.signature&&!this.nullifyingKey)throw Error(`No signature or private key provided`)}verifyTronMessage(e,t){return this.requireSignature(),t===f.Trx.verifyMessageV2(e,this.signature)}getShieldedPrivateKey=()=>(this.requireKeyMaterial(),this.nullifyingKey||=s.ethers.keccak256(this.signature),this.nullifyingKey);getShieldedPublicKey=()=>(this.requireKeyMaterial(),n.poseidonHash(this.getShieldedPrivateKey()));getSpendingKeyPair=()=>{this.requireSignature();let e=i.eddsaInstance(),t=r.babyJubInstance(),a=n.poseidonHash(this.PREFIX_FOR_SPENDING_PAIR,this.getSignature()),o=Buffer.from(s.ethers.getBytes(a)),c=e.prv2pub(o);return{privSpendingKey:a,pubSpendingBJJPoint:[BigInt(t.F.toString(c[0])),BigInt(t.F.toString(c[1]))]}};signEddsa=e=>{this.requireSignature();let t=r.babyJubInstance(),n=i.eddsaInstance();console.log(`message`,e),console.log(`this.getSpendingKeyPair().privSpendingKey`,this.getSpendingKeyPair().privSpendingKey);let a=Buffer.from(s.ethers.getBytes(this.getSpendingKeyPair().privSpendingKey));console.log(`prvBytes`,a);let o=t.F.e(e);console.log(`msgF`,o);let c=n.signPoseidon(a,o);return console.log(`sig`,c),{R8:[BigInt(t.F.toString(c.R8[0])),BigInt(t.F.toString(c.R8[1]))],S:BigInt(c.S)}};getShieldedPrivateKeyFromNonce=e=>{this.requireKeyMaterial();let t=n.poseidonHash(e,this.getShieldedPrivateKey(),this.getShieldedPublicKey());return s.ethers.keccak256(s.ethers.toUtf8Bytes(`hinkal-offchain-shielded-key:${t}`))};getClaimableSignatureFromNonce=e=>{this.requireKeyMaterial();let t=n.poseidonHash(e,this.getShieldedPrivateKey(),this.getShieldedPublicKey());return s.ethers.keccak256(s.ethers.toUtf8Bytes(`hinkal-claimable-utxo-signature:${t}`))};getDerivedEthereumAddress=()=>(this.requireKeyMaterial(),new s.ethers.Wallet(this.getShieldedPrivateKey()).address);getDerivedSolanaPublicKey=()=>(this.requireKeyMaterial(),c.Keypair.fromSeed(s.ethers.getBytes(this.getShieldedPrivateKey())).publicKey.toBase58());getNearIntentsAccountId=()=>{this.requireKeyMaterial();let e=c.Keypair.fromSeed(s.ethers.getBytes(this.getShieldedPrivateKey()));return s.ethers.hexlify(e.publicKey.toBytes()).slice(2)};getNearIntentsKeyPairString=()=>{this.requireKeyMaterial();let e=c.Keypair.fromSeed(s.ethers.getBytes(this.getShieldedPrivateKey()));return`ed25519:${l.default.encode(e.secretKey)}`};getSignerPrivateKeyFromNonce=e=>{this.requireKeyMaterial();let t=n.poseidonHash(e,this.getShieldedPrivateKey(),this.getShieldedPublicKey());return s.ethers.keccak256(s.ethers.toUtf8Bytes(t))};getSignerSolanaPrivateKeyFromNonce=e=>{let t=this.getSignerPrivateKeyFromNonce(e),n=s.ethers.getBytes(t),r=c.Keypair.fromSeed(n);return l.default.encode(r.secretKey)};verifyMessage(e){return this.requireSignature(),s.ethers.verifyMessage(e,this.signature)}verifySolanaMessage(e,t){this.requireSignature();let n=new TextEncoder().encode(e),r=s.ethers.getBytes(this.signature),i=new c.PublicKey(t).toBytes();return d.default.sign.detached.verify(n,r,i)}static getRandomizedStealthPairOld=m.attach((e,n)=>{let i=r.babyJubInstance(),a=e*(BigInt(n)%t.CIRCOM_P)%t.CIRCOM_P,o=i.mulPointEscalar(i.Base8,e),s=i.mulPointEscalar(i.Base8,a);return{H0:[BigInt(i.F.toString(o[0])),BigInt(i.F.toString(o[1]))],H1:[BigInt(i.F.toString(s[0])),BigInt(i.F.toString(s[1]))]}});static getRandomizedStealthPair=p.attach((e,n)=>{let i=r.babyJubInstance(),a=BigInt(n)%t.CIRCOM_P,o=i.mulPointEscalar(i.Base8,e),s=i.mulPointEscalar(o,a);return{H0:[BigInt(i.F.toString(o[0])),BigInt(i.F.toString(o[1]))],H1:[BigInt(i.F.toString(s[0])),BigInt(i.F.toString(s[1]))]}});static getStealthAddressCompressedPoints=(e,t)=>{let{H0:n,H1:r}=this.getRandomizedStealthPairOld(e,t),[i,a]=[n,r].map(e=>BigInt(e[1])+2n**255n*o.getCircomSign(e[0]));return{h0:i,h1:a}};static checkSignature=(e,t,n,r)=>{let{h0:i,h1:a}=this.getStealthAddressCompressedPoints(e,r);return t===i&&n===a};static getStealthAddress=h.attach((e,t)=>{let{H0:r,H1:i}=this.getRandomizedStealthPairOld(e,t);return n.poseidonHash(2n*o.getCircomSign(r[0])+o.getCircomSign(i[0]),r[1],i[1])});static getH1FromH0=(e,n)=>{let i=r.babyJubInstance(),a=BigInt(n)%t.CIRCOM_P,o=[i.F.e(e[0]),i.F.e(e[1])],s=i.mulPointEscalar(o,a);return[BigInt(i.F.toString(s[0])),BigInt(i.F.toString(s[1]))]};static verifyStealthPair=(e,t,n,r=!0)=>{let i=this.getH1FromH0(e,n);return r?i[1]===t[1]:i===t};static getStealthAddressNewStyle=(e,t,r)=>{if(r?.length!==2)throw Error(`Spending public key must be an array of 2 elements`);let i=this.getH1FromH0(e,t);return n.poseidonHash(2n*o.getCircomSign(e[0])+o.getCircomSign(i[0]),e[1],i[1],r[0],r[1],t)};static findCorrectRandomization(e,n){if(!n)throw Error(`No Private Shielded Key Provided`);let r=BigInt(n)%t.CIRCOM_P,i,a,o=0n;do i=e*10n**o%t.CIRCOM_P,a=i*r%t.CIRCOM_P,o+=1n;while(a>=2n**253n||i>=2n**253n);return i}static getH0FromRandomization=e=>{let t=r.babyJubInstance(),n=t.mulPointEscalar(t.Base8,e);return[BigInt(t.F.toString(n[0])),BigInt(t.F.toString(n[1]))]};static findH0(e,t){if(!t)return;let{H0:n}=this.getRandomizedStealthPair(e,t);return n}static getEncryptionKeyPair=e=>{let t=u.default.crypto_box_seed_keypair(s.ethers.getBytes(e));return{privateKey:s.ethers.hexlify(t.privateKey),publicKey:s.ethers.hexlify(t.publicKey)}};getAccessKey=()=>(this.requireKeyMaterial(),n.poseidonHash(this.getShieldedPrivateKey(),this.getShieldedPublicKey()));getBackendToken=()=>(this.requireKeyMaterial(),n.poseidonHash(this.getAccessKey(),this.getShieldedPublicKey()))};exports.UserKeys=g,exports.stealthAddressCacheDevice=h,exports.stealthPairCacheDevice=p,exports.stealthPairOldCacheDevice=m;
|