@zama-fhe/sdk 3.8.0-beta.20 → 3.8.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/alignment.cjs +1 -1
- package/dist/cjs/alignment.cjs.map +1 -1
- package/dist/cjs/base-signer.cjs +1 -1
- package/dist/cjs/base-signer.cjs.map +1 -1
- package/dist/cjs/ethers/index.cjs +1 -1
- package/dist/cjs/ethers/index.cjs.map +1 -1
- package/dist/cjs/fhevm-relayer.cjs +2 -2
- package/dist/cjs/fhevm-relayer.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/log-decoding.cjs +2 -0
- package/dist/cjs/log-decoding.cjs.map +1 -0
- package/dist/cjs/query/index.cjs +1 -1
- package/dist/cjs/query/index.cjs.map +1 -1
- package/dist/cjs/query-keys.cjs +2 -0
- package/dist/cjs/query-keys.cjs.map +1 -0
- package/dist/cjs/relayer.cjs +1 -1
- package/dist/cjs/relayer.cjs.map +1 -1
- package/dist/cjs/telemetry.cjs +1 -1
- package/dist/cjs/telemetry.cjs.map +1 -1
- package/dist/cjs/token.cjs +1 -1
- package/dist/cjs/token.cjs.map +1 -1
- package/dist/cjs/vaults/index.cjs +1 -1
- package/dist/cjs/vaults/index.cjs.map +1 -1
- package/dist/cjs/viem/index.cjs +1 -1
- package/dist/cjs/viem/index.cjs.map +1 -1
- package/dist/cjs/wrappers-registry.cjs +2 -0
- package/dist/cjs/wrappers-registry.cjs.map +1 -0
- package/dist/esm/alignment-o-YIndFR.js +2 -0
- package/dist/esm/alignment-o-YIndFR.js.map +1 -0
- package/dist/esm/{base-signer-C4P_Y-TS.d.ts → base-signer-nenGJU9U.d.ts} +1 -1
- package/dist/esm/base-signer-p5iz9eeb.js +2 -0
- package/dist/esm/base-signer-p5iz9eeb.js.map +1 -0
- package/dist/esm/cleartext/index.d.ts +2 -2
- package/dist/esm/cleartext/index.js +1 -1
- package/dist/esm/{cleartext-D587CgVj.d.ts → cleartext-BLMLdKFh.d.ts} +1 -1
- package/dist/esm/{cleartext-BrJewisr.js → cleartext-C1Y5zc1Y.js} +2 -2
- package/dist/esm/{cleartext-BrJewisr.js.map → cleartext-C1Y5zc1Y.js.map} +1 -1
- package/dist/esm/{index-TuEeFx9Z.d.ts → decryption-Cp8calaa.d.ts} +1110 -1575
- package/dist/esm/{encrypt-worker-client-Bjab5Grh.d.ts → encrypt-worker-client-CkEIA0Tp.d.ts} +1 -1
- package/dist/esm/{encryption-DDP0UpGa.js → encryption-BT886Jlj.js} +2 -2
- package/dist/esm/{encryption-DDP0UpGa.js.map → encryption-BT886Jlj.js.map} +1 -1
- package/dist/esm/ethers/index.d.ts +12 -4
- package/dist/esm/ethers/index.js +1 -1
- package/dist/esm/ethers/index.js.map +1 -1
- package/dist/esm/{fatal-batch-BqKg7m3V.js → fatal-batch-BYeHrf0V.js} +2 -2
- package/dist/esm/{fatal-batch-BqKg7m3V.js.map → fatal-batch-BYeHrf0V.js.map} +1 -1
- package/dist/esm/{fhevm-relayer-B-Ve8Yyz.js → fhevm-relayer-BEzN0aev.js} +2 -2
- package/dist/esm/{fhevm-relayer-B-Ve8Yyz.js.map → fhevm-relayer-BEzN0aev.js.map} +1 -1
- package/dist/esm/{index-Dae8rZWN.d.ts → index-CI6f4jxt.d.ts} +5 -5
- package/dist/esm/{index-yCC7GnOx.d.ts → index-ClNBSbRy.d.ts} +2 -2
- package/dist/esm/index.d.ts +8 -8
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internal/index.d.ts +3 -3
- package/dist/esm/internal/index.js +1 -1
- package/dist/esm/log-decoding-ZthqwHOv.js +2 -0
- package/dist/esm/log-decoding-ZthqwHOv.js.map +1 -0
- package/dist/esm/node/index.d.ts +3 -3
- package/dist/esm/node/index.js +1 -1
- package/dist/esm/query/index.d.ts +5 -5
- package/dist/esm/query/index.js +1 -1
- package/dist/esm/query/index.js.map +1 -1
- package/dist/esm/query-keys-CSPxPLBB.js +2 -0
- package/dist/esm/query-keys-CSPxPLBB.js.map +1 -0
- package/dist/esm/{relayer-CqdiNLZH.js → relayer-nWfQAlo7.js} +2 -2
- package/dist/esm/{relayer-CqdiNLZH.js.map → relayer-nWfQAlo7.js.map} +1 -1
- package/dist/esm/{signing-BIlZhi5G.js → signing-CVEOw21I.js} +2 -2
- package/dist/esm/{signing-BIlZhi5G.js.map → signing-CVEOw21I.js.map} +1 -1
- package/dist/esm/telemetry-YFH36F_7.js +2 -0
- package/dist/esm/telemetry-YFH36F_7.js.map +1 -0
- package/dist/esm/token-AXsOIUDB.js +2 -0
- package/dist/esm/{token-CxDfm7V-.js.map → token-AXsOIUDB.js.map} +1 -1
- package/dist/esm/{types-Bi-kDUxb.d.ts → types-D253qkvB.d.ts} +1 -1
- package/dist/esm/{types-D1qhoqkF.d.ts → types-DH06Ap0n.d.ts} +1 -1
- package/dist/esm/{types-DbnDm2O9.d.ts → types-Ubeo72FV.d.ts} +13 -1
- package/dist/esm/{validation-CL7MJT6k.js → validation-CZfDLOUh.js} +2 -2
- package/dist/esm/{validation-CL7MJT6k.js.map → validation-CZfDLOUh.js.map} +1 -1
- package/dist/esm/vaults/index.d.ts +262 -15600
- package/dist/esm/vaults/index.js +1 -1
- package/dist/esm/vaults/index.js.map +1 -1
- package/dist/esm/viem/index.d.ts +12 -4
- package/dist/esm/viem/index.js +1 -1
- package/dist/esm/viem/index.js.map +1 -1
- package/dist/esm/web/index.d.ts +2 -2
- package/dist/esm/web/index.js +1 -1
- package/dist/esm/wrappers-registry-Cm3JJeqx.js +2 -0
- package/dist/esm/wrappers-registry-Cm3JJeqx.js.map +1 -0
- package/package.json +1 -1
- package/dist/cjs/applied-runtime.cjs +0 -2
- package/dist/cjs/applied-runtime.cjs.map +0 -1
- package/dist/cjs/invalidation.cjs +0 -2
- package/dist/cjs/invalidation.cjs.map +0 -1
- package/dist/cjs/primitives.cjs +0 -2
- package/dist/cjs/primitives.cjs.map +0 -1
- package/dist/cjs/wrapped-token.cjs +0 -2
- package/dist/cjs/wrapped-token.cjs.map +0 -1
- package/dist/esm/alignment-CYa0d0Ud.js +0 -2
- package/dist/esm/alignment-CYa0d0Ud.js.map +0 -1
- package/dist/esm/applied-runtime-3fzqBC2V.js +0 -2
- package/dist/esm/applied-runtime-3fzqBC2V.js.map +0 -1
- package/dist/esm/base-signer-DvCCKQfk.js +0 -2
- package/dist/esm/base-signer-DvCCKQfk.js.map +0 -1
- package/dist/esm/invalidation-CzspPBR7.js +0 -2
- package/dist/esm/invalidation-CzspPBR7.js.map +0 -1
- package/dist/esm/primitives-Cym-3HKa.js +0 -2
- package/dist/esm/primitives-Cym-3HKa.js.map +0 -1
- package/dist/esm/telemetry-CmBkkrXK.js +0 -2
- package/dist/esm/telemetry-CmBkkrXK.js.map +0 -1
- package/dist/esm/token-CxDfm7V-.js +0 -2
- package/dist/esm/wrapped-token-BWMNyFj2.js +0 -2
- package/dist/esm/wrapped-token-BWMNyFj2.js.map +0 -1
package/dist/esm/index.d.ts
CHANGED
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @packageDocumentation
|
|
7
7
|
*/
|
|
8
|
-
import { t as createConfig } from "./index-
|
|
9
|
-
import { $ as
|
|
10
|
-
import { t as cleartext } from "./cleartext-
|
|
11
|
-
import { t as ZamaConfigEthers } from "./types-
|
|
8
|
+
import { t as createConfig } from "./index-CI6f4jxt.js";
|
|
9
|
+
import { $ as RevokeDelegationSubmittedEvent, $t as RawLog, A as WalletAccountListener, At as ConfidentialTransferEvent, B as WriteFunctionName, Bt as decodeAclEvents, C as TransferAndCallRequest, Ct as WrapOptions, D as GenericSigner, Dt as ACL_TOPICS, E as WrapRequest, Et as UnshieldCallbacks, F as ReadContractConfig, Ft as Topics, G as DecryptStartEvent, Gt as decodeRevokedDelegationForUserDecryption, H as BaseEvent, Ht as decodeDelegatedForUserDecryption, I as ReadContractReturnType, It as UnwrapFinalizedEvent, J as EncryptErrorEvent, Jt as decodeWrap, K as DelegationSubmittedEvent, Kt as decodeUnwrapFinalized, L as ReadFunctionName, Lt as UnwrapRequestedEvent, M as ContractAbi, Mt as OnChainEvent, N as MulticallReturnType, Nt as RevokedDelegationForUserDecryptionEvent, O as WalletAccount, Ot as AclEvent, P as ReadContractArgs, Pt as TOKEN_TOPICS, Q as PermitOperation, Qt as findWrap, R as WriteContractArgs, Rt as WrapEvent, S as TransactionKind, St as UnwrapResult, T as UnwrapRequest, Tt as TransferCallbacks, U as DecryptEndEvent, Ut as decodeOnChainEvent, V as ApproveUnderlyingSubmittedEvent, Vt as decodeConfidentialTransfer, W as DecryptErrorEvent, Wt as decodeOnChainEvents, X as FinalizeUnwrapSubmittedEvent, Xt as findRevokedDelegationForUserDecryption, Y as EncryptStartEvent, Yt as findDelegatedForUserDecryption, Z as PermitErrorEvent, Zt as findUnwrapRequested, _ as PrepareTransactionRequest, _n as TypedValue, _t as ApprovalStrategy, a as ZamaConfigBase, an as EIP712TypedData, at as TransferSubmittedEvent, b as RevokeDelegationRequest, bt as TransferOptions, c as GenericStorage, cn as EncryptResult, ct as UnshieldPhase2SubmittedEvent, d as ConfidentialTransferFromRequest, dn as FhevmClientOptions, dt as VaultSubmittedEvent, en as TransactionReceipt, et as SetOperatorSubmittedEvent, f as ConfidentialTransferRequest, fn as FhevmRelayerOptions, ft as WrapSubmittedEvent, g as PrepareOptions, gn as RelayerSDK, gt as ZamaSDKEvents, h as PrepareFees, hn as RelayerRequestOptions, ht as ZamaSDKEventType, i as ZamaConfig, in as DecryptValuesParameters, it as TransferFromSubmittedEvent, j as WalletAccountStore, jt as DelegatedForUserDecryptionEvent, k as WalletAccountChange, kt as AclTopics, l as GenericProvider, ln as EncryptedValue, lt as UnwrapSubmittedEvent, m as FinalizeUnwrapRequest, mn as RelayerOptions, mt as ZamaSDKEventListener, n as RelayerConfig, nn as ClearValue, nt as TransactionErrorEvent, o as ZamaConfigGeneric, on as EncryptInput, ot as UnshieldPhase1SubmittedEvent, p as DelegateDecryptionRequest, pn as FhevmRuntimeConfig, pt as ZamaSDKEvent, q as EncryptEndEvent, qt as decodeUnwrapRequested, rn as DecryptPublicValuesResult, rt as TransactionOperation, s as GenericLogger, sn as EncryptParams, st as UnshieldPhase2StartedEvent, t as CleartextRelayerConfig, tn as TransactionResult, tt as ShieldSubmittedEvent, u as ApproveUnderlyingRequest, un as FhevmClient, ut as VaultOperation, v as PreparedFor, vt as ShieldOptions, w as UnwrapAllRequest, wt as ShieldCallbacks, x as SetOperatorRequest, xt as UnshieldOptions, y as PreparedTransaction, yt as ShieldPath, z as WriteContractConfig, zt as decodeAclEvent } from "./types-Ubeo72FV.js";
|
|
10
|
+
import { t as cleartext } from "./cleartext-BLMLdKFh.js";
|
|
11
|
+
import { t as ZamaConfigEthers } from "./types-DH06Ap0n.js";
|
|
12
12
|
import { a as hoodi, c as polygonAmoy, d as AtLeastOneChain, f as FheChain, i as hardhat, l as sepolia, n as bscTestnet, o as mainnet, p as FheChainAuth, r as chains, s as polygon, t as anvil, u as zenithTrexTestnet } from "./index-ZTcD9b_z.js";
|
|
13
|
-
import { $
|
|
14
|
-
import { t as ZamaConfigViem } from "./types-
|
|
15
|
-
import { n as MutableWalletAccountStore, r as createWalletAccountStore, t as BaseSigner } from "./base-signer-
|
|
13
|
+
import { $t as PreparedPermit, A as VaultBatcherPausedDetails, An as nameContract, At as DelegationDelegateEqualsContractError, Bn as isOperatorContract, Bt as PreparedPermitChainMismatchError, C as Delegations, Cn as isConfidentialTokenContract, Ct as DecryptionFailedError, D as matchZamaError, Dn as approveContract, Dt as DelegationContractIsSelfError, E as ErrorForCode, En as allowanceContract, Et as AclPausedError, Fn as confidentialTransferContract, Ft as DelegationNotPropagatedError, Gn as unwrapContract, Gt as ChainMismatchError, Hn as setOperatorContract, Ht as RevokedKmsContextError, In as confidentialTransferFromAndCallContract, It as DelegationSelfNotAllowedError, Jn as wrapContract, Jt as isRetryable, Kn as unwrapFromBalanceContract, Kt as ZamaError, Ln as confidentialTransferFromContract, Lt as InvalidTransportKeyPairError, M as VaultJoinUnconfirmedDetails, Mn as confidentialBalanceOfContract, Mt as DelegationExpiredError, N as VaultJoinUnconfirmedError, Nn as confidentialTotalSupplyContract, Nt as DelegationExpiryUnchangedError, O as VaultBatchNotDispatchedDetails, On as balanceOfContract, Ot as DelegationCooldownError, Pn as confidentialTransferAndCallContract, Pt as DelegationNotFoundError, Qt as PreparePermitRequest, Rn as finalizeUnwrapContract, Rt as KeyWrappingError, S as Offline, Sn as ERC7984_WRAPPER_INTERFACE_ID, St as InsufficientERC20BalanceError, T as Permits, Tn as supportsInterfaceContract, Tt as EncryptionFailedError, Un as underlyingContract, Ut as TransportKeyPairChangedError, Vn as rateContract, Vt as PreparedPermitExpiredError, Wn as unwrapAmountContract, Wt as TransportKeyPairExpiredError, Xt as parsePreparedPermit, Yt as retryAfterSeconds, Zt as Permission, _ as WrappersRegistryConfig, _n as isHandleDelegatedContract, _t as BalanceCheckUnavailableError, a as DecryptResult, an as PaginatedResult, at as TransactionRevertedError, b as BatchDecryptAsOptions, bn as ERC1363_INTERFACE_ID, bt as InsufficientAllowanceError, cn as getConfidentialTokenAddressContract, ct as SigningRejectedError, dn as getTokenPairsContract, dt as WalletAccountNotReadyError, en as SerializedPermit, f as ZamaSDK, fn as getTokenPairsLengthContract, ft as WalletNotConnectedError, g as WrappersRegistry, gn as getDelegationExpiryContract, gt as RelayerRequestFailedError, h as ListPairsOptions, hn as delegateForUserDecryptionContract, ht as ConfigurationError, i as DelegatedDecryptOptions, in as ChecksummedAddress, it as HcuTransactionLimitExceededError, j as VaultBatcherPausedError, jn as symbolContract, jt as DelegationExpirationTooSoonError, k as VaultBatchNotDispatchedError, kn as decimalsContract, kt as DelegationDelegateCannotBeWildcardError, ln as getTokenAddressContract, lt as SignerNotConfiguredError, m as DefaultRegistryAddresses, mn as isConfidentialTokenValidContract, mt as NotEntitledError, n as BatchDecryptItem, nn as SerializedTransportKeyPair, nt as UnshieldAlreadyFinalizedError, o as EncryptedInput, on as TokenWrapperPair, ot as SigningErrorMetadata, p as ZamaSDKOptions, pn as getTokenPairsSliceContract, pt as RpcRateLimitError, qn as unwrapRequesterContract, qt as ZamaErrorCode, r as BatchDecryptResult, rn as SignedPreparedPermit, rt as HcuBlockLimitExceededError, sn as TokenWrapperPairWithMetadata, st as SigningFailedError, t as Decryption, tn as SerializedPermitEip712, tt as UnshieldAlreadyFinalizedDetails, un as getTokenPairContract, ut as SignerRequiredError, v as WrappedToken, vn as revokeDelegationContract, vt as BalanceErrorDetails, w as DelegationStatus, wn as isConfidentialWrapperContract, wt as EncryptOffloadUnavailableError, x as Token, xn as ERC7984_INTERFACE_ID, xt as InsufficientConfidentialBalanceError, y as BatchBalancesResult, yn as transferAndCallContract, yt as ERC20ReadFailedError, zn as inferredTotalSupplyContract, zt as NoCiphertextError } from "./decryption-Cp8calaa.js";
|
|
14
|
+
import { t as ZamaConfigViem } from "./types-D253qkvB.js";
|
|
15
|
+
import { n as MutableWalletAccountStore, r as createWalletAccountStore, t as BaseSigner } from "./base-signer-nenGJU9U.js";
|
|
16
16
|
import { Address, Hex } from "viem";
|
|
17
17
|
/** uint64 max — represents a permanent (no-expiry) delegation. */
|
|
18
18
|
export declare const MAX_UINT64: bigint;
|
|
@@ -102,4 +102,4 @@ export declare const ZERO_ENCRYPTED_VALUE: "0x0000000000000000000000000000000000
|
|
|
102
102
|
* Check whether an encrypted value represents the zero value.
|
|
103
103
|
*/
|
|
104
104
|
export declare function isEncryptedValueZero(encryptedValue: string): boolean;
|
|
105
|
-
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, 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, HcuBlockLimitExceededError, HcuTransactionLimitExceededError, type Hex, InsufficientAllowanceError, InsufficientConfidentialBalanceError, InsufficientERC20BalanceError, InvalidTransportKeyPairError, KeyWrappingError, type ListPairsOptions, 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 RelayerRequestOptions, 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, type SignedPreparedPermit, 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
|
|
105
|
+
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, 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, HcuBlockLimitExceededError, HcuTransactionLimitExceededError, type Hex, InsufficientAllowanceError, InsufficientConfidentialBalanceError, InsufficientERC20BalanceError, InvalidTransportKeyPairError, KeyWrappingError, type ListPairsOptions, type MulticallReturnType, 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 RelayerRequestOptions, 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, type SignedPreparedPermit, 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 VaultBatchNotDispatchedDetails, VaultBatchNotDispatchedError, type VaultBatcherPausedDetails, VaultBatcherPausedError, type VaultJoinUnconfirmedDetails, VaultJoinUnconfirmedError, 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, 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, cleartext, confidentialBalanceOfContract, confidentialTotalSupplyContract, confidentialTransferAndCallContract, confidentialTransferContract, confidentialTransferFromAndCallContract, 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, inferredTotalSupplyContract, isConfidentialTokenContract, isConfidentialTokenValidContract, isConfidentialWrapperContract, isHandleDelegatedContract, isOperatorContract, isRetryable, mainnet, matchZamaError, nameContract, parsePreparedPermit, polygon, polygonAmoy, rateContract, retryAfterSeconds, revokeDelegationContract, sepolia, setOperatorContract, supportsInterfaceContract, symbolContract, transferAndCallContract, underlyingContract, unwrapAmountContract, unwrapContract, unwrapFromBalanceContract, unwrapRequesterContract, wrapContract, zenithTrexTestnet };
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./cleartext-BrJewisr.js";import{a as t,c as n,d as r,f as i,i as a,l as o,m as s,n as c,o as l,p as u,r as d,s as f,t as p,u as m}from"./base-signer-DvCCKQfk.js";import{a as ee,c as te,i as ne,l as re,n as ie,o as ae,r as oe,s as se,t as ce,u as le}from"./chains-BQXSxIwU.js";import{$ as h,A as ue,B as de,D as fe,E as pe,F as me,H as he,I as ge,K as _e,L as ve,M as ye,N as be,O as xe,P as Se,Q as Ce,R as we,S as Te,T as Ee,U as g,V as De,W as Oe,X as ke,Y as Ae,Z as je,a as Me,b as Ne,c as Pe,d as Fe,et as Ie,f as Le,g as Re,h as ze,j as Be,k as Ve,l as He,m as Ue,n as We,nt as Ge,o as Ke,p as qe,q as _,rt as v,s as Je,t as y,tt as Ye,u as Xe,v as Ze,w as Qe,x as $e,y as et,z as tt}from"./alignment-CYa0d0Ud.js";import{C as nt,_ as rt,a as it,c as b,f as at,g as ot,h as st,i as x,m as ct,n as S,o as lt,r as C,s as ut,t as w,v as dt,x as ft,y as pt}from"./relayer-CqdiNLZH.js";import{c as mt,d as ht,f as gt,i as _t,l as vt,n as yt,o as bt,p as xt,r as St,s as Ct,t as wt,u as Tt}from"./token-CxDfm7V-.js";import{n as Et,r as T,t as E}from"./encryption-DDP0UpGa.js";import{a as Dt,c as Ot,d as kt,i as D,l as O,n as At,o as k,s as jt,t as A,u as Mt}from"./signing-BIlZhi5G.js";import{n as Nt,r as j}from"./fatal-batch-BqKg7m3V.js";import{C as Pt,D as Ft,E as It,O as Lt,T as Rt,_ as zt,a as Bt,c as Vt,d as Ht,f as Ut,g as Wt,h as Gt,i as Kt,k as qt,l as Jt,m as Yt,n as Xt,o as Zt,p as Qt,r as $t,s as en,t as tn,u as nn,v as rn,w as an,y as on}from"./wrapped-token-BWMNyFj2.js";import{r as M}from"./telemetry-CmBkkrXK.js";import{n as N,r as sn,s as cn,t as ln}from"./primitives-Cym-3HKa.js";import{t as P}from"./validation-CL7MJT6k.js";import{getAddress as F,size as un}from"viem";import{z as I}from"zod/mini";function dn(e,t){if(e instanceof C){let n=t[e.code];if(n)return n(e)}return t._?.(e)}var L=class extends C{encryptedValue;contractAddress;account;constructor(e,t){super(x.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}},R=class extends C{constructor(e,t){super(x.DelegationSelfNotAllowed,e,t),this.name=`DelegationSelfNotAllowedError`}},fn=class extends C{constructor(e,t){super(x.DelegationCooldown,e,t),this.name=`DelegationCooldownError`}},z=class extends C{constructor(e,t){super(x.DelegationNotFound,e,t),this.name=`DelegationNotFoundError`}},B=class extends C{constructor(e,t){super(x.DelegationExpired,e,t),this.name=`DelegationExpiredError`}},V=class extends C{constructor(e,t){super(x.DelegationExpiryUnchanged,e,t),this.name=`DelegationExpiryUnchangedError`}},H=class extends C{constructor(e,t){super(x.DelegationDelegateEqualsContract,e,t),this.name=`DelegationDelegateEqualsContractError`}},U=class extends C{constructor(e,t){super(x.DelegationDelegateCannotBeWildcard,e,t),this.name=`DelegationDelegateCannotBeWildcardError`}},pn=class extends C{constructor(e,t){super(x.DelegationContractIsSelf,e,t),this.name=`DelegationContractIsSelfError`}},W=class extends C{constructor(e,t){super(x.AclPaused,e,t),this.name=`AclPausedError`}},G=class extends C{constructor(e,t){super(x.DelegationExpirationTooSoon,e,t),this.name=`DelegationExpirationTooSoonError`}},K=class extends C{constructor(e,t){super(x.DelegationNotPropagated,e,t),this.name=`DelegationNotPropagatedError`}};const mn=[E,k,S,K,At,A,L,j,D,O];function q(e,t,n={}){if(mn.some(t=>e instanceof t))return e;let r=e instanceof Error?e.message:t;if(e instanceof Error&&ct(e.message))return new D(e.message,{cause:e});if(dt(e))return new O(`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&&st(e.message))return n.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 L({encryptedValue:ft(e.message)??``,contractAddress:n.contractAddress??``,account:n.account??``},{cause:e});if(at(e))return new j(r,{cause:e,retryAfter:b(e)});let i=ut(e);return i===void 0&&pt(e)?new j(r,{cause:e,retryAfter:b(e)}):i===400?new k(e instanceof Error?e.message:`No ciphertext for this account`,{cause:e}):n.isDelegated&&i===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}):ot(e)||i!==void 0?new S(r,i,{cause:e,retryAfter:b(e),retryable:rt(e)||void 0}):new E(t,{cause:e})}function hn(e,t){if(e instanceof C)return e;let n=ut(e),r=rt(e);return n!==void 0||ot(e)?new S(e instanceof Error?e.message:t,n,{cause:e,retryAfter:b(e),retryable:r||void 0}):new T(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 gn(e,t,n,r){return{address:e,abi:J,functionName:`getUserDecryptionDelegationExpirationDate`,args:[t,n,r]}}function _n(e,t,n,r,i){return{address:e,abi:J,functionName:`isHandleDelegatedForUserDecryption`,args:[t,n,r,i]}}const Z=2n**64n-1n,Q=`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`;function vn(e){return a(e.signer,e.provider,e)}var yn=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 h(this.#r,e)}#s(e,t){throw this.#a({type:_.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 We(`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 We(`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)}registerPermit(e,t){return this.batchRegisterPermits([{prepared:e,signature:t}])}async batchRegisterPermits(e){let t;try{t=this.#o(`registerPermit`)}catch(e){this.#s(`registerPermit`,e)}await t.batchRegisterPermits(e),await Promise.all([...new Set(e.map(e=>e.prepared.signerAddress))].map(e=>this.#c(e)))}async revokePermits(e){let t=this.#o(`revokePermits`),n=await y(`revokePermits`,this.#e,this.#t),r=F(n.address);try{await t.revokePermits(e)}finally{await this.#c(r)}}async clear(){let e=this.#o(`clear`),t=await y(`clear`,this.#e,this.#t),n=F(t.address);try{await e.clearCredentials()}finally{await this.#c(n)}}async#c(e){await g(`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)}},bn=class{#e;#t;#n;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.delegationService}#r(e){return h(this.#e,e)}async delegateDecryption({contractAddress:e,delegateAddress:t,expirationDate:n}){let r=this.#r(`delegateDecryption`),i=await y(`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 y(`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)}},xn=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 h(this.#r,e)}async decryptValues(e,t){let n=this.#i(`decryptValues`),r=await y(`decryptValues`,this.#e,this.#t);return n.decryptValues(e,r.address,M(t,`decrypt-values`))}async delegatedDecryptValues(e,t,n=t,r){let i=this.#i(`delegatedDecryptValues`),a=await y(`delegatedDecryptValues`,this.#e,this.#t);return i.delegatedDecryptValues(e,t,a.address,n,M(r,`delegated-decrypt-values`))}async decryptPublicValues(e,t){if(e.length===0)return{clearValues:{},decryptionProof:`0x`,abiEncodedClearValues:`0x`};let n=M(t,`decrypt-public-values`);try{let t=await this.#n.relayer.decryptPublicValuesWithSignatures({encryptedValues:e,options:n}),r={};return t.checkSignaturesArgs.handlesList.forEach((e,n)=>{_e(t.clearValues[n],`result.clearValues[${n}]`),r[e]=t.clearValues[n].value}),{clearValues:r,abiEncodedClearValues:t.checkSignaturesArgs.abiEncodedCleartexts,decryptionProof:t.checkSignaturesArgs.decryptionProof}}catch(e){throw q(e,`Public decryption failed`)}}async delegatedBatchDecryptValues({encryptedInputs:e,delegatorAddress:t,accountAddress:n=t,maxConcurrency:r,waitForPropagation:i,operation:a}){let o=this.#i(`delegatedBatchDecryptValues`),s=await y(`delegatedBatchDecryptValues`,this.#e,this.#t);return o.delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:s.address,accountAddress:n,maxConcurrency:r,waitForPropagation:i,operation:a??`delegated-batch-decrypt-values`})}},Sn=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)}batchPreparePermits(e){return this.#t.batchPreparePermits(e)}},Cn=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 wn=new Cn,Tn=I.union([I.bigint(),I.boolean(),N]),En=I.array(I.string());var Dn=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=Tn.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=En.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 On(e,t){let n=kn(e,t);if(!n)throw new E(`No permit covers contract ${t} after allow()`);return{privateKey:e.keypair.privateKey,publicKey:e.keypair.publicKey,serializedPermit:n.serializedPermit}}function kn(e,t){let n=ln(t);return e.permissions.find(e=>e.contractAddresses.includes(n))}const An=e=>new Promise(t=>setTimeout(t,e));var jn=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`},{operation:i?.operation},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 An(2e3)}throw n}async delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:n,accountAddress:r,maxConcurrency:i=5,waitForPropagation:a=!0,operation:o}){let s=e.map(e=>({encryptedValue:e.encryptedValue,contractAddress:F(e.contractAddress)}));if(s.length===0)return{items:s};let c=F(r);try{let e=await this.delegatedDecryptValues(s.map(({encryptedValue:e,contractAddress:t})=>({encryptedValue:e,contractAddress:t})),t,n,c,{waitForPropagation:a,operation:o});for(let t of s)this.#d(t,e);return{items:s}}catch(e){if(Nt(e))throw e;if(s.length===1){let[n=this.#p()]=s;return n.error=this.#f(e,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:n.contractAddress,account:F(t)}),{items:s}}}let l=!1,u;if(await _t(s.map(e=>async()=>{if(!l)try{let r=await this.delegatedDecryptValues([{encryptedValue:e.encryptedValue,contractAddress:e.contractAddress}],t,n,c,{waitForPropagation:!1,operation:o});this.#d(e,r)}catch(n){if(Nt(n)){l=!0,u??=n;return}e.error=this.#f(n,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:e.contractAddress,account:F(t)})}}),i),u!==void 0)throw u;return{items:s}}async#o(e,t,n,r){let i=On(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&&ct(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)mt(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 pt(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=/* @__PURE__ */ 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 f=[];for(let[e,t]of d)for(let n of Ct(t))f.push({contractAddress:e,encryptedValues:n});let p=Date.now(),m=l.map(e=>e.encryptedValue);try{this.#i({type:_.DecryptStart,encryptedValues:m});try{await this.#c(t,u,f,a,n)}catch(e){if(!(e instanceof O)||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 A?new O(`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,f.filter(({encryptedValues:e})=>e.some(e=>a[e]===void 0)),a,n)}let e={};for(let t of m){let n=a[t];n!==void 0&&(e[t]=n)}return this.#i({type:_.DecryptEnd,durationMs:Date.now()-p,encryptedValues:m,result:e}),a}catch(e){let n=e instanceof C&&e.cause instanceof Error?e.cause:e;throw this.#i({type:_.DecryptError,error:nt(n),durationMs:Date.now()-p,encryptedValues:m}),q(e,t.errorMessage,{isDelegated:t.delegator!==void 0})}}async#c(e,t,n,r,i){let a=(await _t(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 O)??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 E(`${e.errorMessage}: relayer returned no clear value for ${s.length} of ${r.length} handle(s) on ${n}`,{cause:AggregateError(s.map(e=>new E(`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:b(e)})}#d(e,t){let n=t[e.encryptedValue];n===void 0?e.error=new E(`Batch delegated decryption returned no value for encrypted value ${e.encryptedValue} on contract ${e.contractAddress}`):e.value=n}#f(e,t,n){return e instanceof C?e:q(e,t,n)}#p(){throw new E(`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 $={AlreadyDelegatedOrRevokedInSameBlock:e=>new fn(`Only one delegate/revoke per (delegator, delegate, contract) per block. Wait for the next block before retrying.`,{cause:e}),SenderCannotBeContractAddress:e=>new pn(`The contract address cannot be the caller address.`,{cause:e}),EnforcedPause:e=>new W(`The ACL contract is paused. Delegation operations are temporarily disabled.`,{cause:e}),SenderCannotBeDelegate:e=>new R(`Cannot delegate to yourself (delegate === msg.sender).`,{cause:e}),DelegateCannotBeContractAddress:e=>new H(`Delegate address cannot be the same as the contract address.`,{cause:e}),DelegateCannotBeWildcard:e=>new U(`Delegate address cannot be the wildcard address; it can only be used 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 V(`The new expiration date is the same as the current one.`,{cause:e}),NotDelegatedYet:e=>new z(`Cannot revoke: no active delegation exists.`,{cause:e})};function Mn(e){return Object.hasOwn($,e)}function Nn(e,t){let n=qt(e);if(n&&Mn(n))return $[n](t);let r=e instanceof Error?e.message:String(e);for(let[e,n]of Object.entries($))if(r.includes(e))return n(t);return null}var Pn=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=F(t),o=F(n),s=F(r);if(o===s)throw new R(`Cannot delegate to yourself (delegate === msg.sender).`);if(o===F(`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`))throw new U(`Delegate address cannot be the wildcard address; it can only be used as the contract address.`);if(o===a)throw new H(`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 V(`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:Y(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 z(`No active delegation found for delegate ${a} on contract ${i}.`);return this.#s({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=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!==Z}#o(e,t){return e===0n?{isActive:!1,expiryTimestamp:e}:e===Z?{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(gn(r,F(t),F(n),F(e)))}async#s({operation:e,signer:t,contractAddress:n,config:r}){try{return await yt({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}}#c(e){if(!(e instanceof v))return;let t=Nn(e.cause??e,e);if(t)throw t}async findInactiveDelegations(e,t,n){let r=/* @__PURE__ */ new Map;return await Promise.all(e.map(async e=>{try{await this.assertDelegationActive(e,t,n)}catch(t){if(t instanceof z||t instanceof B){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 z(`No active delegation from ${i} to ${a} for ${r}`):new B(`Delegation from ${i} to ${a} for ${r} has expired`)}},Fn=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:_.EncryptStart},r);let i=await this.#e.relayer.encryptValues({...e,options:t});return this.#t({type:_.EncryptEnd,durationMs:Date.now()-n},r),i}catch(e){throw this.#t({type:_.EncryptError,error:nt(e),durationMs:Date.now()-n},r),hn(e,`Encryption failed`)}}},In=class{#e;#t;#n;#r;#i;#a;#o=/* @__PURE__ */ new Set;#s;constructor(e){this.#e=e.signer,this.#t=e.router,this.#n=e.cachingService,this.#r=e.credentialService,this.#i=e.clearCredentialsOnWalletChange,this.#a=e.logger,this.#e&&(this.#s=this.#e.walletAccount.subscribe(e=>{this.#c(e).catch(e=>{this.#a.warn(`wallet account handler failed`,{error:e})})}))}onWalletAccountChange(e){return this.#o.add(e),()=>{this.#o.delete(e)}}dispose(){this.#s?.(),this.#s=void 0,this.#o.clear()}async#c(e){let t=e.previous,n=e.next,r=n?.chainId;r!==void 0&&await g(`switch relayer chain`,()=>this.#t.switchChain(r),this.#a),this.#i&&await this.#l(t,n),await Promise.all(Array.from(this.#o,t=>g(`wallet account listener`,()=>t(e),this.#a)))}async#l(e,t){let n=this.#r;n&&await g(`credential wallet account change`,()=>n.handleWalletAccountChange(e,t),this.#a),e&&await g(`clear decrypt cache`,()=>this.#n.clearForRequester(e.address),this.#a)}};const Ln=I.object({kind:I.literal(`ConfidentialTransfer`),from:N,token:N,to:N,amount:I.bigint()}),Rn=I.object({kind:I.literal(`ConfidentialTransferFrom`),from:N,token:N,owner:N,to:N,amount:I.bigint()}),zn=I.object({kind:I.literal(`SetOperator`),from:N,token:N,operator:N,until:cn}),Bn=I.object({kind:I.literal(`Unwrap`),from:N,token:N,to:N,amount:I.bigint()}),Vn=I.object({kind:I.literal(`UnwrapAll`),from:N,token:N,to:N}),Hn=I.object({kind:I.literal(`FinalizeUnwrap`),from:N,wrapper:N,unwrapRequestIdOrAmount:sn}),Un=I.object({kind:I.literal(`ApproveUnderlying`),from:N,underlying:N,spender:N,amount:I.bigint()}),Wn=I.object({kind:I.literal(`Wrap`),from:N,wrapper:N,to:N,amount:I.bigint()}),Gn=sn.check(I.refine(e=>e===`0x`||un(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`)),Kn=I.object({kind:I.literal(`TransferAndCall`),from:N,underlying:N,wrapper:N,amount:I.bigint(),recipientData:I.optional(Gn)}),qn=I.object({kind:I.literal(`DelegateDecryption`),from:N,contractAddress:N,delegateAddress:N,expirationDate:I.optional(I.date())}),Jn=I.object({kind:I.literal(`RevokeDelegation`),from:N,contractAddress:N,delegateAddress:N});I.discriminatedUnion(`kind`,[Ln,Rn,zn,Bn,Vn,Hn,Un,Wn,Kn,qn,Jn]);const Yn=I.strictObject({maxFeePerGas:I.bigint(),maxPriorityFeePerGas:I.bigint()}),Xn=I.object({nonce:I.optional(I.int().check(I.nonnegative())),gasLimit:I.optional(I.bigint()),fees:I.optional(Yn)}),Zn=I.object({address:N,abi:I.array(I.unknown()),functionName:I.string(),args:I.array(I.unknown()),value:I.optional(I.bigint()),gas:I.optional(I.bigint())}),Qn=I.extend(Xn,{from:N,calldata:Zn});var $n=class{#e;#t;#n;constructor(e){this.#e=e.provider,this.#t=e.router,this.#n=e.encryption}async prepare(e,t){t&&=P(Xn,t);let n=await this.#e.getChainId(),r=this.#t.chain.id;if(n!==r)throw new w(`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={calldata:await this.#r(e),from:e.from,nonce:t?.nonce,gasLimit:t?.gasLimit,fees:t?.fees},a=P(Qn,i),o=await this.#e.prepareTransaction(a).catch(t=>{throw St(t,`prepare ${e.kind}`)??t});return{kind:e.kind,unsignedTx:o,from:a.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 w(`OfflineService.prepare: unsupported transaction kind '${e.kind}'.`)}}async#i(e){e=P(Ln,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from},{operation:`offline-confidential-transfer`}),r=t[0];if(!r)throw new T(`Encryption returned no handles for ConfidentialTransfer`);return Ve(e.token,e.to,r,n)}async#a(e){e=P(Rn,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from},{operation:`offline-confidential-transfer-from`}),r=t[0];if(!r)throw new T(`Encryption returned no handles for ConfidentialTransferFrom`);return Be(e.token,e.owner,e.to,r,n)}#o(e){return e=P(zn,e),ge(e.token,e.operator,e.until)}async#s(e){e=P(Bn,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from},{operation:`offline-unwrap`}),r=t[0];if(!r)throw new T(`Encryption returned no handles for Unwrap`);return tt(e.token,e.from,e.to,r,n)}async#c(e){e=P(Vn,e);let t=await this.#e.readContract(pe(e.token,e.from));return de(e.token,e.from,e.to,t)}async#l(e){e=P(Hn,e);let t=await this.#t.relayer.decryptPublicValuesWithSignatures({encryptedValues:[e.unwrapRequestIdOrAmount],options:{operation:`offline-finalize-unwrap`}}).catch(e=>{throw q(e,`Public decryption failed during FinalizeUnwrap`)}),n=t.clearValues[0]?.value;return Oe(n,`FinalizeUnwrap: decryptPublicValuesWithSignatures(handle).clearValue`),ye(e.wrapper,e.unwrapRequestIdOrAmount,n,t.checkSignaturesArgs.decryptionProof)}#u(e){return e=P(Un,e),Ne(e.underlying,e.spender,e.amount)}#d(e){return e=P(Wn,e),he(e.wrapper,e.to,e.amount)}#f(e){return e=P(Kn,e),Pt(e.underlying,e.wrapper,e.amount,e.recipientData)}#p(e){if(e=P(qn,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 R(`Cannot delegate to yourself (delegate === msg.sender).`);if(e.delegateAddress===e.contractAddress)throw new H(`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=P(Jn,e),X(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress)}};function er(e){if(Object.hasOwn(e,`transportKeyPairDerivationSecret`)&&e.transportKeyPairDerivationSecret===void 0)throw new w(`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 tr(e){if(e===void 0)return;let{importScripts:t}=globalThis;if(typeof window<`u`||typeof document<`u`||typeof t==`function`)throw new w(`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 nr(e){if(e===void 0)return;let t=P(o,e);return new m(typeof t==`string`?t:new Uint8Array(t))}var rr=class{#e;provider;signer;storage;registry;permits;delegations;decryption;offline;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;constructor(e,t={}){er(t),tr(t.transportKeyPairDerivationSecret);let n=nr(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 Dn(e.storage,this.#i),this.#u=new Pn({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 l({provider:this.provider,registryAddresses:r,registryTTL:e.registryTTL}),this.#n=r,this.#t=e.registryTTL,this.#l=new f({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 jn({cache:this.#a,credentialService:this.#l,delegationService:this.#u,router:e.router,emitEvent:this.emitEvent.bind(this)})),this.#s=new Fn({router:e.router,emitEvent:this.emitEvent.bind(this)}),this.#o=new In({signer:e.signer,router:e.router,cachingService:this.#a,credentialService:this.#l,clearCredentialsOnWalletChange:e.clearCredentialsOnWalletChange,logger:this.#i}),this.#d=new $n({provider:this.provider,router:e.router,encryption:this.#s,emitEvent:(e,t)=>this.emitEvent(e,t)}),this.permits=new yn({signer:this.signer,provider:this.provider,cachingService:this.#a,credentialService:this.#l,logger:this.#i,emitEvent:this.emitEvent.bind(this)}),this.delegations=new bn({signer:this.signer,provider:this.provider,delegationService:this.#u}),this.decryption=new xn({signer:this.signer,provider:this.provider,router:e.router,decryptionService:this.#c}),this.offline=new Sn(this.#d,this.#l)}onWalletAccountChange(e){return this.#o.onWalletAccountChange(e)}get logger(){return this.#i}get relayer(){return this.#e.relayer}get chains(){return this.#e.chains}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 l({provider:this.provider,registryAddresses:{...this.#n,...e},registryTTL:this.#t})}async encrypt(e,t){return this.#s.encryptValues(e,M(t,`encrypt`))}createToken(e){return new wt(this,e)}createWrappedToken(e){return new tn(this,e)}dispose(){this.#o.dispose(),this.#e.dispose()}terminate(){this.dispose(),this.signer?.dispose?.()}[Symbol.dispose](){this.terminate()}};export{Xt as ACL_TOPICS,W as AclPausedError,$t as AclTopics,vt as BalanceCheckUnavailableError,p as BaseSigner,Ie as ChainMismatchError,Cn as ChromeSessionStorage,w as ConfigurationError,xn as Decryption,E as DecryptionFailedError,t as DefaultRegistryAddresses,pn as DelegationContractIsSelfError,fn as DelegationCooldownError,U as DelegationDelegateCannotBeWildcardError,H as DelegationDelegateEqualsContractError,G as DelegationExpirationTooSoonError,B as DelegationExpiredError,V as DelegationExpiryUnchangedError,z as DelegationNotFoundError,K as DelegationNotPropagatedError,R as DelegationSelfNotAllowedError,bn as Delegations,Le as ERC1363_INTERFACE_ID,Tt as ERC20ReadFailedError,qe as ERC7984_INTERFACE_ID,Ue as ERC7984_WRAPPER_INTERFACE_ID,Et as EncryptOffloadUnavailableError,T as EncryptionFailedError,Ye as HcuBlockLimitExceededError,Ge as HcuTransactionLimitExceededError,u as IndexedDBStorage,ht as InsufficientAllowanceError,gt as InsufficientConfidentialBalanceError,xt as InsufficientERC20BalanceError,D as InvalidTransportKeyPairError,Dt as KeyWrappingError,Z as MAX_UINT64,r as MemoryStorage,c as MutableWalletAccountStore,k as NoCiphertextError,L as NotEntitledError,Sn as Offline,yn as Permits,jt as PreparedPermitChainMismatchError,Ot as PreparedPermitExpiredError,S as RelayerRequestFailedError,O as RevokedKmsContextError,j as RpcRateLimitError,Ae as SignerNotConfiguredError,ke as SignerRequiredError,A as SigningFailedError,At as SigningRejectedError,Kt as TOKEN_TOPICS,wt as Token,Bt as Topics,v as TransactionRevertedError,Mt as TransportKeyPairChangedError,kt as TransportKeyPairExpiredError,an as UnlistedConfidentialTokenError,Lt as UnshieldAlreadyFinalizedError,Rt as VaultBatchNotDispatchedError,It as VaultBatcherPausedError,Ft as VaultGroupJoinUnconfirmedError,Q as WILDCARD_CONTRACT,je as WalletAccountNotReadyError,Ce as WalletNotConnectedError,tn as WrappedToken,l as WrappersRegistry,bt as ZERO_ENCRYPTED_VALUE,C as ZamaError,x as ZamaErrorCode,rr as ZamaSDK,_ as ZamaSDKEvents,et as allowanceContract,ce as anvil,Ne as approveContract,$e as balanceOfContract,ie as bscTestnet,oe as chains,wn as chromeSessionStorage,e as cleartext,pe as confidentialBalanceOfContract,fe as confidentialTotalSupplyContract,xe as confidentialTransferAndCallContract,Ve as confidentialTransferContract,ue as confidentialTransferFromAndCallContract,Be as confidentialTransferFromContract,vn as createConfig,d as createWalletAccountStore,Te as decimalsContract,Zt as decodeAclEvent,en as decodeAclEvents,Vt as decodeConfidentialTransfer,Jt as decodeDelegatedForUserDecryption,nn as decodeOnChainEvent,Ht as decodeOnChainEvents,Ut as decodeRevokedDelegationForUserDecryption,Qt as decodeUnwrapFinalized,Yt as decodeUnwrapRequested,Gt as decodeWrap,Y as delegateForUserDecryptionContract,ye as finalizeUnwrapContract,Wt as findDelegatedForUserDecryption,zt as findRevokedDelegationForUserDecryption,rn as findUnwrapRequested,on as findWrap,Me as getConfidentialTokenAddressContract,gn as getDelegationExpiryContract,Ke as getTokenAddressContract,Je as getTokenPairContract,Pe as getTokenPairsContract,He as getTokenPairsLengthContract,Xe as getTokenPairsSliceContract,ne as hardhat,ee as hoodi,s as indexedDBStorage,be as inferredTotalSupplyContract,ze as isConfidentialTokenContract,Fe as isConfidentialTokenValidContract,Re as isConfidentialWrapperContract,mt as isEncryptedValueZero,_n as isHandleDelegatedContract,Se as isOperatorContract,it as isRetryable,ae as mainnet,dn as matchZamaError,i as memoryStorage,Qe as nameContract,n as parsePreparedPermit,se as polygon,te as polygonAmoy,me as rateContract,lt as retryAfterSeconds,X as revokeDelegationContract,re as sepolia,ge as setOperatorContract,Ze as supportsInterfaceContract,Ee as symbolContract,Pt as transferAndCallContract,ve as underlyingContract,we as unwrapAmountContract,tt as unwrapContract,de as unwrapFromBalanceContract,De as unwrapRequesterContract,he as wrapContract,le as zenithTrexTestnet};
|
|
1
|
+
import{t as e}from"./cleartext-C1Y5zc1Y.js";import{_ as t,a as n,c as r,d as i,f as a,g as o,h as s,i as c,l,m as u,n as d,o as f,p,r as m,s as ee,t as te,u as ne,v as re}from"./base-signer-p5iz9eeb.js";import{a as ie,c as ae,i as oe,l as se,n as ce,o as le,r as ue,s as de,t as fe,u as pe}from"./chains-BQXSxIwU.js";import{A as me,B as h,C as he,D as ge,E as _e,F as g,G as ve,H as ye,I as _,J as be,K as v,L as xe,M as Se,N as Ce,O as we,P as Te,S as Ee,T as De,U as Oe,W as ke,X as y,Y as Ae,_ as je,a as Me,b as Ne,c as Pe,d as Fe,f as b,h as Ie,j as Le,k as Re,l as ze,m as Be,n as Ve,o as He,p as x,q as Ue,s as We,t as S,u as Ge,v as Ke,w as qe,x as Je,y as Ye,z as Xe}from"./alignment-o-YIndFR.js";import{C,_ as Ze,a as Qe,c as w,f as $e,g as et,h as tt,i as T,m as nt,n as E,o as rt,r as D,s as it,t as O,v as at,x as ot,y as st}from"./relayer-nWfQAlo7.js";import{c as ct,d as lt,f as ut,i as dt,l as ft,n as pt,o as mt,p as ht,r as gt,s as _t,t as vt,u as k}from"./token-AXsOIUDB.js";import{n as yt,r as A,t as j}from"./encryption-BT886Jlj.js";import{a as bt,c as xt,d as St,i as Ct,l as M,n as wt,o as Tt,s as Et,t as Dt,u as Ot}from"./signing-CVEOw21I.js";import{n as kt,r as N}from"./fatal-batch-BYeHrf0V.js";import{a as P,c as At,i as jt,l as Mt,n as F,o as Nt,r as Pt,s as Ft,t as I}from"./log-decoding-ZthqwHOv.js";import{r as L}from"./telemetry-YFH36F_7.js";import{t as R}from"./validation-CZfDLOUh.js";import{a as It,i as Lt,n as Rt,o as zt,r as Bt,s as Vt,t as Ht}from"./wrappers-registry-Cm3JJeqx.js";import{getAddress as z,keccak256 as Ut,size as Wt,toBytes as Gt,zeroAddress as Kt}from"viem";import{z as B}from"zod/mini";function qt(e,t){if(e instanceof D){let n=t[e.code];if(n)return n(e)}return t._?.(e)}var Jt=class extends D{encryptedValue;contractAddress;account;constructor(e,t){super(T.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}},V=class extends D{constructor(e,t){super(T.DelegationSelfNotAllowed,e,t),this.name=`DelegationSelfNotAllowedError`}},Yt=class extends D{constructor(e,t){super(T.DelegationCooldown,e,t),this.name=`DelegationCooldownError`}},H=class extends D{constructor(e,t){super(T.DelegationNotFound,e,t),this.name=`DelegationNotFoundError`}},Xt=class extends D{constructor(e,t){super(T.DelegationExpired,e,t),this.name=`DelegationExpiredError`}},Zt=class extends D{constructor(e,t){super(T.DelegationExpiryUnchanged,e,t),this.name=`DelegationExpiryUnchangedError`}},U=class extends D{constructor(e,t){super(T.DelegationDelegateEqualsContract,e,t),this.name=`DelegationDelegateEqualsContractError`}},Qt=class extends D{constructor(e,t){super(T.DelegationDelegateCannotBeWildcard,e,t),this.name=`DelegationDelegateCannotBeWildcardError`}},$t=class extends D{constructor(e,t){super(T.DelegationContractIsSelf,e,t),this.name=`DelegationContractIsSelfError`}},en=class extends D{constructor(e,t){super(T.AclPaused,e,t),this.name=`AclPausedError`}},W=class extends D{constructor(e,t){super(T.DelegationExpirationTooSoon,e,t),this.name=`DelegationExpirationTooSoonError`}},G=class extends D{constructor(e,t){super(T.DelegationNotPropagated,e,t),this.name=`DelegationNotPropagatedError`}};function tn(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 nn=class extends D{unwrapTxHash;unwrapRequestId;constructor(e,t,n){super(T.UnshieldAlreadyFinalized,e,n),this.name=`UnshieldAlreadyFinalizedError`,this.unwrapTxHash=t.unwrapTxHash,this.unwrapRequestId=t.unwrapRequestId}};const rn=`InvalidUnwrapRequest`,an=Ut(Gt(`${rn}(bytes32)`)).slice(0,10);function on(e){for(let t=e;t instanceof Error;t=t.cause)if(tn(t)===rn||t.message.includes(rn)||t.message.includes(an))return!0;return!1}const sn=[j,Tt,E,G,wt,Dt,Jt,N,Ct,M];function K(e,t,n={}){if(sn.some(t=>e instanceof t))return e;let r=e instanceof Error?e.message:t;if(e instanceof Error&&nt(e.message))return new Ct(e.message,{cause:e});if(at(e))return new M(`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&&tt(e.message))return n.isDelegated?new G(`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 Jt({encryptedValue:ot(e.message)??``,contractAddress:n.contractAddress??``,account:n.account??``},{cause:e});if($e(e))return new N(r,{cause:e,retryAfter:w(e)});let i=it(e);return i===void 0&&st(e)?new N(r,{cause:e,retryAfter:w(e)}):i===400?new Tt(e instanceof Error?e.message:`No ciphertext for this account`,{cause:e}):n.isDelegated&&i===500?new G(`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}):et(e)||i!==void 0?new E(r,i,{cause:e,retryAfter:w(e),retryable:Ze(e)||void 0}):new j(t,{cause:e})}function cn(e,t){if(e instanceof D)return e;let n=it(e),r=Ze(e);return n!==void 0||et(e)?new E(e instanceof Error?e.message:t,n,{cause:e,retryAfter:w(e),retryable:r||void 0}):new A(t,{cause:e})}const ln=[{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 un(e,t,n,r=`0x`){return{address:e,abi:ln,functionName:`transferAndCall`,args:[t,n,r]}}const q=[{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 dn(e,t,n,r){return{address:e,abi:q,functionName:`delegateForUserDecryption`,args:[t,n,r]}}function fn(e,t,n){return{address:e,abi:q,functionName:`revokeDelegationForUserDecryption`,args:[t,n]}}function pn(e,t,n,r){return{address:e,abi:q,functionName:`getUserDecryptionDelegationExpirationDate`,args:[t,n,r]}}function mn(e,t,n,r,i){return{address:e,abi:q,functionName:`isHandleDelegatedForUserDecryption`,args:[t,n,r,i]}}const J=2n**64n-1n,Y=`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`;function hn(e){return c(e.signer,e.provider,e)}const X={ConfidentialTransfer:I(`ConfidentialTransfer(address,address,bytes32)`),Wrap:I(`Wrap(address,uint256,bytes32)`),UnwrapRequested:I(`UnwrapRequested(address,bytes32,bytes32)`),UnwrapFinalized:I(`UnwrapFinalized(address,bytes32,bytes32,uint64)`)};function gn(e){return e.topics[0]!==X.ConfidentialTransfer||e.topics.length<4?null:{eventName:`ConfidentialTransfer`,from:F(e.topics[1]),to:F(e.topics[2]),encryptedAmount:Pt(e.topics[3])}}function Z(e){return e.topics[0]!==X.Wrap||e.topics.length<2?null:{eventName:`Wrap`,to:F(e.topics[1]),roundedAmount:P(e.data,0),encryptedWrappedAmount:Nt(e.data,1)}}function _n(e){return e.topics[0]!==X.UnwrapRequested||e.topics.length<3?null:{eventName:`UnwrapRequested`,receiver:F(e.topics[1]),unwrapRequestId:Pt(e.topics[2]),encryptedAmount:Nt(e.data,0)}}function vn(e){return e.topics[0]!==X.UnwrapFinalized||e.topics.length<3?null:{eventName:`UnwrapFinalized`,receiver:F(e.topics[1]),unwrapRequestId:Pt(e.topics[2]),encryptedAmount:Nt(e.data,0),cleartextAmount:P(e.data,1)}}function yn(e){return gn(e)??Z(e)??_n(e)??vn(e)}function bn(e){let t=[];for(let n of e){let e=yn(n);e&&t.push(e)}return t}function xn(e){for(let t of e){let e=_n(t);if(e)return e}return null}function Sn(e){for(let t of e){let e=Z(t);if(e)return e}return null}const Cn=[X.ConfidentialTransfer,X.Wrap,X.UnwrapRequested,X.UnwrapFinalized],Q={DelegatedForUserDecryption:I(`DelegatedForUserDecryption(address,address,address,uint64,uint64,uint64)`),RevokedDelegationForUserDecryption:I(`RevokedDelegationForUserDecryption(address,address,address,uint64,uint64)`)};function wn(e){return e.topics[0]!==Q.DelegatedForUserDecryption||e.topics.length<3?null:{eventName:`DelegatedForUserDecryption`,delegator:F(e.topics[1]),delegate:F(e.topics[2]),contractAddress:jt(e.data,0),delegationCounter:P(e.data,1),oldExpirationDate:P(e.data,2),newExpirationDate:P(e.data,3)}}function Tn(e){return e.topics[0]!==Q.RevokedDelegationForUserDecryption||e.topics.length<3?null:{eventName:`RevokedDelegationForUserDecryption`,delegator:F(e.topics[1]),delegate:F(e.topics[2]),contractAddress:jt(e.data,0),delegationCounter:P(e.data,1),oldExpirationDate:P(e.data,2)}}function En(e){return wn(e)??Tn(e)}function Dn(e){let t=[];for(let n of e){let e=En(n);e&&t.push(e)}return t}function On(e){for(let t of e){let e=wn(t);if(e)return e}return null}function kn(e){for(let t of e){let e=Tn(t);if(e)return e}return null}const An=[Q.DelegatedForUserDecryption,Q.RevokedDelegationForUserDecryption];var jn=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 v(this.#r,e)}#s(e,t){throw this.#a({type:h.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)}registerPermit(e,t){return this.batchRegisterPermits([{prepared:e,signature:t}])}async batchRegisterPermits(e){let t;try{t=this.#o(`registerPermit`)}catch(e){this.#s(`registerPermit`,e)}await t.batchRegisterPermits(e),await Promise.all([...new Set(e.map(e=>e.prepared.signerAddress))].map(e=>this.#c(e)))}async revokePermits(e){let t=this.#o(`revokePermits`),n=await S(`revokePermits`,this.#e,this.#t),r=z(n.address);try{await t.revokePermits(e)}finally{await this.#c(r)}}async clear(){let e=this.#o(`clear`),t=await S(`clear`,this.#e,this.#t),n=z(t.address);try{await e.clearCredentials()}finally{await this.#c(n)}}async#c(e){await _(`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)}},Mn=class{#e;#t;#n;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.delegationService}#r(e){return v(this.#e,e)}async delegateDecryption({contractAddress:e,delegateAddress:t,expirationDate:n}){let r=this.#r(`delegateDecryption`),i=await S(`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 S(`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)}},Nn=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 v(this.#r,e)}async decryptValues(e,t){let n=this.#i(`decryptValues`),r=await S(`decryptValues`,this.#e,this.#t);return n.decryptValues(e,r.address,L(t,`decrypt-values`))}async delegatedDecryptValues(e,t,n=t,r){let i=this.#i(`delegatedDecryptValues`),a=await S(`delegatedDecryptValues`,this.#e,this.#t);return i.delegatedDecryptValues(e,t,a.address,n,L(r,`delegated-decrypt-values`))}async decryptPublicValues(e,t){if(e.length===0)return{clearValues:{},decryptionProof:`0x`,abiEncodedClearValues:`0x`};let n=L(t,`decrypt-public-values`);try{let t=await this.#n.relayer.decryptPublicValuesWithSignatures({encryptedValues:e,options:n}),r={};return t.checkSignaturesArgs.handlesList.forEach((e,n)=>{Xe(t.clearValues[n],`result.clearValues[${n}]`),r[e]=t.clearValues[n].value}),{clearValues:r,abiEncodedClearValues:t.checkSignaturesArgs.abiEncodedCleartexts,decryptionProof:t.checkSignaturesArgs.decryptionProof}}catch(e){throw K(e,`Public decryption failed`)}}async delegatedBatchDecryptValues({encryptedInputs:e,delegatorAddress:t,accountAddress:n=t,maxConcurrency:r,waitForPropagation:i,operation:a}){let o=this.#i(`delegatedBatchDecryptValues`),s=await S(`delegatedBatchDecryptValues`,this.#e,this.#t);return o.delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:s.address,accountAddress:n,maxConcurrency:r,waitForPropagation:i,operation:a??`delegated-batch-decrypt-values`})}},Pn=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)}batchPreparePermits(e){return this.#t.batchPreparePermits(e)}},Fn=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 In=new Fn;function $(e){return`zama:pending-unshield:${i(e)}`}const Ln=B.union([B.pipe(p,B.transform(e=>({unwrapTxHash:e}))),B.pipe(B.object({version:B.literal(1),unwrapTxHash:p,unwrapRequestId:B.optional(p)}),B.transform(({unwrapTxHash:e,unwrapRequestId:t})=>({unwrapTxHash:e,unwrapRequestId:t})))]);async function Rn(e,t,n,r){r===void 0?await e.set($(t),n):await e.set($(t),{version:1,unwrapTxHash:n,unwrapRequestId:r})}async function zn(e,t){let n=$(t),r=await e.get(n);if(r==null)return null;let i=Ln.safeParse(r);return i.success?i.data:(await e.delete(n),null)}async function Bn(e,t){await e.delete($(t))}var Vn=class extends vt{#e;#t=null;#n=null;#r(e){try{return Xe(this.sdk.signer,`WrappedToken.sdk.signer`),this.sdk.signer}catch(t){throw new ye(e,{cause:t})}}async underlying(){return this.#f()}async isPayable(){if(this.#n!==null)return this.#n;try{let e=await this.#f();this.#n=await this.sdk.provider.readContract(Ge(e))}catch{this.#n=!1}return this.#n}async allowance(e){let t=await this.#f();return this.sdk.provider.readContract(b(t,z(e),this.address))}async shield(e,t){let n=await S(`shield`,this.sdk.signer,this.sdk.provider),r=await this.isPayable(),i=await this.#f(),a=z(n.address),o;try{o=await this.sdk.provider.readContract(Be(i,a))}catch(e){throw e instanceof D?e:new k(`Could not read ERC-20 balance for shield validation (token: ${i})`,{cause:C(e)})}if(o<e)throw new ht(`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?z(r.to):n,a=i===n?`0x`:i;return this.submitTransaction({operation:`shield:transferAndCall`,config:un(t,this.address,e,a),onSubmitted:r?.onShieldSubmitted})}async wrap(e,t){this.#r(`wrap`);let n=await S(`wrap`,this.sdk.signer,this.sdk.provider),r=await this.#f(),i=z(n.address),a;try{a=await this.sdk.provider.readContract(Be(r,i))}catch(e){throw e instanceof D?e:new k(`Could not read ERC-20 balance for wrap validation (token: ${r})`,{cause:C(e)})}if(a<e)throw new ht(`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(b(r,i,this.address))}catch(e){throw e instanceof D?e:new k(`Could not read ERC-20 allowance for wrap validation (token: ${r})`,{cause:C(e)})}if(o<e)throw new lt(`Insufficient allowance for wrap: requested ${e}, approved ${o}. Call approveUnderlying() first (token: ${r}).`,{requested:e,available:o,token:r});let s=t?.to?z(t.to):i;return this.submitTransaction({operation:`wrap`,config:g(this.address,s,e),onSubmitted:t?.onWrapSubmitted})}async#a(e,t,n){this.#r(`shield`);let r=n?.approvalStrategy??`exact`;r!==`skip`&&await this.#m(e,r===`max`,n);let i=n?.to?z(n.to):t;return this.submitTransaction({operation:`shield:approveAndWrap`,config:g(this.address,i,e),onSubmitted:n?.onShieldSubmitted})}async approveUnderlying(e){this.#r(`approveUnderlying`);let t=await S(`approveUnderlying`,this.sdk.signer,this.sdk.provider),n=await this.#f(),r=z(t.address),i=e??2n**256n-1n;return i>0n&&await this.sdk.provider.readContract(b(n,r,this.address))>0n&&await this.submitTransaction({operation:`approveUnderlying:reset`,config:x(n,this.address,0n)}),this.submitTransaction({operation:`approveUnderlying`,config:x(n,this.address,i)})}async unshield(e,t){let{skipBalanceCheck:n=!1,onUnwrapSubmitted:r,onFinalizing:i,onFinalizeSubmitted:a}=t??{};n||await this.assertConfidentialBalance(e,`unshield`);let o={onFinalizing:i,onFinalizeSubmitted:a},s=crypto.randomUUID(),c=await this.#o(e,`unshield`);return _(`unshield: onUnwrapSubmitted`,()=>r?.(c.txHash),this.sdk.logger),this.#p(c.unwrapRequestId,c.txHash,s,o,`unshield`)}async unshieldAll(e){let t=crypto.randomUUID(),n=await this.unwrapAll();return _(`unshieldAll: onUnwrapSubmitted`,()=>e?.onUnwrapSubmitted?.(n.txHash),this.sdk.logger),this.#p(n.unwrapRequestId,n.txHash,t,e,`unshield-all`)}async resumeUnshield(e,t){let n;try{n=await this.sdk.provider.waitForTransactionReceipt(e)}catch(e){throw e instanceof D?e:new y(`Failed to get unwrap receipt`,{cause:e})}if(n.status===`reverted`)throw new y(`Unwrap transaction ${e} reverted, so there is nothing to resume`);let r=this.#c(n.logs);if(await this.#l(r))throw await this.#d(`resumeUnshield`),new nn(`Nothing to resume: the unwrap request was already finalized on-chain and the funds were delivered.`,{unwrapTxHash:e,unwrapRequestId:r});return this.#p(r,e,crypto.randomUUID(),t,`resume-unshield`)}async getPendingUnshield(){let e=await zn(this.sdk.storage,this.address);return e?await this.#u(e)?(await this.#d(`getPendingUnshield`),null):e.unwrapTxHash:null}async unwrap(e){return this.#o(e,`unwrap`)}async#o(e,t){this.#r(`unwrap`);let n=await S(`unwrap`,this.sdk.signer,this.sdk.provider),r=z(n.address),{encryptedValues:i,inputProof:a}=await this.sdk.encrypt({values:[{value:e,type:`euint64`}],contractAddress:this.address,userAddress:r},{operation:t}),[o]=i;if(!o)throw new A(`Encryption returned no encrypted values`);let s=await this.submitTransaction({operation:`unwrap`,config:Se(this.address,r,r,o,a)});return{...s,unwrapRequestId:this.#c(s.receipt.logs)}}async unwrapAll(){this.#r(`unwrapAll`);let e=await S(`unwrapAll`,this.sdk.signer,this.sdk.provider),t=z(e.address),n=await this.readConfidentialBalanceOf(t);if(ct(n))throw new j(`Cannot unshield: balance is zero`);let r=await this.submitTransaction({operation:`unwrapAll`,config:Ce(this.address,t,t,n)});return{...r,unwrapRequestId:this.#c(r.receipt.logs)}}async finalizeUnwrap(e){return this.#s(e,`finalize-unwrap`)}async#s(e,t){this.#r(`finalizeUnwrap`),await Ve(`finalizeUnwrap`,this.sdk.signer,this.sdk.provider);let n=await this.sdk.decryption.decryptPublicValues([e],{operation:t}),r=n.clearValues[e];return xe(r,`finalizeUnwrap: clearValue`),this.submitTransaction({operation:`finalizeUnwrap`,config:De(this.address,e,r,n.decryptionProof)})}#c(e){let t=xn(e.filter(e=>e.address===void 0||z(e.address)===this.address));if(!t)throw new y(`No UnwrapRequested event from this wrapper found in the unwrap receipt`);return t.unwrapRequestId}async#l(e){try{return await this.sdk.provider.readContract(Te(this.address,e))===Kt}catch{return!1}}async#u(e){let t=e.unwrapRequestId;if(t===void 0)try{let n=await this.sdk.provider.waitForTransactionReceipt(e.unwrapTxHash);t=this.#c(n.logs)}catch{return!1}return this.#l(t)}async#d(e){await _(`${e}: clearPendingUnshield`,()=>Bn(this.sdk.storage,this.address),this.sdk.logger)}async#f(){return this.#e===void 0?(this.#t||=this.sdk.provider.readContract(me(this.address)).then(e=>(this.#e=e,this.#t=null,e)).catch(e=>{throw this.#t=null,e}),this.#t):this.#e}async#p(e,t,n,r,i){this.emit({type:h.UnshieldPhase1Submitted,txHash:t,operationId:n}),await _(`unshield: savePendingUnshield`,()=>Rn(this.sdk.storage,this.address,t,e),this.sdk.logger),this.emit({type:h.UnshieldPhase2Started,operationId:n}),_(`unshield: onFinalizing`,()=>r?.onFinalizing?.(),this.sdk.logger);let a;try{a=await this.#s(e,i)}catch(n){throw on(n)||n instanceof y&&await this.#l(e)?(await this.#d(`unshield`),new nn(`The unwrap request was finalized concurrently — the funds were already delivered.`,{unwrapTxHash:t,unwrapRequestId:e},{cause:n})):n}return this.emit({type:h.UnshieldPhase2Submitted,txHash:a.txHash,operationId:n}),_(`unshield: onFinalizeSubmitted`,()=>r?.onFinalizeSubmitted?.(a.txHash),this.sdk.logger),await this.#d(`unshield`),a}async#m(e,t,n){this.#r(`approveUnderlying`);let r=await this.#f(),i=await S(`approveUnderlying`,this.sdk.signer,this.sdk.provider),a=z(i.address),o=await this.sdk.provider.readContract(b(r,a,this.address));if(o>=e)return;o>0n&&await this.submitTransaction({operation:`approveUnderlying:reset`,config:x(r,this.address,0n)});let s=t?2n**256n-1n:e;await this.submitTransaction({operation:`approveUnderlying`,config:x(r,this.address,s),onSubmitted:n?.onApprovalSubmitted})}};const Hn=B.union([B.bigint(),B.boolean(),a]),Un=B.array(B.string());var Wn=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=Hn.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=z(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}:${z(e)}:${z(t)}:${n.toLowerCase()}`}async#l(){let e=await this.#e.get(this.#r);if(e===null)return[];let t=Un.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 Gn(e,t){let n=Kn(e,t);if(!n)throw new j(`No permit covers contract ${t} after allow()`);return{privateKey:e.keypair.privateKey,publicKey:e.keypair.publicKey,serializedPermit:n.serializedPermit}}function Kn(e,t){let n=i(t);return e.permissions.find(e=>e.contractAddresses.includes(n))}const qn=e=>new Promise(t=>setTimeout(t,e));var Jn=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=z(t);return this.#s(e,{requesterAddress:r,errorMessage:`Failed to decrypt encrypted values`},n)}async delegatedDecryptValues(e,t,n,r,i){let a=z(t),o=z(n),s={spent:!1};return this.#a(i?.waitForPropagation??!0,()=>this.#s(e,{requesterAddress:z(r),delegator:a,validate:e=>this.#m(e,{delegatorAddress:a,delegateAddress:o}),errorMessage:`Failed to decrypt delegated encrypted values`},{operation:i?.operation},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 G))throw t;await qn(2e3)}throw n}async delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:n,accountAddress:r,maxConcurrency:i=5,waitForPropagation:a=!0,operation:o}){let s=e.map(e=>({encryptedValue:e.encryptedValue,contractAddress:z(e.contractAddress)}));if(s.length===0)return{items:s};let c=z(r);try{let e=await this.delegatedDecryptValues(s.map(({encryptedValue:e,contractAddress:t})=>({encryptedValue:e,contractAddress:t})),t,n,c,{waitForPropagation:a,operation:o});for(let t of s)this.#d(t,e);return{items:s}}catch(e){if(kt(e))throw e;if(s.length===1){let[n=this.#p()]=s;return n.error=this.#f(e,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:n.contractAddress,account:z(t)}),{items:s}}}let l=!1,u;if(await dt(s.map(e=>async()=>{if(!l)try{let r=await this.delegatedDecryptValues([{encryptedValue:e.encryptedValue,contractAddress:e.contractAddress}],t,n,c,{waitForPropagation:!1,operation:o});this.#d(e,r)}catch(n){if(kt(n)){l=!0,u??=n;return}e.error=this.#f(n,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:e.contractAddress,account:z(t)})}}),i),u!==void 0)throw u;return{items:s}}async#o(e,t,n,r){let i=Gn(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&&nt(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:z(e.contractAddress)})),a={},o=[];for(let e of i)ct(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 st(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=/* @__PURE__ */ 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 f=[];for(let[e,t]of d)for(let n of _t(t))f.push({contractAddress:e,encryptedValues:n});let p=Date.now(),m=l.map(e=>e.encryptedValue);try{this.#i({type:h.DecryptStart,encryptedValues:m});try{await this.#c(t,u,f,a,n)}catch(e){if(!(e instanceof M)||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 Dt?new M(`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,f.filter(({encryptedValues:e})=>e.some(e=>a[e]===void 0)),a,n)}let e={};for(let t of m){let n=a[t];n!==void 0&&(e[t]=n)}return this.#i({type:h.DecryptEnd,durationMs:Date.now()-p,encryptedValues:m,result:e}),a}catch(e){let n=e instanceof D&&e.cause instanceof Error?e.cause:e;throw this.#i({type:h.DecryptError,error:C(n),durationMs:Date.now()-p,encryptedValues:m}),K(e,t.errorMessage,{isDelegated:t.delegator!==void 0})}}async#c(e,t,n,r,i){let a=(await dt(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 M)??a[0]}async#l(e,t,n,r,i,a){let o;try{o=await this.#o(t,n,r,a)}catch(t){throw K(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 j(`${e.errorMessage}: relayer returned no clear value for ${s.length} of ${r.length} handle(s) on ${n}`,{cause:AggregateError(s.map(e=>new j(`No clear value for handle ${e} on ${n}`)),`${s.length} handle(s) missing a clear value on ${n}`)})}#u(e,t){return new N(`RPC provider rate-limited ${t}; retry with backoff.`,{cause:e,retryAfter:w(e)})}#d(e,t){let n=t[e.encryptedValue];n===void 0?e.error=new j(`Batch delegated decryption returned no value for encrypted value ${e.encryptedValue} on contract ${e.contractAddress}`):e.value=n}#f(e,t,n){return e instanceof D?e:K(e,t,n)}#p(){throw new j(`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 Yn={AlreadyDelegatedOrRevokedInSameBlock:e=>new Yt(`Only one delegate/revoke per (delegator, delegate, contract) per block. Wait for the next block before retrying.`,{cause:e}),SenderCannotBeContractAddress:e=>new $t(`The contract address cannot be the caller address.`,{cause:e}),EnforcedPause:e=>new en(`The ACL contract is paused. Delegation operations are temporarily disabled.`,{cause:e}),SenderCannotBeDelegate:e=>new V(`Cannot delegate to yourself (delegate === msg.sender).`,{cause:e}),DelegateCannotBeContractAddress:e=>new U(`Delegate address cannot be the same as the contract address.`,{cause:e}),DelegateCannotBeWildcard:e=>new Qt(`Delegate address cannot be the wildcard address; it can only be used as the contract address.`,{cause:e}),ExpirationDateBeforeOneHour:e=>new W(`Expiration date must be at least 1 hour in the future.`,{cause:e}),ExpirationDateAlreadySetToSameValue:e=>new Zt(`The new expiration date is the same as the current one.`,{cause:e}),NotDelegatedYet:e=>new H(`Cannot revoke: no active delegation exists.`,{cause:e})};function Xn(e){return Object.hasOwn(Yn,e)}function Zn(e,t){let n=tn(e);if(n&&Xn(n))return Yn[n](t);let r=e instanceof Error?e.message:String(e);for(let[e,n]of Object.entries(Yn))if(r.includes(e))return n(t);return null}var Qn=class{#e;#t;#n;#r;constructor({provider:e,router:t,emitEvent:n=()=>{},logger:r}){this.#t=e,this.#e=t,this.#r=r,this.#n=n}async delegateDecryption(e,{contractAddress:t,delegateAddress:n,delegatorAddress:r,expirationDate:i}){if(i&&i.getTime()<Date.now()+36e5)throw new W(`Expiration date must be at least 1 hour in the future`);let a=z(t),o=z(n),s=z(r);if(o===s)throw new V(`Cannot delegate to yourself (delegate === msg.sender).`);if(o===z(`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`))throw new Qt(`Delegate address cannot be the wildcard address; it can only be used as the contract address.`);if(o===a)throw new U(`Delegate address cannot be the same as the contract address (${a}).`);let c=this.#e.relayer.chain.aclContractAddress,l=i?BigInt(Math.floor(i.getTime()/1e3)):J,u;try{u=await this.getDelegationExpiry({contractAddress:a,delegatorAddress:s,delegateAddress:o})}catch(e){this.#r.warn(`delegateDecryption: pre-flight expiry check failed`,{error:e}),u=-1n}if(u===l)throw new Zt(`The new expiration date (${l}) is the same as the current one. No on-chain change needed.`);return a!==z(`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`)&&await this.#i({contractAddress:a,delegatorAddress:s,delegateAddress:o}),this.#s({operation:`delegateDecryption`,signer:e,contractAddress:a,config:dn(c,o,a,l)})}async revokeDelegation(e,{contractAddress:t,delegateAddress:n,delegatorAddress:r}){let i=z(t),a=z(n),o=z(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 H(`No active delegation found for delegate ${a} on contract ${i}.`);return this.#s({operation:`revokeDelegation`,signer:e,contractAddress:i,config:fn(s,a,i)})}async isDelegated(e){return(await this.getStatus(e)).isActive}async getStatus(e){let t=z(e.contractAddress)===Y,[n,r]=await Promise.all([this.getDelegationExpiry(e),t?Promise.resolve(0n):this.getDelegationExpiry({...e,contractAddress:Y})]),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:Y});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!==J}#o(e,t){return e===0n?{isActive:!1,expiryTimestamp:e}:e===J?{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(pn(r,z(t),z(n),z(e)))}async#s({operation:e,signer:t,contractAddress:n,config:r}){try{return await pt({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}}#c(e){if(!(e instanceof y))return;let t=Zn(e.cause??e,e);if(t)throw t}async findInactiveDelegations(e,t,n){let r=/* @__PURE__ */ new Map;return await Promise.all(e.map(async e=>{try{await this.assertDelegationActive(e,t,n)}catch(t){if(t instanceof H||t instanceof Xt){let n=z(e);r.set(n,t);return}throw t}})),r}async assertDelegationActive(e,t,n){let r=z(e),i=z(t),a=z(n),{isActive:o,expiryTimestamp:s}=await this.getStatus({contractAddress:r,delegatorAddress:i,delegateAddress:a});if(!o)throw s===0n?new H(`No active delegation from ${i} to ${a} for ${r}`):new Xt(`Delegation from ${i} to ${a} for ${r} has expired`)}},$n=class{#e;#t;constructor({router:e,emitEvent:t}){this.#e=e,this.#t=t}async encryptValues(e,t){let n=Date.now(),r=z(e.contractAddress);try{this.#t({type:h.EncryptStart},r);let i=await this.#e.relayer.encryptValues({...e,options:t});return this.#t({type:h.EncryptEnd,durationMs:Date.now()-n},r),i}catch(e){throw this.#t({type:h.EncryptError,error:C(e),durationMs:Date.now()-n},r),cn(e,`Encryption failed`)}}},er=class{#e;#t;#n;#r;#i;#a;#o=/* @__PURE__ */ new Set;#s;constructor(e){this.#e=e.signer,this.#t=e.router,this.#n=e.cachingService,this.#r=e.credentialService,this.#i=e.clearCredentialsOnWalletChange,this.#a=e.logger,this.#e&&(this.#s=this.#e.walletAccount.subscribe(e=>{this.#c(e).catch(e=>{this.#a.warn(`wallet account handler failed`,{error:e})})}))}onWalletAccountChange(e){return this.#o.add(e),()=>{this.#o.delete(e)}}dispose(){this.#s?.(),this.#s=void 0,this.#o.clear()}async#c(e){let t=e.previous,n=e.next,r=n?.chainId;r!==void 0&&await _(`switch relayer chain`,()=>this.#t.switchChain(r),this.#a),this.#i&&await this.#l(t,n),await Promise.all(Array.from(this.#o,t=>_(`wallet account listener`,()=>t(e),this.#a)))}async#l(e,t){let n=this.#r;n&&await _(`credential wallet account change`,()=>n.handleWalletAccountChange(e,t),this.#a),e&&await _(`clear decrypt cache`,()=>this.#n.clearForRequester(e.address),this.#a)}};const tr=B.object({kind:B.literal(`ConfidentialTransfer`),from:a,token:a,to:a,amount:B.bigint()}),nr=B.object({kind:B.literal(`ConfidentialTransferFrom`),from:a,token:a,owner:a,to:a,amount:B.bigint()}),rr=B.object({kind:B.literal(`SetOperator`),from:a,token:a,operator:a,until:u}),ir=B.object({kind:B.literal(`Unwrap`),from:a,token:a,to:a,amount:B.bigint()}),ar=B.object({kind:B.literal(`UnwrapAll`),from:a,token:a,to:a}),or=B.object({kind:B.literal(`FinalizeUnwrap`),from:a,wrapper:a,unwrapRequestIdOrAmount:p}),sr=B.object({kind:B.literal(`ApproveUnderlying`),from:a,underlying:a,spender:a,amount:B.bigint()}),cr=B.object({kind:B.literal(`Wrap`),from:a,wrapper:a,to:a,amount:B.bigint()}),lr=p.check(B.refine(e=>e===`0x`||Wt(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`)),ur=B.object({kind:B.literal(`TransferAndCall`),from:a,underlying:a,wrapper:a,amount:B.bigint(),recipientData:B.optional(lr)}),dr=B.object({kind:B.literal(`DelegateDecryption`),from:a,contractAddress:a,delegateAddress:a,expirationDate:B.optional(B.date())}),fr=B.object({kind:B.literal(`RevokeDelegation`),from:a,contractAddress:a,delegateAddress:a});B.discriminatedUnion(`kind`,[tr,nr,rr,ir,ar,or,sr,cr,ur,dr,fr]);const pr=B.strictObject({maxFeePerGas:B.bigint(),maxPriorityFeePerGas:B.bigint()}),mr=B.object({nonce:B.optional(B.int().check(B.nonnegative())),gasLimit:B.optional(B.bigint()),fees:B.optional(pr)}),hr=B.object({address:a,abi:B.array(B.unknown()),functionName:B.string(),args:B.array(B.unknown()),value:B.optional(B.bigint()),gas:B.optional(B.bigint())}),gr=B.extend(mr,{from:a,calldata:hr});var _r=class{#e;#t;#n;constructor(e){this.#e=e.provider,this.#t=e.router,this.#n=e.encryption}async prepare(e,t){t&&=R(mr,t);let n=await this.#e.getChainId(),r=this.#t.chain.id;if(n!==r)throw new O(`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={calldata:await this.#r(e),from:e.from,nonce:t?.nonce,gasLimit:t?.gasLimit,fees:t?.fees},a=R(gr,i),o=await this.#e.prepareTransaction(a).catch(t=>{throw gt(t,`prepare ${e.kind}`)??t});return{kind:e.kind,unsignedTx:o,from:a.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 O(`OfflineService.prepare: unsupported transaction kind '${e.kind}'.`)}}async#i(e){e=R(tr,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from},{operation:`offline-confidential-transfer`}),r=t[0];if(!r)throw new A(`Encryption returned no handles for ConfidentialTransfer`);return Ee(e.token,e.to,r,n)}async#a(e){e=R(nr,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from},{operation:`offline-confidential-transfer-from`}),r=t[0];if(!r)throw new A(`Encryption returned no handles for ConfidentialTransferFrom`);return qe(e.token,e.owner,e.to,r,n)}#o(e){return e=R(rr,e),Re(e.token,e.operator,e.until)}async#s(e){e=R(ir,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from},{operation:`offline-unwrap`}),r=t[0];if(!r)throw new A(`Encryption returned no handles for Unwrap`);return Se(e.token,e.from,e.to,r,n)}async#c(e){e=R(ar,e);let t=await this.#e.readContract(Ye(e.token,e.from));return Ce(e.token,e.from,e.to,t)}async#l(e){e=R(or,e);let t=await this.#t.relayer.decryptPublicValuesWithSignatures({encryptedValues:[e.unwrapRequestIdOrAmount],options:{operation:`offline-finalize-unwrap`}}).catch(e=>{throw K(e,`Public decryption failed during FinalizeUnwrap`)}),n=t.clearValues[0]?.value;return xe(n,`FinalizeUnwrap: decryptPublicValuesWithSignatures(handle).clearValue`),De(e.wrapper,e.unwrapRequestIdOrAmount,n,t.checkSignaturesArgs.decryptionProof)}#u(e){return e=R(sr,e),x(e.underlying,e.spender,e.amount)}#d(e){return e=R(cr,e),g(e.wrapper,e.to,e.amount)}#f(e){return e=R(ur,e),un(e.underlying,e.wrapper,e.amount,e.recipientData)}#p(e){if(e=R(dr,e),e.expirationDate&&e.expirationDate.getTime()<Date.now()+36e5)throw new W(`Expiration date must be at least 1 hour in the future`);if(e.delegateAddress===e.from)throw new V(`Cannot delegate to yourself (delegate === msg.sender).`);if(e.delegateAddress===e.contractAddress)throw new U(`Delegate address cannot be the same as the contract address (${e.contractAddress}).`);let t=e.expirationDate?BigInt(Math.floor(e.expirationDate.getTime()/1e3)):J;return dn(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress,t)}#m(e){return e=R(fr,e),fn(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress)}};function vr(e){if(Object.hasOwn(e,`transportKeyPairDerivationSecret`)&&e.transportKeyPairDerivationSecret===void 0)throw new O(`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 yr(e){if(e===void 0)return;let{importScripts:t}=globalThis;if(typeof window<`u`||typeof document<`u`||typeof t==`function`)throw new O(`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 br(e){if(e===void 0)return;let t=R(l,e);return new ne(typeof t==`string`?t:new Uint8Array(t))}var xr=class{#e;provider;signer;storage;registry;permits;delegations;decryption;offline;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;constructor(e,t={}){vr(t),yr(t.transportKeyPairDerivationSecret);let n=br(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 Wn(e.storage,this.#i),this.#u=new Qn({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 f({provider:this.provider,registryAddresses:r,registryTTL:e.registryTTL}),this.#n=r,this.#t=e.registryTTL,this.#l=new ee({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 Jn({cache:this.#a,credentialService:this.#l,delegationService:this.#u,router:e.router,emitEvent:this.emitEvent.bind(this)})),this.#s=new $n({router:e.router,emitEvent:this.emitEvent.bind(this)}),this.#o=new er({signer:e.signer,router:e.router,cachingService:this.#a,credentialService:this.#l,clearCredentialsOnWalletChange:e.clearCredentialsOnWalletChange,logger:this.#i}),this.#d=new _r({provider:this.provider,router:e.router,encryption:this.#s,emitEvent:(e,t)=>this.emitEvent(e,t)}),this.permits=new jn({signer:this.signer,provider:this.provider,cachingService:this.#a,credentialService:this.#l,logger:this.#i,emitEvent:this.emitEvent.bind(this)}),this.delegations=new Mn({signer:this.signer,provider:this.provider,delegationService:this.#u}),this.decryption=new Nn({signer:this.signer,provider:this.provider,router:e.router,decryptionService:this.#c}),this.offline=new Pn(this.#d,this.#l)}onWalletAccountChange(e){return this.#o.onWalletAccountChange(e)}get logger(){return this.#i}get relayer(){return this.#e.relayer}get chains(){return this.#e.chains}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 f({provider:this.provider,registryAddresses:{...this.#n,...e},registryTTL:this.#t})}async encrypt(e,t){return this.#s.encryptValues(e,L(t,`encrypt`))}createToken(e){return new vt(this,e)}createWrappedToken(e){return new Vn(this,e)}dispose(){this.#o.dispose(),this.#e.dispose()}terminate(){this.dispose(),this.signer?.dispose?.()}[Symbol.dispose](){this.terminate()}};export{An as ACL_TOPICS,en as AclPausedError,Q as AclTopics,ft as BalanceCheckUnavailableError,te as BaseSigner,Ue as ChainMismatchError,Fn as ChromeSessionStorage,O as ConfigurationError,Nn as Decryption,j as DecryptionFailedError,n as DefaultRegistryAddresses,$t as DelegationContractIsSelfError,Yt as DelegationCooldownError,Qt as DelegationDelegateCannotBeWildcardError,U as DelegationDelegateEqualsContractError,W as DelegationExpirationTooSoonError,Xt as DelegationExpiredError,Zt as DelegationExpiryUnchangedError,H as DelegationNotFoundError,G as DelegationNotPropagatedError,V as DelegationSelfNotAllowedError,Mn as Delegations,Me as ERC1363_INTERFACE_ID,k as ERC20ReadFailedError,He as ERC7984_INTERFACE_ID,We as ERC7984_WRAPPER_INTERFACE_ID,yt as EncryptOffloadUnavailableError,A as EncryptionFailedError,be as HcuBlockLimitExceededError,Ae as HcuTransactionLimitExceededError,t as IndexedDBStorage,lt as InsufficientAllowanceError,ut as InsufficientConfidentialBalanceError,ht as InsufficientERC20BalanceError,Ct as InvalidTransportKeyPairError,bt as KeyWrappingError,J as MAX_UINT64,s as MemoryStorage,d as MutableWalletAccountStore,Tt as NoCiphertextError,Jt as NotEntitledError,Pn as Offline,jn as Permits,Et as PreparedPermitChainMismatchError,xt as PreparedPermitExpiredError,E as RelayerRequestFailedError,M as RevokedKmsContextError,N as RpcRateLimitError,ye as SignerNotConfiguredError,Oe as SignerRequiredError,Dt as SigningFailedError,wt as SigningRejectedError,Cn as TOKEN_TOPICS,vt as Token,X as Topics,y as TransactionRevertedError,Ot as TransportKeyPairChangedError,St as TransportKeyPairExpiredError,nn as UnshieldAlreadyFinalizedError,Ft as VaultBatchNotDispatchedError,At as VaultBatcherPausedError,Mt as VaultJoinUnconfirmedError,Y as WILDCARD_CONTRACT,ke as WalletAccountNotReadyError,ve as WalletNotConnectedError,Vn as WrappedToken,f as WrappersRegistry,mt as ZERO_ENCRYPTED_VALUE,D as ZamaError,T as ZamaErrorCode,xr as ZamaSDK,h as ZamaSDKEvents,b as allowanceContract,fe as anvil,x as approveContract,Be as balanceOfContract,ce as bscTestnet,ue as chains,In as chromeSessionStorage,e as cleartext,Ye as confidentialBalanceOfContract,Ne as confidentialTotalSupplyContract,Je as confidentialTransferAndCallContract,Ee as confidentialTransferContract,he as confidentialTransferFromAndCallContract,qe as confidentialTransferFromContract,hn as createConfig,m as createWalletAccountStore,Ie as decimalsContract,En as decodeAclEvent,Dn as decodeAclEvents,gn as decodeConfidentialTransfer,wn as decodeDelegatedForUserDecryption,yn as decodeOnChainEvent,bn as decodeOnChainEvents,Tn as decodeRevokedDelegationForUserDecryption,vn as decodeUnwrapFinalized,_n as decodeUnwrapRequested,Z as decodeWrap,dn as delegateForUserDecryptionContract,De as finalizeUnwrapContract,On as findDelegatedForUserDecryption,kn as findRevokedDelegationForUserDecryption,xn as findUnwrapRequested,Sn as findWrap,Ht as getConfidentialTokenAddressContract,pn as getDelegationExpiryContract,Rt as getTokenAddressContract,Bt as getTokenPairContract,Lt as getTokenPairsContract,It as getTokenPairsLengthContract,zt as getTokenPairsSliceContract,oe as hardhat,ie as hoodi,re as indexedDBStorage,_e as inferredTotalSupplyContract,Pe as isConfidentialTokenContract,Vt as isConfidentialTokenValidContract,ze as isConfidentialWrapperContract,ct as isEncryptedValueZero,mn as isHandleDelegatedContract,ge as isOperatorContract,Qe as isRetryable,le as mainnet,qt as matchZamaError,o as memoryStorage,je as nameContract,r as parsePreparedPermit,de as polygon,ae as polygonAmoy,we as rateContract,rt as retryAfterSeconds,fn as revokeDelegationContract,se as sepolia,Re as setOperatorContract,Fe as supportsInterfaceContract,Ke as symbolContract,un as transferAndCallContract,me as underlyingContract,Le as unwrapAmountContract,Se as unwrapContract,Ce as unwrapFromBalanceContract,Te as unwrapRequesterContract,g as wrapContract,pe as zenithTrexTestnet};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|