@zama-fhe/sdk 3.9.0-beta.9 → 3.9.0
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/configs.cjs +1 -1
- package/dist/cjs/configs.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/public-decrypt.cjs +2 -0
- package/dist/cjs/public-decrypt.cjs.map +1 -0
- package/dist/cjs/query/index.cjs +1 -1
- package/dist/cjs/query/index.cjs.map +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/unshield.cjs +2 -0
- package/dist/cjs/unshield.cjs.map +1 -0
- package/dist/cjs/vaults/index.cjs +1 -1
- package/dist/cjs/vaults/index.cjs.map +1 -1
- package/dist/esm/{base-signer-DuHym9wR.d.ts → base-signer-C3_eu3aC.d.ts} +1 -1
- package/dist/esm/{base-signer-C6h8RUMT.js → base-signer-CD9a2hyy.js} +2 -2
- package/dist/esm/{base-signer-C6h8RUMT.js.map → base-signer-CD9a2hyy.js.map} +1 -1
- package/dist/esm/chains/index.d.ts +1 -1
- package/dist/esm/chains/index.js +1 -1
- package/dist/esm/cleartext/index.d.ts +2 -2
- package/dist/esm/cleartext/index.js +1 -1
- package/dist/esm/{cleartext-4VgPwU6v.js → cleartext-Bmwhc1xE.js} +2 -2
- package/dist/esm/{cleartext-4VgPwU6v.js.map → cleartext-Bmwhc1xE.js.map} +1 -1
- package/dist/esm/{cleartext-DydTYxOw.d.ts → cleartext-BxZphbB4.d.ts} +1 -1
- package/dist/esm/{configs-C65OaOKz.js → configs-9EL-DJHq.js} +2 -2
- package/dist/esm/{configs-C65OaOKz.js.map → configs-9EL-DJHq.js.map} +1 -1
- package/dist/esm/{decryption-DVfeQvb9.d.ts → decryption-BvvhpFM2.d.ts} +10 -4
- package/dist/esm/{encrypt-worker-client-BJJbrdZB.d.ts → encrypt-worker-client-Dt_x4FZd.d.ts} +1 -1
- package/dist/esm/encrypt.worker.js +47 -45
- package/dist/esm/ethers/index.d.ts +4 -4
- package/dist/esm/ethers/index.js +1 -1
- package/dist/esm/{fhevm-relayer-B6Xs5fOl.js → fhevm-relayer-ClfJ8FQG.js} +2 -2
- package/dist/esm/{fhevm-relayer-B6Xs5fOl.js.map → fhevm-relayer-ClfJ8FQG.js.map} +1 -1
- package/dist/esm/{index-BL2fvV8e.d.ts → index-B7M2GEtA.d.ts} +6 -6
- package/dist/esm/{index-O1xwLjWX.d.ts → index-BSkvEzGu.d.ts} +25 -11
- package/dist/esm/{index-8R-9woWN.d.ts → index-DTLVaNIj.d.ts} +3 -3
- 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 +4 -4
- package/dist/esm/internal/index.js +1 -1
- package/dist/esm/{invalidation-IBiMIXGB.d.ts → invalidation-BpkhN3Qu.d.ts} +3 -1
- package/dist/esm/node/index.d.ts +4 -4
- package/dist/esm/node/index.js +1 -1
- package/dist/esm/public-decrypt-Bec9uoNY.js +2 -0
- package/dist/esm/public-decrypt-Bec9uoNY.js.map +1 -0
- package/dist/esm/query/index.d.ts +7 -7
- package/dist/esm/query/index.js +1 -1
- package/dist/esm/query/index.js.map +1 -1
- package/dist/esm/relayer-Cki3j_Ba.js.map +1 -1
- package/dist/esm/{telemetry-CUO0AOiR.js → telemetry-B0ypjU_K.js} +2 -2
- package/dist/esm/{telemetry-CUO0AOiR.js.map → telemetry-B0ypjU_K.js.map} +1 -1
- package/dist/esm/{types-gKZ_zPFn.d.ts → types-BGMWYQds.d.ts} +2 -2
- package/dist/esm/{types-NmMfCGuC.d.ts → types-CHA7Mcqr.d.ts} +1 -1
- package/dist/esm/{types-D1kIafm6.d.ts → types-CoI5slhu.d.ts} +2 -2
- package/dist/esm/unshield-xO66p_da.js +2 -0
- package/dist/esm/unshield-xO66p_da.js.map +1 -0
- package/dist/esm/vaults/index.d.ts +20 -17
- package/dist/esm/vaults/index.js +1 -1
- package/dist/esm/vaults/index.js.map +1 -1
- package/dist/esm/viem/index.d.ts +4 -4
- package/dist/esm/viem/index.js +1 -1
- package/dist/esm/web/index.d.ts +2 -2
- package/dist/esm/web/index.js +1 -1
- package/package.json +12 -2
- package/dist/cjs/log-decoding.cjs +0 -2
- package/dist/cjs/log-decoding.cjs.map +0 -1
- package/dist/esm/log-decoding-Cl4zZCe8.js +0 -2
- package/dist/esm/log-decoding-Cl4zZCe8.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 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-
|
|
10
|
-
import { t as cleartext } from "./cleartext-
|
|
11
|
-
import { t as ZamaConfigEthers } from "./types-
|
|
12
|
-
import { a as hoodi, c as polygonAmoy, d as AtLeastOneChain, f as FheChain, i as hardhat, l as sepolia, m as FheKeyVerification, n as bscTestnet, o as mainnet, p as FheChainAuth, r as chains, s as polygon, t as anvil, u as zenithTrexTestnet } from "./index-
|
|
13
|
-
import { $t as parsePreparedPermit, A as VaultBatcherPausedDetails, An as approveContract, At as DelegationContractIsSelfError, Bn as confidentialTransferFromContract, Bt as InvalidTransportKeyPairError, C as Delegations, Cn as ERC1363_INTERFACE_ID, Ct as InsufficientAllowanceError, D as matchZamaError, Dn as isConfidentialWrapperContract, Dt as EncryptOffloadUnavailableError, E as ErrorForCode, En as isConfidentialTokenContract, Et as DecryptionFailedError, F as VaultJoinUnconfirmedError, Fn as confidentialBalanceOfContract, Ft as DelegationExpiredError, Gn as setOperatorContract, Gt as RevokedKmsContextError, Hn as inferredTotalSupplyContract, Ht as NoCiphertextError, In as confidentialTotalSupplyContract, It as DelegationExpiryUnchangedError, Jn as unwrapContract, Jt as ChainMismatchError, Kn as underlyingContract, Kt as TransportKeyPairChangedError, Ln as confidentialTransferAndCallContract, Lt as DelegationNotFoundError, M as VaultBatcherReadFailedDetails, Mn as decimalsContract, Mt as DelegationDelegateCannotBeWildcardError, N as VaultBatcherReadFailedError, Nn as nameContract, Nt as DelegationDelegateEqualsContractError, O as VaultBatchNotDispatchedDetails, On as supportsInterfaceContract, Ot as EncryptionFailedError, P as VaultJoinUnconfirmedDetails, Pn as symbolContract, Pt as DelegationExpirationTooSoonError, Qt as retryAfterSeconds, Rn as confidentialTransferContract, Rt as DelegationNotPropagatedError, S as Offline, Sn as transferAndCallContract, St as ERC20ReadFailedError, T as Permits, Tn as ERC7984_WRAPPER_INTERFACE_ID, Tt as InsufficientERC20BalanceError, Un as isOperatorContract, Ut as PreparedPermitChainMismatchError, Vn as finalizeUnwrapContract, Vt as KeyWrappingError, Wn as rateContract, Wt as PreparedPermitExpiredError, Xn as unwrapRequesterContract, Xt as ZamaErrorCode, Yn as unwrapFromBalanceContract, Yt as ZamaError, Zn as wrapContract, Zt as isRetryable, _ as WrappersRegistryConfig, _n as isConfidentialTokenValidContract, _t as NotEntitledError, a as DecryptResult, an as SerializedTransportKeyPair, at as UnwrapNotMinedError, b as BatchDecryptAsOptions, bn as isHandleDelegatedContract, bt as BalanceCheckUnavailableError, cn as PaginatedResult, ct as TransactionRevertedError, dn as getConfidentialTokenAddressContract, dt as SigningRejectedError, en as Permission, f as ZamaSDK, fn as getTokenAddressContract, ft as SignerNotConfiguredError, g as WrappersRegistry, gn as getTokenPairsSliceContract, gt as RpcRateLimitError, h as ListPairsOptions, hn as getTokenPairsLengthContract, ht as WalletNotConnectedError, i as DelegatedDecryptOptions, in as SerializedPermitEip712, it as UnshieldAlreadyFinalizedError, j as VaultBatcherPausedError, jn as balanceOfContract, jt as DelegationCooldownError, k as VaultBatchNotDispatchedError, kn as allowanceContract, kt as AclPausedError, ln as TokenWrapperPair, lt as SigningErrorMetadata, m as DefaultRegistryAddresses, mn as getTokenPairsContract, mt as WalletAccountNotReadyError, n as BatchDecryptItem, nn as PreparedPermit, o as EncryptedInput, on as SignedPreparedPermit, ot as HcuBlockLimitExceededError, p as ZamaSDKOptions, pn as getTokenPairContract, pt as SignerRequiredError, qn as unwrapAmountContract, qt as TransportKeyPairExpiredError, r as BatchDecryptResult, rn as SerializedPermit, rt as UnshieldAlreadyFinalizedDetails, sn as ChecksummedAddress, st as HcuTransactionLimitExceededError, t as Decryption, tn as PreparePermitRequest, un as TokenWrapperPairWithMetadata, ut as SigningFailedError, v as WrappedToken, vn as delegateForUserDecryptionContract, vt as ConfigurationError, w as DelegationStatus, wn as ERC7984_INTERFACE_ID, wt as InsufficientConfidentialBalanceError, x as Token, xn as revokeDelegationContract, xt as BalanceErrorDetails, y as BatchBalancesResult, yn as getDelegationExpiryContract, yt as RelayerRequestFailedError, zn as confidentialTransferFromAndCallContract, zt as DelegationSelfNotAllowedError } from "./decryption-
|
|
14
|
-
import { t as ZamaConfigViem } from "./types-
|
|
15
|
-
import { n as MutableWalletAccountStore, r as createWalletAccountStore, t as BaseSigner } from "./base-signer-
|
|
8
|
+
import { t as createConfig } from "./index-B7M2GEtA.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-CHA7Mcqr.js";
|
|
10
|
+
import { t as cleartext } from "./cleartext-BxZphbB4.js";
|
|
11
|
+
import { t as ZamaConfigEthers } from "./types-BGMWYQds.js";
|
|
12
|
+
import { a as hoodi, c as polygonAmoy, d as AtLeastOneChain, f as FheChain, i as hardhat, l as sepolia, m as FheKeyVerification, n as bscTestnet, o as mainnet, p as FheChainAuth, r as chains, s as polygon, t as anvil, u as zenithTrexTestnet } from "./index-BSkvEzGu.js";
|
|
13
|
+
import { $t as parsePreparedPermit, A as VaultBatcherPausedDetails, An as approveContract, At as DelegationContractIsSelfError, Bn as confidentialTransferFromContract, Bt as InvalidTransportKeyPairError, C as Delegations, Cn as ERC1363_INTERFACE_ID, Ct as InsufficientAllowanceError, D as matchZamaError, Dn as isConfidentialWrapperContract, Dt as EncryptOffloadUnavailableError, E as ErrorForCode, En as isConfidentialTokenContract, Et as DecryptionFailedError, F as VaultJoinUnconfirmedError, Fn as confidentialBalanceOfContract, Ft as DelegationExpiredError, Gn as setOperatorContract, Gt as RevokedKmsContextError, Hn as inferredTotalSupplyContract, Ht as NoCiphertextError, In as confidentialTotalSupplyContract, It as DelegationExpiryUnchangedError, Jn as unwrapContract, Jt as ChainMismatchError, Kn as underlyingContract, Kt as TransportKeyPairChangedError, Ln as confidentialTransferAndCallContract, Lt as DelegationNotFoundError, M as VaultBatcherReadFailedDetails, Mn as decimalsContract, Mt as DelegationDelegateCannotBeWildcardError, N as VaultBatcherReadFailedError, Nn as nameContract, Nt as DelegationDelegateEqualsContractError, O as VaultBatchNotDispatchedDetails, On as supportsInterfaceContract, Ot as EncryptionFailedError, P as VaultJoinUnconfirmedDetails, Pn as symbolContract, Pt as DelegationExpirationTooSoonError, Qt as retryAfterSeconds, Rn as confidentialTransferContract, Rt as DelegationNotPropagatedError, S as Offline, Sn as transferAndCallContract, St as ERC20ReadFailedError, T as Permits, Tn as ERC7984_WRAPPER_INTERFACE_ID, Tt as InsufficientERC20BalanceError, Un as isOperatorContract, Ut as PreparedPermitChainMismatchError, Vn as finalizeUnwrapContract, Vt as KeyWrappingError, Wn as rateContract, Wt as PreparedPermitExpiredError, Xn as unwrapRequesterContract, Xt as ZamaErrorCode, Yn as unwrapFromBalanceContract, Yt as ZamaError, Zn as wrapContract, Zt as isRetryable, _ as WrappersRegistryConfig, _n as isConfidentialTokenValidContract, _t as NotEntitledError, a as DecryptResult, an as SerializedTransportKeyPair, at as UnwrapNotMinedError, b as BatchDecryptAsOptions, bn as isHandleDelegatedContract, bt as BalanceCheckUnavailableError, cn as PaginatedResult, ct as TransactionRevertedError, dn as getConfidentialTokenAddressContract, dt as SigningRejectedError, en as Permission, f as ZamaSDK, fn as getTokenAddressContract, ft as SignerNotConfiguredError, g as WrappersRegistry, gn as getTokenPairsSliceContract, gt as RpcRateLimitError, h as ListPairsOptions, hn as getTokenPairsLengthContract, ht as WalletNotConnectedError, i as DelegatedDecryptOptions, in as SerializedPermitEip712, it as UnshieldAlreadyFinalizedError, j as VaultBatcherPausedError, jn as balanceOfContract, jt as DelegationCooldownError, k as VaultBatchNotDispatchedError, kn as allowanceContract, kt as AclPausedError, ln as TokenWrapperPair, lt as SigningErrorMetadata, m as DefaultRegistryAddresses, mn as getTokenPairsContract, mt as WalletAccountNotReadyError, n as BatchDecryptItem, nn as PreparedPermit, o as EncryptedInput, on as SignedPreparedPermit, ot as HcuBlockLimitExceededError, p as ZamaSDKOptions, pn as getTokenPairContract, pt as SignerRequiredError, qn as unwrapAmountContract, qt as TransportKeyPairExpiredError, r as BatchDecryptResult, rn as SerializedPermit, rt as UnshieldAlreadyFinalizedDetails, sn as ChecksummedAddress, st as HcuTransactionLimitExceededError, t as Decryption, tn as PreparePermitRequest, un as TokenWrapperPairWithMetadata, ut as SigningFailedError, v as WrappedToken, vn as delegateForUserDecryptionContract, vt as ConfigurationError, w as DelegationStatus, wn as ERC7984_INTERFACE_ID, wt as InsufficientConfidentialBalanceError, x as Token, xn as revokeDelegationContract, xt as BalanceErrorDetails, y as BatchBalancesResult, yn as getDelegationExpiryContract, yt as RelayerRequestFailedError, zn as confidentialTransferFromAndCallContract, zt as DelegationSelfNotAllowedError } from "./decryption-BvvhpFM2.js";
|
|
14
|
+
import { t as ZamaConfigViem } from "./types-CoI5slhu.js";
|
|
15
|
+
import { n as MutableWalletAccountStore, r as createWalletAccountStore, t as BaseSigner } from "./base-signer-C3_eu3aC.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;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as e}from"./cleartext-4VgPwU6v.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-C6h8RUMT.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"./configs-C65OaOKz.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 xe,L as Se,M as Ce,N as we,O as Te,P as Ee,S as De,T as Oe,U as ke,W as Ae,X as v,Y as je,_ as Me,a as Ne,b as Pe,c as Fe,d as Ie,f as y,h as Le,j as Re,k as ze,l as Be,m as b,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-D1cVCzw8.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-Cki3j_Ba.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-DnriE-3y.js";import{n as yt,r as A,t as j}from"./encryption-QHaWnnx-.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-DX-xyved.js";import{n as kt,r as N}from"./fatal-batch-CI0ESPnd.js";import{a as P,c as At,i as jt,l as Mt,n as F,o as Nt,r as I,s as Pt,t as L,u as Ft}from"./log-decoding-Cl4zZCe8.js";import{r as R}from"./telemetry-CUO0AOiR.js";import{t as z}from"./validation-BLmG7UVk.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 B,keccak256 as Ut,size as Wt,toBytes as Gt,zeroAddress as Kt}from"viem";import{z as V}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}},H=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`}},U=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`}},W=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`}},G=class extends D{constructor(e,t){super(T.DelegationExpirationTooSoon,e,t),this.name=`DelegationExpirationTooSoonError`}},K=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}},rn=class extends D{unwrapTxHash;constructor(e,t,n){super(T.UnwrapNotMined,e,n),this.name=`UnwrapNotMinedError`,this.unwrapTxHash=t}};const an=`InvalidUnwrapRequest`,on=Ut(Gt(`${an}(bytes32)`)).slice(0,10);function sn(e){for(let t=e;t instanceof Error;t=t.cause)if(tn(t)===an||t.message.includes(an)||t.message.includes(on))return!0;return!1}const cn=[j,Tt,E,K,wt,Dt,Jt,N,Ct,M];function q(e,t,n={}){if(cn.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 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 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 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}):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 ln(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 un=[{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 dn(e,t,n,r=`0x`){return{address:e,abi:un,functionName:`transferAndCall`,args:[t,n,r]}}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 fn(e,t,n,r){return{address:e,abi:J,functionName:`delegateForUserDecryption`,args:[t,n,r]}}function pn(e,t,n){return{address:e,abi:J,functionName:`revokeDelegationForUserDecryption`,args:[t,n]}}function mn(e,t,n,r){return{address:e,abi:J,functionName:`getUserDecryptionDelegationExpirationDate`,args:[t,n,r]}}function hn(e,t,n,r,i){return{address:e,abi:J,functionName:`isHandleDelegatedForUserDecryption`,args:[t,n,r,i]}}const Y=2n**64n-1n,X=`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`;function gn(e){return c(e.signer,e.provider,e)}const Z={ConfidentialTransfer:L(`ConfidentialTransfer(address,address,bytes32)`),Wrap:L(`Wrap(address,uint256,bytes32)`),UnwrapRequested:L(`UnwrapRequested(address,bytes32,bytes32)`),UnwrapFinalized:L(`UnwrapFinalized(address,bytes32,bytes32,uint64)`)};function _n(e){return e.topics[0]!==Z.ConfidentialTransfer||e.topics.length<4?null:{eventName:`ConfidentialTransfer`,from:F(e.topics[1]),to:F(e.topics[2]),encryptedAmount:I(e.topics[3])}}function vn(e){return e.topics[0]!==Z.Wrap||e.topics.length<2?null:{eventName:`Wrap`,to:F(e.topics[1]),roundedAmount:P(e.data,0),encryptedWrappedAmount:Nt(e.data,1)}}function yn(e){return e.topics[0]!==Z.UnwrapRequested||e.topics.length<3?null:{eventName:`UnwrapRequested`,receiver:F(e.topics[1]),unwrapRequestId:I(e.topics[2]),encryptedAmount:Nt(e.data,0)}}function bn(e){return e.topics[0]!==Z.UnwrapFinalized||e.topics.length<3?null:{eventName:`UnwrapFinalized`,receiver:F(e.topics[1]),unwrapRequestId:I(e.topics[2]),encryptedAmount:Nt(e.data,0),cleartextAmount:P(e.data,1)}}function xn(e){return _n(e)??vn(e)??yn(e)??bn(e)}function Sn(e){let t=[];for(let n of e){let e=xn(n);e&&t.push(e)}return t}function Cn(e){for(let t of e){let e=yn(t);if(e)return e}return null}function wn(e){for(let t of e){let e=vn(t);if(e)return e}return null}const Tn=[Z.ConfidentialTransfer,Z.Wrap,Z.UnwrapRequested,Z.UnwrapFinalized],Q={DelegatedForUserDecryption:L(`DelegatedForUserDecryption(address,address,address,uint64,uint64,uint64)`),RevokedDelegationForUserDecryption:L(`RevokedDelegationForUserDecryption(address,address,address,uint64,uint64)`)};function En(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 Dn(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 On(e){return En(e)??Dn(e)}function kn(e){let t=[];for(let n of e){let e=On(n);e&&t.push(e)}return t}function An(e){for(let t of e){let e=En(t);if(e)return e}return null}function jn(e){for(let t of e){let e=Dn(t);if(e)return e}return null}const Mn=[Q.DelegatedForUserDecryption,Q.RevokedDelegationForUserDecryption];var Nn=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 xe(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=B(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=B(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)}},Pn=class{#e;#t;#n;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.delegationService}#r(e){return xe(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)}},Fn=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 xe(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,R(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,R(r,`delegated-decrypt-values`))}async decryptPublicValues(e,t){if(e.length===0)return{clearValues:{},decryptionProof:`0x`,abiEncodedClearValues:`0x`};let n=R(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 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 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`})}},In=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)}},Ln=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 Rn=new Ln;async function zn(e,t){if(e.getTransactionReceipt)return e.getTransactionReceipt(t);let n,r=new Promise(e=>{n=setTimeout(()=>e(null),5e3)});try{return await Promise.race([e.waitForTransactionReceipt(t),r])}finally{clearTimeout(n)}}function Bn(e){return`zama:pending-unshields:${i(e)}`}function Vn(e){return`zama:pending-unshield:${i(e)}`}function Hn(e){return{version:2,unwrapTxHashes:e}}const Un=V.union([p,V.pipe(V.object({version:V.literal(1),unwrapTxHash:p}),V.transform(({unwrapTxHash:e})=>e))]),Wn=V.object({version:V.number(),unwrapTxHashes:V.optional(V.unknown())}),Gn=(e,t)=>e.toLowerCase()===t.toLowerCase();async function Kn(e,t,n){let r=await e.get(t);if(r==null)return{hashes:[],writable:!0};let i=Wn.safeParse(r);if(i.success&&i.data.version!==2)return n?.warn(`pending unshields saved by an unknown SDK version were left as is`,{version:i.data.version}),{hashes:[],writable:!1};let a=i.success?i.data.unwrapTxHashes:void 0;if(!Array.isArray(a))return n?.warn(`unreadable pending unshields were dropped`,{value:r}),{hashes:[],writable:!0};let o=a.filter(e=>p.safeParse(e).success);return o.length!==a.length&&n?.warn(`unreadable pending unshield entries were dropped`,{unwrapTxHashes:a}),{hashes:o,writable:!0}}async function qn(e,t,n){let r=await Kn(e,Bn(t),n),i=Un.safeParse(await e.get(Vn(t)));return!i.success||!r.writable?{...r,hasLegacy:!1}:{hashes:r.hashes.some(e=>Gn(e,i.data))?r.hashes:[i.data,...r.hashes],writable:!0,hasLegacy:!0}}async function Jn(e,t,n){let r=Bn(t);await(n.length===0?e.delete(r):e.set(r,Hn(n)))}const Yn=/* @__PURE__ */ new WeakMap;function Xn(e,t){let n=(Yn.get(e)??Promise.resolve()).then(t);return Yn.set(e,n.then(()=>{},()=>{})),n}function Zn(e,t,n,r){return Xn(e,async()=>{let{hashes:i,writable:a,hasLegacy:o}=await qn(e,t,n);if(!a)return;let s=r(i);(o||s.length!==i.length)&&await Jn(e,t,s),o&&await e.delete(Vn(t))})}async function Qn(e,t,n){return(await Xn(e,()=>qn(e,t,n))).hashes}function $n(e,t,n,r){return Zn(e,t,r,e=>e.some(e=>Gn(e,n))?e:[...e,n])}function er(e,t,n,r){return Zn(e,t,r,e=>e.filter(e=>!Gn(e,n)))}function tr(e,t){let n=B(t);return Cn(e.filter(e=>e.address===void 0||B(e.address)===n))?.unwrapRequestId}function nr(e,t){if(!e)return`unknown`;let n=e.status===`reverted`?void 0:tr(e.logs,t);return n===void 0?`settled`:{unwrapRequestId:n}}var rr=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.#m()}async isPayable(){if(this.#n!==null)return this.#n;try{let e=await this.#m();this.#n=await this.sdk.provider.readContract(Ge(e))}catch{this.#n=!1}return this.#n}async allowance(e){let t=await this.#m();return this.sdk.provider.readContract(y(t,B(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.#m(),a=B(n.address),o;try{o=await this.sdk.provider.readContract(b(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?B(r.to):n,a=i===n?`0x`:i;return this.submitTransaction({operation:`shield:transferAndCall`,config:dn(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.#m(),i=B(n.address),a;try{a=await this.sdk.provider.readContract(b(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(y(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?B(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.#g(e,r===`max`,n);let i=n?.to?B(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.#m(),r=B(t.address),i=e??2n**256n-1n;return i>0n&&await this.sdk.provider.readContract(y(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`,e=>this.#d(e));return _(`unshield: onUnwrapSubmitted`,()=>r?.(c.txHash),this.sdk.logger),this.#h(c.unwrapRequestId,c.txHash,s,o,`unshield`)}async unshieldAll(e){let t=crypto.randomUUID(),n=await this.#s(e=>this.#d(e));return _(`unshieldAll: onUnwrapSubmitted`,()=>e?.onUnwrapSubmitted?.(n.txHash),this.sdk.logger),this.#h(n.unwrapRequestId,n.txHash,t,e,`unshield-all`)}async resumeUnshield(e,t){let n;try{n=await zn(this.sdk.provider,e)}catch(e){throw e instanceof D?e:new v(`Failed to get unwrap receipt`,{cause:e})}let r=nr(n,this.address);if(r===`unknown`)throw new rn(`Unwrap transaction ${e} is not mined, so there is nothing to resume yet`,e);if(r===`settled`)throw await this.#p(`resumeUnshield`,e),new v(`Unwrap transaction ${e} reverted or opened no unwrap request from this wrapper, so there is nothing to resume`);let{unwrapRequestId:i}=r;if(await this.#u(i)===`settled`)throw await this.#p(`resumeUnshield`,e),new nn(`Nothing to resume: the unwrap request was already finalized on-chain and the funds were delivered.`,{unwrapTxHash:e,unwrapRequestId:i});return await _(`resumeUnshield: savePendingUnshield`,()=>this.#d(e),this.sdk.logger),this.#h(i,e,crypto.randomUUID(),t,`resume-unshield`)}async getPendingUnshield(){let e=null,t=await Qn(this.sdk.storage,this.address,this.sdk.logger);for(let n of t){let t=await this.#f(n);if(t===`open`)return n;t===`settled`?await this.#p(`getPendingUnshield`,n):e??=n}return e}async unwrap(e){return this.#o(e,`unwrap`)}async#o(e,t,n){this.#r(`unwrap`);let r=await S(`unwrap`,this.sdk.signer,this.sdk.provider),i=B(r.address),{encryptedValues:a,inputProof:o}=await this.sdk.encrypt({values:[{value:e,type:`euint64`}],contractAddress:this.address,userAddress:i},{operation:t}),[s]=a;if(!s)throw new A(`Encryption returned no encrypted values`);let c=await this.submitTransaction({operation:`unwrap`,config:Ce(this.address,i,i,s,o),beforeReceipt:n});return{...c,unwrapRequestId:this.#l(c.receipt.logs)}}async unwrapAll(){return this.#s()}async#s(e){this.#r(`unwrapAll`);let t=await S(`unwrapAll`,this.sdk.signer,this.sdk.provider),n=B(t.address),r=await this.readConfidentialBalanceOf(n);if(ct(r))throw new j(`Cannot unshield: balance is zero`);let i=await this.submitTransaction({operation:`unwrapAll`,config:we(this.address,n,n,r),beforeReceipt:e});return{...i,unwrapRequestId:this.#l(i.receipt.logs)}}async finalizeUnwrap(e){return this.#c(e,`finalize-unwrap`)}async#c(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 Se(r,`finalizeUnwrap: clearValue`),this.submitTransaction({operation:`finalizeUnwrap`,config:Oe(this.address,e,r,n.decryptionProof)})}#l(e){let t=tr(e,this.address);if(t===void 0)throw new v(`No UnwrapRequested event from this wrapper found in the unwrap receipt`);return t}async#u(e){try{return await this.sdk.provider.readContract(Ee(this.address,e))===Kt?`settled`:`open`}catch{return`unknown`}}#d(e){return $n(this.sdk.storage,this.address,e,this.sdk.logger)}async#f(e){let t;try{t=await zn(this.sdk.provider,e)}catch{return`unknown`}let n=nr(t,this.address);return typeof n==`string`?n:this.#u(n.unwrapRequestId)}async#p(e,t){await _(`${e}: clearPendingUnshield`,()=>er(this.sdk.storage,this.address,t,this.sdk.logger),this.sdk.logger)}async#m(){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#h(e,t,n,r,i){this.emit({type:h.UnshieldPhase1Submitted,txHash:t,operationId:n}),this.emit({type:h.UnshieldPhase2Started,operationId:n}),_(`unshield: onFinalizing`,()=>r?.onFinalizing?.(),this.sdk.logger);let a;try{a=await this.#c(e,i)}catch(n){throw sn(n)||n instanceof v&&await this.#u(e)===`settled`?(await this.#p(`unshield`,t),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.#p(`unshield`,t),a}async#g(e,t,n){this.#r(`approveUnderlying`);let r=await this.#m(),i=await S(`approveUnderlying`,this.sdk.signer,this.sdk.provider),a=B(i.address),o=await this.sdk.provider.readContract(y(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 ir=V.union([V.bigint(),V.boolean(),a]),ar=V.array(V.string());var or=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=ir.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=B(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}:${B(e)}:${B(t)}:${n.toLowerCase()}`}async#l(){let e=await this.#e.get(this.#r);if(e===null)return[];let t=ar.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 sr(e,t){let n=cr(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 cr(e,t){let n=i(t);return e.permissions.find(e=>e.contractAddresses.includes(n))}const lr=e=>new Promise(t=>setTimeout(t,e));var ur=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=B(t);return this.#s(e,{requesterAddress:r,errorMessage:`Failed to decrypt encrypted values`},n)}async delegatedDecryptValues(e,t,n,r,i){let a=B(t),o=B(n),s={spent:!1};return this.#a(i?.waitForPropagation??!0,()=>this.#s(e,{requesterAddress:B(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 lr(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:B(e.contractAddress)}));if(s.length===0)return{items:s};let c=B(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:B(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:B(t)})}}),i),u!==void 0)throw u;return{items:s}}async#o(e,t,n,r){let i=sr(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:B(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}),q(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 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 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:q(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 $={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 H(`Cannot delegate to yourself (delegate === msg.sender).`,{cause:e}),DelegateCannotBeContractAddress:e=>new W(`Delegate address cannot be the same as the contract address.`,{cause:e}),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 G(`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 U(`Cannot revoke: no active delegation exists.`,{cause:e})};function dr(e){return Object.hasOwn($,e)}function fr(e,t){let n=tn(e);if(n&&dr(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 pr=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=B(t),o=B(n),s=B(r);if(o===s)throw new H(`Cannot delegate to yourself (delegate === msg.sender).`);if(o===B(`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 W(`Delegate address cannot be the same as the contract address (${a}).`);let c=this.#e.relayer.chain.aclContractAddress,l=i?BigInt(Math.floor(i.getTime()/1e3)):Y,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!==B(`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`)&&await this.#i({contractAddress:a,delegatorAddress:s,delegateAddress:o}),this.#s({operation:`delegateDecryption`,signer:e,contractAddress:a,config:fn(c,o,a,l)})}async revokeDelegation(e,{contractAddress:t,delegateAddress:n,delegatorAddress:r}){let i=B(t),a=B(n),o=B(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 U(`No active delegation found for delegate ${a} on contract ${i}.`);return this.#s({operation:`revokeDelegation`,signer:e,contractAddress:i,config:pn(s,a,i)})}async isDelegated(e){return(await this.getStatus(e)).isActive}async getStatus(e){let t=B(e.contractAddress)===X,[n,r]=await Promise.all([this.getDelegationExpiry(e),t?Promise.resolve(0n):this.getDelegationExpiry({...e,contractAddress:X})]),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:X});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!==Y}#o(e,t){return e===0n?{isActive:!1,expiryTimestamp:e}:e===Y?{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(mn(r,B(t),B(n),B(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 v))return;let t=fr(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 U||t instanceof Xt){let n=B(e);r.set(n,t);return}throw t}})),r}async assertDelegationActive(e,t,n){let r=B(e),i=B(t),a=B(n),{isActive:o,expiryTimestamp:s}=await this.getStatus({contractAddress:r,delegatorAddress:i,delegateAddress:a});if(!o)throw s===0n?new U(`No active delegation from ${i} to ${a} for ${r}`):new Xt(`Delegation from ${i} to ${a} for ${r} has expired`)}},mr=class{#e;#t;constructor({router:e,emitEvent:t}){this.#e=e,this.#t=t}async encryptValues(e,t){let n=Date.now(),r=B(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),ln(e,`Encryption failed`)}}},hr=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 gr=V.object({kind:V.literal(`ConfidentialTransfer`),from:a,token:a,to:a,amount:V.bigint()}),_r=V.object({kind:V.literal(`ConfidentialTransferFrom`),from:a,token:a,owner:a,to:a,amount:V.bigint()}),vr=V.object({kind:V.literal(`SetOperator`),from:a,token:a,operator:a,until:u}),yr=V.object({kind:V.literal(`Unwrap`),from:a,token:a,to:a,amount:V.bigint()}),br=V.object({kind:V.literal(`UnwrapAll`),from:a,token:a,to:a}),xr=V.object({kind:V.literal(`FinalizeUnwrap`),from:a,wrapper:a,unwrapRequestIdOrAmount:p}),Sr=V.object({kind:V.literal(`ApproveUnderlying`),from:a,underlying:a,spender:a,amount:V.bigint()}),Cr=V.object({kind:V.literal(`Wrap`),from:a,wrapper:a,to:a,amount:V.bigint()}),wr=p.check(V.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`)),Tr=V.object({kind:V.literal(`TransferAndCall`),from:a,underlying:a,wrapper:a,amount:V.bigint(),recipientData:V.optional(wr)}),Er=V.object({kind:V.literal(`DelegateDecryption`),from:a,contractAddress:a,delegateAddress:a,expirationDate:V.optional(V.date())}),Dr=V.object({kind:V.literal(`RevokeDelegation`),from:a,contractAddress:a,delegateAddress:a});V.discriminatedUnion(`kind`,[gr,_r,vr,yr,br,xr,Sr,Cr,Tr,Er,Dr]);const Or=V.strictObject({maxFeePerGas:V.bigint(),maxPriorityFeePerGas:V.bigint()}),kr=V.object({nonce:V.optional(V.int().check(V.nonnegative())),gasLimit:V.optional(V.bigint()),fees:V.optional(Or)}),Ar=V.object({address:a,abi:V.array(V.unknown()),functionName:V.string(),args:V.array(V.unknown()),value:V.optional(V.bigint()),gas:V.optional(V.bigint())}),jr=V.extend(kr,{from:a,calldata:Ar});var Mr=class{#e;#t;#n;constructor(e){this.#e=e.provider,this.#t=e.router,this.#n=e.encryption}async prepare(e,t){t&&=z(kr,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=z(jr,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=z(gr,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 De(e.token,e.to,r,n)}async#a(e){e=z(_r,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=z(vr,e),ze(e.token,e.operator,e.until)}async#s(e){e=z(yr,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 Ce(e.token,e.from,e.to,r,n)}async#c(e){e=z(br,e);let t=await this.#e.readContract(Ye(e.token,e.from));return we(e.token,e.from,e.to,t)}async#l(e){e=z(xr,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 Se(n,`FinalizeUnwrap: decryptPublicValuesWithSignatures(handle).clearValue`),Oe(e.wrapper,e.unwrapRequestIdOrAmount,n,t.checkSignaturesArgs.decryptionProof)}#u(e){return e=z(Sr,e),x(e.underlying,e.spender,e.amount)}#d(e){return e=z(Cr,e),g(e.wrapper,e.to,e.amount)}#f(e){return e=z(Tr,e),dn(e.underlying,e.wrapper,e.amount,e.recipientData)}#p(e){if(e=z(Er,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 H(`Cannot delegate to yourself (delegate === msg.sender).`);if(e.delegateAddress===e.contractAddress)throw new W(`Delegate address cannot be the same as the contract address (${e.contractAddress}).`);let t=e.expirationDate?BigInt(Math.floor(e.expirationDate.getTime()/1e3)):Y;return fn(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress,t)}#m(e){return e=z(Dr,e),pn(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress)}};function Nr(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 Pr(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 Fr(e){if(e===void 0)return;let t=z(l,e);return new ne(typeof t==`string`?t:new Uint8Array(t))}var Ir=class{#e;provider;signer;storage;registry;permits;delegations;decryption;offline;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;constructor(e,t={}){Nr(t),Pr(t.transportKeyPairDerivationSecret);let n=Fr(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 or(e.storage,this.#i),this.#u=new pr({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 ur({cache:this.#a,credentialService:this.#l,delegationService:this.#u,router:e.router,emitEvent:this.emitEvent.bind(this)})),this.#s=new mr({router:e.router,emitEvent:this.emitEvent.bind(this)}),this.#o=new hr({signer:e.signer,router:e.router,cachingService:this.#a,credentialService:this.#l,clearCredentialsOnWalletChange:e.clearCredentialsOnWalletChange,logger:this.#i}),this.#d=new Mr({provider:this.provider,router:e.router,encryption:this.#s,emitEvent:(e,t)=>this.emitEvent(e,t)}),this.permits=new Nn({signer:this.signer,provider:this.provider,cachingService:this.#a,credentialService:this.#l,logger:this.#i,emitEvent:this.emitEvent.bind(this)}),this.delegations=new Pn({signer:this.signer,provider:this.provider,delegationService:this.#u}),this.decryption=new Fn({signer:this.signer,provider:this.provider,router:e.router,decryptionService:this.#c}),this.offline=new In(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,R(t,`encrypt`))}createToken(e){return new vt(this,e)}createWrappedToken(e){return new rr(this,e)}dispose(){this.#o.dispose(),this.#e.dispose()}terminate(){this.dispose(),this.signer?.dispose?.()}[Symbol.dispose](){this.terminate()}};export{Mn as ACL_TOPICS,en as AclPausedError,Q as AclTopics,ft as BalanceCheckUnavailableError,te as BaseSigner,Ue as ChainMismatchError,Ln as ChromeSessionStorage,O as ConfigurationError,Fn as Decryption,j as DecryptionFailedError,n as DefaultRegistryAddresses,$t as DelegationContractIsSelfError,Yt as DelegationCooldownError,Qt as DelegationDelegateCannotBeWildcardError,W as DelegationDelegateEqualsContractError,G as DelegationExpirationTooSoonError,Xt as DelegationExpiredError,Zt as DelegationExpiryUnchangedError,U as DelegationNotFoundError,K as DelegationNotPropagatedError,H as DelegationSelfNotAllowedError,Pn as Delegations,Ne 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,je as HcuTransactionLimitExceededError,t as IndexedDBStorage,lt as InsufficientAllowanceError,ut as InsufficientConfidentialBalanceError,ht as InsufficientERC20BalanceError,Ct as InvalidTransportKeyPairError,bt as KeyWrappingError,Y as MAX_UINT64,s as MemoryStorage,d as MutableWalletAccountStore,Tt as NoCiphertextError,Jt as NotEntitledError,In as Offline,Nn as Permits,Et as PreparedPermitChainMismatchError,xt as PreparedPermitExpiredError,E as RelayerRequestFailedError,M as RevokedKmsContextError,N as RpcRateLimitError,ye as SignerNotConfiguredError,ke as SignerRequiredError,Dt as SigningFailedError,wt as SigningRejectedError,Tn as TOKEN_TOPICS,vt as Token,Z as Topics,v as TransactionRevertedError,Ot as TransportKeyPairChangedError,St as TransportKeyPairExpiredError,nn as UnshieldAlreadyFinalizedError,rn as UnwrapNotMinedError,Pt as VaultBatchNotDispatchedError,At as VaultBatcherPausedError,Mt as VaultBatcherReadFailedError,Ft as VaultJoinUnconfirmedError,X as WILDCARD_CONTRACT,Ae as WalletAccountNotReadyError,ve as WalletNotConnectedError,rr as WrappedToken,f as WrappersRegistry,mt as ZERO_ENCRYPTED_VALUE,D as ZamaError,T as ZamaErrorCode,Ir as ZamaSDK,h as ZamaSDKEvents,y as allowanceContract,fe as anvil,x as approveContract,b as balanceOfContract,ce as bscTestnet,ue as chains,Rn as chromeSessionStorage,e as cleartext,Ye as confidentialBalanceOfContract,Pe as confidentialTotalSupplyContract,Je as confidentialTransferAndCallContract,De as confidentialTransferContract,he as confidentialTransferFromAndCallContract,qe as confidentialTransferFromContract,gn as createConfig,m as createWalletAccountStore,Le as decimalsContract,On as decodeAclEvent,kn as decodeAclEvents,_n as decodeConfidentialTransfer,En as decodeDelegatedForUserDecryption,xn as decodeOnChainEvent,Sn as decodeOnChainEvents,Dn as decodeRevokedDelegationForUserDecryption,bn as decodeUnwrapFinalized,yn as decodeUnwrapRequested,vn as decodeWrap,fn as delegateForUserDecryptionContract,Oe as finalizeUnwrapContract,An as findDelegatedForUserDecryption,jn as findRevokedDelegationForUserDecryption,Cn as findUnwrapRequested,wn as findWrap,Ht as getConfidentialTokenAddressContract,mn 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,Fe as isConfidentialTokenContract,Vt as isConfidentialTokenValidContract,Be as isConfidentialWrapperContract,ct as isEncryptedValueZero,hn as isHandleDelegatedContract,ge as isOperatorContract,Qe as isRetryable,le as mainnet,qt as matchZamaError,o as memoryStorage,Me as nameContract,r as parsePreparedPermit,de as polygon,ae as polygonAmoy,Te as rateContract,rt as retryAfterSeconds,pn as revokeDelegationContract,se as sepolia,ze as setOperatorContract,Ie as supportsInterfaceContract,Ke as symbolContract,dn as transferAndCallContract,me as underlyingContract,Re as unwrapAmountContract,Ce as unwrapContract,we as unwrapFromBalanceContract,Ee as unwrapRequesterContract,g as wrapContract,pe as zenithTrexTestnet};
|
|
1
|
+
import{t as e}from"./cleartext-Bmwhc1xE.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-CD9a2hyy.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"./configs-9EL-DJHq.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,M as xe,N as Se,O as Ce,P as we,S as Te,T as Ee,U as De,W as Oe,X as y,Y as ke,_ as Ae,a as je,b as Me,c as Ne,d as Pe,f as b,h as Fe,j as Ie,k as Le,l as Re,m as x,n as ze,o as Be,p as S,q as Ve,s as He,t as C,u as Ue,v as We,w as Ge,x as Ke,y as qe,z as Je}from"./alignment-D1cVCzw8.js";import{C as w,S as Ye,_ as T,a as Xe,b as Ze,c as E,d as Qe,f as $e,g as et,h as tt,i as D,l as nt,m as rt,n as O,o as k,p as it,r as A,s as j,t as at,u as ot,v as M,w as st,x as N,y as P}from"./public-decrypt-Bec9uoNY.js";import{c as F,d as ct,f as lt,i as ut,l as dt,n as ft,o as pt,p as I,r as mt,s as ht,t as gt,u as L}from"./token-DnriE-3y.js";import{C as R,_ as _t,a as vt,c as yt,g as bt,i as xt,m as St,n as Ct,o as wt,r as z,s as Tt,t as B,y as Et}from"./relayer-Cki3j_Ba.js";import{n as Dt,r as V,t as H}from"./encryption-QHaWnnx-.js";import{a as Ot,c as kt,d as At,i as jt,l as U,n as Mt,o as Nt,s as Pt,t as Ft,u as It}from"./signing-DX-xyved.js";import{n as Lt,r as Rt}from"./fatal-batch-CI0ESPnd.js";import{i as zt,n as Bt,r as Vt,t as Ht}from"./unshield-xO66p_da.js";import{r as W}from"./telemetry-B0ypjU_K.js";import{t as G}from"./validation-BLmG7UVk.js";import{a as Ut,i as Wt,n as Gt,o as Kt,r as qt,s as Jt,t as Yt}from"./wrappers-registry-Cm3JJeqx.js";import{getAddress as K,size as Xt,zeroAddress as Zt}from"viem";import{z as q}from"zod/mini";function Qt(e,t){if(e instanceof z){let n=t[e.code];if(n)return n(e)}return t._?.(e)}function $t(e,t){if(e instanceof z)return e;let n=Tt(e),r=_t(e);return n!==void 0||bt(e)?new Ct(e instanceof Error?e.message:t,n,{cause:e,retryAfter:yt(e),retryable:r||void 0}):new V(t,{cause:e})}const en=[{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 tn(e,t,n,r=`0x`){return{address:e,abi:en,functionName:`transferAndCall`,args:[t,n,r]}}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 nn(e,t,n,r){return{address:e,abi:J,functionName:`delegateForUserDecryption`,args:[t,n,r]}}function rn(e,t,n){return{address:e,abi:J,functionName:`revokeDelegationForUserDecryption`,args:[t,n]}}function an(e,t,n,r){return{address:e,abi:J,functionName:`getUserDecryptionDelegationExpirationDate`,args:[t,n,r]}}function on(e,t,n,r,i){return{address:e,abi:J,functionName:`isHandleDelegatedForUserDecryption`,args:[t,n,r,i]}}const Y=2n**64n-1n,X=`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`;function sn(e){return c(e.signer,e.provider,e)}const Z={ConfidentialTransfer:O(`ConfidentialTransfer(address,address,bytes32)`),Wrap:O(`Wrap(address,uint256,bytes32)`),UnwrapRequested:O(`UnwrapRequested(address,bytes32,bytes32)`),UnwrapFinalized:O(`UnwrapFinalized(address,bytes32,bytes32,uint64)`)};function cn(e){return e.topics[0]!==Z.ConfidentialTransfer||e.topics.length<4?null:{eventName:`ConfidentialTransfer`,from:A(e.topics[1]),to:A(e.topics[2]),encryptedAmount:D(e.topics[3])}}function ln(e){return e.topics[0]!==Z.Wrap||e.topics.length<2?null:{eventName:`Wrap`,to:A(e.topics[1]),roundedAmount:k(e.data,0),encryptedWrappedAmount:j(e.data,1)}}function un(e){return e.topics[0]!==Z.UnwrapRequested||e.topics.length<3?null:{eventName:`UnwrapRequested`,receiver:A(e.topics[1]),unwrapRequestId:D(e.topics[2]),encryptedAmount:j(e.data,0)}}function dn(e){return e.topics[0]!==Z.UnwrapFinalized||e.topics.length<3?null:{eventName:`UnwrapFinalized`,receiver:A(e.topics[1]),unwrapRequestId:D(e.topics[2]),encryptedAmount:j(e.data,0),cleartextAmount:k(e.data,1)}}function fn(e){return cn(e)??ln(e)??un(e)??dn(e)}function pn(e){let t=[];for(let n of e){let e=fn(n);e&&t.push(e)}return t}function mn(e){for(let t of e){let e=un(t);if(e)return e}return null}function hn(e){for(let t of e){let e=ln(t);if(e)return e}return null}const gn=[Z.ConfidentialTransfer,Z.Wrap,Z.UnwrapRequested,Z.UnwrapFinalized],Q={DelegatedForUserDecryption:O(`DelegatedForUserDecryption(address,address,address,uint64,uint64,uint64)`),RevokedDelegationForUserDecryption:O(`RevokedDelegationForUserDecryption(address,address,address,uint64,uint64)`)};function _n(e){return e.topics[0]!==Q.DelegatedForUserDecryption||e.topics.length<3?null:{eventName:`DelegatedForUserDecryption`,delegator:A(e.topics[1]),delegate:A(e.topics[2]),contractAddress:Xe(e.data,0),delegationCounter:k(e.data,1),oldExpirationDate:k(e.data,2),newExpirationDate:k(e.data,3)}}function vn(e){return e.topics[0]!==Q.RevokedDelegationForUserDecryption||e.topics.length<3?null:{eventName:`RevokedDelegationForUserDecryption`,delegator:A(e.topics[1]),delegate:A(e.topics[2]),contractAddress:Xe(e.data,0),delegationCounter:k(e.data,1),oldExpirationDate:k(e.data,2)}}function yn(e){return _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=vn(t);if(e)return e}return null}const Cn=[Q.DelegatedForUserDecryption,Q.RevokedDelegationForUserDecryption];var wn=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 ze(`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 ze(`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 C(`revokePermits`,this.#e,this.#t),r=K(n.address);try{await t.revokePermits(e)}finally{await this.#c(r)}}async clear(){let e=this.#o(`clear`),t=await C(`clear`,this.#e,this.#t),n=K(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)}},Tn=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 C(`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 C(`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)}},En=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 C(`decryptValues`,this.#e,this.#t);return n.decryptValues(e,r.address,W(t,`decrypt-values`))}async delegatedDecryptValues(e,t,n=t,r){let i=this.#i(`delegatedDecryptValues`),a=await C(`delegatedDecryptValues`,this.#e,this.#t);return i.delegatedDecryptValues(e,t,a.address,n,W(r,`delegated-decrypt-values`))}async decryptPublicValues(e,t){if(e.length===0)return{clearValues:{},decryptionProof:`0x`,abiEncodedClearValues:`0x`};let n=W(t,`decrypt-public-values`);try{let t=await this.#n.relayer.decryptPublicValuesWithSignatures({encryptedValues:e,options:n}),r={};return t.checkSignaturesArgs.handlesList.forEach((e,n)=>{Je(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 E(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 C(`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`})}},Dn=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)}},On=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 kn=new On;async function An(e,t){if(e.getTransactionReceipt)return e.getTransactionReceipt(t);let n,r=new Promise(e=>{n=setTimeout(()=>e(null),5e3)});try{return await Promise.race([e.waitForTransactionReceipt(t),r])}finally{clearTimeout(n)}}function jn(e){return`zama:pending-unshields:${i(e)}`}function Mn(e){return`zama:pending-unshield:${i(e)}`}function Nn(e){return{version:2,unwrapTxHashes:e}}const Pn=q.union([p,q.pipe(q.object({version:q.literal(1),unwrapTxHash:p}),q.transform(({unwrapTxHash:e})=>e))]),Fn=q.object({version:q.number(),unwrapTxHashes:q.optional(q.unknown())}),In=(e,t)=>e.toLowerCase()===t.toLowerCase();async function Ln(e,t,n){let r=await e.get(t);if(r==null)return{hashes:[],writable:!0};let i=Fn.safeParse(r);if(i.success&&i.data.version!==2)return n?.warn(`pending unshields saved by an unknown SDK version were left as is`,{version:i.data.version}),{hashes:[],writable:!1};let a=i.success?i.data.unwrapTxHashes:void 0;if(!Array.isArray(a))return n?.warn(`unreadable pending unshields were dropped`,{value:r}),{hashes:[],writable:!0};let o=a.filter(e=>p.safeParse(e).success);return o.length!==a.length&&n?.warn(`unreadable pending unshield entries were dropped`,{unwrapTxHashes:a}),{hashes:o,writable:!0}}async function Rn(e,t,n){let r=await Ln(e,jn(t),n),i=Pn.safeParse(await e.get(Mn(t)));return!i.success||!r.writable?{...r,hasLegacy:!1}:{hashes:r.hashes.some(e=>In(e,i.data))?r.hashes:[i.data,...r.hashes],writable:!0,hasLegacy:!0}}async function zn(e,t,n){let r=jn(t);await(n.length===0?e.delete(r):e.set(r,Nn(n)))}const Bn=/* @__PURE__ */ new WeakMap;function Vn(e,t){let n=(Bn.get(e)??Promise.resolve()).then(t);return Bn.set(e,n.then(()=>{},()=>{})),n}function Hn(e,t,n,r){return Vn(e,async()=>{let{hashes:i,writable:a,hasLegacy:o}=await Rn(e,t,n);if(!a)return;let s=r(i);(o||s.length!==i.length)&&await zn(e,t,s),o&&await e.delete(Mn(t))})}async function Un(e,t,n){return(await Vn(e,()=>Rn(e,t,n))).hashes}function Wn(e,t,n,r){return Hn(e,t,r,e=>e.some(e=>In(e,n))?e:[...e,n])}function Gn(e,t,n,r){return Hn(e,t,r,e=>e.filter(e=>!In(e,n)))}function Kn(e,t){let n=K(t);return mn(e.filter(e=>e.address===void 0||K(e.address)===n))?.unwrapRequestId}function qn(e,t){if(!e)return`unknown`;let n=e.status===`reverted`?void 0:Kn(e.logs,t);return n===void 0?`settled`:{unwrapRequestId:n}}var Jn=class extends gt{#e;#t=null;#n=null;#r(e){try{return Je(this.sdk.signer,`WrappedToken.sdk.signer`),this.sdk.signer}catch(t){throw new ye(e,{cause:t})}}async underlying(){return this.#m()}async isPayable(){if(this.#n!==null)return this.#n;try{let e=await this.#m();this.#n=await this.sdk.provider.readContract(Ue(e))}catch{this.#n=!1}return this.#n}async allowance(e){let t=await this.#m();return this.sdk.provider.readContract(b(t,K(e),this.address))}async shield(e,t){let n=await C(`shield`,this.sdk.signer,this.sdk.provider),r=await this.isPayable(),i=await this.#m(),a=K(n.address),o;try{o=await this.sdk.provider.readContract(x(i,a))}catch(e){throw e instanceof z?e:new L(`Could not read ERC-20 balance for shield validation (token: ${i})`,{cause:R(e)})}if(o<e)throw new I(`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?K(r.to):n,a=i===n?`0x`:i;return this.submitTransaction({operation:`shield:transferAndCall`,config:tn(t,this.address,e,a),onSubmitted:r?.onShieldSubmitted})}async wrap(e,t){this.#r(`wrap`);let n=await C(`wrap`,this.sdk.signer,this.sdk.provider),r=await this.#m(),i=K(n.address),a;try{a=await this.sdk.provider.readContract(x(r,i))}catch(e){throw e instanceof z?e:new L(`Could not read ERC-20 balance for wrap validation (token: ${r})`,{cause:R(e)})}if(a<e)throw new I(`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 z?e:new L(`Could not read ERC-20 allowance for wrap validation (token: ${r})`,{cause:R(e)})}if(o<e)throw new ct(`Insufficient allowance for wrap: requested ${e}, approved ${o}. Call approveUnderlying() first (token: ${r}).`,{requested:e,available:o,token:r});let s=t?.to?K(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.#g(e,r===`max`,n);let i=n?.to?K(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 C(`approveUnderlying`,this.sdk.signer,this.sdk.provider),n=await this.#m(),r=K(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:S(n,this.address,0n)}),this.submitTransaction({operation:`approveUnderlying`,config:S(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`,e=>this.#d(e));return _(`unshield: onUnwrapSubmitted`,()=>r?.(c.txHash),this.sdk.logger),this.#h(c.unwrapRequestId,c.txHash,s,o,`unshield`)}async unshieldAll(e){let t=crypto.randomUUID(),n=await this.#s(e=>this.#d(e));return _(`unshieldAll: onUnwrapSubmitted`,()=>e?.onUnwrapSubmitted?.(n.txHash),this.sdk.logger),this.#h(n.unwrapRequestId,n.txHash,t,e,`unshield-all`)}async resumeUnshield(e,t){let n;try{n=await An(this.sdk.provider,e)}catch(e){throw e instanceof z?e:new y(`Failed to get unwrap receipt`,{cause:e})}let r=qn(n,this.address);if(r===`unknown`)throw new Bt(`Unwrap transaction ${e} is not mined, so there is nothing to resume yet`,e);if(r===`settled`)throw await this.#p(`resumeUnshield`,e),new y(`Unwrap transaction ${e} reverted or opened no unwrap request from this wrapper, so there is nothing to resume`);let{unwrapRequestId:i}=r;if(await this.#u(i)===`settled`)throw await this.#p(`resumeUnshield`,e),new Ht(`Nothing to resume: the unwrap request was already finalized on-chain and the funds were delivered.`,{unwrapTxHash:e,unwrapRequestId:i});return await _(`resumeUnshield: savePendingUnshield`,()=>this.#d(e),this.sdk.logger),this.#h(i,e,crypto.randomUUID(),t,`resume-unshield`)}async getPendingUnshield(){let e=null,t=await Un(this.sdk.storage,this.address,this.sdk.logger);for(let n of t){let t=await this.#f(n);if(t===`open`)return n;t===`settled`?await this.#p(`getPendingUnshield`,n):e??=n}return e}async unwrap(e){return this.#o(e,`unwrap`)}async#o(e,t,n){this.#r(`unwrap`);let r=await C(`unwrap`,this.sdk.signer,this.sdk.provider),i=K(r.address),{encryptedValues:a,inputProof:o}=await this.sdk.encrypt({values:[{value:e,type:`euint64`}],contractAddress:this.address,userAddress:i},{operation:t}),[s]=a;if(!s)throw new V(`Encryption returned no encrypted values`);let c=await this.submitTransaction({operation:`unwrap`,config:xe(this.address,i,i,s,o),beforeReceipt:n});return{...c,unwrapRequestId:this.#l(c.receipt.logs)}}async unwrapAll(){return this.#s()}async#s(e){this.#r(`unwrapAll`);let t=await C(`unwrapAll`,this.sdk.signer,this.sdk.provider),n=K(t.address),r=await this.readConfidentialBalanceOf(n);if(F(r))throw new H(`Cannot unshield: balance is zero`);let i=await this.submitTransaction({operation:`unwrapAll`,config:Se(this.address,n,n,r),beforeReceipt:e});return{...i,unwrapRequestId:this.#l(i.receipt.logs)}}async finalizeUnwrap(e){return this.#c(e,`finalize-unwrap`)}async#c(e,t){this.#r(`finalizeUnwrap`),await ze(`finalizeUnwrap`,this.sdk.signer,this.sdk.provider);let{value:n,decryptionProof:r}=await at(this.sdk.relayer,e,{operation:t});return this.submitTransaction({operation:`finalizeUnwrap`,config:Ee(this.address,e,n,r)})}#l(e){let t=Kn(e,this.address);if(t===void 0)throw new y(`No UnwrapRequested event from this wrapper found in the unwrap receipt`);return t}async#u(e){try{return await this.sdk.provider.readContract(we(this.address,e))===Zt?`settled`:`open`}catch{return`unknown`}}#d(e){return Wn(this.sdk.storage,this.address,e,this.sdk.logger)}async#f(e){let t;try{t=await An(this.sdk.provider,e)}catch{return`unknown`}let n=qn(t,this.address);return typeof n==`string`?n:this.#u(n.unwrapRequestId)}async#p(e,t){await _(`${e}: clearPendingUnshield`,()=>Gn(this.sdk.storage,this.address,t,this.sdk.logger),this.sdk.logger)}async#m(){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#h(e,t,n,r,i){this.emit({type:h.UnshieldPhase1Submitted,txHash:t,operationId:n}),this.emit({type:h.UnshieldPhase2Started,operationId:n}),_(`unshield: onFinalizing`,()=>r?.onFinalizing?.(),this.sdk.logger);let a;try{a=await this.#c(e,i)}catch(n){throw Vt(n)||n instanceof y&&await this.#u(e)===`settled`?(await this.#p(`unshield`,t),new Ht(`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.#p(`unshield`,t),a}async#g(e,t,n){this.#r(`approveUnderlying`);let r=await this.#m(),i=await C(`approveUnderlying`,this.sdk.signer,this.sdk.provider),a=K(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:S(r,this.address,0n)});let s=t?2n**256n-1n:e;await this.submitTransaction({operation:`approveUnderlying`,config:S(r,this.address,s),onSubmitted:n?.onApprovalSubmitted})}};const Yn=q.union([q.bigint(),q.boolean(),a]),Xn=q.array(q.string());var Zn=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=Yn.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=K(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}:${K(e)}:${K(t)}:${n.toLowerCase()}`}async#l(){let e=await this.#e.get(this.#r);if(e===null)return[];let t=Xn.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 Qn(e,t){let n=$n(e,t);if(!n)throw new H(`No permit covers contract ${t} after allow()`);return{privateKey:e.keypair.privateKey,publicKey:e.keypair.publicKey,serializedPermit:n.serializedPermit}}function $n(e,t){let n=i(t);return e.permissions.find(e=>e.contractAddresses.includes(n))}const er=e=>new Promise(t=>setTimeout(t,e));var tr=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=K(t);return this.#s(e,{requesterAddress:r,errorMessage:`Failed to decrypt encrypted values`},n)}async delegatedDecryptValues(e,t,n,r,i){let a=K(t),o=K(n),s={spent:!1};return this.#a(i?.waitForPropagation??!0,()=>this.#s(e,{requesterAddress:K(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 Ye))throw t;await er(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:K(e.contractAddress)}));if(s.length===0)return{items:s};let c=K(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(Lt(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:K(t)}),{items:s}}}let l=!1,u;if(await ut(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(Lt(n)){l=!0,u??=n;return}e.error=this.#f(n,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:e.contractAddress,account:K(t)})}}),i),u!==void 0)throw u;return{items:s}}async#o(e,t,n,r){let i=Qn(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&&St(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:K(e.contractAddress)})),a={},o=[];for(let e of i)F(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 Et(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 ht(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 U)||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 Ft?new U(`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 z&&e.cause instanceof Error?e.cause:e;throw this.#i({type:h.DecryptError,error:R(n),durationMs:Date.now()-p,encryptedValues:m}),E(e,t.errorMessage,{isDelegated:t.delegator!==void 0})}}async#c(e,t,n,r,i){let a=(await ut(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 U)??a[0]}async#l(e,t,n,r,i,a){let o;try{o=await this.#o(t,n,r,a)}catch(t){throw E(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 H(`${e.errorMessage}: relayer returned no clear value for ${s.length} of ${r.length} handle(s) on ${n}`,{cause:AggregateError(s.map(e=>new H(`No clear value for handle ${e} on ${n}`)),`${s.length} handle(s) missing a clear value on ${n}`)})}#u(e,t){return new Rt(`RPC provider rate-limited ${t}; retry with backoff.`,{cause:e,retryAfter:yt(e)})}#d(e,t){let n=t[e.encryptedValue];n===void 0?e.error=new H(`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 z?e:E(e,t,n)}#p(){throw new H(`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 tt(`Only one delegate/revoke per (delegator, delegate, contract) per block. Wait for the next block before retrying.`,{cause:e}),SenderCannotBeContractAddress:e=>new rt(`The contract address cannot be the caller address.`,{cause:e}),EnforcedPause:e=>new it(`The ACL contract is paused. Delegation operations are temporarily disabled.`,{cause:e}),SenderCannotBeDelegate:e=>new w(`Cannot delegate to yourself (delegate === msg.sender).`,{cause:e}),DelegateCannotBeContractAddress:e=>new T(`Delegate address cannot be the same as the contract address.`,{cause:e}),DelegateCannotBeWildcard:e=>new et(`Delegate address cannot be the wildcard address; it can only be used as the contract address.`,{cause:e}),ExpirationDateBeforeOneHour:e=>new M(`Expiration date must be at least 1 hour in the future.`,{cause:e}),ExpirationDateAlreadySetToSameValue:e=>new Ze(`The new expiration date is the same as the current one.`,{cause:e}),NotDelegatedYet:e=>new N(`Cannot revoke: no active delegation exists.`,{cause:e})};function nr(e){return Object.hasOwn($,e)}function rr(e,t){let n=zt(e);if(n&&nr(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 ir=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 M(`Expiration date must be at least 1 hour in the future`);let a=K(t),o=K(n),s=K(r);if(o===s)throw new w(`Cannot delegate to yourself (delegate === msg.sender).`);if(o===K(`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`))throw new et(`Delegate address cannot be the wildcard address; it can only be used as the contract address.`);if(o===a)throw new T(`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)):Y,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 Ze(`The new expiration date (${l}) is the same as the current one. No on-chain change needed.`);return a!==K(`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`)&&await this.#i({contractAddress:a,delegatorAddress:s,delegateAddress:o}),this.#s({operation:`delegateDecryption`,signer:e,contractAddress:a,config:nn(c,o,a,l)})}async revokeDelegation(e,{contractAddress:t,delegateAddress:n,delegatorAddress:r}){let i=K(t),a=K(n),o=K(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 N(`No active delegation found for delegate ${a} on contract ${i}.`);return this.#s({operation:`revokeDelegation`,signer:e,contractAddress:i,config:rn(s,a,i)})}async isDelegated(e){return(await this.getStatus(e)).isActive}async getStatus(e){let t=K(e.contractAddress)===X,[n,r]=await Promise.all([this.getDelegationExpiry(e),t?Promise.resolve(0n):this.getDelegationExpiry({...e,contractAddress:X})]),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:X});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!==Y}#o(e,t){return e===0n?{isActive:!1,expiryTimestamp:e}:e===Y?{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(an(r,K(t),K(n),K(e)))}async#s({operation:e,signer:t,contractAddress:n,config:r}){try{return await ft({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=rr(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 N||t instanceof P){let n=K(e);r.set(n,t);return}throw t}})),r}async assertDelegationActive(e,t,n){let r=K(e),i=K(t),a=K(n),{isActive:o,expiryTimestamp:s}=await this.getStatus({contractAddress:r,delegatorAddress:i,delegateAddress:a});if(!o)throw s===0n?new N(`No active delegation from ${i} to ${a} for ${r}`):new P(`Delegation from ${i} to ${a} for ${r} has expired`)}},ar=class{#e;#t;constructor({router:e,emitEvent:t}){this.#e=e,this.#t=t}async encryptValues(e,t){let n=Date.now(),r=K(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:R(e),durationMs:Date.now()-n},r),$t(e,`Encryption failed`)}}},or=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 sr=q.object({kind:q.literal(`ConfidentialTransfer`),from:a,token:a,to:a,amount:q.bigint()}),cr=q.object({kind:q.literal(`ConfidentialTransferFrom`),from:a,token:a,owner:a,to:a,amount:q.bigint()}),lr=q.object({kind:q.literal(`SetOperator`),from:a,token:a,operator:a,until:u}),ur=q.object({kind:q.literal(`Unwrap`),from:a,token:a,to:a,amount:q.bigint()}),dr=q.object({kind:q.literal(`UnwrapAll`),from:a,token:a,to:a}),fr=q.object({kind:q.literal(`FinalizeUnwrap`),from:a,wrapper:a,unwrapRequestIdOrAmount:p}),pr=q.object({kind:q.literal(`ApproveUnderlying`),from:a,underlying:a,spender:a,amount:q.bigint()}),mr=q.object({kind:q.literal(`Wrap`),from:a,wrapper:a,to:a,amount:q.bigint()}),hr=p.check(q.refine(e=>e===`0x`||Xt(e)===20,`TransferAndCall.recipientData must be "0x" (self-shield to the sender) or a raw 20-byte address, not a 32-byte ABI-encoded value the wrapper would truncate to a garbage address`)),gr=q.object({kind:q.literal(`TransferAndCall`),from:a,underlying:a,wrapper:a,amount:q.bigint(),recipientData:q.optional(hr)}),_r=q.object({kind:q.literal(`DelegateDecryption`),from:a,contractAddress:a,delegateAddress:a,expirationDate:q.optional(q.date())}),vr=q.object({kind:q.literal(`RevokeDelegation`),from:a,contractAddress:a,delegateAddress:a});q.discriminatedUnion(`kind`,[sr,cr,lr,ur,dr,fr,pr,mr,gr,_r,vr]);const yr=q.strictObject({maxFeePerGas:q.bigint(),maxPriorityFeePerGas:q.bigint()}),br=q.object({nonce:q.optional(q.int().check(q.nonnegative())),gasLimit:q.optional(q.bigint()),fees:q.optional(yr)}),xr=q.object({address:a,abi:q.array(q.unknown()),functionName:q.string(),args:q.array(q.unknown()),value:q.optional(q.bigint()),gas:q.optional(q.bigint())}),Sr=q.extend(br,{from:a,calldata:xr});var Cr=class{#e;#t;#n;constructor(e){this.#e=e.provider,this.#t=e.router,this.#n=e.encryption}async prepare(e,t){t&&=G(br,t);let n=await this.#e.getChainId(),r=this.#t.chain.id;if(n!==r)throw new B(`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=G(Sr,i),o=await this.#e.prepareTransaction(a).catch(t=>{throw mt(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 B(`OfflineService.prepare: unsupported transaction kind '${e.kind}'.`)}}async#i(e){e=G(sr,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 V(`Encryption returned no handles for ConfidentialTransfer`);return Te(e.token,e.to,r,n)}async#a(e){e=G(cr,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 V(`Encryption returned no handles for ConfidentialTransferFrom`);return Ge(e.token,e.owner,e.to,r,n)}#o(e){return e=G(lr,e),Le(e.token,e.operator,e.until)}async#s(e){e=G(ur,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 V(`Encryption returned no handles for Unwrap`);return xe(e.token,e.from,e.to,r,n)}async#c(e){e=G(dr,e);let t=await this.#e.readContract(qe(e.token,e.from));return Se(e.token,e.from,e.to,t)}async#l(e){e=G(fr,e);let{value:t,decryptionProof:n}=await at(this.#t.relayer,e.unwrapRequestIdOrAmount,{operation:`offline-finalize-unwrap`});return Ee(e.wrapper,e.unwrapRequestIdOrAmount,t,n)}#u(e){return e=G(pr,e),S(e.underlying,e.spender,e.amount)}#d(e){return e=G(mr,e),g(e.wrapper,e.to,e.amount)}#f(e){return e=G(gr,e),tn(e.underlying,e.wrapper,e.amount,e.recipientData)}#p(e){if(e=G(_r,e),e.expirationDate&&e.expirationDate.getTime()<Date.now()+36e5)throw new M(`Expiration date must be at least 1 hour in the future`);if(e.delegateAddress===e.from)throw new w(`Cannot delegate to yourself (delegate === msg.sender).`);if(e.delegateAddress===e.contractAddress)throw new T(`Delegate address cannot be the same as the contract address (${e.contractAddress}).`);let t=e.expirationDate?BigInt(Math.floor(e.expirationDate.getTime()/1e3)):Y;return nn(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress,t)}#m(e){return e=G(vr,e),rn(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress)}};function wr(e){if(Object.hasOwn(e,`transportKeyPairDerivationSecret`)&&e.transportKeyPairDerivationSecret===void 0)throw new B(`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 B(`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 Er(e){if(e===void 0)return;let t=G(l,e);return new ne(typeof t==`string`?t:new Uint8Array(t))}var Dr=class{#e;provider;signer;storage;registry;permits;delegations;decryption;offline;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;constructor(e,t={}){wr(t),Tr(t.transportKeyPairDerivationSecret);let n=Er(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 Zn(e.storage,this.#i),this.#u=new ir({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 tr({cache:this.#a,credentialService:this.#l,delegationService:this.#u,router:e.router,emitEvent:this.emitEvent.bind(this)})),this.#s=new ar({router:e.router,emitEvent:this.emitEvent.bind(this)}),this.#o=new or({signer:e.signer,router:e.router,cachingService:this.#a,credentialService:this.#l,clearCredentialsOnWalletChange:e.clearCredentialsOnWalletChange,logger:this.#i}),this.#d=new Cr({provider:this.provider,router:e.router,encryption:this.#s,emitEvent:(e,t)=>this.emitEvent(e,t)}),this.permits=new wn({signer:this.signer,provider:this.provider,cachingService:this.#a,credentialService:this.#l,logger:this.#i,emitEvent:this.emitEvent.bind(this)}),this.delegations=new Tn({signer:this.signer,provider:this.provider,delegationService:this.#u}),this.decryption=new En({signer:this.signer,provider:this.provider,router:e.router,decryptionService:this.#c}),this.offline=new Dn(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,W(t,`encrypt`))}createToken(e){return new gt(this,e)}createWrappedToken(e){return new Jn(this,e)}dispose(){this.#o.dispose(),this.#e.dispose()}terminate(){this.dispose(),this.signer?.dispose?.()}[Symbol.dispose](){this.terminate()}};export{Cn as ACL_TOPICS,it as AclPausedError,Q as AclTopics,dt as BalanceCheckUnavailableError,te as BaseSigner,Ve as ChainMismatchError,On as ChromeSessionStorage,B as ConfigurationError,En as Decryption,H as DecryptionFailedError,n as DefaultRegistryAddresses,rt as DelegationContractIsSelfError,tt as DelegationCooldownError,et as DelegationDelegateCannotBeWildcardError,T as DelegationDelegateEqualsContractError,M as DelegationExpirationTooSoonError,P as DelegationExpiredError,Ze as DelegationExpiryUnchangedError,N as DelegationNotFoundError,Ye as DelegationNotPropagatedError,w as DelegationSelfNotAllowedError,Tn as Delegations,je as ERC1363_INTERFACE_ID,L as ERC20ReadFailedError,Be as ERC7984_INTERFACE_ID,He as ERC7984_WRAPPER_INTERFACE_ID,Dt as EncryptOffloadUnavailableError,V as EncryptionFailedError,be as HcuBlockLimitExceededError,ke as HcuTransactionLimitExceededError,t as IndexedDBStorage,ct as InsufficientAllowanceError,lt as InsufficientConfidentialBalanceError,I as InsufficientERC20BalanceError,jt as InvalidTransportKeyPairError,Ot as KeyWrappingError,Y as MAX_UINT64,s as MemoryStorage,d as MutableWalletAccountStore,Nt as NoCiphertextError,st as NotEntitledError,Dn as Offline,wn as Permits,Pt as PreparedPermitChainMismatchError,kt as PreparedPermitExpiredError,Ct as RelayerRequestFailedError,U as RevokedKmsContextError,Rt as RpcRateLimitError,ye as SignerNotConfiguredError,De as SignerRequiredError,Ft as SigningFailedError,Mt as SigningRejectedError,gn as TOKEN_TOPICS,gt as Token,Z as Topics,y as TransactionRevertedError,It as TransportKeyPairChangedError,At as TransportKeyPairExpiredError,Ht as UnshieldAlreadyFinalizedError,Bt as UnwrapNotMinedError,nt as VaultBatchNotDispatchedError,ot as VaultBatcherPausedError,Qe as VaultBatcherReadFailedError,$e as VaultJoinUnconfirmedError,X as WILDCARD_CONTRACT,Oe as WalletAccountNotReadyError,ve as WalletNotConnectedError,Jn as WrappedToken,f as WrappersRegistry,pt as ZERO_ENCRYPTED_VALUE,z as ZamaError,xt as ZamaErrorCode,Dr as ZamaSDK,h as ZamaSDKEvents,b as allowanceContract,fe as anvil,S as approveContract,x as balanceOfContract,ce as bscTestnet,ue as chains,kn as chromeSessionStorage,e as cleartext,qe as confidentialBalanceOfContract,Me as confidentialTotalSupplyContract,Ke as confidentialTransferAndCallContract,Te as confidentialTransferContract,he as confidentialTransferFromAndCallContract,Ge as confidentialTransferFromContract,sn as createConfig,m as createWalletAccountStore,Fe as decimalsContract,yn as decodeAclEvent,bn as decodeAclEvents,cn as decodeConfidentialTransfer,_n as decodeDelegatedForUserDecryption,fn as decodeOnChainEvent,pn as decodeOnChainEvents,vn as decodeRevokedDelegationForUserDecryption,dn as decodeUnwrapFinalized,un as decodeUnwrapRequested,ln as decodeWrap,nn as delegateForUserDecryptionContract,Ee as finalizeUnwrapContract,xn as findDelegatedForUserDecryption,Sn as findRevokedDelegationForUserDecryption,mn as findUnwrapRequested,hn as findWrap,Yt as getConfidentialTokenAddressContract,an as getDelegationExpiryContract,Gt as getTokenAddressContract,qt as getTokenPairContract,Wt as getTokenPairsContract,Ut as getTokenPairsLengthContract,Kt as getTokenPairsSliceContract,oe as hardhat,ie as hoodi,re as indexedDBStorage,_e as inferredTotalSupplyContract,Ne as isConfidentialTokenContract,Jt as isConfidentialTokenValidContract,Re as isConfidentialWrapperContract,F as isEncryptedValueZero,on as isHandleDelegatedContract,ge as isOperatorContract,vt as isRetryable,le as mainnet,Qt as matchZamaError,o as memoryStorage,Ae as nameContract,r as parsePreparedPermit,de as polygon,ae as polygonAmoy,Ce as rateContract,wt as retryAfterSeconds,rn as revokeDelegationContract,se as sepolia,Le as setOperatorContract,Pe as supportsInterfaceContract,We as symbolContract,tn as transferAndCallContract,me as underlyingContract,Ie as unwrapAmountContract,xe as unwrapContract,Se as unwrapFromBalanceContract,we as unwrapRequesterContract,g as wrapContract,pe as zenithTrexTestnet};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|