@zama-fhe/sdk 3.8.0-beta.12 → 3.8.0-beta.13

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
- function e(e,t){let n=Object.entries({version:`3.8.0-beta.12`,layer:e.state.layer,runtime:e.runtime,...t!==void 0&&{operation:t}}),r=e=>Object.fromEntries(n.map(([t,n])=>[`${e}${t}`,n]));return e.mode===`query`?{query:r(`zama_sdk_`)}:{headers:r(`x-zama-sdk-`)}}function t(e,t){return Object.assign({},e,{operation:e?.operation??t})}function n(e){if(typeof e==`boolean`)return e?`header`:`off`;let t=typeof e==`string`?e.trim().toLowerCase():void 0;return t===`0`||t===`false`?`off`:t===`header`||t===`query`||t===`off`?t:void 0}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return n}});
1
+ function e(e,t){let n=Object.entries({version:`3.8.0-beta.13`,layer:e.state.layer,runtime:e.runtime,...t!==void 0&&{operation:t}}),r=e=>Object.fromEntries(n.map(([t,n])=>[`${e}${t}`,n]));return e.mode===`query`?{query:r(`zama_sdk_`)}:{headers:r(`x-zama-sdk-`)}}function t(e,t){return Object.assign({},e,{operation:e?.operation??t})}function n(e){if(typeof e==`boolean`)return e?`header`:`off`;let t=typeof e==`string`?e.trim().toLowerCase():void 0;return t===`0`||t===`false`?`off`:t===`header`||t===`query`||t===`off`?t:void 0}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return e}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return n}});
2
2
  //# sourceMappingURL=telemetry.cjs.map
