@zama-fhe/sdk 3.6.0-beta.2 → 3.6.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/base-signer.cjs +1 -1
- package/dist/cjs/base-signer.cjs.map +1 -1
- package/dist/cjs/fhevm-relayer.cjs.map +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/wrappers-registry.cjs.map +1 -1
- package/dist/esm/base-signer-DGIEzavu.js +2 -0
- package/dist/esm/base-signer-DGIEzavu.js.map +1 -0
- package/dist/esm/ethers/index.js +1 -1
- package/dist/esm/fhevm-relayer-Cm-ZR1vP.js.map +1 -1
- package/dist/esm/{index-Doh_XVSI.d.ts → index-BCh3VaZo.d.ts} +4 -4
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/query/index.d.ts +1 -1
- package/dist/esm/viem/index.js +1 -1
- package/dist/esm/wrappers-registry-BLe7PkZi.js.map +1 -1
- package/package.json +1 -1
- package/dist/esm/base-signer-CzEZ2cCF.js +0 -2
- package/dist/esm/base-signer-CzEZ2cCF.js.map +0 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{S as e,_ as t,a as n,b as r,c as i,d as a,g as o,h as s,i as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h,v as ee}from"./relayer-CVKO9GmQ.js";import{$ as g,A as te,C as ne,D as re,F as ie,G as _,H as ae,I as oe,J as se,K as v,L as y,M as ce,N as le,O as b,P as ue,Q as de,R as x,S as fe,T as pe,U as me,V as he,W as ge,X as _e,Z as ve,_ as S,a as ye,b as be,c as xe,d as Se,et as Ce,f as we,g as C,h as w,i as Te,j as Ee,k as De,l as Oe,m as ke,n as Ae,nt as je,o as Me,p as Ne,q as Pe,r as Fe,rt as Ie,s as Le,t as Re,tt as T,u as ze,v as Be,x as Ve,z as E}from"./wrappers-registry-BLe7PkZi.js";import{n as He,r as D,t as O}from"./encryption-BKoalB4o.js";import{a as Ue,c as k,d as A,f as We,g as j,h as Ge,i as M,l as Ke,m as qe,n as Je,o as Ye,p as Xe,r as Ze,s as Qe,t as $e,u as et}from"./token-BejFVO8m.js";import{t as tt}from"./cleartext-iE4sWgSP.js";import{_ as nt,a as rt,c as it,d as N,f as P,g as at,h as ot,i as st,l as ct,m as lt,n as ut,o as dt,p as ft,r as pt,s as mt,t as ht,u as gt}from"./base-signer-CzEZ2cCF.js";import{t as F}from"./validation-BRu06AM_.js";import{a as _t,c as vt,i as yt,l as bt,n as xt,o as St,r as Ct,s as wt,t as Tt,u as Et}from"./chains-ByyCdrrd.js";import{r as Dt,t as Ot}from"./assertions-Ca1ePdRJ.js";import{getAddress as I,keccak256 as kt,size as At,toBytes as jt,zeroAddress as Mt}from"viem";import{z as L}from"zod/mini";function Nt(e,t){if(e instanceof p){let n=t[e.code];if(n)return n(e)}return t._?.(e)}var Pt=class extends p{encryptedValue;contractAddress;account;constructor(e,t){super(c.NotEntitled,`Account ${e.account} is not entitled to decrypt encrypted value ${e.encryptedValue} on contract ${e.contractAddress}. This is not a transient failure — the account needs an on-chain ACL grant before it can decrypt this encrypted value.`,t),this.name=`NotEntitledError`,this.encryptedValue=e.encryptedValue,this.contractAddress=e.contractAddress,this.account=e.account}},R=class extends p{constructor(e,t){super(c.DelegationSelfNotAllowed,e,t),this.name=`DelegationSelfNotAllowedError`}},Ft=class extends p{constructor(e,t){super(c.DelegationCooldown,e,t),this.name=`DelegationCooldownError`}},z=class extends p{constructor(e,t){super(c.DelegationNotFound,e,t),this.name=`DelegationNotFoundError`}},B=class extends p{constructor(e,t){super(c.DelegationExpired,e,t),this.name=`DelegationExpiredError`}},V=class extends p{constructor(e,t){super(c.DelegationExpiryUnchanged,e,t),this.name=`DelegationExpiryUnchangedError`}},H=class extends p{constructor(e,t){super(c.DelegationDelegateEqualsContract,e,t),this.name=`DelegationDelegateEqualsContractError`}},It=class extends p{constructor(e,t){super(c.DelegationContractIsSelf,e,t),this.name=`DelegationContractIsSelfError`}},Lt=class extends p{constructor(e,t){super(c.AclPaused,e,t),this.name=`AclPausedError`}},U=class extends p{constructor(e,t){super(c.DelegationExpirationTooSoon,e,t),this.name=`DelegationExpirationTooSoonError`}},W=class extends p{constructor(e,t){super(c.DelegationNotPropagated,e,t),this.name=`DelegationNotPropagatedError`}};function Rt(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 zt=class extends p{unwrapTxHash;unwrapRequestId;constructor(e,t,n){super(c.UnshieldAlreadyFinalized,e,n),this.name=`UnshieldAlreadyFinalizedError`,this.unwrapTxHash=t.unwrapTxHash,this.unwrapRequestId=t.unwrapRequestId}};const Bt=`InvalidUnwrapRequest`,Vt=kt(jt(`${Bt}(bytes32)`)).slice(0,10);function Ht(e){for(let t=e;t instanceof Error;t=t.cause)if(Rt(t)===Bt||t.message.includes(Bt)||t.message.includes(Vt))return!0;return!1}const Ut=[O,de,u,W,se,Pe,Pt,j,_e,T];function G(e,n,c={}){if(Ut.some(t=>e instanceof t))return e;let d=e instanceof Error?e.message:n;if(e instanceof Error&&f(e.message))return new _e(e.message,{cause:e});if(t(e))return new T(`The permit's KMS context has been revoked on-chain, so the permit is no longer usable. The SDK evicts the permit and re-grants automatically; if this error surfaced, the retry failed the same way. The on-chain validity check is cached for up to 15 minutes, so a just-revoked context can keep failing across that window. Retry after the window; the SDK re-runs the recovery on the next decrypt, no manual cleanup is needed.`,{cause:e});if(e instanceof Error&&l(e.message))return c.isDelegated?new W(`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 Pt({encryptedValue:r(e.message)??``,contractAddress:c.contractAddress??``,account:c.account??``},{cause:e});if(a(e))return new j(d,{cause:e,retryAfter:i(e)});let p=m(e);return p===void 0&&ee(e)?new j(d,{cause:e,retryAfter:i(e)}):p===400?new de(e instanceof Error?e.message:`No ciphertext for this account`,{cause:e}):c.isDelegated&&p===500?new W(`Delegated decryption failed with a server error. This is most commonly caused by the delegation not having propagated to the gateway yet. Cross-chain sync usually completes within ~10 blocks (a few seconds) and the SDK retries across that window; seeing this means it did not sync in time — retry shortly. If the error persists, the gateway or relayer may be experiencing an unrelated issue.`,{cause:e}):s(e)||p!==void 0?new u(d,p,{cause:e,retryAfter:i(e),retryable:o(e)||void 0}):new O(n,{cause:e})}function Wt(e,t){if(e instanceof p)return e;let n=m(e),r=o(e);return n!==void 0||s(e)?new u(e instanceof Error?e.message:t,n,{cause:e,retryAfter:i(e),retryable:r||void 0}):new D(t,{cause:e})}const Gt=[{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 Kt(e,t,n,r=`0x`){return{address:e,abi:Gt,functionName:`transferAndCall`,args:[t,n,r]}}const K=[{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 qt(e,t,n,r){return{address:e,abi:K,functionName:`delegateForUserDecryption`,args:[t,n,r]}}function Jt(e,t,n){return{address:e,abi:K,functionName:`revokeDelegationForUserDecryption`,args:[t,n]}}function Yt(e,t,n,r){return{address:e,abi:K,functionName:`getUserDecryptionDelegationExpirationDate`,args:[t,n,r]}}function Xt(e,t,n,r,i){return{address:e,abi:K,functionName:`isHandleDelegatedForUserDecryption`,args:[t,n,r,i]}}const Zt=2n**64n-1n;function Qt(e){return st(e.signer,e.provider,e)}function $t(e){return e.startsWith(`0x`)?e:`0x${e}`}function q(e){return kt(jt(e))}const J={ConfidentialTransfer:q(`ConfidentialTransfer(address,address,bytes32)`),Wrap:q(`Wrap(address,uint256,bytes32)`),UnwrapRequested:q(`UnwrapRequested(address,bytes32,bytes32)`),UnwrapFinalized:q(`UnwrapFinalized(address,bytes32,bytes32,uint64)`)};function Y(e){return I($t(e.slice(-40)))}function en(e){return e}function tn(e,t){let n=2+t*64,r=e.slice(n,n+64);return r.length===64?r:r.padEnd(64,`0`)}function nn(e,t){return I($t(tn(e,t).slice(-40)))}function X(e,t){return BigInt(`0x`+tn(e,t))}function rn(e,t){return $t(tn(e,t))}function an(e){return e.topics[0]!==J.ConfidentialTransfer||e.topics.length<4?null:{eventName:`ConfidentialTransfer`,from:Y(e.topics[1]),to:Y(e.topics[2]),encryptedAmount:en(e.topics[3])}}function on(e){return e.topics[0]!==J.Wrap||e.topics.length<2?null:{eventName:`Wrap`,to:Y(e.topics[1]),roundedAmount:X(e.data,0),encryptedWrappedAmount:rn(e.data,1)}}function sn(e){return e.topics[0]!==J.UnwrapRequested||e.topics.length<3?null:{eventName:`UnwrapRequested`,receiver:Y(e.topics[1]),unwrapRequestId:en(e.topics[2]),encryptedAmount:rn(e.data,0)}}function cn(e){return e.topics[0]!==J.UnwrapFinalized||e.topics.length<3?null:{eventName:`UnwrapFinalized`,receiver:Y(e.topics[1]),unwrapRequestId:en(e.topics[2]),encryptedAmount:rn(e.data,0),cleartextAmount:X(e.data,1)}}function ln(e){return an(e)??on(e)??sn(e)??cn(e)}function un(e){let t=[];for(let n of e){let e=ln(n);e&&t.push(e)}return t}function dn(e){for(let t of e){let e=sn(t);if(e)return e}return null}function fn(e){for(let t of e){let e=on(t);if(e)return e}return null}const pn=[J.ConfidentialTransfer,J.Wrap,J.UnwrapRequested,J.UnwrapFinalized],Z={DelegatedForUserDecryption:q(`DelegatedForUserDecryption(address,address,address,uint64,uint64,uint64)`),RevokedDelegationForUserDecryption:q(`RevokedDelegationForUserDecryption(address,address,address,uint64,uint64)`)};function Q(e){return e.topics[0]!==Z.DelegatedForUserDecryption||e.topics.length<3?null:{eventName:`DelegatedForUserDecryption`,delegator:Y(e.topics[1]),delegate:Y(e.topics[2]),contractAddress:nn(e.data,0),delegationCounter:X(e.data,1),oldExpirationDate:X(e.data,2),newExpirationDate:X(e.data,3)}}function mn(e){return e.topics[0]!==Z.RevokedDelegationForUserDecryption||e.topics.length<3?null:{eventName:`RevokedDelegationForUserDecryption`,delegator:Y(e.topics[1]),delegate:Y(e.topics[2]),contractAddress:nn(e.data,0),delegationCounter:X(e.data,1),oldExpirationDate:X(e.data,2)}}function hn(e){return Q(e)??mn(e)}function gn(e){let t=[];for(let n of e){let e=hn(n);e&&t.push(e)}return t}function _n(e){for(let t of e){let e=Q(t);if(e)return e}return null}function vn(e){for(let t of e){let e=mn(t);if(e)return e}return null}const yn=[Z.DelegatedForUserDecryption,Z.RevokedDelegationForUserDecryption];var bn=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 _(this.#r,e)}#s(e,t){throw this.#a({type:E.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 Ue(`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 Ue(`grantDelegationPermit`,this.#e,this.#t)}catch(e){this.#s(`grantDelegationPermit`,e)}await n.grantPermit(t,e)}async hasPermit(e){return this.#r?this.#r.hasPermit(e):!1}async hasDelegationPermit(e,t){return this.#r?this.#r.hasPermit(t,e):!1}async warmTransportKeyPair(){let e=this.#r;if(!e)return;let t=this.#e?.walletAccount.getSnapshot();t&&await e.warmTransportKeyPair(t.address)}async registerPermit(e,t){let n;try{n=this.#o(`registerPermit`)}catch(e){this.#s(`registerPermit`,e)}await n.registerPermit(e,t),await this.#c(e.signerAddress)}async revokePermits(e){let t=this.#o(`revokePermits`),n=I((await M(`revokePermits`,this.#e,this.#t)).address);try{await t.revokePermits(e)}finally{await this.#c(n)}}async clear(){let e=this.#o(`clear`),t=I((await M(`clear`,this.#e,this.#t)).address);try{await e.clearCredentials()}finally{await this.#c(t)}}async#c(e){await x(`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)}},xn=class{#e;#t;#n;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.delegationService}#r(e){return _(this.#e,e)}async delegateDecryption({contractAddress:e,delegateAddress:t,expirationDate:n}){let r=this.#r(`delegateDecryption`),i=await M(`delegateDecryption`,this.#e,this.#t);return this.#n.delegateDecryption(r,{contractAddress:e,delegateAddress:t,delegatorAddress:i.address,expirationDate:n})}async revokeDelegation({contractAddress:e,delegateAddress:t}){let n=this.#r(`revokeDelegation`),r=await M(`revokeDelegation`,this.#e,this.#t);return this.#n.revokeDelegation(n,{contractAddress:e,delegateAddress:t,delegatorAddress:r.address})}async isActive(e){return this.#n.isDelegated(e)}async getExpiry(e){return this.#n.getDelegationExpiry(e)}async getStatus(e){return this.#n.getStatus(e)}},Sn=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 _(this.#r,e)}async decryptValues(e,t){let n=this.#i(`decryptValues`),r=await M(`decryptValues`,this.#e,this.#t);return n.decryptValues(e,r.address,t)}async delegatedDecryptValues(e,t,n=t,r){let i=this.#i(`delegatedDecryptValues`),a=await M(`delegatedDecryptValues`,this.#e,this.#t);return i.delegatedDecryptValues(e,t,a.address,n,r)}async decryptPublicValues(e,t){if(e.length===0)return{clearValues:{},decryptionProof:`0x`,abiEncodedClearValues:`0x`};try{let n=await this.#n.relayer.decryptPublicValuesWithSignatures({encryptedValues:e,options:t}),r={};return n.checkSignaturesArgs.handlesList.forEach((e,t)=>{Dt(n.clearValues[t],`result.clearValues[${t}]`),r[e]=n.clearValues[t].value}),{clearValues:r,abiEncodedClearValues:n.checkSignaturesArgs.abiEncodedCleartexts,decryptionProof:n.checkSignaturesArgs.decryptionProof}}catch(e){throw G(e,`Public decryption failed`)}}async delegatedBatchDecryptValues({encryptedInputs:e,delegatorAddress:t,accountAddress:n=t,maxConcurrency:r,waitForPropagation:i}){let a=this.#i(`delegatedBatchDecryptValues`),o=await M(`delegatedBatchDecryptValues`,this.#e,this.#t);return a.delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:o.address,accountAddress:n,maxConcurrency:r,waitForPropagation:i})}},Cn=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)}},wn=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 Tn=new wn;function $(e){return`zama:pending-unshield:${gt(e)}`}const En=L.union([L.pipe(P,L.transform(e=>({unwrapTxHash:e}))),L.pipe(L.object({version:L.literal(1),unwrapTxHash:P,unwrapRequestId:L.optional(P)}),L.transform(({unwrapTxHash:e,unwrapRequestId:t})=>({unwrapTxHash:e,unwrapRequestId:t})))]);async function Dn(e,t,n,r){if(r===void 0){await e.set($(t),n);return}await e.set($(t),{version:1,unwrapTxHash:n,unwrapRequestId:r})}async function On(e,t){let n=$(t),r=await e.get(n);if(r==null)return null;let i=En.safeParse(r);return i.success?i.data:(await e.delete(n),null)}async function kn(e,t){await e.delete($(t))}var An=class extends $e{#e;#t=null;#n=null;#r(e){try{return Dt(this.sdk.signer,`WrappedToken.sdk.signer`),this.sdk.signer}catch(t){throw new he(e,{cause:t})}}async underlying(){return this.#u()}async isPayable(){if(this.#n!==null)return this.#n;try{let e=await this.#u();this.#n=await this.sdk.provider.readContract(Ne(e))}catch{this.#n=!1}return this.#n}async allowance(e){let t=await this.#u();return this.sdk.provider.readContract(w(t,I(e),this.address))}async shield(t,n){let r=await M(`shield`,this.sdk.signer,this.sdk.provider),i=await this.isPayable(),a=await this.#u(),o=I(r.address),s;try{s=await this.sdk.provider.readContract(S(a,o))}catch(t){throw t instanceof p?t:new A(`Could not read ERC-20 balance for shield validation (token: ${a})`,{cause:e(t)})}if(s<t)throw new qe(`Insufficient ERC-20 balance: requested ${t}, available ${s} (token: ${a})`,{requested:t,available:s,token:a});return i?this.#i(t,a,o,n):this.#a(t,o,n)}async#i(e,t,n,r){this.#r(`shield`);let i=r?.to?I(r.to):n,a=i===n?`0x`:i;return this.submitTransaction({operation:`shield:transferAndCall`,config:Kt(t,this.address,e,a),onSubmitted:r?.onShieldSubmitted})}async wrap(t,n){this.#r(`wrap`);let r=await M(`wrap`,this.sdk.signer,this.sdk.provider),i=await this.#u(),a=I(r.address),o;try{o=await this.sdk.provider.readContract(S(i,a))}catch(t){throw t instanceof p?t:new A(`Could not read ERC-20 balance for wrap validation (token: ${i})`,{cause:e(t)})}if(o<t)throw new qe(`Insufficient ERC-20 balance: requested ${t}, available ${o} (token: ${i})`,{requested:t,available:o,token:i});let s;try{s=await this.sdk.provider.readContract(w(i,a,this.address))}catch(t){throw t instanceof p?t:new A(`Could not read ERC-20 allowance for wrap validation (token: ${i})`,{cause:e(t)})}if(s<t)throw new We(`Insufficient allowance for wrap: requested ${t}, approved ${s}. Call approveUnderlying() first (token: ${i}).`,{requested:t,available:s,token:i});let c=n?.to?I(n.to):a;return this.submitTransaction({operation:`wrap`,config:y(this.address,c,t),onSubmitted:n?.onWrapSubmitted})}async#a(e,t,n){this.#r(`shield`);let r=n?.approvalStrategy??`exact`;r!==`skip`&&await this.#f(e,r===`max`,n);let i=n?.to?I(n.to):t;return this.submitTransaction({operation:`shield:approveAndWrap`,config:y(this.address,i,e),onSubmitted:n?.onShieldSubmitted})}async approveUnderlying(e){this.#r(`approveUnderlying`);let t=await M(`approveUnderlying`,this.sdk.signer,this.sdk.provider),n=await this.#u(),r=I(t.address),i=e??2n**256n-1n;return i>0n&&await this.sdk.provider.readContract(w(n,r,this.address))>0n&&await this.submitTransaction({operation:`approveUnderlying:reset`,config:C(n,this.address,0n)}),this.submitTransaction({operation:`approveUnderlying`,config:C(n,this.address,i)})}async unshield(e,t){let{skipBalanceCheck:n=!1,onUnwrapSubmitted:r,onFinalizing:i,onFinalizeSubmitted:a}=t??{};n||await this.assertConfidentialBalance(e);let o={onFinalizing:i,onFinalizeSubmitted:a},s=crypto.randomUUID(),c=await this.unwrap(e);return x(`unshield: onUnwrapSubmitted`,()=>r?.(c.txHash),this.sdk.logger),this.#d(c.unwrapRequestId,c.txHash,s,o)}async unshieldAll(e){let t=crypto.randomUUID(),n=await this.unwrapAll();return x(`unshieldAll: onUnwrapSubmitted`,()=>e?.onUnwrapSubmitted?.(n.txHash),this.sdk.logger),this.#d(n.unwrapRequestId,n.txHash,t,e)}async resumeUnshield(e,t){let n;try{n=await this.sdk.provider.waitForTransactionReceipt(e)}catch(e){throw e instanceof p?e:new v(`Failed to get unwrap receipt`,{cause:e})}let r=this.#o(n.logs);if(await this.#s(r))throw await this.#l(`resumeUnshield`),new zt(`Nothing to resume: the unwrap request was already finalized on-chain and the funds were delivered.`,{unwrapTxHash:e,unwrapRequestId:r});return this.#d(r,e,crypto.randomUUID(),t)}async getPendingUnshield(){let e=await On(this.sdk.storage,this.address);return e?await this.#c(e)?(await this.#l(`getPendingUnshield`),null):e.unwrapTxHash:null}async unwrap(e){this.#r(`unwrap`);let t=I((await M(`unwrap`,this.sdk.signer,this.sdk.provider)).address),{encryptedValues:n,inputProof:r}=await this.sdk.encrypt({values:[{value:e,type:`euint64`}],contractAddress:this.address,userAddress:t}),[i]=n;if(!i)throw new D(`Encryption returned no encrypted values`);let a=await this.submitTransaction({operation:`unwrap`,config:ue(this.address,t,t,i,r)});return{...a,unwrapRequestId:this.#o(a.receipt.logs)}}async unwrapAll(){this.#r(`unwrapAll`);let e=I((await M(`unwrapAll`,this.sdk.signer,this.sdk.provider)).address),t=await this.readConfidentialBalanceOf(e);if(k(t))throw new O(`Cannot unshield: balance is zero`);let n=await this.submitTransaction({operation:`unwrapAll`,config:ie(this.address,e,e,t)});return{...n,unwrapRequestId:this.#o(n.receipt.logs)}}async finalizeUnwrap(e){this.#r(`finalizeUnwrap`),await Ue(`finalizeUnwrap`,this.sdk.signer,this.sdk.provider);let t=await this.sdk.decryption.decryptPublicValues([e]),n=t.clearValues[e];return Ot(n,`finalizeUnwrap: clearValue`),this.submitTransaction({operation:`finalizeUnwrap`,config:b(this.address,e,n,t.decryptionProof)})}#o(e){let t=dn(e.filter(e=>e.address===void 0||I(e.address)===this.address));if(!t)throw new v(`No UnwrapRequested event from this wrapper found in the unwrap receipt`);return t.unwrapRequestId}async#s(e){try{return await this.sdk.provider.readContract(oe(this.address,e))===Mt}catch{return!1}}async#c(e){let t=e.unwrapRequestId;if(t===void 0)try{let n=await this.sdk.provider.waitForTransactionReceipt(e.unwrapTxHash);t=this.#o(n.logs)}catch{return!1}return this.#s(t)}async#l(e){await x(`${e}: clearPendingUnshield`,()=>kn(this.sdk.storage,this.address),this.sdk.logger)}async#u(){return this.#e===void 0?(this.#t||=this.sdk.provider.readContract(le(this.address)).then(e=>(this.#e=e,this.#t=null,e)).catch(e=>{throw this.#t=null,e}),this.#t):this.#e}async#d(e,t,n,r){this.emit({type:E.UnshieldPhase1Submitted,txHash:t,operationId:n}),await x(`unshield: savePendingUnshield`,()=>Dn(this.sdk.storage,this.address,t,e),this.sdk.logger),this.emit({type:E.UnshieldPhase2Started,operationId:n}),x(`unshield: onFinalizing`,()=>r?.onFinalizing?.(),this.sdk.logger);let i;try{i=await this.finalizeUnwrap(e)}catch(n){throw Ht(n)?(await this.#l(`unshield`),new zt(`The unwrap request was finalized concurrently — the funds were already delivered.`,{unwrapTxHash:t,unwrapRequestId:e},{cause:n})):n}return this.emit({type:E.UnshieldPhase2Submitted,txHash:i.txHash,operationId:n}),x(`unshield: onFinalizeSubmitted`,()=>r?.onFinalizeSubmitted?.(i.txHash),this.sdk.logger),await this.#l(`unshield`),i}async#f(e,t,n){this.#r(`approveUnderlying`);let r=await this.#u(),i=I((await M(`approveUnderlying`,this.sdk.signer,this.sdk.provider)).address),a=await this.sdk.provider.readContract(w(r,i,this.address));if(a>=e)return;a>0n&&await this.submitTransaction({operation:`approveUnderlying:reset`,config:C(r,this.address,0n)});let o=t?2n**256n-1n:e;await this.submitTransaction({operation:`approveUnderlying`,config:C(r,this.address,o),onSubmitted:n?.onApprovalSubmitted})}};const jn=L.union([L.bigint(),L.boolean(),N]),Mn=L.array(L.string());var Nn=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=jn.safeParse(i);return a.success?a.data:(await this.delete(e,t,n),null)}catch(e){return this.#t.warn(`CachingService.get failed`,{error:e}),null}}async set(e,t,n,r){try{let i=this.#c(e,t,n);await this.#e.set(i,r),this.#i=this.#i.then(()=>this.#u(i).catch(e=>{this.#t.warn(`CachingService index write failed`,{error:e})})),await this.#i}catch(e){this.#t.warn(`CachingService.set failed`,{error:e})}}async delete(e,t,n){let r=this.#c(e,t,n);this.#i=this.#i.then(()=>this.#a(r).catch(e=>{this.#t.warn(`CachingService.delete failed`,{error:e})})),await this.#i}async clearForRequester(e){this.#i=this.#i.then(()=>this.#o(e).catch(e=>{this.#t.warn(`CachingService.clearForRequester failed`,{error:e})})),await this.#i}async clearAll(){this.#i=this.#i.then(()=>this.#s().catch(e=>{this.#t.warn(`CachingService.clearAll failed`,{error:e})})),await this.#i}async#a(e){await this.#e.delete(e).catch(()=>{});let t=await this.#l(),n=t.filter(t=>t!==e);n.length!==t.length&&await this.#e.set(this.#r,n)}async#o(e){let t=I(e),n=`${this.#n}:${t}:`,r=await this.#l(),i=[],a=[];for(let e of r)e.startsWith(n)?i.push(e):a.push(e);await Promise.all(i.map(e=>this.#e.delete(e).catch(()=>{}))),await this.#e.set(this.#r,a)}async#s(){let e=await this.#l();await Promise.all(e.map(e=>this.#e.delete(e).catch(()=>{}))),await this.#e.delete(this.#r)}#c(e,t,n){return`${this.#n}:${I(e)}:${I(t)}:${n.toLowerCase()}`}async#l(){let e=await this.#e.get(this.#r);if(e===null)return[];let t=Mn.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 Pn(e,t){let n=Fn(e,t);if(!n)throw new O(`No permit covers contract ${t} after allow()`);return{privateKey:e.keypair.privateKey,publicKey:e.keypair.publicKey,serializedPermit:n.serializedPermit}}function Fn(e,t){let n=gt(t);return e.permissions.find(e=>e.contractAddresses.includes(n))}const In=e=>new Promise(t=>setTimeout(t,e));var Ln=class{#e;#t;#n;#r;#i;constructor({cache:e,credentialService:t,delegationService:n,router:r,emitEvent:i}){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i}async decryptValues(e,t,n){let r=I(t);return this.#s(e,{requesterAddress:r,errorMessage:`Failed to decrypt encrypted values`},n)}async delegatedDecryptValues(e,t,n,r,i){let a=I(t),o=I(n),s={spent:!1};return this.#a(i?.waitForPropagation??!0,()=>this.#s(e,{requesterAddress:I(r),delegator:a,validate:e=>this.#m(e,{delegatorAddress:a,delegateAddress:o}),errorMessage:`Failed to decrypt delegated encrypted values`},void 0,s))}async#a(e,t){let n;for(let r=0;r<16;r++)try{return await t()}catch(t){if(n=t,!(r<15&&e&&t instanceof W))throw t;await In(2e3)}throw n}async delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:n,accountAddress:r,maxConcurrency:i=5,waitForPropagation:a=!0}){let o=e.map(e=>({encryptedValue:e.encryptedValue,contractAddress:I(e.contractAddress)}));if(o.length===0)return{items:o};let s=I(r);try{let e=await this.delegatedDecryptValues(o.map(({encryptedValue:e,contractAddress:t})=>({encryptedValue:e,contractAddress:t})),t,n,s,{waitForPropagation:a});for(let t of o)this.#d(t,e);return{items:o}}catch(e){if(Ke(e))throw e;if(o.length===1){let[n=this.#p()]=o;return n.error=this.#f(e,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:n.contractAddress,account:I(t)}),{items:o}}}let c=!1,l;if(await Ze(o.map(e=>async()=>{if(!c)try{let r=await this.delegatedDecryptValues([{encryptedValue:e.encryptedValue,contractAddress:e.contractAddress}],t,n,s,{waitForPropagation:!1});this.#d(e,r)}catch(n){if(Ke(n)){c=!0,l??=n;return}e.error=this.#f(n,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:e.contractAddress,account:I(t)})}}),i),l!==void 0)throw l;return{items:o}}async#o(e,t,n,r){let i=Pn(e,t),a;try{a=await this.#r.relayer.parseTransportKeyPair({publicKey:i.publicKey,privateKey:i.privateKey,tkmsVersion:e.keypair.tkmsVersion})}catch(e){throw e instanceof Error&&f(e.message)&&await this.#t.evictTransportKeyPair(),e}let o=await this.#r.relayer.parseSignedDecryptionPermit({transportKeyPair:a,serializedPermit:i.serializedPermit});return this.#r.relayer.decryptValues({transportKeyPair:a,signedPermit:o,encryptedValues:n,contractAddress:t,options:r})}async#s(t,n,r,i={spent:!1}){if(t.length===0)return{};let a=t.map(e=>({encryptedValue:e.encryptedValue,contractAddress:I(e.contractAddress)})),o={},s=[];for(let e of a)k(e.encryptedValue)?o[e.encryptedValue]=0n:s.push(e);if(s.length===0)return o;let c=Array.from(new Set(a.map(e=>e.contractAddress))),l=Array.from(new Set(s.map(e=>e.contractAddress)));if(n.validate)try{await n.validate(l)}catch(e){throw ee(e)?this.#u(e,`the delegation pre-check`):e}let u=[];for(let e of s){let t=await this.#e.get(n.requesterAddress,e.contractAddress,e.encryptedValue);t===null?u.push(e):o[e.encryptedValue]=t}if(u.length===0)return o;let d=await this.#t.grantPermit(c,n.delegator),f=new Map;for(let e of u){let t=f.get(e.contractAddress);t?t.push(e.encryptedValue):f.set(e.contractAddress,[e.encryptedValue])}let m=[];for(let[e,t]of f)for(let n of Qe(t))m.push({contractAddress:e,encryptedValues:n});let h=Date.now(),g=u.map(e=>e.encryptedValue);try{this.#i({type:E.DecryptStart,encryptedValues:g});try{await this.#c(n,d,m,o,r)}catch(e){if(!(e instanceof T)||i.spent)throw e;let t=d.permissions.map(e=>e.serializedPermit.signature);i.spent=!0;try{d=await this.#t.recoverPermits(c,n.delegator,t)}catch(e){throw e instanceof Pe?new T(`The permit's KMS context has been revoked on-chain and the automatic re-grant failed, so the decrypt cannot proceed. Establish a new permit for this scope and retry.`,{cause:e}):e}await this.#c(n,d,m.filter(({encryptedValues:e})=>e.some(e=>o[e]===void 0)),o,r)}let e={};for(let t of g){let n=o[t];n!==void 0&&(e[t]=n)}return this.#i({type:E.DecryptEnd,durationMs:Date.now()-h,encryptedValues:g,result:e}),o}catch(t){let r=t instanceof p&&t.cause instanceof Error?t.cause:t;throw this.#i({type:E.DecryptError,error:e(r),durationMs:Date.now()-h,encryptedValues:g}),G(t,n.errorMessage,{isDelegated:n.delegator!==void 0})}}async#c(e,t,n,r,i){let a=(await Ze(n.map(({contractAddress:n,encryptedValues:a})=>async()=>{try{await this.#l(e,t,n,a,r,i);return}catch(e){return e}}),5)).filter(e=>e!==void 0);if(a.length>0)throw a.find(e=>e instanceof T)??a[0]}async#l(e,t,n,r,i,a){let o;try{o=await this.#o(t,n,r,a)}catch(t){throw G(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 O(`${e.errorMessage}: relayer returned no clear value for ${s.length} of ${r.length} handle(s) on ${n}`,{cause:AggregateError(s.map(e=>new O(`No clear value for handle ${e} on ${n}`)),`${s.length} handle(s) missing a clear value on ${n}`)})}#u(e,t){return new j(`RPC provider rate-limited ${t}; retry with backoff.`,{cause:e,retryAfter:i(e)})}#d(e,t){let n=t[e.encryptedValue];if(n===void 0){e.error=new O(`Batch delegated decryption returned no value for encrypted value ${e.encryptedValue} on contract ${e.contractAddress}`);return}e.value=n}#f(e,t,n){return e instanceof p?e:G(e,t,n)}#p(){throw new O(`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 Rn={AlreadyDelegatedOrRevokedInSameBlock:e=>new Ft(`Only one delegate/revoke per (delegator, delegate, contract) per block. Wait for the next block before retrying.`,{cause:e}),SenderCannotBeContractAddress:e=>new It(`The contract address cannot be the caller address.`,{cause:e}),EnforcedPause:e=>new Lt(`The ACL contract is paused. Delegation operations are temporarily disabled.`,{cause:e}),SenderCannotBeDelegate:e=>new R(`Cannot delegate to yourself (delegate === msg.sender).`,{cause:e}),DelegateCannotBeContractAddress:e=>new H(`Delegate address cannot be the same as the contract address.`,{cause:e}),ExpirationDateBeforeOneHour:e=>new U(`Expiration date must be at least 1 hour in the future.`,{cause:e}),ExpirationDateAlreadySetToSameValue:e=>new V(`The new expiration date is the same as the current one.`,{cause:e}),NotDelegatedYet:e=>new z(`Cannot revoke: no active delegation exists.`,{cause:e})};function zn(e){return Object.hasOwn(Rn,e)}function Bn(e,t){let n=Rt(e);if(n&&zn(n))return Rn[n](t);let r=e instanceof Error?e.message:String(e);for(let[e,n]of Object.entries(Rn))if(r.includes(e))return n(t);return null}var Vn=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 U(`Expiration date must be at least 1 hour in the future`);let a=I(t),o=I(n),s=I(r);if(o===s)throw new R(`Cannot delegate to yourself (delegate === msg.sender).`);if(o===a)throw new H(`Delegate address cannot be the same as the contract address (${a}).`);let c=this.#e.relayer.chain.aclContractAddress,l=i?BigInt(Math.floor(i.getTime()/1e3)):Zt,u;try{u=await this.getDelegationExpiry({contractAddress:a,delegatorAddress:s,delegateAddress:o})}catch(e){this.#r.warn(`delegateDecryption: pre-flight expiry check failed`,{error:e}),u=-1n}if(u===l)throw new V(`The new expiration date (${l}) is the same as the current one. No on-chain change needed.`);return this.#i({operation:`delegateDecryption`,signer:e,contractAddress:a,config:qt(c,o,a,l)})}async revokeDelegation(e,{contractAddress:t,delegateAddress:n,delegatorAddress:r}){let i=I(t),a=I(n),o=I(r),s=this.#e.relayer.chain.aclContractAddress,c;try{c=await this.getDelegationExpiry({contractAddress:i,delegatorAddress:o,delegateAddress:a})}catch(e){this.#r.warn(`revokeDelegation: pre-flight expiry check failed`,{error:e}),c=1n}if(c===0n)throw new z(`No active delegation found for delegate ${a} on contract ${i}.`);return this.#i({operation:`revokeDelegation`,signer:e,contractAddress:i,config:Jt(s,a,i)})}async isDelegated(e){return(await this.getStatus(e)).isActive}async getStatus(e){let t=await this.getDelegationExpiry(e);return t===0n?{isActive:!1,expiryTimestamp:t}:t===Zt?{isActive:!0,expiryTimestamp:t}:{isActive:t>await this.#t.getBlockTimestamp(),expiryTimestamp:t}}async getDelegationExpiry({contractAddress:e,delegatorAddress:t,delegateAddress:n}){let r=this.#e.relayer.chain.aclContractAddress;return this.#t.readContract(Yt(r,I(t),I(n),I(e)))}async#i({operation:e,signer:t,contractAddress:n,config:r}){try{return await Je({operation:e,signer:t,provider:this.#t,config:r,emit:e=>this.#n(e,n),logger:this.#r})}catch(e){throw this.#a(e),e}}#a(e){if(!(e instanceof v))return;let t=Bn(e.cause??e,e);if(t)throw t}async findInactiveDelegations(e,t,n){let r=new Map;return await Promise.all(e.map(async e=>{try{await this.assertDelegationActive(e,t,n)}catch(t){if(t instanceof z||t instanceof B){let n=I(e);r.set(n,t);return}throw t}})),r}async assertDelegationActive(e,t,n){let r=I(e),i=I(t),a=I(n),{isActive:o,expiryTimestamp:s}=await this.getStatus({contractAddress:r,delegatorAddress:i,delegateAddress:a});if(!o)throw s===0n?new z(`No active delegation from ${i} to ${a} for ${r}`):new B(`Delegation from ${i} to ${a} for ${r} has expired`)}},Hn=class{#e;#t;constructor({router:e,emitEvent:t}){this.#e=e,this.#t=t}async encryptValues(t,n){let r=Date.now(),i=I(t.contractAddress);try{this.#t({type:E.EncryptStart},i);let e=await this.#e.relayer.encryptValues({...t,options:n});return this.#t({type:E.EncryptEnd,durationMs:Date.now()-r},i),e}catch(t){throw this.#t({type:E.EncryptError,error:e(t),durationMs:Date.now()-r},i),Wt(t,`Encryption failed`)}}},Un=class{#e;#t;#n;#r;#i;#a=new Set;#o;constructor(e){this.#e=e.signer,this.#t=e.router,this.#n=e.cachingService,this.#r=e.credentialService,this.#i=e.logger,this.#e&&(this.#o=this.#e.walletAccount.subscribe(e=>{this.#s(e).catch(e=>{this.#i.warn(`wallet account handler failed`,{error:e})})}))}onWalletAccountChange(e){return this.#a.add(e),()=>{this.#a.delete(e)}}dispose(){this.#o?.(),this.#o=void 0,this.#a.clear()}async#s(e){let t=e.previous,n=e.next,r=n?.chainId;r!==void 0&&await x(`switch relayer chain`,()=>this.#t.switchChain(r),this.#i);let i=this.#r;i&&await x(`credential wallet account change`,()=>i.handleWalletAccountChange(t,n),this.#i),t&&await x(`clear decrypt cache`,()=>this.#n.clearForRequester(t.address),this.#i),await Promise.all(Array.from(this.#a,t=>x(`wallet account listener`,()=>t(e),this.#i)))}};const Wn=L.object({kind:L.literal(`ConfidentialTransfer`),from:N,token:N,to:N,amount:L.bigint()}),Gn=L.object({kind:L.literal(`ConfidentialTransferFrom`),from:N,token:N,owner:N,to:N,amount:L.bigint()}),Kn=L.object({kind:L.literal(`SetOperator`),from:N,token:N,operator:N,until:ft}),qn=L.object({kind:L.literal(`Unwrap`),from:N,token:N,to:N,amount:L.bigint()}),Jn=L.object({kind:L.literal(`UnwrapAll`),from:N,token:N,to:N}),Yn=L.object({kind:L.literal(`FinalizeUnwrap`),from:N,wrapper:N,unwrapRequestIdOrAmount:P}),Xn=L.object({kind:L.literal(`ApproveUnderlying`),from:N,underlying:N,spender:N,amount:L.bigint()}),Zn=L.object({kind:L.literal(`Wrap`),from:N,wrapper:N,to:N,amount:L.bigint()}),Qn=P.check(L.refine(e=>e===`0x`||At(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`)),$n=L.object({kind:L.literal(`TransferAndCall`),from:N,underlying:N,wrapper:N,amount:L.bigint(),recipientData:L.optional(Qn)}),er=L.object({kind:L.literal(`DelegateDecryption`),from:N,contractAddress:N,delegateAddress:N,expirationDate:L.optional(L.date())}),tr=L.object({kind:L.literal(`RevokeDelegation`),from:N,contractAddress:N,delegateAddress:N});L.discriminatedUnion(`kind`,[Wn,Gn,Kn,qn,Jn,Yn,Xn,Zn,$n,er,tr]);const nr=L.strictObject({maxFeePerGas:L.bigint(),maxPriorityFeePerGas:L.bigint()}),rr=L.object({nonce:L.optional(L.int().check(L.nonnegative())),gasLimit:L.optional(L.bigint()),fees:L.optional(nr)}),ir=L.object({address:N,abi:L.array(L.unknown()),functionName:L.string(),args:L.array(L.unknown()),value:L.optional(L.bigint()),gas:L.optional(L.bigint())}),ar=L.extend(rr,{from:N,calldata:ir});var or=class{#e;#t;#n;constructor(e){this.#e=e.provider,this.#t=e.router,this.#n=e.encryption}async prepare(e,t){t&&=F(rr,t);let n=await this.#e.getChainId(),r=this.#t.chain.id;if(n!==r)throw new h(`Offline.prepare: provider is on chain ${n} but the SDK is configured for chain ${r}. The prepared transaction's contract addresses and encrypted inputs are bound to chain ${r} — point the provider at the same chain.`);let i=F(ar,{calldata:await this.#r(e),from:e.from,nonce:t?.nonce,gasLimit:t?.gasLimit,fees:t?.fees}),a=await this.#e.prepareTransaction(i);return{kind:e.kind,unsignedTx:a,from:i.from}}async#r(e){switch(e.kind){case`ConfidentialTransfer`:return this.#i(e);case`ConfidentialTransferFrom`:return this.#a(e);case`SetOperator`:return this.#o(e);case`Unwrap`:return this.#s(e);case`UnwrapAll`:return this.#c(e);case`FinalizeUnwrap`:return this.#l(e);case`ApproveUnderlying`:return this.#u(e);case`Wrap`:return this.#d(e);case`TransferAndCall`:return this.#f(e);case`DelegateDecryption`:return this.#p(e);case`RevokeDelegation`:return this.#m(e);default:throw new h(`OfflineService.prepare: unsupported transaction kind '${e.kind}'.`)}}async#i(e){e=F(Wn,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from}),r=t[0];if(!r)throw new D(`Encryption returned no handles for ConfidentialTransfer`);return pe(e.token,e.to,r,n)}async#a(e){e=F(Gn,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from}),r=t[0];if(!r)throw new D(`Encryption returned no handles for ConfidentialTransferFrom`);return re(e.token,e.owner,e.to,r,n)}#o(e){return e=F(Kn,e),ce(e.token,e.operator,e.until)}async#s(e){e=F(qn,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from}),r=t[0];if(!r)throw new D(`Encryption returned no handles for Unwrap`);return ue(e.token,e.from,e.to,r,n)}async#c(e){e=F(Jn,e);let t=await this.#e.readContract(fe(e.token,e.from));return ie(e.token,e.from,e.to,t)}async#l(e){e=F(Yn,e);let t=await this.#t.relayer.decryptPublicValuesWithSignatures({encryptedValues:[e.unwrapRequestIdOrAmount]}).catch(e=>{throw G(e,`Public decryption failed during FinalizeUnwrap`)}),n=t.clearValues[0]?.value;return Ot(n,`FinalizeUnwrap: decryptPublicValuesWithSignatures(handle).clearValue`),b(e.wrapper,e.unwrapRequestIdOrAmount,n,t.checkSignaturesArgs.decryptionProof)}#u(e){return e=F(Xn,e),C(e.underlying,e.spender,e.amount)}#d(e){return e=F(Zn,e),y(e.wrapper,e.to,e.amount)}#f(e){return e=F($n,e),Kt(e.underlying,e.wrapper,e.amount,e.recipientData)}#p(e){if(e=F(er,e),e.expirationDate&&e.expirationDate.getTime()<Date.now()+36e5)throw new U(`Expiration date must be at least 1 hour in the future`);if(e.delegateAddress===e.from)throw new R(`Cannot delegate to yourself (delegate === msg.sender).`);if(e.delegateAddress===e.contractAddress)throw new H(`Delegate address cannot be the same as the contract address (${e.contractAddress}).`);let t=e.expirationDate?BigInt(Math.floor(e.expirationDate.getTime()/1e3)):Zt;return qt(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress,t)}#m(e){return e=F(tr,e),Jt(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress)}};function sr(e){if(!(!Object.hasOwn(e,`transportKeyPairDerivationSecret`)||e.transportKeyPairDerivationSecret!==void 0))throw new h(`transportKeyPairDerivationSecret was passed as undefined, which usually means the environment variable it reads is unset (e.g. process.env.ZAMA_DERIVATION_SECRET). Supply the secret, or omit the option entirely to persist transport key pairs in cleartext on purpose.`)}function cr(e){if(e===void 0)return;let{importScripts:t}=globalThis;if(!(typeof window>`u`&&typeof document>`u`&&typeof t!=`function`))throw new h(`transportKeyPairDerivationSecret is supported in headless environments only (CLI tools, servers, agents). Remove the option: an environment with a platform keystore, or one that ships a bundle, must delegate at-rest security of the transport key pair to the storage backend.`)}function lr(e){if(e===void 0)return;let t=F(it,e);return new ct(typeof t==`string`?t:new Uint8Array(t))}var ur=class{#e;provider;signer;storage;registry;permits;delegations;decryption;offline;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;constructor(e,t={}){sr(t),cr(t.transportKeyPairDerivationSecret);let n=lr(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 Nn(e.storage,this.#i),this.#u=new Vn({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 dt({provider:this.provider,registryAddresses:r,registryTTL:e.registryTTL}),this.#n=r,this.#t=e.registryTTL,this.#l=new mt({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 Ln({cache:this.#a,credentialService:this.#l,delegationService:this.#u,router:e.router,emitEvent:this.emitEvent.bind(this)})),this.#s=new Hn({router:e.router,emitEvent:this.emitEvent.bind(this)}),this.#o=new Un({signer:e.signer,router:e.router,cachingService:this.#a,credentialService:this.#l,logger:this.#i}),this.#d=new or({provider:this.provider,router:e.router,encryption:this.#s,emitEvent:(e,t)=>this.emitEvent(e,t)}),this.permits=new bn({signer:this.signer,provider:this.provider,cachingService:this.#a,credentialService:this.#l,logger:this.#i,emitEvent:this.emitEvent.bind(this)}),this.delegations=new xn({signer:this.signer,provider:this.provider,delegationService:this.#u}),this.decryption=new Sn({signer:this.signer,provider:this.provider,router:e.router,decryptionService:this.#c}),this.offline=new Cn(this.#d,this.#l)}onWalletAccountChange(e){return this.#o.onWalletAccountChange(e)}get logger(){return this.#i}get relayer(){return this.#e.relayer}emitEvent(e,t){try{this.#r({...e,tokenAddress:t,timestamp:Date.now()})}catch(t){this.#i.warn(`${e.type} event listener silently failed`,{error:t})}}createWrappersRegistry(e){return new dt({provider:this.provider,registryAddresses:{...this.#n,...e},registryTTL:this.#t})}async encrypt(e,t){return this.#s.encryptValues(e,t)}createToken(e){return new $e(this,e)}createWrappedToken(e){return new An(this,e)}dispose(){this.#o.dispose(),this.#e.dispose()}terminate(){this.dispose(),this.signer?.dispose?.()}[Symbol.dispose](){this.terminate()}};export{yn as ACL_TOPICS,Lt as AclPausedError,Z as AclTopics,et as BalanceCheckUnavailableError,ht as BaseSigner,Ge as ChainMismatchError,wn as ChromeSessionStorage,h as ConfigurationError,Sn as Decryption,O as DecryptionFailedError,rt as DefaultRegistryAddresses,It as DelegationContractIsSelfError,Ft as DelegationCooldownError,H as DelegationDelegateEqualsContractError,U as DelegationExpirationTooSoonError,B as DelegationExpiredError,V as DelegationExpiryUnchangedError,z as DelegationNotFoundError,W as DelegationNotPropagatedError,R as DelegationSelfNotAllowedError,xn as Delegations,xe as ERC1363_INTERFACE_ID,A as ERC20ReadFailedError,Oe as ERC7984_INTERFACE_ID,ze as ERC7984_WRAPPER_INTERFACE_ID,He as EncryptOffloadUnavailableError,D as EncryptionFailedError,at as IndexedDBStorage,We as InsufficientAllowanceError,Xe as InsufficientConfidentialBalanceError,qe as InsufficientERC20BalanceError,_e as InvalidTransportKeyPairError,ve as KeyWrappingError,lt as MemoryStorage,ut as MutableWalletAccountStore,de as NoCiphertextError,Pt as NotEntitledError,Cn as Offline,bn as Permits,g as PreparedPermitChainMismatchError,Ce as PreparedPermitExpiredError,u as RelayerRequestFailedError,T as RevokedKmsContextError,j as RpcRateLimitError,he as SignerNotConfiguredError,ae as SignerRequiredError,Pe as SigningFailedError,se as SigningRejectedError,pn as TOKEN_TOPICS,$e as Token,J as Topics,v as TransactionRevertedError,je as TransportKeyPairChangedError,Ie as TransportKeyPairExpiredError,zt as UnshieldAlreadyFinalizedError,me as WalletAccountNotReadyError,ge as WalletNotConnectedError,An as WrappedToken,dt as WrappersRegistry,Ye as ZERO_ENCRYPTED_VALUE,p as ZamaError,c as ZamaErrorCode,ur as ZamaSDK,E as ZamaSDKEvents,w as allowanceContract,Tt as anvil,C as approveContract,S as balanceOfContract,xt as bscTestnet,Ct as chains,Tn as chromeSessionStorage,tt as cleartext,fe as confidentialBalanceOfContract,ne as confidentialTotalSupplyContract,pe as confidentialTransferContract,re as confidentialTransferFromContract,Qt as createConfig,pt as createWalletAccountStore,Be as decimalsContract,hn as decodeAclEvent,gn as decodeAclEvents,an as decodeConfidentialTransfer,Q as decodeDelegatedForUserDecryption,ln as decodeOnChainEvent,un as decodeOnChainEvents,mn as decodeRevokedDelegationForUserDecryption,cn as decodeUnwrapFinalized,sn as decodeUnwrapRequested,on as decodeWrap,qt as delegateForUserDecryptionContract,b as finalizeUnwrapContract,_n as findDelegatedForUserDecryption,vn as findRevokedDelegationForUserDecryption,dn as findUnwrapRequested,fn as findWrap,Re as getConfidentialTokenAddressContract,Yt as getDelegationExpiryContract,Ae as getTokenAddressContract,Fe as getTokenPairContract,Te as getTokenPairsContract,ye as getTokenPairsLengthContract,Me as getTokenPairsSliceContract,yt as hardhat,_t as hoodi,nt as indexedDBStorage,De as inferredTotalSupplyContract,St as ingenTestnet,Se as isConfidentialTokenContract,Le as isConfidentialTokenValidContract,we as isConfidentialWrapperContract,k as isEncryptedValueZero,Xt as isHandleDelegatedContract,te as isOperatorContract,n as isRetryable,wt as mainnet,Nt as matchZamaError,ot as memoryStorage,be as nameContract,vt as polygon,bt as polygonAmoy,Ee as rateContract,d as retryAfterSeconds,Jt as revokeDelegationContract,Et as sepolia,ce as setOperatorContract,ke as supportsInterfaceContract,Ve as symbolContract,Kt as transferAndCallContract,le as underlyingContract,ue as unwrapContract,ie as unwrapFromBalanceContract,oe as unwrapRequesterContract,y as wrapContract};
|
|
1
|
+
import{S as e,_ as t,a as n,b as r,c as i,d as a,g as o,h as s,i as c,m as l,n as u,o as d,p as f,r as p,s as m,t as h,v as ee}from"./relayer-CVKO9GmQ.js";import{$ as g,A as te,C as ne,D as re,F as ie,G as _,H as ae,I as oe,J as se,K as v,L as y,M as ce,N as le,O as b,P as ue,Q as de,R as x,S as fe,T as pe,U as me,V as he,W as ge,X as _e,Z as ve,_ as S,a as ye,b as be,c as xe,d as Se,et as Ce,f as we,g as C,h as w,i as Te,j as Ee,k as De,l as Oe,m as ke,n as Ae,nt as je,o as Me,p as Ne,q as Pe,r as Fe,rt as Ie,s as Le,t as Re,tt as T,u as ze,v as Be,x as Ve,z as E}from"./wrappers-registry-BLe7PkZi.js";import{n as He,r as D,t as O}from"./encryption-BKoalB4o.js";import{a as Ue,c as k,d as A,f as We,g as j,h as Ge,i as M,l as Ke,m as qe,n as Je,o as Ye,p as Xe,r as Ze,s as Qe,t as $e,u as et}from"./token-BejFVO8m.js";import{t as tt}from"./cleartext-iE4sWgSP.js";import{_ as nt,a as rt,c as it,d as N,f as P,g as at,h as ot,i as st,l as ct,m as lt,n as ut,o as dt,p as ft,r as pt,s as mt,t as ht,u as gt}from"./base-signer-DGIEzavu.js";import{t as F}from"./validation-BRu06AM_.js";import{a as _t,c as vt,i as yt,l as bt,n as xt,o as St,r as Ct,s as wt,t as Tt,u as Et}from"./chains-ByyCdrrd.js";import{r as Dt,t as Ot}from"./assertions-Ca1ePdRJ.js";import{getAddress as I,keccak256 as kt,size as At,toBytes as jt,zeroAddress as Mt}from"viem";import{z as L}from"zod/mini";function Nt(e,t){if(e instanceof p){let n=t[e.code];if(n)return n(e)}return t._?.(e)}var Pt=class extends p{encryptedValue;contractAddress;account;constructor(e,t){super(c.NotEntitled,`Account ${e.account} is not entitled to decrypt encrypted value ${e.encryptedValue} on contract ${e.contractAddress}. This is not a transient failure — the account needs an on-chain ACL grant before it can decrypt this encrypted value.`,t),this.name=`NotEntitledError`,this.encryptedValue=e.encryptedValue,this.contractAddress=e.contractAddress,this.account=e.account}},R=class extends p{constructor(e,t){super(c.DelegationSelfNotAllowed,e,t),this.name=`DelegationSelfNotAllowedError`}},Ft=class extends p{constructor(e,t){super(c.DelegationCooldown,e,t),this.name=`DelegationCooldownError`}},z=class extends p{constructor(e,t){super(c.DelegationNotFound,e,t),this.name=`DelegationNotFoundError`}},B=class extends p{constructor(e,t){super(c.DelegationExpired,e,t),this.name=`DelegationExpiredError`}},V=class extends p{constructor(e,t){super(c.DelegationExpiryUnchanged,e,t),this.name=`DelegationExpiryUnchangedError`}},H=class extends p{constructor(e,t){super(c.DelegationDelegateEqualsContract,e,t),this.name=`DelegationDelegateEqualsContractError`}},It=class extends p{constructor(e,t){super(c.DelegationContractIsSelf,e,t),this.name=`DelegationContractIsSelfError`}},Lt=class extends p{constructor(e,t){super(c.AclPaused,e,t),this.name=`AclPausedError`}},U=class extends p{constructor(e,t){super(c.DelegationExpirationTooSoon,e,t),this.name=`DelegationExpirationTooSoonError`}},W=class extends p{constructor(e,t){super(c.DelegationNotPropagated,e,t),this.name=`DelegationNotPropagatedError`}};function Rt(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 zt=class extends p{unwrapTxHash;unwrapRequestId;constructor(e,t,n){super(c.UnshieldAlreadyFinalized,e,n),this.name=`UnshieldAlreadyFinalizedError`,this.unwrapTxHash=t.unwrapTxHash,this.unwrapRequestId=t.unwrapRequestId}};const Bt=`InvalidUnwrapRequest`,Vt=kt(jt(`${Bt}(bytes32)`)).slice(0,10);function Ht(e){for(let t=e;t instanceof Error;t=t.cause)if(Rt(t)===Bt||t.message.includes(Bt)||t.message.includes(Vt))return!0;return!1}const Ut=[O,de,u,W,se,Pe,Pt,j,_e,T];function G(e,n,c={}){if(Ut.some(t=>e instanceof t))return e;let d=e instanceof Error?e.message:n;if(e instanceof Error&&f(e.message))return new _e(e.message,{cause:e});if(t(e))return new T(`The permit's KMS context has been revoked on-chain, so the permit is no longer usable. The SDK evicts the permit and re-grants automatically; if this error surfaced, the retry failed the same way. The on-chain validity check is cached for up to 15 minutes, so a just-revoked context can keep failing across that window. Retry after the window; the SDK re-runs the recovery on the next decrypt, no manual cleanup is needed.`,{cause:e});if(e instanceof Error&&l(e.message))return c.isDelegated?new W(`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 Pt({encryptedValue:r(e.message)??``,contractAddress:c.contractAddress??``,account:c.account??``},{cause:e});if(a(e))return new j(d,{cause:e,retryAfter:i(e)});let p=m(e);return p===void 0&&ee(e)?new j(d,{cause:e,retryAfter:i(e)}):p===400?new de(e instanceof Error?e.message:`No ciphertext for this account`,{cause:e}):c.isDelegated&&p===500?new W(`Delegated decryption failed with a server error. This is most commonly caused by the delegation not having propagated to the gateway yet. Cross-chain sync usually completes within ~10 blocks (a few seconds) and the SDK retries across that window; seeing this means it did not sync in time — retry shortly. If the error persists, the gateway or relayer may be experiencing an unrelated issue.`,{cause:e}):s(e)||p!==void 0?new u(d,p,{cause:e,retryAfter:i(e),retryable:o(e)||void 0}):new O(n,{cause:e})}function Wt(e,t){if(e instanceof p)return e;let n=m(e),r=o(e);return n!==void 0||s(e)?new u(e instanceof Error?e.message:t,n,{cause:e,retryAfter:i(e),retryable:r||void 0}):new D(t,{cause:e})}const Gt=[{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 Kt(e,t,n,r=`0x`){return{address:e,abi:Gt,functionName:`transferAndCall`,args:[t,n,r]}}const K=[{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 qt(e,t,n,r){return{address:e,abi:K,functionName:`delegateForUserDecryption`,args:[t,n,r]}}function Jt(e,t,n){return{address:e,abi:K,functionName:`revokeDelegationForUserDecryption`,args:[t,n]}}function Yt(e,t,n,r){return{address:e,abi:K,functionName:`getUserDecryptionDelegationExpirationDate`,args:[t,n,r]}}function Xt(e,t,n,r,i){return{address:e,abi:K,functionName:`isHandleDelegatedForUserDecryption`,args:[t,n,r,i]}}const Zt=2n**64n-1n;function Qt(e){return st(e.signer,e.provider,e)}function $t(e){return e.startsWith(`0x`)?e:`0x${e}`}function q(e){return kt(jt(e))}const J={ConfidentialTransfer:q(`ConfidentialTransfer(address,address,bytes32)`),Wrap:q(`Wrap(address,uint256,bytes32)`),UnwrapRequested:q(`UnwrapRequested(address,bytes32,bytes32)`),UnwrapFinalized:q(`UnwrapFinalized(address,bytes32,bytes32,uint64)`)};function Y(e){return I($t(e.slice(-40)))}function en(e){return e}function tn(e,t){let n=2+t*64,r=e.slice(n,n+64);return r.length===64?r:r.padEnd(64,`0`)}function nn(e,t){return I($t(tn(e,t).slice(-40)))}function X(e,t){return BigInt(`0x`+tn(e,t))}function rn(e,t){return $t(tn(e,t))}function an(e){return e.topics[0]!==J.ConfidentialTransfer||e.topics.length<4?null:{eventName:`ConfidentialTransfer`,from:Y(e.topics[1]),to:Y(e.topics[2]),encryptedAmount:en(e.topics[3])}}function on(e){return e.topics[0]!==J.Wrap||e.topics.length<2?null:{eventName:`Wrap`,to:Y(e.topics[1]),roundedAmount:X(e.data,0),encryptedWrappedAmount:rn(e.data,1)}}function sn(e){return e.topics[0]!==J.UnwrapRequested||e.topics.length<3?null:{eventName:`UnwrapRequested`,receiver:Y(e.topics[1]),unwrapRequestId:en(e.topics[2]),encryptedAmount:rn(e.data,0)}}function cn(e){return e.topics[0]!==J.UnwrapFinalized||e.topics.length<3?null:{eventName:`UnwrapFinalized`,receiver:Y(e.topics[1]),unwrapRequestId:en(e.topics[2]),encryptedAmount:rn(e.data,0),cleartextAmount:X(e.data,1)}}function ln(e){return an(e)??on(e)??sn(e)??cn(e)}function un(e){let t=[];for(let n of e){let e=ln(n);e&&t.push(e)}return t}function dn(e){for(let t of e){let e=sn(t);if(e)return e}return null}function fn(e){for(let t of e){let e=on(t);if(e)return e}return null}const pn=[J.ConfidentialTransfer,J.Wrap,J.UnwrapRequested,J.UnwrapFinalized],Z={DelegatedForUserDecryption:q(`DelegatedForUserDecryption(address,address,address,uint64,uint64,uint64)`),RevokedDelegationForUserDecryption:q(`RevokedDelegationForUserDecryption(address,address,address,uint64,uint64)`)};function Q(e){return e.topics[0]!==Z.DelegatedForUserDecryption||e.topics.length<3?null:{eventName:`DelegatedForUserDecryption`,delegator:Y(e.topics[1]),delegate:Y(e.topics[2]),contractAddress:nn(e.data,0),delegationCounter:X(e.data,1),oldExpirationDate:X(e.data,2),newExpirationDate:X(e.data,3)}}function mn(e){return e.topics[0]!==Z.RevokedDelegationForUserDecryption||e.topics.length<3?null:{eventName:`RevokedDelegationForUserDecryption`,delegator:Y(e.topics[1]),delegate:Y(e.topics[2]),contractAddress:nn(e.data,0),delegationCounter:X(e.data,1),oldExpirationDate:X(e.data,2)}}function hn(e){return Q(e)??mn(e)}function gn(e){let t=[];for(let n of e){let e=hn(n);e&&t.push(e)}return t}function _n(e){for(let t of e){let e=Q(t);if(e)return e}return null}function vn(e){for(let t of e){let e=mn(t);if(e)return e}return null}const yn=[Z.DelegatedForUserDecryption,Z.RevokedDelegationForUserDecryption];var bn=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 _(this.#r,e)}#s(e,t){throw this.#a({type:E.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 Ue(`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 Ue(`grantDelegationPermit`,this.#e,this.#t)}catch(e){this.#s(`grantDelegationPermit`,e)}await n.grantPermit(t,e)}async hasPermit(e){return this.#r?this.#r.hasPermit(e):!1}async hasDelegationPermit(e,t){return this.#r?this.#r.hasPermit(t,e):!1}async warmTransportKeyPair(){let e=this.#r;if(!e)return;let t=this.#e?.walletAccount.getSnapshot();t&&await e.warmTransportKeyPair(t.address)}async registerPermit(e,t){let n;try{n=this.#o(`registerPermit`)}catch(e){this.#s(`registerPermit`,e)}await n.registerPermit(e,t),await this.#c(e.signerAddress)}async revokePermits(e){let t=this.#o(`revokePermits`),n=I((await M(`revokePermits`,this.#e,this.#t)).address);try{await t.revokePermits(e)}finally{await this.#c(n)}}async clear(){let e=this.#o(`clear`),t=I((await M(`clear`,this.#e,this.#t)).address);try{await e.clearCredentials()}finally{await this.#c(t)}}async#c(e){await x(`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)}},xn=class{#e;#t;#n;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.delegationService}#r(e){return _(this.#e,e)}async delegateDecryption({contractAddress:e,delegateAddress:t,expirationDate:n}){let r=this.#r(`delegateDecryption`),i=await M(`delegateDecryption`,this.#e,this.#t);return this.#n.delegateDecryption(r,{contractAddress:e,delegateAddress:t,delegatorAddress:i.address,expirationDate:n})}async revokeDelegation({contractAddress:e,delegateAddress:t}){let n=this.#r(`revokeDelegation`),r=await M(`revokeDelegation`,this.#e,this.#t);return this.#n.revokeDelegation(n,{contractAddress:e,delegateAddress:t,delegatorAddress:r.address})}async isActive(e){return this.#n.isDelegated(e)}async getExpiry(e){return this.#n.getDelegationExpiry(e)}async getStatus(e){return this.#n.getStatus(e)}},Sn=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 _(this.#r,e)}async decryptValues(e,t){let n=this.#i(`decryptValues`),r=await M(`decryptValues`,this.#e,this.#t);return n.decryptValues(e,r.address,t)}async delegatedDecryptValues(e,t,n=t,r){let i=this.#i(`delegatedDecryptValues`),a=await M(`delegatedDecryptValues`,this.#e,this.#t);return i.delegatedDecryptValues(e,t,a.address,n,r)}async decryptPublicValues(e,t){if(e.length===0)return{clearValues:{},decryptionProof:`0x`,abiEncodedClearValues:`0x`};try{let n=await this.#n.relayer.decryptPublicValuesWithSignatures({encryptedValues:e,options:t}),r={};return n.checkSignaturesArgs.handlesList.forEach((e,t)=>{Dt(n.clearValues[t],`result.clearValues[${t}]`),r[e]=n.clearValues[t].value}),{clearValues:r,abiEncodedClearValues:n.checkSignaturesArgs.abiEncodedCleartexts,decryptionProof:n.checkSignaturesArgs.decryptionProof}}catch(e){throw G(e,`Public decryption failed`)}}async delegatedBatchDecryptValues({encryptedInputs:e,delegatorAddress:t,accountAddress:n=t,maxConcurrency:r,waitForPropagation:i}){let a=this.#i(`delegatedBatchDecryptValues`),o=await M(`delegatedBatchDecryptValues`,this.#e,this.#t);return a.delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:o.address,accountAddress:n,maxConcurrency:r,waitForPropagation:i})}},Cn=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)}},wn=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 Tn=new wn;function $(e){return`zama:pending-unshield:${gt(e)}`}const En=L.union([L.pipe(P,L.transform(e=>({unwrapTxHash:e}))),L.pipe(L.object({version:L.literal(1),unwrapTxHash:P,unwrapRequestId:L.optional(P)}),L.transform(({unwrapTxHash:e,unwrapRequestId:t})=>({unwrapTxHash:e,unwrapRequestId:t})))]);async function Dn(e,t,n,r){if(r===void 0){await e.set($(t),n);return}await e.set($(t),{version:1,unwrapTxHash:n,unwrapRequestId:r})}async function On(e,t){let n=$(t),r=await e.get(n);if(r==null)return null;let i=En.safeParse(r);return i.success?i.data:(await e.delete(n),null)}async function kn(e,t){await e.delete($(t))}var An=class extends $e{#e;#t=null;#n=null;#r(e){try{return Dt(this.sdk.signer,`WrappedToken.sdk.signer`),this.sdk.signer}catch(t){throw new he(e,{cause:t})}}async underlying(){return this.#u()}async isPayable(){if(this.#n!==null)return this.#n;try{let e=await this.#u();this.#n=await this.sdk.provider.readContract(Ne(e))}catch{this.#n=!1}return this.#n}async allowance(e){let t=await this.#u();return this.sdk.provider.readContract(w(t,I(e),this.address))}async shield(t,n){let r=await M(`shield`,this.sdk.signer,this.sdk.provider),i=await this.isPayable(),a=await this.#u(),o=I(r.address),s;try{s=await this.sdk.provider.readContract(S(a,o))}catch(t){throw t instanceof p?t:new A(`Could not read ERC-20 balance for shield validation (token: ${a})`,{cause:e(t)})}if(s<t)throw new qe(`Insufficient ERC-20 balance: requested ${t}, available ${s} (token: ${a})`,{requested:t,available:s,token:a});return i?this.#i(t,a,o,n):this.#a(t,o,n)}async#i(e,t,n,r){this.#r(`shield`);let i=r?.to?I(r.to):n,a=i===n?`0x`:i;return this.submitTransaction({operation:`shield:transferAndCall`,config:Kt(t,this.address,e,a),onSubmitted:r?.onShieldSubmitted})}async wrap(t,n){this.#r(`wrap`);let r=await M(`wrap`,this.sdk.signer,this.sdk.provider),i=await this.#u(),a=I(r.address),o;try{o=await this.sdk.provider.readContract(S(i,a))}catch(t){throw t instanceof p?t:new A(`Could not read ERC-20 balance for wrap validation (token: ${i})`,{cause:e(t)})}if(o<t)throw new qe(`Insufficient ERC-20 balance: requested ${t}, available ${o} (token: ${i})`,{requested:t,available:o,token:i});let s;try{s=await this.sdk.provider.readContract(w(i,a,this.address))}catch(t){throw t instanceof p?t:new A(`Could not read ERC-20 allowance for wrap validation (token: ${i})`,{cause:e(t)})}if(s<t)throw new We(`Insufficient allowance for wrap: requested ${t}, approved ${s}. Call approveUnderlying() first (token: ${i}).`,{requested:t,available:s,token:i});let c=n?.to?I(n.to):a;return this.submitTransaction({operation:`wrap`,config:y(this.address,c,t),onSubmitted:n?.onWrapSubmitted})}async#a(e,t,n){this.#r(`shield`);let r=n?.approvalStrategy??`exact`;r!==`skip`&&await this.#f(e,r===`max`,n);let i=n?.to?I(n.to):t;return this.submitTransaction({operation:`shield:approveAndWrap`,config:y(this.address,i,e),onSubmitted:n?.onShieldSubmitted})}async approveUnderlying(e){this.#r(`approveUnderlying`);let t=await M(`approveUnderlying`,this.sdk.signer,this.sdk.provider),n=await this.#u(),r=I(t.address),i=e??2n**256n-1n;return i>0n&&await this.sdk.provider.readContract(w(n,r,this.address))>0n&&await this.submitTransaction({operation:`approveUnderlying:reset`,config:C(n,this.address,0n)}),this.submitTransaction({operation:`approveUnderlying`,config:C(n,this.address,i)})}async unshield(e,t){let{skipBalanceCheck:n=!1,onUnwrapSubmitted:r,onFinalizing:i,onFinalizeSubmitted:a}=t??{};n||await this.assertConfidentialBalance(e);let o={onFinalizing:i,onFinalizeSubmitted:a},s=crypto.randomUUID(),c=await this.unwrap(e);return x(`unshield: onUnwrapSubmitted`,()=>r?.(c.txHash),this.sdk.logger),this.#d(c.unwrapRequestId,c.txHash,s,o)}async unshieldAll(e){let t=crypto.randomUUID(),n=await this.unwrapAll();return x(`unshieldAll: onUnwrapSubmitted`,()=>e?.onUnwrapSubmitted?.(n.txHash),this.sdk.logger),this.#d(n.unwrapRequestId,n.txHash,t,e)}async resumeUnshield(e,t){let n;try{n=await this.sdk.provider.waitForTransactionReceipt(e)}catch(e){throw e instanceof p?e:new v(`Failed to get unwrap receipt`,{cause:e})}let r=this.#o(n.logs);if(await this.#s(r))throw await this.#l(`resumeUnshield`),new zt(`Nothing to resume: the unwrap request was already finalized on-chain and the funds were delivered.`,{unwrapTxHash:e,unwrapRequestId:r});return this.#d(r,e,crypto.randomUUID(),t)}async getPendingUnshield(){let e=await On(this.sdk.storage,this.address);return e?await this.#c(e)?(await this.#l(`getPendingUnshield`),null):e.unwrapTxHash:null}async unwrap(e){this.#r(`unwrap`);let t=I((await M(`unwrap`,this.sdk.signer,this.sdk.provider)).address),{encryptedValues:n,inputProof:r}=await this.sdk.encrypt({values:[{value:e,type:`euint64`}],contractAddress:this.address,userAddress:t}),[i]=n;if(!i)throw new D(`Encryption returned no encrypted values`);let a=await this.submitTransaction({operation:`unwrap`,config:ue(this.address,t,t,i,r)});return{...a,unwrapRequestId:this.#o(a.receipt.logs)}}async unwrapAll(){this.#r(`unwrapAll`);let e=I((await M(`unwrapAll`,this.sdk.signer,this.sdk.provider)).address),t=await this.readConfidentialBalanceOf(e);if(k(t))throw new O(`Cannot unshield: balance is zero`);let n=await this.submitTransaction({operation:`unwrapAll`,config:ie(this.address,e,e,t)});return{...n,unwrapRequestId:this.#o(n.receipt.logs)}}async finalizeUnwrap(e){this.#r(`finalizeUnwrap`),await Ue(`finalizeUnwrap`,this.sdk.signer,this.sdk.provider);let t=await this.sdk.decryption.decryptPublicValues([e]),n=t.clearValues[e];return Ot(n,`finalizeUnwrap: clearValue`),this.submitTransaction({operation:`finalizeUnwrap`,config:b(this.address,e,n,t.decryptionProof)})}#o(e){let t=dn(e.filter(e=>e.address===void 0||I(e.address)===this.address));if(!t)throw new v(`No UnwrapRequested event from this wrapper found in the unwrap receipt`);return t.unwrapRequestId}async#s(e){try{return await this.sdk.provider.readContract(oe(this.address,e))===Mt}catch{return!1}}async#c(e){let t=e.unwrapRequestId;if(t===void 0)try{let n=await this.sdk.provider.waitForTransactionReceipt(e.unwrapTxHash);t=this.#o(n.logs)}catch{return!1}return this.#s(t)}async#l(e){await x(`${e}: clearPendingUnshield`,()=>kn(this.sdk.storage,this.address),this.sdk.logger)}async#u(){return this.#e===void 0?(this.#t||=this.sdk.provider.readContract(le(this.address)).then(e=>(this.#e=e,this.#t=null,e)).catch(e=>{throw this.#t=null,e}),this.#t):this.#e}async#d(e,t,n,r){this.emit({type:E.UnshieldPhase1Submitted,txHash:t,operationId:n}),await x(`unshield: savePendingUnshield`,()=>Dn(this.sdk.storage,this.address,t,e),this.sdk.logger),this.emit({type:E.UnshieldPhase2Started,operationId:n}),x(`unshield: onFinalizing`,()=>r?.onFinalizing?.(),this.sdk.logger);let i;try{i=await this.finalizeUnwrap(e)}catch(n){throw Ht(n)?(await this.#l(`unshield`),new zt(`The unwrap request was finalized concurrently — the funds were already delivered.`,{unwrapTxHash:t,unwrapRequestId:e},{cause:n})):n}return this.emit({type:E.UnshieldPhase2Submitted,txHash:i.txHash,operationId:n}),x(`unshield: onFinalizeSubmitted`,()=>r?.onFinalizeSubmitted?.(i.txHash),this.sdk.logger),await this.#l(`unshield`),i}async#f(e,t,n){this.#r(`approveUnderlying`);let r=await this.#u(),i=I((await M(`approveUnderlying`,this.sdk.signer,this.sdk.provider)).address),a=await this.sdk.provider.readContract(w(r,i,this.address));if(a>=e)return;a>0n&&await this.submitTransaction({operation:`approveUnderlying:reset`,config:C(r,this.address,0n)});let o=t?2n**256n-1n:e;await this.submitTransaction({operation:`approveUnderlying`,config:C(r,this.address,o),onSubmitted:n?.onApprovalSubmitted})}};const jn=L.union([L.bigint(),L.boolean(),N]),Mn=L.array(L.string());var Nn=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=jn.safeParse(i);return a.success?a.data:(await this.delete(e,t,n),null)}catch(e){return this.#t.warn(`CachingService.get failed`,{error:e}),null}}async set(e,t,n,r){try{let i=this.#c(e,t,n);await this.#e.set(i,r),this.#i=this.#i.then(()=>this.#u(i).catch(e=>{this.#t.warn(`CachingService index write failed`,{error:e})})),await this.#i}catch(e){this.#t.warn(`CachingService.set failed`,{error:e})}}async delete(e,t,n){let r=this.#c(e,t,n);this.#i=this.#i.then(()=>this.#a(r).catch(e=>{this.#t.warn(`CachingService.delete failed`,{error:e})})),await this.#i}async clearForRequester(e){this.#i=this.#i.then(()=>this.#o(e).catch(e=>{this.#t.warn(`CachingService.clearForRequester failed`,{error:e})})),await this.#i}async clearAll(){this.#i=this.#i.then(()=>this.#s().catch(e=>{this.#t.warn(`CachingService.clearAll failed`,{error:e})})),await this.#i}async#a(e){await this.#e.delete(e).catch(()=>{});let t=await this.#l(),n=t.filter(t=>t!==e);n.length!==t.length&&await this.#e.set(this.#r,n)}async#o(e){let t=I(e),n=`${this.#n}:${t}:`,r=await this.#l(),i=[],a=[];for(let e of r)e.startsWith(n)?i.push(e):a.push(e);await Promise.all(i.map(e=>this.#e.delete(e).catch(()=>{}))),await this.#e.set(this.#r,a)}async#s(){let e=await this.#l();await Promise.all(e.map(e=>this.#e.delete(e).catch(()=>{}))),await this.#e.delete(this.#r)}#c(e,t,n){return`${this.#n}:${I(e)}:${I(t)}:${n.toLowerCase()}`}async#l(){let e=await this.#e.get(this.#r);if(e===null)return[];let t=Mn.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 Pn(e,t){let n=Fn(e,t);if(!n)throw new O(`No permit covers contract ${t} after allow()`);return{privateKey:e.keypair.privateKey,publicKey:e.keypair.publicKey,serializedPermit:n.serializedPermit}}function Fn(e,t){let n=gt(t);return e.permissions.find(e=>e.contractAddresses.includes(n))}const In=e=>new Promise(t=>setTimeout(t,e));var Ln=class{#e;#t;#n;#r;#i;constructor({cache:e,credentialService:t,delegationService:n,router:r,emitEvent:i}){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i}async decryptValues(e,t,n){let r=I(t);return this.#s(e,{requesterAddress:r,errorMessage:`Failed to decrypt encrypted values`},n)}async delegatedDecryptValues(e,t,n,r,i){let a=I(t),o=I(n),s={spent:!1};return this.#a(i?.waitForPropagation??!0,()=>this.#s(e,{requesterAddress:I(r),delegator:a,validate:e=>this.#m(e,{delegatorAddress:a,delegateAddress:o}),errorMessage:`Failed to decrypt delegated encrypted values`},void 0,s))}async#a(e,t){let n;for(let r=0;r<16;r++)try{return await t()}catch(t){if(n=t,!(r<15&&e&&t instanceof W))throw t;await In(2e3)}throw n}async delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:n,accountAddress:r,maxConcurrency:i=5,waitForPropagation:a=!0}){let o=e.map(e=>({encryptedValue:e.encryptedValue,contractAddress:I(e.contractAddress)}));if(o.length===0)return{items:o};let s=I(r);try{let e=await this.delegatedDecryptValues(o.map(({encryptedValue:e,contractAddress:t})=>({encryptedValue:e,contractAddress:t})),t,n,s,{waitForPropagation:a});for(let t of o)this.#d(t,e);return{items:o}}catch(e){if(Ke(e))throw e;if(o.length===1){let[n=this.#p()]=o;return n.error=this.#f(e,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:n.contractAddress,account:I(t)}),{items:o}}}let c=!1,l;if(await Ze(o.map(e=>async()=>{if(!c)try{let r=await this.delegatedDecryptValues([{encryptedValue:e.encryptedValue,contractAddress:e.contractAddress}],t,n,s,{waitForPropagation:!1});this.#d(e,r)}catch(n){if(Ke(n)){c=!0,l??=n;return}e.error=this.#f(n,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:e.contractAddress,account:I(t)})}}),i),l!==void 0)throw l;return{items:o}}async#o(e,t,n,r){let i=Pn(e,t),a;try{a=await this.#r.relayer.parseTransportKeyPair({publicKey:i.publicKey,privateKey:i.privateKey,tkmsVersion:e.keypair.tkmsVersion})}catch(e){throw e instanceof Error&&f(e.message)&&await this.#t.evictTransportKeyPair(),e}let o=await this.#r.relayer.parseSignedDecryptionPermit({transportKeyPair:a,serializedPermit:i.serializedPermit});return this.#r.relayer.decryptValues({transportKeyPair:a,signedPermit:o,encryptedValues:n,contractAddress:t,options:r})}async#s(t,n,r,i={spent:!1}){if(t.length===0)return{};let a=t.map(e=>({encryptedValue:e.encryptedValue,contractAddress:I(e.contractAddress)})),o={},s=[];for(let e of a)k(e.encryptedValue)?o[e.encryptedValue]=0n:s.push(e);if(s.length===0)return o;let c=Array.from(new Set(a.map(e=>e.contractAddress))),l=Array.from(new Set(s.map(e=>e.contractAddress)));if(n.validate)try{await n.validate(l)}catch(e){throw ee(e)?this.#u(e,`the delegation pre-check`):e}let u=[];for(let e of s){let t=await this.#e.get(n.requesterAddress,e.contractAddress,e.encryptedValue);t===null?u.push(e):o[e.encryptedValue]=t}if(u.length===0)return o;let d=await this.#t.grantPermit(c,n.delegator),f=new Map;for(let e of u){let t=f.get(e.contractAddress);t?t.push(e.encryptedValue):f.set(e.contractAddress,[e.encryptedValue])}let m=[];for(let[e,t]of f)for(let n of Qe(t))m.push({contractAddress:e,encryptedValues:n});let h=Date.now(),g=u.map(e=>e.encryptedValue);try{this.#i({type:E.DecryptStart,encryptedValues:g});try{await this.#c(n,d,m,o,r)}catch(e){if(!(e instanceof T)||i.spent)throw e;let t=d.permissions.map(e=>e.serializedPermit.signature);i.spent=!0;try{d=await this.#t.recoverPermits(c,n.delegator,t)}catch(e){throw e instanceof Pe?new T(`The permit's KMS context has been revoked on-chain and the automatic re-grant failed, so the decrypt cannot proceed. Establish a new permit for this scope and retry.`,{cause:e}):e}await this.#c(n,d,m.filter(({encryptedValues:e})=>e.some(e=>o[e]===void 0)),o,r)}let e={};for(let t of g){let n=o[t];n!==void 0&&(e[t]=n)}return this.#i({type:E.DecryptEnd,durationMs:Date.now()-h,encryptedValues:g,result:e}),o}catch(t){let r=t instanceof p&&t.cause instanceof Error?t.cause:t;throw this.#i({type:E.DecryptError,error:e(r),durationMs:Date.now()-h,encryptedValues:g}),G(t,n.errorMessage,{isDelegated:n.delegator!==void 0})}}async#c(e,t,n,r,i){let a=(await Ze(n.map(({contractAddress:n,encryptedValues:a})=>async()=>{try{await this.#l(e,t,n,a,r,i);return}catch(e){return e}}),5)).filter(e=>e!==void 0);if(a.length>0)throw a.find(e=>e instanceof T)??a[0]}async#l(e,t,n,r,i,a){let o;try{o=await this.#o(t,n,r,a)}catch(t){throw G(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 O(`${e.errorMessage}: relayer returned no clear value for ${s.length} of ${r.length} handle(s) on ${n}`,{cause:AggregateError(s.map(e=>new O(`No clear value for handle ${e} on ${n}`)),`${s.length} handle(s) missing a clear value on ${n}`)})}#u(e,t){return new j(`RPC provider rate-limited ${t}; retry with backoff.`,{cause:e,retryAfter:i(e)})}#d(e,t){let n=t[e.encryptedValue];if(n===void 0){e.error=new O(`Batch delegated decryption returned no value for encrypted value ${e.encryptedValue} on contract ${e.contractAddress}`);return}e.value=n}#f(e,t,n){return e instanceof p?e:G(e,t,n)}#p(){throw new O(`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 Rn={AlreadyDelegatedOrRevokedInSameBlock:e=>new Ft(`Only one delegate/revoke per (delegator, delegate, contract) per block. Wait for the next block before retrying.`,{cause:e}),SenderCannotBeContractAddress:e=>new It(`The contract address cannot be the caller address.`,{cause:e}),EnforcedPause:e=>new Lt(`The ACL contract is paused. Delegation operations are temporarily disabled.`,{cause:e}),SenderCannotBeDelegate:e=>new R(`Cannot delegate to yourself (delegate === msg.sender).`,{cause:e}),DelegateCannotBeContractAddress:e=>new H(`Delegate address cannot be the same as the contract address.`,{cause:e}),ExpirationDateBeforeOneHour:e=>new U(`Expiration date must be at least 1 hour in the future.`,{cause:e}),ExpirationDateAlreadySetToSameValue:e=>new V(`The new expiration date is the same as the current one.`,{cause:e}),NotDelegatedYet:e=>new z(`Cannot revoke: no active delegation exists.`,{cause:e})};function zn(e){return Object.hasOwn(Rn,e)}function Bn(e,t){let n=Rt(e);if(n&&zn(n))return Rn[n](t);let r=e instanceof Error?e.message:String(e);for(let[e,n]of Object.entries(Rn))if(r.includes(e))return n(t);return null}var Vn=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 U(`Expiration date must be at least 1 hour in the future`);let a=I(t),o=I(n),s=I(r);if(o===s)throw new R(`Cannot delegate to yourself (delegate === msg.sender).`);if(o===a)throw new H(`Delegate address cannot be the same as the contract address (${a}).`);let c=this.#e.relayer.chain.aclContractAddress,l=i?BigInt(Math.floor(i.getTime()/1e3)):Zt,u;try{u=await this.getDelegationExpiry({contractAddress:a,delegatorAddress:s,delegateAddress:o})}catch(e){this.#r.warn(`delegateDecryption: pre-flight expiry check failed`,{error:e}),u=-1n}if(u===l)throw new V(`The new expiration date (${l}) is the same as the current one. No on-chain change needed.`);return this.#i({operation:`delegateDecryption`,signer:e,contractAddress:a,config:qt(c,o,a,l)})}async revokeDelegation(e,{contractAddress:t,delegateAddress:n,delegatorAddress:r}){let i=I(t),a=I(n),o=I(r),s=this.#e.relayer.chain.aclContractAddress,c;try{c=await this.getDelegationExpiry({contractAddress:i,delegatorAddress:o,delegateAddress:a})}catch(e){this.#r.warn(`revokeDelegation: pre-flight expiry check failed`,{error:e}),c=1n}if(c===0n)throw new z(`No active delegation found for delegate ${a} on contract ${i}.`);return this.#i({operation:`revokeDelegation`,signer:e,contractAddress:i,config:Jt(s,a,i)})}async isDelegated(e){return(await this.getStatus(e)).isActive}async getStatus(e){let t=await this.getDelegationExpiry(e);return t===0n?{isActive:!1,expiryTimestamp:t}:t===Zt?{isActive:!0,expiryTimestamp:t}:{isActive:t>await this.#t.getBlockTimestamp(),expiryTimestamp:t}}async getDelegationExpiry({contractAddress:e,delegatorAddress:t,delegateAddress:n}){let r=this.#e.relayer.chain.aclContractAddress;return this.#t.readContract(Yt(r,I(t),I(n),I(e)))}async#i({operation:e,signer:t,contractAddress:n,config:r}){try{return await Je({operation:e,signer:t,provider:this.#t,config:r,emit:e=>this.#n(e,n),logger:this.#r})}catch(e){throw this.#a(e),e}}#a(e){if(!(e instanceof v))return;let t=Bn(e.cause??e,e);if(t)throw t}async findInactiveDelegations(e,t,n){let r=new Map;return await Promise.all(e.map(async e=>{try{await this.assertDelegationActive(e,t,n)}catch(t){if(t instanceof z||t instanceof B){let n=I(e);r.set(n,t);return}throw t}})),r}async assertDelegationActive(e,t,n){let r=I(e),i=I(t),a=I(n),{isActive:o,expiryTimestamp:s}=await this.getStatus({contractAddress:r,delegatorAddress:i,delegateAddress:a});if(!o)throw s===0n?new z(`No active delegation from ${i} to ${a} for ${r}`):new B(`Delegation from ${i} to ${a} for ${r} has expired`)}},Hn=class{#e;#t;constructor({router:e,emitEvent:t}){this.#e=e,this.#t=t}async encryptValues(t,n){let r=Date.now(),i=I(t.contractAddress);try{this.#t({type:E.EncryptStart},i);let e=await this.#e.relayer.encryptValues({...t,options:n});return this.#t({type:E.EncryptEnd,durationMs:Date.now()-r},i),e}catch(t){throw this.#t({type:E.EncryptError,error:e(t),durationMs:Date.now()-r},i),Wt(t,`Encryption failed`)}}},Un=class{#e;#t;#n;#r;#i;#a=new Set;#o;constructor(e){this.#e=e.signer,this.#t=e.router,this.#n=e.cachingService,this.#r=e.credentialService,this.#i=e.logger,this.#e&&(this.#o=this.#e.walletAccount.subscribe(e=>{this.#s(e).catch(e=>{this.#i.warn(`wallet account handler failed`,{error:e})})}))}onWalletAccountChange(e){return this.#a.add(e),()=>{this.#a.delete(e)}}dispose(){this.#o?.(),this.#o=void 0,this.#a.clear()}async#s(e){let t=e.previous,n=e.next,r=n?.chainId;r!==void 0&&await x(`switch relayer chain`,()=>this.#t.switchChain(r),this.#i);let i=this.#r;i&&await x(`credential wallet account change`,()=>i.handleWalletAccountChange(t,n),this.#i),t&&await x(`clear decrypt cache`,()=>this.#n.clearForRequester(t.address),this.#i),await Promise.all(Array.from(this.#a,t=>x(`wallet account listener`,()=>t(e),this.#i)))}};const Wn=L.object({kind:L.literal(`ConfidentialTransfer`),from:N,token:N,to:N,amount:L.bigint()}),Gn=L.object({kind:L.literal(`ConfidentialTransferFrom`),from:N,token:N,owner:N,to:N,amount:L.bigint()}),Kn=L.object({kind:L.literal(`SetOperator`),from:N,token:N,operator:N,until:ft}),qn=L.object({kind:L.literal(`Unwrap`),from:N,token:N,to:N,amount:L.bigint()}),Jn=L.object({kind:L.literal(`UnwrapAll`),from:N,token:N,to:N}),Yn=L.object({kind:L.literal(`FinalizeUnwrap`),from:N,wrapper:N,unwrapRequestIdOrAmount:P}),Xn=L.object({kind:L.literal(`ApproveUnderlying`),from:N,underlying:N,spender:N,amount:L.bigint()}),Zn=L.object({kind:L.literal(`Wrap`),from:N,wrapper:N,to:N,amount:L.bigint()}),Qn=P.check(L.refine(e=>e===`0x`||At(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`)),$n=L.object({kind:L.literal(`TransferAndCall`),from:N,underlying:N,wrapper:N,amount:L.bigint(),recipientData:L.optional(Qn)}),er=L.object({kind:L.literal(`DelegateDecryption`),from:N,contractAddress:N,delegateAddress:N,expirationDate:L.optional(L.date())}),tr=L.object({kind:L.literal(`RevokeDelegation`),from:N,contractAddress:N,delegateAddress:N});L.discriminatedUnion(`kind`,[Wn,Gn,Kn,qn,Jn,Yn,Xn,Zn,$n,er,tr]);const nr=L.strictObject({maxFeePerGas:L.bigint(),maxPriorityFeePerGas:L.bigint()}),rr=L.object({nonce:L.optional(L.int().check(L.nonnegative())),gasLimit:L.optional(L.bigint()),fees:L.optional(nr)}),ir=L.object({address:N,abi:L.array(L.unknown()),functionName:L.string(),args:L.array(L.unknown()),value:L.optional(L.bigint()),gas:L.optional(L.bigint())}),ar=L.extend(rr,{from:N,calldata:ir});var or=class{#e;#t;#n;constructor(e){this.#e=e.provider,this.#t=e.router,this.#n=e.encryption}async prepare(e,t){t&&=F(rr,t);let n=await this.#e.getChainId(),r=this.#t.chain.id;if(n!==r)throw new h(`Offline.prepare: provider is on chain ${n} but the SDK is configured for chain ${r}. The prepared transaction's contract addresses and encrypted inputs are bound to chain ${r} — point the provider at the same chain.`);let i=F(ar,{calldata:await this.#r(e),from:e.from,nonce:t?.nonce,gasLimit:t?.gasLimit,fees:t?.fees}),a=await this.#e.prepareTransaction(i);return{kind:e.kind,unsignedTx:a,from:i.from}}async#r(e){switch(e.kind){case`ConfidentialTransfer`:return this.#i(e);case`ConfidentialTransferFrom`:return this.#a(e);case`SetOperator`:return this.#o(e);case`Unwrap`:return this.#s(e);case`UnwrapAll`:return this.#c(e);case`FinalizeUnwrap`:return this.#l(e);case`ApproveUnderlying`:return this.#u(e);case`Wrap`:return this.#d(e);case`TransferAndCall`:return this.#f(e);case`DelegateDecryption`:return this.#p(e);case`RevokeDelegation`:return this.#m(e);default:throw new h(`OfflineService.prepare: unsupported transaction kind '${e.kind}'.`)}}async#i(e){e=F(Wn,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from}),r=t[0];if(!r)throw new D(`Encryption returned no handles for ConfidentialTransfer`);return pe(e.token,e.to,r,n)}async#a(e){e=F(Gn,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from}),r=t[0];if(!r)throw new D(`Encryption returned no handles for ConfidentialTransferFrom`);return re(e.token,e.owner,e.to,r,n)}#o(e){return e=F(Kn,e),ce(e.token,e.operator,e.until)}async#s(e){e=F(qn,e);let{encryptedValues:t,inputProof:n}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from}),r=t[0];if(!r)throw new D(`Encryption returned no handles for Unwrap`);return ue(e.token,e.from,e.to,r,n)}async#c(e){e=F(Jn,e);let t=await this.#e.readContract(fe(e.token,e.from));return ie(e.token,e.from,e.to,t)}async#l(e){e=F(Yn,e);let t=await this.#t.relayer.decryptPublicValuesWithSignatures({encryptedValues:[e.unwrapRequestIdOrAmount]}).catch(e=>{throw G(e,`Public decryption failed during FinalizeUnwrap`)}),n=t.clearValues[0]?.value;return Ot(n,`FinalizeUnwrap: decryptPublicValuesWithSignatures(handle).clearValue`),b(e.wrapper,e.unwrapRequestIdOrAmount,n,t.checkSignaturesArgs.decryptionProof)}#u(e){return e=F(Xn,e),C(e.underlying,e.spender,e.amount)}#d(e){return e=F(Zn,e),y(e.wrapper,e.to,e.amount)}#f(e){return e=F($n,e),Kt(e.underlying,e.wrapper,e.amount,e.recipientData)}#p(e){if(e=F(er,e),e.expirationDate&&e.expirationDate.getTime()<Date.now()+36e5)throw new U(`Expiration date must be at least 1 hour in the future`);if(e.delegateAddress===e.from)throw new R(`Cannot delegate to yourself (delegate === msg.sender).`);if(e.delegateAddress===e.contractAddress)throw new H(`Delegate address cannot be the same as the contract address (${e.contractAddress}).`);let t=e.expirationDate?BigInt(Math.floor(e.expirationDate.getTime()/1e3)):Zt;return qt(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress,t)}#m(e){return e=F(tr,e),Jt(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress)}};function sr(e){if(!(!Object.hasOwn(e,`transportKeyPairDerivationSecret`)||e.transportKeyPairDerivationSecret!==void 0))throw new h(`transportKeyPairDerivationSecret was passed as undefined, which usually means the environment variable it reads is unset (e.g. process.env.ZAMA_DERIVATION_SECRET). Supply the secret, or omit the option entirely to persist transport key pairs in cleartext on purpose.`)}function cr(e){if(e===void 0)return;let{importScripts:t}=globalThis;if(!(typeof window>`u`&&typeof document>`u`&&typeof t!=`function`))throw new h(`transportKeyPairDerivationSecret is supported in headless environments only (CLI tools, servers, agents). Remove the option: an environment with a platform keystore, or one that ships a bundle, must delegate at-rest security of the transport key pair to the storage backend.`)}function lr(e){if(e===void 0)return;let t=F(it,e);return new ct(typeof t==`string`?t:new Uint8Array(t))}var ur=class{#e;provider;signer;storage;registry;permits;delegations;decryption;offline;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;constructor(e,t={}){sr(t),cr(t.transportKeyPairDerivationSecret);let n=lr(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 Nn(e.storage,this.#i),this.#u=new Vn({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 dt({provider:this.provider,registryAddresses:r,registryTTL:e.registryTTL}),this.#n=r,this.#t=e.registryTTL,this.#l=new mt({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 Ln({cache:this.#a,credentialService:this.#l,delegationService:this.#u,router:e.router,emitEvent:this.emitEvent.bind(this)})),this.#s=new Hn({router:e.router,emitEvent:this.emitEvent.bind(this)}),this.#o=new Un({signer:e.signer,router:e.router,cachingService:this.#a,credentialService:this.#l,logger:this.#i}),this.#d=new or({provider:this.provider,router:e.router,encryption:this.#s,emitEvent:(e,t)=>this.emitEvent(e,t)}),this.permits=new bn({signer:this.signer,provider:this.provider,cachingService:this.#a,credentialService:this.#l,logger:this.#i,emitEvent:this.emitEvent.bind(this)}),this.delegations=new xn({signer:this.signer,provider:this.provider,delegationService:this.#u}),this.decryption=new Sn({signer:this.signer,provider:this.provider,router:e.router,decryptionService:this.#c}),this.offline=new Cn(this.#d,this.#l)}onWalletAccountChange(e){return this.#o.onWalletAccountChange(e)}get logger(){return this.#i}get relayer(){return this.#e.relayer}emitEvent(e,t){try{this.#r({...e,tokenAddress:t,timestamp:Date.now()})}catch(t){this.#i.warn(`${e.type} event listener silently failed`,{error:t})}}createWrappersRegistry(e){return new dt({provider:this.provider,registryAddresses:{...this.#n,...e},registryTTL:this.#t})}async encrypt(e,t){return this.#s.encryptValues(e,t)}createToken(e){return new $e(this,e)}createWrappedToken(e){return new An(this,e)}dispose(){this.#o.dispose(),this.#e.dispose()}terminate(){this.dispose(),this.signer?.dispose?.()}[Symbol.dispose](){this.terminate()}};export{yn as ACL_TOPICS,Lt as AclPausedError,Z as AclTopics,et as BalanceCheckUnavailableError,ht as BaseSigner,Ge as ChainMismatchError,wn as ChromeSessionStorage,h as ConfigurationError,Sn as Decryption,O as DecryptionFailedError,rt as DefaultRegistryAddresses,It as DelegationContractIsSelfError,Ft as DelegationCooldownError,H as DelegationDelegateEqualsContractError,U as DelegationExpirationTooSoonError,B as DelegationExpiredError,V as DelegationExpiryUnchangedError,z as DelegationNotFoundError,W as DelegationNotPropagatedError,R as DelegationSelfNotAllowedError,xn as Delegations,xe as ERC1363_INTERFACE_ID,A as ERC20ReadFailedError,Oe as ERC7984_INTERFACE_ID,ze as ERC7984_WRAPPER_INTERFACE_ID,He as EncryptOffloadUnavailableError,D as EncryptionFailedError,at as IndexedDBStorage,We as InsufficientAllowanceError,Xe as InsufficientConfidentialBalanceError,qe as InsufficientERC20BalanceError,_e as InvalidTransportKeyPairError,ve as KeyWrappingError,lt as MemoryStorage,ut as MutableWalletAccountStore,de as NoCiphertextError,Pt as NotEntitledError,Cn as Offline,bn as Permits,g as PreparedPermitChainMismatchError,Ce as PreparedPermitExpiredError,u as RelayerRequestFailedError,T as RevokedKmsContextError,j as RpcRateLimitError,he as SignerNotConfiguredError,ae as SignerRequiredError,Pe as SigningFailedError,se as SigningRejectedError,pn as TOKEN_TOPICS,$e as Token,J as Topics,v as TransactionRevertedError,je as TransportKeyPairChangedError,Ie as TransportKeyPairExpiredError,zt as UnshieldAlreadyFinalizedError,me as WalletAccountNotReadyError,ge as WalletNotConnectedError,An as WrappedToken,dt as WrappersRegistry,Ye as ZERO_ENCRYPTED_VALUE,p as ZamaError,c as ZamaErrorCode,ur as ZamaSDK,E as ZamaSDKEvents,w as allowanceContract,Tt as anvil,C as approveContract,S as balanceOfContract,xt as bscTestnet,Ct as chains,Tn as chromeSessionStorage,tt as cleartext,fe as confidentialBalanceOfContract,ne as confidentialTotalSupplyContract,pe as confidentialTransferContract,re as confidentialTransferFromContract,Qt as createConfig,pt as createWalletAccountStore,Be as decimalsContract,hn as decodeAclEvent,gn as decodeAclEvents,an as decodeConfidentialTransfer,Q as decodeDelegatedForUserDecryption,ln as decodeOnChainEvent,un as decodeOnChainEvents,mn as decodeRevokedDelegationForUserDecryption,cn as decodeUnwrapFinalized,sn as decodeUnwrapRequested,on as decodeWrap,qt as delegateForUserDecryptionContract,b as finalizeUnwrapContract,_n as findDelegatedForUserDecryption,vn as findRevokedDelegationForUserDecryption,dn as findUnwrapRequested,fn as findWrap,Re as getConfidentialTokenAddressContract,Yt as getDelegationExpiryContract,Ae as getTokenAddressContract,Fe as getTokenPairContract,Te as getTokenPairsContract,ye as getTokenPairsLengthContract,Me as getTokenPairsSliceContract,yt as hardhat,_t as hoodi,nt as indexedDBStorage,De as inferredTotalSupplyContract,St as ingenTestnet,Se as isConfidentialTokenContract,Le as isConfidentialTokenValidContract,we as isConfidentialWrapperContract,k as isEncryptedValueZero,Xt as isHandleDelegatedContract,te as isOperatorContract,n as isRetryable,wt as mainnet,Nt as matchZamaError,ot as memoryStorage,be as nameContract,vt as polygon,bt as polygonAmoy,Ee as rateContract,d as retryAfterSeconds,Jt as revokeDelegationContract,Et as sepolia,ce as setOperatorContract,ke as supportsInterfaceContract,Ve as symbolContract,Kt as transferAndCallContract,le as underlyingContract,ue as unwrapContract,ie as unwrapFromBalanceContract,oe as unwrapRequesterContract,y as wrapContract};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|