@zama-fhe/sdk 3.4.0-alpha.7 → 3.4.0-alpha.9

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.
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./relayer.cjs"),t=require("./wrappers-registry.cjs"),n=require("./token.cjs"),r=require("./cleartext.cjs"),i=require("./base-signer.cjs"),a=require("./chains.cjs");let o=require("viem"),s=require("zod/mini");function c(t,n){if(t instanceof e.r){let e=n[t.code];if(e)return e(t)}return n._?.(t)}var l=class extends e.r{constructor(t,n){super(e.i.TransportKeyPairExpired,t,n),this.name=`TransportKeyPairExpiredError`}},u=class extends e.r{constructor(t,n){super(e.i.InvalidTransportKeyPair,t,n),this.name=`InvalidTransportKeyPairError`}},d=class extends e.r{constructor(t,n){super(e.i.NoCiphertext,t,n),this.name=`NoCiphertextError`}},f=class extends e.r{encryptedValue;contractAddress;account;constructor(t,n){super(e.i.NotEntitled,`Account ${t.account} is not entitled to decrypt encrypted value ${t.encryptedValue} on contract ${t.contractAddress}. This is not a transient failure — the account needs an on-chain ACL grant before it can decrypt this encrypted value.`,n),this.name=`NotEntitledError`,this.encryptedValue=t.encryptedValue,this.contractAddress=t.contractAddress,this.account=t.account}},p=class extends e.r{constructor(t,n){super(e.i.DelegationSelfNotAllowed,t,n),this.name=`DelegationSelfNotAllowedError`}},m=class extends e.r{constructor(t,n){super(e.i.DelegationCooldown,t,n),this.name=`DelegationCooldownError`}},h=class extends e.r{constructor(t,n){super(e.i.DelegationNotFound,t,n),this.name=`DelegationNotFoundError`}},g=class extends e.r{constructor(t,n){super(e.i.DelegationExpired,t,n),this.name=`DelegationExpiredError`}},_=class extends e.r{constructor(t,n){super(e.i.DelegationExpiryUnchanged,t,n),this.name=`DelegationExpiryUnchangedError`}},v=class extends e.r{constructor(t,n){super(e.i.DelegationDelegateEqualsContract,t,n),this.name=`DelegationDelegateEqualsContractError`}},y=class extends e.r{constructor(t,n){super(e.i.DelegationContractIsSelf,t,n),this.name=`DelegationContractIsSelfError`}},b=class extends e.r{constructor(t,n){super(e.i.AclPaused,t,n),this.name=`AclPausedError`}},x=class extends e.r{constructor(t,n){super(e.i.DelegationExpirationTooSoon,t,n),this.name=`DelegationExpirationTooSoonError`}},S=class extends e.r{constructor(t,n){super(e.i.DelegationNotPropagated,t,n),this.name=`DelegationNotPropagatedError`}};const ee=[n.E,d,e.n,S,t.W,t.U,f,n.w];function C(t,r,i={}){if(ee.some(e=>t instanceof e))return t;let a=t instanceof Error?t.message:r;if(t instanceof Error&&e.d(t.message))return i.isDelegated?new S(`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:t}):new f({encryptedValue:e.h(t.message)??``,contractAddress:i.contractAddress??``,account:i.account??``},{cause:t});if(e.l(t))return new n.w(a,{cause:t,retryAfter:e.c(t)});let o=e.s(t);return o===void 0&&e.m(t)?new n.w(a,{cause:t,retryAfter:e.c(t)}):o===400?new d(t instanceof Error?t.message:`No ciphertext for this account`,{cause:t}):i.isDelegated&&o===500?new S(`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:t}):e.f(t)||o!==void 0?new e.n(a,o,{cause:t,retryAfter:e.c(t),retryable:e.p(t)||void 0}):new n.E(r,{cause:t})}function te(t,r){if(t instanceof e.r)return t;let i=e.s(t),a=e.p(t);return i!==void 0||e.f(t)?new e.n(t instanceof Error?t.message:r,i,{cause:t,retryAfter:e.c(t),retryable:a||void 0}):new n.D(r,{cause:t})}const ne=[{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 w(e,t,n,r=`0x`){return{address:e,abi:ne,functionName:`transferAndCall`,args:[t,n,r]}}function re(e){return i.i(e.signer,e.provider,e)}function T(e){return e.startsWith(`0x`)?e:`0x${e}`}var E=class{#e;#t;#n;#r;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.router,this.#r=e.decryptionService}#i(e){return t.H(this.#r,e)}async decryptValues(e,t){let r=this.#i(`decryptValues`),i=await n.u(`decryptValues`,this.#e,this.#t);return r.decryptValues(e,i.address,t)}async delegatedDecryptValues(e,t,r=t,i){let a=this.#i(`delegatedDecryptValues`),o=await n.u(`delegatedDecryptValues`,this.#e,this.#t);return a.delegatedDecryptValues(e,t,o.address,r,i)}async decryptPublicValues(e,t){if(e.length===0)return{clearValues:{},decryptionProof:`0x`,abiEncodedClearValues:`0x`};try{let r=await this.#n.relayer.decryptPublicValuesWithSignatures({encryptedValues:e,options:t}),i={};return r.checkSignaturesArgs.handlesList.forEach((e,t)=>{n.l(r.clearValues[t],`result.clearValues[${t}]`),i[e]=r.clearValues[t].value}),{clearValues:i,abiEncodedClearValues:r.checkSignaturesArgs.abiEncodedCleartexts,decryptionProof:r.checkSignaturesArgs.decryptionProof}}catch(e){throw C(e,`Public decryption failed`)}}async delegatedBatchDecryptValues({encryptedInputs:e,delegatorAddress:t,accountAddress:r=t,maxConcurrency:i,waitForPropagation:a}){let o=this.#i(`delegatedBatchDecryptValues`),s=await n.u(`delegatedBatchDecryptValues`,this.#e,this.#t);return o.delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:s.address,accountAddress:r,maxConcurrency:i,waitForPropagation:a})}},D=class{#e;#t;#n;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.delegationService}#r(e){return t.H(this.#e,e)}async delegateDecryption({contractAddress:e,delegateAddress:t,expirationDate:r}){let i=this.#r(`delegateDecryption`),a=await n.u(`delegateDecryption`,this.#e,this.#t);return this.#n.delegateDecryption(i,{contractAddress:e,delegateAddress:t,delegatorAddress:a.address,expirationDate:r})}async revokeDelegation({contractAddress:e,delegateAddress:t}){let r=this.#r(`revokeDelegation`),i=await n.u(`revokeDelegation`,this.#e,this.#t);return this.#n.revokeDelegation(r,{contractAddress:e,delegateAddress:t,delegatorAddress:i.address})}async isActive(e){return this.#n.isDelegated(e)}async getExpiry(e){return this.#n.getDelegationExpiry(e)}},O=class{#e;#t;#n;#r;#i;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.cachingService,this.#r=e.credentialService,this.#i=e.logger}#a(e){return t.H(this.#r,e)}async grantPermit(e){if(e.length===0)return;let t=this.#a(`grantPermit`);await n.d(`grantPermit`,this.#e,this.#t),await t.grantPermit(e)}async grantDelegationPermit(e,t){if(t.length===0)return;let r=this.#a(`grantDelegationPermit`);await n.d(`grantDelegationPermit`,this.#e,this.#t),await r.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 revokePermits(e){let r=this.#a(`revokePermits`),i=(0,o.getAddress)((await n.u(`revokePermits`,this.#e,this.#t)).address);try{await r.revokePermits(e)}finally{await t.L(`clear decrypt cache`,()=>this.#n.clearForRequester(i),this.#i)}}async clear(){let e=this.#a(`clear`),r=(0,o.getAddress)((await n.u(`clear`,this.#e,this.#t)).address);try{await e.clearCredentials()}finally{await t.L(`clear decrypt cache`,()=>this.#n.clearForRequester(r),this.#i)}}async revokeTransportKeyPair(e){await this.#a(`revokeTransportKeyPair`).revokeTransportKeyPair(e)}async warmTransportKeyPairScope(e){await this.#a(`warmTransportKeyPairScope`).warmTransportKeyPairScope(e)}};const ie=s.z.union([s.z.bigint(),s.z.boolean(),i.l]),ae=s.z.array(s.z.string());var k=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=ie.safeParse(i);return a.success?a.data:(await this.delete(e,t,n),null)}catch(e){return this.#t.warn(`CachingService.get failed`,{error:e}),null}}async set(e,t,n,r){try{let i=this.#c(e,t,n);await this.#e.set(i,r),this.#i=this.#i.then(()=>this.#u(i).catch(e=>{this.#t.warn(`CachingService index write failed`,{error:e})})),await this.#i}catch(e){this.#t.warn(`CachingService.set failed`,{error:e})}}async delete(e,t,n){let r=this.#c(e,t,n);this.#i=this.#i.then(()=>this.#a(r).catch(e=>{this.#t.warn(`CachingService.delete failed`,{error:e})})),await this.#i}async clearForRequester(e){this.#i=this.#i.then(()=>this.#o(e).catch(e=>{this.#t.warn(`CachingService.clearForRequester failed`,{error:e})})),await this.#i}async clearAll(){this.#i=this.#i.then(()=>this.#s().catch(e=>{this.#t.warn(`CachingService.clearAll failed`,{error:e})})),await this.#i}async#a(e){await this.#e.delete(e).catch(()=>{});let t=await this.#l(),n=t.filter(t=>t!==e);n.length!==t.length&&await this.#e.set(this.#r,n)}async#o(e){let t=(0,o.getAddress)(e),n=`${this.#n}:${t}:`,r=await this.#l(),i=[],a=[];for(let e of r)e.startsWith(n)?i.push(e):a.push(e);await Promise.all(i.map(e=>this.#e.delete(e).catch(()=>{}))),await this.#e.set(this.#r,a)}async#s(){let e=await this.#l();await Promise.all(e.map(e=>this.#e.delete(e).catch(()=>{}))),await this.#e.delete(this.#r)}#c(e,t,n){return`${this.#n}:${(0,o.getAddress)(e)}:${(0,o.getAddress)(t)}:${n.toLowerCase()}`}async#l(){let e=await this.#e.get(this.#r);if(e===null)return[];let t=ae.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 A(e,t){let r=oe(e,t);if(!r)throw new n.E(`No permit covers contract ${t} after allow()`);return{privateKey:e.keypair.privateKey,publicKey:e.keypair.publicKey,serializedPermit:r.serializedPermit}}function oe(e,t){let n=i.c(t);return e.permissions.find(e=>e.contractAddresses.includes(n))}const se=e=>new Promise(t=>setTimeout(t,e));var ce=class{#e;#t;#n;#r;#i;constructor({cache:e,credentialService:t,delegationService:n,router:r,emitEvent:i}){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i}async decryptValues(e,t,n){let r=(0,o.getAddress)(t);return this.#s(e,{requesterAddress:r,aclActorAddress:r,resolveCredentials:e=>this.#t.grantPermit(e),decryptContract:({credentials:e,contractAddress:t,encryptedValues:n,options:r})=>this.#o(e,t,n,r),errorMessage:`Failed to decrypt encrypted values`},n)}async delegatedDecryptValues(e,t,n,r,i){let a=(0,o.getAddress)(t),s=(0,o.getAddress)(n);return this.#a(i?.waitForPropagation??!0,()=>this.#s(e,{requesterAddress:(0,o.getAddress)(r),aclActorAddress:a,resolveCredentials:e=>this.#t.grantPermit(e,a),validate:e=>this.#f(e,{delegatorAddress:a,delegateAddress:s}),decryptContract:({credentials:e,contractAddress:t,encryptedValues:n,options:r})=>this.#o(e,t,n,r),errorMessage:`Failed to decrypt delegated encrypted values`,delegated:!0}))}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 S))throw t;await se(2e3)}throw n}async delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:r,accountAddress:i,maxConcurrency:a=5,waitForPropagation:s=!0}){let c=e.map(e=>({encryptedValue:e.encryptedValue,contractAddress:(0,o.getAddress)(e.contractAddress)}));if(c.length===0)return{items:c};let l=(0,o.getAddress)(i);try{let e=await this.delegatedDecryptValues(c.map(({encryptedValue:e,contractAddress:t})=>({encryptedValue:e,contractAddress:t})),t,r,l,{waitForPropagation:s});for(let t of c)this.#l(t,e);return{items:c}}catch(e){if(n._(e))throw e;if(c.length===1){let[n=this.#d()]=c;return n.error=this.#u(e,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:n.contractAddress,account:(0,o.getAddress)(t)}),{items:c}}}let u=!1;return await n.o(c.map(e=>async()=>{if(!u)try{let n=await this.delegatedDecryptValues([{encryptedValue:e.encryptedValue,contractAddress:e.contractAddress}],t,r,l,{waitForPropagation:!1});this.#l(e,n)}catch(r){if(n._(r))throw u=!0,r;e.error=this.#u(r,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:e.contractAddress,account:(0,o.getAddress)(t)})}}),a),{items:c}}async#o(e,t,n,r){let i=A(e,t),a=await this.#r.relayer.parseTransportKeyPair({publicKey:i.publicKey,privateKey:i.privateKey}),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,r,i){if(t.length===0)return{};let a=t.map(e=>({encryptedValue:e.encryptedValue,contractAddress:(0,o.getAddress)(e.contractAddress)})),s={},c=[];for(let e of a)n.a(e.encryptedValue)?s[e.encryptedValue]=0n:c.push(e);if(c.length===0)return s;let l=Array.from(new Set(a.map(e=>e.contractAddress))),u=Array.from(new Set(c.map(e=>e.contractAddress)));if(r.validate)try{await r.validate(u)}catch(t){throw e.m(t)?this.#c(t,`the delegation pre-check`):t}let d=[];for(let e of c){let t=await this.#e.get(r.requesterAddress,e.contractAddress,e.encryptedValue);t===null?d.push(e):s[e.encryptedValue]=t}if(d.length===0)return s;let f=await r.resolveCredentials(l),p=new Map;for(let e of d){let t=p.get(e.contractAddress);t?t.push(e.encryptedValue):p.set(e.contractAddress,[e.encryptedValue])}let m=[];for(let[e,t]of p)for(let r of n.i(t))m.push({contractAddress:e,encryptedValues:r});let h=Date.now(),g=d.map(e=>e.encryptedValue);try{this.#i({type:n.s.DecryptStart,encryptedValues:g}),await n.o(m.map(({contractAddress:e,encryptedValues:t})=>async()=>{let a;try{a=await r.decryptContract({credentials:f,contractAddress:e,encryptedValues:t,options:i})}catch(t){throw C(t,r.errorMessage,{isDelegated:r.delegated,contractAddress:e,account:r.aclActorAddress})}for(let n=0;n<t.length;n++){let i=t[n],o=a[n]?.value;i===void 0||o===void 0||(s[i]=o,await this.#e.set(r.requesterAddress,e,i,o))}let o=t.filter(e=>s[e]===void 0);if(o.length>0)throw new n.E(`${r.errorMessage}: relayer returned no clear value for ${o.length} of ${t.length} handle(s) on ${e}`,{cause:AggregateError(o.map(t=>new n.E(`No clear value for handle ${t} on ${e}`)),`${o.length} handle(s) missing a clear value on ${e}`)})}),5);let e={};for(let t of g){let n=s[t];n!==void 0&&(e[t]=n)}return this.#i({type:n.s.DecryptEnd,durationMs:Date.now()-h,encryptedValues:g,result:e}),s}catch(t){let i=t instanceof e.r&&t.cause instanceof Error?t.cause:t;throw this.#i({type:n.s.DecryptError,error:e.g(i),durationMs:Date.now()-h,encryptedValues:g}),C(t,r.errorMessage,{isDelegated:r.delegated})}}#c(t,r){return new n.w(`RPC provider rate-limited ${r}; retry with backoff.`,{cause:t,retryAfter:e.c(t)})}#l(e,t){let r=t[e.encryptedValue];if(r===void 0){e.error=new n.E(`Batch delegated decryption returned no value for encrypted value ${e.encryptedValue} on contract ${e.contractAddress}`);return}e.value=r}#u(t,n,r){return t instanceof e.r?t:C(t,n,r)}#d(){throw new n.E(`Batch delegated decryption invariant failed: missing item`)}async#f(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}};function le(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}const j={AlreadyDelegatedOrRevokedInSameBlock:e=>new m(`Only one delegate/revoke per (delegator, delegate, contract) per block. Wait for the next block before retrying.`,{cause:e}),SenderCannotBeContractAddress:e=>new y(`The contract address cannot be the caller address.`,{cause:e}),EnforcedPause:e=>new b(`The ACL contract is paused. Delegation operations are temporarily disabled.`,{cause:e}),SenderCannotBeDelegate:e=>new p(`Cannot delegate to yourself (delegate === msg.sender).`,{cause:e}),DelegateCannotBeContractAddress:e=>new v(`Delegate address cannot be the same as the contract address.`,{cause:e}),ExpirationDateBeforeOneHour:e=>new x(`Expiration date must be at least 1 hour in the future.`,{cause:e}),ExpirationDateAlreadySetToSameValue:e=>new _(`The new expiration date is the same as the current one.`,{cause:e}),NotDelegatedYet:e=>new h(`Cannot revoke: no active delegation exists.`,{cause:e})};function ue(e){return e in j}function de(e,t){let n=le(e);if(n&&ue(n))return j[n](t);let r=e instanceof Error?e.message:String(e);for(let[e,n]of Object.entries(j))if(r.includes(e))return n(t);return null}var fe=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:r,delegatorAddress:i,expirationDate:a}){if(a&&a.getTime()<Date.now()+36e5)throw new x(`Expiration date must be at least 1 hour in the future`);let s=(0,o.getAddress)(t),c=(0,o.getAddress)(r),l=(0,o.getAddress)(i);if(c===l)throw new p(`Cannot delegate to yourself (delegate === msg.sender).`);if(c===s)throw new v(`Delegate address cannot be the same as the contract address (${s}).`);let u=this.#e.relayer.chain.aclContractAddress,d=a?BigInt(Math.floor(a.getTime()/1e3)):n.f,f;try{f=await this.getDelegationExpiry({contractAddress:s,delegatorAddress:l,delegateAddress:c})}catch(e){this.#r.warn(`delegateDecryption: pre-flight expiry check failed`,{error:e}),f=-1n}if(f===d)throw new _(`The new expiration date (${d}) is the same as the current one. No on-chain change needed.`);return this.#i({operation:`delegateDecryption`,signer:e,contractAddress:t,config:n.p(u,c,s,d)})}async revokeDelegation(e,{contractAddress:t,delegateAddress:r,delegatorAddress:i}){let a=(0,o.getAddress)(t),s=(0,o.getAddress)(r),c=(0,o.getAddress)(i),l=this.#e.relayer.chain.aclContractAddress,u;try{u=await this.getDelegationExpiry({contractAddress:a,delegatorAddress:c,delegateAddress:s})}catch(e){this.#r.warn(`revokeDelegation: pre-flight expiry check failed`,{error:e}),u=1n}if(u===0n)throw new h(`No active delegation found for delegate ${s} on contract ${a}.`);return this.#i({operation:`revokeDelegation`,signer:e,contractAddress:t,config:n.g(l,s,a)})}async isDelegated(e){let t=await this.getDelegationExpiry(e);return t===0n?!1:t===n.f?!0:t>await this.#t.getBlockTimestamp()}async getDelegationExpiry({contractAddress:e,delegatorAddress:t,delegateAddress:r}){let i=this.#e.relayer.chain.aclContractAddress;return this.#t.readContract(n.m(i,(0,o.getAddress)(t),(0,o.getAddress)(r),(0,o.getAddress)(e)))}async#i({operation:e,signer:t,contractAddress:r,config:i}){try{return await n.n({operation:e,signer:t,provider:this.#t,config:i,emit:e=>this.#n(e,r),logger:this.#r})}catch(e){throw this.#a(e),e}}#a(e){if(!(e instanceof n.T))return;let t=de(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 h||t instanceof g){let n=(0,o.getAddress)(e);r.set(n,t);return}throw t}})),r}async assertDelegationActive(e,t,r){let i=(0,o.getAddress)(e),a=(0,o.getAddress)(t),s=(0,o.getAddress)(r),c=await this.getDelegationExpiry({contractAddress:i,delegatorAddress:a,delegateAddress:s});if(c===0n)throw new h(`No active delegation from ${a} to ${s} for ${i}`);if(c!==n.f&&c<=await this.#t.getBlockTimestamp())throw new g(`Delegation from ${a} to ${s} for ${i} has expired`)}},pe=class{#e;#t;constructor({router:e,emitEvent:t}){this.#e=e,this.#t=t}async encryptValues(t,r){let i=Date.now(),a=(0,o.getAddress)(t.contractAddress);try{this.#t({type:n.s.EncryptStart},a);let e=await this.#e.relayer.encryptValues({...t,options:r});return this.#t({type:n.s.EncryptEnd,durationMs:Date.now()-i},a),e}catch(t){throw this.#t({type:n.s.EncryptError,error:e.g(t),durationMs:Date.now()-i},a),te(t,`Encryption failed`)}}},me=class{#e;#t;#n;#r;#i;#a=new Set;#o;constructor(e){this.#e=e.signer,this.#t=e.router,this.#n=e.cachingService,this.#r=e.credentialService,this.#i=e.logger,this.#e&&(this.#o=this.#e.walletAccount.subscribe(e=>{this.#s(e).catch(e=>{this.#i.warn(`wallet account handler failed`,{error:e})})}))}onWalletAccountChange(e){return this.#a.add(e),()=>{this.#a.delete(e)}}dispose(){this.#o?.(),this.#o=void 0,this.#a.clear()}async#s(e){let n=e.previous,r=e.next,i=r?.chainId;i!==void 0&&await t.L(`switch relayer chain`,()=>this.#t.switchChain(i),this.#i);let a=this.#r;a&&await t.L(`credential wallet account change`,()=>a.handleWalletAccountChange(n,r),this.#i),n&&await t.L(`clear decrypt cache`,()=>this.#n.clearForRequester(n.address),this.#i),await Promise.all(Array.from(this.#a,n=>t.L(`wallet account listener`,()=>n(e),this.#i)))}};function M(e){return(0,o.keccak256)((0,o.toBytes)(e))}const N={ConfidentialTransfer:M(`ConfidentialTransfer(address,address,bytes32)`),Wrap:M(`Wrap(address,uint256,bytes32)`),UnwrapRequested:M(`UnwrapRequested(address,bytes32,bytes32)`),UnwrapFinalized:M(`UnwrapFinalized(address,bytes32,bytes32,uint64)`)};function P(e){return(0,o.getAddress)(T(e.slice(-40)))}function F(e){return e}function I(e,t){let n=2+t*64,r=e.slice(n,n+64);return r.length===64?r:r.padEnd(64,`0`)}function L(e,t){return(0,o.getAddress)(T(I(e,t).slice(-40)))}function R(e,t){return BigInt(`0x`+I(e,t))}function z(e,t){return T(I(e,t))}function B(e){return e.topics[0]!==N.ConfidentialTransfer||e.topics.length<4?null:{eventName:`ConfidentialTransfer`,from:P(e.topics[1]),to:P(e.topics[2]),encryptedAmount:F(e.topics[3])}}function V(e){return e.topics[0]!==N.Wrap||e.topics.length<2?null:{eventName:`Wrap`,to:P(e.topics[1]),roundedAmount:R(e.data,0),encryptedWrappedAmount:z(e.data,1)}}function H(e){return e.topics[0]!==N.UnwrapRequested||e.topics.length<3?null:{eventName:`UnwrapRequested`,receiver:P(e.topics[1]),unwrapRequestId:F(e.topics[2]),encryptedAmount:z(e.data,0)}}function U(e){return e.topics[0]!==N.UnwrapFinalized||e.topics.length<3?null:{eventName:`UnwrapFinalized`,receiver:P(e.topics[1]),unwrapRequestId:F(e.topics[2]),encryptedAmount:z(e.data,0),cleartextAmount:R(e.data,1)}}function W(e){return B(e)??V(e)??H(e)??U(e)}function he(e){let t=[];for(let n of e){let e=W(n);e&&t.push(e)}return t}function G(e){for(let t of e){let e=H(t);if(e)return e}return null}function ge(e){for(let t of e){let e=V(t);if(e)return e}return null}const _e=[N.ConfidentialTransfer,N.Wrap,N.UnwrapRequested,N.UnwrapFinalized],K={DelegatedForUserDecryption:M(`DelegatedForUserDecryption(address,address,address,uint64,uint64,uint64)`),RevokedDelegationForUserDecryption:M(`RevokedDelegationForUserDecryption(address,address,address,uint64,uint64)`)};function q(e){return e.topics[0]!==K.DelegatedForUserDecryption||e.topics.length<3?null:{eventName:`DelegatedForUserDecryption`,delegator:P(e.topics[1]),delegate:P(e.topics[2]),contractAddress:L(e.data,0),delegationCounter:R(e.data,1),oldExpirationDate:R(e.data,2),newExpirationDate:R(e.data,3)}}function J(e){return e.topics[0]!==K.RevokedDelegationForUserDecryption||e.topics.length<3?null:{eventName:`RevokedDelegationForUserDecryption`,delegator:P(e.topics[1]),delegate:P(e.topics[2]),contractAddress:L(e.data,0),delegationCounter:R(e.data,1),oldExpirationDate:R(e.data,2)}}function Y(e){return q(e)??J(e)}function ve(e){let t=[];for(let n of e){let e=Y(n);e&&t.push(e)}return t}function ye(e){for(let t of e){let e=q(t);if(e)return e}return null}function be(e){for(let t of e){let e=J(t);if(e)return e}return null}const xe=[K.DelegatedForUserDecryption,K.RevokedDelegationForUserDecryption];function X(e){return`zama:pending-unshield:${i.c(e)}`}const Se=s.z.union([s.z.pipe(i.u,s.z.transform(e=>({unwrapTxHash:e}))),s.z.pipe(s.z.object({version:s.z.literal(1),unwrapTxHash:i.u,unwrapRequestId:s.z.optional(i.u)}),s.z.transform(({unwrapTxHash:e,unwrapRequestId:t})=>({unwrapTxHash:e,unwrapRequestId:t})))]);async function Z(e,t,n,r){if(r===void 0){await e.set(X(t),n);return}await e.set(X(t),{version:1,unwrapTxHash:n,unwrapRequestId:r})}async function Ce(e,t){return(await we(e,t))?.unwrapTxHash??null}async function we(e,t){let n=X(t),r=await e.get(n);if(r==null)return null;let i=Se.safeParse(r);return i.success?i.data:(await e.delete(n),null)}async function Te(e,t){await e.delete(X(t))}var Q=class extends n.t{#e;#t=null;#n=null;#r(e){try{return n.l(this.sdk.signer,`WrappedToken.sdk.signer`),this.sdk.signer}catch(n){throw new t.R(e,{cause:n})}}async underlying(){return this.#s()}async isPayable(){if(this.#n!==null)return this.#n;try{let e=await this.#s();this.#n=await this.sdk.provider.readContract(t.p(e))}catch{this.#n=!1}return this.#n}async allowance(e){let n=await this.#s();return this.sdk.provider.readContract(t.h(n,(0,o.getAddress)(e),this.address))}async shield(r,i){let a=await n.u(`shield`,this.sdk.signer,this.sdk.provider),s=await this.isPayable(),c=await this.#s(),l=(0,o.getAddress)(a.address),u;try{u=await this.sdk.provider.readContract(t._(c,l))}catch(t){throw t instanceof e.r?t:new n.y(`Could not read ERC-20 balance for shield validation (token: ${c})`,{cause:e.g(t)})}if(u<r)throw new n.S(`Insufficient ERC-20 balance: requested ${r}, available ${u} (token: ${c})`,{requested:r,available:u,token:c});return s?this.#i(r,c,l,i):this.#a(r,l,i)}async#i(e,t,n,r){this.#r(`shield`);let i=r?.to?(0,o.getAddress)(r.to):n,a=i===n?`0x`:i;return this.submitTransaction({operation:`shield:transferAndCall`,config:w(t,this.address,e,a),onSubmitted:r?.onShieldSubmitted})}async wrap(r,i){this.#r(`wrap`);let a=await n.u(`wrap`,this.sdk.signer,this.sdk.provider),s=await this.#s(),c=(0,o.getAddress)(a.address),l;try{l=await this.sdk.provider.readContract(t._(s,c))}catch(t){throw t instanceof e.r?t:new n.y(`Could not read ERC-20 balance for wrap validation (token: ${s})`,{cause:e.g(t)})}if(l<r)throw new n.S(`Insufficient ERC-20 balance: requested ${r}, available ${l} (token: ${s})`,{requested:r,available:l,token:s});let u;try{u=await this.sdk.provider.readContract(t.h(s,c,this.address))}catch(t){throw t instanceof e.r?t:new n.y(`Could not read ERC-20 allowance for wrap validation (token: ${s})`,{cause:e.g(t)})}if(u<r)throw new n.b(`Insufficient allowance for wrap: requested ${r}, approved ${u}. Call approveUnderlying() first (token: ${s}).`,{requested:r,available:u,token:s});let d=i?.to?(0,o.getAddress)(i.to):c;return this.submitTransaction({operation:`wrap`,config:t.I(this.address,d,r),onSubmitted:i?.onWrapSubmitted})}async#a(e,n,r){this.#r(`shield`);let i=r?.approvalStrategy??`exact`;i!==`skip`&&await this.#l(e,i===`max`,r);let a=r?.to?(0,o.getAddress)(r.to):n;return this.submitTransaction({operation:`shield:approveAndWrap`,config:t.I(this.address,a,e),onSubmitted:r?.onShieldSubmitted})}async approveUnderlying(e){this.#r(`approveUnderlying`);let r=await n.u(`approveUnderlying`,this.sdk.signer,this.sdk.provider),i=await this.#s(),a=(0,o.getAddress)(r.address),s=e??2n**256n-1n;return s>0n&&await this.sdk.provider.readContract(t.h(i,a,this.address))>0n&&await this.submitTransaction({operation:`approveUnderlying:reset`,config:t.g(i,this.address,0n)}),this.submitTransaction({operation:`approveUnderlying`,config:t.g(i,this.address,s)})}async unshield(e,n){let{skipBalanceCheck:r=!1,onUnwrapSubmitted:i,onFinalizing:a,onFinalizeSubmitted:o}=n??{};r||await this.assertConfidentialBalance(e);let s={onFinalizing:a,onFinalizeSubmitted:o},c=crypto.randomUUID(),l=await this.unwrap(e);return t.L(`unshield: onUnwrapSubmitted`,()=>i?.(l.txHash),this.sdk.logger),this.#c(l.unwrapRequestId,l.txHash,c,s)}async unshieldAll(e){let n=crypto.randomUUID(),r=await this.unwrapAll();return t.L(`unshieldAll: onUnwrapSubmitted`,()=>e?.onUnwrapSubmitted?.(r.txHash),this.sdk.logger),this.#c(r.unwrapRequestId,r.txHash,n,e)}async resumeUnshield(t,r){let i;try{i=await this.sdk.provider.waitForTransactionReceipt(t)}catch(t){throw t instanceof e.r?t:new n.T(`Failed to get unwrap receipt`,{cause:t})}let a=this.#o(i.logs);return this.#c(a,t,crypto.randomUUID(),r)}async getPendingUnshield(){return Ce(this.sdk.storage,this.address)}async unwrap(e){this.#r(`unwrap`);let r=(0,o.getAddress)((await n.u(`unwrap`,this.sdk.signer,this.sdk.provider)).address),{encryptedValues:i,inputProof:a}=await this.sdk.encrypt({values:[{value:e,type:`euint64`}],contractAddress:this.address,userAddress:r}),[s]=i;if(!s)throw new n.D(`Encryption returned no encrypted values`);let c=await this.submitTransaction({operation:`unwrap`,config:t.P(this.address,r,r,s,a)});return{...c,unwrapRequestId:this.#o(c.receipt.logs)}}async unwrapAll(){this.#r(`unwrapAll`);let e=(0,o.getAddress)((await n.u(`unwrapAll`,this.sdk.signer,this.sdk.provider)).address),r=await this.readConfidentialBalanceOf(e);if(n.a(r))throw new n.E(`Cannot unshield: balance is zero`);let i=await this.submitTransaction({operation:`unwrapAll`,config:t.F(this.address,e,e,r)});return{...i,unwrapRequestId:this.#o(i.receipt.logs)}}async finalizeUnwrap(e){this.#r(`finalizeUnwrap`),await n.d(`finalizeUnwrap`,this.sdk.signer,this.sdk.provider);let r=await this.sdk.decryption.decryptPublicValues([e]),i=r.clearValues[e];return n.c(i,`finalizeUnwrap: clearValue`),this.submitTransaction({operation:`finalizeUnwrap`,config:t.O(this.address,e,i,r.decryptionProof)})}#o(e){let t=G(e);if(!t)throw new n.T(`No UnwrapRequested event found in unwrap receipt`);return t.unwrapRequestId}async#s(){return this.#e===void 0?(this.#t||=this.sdk.provider.readContract(t.N(this.address)).then(e=>(this.#e=e,this.#t=null,e)).catch(e=>{throw this.#t=null,e}),this.#t):this.#e}async#c(e,r,i,a){this.emit({type:n.s.UnshieldPhase1Submitted,txHash:r,operationId:i}),await t.L(`unshield: savePendingUnshield`,()=>Z(this.sdk.storage,this.address,r),this.sdk.logger),this.emit({type:n.s.UnshieldPhase2Started,operationId:i}),t.L(`unshield: onFinalizing`,()=>a?.onFinalizing?.(),this.sdk.logger);let o=await this.finalizeUnwrap(e);return this.emit({type:n.s.UnshieldPhase2Submitted,txHash:o.txHash,operationId:i}),t.L(`unshield: onFinalizeSubmitted`,()=>a?.onFinalizeSubmitted?.(o.txHash),this.sdk.logger),await t.L(`unshield: clearPendingUnshield`,()=>Te(this.sdk.storage,this.address),this.sdk.logger),o}async#l(e,r,i){this.#r(`approveUnderlying`);let a=await this.#s(),s=(0,o.getAddress)((await n.u(`approveUnderlying`,this.sdk.signer,this.sdk.provider)).address),c=await this.sdk.provider.readContract(t.h(a,s,this.address));if(c>=e)return;c>0n&&await this.submitTransaction({operation:`approveUnderlying:reset`,config:t.g(a,this.address,0n)});let l=r?2n**256n-1n:e;await this.submitTransaction({operation:`approveUnderlying`,config:t.g(a,this.address,l),onSubmitted:i?.onApprovalSubmitted})}},Ee=class{#e;provider;signer;storage;registry;permits;delegations;decryption;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;constructor(e){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 k(e.storage,this.#i),this.#u=new fe({provider:this.provider,router:e.router,emitEvent:this.emitEvent.bind(this),logger:this.#i});let t={};for(let n of e.chains)n.registryAddress&&(t[n.id]=n.registryAddress);this.registry=new i.o({provider:this.provider,registryAddresses:t,registryTTL:e.registryTTL}),this.#n=t,this.#t=e.registryTTL,e.signer&&(this.#l=new i.s({router:e.router,signer:e.signer,transportKeyPairTTL:e.transportKeyPairTTL,permitTTL:e.permitTTL,scope:e.transportKeyPairScope,storage:this.storage,permitStorage:e.permitStorage,logger:this.#i}),this.#c=new ce({cache:this.#a,credentialService:this.#l,delegationService:this.#u,router:e.router,emitEvent:this.emitEvent.bind(this)})),this.#s=new pe({router:e.router,emitEvent:this.emitEvent.bind(this)}),this.#o=new me({signer:e.signer,router:e.router,cachingService:this.#a,credentialService:this.#l,logger:this.#i}),this.permits=new O({signer:this.signer,provider:this.provider,cachingService:this.#a,credentialService:this.#l,logger:this.#i}),this.delegations=new D({signer:this.signer,provider:this.provider,delegationService:this.#u}),this.decryption=new E({signer:this.signer,provider:this.provider,router:e.router,decryptionService:this.#c})}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 i.o({provider:this.provider,registryAddresses:{...this.#n,...e},registryTTL:this.#t})}async encrypt(e,t){return this.#s.encryptValues(e,t)}createToken(e){return new n.t(this,e)}createWrappedToken(e){return new Q(this,e)}dispose(){this.#o.dispose()}terminate(){this.dispose(),this.signer?.dispose?.()}[Symbol.dispose](){this.terminate()}},$=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 De=new $;exports.ACL_TOPICS=xe,exports.AclPausedError=b,exports.AclTopics=K,exports.BalanceCheckUnavailableError=n.v,exports.BaseSigner=i.t,exports.ChainMismatchError=n.C,exports.ChromeSessionStorage=$,exports.ConfigurationError=e.t,exports.Decryption=E,exports.DecryptionFailedError=n.E,exports.DefaultRegistryAddresses=i.a,exports.DelegationContractIsSelfError=y,exports.DelegationCooldownError=m,exports.DelegationDelegateEqualsContractError=v,exports.DelegationExpirationTooSoonError=x,exports.DelegationExpiredError=g,exports.DelegationExpiryUnchangedError=_,exports.DelegationNotFoundError=h,exports.DelegationNotPropagatedError=S,exports.DelegationSelfNotAllowedError=p,exports.Delegations=D,exports.ERC1363_INTERFACE_ID=t.c,exports.ERC20ReadFailedError=n.y,exports.ERC7984_INTERFACE_ID=t.l,exports.ERC7984_WRAPPER_INTERFACE_ID=t.u,exports.EncryptionFailedError=n.D,exports.IndexedDBStorage=i.h,exports.InsufficientAllowanceError=n.b,exports.InsufficientConfidentialBalanceError=n.x,exports.InsufficientERC20BalanceError=n.S,exports.InvalidTransportKeyPairError=u,exports.MemoryStorage=i.p,exports.MutableWalletAccountStore=i.n,exports.NoCiphertextError=d,exports.NotEntitledError=f,exports.Permits=O,exports.RelayerRequestFailedError=e.n,exports.RpcRateLimitError=n.w,exports.SignerNotConfiguredError=t.R,exports.SignerRequiredError=t.z,exports.SigningFailedError=t.U,exports.SigningRejectedError=t.W,exports.TOKEN_TOPICS=_e,exports.Token=n.t,exports.Topics=N,exports.TransactionRevertedError=n.T,exports.TransportKeyPairExpiredError=l,exports.WalletAccountNotReadyError=t.B,exports.WalletNotConnectedError=t.V,exports.WrappedToken=Q,exports.WrappersRegistry=i.o,exports.ZERO_ENCRYPTED_VALUE=n.r,exports.ZamaError=e.r,exports.ZamaErrorCode=e.i,exports.ZamaSDK=Ee,exports.ZamaSDKEvents=n.s,exports.allowanceContract=t.h,exports.anvil=a.t,exports.approveContract=t.g,exports.balanceOfContract=t._,exports.bscTestnet=a.n,exports.chains=a.r,exports.chromeSessionStorage=De,exports.cleartext=r.t,exports.confidentialBalanceOfContract=t.S,exports.confidentialTotalSupplyContract=t.C,exports.confidentialTransferContract=t.T,exports.confidentialTransferFromContract=t.D,exports.createConfig=re,exports.createWalletAccountStore=i.r,exports.decimalsContract=t.v,exports.decodeAclEvent=Y,exports.decodeAclEvents=ve,exports.decodeConfidentialTransfer=B,exports.decodeDelegatedForUserDecryption=q,exports.decodeOnChainEvent=W,exports.decodeOnChainEvents=he,exports.decodeRevokedDelegationForUserDecryption=J,exports.decodeUnwrapFinalized=U,exports.decodeUnwrapRequested=H,exports.decodeWrap=V,exports.delegateForUserDecryptionContract=n.p,exports.finalizeUnwrapContract=t.O,exports.findDelegatedForUserDecryption=ye,exports.findRevokedDelegationForUserDecryption=be,exports.findUnwrapRequested=G,exports.findWrap=ge,exports.getConfidentialTokenAddressContract=t.t,exports.getDelegationExpiryContract=n.m,exports.getTokenAddressContract=t.n,exports.getTokenPairContract=t.r,exports.getTokenPairsContract=t.i,exports.getTokenPairsLengthContract=t.a,exports.getTokenPairsSliceContract=t.o,exports.hardhat=a.i,exports.hoodi=a.a,exports.indexedDBStorage=i.g,exports.inferredTotalSupplyContract=t.k,exports.ingenTestnet=a.o,exports.isConfidentialTokenContract=t.d,exports.isConfidentialTokenValidContract=t.s,exports.isConfidentialWrapperContract=t.f,exports.isEncryptedValueZero=n.a,exports.isHandleDelegatedContract=n.h,exports.isOperatorContract=t.A,exports.isRetryable=e.a,exports.mainnet=a.s,exports.matchZamaError=c,exports.memoryStorage=i.m,exports.nameContract=t.b,exports.rateContract=t.j,exports.resolveChainRelayers=i.d,exports.resolveStorage=i.f,exports.retryAfterSeconds=e.o,exports.revokeDelegationContract=n.g,exports.sepolia=a.c,exports.setOperatorContract=t.M,exports.supportsInterfaceContract=t.m,exports.symbolContract=t.x,exports.transferAndCallContract=w,exports.underlyingContract=t.N,exports.unwrapContract=t.P,exports.unwrapFromBalanceContract=t.F,exports.wrapContract=t.I;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./relayer.cjs"),t=require("./wrappers-registry.cjs"),n=require("./token.cjs"),r=require("./cleartext.cjs"),i=require("./base-signer.cjs"),a=require("./chains.cjs");let o=require("viem"),s=require("zod/mini");function c(t,n){if(t instanceof e.r){let e=n[t.code];if(e)return e(t)}return n._?.(t)}var l=class extends e.r{constructor(t,n){super(e.i.TransportKeyPairExpired,t,n),this.name=`TransportKeyPairExpiredError`}},u=class extends e.r{constructor(t,n){super(e.i.InvalidTransportKeyPair,t,n),this.name=`InvalidTransportKeyPairError`}},d=class extends e.r{constructor(t,n){super(e.i.NoCiphertext,t,n),this.name=`NoCiphertextError`}},f=class extends e.r{encryptedValue;contractAddress;account;constructor(t,n){super(e.i.NotEntitled,`Account ${t.account} is not entitled to decrypt encrypted value ${t.encryptedValue} on contract ${t.contractAddress}. This is not a transient failure — the account needs an on-chain ACL grant before it can decrypt this encrypted value.`,n),this.name=`NotEntitledError`,this.encryptedValue=t.encryptedValue,this.contractAddress=t.contractAddress,this.account=t.account}},p=class extends e.r{constructor(t,n){super(e.i.DelegationSelfNotAllowed,t,n),this.name=`DelegationSelfNotAllowedError`}},m=class extends e.r{constructor(t,n){super(e.i.DelegationCooldown,t,n),this.name=`DelegationCooldownError`}},h=class extends e.r{constructor(t,n){super(e.i.DelegationNotFound,t,n),this.name=`DelegationNotFoundError`}},g=class extends e.r{constructor(t,n){super(e.i.DelegationExpired,t,n),this.name=`DelegationExpiredError`}},_=class extends e.r{constructor(t,n){super(e.i.DelegationExpiryUnchanged,t,n),this.name=`DelegationExpiryUnchangedError`}},v=class extends e.r{constructor(t,n){super(e.i.DelegationDelegateEqualsContract,t,n),this.name=`DelegationDelegateEqualsContractError`}},y=class extends e.r{constructor(t,n){super(e.i.DelegationContractIsSelf,t,n),this.name=`DelegationContractIsSelfError`}},b=class extends e.r{constructor(t,n){super(e.i.AclPaused,t,n),this.name=`AclPausedError`}},x=class extends e.r{constructor(t,n){super(e.i.DelegationExpirationTooSoon,t,n),this.name=`DelegationExpirationTooSoonError`}},S=class extends e.r{constructor(t,n){super(e.i.DelegationNotPropagated,t,n),this.name=`DelegationNotPropagatedError`}};const ee=[n.x,d,e.n,S,t.W,t.U,f,n.y];function C(t,r,i={}){if(ee.some(e=>t instanceof e))return t;let a=t instanceof Error?t.message:r;if(t instanceof Error&&e.d(t.message))return i.isDelegated?new S(`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:t}):new f({encryptedValue:e.h(t.message)??``,contractAddress:i.contractAddress??``,account:i.account??``},{cause:t});if(e.l(t))return new n.y(a,{cause:t,retryAfter:e.c(t)});let o=e.s(t);return o===void 0&&e.m(t)?new n.y(a,{cause:t,retryAfter:e.c(t)}):o===400?new d(t instanceof Error?t.message:`No ciphertext for this account`,{cause:t}):i.isDelegated&&o===500?new S(`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:t}):e.f(t)||o!==void 0?new e.n(a,o,{cause:t,retryAfter:e.c(t),retryable:e.p(t)||void 0}):new n.x(r,{cause:t})}function te(t,r){if(t instanceof e.r)return t;let i=e.s(t),a=e.p(t);return i!==void 0||e.f(t)?new e.n(t instanceof Error?t.message:r,i,{cause:t,retryAfter:e.c(t),retryable:a||void 0}):new n.S(r,{cause:t})}const ne=[{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 w(e,t,n,r=`0x`){return{address:e,abi:ne,functionName:`transferAndCall`,args:[t,n,r]}}const T=[{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 E(e,t,n,r){return{address:e,abi:T,functionName:`delegateForUserDecryption`,args:[t,n,r]}}function D(e,t,n){return{address:e,abi:T,functionName:`revokeDelegationForUserDecryption`,args:[t,n]}}function O(e,t,n,r){return{address:e,abi:T,functionName:`getUserDecryptionDelegationExpirationDate`,args:[t,n,r]}}function re(e,t,n,r,i){return{address:e,abi:T,functionName:`isHandleDelegatedForUserDecryption`,args:[t,n,r,i]}}const k=2n**64n-1n;function ie(e){return i.i(e.signer,e.provider,e)}function A(e){return e.startsWith(`0x`)?e:`0x${e}`}var j=class{#e;#t;#n;#r;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.router,this.#r=e.decryptionService}#i(e){return t.H(this.#r,e)}async decryptValues(e,t){let r=this.#i(`decryptValues`),i=await n.u(`decryptValues`,this.#e,this.#t);return r.decryptValues(e,i.address,t)}async delegatedDecryptValues(e,t,r=t,i){let a=this.#i(`delegatedDecryptValues`),o=await n.u(`delegatedDecryptValues`,this.#e,this.#t);return a.delegatedDecryptValues(e,t,o.address,r,i)}async decryptPublicValues(e,t){if(e.length===0)return{clearValues:{},decryptionProof:`0x`,abiEncodedClearValues:`0x`};try{let r=await this.#n.relayer.decryptPublicValuesWithSignatures({encryptedValues:e,options:t}),i={};return r.checkSignaturesArgs.handlesList.forEach((e,t)=>{n.l(r.clearValues[t],`result.clearValues[${t}]`),i[e]=r.clearValues[t].value}),{clearValues:i,abiEncodedClearValues:r.checkSignaturesArgs.abiEncodedCleartexts,decryptionProof:r.checkSignaturesArgs.decryptionProof}}catch(e){throw C(e,`Public decryption failed`)}}async delegatedBatchDecryptValues({encryptedInputs:e,delegatorAddress:t,accountAddress:r=t,maxConcurrency:i,waitForPropagation:a}){let o=this.#i(`delegatedBatchDecryptValues`),s=await n.u(`delegatedBatchDecryptValues`,this.#e,this.#t);return o.delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:s.address,accountAddress:r,maxConcurrency:i,waitForPropagation:a})}},M=class{#e;#t;#n;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.delegationService}#r(e){return t.H(this.#e,e)}async delegateDecryption({contractAddress:e,delegateAddress:t,expirationDate:r}){let i=this.#r(`delegateDecryption`),a=await n.u(`delegateDecryption`,this.#e,this.#t);return this.#n.delegateDecryption(i,{contractAddress:e,delegateAddress:t,delegatorAddress:a.address,expirationDate:r})}async revokeDelegation({contractAddress:e,delegateAddress:t}){let r=this.#r(`revokeDelegation`),i=await n.u(`revokeDelegation`,this.#e,this.#t);return this.#n.revokeDelegation(r,{contractAddress:e,delegateAddress:t,delegatorAddress:i.address})}async isActive(e){return this.#n.isDelegated(e)}async getExpiry(e){return this.#n.getDelegationExpiry(e)}async getStatus(e){return this.#n.getStatus(e)}},N=class{#e;#t;#n;#r;#i;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.cachingService,this.#r=e.credentialService,this.#i=e.logger}#a(e){return t.H(this.#r,e)}async grantPermit(e){if(e.length===0)return;let t=this.#a(`grantPermit`);await n.d(`grantPermit`,this.#e,this.#t),await t.grantPermit(e)}async grantDelegationPermit(e,t){if(t.length===0)return;let r=this.#a(`grantDelegationPermit`);await n.d(`grantDelegationPermit`,this.#e,this.#t),await r.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 revokePermits(e){let t=this.#a(`revokePermits`),r=(0,o.getAddress)((await n.u(`revokePermits`,this.#e,this.#t)).address);try{await t.revokePermits(e)}finally{await this.#o(r)}}async clear(){let e=this.#a(`clear`),t=(0,o.getAddress)((await n.u(`clear`,this.#e,this.#t)).address);try{await e.clearCredentials()}finally{await this.#o(t)}}async#o(e){await t.L(`clear decrypt cache`,()=>this.#n.clearForRequester(e),this.#i)}async revokeTransportKeyPair(e){await this.#a(`revokeTransportKeyPair`).revokeTransportKeyPair(e)}async warmTransportKeyPairScope(e){await this.#a(`warmTransportKeyPairScope`).warmTransportKeyPairScope(e)}};const ae=s.z.union([s.z.bigint(),s.z.boolean(),i.l]),oe=s.z.array(s.z.string());var se=class{#e;#t;#n=`zama:decrypt`;#r=`${this.#n}:keys`;#i=Promise.resolve();constructor(e,t){this.#e=e,this.#t=t}async get(e,t,n){try{let r=this.#c(e,t,n),i=await this.#e.get(r);if(i===null)return null;let a=ae.safeParse(i);return a.success?a.data:(await this.delete(e,t,n),null)}catch(e){return this.#t.warn(`CachingService.get failed`,{error:e}),null}}async set(e,t,n,r){try{let i=this.#c(e,t,n);await this.#e.set(i,r),this.#i=this.#i.then(()=>this.#u(i).catch(e=>{this.#t.warn(`CachingService index write failed`,{error:e})})),await this.#i}catch(e){this.#t.warn(`CachingService.set failed`,{error:e})}}async delete(e,t,n){let r=this.#c(e,t,n);this.#i=this.#i.then(()=>this.#a(r).catch(e=>{this.#t.warn(`CachingService.delete failed`,{error:e})})),await this.#i}async clearForRequester(e){this.#i=this.#i.then(()=>this.#o(e).catch(e=>{this.#t.warn(`CachingService.clearForRequester failed`,{error:e})})),await this.#i}async clearAll(){this.#i=this.#i.then(()=>this.#s().catch(e=>{this.#t.warn(`CachingService.clearAll failed`,{error:e})})),await this.#i}async#a(e){await this.#e.delete(e).catch(()=>{});let t=await this.#l(),n=t.filter(t=>t!==e);n.length!==t.length&&await this.#e.set(this.#r,n)}async#o(e){let t=(0,o.getAddress)(e),n=`${this.#n}:${t}:`,r=await this.#l(),i=[],a=[];for(let e of r)e.startsWith(n)?i.push(e):a.push(e);await Promise.all(i.map(e=>this.#e.delete(e).catch(()=>{}))),await this.#e.set(this.#r,a)}async#s(){let e=await this.#l();await Promise.all(e.map(e=>this.#e.delete(e).catch(()=>{}))),await this.#e.delete(this.#r)}#c(e,t,n){return`${this.#n}:${(0,o.getAddress)(e)}:${(0,o.getAddress)(t)}:${n.toLowerCase()}`}async#l(){let e=await this.#e.get(this.#r);if(e===null)return[];let t=oe.safeParse(e);return t.success?t.data:(await this.#e.delete(this.#r).catch(()=>{}),[])}async#u(e){let t=await this.#l();t.includes(e)||(t.push(e),await this.#e.set(this.#r,t))}};function ce(e,t){let r=le(e,t);if(!r)throw new n.x(`No permit covers contract ${t} after allow()`);return{privateKey:e.keypair.privateKey,publicKey:e.keypair.publicKey,serializedPermit:r.serializedPermit}}function le(e,t){let n=i.c(t);return e.permissions.find(e=>e.contractAddresses.includes(n))}const ue=e=>new Promise(t=>setTimeout(t,e));var de=class{#e;#t;#n;#r;#i;constructor({cache:e,credentialService:t,delegationService:n,router:r,emitEvent:i}){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i}async decryptValues(e,t,n){let r=(0,o.getAddress)(t);return this.#s(e,{requesterAddress:r,aclActorAddress:r,resolveCredentials:e=>this.#t.grantPermit(e),decryptContract:({credentials:e,contractAddress:t,encryptedValues:n,options:r})=>this.#o(e,t,n,r),errorMessage:`Failed to decrypt encrypted values`},n)}async delegatedDecryptValues(e,t,n,r,i){let a=(0,o.getAddress)(t),s=(0,o.getAddress)(n);return this.#a(i?.waitForPropagation??!0,()=>this.#s(e,{requesterAddress:(0,o.getAddress)(r),aclActorAddress:a,resolveCredentials:e=>this.#t.grantPermit(e,a),validate:e=>this.#f(e,{delegatorAddress:a,delegateAddress:s}),decryptContract:({credentials:e,contractAddress:t,encryptedValues:n,options:r})=>this.#o(e,t,n,r),errorMessage:`Failed to decrypt delegated encrypted values`,delegated:!0}))}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 S))throw t;await ue(2e3)}throw n}async delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:r,accountAddress:i,maxConcurrency:a=5,waitForPropagation:s=!0}){let c=e.map(e=>({encryptedValue:e.encryptedValue,contractAddress:(0,o.getAddress)(e.contractAddress)}));if(c.length===0)return{items:c};let l=(0,o.getAddress)(i);try{let e=await this.delegatedDecryptValues(c.map(({encryptedValue:e,contractAddress:t})=>({encryptedValue:e,contractAddress:t})),t,r,l,{waitForPropagation:s});for(let t of c)this.#l(t,e);return{items:c}}catch(e){if(n.f(e))throw e;if(c.length===1){let[n=this.#d()]=c;return n.error=this.#u(e,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:n.contractAddress,account:(0,o.getAddress)(t)}),{items:c}}}let u=!1;return await n.o(c.map(e=>async()=>{if(!u)try{let n=await this.delegatedDecryptValues([{encryptedValue:e.encryptedValue,contractAddress:e.contractAddress}],t,r,l,{waitForPropagation:!1});this.#l(e,n)}catch(r){if(n.f(r))throw u=!0,r;e.error=this.#u(r,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:e.contractAddress,account:(0,o.getAddress)(t)})}}),a),{items:c}}async#o(e,t,n,r){let i=ce(e,t),a=await this.#r.relayer.parseTransportKeyPair({publicKey:i.publicKey,privateKey:i.privateKey}),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,r,i){if(t.length===0)return{};let a=t.map(e=>({encryptedValue:e.encryptedValue,contractAddress:(0,o.getAddress)(e.contractAddress)})),s={},c=[];for(let e of a)n.a(e.encryptedValue)?s[e.encryptedValue]=0n:c.push(e);if(c.length===0)return s;let l=Array.from(new Set(a.map(e=>e.contractAddress))),u=Array.from(new Set(c.map(e=>e.contractAddress)));if(r.validate)try{await r.validate(u)}catch(t){throw e.m(t)?this.#c(t,`the delegation pre-check`):t}let d=[];for(let e of c){let t=await this.#e.get(r.requesterAddress,e.contractAddress,e.encryptedValue);t===null?d.push(e):s[e.encryptedValue]=t}if(d.length===0)return s;let f=await r.resolveCredentials(l),p=new Map;for(let e of d){let t=p.get(e.contractAddress);t?t.push(e.encryptedValue):p.set(e.contractAddress,[e.encryptedValue])}let m=[];for(let[e,t]of p)for(let r of n.i(t))m.push({contractAddress:e,encryptedValues:r});let h=Date.now(),g=d.map(e=>e.encryptedValue);try{this.#i({type:n.s.DecryptStart,encryptedValues:g}),await n.o(m.map(({contractAddress:e,encryptedValues:t})=>async()=>{let a;try{a=await r.decryptContract({credentials:f,contractAddress:e,encryptedValues:t,options:i})}catch(t){throw C(t,r.errorMessage,{isDelegated:r.delegated,contractAddress:e,account:r.aclActorAddress})}for(let n=0;n<t.length;n++){let i=t[n],o=a[n]?.value;i===void 0||o===void 0||(s[i]=o,await this.#e.set(r.requesterAddress,e,i,o))}let o=t.filter(e=>s[e]===void 0);if(o.length>0)throw new n.x(`${r.errorMessage}: relayer returned no clear value for ${o.length} of ${t.length} handle(s) on ${e}`,{cause:AggregateError(o.map(t=>new n.x(`No clear value for handle ${t} on ${e}`)),`${o.length} handle(s) missing a clear value on ${e}`)})}),5);let e={};for(let t of g){let n=s[t];n!==void 0&&(e[t]=n)}return this.#i({type:n.s.DecryptEnd,durationMs:Date.now()-h,encryptedValues:g,result:e}),s}catch(t){let i=t instanceof e.r&&t.cause instanceof Error?t.cause:t;throw this.#i({type:n.s.DecryptError,error:e.g(i),durationMs:Date.now()-h,encryptedValues:g}),C(t,r.errorMessage,{isDelegated:r.delegated})}}#c(t,r){return new n.y(`RPC provider rate-limited ${r}; retry with backoff.`,{cause:t,retryAfter:e.c(t)})}#l(e,t){let r=t[e.encryptedValue];if(r===void 0){e.error=new n.x(`Batch delegated decryption returned no value for encrypted value ${e.encryptedValue} on contract ${e.contractAddress}`);return}e.value=r}#u(t,n,r){return t instanceof e.r?t:C(t,n,r)}#d(){throw new n.x(`Batch delegated decryption invariant failed: missing item`)}async#f(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}};function fe(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}const P={AlreadyDelegatedOrRevokedInSameBlock:e=>new m(`Only one delegate/revoke per (delegator, delegate, contract) per block. Wait for the next block before retrying.`,{cause:e}),SenderCannotBeContractAddress:e=>new y(`The contract address cannot be the caller address.`,{cause:e}),EnforcedPause:e=>new b(`The ACL contract is paused. Delegation operations are temporarily disabled.`,{cause:e}),SenderCannotBeDelegate:e=>new p(`Cannot delegate to yourself (delegate === msg.sender).`,{cause:e}),DelegateCannotBeContractAddress:e=>new v(`Delegate address cannot be the same as the contract address.`,{cause:e}),ExpirationDateBeforeOneHour:e=>new x(`Expiration date must be at least 1 hour in the future.`,{cause:e}),ExpirationDateAlreadySetToSameValue:e=>new _(`The new expiration date is the same as the current one.`,{cause:e}),NotDelegatedYet:e=>new h(`Cannot revoke: no active delegation exists.`,{cause:e})};function pe(e){return e in P}function me(e,t){let n=fe(e);if(n&&pe(n))return P[n](t);let r=e instanceof Error?e.message:String(e);for(let[e,n]of Object.entries(P))if(r.includes(e))return n(t);return null}var he=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 x(`Expiration date must be at least 1 hour in the future`);let a=(0,o.getAddress)(t),s=(0,o.getAddress)(n),c=(0,o.getAddress)(r);if(s===c)throw new p(`Cannot delegate to yourself (delegate === msg.sender).`);if(s===a)throw new v(`Delegate address cannot be the same as the contract address (${a}).`);let l=this.#e.relayer.chain.aclContractAddress,u=i?BigInt(Math.floor(i.getTime()/1e3)):k,d;try{d=await this.getDelegationExpiry({contractAddress:a,delegatorAddress:c,delegateAddress:s})}catch(e){this.#r.warn(`delegateDecryption: pre-flight expiry check failed`,{error:e}),d=-1n}if(d===u)throw new _(`The new expiration date (${u}) is the same as the current one. No on-chain change needed.`);return this.#i({operation:`delegateDecryption`,signer:e,contractAddress:t,config:E(l,s,a,u)})}async revokeDelegation(e,{contractAddress:t,delegateAddress:n,delegatorAddress:r}){let i=(0,o.getAddress)(t),a=(0,o.getAddress)(n),s=(0,o.getAddress)(r),c=this.#e.relayer.chain.aclContractAddress,l;try{l=await this.getDelegationExpiry({contractAddress:i,delegatorAddress:s,delegateAddress:a})}catch(e){this.#r.warn(`revokeDelegation: pre-flight expiry check failed`,{error:e}),l=1n}if(l===0n)throw new h(`No active delegation found for delegate ${a} on contract ${i}.`);return this.#i({operation:`revokeDelegation`,signer:e,contractAddress:t,config:D(c,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===k?{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(O(r,(0,o.getAddress)(t),(0,o.getAddress)(n),(0,o.getAddress)(e)))}async#i({operation:e,signer:t,contractAddress:r,config:i}){try{return await n.n({operation:e,signer:t,provider:this.#t,config:i,emit:e=>this.#n(e,r),logger:this.#r})}catch(e){throw this.#a(e),e}}#a(e){if(!(e instanceof n.b))return;let t=me(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 h||t instanceof g){let n=(0,o.getAddress)(e);r.set(n,t);return}throw t}})),r}async assertDelegationActive(e,t,n){let r=(0,o.getAddress)(e),i=(0,o.getAddress)(t),a=(0,o.getAddress)(n),{isActive:s,expiryTimestamp:c}=await this.getStatus({contractAddress:r,delegatorAddress:i,delegateAddress:a});if(!s)throw c===0n?new h(`No active delegation from ${i} to ${a} for ${r}`):new g(`Delegation from ${i} to ${a} for ${r} has expired`)}},ge=class{#e;#t;constructor({router:e,emitEvent:t}){this.#e=e,this.#t=t}async encryptValues(t,r){let i=Date.now(),a=(0,o.getAddress)(t.contractAddress);try{this.#t({type:n.s.EncryptStart},a);let e=await this.#e.relayer.encryptValues({...t,options:r});return this.#t({type:n.s.EncryptEnd,durationMs:Date.now()-i},a),e}catch(t){throw this.#t({type:n.s.EncryptError,error:e.g(t),durationMs:Date.now()-i},a),te(t,`Encryption failed`)}}},_e=class{#e;#t;#n;#r;#i;#a=new Set;#o;constructor(e){this.#e=e.signer,this.#t=e.router,this.#n=e.cachingService,this.#r=e.credentialService,this.#i=e.logger,this.#e&&(this.#o=this.#e.walletAccount.subscribe(e=>{this.#s(e).catch(e=>{this.#i.warn(`wallet account handler failed`,{error:e})})}))}onWalletAccountChange(e){return this.#a.add(e),()=>{this.#a.delete(e)}}dispose(){this.#o?.(),this.#o=void 0,this.#a.clear()}async#s(e){let n=e.previous,r=e.next,i=r?.chainId;i!==void 0&&await t.L(`switch relayer chain`,()=>this.#t.switchChain(i),this.#i);let a=this.#r;a&&await t.L(`credential wallet account change`,()=>a.handleWalletAccountChange(n,r),this.#i),n&&await t.L(`clear decrypt cache`,()=>this.#n.clearForRequester(n.address),this.#i),await Promise.all(Array.from(this.#a,n=>t.L(`wallet account listener`,()=>n(e),this.#i)))}};function F(e){return(0,o.keccak256)((0,o.toBytes)(e))}const I={ConfidentialTransfer:F(`ConfidentialTransfer(address,address,bytes32)`),Wrap:F(`Wrap(address,uint256,bytes32)`),UnwrapRequested:F(`UnwrapRequested(address,bytes32,bytes32)`),UnwrapFinalized:F(`UnwrapFinalized(address,bytes32,bytes32,uint64)`)};function L(e){return(0,o.getAddress)(A(e.slice(-40)))}function R(e){return e}function z(e,t){let n=2+t*64,r=e.slice(n,n+64);return r.length===64?r:r.padEnd(64,`0`)}function B(e,t){return(0,o.getAddress)(A(z(e,t).slice(-40)))}function V(e,t){return BigInt(`0x`+z(e,t))}function H(e,t){return A(z(e,t))}function U(e){return e.topics[0]!==I.ConfidentialTransfer||e.topics.length<4?null:{eventName:`ConfidentialTransfer`,from:L(e.topics[1]),to:L(e.topics[2]),encryptedAmount:R(e.topics[3])}}function W(e){return e.topics[0]!==I.Wrap||e.topics.length<2?null:{eventName:`Wrap`,to:L(e.topics[1]),roundedAmount:V(e.data,0),encryptedWrappedAmount:H(e.data,1)}}function G(e){return e.topics[0]!==I.UnwrapRequested||e.topics.length<3?null:{eventName:`UnwrapRequested`,receiver:L(e.topics[1]),unwrapRequestId:R(e.topics[2]),encryptedAmount:H(e.data,0)}}function K(e){return e.topics[0]!==I.UnwrapFinalized||e.topics.length<3?null:{eventName:`UnwrapFinalized`,receiver:L(e.topics[1]),unwrapRequestId:R(e.topics[2]),encryptedAmount:H(e.data,0),cleartextAmount:V(e.data,1)}}function q(e){return U(e)??W(e)??G(e)??K(e)}function ve(e){let t=[];for(let n of e){let e=q(n);e&&t.push(e)}return t}function J(e){for(let t of e){let e=G(t);if(e)return e}return null}function ye(e){for(let t of e){let e=W(t);if(e)return e}return null}const be=[I.ConfidentialTransfer,I.Wrap,I.UnwrapRequested,I.UnwrapFinalized],Y={DelegatedForUserDecryption:F(`DelegatedForUserDecryption(address,address,address,uint64,uint64,uint64)`),RevokedDelegationForUserDecryption:F(`RevokedDelegationForUserDecryption(address,address,address,uint64,uint64)`)};function X(e){return e.topics[0]!==Y.DelegatedForUserDecryption||e.topics.length<3?null:{eventName:`DelegatedForUserDecryption`,delegator:L(e.topics[1]),delegate:L(e.topics[2]),contractAddress:B(e.data,0),delegationCounter:V(e.data,1),oldExpirationDate:V(e.data,2),newExpirationDate:V(e.data,3)}}function Z(e){return e.topics[0]!==Y.RevokedDelegationForUserDecryption||e.topics.length<3?null:{eventName:`RevokedDelegationForUserDecryption`,delegator:L(e.topics[1]),delegate:L(e.topics[2]),contractAddress:B(e.data,0),delegationCounter:V(e.data,1),oldExpirationDate:V(e.data,2)}}function Q(e){return X(e)??Z(e)}function xe(e){let t=[];for(let n of e){let e=Q(n);e&&t.push(e)}return t}function Se(e){for(let t of e){let e=X(t);if(e)return e}return null}function Ce(e){for(let t of e){let e=Z(t);if(e)return e}return null}const we=[Y.DelegatedForUserDecryption,Y.RevokedDelegationForUserDecryption];function $(e){return`zama:pending-unshield:${i.c(e)}`}const Te=s.z.union([s.z.pipe(i.u,s.z.transform(e=>({unwrapTxHash:e}))),s.z.pipe(s.z.object({version:s.z.literal(1),unwrapTxHash:i.u,unwrapRequestId:s.z.optional(i.u)}),s.z.transform(({unwrapTxHash:e,unwrapRequestId:t})=>({unwrapTxHash:e,unwrapRequestId:t})))]);async function Ee(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 De(e,t){return(await Oe(e,t))?.unwrapTxHash??null}async function Oe(e,t){let n=$(t),r=await e.get(n);if(r==null)return null;let i=Te.safeParse(r);return i.success?i.data:(await e.delete(n),null)}async function ke(e,t){await e.delete($(t))}var Ae=class extends n.t{#e;#t=null;#n=null;#r(e){try{return n.l(this.sdk.signer,`WrappedToken.sdk.signer`),this.sdk.signer}catch(n){throw new t.R(e,{cause:n})}}async underlying(){return this.#s()}async isPayable(){if(this.#n!==null)return this.#n;try{let e=await this.#s();this.#n=await this.sdk.provider.readContract(t.p(e))}catch{this.#n=!1}return this.#n}async allowance(e){let n=await this.#s();return this.sdk.provider.readContract(t.h(n,(0,o.getAddress)(e),this.address))}async shield(r,i){let a=await n.u(`shield`,this.sdk.signer,this.sdk.provider),s=await this.isPayable(),c=await this.#s(),l=(0,o.getAddress)(a.address),u;try{u=await this.sdk.provider.readContract(t._(c,l))}catch(t){throw t instanceof e.r?t:new n.m(`Could not read ERC-20 balance for shield validation (token: ${c})`,{cause:e.g(t)})}if(u<r)throw new n._(`Insufficient ERC-20 balance: requested ${r}, available ${u} (token: ${c})`,{requested:r,available:u,token:c});return s?this.#i(r,c,l,i):this.#a(r,l,i)}async#i(e,t,n,r){this.#r(`shield`);let i=r?.to?(0,o.getAddress)(r.to):n,a=i===n?`0x`:i;return this.submitTransaction({operation:`shield:transferAndCall`,config:w(t,this.address,e,a),onSubmitted:r?.onShieldSubmitted})}async wrap(r,i){this.#r(`wrap`);let a=await n.u(`wrap`,this.sdk.signer,this.sdk.provider),s=await this.#s(),c=(0,o.getAddress)(a.address),l;try{l=await this.sdk.provider.readContract(t._(s,c))}catch(t){throw t instanceof e.r?t:new n.m(`Could not read ERC-20 balance for wrap validation (token: ${s})`,{cause:e.g(t)})}if(l<r)throw new n._(`Insufficient ERC-20 balance: requested ${r}, available ${l} (token: ${s})`,{requested:r,available:l,token:s});let u;try{u=await this.sdk.provider.readContract(t.h(s,c,this.address))}catch(t){throw t instanceof e.r?t:new n.m(`Could not read ERC-20 allowance for wrap validation (token: ${s})`,{cause:e.g(t)})}if(u<r)throw new n.h(`Insufficient allowance for wrap: requested ${r}, approved ${u}. Call approveUnderlying() first (token: ${s}).`,{requested:r,available:u,token:s});let d=i?.to?(0,o.getAddress)(i.to):c;return this.submitTransaction({operation:`wrap`,config:t.I(this.address,d,r),onSubmitted:i?.onWrapSubmitted})}async#a(e,n,r){this.#r(`shield`);let i=r?.approvalStrategy??`exact`;i!==`skip`&&await this.#l(e,i===`max`,r);let a=r?.to?(0,o.getAddress)(r.to):n;return this.submitTransaction({operation:`shield:approveAndWrap`,config:t.I(this.address,a,e),onSubmitted:r?.onShieldSubmitted})}async approveUnderlying(e){this.#r(`approveUnderlying`);let r=await n.u(`approveUnderlying`,this.sdk.signer,this.sdk.provider),i=await this.#s(),a=(0,o.getAddress)(r.address),s=e??2n**256n-1n;return s>0n&&await this.sdk.provider.readContract(t.h(i,a,this.address))>0n&&await this.submitTransaction({operation:`approveUnderlying:reset`,config:t.g(i,this.address,0n)}),this.submitTransaction({operation:`approveUnderlying`,config:t.g(i,this.address,s)})}async unshield(e,n){let{skipBalanceCheck:r=!1,onUnwrapSubmitted:i,onFinalizing:a,onFinalizeSubmitted:o}=n??{};r||await this.assertConfidentialBalance(e);let s={onFinalizing:a,onFinalizeSubmitted:o},c=crypto.randomUUID(),l=await this.unwrap(e);return t.L(`unshield: onUnwrapSubmitted`,()=>i?.(l.txHash),this.sdk.logger),this.#c(l.unwrapRequestId,l.txHash,c,s)}async unshieldAll(e){let n=crypto.randomUUID(),r=await this.unwrapAll();return t.L(`unshieldAll: onUnwrapSubmitted`,()=>e?.onUnwrapSubmitted?.(r.txHash),this.sdk.logger),this.#c(r.unwrapRequestId,r.txHash,n,e)}async resumeUnshield(t,r){let i;try{i=await this.sdk.provider.waitForTransactionReceipt(t)}catch(t){throw t instanceof e.r?t:new n.b(`Failed to get unwrap receipt`,{cause:t})}let a=this.#o(i.logs);return this.#c(a,t,crypto.randomUUID(),r)}async getPendingUnshield(){return De(this.sdk.storage,this.address)}async unwrap(e){this.#r(`unwrap`);let r=(0,o.getAddress)((await n.u(`unwrap`,this.sdk.signer,this.sdk.provider)).address),{encryptedValues:i,inputProof:a}=await this.sdk.encrypt({values:[{value:e,type:`euint64`}],contractAddress:this.address,userAddress:r}),[s]=i;if(!s)throw new n.S(`Encryption returned no encrypted values`);let c=await this.submitTransaction({operation:`unwrap`,config:t.P(this.address,r,r,s,a)});return{...c,unwrapRequestId:this.#o(c.receipt.logs)}}async unwrapAll(){this.#r(`unwrapAll`);let e=(0,o.getAddress)((await n.u(`unwrapAll`,this.sdk.signer,this.sdk.provider)).address),r=await this.readConfidentialBalanceOf(e);if(n.a(r))throw new n.x(`Cannot unshield: balance is zero`);let i=await this.submitTransaction({operation:`unwrapAll`,config:t.F(this.address,e,e,r)});return{...i,unwrapRequestId:this.#o(i.receipt.logs)}}async finalizeUnwrap(e){this.#r(`finalizeUnwrap`),await n.d(`finalizeUnwrap`,this.sdk.signer,this.sdk.provider);let r=await this.sdk.decryption.decryptPublicValues([e]),i=r.clearValues[e];return n.c(i,`finalizeUnwrap: clearValue`),this.submitTransaction({operation:`finalizeUnwrap`,config:t.O(this.address,e,i,r.decryptionProof)})}#o(e){let t=J(e);if(!t)throw new n.b(`No UnwrapRequested event found in unwrap receipt`);return t.unwrapRequestId}async#s(){return this.#e===void 0?(this.#t||=this.sdk.provider.readContract(t.N(this.address)).then(e=>(this.#e=e,this.#t=null,e)).catch(e=>{throw this.#t=null,e}),this.#t):this.#e}async#c(e,r,i,a){this.emit({type:n.s.UnshieldPhase1Submitted,txHash:r,operationId:i}),await t.L(`unshield: savePendingUnshield`,()=>Ee(this.sdk.storage,this.address,r),this.sdk.logger),this.emit({type:n.s.UnshieldPhase2Started,operationId:i}),t.L(`unshield: onFinalizing`,()=>a?.onFinalizing?.(),this.sdk.logger);let o=await this.finalizeUnwrap(e);return this.emit({type:n.s.UnshieldPhase2Submitted,txHash:o.txHash,operationId:i}),t.L(`unshield: onFinalizeSubmitted`,()=>a?.onFinalizeSubmitted?.(o.txHash),this.sdk.logger),await t.L(`unshield: clearPendingUnshield`,()=>ke(this.sdk.storage,this.address),this.sdk.logger),o}async#l(e,r,i){this.#r(`approveUnderlying`);let a=await this.#s(),s=(0,o.getAddress)((await n.u(`approveUnderlying`,this.sdk.signer,this.sdk.provider)).address),c=await this.sdk.provider.readContract(t.h(a,s,this.address));if(c>=e)return;c>0n&&await this.submitTransaction({operation:`approveUnderlying:reset`,config:t.g(a,this.address,0n)});let l=r?2n**256n-1n:e;await this.submitTransaction({operation:`approveUnderlying`,config:t.g(a,this.address,l),onSubmitted:i?.onApprovalSubmitted})}},je=class{#e;provider;signer;storage;registry;permits;delegations;decryption;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;constructor(e){this.#e=e.router,this.provider=e.provider,this.signer=e.signer,this.storage=e.storage,this.#r=e.onEvent??function(){},this.#i=e.logger,this.#a=new se(e.storage,this.#i),this.#u=new he({provider:this.provider,router:e.router,emitEvent:this.emitEvent.bind(this),logger:this.#i});let t={};for(let n of e.chains)n.registryAddress&&(t[n.id]=n.registryAddress);this.registry=new i.o({provider:this.provider,registryAddresses:t,registryTTL:e.registryTTL}),this.#n=t,this.#t=e.registryTTL,e.signer&&(this.#l=new i.s({router:e.router,signer:e.signer,transportKeyPairTTL:e.transportKeyPairTTL,permitTTL:e.permitTTL,scope:e.transportKeyPairScope,storage:this.storage,permitStorage:e.permitStorage,logger:this.#i}),this.#c=new de({cache:this.#a,credentialService:this.#l,delegationService:this.#u,router:e.router,emitEvent:this.emitEvent.bind(this)})),this.#s=new ge({router:e.router,emitEvent:this.emitEvent.bind(this)}),this.#o=new _e({signer:e.signer,router:e.router,cachingService:this.#a,credentialService:this.#l,logger:this.#i}),this.permits=new N({signer:this.signer,provider:this.provider,cachingService:this.#a,credentialService:this.#l,logger:this.#i}),this.delegations=new M({signer:this.signer,provider:this.provider,delegationService:this.#u}),this.decryption=new j({signer:this.signer,provider:this.provider,router:e.router,decryptionService:this.#c})}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 i.o({provider:this.provider,registryAddresses:{...this.#n,...e},registryTTL:this.#t})}async encrypt(e,t){return this.#s.encryptValues(e,t)}createToken(e){return new n.t(this,e)}createWrappedToken(e){return new Ae(this,e)}dispose(){this.#o.dispose()}terminate(){this.dispose(),this.signer?.dispose?.()}[Symbol.dispose](){this.terminate()}},Me=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 Ne=new Me;exports.ACL_TOPICS=we,exports.AclPausedError=b,exports.AclTopics=Y,exports.BalanceCheckUnavailableError=n.p,exports.BaseSigner=i.t,exports.ChainMismatchError=n.v,exports.ChromeSessionStorage=Me,exports.ConfigurationError=e.t,exports.Decryption=j,exports.DecryptionFailedError=n.x,exports.DefaultRegistryAddresses=i.a,exports.DelegationContractIsSelfError=y,exports.DelegationCooldownError=m,exports.DelegationDelegateEqualsContractError=v,exports.DelegationExpirationTooSoonError=x,exports.DelegationExpiredError=g,exports.DelegationExpiryUnchangedError=_,exports.DelegationNotFoundError=h,exports.DelegationNotPropagatedError=S,exports.DelegationSelfNotAllowedError=p,exports.Delegations=M,exports.ERC1363_INTERFACE_ID=t.c,exports.ERC20ReadFailedError=n.m,exports.ERC7984_INTERFACE_ID=t.l,exports.ERC7984_WRAPPER_INTERFACE_ID=t.u,exports.EncryptionFailedError=n.S,exports.IndexedDBStorage=i.h,exports.InsufficientAllowanceError=n.h,exports.InsufficientConfidentialBalanceError=n.g,exports.InsufficientERC20BalanceError=n._,exports.InvalidTransportKeyPairError=u,exports.MemoryStorage=i.p,exports.MutableWalletAccountStore=i.n,exports.NoCiphertextError=d,exports.NotEntitledError=f,exports.Permits=N,exports.RelayerRequestFailedError=e.n,exports.RpcRateLimitError=n.y,exports.SignerNotConfiguredError=t.R,exports.SignerRequiredError=t.z,exports.SigningFailedError=t.U,exports.SigningRejectedError=t.W,exports.TOKEN_TOPICS=be,exports.Token=n.t,exports.Topics=I,exports.TransactionRevertedError=n.b,exports.TransportKeyPairExpiredError=l,exports.WalletAccountNotReadyError=t.B,exports.WalletNotConnectedError=t.V,exports.WrappedToken=Ae,exports.WrappersRegistry=i.o,exports.ZERO_ENCRYPTED_VALUE=n.r,exports.ZamaError=e.r,exports.ZamaErrorCode=e.i,exports.ZamaSDK=je,exports.ZamaSDKEvents=n.s,exports.allowanceContract=t.h,exports.anvil=a.t,exports.approveContract=t.g,exports.balanceOfContract=t._,exports.bscTestnet=a.n,exports.chains=a.r,exports.chromeSessionStorage=Ne,exports.cleartext=r.t,exports.confidentialBalanceOfContract=t.S,exports.confidentialTotalSupplyContract=t.C,exports.confidentialTransferContract=t.T,exports.confidentialTransferFromContract=t.D,exports.createConfig=ie,exports.createWalletAccountStore=i.r,exports.decimalsContract=t.v,exports.decodeAclEvent=Q,exports.decodeAclEvents=xe,exports.decodeConfidentialTransfer=U,exports.decodeDelegatedForUserDecryption=X,exports.decodeOnChainEvent=q,exports.decodeOnChainEvents=ve,exports.decodeRevokedDelegationForUserDecryption=Z,exports.decodeUnwrapFinalized=K,exports.decodeUnwrapRequested=G,exports.decodeWrap=W,exports.delegateForUserDecryptionContract=E,exports.finalizeUnwrapContract=t.O,exports.findDelegatedForUserDecryption=Se,exports.findRevokedDelegationForUserDecryption=Ce,exports.findUnwrapRequested=J,exports.findWrap=ye,exports.getConfidentialTokenAddressContract=t.t,exports.getDelegationExpiryContract=O,exports.getTokenAddressContract=t.n,exports.getTokenPairContract=t.r,exports.getTokenPairsContract=t.i,exports.getTokenPairsLengthContract=t.a,exports.getTokenPairsSliceContract=t.o,exports.hardhat=a.i,exports.hoodi=a.a,exports.indexedDBStorage=i.g,exports.inferredTotalSupplyContract=t.k,exports.ingenTestnet=a.o,exports.isConfidentialTokenContract=t.d,exports.isConfidentialTokenValidContract=t.s,exports.isConfidentialWrapperContract=t.f,exports.isEncryptedValueZero=n.a,exports.isHandleDelegatedContract=re,exports.isOperatorContract=t.A,exports.isRetryable=e.a,exports.mainnet=a.s,exports.matchZamaError=c,exports.memoryStorage=i.m,exports.nameContract=t.b,exports.rateContract=t.j,exports.resolveChainRelayers=i.d,exports.resolveStorage=i.f,exports.retryAfterSeconds=e.o,exports.revokeDelegationContract=D,exports.sepolia=a.c,exports.setOperatorContract=t.M,exports.supportsInterfaceContract=t.m,exports.symbolContract=t.x,exports.transferAndCallContract=w,exports.underlyingContract=t.N,exports.unwrapContract=t.P,exports.unwrapFromBalanceContract=t.F,exports.wrapContract=t.I;
2
2
  //# sourceMappingURL=index.cjs.map