@@ -1,2 +1,2 @@
1
- import{p as e,r as t,t as n}from"./relayer-ov8b_HOu.js";import{a as r,c as i,r as a,s as o,u as s}from"./signing-CneT-WIV.js";import{H as c,R as l,V as u,W as d,a as f,b as p,i as m,n as h,o as g,q as _,r as v,s as ee,t as y,v as b,x,y as te}from"./wrappers-registry-DnYVQ02R.js";import{r as ne}from"./applied-runtime-3fzqBC2V.js";import{t as re}from"./telemetry-BsoDvF-G.js";import{a as ie,i as ae,n as S,o as C,r as w,s as T,t as E}from"./primitives-Cym-3HKa.js";import{t as D}from"./validation-ChQwNxaY.js";import{a as O,l as oe,n as se,o as ce,s as le,u as ue}from"./chains-CF-Hzs9R.js";import{getAddress as k,toBytes as A,toHex as j,zeroAddress as de}from"viem";import{hasFhevmRuntimeConfig as fe,setFhevmRuntimeConfig as pe}from"@fhevm/sdk/viem";import{z as M}from"zod/mini";var N=class{#e=null;#t=null;#n;#r;#i;constructor(e=`CredentialStore`,t=1,n=`credentials`){this.#n=e,this.#r=t,this.#i=n}#a(){return this.#e?Promise.resolve(this.#e):(this.#t||=new Promise((e,t)=>{let n=indexedDB.open(this.#n,this.#r);n.onupgradeneeded=()=>{let e=n.result;e.objectStoreNames.contains(this.#i)||e.createObjectStore(this.#i,{keyPath:`key`})},n.onsuccess=()=>{this.#e=n.result,this.#t=null,this.#e.onversionchange=()=>{this.#e?.close(),this.#e=null,this.#t=null},this.#e.onclose=()=>{this.#e=null,this.#t=null},e(this.#e)},n.onerror=()=>{this.#e=null,this.#t=null,t(n.error)}}),this.#t)}async#o(e,t){let n=await this.#a();return new Promise((r,i)=>{let a=n.transaction(this.#i,e);a.onabort=()=>i(a.error??Error(`Transaction aborted`));let o=t(a.objectStore(this.#i));e===`readonly`?o.onsuccess=()=>r(o.result):a.oncomplete=()=>r(o.result),o.onerror=()=>i(o.error)})}async get(e){return(await this.#o(`readonly`,t=>t.get(e)))?.value??null}async set(e,t){await this.#o(`readwrite`,n=>n.put({key:e,value:t}))}async delete(e){await this.#o(`readwrite`,t=>t.delete(e))}async clear(){await this.#o(`readwrite`,e=>e.clear())}};const me=new N;var P=class{#e=new Map;async get(e){return this.#e.get(e)??null}async set(e,t){this.#e.set(e,t)}async delete(e){this.#e.delete(e)}};const he=new P;function ge(){return typeof window<`u`?new N(`CredentialStore`):new P}function _e(e=ge(),t=e){return{storage:e,permitStorage:t}}function ve(e,t,r){let i=e.map(e=>e.id),a=[...new Set(i.filter((e,t)=>i.indexOf(e)!==t))];if(a.length>0)throw new n(`Duplicate chain id(s) [${a.join(`, `)}] in the chains array. Each chain id must appear only once. Note: hardhat and anvil are aliases (both use 31337).`);let o=Object.keys(t).map(Number).filter(e=>!i.includes(e));o.length>0&&r.warn(`Relayer entries for chain(s) [${o.join(`, `)}] are ignored: those chains are not in the chains array. Add the chain config to use them, or drop the relayer entries.`);let s=new Map;for(let r of e){let e=t[r.id];if(!e)throw new n(`Chain ${r.id} has no relayer configured. Add a relayer entry: relayers: { [${r.id}]: web() }`);s.set(r.id,{chain:r,relayerConfig:e})}return s}var ye=class{#e;#t;#n;constructor(e,t,r,i){if(e.length===0)throw new n(`At least one chain is required.`);this.#e=new Map(e.map(e=>[e.id,e])),this.#n=e[0].id;let a=new Map;for(let[n,{relayerConfig:o,chain:s}]of ve(e,t,r))a.set(n,o.createRelayer(s,r,i));this.#t=a}get chains(){return[...this.#e.values()]}get chain(){let e=this.#e.get(this.#n);if(e===void 0)throw new n(`Chain ${this.#n} is not configured. Add it to the chains array.`);return e}switchChain(e){this.#n=e}dispose(){for(let e of new Set(this.#t.values()))e.dispose?.()}get relayer(){let e=this.#t.get(this.chain.id);if(e===void 0)throw new n(`No relayer configured for chain ${this.#n}. Add it to the relayers object.`);return e}};const F={version:1,info:`zama-sdk-keypair-wrapping-v1`,ivLengthBytes:12,tagLengthBytes:16};function I(e){return new Uint8Array(e)}function L(e){return I(new TextEncoder().encode(JSON.stringify([e.publicKey,e.createdAt,e.expiresAt,e.tkmsVersion??null])))}function be(e){return typeof e==`string`?new TextEncoder().encode(e):I(e)}var xe=class{#e;#t;constructor(e){this.#e=e}async baseKey(){return this.#t??=this.#n(this.#e),this.#t}async#n(e){let t=be(e),n=await crypto.subtle.importKey(`raw`,t,`HKDF`,!1,[`deriveKey`]);return t.fill(0),e instanceof Uint8Array&&e.fill(0),this.#e=void 0,n}};async function R(e,t){let n=await e.baseKey();return crypto.subtle.deriveKey({name:`HKDF`,hash:`SHA-256`,salt:new TextEncoder().encode(t),info:new TextEncoder().encode(F.info)},n,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`])}async function Se(e,t,n,r){let i=await R(t,n),a=crypto.getRandomValues(new Uint8Array(F.ivLengthBytes)),o=await crypto.subtle.encrypt({name:`AES-GCM`,iv:a,additionalData:L(r)},i,I(A(e)));return{wrappedPrivateKey:j(new Uint8Array(o)),iv:j(a)}}async function Ce(e,t,n,r){let i=await R(t,n),a=await crypto.subtle.decrypt({name:`AES-GCM`,iv:I(A(e.iv)),additionalData:L(r)},i,I(A(e.wrappedPrivateKey)));return j(new Uint8Array(a))}function we(e){return typeof e==`object`&&!!e&&`name`in e&&e.name===`OperationError`}const z=86400;function B(){return Math.floor(Date.now()/1e3)}function V(e){return[...new Set(e.map(E))].sort()}function Te(e){let{chainId:t}=e.domain;return typeof t==`bigint`?{...e,domain:{...e.domain,chainId:t.toString()}}:e}const Ee=`transportKeyPairTTL must be a positive integer number of seconds`,De=`permitTTL must be a positive integer number of days`,Oe=`transportKeyPairScope must be a non-empty string`,H=`transportKeyPairDerivationSecret must be a Uint8Array of at least 32 bytes or a string of at least 64 characters (256 bits of entropy): source it from a CSPRNG or secrets manager, not a human-memorable passphrase`,ke=365*z,Ae=M.int({error:Ee}).check(M.positive({error:Ee}),M.maximum(ke,`transportKeyPairTTL must not exceed the fhevm ACL maximum of ${ke}s (365 days)`)),je=M.int({error:De}).check(M.positive({error:De}),M.maximum(365,`permitTTL must not exceed the V1 permit maximum of 365 days`)),Me=M.string({error:Oe}).check(M.minLength(1,Oe)),Ne=M.union([M.string({error:H}).check(M.minLength(64,H)),M.instanceof(Uint8Array,{error:H}).check(M.refine(e=>e.byteLength>=32,{error:H}))],{error:H}),Pe=M.object({publicKey:w,privateKey:w,createdAt:T,expiresAt:C,tkmsVersion:M.optional(M.string())}),U=M.object({domain:M.record(M.string(),M.unknown()),primaryType:M.optional(M.string()),types:M.record(M.string(),M.array(M.object({name:M.string(),type:M.string()}))),message:M.record(M.string(),M.unknown())}),W=M.object({version:M.int().check(M.positive()),eip712:U,signature:w,signerAddress:S}),G=M.object({keypairPublicKey:w,contractAddresses:M.array(S).check(M.maxLength(10)),serializedPermit:W,startTimestamp:T,durationDays:ie}),Fe=M.array(G),Ie=M.array(M.string()),Le=M.object({version:M.literal(1),eip712:U,signerAddress:S}),Re=`iv must be a ${F.ivLengthBytes}-byte hex string`,ze=`wrappedPrivateKey must be a whole number of bytes and at least ${F.tagLengthBytes} bytes (the AES-GCM authentication tag)`;function Be(e){return(e.length-2)/2}const Ve=M.object({wrappingVersion:M.literal(F.version,{error:`wrappingVersion must be a wrapping scheme this SDK can read`}),publicKey:w,wrappedPrivateKey:w.check(M.refine(e=>e.length%2==0&&Be(e)>=F.tagLengthBytes,{error:ze})),iv:w.check(M.refine(e=>Be(e)===F.ivLengthBytes,{error:Re})),createdAt:T,expiresAt:C,tkmsVersion:M.optional(M.string())});function He(e){let t={publicKey:e.publicKey,createdAt:e.createdAt,expiresAt:e.expiresAt};return e.tkmsVersion&&(t.tkmsVersion=e.tkmsVersion),t}const K={version:F.version,schema:Ve,async encode(e,t,n){let{wrappedPrivateKey:r,iv:i}=await Se(e.privateKey,t,n,He(e)),a={wrappingVersion:F.version,publicKey:e.publicKey,wrappedPrivateKey:r,iv:i,createdAt:e.createdAt,expiresAt:e.expiresAt};return e.tkmsVersion&&(a.tkmsVersion=e.tkmsVersion),a},async decode(e,t,n){let r=await Ce({wrappedPrivateKey:e.wrappedPrivateKey,iv:e.iv},t,n,He(e)),i={publicKey:e.publicKey,privateKey:r,createdAt:e.createdAt,expiresAt:e.expiresAt};return e.tkmsVersion&&(i.tkmsVersion=e.tkmsVersion),i}},Ue=new Map([[K.version,K]]),We=K;function Ge(e){let t=e;return t.wrappingVersion!==void 0||t.wrappedPrivateKey!==void 0&&t.iv!==void 0}function Ke(e){if(typeof e!=`object`||!e||!Ge(e)){let t=Pe.safeParse(e);return t.success?{kind:`plaintext`,keyPair:t.data}:{kind:`unrecognized`}}let t=e.wrappingVersion,n=typeof t==`number`?Ue.get(t):void 0;if(n===void 0)return{kind:`unsupported-version`,version:t};let r=n.schema.safeParse(e);if(!r.success)return{kind:`corrupt-wrapped`};let i=r.data;return{kind:`wrapped`,expiresAt:i.expiresAt,decode:(e,t)=>n.decode(i,e,t)}}function qe(e,t,n){return We.encode(e,t,n)}function Je(e){return`keypair:${e}`}function q(e){return`keypair:scope:${e}`}function J(e){return`permits:${e.signerAddress}:${e.chainId}:${e.delegatorAddress}`}function Y(e){return`permits-index:${e}`}function Ye(e){return`scope:${e}`}function Xe(e,t){return{"wrapped-without-secret":`Transport key pair for scope "${t}" is wrapped, but this instance has no transportKeyPairDerivationSecret configured. Every instance sharing this scope must use the same transportKeyPairDerivationSecret; once they do, call permits.revokeTransportKeyPair() to rotate the entry.`,"unwrapped-under-secret":`Transport key pair for scope "${t}" is stored unwrapped, but this instance is configured with a transportKeyPairDerivationSecret. A peer instance sharing this scope is running without the secret: configure the same transportKeyPairDerivationSecret everywhere, then call permits.revokeTransportKeyPair() to migrate the scope to a wrapped entry.`,"unwrap-failed":`Transport key pair for scope "${t}" failed to unwrap. This usually means another instance created it with a different transportKeyPairDerivationSecret: every instance sharing this scope must use the same secret. It can also mean the stored entry is corrupted.`,"corrupt-wrapped":`Transport key pair for scope "${t}" is wrapped but structurally invalid: the stored iv or ciphertext is not a shape this wrapping scheme can produce. This usually means the stored entry is corrupted, or instances sharing this scope are running mismatched wrapping-scheme versions.`}[e]}const Ze={"unwrapped-under-secret":`unwrapped transport key pair entry found while a transportKeyPairDerivationSecret is configured`,"unwrap-failed":`transport key pair entry failed to unwrap (wrong transportKeyPairDerivationSecret?)`,"corrupt-wrapped":`structurally invalid wrapped transport key pair entry`};function Qe(e,t){let n=typeof e==`number`?`wrappingVersion ${e}`:`no wrappingVersion this build recognizes`;return`Transport key pair ${t===void 0?`for this signer`:`for scope "${t}"`} was written under a wrapping scheme this SDK build cannot read (${n}). The entry is preserved instead of regenerated, since an instance that understands the scheme may still be using it: ${t===void 0?`run a build that supports it, or call permits.clear() to discard the entry deliberately`:`run a build that supports it everywhere, or call permits.revokeTransportKeyPair() to rotate the scope`}.`}var $e=class{#e;#t;#n;#r;#i;#a;#o=new Map;#s=new Map;constructor(e){this.#e=e.generator,this.#t=e.storage,this.#n=e.ttl,this.#r=e.logger,this.#i=e.scope,this.#a=e.derivationSecret}#c(e){return this.#i===void 0?`signer:${e}`:Ye(this.#i)}#l(e){return this.#i===void 0?Je(e):q(this.#i)}async readStored(e){return this.#u(this.#l(e),this.#c(e))}async#u(e,t){let n=await this.#t.get(e);if(n==null)return null;let i=Ke(n);if(i.kind===`unsupported-version`)throw this.#f(e,Qe(i.version,this.#i));if(i.kind===`unrecognized`)return await this.#m(e,`malformed transport key pair entry`),null;let a=this.#a;if(a===void 0)return i.kind===`plaintext`?await this.#p(e,i.keyPair.expiresAt)?null:i.keyPair:this.#d(e,`wrapped-without-secret`);if(i.kind===`plaintext`)return this.#d(e,`unwrapped-under-secret`);if(i.kind===`corrupt-wrapped`)return this.#d(e,`corrupt-wrapped`);if(await this.#p(e,i.expiresAt))return null;try{return await i.decode(a,t)}catch(t){if(!we(t))throw this.#r.error(`transport key pair unwrap failed unexpectedly`,{key:e,error:t}),new r(`Transport key pair unwrap failed unexpectedly.`,{cause:t});return this.#d(e,`unwrap-failed`,t)}}async#d(e,t,n){if(this.#i!==void 0)throw this.#f(e,Xe(t,this.#i),n);if(t===`wrapped-without-secret`)throw this.#f(e,`Transport key pair for this signer is wrapped, but this instance has no transportKeyPairDerivationSecret configured. Configure the same transportKeyPairDerivationSecret the entry was written with. To downgrade to plaintext at rest on purpose, discard the stored entry first by calling permits.clear(), then run without the secret.`,n);let r=Ze[t];return this.#r.warn(r,{key:e}),await this.#m(e,r),null}#f(e,t,n){return this.#r.error(t,{key:e}),new r(t,{cause:n})}async#p(e,t){return B()<t?!1:(await this.#m(e,`expired transport key pair entry`),!0)}async#m(e,t){this.#r.debug(`discarding transport key pair entry`,{key:e,reason:t}),await l(`delete transport key pair entry`,()=>this.#t.delete(e),this.#r)}async getOrCreate(e,t){return this.#h(this.#l(e),this.#c(e),{strict:t?.strict})}async#h(e,t,n){let i=n?.strict??!1,a=`${e}::${i}`,o=this.#o.get(a);if(o)return o;let c=this.#s.get(e)??0,u=(async()=>{let n=await this.#u(e,t);if(n!==null)return n;let a=await this.#e(),o=B(),u=o+this.#n,d={publicKey:a.publicKey,privateKey:a.privateKey,createdAt:o,expiresAt:u};a.tkmsVersion&&(d.tkmsVersion=a.tkmsVersion);let f=d;if(this.#a!==void 0)try{f=await qe(d,this.#a,t)}catch(t){let n=`Failed to wrap the transport private key for at-rest storage.`;throw this.#r.error(n,{key:e,error:t}),new r(n,{cause:t})}if((this.#s.get(e)??0)===c)i?await this.#t.set(e,f):await l(`persist transport key pair`,()=>this.#t.set(e,f),this.#r);else if(i)throw new s(`The transport key pair was rotated while it was being generated, so the freshly generated key pair could not be persisted. Retry.`);return d})().finally(()=>{this.#o.delete(a)});return this.#o.set(a,u),u}async clear(e){let t=Je(e);await l(`delete transport key pair entry`,()=>this.#t.delete(t),this.#r)}async evict(e){let t=this.#l(e);await l(`evict transport key pair entry`,()=>this.#t.delete(t),this.#r)}async clearScope(){if(this.#i===void 0)return;let e=q(this.#i);this.#s.set(e,(this.#s.get(e)??0)+1),await this.#t.delete(e)}async warmScope(){this.#i!==void 0&&await this.#h(q(this.#i),Ye(this.#i),{strict:!0})}};function et(e){return D(Le,e)}function tt(e,t){let n=new Set(e.flatMap(e=>e.contractAddresses));return t.filter(e=>!n.has(e))}function nt(e){let t=[];for(let n=0;n<e.length;n+=10)t.push(e.slice(n,n+10));return t}function rt(e,t,n){return e.filter(e=>e.keypairPublicKey===t&&n<e.startTimestamp+e.durationDays*86400)}function it(e,t){let n=new Set(t);return e.filter(e=>!e.contractAddresses.some(e=>n.has(e)))}function X(e,t){return[...new Set([...e,...t])].sort()}function at(e,t,n){let r=new Set(n),i=e.filter(e=>new Set([...e.contractAddresses,...t]).size<=10);if(i.length===0)return null;function a(e){return e.contractAddresses.reduce((e,t)=>e+ +!!r.has(t),0)}let o=Math.max(...i.map(a));return i.filter(e=>a(e)===o).reduce((e,t)=>t.startTimestamp>e.startTimestamp?t:e)}var ot=class{#e;#t;constructor(e){this.#e=e.storage,this.#t=e.logger}async list(e){let t=J(e),n=await this.#e.get(t);if(n==null)return[];let r=Fe.safeParse(n);return r.success?r.data:(await this.clearScope(e),[])}async listUsableAndPrune(e,t){let n=await this.list(e),r=rt(n,t,Math.floor(Date.now()/1e3));return r.length!==n.length&&(r.length===0?await this.clearScope(e):await l(`update permit entry`,()=>this.#e.set(J(e),r),this.#t)),r}async append(e,t){if(t.length===0)return;let n=t.map(e=>G.parse(e)),r=await this.list(e);await this.#e.set(J(e),[...r,...n]),await this.#r(e)}async replace(e,t,n){let r=G.parse(n),i=(await this.list(e)).filter(e=>e.serializedPermit.signature!==t);await this.#e.set(J(e),[...i,r]),await this.#r(e)}async deletePermitsTouching(e,t){let n=await this.list(e);if(n.length===0)return;let r=it(n,t);r.length===0?await this.clearScope(e):await this.#e.set(J(e),r)}async clearScope(e){await this.#a(J(e)),await this.#i(e)}async clearAllForSigner(e){let t=Y(e),n=await this.#n(t);await Promise.all(n.map(e=>this.#a(e))),await l(`delete permit index`,()=>this.#e.delete(t),this.#t)}async#n(e){let t=await this.#e.get(e);if(t==null)return[];let n=Ie.safeParse(t);return n.success?n.data:(await l(`delete permit index`,()=>this.#e.delete(e),this.#t),[])}async#r(e){let t=Y(e.signerAddress),n=J(e),r=await this.#n(t);r.includes(n)||await this.#e.set(t,[...r,n])}async#i(e){let t=Y(e.signerAddress),n=J(e),r=await this.#n(t),i=r.filter(e=>e!==n);i.length!==r.length&&(i.length===0?await l(`delete permit index`,()=>this.#e.delete(t),this.#t):await l(`update permit index`,()=>this.#e.set(t,i),this.#t))}async#a(e){await l(`delete permit entry`,()=>this.#e.delete(e),this.#t)}};async function st(e,t,n){let r=e.get(t);if(r!==void 0)return r;let i=await n();return e.set(t,i),i}var ct=class{#e;#t;#n;#r;#i;#a;#o;#s;#c=new Map;constructor(e){this.#e=new $e({generator:async()=>{let t=e.router.relayer,n=await t.generateTransportKeyPair();return t.serializeTransportKeyPair({transportKeyPair:n})},storage:e.storage,ttl:e.transportKeyPairTTL,logger:e.logger,scope:e.scope,derivationSecret:e.derivationSecret}),this.#t=new ot({storage:e.permitStorage??e.storage,logger:e.logger}),this.#n=e.router,this.#r=e.signer,this.#i=e.permitTTL,this.#a=e.logger,this.#o=e.emitEvent,this.#s=e.scope}#l(e){if(!this.#r)throw new d(e);return this.#r}#u(e,t,n=``){let r=a(t,{operation:e});return n&&(r.message=n+r.message),this.#o({type:c.PermitError,operation:e,error:r}),r}async grantPermit(e,t){let n=t===void 0?`grantPermit`:`grantDelegationPermit`,r,i,a;try{r=E(this.#l(`grantPermit`).requireWalletAccount(`grantPermit`).address),i=V(e),a=this.#f(r,t)}catch(e){throw this.#u(n,e)}let o=await this.#e.getOrCreate(r);if(i.length===0)return{keypair:o,permissions:[]};let s;try{s=await this.#t.listUsableAndPrune(a,o.publicKey)}catch(e){throw this.#u(n,e)}let c=tt(s,i);if(c.length>0){let e=at(s,c,i);if(e!==null){let t=X(e.contractAddresses,c),n=await this.#p({chunk:t,keypair:o,scope:a});await l(`replace permit`,()=>this.#t.replace(a,e.serializedPermit.signature,n),this.#a),s[s.indexOf(e)]=n}else for(let e of nt(c)){let t=await this.#p({chunk:e,keypair:o,scope:a});s.push(t),await l(`persist permit`,()=>this.#t.append(a,[t]),this.#a)}}let u=new Set(i);return{keypair:o,permissions:s.filter(e=>e.contractAddresses.some(e=>u.has(e)))}}async preparePermit(e){let t=V(e.contracts).length;if(t>10)throw new n(`preparePermit: request.contracts must not exceed 10 addresses (got ${t}). Use batchPreparePermits to split them across permits.`);let[r]=await this.batchPreparePermits(e);return u(r,`batchPreparePermits result`),r}async batchPreparePermits(e){let t=E(e.signer),r=V(e.contracts);if(r.length===0)throw new n(`request.contracts must not be empty.`);let i=e.delegator?E(e.delegator):void 0;if(i!==void 0&&i===t)throw new n(`request.delegator must differ from request.signer: self-delegation is not allowed.`);let a=e.durationDays===void 0?this.#i:D(je,e.durationDays),o=this.#n.relayer,s=await this.#e.getOrCreate(t,{strict:!0}),c=await o.parseTransportKeyPair(s),l=B();return Promise.all(nt(r).map(async e=>({version:1,eip712:Te(U.parse(await o.createUnsignedLegacyDecryptionPermitEip712({transportKeyPair:c,contractAddresses:e,startTimestamp:l,durationSeconds:a*z,...i&&{delegatorAddress:i}}))),signerAddress:t})))}async batchRegisterPermits(e){if(e.length===0)throw new n(`permits must not be empty.`);let t={relayer:this.#n.relayer,activeChainId:this.#n.chain.id,storedKeyPairs:new Map,transportKeyPairs:new Map},r=[];for(let[n,{prepared:i,signature:a}]of e.entries()){let o=e.length>1?`permits[${n}]: `:``;r.push(await this.#d(i,a,t,o))}for(let{scope:e,permission:t}of r)await l(`replace permit`,()=>this.#t.replace(e,t.serializedPermit.signature,t),this.#a)}async#d(e,t,{relayer:r,activeChainId:a,storedKeyPairs:c,transportKeyPairs:l},u){let d;try{d=et(e)}catch(e){throw this.#u(`registerPermit`,e,u)}let{domain:f,message:p}=d.eip712,m=Number(f.chainId);if(m!==a)throw this.#u(`registerPermit`,new o({preparedChainId:m,activeChainId:a}),u);let h=Number(p.startTimestamp),g=Number(p.durationDays);if(B()>=h+g*86400)throw this.#u(`registerPermit`,new i(`registerPermit: the prepared permit's validity window (starting ${h}, ${g}d) has already elapsed. Prepare the permit again.`),u);let _=d.signerAddress,v=await st(c,_,()=>this.#e.readStored(_));if(v===null||v.publicKey!==p.publicKey)throw new s(`${u}registerPermit: the transport key pair changed since the permit was prepared. Prepare it again to rebind the signature request to the current key pair.`);try{let e=await st(l,_,()=>r.parseTransportKeyPair(v)),i=await r.parseSignedDecryptionPermit({serializedPermit:{version:d.version,eip712:d.eip712,signature:t,signerAddress:_},transportKeyPair:e});if(i.version!==1)throw new n(`registerPermit: expected a V1 signed permit, got version ${i.version}.`);let o=D(W,await r.serializeSignedDecryptionPermit({signedPermit:i})),s={keypairPublicKey:v.publicKey,contractAddresses:V(i.eip712.message.contractAddresses),serializedPermit:o,startTimestamp:Number(i.eip712.message.startTimestamp),durationDays:Number(i.eip712.message.durationDays)};return{scope:{signerAddress:_,chainId:a,delegatorAddress:E(i.encryptedDataOwnerAddress)},permission:s}}catch(e){throw this.#u(`registerPermit`,e,u)}}async hasPermit(e,t){if(e.length===0)return!0;let n=this.#r?.walletAccount.getSnapshot();if(!n)return!1;let i=E(n.address),a;try{a=await this.#e.readStored(i)}catch(e){if(!(e instanceof r))throw e;return!1}if(a===null)return!1;let o=this.#f(i,t);return tt(await this.#t.listUsableAndPrune(o,a.publicKey),V(e)).length===0}async revokePermits(e){let t=E(this.#l(`revokePermits`).requireWalletAccount(`revokePermits`).address);if(e===void 0){await this.#t.clearAllForSigner(t);return}let n=V(e);n.length!==0&&await this.#t.deletePermitsTouching(this.#f(t),n)}#f(e,t){return{signerAddress:e,chainId:this.#n.chain.id,delegatorAddress:t?E(t):e}}async clearCredentials(){let e=E(this.#l(`clearCredentials`).requireWalletAccount(`clearCredentials`).address);await this.#e.clear(e),await this.#t.clearAllForSigner(e)}async revokeTransportKeyPair(e){if(this.#s===void 0)throw new n(`revokeTransportKeyPair() requires a transportKeyPairScope to be configured on this SDK instance — there is no shared key pair to revoke.`);if(e!==this.#s)throw new n(`revokeTransportKeyPair("${e}") does not match the configured scope ("${this.#s}").`);await this.#e.clearScope()}async warmTransportKeyPair(e){await this.#e.getOrCreate(E(e))}async warmTransportKeyPairScope(e){if(this.#s===void 0)throw new n(`warmTransportKeyPairScope() requires a transportKeyPairScope to be configured on this SDK instance — there is no shared key pair to warm.`);if(e!==this.#s)throw new n(`warmTransportKeyPairScope("${e}") does not match the configured scope ("${this.#s}").`);await this.#e.warmScope()}async handleWalletAccountChange(e,t){let n=e?E(e.address):void 0;n!==(t?E(t.address):void 0)&&n&&(await this.#e.clear(n),await this.#t.clearAllForSigner(n))}async#p(n){let{chunk:r,keypair:i,scope:a}=n,o=B(),s=a.delegatorAddress!==a.signerAddress,c=this.#n.relayer;try{let e={transportKeyPair:await c.parseTransportKeyPair(i),contractAddresses:r,startTimestamp:o,durationSeconds:this.#i*z,signerAddress:a.signerAddress,signer:this.#l(`signPermit`)},t=s?await c.signDecryptionPermit({...e,delegatorAddress:a.delegatorAddress}):await c.signDecryptionPermit(e),n=D(W,await c.serializeSignedDecryptionPermit({signedPermit:t}));return{keypairPublicKey:i.publicKey,contractAddresses:r,serializedPermit:n,startTimestamp:o,durationDays:this.#i}}catch(n){let r=s?`grantDelegationPermit`:`grantPermit`;throw!(n instanceof t)&&n instanceof Error&&e(n.message)&&await this.#e.evict(a.signerAddress),this.#u(r,n)}}async evictTransportKeyPair(){let e=this.#r?.walletAccount.getSnapshot();e&&await this.#e.evict(E(e.address))}async recoverPermits(e,t,n){let r=this.#l(`recoverPermits`).requireWalletAccount(`recoverPermits`),i=this.#f(E(r.address),t),a=J(i),o=this.#c.get(a);if(o)return await o,this.grantPermit(e,t);let s=await this.#m(i),c=this.#c.get(a);if(c)return await c,this.grantPermit(e,t);if(s===null)return this.grantPermit(e,t);let l=new Set(n??[]);if(l.size>0&&!s.some(e=>l.has(e.serializedPermit.signature)))return this.grantPermit(e,t);let u=s.filter(e=>!l.has(e.serializedPermit.signature)),d=s.flatMap(e=>e.contractAddresses),f=this.#h(i,d,e,u,t).finally(()=>{this.#c.delete(a)});return this.#c.set(a,f),await f,this.grantPermit(e,t)}async#m(e){try{return await this.#t.list(e)}catch(e){return this.#a.warn(`read permits for recovery failed`,{error:e}),null}}async#h(e,t,n,r,i){await l(`evict revoked permits`,()=>this.#t.clearScope(e),this.#a);try{await this.grantPermit(X(t,V(n)),i)}catch(t){throw r.length>0&&await l(`restore surviving permits`,async()=>{let t=await this.#t.list(e),n=new Set(t.map(e=>e.serializedPermit.signature)),i=r.filter(e=>!n.has(e.serializedPermit.signature));i.length>0&&await this.#t.append(e,i)},this.#a),t}}},lt=class{#e;#t=`[zama-sdk]`;constructor(e){this.#e=e}error(e,t){this.#e?.error(`${this.#t} ${e}`,t)}warn(e,t){this.#e?.warn(`${this.#t} ${e}`,t)}info(e,t){this.#e?.info(`${this.#t} ${e}`,t)}debug(e,t){this.#e?.debug(`${this.#t} ${e}`,t)}warnAlways(e){console.warn(`${this.#t} ${e}`),this.warn(e)}};const ut={[ce.id]:ce.registryAddress,[le.id]:le.registryAddress,[oe.id]:oe.registryAddress,[O.id]:O.registryAddress,[ue.id]:ue.registryAddress,[se.id]:se.registryAddress},dt=M.record(M.string().check(M.regex(/^\d+$/,`expected numeric chain id key`)),S),Z=ae,Q=300*1e3;var ft=class{provider;#e;#t;#n=new Map;constructor(e){this.provider=e.provider,this.#e=Object.assign({},ut,D(M.optional(dt),e.registryAddresses)),this.#t=D(Z,e.registryTTL??86400)*1e3}getAddress(e){return this.#e[e]}#r(e){let t=this.#n.get(e);if(t){if(Date.now()>=t.expiresAt){this.#n.delete(e);return}return t.data}}#i(e,t,n=this.#t){return this.#n.set(e,{data:t,expiresAt:Date.now()+n}),t}refresh(){this.#n.clear()}get ttlMs(){return this.#t}async getRegistryAddress(){let e=await this.provider.getChainId(),t=this.#e[e];if(!t)throw new n(`No wrappers registry address configured for chain ${e}.\nPass a registryAddresses entry for this chain.`);return k(t)}async listPairs(e={}){let t=e.page??1,r=e.pageSize??100,i=e.metadata??!1;if(t<1)throw new n(`page must be >= 1, got ${t}`);if(r<1)throw new n(`pageSize must be >= 1, got ${r}`);let a=await this.getRegistryAddress(),o=`total:${a}`,s=this.#r(o);if(s===void 0){let e=await this.provider.readContract(f(a));s=this.#i(o,Number(e))}let c=BigInt((t-1)*r),l=c+BigInt(r)>BigInt(s)?BigInt(s):c+BigInt(r);if(c>=BigInt(s))return{items:[],total:s,page:t,pageSize:r};let u=`slice:${a}:${c}:${l}`,d=this.#r(u);if(d===void 0){let e=await this.provider.readContract(g(a,c,l));d=this.#i(u,[...e])}if(!i)return{items:d,total:s,page:t,pageSize:r};let p=`metadata:${a}:${c}:${l}`,m=this.#r(p);if(m===void 0){let e=await Promise.allSettled(d.map(e=>this.#a(e))),t=e.some(e=>e.status===`rejected`),n=e.map((e,t)=>e.status===`fulfilled`?e.value:Object.assign({},d[t],{metadataFailed:!0,underlying:{name:`Unknown`,symbol:`???`,decimals:0,totalSupply:0n},confidential:{name:`Unknown`,symbol:`???`,decimals:0}}));m=this.#i(p,n,t?Q:void 0)}return{items:m,total:s,page:t,pageSize:r}}async#a(e){let[t,n,r,i,a,o,s]=await Promise.all([this.provider.readContract(p(e.tokenAddress)),this.provider.readContract(x(e.tokenAddress)),this.provider.readContract(b(e.tokenAddress)),this.provider.readContract(te(e.tokenAddress)),this.provider.readContract(p(e.confidentialTokenAddress)),this.provider.readContract(x(e.confidentialTokenAddress)),this.provider.readContract(b(e.confidentialTokenAddress))]);return{...e,underlying:{name:t,symbol:n,decimals:r,totalSupply:i},confidential:{name:a,symbol:o,decimals:s}}}async getConfidentialToken(e){let t=await this.getRegistryAddress(),n=k(e),r=`ct:${t}:${n}`,i=this.#r(r);if(i!==void 0)return i;let[a,o]=await this.provider.readContract(y(t,n));return o===de?this.#i(r,null,Q):this.#i(r,{confidentialTokenAddress:o,isValid:a})}async getUnderlyingToken(e){let t=await this.getRegistryAddress(),n=k(e),r=`ut:${t}:${n}`,i=this.#r(r);if(i!==void 0)return i;let[a,o]=await this.provider.readContract(h(t,n));return o===de?this.#i(r,null,Q):this.#i(r,{tokenAddress:o,isValid:a})}async getTokenPairs(){let e=await this.getRegistryAddress();return this.provider.readContract(m(e))}async getTokenPairsLength(){let e=await this.getRegistryAddress();return this.provider.readContract(f(e))}async getTokenPairsSlice(e,t){let n=await this.getRegistryAddress();return this.provider.readContract(g(n,e,t))}async getTokenPair(e){let t=await this.getRegistryAddress();return this.provider.readContract(v(t,e))}async getConfidentialTokenAddress(e){let t=await this.getRegistryAddress();return this.provider.readContract(y(t,k(e)))}async getTokenAddress(e){let t=await this.getRegistryAddress();return this.provider.readContract(h(t,k(e)))}async isConfidentialTokenValid(e){let t=await this.getRegistryAddress();return this.provider.readContract(ee(t,k(e)))}};function pt(e,t,n){let r=new lt(n.logger),i=n.logger,a={wasmAssetLoadMode:`auto`,moduleVersions:`auto`,logger:{error:(e,t)=>i?.error(e,{cause:t}),warn:e=>i?.warn(e),debug:e=>i?.debug(e)},...n.runtime};if(fe()){let e=`runtime configuration is already set and cannot be changed.`;n.runtime===void 0?r.debug(e):r.warn(e)}else pe(a),ne(a);let{storage:o,permitStorage:s}=_e(n.storage,n.permitStorage),c=re(n.telemetry)??`header`,l=c===`off`?void 0:{layer:`core`,mode:c},u=new ye(n.chains,n.relayers,r,l);return{chains:n.chains,router:u,provider:t,signer:e,storage:o,permitStorage:s,transportKeyPairTTL:D(Ae,n.transportKeyPairTTL??2592e3),permitTTL:D(je,n.permitTTL??30),clearCredentialsOnWalletChange:n.clearCredentialsOnWalletChange??!0,transportKeyPairScope:n.transportKeyPairScope===void 0?void 0:D(Me,n.transportKeyPairScope),registryTTL:D(Z,n.registryTTL??86400),logger:r,onEvent:n.onEvent,telemetry:l}}function mt(e,t){return e?.address===t?.address&&e?.chainId===t?.chainId}var $=class{#e=new Set;#t;#n;constructor(e){this.#t=e,this.#n=e!==void 0}getSnapshot(){return this.#t}isReady(){return this.#n}setSnapshot(e){this.#n=!0;let t=this.#t;mt(t,e)||(this.#t=e,this.#r({previous:t,next:e}))}subscribe(e){this.#e.add(e);let t=this.#t;return t&&e({previous:void 0,next:t}),()=>{this.#e.delete(e)}}#r(e){for(let t of this.#e)t(e)}};function ht(e){return new $(e)}var gt=class{walletAccount;#e=!1;constructor(e){this.walletAccount=new $(e)}requireWalletAccount(e){let t=this.walletAccount.getSnapshot();if(!t)throw new _(e);return t}dispose(){this.#e||(this.#e=!0,this.onDispose())}[Symbol.dispose](){this.dispose()}onDispose(){}};export{ut as a,et as c,P as d,he as f,pt as i,Ne as l,me as m,$ as n,ft as o,N as p,ht as r,ct as s,gt as t,xe as u};
2
- //# sourceMappingURL=base-signer-CfjlL6bq.js.map
1
+ import{p as e,r as t,t as n}from"./relayer-ov8b_HOu.js";import{a as r,c as i,r as a,s as o,u as s}from"./signing-CneT-WIV.js";import{H as c,R as l,V as u,W as d,a as f,b as p,i as m,n as h,o as g,q as _,r as v,s as ee,t as y,v as b,x,y as te}from"./wrappers-registry-DnYVQ02R.js";import{r as ne}from"./applied-runtime-3fzqBC2V.js";import{t as re}from"./telemetry-D9Mf59ts.js";import{a as ie,i as ae,n as S,o as C,r as w,s as T,t as E}from"./primitives-Cym-3HKa.js";import{t as D}from"./validation-ChQwNxaY.js";import{a as O,l as oe,n as se,o as ce,s as le,u as ue}from"./chains-CF-Hzs9R.js";import{getAddress as k,toBytes as A,toHex as j,zeroAddress as de}from"viem";import{hasFhevmRuntimeConfig as fe,setFhevmRuntimeConfig as pe}from"@fhevm/sdk/viem";import{z as M}from"zod/mini";var N=class{#e=null;#t=null;#n;#r;#i;constructor(e=`CredentialStore`,t=1,n=`credentials`){this.#n=e,this.#r=t,this.#i=n}#a(){return this.#e?Promise.resolve(this.#e):(this.#t||=new Promise((e,t)=>{let n=indexedDB.open(this.#n,this.#r);n.onupgradeneeded=()=>{let e=n.result;e.objectStoreNames.contains(this.#i)||e.createObjectStore(this.#i,{keyPath:`key`})},n.onsuccess=()=>{this.#e=n.result,this.#t=null,this.#e.onversionchange=()=>{this.#e?.close(),this.#e=null,this.#t=null},this.#e.onclose=()=>{this.#e=null,this.#t=null},e(this.#e)},n.onerror=()=>{this.#e=null,this.#t=null,t(n.error)}}),this.#t)}async#o(e,t){let n=await this.#a();return new Promise((r,i)=>{let a=n.transaction(this.#i,e);a.onabort=()=>i(a.error??Error(`Transaction aborted`));let o=t(a.objectStore(this.#i));e===`readonly`?o.onsuccess=()=>r(o.result):a.oncomplete=()=>r(o.result),o.onerror=()=>i(o.error)})}async get(e){return(await this.#o(`readonly`,t=>t.get(e)))?.value??null}async set(e,t){await this.#o(`readwrite`,n=>n.put({key:e,value:t}))}async delete(e){await this.#o(`readwrite`,t=>t.delete(e))}async clear(){await this.#o(`readwrite`,e=>e.clear())}};const me=new N;var P=class{#e=new Map;async get(e){return this.#e.get(e)??null}async set(e,t){this.#e.set(e,t)}async delete(e){this.#e.delete(e)}};const he=new P;function ge(){return typeof window<`u`?new N(`CredentialStore`):new P}function _e(e=ge(),t=e){return{storage:e,permitStorage:t}}function ve(e,t,r){let i=e.map(e=>e.id),a=[...new Set(i.filter((e,t)=>i.indexOf(e)!==t))];if(a.length>0)throw new n(`Duplicate chain id(s) [${a.join(`, `)}] in the chains array. Each chain id must appear only once. Note: hardhat and anvil are aliases (both use 31337).`);let o=Object.keys(t).map(Number).filter(e=>!i.includes(e));o.length>0&&r.warn(`Relayer entries for chain(s) [${o.join(`, `)}] are ignored: those chains are not in the chains array. Add the chain config to use them, or drop the relayer entries.`);let s=new Map;for(let r of e){let e=t[r.id];if(!e)throw new n(`Chain ${r.id} has no relayer configured. Add a relayer entry: relayers: { [${r.id}]: web() }`);s.set(r.id,{chain:r,relayerConfig:e})}return s}var ye=class{#e;#t;#n;constructor(e,t,r,i){if(e.length===0)throw new n(`At least one chain is required.`);this.#e=new Map(e.map(e=>[e.id,e])),this.#n=e[0].id;let a=new Map;for(let[n,{relayerConfig:o,chain:s}]of ve(e,t,r))a.set(n,o.createRelayer(s,r,i));this.#t=a}get chains(){return[...this.#e.values()]}get chain(){let e=this.#e.get(this.#n);if(e===void 0)throw new n(`Chain ${this.#n} is not configured. Add it to the chains array.`);return e}switchChain(e){this.#n=e}dispose(){for(let e of new Set(this.#t.values()))e.dispose?.()}get relayer(){let e=this.#t.get(this.chain.id);if(e===void 0)throw new n(`No relayer configured for chain ${this.#n}. Add it to the relayers object.`);return e}};const F={version:1,info:`zama-sdk-keypair-wrapping-v1`,ivLengthBytes:12,tagLengthBytes:16};function I(e){return new Uint8Array(e)}function L(e){return I(new TextEncoder().encode(JSON.stringify([e.publicKey,e.createdAt,e.expiresAt,e.tkmsVersion??null])))}function be(e){return typeof e==`string`?new TextEncoder().encode(e):I(e)}var xe=class{#e;#t;constructor(e){this.#e=e}async baseKey(){return this.#t??=this.#n(this.#e),this.#t}async#n(e){let t=be(e),n=await crypto.subtle.importKey(`raw`,t,`HKDF`,!1,[`deriveKey`]);return t.fill(0),e instanceof Uint8Array&&e.fill(0),this.#e=void 0,n}};async function R(e,t){let n=await e.baseKey();return crypto.subtle.deriveKey({name:`HKDF`,hash:`SHA-256`,salt:new TextEncoder().encode(t),info:new TextEncoder().encode(F.info)},n,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`])}async function Se(e,t,n,r){let i=await R(t,n),a=crypto.getRandomValues(new Uint8Array(F.ivLengthBytes)),o=await crypto.subtle.encrypt({name:`AES-GCM`,iv:a,additionalData:L(r)},i,I(A(e)));return{wrappedPrivateKey:j(new Uint8Array(o)),iv:j(a)}}async function Ce(e,t,n,r){let i=await R(t,n),a=await crypto.subtle.decrypt({name:`AES-GCM`,iv:I(A(e.iv)),additionalData:L(r)},i,I(A(e.wrappedPrivateKey)));return j(new Uint8Array(a))}function we(e){return typeof e==`object`&&!!e&&`name`in e&&e.name===`OperationError`}const z=86400;function B(){return Math.floor(Date.now()/1e3)}function V(e){return[...new Set(e.map(E))].sort()}function Te(e){let{chainId:t}=e.domain;return typeof t==`bigint`?{...e,domain:{...e.domain,chainId:t.toString()}}:e}const Ee=`transportKeyPairTTL must be a positive integer number of seconds`,De=`permitTTL must be a positive integer number of days`,Oe=`transportKeyPairScope must be a non-empty string`,H=`transportKeyPairDerivationSecret must be a Uint8Array of at least 32 bytes or a string of at least 64 characters (256 bits of entropy): source it from a CSPRNG or secrets manager, not a human-memorable passphrase`,ke=365*z,Ae=M.int({error:Ee}).check(M.positive({error:Ee}),M.maximum(ke,`transportKeyPairTTL must not exceed the fhevm ACL maximum of ${ke}s (365 days)`)),je=M.int({error:De}).check(M.positive({error:De}),M.maximum(365,`permitTTL must not exceed the V1 permit maximum of 365 days`)),Me=M.string({error:Oe}).check(M.minLength(1,Oe)),Ne=M.union([M.string({error:H}).check(M.minLength(64,H)),M.instanceof(Uint8Array,{error:H}).check(M.refine(e=>e.byteLength>=32,{error:H}))],{error:H}),Pe=M.object({publicKey:w,privateKey:w,createdAt:T,expiresAt:C,tkmsVersion:M.optional(M.string())}),U=M.object({domain:M.record(M.string(),M.unknown()),primaryType:M.optional(M.string()),types:M.record(M.string(),M.array(M.object({name:M.string(),type:M.string()}))),message:M.record(M.string(),M.unknown())}),W=M.object({version:M.int().check(M.positive()),eip712:U,signature:w,signerAddress:S}),G=M.object({keypairPublicKey:w,contractAddresses:M.array(S).check(M.maxLength(10)),serializedPermit:W,startTimestamp:T,durationDays:ie}),Fe=M.array(G),Ie=M.array(M.string()),Le=M.object({version:M.literal(1),eip712:U,signerAddress:S}),Re=`iv must be a ${F.ivLengthBytes}-byte hex string`,ze=`wrappedPrivateKey must be a whole number of bytes and at least ${F.tagLengthBytes} bytes (the AES-GCM authentication tag)`;function Be(e){return(e.length-2)/2}const Ve=M.object({wrappingVersion:M.literal(F.version,{error:`wrappingVersion must be a wrapping scheme this SDK can read`}),publicKey:w,wrappedPrivateKey:w.check(M.refine(e=>e.length%2==0&&Be(e)>=F.tagLengthBytes,{error:ze})),iv:w.check(M.refine(e=>Be(e)===F.ivLengthBytes,{error:Re})),createdAt:T,expiresAt:C,tkmsVersion:M.optional(M.string())});function He(e){let t={publicKey:e.publicKey,createdAt:e.createdAt,expiresAt:e.expiresAt};return e.tkmsVersion&&(t.tkmsVersion=e.tkmsVersion),t}const K={version:F.version,schema:Ve,async encode(e,t,n){let{wrappedPrivateKey:r,iv:i}=await Se(e.privateKey,t,n,He(e)),a={wrappingVersion:F.version,publicKey:e.publicKey,wrappedPrivateKey:r,iv:i,createdAt:e.createdAt,expiresAt:e.expiresAt};return e.tkmsVersion&&(a.tkmsVersion=e.tkmsVersion),a},async decode(e,t,n){let r=await Ce({wrappedPrivateKey:e.wrappedPrivateKey,iv:e.iv},t,n,He(e)),i={publicKey:e.publicKey,privateKey:r,createdAt:e.createdAt,expiresAt:e.expiresAt};return e.tkmsVersion&&(i.tkmsVersion=e.tkmsVersion),i}},Ue=new Map([[K.version,K]]),We=K;function Ge(e){let t=e;return t.wrappingVersion!==void 0||t.wrappedPrivateKey!==void 0&&t.iv!==void 0}function Ke(e){if(typeof e!=`object`||!e||!Ge(e)){let t=Pe.safeParse(e);return t.success?{kind:`plaintext`,keyPair:t.data}:{kind:`unrecognized`}}let t=e.wrappingVersion,n=typeof t==`number`?Ue.get(t):void 0;if(n===void 0)return{kind:`unsupported-version`,version:t};let r=n.schema.safeParse(e);if(!r.success)return{kind:`corrupt-wrapped`};let i=r.data;return{kind:`wrapped`,expiresAt:i.expiresAt,decode:(e,t)=>n.decode(i,e,t)}}function qe(e,t,n){return We.encode(e,t,n)}function Je(e){return`keypair:${e}`}function q(e){return`keypair:scope:${e}`}function J(e){return`permits:${e.signerAddress}:${e.chainId}:${e.delegatorAddress}`}function Y(e){return`permits-index:${e}`}function Ye(e){return`scope:${e}`}function Xe(e,t){return{"wrapped-without-secret":`Transport key pair for scope "${t}" is wrapped, but this instance has no transportKeyPairDerivationSecret configured. Every instance sharing this scope must use the same transportKeyPairDerivationSecret; once they do, call permits.revokeTransportKeyPair() to rotate the entry.`,"unwrapped-under-secret":`Transport key pair for scope "${t}" is stored unwrapped, but this instance is configured with a transportKeyPairDerivationSecret. A peer instance sharing this scope is running without the secret: configure the same transportKeyPairDerivationSecret everywhere, then call permits.revokeTransportKeyPair() to migrate the scope to a wrapped entry.`,"unwrap-failed":`Transport key pair for scope "${t}" failed to unwrap. This usually means another instance created it with a different transportKeyPairDerivationSecret: every instance sharing this scope must use the same secret. It can also mean the stored entry is corrupted.`,"corrupt-wrapped":`Transport key pair for scope "${t}" is wrapped but structurally invalid: the stored iv or ciphertext is not a shape this wrapping scheme can produce. This usually means the stored entry is corrupted, or instances sharing this scope are running mismatched wrapping-scheme versions.`}[e]}const Ze={"unwrapped-under-secret":`unwrapped transport key pair entry found while a transportKeyPairDerivationSecret is configured`,"unwrap-failed":`transport key pair entry failed to unwrap (wrong transportKeyPairDerivationSecret?)`,"corrupt-wrapped":`structurally invalid wrapped transport key pair entry`};function Qe(e,t){let n=typeof e==`number`?`wrappingVersion ${e}`:`no wrappingVersion this build recognizes`;return`Transport key pair ${t===void 0?`for this signer`:`for scope "${t}"`} was written under a wrapping scheme this SDK build cannot read (${n}). The entry is preserved instead of regenerated, since an instance that understands the scheme may still be using it: ${t===void 0?`run a build that supports it, or call permits.clear() to discard the entry deliberately`:`run a build that supports it everywhere, or call permits.revokeTransportKeyPair() to rotate the scope`}.`}var $e=class{#e;#t;#n;#r;#i;#a;#o=new Map;#s=new Map;constructor(e){this.#e=e.generator,this.#t=e.storage,this.#n=e.ttl,this.#r=e.logger,this.#i=e.scope,this.#a=e.derivationSecret}#c(e){return this.#i===void 0?`signer:${e}`:Ye(this.#i)}#l(e){return this.#i===void 0?Je(e):q(this.#i)}async readStored(e){return this.#u(this.#l(e),this.#c(e))}async#u(e,t){let n=await this.#t.get(e);if(n==null)return null;let i=Ke(n);if(i.kind===`unsupported-version`)throw this.#f(e,Qe(i.version,this.#i));if(i.kind===`unrecognized`)return await this.#m(e,`malformed transport key pair entry`),null;let a=this.#a;if(a===void 0)return i.kind===`plaintext`?await this.#p(e,i.keyPair.expiresAt)?null:i.keyPair:this.#d(e,`wrapped-without-secret`);if(i.kind===`plaintext`)return this.#d(e,`unwrapped-under-secret`);if(i.kind===`corrupt-wrapped`)return this.#d(e,`corrupt-wrapped`);if(await this.#p(e,i.expiresAt))return null;try{return await i.decode(a,t)}catch(t){if(!we(t))throw this.#r.error(`transport key pair unwrap failed unexpectedly`,{key:e,error:t}),new r(`Transport key pair unwrap failed unexpectedly.`,{cause:t});return this.#d(e,`unwrap-failed`,t)}}async#d(e,t,n){if(this.#i!==void 0)throw this.#f(e,Xe(t,this.#i),n);if(t===`wrapped-without-secret`)throw this.#f(e,`Transport key pair for this signer is wrapped, but this instance has no transportKeyPairDerivationSecret configured. Configure the same transportKeyPairDerivationSecret the entry was written with. To downgrade to plaintext at rest on purpose, discard the stored entry first by calling permits.clear(), then run without the secret.`,n);let r=Ze[t];return this.#r.warn(r,{key:e}),await this.#m(e,r),null}#f(e,t,n){return this.#r.error(t,{key:e}),new r(t,{cause:n})}async#p(e,t){return B()<t?!1:(await this.#m(e,`expired transport key pair entry`),!0)}async#m(e,t){this.#r.debug(`discarding transport key pair entry`,{key:e,reason:t}),await l(`delete transport key pair entry`,()=>this.#t.delete(e),this.#r)}async getOrCreate(e,t){return this.#h(this.#l(e),this.#c(e),{strict:t?.strict})}async#h(e,t,n){let i=n?.strict??!1,a=`${e}::${i}`,o=this.#o.get(a);if(o)return o;let c=this.#s.get(e)??0,u=(async()=>{let n=await this.#u(e,t);if(n!==null)return n;let a=await this.#e(),o=B(),u=o+this.#n,d={publicKey:a.publicKey,privateKey:a.privateKey,createdAt:o,expiresAt:u};a.tkmsVersion&&(d.tkmsVersion=a.tkmsVersion);let f=d;if(this.#a!==void 0)try{f=await qe(d,this.#a,t)}catch(t){let n=`Failed to wrap the transport private key for at-rest storage.`;throw this.#r.error(n,{key:e,error:t}),new r(n,{cause:t})}if((this.#s.get(e)??0)===c)i?await this.#t.set(e,f):await l(`persist transport key pair`,()=>this.#t.set(e,f),this.#r);else if(i)throw new s(`The transport key pair was rotated while it was being generated, so the freshly generated key pair could not be persisted. Retry.`);return d})().finally(()=>{this.#o.delete(a)});return this.#o.set(a,u),u}async clear(e){let t=Je(e);await l(`delete transport key pair entry`,()=>this.#t.delete(t),this.#r)}async evict(e){let t=this.#l(e);await l(`evict transport key pair entry`,()=>this.#t.delete(t),this.#r)}async clearScope(){if(this.#i===void 0)return;let e=q(this.#i);this.#s.set(e,(this.#s.get(e)??0)+1),await this.#t.delete(e)}async warmScope(){this.#i!==void 0&&await this.#h(q(this.#i),Ye(this.#i),{strict:!0})}};function et(e){return D(Le,e)}function tt(e,t){let n=new Set(e.flatMap(e=>e.contractAddresses));return t.filter(e=>!n.has(e))}function nt(e){let t=[];for(let n=0;n<e.length;n+=10)t.push(e.slice(n,n+10));return t}function rt(e,t,n){return e.filter(e=>e.keypairPublicKey===t&&n<e.startTimestamp+e.durationDays*86400)}function it(e,t){let n=new Set(t);return e.filter(e=>!e.contractAddresses.some(e=>n.has(e)))}function X(e,t){return[...new Set([...e,...t])].sort()}function at(e,t,n){let r=new Set(n),i=e.filter(e=>new Set([...e.contractAddresses,...t]).size<=10);if(i.length===0)return null;function a(e){return e.contractAddresses.reduce((e,t)=>e+ +!!r.has(t),0)}let o=Math.max(...i.map(a));return i.filter(e=>a(e)===o).reduce((e,t)=>t.startTimestamp>e.startTimestamp?t:e)}var ot=class{#e;#t;constructor(e){this.#e=e.storage,this.#t=e.logger}async list(e){let t=J(e),n=await this.#e.get(t);if(n==null)return[];let r=Fe.safeParse(n);return r.success?r.data:(await this.clearScope(e),[])}async listUsableAndPrune(e,t){let n=await this.list(e),r=rt(n,t,Math.floor(Date.now()/1e3));return r.length!==n.length&&(r.length===0?await this.clearScope(e):await l(`update permit entry`,()=>this.#e.set(J(e),r),this.#t)),r}async append(e,t){if(t.length===0)return;let n=t.map(e=>G.parse(e)),r=await this.list(e);await this.#e.set(J(e),[...r,...n]),await this.#r(e)}async replace(e,t,n){let r=G.parse(n),i=(await this.list(e)).filter(e=>e.serializedPermit.signature!==t);await this.#e.set(J(e),[...i,r]),await this.#r(e)}async deletePermitsTouching(e,t){let n=await this.list(e);if(n.length===0)return;let r=it(n,t);r.length===0?await this.clearScope(e):await this.#e.set(J(e),r)}async clearScope(e){await this.#a(J(e)),await this.#i(e)}async clearAllForSigner(e){let t=Y(e),n=await this.#n(t);await Promise.all(n.map(e=>this.#a(e))),await l(`delete permit index`,()=>this.#e.delete(t),this.#t)}async#n(e){let t=await this.#e.get(e);if(t==null)return[];let n=Ie.safeParse(t);return n.success?n.data:(await l(`delete permit index`,()=>this.#e.delete(e),this.#t),[])}async#r(e){let t=Y(e.signerAddress),n=J(e),r=await this.#n(t);r.includes(n)||await this.#e.set(t,[...r,n])}async#i(e){let t=Y(e.signerAddress),n=J(e),r=await this.#n(t),i=r.filter(e=>e!==n);i.length!==r.length&&(i.length===0?await l(`delete permit index`,()=>this.#e.delete(t),this.#t):await l(`update permit index`,()=>this.#e.set(t,i),this.#t))}async#a(e){await l(`delete permit entry`,()=>this.#e.delete(e),this.#t)}};async function st(e,t,n){let r=e.get(t);if(r!==void 0)return r;let i=await n();return e.set(t,i),i}var ct=class{#e;#t;#n;#r;#i;#a;#o;#s;#c=new Map;constructor(e){this.#e=new $e({generator:async()=>{let t=e.router.relayer,n=await t.generateTransportKeyPair();return t.serializeTransportKeyPair({transportKeyPair:n})},storage:e.storage,ttl:e.transportKeyPairTTL,logger:e.logger,scope:e.scope,derivationSecret:e.derivationSecret}),this.#t=new ot({storage:e.permitStorage??e.storage,logger:e.logger}),this.#n=e.router,this.#r=e.signer,this.#i=e.permitTTL,this.#a=e.logger,this.#o=e.emitEvent,this.#s=e.scope}#l(e){if(!this.#r)throw new d(e);return this.#r}#u(e,t,n=``){let r=a(t,{operation:e});return n&&(r.message=n+r.message),this.#o({type:c.PermitError,operation:e,error:r}),r}async grantPermit(e,t){let n=t===void 0?`grantPermit`:`grantDelegationPermit`,r,i,a;try{r=E(this.#l(`grantPermit`).requireWalletAccount(`grantPermit`).address),i=V(e),a=this.#f(r,t)}catch(e){throw this.#u(n,e)}let o=await this.#e.getOrCreate(r);if(i.length===0)return{keypair:o,permissions:[]};let s;try{s=await this.#t.listUsableAndPrune(a,o.publicKey)}catch(e){throw this.#u(n,e)}let c=tt(s,i);if(c.length>0){let e=at(s,c,i);if(e!==null){let t=X(e.contractAddresses,c),n=await this.#p({chunk:t,keypair:o,scope:a});await l(`replace permit`,()=>this.#t.replace(a,e.serializedPermit.signature,n),this.#a),s[s.indexOf(e)]=n}else for(let e of nt(c)){let t=await this.#p({chunk:e,keypair:o,scope:a});s.push(t),await l(`persist permit`,()=>this.#t.append(a,[t]),this.#a)}}let u=new Set(i);return{keypair:o,permissions:s.filter(e=>e.contractAddresses.some(e=>u.has(e)))}}async preparePermit(e){let t=V(e.contracts).length;if(t>10)throw new n(`preparePermit: request.contracts must not exceed 10 addresses (got ${t}). Use batchPreparePermits to split them across permits.`);let[r]=await this.batchPreparePermits(e);return u(r,`batchPreparePermits result`),r}async batchPreparePermits(e){let t=E(e.signer),r=V(e.contracts);if(r.length===0)throw new n(`request.contracts must not be empty.`);let i=e.delegator?E(e.delegator):void 0;if(i!==void 0&&i===t)throw new n(`request.delegator must differ from request.signer: self-delegation is not allowed.`);let a=e.durationDays===void 0?this.#i:D(je,e.durationDays),o=this.#n.relayer,s=await this.#e.getOrCreate(t,{strict:!0}),c=await o.parseTransportKeyPair(s),l=B();return Promise.all(nt(r).map(async e=>({version:1,eip712:Te(U.parse(await o.createUnsignedLegacyDecryptionPermitEip712({transportKeyPair:c,contractAddresses:e,startTimestamp:l,durationSeconds:a*z,...i&&{delegatorAddress:i}}))),signerAddress:t})))}async batchRegisterPermits(e){if(e.length===0)throw new n(`permits must not be empty.`);let t={relayer:this.#n.relayer,activeChainId:this.#n.chain.id,storedKeyPairs:new Map,transportKeyPairs:new Map},r=[];for(let[n,{prepared:i,signature:a}]of e.entries()){let o=e.length>1?`permits[${n}]: `:``;r.push(await this.#d(i,a,t,o))}for(let{scope:e,permission:t}of r)await l(`replace permit`,()=>this.#t.replace(e,t.serializedPermit.signature,t),this.#a)}async#d(e,t,{relayer:r,activeChainId:a,storedKeyPairs:c,transportKeyPairs:l},u){let d;try{d=et(e)}catch(e){throw this.#u(`registerPermit`,e,u)}let{domain:f,message:p}=d.eip712,m=Number(f.chainId);if(m!==a)throw this.#u(`registerPermit`,new o({preparedChainId:m,activeChainId:a}),u);let h=Number(p.startTimestamp),g=Number(p.durationDays);if(B()>=h+g*86400)throw this.#u(`registerPermit`,new i(`registerPermit: the prepared permit's validity window (starting ${h}, ${g}d) has already elapsed. Prepare the permit again.`),u);let _=d.signerAddress,v=await st(c,_,()=>this.#e.readStored(_));if(v===null||v.publicKey!==p.publicKey)throw new s(`${u}registerPermit: the transport key pair changed since the permit was prepared. Prepare it again to rebind the signature request to the current key pair.`);try{let e=await st(l,_,()=>r.parseTransportKeyPair(v)),i=await r.parseSignedDecryptionPermit({serializedPermit:{version:d.version,eip712:d.eip712,signature:t,signerAddress:_},transportKeyPair:e});if(i.version!==1)throw new n(`registerPermit: expected a V1 signed permit, got version ${i.version}.`);let o=D(W,await r.serializeSignedDecryptionPermit({signedPermit:i})),s={keypairPublicKey:v.publicKey,contractAddresses:V(i.eip712.message.contractAddresses),serializedPermit:o,startTimestamp:Number(i.eip712.message.startTimestamp),durationDays:Number(i.eip712.message.durationDays)};return{scope:{signerAddress:_,chainId:a,delegatorAddress:E(i.encryptedDataOwnerAddress)},permission:s}}catch(e){throw this.#u(`registerPermit`,e,u)}}async hasPermit(e,t){if(e.length===0)return!0;let n=this.#r?.walletAccount.getSnapshot();if(!n)return!1;let i=E(n.address),a;try{a=await this.#e.readStored(i)}catch(e){if(!(e instanceof r))throw e;return!1}if(a===null)return!1;let o=this.#f(i,t);return tt(await this.#t.listUsableAndPrune(o,a.publicKey),V(e)).length===0}async revokePermits(e){let t=E(this.#l(`revokePermits`).requireWalletAccount(`revokePermits`).address);if(e===void 0){await this.#t.clearAllForSigner(t);return}let n=V(e);n.length!==0&&await this.#t.deletePermitsTouching(this.#f(t),n)}#f(e,t){return{signerAddress:e,chainId:this.#n.chain.id,delegatorAddress:t?E(t):e}}async clearCredentials(){let e=E(this.#l(`clearCredentials`).requireWalletAccount(`clearCredentials`).address);await this.#e.clear(e),await this.#t.clearAllForSigner(e)}async revokeTransportKeyPair(e){if(this.#s===void 0)throw new n(`revokeTransportKeyPair() requires a transportKeyPairScope to be configured on this SDK instance — there is no shared key pair to revoke.`);if(e!==this.#s)throw new n(`revokeTransportKeyPair("${e}") does not match the configured scope ("${this.#s}").`);await this.#e.clearScope()}async warmTransportKeyPair(e){await this.#e.getOrCreate(E(e))}async warmTransportKeyPairScope(e){if(this.#s===void 0)throw new n(`warmTransportKeyPairScope() requires a transportKeyPairScope to be configured on this SDK instance — there is no shared key pair to warm.`);if(e!==this.#s)throw new n(`warmTransportKeyPairScope("${e}") does not match the configured scope ("${this.#s}").`);await this.#e.warmScope()}async handleWalletAccountChange(e,t){let n=e?E(e.address):void 0;n!==(t?E(t.address):void 0)&&n&&(await this.#e.clear(n),await this.#t.clearAllForSigner(n))}async#p(n){let{chunk:r,keypair:i,scope:a}=n,o=B(),s=a.delegatorAddress!==a.signerAddress,c=this.#n.relayer;try{let e={transportKeyPair:await c.parseTransportKeyPair(i),contractAddresses:r,startTimestamp:o,durationSeconds:this.#i*z,signerAddress:a.signerAddress,signer:this.#l(`signPermit`)},t=s?await c.signDecryptionPermit({...e,delegatorAddress:a.delegatorAddress}):await c.signDecryptionPermit(e),n=D(W,await c.serializeSignedDecryptionPermit({signedPermit:t}));return{keypairPublicKey:i.publicKey,contractAddresses:r,serializedPermit:n,startTimestamp:o,durationDays:this.#i}}catch(n){let r=s?`grantDelegationPermit`:`grantPermit`;throw!(n instanceof t)&&n instanceof Error&&e(n.message)&&await this.#e.evict(a.signerAddress),this.#u(r,n)}}async evictTransportKeyPair(){let e=this.#r?.walletAccount.getSnapshot();e&&await this.#e.evict(E(e.address))}async recoverPermits(e,t,n){let r=this.#l(`recoverPermits`).requireWalletAccount(`recoverPermits`),i=this.#f(E(r.address),t),a=J(i),o=this.#c.get(a);if(o)return await o,this.grantPermit(e,t);let s=await this.#m(i),c=this.#c.get(a);if(c)return await c,this.grantPermit(e,t);if(s===null)return this.grantPermit(e,t);let l=new Set(n??[]);if(l.size>0&&!s.some(e=>l.has(e.serializedPermit.signature)))return this.grantPermit(e,t);let u=s.filter(e=>!l.has(e.serializedPermit.signature)),d=s.flatMap(e=>e.contractAddresses),f=this.#h(i,d,e,u,t).finally(()=>{this.#c.delete(a)});return this.#c.set(a,f),await f,this.grantPermit(e,t)}async#m(e){try{return await this.#t.list(e)}catch(e){return this.#a.warn(`read permits for recovery failed`,{error:e}),null}}async#h(e,t,n,r,i){await l(`evict revoked permits`,()=>this.#t.clearScope(e),this.#a);try{await this.grantPermit(X(t,V(n)),i)}catch(t){throw r.length>0&&await l(`restore surviving permits`,async()=>{let t=await this.#t.list(e),n=new Set(t.map(e=>e.serializedPermit.signature)),i=r.filter(e=>!n.has(e.serializedPermit.signature));i.length>0&&await this.#t.append(e,i)},this.#a),t}}},lt=class{#e;#t=`[zama-sdk]`;constructor(e){this.#e=e}error(e,t){this.#e?.error(`${this.#t} ${e}`,t)}warn(e,t){this.#e?.warn(`${this.#t} ${e}`,t)}info(e,t){this.#e?.info(`${this.#t} ${e}`,t)}debug(e,t){this.#e?.debug(`${this.#t} ${e}`,t)}warnAlways(e){console.warn(`${this.#t} ${e}`),this.warn(e)}};const ut={[ce.id]:ce.registryAddress,[le.id]:le.registryAddress,[oe.id]:oe.registryAddress,[O.id]:O.registryAddress,[ue.id]:ue.registryAddress,[se.id]:se.registryAddress},dt=M.record(M.string().check(M.regex(/^\d+$/,`expected numeric chain id key`)),S),Z=ae,Q=300*1e3;var ft=class{provider;#e;#t;#n=new Map;constructor(e){this.provider=e.provider,this.#e=Object.assign({},ut,D(M.optional(dt),e.registryAddresses)),this.#t=D(Z,e.registryTTL??86400)*1e3}getAddress(e){return this.#e[e]}#r(e){let t=this.#n.get(e);if(t){if(Date.now()>=t.expiresAt){this.#n.delete(e);return}return t.data}}#i(e,t,n=this.#t){return this.#n.set(e,{data:t,expiresAt:Date.now()+n}),t}refresh(){this.#n.clear()}get ttlMs(){return this.#t}async getRegistryAddress(){let e=await this.provider.getChainId(),t=this.#e[e];if(!t)throw new n(`No wrappers registry address configured for chain ${e}.\nPass a registryAddresses entry for this chain.`);return k(t)}async listPairs(e={}){let t=e.page??1,r=e.pageSize??100,i=e.metadata??!1;if(t<1)throw new n(`page must be >= 1, got ${t}`);if(r<1)throw new n(`pageSize must be >= 1, got ${r}`);let a=await this.getRegistryAddress(),o=`total:${a}`,s=this.#r(o);if(s===void 0){let e=await this.provider.readContract(f(a));s=this.#i(o,Number(e))}let c=BigInt((t-1)*r),l=c+BigInt(r)>BigInt(s)?BigInt(s):c+BigInt(r);if(c>=BigInt(s))return{items:[],total:s,page:t,pageSize:r};let u=`slice:${a}:${c}:${l}`,d=this.#r(u);if(d===void 0){let e=await this.provider.readContract(g(a,c,l));d=this.#i(u,[...e])}if(!i)return{items:d,total:s,page:t,pageSize:r};let p=`metadata:${a}:${c}:${l}`,m=this.#r(p);if(m===void 0){let e=await Promise.allSettled(d.map(e=>this.#a(e))),t=e.some(e=>e.status===`rejected`),n=e.map((e,t)=>e.status===`fulfilled`?e.value:Object.assign({},d[t],{metadataFailed:!0,underlying:{name:`Unknown`,symbol:`???`,decimals:0,totalSupply:0n},confidential:{name:`Unknown`,symbol:`???`,decimals:0}}));m=this.#i(p,n,t?Q:void 0)}return{items:m,total:s,page:t,pageSize:r}}async#a(e){let[t,n,r,i,a,o,s]=await Promise.all([this.provider.readContract(p(e.tokenAddress)),this.provider.readContract(x(e.tokenAddress)),this.provider.readContract(b(e.tokenAddress)),this.provider.readContract(te(e.tokenAddress)),this.provider.readContract(p(e.confidentialTokenAddress)),this.provider.readContract(x(e.confidentialTokenAddress)),this.provider.readContract(b(e.confidentialTokenAddress))]);return{...e,underlying:{name:t,symbol:n,decimals:r,totalSupply:i},confidential:{name:a,symbol:o,decimals:s}}}async getConfidentialToken(e){let t=await this.getRegistryAddress(),n=k(e),r=`ct:${t}:${n}`,i=this.#r(r);if(i!==void 0)return i;let[a,o]=await this.provider.readContract(y(t,n));return o===de?this.#i(r,null,Q):this.#i(r,{confidentialTokenAddress:o,isValid:a})}async getUnderlyingToken(e){let t=await this.getRegistryAddress(),n=k(e),r=`ut:${t}:${n}`,i=this.#r(r);if(i!==void 0)return i;let[a,o]=await this.provider.readContract(h(t,n));return o===de?this.#i(r,null,Q):this.#i(r,{tokenAddress:o,isValid:a})}async getTokenPairs(){let e=await this.getRegistryAddress();return this.provider.readContract(m(e))}async getTokenPairsLength(){let e=await this.getRegistryAddress();return this.provider.readContract(f(e))}async getTokenPairsSlice(e,t){let n=await this.getRegistryAddress();return this.provider.readContract(g(n,e,t))}async getTokenPair(e){let t=await this.getRegistryAddress();return this.provider.readContract(v(t,e))}async getConfidentialTokenAddress(e){let t=await this.getRegistryAddress();return this.provider.readContract(y(t,k(e)))}async getTokenAddress(e){let t=await this.getRegistryAddress();return this.provider.readContract(h(t,k(e)))}async isConfidentialTokenValid(e){let t=await this.getRegistryAddress();return this.provider.readContract(ee(t,k(e)))}};function pt(e,t,n){let r=new lt(n.logger),i=n.logger,a={wasmAssetLoadMode:`auto`,moduleVersions:`auto`,logger:{error:(e,t)=>i?.error(e,{cause:t}),warn:e=>i?.warn(e),debug:e=>i?.debug(e)},...n.runtime};if(fe()){let e=`runtime configuration is already set and cannot be changed.`;n.runtime===void 0?r.debug(e):r.warn(e)}else pe(a),ne(a);let{storage:o,permitStorage:s}=_e(n.storage,n.permitStorage),c=re(n.telemetry)??`header`,l=c===`off`?void 0:{layer:`core`,mode:c},u=new ye(n.chains,n.relayers,r,l);return{chains:n.chains,router:u,provider:t,signer:e,storage:o,permitStorage:s,transportKeyPairTTL:D(Ae,n.transportKeyPairTTL??2592e3),permitTTL:D(je,n.permitTTL??30),clearCredentialsOnWalletChange:n.clearCredentialsOnWalletChange??!0,transportKeyPairScope:n.transportKeyPairScope===void 0?void 0:D(Me,n.transportKeyPairScope),registryTTL:D(Z,n.registryTTL??86400),logger:r,onEvent:n.onEvent,telemetry:l}}function mt(e,t){return e?.address===t?.address&&e?.chainId===t?.chainId}var $=class{#e=new Set;#t;#n;constructor(e){this.#t=e,this.#n=e!==void 0}getSnapshot(){return this.#t}isReady(){return this.#n}setSnapshot(e){this.#n=!0;let t=this.#t;mt(t,e)||(this.#t=e,this.#r({previous:t,next:e}))}subscribe(e){this.#e.add(e);let t=this.#t;return t&&e({previous:void 0,next:t}),()=>{this.#e.delete(e)}}#r(e){for(let t of this.#e)t(e)}};function ht(e){return new $(e)}var gt=class{walletAccount;#e=!1;constructor(e){this.walletAccount=new $(e)}requireWalletAccount(e){let t=this.walletAccount.getSnapshot();if(!t)throw new _(e);return t}dispose(){this.#e||(this.#e=!0,this.onDispose())}[Symbol.dispose](){this.dispose()}onDispose(){}};export{ut as a,et as c,P as d,he as f,pt as i,Ne as l,me as m,$ as n,ft as o,N as p,ht as r,ct as s,gt as t,xe as u};
2
+ //# sourceMappingURL=base-signer-6YPpqhw9.js.map