@zama-fhe/sdk 3.7.0-alpha.2 → 3.7.0-beta.2

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.
Files changed (102) hide show
  1. package/dist/cjs/base-signer.cjs +1 -1
  2. package/dist/cjs/base-signer.cjs.map +1 -1
  3. package/dist/cjs/chains.cjs +1 -1
  4. package/dist/cjs/chains.cjs.map +1 -1
  5. package/dist/cjs/erc165.cjs +2 -0
  6. package/dist/cjs/erc165.cjs.map +1 -0
  7. package/dist/cjs/ethers/index.cjs +1 -1
  8. package/dist/cjs/ethers/index.cjs.map +1 -1
  9. package/dist/cjs/fhevm-relayer.cjs +2 -2
  10. package/dist/cjs/fhevm-relayer.cjs.map +1 -1
  11. package/dist/cjs/index.cjs +1 -1
  12. package/dist/cjs/index.cjs.map +1 -1
  13. package/dist/cjs/invalidation.cjs +2 -0
  14. package/dist/cjs/invalidation.cjs.map +1 -0
  15. package/dist/cjs/primitives.cjs +2 -0
  16. package/dist/cjs/primitives.cjs.map +1 -0
  17. package/dist/cjs/query/index.cjs +1 -1
  18. package/dist/cjs/query/index.cjs.map +1 -1
  19. package/dist/cjs/relayer.cjs +1 -1
  20. package/dist/cjs/relayer.cjs.map +1 -1
  21. package/dist/cjs/token.cjs +1 -1
  22. package/dist/cjs/token.cjs.map +1 -1
  23. package/dist/cjs/vaults/index.cjs +2 -0
  24. package/dist/cjs/vaults/index.cjs.map +1 -0
  25. package/dist/cjs/viem/index.cjs +1 -1
  26. package/dist/cjs/viem/index.cjs.map +1 -1
  27. package/dist/cjs/wrapped-token.cjs +2 -0
  28. package/dist/cjs/wrapped-token.cjs.map +1 -0
  29. package/dist/cjs/wrappers-registry.cjs +1 -1
  30. package/dist/cjs/wrappers-registry.cjs.map +1 -1
  31. package/dist/esm/base-signer-D5Cwv7yb.js +2 -0
  32. package/dist/esm/base-signer-D5Cwv7yb.js.map +1 -0
  33. package/dist/esm/{base-signer-S2Ogf6L4.d.ts → base-signer-DIYZwDnc.d.ts} +2 -2
  34. package/dist/esm/chains/index.d.ts +1 -1
  35. package/dist/esm/chains/index.js +1 -1
  36. package/dist/esm/chains-ByyCdrrd.js +2 -0
  37. package/dist/esm/chains-ByyCdrrd.js.map +1 -0
  38. package/dist/esm/cleartext/index.d.ts +2 -2
  39. package/dist/esm/cleartext/index.js +1 -1
  40. package/dist/esm/{cleartext-pv2blbFU.d.ts → cleartext-3HOk1BAg.d.ts} +2 -2
  41. package/dist/esm/{cleartext-DcbDCDXj.js → cleartext-PCpNqRGV.js} +2 -2
  42. package/dist/esm/{cleartext-DcbDCDXj.js.map → cleartext-PCpNqRGV.js.map} +1 -1
  43. package/dist/esm/encrypt.worker.js +51 -51
  44. package/dist/esm/{encryption-DJljZ2oV.js → encryption-BKoalB4o.js} +2 -2
  45. package/dist/esm/{encryption-DJljZ2oV.js.map → encryption-BKoalB4o.js.map} +1 -1
  46. package/dist/esm/erc165-DbMOt-s6.js +2 -0
  47. package/dist/esm/erc165-DbMOt-s6.js.map +1 -0
  48. package/dist/esm/ethers/index.d.ts +5 -5
  49. package/dist/esm/ethers/index.js +1 -1
  50. package/dist/esm/ethers/index.js.map +1 -1
  51. package/dist/esm/fhevm-relayer-CtrnKjJf.js +8 -0
  52. package/dist/esm/fhevm-relayer-CtrnKjJf.js.map +1 -0
  53. package/dist/esm/{index-tfvbrVa2.d.ts → index-BHrjck_q.d.ts} +4 -4
  54. package/dist/esm/{index-DRrrBtMX.d.ts → index-DJYq1rAB.d.ts} +989 -1874
  55. package/dist/esm/{index-Gk1S0gjO.d.ts → index-ijgDL4IC.d.ts} +1 -14
  56. package/dist/esm/index.d.ts +8 -108
  57. package/dist/esm/index.js +1 -1
  58. package/dist/esm/index.js.map +1 -1
  59. package/dist/esm/invalidation-BgFjmXeQ.js +2 -0
  60. package/dist/esm/invalidation-BgFjmXeQ.js.map +1 -0
  61. package/dist/esm/invalidation-CJ-pzOUG.d.ts +46 -0
  62. package/dist/esm/node/index.d.ts +4 -4
  63. package/dist/esm/node/index.js +1 -1
  64. package/dist/esm/primitives-Cym-3HKa.js +2 -0
  65. package/dist/esm/primitives-Cym-3HKa.js.map +1 -0
  66. package/dist/esm/query/index.d.ts +495 -4
  67. package/dist/esm/query/index.js +1 -1
  68. package/dist/esm/query/index.js.map +1 -1
  69. package/dist/esm/relayer-CVKO9GmQ.js +2 -0
  70. package/dist/esm/relayer-CVKO9GmQ.js.map +1 -0
  71. package/dist/esm/token-CRJ8eCr7.js +2 -0
  72. package/dist/esm/token-CRJ8eCr7.js.map +1 -0
  73. package/dist/esm/{types-BOyFfG7D.d.ts → types-Bz5-wHPv.d.ts} +23 -43
  74. package/dist/esm/{types-BRIpBy9n.d.ts → types-CI6BtpB7.d.ts} +3 -3
  75. package/dist/esm/{types-OXQqX_kH.d.ts → types-v0_sfkli.d.ts} +3 -3
  76. package/dist/esm/{validation-DWe2k89s.js → validation-BRu06AM_.js} +2 -2
  77. package/dist/esm/{validation-DWe2k89s.js.map → validation-BRu06AM_.js.map} +1 -1
  78. package/dist/esm/vaults/index.d.ts +13833 -0
  79. package/dist/esm/vaults/index.js +2 -0
  80. package/dist/esm/vaults/index.js.map +1 -0
  81. package/dist/esm/viem/index.d.ts +5 -5
  82. package/dist/esm/viem/index.js +1 -1
  83. package/dist/esm/viem/index.js.map +1 -1
  84. package/dist/esm/web/index.d.ts +1 -1
  85. package/dist/esm/web/index.js +1 -1
  86. package/dist/esm/wrapped-token-BOtzaSAY.js +2 -0
  87. package/dist/esm/wrapped-token-BOtzaSAY.js.map +1 -0
  88. package/dist/esm/wrappers-registry-Cm3JJeqx.js +2 -0
  89. package/dist/esm/wrappers-registry-Cm3JJeqx.js.map +1 -0
  90. package/package.json +19 -5
  91. package/dist/esm/base-signer--sBO2qJp.js +0 -2
  92. package/dist/esm/base-signer--sBO2qJp.js.map +0 -1
  93. package/dist/esm/chains-DEpKup1n.js +0 -2
  94. package/dist/esm/chains-DEpKup1n.js.map +0 -1
  95. package/dist/esm/fhevm-relayer-CPmCytDX.js +0 -8
  96. package/dist/esm/fhevm-relayer-CPmCytDX.js.map +0 -1
  97. package/dist/esm/relayer-B6Zo6EkX.js +0 -2
  98. package/dist/esm/relayer-B6Zo6EkX.js.map +0 -1
  99. package/dist/esm/token-BMQ6xlrk.js +0 -2
  100. package/dist/esm/token-BMQ6xlrk.js.map +0 -1
  101. package/dist/esm/wrappers-registry-BfQr2QHn.js +0 -2
  102. package/dist/esm/wrappers-registry-BfQr2QHn.js.map +0 -1
