@zama-fhe/sdk 3.7.0-beta.8 → 3.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/dist/cjs/base-signer.cjs +1 -1
  2. package/dist/cjs/base-signer.cjs.map +1 -1
  3. package/dist/cjs/chains/index.cjs +1 -1
  4. package/dist/cjs/chains.cjs +1 -1
  5. package/dist/cjs/chains.cjs.map +1 -1
  6. package/dist/cjs/erc165.cjs +1 -1
  7. package/dist/cjs/erc165.cjs.map +1 -1
  8. package/dist/cjs/fhevm-relayer.cjs +1 -1
  9. package/dist/cjs/fhevm-relayer.cjs.map +1 -1
  10. package/dist/cjs/index.cjs +1 -1
  11. package/dist/cjs/index.cjs.map +1 -1
  12. package/dist/cjs/node/index.cjs +1 -1
  13. package/dist/cjs/telemetry.cjs +1 -1
  14. package/dist/cjs/telemetry.cjs.map +1 -1
  15. package/dist/cjs/token.cjs +1 -1
  16. package/dist/cjs/token.cjs.map +1 -1
  17. package/dist/cjs/vaults/index.cjs +1 -1
  18. package/dist/cjs/web/index.cjs +1 -1
  19. package/dist/cjs/wrapped-token.cjs +1 -1
  20. package/dist/esm/{base-signer-46j6PRq-.d.ts → base-signer-BxIDBDTF.d.ts} +2 -2
  21. package/dist/esm/base-signer-ClrhHzbm.js +2 -0
  22. package/dist/esm/base-signer-ClrhHzbm.js.map +1 -0
  23. package/dist/esm/chains/index.d.ts +2 -2
  24. package/dist/esm/chains/index.js +1 -1
  25. package/dist/esm/{chains-iPpnjXql.js → chains-BwlDI944.js} +2 -2
  26. package/dist/esm/chains-BwlDI944.js.map +1 -0
  27. package/dist/esm/cleartext/index.d.ts +2 -2
  28. package/dist/esm/cleartext/index.js +1 -1
  29. package/dist/esm/{cleartext-DInZ0vz-.d.ts → cleartext-BnTAN4-g.d.ts} +2 -2
  30. package/dist/esm/{cleartext-C0ba9z6Z.js → cleartext-DBZq4E1O.js} +2 -2
  31. package/dist/esm/{cleartext-C0ba9z6Z.js.map → cleartext-DBZq4E1O.js.map} +1 -1
  32. package/dist/esm/erc165-BAd2z3ay.js +2 -0
  33. package/dist/esm/erc165-BAd2z3ay.js.map +1 -0
  34. package/dist/esm/ethers/index.d.ts +4 -4
  35. package/dist/esm/ethers/index.js +1 -1
  36. package/dist/esm/fhevm-relayer-BEQ31nmT.js +8 -0
  37. package/dist/esm/{fhevm-relayer-BWhXU1WB.js.map → fhevm-relayer-BEQ31nmT.js.map} +1 -1
  38. package/dist/esm/{index-DHMs4ZRb.d.ts → index-BlY7CCPB.d.ts} +7 -7
  39. package/dist/esm/{decryption-q0ODuDDS.d.ts → index-CD2sMpst.d.ts} +3 -7
  40. package/dist/esm/{index-Cdbp_93f.d.ts → index-D1Wtji3m.d.ts} +4 -26
  41. package/dist/esm/{index-C1clixw5.d.ts → index-fsWBYM8S.d.ts} +4 -4
  42. package/dist/esm/index.d.ts +9 -10
  43. package/dist/esm/index.js +1 -1
  44. package/dist/esm/index.js.map +1 -1
  45. package/dist/esm/node/index.d.ts +5 -5
  46. package/dist/esm/node/index.js +1 -1
  47. package/dist/esm/node/index.js.map +1 -1
  48. package/dist/esm/query/index.d.ts +5 -6
  49. package/dist/esm/query/index.js +1 -1
  50. package/dist/esm/telemetry-CBSzrmab.js +2 -0
  51. package/dist/esm/{telemetry-DvJV3oBk.js.map → telemetry-CBSzrmab.js.map} +1 -1
  52. package/dist/esm/token-CTvEGQmH.js +2 -0
  53. package/dist/esm/token-CTvEGQmH.js.map +1 -0
  54. package/dist/esm/{types-Bz42Emet.d.ts → types-C2ccCjoA.d.ts} +3 -3
  55. package/dist/esm/{types-BIgPY1yI.d.ts → types-CHepK8MK.d.ts} +2 -2
  56. package/dist/esm/{types-I9lJwH20.d.ts → types-Dc1fpXWt.d.ts} +3 -3
  57. package/dist/esm/vaults/index.d.ts +2 -3
  58. package/dist/esm/vaults/index.js +1 -1
  59. package/dist/esm/viem/index.d.ts +4 -4
  60. package/dist/esm/viem/index.js +1 -1
  61. package/dist/esm/web/index.d.ts +17 -2
  62. package/dist/esm/web/index.js +1 -1
  63. package/dist/esm/wrapped-token-IDUEFpZx.js +2 -0
  64. package/dist/esm/{wrapped-token-3usJd0oi.js.map → wrapped-token-IDUEFpZx.js.map} +1 -1
  65. package/package.json +1 -15
  66. package/dist/cjs/fatal-batch.cjs +0 -2
  67. package/dist/cjs/fatal-batch.cjs.map +0 -1
  68. package/dist/cjs/internal/index.cjs +0 -2
  69. package/dist/cjs/internal/index.cjs.map +0 -1
  70. package/dist/cjs/signing.cjs +0 -2
  71. package/dist/cjs/signing.cjs.map +0 -1
  72. package/dist/esm/base-signer-CNHZZnr2.js +0 -2
  73. package/dist/esm/base-signer-CNHZZnr2.js.map +0 -1
  74. package/dist/esm/chains-iPpnjXql.js.map +0 -1
  75. package/dist/esm/encrypt-worker-client-CKTlhAGI.d.ts +0 -19
  76. package/dist/esm/erc165-B8gx2luK.js +0 -2
  77. package/dist/esm/erc165-B8gx2luK.js.map +0 -1
  78. package/dist/esm/fatal-batch-BiiS7KdS.js +0 -2
  79. package/dist/esm/fatal-batch-BiiS7KdS.js.map +0 -1
  80. package/dist/esm/fhevm-relayer-BWhXU1WB.js +0 -8
  81. package/dist/esm/index-B09m_e9L.d.ts +0 -1
  82. package/dist/esm/internal/index.d.ts +0 -26
  83. package/dist/esm/internal/index.js +0 -2
  84. package/dist/esm/internal/index.js.map +0 -1
  85. package/dist/esm/signing-C6nbPCyd.js +0 -2
  86. package/dist/esm/signing-C6nbPCyd.js.map +0 -1
  87. package/dist/esm/telemetry-DvJV3oBk.js +0 -2
  88. package/dist/esm/token-g6sinwTx.js +0 -2
  89. package/dist/esm/token-g6sinwTx.js.map +0 -1
  90. package/dist/esm/wrapped-token-3usJd0oi.js +0 -2
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./relayer.cjs"),t=require("./signing.cjs"),n=require("./encryption.cjs"),r=require("./erc165.cjs"),i=require("./fatal-batch.cjs"),a=require("./token.cjs"),o=require("./wrapped-token.cjs"),s=require("./telemetry.cjs"),c=require("./cleartext.cjs"),l=require("./base-signer.cjs"),u=require("./primitives.cjs"),d=require("./validation.cjs"),f=require("./wrappers-registry.cjs"),p=require("./chains.cjs");let m=require("viem"),h=require("zod/mini");function g(t,n){if(t instanceof e.r){let e=n[t.code];if(e)return e(t)}return n._?.(t)}var _=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}},v=class extends e.r{constructor(t,n){super(e.i.DelegationSelfNotAllowed,t,n),this.name=`DelegationSelfNotAllowedError`}},y=class extends e.r{constructor(t,n){super(e.i.DelegationCooldown,t,n),this.name=`DelegationCooldownError`}},b=class extends e.r{constructor(t,n){super(e.i.DelegationNotFound,t,n),this.name=`DelegationNotFoundError`}},x=class extends e.r{constructor(t,n){super(e.i.DelegationExpired,t,n),this.name=`DelegationExpiredError`}},S=class extends e.r{constructor(t,n){super(e.i.DelegationExpiryUnchanged,t,n),this.name=`DelegationExpiryUnchangedError`}},C=class extends e.r{constructor(t,n){super(e.i.DelegationDelegateEqualsContract,t,n),this.name=`DelegationDelegateEqualsContractError`}},w=class extends e.r{constructor(t,n){super(e.i.DelegationDelegateCannotBeWildcard,t,n),this.name=`DelegationDelegateCannotBeWildcardError`}},T=class extends e.r{constructor(t,n){super(e.i.DelegationContractIsSelf,t,n),this.name=`DelegationContractIsSelfError`}},E=class extends e.r{constructor(t,n){super(e.i.AclPaused,t,n),this.name=`AclPausedError`}},D=class extends e.r{constructor(t,n){super(e.i.DelegationExpirationTooSoon,t,n),this.name=`DelegationExpirationTooSoonError`}},O=class extends e.r{constructor(t,n){super(e.i.DelegationNotPropagated,t,n),this.name=`DelegationNotPropagatedError`}};const ee=[n.t,t.o,e.n,O,t.n,t.t,_,i.r,t.i,t.l];function k(r,a,o={}){if(ee.some(e=>r instanceof e))return r;let s=r instanceof Error?r.message:a;if(r instanceof Error&&e.p(r.message))return new t.i(r.message,{cause:r});if(e._(r))return new t.l(`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:r});if(r instanceof Error&&e.m(r.message))return o.isDelegated?new O(`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:r}):new _({encryptedValue:e.b(r.message)??``,contractAddress:o.contractAddress??``,account:o.account??``},{cause:r});if(e.d(r))return new i.r(s,{cause:r,retryAfter:e.c(r)});let c=e.s(r);return c===void 0&&e.v(r)?new i.r(s,{cause:r,retryAfter:e.c(r)}):c===400?new t.o(r instanceof Error?r.message:`No ciphertext for this account`,{cause:r}):o.isDelegated&&c===500?new O(`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:r}):e.h(r)||c!==void 0?new e.n(s,c,{cause:r,retryAfter:e.c(r),retryable:e.g(r)||void 0}):new n.t(a,{cause:r})}function te(t,r){if(t instanceof e.r)return t;let i=e.s(t),a=e.g(t);return i!==void 0||e.h(t)?new e.n(t instanceof Error?t.message:r,i,{cause:t,retryAfter:e.c(t),retryable:a||void 0}):new n.r(r,{cause:t})}const A=[{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 j(e,t,n,r){return{address:e,abi:A,functionName:`delegateForUserDecryption`,args:[t,n,r]}}function M(e,t,n){return{address:e,abi:A,functionName:`revokeDelegationForUserDecryption`,args:[t,n]}}function N(e,t,n,r){return{address:e,abi:A,functionName:`getUserDecryptionDelegationExpirationDate`,args:[t,n,r]}}function ne(e,t,n,r,i){return{address:e,abi:A,functionName:`isHandleDelegatedForUserDecryption`,args:[t,n,r,i]}}const P=2n**64n-1n,F=`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`;function re(e){return l.i(e.signer,e.provider,e)}var I=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 r.V(this.#r,e)}#s(e,t){throw this.#a({type:r.F.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 a.o(`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 a.o(`grantDelegationPermit`,this.#e,this.#t)}catch(e){this.#s(`grantDelegationPermit`,e)}await n.grantPermit(t,e)}async hasPermit(e){return this.#r?this.#r.hasPermit(e):!1}async hasDelegationPermit(e,t){return this.#r?this.#r.hasPermit(t,e):!1}async warmTransportKeyPair(){let e=this.#r;if(!e)return;let t=this.#e?.walletAccount.getSnapshot();t&&await e.warmTransportKeyPair(t.address)}registerPermit(e,t){return this.batchRegisterPermits([{prepared:e,signature:t}])}async batchRegisterPermits(e){let t;try{t=this.#o(`registerPermit`)}catch(e){this.#s(`registerPermit`,e)}await t.batchRegisterPermits(e),await Promise.all([...new Set(e.map(e=>e.prepared.signerAddress))].map(e=>this.#c(e)))}async revokePermits(e){let t=this.#o(`revokePermits`),n=(0,m.getAddress)((await a.a(`revokePermits`,this.#e,this.#t)).address);try{await t.revokePermits(e)}finally{await this.#c(n)}}async clear(){let e=this.#o(`clear`),t=(0,m.getAddress)((await a.a(`clear`,this.#e,this.#t)).address);try{await e.clearCredentials()}finally{await this.#c(t)}}async#c(e){await r.j(`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)}},L=class{#e;#t;#n;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.delegationService}#r(e){return r.V(this.#e,e)}async delegateDecryption({contractAddress:e,delegateAddress:t,expirationDate:n}){let r=this.#r(`delegateDecryption`),i=await a.a(`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 a.a(`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)}},R=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 r.V(this.#r,e)}async decryptValues(e,t){let n=this.#i(`decryptValues`),r=await a.a(`decryptValues`,this.#e,this.#t);return n.decryptValues(e,r.address,s.r(t,`decrypt-values`))}async delegatedDecryptValues(e,t,n=t,r){let i=this.#i(`delegatedDecryptValues`),o=await a.a(`delegatedDecryptValues`,this.#e,this.#t);return i.delegatedDecryptValues(e,t,o.address,n,s.r(r,`delegated-decrypt-values`))}async decryptPublicValues(e,t){if(e.length===0)return{clearValues:{},decryptionProof:`0x`,abiEncodedClearValues:`0x`};let n=s.r(t,`decrypt-public-values`);try{let t=await this.#n.relayer.decryptPublicValuesWithSignatures({encryptedValues:e,options:n}),i={};return t.checkSignaturesArgs.handlesList.forEach((e,n)=>{r.P(t.clearValues[n],`result.clearValues[${n}]`),i[e]=t.clearValues[n].value}),{clearValues:i,abiEncodedClearValues:t.checkSignaturesArgs.abiEncodedCleartexts,decryptionProof:t.checkSignaturesArgs.decryptionProof}}catch(e){throw k(e,`Public decryption failed`)}}async delegatedBatchDecryptValues({encryptedInputs:e,delegatorAddress:t,accountAddress:n=t,maxConcurrency:r,waitForPropagation:i,operation:o}){let s=this.#i(`delegatedBatchDecryptValues`),c=await a.a(`delegatedBatchDecryptValues`,this.#e,this.#t);return s.delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:c.address,accountAddress:n,maxConcurrency:r,waitForPropagation:i,operation:o??`delegated-batch-decrypt-values`})}},z=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}prepare(e,t){return this.#e.prepare(e,t)}preparePermit(e){return this.#t.preparePermit(e)}batchPreparePermits(e){return this.#t.batchPreparePermits(e)}},B=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 ie=new B,ae=h.z.union([h.z.bigint(),h.z.boolean(),u.n]),oe=h.z.array(h.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,m.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,m.getAddress)(e)}:${(0,m.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.t(`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=u.t(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,m.getAddress)(t);return this.#s(e,{requesterAddress:r,errorMessage:`Failed to decrypt encrypted values`},n)}async delegatedDecryptValues(e,t,n,r,i){let a=(0,m.getAddress)(t),o=(0,m.getAddress)(n),s={spent:!1};return this.#a(i?.waitForPropagation??!0,()=>this.#s(e,{requesterAddress:(0,m.getAddress)(r),delegator:a,validate:e=>this.#m(e,{delegatorAddress:a,delegateAddress:o}),errorMessage:`Failed to decrypt delegated encrypted values`},{operation:i?.operation},s))}async#a(e,t){let n;for(let r=0;r<16;r++)try{return await t()}catch(t){if(n=t,!(r<15&&e&&t instanceof O))throw t;await ue(2e3)}throw n}async delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:n,accountAddress:r,maxConcurrency:o=5,waitForPropagation:s=!0,operation:c}){let l=e.map(e=>({encryptedValue:e.encryptedValue,contractAddress:(0,m.getAddress)(e.contractAddress)}));if(l.length===0)return{items:l};let u=(0,m.getAddress)(r);try{let e=await this.delegatedDecryptValues(l.map(({encryptedValue:e,contractAddress:t})=>({encryptedValue:e,contractAddress:t})),t,n,u,{waitForPropagation:s,operation:c});for(let t of l)this.#d(t,e);return{items:l}}catch(e){if(i.n(e))throw e;if(l.length===1){let[n=this.#p()]=l;return n.error=this.#f(e,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:n.contractAddress,account:(0,m.getAddress)(t)}),{items:l}}}let d=!1,f;if(await a.r(l.map(e=>async()=>{if(!d)try{let r=await this.delegatedDecryptValues([{encryptedValue:e.encryptedValue,contractAddress:e.contractAddress}],t,n,u,{waitForPropagation:!1,operation:c});this.#d(e,r)}catch(n){if(i.n(n)){d=!0,f??=n;return}e.error=this.#f(n,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:e.contractAddress,account:(0,m.getAddress)(t)})}}),o),f!==void 0)throw f;return{items:l}}async#o(t,n,r,i){let a=ce(t,n),o;try{o=await this.#r.relayer.parseTransportKeyPair({publicKey:a.publicKey,privateKey:a.privateKey,tkmsVersion:t.keypair.tkmsVersion})}catch(t){throw t instanceof Error&&e.p(t.message)&&await this.#t.evictTransportKeyPair(),t}let s=await this.#r.relayer.parseSignedDecryptionPermit({transportKeyPair:o,serializedPermit:a.serializedPermit});return this.#r.relayer.decryptValues({transportKeyPair:o,signedPermit:s,encryptedValues:r,contractAddress:n,options:i})}async#s(n,i,o,s={spent:!1}){if(n.length===0)return{};let c=n.map(e=>({encryptedValue:e.encryptedValue,contractAddress:(0,m.getAddress)(e.contractAddress)})),l={},u=[];for(let e of c)a.l(e.encryptedValue)?l[e.encryptedValue]=0n:u.push(e);if(u.length===0)return l;let d=Array.from(new Set(c.map(e=>e.contractAddress))),f=Array.from(new Set(u.map(e=>e.contractAddress)));if(i.validate)try{await i.validate(f)}catch(t){throw e.v(t)?this.#u(t,`the delegation pre-check`):t}let p=[];for(let e of u){let t=await this.#e.get(i.requesterAddress,e.contractAddress,e.encryptedValue);t===null?p.push(e):l[e.encryptedValue]=t}if(p.length===0)return l;let h=await this.#t.grantPermit(d,i.delegator),g=new Map;for(let e of p){let t=g.get(e.contractAddress);t?t.push(e.encryptedValue):g.set(e.contractAddress,[e.encryptedValue])}let _=[];for(let[e,t]of g)for(let n of a.c(t))_.push({contractAddress:e,encryptedValues:n});let v=Date.now(),y=p.map(e=>e.encryptedValue);try{this.#i({type:r.F.DecryptStart,encryptedValues:y});try{await this.#c(i,h,_,l,o)}catch(e){if(!(e instanceof t.l)||s.spent)throw e;let n=h.permissions.map(e=>e.serializedPermit.signature);s.spent=!0;try{h=await this.#t.recoverPermits(d,i.delegator,n)}catch(e){throw e instanceof t.t?new t.l(`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(i,h,_.filter(({encryptedValues:e})=>e.some(e=>l[e]===void 0)),l,o)}let e={};for(let t of y){let n=l[t];n!==void 0&&(e[t]=n)}return this.#i({type:r.F.DecryptEnd,durationMs:Date.now()-v,encryptedValues:y,result:e}),l}catch(t){let n=t instanceof e.r&&t.cause instanceof Error?t.cause:t;throw this.#i({type:r.F.DecryptError,error:e.S(n),durationMs:Date.now()-v,encryptedValues:y}),k(t,i.errorMessage,{isDelegated:i.delegator!==void 0})}}async#c(e,n,r,i,o){let s=(await a.r(r.map(({contractAddress:t,encryptedValues:r})=>async()=>{try{await this.#l(e,n,t,r,i,o);return}catch(e){return e}}),5)).filter(e=>e!==void 0);if(s.length>0)throw s.find(e=>e instanceof t.l)??s[0]}async#l(e,t,r,i,a,o){let s;try{s=await this.#o(t,r,i,o)}catch(t){throw k(t,e.errorMessage,{isDelegated:e.delegator!==void 0,contractAddress:r,account:e.delegator??e.requesterAddress})}for(let t=0;t<i.length;t++){let n=i[t],o=s[t]?.value;n!==void 0&&o!==void 0&&(a[n]=o,await this.#e.set(e.requesterAddress,r,n,o))}let c=i.filter(e=>a[e]===void 0);if(c.length>0)throw new n.t(`${e.errorMessage}: relayer returned no clear value for ${c.length} of ${i.length} handle(s) on ${r}`,{cause:AggregateError(c.map(e=>new n.t(`No clear value for handle ${e} on ${r}`)),`${c.length} handle(s) missing a clear value on ${r}`)})}#u(t,n){return new i.r(`RPC provider rate-limited ${n}; retry with backoff.`,{cause:t,retryAfter:e.c(t)})}#d(e,t){let r=t[e.encryptedValue];if(r===void 0){e.error=new n.t(`Batch delegated decryption returned no value for encrypted value ${e.encryptedValue} on contract ${e.contractAddress}`);return}e.value=r}#f(t,n,r){return t instanceof e.r?t:k(t,n,r)}#p(){throw new n.t(`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 V={AlreadyDelegatedOrRevokedInSameBlock:e=>new y(`Only one delegate/revoke per (delegator, delegate, contract) per block. Wait for the next block before retrying.`,{cause:e}),SenderCannotBeContractAddress:e=>new T(`The contract address cannot be the caller address.`,{cause:e}),EnforcedPause:e=>new E(`The ACL contract is paused. Delegation operations are temporarily disabled.`,{cause:e}),SenderCannotBeDelegate:e=>new v(`Cannot delegate to yourself (delegate === msg.sender).`,{cause:e}),DelegateCannotBeContractAddress:e=>new C(`Delegate address cannot be the same as the contract address.`,{cause:e}),DelegateCannotBeWildcard:e=>new w(`Delegate address cannot be the wildcard address; it can only be used as the contract address.`,{cause:e}),ExpirationDateBeforeOneHour:e=>new D(`Expiration date must be at least 1 hour in the future.`,{cause:e}),ExpirationDateAlreadySetToSameValue:e=>new S(`The new expiration date is the same as the current one.`,{cause:e}),NotDelegatedYet:e=>new b(`Cannot revoke: no active delegation exists.`,{cause:e})};function fe(e){return Object.hasOwn(V,e)}function pe(e,t){let n=o.T(e);if(n&&fe(n))return V[n](t);let r=e instanceof Error?e.message:String(e);for(let[e,n]of Object.entries(V))if(r.includes(e))return n(t);return null}var me=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 D(`Expiration date must be at least 1 hour in the future`);let a=(0,m.getAddress)(t),o=(0,m.getAddress)(n),s=(0,m.getAddress)(r);if(o===s)throw new v(`Cannot delegate to yourself (delegate === msg.sender).`);if(o===(0,m.getAddress)(`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`))throw new w(`Delegate address cannot be the wildcard address; it can only be used as the contract address.`);if(o===a)throw new C(`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)):P,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 S(`The new expiration date (${l}) is the same as the current one. No on-chain change needed.`);return a!==(0,m.getAddress)(`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`)&&await this.#i({contractAddress:a,delegatorAddress:s,delegateAddress:o}),this.#s({operation:`delegateDecryption`,signer:e,contractAddress:a,config:j(c,o,a,l)})}async revokeDelegation(e,{contractAddress:t,delegateAddress:n,delegatorAddress:r}){let i=(0,m.getAddress)(t),a=(0,m.getAddress)(n),o=(0,m.getAddress)(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 b(`No active delegation found for delegate ${a} on contract ${i}.`);return this.#s({operation:`revokeDelegation`,signer:e,contractAddress:i,config:M(s,a,i)})}async isDelegated(e){return(await this.getStatus(e)).isActive}async getStatus(e){let t=(0,m.getAddress)(e.contractAddress)===F,[n,r]=await Promise.all([this.getDelegationExpiry(e),t?Promise.resolve(0n):this.getDelegationExpiry({...e,contractAddress:F})]),i=this.#a(n)||this.#a(r)?await this.#t.getBlockTimestamp():void 0,a=this.#o(n,i);if(a.isActive)return a;let o=this.#o(r,i);return o.isActive?o:n>=r?a:o}async#i(e){try{let{isActive:t}=await this.getStatus({...e,contractAddress:F});t&&this.#r.warn(`delegateDecryption: ${e.delegateAddress} already holds an active wildcard delegation from ${e.delegatorAddress}; this grant for ${e.contractAddress} is redundant.`)}catch(e){this.#r.warn(`delegateDecryption: wildcard redundancy check failed`,{error:e})}}#a(e){return e!==0n&&e!==P}#o(e,t){return e===0n?{isActive:!1,expiryTimestamp:e}:e===P?{isActive:!0,expiryTimestamp:e}:{isActive:t!==void 0&&e>t,expiryTimestamp:e}}async getDelegationExpiry({contractAddress:e,delegatorAddress:t,delegateAddress:n}){let r=this.#e.relayer.chain.aclContractAddress;return this.#t.readContract(N(r,(0,m.getAddress)(t),(0,m.getAddress)(n),(0,m.getAddress)(e)))}async#s({operation:e,signer:t,contractAddress:n,config:r}){try{return await a.n({operation:e,signer:t,provider:this.#t,config:r,emit:e=>this.#n(e,n),logger:this.#r})}catch(e){throw this.#c(e),e}}#c(e){if(!(e instanceof r.H))return;let t=pe(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 b||t instanceof x){let n=(0,m.getAddress)(e);r.set(n,t);return}throw t}})),r}async assertDelegationActive(e,t,n){let r=(0,m.getAddress)(e),i=(0,m.getAddress)(t),a=(0,m.getAddress)(n),{isActive:o,expiryTimestamp:s}=await this.getStatus({contractAddress:r,delegatorAddress:i,delegateAddress:a});if(!o)throw s===0n?new b(`No active delegation from ${i} to ${a} for ${r}`):new x(`Delegation from ${i} to ${a} for ${r} has expired`)}},he=class{#e;#t;constructor({router:e,emitEvent:t}){this.#e=e,this.#t=t}async encryptValues(t,n){let i=Date.now(),a=(0,m.getAddress)(t.contractAddress);try{this.#t({type:r.F.EncryptStart},a);let e=await this.#e.relayer.encryptValues({...t,options:n});return this.#t({type:r.F.EncryptEnd,durationMs:Date.now()-i},a),e}catch(t){throw this.#t({type:r.F.EncryptError,error:e.S(t),durationMs:Date.now()-i},a),te(t,`Encryption failed`)}}},ge=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,i=n?.chainId;i!==void 0&&await r.j(`switch relayer chain`,()=>this.#t.switchChain(i),this.#i);let a=this.#r;a&&await r.j(`credential wallet account change`,()=>a.handleWalletAccountChange(t,n),this.#i),t&&await r.j(`clear decrypt cache`,()=>this.#n.clearForRequester(t.address),this.#i),await Promise.all(Array.from(this.#a,t=>r.j(`wallet account listener`,()=>t(e),this.#i)))}};const H=h.z.object({kind:h.z.literal(`ConfidentialTransfer`),from:u.n,token:u.n,to:u.n,amount:h.z.bigint()}),U=h.z.object({kind:h.z.literal(`ConfidentialTransferFrom`),from:u.n,token:u.n,owner:u.n,to:u.n,amount:h.z.bigint()}),W=h.z.object({kind:h.z.literal(`SetOperator`),from:u.n,token:u.n,operator:u.n,until:u.s}),G=h.z.object({kind:h.z.literal(`Unwrap`),from:u.n,token:u.n,to:u.n,amount:h.z.bigint()}),K=h.z.object({kind:h.z.literal(`UnwrapAll`),from:u.n,token:u.n,to:u.n}),q=h.z.object({kind:h.z.literal(`FinalizeUnwrap`),from:u.n,wrapper:u.n,unwrapRequestIdOrAmount:u.r}),J=h.z.object({kind:h.z.literal(`ApproveUnderlying`),from:u.n,underlying:u.n,spender:u.n,amount:h.z.bigint()}),Y=h.z.object({kind:h.z.literal(`Wrap`),from:u.n,wrapper:u.n,to:u.n,amount:h.z.bigint()}),_e=u.r.check(h.z.refine(e=>e===`0x`||(0,m.size)(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`)),X=h.z.object({kind:h.z.literal(`TransferAndCall`),from:u.n,underlying:u.n,wrapper:u.n,amount:h.z.bigint(),recipientData:h.z.optional(_e)}),Z=h.z.object({kind:h.z.literal(`DelegateDecryption`),from:u.n,contractAddress:u.n,delegateAddress:u.n,expirationDate:h.z.optional(h.z.date())}),Q=h.z.object({kind:h.z.literal(`RevokeDelegation`),from:u.n,contractAddress:u.n,delegateAddress:u.n});h.z.discriminatedUnion(`kind`,[H,U,W,G,K,q,J,Y,X,Z,Q]);const ve=h.z.strictObject({maxFeePerGas:h.z.bigint(),maxPriorityFeePerGas:h.z.bigint()}),$=h.z.object({nonce:h.z.optional(h.z.int().check(h.z.nonnegative())),gasLimit:h.z.optional(h.z.bigint()),fees:h.z.optional(ve)}),ye=h.z.object({address:u.n,abi:h.z.array(h.z.unknown()),functionName:h.z.string(),args:h.z.array(h.z.unknown()),value:h.z.optional(h.z.bigint()),gas:h.z.optional(h.z.bigint())}),be=h.z.extend($,{from:u.n,calldata:ye});var xe=class{#e;#t;#n;constructor(e){this.#e=e.provider,this.#t=e.router,this.#n=e.encryption}async prepare(t,n){n&&=d.t($,n);let r=await this.#e.getChainId(),i=this.#t.chain.id;if(r!==i)throw new e.t(`Offline.prepare: provider is on chain ${r} but the SDK is configured for chain ${i}. The prepared transaction's contract addresses and encrypted inputs are bound to chain ${i} — point the provider at the same chain.`);let a=d.t(be,{calldata:await this.#r(t),from:t.from,nonce:n?.nonce,gasLimit:n?.gasLimit,fees:n?.fees}),o=await this.#e.prepareTransaction(a);return{kind:t.kind,unsignedTx:o,from:a.from}}async#r(t){switch(t.kind){case`ConfidentialTransfer`:return this.#i(t);case`ConfidentialTransferFrom`:return this.#a(t);case`SetOperator`:return this.#o(t);case`Unwrap`:return this.#s(t);case`UnwrapAll`:return this.#c(t);case`FinalizeUnwrap`:return this.#l(t);case`ApproveUnderlying`:return this.#u(t);case`Wrap`:return this.#d(t);case`TransferAndCall`:return this.#f(t);case`DelegateDecryption`:return this.#p(t);case`RevokeDelegation`:return this.#m(t);default:throw new e.t(`OfflineService.prepare: unsupported transaction kind '${t.kind}'.`)}}async#i(e){e=d.t(H,e);let{encryptedValues:t,inputProof:i}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from},{operation:`offline-confidential-transfer`}),a=t[0];if(!a)throw new n.r(`Encryption returned no handles for ConfidentialTransfer`);return r.v(e.token,e.to,a,i)}async#a(e){e=d.t(U,e);let{encryptedValues:t,inputProof:i}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from},{operation:`offline-confidential-transfer-from`}),a=t[0];if(!a)throw new n.r(`Encryption returned no handles for ConfidentialTransferFrom`);return r.b(e.token,e.owner,e.to,a,i)}#o(e){return e=d.t(W,e),r.T(e.token,e.operator,e.until)}async#s(e){e=d.t(G,e);let{encryptedValues:t,inputProof:i}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from},{operation:`offline-unwrap`}),a=t[0];if(!a)throw new n.r(`Encryption returned no handles for Unwrap`);return r.D(e.token,e.from,e.to,a,i)}async#c(e){e=d.t(K,e);let t=await this.#e.readContract(r.h(e.token,e.from));return r.O(e.token,e.from,e.to,t)}async#l(e){e=d.t(q,e);let t=await this.#t.relayer.decryptPublicValuesWithSignatures({encryptedValues:[e.unwrapRequestIdOrAmount],options:{operation:`offline-finalize-unwrap`}}).catch(e=>{throw k(e,`Public decryption failed during FinalizeUnwrap`)}),n=t.clearValues[0]?.value;return r.M(n,`FinalizeUnwrap: decryptPublicValuesWithSignatures(handle).clearValue`),r.x(e.wrapper,e.unwrapRequestIdOrAmount,n,t.checkSignaturesArgs.decryptionProof)}#u(e){return e=d.t(J,e),r.l(e.underlying,e.spender,e.amount)}#d(e){return e=d.t(Y,e),r.A(e.wrapper,e.to,e.amount)}#f(e){return e=d.t(X,e),o.C(e.underlying,e.wrapper,e.amount,e.recipientData)}#p(e){if(e=d.t(Z,e),e.expirationDate&&e.expirationDate.getTime()<Date.now()+36e5)throw new D(`Expiration date must be at least 1 hour in the future`);if(e.delegateAddress===e.from)throw new v(`Cannot delegate to yourself (delegate === msg.sender).`);if(e.delegateAddress===e.contractAddress)throw new C(`Delegate address cannot be the same as the contract address (${e.contractAddress}).`);let t=e.expirationDate?BigInt(Math.floor(e.expirationDate.getTime()/1e3)):P;return j(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress,t)}#m(e){return e=d.t(Q,e),M(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress)}};function Se(t){if(!(!Object.hasOwn(t,`transportKeyPairDerivationSecret`)||t.transportKeyPairDerivationSecret!==void 0))throw new e.t(`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 Ce(t){if(t===void 0)return;let{importScripts:n}=globalThis;if(!(typeof window>`u`&&typeof document>`u`&&typeof n!=`function`))throw new e.t(`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 we(e){if(e===void 0)return;let t=d.t(l.l,e);return new l.u(typeof t==`string`?t:new Uint8Array(t))}var Te=class{#e;provider;signer;storage;registry;permits;delegations;decryption;offline;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;constructor(e,t={}){Se(t),Ce(t.transportKeyPairDerivationSecret);let n=we(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 se(e.storage,this.#i),this.#u=new me({provider:this.provider,router:e.router,emitEvent:this.emitEvent.bind(this),logger:this.#i});let r={};for(let t of e.chains)t.registryAddress&&(r[t.id]=t.registryAddress);this.registry=new l.o({provider:this.provider,registryAddresses:r,registryTTL:e.registryTTL}),this.#n=r,this.#t=e.registryTTL,this.#l=new l.s({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 de({cache:this.#a,credentialService:this.#l,delegationService:this.#u,router:e.router,emitEvent:this.emitEvent.bind(this)})),this.#s=new he({router:e.router,emitEvent:this.emitEvent.bind(this)}),this.#o=new ge({signer:e.signer,router:e.router,cachingService:this.#a,credentialService:this.#l,logger:this.#i}),this.#d=new xe({provider:this.provider,router:e.router,encryption:this.#s,emitEvent:(e,t)=>this.emitEvent(e,t)}),this.permits=new I({signer:this.signer,provider:this.provider,cachingService:this.#a,credentialService:this.#l,logger:this.#i,emitEvent:this.emitEvent.bind(this)}),this.delegations=new L({signer:this.signer,provider:this.provider,delegationService:this.#u}),this.decryption=new R({signer:this.signer,provider:this.provider,router:e.router,decryptionService:this.#c}),this.offline=new z(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 l.o({provider:this.provider,registryAddresses:{...this.#n,...e},registryTTL:this.#t})}async encrypt(e,t){return this.#s.encryptValues(e,s.r(t,`encrypt`))}createToken(e){return new a.t(this,e)}createWrappedToken(e){return new o.t(this,e)}dispose(){this.#o.dispose(),this.#e.dispose()}terminate(){this.dispose(),this.signer?.dispose?.()}[Symbol.dispose](){this.terminate()}};exports.ACL_TOPICS=o.n,exports.AclPausedError=E,exports.AclTopics=o.r,exports.BalanceCheckUnavailableError=a.u,exports.BaseSigner=l.t,exports.ChainMismatchError=a.h,exports.ChromeSessionStorage=B,exports.ConfigurationError=e.t,exports.Decryption=R,exports.DecryptionFailedError=n.t,exports.DefaultRegistryAddresses=l.a,exports.DelegationContractIsSelfError=T,exports.DelegationCooldownError=y,exports.DelegationDelegateCannotBeWildcardError=w,exports.DelegationDelegateEqualsContractError=C,exports.DelegationExpirationTooSoonError=D,exports.DelegationExpiredError=x,exports.DelegationExpiryUnchangedError=S,exports.DelegationNotFoundError=b,exports.DelegationNotPropagatedError=O,exports.DelegationSelfNotAllowedError=v,exports.Delegations=L,exports.ERC1363_INTERFACE_ID=r.t,exports.ERC20ReadFailedError=a.d,exports.ERC7984_INTERFACE_ID=r.n,exports.ERC7984_WRAPPER_INTERFACE_ID=r.r,exports.EncryptOffloadUnavailableError=n.n,exports.EncryptionFailedError=n.r,exports.IndexedDBStorage=l.p,exports.InsufficientAllowanceError=a.f,exports.InsufficientConfidentialBalanceError=a.p,exports.InsufficientERC20BalanceError=a.m,exports.InvalidTransportKeyPairError=t.i,exports.KeyWrappingError=t.a,exports.MAX_UINT64=P,exports.MemoryStorage=l.d,exports.MutableWalletAccountStore=l.n,exports.NoCiphertextError=t.o,exports.NotEntitledError=_,exports.Offline=z,exports.Permits=I,exports.PreparedPermitChainMismatchError=t.s,exports.PreparedPermitExpiredError=t.c,exports.RelayerRequestFailedError=e.n,exports.RevokedKmsContextError=t.l,exports.RpcRateLimitError=i.r,exports.SignerNotConfiguredError=r.L,exports.SignerRequiredError=r.R,exports.SigningFailedError=t.t,exports.SigningRejectedError=t.n,exports.TOKEN_TOPICS=o.i,exports.Token=a.t,exports.Topics=o.a,exports.TransactionRevertedError=r.H,exports.TransportKeyPairChangedError=t.u,exports.TransportKeyPairExpiredError=t.d,exports.UnshieldAlreadyFinalizedError=o.w,exports.WILDCARD_CONTRACT=F,exports.WalletAccountNotReadyError=r.z,exports.WalletNotConnectedError=r.B,exports.WrappedToken=o.t,exports.WrappersRegistry=l.o,exports.ZERO_ENCRYPTED_VALUE=a.s,exports.ZamaError=e.r,exports.ZamaErrorCode=e.i,exports.ZamaSDK=Te,exports.ZamaSDKEvents=r.F,exports.allowanceContract=r.c,exports.anvil=p.t,exports.approveContract=r.l,exports.balanceOfContract=r.u,exports.bscTestnet=p.n,exports.chains=p.r,exports.chromeSessionStorage=ie,exports.cleartext=c.t,exports.confidentialBalanceOfContract=r.h,exports.confidentialTotalSupplyContract=r.g,exports.confidentialTransferContract=r.v,exports.confidentialTransferFromContract=r.b,exports.createConfig=re,exports.createWalletAccountStore=l.r,exports.decimalsContract=r.d,exports.decodeAclEvent=o.o,exports.decodeAclEvents=o.s,exports.decodeConfidentialTransfer=o.c,exports.decodeDelegatedForUserDecryption=o.l,exports.decodeOnChainEvent=o.u,exports.decodeOnChainEvents=o.d,exports.decodeRevokedDelegationForUserDecryption=o.f,exports.decodeUnwrapFinalized=o.p,exports.decodeUnwrapRequested=o.m,exports.decodeWrap=o.h,exports.delegateForUserDecryptionContract=j,exports.finalizeUnwrapContract=r.x,exports.findDelegatedForUserDecryption=o.g,exports.findRevokedDelegationForUserDecryption=o._,exports.findUnwrapRequested=o.v,exports.findWrap=o.y,exports.getConfidentialTokenAddressContract=f.t,exports.getDelegationExpiryContract=N,exports.getTokenAddressContract=f.n,exports.getTokenPairContract=f.r,exports.getTokenPairsContract=f.i,exports.getTokenPairsLengthContract=f.a,exports.getTokenPairsSliceContract=f.o,exports.hardhat=p.i,exports.hoodi=p.a,exports.indexedDBStorage=l.m,exports.inferredTotalSupplyContract=r.S,exports.ingenTestnet=p.o,exports.isConfidentialTokenContract=r.i,exports.isConfidentialTokenValidContract=f.s,exports.isConfidentialWrapperContract=r.a,exports.isEncryptedValueZero=a.l,exports.isHandleDelegatedContract=ne,exports.isOperatorContract=r.C,exports.isRetryable=e.a,exports.mainnet=p.s,exports.matchZamaError=g,exports.memoryStorage=l.f,exports.nameContract=r.p,exports.parsePreparedPermit=l.c,exports.polygon=p.c,exports.polygonAmoy=p.l,exports.rateContract=r.w,exports.retryAfterSeconds=e.o,exports.revokeDelegationContract=M,exports.sepolia=p.u,exports.setOperatorContract=r.T,exports.supportsInterfaceContract=r.s,exports.symbolContract=r.m,exports.transferAndCallContract=o.C,exports.underlyingContract=r.E,exports.unwrapContract=r.D,exports.unwrapFromBalanceContract=r.O,exports.unwrapRequesterContract=r.k,exports.wrapContract=r.A,exports.zenithTrexTestnet=p.d;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./relayer.cjs"),t=require("./erc165.cjs"),n=require("./encryption.cjs"),r=require("./token.cjs"),i=require("./wrapped-token.cjs"),a=require("./telemetry.cjs"),o=require("./cleartext.cjs"),s=require("./base-signer.cjs"),c=require("./primitives.cjs"),l=require("./validation.cjs"),u=require("./wrappers-registry.cjs"),d=require("./chains.cjs");let f=require("viem"),p=require("zod/mini");function m(t,n){if(t instanceof e.r){let e=n[t.code];if(e)return e(t)}return n._?.(t)}var h=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}},g=class extends e.r{constructor(t,n){super(e.i.DelegationSelfNotAllowed,t,n),this.name=`DelegationSelfNotAllowedError`}},_=class extends e.r{constructor(t,n){super(e.i.DelegationCooldown,t,n),this.name=`DelegationCooldownError`}},v=class extends e.r{constructor(t,n){super(e.i.DelegationNotFound,t,n),this.name=`DelegationNotFoundError`}},y=class extends e.r{constructor(t,n){super(e.i.DelegationExpired,t,n),this.name=`DelegationExpiredError`}},b=class extends e.r{constructor(t,n){super(e.i.DelegationExpiryUnchanged,t,n),this.name=`DelegationExpiryUnchangedError`}},x=class extends e.r{constructor(t,n){super(e.i.DelegationDelegateEqualsContract,t,n),this.name=`DelegationDelegateEqualsContractError`}},S=class extends e.r{constructor(t,n){super(e.i.DelegationDelegateCannotBeWildcard,t,n),this.name=`DelegationDelegateCannotBeWildcardError`}},C=class extends e.r{constructor(t,n){super(e.i.DelegationContractIsSelf,t,n),this.name=`DelegationContractIsSelfError`}},w=class extends e.r{constructor(t,n){super(e.i.AclPaused,t,n),this.name=`AclPausedError`}},T=class extends e.r{constructor(t,n){super(e.i.DelegationExpirationTooSoon,t,n),this.name=`DelegationExpirationTooSoonError`}},E=class extends e.r{constructor(t,n){super(e.i.DelegationNotPropagated,t,n),this.name=`DelegationNotPropagatedError`}};const ee=[n.t,t.J,e.n,E,t.W,t.U,h,r._,t.K,t.Z];function D(i,a,o={}){if(ee.some(e=>i instanceof e))return i;let s=i instanceof Error?i.message:a;if(i instanceof Error&&e.p(i.message))return new t.K(i.message,{cause:i});if(e._(i))return new t.Z(`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:i});if(i instanceof Error&&e.m(i.message))return o.isDelegated?new E(`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:i}):new h({encryptedValue:e.b(i.message)??``,contractAddress:o.contractAddress??``,account:o.account??``},{cause:i});if(e.d(i))return new r._(s,{cause:i,retryAfter:e.c(i)});let c=e.s(i);return c===void 0&&e.v(i)?new r._(s,{cause:i,retryAfter:e.c(i)}):c===400?new t.J(i instanceof Error?i.message:`No ciphertext for this account`,{cause:i}):o.isDelegated&&c===500?new E(`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:i}):e.h(i)||c!==void 0?new e.n(s,c,{cause:i,retryAfter:e.c(i),retryable:e.g(i)||void 0}):new n.t(a,{cause:i})}function te(t,r){if(t instanceof e.r)return t;let i=e.s(t),a=e.g(t);return i!==void 0||e.h(t)?new e.n(t instanceof Error?t.message:r,i,{cause:t,retryAfter:e.c(t),retryable:a||void 0}):new n.r(r,{cause:t})}const O=[{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 k(e,t,n,r){return{address:e,abi:O,functionName:`delegateForUserDecryption`,args:[t,n,r]}}function A(e,t,n){return{address:e,abi:O,functionName:`revokeDelegationForUserDecryption`,args:[t,n]}}function j(e,t,n,r){return{address:e,abi:O,functionName:`getUserDecryptionDelegationExpirationDate`,args:[t,n,r]}}function M(e,t,n,r,i){return{address:e,abi:O,functionName:`isHandleDelegatedForUserDecryption`,args:[t,n,r,i]}}const N=2n**64n-1n,P=`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`;function ne(e){return s.i(e.signer,e.provider,e)}var F=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 t.V(this.#r,e)}#s(e,n){throw this.#a({type:t.F.PermitError,operation:e,error:n instanceof Error?n:Error(String(n))}),n}async grantPermit(e){if(e.length===0)return;let t;try{t=this.#o(`grantPermit`),await r.o(`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 r.o(`grantDelegationPermit`,this.#e,this.#t)}catch(e){this.#s(`grantDelegationPermit`,e)}await n.grantPermit(t,e)}async hasPermit(e){return this.#r?this.#r.hasPermit(e):!1}async hasDelegationPermit(e,t){return this.#r?this.#r.hasPermit(t,e):!1}async warmTransportKeyPair(){let e=this.#r;if(!e)return;let t=this.#e?.walletAccount.getSnapshot();t&&await e.warmTransportKeyPair(t.address)}registerPermit(e,t){return this.batchRegisterPermits([{prepared:e,signature:t}])}async batchRegisterPermits(e){let t;try{t=this.#o(`registerPermit`)}catch(e){this.#s(`registerPermit`,e)}await t.batchRegisterPermits(e),await Promise.all([...new Set(e.map(e=>e.prepared.signerAddress))].map(e=>this.#c(e)))}async revokePermits(e){let t=this.#o(`revokePermits`),n=(0,f.getAddress)((await r.a(`revokePermits`,this.#e,this.#t)).address);try{await t.revokePermits(e)}finally{await this.#c(n)}}async clear(){let e=this.#o(`clear`),t=(0,f.getAddress)((await r.a(`clear`,this.#e,this.#t)).address);try{await e.clearCredentials()}finally{await this.#c(t)}}async#c(e){await t.j(`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)}},I=class{#e;#t;#n;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.delegationService}#r(e){return t.V(this.#e,e)}async delegateDecryption({contractAddress:e,delegateAddress:t,expirationDate:n}){let i=this.#r(`delegateDecryption`),a=await r.a(`delegateDecryption`,this.#e,this.#t);return this.#n.delegateDecryption(i,{contractAddress:e,delegateAddress:t,delegatorAddress:a.address,expirationDate:n})}async revokeDelegation({contractAddress:e,delegateAddress:t}){let n=this.#r(`revokeDelegation`),i=await r.a(`revokeDelegation`,this.#e,this.#t);return this.#n.revokeDelegation(n,{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)}},L=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.V(this.#r,e)}async decryptValues(e,t){let n=this.#i(`decryptValues`),i=await r.a(`decryptValues`,this.#e,this.#t);return n.decryptValues(e,i.address,a.r(t,`decrypt-values`))}async delegatedDecryptValues(e,t,n=t,i){let o=this.#i(`delegatedDecryptValues`),s=await r.a(`delegatedDecryptValues`,this.#e,this.#t);return o.delegatedDecryptValues(e,t,s.address,n,a.r(i,`delegated-decrypt-values`))}async decryptPublicValues(e,n){if(e.length===0)return{clearValues:{},decryptionProof:`0x`,abiEncodedClearValues:`0x`};let r=a.r(n,`decrypt-public-values`);try{let n=await this.#n.relayer.decryptPublicValuesWithSignatures({encryptedValues:e,options:r}),i={};return n.checkSignaturesArgs.handlesList.forEach((e,r)=>{t.P(n.clearValues[r],`result.clearValues[${r}]`),i[e]=n.clearValues[r].value}),{clearValues:i,abiEncodedClearValues:n.checkSignaturesArgs.abiEncodedCleartexts,decryptionProof:n.checkSignaturesArgs.decryptionProof}}catch(e){throw D(e,`Public decryption failed`)}}async delegatedBatchDecryptValues({encryptedInputs:e,delegatorAddress:t,accountAddress:n=t,maxConcurrency:i,waitForPropagation:a,operation:o}){let s=this.#i(`delegatedBatchDecryptValues`),c=await r.a(`delegatedBatchDecryptValues`,this.#e,this.#t);return s.delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:c.address,accountAddress:n,maxConcurrency:i,waitForPropagation:a,operation:o??`delegated-batch-decrypt-values`})}},R=class{#e;#t;constructor(e,t){this.#e=e,this.#t=t}prepare(e,t){return this.#e.prepare(e,t)}preparePermit(e){return this.#t.preparePermit(e)}batchPreparePermits(e){return this.#t.batchPreparePermits(e)}},z=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 re=new z,ie=p.z.union([p.z.bigint(),p.z.boolean(),c.n]),ae=p.z.array(p.z.string());var oe=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,f.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,f.getAddress)(e)}:${(0,f.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 se(e,t){let r=ce(e,t);if(!r)throw new n.t(`No permit covers contract ${t} after allow()`);return{privateKey:e.keypair.privateKey,publicKey:e.keypair.publicKey,serializedPermit:r.serializedPermit}}function ce(e,t){let n=c.t(t);return e.permissions.find(e=>e.contractAddresses.includes(n))}const le=e=>new Promise(t=>setTimeout(t,e));var ue=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,f.getAddress)(t);return this.#s(e,{requesterAddress:r,errorMessage:`Failed to decrypt encrypted values`},n)}async delegatedDecryptValues(e,t,n,r,i){let a=(0,f.getAddress)(t),o=(0,f.getAddress)(n),s={spent:!1};return this.#a(i?.waitForPropagation??!0,()=>this.#s(e,{requesterAddress:(0,f.getAddress)(r),delegator:a,validate:e=>this.#m(e,{delegatorAddress:a,delegateAddress:o}),errorMessage:`Failed to decrypt delegated encrypted values`},{operation:i?.operation},s))}async#a(e,t){let n;for(let r=0;r<16;r++)try{return await t()}catch(t){if(n=t,!(r<15&&e&&t instanceof E))throw t;await le(2e3)}throw n}async delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:n,accountAddress:i,maxConcurrency:a=5,waitForPropagation:o=!0,operation:s}){let c=e.map(e=>({encryptedValue:e.encryptedValue,contractAddress:(0,f.getAddress)(e.contractAddress)}));if(c.length===0)return{items:c};let l=(0,f.getAddress)(i);try{let e=await this.delegatedDecryptValues(c.map(({encryptedValue:e,contractAddress:t})=>({encryptedValue:e,contractAddress:t})),t,n,l,{waitForPropagation:o,operation:s});for(let t of c)this.#d(t,e);return{items:c}}catch(e){if(r.u(e))throw e;if(c.length===1){let[n=this.#p()]=c;return n.error=this.#f(e,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:n.contractAddress,account:(0,f.getAddress)(t)}),{items:c}}}let u=!1,d;if(await r.r(c.map(e=>async()=>{if(!u)try{let r=await this.delegatedDecryptValues([{encryptedValue:e.encryptedValue,contractAddress:e.contractAddress}],t,n,l,{waitForPropagation:!1,operation:s});this.#d(e,r)}catch(n){if(r.u(n)){u=!0,d??=n;return}e.error=this.#f(n,`Failed to decrypt delegated encrypted values`,{isDelegated:!0,contractAddress:e.contractAddress,account:(0,f.getAddress)(t)})}}),a),d!==void 0)throw d;return{items:c}}async#o(t,n,r,i){let a=se(t,n),o;try{o=await this.#r.relayer.parseTransportKeyPair({publicKey:a.publicKey,privateKey:a.privateKey,tkmsVersion:t.keypair.tkmsVersion})}catch(t){throw t instanceof Error&&e.p(t.message)&&await this.#t.evictTransportKeyPair(),t}let s=await this.#r.relayer.parseSignedDecryptionPermit({transportKeyPair:o,serializedPermit:a.serializedPermit});return this.#r.relayer.decryptValues({transportKeyPair:o,signedPermit:s,encryptedValues:r,contractAddress:n,options:i})}async#s(n,i,a,o={spent:!1}){if(n.length===0)return{};let s=n.map(e=>({encryptedValue:e.encryptedValue,contractAddress:(0,f.getAddress)(e.contractAddress)})),c={},l=[];for(let e of s)r.l(e.encryptedValue)?c[e.encryptedValue]=0n:l.push(e);if(l.length===0)return c;let u=Array.from(new Set(s.map(e=>e.contractAddress))),d=Array.from(new Set(l.map(e=>e.contractAddress)));if(i.validate)try{await i.validate(d)}catch(t){throw e.v(t)?this.#u(t,`the delegation pre-check`):t}let p=[];for(let e of l){let t=await this.#e.get(i.requesterAddress,e.contractAddress,e.encryptedValue);t===null?p.push(e):c[e.encryptedValue]=t}if(p.length===0)return c;let m=await this.#t.grantPermit(u,i.delegator),h=new Map;for(let e of p){let t=h.get(e.contractAddress);t?t.push(e.encryptedValue):h.set(e.contractAddress,[e.encryptedValue])}let g=[];for(let[e,t]of h)for(let n of r.c(t))g.push({contractAddress:e,encryptedValues:n});let _=Date.now(),v=p.map(e=>e.encryptedValue);try{this.#i({type:t.F.DecryptStart,encryptedValues:v});try{await this.#c(i,m,g,c,a)}catch(e){if(!(e instanceof t.Z)||o.spent)throw e;let n=m.permissions.map(e=>e.serializedPermit.signature);o.spent=!0;try{m=await this.#t.recoverPermits(u,i.delegator,n)}catch(e){throw e instanceof t.U?new t.Z(`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(i,m,g.filter(({encryptedValues:e})=>e.some(e=>c[e]===void 0)),c,a)}let e={};for(let t of v){let n=c[t];n!==void 0&&(e[t]=n)}return this.#i({type:t.F.DecryptEnd,durationMs:Date.now()-_,encryptedValues:v,result:e}),c}catch(n){let r=n instanceof e.r&&n.cause instanceof Error?n.cause:n;throw this.#i({type:t.F.DecryptError,error:e.S(r),durationMs:Date.now()-_,encryptedValues:v}),D(n,i.errorMessage,{isDelegated:i.delegator!==void 0})}}async#c(e,n,i,a,o){let s=(await r.r(i.map(({contractAddress:t,encryptedValues:r})=>async()=>{try{await this.#l(e,n,t,r,a,o);return}catch(e){return e}}),5)).filter(e=>e!==void 0);if(s.length>0)throw s.find(e=>e instanceof t.Z)??s[0]}async#l(e,t,r,i,a,o){let s;try{s=await this.#o(t,r,i,o)}catch(t){throw D(t,e.errorMessage,{isDelegated:e.delegator!==void 0,contractAddress:r,account:e.delegator??e.requesterAddress})}for(let t=0;t<i.length;t++){let n=i[t],o=s[t]?.value;n!==void 0&&o!==void 0&&(a[n]=o,await this.#e.set(e.requesterAddress,r,n,o))}let c=i.filter(e=>a[e]===void 0);if(c.length>0)throw new n.t(`${e.errorMessage}: relayer returned no clear value for ${c.length} of ${i.length} handle(s) on ${r}`,{cause:AggregateError(c.map(e=>new n.t(`No clear value for handle ${e} on ${r}`)),`${c.length} handle(s) missing a clear value on ${r}`)})}#u(t,n){return new r._(`RPC provider rate-limited ${n}; retry with backoff.`,{cause:t,retryAfter:e.c(t)})}#d(e,t){let r=t[e.encryptedValue];if(r===void 0){e.error=new n.t(`Batch delegated decryption returned no value for encrypted value ${e.encryptedValue} on contract ${e.contractAddress}`);return}e.value=r}#f(t,n,r){return t instanceof e.r?t:D(t,n,r)}#p(){throw new n.t(`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 B={AlreadyDelegatedOrRevokedInSameBlock:e=>new _(`Only one delegate/revoke per (delegator, delegate, contract) per block. Wait for the next block before retrying.`,{cause:e}),SenderCannotBeContractAddress:e=>new C(`The contract address cannot be the caller address.`,{cause:e}),EnforcedPause:e=>new w(`The ACL contract is paused. Delegation operations are temporarily disabled.`,{cause:e}),SenderCannotBeDelegate:e=>new g(`Cannot delegate to yourself (delegate === msg.sender).`,{cause:e}),DelegateCannotBeContractAddress:e=>new x(`Delegate address cannot be the same as the contract address.`,{cause:e}),DelegateCannotBeWildcard:e=>new S(`Delegate address cannot be the wildcard address; it can only be used as the contract address.`,{cause:e}),ExpirationDateBeforeOneHour:e=>new T(`Expiration date must be at least 1 hour in the future.`,{cause:e}),ExpirationDateAlreadySetToSameValue:e=>new b(`The new expiration date is the same as the current one.`,{cause:e}),NotDelegatedYet:e=>new v(`Cannot revoke: no active delegation exists.`,{cause:e})};function de(e){return Object.hasOwn(B,e)}function V(e,t){let n=i.T(e);if(n&&de(n))return B[n](t);let r=e instanceof Error?e.message:String(e);for(let[e,n]of Object.entries(B))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:n,delegatorAddress:r,expirationDate:i}){if(i&&i.getTime()<Date.now()+36e5)throw new T(`Expiration date must be at least 1 hour in the future`);let a=(0,f.getAddress)(t),o=(0,f.getAddress)(n),s=(0,f.getAddress)(r);if(o===s)throw new g(`Cannot delegate to yourself (delegate === msg.sender).`);if(o===(0,f.getAddress)(`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`))throw new S(`Delegate address cannot be the wildcard address; it can only be used as the contract address.`);if(o===a)throw new x(`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)):N,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 b(`The new expiration date (${l}) is the same as the current one. No on-chain change needed.`);return a!==(0,f.getAddress)(`0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF`)&&await this.#i({contractAddress:a,delegatorAddress:s,delegateAddress:o}),this.#s({operation:`delegateDecryption`,signer:e,contractAddress:a,config:k(c,o,a,l)})}async revokeDelegation(e,{contractAddress:t,delegateAddress:n,delegatorAddress:r}){let i=(0,f.getAddress)(t),a=(0,f.getAddress)(n),o=(0,f.getAddress)(r),s=this.#e.relayer.chain.aclContractAddress,c;try{c=await this.getDelegationExpiry({contractAddress:i,delegatorAddress:o,delegateAddress:a})}catch(e){this.#r.warn(`revokeDelegation: pre-flight expiry check failed`,{error:e}),c=1n}if(c===0n)throw new v(`No active delegation found for delegate ${a} on contract ${i}.`);return this.#s({operation:`revokeDelegation`,signer:e,contractAddress:i,config:A(s,a,i)})}async isDelegated(e){return(await this.getStatus(e)).isActive}async getStatus(e){let t=(0,f.getAddress)(e.contractAddress)===P,[n,r]=await Promise.all([this.getDelegationExpiry(e),t?Promise.resolve(0n):this.getDelegationExpiry({...e,contractAddress:P})]),i=this.#a(n)||this.#a(r)?await this.#t.getBlockTimestamp():void 0,a=this.#o(n,i);if(a.isActive)return a;let o=this.#o(r,i);return o.isActive?o:n>=r?a:o}async#i(e){try{let{isActive:t}=await this.getStatus({...e,contractAddress:P});t&&this.#r.warn(`delegateDecryption: ${e.delegateAddress} already holds an active wildcard delegation from ${e.delegatorAddress}; this grant for ${e.contractAddress} is redundant.`)}catch(e){this.#r.warn(`delegateDecryption: wildcard redundancy check failed`,{error:e})}}#a(e){return e!==0n&&e!==N}#o(e,t){return e===0n?{isActive:!1,expiryTimestamp:e}:e===N?{isActive:!0,expiryTimestamp:e}:{isActive:t!==void 0&&e>t,expiryTimestamp:e}}async getDelegationExpiry({contractAddress:e,delegatorAddress:t,delegateAddress:n}){let r=this.#e.relayer.chain.aclContractAddress;return this.#t.readContract(j(r,(0,f.getAddress)(t),(0,f.getAddress)(n),(0,f.getAddress)(e)))}async#s({operation:e,signer:t,contractAddress:n,config:i}){try{return await r.n({operation:e,signer:t,provider:this.#t,config:i,emit:e=>this.#n(e,n),logger:this.#r})}catch(e){throw this.#c(e),e}}#c(e){if(!(e instanceof t.H))return;let n=V(e.cause??e,e);if(n)throw n}async findInactiveDelegations(e,t,n){let r=new Map;return await Promise.all(e.map(async e=>{try{await this.assertDelegationActive(e,t,n)}catch(t){if(t instanceof v||t instanceof y){let n=(0,f.getAddress)(e);r.set(n,t);return}throw t}})),r}async assertDelegationActive(e,t,n){let r=(0,f.getAddress)(e),i=(0,f.getAddress)(t),a=(0,f.getAddress)(n),{isActive:o,expiryTimestamp:s}=await this.getStatus({contractAddress:r,delegatorAddress:i,delegateAddress:a});if(!o)throw s===0n?new v(`No active delegation from ${i} to ${a} for ${r}`):new y(`Delegation from ${i} to ${a} for ${r} has expired`)}},pe=class{#e;#t;constructor({router:e,emitEvent:t}){this.#e=e,this.#t=t}async encryptValues(n,r){let i=Date.now(),a=(0,f.getAddress)(n.contractAddress);try{this.#t({type:t.F.EncryptStart},a);let e=await this.#e.relayer.encryptValues({...n,options:r});return this.#t({type:t.F.EncryptEnd,durationMs:Date.now()-i},a),e}catch(n){throw this.#t({type:t.F.EncryptError,error:e.S(n),durationMs:Date.now()-i},a),te(n,`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.j(`switch relayer chain`,()=>this.#t.switchChain(i),this.#i);let a=this.#r;a&&await t.j(`credential wallet account change`,()=>a.handleWalletAccountChange(n,r),this.#i),n&&await t.j(`clear decrypt cache`,()=>this.#n.clearForRequester(n.address),this.#i),await Promise.all(Array.from(this.#a,n=>t.j(`wallet account listener`,()=>n(e),this.#i)))}};const H=p.z.object({kind:p.z.literal(`ConfidentialTransfer`),from:c.n,token:c.n,to:c.n,amount:p.z.bigint()}),U=p.z.object({kind:p.z.literal(`ConfidentialTransferFrom`),from:c.n,token:c.n,owner:c.n,to:c.n,amount:p.z.bigint()}),W=p.z.object({kind:p.z.literal(`SetOperator`),from:c.n,token:c.n,operator:c.n,until:c.s}),G=p.z.object({kind:p.z.literal(`Unwrap`),from:c.n,token:c.n,to:c.n,amount:p.z.bigint()}),K=p.z.object({kind:p.z.literal(`UnwrapAll`),from:c.n,token:c.n,to:c.n}),q=p.z.object({kind:p.z.literal(`FinalizeUnwrap`),from:c.n,wrapper:c.n,unwrapRequestIdOrAmount:c.r}),J=p.z.object({kind:p.z.literal(`ApproveUnderlying`),from:c.n,underlying:c.n,spender:c.n,amount:p.z.bigint()}),Y=p.z.object({kind:p.z.literal(`Wrap`),from:c.n,wrapper:c.n,to:c.n,amount:p.z.bigint()}),he=c.r.check(p.z.refine(e=>e===`0x`||(0,f.size)(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`)),X=p.z.object({kind:p.z.literal(`TransferAndCall`),from:c.n,underlying:c.n,wrapper:c.n,amount:p.z.bigint(),recipientData:p.z.optional(he)}),Z=p.z.object({kind:p.z.literal(`DelegateDecryption`),from:c.n,contractAddress:c.n,delegateAddress:c.n,expirationDate:p.z.optional(p.z.date())}),Q=p.z.object({kind:p.z.literal(`RevokeDelegation`),from:c.n,contractAddress:c.n,delegateAddress:c.n});p.z.discriminatedUnion(`kind`,[H,U,W,G,K,q,J,Y,X,Z,Q]);const ge=p.z.strictObject({maxFeePerGas:p.z.bigint(),maxPriorityFeePerGas:p.z.bigint()}),$=p.z.object({nonce:p.z.optional(p.z.int().check(p.z.nonnegative())),gasLimit:p.z.optional(p.z.bigint()),fees:p.z.optional(ge)}),_e=p.z.object({address:c.n,abi:p.z.array(p.z.unknown()),functionName:p.z.string(),args:p.z.array(p.z.unknown()),value:p.z.optional(p.z.bigint()),gas:p.z.optional(p.z.bigint())}),ve=p.z.extend($,{from:c.n,calldata:_e});var ye=class{#e;#t;#n;constructor(e){this.#e=e.provider,this.#t=e.router,this.#n=e.encryption}async prepare(t,n){n&&=l.t($,n);let r=await this.#e.getChainId(),i=this.#t.chain.id;if(r!==i)throw new e.t(`Offline.prepare: provider is on chain ${r} but the SDK is configured for chain ${i}. The prepared transaction's contract addresses and encrypted inputs are bound to chain ${i} — point the provider at the same chain.`);let a=l.t(ve,{calldata:await this.#r(t),from:t.from,nonce:n?.nonce,gasLimit:n?.gasLimit,fees:n?.fees}),o=await this.#e.prepareTransaction(a);return{kind:t.kind,unsignedTx:o,from:a.from}}async#r(t){switch(t.kind){case`ConfidentialTransfer`:return this.#i(t);case`ConfidentialTransferFrom`:return this.#a(t);case`SetOperator`:return this.#o(t);case`Unwrap`:return this.#s(t);case`UnwrapAll`:return this.#c(t);case`FinalizeUnwrap`:return this.#l(t);case`ApproveUnderlying`:return this.#u(t);case`Wrap`:return this.#d(t);case`TransferAndCall`:return this.#f(t);case`DelegateDecryption`:return this.#p(t);case`RevokeDelegation`:return this.#m(t);default:throw new e.t(`OfflineService.prepare: unsupported transaction kind '${t.kind}'.`)}}async#i(e){e=l.t(H,e);let{encryptedValues:r,inputProof:i}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from},{operation:`offline-confidential-transfer`}),a=r[0];if(!a)throw new n.r(`Encryption returned no handles for ConfidentialTransfer`);return t.v(e.token,e.to,a,i)}async#a(e){e=l.t(U,e);let{encryptedValues:r,inputProof:i}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from},{operation:`offline-confidential-transfer-from`}),a=r[0];if(!a)throw new n.r(`Encryption returned no handles for ConfidentialTransferFrom`);return t.b(e.token,e.owner,e.to,a,i)}#o(e){return e=l.t(W,e),t.T(e.token,e.operator,e.until)}async#s(e){e=l.t(G,e);let{encryptedValues:r,inputProof:i}=await this.#n.encryptValues({values:[{value:e.amount,type:`euint64`}],contractAddress:e.token,userAddress:e.from},{operation:`offline-unwrap`}),a=r[0];if(!a)throw new n.r(`Encryption returned no handles for Unwrap`);return t.D(e.token,e.from,e.to,a,i)}async#c(e){e=l.t(K,e);let n=await this.#e.readContract(t.h(e.token,e.from));return t.O(e.token,e.from,e.to,n)}async#l(e){e=l.t(q,e);let n=await this.#t.relayer.decryptPublicValuesWithSignatures({encryptedValues:[e.unwrapRequestIdOrAmount],options:{operation:`offline-finalize-unwrap`}}).catch(e=>{throw D(e,`Public decryption failed during FinalizeUnwrap`)}),r=n.clearValues[0]?.value;return t.M(r,`FinalizeUnwrap: decryptPublicValuesWithSignatures(handle).clearValue`),t.x(e.wrapper,e.unwrapRequestIdOrAmount,r,n.checkSignaturesArgs.decryptionProof)}#u(e){return e=l.t(J,e),t.l(e.underlying,e.spender,e.amount)}#d(e){return e=l.t(Y,e),t.A(e.wrapper,e.to,e.amount)}#f(e){return e=l.t(X,e),i.C(e.underlying,e.wrapper,e.amount,e.recipientData)}#p(e){if(e=l.t(Z,e),e.expirationDate&&e.expirationDate.getTime()<Date.now()+36e5)throw new T(`Expiration date must be at least 1 hour in the future`);if(e.delegateAddress===e.from)throw new g(`Cannot delegate to yourself (delegate === msg.sender).`);if(e.delegateAddress===e.contractAddress)throw new x(`Delegate address cannot be the same as the contract address (${e.contractAddress}).`);let t=e.expirationDate?BigInt(Math.floor(e.expirationDate.getTime()/1e3)):N;return k(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress,t)}#m(e){return e=l.t(Q,e),A(this.#t.chain.aclContractAddress,e.delegateAddress,e.contractAddress)}};function be(t){if(!(!Object.hasOwn(t,`transportKeyPairDerivationSecret`)||t.transportKeyPairDerivationSecret!==void 0))throw new e.t(`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 xe(t){if(t===void 0)return;let{importScripts:n}=globalThis;if(!(typeof window>`u`&&typeof document>`u`&&typeof n!=`function`))throw new e.t(`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 Se(e){if(e===void 0)return;let t=l.t(s.c,e);return new s.l(typeof t==`string`?t:new Uint8Array(t))}var Ce=class{#e;provider;signer;storage;registry;permits;delegations;decryption;offline;#t;#n;#r;#i;#a;#o;#s;#c;#l;#u;#d;constructor(e,t={}){be(t),xe(t.transportKeyPairDerivationSecret);let n=Se(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 oe(e.storage,this.#i),this.#u=new fe({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 s.o({provider:this.provider,registryAddresses:r,registryTTL:e.registryTTL}),this.#n=r,this.#t=e.registryTTL,this.#l=new s.s({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 ue({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.#d=new ye({provider:this.provider,router:e.router,encryption:this.#s,emitEvent:(e,t)=>this.emitEvent(e,t)}),this.permits=new F({signer:this.signer,provider:this.provider,cachingService:this.#a,credentialService:this.#l,logger:this.#i,emitEvent:this.emitEvent.bind(this)}),this.delegations=new I({signer:this.signer,provider:this.provider,delegationService:this.#u}),this.decryption=new L({signer:this.signer,provider:this.provider,router:e.router,decryptionService:this.#c}),this.offline=new R(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 s.o({provider:this.provider,registryAddresses:{...this.#n,...e},registryTTL:this.#t})}async encrypt(e,t){return this.#s.encryptValues(e,a.r(t,`encrypt`))}createToken(e){return new r.t(this,e)}createWrappedToken(e){return new i.t(this,e)}dispose(){this.#o.dispose(),this.#e.dispose()}terminate(){this.dispose(),this.signer?.dispose?.()}[Symbol.dispose](){this.terminate()}};exports.ACL_TOPICS=i.n,exports.AclPausedError=w,exports.AclTopics=i.r,exports.BalanceCheckUnavailableError=r.d,exports.BaseSigner=s.t,exports.ChainMismatchError=r.g,exports.ChromeSessionStorage=z,exports.ConfigurationError=e.t,exports.Decryption=L,exports.DecryptionFailedError=n.t,exports.DefaultRegistryAddresses=s.a,exports.DelegationContractIsSelfError=C,exports.DelegationCooldownError=_,exports.DelegationDelegateCannotBeWildcardError=S,exports.DelegationDelegateEqualsContractError=x,exports.DelegationExpirationTooSoonError=T,exports.DelegationExpiredError=y,exports.DelegationExpiryUnchangedError=b,exports.DelegationNotFoundError=v,exports.DelegationNotPropagatedError=E,exports.DelegationSelfNotAllowedError=g,exports.Delegations=I,exports.ERC1363_INTERFACE_ID=t.t,exports.ERC20ReadFailedError=r.f,exports.ERC7984_INTERFACE_ID=t.n,exports.ERC7984_WRAPPER_INTERFACE_ID=t.r,exports.EncryptOffloadUnavailableError=n.n,exports.EncryptionFailedError=n.r,exports.IndexedDBStorage=s.f,exports.InsufficientAllowanceError=r.p,exports.InsufficientConfidentialBalanceError=r.m,exports.InsufficientERC20BalanceError=r.h,exports.InvalidTransportKeyPairError=t.K,exports.KeyWrappingError=t.q,exports.MAX_UINT64=N,exports.MemoryStorage=s.u,exports.MutableWalletAccountStore=s.n,exports.NoCiphertextError=t.J,exports.NotEntitledError=h,exports.Offline=R,exports.Permits=F,exports.PreparedPermitChainMismatchError=t.Y,exports.PreparedPermitExpiredError=t.X,exports.RelayerRequestFailedError=e.n,exports.RevokedKmsContextError=t.Z,exports.RpcRateLimitError=r._,exports.SignerNotConfiguredError=t.L,exports.SignerRequiredError=t.R,exports.SigningFailedError=t.U,exports.SigningRejectedError=t.W,exports.TOKEN_TOPICS=i.i,exports.Token=r.t,exports.Topics=i.a,exports.TransactionRevertedError=t.H,exports.TransportKeyPairChangedError=t.Q,exports.TransportKeyPairExpiredError=t.$,exports.UnshieldAlreadyFinalizedError=i.w,exports.WILDCARD_CONTRACT=P,exports.WalletAccountNotReadyError=t.z,exports.WalletNotConnectedError=t.B,exports.WrappedToken=i.t,exports.WrappersRegistry=s.o,exports.ZERO_ENCRYPTED_VALUE=r.s,exports.ZamaError=e.r,exports.ZamaErrorCode=e.i,exports.ZamaSDK=Ce,exports.ZamaSDKEvents=t.F,exports.allowanceContract=t.c,exports.anvil=d.t,exports.approveContract=t.l,exports.balanceOfContract=t.u,exports.bscTestnet=d.n,exports.chains=d.r,exports.chromeSessionStorage=re,exports.cleartext=o.t,exports.confidentialBalanceOfContract=t.h,exports.confidentialTotalSupplyContract=t.g,exports.confidentialTransferContract=t.v,exports.confidentialTransferFromContract=t.b,exports.createConfig=ne,exports.createWalletAccountStore=s.r,exports.decimalsContract=t.d,exports.decodeAclEvent=i.o,exports.decodeAclEvents=i.s,exports.decodeConfidentialTransfer=i.c,exports.decodeDelegatedForUserDecryption=i.l,exports.decodeOnChainEvent=i.u,exports.decodeOnChainEvents=i.d,exports.decodeRevokedDelegationForUserDecryption=i.f,exports.decodeUnwrapFinalized=i.p,exports.decodeUnwrapRequested=i.m,exports.decodeWrap=i.h,exports.delegateForUserDecryptionContract=k,exports.finalizeUnwrapContract=t.x,exports.findDelegatedForUserDecryption=i.g,exports.findRevokedDelegationForUserDecryption=i._,exports.findUnwrapRequested=i.v,exports.findWrap=i.y,exports.getConfidentialTokenAddressContract=u.t,exports.getDelegationExpiryContract=j,exports.getTokenAddressContract=u.n,exports.getTokenPairContract=u.r,exports.getTokenPairsContract=u.i,exports.getTokenPairsLengthContract=u.a,exports.getTokenPairsSliceContract=u.o,exports.hardhat=d.i,exports.hoodi=d.a,exports.indexedDBStorage=s.p,exports.inferredTotalSupplyContract=t.S,exports.isConfidentialTokenContract=t.i,exports.isConfidentialTokenValidContract=u.s,exports.isConfidentialWrapperContract=t.a,exports.isEncryptedValueZero=r.l,exports.isHandleDelegatedContract=M,exports.isOperatorContract=t.C,exports.isRetryable=e.a,exports.mainnet=d.o,exports.matchZamaError=m,exports.memoryStorage=s.d,exports.nameContract=t.p,exports.polygon=d.s,exports.polygonAmoy=d.c,exports.rateContract=t.w,exports.retryAfterSeconds=e.o,exports.revokeDelegationContract=A,exports.sepolia=d.l,exports.setOperatorContract=t.T,exports.supportsInterfaceContract=t.s,exports.symbolContract=t.m,exports.transferAndCallContract=i.C,exports.underlyingContract=t.E,exports.unwrapContract=t.D,exports.unwrapFromBalanceContract=t.O,exports.unwrapRequesterContract=t.k,exports.wrapContract=t.A,exports.zenithTrexTestnet=d.u;
2
2
  //# sourceMappingURL=index.cjs.map