@zama-fhe/sdk 3.7.0-beta.2 → 3.7.0-beta.3
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/dist/cjs/base-signer.cjs +1 -1
- package/dist/cjs/base-signer.cjs.map +1 -1
- package/dist/cjs/chains/index.cjs +1 -1
- package/dist/cjs/chains.cjs +1 -1
- package/dist/cjs/chains.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/node/index.cjs +1 -1
- package/dist/esm/{base-signer-DIYZwDnc.d.ts → base-signer-D902THgk.d.ts} +2 -2
- package/dist/esm/base-signer-ws-wq22y.js +2 -0
- package/dist/esm/{base-signer-D5Cwv7yb.js.map → base-signer-ws-wq22y.js.map} +1 -1
- package/dist/esm/chains/index.d.ts +2 -2
- package/dist/esm/chains/index.js +1 -1
- package/dist/esm/{chains-ByyCdrrd.js → chains-iPpnjXql.js} +2 -2
- package/dist/esm/{chains-ByyCdrrd.js.map → chains-iPpnjXql.js.map} +1 -1
- package/dist/esm/cleartext/index.d.ts +2 -2
- package/dist/esm/{cleartext-3HOk1BAg.d.ts → cleartext-B6vrnBzO.d.ts} +2 -2
- package/dist/esm/ethers/index.d.ts +4 -4
- package/dist/esm/ethers/index.js +1 -1
- package/dist/esm/{index-ijgDL4IC.d.ts → index-Cdbp_93f.d.ts} +24 -4
- package/dist/esm/{index-DJYq1rAB.d.ts → index-CnIEp8zv.d.ts} +1521 -1080
- package/dist/esm/{index-BHrjck_q.d.ts → index-CsuDB4UI.d.ts} +4 -4
- package/dist/esm/index.d.ts +99 -8
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/node/index.d.ts +5 -5
- package/dist/esm/node/index.js +1 -1
- package/dist/esm/node/index.js.map +1 -1
- package/dist/esm/query/index.d.ts +4 -495
- package/dist/esm/{types-Bz5-wHPv.d.ts → types-Crf7ymyj.d.ts} +2 -2
- package/dist/esm/{types-v0_sfkli.d.ts → types-CuldbZne.d.ts} +3 -3
- package/dist/esm/{types-CI6BtpB7.d.ts → types-DnJSNoEC.d.ts} +3 -3
- package/dist/esm/vaults/index.d.ts +2 -3
- package/dist/esm/viem/index.d.ts +4 -4
- package/dist/esm/viem/index.js +1 -1
- package/dist/esm/web/index.d.ts +1 -1
- package/package.json +1 -1
- package/dist/esm/base-signer-D5Cwv7yb.js +0 -2
- package/dist/esm/invalidation-CJ-pzOUG.d.ts +0 -46
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../chains.cjs");exports.anvil=e.t,exports.bscTestnet=e.n,exports.chains=e.r,exports.hardhat=e.i,exports.hoodi=e.a,exports.ingenTestnet=e.o,exports.mainnet=e.s,exports.polygon=e.c,exports.polygonAmoy=e.l,exports.sepolia=e.u;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../chains.cjs");exports.anvil=e.t,exports.bscTestnet=e.n,exports.chains=e.r,exports.hardhat=e.i,exports.hoodi=e.a,exports.ingenTestnet=e.o,exports.mainnet=e.s,exports.polygon=e.c,exports.polygonAmoy=e.l,exports.sepolia=e.u,exports.zenithTrexTestnet=e.d;
|
package/dist/cjs/chains.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e={id:1,gatewayChainId:261131,relayerUrl:`https://relayer.mainnet.zama.org`,network:`https://ethereum-rpc.publicnode.com`,aclContractAddress:`0xcA2E8f1F656CD25C01F05d0b243Ab1ecd4a8ffb6`,kmsContractAddress:`0x77627828a55156b04Ac0DC0eb30467f1a552BB03`,inputVerifierContractAddress:`0xCe0FC2e05CFff1B719EFF7169f7D80Af770c8EA2`,verifyingContractAddressDecryption:`0x0f6024a97684f7d90ddb0fAAD79cB15F2C888D24`,verifyingContractAddressInputVerification:`0xcB1bB072f38bdAF0F328CdEf1Fc6eDa1DF029287`,registryAddress:`0xeb5015fF021DB115aCe010f23F55C2591059bBA0`},t={id:137,gatewayChainId:261131,relayerUrl:`https://relayer.mainnet.zama.org`,network:`https://polygon-bor-rpc.publicnode.com`,aclContractAddress:`0x6737F17e31cf26a1b62fb0362acC5a16CB156F49`,kmsContractAddress:`0x14e609595474874Dd6b6128376E336EfADfdBE37`,inputVerifierContractAddress:`0xf40BD204B035522EaAc8E5afAdc55113Acac96ca`,verifyingContractAddressDecryption:`0x0f6024a97684f7d90ddb0fAAD79cB15F2C888D24`,verifyingContractAddressInputVerification:`0xcB1bB072f38bdAF0F328CdEf1Fc6eDa1DF029287`,registryAddress:`0xc8908569868758dAF814B5a8b96bBc44D1653d54`},n={id:11155111,gatewayChainId:10901,relayerUrl:`https://relayer.testnet.zama.org`,network:`https://ethereum-sepolia-rpc.publicnode.com`,aclContractAddress:`0xf0Ffdc93b7E186bC2f8CB3dAA75D86d1930A433D`,kmsContractAddress:`0xbE0E383937d564D7FF0BC3b46c51f0bF8d5C311A`,inputVerifierContractAddress:`0xBBC1fFCdc7C316aAAd72E807D9b0272BE8F84DA0`,verifyingContractAddressDecryption:`0x5D8BD78e2ea6bbE41f26dFe9fdaEAa349e077478`,verifyingContractAddressInputVerification:`0x483b9dE06E4E4C7D35CCf5837A1668487406D955`,registryAddress:`0x2f0750Bbb0A246059d80e94c454586a7F27a128e`},r={id:80002,gatewayChainId:10901,relayerUrl:`https://relayer.testnet.zama.org`,network:`https://polygon-amoy-bor-rpc.publicnode.com`,aclContractAddress:`0xD99Cb9Fc3c42c87f2A4A12e8Fd60318d6bDdf985`,kmsContractAddress:`0xCD1D89E311bce4C8DEa9a0857a0c9A4E153D4041`,inputVerifierContractAddress:`0x6e5A7D8b0c645467Cba7e62D6624917085118631`,verifyingContractAddressDecryption:`0x5D8BD78e2ea6bbE41f26dFe9fdaEAa349e077478`,verifyingContractAddressInputVerification:`0x483b9dE06E4E4C7D35CCf5837A1668487406D955`,registryAddress:`0xF486c3D4F4562760A43883e72E8D6f6Cf2EFdA94`},i={id:560048,gatewayChainId:10901,relayerUrl:``,network:`https://rpc.hoodi.ethpandaops.io`,aclContractAddress:`0x6D3FAf6f86e1fF9F3B0831Dda920AbA1cBd5bd68`,kmsContractAddress:`0x822BE20679CfAfdc352F05dEdfe12a07E912212e`,inputVerifierContractAddress:`0xf3D9A51f32D9bC23E1eECb0fAbF1f1DA4d9Bba26`,verifyingContractAddressDecryption:`0x5ffdaAB0373E62E2ea2944776209aEf29E631A64`,verifyingContractAddressInputVerification:`0x812b06e1CDCE800494b79fFE4f925A504a9A9810`,registryAddress:`0x1807aE2f693F8530DFB126D0eF98F2F2518F292f`,executorAddress:`0xC316692627de536368d82e9121F1D44a550894E6`},a={id:364301,gatewayChainId:10901,relayerUrl:``,network:`https://rpc.ingen.t-rex.network`,aclContractAddress:`0x09a4710BfBe7B557cD5CFE88BB31e9b5b85C419b`,kmsContractAddress:`0xd885DEa6a924785fCcdf9CE993FEe27EA11832e6`,inputVerifierContractAddress:`0x90f05B10db153365D8cB143EA17f5E5714D0bCD5`,verifyingContractAddressDecryption:`0x5ffdaAB0373E62E2ea2944776209aEf29E631A64`,verifyingContractAddressInputVerification:`0x812b06e1CDCE800494b79fFE4f925A504a9A9810`,registryAddress:`0x7FC3D79EF9d01fA318CF2Aa5D91dDC492383Be0F`,executorAddress:`0x1B05DE5b67b8f8363DC04E3a5996a616f11f8C7B`},o={id:97,gatewayChainId:10901,relayerUrl:``,network:`https://bsc-testnet.bnbchain.org`,aclContractAddress:`0x52470e945521E247Cb4754088a836Dc4b838AFBE`,kmsContractAddress:`0x788F5BB2d93aB4Cb67Fe2277757aE95006504F6F`,inputVerifierContractAddress:`0x49e0BAB39904E4192c30CFB58573Cbe27B7E398E`,verifyingContractAddressDecryption:`0x5ffdaAB0373E62E2ea2944776209aEf29E631A64`,verifyingContractAddressInputVerification:`0x812b06e1CDCE800494b79fFE4f925A504a9A9810`,registryAddress:`0xc0E8B73b1C58D846e1d4f8fAE2E1466C85BCeAeC`,executorAddress:`0x5985e48689550c1b2893ABfBbe4cc0eE3A22cc54`},
|
|
1
|
+
const e={id:1,gatewayChainId:261131,relayerUrl:`https://relayer.mainnet.zama.org`,network:`https://ethereum-rpc.publicnode.com`,aclContractAddress:`0xcA2E8f1F656CD25C01F05d0b243Ab1ecd4a8ffb6`,kmsContractAddress:`0x77627828a55156b04Ac0DC0eb30467f1a552BB03`,inputVerifierContractAddress:`0xCe0FC2e05CFff1B719EFF7169f7D80Af770c8EA2`,verifyingContractAddressDecryption:`0x0f6024a97684f7d90ddb0fAAD79cB15F2C888D24`,verifyingContractAddressInputVerification:`0xcB1bB072f38bdAF0F328CdEf1Fc6eDa1DF029287`,registryAddress:`0xeb5015fF021DB115aCe010f23F55C2591059bBA0`},t={id:137,gatewayChainId:261131,relayerUrl:`https://relayer.mainnet.zama.org`,network:`https://polygon-bor-rpc.publicnode.com`,aclContractAddress:`0x6737F17e31cf26a1b62fb0362acC5a16CB156F49`,kmsContractAddress:`0x14e609595474874Dd6b6128376E336EfADfdBE37`,inputVerifierContractAddress:`0xf40BD204B035522EaAc8E5afAdc55113Acac96ca`,verifyingContractAddressDecryption:`0x0f6024a97684f7d90ddb0fAAD79cB15F2C888D24`,verifyingContractAddressInputVerification:`0xcB1bB072f38bdAF0F328CdEf1Fc6eDa1DF029287`,registryAddress:`0xc8908569868758dAF814B5a8b96bBc44D1653d54`},n={id:11155111,gatewayChainId:10901,relayerUrl:`https://relayer.testnet.zama.org`,network:`https://ethereum-sepolia-rpc.publicnode.com`,aclContractAddress:`0xf0Ffdc93b7E186bC2f8CB3dAA75D86d1930A433D`,kmsContractAddress:`0xbE0E383937d564D7FF0BC3b46c51f0bF8d5C311A`,inputVerifierContractAddress:`0xBBC1fFCdc7C316aAAd72E807D9b0272BE8F84DA0`,verifyingContractAddressDecryption:`0x5D8BD78e2ea6bbE41f26dFe9fdaEAa349e077478`,verifyingContractAddressInputVerification:`0x483b9dE06E4E4C7D35CCf5837A1668487406D955`,registryAddress:`0x2f0750Bbb0A246059d80e94c454586a7F27a128e`},r={id:80002,gatewayChainId:10901,relayerUrl:`https://relayer.testnet.zama.org`,network:`https://polygon-amoy-bor-rpc.publicnode.com`,aclContractAddress:`0xD99Cb9Fc3c42c87f2A4A12e8Fd60318d6bDdf985`,kmsContractAddress:`0xCD1D89E311bce4C8DEa9a0857a0c9A4E153D4041`,inputVerifierContractAddress:`0x6e5A7D8b0c645467Cba7e62D6624917085118631`,verifyingContractAddressDecryption:`0x5D8BD78e2ea6bbE41f26dFe9fdaEAa349e077478`,verifyingContractAddressInputVerification:`0x483b9dE06E4E4C7D35CCf5837A1668487406D955`,registryAddress:`0xF486c3D4F4562760A43883e72E8D6f6Cf2EFdA94`},i={id:560048,gatewayChainId:10901,relayerUrl:``,network:`https://rpc.hoodi.ethpandaops.io`,aclContractAddress:`0x6D3FAf6f86e1fF9F3B0831Dda920AbA1cBd5bd68`,kmsContractAddress:`0x822BE20679CfAfdc352F05dEdfe12a07E912212e`,inputVerifierContractAddress:`0xf3D9A51f32D9bC23E1eECb0fAbF1f1DA4d9Bba26`,verifyingContractAddressDecryption:`0x5ffdaAB0373E62E2ea2944776209aEf29E631A64`,verifyingContractAddressInputVerification:`0x812b06e1CDCE800494b79fFE4f925A504a9A9810`,registryAddress:`0x1807aE2f693F8530DFB126D0eF98F2F2518F292f`,executorAddress:`0xC316692627de536368d82e9121F1D44a550894E6`},a={id:364301,gatewayChainId:10901,relayerUrl:``,network:`https://rpc.ingen.t-rex.network`,aclContractAddress:`0x09a4710BfBe7B557cD5CFE88BB31e9b5b85C419b`,kmsContractAddress:`0xd885DEa6a924785fCcdf9CE993FEe27EA11832e6`,inputVerifierContractAddress:`0x90f05B10db153365D8cB143EA17f5E5714D0bCD5`,verifyingContractAddressDecryption:`0x5ffdaAB0373E62E2ea2944776209aEf29E631A64`,verifyingContractAddressInputVerification:`0x812b06e1CDCE800494b79fFE4f925A504a9A9810`,registryAddress:`0x7FC3D79EF9d01fA318CF2Aa5D91dDC492383Be0F`,executorAddress:`0x1B05DE5b67b8f8363DC04E3a5996a616f11f8C7B`},o={id:936486,gatewayChainId:10901,relayerUrl:``,network:`https://rpc.testnet.t-rex.zenith.network`,aclContractAddress:`0x061AAc7aAACc98d8e30459d4D858DaB9b6F3bd23`,kmsContractAddress:`0x85fBA21840059cB7E2E5BB7Fa2c5b2A324Ea7a7D`,inputVerifierContractAddress:`0xE90965601D10D42D3d88486b47b0Caf12C5C9fDe`,verifyingContractAddressDecryption:`0x5ffdaAB0373E62E2ea2944776209aEf29E631A64`,verifyingContractAddressInputVerification:`0x812b06e1CDCE800494b79fFE4f925A504a9A9810`,registryAddress:`0xde2e3948d35ef9C406A7317eAF332F3c2786a566`,executorAddress:`0x6C5036A4ad55DBA8007ae82c4e9C123F143e53ab`},s={id:97,gatewayChainId:10901,relayerUrl:``,network:`https://bsc-testnet.bnbchain.org`,aclContractAddress:`0x52470e945521E247Cb4754088a836Dc4b838AFBE`,kmsContractAddress:`0x788F5BB2d93aB4Cb67Fe2277757aE95006504F6F`,inputVerifierContractAddress:`0x49e0BAB39904E4192c30CFB58573Cbe27B7E398E`,verifyingContractAddressDecryption:`0x5ffdaAB0373E62E2ea2944776209aEf29E631A64`,verifyingContractAddressInputVerification:`0x812b06e1CDCE800494b79fFE4f925A504a9A9810`,registryAddress:`0xc0E8B73b1C58D846e1d4f8fAE2E1466C85BCeAeC`,executorAddress:`0x5985e48689550c1b2893ABfBbe4cc0eE3A22cc54`},c={id:31337,gatewayChainId:10901,relayerUrl:``,network:`http://127.0.0.1:8545`,aclContractAddress:`0x50157CFfD6bBFA2DECe204a89ec419c23ef5755D`,inputVerifierContractAddress:`0x36772142b74871f255CbD7A3e89B401d3e45825f`,kmsContractAddress:`0x901F8942346f7AB3a01F6D7613119Bca447Bb030`,verifyingContractAddressDecryption:`0x5ffdaAB0373E62E2ea2944776209aEf29E631A64`,verifyingContractAddressInputVerification:`0x812b06e1CDCE800494b79fFE4f925A504a9A9810`,registryAddress:void 0,executorAddress:`0xe3a9105a3a932253A70F126eb1E3b589C643dD24`},l=c,u={[e.id]:e,[t.id]:t,[n.id]:n,[r.id]:r,[i.id]:i,[a.id]:a,[o.id]:o,[s.id]:s,[c.id]:c};Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return i}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return s}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return n}});
|
|
2
2
|
//# sourceMappingURL=chains.cjs.map
|
package/dist/cjs/chains.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chains.cjs","names":[],"sources":["../../src/chains/configs.ts"],"sourcesContent":["import type { FheChain } from \"./types\";\n\n/**\n * Mainnet network configuration (chainId 1).\n */\nexport const mainnet = {\n id: 1,\n gatewayChainId: 261131,\n relayerUrl: \"https://relayer.mainnet.zama.org\",\n network: \"https://ethereum-rpc.publicnode.com\",\n aclContractAddress: \"0xcA2E8f1F656CD25C01F05d0b243Ab1ecd4a8ffb6\",\n kmsContractAddress: \"0x77627828a55156b04Ac0DC0eb30467f1a552BB03\",\n inputVerifierContractAddress: \"0xCe0FC2e05CFff1B719EFF7169f7D80Af770c8EA2\",\n verifyingContractAddressDecryption: \"0x0f6024a97684f7d90ddb0fAAD79cB15F2C888D24\",\n verifyingContractAddressInputVerification: \"0xcB1bB072f38bdAF0F328CdEf1Fc6eDa1DF029287\",\n registryAddress: \"0xeb5015fF021DB115aCe010f23F55C2591059bBA0\",\n} as const satisfies FheChain;\n\n/**\n * Polygon mainnet network configuration (chainId 137).\n */\nexport const polygon = {\n id: 137,\n gatewayChainId: 261131,\n relayerUrl: \"https://relayer.mainnet.zama.org\",\n network: \"https://polygon-bor-rpc.publicnode.com\",\n aclContractAddress: \"0x6737F17e31cf26a1b62fb0362acC5a16CB156F49\",\n kmsContractAddress: \"0x14e609595474874Dd6b6128376E336EfADfdBE37\",\n inputVerifierContractAddress: \"0xf40BD204B035522EaAc8E5afAdc55113Acac96ca\",\n verifyingContractAddressDecryption: \"0x0f6024a97684f7d90ddb0fAAD79cB15F2C888D24\",\n verifyingContractAddressInputVerification: \"0xcB1bB072f38bdAF0F328CdEf1Fc6eDa1DF029287\",\n registryAddress: \"0xc8908569868758dAF814B5a8b96bBc44D1653d54\",\n} as const satisfies FheChain;\n\n/**\n * Sepolia testnet network configuration (chainId 11155111).\n */\nexport const sepolia = {\n id: 11155111,\n gatewayChainId: 10901,\n relayerUrl: \"https://relayer.testnet.zama.org\",\n network: \"https://ethereum-sepolia-rpc.publicnode.com\",\n aclContractAddress: \"0xf0Ffdc93b7E186bC2f8CB3dAA75D86d1930A433D\",\n kmsContractAddress: \"0xbE0E383937d564D7FF0BC3b46c51f0bF8d5C311A\",\n inputVerifierContractAddress: \"0xBBC1fFCdc7C316aAAd72E807D9b0272BE8F84DA0\",\n verifyingContractAddressDecryption: \"0x5D8BD78e2ea6bbE41f26dFe9fdaEAa349e077478\",\n verifyingContractAddressInputVerification: \"0x483b9dE06E4E4C7D35CCf5837A1668487406D955\",\n registryAddress: \"0x2f0750Bbb0A246059d80e94c454586a7F27a128e\",\n} as const satisfies FheChain;\n\n/**\n * Polygon Amoy testnet network configuration (chainId 80002).\n */\nexport const polygonAmoy = {\n id: 80002,\n gatewayChainId: 10901,\n relayerUrl: \"https://relayer.testnet.zama.org\",\n network: \"https://polygon-amoy-bor-rpc.publicnode.com\",\n aclContractAddress: \"0xD99Cb9Fc3c42c87f2A4A12e8Fd60318d6bDdf985\",\n kmsContractAddress: \"0xCD1D89E311bce4C8DEa9a0857a0c9A4E153D4041\",\n inputVerifierContractAddress: \"0x6e5A7D8b0c645467Cba7e62D6624917085118631\",\n verifyingContractAddressDecryption: \"0x5D8BD78e2ea6bbE41f26dFe9fdaEAa349e077478\",\n verifyingContractAddressInputVerification: \"0x483b9dE06E4E4C7D35CCf5837A1668487406D955\",\n registryAddress: \"0xF486c3D4F4562760A43883e72E8D6f6Cf2EFdA94\",\n} as const satisfies FheChain;\n\n/**\n * Hoodi testnet configuration (chainId 560048).\n *\n * Hoodi does not have full FHE infrastructure — use with `cleartext()` transport.\n * Contract addresses match the cleartext deployment.\n */\nexport const hoodi = {\n id: 560048,\n gatewayChainId: 10901,\n relayerUrl: \"\",\n network: \"https://rpc.hoodi.ethpandaops.io\",\n aclContractAddress: \"0x6D3FAf6f86e1fF9F3B0831Dda920AbA1cBd5bd68\",\n kmsContractAddress: \"0x822BE20679CfAfdc352F05dEdfe12a07E912212e\",\n inputVerifierContractAddress: \"0xf3D9A51f32D9bC23E1eECb0fAbF1f1DA4d9Bba26\",\n verifyingContractAddressDecryption: \"0x5ffdaAB0373E62E2ea2944776209aEf29E631A64\",\n verifyingContractAddressInputVerification: \"0x812b06e1CDCE800494b79fFE4f925A504a9A9810\",\n registryAddress: \"0x1807aE2f693F8530DFB126D0eF98F2F2518F292f\",\n executorAddress: \"0xC316692627de536368d82e9121F1D44a550894E6\",\n} as const satisfies FheChain;\n\n/**\n * T-Rex InGen testnet configuration (chainId 364301).\n *\n * InGen does not have full FHE infrastructure — use with `cleartext()` transport.\n * Contract addresses match the cleartext deployment.\n */\nexport const ingenTestnet = {\n id: 364301,\n gatewayChainId: 10901,\n relayerUrl: \"\",\n network: \"https://rpc.ingen.t-rex.network\",\n aclContractAddress: \"0x09a4710BfBe7B557cD5CFE88BB31e9b5b85C419b\",\n kmsContractAddress: \"0xd885DEa6a924785fCcdf9CE993FEe27EA11832e6\",\n inputVerifierContractAddress: \"0x90f05B10db153365D8cB143EA17f5E5714D0bCD5\",\n verifyingContractAddressDecryption: \"0x5ffdaAB0373E62E2ea2944776209aEf29E631A64\",\n verifyingContractAddressInputVerification: \"0x812b06e1CDCE800494b79fFE4f925A504a9A9810\",\n registryAddress: \"0x7FC3D79EF9d01fA318CF2Aa5D91dDC492383Be0F\",\n executorAddress: \"0x1B05DE5b67b8f8363DC04E3a5996a616f11f8C7B\",\n} as const satisfies FheChain;\n\n/**\n * BNB Smart Chain testnet configuration (chainId 97, Chapel).\n *\n * BSC testnet does not have full FHE infrastructure — use with `cleartext()` transport.\n * Contract addresses match the cleartext deployment.\n */\nexport const bscTestnet = {\n id: 97,\n gatewayChainId: 10901,\n relayerUrl: \"\",\n network: \"https://bsc-testnet.bnbchain.org\",\n aclContractAddress: \"0x52470e945521E247Cb4754088a836Dc4b838AFBE\",\n kmsContractAddress: \"0x788F5BB2d93aB4Cb67Fe2277757aE95006504F6F\",\n inputVerifierContractAddress: \"0x49e0BAB39904E4192c30CFB58573Cbe27B7E398E\",\n verifyingContractAddressDecryption: \"0x5ffdaAB0373E62E2ea2944776209aEf29E631A64\",\n verifyingContractAddressInputVerification: \"0x812b06e1CDCE800494b79fFE4f925A504a9A9810\",\n registryAddress: \"0xc0E8B73b1C58D846e1d4f8fAE2E1466C85BCeAeC\",\n executorAddress: \"0x5985e48689550c1b2893ABfBbe4cc0eE3A22cc54\",\n} as const satisfies FheChain;\n\n/**\n * Hardhat local network configuration (chainId 31337).\n *\n * The addresses in this configuration must match those of your deployment.\n */\nexport const hardhat = {\n id: 31337,\n gatewayChainId: 10901,\n relayerUrl: \"\",\n network: \"http://127.0.0.1:8545\",\n aclContractAddress: \"0x50157CFfD6bBFA2DECe204a89ec419c23ef5755D\",\n inputVerifierContractAddress: \"0x36772142b74871f255CbD7A3e89B401d3e45825f\",\n kmsContractAddress: \"0x901F8942346f7AB3a01F6D7613119Bca447Bb030\",\n verifyingContractAddressDecryption: \"0x5ffdaAB0373E62E2ea2944776209aEf29E631A64\",\n verifyingContractAddressInputVerification: \"0x812b06e1CDCE800494b79fFE4f925A504a9A9810\",\n registryAddress: undefined,\n executorAddress: \"0xe3a9105a3a932253A70F126eb1E3b589C643dD24\",\n} as const satisfies FheChain;\n\n/** Alias for {@link hardhat}. */\nexport const anvil = hardhat;\n\n/**\n * Built-in chain configurations keyed by chain ID.\n */\nexport const chains: Record<number, FheChain> = {\n [mainnet.id]: mainnet,\n [polygon.id]: polygon,\n [sepolia.id]: sepolia,\n [polygonAmoy.id]: polygonAmoy,\n [hoodi.id]: hoodi,\n [ingenTestnet.id]: ingenTestnet,\n [bscTestnet.id]: bscTestnet,\n [hardhat.id]: hardhat,\n} as const;\n"],"mappings":"AAKA,MAAa,EAAU,CACrB,GAAI,EACJ,eAAgB,OAChB,WAAY,mCACZ,QAAS,sCACT,mBAAoB,6CACpB,mBAAoB,6CACpB,6BAA8B,6CAC9B,mCAAoC,6CACpC,0CAA2C,6CAC3C,gBAAiB,4CACnB,EAKa,EAAU,CACrB,GAAI,IACJ,eAAgB,OAChB,WAAY,mCACZ,QAAS,yCACT,mBAAoB,6CACpB,mBAAoB,6CACpB,6BAA8B,6CAC9B,mCAAoC,6CACpC,0CAA2C,6CAC3C,gBAAiB,4CACnB,EAKa,EAAU,CACrB,GAAI,SACJ,eAAgB,MAChB,WAAY,mCACZ,QAAS,8CACT,mBAAoB,6CACpB,mBAAoB,6CACpB,6BAA8B,6CAC9B,mCAAoC,6CACpC,0CAA2C,6CAC3C,gBAAiB,4CACnB,EAKa,EAAc,CACzB,GAAI,MACJ,eAAgB,MAChB,WAAY,mCACZ,QAAS,8CACT,mBAAoB,6CACpB,mBAAoB,6CACpB,6BAA8B,6CAC9B,mCAAoC,6CACpC,0CAA2C,6CAC3C,gBAAiB,4CACnB,EAQa,EAAQ,CACnB,GAAI,OACJ,eAAgB,MAChB,WAAY,GACZ,QAAS,mCACT,mBAAoB,6CACpB,mBAAoB,6CACpB,6BAA8B,6CAC9B,mCAAoC,6CACpC,0CAA2C,6CAC3C,gBAAiB,6CACjB,gBAAiB,4CACnB,EAQa,EAAe,CAC1B,GAAI,OACJ,eAAgB,MAChB,WAAY,GACZ,QAAS,kCACT,mBAAoB,6CACpB,mBAAoB,6CACpB,6BAA8B,6CAC9B,mCAAoC,6CACpC,0CAA2C,6CAC3C,gBAAiB,6CACjB,gBAAiB,4CACnB,EAQa,EAAa,CACxB,GAAI,GACJ,eAAgB,MAChB,WAAY,GACZ,QAAS,mCACT,mBAAoB,6CACpB,mBAAoB,6CACpB,6BAA8B,6CAC9B,mCAAoC,6CACpC,0CAA2C,6CAC3C,gBAAiB,6CACjB,gBAAiB,4CACnB,EAOa,EAAU,CACrB,GAAI,MACJ,eAAgB,MAChB,WAAY,GACZ,QAAS,wBACT,mBAAoB,6CACpB,6BAA8B,6CAC9B,mBAAoB,6CACpB,mCAAoC,6CACpC,0CAA2C,6CAC3C,gBAAiB,IAAA,GACjB,gBAAiB,4CACnB,EAGa,EAAQ,EAKR,EAAmC,EAC7C,EAAQ,IAAK,GACb,EAAQ,IAAK,GACb,EAAQ,IAAK,GACb,EAAY,IAAK,GACjB,EAAM,IAAK,GACX,EAAa,IAAK,GAClB,EAAW,IAAK,GAChB,EAAQ,IAAK,CAChB"}
|
|
1
|
+
{"version":3,"file":"chains.cjs","names":[],"sources":["../../src/chains/configs.ts"],"sourcesContent":["import type { FheChain } from \"./types\";\n\n/**\n * Mainnet network configuration (chainId 1).\n */\nexport const mainnet = {\n id: 1,\n gatewayChainId: 261131,\n relayerUrl: \"https://relayer.mainnet.zama.org\",\n network: \"https://ethereum-rpc.publicnode.com\",\n aclContractAddress: \"0xcA2E8f1F656CD25C01F05d0b243Ab1ecd4a8ffb6\",\n kmsContractAddress: \"0x77627828a55156b04Ac0DC0eb30467f1a552BB03\",\n inputVerifierContractAddress: \"0xCe0FC2e05CFff1B719EFF7169f7D80Af770c8EA2\",\n verifyingContractAddressDecryption: \"0x0f6024a97684f7d90ddb0fAAD79cB15F2C888D24\",\n verifyingContractAddressInputVerification: \"0xcB1bB072f38bdAF0F328CdEf1Fc6eDa1DF029287\",\n registryAddress: \"0xeb5015fF021DB115aCe010f23F55C2591059bBA0\",\n} as const satisfies FheChain;\n\n/**\n * Polygon mainnet network configuration (chainId 137).\n */\nexport const polygon = {\n id: 137,\n gatewayChainId: 261131,\n relayerUrl: \"https://relayer.mainnet.zama.org\",\n network: \"https://polygon-bor-rpc.publicnode.com\",\n aclContractAddress: \"0x6737F17e31cf26a1b62fb0362acC5a16CB156F49\",\n kmsContractAddress: \"0x14e609595474874Dd6b6128376E336EfADfdBE37\",\n inputVerifierContractAddress: \"0xf40BD204B035522EaAc8E5afAdc55113Acac96ca\",\n verifyingContractAddressDecryption: \"0x0f6024a97684f7d90ddb0fAAD79cB15F2C888D24\",\n verifyingContractAddressInputVerification: \"0xcB1bB072f38bdAF0F328CdEf1Fc6eDa1DF029287\",\n registryAddress: \"0xc8908569868758dAF814B5a8b96bBc44D1653d54\",\n} as const satisfies FheChain;\n\n/**\n * Sepolia testnet network configuration (chainId 11155111).\n */\nexport const sepolia = {\n id: 11155111,\n gatewayChainId: 10901,\n relayerUrl: \"https://relayer.testnet.zama.org\",\n network: \"https://ethereum-sepolia-rpc.publicnode.com\",\n aclContractAddress: \"0xf0Ffdc93b7E186bC2f8CB3dAA75D86d1930A433D\",\n kmsContractAddress: \"0xbE0E383937d564D7FF0BC3b46c51f0bF8d5C311A\",\n inputVerifierContractAddress: \"0xBBC1fFCdc7C316aAAd72E807D9b0272BE8F84DA0\",\n verifyingContractAddressDecryption: \"0x5D8BD78e2ea6bbE41f26dFe9fdaEAa349e077478\",\n verifyingContractAddressInputVerification: \"0x483b9dE06E4E4C7D35CCf5837A1668487406D955\",\n registryAddress: \"0x2f0750Bbb0A246059d80e94c454586a7F27a128e\",\n} as const satisfies FheChain;\n\n/**\n * Polygon Amoy testnet network configuration (chainId 80002).\n */\nexport const polygonAmoy = {\n id: 80002,\n gatewayChainId: 10901,\n relayerUrl: \"https://relayer.testnet.zama.org\",\n network: \"https://polygon-amoy-bor-rpc.publicnode.com\",\n aclContractAddress: \"0xD99Cb9Fc3c42c87f2A4A12e8Fd60318d6bDdf985\",\n kmsContractAddress: \"0xCD1D89E311bce4C8DEa9a0857a0c9A4E153D4041\",\n inputVerifierContractAddress: \"0x6e5A7D8b0c645467Cba7e62D6624917085118631\",\n verifyingContractAddressDecryption: \"0x5D8BD78e2ea6bbE41f26dFe9fdaEAa349e077478\",\n verifyingContractAddressInputVerification: \"0x483b9dE06E4E4C7D35CCf5837A1668487406D955\",\n registryAddress: \"0xF486c3D4F4562760A43883e72E8D6f6Cf2EFdA94\",\n} as const satisfies FheChain;\n\n/**\n * Hoodi testnet configuration (chainId 560048).\n *\n * Hoodi does not have full FHE infrastructure — use with `cleartext()` transport.\n * Contract addresses match the cleartext deployment.\n */\nexport const hoodi = {\n id: 560048,\n gatewayChainId: 10901,\n relayerUrl: \"\",\n network: \"https://rpc.hoodi.ethpandaops.io\",\n aclContractAddress: \"0x6D3FAf6f86e1fF9F3B0831Dda920AbA1cBd5bd68\",\n kmsContractAddress: \"0x822BE20679CfAfdc352F05dEdfe12a07E912212e\",\n inputVerifierContractAddress: \"0xf3D9A51f32D9bC23E1eECb0fAbF1f1DA4d9Bba26\",\n verifyingContractAddressDecryption: \"0x5ffdaAB0373E62E2ea2944776209aEf29E631A64\",\n verifyingContractAddressInputVerification: \"0x812b06e1CDCE800494b79fFE4f925A504a9A9810\",\n registryAddress: \"0x1807aE2f693F8530DFB126D0eF98F2F2518F292f\",\n executorAddress: \"0xC316692627de536368d82e9121F1D44a550894E6\",\n} as const satisfies FheChain;\n\n/**\n * T-Rex InGen testnet configuration (chainId 364301).\n *\n * InGen does not have full FHE infrastructure — use with `cleartext()` transport.\n * Contract addresses match the cleartext deployment.\n */\nexport const ingenTestnet = {\n id: 364301,\n gatewayChainId: 10901,\n relayerUrl: \"\",\n network: \"https://rpc.ingen.t-rex.network\",\n aclContractAddress: \"0x09a4710BfBe7B557cD5CFE88BB31e9b5b85C419b\",\n kmsContractAddress: \"0xd885DEa6a924785fCcdf9CE993FEe27EA11832e6\",\n inputVerifierContractAddress: \"0x90f05B10db153365D8cB143EA17f5E5714D0bCD5\",\n verifyingContractAddressDecryption: \"0x5ffdaAB0373E62E2ea2944776209aEf29E631A64\",\n verifyingContractAddressInputVerification: \"0x812b06e1CDCE800494b79fFE4f925A504a9A9810\",\n registryAddress: \"0x7FC3D79EF9d01fA318CF2Aa5D91dDC492383Be0F\",\n executorAddress: \"0x1B05DE5b67b8f8363DC04E3a5996a616f11f8C7B\",\n} as const satisfies FheChain;\n\n/**\n * T-Rex Zenith testnet configuration (chainId 936486).\n *\n * T-Rex's testnet instance on Zenith EVM (Reth execution, Canton-mediated\n * finality) — a separate chain from Zenith's shared testnet (chainId 936485).\n * It does not have full FHE infrastructure — use with `cleartext()` transport.\n */\nexport const zenithTrexTestnet = {\n id: 936486,\n gatewayChainId: 10901,\n relayerUrl: \"\",\n network: \"https://rpc.testnet.t-rex.zenith.network\",\n aclContractAddress: \"0x061AAc7aAACc98d8e30459d4D858DaB9b6F3bd23\",\n kmsContractAddress: \"0x85fBA21840059cB7E2E5BB7Fa2c5b2A324Ea7a7D\",\n inputVerifierContractAddress: \"0xE90965601D10D42D3d88486b47b0Caf12C5C9fDe\",\n verifyingContractAddressDecryption: \"0x5ffdaAB0373E62E2ea2944776209aEf29E631A64\",\n verifyingContractAddressInputVerification: \"0x812b06e1CDCE800494b79fFE4f925A504a9A9810\",\n registryAddress: \"0xde2e3948d35ef9C406A7317eAF332F3c2786a566\",\n executorAddress: \"0x6C5036A4ad55DBA8007ae82c4e9C123F143e53ab\",\n} as const satisfies FheChain;\n\n/**\n * BNB Smart Chain testnet configuration (chainId 97, Chapel).\n *\n * BSC testnet does not have full FHE infrastructure — use with `cleartext()` transport.\n * Contract addresses match the cleartext deployment.\n */\nexport const bscTestnet = {\n id: 97,\n gatewayChainId: 10901,\n relayerUrl: \"\",\n network: \"https://bsc-testnet.bnbchain.org\",\n aclContractAddress: \"0x52470e945521E247Cb4754088a836Dc4b838AFBE\",\n kmsContractAddress: \"0x788F5BB2d93aB4Cb67Fe2277757aE95006504F6F\",\n inputVerifierContractAddress: \"0x49e0BAB39904E4192c30CFB58573Cbe27B7E398E\",\n verifyingContractAddressDecryption: \"0x5ffdaAB0373E62E2ea2944776209aEf29E631A64\",\n verifyingContractAddressInputVerification: \"0x812b06e1CDCE800494b79fFE4f925A504a9A9810\",\n registryAddress: \"0xc0E8B73b1C58D846e1d4f8fAE2E1466C85BCeAeC\",\n executorAddress: \"0x5985e48689550c1b2893ABfBbe4cc0eE3A22cc54\",\n} as const satisfies FheChain;\n\n/**\n * Hardhat local network configuration (chainId 31337).\n *\n * The addresses in this configuration must match those of your deployment.\n */\nexport const hardhat = {\n id: 31337,\n gatewayChainId: 10901,\n relayerUrl: \"\",\n network: \"http://127.0.0.1:8545\",\n aclContractAddress: \"0x50157CFfD6bBFA2DECe204a89ec419c23ef5755D\",\n inputVerifierContractAddress: \"0x36772142b74871f255CbD7A3e89B401d3e45825f\",\n kmsContractAddress: \"0x901F8942346f7AB3a01F6D7613119Bca447Bb030\",\n verifyingContractAddressDecryption: \"0x5ffdaAB0373E62E2ea2944776209aEf29E631A64\",\n verifyingContractAddressInputVerification: \"0x812b06e1CDCE800494b79fFE4f925A504a9A9810\",\n registryAddress: undefined,\n executorAddress: \"0xe3a9105a3a932253A70F126eb1E3b589C643dD24\",\n} as const satisfies FheChain;\n\n/** Alias for {@link hardhat}. */\nexport const anvil = hardhat;\n\n/**\n * Built-in chain configurations keyed by chain ID.\n */\nexport const chains: Record<number, FheChain> = {\n [mainnet.id]: mainnet,\n [polygon.id]: polygon,\n [sepolia.id]: sepolia,\n [polygonAmoy.id]: polygonAmoy,\n [hoodi.id]: hoodi,\n [ingenTestnet.id]: ingenTestnet,\n [zenithTrexTestnet.id]: zenithTrexTestnet,\n [bscTestnet.id]: bscTestnet,\n [hardhat.id]: hardhat,\n} as const;\n"],"mappings":"AAKA,MAAa,EAAU,CACrB,GAAI,EACJ,eAAgB,OAChB,WAAY,mCACZ,QAAS,sCACT,mBAAoB,6CACpB,mBAAoB,6CACpB,6BAA8B,6CAC9B,mCAAoC,6CACpC,0CAA2C,6CAC3C,gBAAiB,4CACnB,EAKa,EAAU,CACrB,GAAI,IACJ,eAAgB,OAChB,WAAY,mCACZ,QAAS,yCACT,mBAAoB,6CACpB,mBAAoB,6CACpB,6BAA8B,6CAC9B,mCAAoC,6CACpC,0CAA2C,6CAC3C,gBAAiB,4CACnB,EAKa,EAAU,CACrB,GAAI,SACJ,eAAgB,MAChB,WAAY,mCACZ,QAAS,8CACT,mBAAoB,6CACpB,mBAAoB,6CACpB,6BAA8B,6CAC9B,mCAAoC,6CACpC,0CAA2C,6CAC3C,gBAAiB,4CACnB,EAKa,EAAc,CACzB,GAAI,MACJ,eAAgB,MAChB,WAAY,mCACZ,QAAS,8CACT,mBAAoB,6CACpB,mBAAoB,6CACpB,6BAA8B,6CAC9B,mCAAoC,6CACpC,0CAA2C,6CAC3C,gBAAiB,4CACnB,EAQa,EAAQ,CACnB,GAAI,OACJ,eAAgB,MAChB,WAAY,GACZ,QAAS,mCACT,mBAAoB,6CACpB,mBAAoB,6CACpB,6BAA8B,6CAC9B,mCAAoC,6CACpC,0CAA2C,6CAC3C,gBAAiB,6CACjB,gBAAiB,4CACnB,EAQa,EAAe,CAC1B,GAAI,OACJ,eAAgB,MAChB,WAAY,GACZ,QAAS,kCACT,mBAAoB,6CACpB,mBAAoB,6CACpB,6BAA8B,6CAC9B,mCAAoC,6CACpC,0CAA2C,6CAC3C,gBAAiB,6CACjB,gBAAiB,4CACnB,EASa,EAAoB,CAC/B,GAAI,OACJ,eAAgB,MAChB,WAAY,GACZ,QAAS,2CACT,mBAAoB,6CACpB,mBAAoB,6CACpB,6BAA8B,6CAC9B,mCAAoC,6CACpC,0CAA2C,6CAC3C,gBAAiB,6CACjB,gBAAiB,4CACnB,EAQa,EAAa,CACxB,GAAI,GACJ,eAAgB,MAChB,WAAY,GACZ,QAAS,mCACT,mBAAoB,6CACpB,mBAAoB,6CACpB,6BAA8B,6CAC9B,mCAAoC,6CACpC,0CAA2C,6CAC3C,gBAAiB,6CACjB,gBAAiB,4CACnB,EAOa,EAAU,CACrB,GAAI,MACJ,eAAgB,MAChB,WAAY,GACZ,QAAS,wBACT,mBAAoB,6CACpB,6BAA8B,6CAC9B,mBAAoB,6CACpB,mCAAoC,6CACpC,0CAA2C,6CAC3C,gBAAiB,IAAA,GACjB,gBAAiB,4CACnB,EAGa,EAAQ,EAKR,EAAmC,EAC7C,EAAQ,IAAK,GACb,EAAQ,IAAK,GACb,EAAQ,IAAK,GACb,EAAY,IAAK,GACjB,EAAM,IAAK,GACX,EAAa,IAAK,GAClB,EAAkB,IAAK,GACvB,EAAW,IAAK,GAChB,EAAQ,IAAK,CAChB"}
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./relayer.cjs"),t=require("./erc165.cjs"),n=require("./encryption.cjs"),r=require("./token.cjs"),i=require("./wrapped-token.cjs"),a=require("./cleartext.cjs"),o=require("./base-signer.cjs"),s=require("./primitives.cjs"),c=require("./validation.cjs"),l=require("./wrappers-registry.cjs"),u=require("./chains.cjs"),d=require("./assertions.cjs");let f=require("viem"),p=require("zod/mini");function m(t,n){if(t instanceof e.r){let e=n[t.code];if(e)return e(t)}return n._?.(t)}var h=class extends e.r{encryptedValue;contractAddress;account;constructor(t,n){super(e.i.NotEntitled,`Account ${t.account} is not entitled to decrypt encrypted value ${t.encryptedValue} on contract ${t.contractAddress}. This is not a transient failure — the account needs an on-chain ACL grant before it can decrypt this encrypted value.`,n),this.name=`NotEntitledError`,this.encryptedValue=t.encryptedValue,this.contractAddress=t.contractAddress,this.account=t.account}},g=class extends e.r{constructor(t,n){super(e.i.DelegationSelfNotAllowed,t,n),this.name=`DelegationSelfNotAllowedError`}},_=class extends e.r{constructor(t,n){super(e.i.DelegationCooldown,t,n),this.name=`DelegationCooldownError`}},v=class extends e.r{constructor(t,n){super(e.i.DelegationNotFound,t,n),this.name=`DelegationNotFoundError`}},y=class extends e.r{constructor(t,n){super(e.i.DelegationExpired,t,n),this.name=`DelegationExpiredError`}},b=class extends e.r{constructor(t,n){super(e.i.DelegationExpiryUnchanged,t,n),this.name=`DelegationExpiryUnchangedError`}},x=class extends e.r{constructor(t,n){super(e.i.DelegationDelegateEqualsContract,t,n),this.name=`DelegationDelegateEqualsContractError`}},S=class extends e.r{constructor(t,n){super(e.i.DelegationContractIsSelf,t,n),this.name=`DelegationContractIsSelfError`}},C=class extends e.r{constructor(t,n){super(e.i.AclPaused,t,n),this.name=`AclPausedError`}},w=class extends e.r{constructor(t,n){super(e.i.DelegationExpirationTooSoon,t,n),this.name=`DelegationExpirationTooSoonError`}},T=class extends e.r{constructor(t,n){super(e.i.DelegationNotPropagated,t,n),this.name=`DelegationNotPropagatedError`}};const ee=[n.t,t.G,e.n,T,t.V,t.B,h,r._,t.U,t.J];function E(i,a,o={}){if(ee.some(e=>i instanceof e))return i;let s=i instanceof Error?i.message:a;if(i instanceof Error&&e.p(i.message))return new t.U(i.message,{cause:i});if(e._(i))return new t.J(`The permit's KMS context has been revoked on-chain, so the permit is no longer usable. The SDK evicts the permit and re-grants automatically; if this error surfaced, the retry failed the same way. The on-chain validity check is cached for up to 15 minutes, so a just-revoked context can keep failing across that window. Retry after the window; the SDK re-runs the recovery on the next decrypt, no manual cleanup is needed.`,{cause:i});if(i instanceof Error&&e.m(i.message))return o.isDelegated?new T(`Delegated decryption was denied by the on-chain ACL check. This is most commonly caused by the delegation not having propagated yet, or by the RPC node serving a stale block. Propagation usually completes within ~10 blocks (a few seconds) and the SDK retries across that window; seeing this means it did not sync in time. Retry shortly (and prefer a fresh, low-lag RPC endpoint). If it persists, the delegator may genuinely lack the on-chain ACL grant.`,{cause:i}):new h({encryptedValue:e.b(i.message)??``,contractAddress:o.contractAddress??``,account:o.account??``},{cause:i});if(e.d(i))return new r._(s,{cause:i,retryAfter:e.c(i)});let c=e.s(i);return c===void 0&&e.v(i)?new r._(s,{cause:i,retryAfter:e.c(i)}):c===400?new t.G(i instanceof Error?i.message:`No ciphertext for this account`,{cause:i}):o.isDelegated&&c===500?new T(`Delegated decryption failed with a server error. This is most commonly caused by the delegation not having propagated to the gateway yet. Cross-chain sync usually completes within ~10 blocks (a few seconds) and the SDK retries across that window; seeing this means it did not sync in time — retry shortly. If the error persists, the gateway or relayer may be experiencing an unrelated issue.`,{cause:i}):e.h(i)||c!==void 0?new e.n(s,c,{cause:i,retryAfter:e.c(i),retryable:e.g(i)||void 0}):new n.t(a,{cause:i})}function te(t,r){if(t instanceof e.r)return t;let i=e.s(t),a=e.g(t);return i!==void 0||e.h(t)?new e.n(t instanceof Error?t.message:r,i,{cause:t,retryAfter:e.c(t),retryable:a||void 0}):new n.r(r,{cause:t})}const D=[{type:`function`,name:`allow`,inputs:[{name:`handle`,type:`bytes32`,internalType:`bytes32`},{name:`account`,type:`address`,internalType:`address`}],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`allowForDecryption`,inputs:[{name:`handlesList`,type:`bytes32[]`,internalType:`bytes32[]`}],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`allowTransient`,inputs:[{name:`ciphertext`,type:`bytes32`,internalType:`bytes32`},{name:`account`,type:`address`,internalType:`address`}],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`cleanTransientStorage`,inputs:[],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`delegateForUserDecryption`,inputs:[{name:`delegate`,type:`address`,internalType:`address`},{name:`contractAddress`,type:`address`,internalType:`address`},{name:`expirationDate`,type:`uint64`,internalType:`uint64`}],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`getUserDecryptionDelegationExpirationDate`,inputs:[{name:`delegator`,type:`address`,internalType:`address`},{name:`delegate`,type:`address`,internalType:`address`},{name:`contractAddress`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`uint64`,internalType:`uint64`}],stateMutability:`view`},{type:`function`,name:`isAccountDenied`,inputs:[{name:`account`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`isAllowed`,inputs:[{name:`handle`,type:`bytes32`,internalType:`bytes32`},{name:`account`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`isAllowedForDecryption`,inputs:[{name:`handle`,type:`bytes32`,internalType:`bytes32`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`isHandleDelegatedForUserDecryption`,inputs:[{name:`delegator`,type:`address`,internalType:`address`},{name:`delegate`,type:`address`,internalType:`address`},{name:`contractAddress`,type:`address`,internalType:`address`},{name:`handle`,type:`bytes32`,internalType:`bytes32`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`multicall`,inputs:[{name:`data`,type:`bytes[]`,internalType:`bytes[]`}],outputs:[{name:`results`,type:`bytes[]`,internalType:`bytes[]`}],stateMutability:`payable`},{type:`function`,name:`persistAllowed`,inputs:[{name:`handle`,type:`bytes32`,internalType:`bytes32`},{name:`account`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`revokeDelegationForUserDecryption`,inputs:[{name:`delegate`,type:`address`,internalType:`address`},{name:`contractAddress`,type:`address`,internalType:`address`}],outputs:[],stateMutability:`nonpayable`}];function O(e,t,n,r){return{address:e,abi:D,functionName:`delegateForUserDecryption`,args:[t,n,r]}}function k(e,t,n){return{address:e,abi:D,functionName:`revokeDelegationForUserDecryption`,args:[t,n]}}function A(e,t,n,r){return{address:e,abi:D,functionName:`getUserDecryptionDelegationExpirationDate`,args:[t,n,r]}}function ne(e,t,n,r,i){return{address:e,abi:D,functionName:`isHandleDelegatedForUserDecryption`,args:[t,n,r,i]}}const j=2n**64n-1n;function re(e){return o.i(e.signer,e.provider,e)}var M=class{#e;#t;#n;#r;#i;#a;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.cachingService,this.#r=e.credentialService,this.#i=e.logger,this.#a=e.emitEvent}#o(e){return t.R(this.#r,e)}#s(e,n){throw this.#a({type:t.M.PermitError,operation:e,error:n instanceof Error?n:Error(String(n))}),n}async grantPermit(e){if(e.length===0)return;let t;try{t=this.#o(`grantPermit`),await r.o(`grantPermit`,this.#e,this.#t)}catch(e){this.#s(`grantPermit`,e)}await t.grantPermit(e)}async grantDelegationPermit(e,t){if(t.length===0)return;let n;try{n=this.#o(`grantDelegationPermit`),await r.o(`grantDelegationPermit`,this.#e,this.#t)}catch(e){this.#s(`grantDelegationPermit`,e)}await n.grantPermit(t,e)}async hasPermit(e){return this.#r?this.#r.hasPermit(e):!1}async hasDelegationPermit(e,t){return this.#r?this.#r.hasPermit(t,e):!1}async warmTransportKeyPair(){let e=this.#r;if(!e)return;let t=this.#e?.walletAccount.getSnapshot();t&&await e.warmTransportKeyPair(t.address)}async registerPermit(e,t){let n;try{n=this.#o(`registerPermit`)}catch(e){this.#s(`registerPermit`,e)}await n.registerPermit(e,t),await this.#c(e.signerAddress)}async revokePermits(e){let t=this.#o(`revokePermits`),n=(0,f.getAddress)((await r.a(`revokePermits`,this.#e,this.#t)).address);try{await t.revokePermits(e)}finally{await this.#c(n)}}async clear(){let e=this.#o(`clear`),t=(0,f.getAddress)((await r.a(`clear`,this.#e,this.#t)).address);try{await e.clearCredentials()}finally{await this.#c(t)}}async#c(e){await t.j(`clear decrypt cache`,()=>this.#n.clearForRequester(e),this.#i)}async revokeTransportKeyPair(e){await this.#o(`revokeTransportKeyPair`).revokeTransportKeyPair(e)}async warmTransportKeyPairScope(e){await this.#o(`warmTransportKeyPairScope`).warmTransportKeyPairScope(e)}},N=class{#e;#t;#n;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.delegationService}#r(e){return t.R(this.#e,e)}async delegateDecryption({contractAddress:e,delegateAddress:t,expirationDate:n}){let i=this.#r(`delegateDecryption`),a=await r.a(`delegateDecryption`,this.#e,this.#t);return this.#n.delegateDecryption(i,{contractAddress:e,delegateAddress:t,delegatorAddress:a.address,expirationDate:n})}async revokeDelegation({contractAddress:e,delegateAddress:t}){let n=this.#r(`revokeDelegation`),i=await r.a(`revokeDelegation`,this.#e,this.#t);return this.#n.revokeDelegation(n,{contractAddress:e,delegateAddress:t,delegatorAddress:i.address})}async isActive(e){return this.#n.isDelegated(e)}async getExpiry(e){return this.#n.getDelegationExpiry(e)}async getStatus(e){return this.#n.getStatus(e)}},P=class{#e;#t;#n;#r;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.router,this.#r=e.decryptionService}#i(e){return t.R(this.#r,e)}async decryptValues(e,t){let n=this.#i(`decryptValues`),i=await r.a(`decryptValues`,this.#e,this.#t);return n.decryptValues(e,i.address,t)}async delegatedDecryptValues(e,t,n=t,i){let a=this.#i(`delegatedDecryptValues`),o=await r.a(`delegatedDecryptValues`,this.#e,this.#t);return a.delegatedDecryptValues(e,t,o.address,n,i)}async decryptPublicValues(e,t){if(e.length===0)return{clearValues:{},decryptionProof:`0x`,abiEncodedClearValues:`0x`};try{let n=await this.#n.relayer.decryptPublicValuesWithSignatures({encryptedValues:e,options:t}),r={};return n.checkSignaturesArgs.handlesList.forEach((e,t)=>{d.r(n.clearValues[t],`result.clearValues[${t}]`),r[e]=n.clearValues[t].value}),{clearValues:r,abiEncodedClearValues:n.checkSignaturesArgs.abiEncodedCleartexts,decryptionProof:n.checkSignaturesArgs.decryptionProof}}catch(e){throw E(e,`Public decryption failed`)}}async delegatedBatchDecryptValues({encryptedInputs:e,delegatorAddress:t,accountAddress:n=t,maxConcurrency:i,waitForPropagation:a}){let o=this.#i(`delegatedBatchDecryptValues`),s=await r.a(`delegatedBatchDecryptValues`,this.#e,this.#t);return o.delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:s.address,accountAddress:n,maxConcurrency:i,waitForPropagation:a})}},F=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}prepare(e,t){return this.#e.prepare(e,t)}preparePermit(e){return this.#t.preparePermit(e)}},I=class{async get(e){return(await chrome.storage.session.get(e))[e]??null}async set(e,t){await chrome.storage.session.set({[e]:t})}async delete(e){await chrome.storage.session.remove(e)}};const ie=new I,ae=p.z.union([p.z.bigint(),p.z.boolean(),s.n]),oe=p.z.array(p.z.string());var se=class{#e;#t;#n=`zama:decrypt`;#r=`${this.#n}:keys`;#i=Promise.resolve();constructor(e,t){this.#e=e,this.#t=t}async get(e,t,n){try{let r=this.#c(e,t,n),i=await this.#e.get(r);if(i===null)return null;let a=ae.safeParse(i);return a.success?a.data:(await this.delete(e,t,n),null)}catch(e){return this.#t.warn(`CachingService.get failed`,{error:e}),null}}async set(e,t,n,r){try{let i=this.#c(e,t,n);await this.#e.set(i,r),this.#i=this.#i.then(()=>this.#u(i).catch(e=>{this.#t.warn(`CachingService index write failed`,{error:e})})),await this.#i}catch(e){this.#t.warn(`CachingService.set failed`,{error:e})}}async delete(e,t,n){let r=this.#c(e,t,n);this.#i=this.#i.then(()=>this.#a(r).catch(e=>{this.#t.warn(`CachingService.delete failed`,{error:e})})),await this.#i}async clearForRequester(e){this.#i=this.#i.then(()=>this.#o(e).catch(e=>{this.#t.warn(`CachingService.clearForRequester failed`,{error:e})})),await this.#i}async clearAll(){this.#i=this.#i.then(()=>this.#s().catch(e=>{this.#t.warn(`CachingService.clearAll failed`,{error:e})})),await this.#i}async#a(e){await this.#e.delete(e).catch(()=>{});let t=await this.#l(),n=t.filter(t=>t!==e);n.length!==t.length&&await this.#e.set(this.#r,n)}async#o(e){let t=(0,f.getAddress)(e),n=`${this.#n}:${t}:`,r=await this.#l(),i=[],a=[];for(let e of r)e.startsWith(n)?i.push(e):a.push(e);await Promise.all(i.map(e=>this.#e.delete(e).catch(()=>{}))),await this.#e.set(this.#r,a)}async#s(){let e=await this.#l();await Promise.all(e.map(e=>this.#e.delete(e).catch(()=>{}))),await this.#e.delete(this.#r)}#c(e,t,n){return`${this.#n}:${(0,f.getAddress)(e)}:${(0,f.getAddress)(t)}:${n.toLowerCase()}`}async#l(){let e=await this.#e.get(this.#r);if(e===null)return[];let t=oe.safeParse(e);return t.success?t.data:(await this.#e.delete(this.#r).catch(()=>{}),[])}async#u(e){let t=await this.#l();t.includes(e)||(t.push(e),await this.#e.set(this.#r,t))}};function ce(e,t){let r=le(e,t);if(!r)throw new n.t(`No permit covers contract ${t} after allow()`);return{privateKey:e.keypair.privateKey,publicKey:e.keypair.publicKey,serializedPermit:r.serializedPermit}}function le(e,t){let n=s.t(t);return e.permissions.find(e=>e.contractAddresses.includes(n))}const ue=e=>new Promise(t=>setTimeout(t,e));var de=class{#e;#t;#n;#r;#i;constructor({cache:e,credentialService:t,delegationService:n,router:r,emitEvent:i}){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i}async decryptValues(e,t,n){let r=(0,f.getAddress)(t);return this.#s(e,{requesterAddress:r,errorMessage:`Failed to decrypt encrypted values`},n)}async delegatedDecryptValues(e,t,n,r,i){let a=(0,f.getAddress)(t),o=(0,f.getAddress)(n),s={spent:!1};return this.#a(i?.waitForPropagation??!0,()=>this.#s(e,{requesterAddress:(0,f.getAddress)(r),delegator:a,validate:e=>this.#m(e,{delegatorAddress:a,delegateAddress:o}),errorMessage:`Failed to decrypt delegated encrypted values`},void 0,s))}async#a(e,t){let n;for(let r=0;r<16;r++)try{return await t()}catch(t){if(n=t,!(r<15&&e&&t instanceof T))throw t;await ue(2e3)}throw n}async delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:n,accountAddress:i,maxConcurrency:a=5,waitForPropagation:o=!0}){let s=e.map(e=>({encryptedValue:e.encryptedValue,contractAddress:(0,f.getAddress)(e.contractAddress)}));if(s.length===0)return{items:s};let c=(0,f.getAddress)(i);try{let e=await this.delegatedDecryptValues(s.map(({encryptedValue:e,contractAddress:t})=>({encryptedValue:e,contractAddress:t})),t,n,c,{waitForPropagation:o});for(let t of s)this.#d(t,e);return{items:s}}catch(e){if(r.u(e))throw e;if(s.length===1){let[n=this.#p()]=s;return n.error=this.#f(e,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:n.contractAddress,account:(0,f.getAddress)(t)}),{items:s}}}let l=!1,u;if(await r.r(s.map(e=>async()=>{if(!l)try{let r=await this.delegatedDecryptValues([{encryptedValue:e.encryptedValue,contractAddress:e.contractAddress}],t,n,c,{waitForPropagation:!1});this.#d(e,r)}catch(n){if(r.u(n)){l=!0,u??=n;return}e.error=this.#f(n,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:e.contractAddress,account:(0,f.getAddress)(t)})}}),a),u!==void 0)throw u;return{items:s}}async#o(t,n,r,i){let a=ce(t,n),o;try{o=await this.#r.relayer.parseTransportKeyPair({publicKey:a.publicKey,privateKey:a.privateKey,tkmsVersion:t.keypair.tkmsVersion})}catch(t){throw t instanceof Error&&e.p(t.message)&&await this.#t.evictTransportKeyPair(),t}let s=await this.#r.relayer.parseSignedDecryptionPermit({transportKeyPair:o,serializedPermit:a.serializedPermit});return this.#r.relayer.decryptValues({transportKeyPair:o,signedPermit:s,encryptedValues:r,contractAddress:n,options:i})}async#s(n,i,a,o={spent:!1}){if(n.length===0)return{};let s=n.map(e=>({encryptedValue:e.encryptedValue,contractAddress:(0,f.getAddress)(e.contractAddress)})),c={},l=[];for(let e of s)r.l(e.encryptedValue)?c[e.encryptedValue]=0n:l.push(e);if(l.length===0)return c;let u=Array.from(new Set(s.map(e=>e.contractAddress))),d=Array.from(new Set(l.map(e=>e.contractAddress)));if(i.validate)try{await i.validate(d)}catch(t){throw e.v(t)?this.#u(t,`the delegation pre-check`):t}let p=[];for(let e of l){let t=await this.#e.get(i.requesterAddress,e.contractAddress,e.encryptedValue);t===null?p.push(e):c[e.encryptedValue]=t}if(p.length===0)return c;let m=await this.#t.grantPermit(u,i.delegator),h=new Map;for(let e of p){let t=h.get(e.contractAddress);t?t.push(e.encryptedValue):h.set(e.contractAddress,[e.encryptedValue])}let g=[];for(let[e,t]of h)for(let n of r.c(t))g.push({contractAddress:e,encryptedValues:n});let _=Date.now(),v=p.map(e=>e.encryptedValue);try{this.#i({type:t.M.DecryptStart,encryptedValues:v});try{await this.#c(i,m,g,c,a)}catch(e){if(!(e instanceof t.J)||o.spent)throw e;let n=m.permissions.map(e=>e.serializedPermit.signature);o.spent=!0;try{m=await this.#t.recoverPermits(u,i.delegator,n)}catch(e){throw e instanceof t.B?new t.J(`The permit's KMS context has been revoked on-chain and the automatic re-grant failed, so the decrypt cannot proceed. Establish a new permit for this scope and retry.`,{cause:e}):e}await this.#c(i,m,g.filter(({encryptedValues:e})=>e.some(e=>c[e]===void 0)),c,a)}let e={};for(let t of v){let n=c[t];n!==void 0&&(e[t]=n)}return this.#i({type:t.M.DecryptEnd,durationMs:Date.now()-_,encryptedValues:v,result:e}),c}catch(n){let r=n instanceof e.r&&n.cause instanceof Error?n.cause:n;throw this.#i({type:t.M.DecryptError,error:e.S(r),durationMs:Date.now()-_,encryptedValues:v}),E(n,i.errorMessage,{isDelegated:i.delegator!==void 0})}}async#c(e,n,i,a,o){let s=(await r.r(i.map(({contractAddress:t,encryptedValues:r})=>async()=>{try{await this.#l(e,n,t,r,a,o);return}catch(e){return e}}),5)).filter(e=>e!==void 0);if(s.length>0)throw s.find(e=>e instanceof t.J)??s[0]}async#l(e,t,r,i,a,o){let s;try{s=await this.#o(t,r,i,o)}catch(t){throw E(t,e.errorMessage,{isDelegated:e.delegator!==void 0,contractAddress:r,account:e.delegator??e.requesterAddress})}for(let t=0;t<i.length;t++){let n=i[t],o=s[t]?.value;n!==void 0&&o!==void 0&&(a[n]=o,await this.#e.set(e.requesterAddress,r,n,o))}let c=i.filter(e=>a[e]===void 0);if(c.length>0)throw new n.t(`${e.errorMessage}: relayer returned no clear value for ${c.length} of ${i.length} handle(s) on ${r}`,{cause:AggregateError(c.map(e=>new n.t(`No clear value for handle ${e} on ${r}`)),`${c.length} handle(s) missing a clear value on ${r}`)})}#u(t,n){return new r._(`RPC provider rate-limited ${n}; retry with backoff.`,{cause:t,retryAfter:e.c(t)})}#d(e,t){let r=t[e.encryptedValue];if(r===void 0){e.error=new n.t(`Batch delegated decryption returned no value for encrypted value ${e.encryptedValue} on contract ${e.contractAddress}`);return}e.value=r}#f(t,n,r){return t instanceof e.r?t:E(t,n,r)}#p(){throw new n.t(`Batch delegated decryption invariant failed: missing item`)}async#m(e,{delegatorAddress:t,delegateAddress:n}){let r=await this.#n.findInactiveDelegations(e,t,n);if(r.size!==0)for(let e of r.values())throw e}};const L={AlreadyDelegatedOrRevokedInSameBlock:e=>new _(`Only one delegate/revoke per (delegator, delegate, contract) per block. Wait for the next block before retrying.`,{cause:e}),SenderCannotBeContractAddress:e=>new S(`The contract address cannot be the caller address.`,{cause:e}),EnforcedPause:e=>new C(`The ACL contract is paused. Delegation operations are temporarily disabled.`,{cause:e}),SenderCannotBeDelegate:e=>new g(`Cannot delegate to yourself (delegate === msg.sender).`,{cause:e}),DelegateCannotBeContractAddress:e=>new x(`Delegate address cannot be the same as the contract address.`,{cause:e}),ExpirationDateBeforeOneHour:e=>new w(`Expiration date must be at least 1 hour in the future.`,{cause:e}),ExpirationDateAlreadySetToSameValue:e=>new b(`The new expiration date is the same as the current one.`,{cause:e}),NotDelegatedYet:e=>new v(`Cannot revoke: no active delegation exists.`,{cause:e})};function R(e){return Object.hasOwn(L,e)}function z(e,t){let n=i.T(e);if(n&&R(n))return L[n](t);let r=e instanceof Error?e.message:String(e);for(let[e,n]of Object.entries(L))if(r.includes(e))return n(t);return null}var B=class{#e;#t;#n;#r;constructor({provider:e,router:t,emitEvent:n=()=>{},logger:r}){this.#t=e,this.#e=t,this.#r=r,this.#n=n}async delegateDecryption(e,{contractAddress:t,delegateAddress:n,delegatorAddress:r,expirationDate:i}){if(i&&i.getTime()<Date.now()+36e5)throw new w(`Expiration date must be at least 1 hour in the future`);let a=(0,f.getAddress)(t),o=(0,f.getAddress)(n),s=(0,f.getAddress)(r);if(o===s)throw new g(`Cannot delegate to yourself (delegate === msg.sender).`);if(o===a)throw new x(`Delegate address cannot be the same as the contract address (${a}).`);let c=this.#e.relayer.chain.aclContractAddress,l=i?BigInt(Math.floor(i.getTime()/1e3)):j,u;try{u=await this.getDelegationExpiry({contractAddress:a,delegatorAddress:s,delegateAddress:o})}catch(e){this.#r.warn(`delegateDecryption: pre-flight expiry check failed`,{error:e}),u=-1n}if(u===l)throw new b(`The new expiration date (${l}) is the same as the current one. No on-chain change needed.`);return this.#i({operation:`delegateDecryption`,signer:e,contractAddress:a,config:O(c,o,a,l)})}async revokeDelegation(e,{contractAddress:t,delegateAddress:n,delegatorAddress:r}){let i=(0,f.getAddress)(t),a=(0,f.getAddress)(n),o=(0,f.getAddress)(r),s=this.#e.relayer.chain.aclContractAddress,c;try{c=await this.getDelegationExpiry({contractAddress:i,delegatorAddress:o,delegateAddress:a})}catch(e){this.#r.warn(`revokeDelegation: pre-flight expiry check failed`,{error:e}),c=1n}if(c===0n)throw new v(`No active delegation found for delegate ${a} on contract ${i}.`);return this.#i({operation:`revokeDelegation`,signer:e,contractAddress:i,config:k(s,a,i)})}async isDelegated(e){return(await this.getStatus(e)).isActive}async getStatus(e){let t=await this.getDelegationExpiry(e);return t===0n?{isActive:!1,expiryTimestamp:t}:t===j?{isActive:!0,expiryTimestamp:t}:{isActive:t>await this.#t.getBlockTimestamp(),expiryTimestamp:t}}async getDelegationExpiry({contractAddress:e,delegatorAddress:t,delegateAddress:n}){let r=this.#e.relayer.chain.aclContractAddress;return this.#t.readContract(A(r,(0,f.getAddress)(t),(0,f.getAddress)(n),(0,f.getAddress)(e)))}async#i({operation:e,signer:t,contractAddress:n,config:i}){try{return await r.n({operation:e,signer:t,provider:this.#t,config:i,emit:e=>this.#n(e,n),logger:this.#r})}catch(e){throw this.#a(e),e}}#a(e){if(!(e instanceof t.z))return;let n=z(e.cause??e,e);if(n)throw n}async findInactiveDelegations(e,t,n){let r=new Map;return await Promise.all(e.map(async e=>{try{await this.assertDelegationActive(e,t,n)}catch(t){if(t instanceof v||t instanceof y){let n=(0,f.getAddress)(e);r.set(n,t);return}throw t}})),r}async assertDelegationActive(e,t,n){let r=(0,f.getAddress)(e),i=(0,f.getAddress)(t),a=(0,f.getAddress)(n),{isActive:o,expiryTimestamp:s}=await this.getStatus({contractAddress:r,delegatorAddress:i,delegateAddress:a});if(!o)throw s===0n?new v(`No active delegation from ${i} to ${a} for ${r}`):new y(`Delegation from ${i} to ${a} for ${r} has expired`)}},V=class{#e;#t;constructor({router:e,emitEvent:t}){this.#e=e,this.#t=t}async encryptValues(n,r){let i=Date.now(),a=(0,f.getAddress)(n.contractAddress);try{this.#t({type:t.M.EncryptStart},a);let e=await this.#e.relayer.encryptValues({...n,options:r});return this.#t({type:t.M.EncryptEnd,durationMs:Date.now()-i},a),e}catch(n){throw this.#t({type:t.M.EncryptError,error:e.S(n),durationMs:Date.now()-i},a),te(n,`Encryption failed`)}}},fe=class{#e;#t;#n;#r;#i;#a=new Set;#o;constructor(e){this.#e=e.signer,this.#t=e.router,this.#n=e.cachingService,this.#r=e.credentialService,this.#i=e.logger,this.#e&&(this.#o=this.#e.walletAccount.subscribe(e=>{this.#s(e).catch(e=>{this.#i.warn(`wallet account handler failed`,{error:e})})}))}onWalletAccountChange(e){return this.#a.add(e),()=>{this.#a.delete(e)}}dispose(){this.#o?.(),this.#o=void 0,this.#a.clear()}async#s(e){let n=e.previous,r=e.next,i=r?.chainId;i!==void 0&&await t.j(`switch relayer chain`,()=>this.#t.switchChain(i),this.#i);let a=this.#r;a&&await t.j(`credential wallet account change`,()=>a.handleWalletAccountChange(n,r),this.#i),n&&await t.j(`clear decrypt cache`,()=>this.#n.clearForRequester(n.address),this.#i),await Promise.all(Array.from(this.#a,n=>t.j(`wallet account listener`,()=>n(e),this.#i)))}};const H=p.z.object({kind:p.z.literal(`ConfidentialTransfer`),from:s.n,token:s.n,to:s.n,amount:p.z.bigint()}),U=p.z.object({kind:p.z.literal(`ConfidentialTransferFrom`),from:s.n,token:s.n,owner:s.n,to:s.n,amount:p.z.bigint()}),W=p.z.object({kind:p.z.literal(`SetOperator`),from:s.n,token:s.n,operator:s.n,until:s.s}),G=p.z.object({kind:p.z.literal(`Unwrap`),from:s.n,token:s.n,to:s.n,amount:p.z.bigint()}),K=p.z.object({kind:p.z.literal(`UnwrapAll`),from:s.n,token:s.n,to:s.n}),q=p.z.object({kind:p.z.literal(`FinalizeUnwrap`),from:s.n,wrapper:s.n,unwrapRequestIdOrAmount:s.r}),J=p.z.object({kind:p.z.literal(`ApproveUnderlying`),from:s.n,underlying:s.n,spender:s.n,amount:p.z.bigint()}),Y=p.z.object({kind:p.z.literal(`Wrap`),from:s.n,wrapper:s.n,to:s.n,amount:p.z.bigint()}),pe=s.r.check(p.z.refine(e=>e===`0x`||(0,f.size)(e)===20,`TransferAndCall.recipientData must be "0x" (self-shield to the sender) or a raw 20-byte address, not a 32-byte ABI-encoded value the wrapper would truncate to a garbage address`)),X=p.z.object({kind:p.z.literal(`TransferAndCall`),from:s.n,underlying:s.n,wrapper:s.n,amount:p.z.bigint(),recipientData:p.z.optional(pe)}),Z=p.z.object({kind:p.z.literal(`DelegateDecryption`),from:s.n,contractAddress:s.n,delegateAddress:s.n,expirationDate:p.z.optional(p.z.date())}),Q=p.z.object({kind:p.z.literal(`RevokeDelegation`),from:s.n,contractAddress:s.n,delegateAddress:s.n});p.z.discriminatedUnion(`kind`,[H,U,W,G,K,q,J,Y,X,Z,Q]);const me=p.z.strictObject({maxFeePerGas:p.z.bigint(),maxPriorityFeePerGas:p.z.bigint()}),$=p.z.object({nonce:p.z.optional(p.z.int().check(p.z.nonnegative())),gasLimit:p.z.optional(p.z.bigint()),fees:p.z.optional(me)}),he=p.z.object({address:s.n,abi:p.z.array(p.z.unknown()),functionName:p.z.string(),args:p.z.array(p.z.unknown()),value:p.z.optional(p.z.bigint()),gas:p.z.optional(p.z.bigint())}),ge=p.z.extend($,{from:s.n,calldata:he});var _e=class{#e;#t;#n;constructor(e){this.#e=e.provider,this.#t=e.router,this.#n=e.encryption}async prepare(t,n){n&&=c.t($,n);let r=await this.#e.getChainId(),i=this.#t.chain.id;if(r!==i)throw new e.t(`Offline.prepare: provider is on chain ${r} but the SDK is configured for chain ${i}. The prepared transaction's contract addresses and encrypted inputs are bound to chain ${i} — point the provider at the same chain.`);let a=c.t(ge,{calldata:await this.#r(t),from:t.from,nonce:n?.nonce,gasLimit:n?.gasLimit,fees:n?.fees}),o=await this.#e.prepareTransaction(a);return{kind:t.kind,unsignedTx:o,from:a.from}}async#r(t){switch(t.kind){case`ConfidentialTransfer`:return this.#i(t);case`ConfidentialTransferFrom`:return this.#a(t);case`SetOperator`:return this.#o(t);case`Unwrap`:return this.#s(t);case`UnwrapAll`:return this.#c(t);case`FinalizeUnwrap`:return this.#l(t);case`ApproveUnderlying`:return this.#u(t);case`Wrap`:return this.#d(t);case`TransferAndCall`:return this.#f(t);case`DelegateDecryption`:return this.#p(t);case`RevokeDelegation`:return this.#m(t);default:throw new e.t(`OfflineService.prepare: unsupported transaction kind '${t.kind}'.`)}}async#i(e){e=c.t(H,e);let{encryptedValues:r,inputProof:i}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from}),a=r[0];if(!a)throw new n.r(`Encryption returned no handles for ConfidentialTransfer`);return t.v(e.token,e.to,a,i)}async#a(e){e=c.t(U,e);let{encryptedValues:r,inputProof:i}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from}),a=r[0];if(!a)throw new n.r(`Encryption returned no handles for ConfidentialTransferFrom`);return t.b(e.token,e.owner,e.to,a,i)}#o(e){return e=c.t(W,e),t.T(e.token,e.operator,e.until)}async#s(e){e=c.t(G,e);let{encryptedValues:r,inputProof:i}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from}),a=r[0];if(!a)throw new n.r(`Encryption returned no handles for Unwrap`);return t.D(e.token,e.from,e.to,a,i)}async#c(e){e=c.t(K,e);let n=await this.#e.readContract(t.h(e.token,e.from));return t.O(e.token,e.from,e.to,n)}async#l(e){e=c.t(q,e);let n=await this.#t.relayer.decryptPublicValuesWithSignatures({encryptedValues:[e.unwrapRequestIdOrAmount]}).catch(e=>{throw E(e,`Public decryption failed during FinalizeUnwrap`)}),r=n.clearValues[0]?.value;return d.t(r,`FinalizeUnwrap: decryptPublicValuesWithSignatures(handle).clearValue`),t.x(e.wrapper,e.unwrapRequestIdOrAmount,r,n.checkSignaturesArgs.decryptionProof)}#u(e){return e=c.t(J,e),t.l(e.underlying,e.spender,e.amount)}#d(e){return e=c.t(Y,e),t.A(e.wrapper,e.to,e.amount)}#f(e){return e=c.t(X,e),i.C(e.underlying,e.wrapper,e.amount,e.recipientData)}#p(e){if(e=c.t(Z,e),e.expirationDate&&e.expirationDate.getTime()<Date.now()+36e5)throw new w(`Expiration date must be at least 1 hour in the future`);if(e.delegateAddress===e.from)throw new g(`Cannot delegate to yourself (delegate === msg.sender).`);if(e.delegateAddress===e.contractAddress)throw new x(`Delegate address cannot be the same as the contract address (${e.contractAddress}).`);let t=e.expirationDate?BigInt(Math.floor(e.expirationDate.getTime()/1e3)):j;return O(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress,t)}#m(e){return e=c.t(Q,e),k(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress)}};function ve(t){if(!(!Object.hasOwn(t,`transportKeyPairDerivationSecret`)||t.transportKeyPairDerivationSecret!==void 0))throw new e.t(`transportKeyPairDerivationSecret was passed as undefined, which usually means the environment variable it reads is unset (e.g. process.env.ZAMA_DERIVATION_SECRET). Supply the secret, or omit the option entirely to persist transport key pairs in cleartext on purpose.`)}function ye(t){if(t===void 0)return;let{importScripts:n}=globalThis;if(!(typeof window>`u`&&typeof document>`u`&&typeof n!=`function`))throw new e.t(`transportKeyPairDerivationSecret is supported in headless environments only (CLI tools, servers, agents). Remove the option: an environment with a platform keystore, or one that ships a bundle, must delegate at-rest security of the transport key pair to the storage backend.`)}function be(e){if(e===void 0)return;let t=c.t(o.c,e);return new o.l(typeof t==`string`?t:new Uint8Array(t))}var xe=class{#e;provider;signer;storage;registry;permits;delegations;decryption;offline;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;constructor(e,t={}){ve(t),ye(t.transportKeyPairDerivationSecret);let n=be(t.transportKeyPairDerivationSecret);this.#e=e.router,this.provider=e.provider,this.signer=e.signer,this.storage=e.storage,this.#r=e.onEvent??function(){},this.#i=e.logger,this.#a=new se(e.storage,this.#i),this.#u=new B({provider:this.provider,router:e.router,emitEvent:this.emitEvent.bind(this),logger:this.#i});let r={};for(let t of e.chains)t.registryAddress&&(r[t.id]=t.registryAddress);this.registry=new o.o({provider:this.provider,registryAddresses:r,registryTTL:e.registryTTL}),this.#n=r,this.#t=e.registryTTL,this.#l=new o.s({router:e.router,signer:e.signer,transportKeyPairTTL:e.transportKeyPairTTL,permitTTL:e.permitTTL,scope:e.transportKeyPairScope,derivationSecret:n,storage:this.storage,permitStorage:e.permitStorage,logger:this.#i,emitEvent:this.emitEvent.bind(this)}),e.signer&&(this.#c=new de({cache:this.#a,credentialService:this.#l,delegationService:this.#u,router:e.router,emitEvent:this.emitEvent.bind(this)})),this.#s=new V({router:e.router,emitEvent:this.emitEvent.bind(this)}),this.#o=new fe({signer:e.signer,router:e.router,cachingService:this.#a,credentialService:this.#l,logger:this.#i}),this.#d=new _e({provider:this.provider,router:e.router,encryption:this.#s,emitEvent:(e,t)=>this.emitEvent(e,t)}),this.permits=new M({signer:this.signer,provider:this.provider,cachingService:this.#a,credentialService:this.#l,logger:this.#i,emitEvent:this.emitEvent.bind(this)}),this.delegations=new N({signer:this.signer,provider:this.provider,delegationService:this.#u}),this.decryption=new P({signer:this.signer,provider:this.provider,router:e.router,decryptionService:this.#c}),this.offline=new F(this.#d,this.#l)}onWalletAccountChange(e){return this.#o.onWalletAccountChange(e)}get logger(){return this.#i}get relayer(){return this.#e.relayer}emitEvent(e,t){try{this.#r({...e,tokenAddress:t,timestamp:Date.now()})}catch(t){this.#i.warn(`${e.type} event listener silently failed`,{error:t})}}createWrappersRegistry(e){return new o.o({provider:this.provider,registryAddresses:{...this.#n,...e},registryTTL:this.#t})}async encrypt(e,t){return this.#s.encryptValues(e,t)}createToken(e){return new r.t(this,e)}createWrappedToken(e){return new i.t(this,e)}dispose(){this.#o.dispose(),this.#e.dispose()}terminate(){this.dispose(),this.signer?.dispose?.()}[Symbol.dispose](){this.terminate()}};exports.ACL_TOPICS=i.n,exports.AclPausedError=C,exports.AclTopics=i.r,exports.BalanceCheckUnavailableError=r.d,exports.BaseSigner=o.t,exports.ChainMismatchError=r.g,exports.ChromeSessionStorage=I,exports.ConfigurationError=e.t,exports.Decryption=P,exports.DecryptionFailedError=n.t,exports.DefaultRegistryAddresses=o.a,exports.DelegationContractIsSelfError=S,exports.DelegationCooldownError=_,exports.DelegationDelegateEqualsContractError=x,exports.DelegationExpirationTooSoonError=w,exports.DelegationExpiredError=y,exports.DelegationExpiryUnchangedError=b,exports.DelegationNotFoundError=v,exports.DelegationNotPropagatedError=T,exports.DelegationSelfNotAllowedError=g,exports.Delegations=N,exports.ERC1363_INTERFACE_ID=t.t,exports.ERC20ReadFailedError=r.f,exports.ERC7984_INTERFACE_ID=t.n,exports.ERC7984_WRAPPER_INTERFACE_ID=t.r,exports.EncryptOffloadUnavailableError=n.n,exports.EncryptionFailedError=n.r,exports.IndexedDBStorage=o.f,exports.InsufficientAllowanceError=r.p,exports.InsufficientConfidentialBalanceError=r.m,exports.InsufficientERC20BalanceError=r.h,exports.InvalidTransportKeyPairError=t.U,exports.KeyWrappingError=t.W,exports.MemoryStorage=o.u,exports.MutableWalletAccountStore=o.n,exports.NoCiphertextError=t.G,exports.NotEntitledError=h,exports.Offline=F,exports.Permits=M,exports.PreparedPermitChainMismatchError=t.K,exports.PreparedPermitExpiredError=t.q,exports.RelayerRequestFailedError=e.n,exports.RevokedKmsContextError=t.J,exports.RpcRateLimitError=r._,exports.SignerNotConfiguredError=t.P,exports.SignerRequiredError=t.F,exports.SigningFailedError=t.B,exports.SigningRejectedError=t.V,exports.TOKEN_TOPICS=i.i,exports.Token=r.t,exports.Topics=i.a,exports.TransactionRevertedError=t.z,exports.TransportKeyPairChangedError=t.Y,exports.TransportKeyPairExpiredError=t.X,exports.UnshieldAlreadyFinalizedError=i.w,exports.WalletAccountNotReadyError=t.I,exports.WalletNotConnectedError=t.L,exports.WrappedToken=i.t,exports.WrappersRegistry=o.o,exports.ZERO_ENCRYPTED_VALUE=r.s,exports.ZamaError=e.r,exports.ZamaErrorCode=e.i,exports.ZamaSDK=xe,exports.ZamaSDKEvents=t.M,exports.allowanceContract=t.c,exports.anvil=u.t,exports.approveContract=t.l,exports.balanceOfContract=t.u,exports.bscTestnet=u.n,exports.chains=u.r,exports.chromeSessionStorage=ie,exports.cleartext=a.t,exports.confidentialBalanceOfContract=t.h,exports.confidentialTotalSupplyContract=t.g,exports.confidentialTransferContract=t.v,exports.confidentialTransferFromContract=t.b,exports.createConfig=re,exports.createWalletAccountStore=o.r,exports.decimalsContract=t.d,exports.decodeAclEvent=i.o,exports.decodeAclEvents=i.s,exports.decodeConfidentialTransfer=i.c,exports.decodeDelegatedForUserDecryption=i.l,exports.decodeOnChainEvent=i.u,exports.decodeOnChainEvents=i.d,exports.decodeRevokedDelegationForUserDecryption=i.f,exports.decodeUnwrapFinalized=i.p,exports.decodeUnwrapRequested=i.m,exports.decodeWrap=i.h,exports.delegateForUserDecryptionContract=O,exports.finalizeUnwrapContract=t.x,exports.findDelegatedForUserDecryption=i.g,exports.findRevokedDelegationForUserDecryption=i._,exports.findUnwrapRequested=i.v,exports.findWrap=i.y,exports.getConfidentialTokenAddressContract=l.t,exports.getDelegationExpiryContract=A,exports.getTokenAddressContract=l.n,exports.getTokenPairContract=l.r,exports.getTokenPairsContract=l.i,exports.getTokenPairsLengthContract=l.a,exports.getTokenPairsSliceContract=l.o,exports.hardhat=u.i,exports.hoodi=u.a,exports.indexedDBStorage=o.p,exports.inferredTotalSupplyContract=t.S,exports.ingenTestnet=u.o,exports.isConfidentialTokenContract=t.i,exports.isConfidentialTokenValidContract=l.s,exports.isConfidentialWrapperContract=t.a,exports.isEncryptedValueZero=r.l,exports.isHandleDelegatedContract=ne,exports.isOperatorContract=t.C,exports.isRetryable=e.a,exports.mainnet=u.s,exports.matchZamaError=m,exports.memoryStorage=o.d,exports.nameContract=t.p,exports.polygon=u.c,exports.polygonAmoy=u.l,exports.rateContract=t.w,exports.retryAfterSeconds=e.o,exports.revokeDelegationContract=k,exports.sepolia=u.u,exports.setOperatorContract=t.T,exports.supportsInterfaceContract=t.s,exports.symbolContract=t.m,exports.transferAndCallContract=i.C,exports.underlyingContract=t.E,exports.unwrapContract=t.D,exports.unwrapFromBalanceContract=t.O,exports.unwrapRequesterContract=t.k,exports.wrapContract=t.A;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./relayer.cjs"),t=require("./erc165.cjs"),n=require("./encryption.cjs"),r=require("./token.cjs"),i=require("./wrapped-token.cjs"),a=require("./cleartext.cjs"),o=require("./base-signer.cjs"),s=require("./primitives.cjs"),c=require("./validation.cjs"),l=require("./wrappers-registry.cjs"),u=require("./chains.cjs"),d=require("./assertions.cjs");let f=require("viem"),p=require("zod/mini");function m(t,n){if(t instanceof e.r){let e=n[t.code];if(e)return e(t)}return n._?.(t)}var h=class extends e.r{encryptedValue;contractAddress;account;constructor(t,n){super(e.i.NotEntitled,`Account ${t.account} is not entitled to decrypt encrypted value ${t.encryptedValue} on contract ${t.contractAddress}. This is not a transient failure — the account needs an on-chain ACL grant before it can decrypt this encrypted value.`,n),this.name=`NotEntitledError`,this.encryptedValue=t.encryptedValue,this.contractAddress=t.contractAddress,this.account=t.account}},g=class extends e.r{constructor(t,n){super(e.i.DelegationSelfNotAllowed,t,n),this.name=`DelegationSelfNotAllowedError`}},_=class extends e.r{constructor(t,n){super(e.i.DelegationCooldown,t,n),this.name=`DelegationCooldownError`}},v=class extends e.r{constructor(t,n){super(e.i.DelegationNotFound,t,n),this.name=`DelegationNotFoundError`}},y=class extends e.r{constructor(t,n){super(e.i.DelegationExpired,t,n),this.name=`DelegationExpiredError`}},b=class extends e.r{constructor(t,n){super(e.i.DelegationExpiryUnchanged,t,n),this.name=`DelegationExpiryUnchangedError`}},x=class extends e.r{constructor(t,n){super(e.i.DelegationDelegateEqualsContract,t,n),this.name=`DelegationDelegateEqualsContractError`}},S=class extends e.r{constructor(t,n){super(e.i.DelegationContractIsSelf,t,n),this.name=`DelegationContractIsSelfError`}},C=class extends e.r{constructor(t,n){super(e.i.AclPaused,t,n),this.name=`AclPausedError`}},w=class extends e.r{constructor(t,n){super(e.i.DelegationExpirationTooSoon,t,n),this.name=`DelegationExpirationTooSoonError`}},T=class extends e.r{constructor(t,n){super(e.i.DelegationNotPropagated,t,n),this.name=`DelegationNotPropagatedError`}};const ee=[n.t,t.G,e.n,T,t.V,t.B,h,r._,t.U,t.J];function E(i,a,o={}){if(ee.some(e=>i instanceof e))return i;let s=i instanceof Error?i.message:a;if(i instanceof Error&&e.p(i.message))return new t.U(i.message,{cause:i});if(e._(i))return new t.J(`The permit's KMS context has been revoked on-chain, so the permit is no longer usable. The SDK evicts the permit and re-grants automatically; if this error surfaced, the retry failed the same way. The on-chain validity check is cached for up to 15 minutes, so a just-revoked context can keep failing across that window. Retry after the window; the SDK re-runs the recovery on the next decrypt, no manual cleanup is needed.`,{cause:i});if(i instanceof Error&&e.m(i.message))return o.isDelegated?new T(`Delegated decryption was denied by the on-chain ACL check. This is most commonly caused by the delegation not having propagated yet, or by the RPC node serving a stale block. Propagation usually completes within ~10 blocks (a few seconds) and the SDK retries across that window; seeing this means it did not sync in time. Retry shortly (and prefer a fresh, low-lag RPC endpoint). If it persists, the delegator may genuinely lack the on-chain ACL grant.`,{cause:i}):new h({encryptedValue:e.b(i.message)??``,contractAddress:o.contractAddress??``,account:o.account??``},{cause:i});if(e.d(i))return new r._(s,{cause:i,retryAfter:e.c(i)});let c=e.s(i);return c===void 0&&e.v(i)?new r._(s,{cause:i,retryAfter:e.c(i)}):c===400?new t.G(i instanceof Error?i.message:`No ciphertext for this account`,{cause:i}):o.isDelegated&&c===500?new T(`Delegated decryption failed with a server error. This is most commonly caused by the delegation not having propagated to the gateway yet. Cross-chain sync usually completes within ~10 blocks (a few seconds) and the SDK retries across that window; seeing this means it did not sync in time — retry shortly. If the error persists, the gateway or relayer may be experiencing an unrelated issue.`,{cause:i}):e.h(i)||c!==void 0?new e.n(s,c,{cause:i,retryAfter:e.c(i),retryable:e.g(i)||void 0}):new n.t(a,{cause:i})}function te(t,r){if(t instanceof e.r)return t;let i=e.s(t),a=e.g(t);return i!==void 0||e.h(t)?new e.n(t instanceof Error?t.message:r,i,{cause:t,retryAfter:e.c(t),retryable:a||void 0}):new n.r(r,{cause:t})}const D=[{type:`function`,name:`allow`,inputs:[{name:`handle`,type:`bytes32`,internalType:`bytes32`},{name:`account`,type:`address`,internalType:`address`}],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`allowForDecryption`,inputs:[{name:`handlesList`,type:`bytes32[]`,internalType:`bytes32[]`}],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`allowTransient`,inputs:[{name:`ciphertext`,type:`bytes32`,internalType:`bytes32`},{name:`account`,type:`address`,internalType:`address`}],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`cleanTransientStorage`,inputs:[],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`delegateForUserDecryption`,inputs:[{name:`delegate`,type:`address`,internalType:`address`},{name:`contractAddress`,type:`address`,internalType:`address`},{name:`expirationDate`,type:`uint64`,internalType:`uint64`}],outputs:[],stateMutability:`nonpayable`},{type:`function`,name:`getUserDecryptionDelegationExpirationDate`,inputs:[{name:`delegator`,type:`address`,internalType:`address`},{name:`delegate`,type:`address`,internalType:`address`},{name:`contractAddress`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`uint64`,internalType:`uint64`}],stateMutability:`view`},{type:`function`,name:`isAccountDenied`,inputs:[{name:`account`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`isAllowed`,inputs:[{name:`handle`,type:`bytes32`,internalType:`bytes32`},{name:`account`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`isAllowedForDecryption`,inputs:[{name:`handle`,type:`bytes32`,internalType:`bytes32`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`isHandleDelegatedForUserDecryption`,inputs:[{name:`delegator`,type:`address`,internalType:`address`},{name:`delegate`,type:`address`,internalType:`address`},{name:`contractAddress`,type:`address`,internalType:`address`},{name:`handle`,type:`bytes32`,internalType:`bytes32`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`multicall`,inputs:[{name:`data`,type:`bytes[]`,internalType:`bytes[]`}],outputs:[{name:`results`,type:`bytes[]`,internalType:`bytes[]`}],stateMutability:`payable`},{type:`function`,name:`persistAllowed`,inputs:[{name:`handle`,type:`bytes32`,internalType:`bytes32`},{name:`account`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`revokeDelegationForUserDecryption`,inputs:[{name:`delegate`,type:`address`,internalType:`address`},{name:`contractAddress`,type:`address`,internalType:`address`}],outputs:[],stateMutability:`nonpayable`}];function O(e,t,n,r){return{address:e,abi:D,functionName:`delegateForUserDecryption`,args:[t,n,r]}}function k(e,t,n){return{address:e,abi:D,functionName:`revokeDelegationForUserDecryption`,args:[t,n]}}function A(e,t,n,r){return{address:e,abi:D,functionName:`getUserDecryptionDelegationExpirationDate`,args:[t,n,r]}}function ne(e,t,n,r,i){return{address:e,abi:D,functionName:`isHandleDelegatedForUserDecryption`,args:[t,n,r,i]}}const j=2n**64n-1n;function re(e){return o.i(e.signer,e.provider,e)}var M=class{#e;#t;#n;#r;#i;#a;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.cachingService,this.#r=e.credentialService,this.#i=e.logger,this.#a=e.emitEvent}#o(e){return t.R(this.#r,e)}#s(e,n){throw this.#a({type:t.M.PermitError,operation:e,error:n instanceof Error?n:Error(String(n))}),n}async grantPermit(e){if(e.length===0)return;let t;try{t=this.#o(`grantPermit`),await r.o(`grantPermit`,this.#e,this.#t)}catch(e){this.#s(`grantPermit`,e)}await t.grantPermit(e)}async grantDelegationPermit(e,t){if(t.length===0)return;let n;try{n=this.#o(`grantDelegationPermit`),await r.o(`grantDelegationPermit`,this.#e,this.#t)}catch(e){this.#s(`grantDelegationPermit`,e)}await n.grantPermit(t,e)}async hasPermit(e){return this.#r?this.#r.hasPermit(e):!1}async hasDelegationPermit(e,t){return this.#r?this.#r.hasPermit(t,e):!1}async warmTransportKeyPair(){let e=this.#r;if(!e)return;let t=this.#e?.walletAccount.getSnapshot();t&&await e.warmTransportKeyPair(t.address)}async registerPermit(e,t){let n;try{n=this.#o(`registerPermit`)}catch(e){this.#s(`registerPermit`,e)}await n.registerPermit(e,t),await this.#c(e.signerAddress)}async revokePermits(e){let t=this.#o(`revokePermits`),n=(0,f.getAddress)((await r.a(`revokePermits`,this.#e,this.#t)).address);try{await t.revokePermits(e)}finally{await this.#c(n)}}async clear(){let e=this.#o(`clear`),t=(0,f.getAddress)((await r.a(`clear`,this.#e,this.#t)).address);try{await e.clearCredentials()}finally{await this.#c(t)}}async#c(e){await t.j(`clear decrypt cache`,()=>this.#n.clearForRequester(e),this.#i)}async revokeTransportKeyPair(e){await this.#o(`revokeTransportKeyPair`).revokeTransportKeyPair(e)}async warmTransportKeyPairScope(e){await this.#o(`warmTransportKeyPairScope`).warmTransportKeyPairScope(e)}},N=class{#e;#t;#n;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.delegationService}#r(e){return t.R(this.#e,e)}async delegateDecryption({contractAddress:e,delegateAddress:t,expirationDate:n}){let i=this.#r(`delegateDecryption`),a=await r.a(`delegateDecryption`,this.#e,this.#t);return this.#n.delegateDecryption(i,{contractAddress:e,delegateAddress:t,delegatorAddress:a.address,expirationDate:n})}async revokeDelegation({contractAddress:e,delegateAddress:t}){let n=this.#r(`revokeDelegation`),i=await r.a(`revokeDelegation`,this.#e,this.#t);return this.#n.revokeDelegation(n,{contractAddress:e,delegateAddress:t,delegatorAddress:i.address})}async isActive(e){return this.#n.isDelegated(e)}async getExpiry(e){return this.#n.getDelegationExpiry(e)}async getStatus(e){return this.#n.getStatus(e)}},P=class{#e;#t;#n;#r;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.router,this.#r=e.decryptionService}#i(e){return t.R(this.#r,e)}async decryptValues(e,t){let n=this.#i(`decryptValues`),i=await r.a(`decryptValues`,this.#e,this.#t);return n.decryptValues(e,i.address,t)}async delegatedDecryptValues(e,t,n=t,i){let a=this.#i(`delegatedDecryptValues`),o=await r.a(`delegatedDecryptValues`,this.#e,this.#t);return a.delegatedDecryptValues(e,t,o.address,n,i)}async decryptPublicValues(e,t){if(e.length===0)return{clearValues:{},decryptionProof:`0x`,abiEncodedClearValues:`0x`};try{let n=await this.#n.relayer.decryptPublicValuesWithSignatures({encryptedValues:e,options:t}),r={};return n.checkSignaturesArgs.handlesList.forEach((e,t)=>{d.r(n.clearValues[t],`result.clearValues[${t}]`),r[e]=n.clearValues[t].value}),{clearValues:r,abiEncodedClearValues:n.checkSignaturesArgs.abiEncodedCleartexts,decryptionProof:n.checkSignaturesArgs.decryptionProof}}catch(e){throw E(e,`Public decryption failed`)}}async delegatedBatchDecryptValues({encryptedInputs:e,delegatorAddress:t,accountAddress:n=t,maxConcurrency:i,waitForPropagation:a}){let o=this.#i(`delegatedBatchDecryptValues`),s=await r.a(`delegatedBatchDecryptValues`,this.#e,this.#t);return o.delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:s.address,accountAddress:n,maxConcurrency:i,waitForPropagation:a})}},F=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}prepare(e,t){return this.#e.prepare(e,t)}preparePermit(e){return this.#t.preparePermit(e)}},I=class{async get(e){return(await chrome.storage.session.get(e))[e]??null}async set(e,t){await chrome.storage.session.set({[e]:t})}async delete(e){await chrome.storage.session.remove(e)}};const ie=new I,ae=p.z.union([p.z.bigint(),p.z.boolean(),s.n]),oe=p.z.array(p.z.string());var se=class{#e;#t;#n=`zama:decrypt`;#r=`${this.#n}:keys`;#i=Promise.resolve();constructor(e,t){this.#e=e,this.#t=t}async get(e,t,n){try{let r=this.#c(e,t,n),i=await this.#e.get(r);if(i===null)return null;let a=ae.safeParse(i);return a.success?a.data:(await this.delete(e,t,n),null)}catch(e){return this.#t.warn(`CachingService.get failed`,{error:e}),null}}async set(e,t,n,r){try{let i=this.#c(e,t,n);await this.#e.set(i,r),this.#i=this.#i.then(()=>this.#u(i).catch(e=>{this.#t.warn(`CachingService index write failed`,{error:e})})),await this.#i}catch(e){this.#t.warn(`CachingService.set failed`,{error:e})}}async delete(e,t,n){let r=this.#c(e,t,n);this.#i=this.#i.then(()=>this.#a(r).catch(e=>{this.#t.warn(`CachingService.delete failed`,{error:e})})),await this.#i}async clearForRequester(e){this.#i=this.#i.then(()=>this.#o(e).catch(e=>{this.#t.warn(`CachingService.clearForRequester failed`,{error:e})})),await this.#i}async clearAll(){this.#i=this.#i.then(()=>this.#s().catch(e=>{this.#t.warn(`CachingService.clearAll failed`,{error:e})})),await this.#i}async#a(e){await this.#e.delete(e).catch(()=>{});let t=await this.#l(),n=t.filter(t=>t!==e);n.length!==t.length&&await this.#e.set(this.#r,n)}async#o(e){let t=(0,f.getAddress)(e),n=`${this.#n}:${t}:`,r=await this.#l(),i=[],a=[];for(let e of r)e.startsWith(n)?i.push(e):a.push(e);await Promise.all(i.map(e=>this.#e.delete(e).catch(()=>{}))),await this.#e.set(this.#r,a)}async#s(){let e=await this.#l();await Promise.all(e.map(e=>this.#e.delete(e).catch(()=>{}))),await this.#e.delete(this.#r)}#c(e,t,n){return`${this.#n}:${(0,f.getAddress)(e)}:${(0,f.getAddress)(t)}:${n.toLowerCase()}`}async#l(){let e=await this.#e.get(this.#r);if(e===null)return[];let t=oe.safeParse(e);return t.success?t.data:(await this.#e.delete(this.#r).catch(()=>{}),[])}async#u(e){let t=await this.#l();t.includes(e)||(t.push(e),await this.#e.set(this.#r,t))}};function ce(e,t){let r=le(e,t);if(!r)throw new n.t(`No permit covers contract ${t} after allow()`);return{privateKey:e.keypair.privateKey,publicKey:e.keypair.publicKey,serializedPermit:r.serializedPermit}}function le(e,t){let n=s.t(t);return e.permissions.find(e=>e.contractAddresses.includes(n))}const ue=e=>new Promise(t=>setTimeout(t,e));var de=class{#e;#t;#n;#r;#i;constructor({cache:e,credentialService:t,delegationService:n,router:r,emitEvent:i}){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i}async decryptValues(e,t,n){let r=(0,f.getAddress)(t);return this.#s(e,{requesterAddress:r,errorMessage:`Failed to decrypt encrypted values`},n)}async delegatedDecryptValues(e,t,n,r,i){let a=(0,f.getAddress)(t),o=(0,f.getAddress)(n),s={spent:!1};return this.#a(i?.waitForPropagation??!0,()=>this.#s(e,{requesterAddress:(0,f.getAddress)(r),delegator:a,validate:e=>this.#m(e,{delegatorAddress:a,delegateAddress:o}),errorMessage:`Failed to decrypt delegated encrypted values`},void 0,s))}async#a(e,t){let n;for(let r=0;r<16;r++)try{return await t()}catch(t){if(n=t,!(r<15&&e&&t instanceof T))throw t;await ue(2e3)}throw n}async delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:n,accountAddress:i,maxConcurrency:a=5,waitForPropagation:o=!0}){let s=e.map(e=>({encryptedValue:e.encryptedValue,contractAddress:(0,f.getAddress)(e.contractAddress)}));if(s.length===0)return{items:s};let c=(0,f.getAddress)(i);try{let e=await this.delegatedDecryptValues(s.map(({encryptedValue:e,contractAddress:t})=>({encryptedValue:e,contractAddress:t})),t,n,c,{waitForPropagation:o});for(let t of s)this.#d(t,e);return{items:s}}catch(e){if(r.u(e))throw e;if(s.length===1){let[n=this.#p()]=s;return n.error=this.#f(e,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:n.contractAddress,account:(0,f.getAddress)(t)}),{items:s}}}let l=!1,u;if(await r.r(s.map(e=>async()=>{if(!l)try{let r=await this.delegatedDecryptValues([{encryptedValue:e.encryptedValue,contractAddress:e.contractAddress}],t,n,c,{waitForPropagation:!1});this.#d(e,r)}catch(n){if(r.u(n)){l=!0,u??=n;return}e.error=this.#f(n,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:e.contractAddress,account:(0,f.getAddress)(t)})}}),a),u!==void 0)throw u;return{items:s}}async#o(t,n,r,i){let a=ce(t,n),o;try{o=await this.#r.relayer.parseTransportKeyPair({publicKey:a.publicKey,privateKey:a.privateKey,tkmsVersion:t.keypair.tkmsVersion})}catch(t){throw t instanceof Error&&e.p(t.message)&&await this.#t.evictTransportKeyPair(),t}let s=await this.#r.relayer.parseSignedDecryptionPermit({transportKeyPair:o,serializedPermit:a.serializedPermit});return this.#r.relayer.decryptValues({transportKeyPair:o,signedPermit:s,encryptedValues:r,contractAddress:n,options:i})}async#s(n,i,a,o={spent:!1}){if(n.length===0)return{};let s=n.map(e=>({encryptedValue:e.encryptedValue,contractAddress:(0,f.getAddress)(e.contractAddress)})),c={},l=[];for(let e of s)r.l(e.encryptedValue)?c[e.encryptedValue]=0n:l.push(e);if(l.length===0)return c;let u=Array.from(new Set(s.map(e=>e.contractAddress))),d=Array.from(new Set(l.map(e=>e.contractAddress)));if(i.validate)try{await i.validate(d)}catch(t){throw e.v(t)?this.#u(t,`the delegation pre-check`):t}let p=[];for(let e of l){let t=await this.#e.get(i.requesterAddress,e.contractAddress,e.encryptedValue);t===null?p.push(e):c[e.encryptedValue]=t}if(p.length===0)return c;let m=await this.#t.grantPermit(u,i.delegator),h=new Map;for(let e of p){let t=h.get(e.contractAddress);t?t.push(e.encryptedValue):h.set(e.contractAddress,[e.encryptedValue])}let g=[];for(let[e,t]of h)for(let n of r.c(t))g.push({contractAddress:e,encryptedValues:n});let _=Date.now(),v=p.map(e=>e.encryptedValue);try{this.#i({type:t.M.DecryptStart,encryptedValues:v});try{await this.#c(i,m,g,c,a)}catch(e){if(!(e instanceof t.J)||o.spent)throw e;let n=m.permissions.map(e=>e.serializedPermit.signature);o.spent=!0;try{m=await this.#t.recoverPermits(u,i.delegator,n)}catch(e){throw e instanceof t.B?new t.J(`The permit's KMS context has been revoked on-chain and the automatic re-grant failed, so the decrypt cannot proceed. Establish a new permit for this scope and retry.`,{cause:e}):e}await this.#c(i,m,g.filter(({encryptedValues:e})=>e.some(e=>c[e]===void 0)),c,a)}let e={};for(let t of v){let n=c[t];n!==void 0&&(e[t]=n)}return this.#i({type:t.M.DecryptEnd,durationMs:Date.now()-_,encryptedValues:v,result:e}),c}catch(n){let r=n instanceof e.r&&n.cause instanceof Error?n.cause:n;throw this.#i({type:t.M.DecryptError,error:e.S(r),durationMs:Date.now()-_,encryptedValues:v}),E(n,i.errorMessage,{isDelegated:i.delegator!==void 0})}}async#c(e,n,i,a,o){let s=(await r.r(i.map(({contractAddress:t,encryptedValues:r})=>async()=>{try{await this.#l(e,n,t,r,a,o);return}catch(e){return e}}),5)).filter(e=>e!==void 0);if(s.length>0)throw s.find(e=>e instanceof t.J)??s[0]}async#l(e,t,r,i,a,o){let s;try{s=await this.#o(t,r,i,o)}catch(t){throw E(t,e.errorMessage,{isDelegated:e.delegator!==void 0,contractAddress:r,account:e.delegator??e.requesterAddress})}for(let t=0;t<i.length;t++){let n=i[t],o=s[t]?.value;n!==void 0&&o!==void 0&&(a[n]=o,await this.#e.set(e.requesterAddress,r,n,o))}let c=i.filter(e=>a[e]===void 0);if(c.length>0)throw new n.t(`${e.errorMessage}: relayer returned no clear value for ${c.length} of ${i.length} handle(s) on ${r}`,{cause:AggregateError(c.map(e=>new n.t(`No clear value for handle ${e} on ${r}`)),`${c.length} handle(s) missing a clear value on ${r}`)})}#u(t,n){return new r._(`RPC provider rate-limited ${n}; retry with backoff.`,{cause:t,retryAfter:e.c(t)})}#d(e,t){let r=t[e.encryptedValue];if(r===void 0){e.error=new n.t(`Batch delegated decryption returned no value for encrypted value ${e.encryptedValue} on contract ${e.contractAddress}`);return}e.value=r}#f(t,n,r){return t instanceof e.r?t:E(t,n,r)}#p(){throw new n.t(`Batch delegated decryption invariant failed: missing item`)}async#m(e,{delegatorAddress:t,delegateAddress:n}){let r=await this.#n.findInactiveDelegations(e,t,n);if(r.size!==0)for(let e of r.values())throw e}};const L={AlreadyDelegatedOrRevokedInSameBlock:e=>new _(`Only one delegate/revoke per (delegator, delegate, contract) per block. Wait for the next block before retrying.`,{cause:e}),SenderCannotBeContractAddress:e=>new S(`The contract address cannot be the caller address.`,{cause:e}),EnforcedPause:e=>new C(`The ACL contract is paused. Delegation operations are temporarily disabled.`,{cause:e}),SenderCannotBeDelegate:e=>new g(`Cannot delegate to yourself (delegate === msg.sender).`,{cause:e}),DelegateCannotBeContractAddress:e=>new x(`Delegate address cannot be the same as the contract address.`,{cause:e}),ExpirationDateBeforeOneHour:e=>new w(`Expiration date must be at least 1 hour in the future.`,{cause:e}),ExpirationDateAlreadySetToSameValue:e=>new b(`The new expiration date is the same as the current one.`,{cause:e}),NotDelegatedYet:e=>new v(`Cannot revoke: no active delegation exists.`,{cause:e})};function R(e){return Object.hasOwn(L,e)}function z(e,t){let n=i.T(e);if(n&&R(n))return L[n](t);let r=e instanceof Error?e.message:String(e);for(let[e,n]of Object.entries(L))if(r.includes(e))return n(t);return null}var B=class{#e;#t;#n;#r;constructor({provider:e,router:t,emitEvent:n=()=>{},logger:r}){this.#t=e,this.#e=t,this.#r=r,this.#n=n}async delegateDecryption(e,{contractAddress:t,delegateAddress:n,delegatorAddress:r,expirationDate:i}){if(i&&i.getTime()<Date.now()+36e5)throw new w(`Expiration date must be at least 1 hour in the future`);let a=(0,f.getAddress)(t),o=(0,f.getAddress)(n),s=(0,f.getAddress)(r);if(o===s)throw new g(`Cannot delegate to yourself (delegate === msg.sender).`);if(o===a)throw new x(`Delegate address cannot be the same as the contract address (${a}).`);let c=this.#e.relayer.chain.aclContractAddress,l=i?BigInt(Math.floor(i.getTime()/1e3)):j,u;try{u=await this.getDelegationExpiry({contractAddress:a,delegatorAddress:s,delegateAddress:o})}catch(e){this.#r.warn(`delegateDecryption: pre-flight expiry check failed`,{error:e}),u=-1n}if(u===l)throw new b(`The new expiration date (${l}) is the same as the current one. No on-chain change needed.`);return this.#i({operation:`delegateDecryption`,signer:e,contractAddress:a,config:O(c,o,a,l)})}async revokeDelegation(e,{contractAddress:t,delegateAddress:n,delegatorAddress:r}){let i=(0,f.getAddress)(t),a=(0,f.getAddress)(n),o=(0,f.getAddress)(r),s=this.#e.relayer.chain.aclContractAddress,c;try{c=await this.getDelegationExpiry({contractAddress:i,delegatorAddress:o,delegateAddress:a})}catch(e){this.#r.warn(`revokeDelegation: pre-flight expiry check failed`,{error:e}),c=1n}if(c===0n)throw new v(`No active delegation found for delegate ${a} on contract ${i}.`);return this.#i({operation:`revokeDelegation`,signer:e,contractAddress:i,config:k(s,a,i)})}async isDelegated(e){return(await this.getStatus(e)).isActive}async getStatus(e){let t=await this.getDelegationExpiry(e);return t===0n?{isActive:!1,expiryTimestamp:t}:t===j?{isActive:!0,expiryTimestamp:t}:{isActive:t>await this.#t.getBlockTimestamp(),expiryTimestamp:t}}async getDelegationExpiry({contractAddress:e,delegatorAddress:t,delegateAddress:n}){let r=this.#e.relayer.chain.aclContractAddress;return this.#t.readContract(A(r,(0,f.getAddress)(t),(0,f.getAddress)(n),(0,f.getAddress)(e)))}async#i({operation:e,signer:t,contractAddress:n,config:i}){try{return await r.n({operation:e,signer:t,provider:this.#t,config:i,emit:e=>this.#n(e,n),logger:this.#r})}catch(e){throw this.#a(e),e}}#a(e){if(!(e instanceof t.z))return;let n=z(e.cause??e,e);if(n)throw n}async findInactiveDelegations(e,t,n){let r=new Map;return await Promise.all(e.map(async e=>{try{await this.assertDelegationActive(e,t,n)}catch(t){if(t instanceof v||t instanceof y){let n=(0,f.getAddress)(e);r.set(n,t);return}throw t}})),r}async assertDelegationActive(e,t,n){let r=(0,f.getAddress)(e),i=(0,f.getAddress)(t),a=(0,f.getAddress)(n),{isActive:o,expiryTimestamp:s}=await this.getStatus({contractAddress:r,delegatorAddress:i,delegateAddress:a});if(!o)throw s===0n?new v(`No active delegation from ${i} to ${a} for ${r}`):new y(`Delegation from ${i} to ${a} for ${r} has expired`)}},V=class{#e;#t;constructor({router:e,emitEvent:t}){this.#e=e,this.#t=t}async encryptValues(n,r){let i=Date.now(),a=(0,f.getAddress)(n.contractAddress);try{this.#t({type:t.M.EncryptStart},a);let e=await this.#e.relayer.encryptValues({...n,options:r});return this.#t({type:t.M.EncryptEnd,durationMs:Date.now()-i},a),e}catch(n){throw this.#t({type:t.M.EncryptError,error:e.S(n),durationMs:Date.now()-i},a),te(n,`Encryption failed`)}}},fe=class{#e;#t;#n;#r;#i;#a=new Set;#o;constructor(e){this.#e=e.signer,this.#t=e.router,this.#n=e.cachingService,this.#r=e.credentialService,this.#i=e.logger,this.#e&&(this.#o=this.#e.walletAccount.subscribe(e=>{this.#s(e).catch(e=>{this.#i.warn(`wallet account handler failed`,{error:e})})}))}onWalletAccountChange(e){return this.#a.add(e),()=>{this.#a.delete(e)}}dispose(){this.#o?.(),this.#o=void 0,this.#a.clear()}async#s(e){let n=e.previous,r=e.next,i=r?.chainId;i!==void 0&&await t.j(`switch relayer chain`,()=>this.#t.switchChain(i),this.#i);let a=this.#r;a&&await t.j(`credential wallet account change`,()=>a.handleWalletAccountChange(n,r),this.#i),n&&await t.j(`clear decrypt cache`,()=>this.#n.clearForRequester(n.address),this.#i),await Promise.all(Array.from(this.#a,n=>t.j(`wallet account listener`,()=>n(e),this.#i)))}};const H=p.z.object({kind:p.z.literal(`ConfidentialTransfer`),from:s.n,token:s.n,to:s.n,amount:p.z.bigint()}),U=p.z.object({kind:p.z.literal(`ConfidentialTransferFrom`),from:s.n,token:s.n,owner:s.n,to:s.n,amount:p.z.bigint()}),W=p.z.object({kind:p.z.literal(`SetOperator`),from:s.n,token:s.n,operator:s.n,until:s.s}),G=p.z.object({kind:p.z.literal(`Unwrap`),from:s.n,token:s.n,to:s.n,amount:p.z.bigint()}),K=p.z.object({kind:p.z.literal(`UnwrapAll`),from:s.n,token:s.n,to:s.n}),q=p.z.object({kind:p.z.literal(`FinalizeUnwrap`),from:s.n,wrapper:s.n,unwrapRequestIdOrAmount:s.r}),J=p.z.object({kind:p.z.literal(`ApproveUnderlying`),from:s.n,underlying:s.n,spender:s.n,amount:p.z.bigint()}),Y=p.z.object({kind:p.z.literal(`Wrap`),from:s.n,wrapper:s.n,to:s.n,amount:p.z.bigint()}),pe=s.r.check(p.z.refine(e=>e===`0x`||(0,f.size)(e)===20,`TransferAndCall.recipientData must be "0x" (self-shield to the sender) or a raw 20-byte address, not a 32-byte ABI-encoded value the wrapper would truncate to a garbage address`)),X=p.z.object({kind:p.z.literal(`TransferAndCall`),from:s.n,underlying:s.n,wrapper:s.n,amount:p.z.bigint(),recipientData:p.z.optional(pe)}),Z=p.z.object({kind:p.z.literal(`DelegateDecryption`),from:s.n,contractAddress:s.n,delegateAddress:s.n,expirationDate:p.z.optional(p.z.date())}),Q=p.z.object({kind:p.z.literal(`RevokeDelegation`),from:s.n,contractAddress:s.n,delegateAddress:s.n});p.z.discriminatedUnion(`kind`,[H,U,W,G,K,q,J,Y,X,Z,Q]);const me=p.z.strictObject({maxFeePerGas:p.z.bigint(),maxPriorityFeePerGas:p.z.bigint()}),$=p.z.object({nonce:p.z.optional(p.z.int().check(p.z.nonnegative())),gasLimit:p.z.optional(p.z.bigint()),fees:p.z.optional(me)}),he=p.z.object({address:s.n,abi:p.z.array(p.z.unknown()),functionName:p.z.string(),args:p.z.array(p.z.unknown()),value:p.z.optional(p.z.bigint()),gas:p.z.optional(p.z.bigint())}),ge=p.z.extend($,{from:s.n,calldata:he});var _e=class{#e;#t;#n;constructor(e){this.#e=e.provider,this.#t=e.router,this.#n=e.encryption}async prepare(t,n){n&&=c.t($,n);let r=await this.#e.getChainId(),i=this.#t.chain.id;if(r!==i)throw new e.t(`Offline.prepare: provider is on chain ${r} but the SDK is configured for chain ${i}. The prepared transaction's contract addresses and encrypted inputs are bound to chain ${i} — point the provider at the same chain.`);let a=c.t(ge,{calldata:await this.#r(t),from:t.from,nonce:n?.nonce,gasLimit:n?.gasLimit,fees:n?.fees}),o=await this.#e.prepareTransaction(a);return{kind:t.kind,unsignedTx:o,from:a.from}}async#r(t){switch(t.kind){case`ConfidentialTransfer`:return this.#i(t);case`ConfidentialTransferFrom`:return this.#a(t);case`SetOperator`:return this.#o(t);case`Unwrap`:return this.#s(t);case`UnwrapAll`:return this.#c(t);case`FinalizeUnwrap`:return this.#l(t);case`ApproveUnderlying`:return this.#u(t);case`Wrap`:return this.#d(t);case`TransferAndCall`:return this.#f(t);case`DelegateDecryption`:return this.#p(t);case`RevokeDelegation`:return this.#m(t);default:throw new e.t(`OfflineService.prepare: unsupported transaction kind '${t.kind}'.`)}}async#i(e){e=c.t(H,e);let{encryptedValues:r,inputProof:i}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from}),a=r[0];if(!a)throw new n.r(`Encryption returned no handles for ConfidentialTransfer`);return t.v(e.token,e.to,a,i)}async#a(e){e=c.t(U,e);let{encryptedValues:r,inputProof:i}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from}),a=r[0];if(!a)throw new n.r(`Encryption returned no handles for ConfidentialTransferFrom`);return t.b(e.token,e.owner,e.to,a,i)}#o(e){return e=c.t(W,e),t.T(e.token,e.operator,e.until)}async#s(e){e=c.t(G,e);let{encryptedValues:r,inputProof:i}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from}),a=r[0];if(!a)throw new n.r(`Encryption returned no handles for Unwrap`);return t.D(e.token,e.from,e.to,a,i)}async#c(e){e=c.t(K,e);let n=await this.#e.readContract(t.h(e.token,e.from));return t.O(e.token,e.from,e.to,n)}async#l(e){e=c.t(q,e);let n=await this.#t.relayer.decryptPublicValuesWithSignatures({encryptedValues:[e.unwrapRequestIdOrAmount]}).catch(e=>{throw E(e,`Public decryption failed during FinalizeUnwrap`)}),r=n.clearValues[0]?.value;return d.t(r,`FinalizeUnwrap: decryptPublicValuesWithSignatures(handle).clearValue`),t.x(e.wrapper,e.unwrapRequestIdOrAmount,r,n.checkSignaturesArgs.decryptionProof)}#u(e){return e=c.t(J,e),t.l(e.underlying,e.spender,e.amount)}#d(e){return e=c.t(Y,e),t.A(e.wrapper,e.to,e.amount)}#f(e){return e=c.t(X,e),i.C(e.underlying,e.wrapper,e.amount,e.recipientData)}#p(e){if(e=c.t(Z,e),e.expirationDate&&e.expirationDate.getTime()<Date.now()+36e5)throw new w(`Expiration date must be at least 1 hour in the future`);if(e.delegateAddress===e.from)throw new g(`Cannot delegate to yourself (delegate === msg.sender).`);if(e.delegateAddress===e.contractAddress)throw new x(`Delegate address cannot be the same as the contract address (${e.contractAddress}).`);let t=e.expirationDate?BigInt(Math.floor(e.expirationDate.getTime()/1e3)):j;return O(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress,t)}#m(e){return e=c.t(Q,e),k(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress)}};function ve(t){if(!(!Object.hasOwn(t,`transportKeyPairDerivationSecret`)||t.transportKeyPairDerivationSecret!==void 0))throw new e.t(`transportKeyPairDerivationSecret was passed as undefined, which usually means the environment variable it reads is unset (e.g. process.env.ZAMA_DERIVATION_SECRET). Supply the secret, or omit the option entirely to persist transport key pairs in cleartext on purpose.`)}function ye(t){if(t===void 0)return;let{importScripts:n}=globalThis;if(!(typeof window>`u`&&typeof document>`u`&&typeof n!=`function`))throw new e.t(`transportKeyPairDerivationSecret is supported in headless environments only (CLI tools, servers, agents). Remove the option: an environment with a platform keystore, or one that ships a bundle, must delegate at-rest security of the transport key pair to the storage backend.`)}function be(e){if(e===void 0)return;let t=c.t(o.c,e);return new o.l(typeof t==`string`?t:new Uint8Array(t))}var xe=class{#e;provider;signer;storage;registry;permits;delegations;decryption;offline;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;constructor(e,t={}){ve(t),ye(t.transportKeyPairDerivationSecret);let n=be(t.transportKeyPairDerivationSecret);this.#e=e.router,this.provider=e.provider,this.signer=e.signer,this.storage=e.storage,this.#r=e.onEvent??function(){},this.#i=e.logger,this.#a=new se(e.storage,this.#i),this.#u=new B({provider:this.provider,router:e.router,emitEvent:this.emitEvent.bind(this),logger:this.#i});let r={};for(let t of e.chains)t.registryAddress&&(r[t.id]=t.registryAddress);this.registry=new o.o({provider:this.provider,registryAddresses:r,registryTTL:e.registryTTL}),this.#n=r,this.#t=e.registryTTL,this.#l=new o.s({router:e.router,signer:e.signer,transportKeyPairTTL:e.transportKeyPairTTL,permitTTL:e.permitTTL,scope:e.transportKeyPairScope,derivationSecret:n,storage:this.storage,permitStorage:e.permitStorage,logger:this.#i,emitEvent:this.emitEvent.bind(this)}),e.signer&&(this.#c=new de({cache:this.#a,credentialService:this.#l,delegationService:this.#u,router:e.router,emitEvent:this.emitEvent.bind(this)})),this.#s=new V({router:e.router,emitEvent:this.emitEvent.bind(this)}),this.#o=new fe({signer:e.signer,router:e.router,cachingService:this.#a,credentialService:this.#l,logger:this.#i}),this.#d=new _e({provider:this.provider,router:e.router,encryption:this.#s,emitEvent:(e,t)=>this.emitEvent(e,t)}),this.permits=new M({signer:this.signer,provider:this.provider,cachingService:this.#a,credentialService:this.#l,logger:this.#i,emitEvent:this.emitEvent.bind(this)}),this.delegations=new N({signer:this.signer,provider:this.provider,delegationService:this.#u}),this.decryption=new P({signer:this.signer,provider:this.provider,router:e.router,decryptionService:this.#c}),this.offline=new F(this.#d,this.#l)}onWalletAccountChange(e){return this.#o.onWalletAccountChange(e)}get logger(){return this.#i}get relayer(){return this.#e.relayer}emitEvent(e,t){try{this.#r({...e,tokenAddress:t,timestamp:Date.now()})}catch(t){this.#i.warn(`${e.type} event listener silently failed`,{error:t})}}createWrappersRegistry(e){return new o.o({provider:this.provider,registryAddresses:{...this.#n,...e},registryTTL:this.#t})}async encrypt(e,t){return this.#s.encryptValues(e,t)}createToken(e){return new r.t(this,e)}createWrappedToken(e){return new i.t(this,e)}dispose(){this.#o.dispose(),this.#e.dispose()}terminate(){this.dispose(),this.signer?.dispose?.()}[Symbol.dispose](){this.terminate()}};exports.ACL_TOPICS=i.n,exports.AclPausedError=C,exports.AclTopics=i.r,exports.BalanceCheckUnavailableError=r.d,exports.BaseSigner=o.t,exports.ChainMismatchError=r.g,exports.ChromeSessionStorage=I,exports.ConfigurationError=e.t,exports.Decryption=P,exports.DecryptionFailedError=n.t,exports.DefaultRegistryAddresses=o.a,exports.DelegationContractIsSelfError=S,exports.DelegationCooldownError=_,exports.DelegationDelegateEqualsContractError=x,exports.DelegationExpirationTooSoonError=w,exports.DelegationExpiredError=y,exports.DelegationExpiryUnchangedError=b,exports.DelegationNotFoundError=v,exports.DelegationNotPropagatedError=T,exports.DelegationSelfNotAllowedError=g,exports.Delegations=N,exports.ERC1363_INTERFACE_ID=t.t,exports.ERC20ReadFailedError=r.f,exports.ERC7984_INTERFACE_ID=t.n,exports.ERC7984_WRAPPER_INTERFACE_ID=t.r,exports.EncryptOffloadUnavailableError=n.n,exports.EncryptionFailedError=n.r,exports.IndexedDBStorage=o.f,exports.InsufficientAllowanceError=r.p,exports.InsufficientConfidentialBalanceError=r.m,exports.InsufficientERC20BalanceError=r.h,exports.InvalidTransportKeyPairError=t.U,exports.KeyWrappingError=t.W,exports.MemoryStorage=o.u,exports.MutableWalletAccountStore=o.n,exports.NoCiphertextError=t.G,exports.NotEntitledError=h,exports.Offline=F,exports.Permits=M,exports.PreparedPermitChainMismatchError=t.K,exports.PreparedPermitExpiredError=t.q,exports.RelayerRequestFailedError=e.n,exports.RevokedKmsContextError=t.J,exports.RpcRateLimitError=r._,exports.SignerNotConfiguredError=t.P,exports.SignerRequiredError=t.F,exports.SigningFailedError=t.B,exports.SigningRejectedError=t.V,exports.TOKEN_TOPICS=i.i,exports.Token=r.t,exports.Topics=i.a,exports.TransactionRevertedError=t.z,exports.TransportKeyPairChangedError=t.Y,exports.TransportKeyPairExpiredError=t.X,exports.UnshieldAlreadyFinalizedError=i.w,exports.WalletAccountNotReadyError=t.I,exports.WalletNotConnectedError=t.L,exports.WrappedToken=i.t,exports.WrappersRegistry=o.o,exports.ZERO_ENCRYPTED_VALUE=r.s,exports.ZamaError=e.r,exports.ZamaErrorCode=e.i,exports.ZamaSDK=xe,exports.ZamaSDKEvents=t.M,exports.allowanceContract=t.c,exports.anvil=u.t,exports.approveContract=t.l,exports.balanceOfContract=t.u,exports.bscTestnet=u.n,exports.chains=u.r,exports.chromeSessionStorage=ie,exports.cleartext=a.t,exports.confidentialBalanceOfContract=t.h,exports.confidentialTotalSupplyContract=t.g,exports.confidentialTransferContract=t.v,exports.confidentialTransferFromContract=t.b,exports.createConfig=re,exports.createWalletAccountStore=o.r,exports.decimalsContract=t.d,exports.decodeAclEvent=i.o,exports.decodeAclEvents=i.s,exports.decodeConfidentialTransfer=i.c,exports.decodeDelegatedForUserDecryption=i.l,exports.decodeOnChainEvent=i.u,exports.decodeOnChainEvents=i.d,exports.decodeRevokedDelegationForUserDecryption=i.f,exports.decodeUnwrapFinalized=i.p,exports.decodeUnwrapRequested=i.m,exports.decodeWrap=i.h,exports.delegateForUserDecryptionContract=O,exports.finalizeUnwrapContract=t.x,exports.findDelegatedForUserDecryption=i.g,exports.findRevokedDelegationForUserDecryption=i._,exports.findUnwrapRequested=i.v,exports.findWrap=i.y,exports.getConfidentialTokenAddressContract=l.t,exports.getDelegationExpiryContract=A,exports.getTokenAddressContract=l.n,exports.getTokenPairContract=l.r,exports.getTokenPairsContract=l.i,exports.getTokenPairsLengthContract=l.a,exports.getTokenPairsSliceContract=l.o,exports.hardhat=u.i,exports.hoodi=u.a,exports.indexedDBStorage=o.p,exports.inferredTotalSupplyContract=t.S,exports.ingenTestnet=u.o,exports.isConfidentialTokenContract=t.i,exports.isConfidentialTokenValidContract=l.s,exports.isConfidentialWrapperContract=t.a,exports.isEncryptedValueZero=r.l,exports.isHandleDelegatedContract=ne,exports.isOperatorContract=t.C,exports.isRetryable=e.a,exports.mainnet=u.s,exports.matchZamaError=m,exports.memoryStorage=o.d,exports.nameContract=t.p,exports.polygon=u.c,exports.polygonAmoy=u.l,exports.rateContract=t.w,exports.retryAfterSeconds=e.o,exports.revokeDelegationContract=k,exports.sepolia=u.u,exports.setOperatorContract=t.T,exports.supportsInterfaceContract=t.s,exports.symbolContract=t.m,exports.transferAndCallContract=i.C,exports.underlyingContract=t.E,exports.unwrapContract=t.D,exports.unwrapFromBalanceContract=t.O,exports.unwrapRequesterContract=t.k,exports.wrapContract=t.A,exports.zenithTrexTestnet=u.d;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/node/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../fhevm-relayer.cjs"),t=require("../cleartext.cjs"),n=require("../chains.cjs");let r=require("node:async_hooks");function i(t){return{type:`node`,createRelayer:(n,r)=>new e.t({chain:n,options:t,logger:r})}}var a=class{#e=new r.AsyncLocalStorage;run(e){return this.#e.run(new Map,e)}async get(e){return this.#e.getStore()?.get(e)??null}async set(e,t){this.#e.getStore()?.set(e,t)}async delete(e){this.#e.getStore()?.delete(e)}};const o=new a;exports.AsyncLocalMapStorage=a,exports.anvil=n.t,exports.asyncLocalStorage=o,exports.bscTestnet=n.n,exports.chains=n.r,exports.cleartext=t.t,exports.hardhat=n.i,exports.hoodi=n.a,exports.ingenTestnet=n.o,exports.mainnet=n.s,exports.node=i,exports.polygon=n.c,exports.polygonAmoy=n.l,exports.sepolia=n.u;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../fhevm-relayer.cjs"),t=require("../cleartext.cjs"),n=require("../chains.cjs");let r=require("node:async_hooks");function i(t){return{type:`node`,createRelayer:(n,r)=>new e.t({chain:n,options:t,logger:r})}}var a=class{#e=new r.AsyncLocalStorage;run(e){return this.#e.run(new Map,e)}async get(e){return this.#e.getStore()?.get(e)??null}async set(e,t){this.#e.getStore()?.set(e,t)}async delete(e){this.#e.getStore()?.delete(e)}};const o=new a;exports.AsyncLocalMapStorage=a,exports.anvil=n.t,exports.asyncLocalStorage=o,exports.bscTestnet=n.n,exports.chains=n.r,exports.cleartext=t.t,exports.hardhat=n.i,exports.hoodi=n.a,exports.ingenTestnet=n.o,exports.mainnet=n.s,exports.node=i,exports.polygon=n.c,exports.polygonAmoy=n.l,exports.sepolia=n.u,exports.zenithTrexTestnet=n.d;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as WalletAccountListener, D as GenericSigner, L as WriteContractArgs, M as ContractAbi, O as WalletAccount, R as WriteContractConfig, in as EIP712TypedData, j as WalletAccountStore, z as WriteFunctionName } from "./types-
|
|
1
|
+
import { A as WalletAccountListener, D as GenericSigner, L as WriteContractArgs, M as ContractAbi, O as WalletAccount, R as WriteContractConfig, in as EIP712TypedData, j as WalletAccountStore, z as WriteFunctionName } from "./types-Crf7ymyj.js";
|
|
2
2
|
import { Hex } from "viem";
|
|
3
3
|
//#region src/signer/wallet-account-store.d.ts
|
|
4
4
|
/**
|
|
@@ -73,4 +73,4 @@ declare abstract class BaseSigner implements GenericSigner, Disposable {
|
|
|
73
73
|
}
|
|
74
74
|
//#endregion
|
|
75
75
|
export { MutableWalletAccountStore as n, createWalletAccountStore as r, BaseSigner as t };
|
|
76
|
-
//# sourceMappingURL=base-signer-
|
|
76
|
+
//# sourceMappingURL=base-signer-D902THgk.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{p as e,r as t,t as n}from"./relayer-CVKO9GmQ.js";import{H as r,K as i,L as a,M as o,P as s,W as c,Y as l,d as u,f as d,j as f,m as p,p as m,q as ee}from"./erc165-DbMOt-s6.js";import{r as h}from"./applied-runtime-3fzqBC2V.js";import{a as te,i as ne,n as g,o as _,r as v,s as y,t as b}from"./primitives-Cym-3HKa.js";import{t as x}from"./validation-BRu06AM_.js";import{a as S,i as re,n as C,o as w,r as ie,s as ae,t as T}from"./wrappers-registry-Cm3JJeqx.js";import{a as E,c as oe,d as se,l as ce,n as le,o as ue,s as de,u as fe}from"./chains-iPpnjXql.js";import{getAddress as D,toBytes as O,toHex as k,zeroAddress as A}from"viem";import{hasFhevmRuntimeConfig as pe,setFhevmRuntimeConfig as me}from"@fhevm/sdk/viem";import{z as j}from"zod/mini";var M=class{#e=null;#t=null;#n;#r;#i;constructor(e=`CredentialStore`,t=1,n=`credentials`){this.#n=e,this.#r=t,this.#i=n}#a(){return this.#e?Promise.resolve(this.#e):(this.#t||=new Promise((e,t)=>{let n=indexedDB.open(this.#n,this.#r);n.onupgradeneeded=()=>{let e=n.result;e.objectStoreNames.contains(this.#i)||e.createObjectStore(this.#i,{keyPath:`key`})},n.onsuccess=()=>{this.#e=n.result,this.#t=null,this.#e.onversionchange=()=>{this.#e?.close(),this.#e=null,this.#t=null},this.#e.onclose=()=>{this.#e=null,this.#t=null},e(this.#e)},n.onerror=()=>{this.#e=null,this.#t=null,t(n.error)}}),this.#t)}async#o(e,t){let n=await this.#a();return new Promise((r,i)=>{let a=n.transaction(this.#i,e);a.onabort=()=>i(a.error??Error(`Transaction aborted`));let o=t(a.objectStore(this.#i));e===`readonly`?o.onsuccess=()=>r(o.result):a.oncomplete=()=>r(o.result),o.onerror=()=>i(o.error)})}async get(e){return(await this.#o(`readonly`,t=>t.get(e)))?.value??null}async set(e,t){await this.#o(`readwrite`,n=>n.put({key:e,value:t}))}async delete(e){await this.#o(`readwrite`,t=>t.delete(e))}async clear(){await this.#o(`readwrite`,e=>e.clear())}};const he=new M;var N=class{#e=new Map;async get(e){return this.#e.get(e)??null}async set(e,t){this.#e.set(e,t)}async delete(e){this.#e.delete(e)}};const ge=new N;function _e(){return typeof window<`u`?new M(`CredentialStore`):new N}function ve(e=_e(),t=e){return{storage:e,permitStorage:t}}function ye(e,t,r){let i=e.map(e=>e.id),a=[...new Set(i.filter((e,t)=>i.indexOf(e)!==t))];if(a.length>0)throw new n(`Duplicate chain id(s) [${a.join(`, `)}] in the chains array. Each chain id must appear only once. Note: hardhat and anvil are aliases (both use 31337).`);let o=Object.keys(t).map(Number).filter(e=>!i.includes(e));o.length>0&&r.warn(`Relayer entries for chain(s) [${o.join(`, `)}] are ignored: those chains are not in the chains array. Add the chain config to use them, or drop the relayer entries.`);let s=new Map;for(let r of e){let e=t[r.id];if(!e)throw new n(`Chain ${r.id} has no relayer configured. Add a relayer entry: relayers: { [${r.id}]: web() }`);s.set(r.id,{chain:r,relayerConfig:e})}return s}var be=class{#e;#t;#n;constructor(e,t,r){if(e.length===0)throw new n(`At least one chain is required.`);this.#e=new Map(e.map(e=>[e.id,e])),this.#n=e[0].id;let i=new Map;for(let[n,{relayerConfig:a,chain:o}]of ye(e,t,r))i.set(n,a.createRelayer(o,r));this.#t=i}get chains(){return[...this.#e.values()]}get chain(){let e=this.#e.get(this.#n);if(e===void 0)throw new n(`Chain ${this.#n} is not configured. Add it to the chains array.`);return e}switchChain(e){this.#n=e}dispose(){for(let e of new Set(this.#t.values()))e.dispose?.()}get relayer(){let e=this.#t.get(this.chain.id);if(e===void 0)throw new n(`No relayer configured for chain ${this.#n}. Add it to the relayers object.`);return e}};const P={version:1,info:`zama-sdk-keypair-wrapping-v1`,ivLengthBytes:12,tagLengthBytes:16};function F(e){return new Uint8Array(e)}function I(e){return F(new TextEncoder().encode(JSON.stringify([e.publicKey,e.createdAt,e.expiresAt,e.tkmsVersion??null])))}function xe(e){return typeof e==`string`?new TextEncoder().encode(e):F(e)}var Se=class{#e;#t;constructor(e){this.#e=e}async baseKey(){return this.#t??=this.#n(this.#e),this.#t}async#n(e){let t=xe(e),n=await crypto.subtle.importKey(`raw`,t,`HKDF`,!1,[`deriveKey`]);return t.fill(0),e instanceof Uint8Array&&e.fill(0),this.#e=void 0,n}};async function L(e,t){let n=await e.baseKey();return crypto.subtle.deriveKey({name:`HKDF`,hash:`SHA-256`,salt:new TextEncoder().encode(t),info:new TextEncoder().encode(P.info)},n,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`])}async function Ce(e,t,n,r){let i=await L(t,n),a=crypto.getRandomValues(new Uint8Array(P.ivLengthBytes)),o=await crypto.subtle.encrypt({name:`AES-GCM`,iv:a,additionalData:I(r)},i,F(O(e)));return{wrappedPrivateKey:k(new Uint8Array(o)),iv:k(a)}}async function we(e,t,n,r){let i=await L(t,n),a=await crypto.subtle.decrypt({name:`AES-GCM`,iv:F(O(e.iv)),additionalData:I(r)},i,F(O(e.wrappedPrivateKey)));return k(new Uint8Array(a))}function Te(e){return typeof e==`object`&&!!e&&`name`in e&&e.name===`OperationError`}const R=86400;function z(){return Math.floor(Date.now()/1e3)}function B(e){return[...new Set(e.map(b))].sort()}function Ee(e){let{chainId:t}=e.domain;return typeof t==`bigint`?{...e,domain:{...e.domain,chainId:t.toString()}}:e}const V=`transportKeyPairTTL must be a positive integer number of seconds`,H=`permitTTL must be a positive integer number of days`,U=`transportKeyPairScope must be a non-empty string`,W=`transportKeyPairDerivationSecret must be a Uint8Array of at least 32 bytes or a string of at least 64 characters (256 bits of entropy): source it from a CSPRNG or secrets manager, not a human-memorable passphrase`,De=365*R,Oe=j.int({error:V}).check(j.positive({error:V}),j.maximum(De,`transportKeyPairTTL must not exceed the fhevm ACL maximum of ${De}s (365 days)`)),ke=j.int({error:H}).check(j.positive({error:H}),j.maximum(365,`permitTTL must not exceed the V1 permit maximum of 365 days`)),Ae=j.string({error:U}).check(j.minLength(1,U)),je=j.union([j.string({error:W}).check(j.minLength(64,W)),j.instanceof(Uint8Array,{error:W}).check(j.refine(e=>e.byteLength>=32,{error:W}))],{error:W}),Me=j.object({publicKey:v,privateKey:v,createdAt:y,expiresAt:_,tkmsVersion:j.optional(j.string())}),G=j.object({domain:j.record(j.string(),j.unknown()),primaryType:j.optional(j.string()),types:j.record(j.string(),j.array(j.object({name:j.string(),type:j.string()}))),message:j.record(j.string(),j.unknown())}),K=j.object({version:j.int().check(j.positive()),eip712:G,signature:v,signerAddress:g}),q=j.object({keypairPublicKey:v,contractAddresses:j.array(g).check(j.maxLength(10)),serializedPermit:K,startTimestamp:y,durationDays:te}),Ne=j.array(q),Pe=j.array(j.string()),Fe=j.object({version:j.literal(1),eip712:G,signerAddress:g}),Ie=`iv must be a ${P.ivLengthBytes}-byte hex string`,Le=`wrappedPrivateKey must be a whole number of bytes and at least ${P.tagLengthBytes} bytes (the AES-GCM authentication tag)`;function Re(e){return(e.length-2)/2}const ze=j.object({wrappingVersion:j.literal(P.version,{error:`wrappingVersion must be a wrapping scheme this SDK can read`}),publicKey:v,wrappedPrivateKey:v.check(j.refine(e=>e.length%2==0&&Re(e)>=P.tagLengthBytes,{error:Le})),iv:v.check(j.refine(e=>Re(e)===P.ivLengthBytes,{error:Ie})),createdAt:y,expiresAt:_,tkmsVersion:j.optional(j.string())});function Be(e){let t={publicKey:e.publicKey,createdAt:e.createdAt,expiresAt:e.expiresAt};return e.tkmsVersion&&(t.tkmsVersion=e.tkmsVersion),t}const J={version:P.version,schema:ze,async encode(e,t,n){let{wrappedPrivateKey:r,iv:i}=await Ce(e.privateKey,t,n,Be(e)),a={wrappingVersion:P.version,publicKey:e.publicKey,wrappedPrivateKey:r,iv:i,createdAt:e.createdAt,expiresAt:e.expiresAt};return e.tkmsVersion&&(a.tkmsVersion=e.tkmsVersion),a},async decode(e,t,n){let r=await we({wrappedPrivateKey:e.wrappedPrivateKey,iv:e.iv},t,n,Be(e)),i={publicKey:e.publicKey,privateKey:r,createdAt:e.createdAt,expiresAt:e.expiresAt};return e.tkmsVersion&&(i.tkmsVersion=e.tkmsVersion),i}},Ve=new Map([[J.version,J]]),He=J;function Ue(e){let t=e;return t.wrappingVersion!==void 0||t.wrappedPrivateKey!==void 0&&t.iv!==void 0}function We(e){if(typeof e!=`object`||!e||!Ue(e)){let t=Me.safeParse(e);return t.success?{kind:`plaintext`,keyPair:t.data}:{kind:`unrecognized`}}let t=e.wrappingVersion,n=typeof t==`number`?Ve.get(t):void 0;if(n===void 0)return{kind:`unsupported-version`,version:t};let r=n.schema.safeParse(e);if(!r.success)return{kind:`corrupt-wrapped`};let i=r.data;return{kind:`wrapped`,expiresAt:i.expiresAt,decode:(e,t)=>n.decode(i,e,t)}}function Ge(e,t,n){return He.encode(e,t,n)}function Ke(e){return`keypair:${e}`}function Y(e){return`keypair:scope:${e}`}function X(e){return`permits:${e.signerAddress}:${e.chainId}:${e.delegatorAddress}`}function Z(e){return`permits-index:${e}`}function qe(e){return`scope:${e}`}function Je(e,t){return{"wrapped-without-secret":`Transport key pair for scope "${t}" is wrapped, but this instance has no transportKeyPairDerivationSecret configured. Every instance sharing this scope must use the same transportKeyPairDerivationSecret; once they do, call permits.revokeTransportKeyPair() to rotate the entry.`,"unwrapped-under-secret":`Transport key pair for scope "${t}" is stored unwrapped, but this instance is configured with a transportKeyPairDerivationSecret. A peer instance sharing this scope is running without the secret: configure the same transportKeyPairDerivationSecret everywhere, then call permits.revokeTransportKeyPair() to migrate the scope to a wrapped entry.`,"unwrap-failed":`Transport key pair for scope "${t}" failed to unwrap. This usually means another instance created it with a different transportKeyPairDerivationSecret: every instance sharing this scope must use the same secret. It can also mean the stored entry is corrupted.`,"corrupt-wrapped":`Transport key pair for scope "${t}" is wrapped but structurally invalid: the stored iv or ciphertext is not a shape this wrapping scheme can produce. This usually means the stored entry is corrupted, or instances sharing this scope are running mismatched wrapping-scheme versions.`}[e]}const Ye={"unwrapped-under-secret":`unwrapped transport key pair entry found while a transportKeyPairDerivationSecret is configured`,"unwrap-failed":`transport key pair entry failed to unwrap (wrong transportKeyPairDerivationSecret?)`,"corrupt-wrapped":`structurally invalid wrapped transport key pair entry`};function Xe(e,t){let n=typeof e==`number`?`wrappingVersion ${e}`:`no wrappingVersion this build recognizes`;return`Transport key pair ${t===void 0?`for this signer`:`for scope "${t}"`} was written under a wrapping scheme this SDK build cannot read (${n}). The entry is preserved instead of regenerated, since an instance that understands the scheme may still be using it: ${t===void 0?`run a build that supports it, or call permits.clear() to discard the entry deliberately`:`run a build that supports it everywhere, or call permits.revokeTransportKeyPair() to rotate the scope`}.`}var Ze=class{#e;#t;#n;#r;#i;#a;#o=new Map;#s=new Map;constructor(e){this.#e=e.generator,this.#t=e.storage,this.#n=e.ttl,this.#r=e.logger,this.#i=e.scope,this.#a=e.derivationSecret}#c(e){return this.#i===void 0?`signer:${e}`:qe(this.#i)}#l(e){return this.#i===void 0?Ke(e):Y(this.#i)}async readStored(e){return this.#u(this.#l(e),this.#c(e))}async#u(e,t){let n=await this.#t.get(e);if(n==null)return null;let r=We(n);if(r.kind===`unsupported-version`)throw this.#f(e,Xe(r.version,this.#i));if(r.kind===`unrecognized`)return await this.#m(e,`malformed transport key pair entry`),null;let i=this.#a;if(i===void 0)return r.kind===`plaintext`?await this.#p(e,r.keyPair.expiresAt)?null:r.keyPair:this.#d(e,`wrapped-without-secret`);if(r.kind===`plaintext`)return this.#d(e,`unwrapped-under-secret`);if(r.kind===`corrupt-wrapped`)return this.#d(e,`corrupt-wrapped`);if(await this.#p(e,r.expiresAt))return null;try{return await r.decode(i,t)}catch(t){if(!Te(t))throw this.#r.error(`transport key pair unwrap failed unexpectedly`,{key:e,error:t}),new c(`Transport key pair unwrap failed unexpectedly.`,{cause:t});return this.#d(e,`unwrap-failed`,t)}}async#d(e,t,n){if(this.#i!==void 0)throw this.#f(e,Je(t,this.#i),n);if(t===`wrapped-without-secret`)throw this.#f(e,`Transport key pair for this signer is wrapped, but this instance has no transportKeyPairDerivationSecret configured. Configure the same transportKeyPairDerivationSecret the entry was written with. To downgrade to plaintext at rest on purpose, discard the stored entry first by calling permits.clear(), then run without the secret.`,n);let r=Ye[t];return this.#r.warn(r,{key:e}),await this.#m(e,r),null}#f(e,t,n){return this.#r.error(t,{key:e}),new c(t,{cause:n})}async#p(e,t){return z()<t?!1:(await this.#m(e,`expired transport key pair entry`),!0)}async#m(e,t){this.#r.debug(`discarding transport key pair entry`,{key:e,reason:t}),await f(`delete transport key pair entry`,()=>this.#t.delete(e),this.#r)}async getOrCreate(e,t){return this.#h(this.#l(e),this.#c(e),{strict:t?.strict})}async#h(e,t,n){let r=n?.strict??!1,i=`${e}::${r}`,a=this.#o.get(i);if(a)return a;let o=this.#s.get(e)??0,s=(async()=>{let n=await this.#u(e,t);if(n!==null)return n;let i=await this.#e(),a=z(),s=a+this.#n,u={publicKey:i.publicKey,privateKey:i.privateKey,createdAt:a,expiresAt:s};i.tkmsVersion&&(u.tkmsVersion=i.tkmsVersion);let d=u;if(this.#a!==void 0)try{d=await Ge(u,this.#a,t)}catch(t){let n=`Failed to wrap the transport private key for at-rest storage.`;throw this.#r.error(n,{key:e,error:t}),new c(n,{cause:t})}if((this.#s.get(e)??0)===o)r?await this.#t.set(e,d):await f(`persist transport key pair`,()=>this.#t.set(e,d),this.#r);else if(r)throw new l(`The transport key pair was rotated while it was being generated, so the freshly generated key pair could not be persisted. Retry.`);return u})().finally(()=>{this.#o.delete(i)});return this.#o.set(i,s),s}async clear(e){let t=Ke(e);await f(`delete transport key pair entry`,()=>this.#t.delete(t),this.#r)}async evict(e){let t=this.#l(e);await f(`evict transport key pair entry`,()=>this.#t.delete(t),this.#r)}async clearScope(){if(this.#i===void 0)return;let e=Y(this.#i);this.#s.set(e,(this.#s.get(e)??0)+1),await this.#t.delete(e)}async warmScope(){this.#i!==void 0&&await this.#h(Y(this.#i),qe(this.#i),{strict:!0})}};function Qe(e,t){let n=new Set(e.flatMap(e=>e.contractAddresses));return t.filter(e=>!n.has(e))}function $e(e){let t=[];for(let n=0;n<e.length;n+=10)t.push(e.slice(n,n+10));return t}function et(e,t,n){return e.filter(e=>e.keypairPublicKey===t&&n<e.startTimestamp+e.durationDays*86400)}function tt(e,t){let n=new Set(t);return e.filter(e=>!e.contractAddresses.some(e=>n.has(e)))}function nt(e,t){return[...new Set([...e,...t])].sort()}function rt(e,t,n){let r=new Set(n),i=e.filter(e=>new Set([...e.contractAddresses,...t]).size<=10);if(i.length===0)return null;function a(e){return e.contractAddresses.reduce((e,t)=>e+ +!!r.has(t),0)}let o=Math.max(...i.map(a));return i.filter(e=>a(e)===o).reduce((e,t)=>t.startTimestamp>e.startTimestamp?t:e)}var it=class{#e;#t;constructor(e){this.#e=e.storage,this.#t=e.logger}async list(e){let t=X(e),n=await this.#e.get(t);if(n==null)return[];let r=Ne.safeParse(n);return r.success?r.data:(await this.clearScope(e),[])}async listUsableAndPrune(e,t){let n=await this.list(e),r=et(n,t,Math.floor(Date.now()/1e3));return r.length!==n.length&&(r.length===0?await this.clearScope(e):await f(`update permit entry`,()=>this.#e.set(X(e),r),this.#t)),r}async append(e,t){if(t.length===0)return;let n=t.map(e=>q.parse(e)),r=await this.list(e);await this.#e.set(X(e),[...r,...n]),await this.#r(e)}async replace(e,t,n){let r=q.parse(n),i=(await this.list(e)).filter(e=>e.serializedPermit.signature!==t);await this.#e.set(X(e),[...i,r]),await this.#r(e)}async deletePermitsTouching(e,t){let n=await this.list(e);if(n.length===0)return;let r=tt(n,t);r.length===0?await this.clearScope(e):await this.#e.set(X(e),r)}async clearScope(e){await this.#a(X(e)),await this.#i(e)}async clearAllForSigner(e){let t=Z(e),n=await this.#n(t);await Promise.all(n.map(e=>this.#a(e))),await f(`delete permit index`,()=>this.#e.delete(t),this.#t)}async#n(e){let t=await this.#e.get(e);if(t==null)return[];let n=Pe.safeParse(t);return n.success?n.data:(await f(`delete permit index`,()=>this.#e.delete(e),this.#t),[])}async#r(e){let t=Z(e.signerAddress),n=X(e),r=await this.#n(t);r.includes(n)||await this.#e.set(t,[...r,n])}async#i(e){let t=Z(e.signerAddress),n=X(e),r=await this.#n(t),i=r.filter(e=>e!==n);i.length!==r.length&&(i.length===0?await f(`delete permit index`,()=>this.#e.delete(t),this.#t):await f(`update permit index`,()=>this.#e.set(t,i),this.#t))}async#a(e){await f(`delete permit entry`,()=>this.#e.delete(e),this.#t)}},at=class{#e;#t;#n;#r;#i;#a;#o;#s;#c=new Map;constructor(e){this.#e=new Ze({generator:async()=>{let t=e.router.relayer,n=await t.generateTransportKeyPair();return t.serializeTransportKeyPair({transportKeyPair:n})},storage:e.storage,ttl:e.transportKeyPairTTL,logger:e.logger,scope:e.scope,derivationSecret:e.derivationSecret}),this.#t=new it({storage:e.permitStorage??e.storage,logger:e.logger}),this.#n=e.router,this.#r=e.signer,this.#i=e.permitTTL,this.#a=e.logger,this.#o=e.emitEvent,this.#s=e.scope}#l(e){if(!this.#r)throw new s(e);return this.#r}#u(e,t){let n=r(t,{operation:e});return this.#o({type:o.PermitError,operation:e,error:n}),n}async grantPermit(e,t){let n=t===void 0?`grantPermit`:`grantDelegationPermit`,r,i,a;try{r=b(this.#l(`grantPermit`).requireWalletAccount(`grantPermit`).address),i=B(e),a=this.#d(r,t)}catch(e){throw this.#u(n,e)}let o=await this.#e.getOrCreate(r);if(i.length===0)return{keypair:o,permissions:[]};let s;try{s=await this.#t.listUsableAndPrune(a,o.publicKey)}catch(e){throw this.#u(n,e)}let c=Qe(s,i);if(c.length>0){let e=rt(s,c,i);if(e!==null){let t=nt(e.contractAddresses,c),n=await this.#f({chunk:t,keypair:o,scope:a});await f(`replace permit`,()=>this.#t.replace(a,e.serializedPermit.signature,n),this.#a),s[s.indexOf(e)]=n}else for(let e of $e(c)){let t=await this.#f({chunk:e,keypair:o,scope:a});s.push(t),await f(`persist permit`,()=>this.#t.append(a,[t]),this.#a)}}let l=new Set(i);return{keypair:o,permissions:s.filter(e=>e.contractAddresses.some(e=>l.has(e)))}}async preparePermit(e){let t=b(e.signer),r=B(e.contracts);if(r.length===0)throw new n(`preparePermit: request.contracts must not be empty.`);if(r.length>10)throw new n(`preparePermit: request.contracts must not exceed 10 addresses per call (got ${r.length}) — grantPermit chunks automatically, preparePermit does not.`);let i=e.delegator?b(e.delegator):void 0;if(i!==void 0&&i===t)throw new n(`preparePermit: request.delegator must differ from request.signer — self-delegation is not allowed.`);let a=e.durationDays===void 0?this.#i:x(ke,e.durationDays),o=this.#n.relayer,s=await this.#e.getOrCreate(t,{strict:!0}),c=await o.parseTransportKeyPair(s),l=z();return{version:1,eip712:Ee(G.parse(await o.createUnsignedLegacyDecryptionPermitEip712({transportKeyPair:c,contractAddresses:r,startTimestamp:l,durationSeconds:a*R,...i&&{delegatorAddress:i}}))),signerAddress:t}}async registerPermit(e,t){let r;try{r=x(Fe,e)}catch(e){throw this.#u(`registerPermit`,e)}let a=this.#n.relayer,o=this.#n.chain.id,{domain:s,message:c}=r.eip712,u=Number(s.chainId);if(u!==o)throw this.#u(`registerPermit`,new i({preparedChainId:u,activeChainId:o}));let d=Number(c.startTimestamp),p=Number(c.durationDays);if(z()>=d+p*86400)throw this.#u(`registerPermit`,new ee(`registerPermit: the prepared permit's validity window (starting ${d}, ${p}d) has already elapsed — call preparePermit again.`));let m=r.signerAddress,h=await this.#e.readStored(m);if(h===null||h.publicKey!==c.publicKey)throw new l(`registerPermit: the transport key pair changed since preparePermit ran — call preparePermit again to rebind the signature request to the current key pair.`);try{let e=await a.parseTransportKeyPair(h),i=await a.parseSignedDecryptionPermit({serializedPermit:{version:r.version,eip712:r.eip712,signature:t,signerAddress:m},transportKeyPair:e});if(i.version!==1)throw new n(`registerPermit: expected a V1 signed permit, got version ${i.version}.`);let s=x(K,await a.serializeSignedDecryptionPermit({signedPermit:i})),c={keypairPublicKey:h.publicKey,contractAddresses:B(i.eip712.message.contractAddresses),serializedPermit:s,startTimestamp:Number(i.eip712.message.startTimestamp),durationDays:Number(i.eip712.message.durationDays)},l={signerAddress:m,chainId:o,delegatorAddress:b(i.encryptedDataOwnerAddress)};await f(`replace permit`,()=>this.#t.replace(l,s.signature,c),this.#a)}catch(e){throw this.#u(`registerPermit`,e)}}async hasPermit(e,t){if(e.length===0)return!0;let n=this.#r?.walletAccount.getSnapshot();if(!n)return!1;let r=b(n.address),i;try{i=await this.#e.readStored(r)}catch(e){if(!(e instanceof c))throw e;return!1}if(i===null)return!1;let a=this.#d(r,t);return Qe(await this.#t.listUsableAndPrune(a,i.publicKey),B(e)).length===0}async revokePermits(e){let t=b(this.#l(`revokePermits`).requireWalletAccount(`revokePermits`).address);if(e===void 0){await this.#t.clearAllForSigner(t);return}let n=B(e);n.length!==0&&await this.#t.deletePermitsTouching(this.#d(t),n)}#d(e,t){return{signerAddress:e,chainId:this.#n.chain.id,delegatorAddress:t?b(t):e}}async clearCredentials(){let e=b(this.#l(`clearCredentials`).requireWalletAccount(`clearCredentials`).address);await this.#e.clear(e),await this.#t.clearAllForSigner(e)}async revokeTransportKeyPair(e){if(this.#s===void 0)throw new n(`revokeTransportKeyPair() requires a transportKeyPairScope to be configured on this SDK instance — there is no shared key pair to revoke.`);if(e!==this.#s)throw new n(`revokeTransportKeyPair("${e}") does not match the configured scope ("${this.#s}").`);await this.#e.clearScope()}async warmTransportKeyPair(e){await this.#e.getOrCreate(b(e))}async warmTransportKeyPairScope(e){if(this.#s===void 0)throw new n(`warmTransportKeyPairScope() requires a transportKeyPairScope to be configured on this SDK instance — there is no shared key pair to warm.`);if(e!==this.#s)throw new n(`warmTransportKeyPairScope("${e}") does not match the configured scope ("${this.#s}").`);await this.#e.warmScope()}async handleWalletAccountChange(e,t){let n=e?b(e.address):void 0;n!==(t?b(t.address):void 0)&&n&&(await this.#e.clear(n),await this.#t.clearAllForSigner(n))}async#f(n){let{chunk:r,keypair:i,scope:a}=n,o=z(),s=a.delegatorAddress!==a.signerAddress,c=this.#n.relayer;try{let e={transportKeyPair:await c.parseTransportKeyPair(i),contractAddresses:r,startTimestamp:o,durationSeconds:this.#i*R,signerAddress:a.signerAddress,signer:this.#l(`signPermit`)},t=s?await c.signDecryptionPermit({...e,delegatorAddress:a.delegatorAddress}):await c.signDecryptionPermit(e),n=x(K,await c.serializeSignedDecryptionPermit({signedPermit:t}));return{keypairPublicKey:i.publicKey,contractAddresses:r,serializedPermit:n,startTimestamp:o,durationDays:this.#i}}catch(n){let r=s?`grantDelegationPermit`:`grantPermit`;throw!(n instanceof t)&&n instanceof Error&&e(n.message)&&await this.#e.evict(a.signerAddress),this.#u(r,n)}}async evictTransportKeyPair(){let e=this.#r?.walletAccount.getSnapshot();e&&await this.#e.evict(b(e.address))}async recoverPermits(e,t,n){let r=this.#l(`recoverPermits`).requireWalletAccount(`recoverPermits`),i=this.#d(b(r.address),t),a=X(i),o=this.#c.get(a);if(o)return await o,this.grantPermit(e,t);let s=await this.#p(i),c=this.#c.get(a);if(c)return await c,this.grantPermit(e,t);if(s===null)return this.grantPermit(e,t);let l=new Set(n??[]);if(l.size>0&&!s.some(e=>l.has(e.serializedPermit.signature)))return this.grantPermit(e,t);let u=s.filter(e=>!l.has(e.serializedPermit.signature)),d=s.flatMap(e=>e.contractAddresses),f=this.#m(i,d,e,u,t).finally(()=>{this.#c.delete(a)});return this.#c.set(a,f),await f,this.grantPermit(e,t)}async#p(e){try{return await this.#t.list(e)}catch(e){return this.#a.warn(`read permits for recovery failed`,{error:e}),null}}async#m(e,t,n,r,i){await f(`evict revoked permits`,()=>this.#t.clearScope(e),this.#a);try{await this.grantPermit(nt(t,B(n)),i)}catch(t){throw r.length>0&&await f(`restore surviving permits`,async()=>{let t=await this.#t.list(e),n=new Set(t.map(e=>e.serializedPermit.signature)),i=r.filter(e=>!n.has(e.serializedPermit.signature));i.length>0&&await this.#t.append(e,i)},this.#a),t}}},ot=class{#e;#t=`[zama-sdk]`;constructor(e){this.#e=e}error(e,t){this.#e?.error(`${this.#t} ${e}`,t)}warn(e,t){this.#e?.warn(`${this.#t} ${e}`,t)}info(e,t){this.#e?.info(`${this.#t} ${e}`,t)}debug(e,t){this.#e?.debug(`${this.#t} ${e}`,t)}warnAlways(e){console.warn(`${this.#t} ${e}`),this.warn(e)}};const st={[de.id]:de.registryAddress,[oe.id]:oe.registryAddress,[fe.id]:fe.registryAddress,[ce.id]:ce.registryAddress,[E.id]:E.registryAddress,[ue.id]:ue.registryAddress,[se.id]:se.registryAddress,[le.id]:le.registryAddress},ct=j.record(j.string().check(j.regex(/^\d+$/,`expected numeric chain id key`)),g),lt=ne,Q=300*1e3;var ut=class{provider;#e;#t;#n=new Map;constructor(e){this.provider=e.provider,this.#e=Object.assign({},st,x(j.optional(ct),e.registryAddresses)),this.#t=x(lt,e.registryTTL??86400)*1e3}getAddress(e){return this.#e[e]}#r(e){let t=this.#n.get(e);if(t){if(Date.now()>=t.expiresAt){this.#n.delete(e);return}return t.data}}#i(e,t,n=this.#t){return this.#n.set(e,{data:t,expiresAt:Date.now()+n}),t}refresh(){this.#n.clear()}get ttlMs(){return this.#t}async getRegistryAddress(){let e=await this.provider.getChainId(),t=this.#e[e];if(!t)throw new n(`No wrappers registry address configured for chain ${e}.\nPass a registryAddresses entry for this chain.`);return D(t)}async listPairs(e={}){let t=e.page??1,r=e.pageSize??100,i=e.metadata??!1;if(t<1)throw new n(`page must be >= 1, got ${t}`);if(r<1)throw new n(`pageSize must be >= 1, got ${r}`);let a=await this.getRegistryAddress(),o=`total:${a}`,s=this.#r(o);if(s===void 0){let e=await this.provider.readContract(S(a));s=this.#i(o,Number(e))}let c=BigInt((t-1)*r),l=c+BigInt(r)>BigInt(s)?BigInt(s):c+BigInt(r);if(c>=BigInt(s))return{items:[],total:s,page:t,pageSize:r};let u=`slice:${a}:${c}:${l}`,d=this.#r(u);if(d===void 0){let e=await this.provider.readContract(w(a,c,l));d=this.#i(u,[...e])}if(!i)return{items:d,total:s,page:t,pageSize:r};let f=`metadata:${a}:${c}:${l}`,p=this.#r(f);if(p===void 0){let e=await Promise.allSettled(d.map(e=>this.#a(e))),t=e.some(e=>e.status===`rejected`),n=e.map((e,t)=>e.status===`fulfilled`?e.value:Object.assign({},d[t],{metadataFailed:!0,underlying:{name:`Unknown`,symbol:`???`,decimals:0,totalSupply:0n},confidential:{name:`Unknown`,symbol:`???`,decimals:0}}));p=this.#i(f,n,t?Q:void 0)}return{items:p,total:s,page:t,pageSize:r}}async#a(e){let[t,n,r,i,a,o,s]=await Promise.all([this.provider.readContract(m(e.tokenAddress)),this.provider.readContract(p(e.tokenAddress)),this.provider.readContract(u(e.tokenAddress)),this.provider.readContract(d(e.tokenAddress)),this.provider.readContract(m(e.confidentialTokenAddress)),this.provider.readContract(p(e.confidentialTokenAddress)),this.provider.readContract(u(e.confidentialTokenAddress))]);return{...e,underlying:{name:t,symbol:n,decimals:r,totalSupply:i},confidential:{name:a,symbol:o,decimals:s}}}async getConfidentialToken(e){let t=await this.getRegistryAddress(),n=D(e),r=`ct:${t}:${n}`,i=this.#r(r);if(i!==void 0)return i;let[a,o]=await this.provider.readContract(T(t,n));return o===A?this.#i(r,null,Q):this.#i(r,{confidentialTokenAddress:o,isValid:a})}async getUnderlyingToken(e){let t=await this.getRegistryAddress(),n=D(e),r=`ut:${t}:${n}`,i=this.#r(r);if(i!==void 0)return i;let[a,o]=await this.provider.readContract(C(t,n));return o===A?this.#i(r,null,Q):this.#i(r,{tokenAddress:o,isValid:a})}async getTokenPairs(){let e=await this.getRegistryAddress();return this.provider.readContract(re(e))}async getTokenPairsLength(){let e=await this.getRegistryAddress();return this.provider.readContract(S(e))}async getTokenPairsSlice(e,t){let n=await this.getRegistryAddress();return this.provider.readContract(w(n,e,t))}async getTokenPair(e){let t=await this.getRegistryAddress();return this.provider.readContract(ie(t,e))}async getConfidentialTokenAddress(e){let t=await this.getRegistryAddress();return this.provider.readContract(T(t,D(e)))}async getTokenAddress(e){let t=await this.getRegistryAddress();return this.provider.readContract(C(t,D(e)))}async isConfidentialTokenValid(e){let t=await this.getRegistryAddress();return this.provider.readContract(ae(t,D(e)))}};function dt(e,t,n){let r=new ot(n.logger),i=n.logger,a={wasmAssetLoadMode:`auto`,moduleVersions:`auto`,logger:{error:(e,t)=>i?.error(e,{cause:t}),warn:e=>i?.warn(e),debug:e=>i?.debug(e)},...n.runtime};if(pe()){let e=`runtime configuration is already set and cannot be changed.`;n.runtime===void 0?r.debug(e):r.warn(e)}else me(a),h(a);let{storage:o,permitStorage:s}=ve(n.storage,n.permitStorage),c=new be(n.chains,n.relayers,r);return{chains:n.chains,router:c,provider:t,signer:e,storage:o,permitStorage:s,transportKeyPairTTL:x(Oe,n.transportKeyPairTTL??2592e3),permitTTL:x(ke,n.permitTTL??30),transportKeyPairScope:n.transportKeyPairScope===void 0?void 0:x(Ae,n.transportKeyPairScope),registryTTL:x(lt,n.registryTTL??86400),logger:r,onEvent:n.onEvent}}function ft(e,t){return e?.address===t?.address&&e?.chainId===t?.chainId}var $=class{#e=new Set;#t;#n;constructor(e){this.#t=e,this.#n=e!==void 0}getSnapshot(){return this.#t}isReady(){return this.#n}setSnapshot(e){this.#n=!0;let t=this.#t;ft(t,e)||(this.#t=e,this.#r({previous:t,next:e}))}subscribe(e){this.#e.add(e);let t=this.#t;return t&&e({previous:void 0,next:t}),()=>{this.#e.delete(e)}}#r(e){for(let t of this.#e)t(e)}};function pt(e){return new $(e)}var mt=class{walletAccount;#e=!1;constructor(e){this.walletAccount=new $(e)}requireWalletAccount(e){let t=this.walletAccount.getSnapshot();if(!t)throw new a(e);return t}dispose(){this.#e||(this.#e=!0,this.onDispose())}[Symbol.dispose](){this.dispose()}onDispose(){}};export{st as a,je as c,ge as d,M as f,dt as i,Se as l,$ as n,ut as o,he as p,pt as r,at as s,mt as t,N as u};
|
|
2
|
+
//# sourceMappingURL=base-signer-ws-wq22y.js.map
|