@@ -36,15 +36,6 @@ interface FheChain<TId extends number = number> {
36
36
  readonly kmsContractAddress: Address;
37
37
  /** Address of the input verifier contract. */
38
38
  readonly inputVerifierContractAddress: Address;
39
- /**
40
- * Address of the `ProtocolConfig` contract. Required to sign or use V2
41
- * (unified) decryption permits — including {@link WILDCARD_PERMIT} — which
42
- * need protocol v0.14+. Leave `undefined` for a chain still on protocol
43
- * ≤0.13, or one whose `ProtocolConfig` address isn't known yet: V2 permit
44
- * signing then fails with a clear {@link UnifiedPermitNotSupportedError}
45
- * instead of a wallet prompt. V1 permits are unaffected either way.
46
- */
47
- readonly protocolConfigContractAddress?: Address | undefined;
48
39
  /** EIP-712 verifying contract address for decryption requests. */
49
40
  readonly verifyingContractAddressDecryption: Address;
50
41
  /** EIP-712 verifying contract address for input verification. */
@@ -85,7 +76,6 @@ declare const mainnet: {
85
76
  readonly verifyingContractAddressDecryption: "0x0f6024a97684f7d90ddb0fAAD79cB15F2C888D24";
86
77
  readonly verifyingContractAddressInputVerification: "0xcB1bB072f38bdAF0F328CdEf1Fc6eDa1DF029287";
87
78
  readonly registryAddress: "0xeb5015fF021DB115aCe010f23F55C2591059bBA0";
88
- readonly protocolConfigContractAddress: "0xD8236B57394f90726b26aB25D38CeAC776E1a7C4";
89
79
  };
90
80
  /**
91
81
  * Polygon mainnet network configuration (chainId 137).
@@ -101,7 +91,6 @@ declare const polygon: {
101
91
  readonly verifyingContractAddressDecryption: "0x0f6024a97684f7d90ddb0fAAD79cB15F2C888D24";
102
92
  readonly verifyingContractAddressInputVerification: "0xcB1bB072f38bdAF0F328CdEf1Fc6eDa1DF029287";
103
93
  readonly registryAddress: "0xc8908569868758dAF814B5a8b96bBc44D1653d54";
104
- readonly protocolConfigContractAddress: "0x17f62Ab3A1Ea519703cD597410147A30Fa1a7f1e";
105
94
  };
106
95
  /**
107
96
  * Sepolia testnet network configuration (chainId 11155111).
@@ -117,7 +106,6 @@ declare const sepolia: {
117
106
  readonly verifyingContractAddressDecryption: "0x5D8BD78e2ea6bbE41f26dFe9fdaEAa349e077478";
118
107
  readonly verifyingContractAddressInputVerification: "0x483b9dE06E4E4C7D35CCf5837A1668487406D955";
119
108
  readonly registryAddress: "0x2f0750Bbb0A246059d80e94c454586a7F27a128e";
120
- readonly protocolConfigContractAddress: "0x51f9AFBc89Ea792e1a21a12AB802ab58D4dbee83";
121
109
  };
122
110
  /**
123
111
  * Polygon Amoy testnet network configuration (chainId 80002).
@@ -133,7 +121,6 @@ declare const polygonAmoy: {
133
121
  readonly verifyingContractAddressDecryption: "0x5D8BD78e2ea6bbE41f26dFe9fdaEAa349e077478";
134
122
  readonly verifyingContractAddressInputVerification: "0x483b9dE06E4E4C7D35CCf5837A1668487406D955";
135
123
  readonly registryAddress: "0xF486c3D4F4562760A43883e72E8D6f6Cf2EFdA94";
136
- readonly protocolConfigContractAddress: "0x4CcF009Aba90D04f52b31fc7aDdE240578aFe10F";
137
124
  };
138
125
  /**
139
126
  * Hoodi testnet configuration (chainId 560048).
@@ -230,4 +217,4 @@ declare const anvil: {
230
217
  declare const chains: Record<number, FheChain>;
231
218
  //#endregion
232
219
  export { hoodi as a, polygon as c, AtLeastOneChain as d, FheChain as f, hardhat as i, polygonAmoy as l, bscTestnet as n, ingenTestnet as o, FheChainAuth as p, chains as r, mainnet as s, anvil as t, sepolia as u };
233
- //# sourceMappingURL=index-Gk1S0gjO.d.ts.map
220
+ //# sourceMappingURL=index-ijgDL4IC.d.ts.map
@@ -1,108 +1,8 @@
1
- import { a as hoodi, c as polygon, d as AtLeastOneChain, f as FheChain, i as hardhat, l as polygonAmoy, n as bscTestnet, o as ingenTestnet, p as FheChainAuth, r as chains, s as mainnet, t as anvil, u as sepolia } from "./index-Gk1S0gjO.js";
2
- import { $ as RevokeDelegationSubmittedEvent, $t as TransactionResult, A as WalletAccountListener, At as OnChainEvent, B as ApproveUnderlyingSubmittedEvent, Bt as decodeDelegatedForUserDecryption, C as TransferAndCallRequest, Ct as TransferCallbacks, D as GenericSigner, Dt as AclTopics, E as WrapRequest, Et as AclEvent, F as ReadContractReturnType, Ft as UnwrapRequestedEvent, G as DelegationSubmittedEvent, Gt as decodeUnwrapRequested, H as DecryptEndEvent, Ht as decodeOnChainEvents, I as ReadFunctionName, It as WrapEvent, J as EncryptStartEvent, Jt as findRevokedDelegationForUserDecryption, K as EncryptEndEvent, Kt as decodeWrap, L as WriteContractArgs, Lt as decodeAclEvent, M as ContractAbi, Mt as TOKEN_TOPICS, N as ReadContractArgs, Nt as Topics, O as WalletAccount, Ot as ConfidentialTransferEvent, P as ReadContractConfig, Pt as UnwrapFinalizedEvent, Q as PermitOperation, Qt as TransactionReceipt, R as WriteContractConfig, Rt as decodeAclEvents, S as TransactionKind, St as ShieldCallbacks, T as UnwrapRequest, Tt as ACL_TOPICS, U as DecryptErrorEvent, Ut as decodeRevokedDelegationForUserDecryption, V as BaseEvent, Vt as decodeOnChainEvent, W as DecryptStartEvent, Wt as decodeUnwrapFinalized, X as InvalidateDecryptionSignaturesSubmittedEvent, Xt as findWrap, Y as FinalizeUnwrapSubmittedEvent, Yt as findUnwrapRequested, Z as PermitErrorEvent, Zt as RawLog, _ as PrepareTransactionRequest, _t as ShieldPath, a as ZamaConfigBase, an as EncryptParams, at as TransferSubmittedEvent, b as RevokeDelegationRequest, bt as UnwrapResult, c as GenericStorage, cn as FhevmClient, ct as UnshieldPhase2SubmittedEvent, d as ConfidentialTransferFromRequest, dn as FhevmRuntimeConfig, dt as ZamaSDKEvent, en as ClearValue, et as SetOperatorSubmittedEvent, f as ConfidentialTransferRequest, fn as RelayerOptions, ft as ZamaSDKEventListener, g as PrepareOptions, gt as ShieldOptions, h as PrepareFees, ht as ApprovalStrategy, i as ZamaConfig, in as EncryptInput, it as TransferFromSubmittedEvent, j as WalletAccountStore, jt as RevokedDelegationForUserDecryptionEvent, k as WalletAccountChange, kt as DelegatedForUserDecryptionEvent, l as GenericProvider, ln as FhevmClientOptions, lt as UnwrapSubmittedEvent, m as FinalizeUnwrapRequest, mn as TypedValue, mt as ZamaSDKEvents, n as RelayerConfig, nn as DecryptValuesParameters, nt as TransactionErrorEvent, o as ZamaConfigGeneric, on as EncryptResult, ot as UnshieldPhase1SubmittedEvent, p as DelegateDecryptionRequest, pn as RelayerSDK, pt as ZamaSDKEventType, q as EncryptErrorEvent, qt as findDelegatedForUserDecryption, rn as EIP712TypedData, rt as TransactionOperation, s as GenericLogger, sn as EncryptedValue, st as UnshieldPhase2StartedEvent, t as CleartextRelayerConfig, tn as DecryptPublicValuesResult, tt as ShieldSubmittedEvent, u as ApproveUnderlyingRequest, un as FhevmRelayerOptions, ut as WrapSubmittedEvent, v as PreparedFor, vt as TransferOptions, w as UnwrapAllRequest, wt as UnshieldCallbacks, x as SetOperatorRequest, xt as WrapOptions, y as PreparedTransaction, yt as UnshieldOptions, z as WriteFunctionName, zt as decodeConfidentialTransfer } from "./types-BOyFfG7D.js";
3
- import { t as cleartext } from "./cleartext-pv2blbFU.js";
4
- import { t as ZamaConfigEthers } from "./types-OXQqX_kH.js";
5
- import { n as MutableWalletAccountStore, r as createWalletAccountStore, t as BaseSigner } from "./base-signer-S2Ogf6L4.js";
6
- import { $n as DelegationExpiryUnchangedError, $r as ERC7984_WRAPPER_INTERFACE_ID, An as SignerRequiredError, Ar as SerializedPermitEip712, At as Token, Bn as InsufficientAllowanceError, Br as getTokenPairContract, Bt as ListPairsOptions, Ci as createConfig, Cn as UnshieldAlreadyFinalizedDetails, Cr as PermissionV2, Dn as SigningFailedError, Dr as PreparedPermitV1, Dt as WrappedToken, En as SigningErrorMetadata, Er as PreparedPermitBase, Fn as ConfigurationError, Fr as PaginatedResult, Gn as EncryptionFailedError, Gr as delegateForUserDecryptionContract, Hn as InsufficientERC20BalanceError, Hr as getTokenPairsLengthContract, Ht as WrappersRegistryConfig, In as RelayerRequestFailedError, Ir as TokenWrapperPair, Jn as DelegationCooldownError, Jr as isHandleDelegatedContract, Kn as AclPausedError, Kr as getDelegationExpiryContract, Ln as BalanceCheckUnavailableError, Lr as TokenWrapperPairWithMetadata, Mn as WalletNotConnectedError, Mr as WILDCARD_PERMIT, Nn as RpcRateLimitError, Nr as WildcardPermit, On as SigningRejectedError, Or as PreparedPermitV2, Ot as BatchBalancesResult, Pn as NotEntitledError, Pr as ChecksummedAddress, Qn as DelegationExpiredError, Qr as ERC7984_INTERFACE_ID, Rn as BalanceErrorDetails, Rr as getConfidentialTokenAddressContract, Si as wrapContract, Sn as matchZamaError, Sr as PermissionV1, Tn as TransactionRevertedError, Tr as PreparedPermit, Un as DecryptionFailedError, Ur as getTokenPairsSliceContract, Vn as InsufficientConfidentialBalanceError, Vr as getTokenPairsContract, Vt as WrappersRegistry, Wn as EncryptOffloadUnavailableError, Wr as isConfidentialTokenValidContract, Xn as DelegationDelegateEqualsContractError, Xr as transferAndCallContract, Yn as DelegationDelegateCannotBeWildcardError, Yr as revokeDelegationContract, Zn as DelegationExpirationTooSoonError, Zr as ERC1363_INTERFACE_ID, _i as setOperatorContract, _r as ZamaErrorCode, a as ZamaSDK, ai as balanceOfContract, ar as InvalidationTimestampTooLowError, bi as unwrapFromBalanceContract, bn as Permits, br as Permission, c as BatchDecryptItem, ci as symbolContract, cr as PreparedPermitChainMismatchError, di as confidentialTransferContract, dr as TransportKeyPairChangedError, ei as isConfidentialTokenContract, er as DelegationNotFoundError, fi as confidentialTransferFromContract, fr as TransportKeyPairExpiredError, gi as rateContract, gr as ZamaError, hi as isOperatorContract, hr as ChainMismatchError, ii as approveContract, ir as InvalidationTimestampInFutureError, jn as WalletAccountNotReadyError, jr as SerializedTransportKeyPair, kn as SignerNotConfiguredError, kr as SerializedPermit, kt as BatchDecryptAsOptions, l as BatchDecryptResult, li as confidentialBalanceOfContract, lr as PreparedPermitExpiredError, mi as inferredTotalSupplyContract, mr as UnifiedPermitNotSupportedError, n as DecryptResult, ni as supportsInterfaceContract, nr as DelegationSelfNotAllowedError, o as ZamaSDKOptions, oi as decimalsContract, or as KeyWrappingError, pi as finalizeUnwrapContract, pr as UnifiedDecryptionUnsupportedError, qn as DelegationContractIsSelfError, qr as invalidateDecryptionSignaturesBeforeContract, r as EncryptedInput, ri as allowanceContract, rr as InvalidTransportKeyPairError, s as Offline, si as nameContract, sr as NoCiphertextError, t as Decryption, ti as isConfidentialWrapperContract, tr as DelegationNotPropagatedError, u as DelegatedDecryptOptions, ui as confidentialTotalSupplyContract, ur as RevokedKmsContextError, vi as underlyingContract, vn as Delegations, vr as isRetryable, wn as UnshieldAlreadyFinalizedError, wr as PreparePermitRequest, xi as unwrapRequesterContract, xn as ErrorForCode, xr as PermissionBase, yi as unwrapContract, yn as DelegationStatus, yr as retryAfterSeconds, zn as ERC20ReadFailedError, zr as getTokenAddressContract, zt as DefaultRegistryAddresses } from "./index-DRrrBtMX.js";
7
- import { t as ZamaConfigViem } from "./types-BRIpBy9n.js";
8
- import { Address, Hex } from "viem";
9
- //#region src/contracts/constants.d.ts
10
- /** uint64 max — represents a permanent (no-expiry) delegation. */
11
- declare const MAX_UINT64: bigint;
12
- /**
13
- * `contractAddress` covering every confidential contract with a single
14
- * delegation.
15
- */
16
- declare const WILDCARD_CONTRACT: "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF";
17
- //#endregion
18
- //#region src/storage/memory-storage.d.ts
19
- /** In-memory credential store. Credentials are lost on page reload. */
20
- declare class MemoryStorage implements GenericStorage {
21
- #private;
22
- /**
23
- * Retrieve a value by key.
24
- * @returns The stored value, or `null` if the key does not exist.
25
- */
26
- get<T = unknown>(key: string): Promise<T | null>;
27
- /** Store a value under the given key, overwriting any existing entry. */
28
- set<T = unknown>(key: string, value: T): Promise<void>;
29
- /** Remove the entry for the given key (no-op if absent). */
30
- delete(key: string): Promise<void>;
31
- }
32
- /** Default singleton for application-wide use. */
33
- declare const memoryStorage: MemoryStorage;
34
- //#endregion
35
- //#region src/storage/indexeddb-storage.d.ts
36
- /**
37
- * IndexedDB-backed {@link GenericStorage}.
38
- *
39
- * Stores keypair and permit objects keyed by a hashed wallet address. The
40
- * SDK delegates security to the storage backend — values are persisted
41
- * verbatim with no SDK-layer encryption.
42
- */
43
- declare class IndexedDBStorage implements GenericStorage {
44
- #private;
45
- constructor(dbName?: string, dbVersion?: number, storeName?: string);
46
- /**
47
- * Retrieve a value by key.
48
- * @returns The stored value, or `null` if the key does not exist.
49
- */
50
- get<T = unknown>(key: string): Promise<T | null>;
51
- /** Store a value under the given key, overwriting any existing entry. */
52
- set<T = unknown>(key: string, value: T): Promise<void>;
53
- /** Remove the entry for the given key (no-op if absent). */
54
- delete(key: string): Promise<void>;
55
- /** Remove all stored entries. */
56
- clear(): Promise<void>;
57
- }
58
- /** Default singleton for application-wide use. */
59
- declare const indexedDBStorage: IndexedDBStorage;
60
- //#endregion
61
- //#region src/storage/chrome-session-storage.d.ts
62
- /**
63
- * {@link GenericStorage} backed by `chrome.storage.session`.
64
- *
65
- * Use this in MV3 web extensions so the wallet signature survives
66
- * service worker restarts and is shared across popup, background,
67
- * and content script contexts.
68
- *
69
- * @example
70
- * ```ts
71
- * import { ZamaSDK, indexedDBStorage, chromeSessionStorage } from "@zama-fhe/sdk";
72
- * import { createConfig } from "@zama-fhe/sdk/viem";
73
- *
74
- * const config = createConfig({
75
- * chains: [mySepolia],
76
- * publicClient,
77
- * walletClient,
78
- * relayers: { [mySepolia.id]: web() },
79
- * storage: indexedDBStorage, // encrypted transport key pair — persistent
80
- * permitStorage: chromeSessionStorage, // signed permits — ephemeral
81
- * });
82
- * const sdk = new ZamaSDK(config);
83
- * ```
84
- */
85
- declare class ChromeSessionStorage implements GenericStorage {
86
- /**
87
- * Retrieve a value by key.
88
- * @returns The stored value, or `null` if the key does not exist.
89
- */
90
- get<T = unknown>(key: string): Promise<T | null>;
91
- /** Store a value under the given key, overwriting any existing entry. */
92
- set(key: string, value: unknown): Promise<void>;
93
- /** Remove the entry for the given key (no-op if absent). */
94
- delete(key: string): Promise<void>;
95
- }
96
- /** Default singleton for application-wide use. */
97
- declare const chromeSessionStorage: ChromeSessionStorage;
98
- //#endregion
99
- //#region src/utils/handles.d.ts
100
- /** All-zero encrypted-value sentinel — a 32-byte zero handle representing the cleartext value `0`. */
101
- declare const ZERO_ENCRYPTED_VALUE: "0x0000000000000000000000000000000000000000000000000000000000000000";
102
- /**
103
- * Check whether an encrypted value represents the zero value.
104
- */
105
- declare function isEncryptedValueZero(encryptedValue: string): boolean;
106
- //#endregion
107
- export { ACL_TOPICS, type AclEvent, AclPausedError, AclTopics, type Address, type ApprovalStrategy, type ApproveUnderlyingRequest, type ApproveUnderlyingSubmittedEvent, type AtLeastOneChain, BalanceCheckUnavailableError, type BalanceErrorDetails, type BaseEvent, BaseSigner, type BatchBalancesResult, type BatchDecryptAsOptions, type BatchDecryptItem, type BatchDecryptResult, ChainMismatchError, type ChecksummedAddress, ChromeSessionStorage, type ClearValue, type CleartextRelayerConfig, type ConfidentialTransferEvent, type ConfidentialTransferFromRequest, type ConfidentialTransferRequest, ConfigurationError, type ContractAbi, type DecryptEndEvent, type DecryptErrorEvent, type EncryptedInput as DecryptInput, type DecryptPublicValuesResult, type DecryptResult, type DecryptStartEvent, type DecryptValuesParameters, Decryption, DecryptionFailedError, DefaultRegistryAddresses, type DelegateDecryptionRequest, type DelegatedDecryptOptions, type DelegatedForUserDecryptionEvent, DelegationContractIsSelfError, DelegationCooldownError, DelegationDelegateCannotBeWildcardError, DelegationDelegateEqualsContractError, DelegationExpirationTooSoonError, DelegationExpiredError, DelegationExpiryUnchangedError, DelegationNotFoundError, DelegationNotPropagatedError, DelegationSelfNotAllowedError, type DelegationStatus, type DelegationSubmittedEvent, Delegations, type EIP712TypedData, ERC1363_INTERFACE_ID, ERC20ReadFailedError, ERC7984_INTERFACE_ID, ERC7984_WRAPPER_INTERFACE_ID, type EncryptEndEvent, type EncryptErrorEvent, type EncryptInput, EncryptOffloadUnavailableError, type EncryptParams, type EncryptResult, type EncryptStartEvent, type EncryptedValue, EncryptionFailedError, type ErrorForCode, type FheChain, type FheChainAuth, type FhevmClient, type FhevmClientOptions, type FhevmRelayerOptions, type FhevmRuntimeConfig, type FinalizeUnwrapRequest, type FinalizeUnwrapSubmittedEvent, type GenericLogger, type GenericProvider, type GenericSigner, type GenericStorage, type Hex, IndexedDBStorage, InsufficientAllowanceError, InsufficientConfidentialBalanceError, InsufficientERC20BalanceError, InvalidTransportKeyPairError, type InvalidateDecryptionSignaturesSubmittedEvent, InvalidationTimestampInFutureError, InvalidationTimestampTooLowError, KeyWrappingError, type ListPairsOptions, MAX_UINT64, MemoryStorage, MutableWalletAccountStore, NoCiphertextError, NotEntitledError, Offline, type OnChainEvent, type PaginatedResult, type Permission, type PermissionBase, type PermissionV1, type PermissionV2, type PermitErrorEvent, type PermitOperation, Permits, type PrepareFees, type PrepareOptions, type PreparePermitRequest, type PrepareTransactionRequest, type PreparedFor, type PreparedPermit, type PreparedPermitBase, PreparedPermitChainMismatchError, PreparedPermitExpiredError, type PreparedPermitV1, type PreparedPermitV2, type PreparedTransaction, type RawLog, type ReadContractArgs, type ReadContractConfig, type ReadContractReturnType, type ReadFunctionName, type RelayerConfig, type RelayerOptions, RelayerRequestFailedError, type RelayerSDK, type RevokeDelegationRequest, type RevokeDelegationSubmittedEvent, type RevokedDelegationForUserDecryptionEvent, RevokedKmsContextError, RpcRateLimitError, type SerializedPermit, type SerializedPermitEip712, type SerializedTransportKeyPair, type SetOperatorRequest, type SetOperatorSubmittedEvent, type ShieldCallbacks, type ShieldOptions, type ShieldPath, type ShieldSubmittedEvent, SignerNotConfiguredError, SignerRequiredError, type SigningErrorMetadata, SigningFailedError, SigningRejectedError, TOKEN_TOPICS, Token, type TokenWrapperPair, type TokenWrapperPairWithMetadata, Topics, type TransactionErrorEvent, type TransactionKind, type TransactionOperation, type TransactionReceipt, type TransactionResult, TransactionRevertedError, type TransferAndCallRequest, type TransferCallbacks, type TransferFromSubmittedEvent, type TransferOptions, type TransferSubmittedEvent, TransportKeyPairChangedError, TransportKeyPairExpiredError, type TypedValue, UnifiedDecryptionUnsupportedError, UnifiedPermitNotSupportedError, type UnshieldAlreadyFinalizedDetails, UnshieldAlreadyFinalizedError, type UnshieldCallbacks, type UnshieldOptions, type UnshieldPhase1SubmittedEvent, type UnshieldPhase2StartedEvent, type UnshieldPhase2SubmittedEvent, type UnwrapAllRequest, type UnwrapFinalizedEvent, type UnwrapRequest, type UnwrapRequestedEvent, type UnwrapResult, type UnwrapSubmittedEvent, WILDCARD_CONTRACT, WILDCARD_PERMIT, type WalletAccount, type WalletAccountChange, type WalletAccountListener, WalletAccountNotReadyError, type WalletAccountStore, WalletNotConnectedError, type WildcardPermit, type WrapEvent, type WrapOptions, type WrapRequest, type WrapSubmittedEvent, WrappedToken, WrappersRegistry, type WrappersRegistryConfig, type WriteContractArgs, type WriteContractConfig, type WriteFunctionName, ZERO_ENCRYPTED_VALUE, type ZamaConfig, type ZamaConfigBase, type ZamaConfigEthers, type ZamaConfigGeneric, type ZamaConfigViem, ZamaError, ZamaErrorCode, ZamaSDK, type ZamaSDKEvent, type ZamaSDKEventListener, type ZamaSDKEventType, ZamaSDKEvents, type ZamaSDKOptions, allowanceContract, anvil, approveContract, balanceOfContract, bscTestnet, chains, chromeSessionStorage, cleartext, confidentialBalanceOfContract, confidentialTotalSupplyContract, confidentialTransferContract, confidentialTransferFromContract, createConfig, createWalletAccountStore, decimalsContract, decodeAclEvent, decodeAclEvents, decodeConfidentialTransfer, decodeDelegatedForUserDecryption, decodeOnChainEvent, decodeOnChainEvents, decodeRevokedDelegationForUserDecryption, decodeUnwrapFinalized, decodeUnwrapRequested, decodeWrap, delegateForUserDecryptionContract, finalizeUnwrapContract, findDelegatedForUserDecryption, findRevokedDelegationForUserDecryption, findUnwrapRequested, findWrap, getConfidentialTokenAddressContract, getDelegationExpiryContract, getTokenAddressContract, getTokenPairContract, getTokenPairsContract, getTokenPairsLengthContract, getTokenPairsSliceContract, hardhat, hoodi, indexedDBStorage, inferredTotalSupplyContract, ingenTestnet, invalidateDecryptionSignaturesBeforeContract, isConfidentialTokenContract, isConfidentialTokenValidContract, isConfidentialWrapperContract, isEncryptedValueZero, isHandleDelegatedContract, isOperatorContract, isRetryable, mainnet, matchZamaError, memoryStorage, nameContract, polygon, polygonAmoy, rateContract, retryAfterSeconds, revokeDelegationContract, sepolia, setOperatorContract, supportsInterfaceContract, symbolContract, transferAndCallContract, underlyingContract, unwrapContract, unwrapFromBalanceContract, unwrapRequesterContract, wrapContract };
108
- //# sourceMappingURL=index.d.ts.map
1
+ import { a as hoodi, c as polygon, d as AtLeastOneChain, f as FheChain, i as hardhat, l as polygonAmoy, n as bscTestnet, o as ingenTestnet, p as FheChainAuth, r as chains, s as mainnet, t as anvil, u as sepolia } from "./index-ijgDL4IC.js";
2
+ import { $ as SetOperatorSubmittedEvent, $t as TransactionReceipt, A as WalletAccountListener, At as DelegatedForUserDecryptionEvent, B as ApproveUnderlyingSubmittedEvent, Bt as decodeConfidentialTransfer, C as TransferAndCallRequest, Ct as ShieldCallbacks, D as GenericSigner, Dt as AclEvent, E as WrapRequest, Et as ACL_TOPICS, F as ReadContractReturnType, Ft as UnwrapFinalizedEvent, G as DelegationSubmittedEvent, Gt as decodeUnwrapFinalized, H as DecryptEndEvent, Ht as decodeOnChainEvent, I as ReadFunctionName, It as UnwrapRequestedEvent, J as EncryptStartEvent, Jt as findDelegatedForUserDecryption, K as EncryptEndEvent, Kt as decodeUnwrapRequested, L as WriteContractArgs, Lt as WrapEvent, M as ContractAbi, Mt as RevokedDelegationForUserDecryptionEvent, N as ReadContractArgs, Nt as TOKEN_TOPICS, O as WalletAccount, Ot as AclTopics, P as ReadContractConfig, Pt as Topics, Q as RevokeDelegationSubmittedEvent, Qt as RawLog, R as WriteContractConfig, Rt as decodeAclEvent, S as TransactionKind, St as WrapOptions, T as UnwrapRequest, Tt as UnshieldCallbacks, U as DecryptErrorEvent, Ut as decodeOnChainEvents, V as BaseEvent, Vt as decodeDelegatedForUserDecryption, W as DecryptStartEvent, Wt as decodeRevokedDelegationForUserDecryption, X as PermitErrorEvent, Xt as findUnwrapRequested, Y as FinalizeUnwrapSubmittedEvent, Yt as findRevokedDelegationForUserDecryption, Z as PermitOperation, Zt as findWrap, _ as PrepareTransactionRequest, _t as ShieldOptions, a as ZamaConfigBase, an as EncryptInput, at as UnshieldPhase1SubmittedEvent, b as RevokeDelegationRequest, bt as UnshieldOptions, c as GenericStorage, cn as EncryptedValue, ct as UnwrapSubmittedEvent, d as ConfidentialTransferFromRequest, dn as FhevmRelayerOptions, dt as WrapSubmittedEvent, en as TransactionResult, et as ShieldSubmittedEvent, f as ConfidentialTransferRequest, fn as FhevmRuntimeConfig, ft as ZamaSDKEvent, g as PrepareOptions, gt as ApprovalStrategy, h as PrepareFees, hn as TypedValue, ht as ZamaSDKEvents, i as ZamaConfig, in as EIP712TypedData, it as TransferSubmittedEvent, j as WalletAccountStore, jt as OnChainEvent, k as WalletAccountChange, kt as ConfidentialTransferEvent, l as GenericProvider, ln as FhevmClient, lt as VaultOperation, m as FinalizeUnwrapRequest, mn as RelayerSDK, mt as ZamaSDKEventType, n as RelayerConfig, nn as DecryptPublicValuesResult, nt as TransactionOperation, o as ZamaConfigGeneric, on as EncryptParams, ot as UnshieldPhase2StartedEvent, p as DelegateDecryptionRequest, pn as RelayerOptions, pt as ZamaSDKEventListener, q as EncryptErrorEvent, qt as decodeWrap, rn as DecryptValuesParameters, rt as TransferFromSubmittedEvent, s as GenericLogger, sn as EncryptResult, st as UnshieldPhase2SubmittedEvent, t as CleartextRelayerConfig, tn as ClearValue, tt as TransactionErrorEvent, u as ApproveUnderlyingRequest, un as FhevmClientOptions, ut as VaultSubmittedEvent, v as PreparedFor, vt as ShieldPath, w as UnwrapAllRequest, wt as TransferCallbacks, x as SetOperatorRequest, xt as UnwrapResult, y as PreparedTransaction, yt as TransferOptions, z as WriteFunctionName, zt as decodeAclEvents } from "./types-Bz5-wHPv.js";
3
+ import { t as cleartext } from "./cleartext-3HOk1BAg.js";
4
+ import { t as ZamaConfigEthers } from "./types-v0_sfkli.js";
5
+ import { n as MutableWalletAccountStore, r as createWalletAccountStore, t as BaseSigner } from "./base-signer-DIYZwDnc.js";
6
+ import { $ as BalanceErrorDetails, $t as ERC7984_INTERFACE_ID, A as BatchDecryptAsOptions, At as Permission, B as TransactionRevertedError, Bt as getConfidentialTokenAddressContract, C as ZamaSDKOptions, Cn as wrapContract, Ct as TransportKeyPairChangedError, D as WrappersRegistryConfig, Dt as ZamaErrorCode, E as WrappersRegistry, Et as ZamaError, F as Permits, Ft as SerializedTransportKeyPair, G as SignerRequiredError, Gt as getTokenPairsSliceContract, H as SigningFailedError, Ht as getTokenPairContract, I as ErrorForCode, It as ChecksummedAddress, J as RpcRateLimitError, Jt as getDelegationExpiryContract, K as WalletAccountNotReadyError, Kt as isConfidentialTokenValidContract, L as matchZamaError, Lt as PaginatedResult, M as Offline, Mt as PreparedPermit, N as Delegations, Nt as SerializedPermit, O as WrappedToken, Ot as isRetryable, P as DelegationStatus, Pt as SerializedPermitEip712, Q as BalanceCheckUnavailableError, Qt as ERC1363_INTERFACE_ID, R as UnshieldAlreadyFinalizedDetails, Rt as TokenWrapperPair, S as ZamaSDK, Sn as unwrapRequesterContract, St as RevokedKmsContextError, T as ListPairsOptions, Tt as ChainMismatchError, U as SigningRejectedError, Ut as getTokenPairsContract, V as SigningErrorMetadata, Vt as getTokenAddressContract, W as SignerNotConfiguredError, Wt as getTokenPairsLengthContract, X as ConfigurationError, Xt as revokeDelegationContract, Y as NotEntitledError, Yt as isHandleDelegatedContract, Z as RelayerRequestFailedError, Zt as transferAndCallContract, _n as rateContract, _t as InvalidTransportKeyPairError, a as ChromeSessionStorage, an as approveContract, at as EncryptOffloadUnavailableError, bn as unwrapContract, bt as PreparedPermitChainMismatchError, c as indexedDBStorage, cn as nameContract, ct as DelegationContractIsSelfError, d as Decryption, dn as confidentialTotalSupplyContract, dt as DelegationExpirationTooSoonError, en as ERC7984_WRAPPER_INTERFACE_ID, et as ERC20ReadFailedError, f as BatchDecryptItem, fn as confidentialTransferContract, ft as DelegationExpiredError, g as EncryptedInput, gn as isOperatorContract, gt as DelegationSelfNotAllowedError, h as DecryptResult, hn as inferredTotalSupplyContract, ht as DelegationNotPropagatedError, i as isEncryptedValueZero, in as allowanceContract, it as DecryptionFailedError, j as Token, jt as PreparePermitRequest, k as BatchBalancesResult, kt as retryAfterSeconds, l as MemoryStorage, ln as symbolContract, lt as DelegationCooldownError, m as DelegatedDecryptOptions, mn as finalizeUnwrapContract, mt as DelegationNotFoundError, n as Hex, nn as isConfidentialWrapperContract, nt as InsufficientConfidentialBalanceError, o as chromeSessionStorage, on as balanceOfContract, ot as EncryptionFailedError, p as BatchDecryptResult, pn as confidentialTransferFromContract, pt as DelegationExpiryUnchangedError, q as WalletNotConnectedError, qt as delegateForUserDecryptionContract, r as ZERO_ENCRYPTED_VALUE, rn as supportsInterfaceContract, rt as InsufficientERC20BalanceError, s as IndexedDBStorage, sn as decimalsContract, st as AclPausedError, t as Address, tn as isConfidentialTokenContract, tt as InsufficientAllowanceError, u as memoryStorage, un as confidentialBalanceOfContract, ut as DelegationDelegateEqualsContractError, vn as setOperatorContract, vt as KeyWrappingError, w as DefaultRegistryAddresses, wn as createConfig, wt as TransportKeyPairExpiredError, xn as unwrapFromBalanceContract, xt as PreparedPermitExpiredError, yn as underlyingContract, yt as NoCiphertextError, z as UnshieldAlreadyFinalizedError, zt as TokenWrapperPairWithMetadata } from "./index-DJYq1rAB.js";
7
+ import { t as ZamaConfigViem } from "./types-CI6BtpB7.js";
8
+ export { ACL_TOPICS, type AclEvent, AclPausedError, AclTopics, type Address, type ApprovalStrategy, type ApproveUnderlyingRequest, type ApproveUnderlyingSubmittedEvent, type AtLeastOneChain, BalanceCheckUnavailableError, type BalanceErrorDetails, type BaseEvent, BaseSigner, type BatchBalancesResult, type BatchDecryptAsOptions, type BatchDecryptItem, type BatchDecryptResult, ChainMismatchError, type ChecksummedAddress, ChromeSessionStorage, type ClearValue, type CleartextRelayerConfig, type ConfidentialTransferEvent, type ConfidentialTransferFromRequest, type ConfidentialTransferRequest, ConfigurationError, type ContractAbi, type DecryptEndEvent, type DecryptErrorEvent, type EncryptedInput as DecryptInput, type DecryptPublicValuesResult, type DecryptResult, type DecryptStartEvent, type DecryptValuesParameters, Decryption, DecryptionFailedError, DefaultRegistryAddresses, type DelegateDecryptionRequest, type DelegatedDecryptOptions, type DelegatedForUserDecryptionEvent, DelegationContractIsSelfError, DelegationCooldownError, DelegationDelegateEqualsContractError, DelegationExpirationTooSoonError, DelegationExpiredError, DelegationExpiryUnchangedError, DelegationNotFoundError, DelegationNotPropagatedError, DelegationSelfNotAllowedError, type DelegationStatus, type DelegationSubmittedEvent, Delegations, type EIP712TypedData, ERC1363_INTERFACE_ID, ERC20ReadFailedError, ERC7984_INTERFACE_ID, ERC7984_WRAPPER_INTERFACE_ID, type EncryptEndEvent, type EncryptErrorEvent, type EncryptInput, EncryptOffloadUnavailableError, type EncryptParams, type EncryptResult, type EncryptStartEvent, type EncryptedValue, EncryptionFailedError, type ErrorForCode, type FheChain, type FheChainAuth, type FhevmClient, type FhevmClientOptions, type FhevmRelayerOptions, type FhevmRuntimeConfig, type FinalizeUnwrapRequest, type FinalizeUnwrapSubmittedEvent, type GenericLogger, type GenericProvider, type GenericSigner, type GenericStorage, type Hex, IndexedDBStorage, InsufficientAllowanceError, InsufficientConfidentialBalanceError, InsufficientERC20BalanceError, InvalidTransportKeyPairError, KeyWrappingError, type ListPairsOptions, MemoryStorage, MutableWalletAccountStore, NoCiphertextError, NotEntitledError, Offline, type OnChainEvent, type PaginatedResult, type Permission, type PermitErrorEvent, type PermitOperation, Permits, type PrepareFees, type PrepareOptions, type PreparePermitRequest, type PrepareTransactionRequest, type PreparedFor, type PreparedPermit, PreparedPermitChainMismatchError, PreparedPermitExpiredError, type PreparedTransaction, type RawLog, type ReadContractArgs, type ReadContractConfig, type ReadContractReturnType, type ReadFunctionName, type RelayerConfig, type RelayerOptions, RelayerRequestFailedError, type RelayerSDK, type RevokeDelegationRequest, type RevokeDelegationSubmittedEvent, type RevokedDelegationForUserDecryptionEvent, RevokedKmsContextError, RpcRateLimitError, type SerializedPermit, type SerializedPermitEip712, type SerializedTransportKeyPair, type SetOperatorRequest, type SetOperatorSubmittedEvent, type ShieldCallbacks, type ShieldOptions, type ShieldPath, type ShieldSubmittedEvent, SignerNotConfiguredError, SignerRequiredError, type SigningErrorMetadata, SigningFailedError, SigningRejectedError, TOKEN_TOPICS, Token, type TokenWrapperPair, type TokenWrapperPairWithMetadata, Topics, type TransactionErrorEvent, type TransactionKind, type TransactionOperation, type TransactionReceipt, type TransactionResult, TransactionRevertedError, type TransferAndCallRequest, type TransferCallbacks, type TransferFromSubmittedEvent, type TransferOptions, type TransferSubmittedEvent, TransportKeyPairChangedError, TransportKeyPairExpiredError, type TypedValue, type UnshieldAlreadyFinalizedDetails, UnshieldAlreadyFinalizedError, type UnshieldCallbacks, type UnshieldOptions, type UnshieldPhase1SubmittedEvent, type UnshieldPhase2StartedEvent, type UnshieldPhase2SubmittedEvent, type UnwrapAllRequest, type UnwrapFinalizedEvent, type UnwrapRequest, type UnwrapRequestedEvent, type UnwrapResult, type UnwrapSubmittedEvent, type VaultOperation, type VaultSubmittedEvent, type WalletAccount, type WalletAccountChange, type WalletAccountListener, WalletAccountNotReadyError, type WalletAccountStore, WalletNotConnectedError, type WrapEvent, type WrapOptions, type WrapRequest, type WrapSubmittedEvent, WrappedToken, WrappersRegistry, type WrappersRegistryConfig, type WriteContractArgs, type WriteContractConfig, type WriteFunctionName, ZERO_ENCRYPTED_VALUE, type ZamaConfig, type ZamaConfigBase, type ZamaConfigEthers, type ZamaConfigGeneric, type ZamaConfigViem, ZamaError, ZamaErrorCode, ZamaSDK, type ZamaSDKEvent, type ZamaSDKEventListener, type ZamaSDKEventType, ZamaSDKEvents, type ZamaSDKOptions, allowanceContract, anvil, approveContract, balanceOfContract, bscTestnet, chains, chromeSessionStorage, cleartext, confidentialBalanceOfContract, confidentialTotalSupplyContract, confidentialTransferContract, confidentialTransferFromContract, createConfig, createWalletAccountStore, decimalsContract, decodeAclEvent, decodeAclEvents, decodeConfidentialTransfer, decodeDelegatedForUserDecryption, decodeOnChainEvent, decodeOnChainEvents, decodeRevokedDelegationForUserDecryption, decodeUnwrapFinalized, decodeUnwrapRequested, decodeWrap, delegateForUserDecryptionContract, finalizeUnwrapContract, findDelegatedForUserDecryption, findRevokedDelegationForUserDecryption, findUnwrapRequested, findWrap, getConfidentialTokenAddressContract, getDelegationExpiryContract, getTokenAddressContract, getTokenPairContract, getTokenPairsContract, getTokenPairsLengthContract, getTokenPairsSliceContract, hardhat, hoodi, indexedDBStorage, inferredTotalSupplyContract, ingenTestnet, isConfidentialTokenContract, isConfidentialTokenValidContract, isConfidentialWrapperContract, isEncryptedValueZero, isHandleDelegatedContract, isOperatorContract, isRetryable, mainnet, matchZamaError, memoryStorage, nameContract, polygon, polygonAmoy, rateContract, retryAfterSeconds, revokeDelegationContract, sepolia, setOperatorContract, supportsInterfaceContract, symbolContract, transferAndCallContract, underlyingContract, unwrapContract, unwrapFromBalanceContract, unwrapRequesterContract, wrapContract };
package/dist/esm/index.js CHANGED
@@ -1,2 +1,2 @@
1
- import{S as e,_ as t,a as n,c as r,d as i,g as a,h as o,i as s,m as c,n as l,o as u,p as d,r as f,s as p,t as m,v as ee,w as h,y as g}from"./relayer-B6Zo6EkX.js";import{$ as te,A as ne,C as re,D as ie,F as _,G as v,I as ae,K as y,L as b,M as oe,N as se,O as ce,P as le,S as ue,T as de,U as x,W as fe,X as pe,Z as S,_ as me,_t as he,a as ge,at as _e,b as ve,c as ye,ct as be,d as xe,dt as Se,et as Ce,f as we,ft as Te,g as C,gt as Ee,h as w,ht as T,i as De,it as E,j as Oe,k as ke,l as Ae,lt as je,m as Me,mt as Ne,n as Pe,nt as Fe,o as Ie,ot as Le,p as Re,pt as ze,r as Be,rt as D,s as Ve,t as He,tt as Ue,u as We,ut as Ge,v as Ke,vt as qe,x as Je,yt as Ye,z as Xe}from"./wrappers-registry-BfQr2QHn.js";import{n as Ze,r as O,t as k}from"./encryption-DJljZ2oV.js";import{a as Qe,c as $e,d as A,f as et,g as j,h as tt,i as M,l as nt,m as rt,n as it,o as at,p as ot,r as st,s as ct,t as N,u as lt}from"./token-BMQ6xlrk.js";import{t as ut}from"./cleartext-DcbDCDXj.js";import{a as dt,c as ft,d as pt,f as mt,i as ht,l as gt,m as _t,n as vt,o as yt,p as bt,r as xt,s as St,t as Ct,u as wt}from"./base-signer--sBO2qJp.js";import{t as P}from"./validation-DWe2k89s.js";import{a as Tt,c as Et,i as Dt,l as Ot,n as kt,o as At,r as jt,s as Mt,t as Nt,u as Pt}from"./chains-DEpKup1n.js";import{r as Ft,t as It}from"./assertions-Ca1ePdRJ.js";import{getAddress as F,keccak256 as Lt,size as Rt,toBytes as zt,zeroAddress as Bt}from"viem";import{z as I}from"zod/mini";function Vt(e,t){if(e instanceof f){let n=t[e.code];if(n)return n(e)}return t._?.(e)}var Ht=class extends f{encryptedValue;contractAddress;account;constructor(e,t){super(s.NotEntitled,`Account ${e.account} is not entitled to decrypt encrypted value ${e.encryptedValue} on contract ${e.contractAddress}. This is not a transient failure — the account needs an on-chain ACL grant before it can decrypt this encrypted value.`,t),this.name=`NotEntitledError`,this.encryptedValue=e.encryptedValue,this.contractAddress=e.contractAddress,this.account=e.account}},L=class extends f{constructor(e,t){super(s.DelegationSelfNotAllowed,e,t),this.name=`DelegationSelfNotAllowedError`}},Ut=class extends f{constructor(e,t){super(s.DelegationCooldown,e,t),this.name=`DelegationCooldownError`}},R=class extends f{constructor(e,t){super(s.DelegationNotFound,e,t),this.name=`DelegationNotFoundError`}},Wt=class extends f{constructor(e,t){super(s.DelegationExpired,e,t),this.name=`DelegationExpiredError`}},z=class extends f{constructor(e,t){super(s.DelegationExpiryUnchanged,e,t),this.name=`DelegationExpiryUnchangedError`}},B=class extends f{constructor(e,t){super(s.DelegationDelegateEqualsContract,e,t),this.name=`DelegationDelegateEqualsContractError`}},Gt=class extends f{constructor(e,t){super(s.DelegationDelegateCannotBeWildcard,e,t),this.name=`DelegationDelegateCannotBeWildcardError`}},Kt=class extends f{constructor(e,t){super(s.DelegationContractIsSelf,e,t),this.name=`DelegationContractIsSelfError`}},qt=class extends f{constructor(e,t){super(s.AclPaused,e,t),this.name=`AclPausedError`}},V=class extends f{constructor(e,t){super(s.DelegationExpirationTooSoon,e,t),this.name=`DelegationExpirationTooSoonError`}},H=class extends f{constructor(e,t){super(s.DelegationNotPropagated,e,t),this.name=`DelegationNotPropagatedError`}};function Jt(e){if(!(e instanceof Error))return null;let t=e.cause;if(typeof t!=`object`||!t||!(`data`in t))return null;let{data:n}=t;return typeof n!=`object`||!n||!(`errorName`in n)?null:typeof n.errorName==`string`?n.errorName:null}var Yt=class extends f{unwrapTxHash;unwrapRequestId;constructor(e,t,n){super(s.UnshieldAlreadyFinalized,e,n),this.name=`UnshieldAlreadyFinalizedError`,this.unwrapTxHash=t.unwrapTxHash,this.unwrapRequestId=t.unwrapRequestId}};const Xt=`InvalidUnwrapRequest`,Zt=Lt(zt(`${Xt}(bytes32)`)).slice(0,10);function Qt(e){for(let t=e;t instanceof Error;t=t.cause)if(Jt(t)===Xt||t.message.includes(Xt)||t.message.includes(Zt))return!0;return!1}const $t=[k,Te,l,H,Le,_e,Ht,j,be,T,qe];function U(n,s,u={}){if($t.some(e=>n instanceof e))return n;let f=n instanceof Error?n.message:s;if(n instanceof Error&&d(n.message))return new be(n.message,{cause:n});if(t(n))return new T(`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:n});if(n instanceof Error&&g(n.message))return new qe(`This account's stored permit for this scope is a wildcard (V2) permit, but the connected relayer does not yet support unified decryption (/v3/user-decrypt). Grant a specific-contract permit instead (sdk.permits.grantPermit([...])), or retry once the relayer upgrades.`,{cause:n});if(n instanceof Error&&c(n.message))return u.isDelegated?new H(`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:n}):new Ht({encryptedValue:e(n.message)??``,contractAddress:u.contractAddress??``,account:u.account??``},{cause:n});if(i(n))return new j(f,{cause:n,retryAfter:r(n)});let m=p(n);return m===void 0&&ee(n)?new j(f,{cause:n,retryAfter:r(n)}):m===400?new Te(n instanceof Error?n.message:`No ciphertext for this account`,{cause:n}):u.isDelegated&&m===500?new H(`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:n}):o(n)||m!==void 0?new l(f,m,{cause:n,retryAfter:r(n),retryable:a(n)||void 0}):new k(s,{cause:n})}function en(e,t){if(e instanceof f)return e;let n=p(e),i=a(e);return n!==void 0||o(e)?new l(e instanceof Error?e.message:t,n,{cause:e,retryAfter:r(e),retryable:i||void 0}):new O(t,{cause:e})}const tn=[{type:`function`,name:`allowance`,inputs:[{name:`owner`,type:`address`,internalType:`address`},{name:`spender`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`approve`,inputs:[{name:`spender`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`approveAndCall`,inputs:[{name:`spender`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`approveAndCall`,inputs:[{name:`spender`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`},{name:`data`,type:`bytes`,internalType:`bytes`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`balanceOf`,inputs:[{name:`account`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`supportsInterface`,inputs:[{name:`interfaceId`,type:`bytes4`,internalType:`bytes4`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`totalSupply`,inputs:[],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`transfer`,inputs:[{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`transferAndCall`,inputs:[{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`transferAndCall`,inputs:[{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`},{name:`data`,type:`bytes`,internalType:`bytes`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`transferFrom`,inputs:[{name:`from`,type:`address`,internalType:`address`},{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`transferFromAndCall`,inputs:[{name:`from`,type:`address`,internalType:`address`},{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`},{name:`data`,type:`bytes`,internalType:`bytes`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`transferFromAndCall`,inputs:[{name:`from`,type:`address`,internalType:`address`},{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`event`,name:`Approval`,inputs:[{name:`owner`,type:`address`,indexed:!0,internalType:`address`},{name:`spender`,type:`address`,indexed:!0,internalType:`address`},{name:`value`,type:`uint256`,indexed:!1,internalType:`uint256`}],anonymous:!1},{type:`event`,name:`Transfer`,inputs:[{name:`from`,type:`address`,indexed:!0,internalType:`address`},{name:`to`,type:`address`,indexed:!0,internalType:`address`},{name:`value`,type:`uint256`,indexed:!1,internalType:`uint256`}],anonymous:!1}];function nn(e,t,n,r=`0x`){return{address:e,abi:tn,functionName:`transferAndCall`,args:[t,n,r]}}const W=[{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:`invalidateDecryptionSignaturesBefore`,inputs:[{name:`timestamp`,type:`uint256`,internalType:`uint256`}],outputs:[],stateMutability:`nonpayable`},{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 G(e,t,n,r){return{address:e,abi:W,functionName:`delegateForUserDecryption`,args:[t,n,r]}}function rn(e,t,n){return{address:e,abi:W,functionName:`revokeDelegationForUserDecryption`,args:[t,n]}}function an(e,t){return{address:e,abi:W,functionName:`invalidateDecryptionSignaturesBefore`,args:[t]}}function on(e,t,n,r){return{address:e,abi:W,functionName:`getUserDecryptionDelegationExpirationDate`,args:[t,n,r]}}function sn(e,t,n,r,i){return{address:e,abi:W,functionName:`isHandleDelegatedForUserDecryption`,args:[t,n,r,i]}}const K=2n**64n-1n,q=`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`;function cn(e){return ht(e.signer,e.provider,e)}function ln(e){return e.startsWith(`0x`)?e:`0x${e}`}function J(e){return Lt(zt(e))}const Y={ConfidentialTransfer:J(`ConfidentialTransfer(address,address,bytes32)`),Wrap:J(`Wrap(address,uint256,bytes32)`),UnwrapRequested:J(`UnwrapRequested(address,bytes32,bytes32)`),UnwrapFinalized:J(`UnwrapFinalized(address,bytes32,bytes32,uint64)`)};function X(e){return F(ln(e.slice(-40)))}function un(e){return e}function dn(e,t){let n=2+t*64,r=e.slice(n,n+64);return r.length===64?r:r.padEnd(64,`0`)}function fn(e,t){return F(ln(dn(e,t).slice(-40)))}function Z(e,t){return BigInt(`0x`+dn(e,t))}function pn(e,t){return ln(dn(e,t))}function mn(e){return e.topics[0]!==Y.ConfidentialTransfer||e.topics.length<4?null:{eventName:`ConfidentialTransfer`,from:X(e.topics[1]),to:X(e.topics[2]),encryptedAmount:un(e.topics[3])}}function hn(e){return e.topics[0]!==Y.Wrap||e.topics.length<2?null:{eventName:`Wrap`,to:X(e.topics[1]),roundedAmount:Z(e.data,0),encryptedWrappedAmount:pn(e.data,1)}}function gn(e){return e.topics[0]!==Y.UnwrapRequested||e.topics.length<3?null:{eventName:`UnwrapRequested`,receiver:X(e.topics[1]),unwrapRequestId:un(e.topics[2]),encryptedAmount:pn(e.data,0)}}function _n(e){return e.topics[0]!==Y.UnwrapFinalized||e.topics.length<3?null:{eventName:`UnwrapFinalized`,receiver:X(e.topics[1]),unwrapRequestId:un(e.topics[2]),encryptedAmount:pn(e.data,0),cleartextAmount:Z(e.data,1)}}function vn(e){return mn(e)??hn(e)??gn(e)??_n(e)}function yn(e){let t=[];for(let n of e){let e=vn(n);e&&t.push(e)}return t}function bn(e){for(let t of e){let e=gn(t);if(e)return e}return null}function xn(e){for(let t of e){let e=hn(t);if(e)return e}return null}const Sn=[Y.ConfidentialTransfer,Y.Wrap,Y.UnwrapRequested,Y.UnwrapFinalized],Q={DelegatedForUserDecryption:J(`DelegatedForUserDecryption(address,address,address,uint64,uint64,uint64)`),RevokedDelegationForUserDecryption:J(`RevokedDelegationForUserDecryption(address,address,address,uint64,uint64)`)};function Cn(e){return e.topics[0]!==Q.DelegatedForUserDecryption||e.topics.length<3?null:{eventName:`DelegatedForUserDecryption`,delegator:X(e.topics[1]),delegate:X(e.topics[2]),contractAddress:fn(e.data,0),delegationCounter:Z(e.data,1),oldExpirationDate:Z(e.data,2),newExpirationDate:Z(e.data,3)}}function wn(e){return e.topics[0]!==Q.RevokedDelegationForUserDecryption||e.topics.length<3?null:{eventName:`RevokedDelegationForUserDecryption`,delegator:X(e.topics[1]),delegate:X(e.topics[2]),contractAddress:fn(e.data,0),delegationCounter:Z(e.data,1),oldExpirationDate:Z(e.data,2)}}function Tn(e){return Cn(e)??wn(e)}function En(e){let t=[];for(let n of e){let e=Tn(n);e&&t.push(e)}return t}function Dn(e){for(let t of e){let e=Cn(t);if(e)return e}return null}function On(e){for(let t of e){let e=wn(t);if(e)return e}return null}const kn=[Q.DelegatedForUserDecryption,Q.RevokedDelegationForUserDecryption];var An=class{#e;#t;#n;#r;#i;#a;#o;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.cachingService,this.#r=e.credentialService,this.#i=e.delegationService,this.#a=e.logger,this.#o=e.emitEvent}#s(e){return D(this.#e,e)}#c(e){return D(this.#r,e)}#l(e,t){throw this.#o({type:S.PermitError,operation:e,error:t instanceof Error?t:Error(String(t))}),t}async grantPermit(e){if(Array.isArray(e)&&e.length===0)return;let t;try{t=this.#c(`grantPermit`),await Qe(`grantPermit`,this.#e,this.#t)}catch(e){this.#l(`grantPermit`,e)}await t.grantPermit(e)}async grantDelegationPermit(e,t){if(Array.isArray(t)&&t.length===0)return;let n;try{n=this.#c(`grantDelegationPermit`),await Qe(`grantDelegationPermit`,this.#e,this.#t)}catch(e){this.#l(`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.#c(`registerPermit`)}catch(e){this.#l(`registerPermit`,e)}await n.registerPermit(e,t),await this.#u(e.signerAddress)}async revokePermits(e){let t=this.#c(`revokePermits`),n=F((await M(`revokePermits`,this.#e,this.#t)).address);try{await t.revokePermits(e)}finally{await this.#u(n)}}async clear(){let e=this.#c(`clear`),t=F((await M(`clear`,this.#e,this.#t)).address);try{await e.clearCredentials()}finally{await this.#u(t)}}async#u(e){await x(`clear decrypt cache`,()=>this.#n.clearForRequester(e),this.#a)}async revokeTransportKeyPair(e){await this.#c(`revokeTransportKeyPair`).revokeTransportKeyPair(e)}async warmTransportKeyPairScope(e){await this.#c(`warmTransportKeyPairScope`).warmTransportKeyPairScope(e)}async invalidateDecryptionSignatures(e){let t=this.#c(`invalidateDecryptionSignatures`),n=this.#s(`invalidateDecryptionSignatures`),r=await M(`invalidateDecryptionSignatures`,this.#e,this.#t),i=fe(r.address),a=await this.#i.invalidateDecryptionSignaturesBefore(n,e);return await t.clearPermitsAfterInvalidation(i),await this.#u(F(r.address)),a}},jn=class{#e;#t;#n;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.delegationService}#r(e){return D(this.#e,e)}async delegateDecryption({contractAddress:e,delegateAddress:t,expirationDate:n}){let r=this.#r(`delegateDecryption`),i=await M(`delegateDecryption`,this.#e,this.#t);return this.#n.delegateDecryption(r,{contractAddress:e,delegateAddress:t,delegatorAddress:i.address,expirationDate:n})}async revokeDelegation({contractAddress:e,delegateAddress:t}){let n=this.#r(`revokeDelegation`),r=await M(`revokeDelegation`,this.#e,this.#t);return this.#n.revokeDelegation(n,{contractAddress:e,delegateAddress:t,delegatorAddress:r.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)}},Mn=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 D(this.#r,e)}async decryptValues(e,t){let n=this.#i(`decryptValues`),r=await M(`decryptValues`,this.#e,this.#t);return n.decryptValues(e,r.address,t)}async delegatedDecryptValues(e,t,n=t,r){let i=this.#i(`delegatedDecryptValues`),a=await M(`delegatedDecryptValues`,this.#e,this.#t);return i.delegatedDecryptValues(e,t,a.address,n,r)}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)=>{Ft(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 U(e,`Public decryption failed`)}}async delegatedBatchDecryptValues({encryptedInputs:e,delegatorAddress:t,accountAddress:n=t,maxConcurrency:r,waitForPropagation:i}){let a=this.#i(`delegatedBatchDecryptValues`),o=await M(`delegatedBatchDecryptValues`,this.#e,this.#t);return a.delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:o.address,accountAddress:n,maxConcurrency:r,waitForPropagation:i})}},Nn=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)}},Pn=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 Fn=new Pn;function $(e){return`zama:pending-unshield:${fe(e)}`}const In=I.union([I.pipe(y,I.transform(e=>({unwrapTxHash:e}))),I.pipe(I.object({version:I.literal(1),unwrapTxHash:y,unwrapRequestId:I.optional(y)}),I.transform(({unwrapTxHash:e,unwrapRequestId:t})=>({unwrapTxHash:e,unwrapRequestId:t})))]);async function Ln(e,t,n,r){if(r===void 0){await e.set($(t),n);return}await e.set($(t),{version:1,unwrapTxHash:n,unwrapRequestId:r})}async function Rn(e,t){let n=$(t),r=await e.get(n);if(r==null)return null;let i=In.safeParse(r);return i.success?i.data:(await e.delete(n),null)}async function zn(e,t){await e.delete($(t))}var Bn=class extends N{#e;#t=null;#n=null;#r(e){try{return Ft(this.sdk.signer,`WrappedToken.sdk.signer`),this.sdk.signer}catch(t){throw new te(e,{cause:t})}}async underlying(){return this.#u()}async isPayable(){if(this.#n!==null)return this.#n;try{let e=await this.#u();this.#n=await this.sdk.provider.readContract(Re(e))}catch{this.#n=!1}return this.#n}async allowance(e){let t=await this.#u();return this.sdk.provider.readContract(w(t,F(e),this.address))}async shield(e,t){let n=await M(`shield`,this.sdk.signer,this.sdk.provider),r=await this.isPayable(),i=await this.#u(),a=F(n.address),o;try{o=await this.sdk.provider.readContract(me(i,a))}catch(e){throw e instanceof f?e:new A(`Could not read ERC-20 balance for shield validation (token: ${i})`,{cause:h(e)})}if(o<e)throw new rt(`Insufficient ERC-20 balance: requested ${e}, available ${o} (token: ${i})`,{requested:e,available:o,token:i});return r?this.#i(e,i,a,t):this.#a(e,a,t)}async#i(e,t,n,r){this.#r(`shield`);let i=r?.to?F(r.to):n,a=i===n?`0x`:i;return this.submitTransaction({operation:`shield:transferAndCall`,config:nn(t,this.address,e,a),onSubmitted:r?.onShieldSubmitted})}async wrap(e,t){this.#r(`wrap`);let n=await M(`wrap`,this.sdk.signer,this.sdk.provider),r=await this.#u(),i=F(n.address),a;try{a=await this.sdk.provider.readContract(me(r,i))}catch(e){throw e instanceof f?e:new A(`Could not read ERC-20 balance for wrap validation (token: ${r})`,{cause:h(e)})}if(a<e)throw new rt(`Insufficient ERC-20 balance: requested ${e}, available ${a} (token: ${r})`,{requested:e,available:a,token:r});let o;try{o=await this.sdk.provider.readContract(w(r,i,this.address))}catch(e){throw e instanceof f?e:new A(`Could not read ERC-20 allowance for wrap validation (token: ${r})`,{cause:h(e)})}if(o<e)throw new et(`Insufficient allowance for wrap: requested ${e}, approved ${o}. Call approveUnderlying() first (token: ${r}).`,{requested:e,available:o,token:r});let s=t?.to?F(t.to):i;return this.submitTransaction({operation:`wrap`,config:b(this.address,s,e),onSubmitted:t?.onWrapSubmitted})}async#a(e,t,n){this.#r(`shield`);let r=n?.approvalStrategy??`exact`;r!==`skip`&&await this.#f(e,r===`max`,n);let i=n?.to?F(n.to):t;return this.submitTransaction({operation:`shield:approveAndWrap`,config:b(this.address,i,e),onSubmitted:n?.onShieldSubmitted})}async approveUnderlying(e){this.#r(`approveUnderlying`);let t=await M(`approveUnderlying`,this.sdk.signer,this.sdk.provider),n=await this.#u(),r=F(t.address),i=e??2n**256n-1n;return i>0n&&await this.sdk.provider.readContract(w(n,r,this.address))>0n&&await this.submitTransaction({operation:`approveUnderlying:reset`,config:C(n,this.address,0n)}),this.submitTransaction({operation:`approveUnderlying`,config:C(n,this.address,i)})}async unshield(e,t){let{skipBalanceCheck:n=!1,onUnwrapSubmitted:r,onFinalizing:i,onFinalizeSubmitted:a}=t??{};n||await this.assertConfidentialBalance(e);let o={onFinalizing:i,onFinalizeSubmitted:a},s=crypto.randomUUID(),c=await this.unwrap(e);return x(`unshield: onUnwrapSubmitted`,()=>r?.(c.txHash),this.sdk.logger),this.#d(c.unwrapRequestId,c.txHash,s,o)}async unshieldAll(e){let t=crypto.randomUUID(),n=await this.unwrapAll();return x(`unshieldAll: onUnwrapSubmitted`,()=>e?.onUnwrapSubmitted?.(n.txHash),this.sdk.logger),this.#d(n.unwrapRequestId,n.txHash,t,e)}async resumeUnshield(e,t){let n;try{n=await this.sdk.provider.waitForTransactionReceipt(e)}catch(e){throw e instanceof f?e:new E(`Failed to get unwrap receipt`,{cause:e})}let r=this.#o(n.logs);if(await this.#s(r))throw await this.#l(`resumeUnshield`),new Yt(`Nothing to resume: the unwrap request was already finalized on-chain and the funds were delivered.`,{unwrapTxHash:e,unwrapRequestId:r});return this.#d(r,e,crypto.randomUUID(),t)}async getPendingUnshield(){let e=await Rn(this.sdk.storage,this.address);return e?await this.#c(e)?(await this.#l(`getPendingUnshield`),null):e.unwrapTxHash:null}async unwrap(e){this.#r(`unwrap`);let t=F((await M(`unwrap`,this.sdk.signer,this.sdk.provider)).address),{encryptedValues:n,inputProof:r}=await this.sdk.encrypt({values:[{value:e,type:`euint64`}],contractAddress:this.address,userAddress:t}),[i]=n;if(!i)throw new O(`Encryption returned no encrypted values`);let a=await this.submitTransaction({operation:`unwrap`,config:le(this.address,t,t,i,r)});return{...a,unwrapRequestId:this.#o(a.receipt.logs)}}async unwrapAll(){this.#r(`unwrapAll`);let e=F((await M(`unwrapAll`,this.sdk.signer,this.sdk.provider)).address),t=await this.readConfidentialBalanceOf(e);if($e(t))throw new k(`Cannot unshield: balance is zero`);let n=await this.submitTransaction({operation:`unwrapAll`,config:_(this.address,e,e,t)});return{...n,unwrapRequestId:this.#o(n.receipt.logs)}}async finalizeUnwrap(e){this.#r(`finalizeUnwrap`),await Qe(`finalizeUnwrap`,this.sdk.signer,this.sdk.provider);let t=await this.sdk.decryption.decryptPublicValues([e]),n=t.clearValues[e];return It(n,`finalizeUnwrap: clearValue`),this.submitTransaction({operation:`finalizeUnwrap`,config:ce(this.address,e,n,t.decryptionProof)})}#o(e){let t=bn(e.filter(e=>e.address===void 0||F(e.address)===this.address));if(!t)throw new E(`No UnwrapRequested event from this wrapper found in the unwrap receipt`);return t.unwrapRequestId}async#s(e){try{return await this.sdk.provider.readContract(ae(this.address,e))===Bt}catch{return!1}}async#c(e){let t=e.unwrapRequestId;if(t===void 0)try{let n=await this.sdk.provider.waitForTransactionReceipt(e.unwrapTxHash);t=this.#o(n.logs)}catch{return!1}return this.#s(t)}async#l(e){await x(`${e}: clearPendingUnshield`,()=>zn(this.sdk.storage,this.address),this.sdk.logger)}async#u(){return this.#e===void 0?(this.#t||=this.sdk.provider.readContract(se(this.address)).then(e=>(this.#e=e,this.#t=null,e)).catch(e=>{throw this.#t=null,e}),this.#t):this.#e}async#d(e,t,n,r){this.emit({type:S.UnshieldPhase1Submitted,txHash:t,operationId:n}),await x(`unshield: savePendingUnshield`,()=>Ln(this.sdk.storage,this.address,t,e),this.sdk.logger),this.emit({type:S.UnshieldPhase2Started,operationId:n}),x(`unshield: onFinalizing`,()=>r?.onFinalizing?.(),this.sdk.logger);let i;try{i=await this.finalizeUnwrap(e)}catch(n){throw Qt(n)?(await this.#l(`unshield`),new Yt(`The unwrap request was finalized concurrently — the funds were already delivered.`,{unwrapTxHash:t,unwrapRequestId:e},{cause:n})):n}return this.emit({type:S.UnshieldPhase2Submitted,txHash:i.txHash,operationId:n}),x(`unshield: onFinalizeSubmitted`,()=>r?.onFinalizeSubmitted?.(i.txHash),this.sdk.logger),await this.#l(`unshield`),i}async#f(e,t,n){this.#r(`approveUnderlying`);let r=await this.#u(),i=F((await M(`approveUnderlying`,this.sdk.signer,this.sdk.provider)).address),a=await this.sdk.provider.readContract(w(r,i,this.address));if(a>=e)return;a>0n&&await this.submitTransaction({operation:`approveUnderlying:reset`,config:C(r,this.address,0n)});let o=t?2n**256n-1n:e;await this.submitTransaction({operation:`approveUnderlying`,config:C(r,this.address,o),onSubmitted:n?.onApprovalSubmitted})}};const Vn=I.union([I.bigint(),I.boolean(),v]),Hn=I.array(I.string());var Un=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=Vn.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=F(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}:${F(e)}:${F(t)}:${n.toLowerCase()}`}async#l(){let e=await this.#e.get(this.#r);if(e===null)return[];let t=Hn.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 Wn(e,t){let n=Gn(e,t);if(!n)throw new k(`No permit covers contract ${t} after allow()`);return{privateKey:e.keypair.privateKey,publicKey:e.keypair.publicKey,serializedPermit:n.serializedPermit}}function Gn(e,t){let n=fe(t);return e.permissions.find(e=>ft(e,n))}const Kn=e=>new Promise(t=>setTimeout(t,e));var qn=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=F(t);return this.#s(e,{requesterAddress:r,errorMessage:`Failed to decrypt encrypted values`},n)}async delegatedDecryptValues(e,t,n,r,i){let a=F(t),o=F(n),s={spent:!1};return this.#a(i?.waitForPropagation??!0,()=>this.#s(e,{requesterAddress:F(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 H))throw t;await Kn(2e3)}throw n}async delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:n,accountAddress:r,maxConcurrency:i=5,waitForPropagation:a=!0}){let o=e.map(e=>({encryptedValue:e.encryptedValue,contractAddress:F(e.contractAddress)}));if(o.length===0)return{items:o};let s=F(r);try{let e=await this.delegatedDecryptValues(o.map(({encryptedValue:e,contractAddress:t})=>({encryptedValue:e,contractAddress:t})),t,n,s,{waitForPropagation:a});for(let t of o)this.#d(t,e);return{items:o}}catch(e){if(nt(e))throw e;if(o.length===1){let[n=this.#p()]=o;return n.error=this.#f(e,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:n.contractAddress,account:F(t)}),{items:o}}}let c=!1,l;if(await st(o.map(e=>async()=>{if(!c)try{let r=await this.delegatedDecryptValues([{encryptedValue:e.encryptedValue,contractAddress:e.contractAddress}],t,n,s,{waitForPropagation:!1});this.#d(e,r)}catch(n){if(nt(n)){c=!0,l??=n;return}e.error=this.#f(n,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:e.contractAddress,account:F(t)})}}),i),l!==void 0)throw l;return{items:o}}async#o(e,t,n,r){let i=Wn(e,t),a;try{a=await this.#r.relayer.parseTransportKeyPair({publicKey:i.publicKey,privateKey:i.privateKey,tkmsVersion:e.keypair.tkmsVersion})}catch(e){throw e instanceof Error&&d(e.message)&&await this.#t.evictTransportKeyPair(),e}let o=await this.#r.relayer.parseSignedDecryptionPermit({transportKeyPair:a,serializedPermit:i.serializedPermit});return this.#r.relayer.decryptValues({transportKeyPair:a,signedPermit:o,encryptedValues:n,contractAddress:t,options:r})}async#s(e,t,n,r={spent:!1}){if(e.length===0)return{};let i=e.map(e=>({encryptedValue:e.encryptedValue,contractAddress:F(e.contractAddress)})),a={},o=[];for(let e of i)$e(e.encryptedValue)?a[e.encryptedValue]=0n:o.push(e);if(o.length===0)return a;let s=Array.from(new Set(i.map(e=>e.contractAddress))),c=Array.from(new Set(o.map(e=>e.contractAddress)));if(t.validate)try{await t.validate(c)}catch(e){throw ee(e)?this.#u(e,`the delegation pre-check`):e}let l=[];for(let e of o){let n=await this.#e.get(t.requesterAddress,e.contractAddress,e.encryptedValue);n===null?l.push(e):a[e.encryptedValue]=n}if(l.length===0)return a;let u=await this.#t.grantPermit(s,t.delegator),d=new Map;for(let e of l){let t=d.get(e.contractAddress);t?t.push(e.encryptedValue):d.set(e.contractAddress,[e.encryptedValue])}let p=[];for(let[e,t]of d)for(let n of ct(t))p.push({contractAddress:e,encryptedValues:n});let m=Date.now(),g=l.map(e=>e.encryptedValue);try{this.#i({type:S.DecryptStart,encryptedValues:g});try{await this.#c(t,u,p,a,n)}catch(e){if(!(e instanceof T)||r.spent)throw e;let i=u.permissions.map(e=>e.serializedPermit.signature);r.spent=!0;try{u=await this.#t.recoverPermits(s,t.delegator,i)}catch(e){throw e instanceof _e?new T(`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(t,u,p.filter(({encryptedValues:e})=>e.some(e=>a[e]===void 0)),a,n)}let e={};for(let t of g){let n=a[t];n!==void 0&&(e[t]=n)}return this.#i({type:S.DecryptEnd,durationMs:Date.now()-m,encryptedValues:g,result:e}),a}catch(e){let n=e instanceof f&&e.cause instanceof Error?e.cause:e;throw this.#i({type:S.DecryptError,error:h(n),durationMs:Date.now()-m,encryptedValues:g}),U(e,t.errorMessage,{isDelegated:t.delegator!==void 0})}}async#c(e,t,n,r,i){let a=(await st(n.map(({contractAddress:n,encryptedValues:a})=>async()=>{try{await this.#l(e,t,n,a,r,i);return}catch(e){return e}}),5)).filter(e=>e!==void 0);if(a.length>0)throw a.find(e=>e instanceof T)??a[0]}async#l(e,t,n,r,i,a){let o;try{o=await this.#o(t,n,r,a)}catch(t){throw U(t,e.errorMessage,{isDelegated:e.delegator!==void 0,contractAddress:n,account:e.delegator??e.requesterAddress})}for(let t=0;t<r.length;t++){let a=r[t],s=o[t]?.value;a!==void 0&&s!==void 0&&(i[a]=s,await this.#e.set(e.requesterAddress,n,a,s))}let s=r.filter(e=>i[e]===void 0);if(s.length>0)throw new k(`${e.errorMessage}: relayer returned no clear value for ${s.length} of ${r.length} handle(s) on ${n}`,{cause:AggregateError(s.map(e=>new k(`No clear value for handle ${e} on ${n}`)),`${s.length} handle(s) missing a clear value on ${n}`)})}#u(e,t){return new j(`RPC provider rate-limited ${t}; retry with backoff.`,{cause:e,retryAfter:r(e)})}#d(e,t){let n=t[e.encryptedValue];if(n===void 0){e.error=new k(`Batch delegated decryption returned no value for encrypted value ${e.encryptedValue} on contract ${e.contractAddress}`);return}e.value=n}#f(e,t,n){return e instanceof f?e:U(e,t,n)}#p(){throw new k(`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 Jn={AlreadyDelegatedOrRevokedInSameBlock:e=>new Ut(`Only one delegate/revoke per (delegator, delegate, contract) per block. Wait for the next block before retrying.`,{cause:e}),SenderCannotBeContractAddress:e=>new Kt(`The contract address cannot be the caller address.`,{cause:e}),EnforcedPause:e=>new qt(`The ACL contract is paused. Delegation operations are temporarily disabled.`,{cause:e}),SenderCannotBeDelegate:e=>new L(`Cannot delegate to yourself (delegate === msg.sender).`,{cause:e}),DelegateCannotBeContractAddress:e=>new B(`Delegate address cannot be the same as the contract address.`,{cause:e}),DelegateCannotBeWildcard:e=>new Gt(`Delegate address cannot be the wildcard address; it can only be used as the contract address.`,{cause:e}),ExpirationDateBeforeOneHour:e=>new V(`Expiration date must be at least 1 hour in the future.`,{cause:e}),ExpirationDateAlreadySetToSameValue:e=>new z(`The new expiration date is the same as the current one.`,{cause:e}),NotDelegatedYet:e=>new R(`Cannot revoke: no active delegation exists.`,{cause:e}),InvalidationTimestampTooLow:e=>new Ge(`The invalidation cutoff must be strictly later than the account's current one. Pass a later timestamp, or omit it to use the current block timestamp.`,{cause:e}),InvalidationTimestampInTheFuture:e=>new je(`The invalidation cutoff cannot be in the future. Pass a timestamp no later than now, or omit it to use the current block timestamp.`,{cause:e})};function Yn(e){return Object.hasOwn(Jn,e)}function Xn(e,t){let n=Jt(e);if(n&&Yn(n))return Jn[n](t);let r=e instanceof Error?e.message:String(e);for(let[e,n]of Object.entries(Jn))if(r.includes(e))return n(t);return null}var Zn=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 V(`Expiration date must be at least 1 hour in the future`);let a=F(t),o=F(n),s=F(r);if(o===s)throw new L(`Cannot delegate to yourself (delegate === msg.sender).`);if(o===F(`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`))throw new Gt(`Delegate address cannot be the wildcard address; it can only be used as the contract address.`);if(o===a)throw new B(`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)):K,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 z(`The new expiration date (${l}) is the same as the current one. No on-chain change needed.`);return a!==F(`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`)&&await this.#i({contractAddress:a,delegatorAddress:s,delegateAddress:o}),this.#s({operation:`delegateDecryption`,signer:e,contractAddress:a,config:G(c,o,a,l)})}async revokeDelegation(e,{contractAddress:t,delegateAddress:n,delegatorAddress:r}){let i=F(t),a=F(n),o=F(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 R(`No active delegation found for delegate ${a} on contract ${i}.`);return this.#s({operation:`revokeDelegation`,signer:e,contractAddress:i,config:rn(s,a,i)})}async isDelegated(e){return(await this.getStatus(e)).isActive}async getStatus(e){let t=F(e.contractAddress)===q,[n,r]=await Promise.all([this.getDelegationExpiry(e),t?Promise.resolve(0n):this.getDelegationExpiry({...e,contractAddress:q})]),i=this.#a(n)||this.#a(r)?await this.#t.getBlockTimestamp():void 0,a=this.#o(n,i);if(a.isActive)return a;let o=this.#o(r,i);return o.isActive?o:n>=r?a:o}async#i(e){try{let{isActive:t}=await this.getStatus({...e,contractAddress:q});t&&this.#r.warn(`delegateDecryption: ${e.delegateAddress} already holds an active wildcard delegation from ${e.delegatorAddress}; this grant for ${e.contractAddress} is redundant.`)}catch(e){this.#r.warn(`delegateDecryption: wildcard redundancy check failed`,{error:e})}}#a(e){return e!==0n&&e!==K}#o(e,t){return e===0n?{isActive:!1,expiryTimestamp:e}:e===K?{isActive:!0,expiryTimestamp:e}:{isActive:t!==void 0&&e>t,expiryTimestamp:e}}async getDelegationExpiry({contractAddress:e,delegatorAddress:t,delegateAddress:n}){let r=this.#e.relayer.chain.aclContractAddress;return this.#t.readContract(on(r,F(t),F(n),F(e)))}async#s({operation:e,signer:t,contractAddress:n,config:r}){try{return await it({operation:e,signer:t,provider:this.#t,config:r,emit:e=>this.#n(e,n),logger:this.#r})}catch(e){throw this.#c(e),e}}async invalidateDecryptionSignaturesBefore(e,t){let n=this.#e.relayer.chain.aclContractAddress,r=t?BigInt(Math.floor(t.getTime()/1e3)):0n;return this.#s({operation:`invalidateDecryptionSignatures`,signer:e,config:an(n,r)})}#c(e){if(!(e instanceof E))return;let t=Xn(e.cause??e,e);if(t)throw t}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 R||t instanceof Wt){let n=F(e);r.set(n,t);return}throw t}})),r}async assertDelegationActive(e,t,n){let r=F(e),i=F(t),a=F(n),{isActive:o,expiryTimestamp:s}=await this.getStatus({contractAddress:r,delegatorAddress:i,delegateAddress:a});if(!o)throw s===0n?new R(`No active delegation from ${i} to ${a} for ${r}`):new Wt(`Delegation from ${i} to ${a} for ${r} has expired`)}},Qn=class{#e;#t;constructor({router:e,emitEvent:t}){this.#e=e,this.#t=t}async encryptValues(e,t){let n=Date.now(),r=F(e.contractAddress);try{this.#t({type:S.EncryptStart},r);let i=await this.#e.relayer.encryptValues({...e,options:t});return this.#t({type:S.EncryptEnd,durationMs:Date.now()-n},r),i}catch(e){throw this.#t({type:S.EncryptError,error:h(e),durationMs:Date.now()-n},r),en(e,`Encryption failed`)}}},$n=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 t=e.previous,n=e.next,r=n?.chainId;r!==void 0&&await x(`switch relayer chain`,()=>this.#t.switchChain(r),this.#i);let i=this.#r;i&&await x(`credential wallet account change`,()=>i.handleWalletAccountChange(t,n),this.#i),t&&await x(`clear decrypt cache`,()=>this.#n.clearForRequester(t.address),this.#i),await Promise.all(Array.from(this.#a,t=>x(`wallet account listener`,()=>t(e),this.#i)))}};const er=I.object({kind:I.literal(`ConfidentialTransfer`),from:v,token:v,to:v,amount:I.bigint()}),tr=I.object({kind:I.literal(`ConfidentialTransferFrom`),from:v,token:v,owner:v,to:v,amount:I.bigint()}),nr=I.object({kind:I.literal(`SetOperator`),from:v,token:v,operator:v,until:pe}),rr=I.object({kind:I.literal(`Unwrap`),from:v,token:v,to:v,amount:I.bigint()}),ir=I.object({kind:I.literal(`UnwrapAll`),from:v,token:v,to:v}),ar=I.object({kind:I.literal(`FinalizeUnwrap`),from:v,wrapper:v,unwrapRequestIdOrAmount:y}),or=I.object({kind:I.literal(`ApproveUnderlying`),from:v,underlying:v,spender:v,amount:I.bigint()}),sr=I.object({kind:I.literal(`Wrap`),from:v,wrapper:v,to:v,amount:I.bigint()}),cr=y.check(I.refine(e=>e===`0x`||Rt(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`)),lr=I.object({kind:I.literal(`TransferAndCall`),from:v,underlying:v,wrapper:v,amount:I.bigint(),recipientData:I.optional(cr)}),ur=I.object({kind:I.literal(`DelegateDecryption`),from:v,contractAddress:v,delegateAddress:v,expirationDate:I.optional(I.date())}),dr=I.object({kind:I.literal(`RevokeDelegation`),from:v,contractAddress:v,delegateAddress:v});I.discriminatedUnion(`kind`,[er,tr,nr,rr,ir,ar,or,sr,lr,ur,dr]);const fr=I.strictObject({maxFeePerGas:I.bigint(),maxPriorityFeePerGas:I.bigint()}),pr=I.object({nonce:I.optional(I.int().check(I.nonnegative())),gasLimit:I.optional(I.bigint()),fees:I.optional(fr)}),mr=I.object({address:v,abi:I.array(I.unknown()),functionName:I.string(),args:I.array(I.unknown()),value:I.optional(I.bigint()),gas:I.optional(I.bigint())}),hr=I.extend(pr,{from:v,calldata:mr});var gr=class{#e;#t;#n;constructor(e){this.#e=e.provider,this.#t=e.router,this.#n=e.encryption}async prepare(e,t){t&&=P(pr,t);let n=await this.#e.getChainId(),r=this.#t.chain.id;if(n!==r)throw new m(`Offline.prepare: provider is on chain ${n} but the SDK is configured for chain ${r}. The prepared transaction's contract addresses and encrypted inputs are bound to chain ${r} — point the provider at the same chain.`);let i=P(hr,{calldata:await this.#r(e),from:e.from,nonce:t?.nonce,gasLimit:t?.gasLimit,fees:t?.fees}),a=await this.#e.prepareTransaction(i);return{kind:e.kind,unsignedTx:a,from:i.from}}async#r(e){switch(e.kind){case`ConfidentialTransfer`:return this.#i(e);case`ConfidentialTransferFrom`:return this.#a(e);case`SetOperator`:return this.#o(e);case`Unwrap`:return this.#s(e);case`UnwrapAll`:return this.#c(e);case`FinalizeUnwrap`:return this.#l(e);case`ApproveUnderlying`:return this.#u(e);case`Wrap`:return this.#d(e);case`TransferAndCall`:return this.#f(e);case`DelegateDecryption`:return this.#p(e);case`RevokeDelegation`:return this.#m(e);default:throw new m(`OfflineService.prepare: unsupported transaction kind '${e.kind}'.`)}}async#i(e){e=P(er,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from}),r=t[0];if(!r)throw new O(`Encryption returned no handles for ConfidentialTransfer`);return de(e.token,e.to,r,n)}async#a(e){e=P(tr,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from}),r=t[0];if(!r)throw new O(`Encryption returned no handles for ConfidentialTransferFrom`);return ie(e.token,e.owner,e.to,r,n)}#o(e){return e=P(nr,e),oe(e.token,e.operator,e.until)}async#s(e){e=P(rr,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from}),r=t[0];if(!r)throw new O(`Encryption returned no handles for Unwrap`);return le(e.token,e.from,e.to,r,n)}async#c(e){e=P(ir,e);let t=await this.#e.readContract(ue(e.token,e.from));return _(e.token,e.from,e.to,t)}async#l(e){e=P(ar,e);let t=await this.#t.relayer.decryptPublicValuesWithSignatures({encryptedValues:[e.unwrapRequestIdOrAmount]}).catch(e=>{throw U(e,`Public decryption failed during FinalizeUnwrap`)}),n=t.clearValues[0]?.value;return It(n,`FinalizeUnwrap: decryptPublicValuesWithSignatures(handle).clearValue`),ce(e.wrapper,e.unwrapRequestIdOrAmount,n,t.checkSignaturesArgs.decryptionProof)}#u(e){return e=P(or,e),C(e.underlying,e.spender,e.amount)}#d(e){return e=P(sr,e),b(e.wrapper,e.to,e.amount)}#f(e){return e=P(lr,e),nn(e.underlying,e.wrapper,e.amount,e.recipientData)}#p(e){if(e=P(ur,e),e.expirationDate&&e.expirationDate.getTime()<Date.now()+36e5)throw new V(`Expiration date must be at least 1 hour in the future`);if(e.delegateAddress===e.from)throw new L(`Cannot delegate to yourself (delegate === msg.sender).`);if(e.delegateAddress===e.contractAddress)throw new B(`Delegate address cannot be the same as the contract address (${e.contractAddress}).`);let t=e.expirationDate?BigInt(Math.floor(e.expirationDate.getTime()/1e3)):K;return G(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress,t)}#m(e){return e=P(dr,e),rn(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress)}};function _r(e){if(!(!Object.hasOwn(e,`transportKeyPairDerivationSecret`)||e.transportKeyPairDerivationSecret!==void 0))throw new m(`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 vr(e){if(e===void 0)return;let{importScripts:t}=globalThis;if(!(typeof window>`u`&&typeof document>`u`&&typeof t!=`function`))throw new m(`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 yr(e){if(e===void 0)return;let t=P(gt,e);return new wt(typeof t==`string`?t:new Uint8Array(t))}var br=class{#e;provider;signer;storage;registry;permits;delegations;decryption;offline;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;constructor(e,t={}){_r(t),vr(t.transportKeyPairDerivationSecret);let n=yr(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 Un(e.storage,this.#i),this.#u=new Zn({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 yt({provider:this.provider,registryAddresses:r,registryTTL:e.registryTTL}),this.#n=r,this.#t=e.registryTTL,this.#l=new St({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 qn({cache:this.#a,credentialService:this.#l,delegationService:this.#u,router:e.router,emitEvent:this.emitEvent.bind(this)})),this.#s=new Qn({router:e.router,emitEvent:this.emitEvent.bind(this)}),this.#o=new $n({signer:e.signer,router:e.router,cachingService:this.#a,credentialService:this.#l,logger:this.#i}),this.#d=new gr({provider:this.provider,router:e.router,encryption:this.#s,emitEvent:(e,t)=>this.emitEvent(e,t)}),this.permits=new An({signer:this.signer,provider:this.provider,cachingService:this.#a,credentialService:this.#l,delegationService:this.#u,logger:this.#i,emitEvent:this.emitEvent.bind(this)}),this.delegations=new jn({signer:this.signer,provider:this.provider,delegationService:this.#u}),this.decryption=new Mn({signer:this.signer,provider:this.provider,router:e.router,decryptionService:this.#c}),this.offline=new Nn(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 yt({provider:this.provider,registryAddresses:{...this.#n,...e},registryTTL:this.#t})}async encrypt(e,t){return this.#s.encryptValues(e,t)}createToken(e){return new N(this,e)}createWrappedToken(e){return new Bn(this,e)}dispose(){this.#o.dispose(),this.#e.dispose()}terminate(){this.dispose(),this.signer?.dispose?.()}[Symbol.dispose](){this.terminate()}};export{kn as ACL_TOPICS,qt as AclPausedError,Q as AclTopics,lt as BalanceCheckUnavailableError,Ct as BaseSigner,tt as ChainMismatchError,Pn as ChromeSessionStorage,m as ConfigurationError,Mn as Decryption,k as DecryptionFailedError,dt as DefaultRegistryAddresses,Kt as DelegationContractIsSelfError,Ut as DelegationCooldownError,Gt as DelegationDelegateCannotBeWildcardError,B as DelegationDelegateEqualsContractError,V as DelegationExpirationTooSoonError,Wt as DelegationExpiredError,z as DelegationExpiryUnchangedError,R as DelegationNotFoundError,H as DelegationNotPropagatedError,L as DelegationSelfNotAllowedError,jn as Delegations,ye as ERC1363_INTERFACE_ID,A as ERC20ReadFailedError,Ae as ERC7984_INTERFACE_ID,We as ERC7984_WRAPPER_INTERFACE_ID,Ze as EncryptOffloadUnavailableError,O as EncryptionFailedError,bt as IndexedDBStorage,et as InsufficientAllowanceError,ot as InsufficientConfidentialBalanceError,rt as InsufficientERC20BalanceError,be as InvalidTransportKeyPairError,je as InvalidationTimestampInFutureError,Ge as InvalidationTimestampTooLowError,Se as KeyWrappingError,K as MAX_UINT64,pt as MemoryStorage,vt as MutableWalletAccountStore,Te as NoCiphertextError,Ht as NotEntitledError,Nn as Offline,An as Permits,ze as PreparedPermitChainMismatchError,Ne as PreparedPermitExpiredError,l as RelayerRequestFailedError,T as RevokedKmsContextError,j as RpcRateLimitError,te as SignerNotConfiguredError,Ce as SignerRequiredError,_e as SigningFailedError,Le as SigningRejectedError,Sn as TOKEN_TOPICS,N as Token,Y as Topics,E as TransactionRevertedError,Ee as TransportKeyPairChangedError,he as TransportKeyPairExpiredError,qe as UnifiedDecryptionUnsupportedError,Ye as UnifiedPermitNotSupportedError,Yt as UnshieldAlreadyFinalizedError,q as WILDCARD_CONTRACT,Xe as WILDCARD_PERMIT,Ue as WalletAccountNotReadyError,Fe as WalletNotConnectedError,Bn as WrappedToken,yt as WrappersRegistry,at as ZERO_ENCRYPTED_VALUE,f as ZamaError,s as ZamaErrorCode,br as ZamaSDK,S as ZamaSDKEvents,w as allowanceContract,Nt as anvil,C as approveContract,me as balanceOfContract,kt as bscTestnet,jt as chains,Fn as chromeSessionStorage,ut as cleartext,ue as confidentialBalanceOfContract,re as confidentialTotalSupplyContract,de as confidentialTransferContract,ie as confidentialTransferFromContract,cn as createConfig,xt as createWalletAccountStore,Ke as decimalsContract,Tn as decodeAclEvent,En as decodeAclEvents,mn as decodeConfidentialTransfer,Cn as decodeDelegatedForUserDecryption,vn as decodeOnChainEvent,yn as decodeOnChainEvents,wn as decodeRevokedDelegationForUserDecryption,_n as decodeUnwrapFinalized,gn as decodeUnwrapRequested,hn as decodeWrap,G as delegateForUserDecryptionContract,ce as finalizeUnwrapContract,Dn as findDelegatedForUserDecryption,On as findRevokedDelegationForUserDecryption,bn as findUnwrapRequested,xn as findWrap,He as getConfidentialTokenAddressContract,on as getDelegationExpiryContract,Pe as getTokenAddressContract,Be as getTokenPairContract,De as getTokenPairsContract,ge as getTokenPairsLengthContract,Ie as getTokenPairsSliceContract,Dt as hardhat,Tt as hoodi,_t as indexedDBStorage,ke as inferredTotalSupplyContract,At as ingenTestnet,an as invalidateDecryptionSignaturesBeforeContract,xe as isConfidentialTokenContract,Ve as isConfidentialTokenValidContract,we as isConfidentialWrapperContract,$e as isEncryptedValueZero,sn as isHandleDelegatedContract,ne as isOperatorContract,n as isRetryable,Mt as mainnet,Vt as matchZamaError,mt as memoryStorage,ve as nameContract,Et as polygon,Ot as polygonAmoy,Oe as rateContract,u as retryAfterSeconds,rn as revokeDelegationContract,Pt as sepolia,oe as setOperatorContract,Me as supportsInterfaceContract,Je as symbolContract,nn as transferAndCallContract,se as underlyingContract,le as unwrapContract,_ as unwrapFromBalanceContract,ae as unwrapRequesterContract,b as wrapContract};
1
+ import{S as e,_ as t,a as n,b as r,c as i,d as a,g as o,h as s,i as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h,v as ee}from"./relayer-CVKO9GmQ.js";import{A as g,B as _,C as te,D as v,E as ne,F as re,G as y,I as ie,J as b,K as ae,L as oe,M as x,O as se,P as ce,R as S,S as le,T as ue,U as C,V as de,W as fe,X as pe,Y as me,a as he,b as ge,c as _e,d as ve,g as ye,h as be,i as xe,j as w,k as Se,l as T,m as Ce,n as we,p as Te,q as Ee,r as De,s as Oe,t as ke,u as Ae,v as E,w as je,x as D,z as O}from"./erc165-DbMOt-s6.js";import{n as Me,r as k,t as A}from"./encryption-BKoalB4o.js";import{_ as j,a as M,c as Ne,d as Pe,f as Fe,g as Ie,h as Le,l as Re,m as ze,n as Be,o as Ve,p as He,r as Ue,s as We,t as Ge,u as Ke}from"./token-CRJ8eCr7.js";import{C as qe,T as Je,_ as Ye,a as Xe,c as Ze,d as Qe,f as $e,g as et,h as tt,i as nt,l as rt,m as it,n as at,o as ot,p as st,r as ct,s as lt,t as ut,u as dt,v as ft,w as pt,y as mt}from"./wrapped-token-BOtzaSAY.js";import{t as ht}from"./cleartext-PCpNqRGV.js";import{a as gt,c as _t,d as vt,f as yt,i as bt,l as xt,n as St,o as N,p as Ct,r as wt,s as Tt,t as Et,u as Dt}from"./base-signer-D5Cwv7yb.js";import{n as P,r as Ot,s as kt,t as At}from"./primitives-Cym-3HKa.js";import{t as F}from"./validation-BRu06AM_.js";import{a as jt,i as Mt,n as Nt,o as Pt,r as Ft,s as It,t as Lt}from"./wrappers-registry-Cm3JJeqx.js";import{a as Rt,c as zt,i as Bt,l as Vt,n as Ht,o as Ut,r as Wt,s as Gt,t as Kt,u as qt}from"./chains-ByyCdrrd.js";import{r as Jt,t as Yt}from"./assertions-Ca1ePdRJ.js";import{getAddress as I,size as Xt}from"viem";import{z as L}from"zod/mini";function Zt(e,t){if(e instanceof p){let n=t[e.code];if(n)return n(e)}return t._?.(e)}var R=class extends p{encryptedValue;contractAddress;account;constructor(e,t){super(c.NotEntitled,`Account ${e.account} is not entitled to decrypt encrypted value ${e.encryptedValue} on contract ${e.contractAddress}. This is not a transient failure — the account needs an on-chain ACL grant before it can decrypt this encrypted value.`,t),this.name=`NotEntitledError`,this.encryptedValue=e.encryptedValue,this.contractAddress=e.contractAddress,this.account=e.account}},z=class extends p{constructor(e,t){super(c.DelegationSelfNotAllowed,e,t),this.name=`DelegationSelfNotAllowedError`}},B=class extends p{constructor(e,t){super(c.DelegationCooldown,e,t),this.name=`DelegationCooldownError`}},V=class extends p{constructor(e,t){super(c.DelegationNotFound,e,t),this.name=`DelegationNotFoundError`}},H=class extends p{constructor(e,t){super(c.DelegationExpired,e,t),this.name=`DelegationExpiredError`}},U=class extends p{constructor(e,t){super(c.DelegationExpiryUnchanged,e,t),this.name=`DelegationExpiryUnchangedError`}},W=class extends p{constructor(e,t){super(c.DelegationDelegateEqualsContract,e,t),this.name=`DelegationDelegateEqualsContractError`}},Qt=class extends p{constructor(e,t){super(c.DelegationContractIsSelf,e,t),this.name=`DelegationContractIsSelfError`}},$t=class extends p{constructor(e,t){super(c.AclPaused,e,t),this.name=`AclPausedError`}},G=class extends p{constructor(e,t){super(c.DelegationExpirationTooSoon,e,t),this.name=`DelegationExpirationTooSoonError`}},K=class extends p{constructor(e,t){super(c.DelegationNotPropagated,e,t),this.name=`DelegationNotPropagatedError`}};const en=[A,y,u,K,de,_,R,j,C,b];function q(e,n,c={}){if(en.some(t=>e instanceof t))return e;let d=e instanceof Error?e.message:n;if(e instanceof Error&&f(e.message))return new C(e.message,{cause:e});if(t(e))return new b(`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:e});if(e instanceof Error&&l(e.message))return c.isDelegated?new K(`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:e}):new R({encryptedValue:r(e.message)??``,contractAddress:c.contractAddress??``,account:c.account??``},{cause:e});if(a(e))return new j(d,{cause:e,retryAfter:i(e)});let p=m(e);return p===void 0&&ee(e)?new j(d,{cause:e,retryAfter:i(e)}):p===400?new y(e instanceof Error?e.message:`No ciphertext for this account`,{cause:e}):c.isDelegated&&p===500?new K(`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:e}):s(e)||p!==void 0?new u(d,p,{cause:e,retryAfter:i(e),retryable:o(e)||void 0}):new A(n,{cause:e})}function tn(e,t){if(e instanceof p)return e;let n=m(e),r=o(e);return n!==void 0||s(e)?new u(e instanceof Error?e.message:t,n,{cause:e,retryAfter:i(e),retryable:r||void 0}):new k(t,{cause:e})}const J=[{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 Y(e,t,n,r){return{address:e,abi:J,functionName:`delegateForUserDecryption`,args:[t,n,r]}}function X(e,t,n){return{address:e,abi:J,functionName:`revokeDelegationForUserDecryption`,args:[t,n]}}function nn(e,t,n,r){return{address:e,abi:J,functionName:`getUserDecryptionDelegationExpirationDate`,args:[t,n,r]}}function rn(e,t,n,r,i){return{address:e,abi:J,functionName:`isHandleDelegatedForUserDecryption`,args:[t,n,r,i]}}const Z=2n**64n-1n;function an(e){return bt(e.signer,e.provider,e)}var on=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 S(this.#r,e)}#s(e,t){throw this.#a({type:x.PermitError,operation:e,error:t instanceof Error?t:Error(String(t))}),t}async grantPermit(e){if(e.length===0)return;let t;try{t=this.#o(`grantPermit`),await Ve(`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 Ve(`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=I((await M(`revokePermits`,this.#e,this.#t)).address);try{await t.revokePermits(e)}finally{await this.#c(n)}}async clear(){let e=this.#o(`clear`),t=I((await M(`clear`,this.#e,this.#t)).address);try{await e.clearCredentials()}finally{await this.#c(t)}}async#c(e){await w(`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)}},sn=class{#e;#t;#n;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.delegationService}#r(e){return S(this.#e,e)}async delegateDecryption({contractAddress:e,delegateAddress:t,expirationDate:n}){let r=this.#r(`delegateDecryption`),i=await M(`delegateDecryption`,this.#e,this.#t);return this.#n.delegateDecryption(r,{contractAddress:e,delegateAddress:t,delegatorAddress:i.address,expirationDate:n})}async revokeDelegation({contractAddress:e,delegateAddress:t}){let n=this.#r(`revokeDelegation`),r=await M(`revokeDelegation`,this.#e,this.#t);return this.#n.revokeDelegation(n,{contractAddress:e,delegateAddress:t,delegatorAddress:r.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)}},cn=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 S(this.#r,e)}async decryptValues(e,t){let n=this.#i(`decryptValues`),r=await M(`decryptValues`,this.#e,this.#t);return n.decryptValues(e,r.address,t)}async delegatedDecryptValues(e,t,n=t,r){let i=this.#i(`delegatedDecryptValues`),a=await M(`delegatedDecryptValues`,this.#e,this.#t);return i.delegatedDecryptValues(e,t,a.address,n,r)}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)=>{Jt(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 q(e,`Public decryption failed`)}}async delegatedBatchDecryptValues({encryptedInputs:e,delegatorAddress:t,accountAddress:n=t,maxConcurrency:r,waitForPropagation:i}){let a=this.#i(`delegatedBatchDecryptValues`),o=await M(`delegatedBatchDecryptValues`,this.#e,this.#t);return a.delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:o.address,accountAddress:n,maxConcurrency:r,waitForPropagation:i})}},ln=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)}},un=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 dn=new un,fn=L.union([L.bigint(),L.boolean(),P]),pn=L.array(L.string());var mn=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=fn.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=I(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}:${I(e)}:${I(t)}:${n.toLowerCase()}`}async#l(){let e=await this.#e.get(this.#r);if(e===null)return[];let t=pn.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 hn(e,t){let n=gn(e,t);if(!n)throw new A(`No permit covers contract ${t} after allow()`);return{privateKey:e.keypair.privateKey,publicKey:e.keypair.publicKey,serializedPermit:n.serializedPermit}}function gn(e,t){let n=At(t);return e.permissions.find(e=>e.contractAddresses.includes(n))}const _n=e=>new Promise(t=>setTimeout(t,e));var vn=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=I(t);return this.#s(e,{requesterAddress:r,errorMessage:`Failed to decrypt encrypted values`},n)}async delegatedDecryptValues(e,t,n,r,i){let a=I(t),o=I(n),s={spent:!1};return this.#a(i?.waitForPropagation??!0,()=>this.#s(e,{requesterAddress:I(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 K))throw t;await _n(2e3)}throw n}async delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:n,accountAddress:r,maxConcurrency:i=5,waitForPropagation:a=!0}){let o=e.map(e=>({encryptedValue:e.encryptedValue,contractAddress:I(e.contractAddress)}));if(o.length===0)return{items:o};let s=I(r);try{let e=await this.delegatedDecryptValues(o.map(({encryptedValue:e,contractAddress:t})=>({encryptedValue:e,contractAddress:t})),t,n,s,{waitForPropagation:a});for(let t of o)this.#d(t,e);return{items:o}}catch(e){if(Ke(e))throw e;if(o.length===1){let[n=this.#p()]=o;return n.error=this.#f(e,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:n.contractAddress,account:I(t)}),{items:o}}}let c=!1,l;if(await Ue(o.map(e=>async()=>{if(!c)try{let r=await this.delegatedDecryptValues([{encryptedValue:e.encryptedValue,contractAddress:e.contractAddress}],t,n,s,{waitForPropagation:!1});this.#d(e,r)}catch(n){if(Ke(n)){c=!0,l??=n;return}e.error=this.#f(n,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:e.contractAddress,account:I(t)})}}),i),l!==void 0)throw l;return{items:o}}async#o(e,t,n,r){let i=hn(e,t),a;try{a=await this.#r.relayer.parseTransportKeyPair({publicKey:i.publicKey,privateKey:i.privateKey,tkmsVersion:e.keypair.tkmsVersion})}catch(e){throw e instanceof Error&&f(e.message)&&await this.#t.evictTransportKeyPair(),e}let o=await this.#r.relayer.parseSignedDecryptionPermit({transportKeyPair:a,serializedPermit:i.serializedPermit});return this.#r.relayer.decryptValues({transportKeyPair:a,signedPermit:o,encryptedValues:n,contractAddress:t,options:r})}async#s(t,n,r,i={spent:!1}){if(t.length===0)return{};let a=t.map(e=>({encryptedValue:e.encryptedValue,contractAddress:I(e.contractAddress)})),o={},s=[];for(let e of a)Re(e.encryptedValue)?o[e.encryptedValue]=0n:s.push(e);if(s.length===0)return o;let c=Array.from(new Set(a.map(e=>e.contractAddress))),l=Array.from(new Set(s.map(e=>e.contractAddress)));if(n.validate)try{await n.validate(l)}catch(e){throw ee(e)?this.#u(e,`the delegation pre-check`):e}let u=[];for(let e of s){let t=await this.#e.get(n.requesterAddress,e.contractAddress,e.encryptedValue);t===null?u.push(e):o[e.encryptedValue]=t}if(u.length===0)return o;let d=await this.#t.grantPermit(c,n.delegator),f=new Map;for(let e of u){let t=f.get(e.contractAddress);t?t.push(e.encryptedValue):f.set(e.contractAddress,[e.encryptedValue])}let m=[];for(let[e,t]of f)for(let n of Ne(t))m.push({contractAddress:e,encryptedValues:n});let h=Date.now(),g=u.map(e=>e.encryptedValue);try{this.#i({type:x.DecryptStart,encryptedValues:g});try{await this.#c(n,d,m,o,r)}catch(e){if(!(e instanceof b)||i.spent)throw e;let t=d.permissions.map(e=>e.serializedPermit.signature);i.spent=!0;try{d=await this.#t.recoverPermits(c,n.delegator,t)}catch(e){throw e instanceof _?new b(`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(n,d,m.filter(({encryptedValues:e})=>e.some(e=>o[e]===void 0)),o,r)}let e={};for(let t of g){let n=o[t];n!==void 0&&(e[t]=n)}return this.#i({type:x.DecryptEnd,durationMs:Date.now()-h,encryptedValues:g,result:e}),o}catch(t){let r=t instanceof p&&t.cause instanceof Error?t.cause:t;throw this.#i({type:x.DecryptError,error:e(r),durationMs:Date.now()-h,encryptedValues:g}),q(t,n.errorMessage,{isDelegated:n.delegator!==void 0})}}async#c(e,t,n,r,i){let a=(await Ue(n.map(({contractAddress:n,encryptedValues:a})=>async()=>{try{await this.#l(e,t,n,a,r,i);return}catch(e){return e}}),5)).filter(e=>e!==void 0);if(a.length>0)throw a.find(e=>e instanceof b)??a[0]}async#l(e,t,n,r,i,a){let o;try{o=await this.#o(t,n,r,a)}catch(t){throw q(t,e.errorMessage,{isDelegated:e.delegator!==void 0,contractAddress:n,account:e.delegator??e.requesterAddress})}for(let t=0;t<r.length;t++){let a=r[t],s=o[t]?.value;a!==void 0&&s!==void 0&&(i[a]=s,await this.#e.set(e.requesterAddress,n,a,s))}let s=r.filter(e=>i[e]===void 0);if(s.length>0)throw new A(`${e.errorMessage}: relayer returned no clear value for ${s.length} of ${r.length} handle(s) on ${n}`,{cause:AggregateError(s.map(e=>new A(`No clear value for handle ${e} on ${n}`)),`${s.length} handle(s) missing a clear value on ${n}`)})}#u(e,t){return new j(`RPC provider rate-limited ${t}; retry with backoff.`,{cause:e,retryAfter:i(e)})}#d(e,t){let n=t[e.encryptedValue];if(n===void 0){e.error=new A(`Batch delegated decryption returned no value for encrypted value ${e.encryptedValue} on contract ${e.contractAddress}`);return}e.value=n}#f(e,t,n){return e instanceof p?e:q(e,t,n)}#p(){throw new A(`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 Q={AlreadyDelegatedOrRevokedInSameBlock:e=>new B(`Only one delegate/revoke per (delegator, delegate, contract) per block. Wait for the next block before retrying.`,{cause:e}),SenderCannotBeContractAddress:e=>new Qt(`The contract address cannot be the caller address.`,{cause:e}),EnforcedPause:e=>new $t(`The ACL contract is paused. Delegation operations are temporarily disabled.`,{cause:e}),SenderCannotBeDelegate:e=>new z(`Cannot delegate to yourself (delegate === msg.sender).`,{cause:e}),DelegateCannotBeContractAddress:e=>new W(`Delegate address cannot be the same as the contract address.`,{cause:e}),ExpirationDateBeforeOneHour:e=>new G(`Expiration date must be at least 1 hour in the future.`,{cause:e}),ExpirationDateAlreadySetToSameValue:e=>new U(`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 yn(e){return Object.hasOwn(Q,e)}function bn(e,t){let n=Je(e);if(n&&yn(n))return Q[n](t);let r=e instanceof Error?e.message:String(e);for(let[e,n]of Object.entries(Q))if(r.includes(e))return n(t);return null}var xn=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 G(`Expiration date must be at least 1 hour in the future`);let a=I(t),o=I(n),s=I(r);if(o===s)throw new z(`Cannot delegate to yourself (delegate === msg.sender).`);if(o===a)throw new W(`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)):Z,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 U(`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:Y(c,o,a,l)})}async revokeDelegation(e,{contractAddress:t,delegateAddress:n,delegatorAddress:r}){let i=I(t),a=I(n),o=I(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:X(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===Z?{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(nn(r,I(t),I(n),I(e)))}async#i({operation:e,signer:t,contractAddress:n,config:r}){try{return await Be({operation:e,signer:t,provider:this.#t,config:r,emit:e=>this.#n(e,n),logger:this.#r})}catch(e){throw this.#a(e),e}}#a(e){if(!(e instanceof O))return;let t=bn(e.cause??e,e);if(t)throw t}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 H){let n=I(e);r.set(n,t);return}throw t}})),r}async assertDelegationActive(e,t,n){let r=I(e),i=I(t),a=I(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 H(`Delegation from ${i} to ${a} for ${r} has expired`)}},Sn=class{#e;#t;constructor({router:e,emitEvent:t}){this.#e=e,this.#t=t}async encryptValues(t,n){let r=Date.now(),i=I(t.contractAddress);try{this.#t({type:x.EncryptStart},i);let e=await this.#e.relayer.encryptValues({...t,options:n});return this.#t({type:x.EncryptEnd,durationMs:Date.now()-r},i),e}catch(t){throw this.#t({type:x.EncryptError,error:e(t),durationMs:Date.now()-r},i),tn(t,`Encryption failed`)}}},Cn=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 t=e.previous,n=e.next,r=n?.chainId;r!==void 0&&await w(`switch relayer chain`,()=>this.#t.switchChain(r),this.#i);let i=this.#r;i&&await w(`credential wallet account change`,()=>i.handleWalletAccountChange(t,n),this.#i),t&&await w(`clear decrypt cache`,()=>this.#n.clearForRequester(t.address),this.#i),await Promise.all(Array.from(this.#a,t=>w(`wallet account listener`,()=>t(e),this.#i)))}};const $=L.object({kind:L.literal(`ConfidentialTransfer`),from:P,token:P,to:P,amount:L.bigint()}),wn=L.object({kind:L.literal(`ConfidentialTransferFrom`),from:P,token:P,owner:P,to:P,amount:L.bigint()}),Tn=L.object({kind:L.literal(`SetOperator`),from:P,token:P,operator:P,until:kt}),En=L.object({kind:L.literal(`Unwrap`),from:P,token:P,to:P,amount:L.bigint()}),Dn=L.object({kind:L.literal(`UnwrapAll`),from:P,token:P,to:P}),On=L.object({kind:L.literal(`FinalizeUnwrap`),from:P,wrapper:P,unwrapRequestIdOrAmount:Ot}),kn=L.object({kind:L.literal(`ApproveUnderlying`),from:P,underlying:P,spender:P,amount:L.bigint()}),An=L.object({kind:L.literal(`Wrap`),from:P,wrapper:P,to:P,amount:L.bigint()}),jn=Ot.check(L.refine(e=>e===`0x`||Xt(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`)),Mn=L.object({kind:L.literal(`TransferAndCall`),from:P,underlying:P,wrapper:P,amount:L.bigint(),recipientData:L.optional(jn)}),Nn=L.object({kind:L.literal(`DelegateDecryption`),from:P,contractAddress:P,delegateAddress:P,expirationDate:L.optional(L.date())}),Pn=L.object({kind:L.literal(`RevokeDelegation`),from:P,contractAddress:P,delegateAddress:P});L.discriminatedUnion(`kind`,[$,wn,Tn,En,Dn,On,kn,An,Mn,Nn,Pn]);const Fn=L.strictObject({maxFeePerGas:L.bigint(),maxPriorityFeePerGas:L.bigint()}),In=L.object({nonce:L.optional(L.int().check(L.nonnegative())),gasLimit:L.optional(L.bigint()),fees:L.optional(Fn)}),Ln=L.object({address:P,abi:L.array(L.unknown()),functionName:L.string(),args:L.array(L.unknown()),value:L.optional(L.bigint()),gas:L.optional(L.bigint())}),Rn=L.extend(In,{from:P,calldata:Ln});var zn=class{#e;#t;#n;constructor(e){this.#e=e.provider,this.#t=e.router,this.#n=e.encryption}async prepare(e,t){t&&=F(In,t);let n=await this.#e.getChainId(),r=this.#t.chain.id;if(n!==r)throw new h(`Offline.prepare: provider is on chain ${n} but the SDK is configured for chain ${r}. The prepared transaction's contract addresses and encrypted inputs are bound to chain ${r} — point the provider at the same chain.`);let i=F(Rn,{calldata:await this.#r(e),from:e.from,nonce:t?.nonce,gasLimit:t?.gasLimit,fees:t?.fees}),a=await this.#e.prepareTransaction(i);return{kind:e.kind,unsignedTx:a,from:i.from}}async#r(e){switch(e.kind){case`ConfidentialTransfer`:return this.#i(e);case`ConfidentialTransferFrom`:return this.#a(e);case`SetOperator`:return this.#o(e);case`Unwrap`:return this.#s(e);case`UnwrapAll`:return this.#c(e);case`FinalizeUnwrap`:return this.#l(e);case`ApproveUnderlying`:return this.#u(e);case`Wrap`:return this.#d(e);case`TransferAndCall`:return this.#f(e);case`DelegateDecryption`:return this.#p(e);case`RevokeDelegation`:return this.#m(e);default:throw new h(`OfflineService.prepare: unsupported transaction kind '${e.kind}'.`)}}async#i(e){e=F($,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from}),r=t[0];if(!r)throw new k(`Encryption returned no handles for ConfidentialTransfer`);return E(e.token,e.to,r,n)}async#a(e){e=F(wn,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from}),r=t[0];if(!r)throw new k(`Encryption returned no handles for ConfidentialTransferFrom`);return ge(e.token,e.owner,e.to,r,n)}#o(e){return e=F(Tn,e),ue(e.token,e.operator,e.until)}async#s(e){e=F(En,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from}),r=t[0];if(!r)throw new k(`Encryption returned no handles for Unwrap`);return v(e.token,e.from,e.to,r,n)}async#c(e){e=F(Dn,e);let t=await this.#e.readContract(be(e.token,e.from));return se(e.token,e.from,e.to,t)}async#l(e){e=F(On,e);let t=await this.#t.relayer.decryptPublicValuesWithSignatures({encryptedValues:[e.unwrapRequestIdOrAmount]}).catch(e=>{throw q(e,`Public decryption failed during FinalizeUnwrap`)}),n=t.clearValues[0]?.value;return Yt(n,`FinalizeUnwrap: decryptPublicValuesWithSignatures(handle).clearValue`),D(e.wrapper,e.unwrapRequestIdOrAmount,n,t.checkSignaturesArgs.decryptionProof)}#u(e){return e=F(kn,e),T(e.underlying,e.spender,e.amount)}#d(e){return e=F(An,e),g(e.wrapper,e.to,e.amount)}#f(e){return e=F(Mn,e),qe(e.underlying,e.wrapper,e.amount,e.recipientData)}#p(e){if(e=F(Nn,e),e.expirationDate&&e.expirationDate.getTime()<Date.now()+36e5)throw new G(`Expiration date must be at least 1 hour in the future`);if(e.delegateAddress===e.from)throw new z(`Cannot delegate to yourself (delegate === msg.sender).`);if(e.delegateAddress===e.contractAddress)throw new W(`Delegate address cannot be the same as the contract address (${e.contractAddress}).`);let t=e.expirationDate?BigInt(Math.floor(e.expirationDate.getTime()/1e3)):Z;return Y(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress,t)}#m(e){return e=F(Pn,e),X(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress)}};function Bn(e){if(!(!Object.hasOwn(e,`transportKeyPairDerivationSecret`)||e.transportKeyPairDerivationSecret!==void 0))throw new h(`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 Vn(e){if(e===void 0)return;let{importScripts:t}=globalThis;if(!(typeof window>`u`&&typeof document>`u`&&typeof t!=`function`))throw new h(`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 Hn(e){if(e===void 0)return;let t=F(_t,e);return new xt(typeof t==`string`?t:new Uint8Array(t))}var Un=class{#e;provider;signer;storage;registry;permits;delegations;decryption;offline;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;constructor(e,t={}){Bn(t),Vn(t.transportKeyPairDerivationSecret);let n=Hn(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 mn(e.storage,this.#i),this.#u=new xn({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 N({provider:this.provider,registryAddresses:r,registryTTL:e.registryTTL}),this.#n=r,this.#t=e.registryTTL,this.#l=new Tt({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 vn({cache:this.#a,credentialService:this.#l,delegationService:this.#u,router:e.router,emitEvent:this.emitEvent.bind(this)})),this.#s=new Sn({router:e.router,emitEvent:this.emitEvent.bind(this)}),this.#o=new Cn({signer:e.signer,router:e.router,cachingService:this.#a,credentialService:this.#l,logger:this.#i}),this.#d=new zn({provider:this.provider,router:e.router,encryption:this.#s,emitEvent:(e,t)=>this.emitEvent(e,t)}),this.permits=new on({signer:this.signer,provider:this.provider,cachingService:this.#a,credentialService:this.#l,logger:this.#i,emitEvent:this.emitEvent.bind(this)}),this.delegations=new sn({signer:this.signer,provider:this.provider,delegationService:this.#u}),this.decryption=new cn({signer:this.signer,provider:this.provider,router:e.router,decryptionService:this.#c}),this.offline=new ln(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 N({provider:this.provider,registryAddresses:{...this.#n,...e},registryTTL:this.#t})}async encrypt(e,t){return this.#s.encryptValues(e,t)}createToken(e){return new Ge(this,e)}createWrappedToken(e){return new ut(this,e)}dispose(){this.#o.dispose(),this.#e.dispose()}terminate(){this.dispose(),this.signer?.dispose?.()}[Symbol.dispose](){this.terminate()}};export{at as ACL_TOPICS,$t as AclPausedError,ct as AclTopics,Pe as BalanceCheckUnavailableError,Et as BaseSigner,Ie as ChainMismatchError,un as ChromeSessionStorage,h as ConfigurationError,cn as Decryption,A as DecryptionFailedError,gt as DefaultRegistryAddresses,Qt as DelegationContractIsSelfError,B as DelegationCooldownError,W as DelegationDelegateEqualsContractError,G as DelegationExpirationTooSoonError,H as DelegationExpiredError,U as DelegationExpiryUnchangedError,V as DelegationNotFoundError,K as DelegationNotPropagatedError,z as DelegationSelfNotAllowedError,sn as Delegations,ke as ERC1363_INTERFACE_ID,Fe as ERC20ReadFailedError,we as ERC7984_INTERFACE_ID,De as ERC7984_WRAPPER_INTERFACE_ID,Me as EncryptOffloadUnavailableError,k as EncryptionFailedError,yt as IndexedDBStorage,He as InsufficientAllowanceError,ze as InsufficientConfidentialBalanceError,Le as InsufficientERC20BalanceError,C as InvalidTransportKeyPairError,fe as KeyWrappingError,Dt as MemoryStorage,St as MutableWalletAccountStore,y as NoCiphertextError,R as NotEntitledError,ln as Offline,on as Permits,ae as PreparedPermitChainMismatchError,Ee as PreparedPermitExpiredError,u as RelayerRequestFailedError,b as RevokedKmsContextError,j as RpcRateLimitError,ce as SignerNotConfiguredError,re as SignerRequiredError,_ as SigningFailedError,de as SigningRejectedError,nt as TOKEN_TOPICS,Ge as Token,Xe as Topics,O as TransactionRevertedError,me as TransportKeyPairChangedError,pe as TransportKeyPairExpiredError,pt as UnshieldAlreadyFinalizedError,ie as WalletAccountNotReadyError,oe as WalletNotConnectedError,ut as WrappedToken,N as WrappersRegistry,We as ZERO_ENCRYPTED_VALUE,p as ZamaError,c as ZamaErrorCode,Un as ZamaSDK,x as ZamaSDKEvents,_e as allowanceContract,Kt as anvil,T as approveContract,Ae as balanceOfContract,Ht as bscTestnet,Wt as chains,dn as chromeSessionStorage,ht as cleartext,be as confidentialBalanceOfContract,ye as confidentialTotalSupplyContract,E as confidentialTransferContract,ge as confidentialTransferFromContract,an as createConfig,wt as createWalletAccountStore,ve as decimalsContract,ot as decodeAclEvent,lt as decodeAclEvents,Ze as decodeConfidentialTransfer,rt as decodeDelegatedForUserDecryption,dt as decodeOnChainEvent,Qe as decodeOnChainEvents,$e as decodeRevokedDelegationForUserDecryption,st as decodeUnwrapFinalized,it as decodeUnwrapRequested,tt as decodeWrap,Y as delegateForUserDecryptionContract,D as finalizeUnwrapContract,et as findDelegatedForUserDecryption,Ye as findRevokedDelegationForUserDecryption,ft as findUnwrapRequested,mt as findWrap,Lt as getConfidentialTokenAddressContract,nn as getDelegationExpiryContract,Nt as getTokenAddressContract,Ft as getTokenPairContract,Mt as getTokenPairsContract,jt as getTokenPairsLengthContract,Pt as getTokenPairsSliceContract,Bt as hardhat,Rt as hoodi,Ct as indexedDBStorage,le as inferredTotalSupplyContract,Ut as ingenTestnet,xe as isConfidentialTokenContract,It as isConfidentialTokenValidContract,he as isConfidentialWrapperContract,Re as isEncryptedValueZero,rn as isHandleDelegatedContract,te as isOperatorContract,n as isRetryable,Gt as mainnet,Zt as matchZamaError,vt as memoryStorage,Te as nameContract,zt as polygon,Vt as polygonAmoy,je as rateContract,d as retryAfterSeconds,X as revokeDelegationContract,qt as sepolia,ue as setOperatorContract,Oe as supportsInterfaceContract,Ce as symbolContract,qe as transferAndCallContract,ne as underlyingContract,v as unwrapContract,se as unwrapFromBalanceContract,Se as unwrapRequesterContract,g as wrapContract};
2
2
  //# sourceMappingURL=index.js.map