@zama-fhe/sdk 3.2.0-alpha.3 → 3.3.0-alpha.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.
- package/dist/cjs/base-signer.cjs +1 -1
- package/dist/cjs/ethers/index.cjs +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/query/index.cjs +1 -1
- package/dist/cjs/query/index.cjs.map +1 -1
- package/dist/cjs/token.cjs +1 -1
- package/dist/cjs/token.cjs.map +1 -1
- package/dist/cjs/viem/index.cjs +1 -1
- package/dist/cjs/wrappers-registry.cjs +1 -1
- package/dist/cjs/wrappers-registry.cjs.map +1 -1
- package/dist/esm/base-signer-DaRQNB29.js +2 -0
- package/dist/esm/{base-signer-BVqcM5jt.js.map → base-signer-DaRQNB29.js.map} +1 -1
- package/dist/esm/{cleartext-DMW5nK1M.d.ts → cleartext-4WhQWHZF.d.ts} +2 -2
- package/dist/esm/ethers/index.d.ts +2 -2
- package/dist/esm/ethers/index.js +1 -1
- package/dist/esm/ethers/index.js.map +1 -1
- package/dist/esm/{index-DoVo9J1n.d.ts → index-BRIQ3Msg.d.ts} +56 -2
- package/dist/esm/index.d.ts +5 -5
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/node/index.d.ts +2 -2
- package/dist/esm/query/index.d.ts +26 -3
- package/dist/esm/query/index.js +1 -1
- package/dist/esm/query/index.js.map +1 -1
- package/dist/esm/token-BTgHqRIL.js +2 -0
- package/dist/esm/token-BTgHqRIL.js.map +1 -0
- package/dist/esm/{types-BjDu-RZg.d.ts → types-C4JRzs5M.d.ts} +13 -1
- package/dist/esm/{types-DiZhtG8i.d.ts → types-Cb7AvEOP.d.ts} +2 -2
- package/dist/esm/{types-Xg_On_yY.d.ts → types-DJp9eoXC.d.ts} +2 -2
- package/dist/esm/viem/index.d.ts +2 -2
- package/dist/esm/viem/index.js +1 -1
- package/dist/esm/web/index.d.ts +1 -1
- package/dist/esm/{wrappers-registry-BWWG0aze.js → wrappers-registry-ChxQp8ty.js} +2 -2
- package/dist/esm/wrappers-registry-ChxQp8ty.js.map +1 -0
- package/package.json +1 -1
- package/dist/esm/base-signer-BVqcM5jt.js +0 -2
- package/dist/esm/token-TQ-VFHS4.js +0 -2
- package/dist/esm/token-TQ-VFHS4.js.map +0 -1
- package/dist/esm/wrappers-registry-BWWG0aze.js.map +0 -1
package/dist/cjs/base-signer.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./relayer.cjs"),t=require("./wrappers-registry.cjs"),n=require("./assertions.cjs"),r=require("./validation.cjs"),i=require("./chains.cjs");let a=require("viem"),o=require("zod/mini");function s(e){return`keypair:${e}`}function c(e){return`permits:${e.signerAddress}:${e.chainId}:${e.delegatorAddress}`}function l(e){return`permits-index:${e}`}function u(e){return(0,a.getAddress)(e)}const d=o.z.custom(e=>typeof e==`string`&&(0,a.isHex)(e,{strict:!0}),`expected 0x-prefixed hex string`),f=o.z.custom(e=>typeof e==`string`&&(0,a.isAddress)(e,{strict:!1}),`expected EVM address`),p=o.z.pipe(f,o.z.transform(u)),m=o.z.int().check(o.z.nonnegative()),h=o.z.int().check(o.z.positive()),g=o.z.int().check(o.z.nonnegative()),_=o.z.int().check(o.z.positive()),v=o.z.int().check(o.z.positive());function y(){return Math.floor(Date.now()/1e3)}function b(e){return[...new Set(e.map(u))].toSorted()}const x=`transportKeyPairTTL must be a positive integer number of seconds`,S=`permitTTL must be a positive integer number of days`,C=365*86400,w=o.z.int({error:x}).check(o.z.positive({error:x}),o.z.maximum(C,`transportKeyPairTTL must not exceed the fhevm ACL maximum of ${C}s (365 days)`)),T=o.z.int({error:S}).check(o.z.positive({error:S})),E=o.z.object({publicKey:d,privateKey:d,createdAt:m,expiresAt:h}),D=o.z.object({keypairPublicKey:d,signerAddress:p,delegatorAddress:p,chainId:v,signedContractAddresses:o.z.array(p).check(o.z.maxLength(10)),signature:d,startTimestamp:m,durationDays:_}),O=o.z.array(D),k=o.z.array(o.z.string());var A=class{#e;#t;#n;#r;#i=new Map;constructor(e){this.#e=e.generator,this.#t=e.storage,this.#n=e.ttl,this.#r=e.logger}async readStored(e){let n=s(e),r=await this.#t.get(n);if(r==null)return null;let i=E.safeParse(r);if(!i.success)return await t.F(`delete transport key pair entry`,()=>this.#t.delete(n),this.#r),null;let a=i.data;return y()>=a.expiresAt?(await t.F(`delete transport key pair entry`,()=>this.#t.delete(n),this.#r),null):a}async getOrCreate(e){let n=this.#i.get(e);if(n)return n;let r=(async()=>{let n=await this.readStored(e);if(n!==null)return n;let r=await this.#e(),i=y(),a={publicKey:r.publicKey,privateKey:r.privateKey,createdAt:i,expiresAt:i+this.#n},o=s(e);return await t.F(`persist transport key pair`,()=>this.#t.set(o,a),this.#r),a})().finally(()=>{this.#i.delete(e)});return this.#i.set(e,r),r}async clear(e){let n=s(e);await t.F(`delete transport key pair entry`,()=>this.#t.delete(n),this.#r)}};function j(e,t){let n=new Set(e.flatMap(e=>e.signedContractAddresses));return t.filter(e=>!n.has(e))}function M(e){let t=[];for(let n=0;n<e.length;n+=10)t.push(e.slice(n,n+10));return t}function N(e,t,n){return e.filter(e=>e.keypairPublicKey===t&&n<e.startTimestamp+e.durationDays*86400)}function P(e,t){let n=new Set(t);return e.filter(e=>!e.signedContractAddresses.some(e=>n.has(e)))}function F(e,t){return[...new Set([...e,...t])].toSorted()}function I(e,t,n){let r=new Set(n),i=e.filter(e=>new Set([...e.signedContractAddresses,...t]).size<=10);if(i.length===0)return null;function a(e){return e.signedContractAddresses.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 L=class{#e;#t;constructor(e){this.#e=e.storage,this.#t=e.logger}async list(e){let t=c(e),n=await this.#e.get(t);if(n==null)return[];let r=O.safeParse(n);return r.success?r.data:(await this.#a(t),await this.#i(e),[])}async listUsableAndPrune(e,n){let r=await this.list(e),i=N(r,n,Math.floor(Date.now()/1e3));if(i.length!==r.length){let n=c(e);i.length===0?(await this.#a(n),await this.#i(e)):await t.F(`update permit entry`,()=>this.#e.set(n,i),this.#t)}return i}async append(e,t){if(t.length===0)return;let n=t.map(e=>D.parse(e)),r=await this.list(e);await this.#e.set(c(e),[...r,...n]),await this.#r(e)}async replace(e,t,n){let r=D.parse(n),i=(await this.list(e)).filter(e=>e.signature!==t);await this.#e.set(c(e),[...i,r]),await this.#r(e)}async deletePermitsTouching(e,t){let n=await this.list(e);if(n.length===0)return;let r=c(e),i=P(n,t);i.length===0?(await this.#a(r),await this.#i(e)):await this.#e.set(r,i)}async clearAllForSigner(e){let n=l(e),r=await this.#n(n);await Promise.all(r.map(e=>this.#a(e))),await t.F(`delete permit index`,()=>this.#e.delete(n),this.#t)}async#n(e){let n=await this.#e.get(e);if(n==null)return[];let r=k.safeParse(n);return r.success?r.data:(await t.F(`delete permit index`,()=>this.#e.delete(e),this.#t),[])}async#r(e){let t=l(e.signerAddress),n=c(e),r=await this.#n(t);r.includes(n)||await this.#e.set(t,[...r,n])}async#i(e){let n=l(e.signerAddress),r=c(e),i=await this.#n(n),a=i.filter(e=>e!==r);a.length!==i.length&&(a.length===0?await t.F(`delete permit index`,()=>this.#e.delete(n),this.#t):await t.F(`update permit index`,()=>this.#e.set(n,a),this.#t))}async#a(e){await t.F(`delete permit entry`,()=>this.#e.delete(e),this.#t)}},R=class{#e;#t;#n;#r;#i;#a;constructor(e){this.#e=new A({generator:()=>e.relayer.generateTransportKeyPair(),storage:e.storage,ttl:e.transportKeyPairTTL,logger:e.logger}),this.#t=new L({storage:e.permitStorage??e.storage,logger:e.logger}),this.#n=e.relayer,this.#r=e.signer,this.#i=e.permitTTL,this.#a=e.logger}async grantPermit(e,n){let r=this.#r.requireWalletAccount(`grantPermit`),i=u(r.address),a=b(e),o=await this.#e.getOrCreate(i);if(a.length===0)return{keypair:o,permits:[]};let s={signerAddress:i,chainId:r.chainId,delegatorAddress:n?u(n):i},c=await this.#t.listUsableAndPrune(s,o.publicKey),l=j(c,a);if(l.length>0){let e=I(c,l,a);if(e!==null){let n=F(e.signedContractAddresses,l),r=await this.#o({chunk:n,keypair:o,scope:s});await t.F(`replace permit`,()=>this.#t.replace(s,e.signature,r),this.#a),c[c.indexOf(e)]=r}else for(let e of M(l)){let n=await this.#o({chunk:e,keypair:o,scope:s});c.push(n),await t.F(`persist permit`,()=>this.#t.append(s,[n]),this.#a)}}let d=new Set(a);return{keypair:o,permits:c.filter(e=>e.signedContractAddresses.some(e=>d.has(e)))}}async hasPermit(e,t){if(e.length===0)return!0;let n=this.#r.walletAccount.getSnapshot();if(!n)return!1;let r=u(n.address),i=await this.#e.readStored(r);if(i===null)return!1;let a={signerAddress:r,chainId:n.chainId,delegatorAddress:t?u(t):r};return j(await this.#t.listUsableAndPrune(a,i.publicKey),b(e)).length===0}async revokePermits(e){let t=this.#r.requireWalletAccount(`revokePermits`),n=u(t.address);if(e===void 0){await this.#t.clearAllForSigner(n);return}let r=b(e);if(r.length===0)return;let i=t.chainId;await this.#t.deletePermitsTouching({signerAddress:n,chainId:i,delegatorAddress:n},r)}async clearCredentials(){let e=u(this.#r.requireWalletAccount(`clearCredentials`).address);await this.#e.clear(e),await this.#t.clearAllForSigner(e)}async warmTransportKeyPair(e){await this.#e.getOrCreate(u(e))}async handleWalletAccountChange(e,t){let n=e?u(e.address):void 0;n!==(t?u(t.address):void 0)&&n&&(await this.#e.clear(n),await this.#t.clearAllForSigner(n))}async#o(n){let{chunk:r,keypair:i,scope:a}=n,o=y(),s=a.delegatorAddress!==a.signerAddress;try{let e=s?await this.#n.createDelegatedUserDecryptEIP712(i.publicKey,r,a.delegatorAddress,o,this.#i):await this.#n.createEIP712(i.publicKey,r,o,this.#i),t=await this.#r.signTypedData(e);return{keypairPublicKey:i.publicKey,signerAddress:a.signerAddress,delegatorAddress:a.delegatorAddress,chainId:a.chainId,signedContractAddresses:r,signature:t,startTimestamp:o,durationDays:this.#i}}catch(n){throw n instanceof e.r?n:t.U(n,`Credential signing failed`)}}},z=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)}},B=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 V=new B;function H(){return typeof window<`u`?new r.n(`CredentialStore`):new B}function U(e=H(),t=e){return{storage:e,permitStorage:t}}function W(t,n){let r=new Map(t.map(e=>[e.id,e]));if(r.size!==t.length){let n=t.map(e=>e.id);throw new e.t(`Duplicate chain id(s) [${[...new Set(n.filter((e,t)=>n.indexOf(e)!==t))].join(`, `)}] in the chains array. Each chain id must appear only once. Note: hardhat and anvil are aliases (both use 31337).`)}let i=new Map(Object.entries(n)),a=new Map;for(let t of r.keys()){let n=r.get(t),o=i.get(String(t));if(!o)throw new e.t(`Chain ${t} has no relayer configured. Add a relayer entry: relayers: { [${t}]: web() }`);if(!n)throw new e.t(`Chain ${t} has a relayer configured but no entry in the chains array. Add the chain config to the chains array.`);a.set(t,{chain:n,relayer:o})}let o=new Set(Object.keys(n).map(Number)),s=new Set([...o].filter(e=>!r.has(e)));if(s.size>0)throw new e.t(`Relayer entries for chain(s) [${[...s].join(`, `)}] have no matching entry in the chains array. Remove them or add the corresponding chain config.`);return a}var G=class{#e;#t;#n;#r;constructor(t,n,r){if(t.length===0)throw new e.t(`At least one chain is required.`);this.#e=new Map(t.map(e=>[e.id,e])),this.#r=t[0].id;let i=W(t,n),a=new Map;for(let[e,t]of i){let n=t.relayer,r=a.get(n);r||(r=[],a.set(n,r)),r.push([e,t.chain])}let o=new Map,s=[];try{for(let[e,t]of a){let n=t.map(([,e])=>e),i=e.createWorker?.(n,r);i&&s.push(i);for(let[n,a]of t)o.set(n,e.createRelayer(a,i,r))}}catch(e){for(let e of s)try{e.terminate()}catch{}throw e}this.#t=o,this.#n=s}get chains(){return[...this.#e.values()]}get chain(){let e=this.#e.get(this.#r);return n.r(e,`RelayerDispatcher: chain`),e}switchChain(t){if(!this.#e.has(t))throw new e.t(`No relayer configured for chain ${t}. Add it to the chains array.`);this.#r=t}get#i(){let e=this.#t.get(this.#r);return n.r(e,`RelayerDispatcher: relayer`),e}generateTransportKeyPair(){return this.#i.generateTransportKeyPair()}createEIP712(e,t,n,r){return this.#i.createEIP712(e,t,n,r)}encrypt(e){return this.#i.encrypt(e)}userDecrypt(e){return this.#i.userDecrypt(e)}publicDecrypt(e){return this.#i.publicDecrypt(e)}createDelegatedUserDecryptEIP712(e,t,n,r,i){return this.#i.createDelegatedUserDecryptEIP712(e,t,n,r,i)}delegatedUserDecrypt(e){return this.#i.delegatedUserDecrypt(e)}requestZKProofVerification(e){return this.#i.requestZKProofVerification(e)}fetchFheEncryptionKeyBytes(){return this.#i.fetchFheEncryptionKeyBytes()}getPublicParams(e){return this.#i.getPublicParams(e)}getAclAddress(){return this.#i.getAclAddress()}terminate(){let e=[];for(let t of new Set(this.#t.values()))try{t.terminate()}catch(t){e.push(n.c(t))}for(let t of new Set(this.#n))try{t.terminate()}catch(t){e.push(n.c(t))}if(e.length>0)throw AggregateError(e,`Failed to terminate relayer resources`)}[Symbol.dispose](){this.terminate()}};const K={[i.s.id]:i.s.registryAddress,[i.c.id]:i.c.registryAddress,[i.a.id]:i.a.registryAddress,[i.o.id]:i.o.registryAddress,[i.n.id]:i.n.registryAddress},q=o.z.record(o.z.string().check(o.z.regex(/^\d+$/,`expected numeric chain id key`)),p),J=g,Y=300*1e3;var X=class{provider;#e;#t;#n=new Map;constructor(e){this.provider=e.provider,this.#e=Object.assign({},K,r.t(o.z.optional(q),e.registryAddresses)),this.#t=r.t(J,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 t=await this.provider.getChainId(),n=this.#e[t];if(!n)throw new e.t(`No wrappers registry address configured for chain ${t}.\nPass a registryAddresses entry for this chain.`);return(0,a.getAddress)(n)}async listPairs(n={}){let r=n.page??1,i=n.pageSize??100,a=n.metadata??!1;if(r<1)throw new e.t(`page must be >= 1, got ${r}`);if(i<1)throw new e.t(`pageSize must be >= 1, got ${i}`);let o=await this.getRegistryAddress(),s=`total:${o}`,c=this.#r(s);if(c===void 0){let e=await this.provider.readContract(t.a(o));c=this.#i(s,Number(e))}let l=BigInt((r-1)*i),u=l+BigInt(i)>BigInt(c)?BigInt(c):l+BigInt(i);if(l>=BigInt(c))return{items:[],total:c,page:r,pageSize:i};let d=`slice:${o}:${l}:${u}`,f=this.#r(d);if(f===void 0){let e=await this.provider.readContract(t.o(o,l,u));f=this.#i(d,[...e])}if(!a)return{items:f,total:c,page:r,pageSize:i};let p=`metadata:${o}:${l}:${u}`,m=this.#r(p);if(m===void 0){let e=await Promise.allSettled(f.map(e=>this.#a(e))),t=e.some(e=>e.status===`rejected`),n=e.map((e,t)=>e.status===`fulfilled`?e.value:Object.assign({},f[t],{metadataFailed:!0,underlying:{name:`Unknown`,symbol:`???`,decimals:0,totalSupply:0n},confidential:{name:`Unknown`,symbol:`???`,decimals:0}}));m=this.#i(p,n,t?Y:void 0)}return{items:m,total:c,page:r,pageSize:i}}async#a(e){let[n,r,i,a,o,s,c]=await Promise.all([this.provider.readContract(t.b(e.tokenAddress)),this.provider.readContract(t.x(e.tokenAddress)),this.provider.readContract(t.v(e.tokenAddress)),this.provider.readContract(t.y(e.tokenAddress)),this.provider.readContract(t.b(e.confidentialTokenAddress)),this.provider.readContract(t.x(e.confidentialTokenAddress)),this.provider.readContract(t.v(e.confidentialTokenAddress))]);return{...e,underlying:{name:n,symbol:r,decimals:i,totalSupply:a},confidential:{name:o,symbol:s,decimals:c}}}async getConfidentialToken(e){let n=await this.getRegistryAddress(),r=(0,a.getAddress)(e),i=`ct:${n}:${r}`,o=this.#r(i);if(o!==void 0)return o;let[s,c]=await this.provider.readContract(t.t(n,r));return c===a.zeroAddress?this.#i(i,null,Y):this.#i(i,{confidentialTokenAddress:c,isValid:s})}async getUnderlyingToken(e){let n=await this.getRegistryAddress(),r=(0,a.getAddress)(e),i=`ut:${n}:${r}`,o=this.#r(i);if(o!==void 0)return o;let[s,c]=await this.provider.readContract(t.n(n,r));return c===a.zeroAddress?this.#i(i,null,Y):this.#i(i,{tokenAddress:c,isValid:s})}async getTokenPairs(){let e=await this.getRegistryAddress();return this.provider.readContract(t.i(e))}async getTokenPairsLength(){let e=await this.getRegistryAddress();return this.provider.readContract(t.a(e))}async getTokenPairsSlice(e,n){let r=await this.getRegistryAddress();return this.provider.readContract(t.o(r,e,n))}async getTokenPair(e){let n=await this.getRegistryAddress();return this.provider.readContract(t.r(n,e))}async getConfidentialTokenAddress(e){let n=await this.getRegistryAddress();return this.provider.readContract(t.t(n,(0,a.getAddress)(e)))}async getTokenAddress(e){let n=await this.getRegistryAddress();return this.provider.readContract(t.n(n,(0,a.getAddress)(e)))}async isConfidentialTokenValid(e){let n=await this.getRegistryAddress();return this.provider.readContract(t.s(n,(0,a.getAddress)(e)))}};function Z(e,t,n){let{storage:i,permitStorage:a}=U(n.storage,n.permitStorage),o=new z(n.logger),s=new G(n.chains,n.relayers,o);return{chains:n.chains,relayer:s,provider:t,signer:e,storage:i,permitStorage:a,transportKeyPairTTL:r.t(w,n.transportKeyPairTTL??2592e3),permitTTL:r.t(T,n.permitTTL??30),registryTTL:r.t(J,n.registryTTL??86400),logger:o,onEvent:n.onEvent}}function Q(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;Q(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 ee(e){return new $(e)}var te=class{walletAccount;#e=!1;constructor(e){this.walletAccount=new $(e)}requireWalletAccount(e){let n=this.walletAccount.getSnapshot();if(!n)throw new t.z(e);return n}dispose(){this.#e||(this.#e=!0,this.onDispose())}[Symbol.dispose](){this.dispose()}onDispose(){}};Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return $}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return X}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return te}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return V}});
|
|
1
|
+
const e=require("./relayer.cjs"),t=require("./wrappers-registry.cjs"),n=require("./assertions.cjs"),r=require("./validation.cjs"),i=require("./chains.cjs");let a=require("viem"),o=require("zod/mini");function s(e){return`keypair:${e}`}function c(e){return`permits:${e.signerAddress}:${e.chainId}:${e.delegatorAddress}`}function l(e){return`permits-index:${e}`}function u(e){return(0,a.getAddress)(e)}const d=o.z.custom(e=>typeof e==`string`&&(0,a.isHex)(e,{strict:!0}),`expected 0x-prefixed hex string`),f=o.z.custom(e=>typeof e==`string`&&(0,a.isAddress)(e,{strict:!1}),`expected EVM address`),p=o.z.pipe(f,o.z.transform(u)),m=o.z.int().check(o.z.nonnegative()),h=o.z.int().check(o.z.positive()),g=o.z.int().check(o.z.nonnegative()),_=o.z.int().check(o.z.positive()),v=o.z.int().check(o.z.positive());function y(){return Math.floor(Date.now()/1e3)}function b(e){return[...new Set(e.map(u))].toSorted()}const x=`transportKeyPairTTL must be a positive integer number of seconds`,S=`permitTTL must be a positive integer number of days`,C=365*86400,w=o.z.int({error:x}).check(o.z.positive({error:x}),o.z.maximum(C,`transportKeyPairTTL must not exceed the fhevm ACL maximum of ${C}s (365 days)`)),T=o.z.int({error:S}).check(o.z.positive({error:S})),E=o.z.object({publicKey:d,privateKey:d,createdAt:m,expiresAt:h}),D=o.z.object({keypairPublicKey:d,signerAddress:p,delegatorAddress:p,chainId:v,signedContractAddresses:o.z.array(p).check(o.z.maxLength(10)),signature:d,startTimestamp:m,durationDays:_}),O=o.z.array(D),k=o.z.array(o.z.string());var A=class{#e;#t;#n;#r;#i=new Map;constructor(e){this.#e=e.generator,this.#t=e.storage,this.#n=e.ttl,this.#r=e.logger}async readStored(e){let n=s(e),r=await this.#t.get(n);if(r==null)return null;let i=E.safeParse(r);if(!i.success)return await t.L(`delete transport key pair entry`,()=>this.#t.delete(n),this.#r),null;let a=i.data;return y()>=a.expiresAt?(await t.L(`delete transport key pair entry`,()=>this.#t.delete(n),this.#r),null):a}async getOrCreate(e){let n=this.#i.get(e);if(n)return n;let r=(async()=>{let n=await this.readStored(e);if(n!==null)return n;let r=await this.#e(),i=y(),a={publicKey:r.publicKey,privateKey:r.privateKey,createdAt:i,expiresAt:i+this.#n},o=s(e);return await t.L(`persist transport key pair`,()=>this.#t.set(o,a),this.#r),a})().finally(()=>{this.#i.delete(e)});return this.#i.set(e,r),r}async clear(e){let n=s(e);await t.L(`delete transport key pair entry`,()=>this.#t.delete(n),this.#r)}};function j(e,t){let n=new Set(e.flatMap(e=>e.signedContractAddresses));return t.filter(e=>!n.has(e))}function M(e){let t=[];for(let n=0;n<e.length;n+=10)t.push(e.slice(n,n+10));return t}function N(e,t,n){return e.filter(e=>e.keypairPublicKey===t&&n<e.startTimestamp+e.durationDays*86400)}function P(e,t){let n=new Set(t);return e.filter(e=>!e.signedContractAddresses.some(e=>n.has(e)))}function F(e,t){return[...new Set([...e,...t])].toSorted()}function I(e,t,n){let r=new Set(n),i=e.filter(e=>new Set([...e.signedContractAddresses,...t]).size<=10);if(i.length===0)return null;function a(e){return e.signedContractAddresses.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 L=class{#e;#t;constructor(e){this.#e=e.storage,this.#t=e.logger}async list(e){let t=c(e),n=await this.#e.get(t);if(n==null)return[];let r=O.safeParse(n);return r.success?r.data:(await this.#a(t),await this.#i(e),[])}async listUsableAndPrune(e,n){let r=await this.list(e),i=N(r,n,Math.floor(Date.now()/1e3));if(i.length!==r.length){let n=c(e);i.length===0?(await this.#a(n),await this.#i(e)):await t.L(`update permit entry`,()=>this.#e.set(n,i),this.#t)}return i}async append(e,t){if(t.length===0)return;let n=t.map(e=>D.parse(e)),r=await this.list(e);await this.#e.set(c(e),[...r,...n]),await this.#r(e)}async replace(e,t,n){let r=D.parse(n),i=(await this.list(e)).filter(e=>e.signature!==t);await this.#e.set(c(e),[...i,r]),await this.#r(e)}async deletePermitsTouching(e,t){let n=await this.list(e);if(n.length===0)return;let r=c(e),i=P(n,t);i.length===0?(await this.#a(r),await this.#i(e)):await this.#e.set(r,i)}async clearAllForSigner(e){let n=l(e),r=await this.#n(n);await Promise.all(r.map(e=>this.#a(e))),await t.L(`delete permit index`,()=>this.#e.delete(n),this.#t)}async#n(e){let n=await this.#e.get(e);if(n==null)return[];let r=k.safeParse(n);return r.success?r.data:(await t.L(`delete permit index`,()=>this.#e.delete(e),this.#t),[])}async#r(e){let t=l(e.signerAddress),n=c(e),r=await this.#n(t);r.includes(n)||await this.#e.set(t,[...r,n])}async#i(e){let n=l(e.signerAddress),r=c(e),i=await this.#n(n),a=i.filter(e=>e!==r);a.length!==i.length&&(a.length===0?await t.L(`delete permit index`,()=>this.#e.delete(n),this.#t):await t.L(`update permit index`,()=>this.#e.set(n,a),this.#t))}async#a(e){await t.L(`delete permit entry`,()=>this.#e.delete(e),this.#t)}},R=class{#e;#t;#n;#r;#i;#a;constructor(e){this.#e=new A({generator:()=>e.relayer.generateTransportKeyPair(),storage:e.storage,ttl:e.transportKeyPairTTL,logger:e.logger}),this.#t=new L({storage:e.permitStorage??e.storage,logger:e.logger}),this.#n=e.relayer,this.#r=e.signer,this.#i=e.permitTTL,this.#a=e.logger}async grantPermit(e,n){let r=this.#r.requireWalletAccount(`grantPermit`),i=u(r.address),a=b(e),o=await this.#e.getOrCreate(i);if(a.length===0)return{keypair:o,permits:[]};let s={signerAddress:i,chainId:r.chainId,delegatorAddress:n?u(n):i},c=await this.#t.listUsableAndPrune(s,o.publicKey),l=j(c,a);if(l.length>0){let e=I(c,l,a);if(e!==null){let n=F(e.signedContractAddresses,l),r=await this.#o({chunk:n,keypair:o,scope:s});await t.L(`replace permit`,()=>this.#t.replace(s,e.signature,r),this.#a),c[c.indexOf(e)]=r}else for(let e of M(l)){let n=await this.#o({chunk:e,keypair:o,scope:s});c.push(n),await t.L(`persist permit`,()=>this.#t.append(s,[n]),this.#a)}}let d=new Set(a);return{keypair:o,permits:c.filter(e=>e.signedContractAddresses.some(e=>d.has(e)))}}async hasPermit(e,t){if(e.length===0)return!0;let n=this.#r.walletAccount.getSnapshot();if(!n)return!1;let r=u(n.address),i=await this.#e.readStored(r);if(i===null)return!1;let a={signerAddress:r,chainId:n.chainId,delegatorAddress:t?u(t):r};return j(await this.#t.listUsableAndPrune(a,i.publicKey),b(e)).length===0}async revokePermits(e){let t=this.#r.requireWalletAccount(`revokePermits`),n=u(t.address);if(e===void 0){await this.#t.clearAllForSigner(n);return}let r=b(e);if(r.length===0)return;let i=t.chainId;await this.#t.deletePermitsTouching({signerAddress:n,chainId:i,delegatorAddress:n},r)}async clearCredentials(){let e=u(this.#r.requireWalletAccount(`clearCredentials`).address);await this.#e.clear(e),await this.#t.clearAllForSigner(e)}async warmTransportKeyPair(e){await this.#e.getOrCreate(u(e))}async handleWalletAccountChange(e,t){let n=e?u(e.address):void 0;n!==(t?u(t.address):void 0)&&n&&(await this.#e.clear(n),await this.#t.clearAllForSigner(n))}async#o(n){let{chunk:r,keypair:i,scope:a}=n,o=y(),s=a.delegatorAddress!==a.signerAddress;try{let e=s?await this.#n.createDelegatedUserDecryptEIP712(i.publicKey,r,a.delegatorAddress,o,this.#i):await this.#n.createEIP712(i.publicKey,r,o,this.#i),t=await this.#r.signTypedData(e);return{keypairPublicKey:i.publicKey,signerAddress:a.signerAddress,delegatorAddress:a.delegatorAddress,chainId:a.chainId,signedContractAddresses:r,signature:t,startTimestamp:o,durationDays:this.#i}}catch(n){throw n instanceof e.r?n:t.G(n,`Credential signing failed`)}}},z=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)}},B=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 V=new B;function H(){return typeof window<`u`?new r.n(`CredentialStore`):new B}function U(e=H(),t=e){return{storage:e,permitStorage:t}}function W(t,n){let r=new Map(t.map(e=>[e.id,e]));if(r.size!==t.length){let n=t.map(e=>e.id);throw new e.t(`Duplicate chain id(s) [${[...new Set(n.filter((e,t)=>n.indexOf(e)!==t))].join(`, `)}] in the chains array. Each chain id must appear only once. Note: hardhat and anvil are aliases (both use 31337).`)}let i=new Map(Object.entries(n)),a=new Map;for(let t of r.keys()){let n=r.get(t),o=i.get(String(t));if(!o)throw new e.t(`Chain ${t} has no relayer configured. Add a relayer entry: relayers: { [${t}]: web() }`);if(!n)throw new e.t(`Chain ${t} has a relayer configured but no entry in the chains array. Add the chain config to the chains array.`);a.set(t,{chain:n,relayer:o})}let o=new Set(Object.keys(n).map(Number)),s=new Set([...o].filter(e=>!r.has(e)));if(s.size>0)throw new e.t(`Relayer entries for chain(s) [${[...s].join(`, `)}] have no matching entry in the chains array. Remove them or add the corresponding chain config.`);return a}var G=class{#e;#t;#n;#r;constructor(t,n,r){if(t.length===0)throw new e.t(`At least one chain is required.`);this.#e=new Map(t.map(e=>[e.id,e])),this.#r=t[0].id;let i=W(t,n),a=new Map;for(let[e,t]of i){let n=t.relayer,r=a.get(n);r||(r=[],a.set(n,r)),r.push([e,t.chain])}let o=new Map,s=[];try{for(let[e,t]of a){let n=t.map(([,e])=>e),i=e.createWorker?.(n,r);i&&s.push(i);for(let[n,a]of t)o.set(n,e.createRelayer(a,i,r))}}catch(e){for(let e of s)try{e.terminate()}catch{}throw e}this.#t=o,this.#n=s}get chains(){return[...this.#e.values()]}get chain(){let e=this.#e.get(this.#r);return n.r(e,`RelayerDispatcher: chain`),e}switchChain(t){if(!this.#e.has(t))throw new e.t(`No relayer configured for chain ${t}. Add it to the chains array.`);this.#r=t}get#i(){let e=this.#t.get(this.#r);return n.r(e,`RelayerDispatcher: relayer`),e}generateTransportKeyPair(){return this.#i.generateTransportKeyPair()}createEIP712(e,t,n,r){return this.#i.createEIP712(e,t,n,r)}encrypt(e){return this.#i.encrypt(e)}userDecrypt(e){return this.#i.userDecrypt(e)}publicDecrypt(e){return this.#i.publicDecrypt(e)}createDelegatedUserDecryptEIP712(e,t,n,r,i){return this.#i.createDelegatedUserDecryptEIP712(e,t,n,r,i)}delegatedUserDecrypt(e){return this.#i.delegatedUserDecrypt(e)}requestZKProofVerification(e){return this.#i.requestZKProofVerification(e)}fetchFheEncryptionKeyBytes(){return this.#i.fetchFheEncryptionKeyBytes()}getPublicParams(e){return this.#i.getPublicParams(e)}getAclAddress(){return this.#i.getAclAddress()}terminate(){let e=[];for(let t of new Set(this.#t.values()))try{t.terminate()}catch(t){e.push(n.c(t))}for(let t of new Set(this.#n))try{t.terminate()}catch(t){e.push(n.c(t))}if(e.length>0)throw AggregateError(e,`Failed to terminate relayer resources`)}[Symbol.dispose](){this.terminate()}};const K={[i.s.id]:i.s.registryAddress,[i.c.id]:i.c.registryAddress,[i.a.id]:i.a.registryAddress,[i.o.id]:i.o.registryAddress,[i.n.id]:i.n.registryAddress},q=o.z.record(o.z.string().check(o.z.regex(/^\d+$/,`expected numeric chain id key`)),p),J=g,Y=300*1e3;var X=class{provider;#e;#t;#n=new Map;constructor(e){this.provider=e.provider,this.#e=Object.assign({},K,r.t(o.z.optional(q),e.registryAddresses)),this.#t=r.t(J,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 t=await this.provider.getChainId(),n=this.#e[t];if(!n)throw new e.t(`No wrappers registry address configured for chain ${t}.\nPass a registryAddresses entry for this chain.`);return(0,a.getAddress)(n)}async listPairs(n={}){let r=n.page??1,i=n.pageSize??100,a=n.metadata??!1;if(r<1)throw new e.t(`page must be >= 1, got ${r}`);if(i<1)throw new e.t(`pageSize must be >= 1, got ${i}`);let o=await this.getRegistryAddress(),s=`total:${o}`,c=this.#r(s);if(c===void 0){let e=await this.provider.readContract(t.a(o));c=this.#i(s,Number(e))}let l=BigInt((r-1)*i),u=l+BigInt(i)>BigInt(c)?BigInt(c):l+BigInt(i);if(l>=BigInt(c))return{items:[],total:c,page:r,pageSize:i};let d=`slice:${o}:${l}:${u}`,f=this.#r(d);if(f===void 0){let e=await this.provider.readContract(t.o(o,l,u));f=this.#i(d,[...e])}if(!a)return{items:f,total:c,page:r,pageSize:i};let p=`metadata:${o}:${l}:${u}`,m=this.#r(p);if(m===void 0){let e=await Promise.allSettled(f.map(e=>this.#a(e))),t=e.some(e=>e.status===`rejected`),n=e.map((e,t)=>e.status===`fulfilled`?e.value:Object.assign({},f[t],{metadataFailed:!0,underlying:{name:`Unknown`,symbol:`???`,decimals:0,totalSupply:0n},confidential:{name:`Unknown`,symbol:`???`,decimals:0}}));m=this.#i(p,n,t?Y:void 0)}return{items:m,total:c,page:r,pageSize:i}}async#a(e){let[n,r,i,a,o,s,c]=await Promise.all([this.provider.readContract(t.b(e.tokenAddress)),this.provider.readContract(t.x(e.tokenAddress)),this.provider.readContract(t.v(e.tokenAddress)),this.provider.readContract(t.y(e.tokenAddress)),this.provider.readContract(t.b(e.confidentialTokenAddress)),this.provider.readContract(t.x(e.confidentialTokenAddress)),this.provider.readContract(t.v(e.confidentialTokenAddress))]);return{...e,underlying:{name:n,symbol:r,decimals:i,totalSupply:a},confidential:{name:o,symbol:s,decimals:c}}}async getConfidentialToken(e){let n=await this.getRegistryAddress(),r=(0,a.getAddress)(e),i=`ct:${n}:${r}`,o=this.#r(i);if(o!==void 0)return o;let[s,c]=await this.provider.readContract(t.t(n,r));return c===a.zeroAddress?this.#i(i,null,Y):this.#i(i,{confidentialTokenAddress:c,isValid:s})}async getUnderlyingToken(e){let n=await this.getRegistryAddress(),r=(0,a.getAddress)(e),i=`ut:${n}:${r}`,o=this.#r(i);if(o!==void 0)return o;let[s,c]=await this.provider.readContract(t.n(n,r));return c===a.zeroAddress?this.#i(i,null,Y):this.#i(i,{tokenAddress:c,isValid:s})}async getTokenPairs(){let e=await this.getRegistryAddress();return this.provider.readContract(t.i(e))}async getTokenPairsLength(){let e=await this.getRegistryAddress();return this.provider.readContract(t.a(e))}async getTokenPairsSlice(e,n){let r=await this.getRegistryAddress();return this.provider.readContract(t.o(r,e,n))}async getTokenPair(e){let n=await this.getRegistryAddress();return this.provider.readContract(t.r(n,e))}async getConfidentialTokenAddress(e){let n=await this.getRegistryAddress();return this.provider.readContract(t.t(n,(0,a.getAddress)(e)))}async getTokenAddress(e){let n=await this.getRegistryAddress();return this.provider.readContract(t.n(n,(0,a.getAddress)(e)))}async isConfidentialTokenValid(e){let n=await this.getRegistryAddress();return this.provider.readContract(t.s(n,(0,a.getAddress)(e)))}};function Z(e,t,n){let{storage:i,permitStorage:a}=U(n.storage,n.permitStorage),o=new z(n.logger),s=new G(n.chains,n.relayers,o);return{chains:n.chains,relayer:s,provider:t,signer:e,storage:i,permitStorage:a,transportKeyPairTTL:r.t(w,n.transportKeyPairTTL??2592e3),permitTTL:r.t(T,n.permitTTL??30),registryTTL:r.t(J,n.registryTTL??86400),logger:o,onEvent:n.onEvent}}function Q(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;Q(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 ee(e){return new $(e)}var te=class{walletAccount;#e=!1;constructor(e){this.walletAccount=new $(e)}requireWalletAccount(e){let n=this.walletAccount.getSnapshot();if(!n)throw new t.V(e);return n}dispose(){this.#e||(this.#e=!0,this.onDispose())}[Symbol.dispose](){this.dispose()}onDispose(){}};Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return K}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return U}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return Z}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return $}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return X}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return p}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return W}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return te}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return V}});
|
|
2
2
|
//# sourceMappingURL=base-signer.cjs.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../wrappers-registry.cjs"),t=require("../base-signer.cjs"),n=require("../eip1193-subscribe.cjs");let r=require("viem"),i=require("ethers");var a=class{#e;constructor(e){`ethereum`in e?this.#e=new i.BrowserProvider(e.ethereum):this.#e=e.provider}async getChainId(){let e=await this.#e.getNetwork();return Number(e.chainId)}async readContract(e){return new i.ethers.Contract(e.address,e.abi,this.#e).getFunction(e.functionName)(...e.args)}async getBlockTimestamp(){let e=await this.#e.getBlock(`latest`);if(!e)throw Error(`Failed to fetch latest block`);if(e.timestamp===null)throw Error(`Latest block has no timestamp`);return BigInt(e.timestamp)}async waitForTransactionReceipt(e){let t=await this.#e.waitForTransaction(e);if(!t)throw Error(`Transaction receipt not found`);return{logs:t.logs.map(e=>({topics:e.topics.filter(e=>e!==null),data:e.data}))}}},o=class extends t.t{#e;#t;#n;#r;#i;constructor(t){super(),`ethereum`in t?(this.#e=new i.BrowserProvider(t.ethereum),this.#n=t.ethereum,this.#r=n.t({provider:t.ethereum,getInitialWalletAccount:()=>this.#l(),onWalletAccountChange:({next:e})=>{this.walletAccount.setSnapshot(e)}})):(this.#t=t.signer,this.#r=()=>{},e.
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../wrappers-registry.cjs"),t=require("../base-signer.cjs"),n=require("../eip1193-subscribe.cjs");let r=require("viem"),i=require("ethers");var a=class{#e;constructor(e){`ethereum`in e?this.#e=new i.BrowserProvider(e.ethereum):this.#e=e.provider}async getChainId(){let e=await this.#e.getNetwork();return Number(e.chainId)}async readContract(e){return new i.ethers.Contract(e.address,e.abi,this.#e).getFunction(e.functionName)(...e.args)}async getBlockTimestamp(){let e=await this.#e.getBlock(`latest`);if(!e)throw Error(`Failed to fetch latest block`);if(e.timestamp===null)throw Error(`Latest block has no timestamp`);return BigInt(e.timestamp)}async waitForTransactionReceipt(e){let t=await this.#e.waitForTransaction(e);if(!t)throw Error(`Transaction receipt not found`);return{logs:t.logs.map(e=>({topics:e.topics.filter(e=>e!==null),data:e.data}))}}},o=class extends t.t{#e;#t;#n;#r;#i;constructor(t){super(),`ethereum`in t?(this.#e=new i.BrowserProvider(t.ethereum),this.#n=t.ethereum,this.#r=n.t({provider:t.ethereum,getInitialWalletAccount:()=>this.#l(),onWalletAccountChange:({next:e})=>{this.walletAccount.setSnapshot(e)}})):(this.#t=t.signer,this.#r=()=>{},e.L(`refresh wallet account`,async()=>{await this.refreshWalletAccount()}))}requireWalletAccount(t){let n=this.walletAccount.getSnapshot();if(!n&&!this.walletAccount.isReady())throw new e.B(t);if(!n)throw new e.V(t);return n}refreshWalletAccount(){return this.#n?this.#c():this.#t?this.#s(this.#t):Promise.resolve(void 0)}onDispose(){this.#r()}async#a(){if(this.#t)return this.#t;if(!this.#e)throw new e.R(`resolveSigner`);return this.#e.getSigner()}async#o(e){let t=e.provider;if(!t)return;let[n,i]=await Promise.all([e.getAddress(),t.getNetwork()]);return{address:(0,r.getAddress)(n),chainId:Number(i.chainId)}}async signTypedData(e){let t=await this.#a(),{domain:n,types:i,message:a}=e,{EIP712Domain:o,...s}=i,c=Object.fromEntries(Object.entries(s).map(([e,t])=>[e,[...t]])),l=await t.signTypedData(n,c,a);if(!(0,r.isHex)(l))throw TypeError(`Expected hex string, got: ${l}`);return l}async writeContract(e){let t=await this.#a(),n=new i.Contract(e.address,e.abi,t),a={};e.value!==void 0&&(a.value=e.value),e.gas!==void 0&&(a.gasLimit=e.gas);let o=await n.getFunction(e.functionName)(...e.args,a);if(!(0,r.isHex)(o.hash))throw TypeError(`Expected hex string, got: ${o.hash}`);return o.hash}async#s(e){return this.#i??=this.#o(e).then(e=>(this.walletAccount.setSnapshot(e),e)).finally(()=>{this.#i=void 0}),this.#i}async#c(){let e=await this.#l();return this.walletAccount.setSnapshot(e),e}async#l(){let e=this.#n;if(!e)return;let[t,n]=await Promise.all([e.request({method:`eth_accounts`}),e.request({method:`eth_chainId`})]);if(!Array.isArray(t)||typeof t[0]!=`string`)return;let i=Number(n);if(!(!Number.isSafeInteger(i)||i<=0))return{address:(0,r.getAddress)(t[0]),chainId:i}}};function s(e){if(`signer`in e&&e.signer){let n=new o({signer:e.signer});if(!e.signer.provider)throw Error(`createConfig requires a Signer with an attached provider for chain reads`);return t.i(n,new a({provider:e.signer.provider}),e)}return t.i(new o({ethereum:e.ethereum}),`provider`in e&&e.provider?new a({provider:e.provider}):new a({ethereum:e.ethereum}),e)}function c(e){return{to:e.address,data:(0,r.encodeFunctionData)({abi:e.abi,functionName:e.functionName,args:e.args}),...e.gas===void 0?{}:{gasLimit:e.gas},...e.value===void 0?{}:{value:e.value}}}async function l(e,t){let n=await e.call(c(t));if(!(0,r.isHex)(n))throw TypeError(`Expected hex string, got: ${n}`);return(0,r.decodeFunctionResult)({abi:t.abi,functionName:t.functionName,data:n})}async function u(e,t){let n=await e.sendTransaction(c(t));if(!(0,r.isHex)(n.hash))throw TypeError(`Expected hex string, got: ${n.hash}`);return n.hash}function d(t,n,r){return l(t,e.S(n,r))}function f(t,n){return l(t,e.N(n))}function p(t,n,r){return l(t,e.m(n,r))}function m(t,n,r,i,a){return u(t,e.T(n,r,i,a))}function h(t,n,r,i,a,o){return u(t,e.P(n,r,i,a,o))}function g(t,n,r,i,a){return u(t,e.F(n,r,i,a))}function _(t,n,r,i,a){return u(t,e.O(n,r,i,a))}function v(t,n,r,i){return u(t,e.M(n,r,i))}function y(t,n,r,i){return u(t,e.I(n,r,i))}function b(t,n){return l(t,e.i(n))}function x(t,n){return l(t,e.a(n))}function S(t,n,r,i){return l(t,e.o(n,r,i))}function C(t,n,r){return l(t,e.r(n,r))}function w(t,n,r){return l(t,e.t(n,r))}function T(t,n,r){return l(t,e.n(n,r))}function E(t,n,r){return l(t,e.s(n,r))}exports.EthersProvider=a,exports.EthersSigner=o,Object.defineProperty(exports,"ProviderRpcError",{enumerable:!0,get:function(){return r.ProviderRpcError}}),exports.createConfig=s,exports.readConfidentialBalanceOfContract=d,exports.readConfidentialTokenAddressContract=w,exports.readIsConfidentialTokenValidContract=E,exports.readSupportsInterfaceContract=p,exports.readTokenAddressContract=T,exports.readTokenPairContract=C,exports.readTokenPairsContract=b,exports.readTokenPairsLengthContract=x,exports.readTokenPairsSliceContract=S,exports.readUnderlyingTokenContract=f,exports.writeConfidentialTransferContract=m,exports.writeFinalizeUnwrapContract=_,exports.writeSetOperatorContract=v,exports.writeUnwrapContract=h,exports.writeUnwrapFromBalanceContract=g,exports.writeWrapContract=y;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./relayer.cjs"),t=require("./wrappers-registry.cjs"),n=require("./encryption.cjs"),r=require("./token.cjs"),i=require("./assertions.cjs"),a=require("./relayer-cleartext.cjs"),o=require("./base-signer.cjs"),s=require("./validation.cjs"),c=require("./chains.cjs");let l=require("viem"),u=require("zod/mini");var d=class extends e.r{constructor(t,n){super(e.i.TransportKeyPairExpired,t,n),this.name=`TransportKeyPairExpiredError`}},f=class extends e.r{constructor(t,n){super(e.i.InvalidTransportKeyPair,t,n),this.name=`InvalidTransportKeyPairError`}},p=class extends e.r{constructor(t,n){super(e.i.NoCiphertext,t,n),this.name=`NoCiphertextError`}},m=class extends e.r{constructor(t,n){super(e.i.DelegationSelfNotAllowed,t,n),this.name=`DelegationSelfNotAllowedError`}},h=class extends e.r{constructor(t,n){super(e.i.DelegationCooldown,t,n),this.name=`DelegationCooldownError`}},g=class extends e.r{constructor(t,n){super(e.i.DelegationNotFound,t,n),this.name=`DelegationNotFoundError`}},_=class extends e.r{constructor(t,n){super(e.i.DelegationExpired,t,n),this.name=`DelegationExpiredError`}},v=class extends e.r{constructor(t,n){super(e.i.DelegationExpiryUnchanged,t,n),this.name=`DelegationExpiryUnchangedError`}},y=class extends e.r{constructor(t,n){super(e.i.DelegationDelegateEqualsContract,t,n),this.name=`DelegationDelegateEqualsContractError`}},b=class extends e.r{constructor(t,n){super(e.i.DelegationContractIsSelf,t,n),this.name=`DelegationContractIsSelfError`}},x=class extends e.r{constructor(t,n){super(e.i.AclPaused,t,n),this.name=`AclPausedError`}},S=class extends e.r{constructor(t,n){super(e.i.DelegationExpirationTooSoon,t,n),this.name=`DelegationExpirationTooSoonError`}},C=class extends e.r{constructor(t,n){super(e.i.DelegationNotPropagated,t,n),this.name=`DelegationNotPropagatedError`}};function w(r,a,o=!1){if(r instanceof n.t||r instanceof p||r instanceof e.n||r instanceof C||r instanceof t.H||r instanceof t.V)return r;let s=i.o(r);return s===400?new p(r instanceof Error?r.message:`No ciphertext for this account`,{cause:r}):o&&s===500?new C(`Delegated decryption failed with a server error. This is most commonly caused by the delegation not having propagated to the gateway yet — after granting delegation, allow 1–2 minutes for cross-chain synchronization before retrying. If the error persists, the gateway or relayer may be experiencing an unrelated issue.`,{cause:r}):s===void 0?new n.t(a,{cause:r}):new e.n(r instanceof Error?r.message:a,s,{cause:r})}function ee(t,r){if(t instanceof e.r)return t;let a=i.o(t);return a===void 0?new n.n(r,{cause:t}):new e.n(t instanceof Error?t.message:r,a,{cause:t})}function te(){return{type:`cleartext`,createRelayer:t=>{if(!t.executorAddress)throw new e.t(`Cleartext relayer requires an executorAddress. Either use a chain preset that includes it (e.g. hardhat, hoodi) or set it on the chain definition.`);return new a.t(t)}}}function T(e){return e.startsWith(`0x`)?e:`0x${e}`}const ne=[{type:`function`,name:`allowance`,inputs:[{name:`owner`,type:`address`,internalType:`address`},{name:`spender`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`approve`,inputs:[{name:`spender`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`approveAndCall`,inputs:[{name:`spender`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`approveAndCall`,inputs:[{name:`spender`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`},{name:`data`,type:`bytes`,internalType:`bytes`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`balanceOf`,inputs:[{name:`account`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`supportsInterface`,inputs:[{name:`interfaceId`,type:`bytes4`,internalType:`bytes4`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`totalSupply`,inputs:[],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`transfer`,inputs:[{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`transferAndCall`,inputs:[{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`transferAndCall`,inputs:[{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`},{name:`data`,type:`bytes`,internalType:`bytes`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`transferFrom`,inputs:[{name:`from`,type:`address`,internalType:`address`},{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`transferFromAndCall`,inputs:[{name:`from`,type:`address`,internalType:`address`},{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`},{name:`data`,type:`bytes`,internalType:`bytes`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`transferFromAndCall`,inputs:[{name:`from`,type:`address`,internalType:`address`},{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`event`,name:`Approval`,inputs:[{name:`owner`,type:`address`,indexed:!0,internalType:`address`},{name:`spender`,type:`address`,indexed:!0,internalType:`address`},{name:`value`,type:`uint256`,indexed:!1,internalType:`uint256`}],anonymous:!1},{type:`event`,name:`Transfer`,inputs:[{name:`from`,type:`address`,indexed:!0,internalType:`address`},{name:`to`,type:`address`,indexed:!0,internalType:`address`},{name:`value`,type:`uint256`,indexed:!1,internalType:`uint256`}],anonymous:!1}];function E(e,t,n,r=`0x`){return{address:e,abi:ne,functionName:`transferAndCall`,args:[t,n,r]}}function re(e){return o.i(e.signer,e.provider,e)}var D=class{#e;#t;#n;#r;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.relayer,this.#r=e.decryptionService}#i(e){return t.B(this.#r,e)}async decryptValues(e){let t=this.#i(`decryptValues`),n=await r.s(`decryptValues`,this.#e,this.#t);return t.userDecrypt(e,n.address)}async delegatedDecryptValues(e,t,n=t){let i=this.#i(`delegatedDecryptValues`),a=await r.s(`delegatedDecryptValues`,this.#e,this.#t);return i.delegatedUserDecrypt(e,t,a.address,n)}async decryptPublicValues(e){if(e.length===0)return{clearValues:{},decryptionProof:`0x`,abiEncodedClearValues:`0x`};try{return await this.#n.publicDecrypt(e)}catch(e){throw w(e,`Public decryption failed`)}}async delegatedBatchDecryptValues({encryptedInputs:e,delegatorAddress:t,accountAddress:n=t,maxConcurrency:i}){let a=this.#i(`delegatedBatchDecryptValues`),o=await r.s(`delegatedBatchDecryptValues`,this.#e,this.#t);return a.delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:o.address,accountAddress:n,maxConcurrency:i})}},O=class{#e;#t;#n;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.delegationService}#r(e){return t.B(this.#e,e)}async delegateDecryption({contractAddress:e,delegateAddress:t,expirationDate:n}){let i=this.#r(`delegateDecryption`),a=await r.s(`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.s(`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)}},k=class{#e;#t;#n;#r;#i;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.cachingService,this.#r=e.credentialService,this.#i=e.logger}#a(e){return t.B(this.#r,e)}async grantPermit(e){if(e.length===0)return;let t=this.#a(`grantPermit`);await r.c(`grantPermit`,this.#e,this.#t),await t.grantPermit(e)}async grantDelegationPermit(e,t){if(t.length===0)return;let n=this.#a(`grantDelegationPermit`);await r.c(`grantDelegationPermit`,this.#e,this.#t),await n.grantPermit(t,e)}async hasPermit(e){return this.#r?this.#r.hasPermit(e):!1}async hasDelegationPermit(e,t){return this.#r?this.#r.hasPermit(t,e):!1}async warmTransportKeyPair(){let e=this.#r;if(!e)return;let t=this.#e?.walletAccount.getSnapshot();t&&await e.warmTransportKeyPair(t.address)}async revokePermits(e){let n=this.#a(`revokePermits`),i=(0,l.getAddress)((await r.s(`revokePermits`,this.#e,this.#t)).address);try{await n.revokePermits(e)}finally{await t.F(`clear decrypt cache`,()=>this.#n.clearForRequester(i),this.#i)}}async clear(){let e=this.#a(`clear`),n=(0,l.getAddress)((await r.s(`clear`,this.#e,this.#t)).address);try{await e.clearCredentials()}finally{await t.F(`clear decrypt cache`,()=>this.#n.clearForRequester(n),this.#i)}}};const ie=u.z.union([u.z.bigint(),u.z.boolean(),o.p]),ae=u.z.array(u.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,l.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,l.getAddress)(e)}:${(0,l.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=j(e,t);if(!r)throw new n.t(`No permit covers contract ${t} after allow()`);return A(e,r)}function ce(e,t){let r=j(e,t);if(!r)throw new n.t(`No delegated permit covers contract ${t} after allow()`);return{...A(e,r),delegatorAddress:r.delegatorAddress}}function A(e,t){return{signedContractAddresses:t.signedContractAddresses,privateKey:e.keypair.privateKey,publicKey:e.keypair.publicKey,signature:t.signature,startTimestamp:t.startTimestamp,durationDays:t.durationDays}}function j(e,t){let n=o.f(t);return e.permits.find(e=>e.signedContractAddresses.includes(n))}var le=class{#e;#t;#n;#r;#i;constructor({cache:e,credentialService:t,delegationService:n,relayer:r,emitEvent:i}){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i}async userDecrypt(e,t){let n=(0,l.getAddress)(t);return this.#a(e,{requesterAddress:n,resolveCredentials:e=>this.#t.grantPermit(e),decryptContract:async({credentials:e,contractAddress:t,encryptedValues:r})=>this.#r.userDecrypt({encryptedValues:r,contractAddress:t,...se(e,t),signerAddress:n}),errorMessage:`Failed to decrypt encrypted values`})}async delegatedUserDecrypt(e,t,n,r){let i=(0,l.getAddress)(t),a=(0,l.getAddress)(n);return this.#a(e,{requesterAddress:(0,l.getAddress)(r),resolveCredentials:e=>this.#t.grantPermit(e,i),validate:e=>this.#l(e,{delegatorAddress:i,delegateAddress:a}),decryptContract:async({credentials:e,contractAddress:t,encryptedValues:n})=>this.#r.delegatedUserDecrypt({encryptedValues:n,contractAddress:t,...ce(e,t),delegateAddress:a}),errorMessage:`Failed to decrypt delegated encrypted values`,delegated:!0})}async delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:n,accountAddress:i,maxConcurrency:a=5}){let o=e.map(e=>({encryptedValue:e.encryptedValue,contractAddress:(0,l.getAddress)(e.contractAddress)}));if(o.length===0)return{items:o};let s=(0,l.getAddress)(i);try{let e=await this.delegatedUserDecrypt(o.map(({encryptedValue:e,contractAddress:t})=>({encryptedValue:e,contractAddress:t})),t,n,s);for(let t of o)this.#o(t,e);return{items:o}}catch(e){if(r.m(e))throw e;if(o.length===1){let[t=this.#c()]=o;return t.error=this.#s(e,`Failed to decrypt delegated encrypted values`,!0),{items:o}}}return await r.a(o.map(e=>async()=>{try{let r=await this.delegatedUserDecrypt([{encryptedValue:e.encryptedValue,contractAddress:e.contractAddress}],t,n,s);this.#o(e,r)}catch(t){if(r.m(t))throw t;e.error=this.#s(t,`Failed to decrypt delegated encrypted values`,!0)}}),a),{items:o}}async#a(e,t){if(e.length===0)return{};let n=e.map(e=>({encryptedValue:e.encryptedValue,contractAddress:(0,l.getAddress)(e.contractAddress)})),a={},o=[];for(let e of n)r.i(e.encryptedValue)?a[e.encryptedValue]=0n:o.push(e);if(o.length===0)return a;let s=Array.from(new Set(n.map(e=>e.contractAddress))),c=Array.from(new Set(o.map(e=>e.contractAddress)));t.validate&&await t.validate(c);let u=[];for(let e of o){let n=await this.#e.get(t.requesterAddress,e.contractAddress,e.encryptedValue);n===null?u.push(e):a[e.encryptedValue]=n}if(u.length===0)return a;let d=await t.resolveCredentials(s),f=new Map;for(let e of u){let t=f.get(e.contractAddress);t?t.push(e.encryptedValue):f.set(e.contractAddress,[e.encryptedValue])}let p=Date.now(),m=u.map(e=>e.encryptedValue);try{this.#i({type:r.o.DecryptStart,encryptedValues:m}),await r.a([...f.entries()].map(([e,n])=>async()=>{let r=await t.decryptContract({credentials:d,contractAddress:e,encryptedValues:n});for(let[n,i]of Object.entries(r))a[n]=i,await this.#e.set(t.requesterAddress,e,n,i)}),5);let e={};for(let t of m){let n=a[t];n!==void 0&&(e[t]=n)}return this.#i({type:r.o.DecryptEnd,durationMs:Date.now()-p,encryptedValues:m,result:e}),a}catch(e){throw this.#i({type:r.o.DecryptError,error:i.c(e),durationMs:Date.now()-p,encryptedValues:m}),w(e,t.errorMessage,t.delegated)}}#o(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}#s(t,n,r=!1){return t instanceof e.r?t:w(t,n,r)}#c(){throw new n.t(`Batch delegated decryption invariant failed: missing item`)}async#l(e,{delegatorAddress:t,delegateAddress:n}){let r=await this.#n.findInactiveDelegations(e,t,n);if(r.size!==0)for(let e of r.values())throw e}};function ue(e){if(!(e instanceof Error))return null;let t=e.cause;if(typeof t!=`object`||!t||!(`data`in t))return null;let{data:n}=t;return typeof n!=`object`||!n||!(`errorName`in n)?null:typeof n.errorName==`string`?n.errorName:null}const M={AlreadyDelegatedOrRevokedInSameBlock:e=>new h(`Only one delegate/revoke per (delegator, delegate, contract) per block. Wait for the next block before retrying.`,{cause:e}),SenderCannotBeContractAddress:e=>new b(`The contract address cannot be the caller address.`,{cause:e}),EnforcedPause:e=>new x(`The ACL contract is paused. Delegation operations are temporarily disabled.`,{cause:e}),SenderCannotBeDelegate:e=>new m(`Cannot delegate to yourself (delegate === msg.sender).`,{cause:e}),DelegateCannotBeContractAddress:e=>new y(`Delegate address cannot be the same as the contract address.`,{cause:e}),ExpirationDateBeforeOneHour:e=>new S(`Expiration date must be at least 1 hour in the future.`,{cause:e}),ExpirationDateAlreadySetToSameValue:e=>new v(`The new expiration date is the same as the current one.`,{cause:e}),NotDelegatedYet:e=>new g(`Cannot revoke: no active delegation exists.`,{cause:e})};function de(e){return e in M}function fe(e,t){let n=ue(e);if(n&&de(n))return M[n](t);let r=e instanceof Error?e.message:String(e);for(let[e,n]of Object.entries(M))if(r.includes(e))return n(t);return null}var pe=class{#e;#t;#n;#r;constructor({provider:e,relayer:t,emitEvent:n=()=>{},logger:r}){this.#e=e,this.#t=t,this.#r=r,this.#n=n}async delegateDecryption(e,{contractAddress:t,delegateAddress:n,delegatorAddress:i,expirationDate:a}){if(a&&a.getTime()<Date.now()+36e5)throw new S(`Expiration date must be at least 1 hour in the future`);let o=(0,l.getAddress)(t),s=(0,l.getAddress)(n),c=(0,l.getAddress)(i);if(s===c)throw new m(`Cannot delegate to yourself (delegate === msg.sender).`);if(s===o)throw new y(`Delegate address cannot be the same as the contract address (${o}).`);let u=await this.#t.getAclAddress(),d=a?BigInt(Math.floor(a.getTime()/1e3)):r.l,f;try{f=await this.getDelegationExpiry({contractAddress:o,delegatorAddress:c,delegateAddress:s})}catch(e){this.#r.warn(`delegateDecryption: pre-flight expiry check failed`,{error:e}),f=-1n}if(f===d)throw new v(`The new expiration date (${d}) is the same as the current one. No on-chain change needed.`);return this.#i({operation:`delegateDecryption`,signer:e,contractAddress:t,config:r.u(u,s,o,d)})}async revokeDelegation(e,{contractAddress:t,delegateAddress:n,delegatorAddress:i}){let a=(0,l.getAddress)(t),o=(0,l.getAddress)(n),s=(0,l.getAddress)(i),c=await this.#t.getAclAddress(),u;try{u=await this.getDelegationExpiry({contractAddress:a,delegatorAddress:s,delegateAddress:o})}catch(e){this.#r.warn(`revokeDelegation: pre-flight expiry check failed`,{error:e}),u=1n}if(u===0n)throw new g(`No active delegation found for delegate ${o} on contract ${a}.`);return this.#i({operation:`revokeDelegation`,signer:e,contractAddress:t,config:r.p(c,o,a)})}async isDelegated(e){let t=await this.getDelegationExpiry(e);return t===0n?!1:t===r.l?!0:t>await this.#e.getBlockTimestamp()}async getDelegationExpiry({contractAddress:e,delegatorAddress:t,delegateAddress:n}){let i=await this.#t.getAclAddress();return this.#e.readContract(r.d(i,(0,l.getAddress)(t),(0,l.getAddress)(n),(0,l.getAddress)(e)))}async#i({operation:e,signer:t,contractAddress:n,config:i}){try{return await r.n({operation:e,signer:t,provider:this.#e,config:i,emit:e=>this.#n(e,n),logger:this.#r})}catch(e){throw this.#a(e),e}}#a(e){if(!(e instanceof r.b))return;let t=fe(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 g||t instanceof _){let n=(0,l.getAddress)(e);r.set(n,t);return}throw t}})),r}async assertDelegationActive(e,t,n){let i=(0,l.getAddress)(e),a=(0,l.getAddress)(t),o=(0,l.getAddress)(n),s=await this.getDelegationExpiry({contractAddress:i,delegatorAddress:a,delegateAddress:o});if(s===0n)throw new g(`No active delegation from ${a} to ${o} for ${i}`);if(s!==r.l&&s<=await this.#e.getBlockTimestamp())throw new _(`Delegation from ${a} to ${o} for ${i} has expired`)}},me=class{#e;#t;constructor({relayer:e,emitEvent:t}){this.#e=e,this.#t=t}async encrypt(e){let t=Date.now();try{this.#t({type:r.o.EncryptStart},e.contractAddress);let n=await this.#e.encrypt(e);return this.#t({type:r.o.EncryptEnd,durationMs:Date.now()-t},e.contractAddress),n}catch(n){throw this.#t({type:r.o.EncryptError,error:i.c(n),durationMs:Date.now()-t},e.contractAddress),ee(n,`Encryption failed`)}}},he=class{#e;#t;#n;#r;#i;#a=new Set;#o;constructor(e){this.#e=e.signer,this.#t=e.relayer,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.F(`switch relayer chain`,()=>this.#t.switchChain(i),this.#i);let a=this.#r;a&&await t.F(`credential wallet account change`,()=>a.handleWalletAccountChange(n,r),this.#i),n&&await t.F(`clear decrypt cache`,()=>this.#n.clearForRequester(n.address),this.#i),await Promise.all(Array.from(this.#a,n=>t.F(`wallet account listener`,()=>n(e),this.#i)))}};function N(e){return(0,l.keccak256)((0,l.toBytes)(e))}const P={ConfidentialTransfer:N(`ConfidentialTransfer(address,address,bytes32)`),Wrap:N(`Wrap(address,uint256,bytes32)`),UnwrapRequested:N(`UnwrapRequested(address,bytes32,bytes32)`),UnwrapFinalized:N(`UnwrapFinalized(address,bytes32,bytes32,uint64)`)};function F(e){return(0,l.getAddress)(T(e.slice(-40)))}function I(e){return e}function L(e,t){let n=2+t*64,r=e.slice(n,n+64);return r.length===64?r:r.padEnd(64,`0`)}function R(e,t){return(0,l.getAddress)(T(L(e,t).slice(-40)))}function z(e,t){return BigInt(`0x`+L(e,t))}function B(e,t){return T(L(e,t))}function V(e){return e.topics[0]!==P.ConfidentialTransfer||e.topics.length<4?null:{eventName:`ConfidentialTransfer`,from:F(e.topics[1]),to:F(e.topics[2]),encryptedAmount:I(e.topics[3])}}function H(e){return e.topics[0]!==P.Wrap||e.topics.length<2?null:{eventName:`Wrap`,to:F(e.topics[1]),roundedAmount:z(e.data,0),encryptedWrappedAmount:B(e.data,1)}}function U(e){return e.topics[0]!==P.UnwrapRequested||e.topics.length<3?null:{eventName:`UnwrapRequested`,receiver:F(e.topics[1]),unwrapRequestId:I(e.topics[2]),encryptedAmount:B(e.data,0)}}function W(e){return e.topics[0]!==P.UnwrapFinalized||e.topics.length<3?null:{eventName:`UnwrapFinalized`,receiver:F(e.topics[1]),unwrapRequestId:I(e.topics[2]),encryptedAmount:B(e.data,0),cleartextAmount:z(e.data,1)}}function G(e){return V(e)??H(e)??U(e)??W(e)}function ge(e){let t=[];for(let n of e){let e=G(n);e&&t.push(e)}return t}function K(e){for(let t of e){let e=U(t);if(e)return e}return null}function _e(e){for(let t of e){let e=H(t);if(e)return e}return null}const ve=[P.ConfidentialTransfer,P.Wrap,P.UnwrapRequested,P.UnwrapFinalized],q={DelegatedForUserDecryption:N(`DelegatedForUserDecryption(address,address,address,uint64,uint64,uint64)`),RevokedDelegationForUserDecryption:N(`RevokedDelegationForUserDecryption(address,address,address,uint64,uint64)`)};function J(e){return e.topics[0]!==q.DelegatedForUserDecryption||e.topics.length<3?null:{eventName:`DelegatedForUserDecryption`,delegator:F(e.topics[1]),delegate:F(e.topics[2]),contractAddress:R(e.data,0),delegationCounter:z(e.data,1),oldExpirationDate:z(e.data,2),newExpirationDate:z(e.data,3)}}function Y(e){return e.topics[0]!==q.RevokedDelegationForUserDecryption||e.topics.length<3?null:{eventName:`RevokedDelegationForUserDecryption`,delegator:F(e.topics[1]),delegate:F(e.topics[2]),contractAddress:R(e.data,0),delegationCounter:z(e.data,1),oldExpirationDate:z(e.data,2)}}function X(e){return J(e)??Y(e)}function ye(e){let t=[];for(let n of e){let e=X(n);e&&t.push(e)}return t}function be(e){for(let t of e){let e=J(t);if(e)return e}return null}function xe(e){for(let t of e){let e=Y(t);if(e)return e}return null}const Se=[q.DelegatedForUserDecryption,q.RevokedDelegationForUserDecryption];var Z=class extends r.t{#e;#t=null;#n=null;#r(e){try{return i.r(this.sdk.signer,`WrappedToken.sdk.signer`),this.sdk.signer}catch(n){throw new t.I(e,{cause:n})}}async underlying(){return this.#o()}async isPayable(){if(this.#n!==null)return this.#n;try{let e=await this.#o();this.#n=await this.sdk.provider.readContract(t.p(e))}catch{this.#n=!1}return this.#n}async allowance(e){let n=await this.#o();return this.sdk.provider.readContract(t.h(n,(0,l.getAddress)(e),this.address))}async shield(n,a){let o=await r.s(`shield`,this.sdk.signer,this.sdk.provider),s=await this.isPayable(),c=await this.#o(),u=(0,l.getAddress)(o.address),d;try{d=await this.sdk.provider.readContract(t._(c,u))}catch(t){throw t instanceof e.r?t:new r.g(`Could not read ERC-20 balance for shield validation (token: ${c})`,{cause:i.c(t)})}if(d<n)throw new r.v(`Insufficient ERC-20 balance: requested ${n}, available ${d} (token: ${c})`,{requested:n,available:d,token:c});return s?this.#i(n,c,u,a):this.#a(n,u,a)}async#i(e,t,n,r){this.#r(`shield`);let i=r?.to?(0,l.getAddress)(r.to):n,a=i===n?`0x`:i;return this.submitTransaction({operation:`shield:transferAndCall`,config:E(t,this.address,e,a),onSubmitted:r?.onShieldSubmitted})}async#a(e,n,r){this.#r(`shield`);let i=r?.approvalStrategy??`exact`;i!==`skip`&&await this.#c(e,i===`max`,r);let a=r?.to?(0,l.getAddress)(r.to):n;return this.submitTransaction({operation:`shield:approveAndWrap`,config:t.P(this.address,a,e),onSubmitted:r?.onShieldSubmitted})}async approveUnderlying(e){this.#r(`approveUnderlying`);let n=await r.s(`approveUnderlying`,this.sdk.signer,this.sdk.provider),i=await this.#o(),a=(0,l.getAddress)(n.address),o=e??2n**256n-1n;return o>0n&&await this.sdk.provider.readContract(t.h(i,a,this.address))>0n&&await this.submitTransaction({operation:`approveUnderlying:reset`,config:t.g(i,this.address,0n)}),this.submitTransaction({operation:`approveUnderlying`,config:t.g(i,this.address,o)})}async unshield(e,n){let{skipBalanceCheck:r=!1,onUnwrapSubmitted:i,onFinalizing:a,onFinalizeSubmitted:o}=n??{};r||await this.assertConfidentialBalance(e);let s={onFinalizing:a,onFinalizeSubmitted:o},c=crypto.randomUUID(),l=await this.unwrap(e);return t.F(`unshield: onUnwrapSubmitted`,()=>i?.(l.txHash),this.sdk.logger),this.#s(l.txHash,c,s)}async unshieldAll(e){let n=crypto.randomUUID(),r=await this.unwrapAll();return t.F(`unshieldAll: onUnwrapSubmitted`,()=>e?.onUnwrapSubmitted?.(r.txHash),this.sdk.logger),this.#s(r.txHash,n,e)}async resumeUnshield(e,t){return this.#s(e,crypto.randomUUID(),t)}async unwrap(e){this.#r(`unwrap`);let i=(0,l.getAddress)((await r.s(`unwrap`,this.sdk.signer,this.sdk.provider)).address),{encryptedValues:a,inputProof:o}=await this.sdk.encrypt({values:[{value:e,type:`euint64`}],contractAddress:this.address,userAddress:i}),[s]=a;if(!s)throw new n.n(`Encryption returned no encrypted values`);return this.submitTransaction({operation:`unwrap`,config:t.M(this.address,i,i,s,o)})}async unwrapAll(){this.#r(`unwrapAll`);let e=(0,l.getAddress)((await r.s(`unwrapAll`,this.sdk.signer,this.sdk.provider)).address),i=await this.readConfidentialBalanceOf(e);if(r.i(i))throw new n.t(`Cannot unshield: balance is zero`);return this.submitTransaction({operation:`unwrapAll`,config:t.N(this.address,e,e,i)})}async finalizeUnwrap(e){this.#r(`finalizeUnwrap`),await r.c(`finalizeUnwrap`,this.sdk.signer,this.sdk.provider);let n=await this.sdk.decryption.decryptPublicValues([e]),a=n.clearValues[e];return i.t(a,`finalizeUnwrap: clearValue`),this.submitTransaction({operation:`finalizeUnwrap`,config:t.E(this.address,e,a,n.decryptionProof)})}async#o(){return this.#e===void 0?(this.#t||=this.sdk.provider.readContract(t.j(this.address)).then(e=>(this.#e=e,this.#t=null,e)).catch(e=>{throw this.#t=null,e}),this.#t):this.#e}async#s(n,i,a){this.emit({type:r.o.UnshieldPhase1Submitted,txHash:n,operationId:i});let o;try{o=await this.sdk.provider.waitForTransactionReceipt(n)}catch(t){throw t instanceof e.r?t:new r.b(`Failed to get unshield receipt`,{cause:t})}let s=K(o.logs);if(!s)throw new r.b(`No UnwrapRequested event found in unshield receipt`);this.emit({type:r.o.UnshieldPhase2Started,operationId:i}),t.F(`unshield: onFinalizing`,()=>a?.onFinalizing?.(),this.sdk.logger);let c=await this.finalizeUnwrap(s.unwrapRequestId??s.encryptedAmount);return this.emit({type:r.o.UnshieldPhase2Submitted,txHash:c.txHash,operationId:i}),t.F(`unshield: onFinalizeSubmitted`,()=>a?.onFinalizeSubmitted?.(c.txHash),this.sdk.logger),c}async#c(e,n,i){this.#r(`approveUnderlying`);let a=await this.#o(),o=(0,l.getAddress)((await r.s(`approveUnderlying`,this.sdk.signer,this.sdk.provider)).address),s=await this.sdk.provider.readContract(t.h(a,o,this.address));if(s>=e)return;s>0n&&await this.submitTransaction({operation:`approveUnderlying:reset`,config:t.g(a,this.address,0n)});let c=n?2n**256n-1n:e;await this.submitTransaction({operation:`approveUnderlying`,config:t.g(a,this.address,c),onSubmitted:i?.onApprovalSubmitted})}},Ce=class{relayer;provider;signer;storage;registry;permits;delegations;decryption;#e;#t;#n;#r;#i;#a;#o;#s;#c;constructor(e){this.relayer=e.relayer,this.provider=e.provider,this.signer=e.signer,this.storage=e.storage,this.#t=e.onEvent??function(){},this.#n=e.logger,this.#r=new oe(e.storage,this.#n),this.#c=new pe({provider:this.provider,relayer:this.relayer,emitEvent:this.emitEvent.bind(this),logger:this.#n});let t={};for(let n of e.chains)n.registryAddress&&(t[n.id]=n.registryAddress);this.registry=new o.o({provider:this.provider,registryAddresses:t,registryTTL:e.registryTTL}),this.#e=e.registryTTL,e.signer&&(this.#s=new o.d({relayer:this.relayer,signer:e.signer,transportKeyPairTTL:e.transportKeyPairTTL,permitTTL:e.permitTTL,storage:this.storage,permitStorage:e.permitStorage,logger:this.#n}),this.#o=new le({cache:this.#r,credentialService:this.#s,delegationService:this.#c,relayer:this.relayer,emitEvent:this.emitEvent.bind(this)})),this.#a=new me({relayer:this.relayer,emitEvent:this.emitEvent.bind(this)}),this.#i=new he({signer:e.signer,relayer:this.relayer,cachingService:this.#r,credentialService:this.#s,logger:this.#n}),this.permits=new k({signer:this.signer,provider:this.provider,cachingService:this.#r,credentialService:this.#s,logger:this.#n}),this.delegations=new O({signer:this.signer,provider:this.provider,delegationService:this.#c}),this.decryption=new D({signer:this.signer,provider:this.provider,relayer:this.relayer,decryptionService:this.#o})}onWalletAccountChange(e){return this.#i.onWalletAccountChange(e)}get logger(){return this.#n}emitEvent(e,t){try{this.#t({...e,tokenAddress:t,timestamp:Date.now()})}catch(t){this.#n.warn(`${e.type} event listener silently failed`,{error:t})}}createWrappersRegistry(e){return new o.o({provider:this.provider,registryAddresses:e,registryTTL:this.#e})}async encrypt(e){return this.#a.encrypt(e)}createToken(e){return new r.t(this,e)}createWrappedToken(e){return new Z(this,e)}dispose(){this.#i.dispose()}terminate(){this.dispose(),this.relayer.terminate(),this.signer?.dispose?.()}[Symbol.dispose](){this.terminate()}};function Q(e){return`zama:pending-unshield:${o.f(e)}`}const we=u.z.union([u.z.pipe(o.m,u.z.transform(e=>({unwrapTxHash:e}))),u.z.pipe(u.z.object({version:u.z.literal(1),unwrapTxHash:o.m,unwrapRequestId:u.z.optional(o.m)}),u.z.transform(({unwrapTxHash:e,unwrapRequestId:t})=>({unwrapTxHash:e,unwrapRequestId:t})))]);async function Te(e,t,n,r){if(r===void 0){await e.set(Q(t),n);return}await e.set(Q(t),{version:1,unwrapTxHash:n,unwrapRequestId:r})}async function Ee(e,t){return(await $(e,t))?.unwrapTxHash??null}async function $(e,t){let n=Q(t),r=await e.get(n);if(r==null)return null;let i=we.safeParse(r);return i.success?i.data:(await e.delete(n),null)}async function De(e,t){await e.delete(Q(t))}var Oe=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 ke=new Oe;exports.ACL_TOPICS=Se,exports.AclPausedError=x,exports.AclTopics=q,exports.BalanceCheckUnavailableError=r.h,exports.BaseSigner=o.t,exports.ChainMismatchError=r.y,exports.ChromeSessionStorage=Oe,exports.ConfigurationError=e.t,exports.Decryption=D,exports.DecryptionFailedError=n.t,exports.DefaultRegistryAddresses=o.a,exports.DelegationContractIsSelfError=b,exports.DelegationCooldownError=h,exports.DelegationDelegateEqualsContractError=y,exports.DelegationExpirationTooSoonError=S,exports.DelegationExpiredError=_,exports.DelegationExpiryUnchangedError=v,exports.DelegationNotFoundError=g,exports.DelegationNotPropagatedError=C,exports.DelegationSelfNotAllowedError=m,exports.Delegations=O,exports.ERC1363_INTERFACE_ID=t.c,exports.ERC20ReadFailedError=r.g,exports.ERC7984_INTERFACE_ID=t.l,exports.ERC7984_WRAPPER_INTERFACE_ID=t.u,exports.EncryptionFailedError=n.n,exports.IndexedDBStorage=s.n,exports.InsufficientConfidentialBalanceError=r._,exports.InsufficientERC20BalanceError=r.v,exports.InvalidTransportKeyPairError=f,exports.MemoryStorage=o.l,exports.MutableWalletAccountStore=o.n,exports.NoCiphertextError=p,exports.Permits=k,exports.RelayerRequestFailedError=e.n,exports.SignerNotConfiguredError=t.I,exports.SignerRequiredError=t.L,exports.SigningFailedError=t.V,exports.SigningRejectedError=t.H,exports.TOKEN_TOPICS=ve,exports.Token=r.t,exports.Topics=P,exports.TransactionRevertedError=r.b,exports.TransportKeyPairExpiredError=d,exports.WalletAccountNotReadyError=t.R,exports.WalletNotConnectedError=t.z,exports.WrappedToken=Z,exports.WrappersRegistry=o.o,exports.ZERO_ENCRYPTED_VALUE=r.r,exports.ZamaError=e.r,exports.ZamaErrorCode=e.i,exports.ZamaSDK=Ce,exports.ZamaSDKEvents=r.o,exports.allowanceContract=t.h,exports.anvil=c.t,exports.approveContract=t.g,exports.balanceOfContract=t._,exports.bscTestnet=c.n,exports.chains=c.r,exports.chromeSessionStorage=ke,exports.clearPendingUnshield=De,exports.cleartext=te,exports.confidentialBalanceOfContract=t.S,exports.confidentialTotalSupplyContract=t.C,exports.confidentialTransferContract=t.w,exports.confidentialTransferFromContract=t.T,exports.createConfig=re,exports.createWalletAccountStore=o.r,exports.decimalsContract=t.v,exports.decodeAclEvent=X,exports.decodeAclEvents=ye,exports.decodeConfidentialTransfer=V,exports.decodeDelegatedForUserDecryption=J,exports.decodeOnChainEvent=G,exports.decodeOnChainEvents=ge,exports.decodeRevokedDelegationForUserDecryption=Y,exports.decodeUnwrapFinalized=W,exports.decodeUnwrapRequested=U,exports.decodeWrap=H,exports.delegateForUserDecryptionContract=r.u,exports.finalizeUnwrapContract=t.E,exports.findDelegatedForUserDecryption=be,exports.findRevokedDelegationForUserDecryption=xe,exports.findUnwrapRequested=K,exports.findWrap=_e,exports.getConfidentialTokenAddressContract=t.t,exports.getDelegationExpiryContract=r.d,exports.getTokenAddressContract=t.n,exports.getTokenPairContract=t.r,exports.getTokenPairsContract=t.i,exports.getTokenPairsLengthContract=t.a,exports.getTokenPairsSliceContract=t.o,exports.hardhat=c.i,exports.hoodi=c.a,exports.indexedDBStorage=s.r,exports.inferredTotalSupplyContract=t.D,exports.ingenTestnet=c.o,exports.isConfidentialTokenContract=t.d,exports.isConfidentialTokenValidContract=t.s,exports.isConfidentialWrapperContract=t.f,exports.isEncryptedValueZero=r.i,exports.isHandleDelegatedContract=r.f,exports.isOperatorContract=t.O,exports.loadPendingUnshield=Ee,exports.loadPendingUnshieldRequest=$,exports.mainnet=c.s,exports.matchZamaError=e.a,exports.memoryStorage=o.u,exports.nameContract=t.b,exports.rateContract=t.k,exports.resolveChainRelayers=o.s,exports.resolveStorage=o.c,exports.revokeDelegationContract=r.p,exports.savePendingUnshield=Te,exports.sepolia=c.c,exports.setOperatorContract=t.A,exports.supportsInterfaceContract=t.m,exports.symbolContract=t.x,exports.transferAndCallContract=E,exports.underlyingContract=t.j,exports.unwrapContract=t.M,exports.unwrapFromBalanceContract=t.N,exports.wrapContract=t.P;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./relayer.cjs"),t=require("./wrappers-registry.cjs"),n=require("./encryption.cjs"),r=require("./token.cjs"),i=require("./assertions.cjs"),a=require("./relayer-cleartext.cjs"),o=require("./base-signer.cjs"),s=require("./validation.cjs"),c=require("./chains.cjs");let l=require("viem"),u=require("zod/mini");var d=class extends e.r{constructor(t,n){super(e.i.TransportKeyPairExpired,t,n),this.name=`TransportKeyPairExpiredError`}},f=class extends e.r{constructor(t,n){super(e.i.InvalidTransportKeyPair,t,n),this.name=`InvalidTransportKeyPairError`}},p=class extends e.r{constructor(t,n){super(e.i.NoCiphertext,t,n),this.name=`NoCiphertextError`}},m=class extends e.r{constructor(t,n){super(e.i.DelegationSelfNotAllowed,t,n),this.name=`DelegationSelfNotAllowedError`}},h=class extends e.r{constructor(t,n){super(e.i.DelegationCooldown,t,n),this.name=`DelegationCooldownError`}},g=class extends e.r{constructor(t,n){super(e.i.DelegationNotFound,t,n),this.name=`DelegationNotFoundError`}},_=class extends e.r{constructor(t,n){super(e.i.DelegationExpired,t,n),this.name=`DelegationExpiredError`}},v=class extends e.r{constructor(t,n){super(e.i.DelegationExpiryUnchanged,t,n),this.name=`DelegationExpiryUnchangedError`}},y=class extends e.r{constructor(t,n){super(e.i.DelegationDelegateEqualsContract,t,n),this.name=`DelegationDelegateEqualsContractError`}},b=class extends e.r{constructor(t,n){super(e.i.DelegationContractIsSelf,t,n),this.name=`DelegationContractIsSelfError`}},x=class extends e.r{constructor(t,n){super(e.i.AclPaused,t,n),this.name=`AclPausedError`}},S=class extends e.r{constructor(t,n){super(e.i.DelegationExpirationTooSoon,t,n),this.name=`DelegationExpirationTooSoonError`}},C=class extends e.r{constructor(t,n){super(e.i.DelegationNotPropagated,t,n),this.name=`DelegationNotPropagatedError`}};function w(r,a,o=!1){if(r instanceof n.t||r instanceof p||r instanceof e.n||r instanceof C||r instanceof t.W||r instanceof t.U)return r;let s=i.o(r);return s===400?new p(r instanceof Error?r.message:`No ciphertext for this account`,{cause:r}):o&&s===500?new C(`Delegated decryption failed with a server error. This is most commonly caused by the delegation not having propagated to the gateway yet — after granting delegation, allow 1–2 minutes for cross-chain synchronization before retrying. If the error persists, the gateway or relayer may be experiencing an unrelated issue.`,{cause:r}):s===void 0?new n.t(a,{cause:r}):new e.n(r instanceof Error?r.message:a,s,{cause:r})}function ee(t,r){if(t instanceof e.r)return t;let a=i.o(t);return a===void 0?new n.n(r,{cause:t}):new e.n(t instanceof Error?t.message:r,a,{cause:t})}function te(){return{type:`cleartext`,createRelayer:t=>{if(!t.executorAddress)throw new e.t(`Cleartext relayer requires an executorAddress. Either use a chain preset that includes it (e.g. hardhat, hoodi) or set it on the chain definition.`);return new a.t(t)}}}function T(e){return e.startsWith(`0x`)?e:`0x${e}`}const ne=[{type:`function`,name:`allowance`,inputs:[{name:`owner`,type:`address`,internalType:`address`},{name:`spender`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`approve`,inputs:[{name:`spender`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`approveAndCall`,inputs:[{name:`spender`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`approveAndCall`,inputs:[{name:`spender`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`},{name:`data`,type:`bytes`,internalType:`bytes`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`balanceOf`,inputs:[{name:`account`,type:`address`,internalType:`address`}],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`supportsInterface`,inputs:[{name:`interfaceId`,type:`bytes4`,internalType:`bytes4`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`view`},{type:`function`,name:`totalSupply`,inputs:[],outputs:[{name:``,type:`uint256`,internalType:`uint256`}],stateMutability:`view`},{type:`function`,name:`transfer`,inputs:[{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`transferAndCall`,inputs:[{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`transferAndCall`,inputs:[{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`},{name:`data`,type:`bytes`,internalType:`bytes`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`transferFrom`,inputs:[{name:`from`,type:`address`,internalType:`address`},{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`transferFromAndCall`,inputs:[{name:`from`,type:`address`,internalType:`address`},{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`},{name:`data`,type:`bytes`,internalType:`bytes`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`function`,name:`transferFromAndCall`,inputs:[{name:`from`,type:`address`,internalType:`address`},{name:`to`,type:`address`,internalType:`address`},{name:`value`,type:`uint256`,internalType:`uint256`}],outputs:[{name:``,type:`bool`,internalType:`bool`}],stateMutability:`nonpayable`},{type:`event`,name:`Approval`,inputs:[{name:`owner`,type:`address`,indexed:!0,internalType:`address`},{name:`spender`,type:`address`,indexed:!0,internalType:`address`},{name:`value`,type:`uint256`,indexed:!1,internalType:`uint256`}],anonymous:!1},{type:`event`,name:`Transfer`,inputs:[{name:`from`,type:`address`,indexed:!0,internalType:`address`},{name:`to`,type:`address`,indexed:!0,internalType:`address`},{name:`value`,type:`uint256`,indexed:!1,internalType:`uint256`}],anonymous:!1}];function E(e,t,n,r=`0x`){return{address:e,abi:ne,functionName:`transferAndCall`,args:[t,n,r]}}function re(e){return o.i(e.signer,e.provider,e)}var D=class{#e;#t;#n;#r;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.relayer,this.#r=e.decryptionService}#i(e){return t.H(this.#r,e)}async decryptValues(e){let t=this.#i(`decryptValues`),n=await r.s(`decryptValues`,this.#e,this.#t);return t.userDecrypt(e,n.address)}async delegatedDecryptValues(e,t,n=t){let i=this.#i(`delegatedDecryptValues`),a=await r.s(`delegatedDecryptValues`,this.#e,this.#t);return i.delegatedUserDecrypt(e,t,a.address,n)}async decryptPublicValues(e){if(e.length===0)return{clearValues:{},decryptionProof:`0x`,abiEncodedClearValues:`0x`};try{return await this.#n.publicDecrypt(e)}catch(e){throw w(e,`Public decryption failed`)}}async delegatedBatchDecryptValues({encryptedInputs:e,delegatorAddress:t,accountAddress:n=t,maxConcurrency:i}){let a=this.#i(`delegatedBatchDecryptValues`),o=await r.s(`delegatedBatchDecryptValues`,this.#e,this.#t);return a.delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:o.address,accountAddress:n,maxConcurrency:i})}},O=class{#e;#t;#n;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.delegationService}#r(e){return t.H(this.#e,e)}async delegateDecryption({contractAddress:e,delegateAddress:t,expirationDate:n}){let i=this.#r(`delegateDecryption`),a=await r.s(`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.s(`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)}},k=class{#e;#t;#n;#r;#i;constructor(e){this.#e=e.signer,this.#t=e.provider,this.#n=e.cachingService,this.#r=e.credentialService,this.#i=e.logger}#a(e){return t.H(this.#r,e)}async grantPermit(e){if(e.length===0)return;let t=this.#a(`grantPermit`);await r.c(`grantPermit`,this.#e,this.#t),await t.grantPermit(e)}async grantDelegationPermit(e,t){if(t.length===0)return;let n=this.#a(`grantDelegationPermit`);await r.c(`grantDelegationPermit`,this.#e,this.#t),await n.grantPermit(t,e)}async hasPermit(e){return this.#r?this.#r.hasPermit(e):!1}async hasDelegationPermit(e,t){return this.#r?this.#r.hasPermit(t,e):!1}async warmTransportKeyPair(){let e=this.#r;if(!e)return;let t=this.#e?.walletAccount.getSnapshot();t&&await e.warmTransportKeyPair(t.address)}async revokePermits(e){let n=this.#a(`revokePermits`),i=(0,l.getAddress)((await r.s(`revokePermits`,this.#e,this.#t)).address);try{await n.revokePermits(e)}finally{await t.L(`clear decrypt cache`,()=>this.#n.clearForRequester(i),this.#i)}}async clear(){let e=this.#a(`clear`),n=(0,l.getAddress)((await r.s(`clear`,this.#e,this.#t)).address);try{await e.clearCredentials()}finally{await t.L(`clear decrypt cache`,()=>this.#n.clearForRequester(n),this.#i)}}};const ie=u.z.union([u.z.bigint(),u.z.boolean(),o.p]),ae=u.z.array(u.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,l.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,l.getAddress)(e)}:${(0,l.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=j(e,t);if(!r)throw new n.t(`No permit covers contract ${t} after allow()`);return A(e,r)}function ce(e,t){let r=j(e,t);if(!r)throw new n.t(`No delegated permit covers contract ${t} after allow()`);return{...A(e,r),delegatorAddress:r.delegatorAddress}}function A(e,t){return{signedContractAddresses:t.signedContractAddresses,privateKey:e.keypair.privateKey,publicKey:e.keypair.publicKey,signature:t.signature,startTimestamp:t.startTimestamp,durationDays:t.durationDays}}function j(e,t){let n=o.f(t);return e.permits.find(e=>e.signedContractAddresses.includes(n))}var le=class{#e;#t;#n;#r;#i;constructor({cache:e,credentialService:t,delegationService:n,relayer:r,emitEvent:i}){this.#e=e,this.#t=t,this.#n=n,this.#r=r,this.#i=i}async userDecrypt(e,t){let n=(0,l.getAddress)(t);return this.#a(e,{requesterAddress:n,resolveCredentials:e=>this.#t.grantPermit(e),decryptContract:async({credentials:e,contractAddress:t,encryptedValues:r})=>this.#r.userDecrypt({encryptedValues:r,contractAddress:t,...se(e,t),signerAddress:n}),errorMessage:`Failed to decrypt encrypted values`})}async delegatedUserDecrypt(e,t,n,r){let i=(0,l.getAddress)(t),a=(0,l.getAddress)(n);return this.#a(e,{requesterAddress:(0,l.getAddress)(r),resolveCredentials:e=>this.#t.grantPermit(e,i),validate:e=>this.#l(e,{delegatorAddress:i,delegateAddress:a}),decryptContract:async({credentials:e,contractAddress:t,encryptedValues:n})=>this.#r.delegatedUserDecrypt({encryptedValues:n,contractAddress:t,...ce(e,t),delegateAddress:a}),errorMessage:`Failed to decrypt delegated encrypted values`,delegated:!0})}async delegatedBatchDecryptHandlesAs({encryptedInputs:e,delegatorAddress:t,delegateAddress:n,accountAddress:i,maxConcurrency:a=5}){let o=e.map(e=>({encryptedValue:e.encryptedValue,contractAddress:(0,l.getAddress)(e.contractAddress)}));if(o.length===0)return{items:o};let s=(0,l.getAddress)(i);try{let e=await this.delegatedUserDecrypt(o.map(({encryptedValue:e,contractAddress:t})=>({encryptedValue:e,contractAddress:t})),t,n,s);for(let t of o)this.#o(t,e);return{items:o}}catch(e){if(r.m(e))throw e;if(o.length===1){let[t=this.#c()]=o;return t.error=this.#s(e,`Failed to decrypt delegated encrypted values`,!0),{items:o}}}return await r.a(o.map(e=>async()=>{try{let r=await this.delegatedUserDecrypt([{encryptedValue:e.encryptedValue,contractAddress:e.contractAddress}],t,n,s);this.#o(e,r)}catch(t){if(r.m(t))throw t;e.error=this.#s(t,`Failed to decrypt delegated encrypted values`,!0)}}),a),{items:o}}async#a(e,t){if(e.length===0)return{};let n=e.map(e=>({encryptedValue:e.encryptedValue,contractAddress:(0,l.getAddress)(e.contractAddress)})),a={},o=[];for(let e of n)r.i(e.encryptedValue)?a[e.encryptedValue]=0n:o.push(e);if(o.length===0)return a;let s=Array.from(new Set(n.map(e=>e.contractAddress))),c=Array.from(new Set(o.map(e=>e.contractAddress)));t.validate&&await t.validate(c);let u=[];for(let e of o){let n=await this.#e.get(t.requesterAddress,e.contractAddress,e.encryptedValue);n===null?u.push(e):a[e.encryptedValue]=n}if(u.length===0)return a;let d=await t.resolveCredentials(s),f=new Map;for(let e of u){let t=f.get(e.contractAddress);t?t.push(e.encryptedValue):f.set(e.contractAddress,[e.encryptedValue])}let p=Date.now(),m=u.map(e=>e.encryptedValue);try{this.#i({type:r.o.DecryptStart,encryptedValues:m}),await r.a([...f.entries()].map(([e,n])=>async()=>{let r=await t.decryptContract({credentials:d,contractAddress:e,encryptedValues:n});for(let[n,i]of Object.entries(r))a[n]=i,await this.#e.set(t.requesterAddress,e,n,i)}),5);let e={};for(let t of m){let n=a[t];n!==void 0&&(e[t]=n)}return this.#i({type:r.o.DecryptEnd,durationMs:Date.now()-p,encryptedValues:m,result:e}),a}catch(e){throw this.#i({type:r.o.DecryptError,error:i.c(e),durationMs:Date.now()-p,encryptedValues:m}),w(e,t.errorMessage,t.delegated)}}#o(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}#s(t,n,r=!1){return t instanceof e.r?t:w(t,n,r)}#c(){throw new n.t(`Batch delegated decryption invariant failed: missing item`)}async#l(e,{delegatorAddress:t,delegateAddress:n}){let r=await this.#n.findInactiveDelegations(e,t,n);if(r.size!==0)for(let e of r.values())throw e}};function ue(e){if(!(e instanceof Error))return null;let t=e.cause;if(typeof t!=`object`||!t||!(`data`in t))return null;let{data:n}=t;return typeof n!=`object`||!n||!(`errorName`in n)?null:typeof n.errorName==`string`?n.errorName:null}const M={AlreadyDelegatedOrRevokedInSameBlock:e=>new h(`Only one delegate/revoke per (delegator, delegate, contract) per block. Wait for the next block before retrying.`,{cause:e}),SenderCannotBeContractAddress:e=>new b(`The contract address cannot be the caller address.`,{cause:e}),EnforcedPause:e=>new x(`The ACL contract is paused. Delegation operations are temporarily disabled.`,{cause:e}),SenderCannotBeDelegate:e=>new m(`Cannot delegate to yourself (delegate === msg.sender).`,{cause:e}),DelegateCannotBeContractAddress:e=>new y(`Delegate address cannot be the same as the contract address.`,{cause:e}),ExpirationDateBeforeOneHour:e=>new S(`Expiration date must be at least 1 hour in the future.`,{cause:e}),ExpirationDateAlreadySetToSameValue:e=>new v(`The new expiration date is the same as the current one.`,{cause:e}),NotDelegatedYet:e=>new g(`Cannot revoke: no active delegation exists.`,{cause:e})};function de(e){return e in M}function fe(e,t){let n=ue(e);if(n&&de(n))return M[n](t);let r=e instanceof Error?e.message:String(e);for(let[e,n]of Object.entries(M))if(r.includes(e))return n(t);return null}var pe=class{#e;#t;#n;#r;constructor({provider:e,relayer:t,emitEvent:n=()=>{},logger:r}){this.#e=e,this.#t=t,this.#r=r,this.#n=n}async delegateDecryption(e,{contractAddress:t,delegateAddress:n,delegatorAddress:i,expirationDate:a}){if(a&&a.getTime()<Date.now()+36e5)throw new S(`Expiration date must be at least 1 hour in the future`);let o=(0,l.getAddress)(t),s=(0,l.getAddress)(n),c=(0,l.getAddress)(i);if(s===c)throw new m(`Cannot delegate to yourself (delegate === msg.sender).`);if(s===o)throw new y(`Delegate address cannot be the same as the contract address (${o}).`);let u=await this.#t.getAclAddress(),d=a?BigInt(Math.floor(a.getTime()/1e3)):r.l,f;try{f=await this.getDelegationExpiry({contractAddress:o,delegatorAddress:c,delegateAddress:s})}catch(e){this.#r.warn(`delegateDecryption: pre-flight expiry check failed`,{error:e}),f=-1n}if(f===d)throw new v(`The new expiration date (${d}) is the same as the current one. No on-chain change needed.`);return this.#i({operation:`delegateDecryption`,signer:e,contractAddress:t,config:r.u(u,s,o,d)})}async revokeDelegation(e,{contractAddress:t,delegateAddress:n,delegatorAddress:i}){let a=(0,l.getAddress)(t),o=(0,l.getAddress)(n),s=(0,l.getAddress)(i),c=await this.#t.getAclAddress(),u;try{u=await this.getDelegationExpiry({contractAddress:a,delegatorAddress:s,delegateAddress:o})}catch(e){this.#r.warn(`revokeDelegation: pre-flight expiry check failed`,{error:e}),u=1n}if(u===0n)throw new g(`No active delegation found for delegate ${o} on contract ${a}.`);return this.#i({operation:`revokeDelegation`,signer:e,contractAddress:t,config:r.p(c,o,a)})}async isDelegated(e){let t=await this.getDelegationExpiry(e);return t===0n?!1:t===r.l?!0:t>await this.#e.getBlockTimestamp()}async getDelegationExpiry({contractAddress:e,delegatorAddress:t,delegateAddress:n}){let i=await this.#t.getAclAddress();return this.#e.readContract(r.d(i,(0,l.getAddress)(t),(0,l.getAddress)(n),(0,l.getAddress)(e)))}async#i({operation:e,signer:t,contractAddress:n,config:i}){try{return await r.n({operation:e,signer:t,provider:this.#e,config:i,emit:e=>this.#n(e,n),logger:this.#r})}catch(e){throw this.#a(e),e}}#a(e){if(!(e instanceof r.b))return;let t=fe(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 g||t instanceof _){let n=(0,l.getAddress)(e);r.set(n,t);return}throw t}})),r}async assertDelegationActive(e,t,n){let i=(0,l.getAddress)(e),a=(0,l.getAddress)(t),o=(0,l.getAddress)(n),s=await this.getDelegationExpiry({contractAddress:i,delegatorAddress:a,delegateAddress:o});if(s===0n)throw new g(`No active delegation from ${a} to ${o} for ${i}`);if(s!==r.l&&s<=await this.#e.getBlockTimestamp())throw new _(`Delegation from ${a} to ${o} for ${i} has expired`)}},me=class{#e;#t;constructor({relayer:e,emitEvent:t}){this.#e=e,this.#t=t}async encrypt(e){let t=Date.now();try{this.#t({type:r.o.EncryptStart},e.contractAddress);let n=await this.#e.encrypt(e);return this.#t({type:r.o.EncryptEnd,durationMs:Date.now()-t},e.contractAddress),n}catch(n){throw this.#t({type:r.o.EncryptError,error:i.c(n),durationMs:Date.now()-t},e.contractAddress),ee(n,`Encryption failed`)}}},he=class{#e;#t;#n;#r;#i;#a=new Set;#o;constructor(e){this.#e=e.signer,this.#t=e.relayer,this.#n=e.cachingService,this.#r=e.credentialService,this.#i=e.logger,this.#e&&(this.#o=this.#e.walletAccount.subscribe(e=>{this.#s(e).catch(e=>{this.#i.warn(`wallet account handler failed`,{error:e})})}))}onWalletAccountChange(e){return this.#a.add(e),()=>{this.#a.delete(e)}}dispose(){this.#o?.(),this.#o=void 0,this.#a.clear()}async#s(e){let n=e.previous,r=e.next,i=r?.chainId;i!==void 0&&await t.L(`switch relayer chain`,()=>this.#t.switchChain(i),this.#i);let a=this.#r;a&&await t.L(`credential wallet account change`,()=>a.handleWalletAccountChange(n,r),this.#i),n&&await t.L(`clear decrypt cache`,()=>this.#n.clearForRequester(n.address),this.#i),await Promise.all(Array.from(this.#a,n=>t.L(`wallet account listener`,()=>n(e),this.#i)))}};function N(e){return(0,l.keccak256)((0,l.toBytes)(e))}const P={ConfidentialTransfer:N(`ConfidentialTransfer(address,address,bytes32)`),Wrap:N(`Wrap(address,uint256,bytes32)`),UnwrapRequested:N(`UnwrapRequested(address,bytes32,bytes32)`),UnwrapFinalized:N(`UnwrapFinalized(address,bytes32,bytes32,uint64)`)};function F(e){return(0,l.getAddress)(T(e.slice(-40)))}function I(e){return e}function L(e,t){let n=2+t*64,r=e.slice(n,n+64);return r.length===64?r:r.padEnd(64,`0`)}function R(e,t){return(0,l.getAddress)(T(L(e,t).slice(-40)))}function z(e,t){return BigInt(`0x`+L(e,t))}function B(e,t){return T(L(e,t))}function V(e){return e.topics[0]!==P.ConfidentialTransfer||e.topics.length<4?null:{eventName:`ConfidentialTransfer`,from:F(e.topics[1]),to:F(e.topics[2]),encryptedAmount:I(e.topics[3])}}function H(e){return e.topics[0]!==P.Wrap||e.topics.length<2?null:{eventName:`Wrap`,to:F(e.topics[1]),roundedAmount:z(e.data,0),encryptedWrappedAmount:B(e.data,1)}}function U(e){return e.topics[0]!==P.UnwrapRequested||e.topics.length<3?null:{eventName:`UnwrapRequested`,receiver:F(e.topics[1]),unwrapRequestId:I(e.topics[2]),encryptedAmount:B(e.data,0)}}function W(e){return e.topics[0]!==P.UnwrapFinalized||e.topics.length<3?null:{eventName:`UnwrapFinalized`,receiver:F(e.topics[1]),unwrapRequestId:I(e.topics[2]),encryptedAmount:B(e.data,0),cleartextAmount:z(e.data,1)}}function G(e){return V(e)??H(e)??U(e)??W(e)}function ge(e){let t=[];for(let n of e){let e=G(n);e&&t.push(e)}return t}function K(e){for(let t of e){let e=U(t);if(e)return e}return null}function _e(e){for(let t of e){let e=H(t);if(e)return e}return null}const ve=[P.ConfidentialTransfer,P.Wrap,P.UnwrapRequested,P.UnwrapFinalized],q={DelegatedForUserDecryption:N(`DelegatedForUserDecryption(address,address,address,uint64,uint64,uint64)`),RevokedDelegationForUserDecryption:N(`RevokedDelegationForUserDecryption(address,address,address,uint64,uint64)`)};function J(e){return e.topics[0]!==q.DelegatedForUserDecryption||e.topics.length<3?null:{eventName:`DelegatedForUserDecryption`,delegator:F(e.topics[1]),delegate:F(e.topics[2]),contractAddress:R(e.data,0),delegationCounter:z(e.data,1),oldExpirationDate:z(e.data,2),newExpirationDate:z(e.data,3)}}function Y(e){return e.topics[0]!==q.RevokedDelegationForUserDecryption||e.topics.length<3?null:{eventName:`RevokedDelegationForUserDecryption`,delegator:F(e.topics[1]),delegate:F(e.topics[2]),contractAddress:R(e.data,0),delegationCounter:z(e.data,1),oldExpirationDate:z(e.data,2)}}function X(e){return J(e)??Y(e)}function ye(e){let t=[];for(let n of e){let e=X(n);e&&t.push(e)}return t}function be(e){for(let t of e){let e=J(t);if(e)return e}return null}function xe(e){for(let t of e){let e=Y(t);if(e)return e}return null}const Se=[q.DelegatedForUserDecryption,q.RevokedDelegationForUserDecryption];var Z=class extends r.t{#e;#t=null;#n=null;#r(e){try{return i.r(this.sdk.signer,`WrappedToken.sdk.signer`),this.sdk.signer}catch(n){throw new t.R(e,{cause:n})}}async underlying(){return this.#o()}async isPayable(){if(this.#n!==null)return this.#n;try{let e=await this.#o();this.#n=await this.sdk.provider.readContract(t.p(e))}catch{this.#n=!1}return this.#n}async allowance(e){let n=await this.#o();return this.sdk.provider.readContract(t.h(n,(0,l.getAddress)(e),this.address))}async shield(n,a){let o=await r.s(`shield`,this.sdk.signer,this.sdk.provider),s=await this.isPayable(),c=await this.#o(),u=(0,l.getAddress)(o.address),d;try{d=await this.sdk.provider.readContract(t._(c,u))}catch(t){throw t instanceof e.r?t:new r.g(`Could not read ERC-20 balance for shield validation (token: ${c})`,{cause:i.c(t)})}if(d<n)throw new r.v(`Insufficient ERC-20 balance: requested ${n}, available ${d} (token: ${c})`,{requested:n,available:d,token:c});return s?this.#i(n,c,u,a):this.#a(n,u,a)}async#i(e,t,n,r){this.#r(`shield`);let i=r?.to?(0,l.getAddress)(r.to):n,a=i===n?`0x`:i;return this.submitTransaction({operation:`shield:transferAndCall`,config:E(t,this.address,e,a),onSubmitted:r?.onShieldSubmitted})}async#a(e,n,r){this.#r(`shield`);let i=r?.approvalStrategy??`exact`;i!==`skip`&&await this.#c(e,i===`max`,r);let a=r?.to?(0,l.getAddress)(r.to):n;return this.submitTransaction({operation:`shield:approveAndWrap`,config:t.I(this.address,a,e),onSubmitted:r?.onShieldSubmitted})}async approveUnderlying(e){this.#r(`approveUnderlying`);let n=await r.s(`approveUnderlying`,this.sdk.signer,this.sdk.provider),i=await this.#o(),a=(0,l.getAddress)(n.address),o=e??2n**256n-1n;return o>0n&&await this.sdk.provider.readContract(t.h(i,a,this.address))>0n&&await this.submitTransaction({operation:`approveUnderlying:reset`,config:t.g(i,this.address,0n)}),this.submitTransaction({operation:`approveUnderlying`,config:t.g(i,this.address,o)})}async unshield(e,n){let{skipBalanceCheck:r=!1,onUnwrapSubmitted:i,onFinalizing:a,onFinalizeSubmitted:o}=n??{};r||await this.assertConfidentialBalance(e);let s={onFinalizing:a,onFinalizeSubmitted:o},c=crypto.randomUUID(),l=await this.unwrap(e);return t.L(`unshield: onUnwrapSubmitted`,()=>i?.(l.txHash),this.sdk.logger),this.#s(l.txHash,c,s)}async unshieldAll(e){let n=crypto.randomUUID(),r=await this.unwrapAll();return t.L(`unshieldAll: onUnwrapSubmitted`,()=>e?.onUnwrapSubmitted?.(r.txHash),this.sdk.logger),this.#s(r.txHash,n,e)}async resumeUnshield(e,t){return this.#s(e,crypto.randomUUID(),t)}async unwrap(e){this.#r(`unwrap`);let i=(0,l.getAddress)((await r.s(`unwrap`,this.sdk.signer,this.sdk.provider)).address),{encryptedValues:a,inputProof:o}=await this.sdk.encrypt({values:[{value:e,type:`euint64`}],contractAddress:this.address,userAddress:i}),[s]=a;if(!s)throw new n.n(`Encryption returned no encrypted values`);return this.submitTransaction({operation:`unwrap`,config:t.P(this.address,i,i,s,o)})}async unwrapAll(){this.#r(`unwrapAll`);let e=(0,l.getAddress)((await r.s(`unwrapAll`,this.sdk.signer,this.sdk.provider)).address),i=await this.readConfidentialBalanceOf(e);if(r.i(i))throw new n.t(`Cannot unshield: balance is zero`);return this.submitTransaction({operation:`unwrapAll`,config:t.F(this.address,e,e,i)})}async finalizeUnwrap(e){this.#r(`finalizeUnwrap`),await r.c(`finalizeUnwrap`,this.sdk.signer,this.sdk.provider);let n=await this.sdk.decryption.decryptPublicValues([e]),a=n.clearValues[e];return i.t(a,`finalizeUnwrap: clearValue`),this.submitTransaction({operation:`finalizeUnwrap`,config:t.O(this.address,e,a,n.decryptionProof)})}async#o(){return this.#e===void 0?(this.#t||=this.sdk.provider.readContract(t.N(this.address)).then(e=>(this.#e=e,this.#t=null,e)).catch(e=>{throw this.#t=null,e}),this.#t):this.#e}async#s(n,i,a){this.emit({type:r.o.UnshieldPhase1Submitted,txHash:n,operationId:i});let o;try{o=await this.sdk.provider.waitForTransactionReceipt(n)}catch(t){throw t instanceof e.r?t:new r.b(`Failed to get unshield receipt`,{cause:t})}let s=K(o.logs);if(!s)throw new r.b(`No UnwrapRequested event found in unshield receipt`);this.emit({type:r.o.UnshieldPhase2Started,operationId:i}),t.L(`unshield: onFinalizing`,()=>a?.onFinalizing?.(),this.sdk.logger);let c=await this.finalizeUnwrap(s.unwrapRequestId??s.encryptedAmount);return this.emit({type:r.o.UnshieldPhase2Submitted,txHash:c.txHash,operationId:i}),t.L(`unshield: onFinalizeSubmitted`,()=>a?.onFinalizeSubmitted?.(c.txHash),this.sdk.logger),c}async#c(e,n,i){this.#r(`approveUnderlying`);let a=await this.#o(),o=(0,l.getAddress)((await r.s(`approveUnderlying`,this.sdk.signer,this.sdk.provider)).address),s=await this.sdk.provider.readContract(t.h(a,o,this.address));if(s>=e)return;s>0n&&await this.submitTransaction({operation:`approveUnderlying:reset`,config:t.g(a,this.address,0n)});let c=n?2n**256n-1n:e;await this.submitTransaction({operation:`approveUnderlying`,config:t.g(a,this.address,c),onSubmitted:i?.onApprovalSubmitted})}},Ce=class{relayer;provider;signer;storage;registry;permits;delegations;decryption;#e;#t;#n;#r;#i;#a;#o;#s;#c;constructor(e){this.relayer=e.relayer,this.provider=e.provider,this.signer=e.signer,this.storage=e.storage,this.#t=e.onEvent??function(){},this.#n=e.logger,this.#r=new oe(e.storage,this.#n),this.#c=new pe({provider:this.provider,relayer:this.relayer,emitEvent:this.emitEvent.bind(this),logger:this.#n});let t={};for(let n of e.chains)n.registryAddress&&(t[n.id]=n.registryAddress);this.registry=new o.o({provider:this.provider,registryAddresses:t,registryTTL:e.registryTTL}),this.#e=e.registryTTL,e.signer&&(this.#s=new o.d({relayer:this.relayer,signer:e.signer,transportKeyPairTTL:e.transportKeyPairTTL,permitTTL:e.permitTTL,storage:this.storage,permitStorage:e.permitStorage,logger:this.#n}),this.#o=new le({cache:this.#r,credentialService:this.#s,delegationService:this.#c,relayer:this.relayer,emitEvent:this.emitEvent.bind(this)})),this.#a=new me({relayer:this.relayer,emitEvent:this.emitEvent.bind(this)}),this.#i=new he({signer:e.signer,relayer:this.relayer,cachingService:this.#r,credentialService:this.#s,logger:this.#n}),this.permits=new k({signer:this.signer,provider:this.provider,cachingService:this.#r,credentialService:this.#s,logger:this.#n}),this.delegations=new O({signer:this.signer,provider:this.provider,delegationService:this.#c}),this.decryption=new D({signer:this.signer,provider:this.provider,relayer:this.relayer,decryptionService:this.#o})}onWalletAccountChange(e){return this.#i.onWalletAccountChange(e)}get logger(){return this.#n}emitEvent(e,t){try{this.#t({...e,tokenAddress:t,timestamp:Date.now()})}catch(t){this.#n.warn(`${e.type} event listener silently failed`,{error:t})}}createWrappersRegistry(e){return new o.o({provider:this.provider,registryAddresses:e,registryTTL:this.#e})}async encrypt(e){return this.#a.encrypt(e)}createToken(e){return new r.t(this,e)}createWrappedToken(e){return new Z(this,e)}dispose(){this.#i.dispose()}terminate(){this.dispose(),this.relayer.terminate(),this.signer?.dispose?.()}[Symbol.dispose](){this.terminate()}};function Q(e){return`zama:pending-unshield:${o.f(e)}`}const we=u.z.union([u.z.pipe(o.m,u.z.transform(e=>({unwrapTxHash:e}))),u.z.pipe(u.z.object({version:u.z.literal(1),unwrapTxHash:o.m,unwrapRequestId:u.z.optional(o.m)}),u.z.transform(({unwrapTxHash:e,unwrapRequestId:t})=>({unwrapTxHash:e,unwrapRequestId:t})))]);async function Te(e,t,n,r){if(r===void 0){await e.set(Q(t),n);return}await e.set(Q(t),{version:1,unwrapTxHash:n,unwrapRequestId:r})}async function Ee(e,t){return(await $(e,t))?.unwrapTxHash??null}async function $(e,t){let n=Q(t),r=await e.get(n);if(r==null)return null;let i=we.safeParse(r);return i.success?i.data:(await e.delete(n),null)}async function De(e,t){await e.delete(Q(t))}var Oe=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 ke=new Oe;exports.ACL_TOPICS=Se,exports.AclPausedError=x,exports.AclTopics=q,exports.BalanceCheckUnavailableError=r.h,exports.BaseSigner=o.t,exports.ChainMismatchError=r.y,exports.ChromeSessionStorage=Oe,exports.ConfigurationError=e.t,exports.Decryption=D,exports.DecryptionFailedError=n.t,exports.DefaultRegistryAddresses=o.a,exports.DelegationContractIsSelfError=b,exports.DelegationCooldownError=h,exports.DelegationDelegateEqualsContractError=y,exports.DelegationExpirationTooSoonError=S,exports.DelegationExpiredError=_,exports.DelegationExpiryUnchangedError=v,exports.DelegationNotFoundError=g,exports.DelegationNotPropagatedError=C,exports.DelegationSelfNotAllowedError=m,exports.Delegations=O,exports.ERC1363_INTERFACE_ID=t.c,exports.ERC20ReadFailedError=r.g,exports.ERC7984_INTERFACE_ID=t.l,exports.ERC7984_WRAPPER_INTERFACE_ID=t.u,exports.EncryptionFailedError=n.n,exports.IndexedDBStorage=s.n,exports.InsufficientConfidentialBalanceError=r._,exports.InsufficientERC20BalanceError=r.v,exports.InvalidTransportKeyPairError=f,exports.MemoryStorage=o.l,exports.MutableWalletAccountStore=o.n,exports.NoCiphertextError=p,exports.Permits=k,exports.RelayerRequestFailedError=e.n,exports.SignerNotConfiguredError=t.R,exports.SignerRequiredError=t.z,exports.SigningFailedError=t.U,exports.SigningRejectedError=t.W,exports.TOKEN_TOPICS=ve,exports.Token=r.t,exports.Topics=P,exports.TransactionRevertedError=r.b,exports.TransportKeyPairExpiredError=d,exports.WalletAccountNotReadyError=t.B,exports.WalletNotConnectedError=t.V,exports.WrappedToken=Z,exports.WrappersRegistry=o.o,exports.ZERO_ENCRYPTED_VALUE=r.r,exports.ZamaError=e.r,exports.ZamaErrorCode=e.i,exports.ZamaSDK=Ce,exports.ZamaSDKEvents=r.o,exports.allowanceContract=t.h,exports.anvil=c.t,exports.approveContract=t.g,exports.balanceOfContract=t._,exports.bscTestnet=c.n,exports.chains=c.r,exports.chromeSessionStorage=ke,exports.clearPendingUnshield=De,exports.cleartext=te,exports.confidentialBalanceOfContract=t.S,exports.confidentialTotalSupplyContract=t.C,exports.confidentialTransferContract=t.T,exports.confidentialTransferFromContract=t.D,exports.createConfig=re,exports.createWalletAccountStore=o.r,exports.decimalsContract=t.v,exports.decodeAclEvent=X,exports.decodeAclEvents=ye,exports.decodeConfidentialTransfer=V,exports.decodeDelegatedForUserDecryption=J,exports.decodeOnChainEvent=G,exports.decodeOnChainEvents=ge,exports.decodeRevokedDelegationForUserDecryption=Y,exports.decodeUnwrapFinalized=W,exports.decodeUnwrapRequested=U,exports.decodeWrap=H,exports.delegateForUserDecryptionContract=r.u,exports.finalizeUnwrapContract=t.O,exports.findDelegatedForUserDecryption=be,exports.findRevokedDelegationForUserDecryption=xe,exports.findUnwrapRequested=K,exports.findWrap=_e,exports.getConfidentialTokenAddressContract=t.t,exports.getDelegationExpiryContract=r.d,exports.getTokenAddressContract=t.n,exports.getTokenPairContract=t.r,exports.getTokenPairsContract=t.i,exports.getTokenPairsLengthContract=t.a,exports.getTokenPairsSliceContract=t.o,exports.hardhat=c.i,exports.hoodi=c.a,exports.indexedDBStorage=s.r,exports.inferredTotalSupplyContract=t.k,exports.ingenTestnet=c.o,exports.isConfidentialTokenContract=t.d,exports.isConfidentialTokenValidContract=t.s,exports.isConfidentialWrapperContract=t.f,exports.isEncryptedValueZero=r.i,exports.isHandleDelegatedContract=r.f,exports.isOperatorContract=t.A,exports.loadPendingUnshield=Ee,exports.loadPendingUnshieldRequest=$,exports.mainnet=c.s,exports.matchZamaError=e.a,exports.memoryStorage=o.u,exports.nameContract=t.b,exports.rateContract=t.j,exports.resolveChainRelayers=o.s,exports.resolveStorage=o.c,exports.revokeDelegationContract=r.p,exports.savePendingUnshield=Te,exports.sepolia=c.c,exports.setOperatorContract=t.M,exports.supportsInterfaceContract=t.m,exports.symbolContract=t.x,exports.transferAndCallContract=E,exports.underlyingContract=t.N,exports.unwrapContract=t.P,exports.unwrapFromBalanceContract=t.F,exports.wrapContract=t.I;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/cjs/query/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../wrappers-registry.cjs"),t=require("../token.cjs"),n=require("../assertions.cjs");let r=require("viem"),i=require("zod/mini");function a(e){if(!o(e))return!1;let t=e.constructor;if(t===void 0)return!0;let n=t.prototype;return!(!o(n)||!n.hasOwnProperty(`isPrototypeOf`))}function o(e){return Object.prototype.toString.call(e)===`[object Object]`}function s(e){let{gcTime:t,staleTime:n,enabled:r,select:i,refetchInterval:a,refetchOnMount:o,refetchOnWindowFocus:s,refetchOnReconnect:c,retry:l,retryDelay:u,retryOnMount:d,queryFn:f,queryKey:p,queryKeyHashFn:m,initialData:h,initialDataUpdatedAt:g,placeholderData:_,structuralSharing:ee,throwOnError:v,meta:y,query:b,pollingInterval:x,...S}=e;return S}function c(e){return JSON.stringify(e,(e,t)=>a(t)?Object.keys(t).toSorted().reduce((e,n)=>(e[n]=t[n],e),{}):typeof t==`bigint`?t.toString():t)}const l=e=>e.map(e=>(0,r.getAddress)(e)),u=e=>e===void 0?void 0:(0,r.getAddress)(e),d=e=>e?{walletAddress:(0,r.getAddress)(e.address),walletChainId:e.chainId}:{},f={confidentialBalance:{all:[`zama.confidentialBalance`],token:e=>[`zama.confidentialBalance`,{tokenAddress:(0,r.getAddress)(e)}],owner:(e,t,n)=>[`zama.confidentialBalance`,{tokenAddress:(0,r.getAddress)(e),...d(n),...t?{owner:(0,r.getAddress)(t)}:{}}]},confidentialBalances:{all:[`zama.confidentialBalances`],tokens:(e,t,n)=>[`zama.confidentialBalances`,{tokenAddresses:l(e),...d(n),...t?{owner:(0,r.getAddress)(t)}:{}}]},tokenMetadata:{all:[`zama.tokenMetadata`],token:e=>[`zama.tokenMetadata`,{tokenAddress:(0,r.getAddress)(e)}]},isConfidential:{all:[`zama.isConfidential`],token:e=>[`zama.isConfidential`,{tokenAddress:(0,r.getAddress)(e)}]},isWrapper:{all:[`zama.isWrapper`],token:e=>[`zama.isWrapper`,{tokenAddress:(0,r.getAddress)(e)}]},wrapperDiscovery:{all:[`zama.wrapperDiscovery`],token:(e,t,n)=>{let r=u(e),i=u(t),a=u(n);return[`zama.wrapperDiscovery`,{...r?{tokenAddress:r}:{},...i?{erc20Address:i}:{},...a?{registryAddress:a}:{}}]}},underlyingAllowance:{all:[`zama.underlyingAllowance`],token:e=>[`zama.underlyingAllowance`,{tokenAddress:(0,r.getAddress)(e)}],scope:(e,t)=>[`zama.underlyingAllowance`,{tokenAddress:(0,r.getAddress)(e),...t?{owner:(0,r.getAddress)(t)}:{}}]},confidentialIsOperator:{all:[`zama.confidentialIsOperator`],token:e=>{let t=u(e);return[`zama.confidentialIsOperator`,t?{tokenAddress:t}:{}]},scope:(e,t,n)=>{let r=u(e),i=u(t),a=u(n);return[`zama.confidentialIsOperator`,{...r?{tokenAddress:r}:{},...i?{holder:i}:{},...a?{spender:a}:{}}]}},totalSupply:{all:[`zama.totalSupply`],token:e=>[`zama.totalSupply`,{tokenAddress:(0,r.getAddress)(e)}]},hasPermit:{all:[`zama.hasPermit`],scope:(e,t)=>[`zama.hasPermit`,{...d(t),contractAddresses:l(e).toSorted()}]},delegationStatus:{all:[`zama.delegationStatus`],contract:e=>{let t=u(e);return[`zama.delegationStatus`,t?{contractAddress:t}:{}]},scope:(e,t,n)=>{let r=u(e),i=u(t),a=u(n);return[`zama.delegationStatus`,{...r?{contractAddress:r}:{},...i?{delegatorAddress:i}:{},...a?{delegateAddress:a}:{}}]}},decryption:{all:[`zama.decryption`],encryptedValue:(e,t)=>[`zama.decryption`,{encryptedValue:e,...t===void 0?{}:{contractAddress:(0,r.getAddress)(t)}}],encryptedInputs:(e,t)=>[`zama.decryption`,{...d(t),encryptedInputs:[...e].toSorted((e,t)=>e.encryptedValue.localeCompare(t.encryptedValue)).map(e=>({encryptedValue:e.encryptedValue,contractAddress:(0,r.getAddress)(e.contractAddress)}))}]},wrappersRegistry:{all:[`zama.wrappersRegistry`],chainId:()=>[`zama.wrappersRegistry`,{type:`chainId`}],tokenPairs:e=>[`zama.wrappersRegistry`,{type:`tokenPairs`,registryAddress:(0,r.getAddress)(e)}],confidentialTokenAddress:(e,t)=>[`zama.wrappersRegistry`,{type:`confidentialTokenAddress`,registryAddress:(0,r.getAddress)(e),tokenAddress:(0,r.getAddress)(t)}],tokenAddress:(e,t)=>[`zama.wrappersRegistry`,{type:`tokenAddress`,registryAddress:(0,r.getAddress)(e),confidentialTokenAddress:(0,r.getAddress)(t)}],tokenPairsLength:e=>[`zama.wrappersRegistry`,{type:`tokenPairsLength`,registryAddress:(0,r.getAddress)(e)}],tokenPairsSlice:(e,t,n)=>[`zama.wrappersRegistry`,{type:`tokenPairsSlice`,registryAddress:(0,r.getAddress)(e),fromIndex:t,toIndex:n}],tokenPair:(e,t)=>[`zama.wrappersRegistry`,{type:`tokenPair`,registryAddress:(0,r.getAddress)(e),index:t}],isConfidentialTokenValid:(e,t)=>[`zama.wrappersRegistry`,{type:`isConfidentialTokenValid`,registryAddress:(0,r.getAddress)(e),confidentialTokenAddress:(0,r.getAddress)(t)}],listPairs:(e,t,n,i)=>[`zama.wrappersRegistry`,{type:`listPairs`,registryAddress:(0,r.getAddress)(e),page:t,pageSize:n,metadata:i}]}};function p(e,t){e.invalidateQueries({queryKey:f.underlyingAllowance.token(t)})}function m(e,t){h(e,t),p(e,t),E(e)}function h(e,t){e.invalidateQueries({queryKey:f.confidentialBalance.token(t)}),e.invalidateQueries({queryKey:f.confidentialBalances.all})}function g(e,t){h(e,t),p(e,t),E(e)}function _(e,t){h(e,t),p(e,t),E(e)}function ee(e,t){h(e,t)}function v(e,t){p(e,t)}function y(e,t){e.invalidateQueries({queryKey:f.confidentialIsOperator.token(t)})}function b(e){return Array.isArray(e.queryKey)&&typeof e.queryKey[0]==`string`?e.queryKey[0].startsWith(`zama.`):!1}const x=i.z.enum([`balanceOf`,`confidentialBalanceOf`]),S=i.z.object({functionName:x}),C=i.z.object({contracts:i.z.array(i.z.unknown())});function w(e){if(S.safeParse(e).success)return!0;let t=C.safeParse(e);return t.success&&t.data.contracts.some(e=>S.safeParse(e).success)}function T(e){return Array.isArray(e.queryKey)&&e.queryKey.some(w)}function E(e){e.invalidateQueries({predicate:T})}function D(e){e.removeQueries({queryKey:f.decryption.all}),e.removeQueries({queryKey:f.hasPermit.all}),e.invalidateQueries({predicate:b}),E(e)}function O(t,n,r){let i=f.tokenMetadata.token(n);return{...s(r?.query??{}),queryKey:i,queryFn:async n=>{let[,{tokenAddress:r}]=n.queryKey,[i,a,o]=await Promise.all([t.provider.readContract(e.b(r)),t.provider.readContract(e.x(r)),t.provider.readContract(e.v(r))]);return{name:i,symbol:a,decimals:o}},staleTime:1/0,enabled:r?.query?.enabled!==!1}}function k(t,r,i){let a=f.isConfidential.token(r);return{...s(i?.query??{}),queryKey:a,queryFn:async r=>{let[,{tokenAddress:i}]=r.queryKey;try{return await t.provider.readContract(e.d(i))}catch(e){if(n.s(e))return!1;throw e}},staleTime:1/0,enabled:i?.query?.enabled!==!1}}function A(t,r,i){let a=f.isWrapper.token(r);return{...s(i?.query??{}),queryKey:a,queryFn:async r=>{let[,{tokenAddress:i}]=r.queryKey;try{return await t.provider.readContract(e.f(i))}catch(e){if(n.s(e))return!1;throw e}},staleTime:1/0,enabled:i?.query?.enabled!==!1}}function j(t,n,r){let i=f.totalSupply.token(n);return{...s(r?.query??{}),queryKey:i,queryFn:async n=>{let[,{tokenAddress:r}]=n.queryKey;return t.provider.readContract(e.D(r))},staleTime:3e4,enabled:r?.query?.enabled!==!1}}function M(e,t){let r=f.wrapperDiscovery.token(t.tokenAddress,t.erc20Address,t.registryAddress);return{...s(t.query??{}),queryKey:r,queryFn:async t=>{let[,{erc20Address:r}]=t.queryKey;n.r(r,`wrapperDiscoveryQueryOptions: erc20Address`);let i=await e.getConfidentialToken(r);return i?i.confidentialTokenAddress:null},staleTime:1/0,enabled:!!(t.tokenAddress&&t.erc20Address&&t.registryAddress)&&t.query?.enabled!==!1}}function N(t,r,i){let a=i.owner,o=i.query?.enabled!==!1,c=f.underlyingAllowance.scope(r,a);return{...s(i.query??{}),queryKey:c,queryFn:async r=>{let[,{tokenAddress:i,owner:a}]=r.queryKey;n.r(a,`underlyingAllowanceQueryOptions: owner`);let o=await t.provider.readContract(e.j(i));return t.provider.readContract(e.h(o,a,i))},staleTime:3e4,enabled:!!a&&o}}function P(t,r,i){let a=i.holder,o=i.spender,c=i.query?.enabled!==!1,l=f.confidentialIsOperator.scope(r,a,o);return{...s(i.query??{}),queryKey:l,queryFn:async r=>{let[,{tokenAddress:i,holder:a,spender:o}]=r.queryKey;return n.r(i,`confidentialIsOperatorQueryOptions: tokenAddress`),n.r(a,`confidentialIsOperatorQueryOptions: holder`),n.r(o,`confidentialIsOperatorQueryOptions: spender`),t.provider.readContract(e.O(i,a,o))},staleTime:3e4,enabled:!!(r&&a&&o)&&c}}function F(e,t,r={}){let i=t.query??{};return{...s(i),queryKey:f.confidentialBalance.owner(t.tokenAddress,t.account,r.walletAccount),queryFn:async t=>{let[,{owner:r}]=t.queryKey;return n.r(r,`confidentialBalanceQueryOptions: owner`),e.balanceOf(r)},enabled:!!t.account&&r.walletAccount!==void 0&&i?.enabled!==!1}}function I(e,r,i={}){let a=r?.account,o=i.walletAccount,c=r?.query??{},l=e.map(e=>e.address);return{...s(c),queryKey:f.confidentialBalances.tokens(l,a,o),queryFn:async r=>{let[,{owner:i}]=r.queryKey;return n.r(i,`confidentialBalancesQueryOptions: owner`),t.t.batchBalancesOf(e,i)},enabled:!!a&&e.length>0&&o!==void 0&&c?.enabled!==!1}}const L=86400*1e3;function R(t,n){let i=!!n.registryAddress&&n.query?.enabled!==!1,a=f.wrappersRegistry.tokenPairs(n.registryAddress??r.zeroAddress);return{...s(n.query??{}),queryKey:a,queryFn:async n=>{let[,{registryAddress:r}]=n.queryKey;return t.provider.readContract(e.i(r))},staleTime:L,enabled:i}}function z(t,n){let i=!!n.registryAddress&&!!n.tokenAddress&&n.query?.enabled!==!1,a=f.wrappersRegistry.confidentialTokenAddress(n.registryAddress??r.zeroAddress,n.tokenAddress??r.zeroAddress);return{...s(n.query??{}),queryKey:a,queryFn:async n=>{let[,{registryAddress:r,tokenAddress:i}]=n.queryKey;return t.provider.readContract(e.t(r,i))},staleTime:L,enabled:i}}function B(t,n){let i=!!n.registryAddress&&!!n.confidentialTokenAddress&&n.query?.enabled!==!1,a=f.wrappersRegistry.tokenAddress(n.registryAddress??r.zeroAddress,n.confidentialTokenAddress??r.zeroAddress);return{...s(n.query??{}),queryKey:a,queryFn:async n=>{let[,{registryAddress:r,confidentialTokenAddress:i}]=n.queryKey;return t.provider.readContract(e.n(r,i))},staleTime:L,enabled:i}}function V(t,n){let i=!!n.registryAddress&&n.query?.enabled!==!1,a=f.wrappersRegistry.tokenPairsLength(n.registryAddress??r.zeroAddress);return{...s(n.query??{}),queryKey:a,queryFn:async n=>{let[,{registryAddress:r}]=n.queryKey;return t.provider.readContract(e.a(r))},staleTime:L,enabled:i}}function te(t,n){let i=!!n.registryAddress&&n.fromIndex!==void 0&&n.toIndex!==void 0&&n.query?.enabled!==!1,a=f.wrappersRegistry.tokenPairsSlice(n.registryAddress??r.zeroAddress,String(n.fromIndex??0n),String(n.toIndex??0n));return{...s(n.query??{}),queryKey:a,queryFn:async n=>{let[,{registryAddress:r,fromIndex:i,toIndex:a}]=n.queryKey;return t.provider.readContract(e.o(r,BigInt(i),BigInt(a)))},staleTime:L,enabled:i}}function H(t,n){let i=!!n.registryAddress&&n.index!==void 0&&n.query?.enabled!==!1,a=f.wrappersRegistry.tokenPair(n.registryAddress??r.zeroAddress,String(n.index??0n));return{...s(n.query??{}),queryKey:a,queryFn:async n=>{let[,{registryAddress:r,index:i}]=n.queryKey;return t.provider.readContract(e.r(r,BigInt(i)))},staleTime:L,enabled:i}}function U(t,n){let i=!!n.registryAddress&&!!n.confidentialTokenAddress&&n.query?.enabled!==!1,a=f.wrappersRegistry.isConfidentialTokenValid(n.registryAddress??r.zeroAddress,n.confidentialTokenAddress??r.zeroAddress);return{...s(n.query??{}),queryKey:a,queryFn:async n=>{let[,{registryAddress:r,confidentialTokenAddress:i}]=n.queryKey;return t.provider.readContract(e.s(r,i))},staleTime:L,enabled:i}}function W(e,t){let n=!!t.registryAddress&&t.query?.enabled!==!1,i=f.wrappersRegistry.listPairs(t.registryAddress??r.zeroAddress,t.page??1,t.pageSize??100,t.metadata??!1);return{...s(t.query??{}),queryKey:i,queryFn:async t=>{let[,{page:n,pageSize:r,metadata:i}]=t.queryKey;return e.listPairs({page:n,pageSize:r,metadata:i})},staleTime:e.ttlMs,enabled:n}}function G(e){return{mutationKey:[`zama.shield`,e.address],mutationFn:async({amount:t,...n})=>e.shield(t,n)}}function K(e){return{mutationKey:[`zama.confidentialTransfer`,e.address],mutationFn:async({to:t,amount:n,...r})=>e.confidentialTransfer(t,n,r)}}function q(e){return{mutationKey:[`zama.confidentialTransferFrom`,e.address],mutationFn:async({from:t,to:n,amount:r,callbacks:i})=>e.confidentialTransferFrom(t,n,r,i)}}function J(e){return{mutationKey:[`zama.confidentialSetOperator`,e.address],mutationFn:async({operator:t,until:n})=>e.setOperator(t,n)}}function Y(e){return{mutationKey:[`zama.approveUnderlying`,e.address],mutationFn:async({amount:t})=>e.approveUnderlying(t)}}function X(e){return{mutationKey:[`zama.unshield`,e.address],mutationFn:async({amount:t,...n})=>e.unshield(t,n)}}function Z(e){return{mutationKey:[`zama.unshieldAll`,e.address],mutationFn:async t=>e.unshieldAll(t||void 0)}}function Q(e){return{mutationKey:[`zama.resumeUnshield`,e.address],mutationFn:async({unwrapTxHash:t,...n})=>e.resumeUnshield(t,n)}}function ne(e){return{mutationKey:[`zama.unwrap`,e.address],mutationFn:async({amount:t})=>e.unwrap(t)}}function re(e){return{mutationKey:[`zama.unwrapAll`,e.address],mutationFn:async()=>e.unwrapAll()}}function ie(e){return{mutationKey:[`zama.finalizeUnwrap`,e.address],mutationFn:async({unwrapRequestId:t})=>e.finalizeUnwrap(t)}}function ae(e){return{mutationKey:[`zama.encrypt`],mutationFn:async t=>e.encrypt(t)}}function oe(e){return{mutationKey:[`zama.delegatedDecryptValues`],mutationFn:async t=>e.decryption.delegatedDecryptValues(t.encryptedInputs,t.delegatorAddress)}}function $(e){return{mutationKey:[`zama.decryptPublicValues`],mutationFn:async t=>e.decryption.decryptPublicValues(t),onSuccess:(e,t,n,r)=>{for(let[t,n]of Object.entries(e.clearValues))r.client.setQueryData(f.decryption.encryptedValue(t),n)}}}function se(e){return{mutationKey:[`zama.grantPermit`],mutationFn:t=>e.permits.grantPermit(t)}}function ce(e,t,n={}){let r=t.query?.enabled!==!1;return{...s(t?.query??{}),queryKey:f.hasPermit.scope(t.contractAddresses,n.walletAccount),queryFn:t=>{let[,{contractAddresses:n}]=t.queryKey;return e.permits.hasPermit(n)},staleTime:0,gcTime:0,refetchOnMount:`always`,refetchOnWindowFocus:!1,enabled:r&&n.walletAccount!==void 0&&t.contractAddresses.length>0}}function le(e){return{mutationKey:[`zama.revokePermits`],mutationFn:t=>t===void 0?e.permits.revokePermits():e.permits.revokePermits(t)}}function ue(e){return{mutationKey:[`zama.clearCredentials`],mutationFn:()=>e.permits.clear()}}function de(e,t){return{mutationKey:[`zama.delegateDecryption`,t],mutationFn:async({delegateAddress:n,expirationDate:r})=>e.delegations.delegateDecryption({contractAddress:t,delegateAddress:n,expirationDate:r})}}function fe(e,t,n={}){return{queryKey:f.decryption.encryptedInputs(t,n.walletAccount),queryFn:t=>{let[,{encryptedInputs:n}]=t.queryKey;return e.decryption.decryptValues(n)},staleTime:1/0,enabled:t.length>0&&n.walletAccount!==void 0}}function pe(e){return{mutationKey:[`zama.decryptBalanceAs`,e.address],mutationFn:async({delegatorAddress:t,accountAddress:n})=>e.decryptBalanceAs({delegatorAddress:t,accountAddress:n})}}function me(e){return{mutationKey:[`zama.batchDecryptBalancesAs`,...e.map(e=>e.address)],mutationFn:async n=>t.t.batchDecryptBalancesAs(e,n)}}function he(e,t){return{mutationKey:[`zama.revokeDelegation`,t],mutationFn:async({delegateAddress:n})=>e.delegations.revokeDelegation({contractAddress:t,delegateAddress:n})}}function ge(e,r){return{...s(r.query??{}),queryKey:f.delegationStatus.scope(r.contractAddress,r.delegatorAddress,r.delegateAddress),queryFn:async r=>{let[,{contractAddress:i,delegatorAddress:a,delegateAddress:o}]=r.queryKey;n.r(i,`delegationStatusQueryOptions: contractAddress`),n.r(a,`delegationStatusQueryOptions: delegatorAddress`),n.r(o,`delegationStatusQueryOptions: delegateAddress`);let s=await e.relayer.getAclAddress(),c=await e.provider.readContract(t.d(s,a,o,i)),l;return l=c===0n?!1:c===t.l?!0:c>await e.provider.getBlockTimestamp(),{isActive:l,expiryTimestamp:c}},enabled:!!(r.contractAddress&&r.delegatorAddress&&r.delegateAddress)&&r.query?.enabled!==!1}}exports.ZamaSDKEvents=t.o,exports.approveUnderlyingMutationOptions=Y,exports.batchDecryptBalancesAsMutationOptions=me,exports.clearCredentialsMutationOptions=ue,exports.confidentialBalanceQueryOptions=F,exports.confidentialBalancesQueryOptions=I,exports.confidentialIsOperatorQueryOptions=P,exports.confidentialSetOperatorMutationOptions=J,exports.confidentialTokenAddressQueryOptions=z,exports.confidentialTransferFromMutationOptions=q,exports.confidentialTransferMutationOptions=K,exports.decryptBalanceAsMutationOptions=pe,exports.decryptPublicValuesMutationOptions=$,exports.decryptValuesQueryOptions=fe,exports.delegateDecryptionMutationOptions=de,exports.delegatedDecryptValuesMutationOptions=oe,exports.delegationStatusQueryOptions=ge,exports.encryptMutationOptions=ae,exports.filterQueryOptions=s,exports.finalizeUnwrapMutationOptions=ie,exports.grantPermitMutationOptions=se,exports.hasPermitQueryOptions=ce,exports.hashFn=c,exports.invalidateAfterApproveUnderlying=v,exports.invalidateAfterSetOperator=y,exports.invalidateAfterShield=g,exports.invalidateAfterTransfer=ee,exports.invalidateAfterUnshield=_,exports.invalidateAfterUnwrap=m,exports.invalidateBalanceQueries=h,exports.invalidateWagmiBalanceQueries=E,exports.invalidateWalletLifecycleQueries=D,exports.isConfidentialQueryOptions=k,exports.isConfidentialTokenValidQueryOptions=U,exports.isWrapperQueryOptions=A,exports.listPairsQueryOptions=W,exports.resumeUnshieldMutationOptions=Q,exports.revokeDelegationMutationOptions=he,exports.revokePermitsMutationOptions=le,exports.shieldMutationOptions=G,exports.tokenAddressQueryOptions=B,exports.tokenMetadataQueryOptions=O,exports.tokenPairQueryOptions=H,exports.tokenPairsLengthQueryOptions=V,exports.tokenPairsQueryOptions=R,exports.tokenPairsSliceQueryOptions=te,exports.totalSupplyQueryOptions=j,exports.underlyingAllowanceQueryOptions=N,exports.unshieldAllMutationOptions=Z,exports.unshieldMutationOptions=X,exports.unwrapAllMutationOptions=re,exports.unwrapMutationOptions=ne,exports.wrapperDiscoveryQueryOptions=M,exports.zamaQueryKeys=f;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("../wrappers-registry.cjs"),t=require("../token.cjs"),n=require("../assertions.cjs");let r=require("viem"),i=require("zod/mini");function a(e){if(!o(e))return!1;let t=e.constructor;if(t===void 0)return!0;let n=t.prototype;return!(!o(n)||!n.hasOwnProperty(`isPrototypeOf`))}function o(e){return Object.prototype.toString.call(e)===`[object Object]`}function s(e){let{gcTime:t,staleTime:n,enabled:r,select:i,refetchInterval:a,refetchOnMount:o,refetchOnWindowFocus:s,refetchOnReconnect:c,retry:l,retryDelay:u,retryOnMount:d,queryFn:f,queryKey:p,queryKeyHashFn:m,initialData:h,initialDataUpdatedAt:g,placeholderData:_,structuralSharing:ee,throwOnError:v,meta:y,query:b,pollingInterval:x,...S}=e;return S}function c(e){return JSON.stringify(e,(e,t)=>a(t)?Object.keys(t).toSorted().reduce((e,n)=>(e[n]=t[n],e),{}):typeof t==`bigint`?t.toString():t)}const l=e=>e.map(e=>(0,r.getAddress)(e)),u=e=>e===void 0?void 0:(0,r.getAddress)(e),d=e=>e?{walletAddress:(0,r.getAddress)(e.address),walletChainId:e.chainId}:{},f={confidentialBalance:{all:[`zama.confidentialBalance`],token:e=>[`zama.confidentialBalance`,{tokenAddress:(0,r.getAddress)(e)}],owner:(e,t,n)=>[`zama.confidentialBalance`,{tokenAddress:(0,r.getAddress)(e),...d(n),...t?{owner:(0,r.getAddress)(t)}:{}}]},confidentialBalances:{all:[`zama.confidentialBalances`],tokens:(e,t,n)=>[`zama.confidentialBalances`,{tokenAddresses:l(e),...d(n),...t?{owner:(0,r.getAddress)(t)}:{}}]},tokenMetadata:{all:[`zama.tokenMetadata`],token:e=>[`zama.tokenMetadata`,{tokenAddress:(0,r.getAddress)(e)}]},isConfidential:{all:[`zama.isConfidential`],token:e=>[`zama.isConfidential`,{tokenAddress:(0,r.getAddress)(e)}]},isWrapper:{all:[`zama.isWrapper`],token:e=>[`zama.isWrapper`,{tokenAddress:(0,r.getAddress)(e)}]},wrapperDiscovery:{all:[`zama.wrapperDiscovery`],token:(e,t,n)=>{let r=u(e),i=u(t),a=u(n);return[`zama.wrapperDiscovery`,{...r?{tokenAddress:r}:{},...i?{erc20Address:i}:{},...a?{registryAddress:a}:{}}]}},underlyingAllowance:{all:[`zama.underlyingAllowance`],token:e=>[`zama.underlyingAllowance`,{tokenAddress:(0,r.getAddress)(e)}],scope:(e,t)=>[`zama.underlyingAllowance`,{tokenAddress:(0,r.getAddress)(e),...t?{owner:(0,r.getAddress)(t)}:{}}]},confidentialIsOperator:{all:[`zama.confidentialIsOperator`],token:e=>{let t=u(e);return[`zama.confidentialIsOperator`,t?{tokenAddress:t}:{}]},scope:(e,t,n)=>{let r=u(e),i=u(t),a=u(n);return[`zama.confidentialIsOperator`,{...r?{tokenAddress:r}:{},...i?{holder:i}:{},...a?{spender:a}:{}}]}},totalSupply:{all:[`zama.totalSupply`],token:e=>[`zama.totalSupply`,{tokenAddress:(0,r.getAddress)(e)}]},hasPermit:{all:[`zama.hasPermit`],scope:(e,t)=>[`zama.hasPermit`,{...d(t),contractAddresses:l(e).toSorted()}]},delegationStatus:{all:[`zama.delegationStatus`],contract:e=>{let t=u(e);return[`zama.delegationStatus`,t?{contractAddress:t}:{}]},scope:(e,t,n)=>{let r=u(e),i=u(t),a=u(n);return[`zama.delegationStatus`,{...r?{contractAddress:r}:{},...i?{delegatorAddress:i}:{},...a?{delegateAddress:a}:{}}]}},decryption:{all:[`zama.decryption`],encryptedValue:(e,t)=>[`zama.decryption`,{encryptedValue:e,...t===void 0?{}:{contractAddress:(0,r.getAddress)(t)}}],encryptedInputs:(e,t)=>[`zama.decryption`,{...d(t),encryptedInputs:[...e].toSorted((e,t)=>e.encryptedValue.localeCompare(t.encryptedValue)).map(e=>({encryptedValue:e.encryptedValue,contractAddress:(0,r.getAddress)(e.contractAddress)}))}]},wrappersRegistry:{all:[`zama.wrappersRegistry`],chainId:()=>[`zama.wrappersRegistry`,{type:`chainId`}],tokenPairs:e=>[`zama.wrappersRegistry`,{type:`tokenPairs`,registryAddress:(0,r.getAddress)(e)}],confidentialTokenAddress:(e,t)=>[`zama.wrappersRegistry`,{type:`confidentialTokenAddress`,registryAddress:(0,r.getAddress)(e),tokenAddress:(0,r.getAddress)(t)}],tokenAddress:(e,t)=>[`zama.wrappersRegistry`,{type:`tokenAddress`,registryAddress:(0,r.getAddress)(e),confidentialTokenAddress:(0,r.getAddress)(t)}],tokenPairsLength:e=>[`zama.wrappersRegistry`,{type:`tokenPairsLength`,registryAddress:(0,r.getAddress)(e)}],tokenPairsSlice:(e,t,n)=>[`zama.wrappersRegistry`,{type:`tokenPairsSlice`,registryAddress:(0,r.getAddress)(e),fromIndex:t,toIndex:n}],tokenPair:(e,t)=>[`zama.wrappersRegistry`,{type:`tokenPair`,registryAddress:(0,r.getAddress)(e),index:t}],isConfidentialTokenValid:(e,t)=>[`zama.wrappersRegistry`,{type:`isConfidentialTokenValid`,registryAddress:(0,r.getAddress)(e),confidentialTokenAddress:(0,r.getAddress)(t)}],listPairs:(e,t,n,i)=>[`zama.wrappersRegistry`,{type:`listPairs`,registryAddress:(0,r.getAddress)(e),page:t,pageSize:n,metadata:i}]}};function p(e,t){e.invalidateQueries({queryKey:f.underlyingAllowance.token(t)})}function m(e,t){h(e,t),p(e,t),E(e)}function h(e,t){e.invalidateQueries({queryKey:f.confidentialBalance.token(t)}),e.invalidateQueries({queryKey:f.confidentialBalances.all})}function g(e,t){h(e,t),p(e,t),E(e)}function _(e,t){h(e,t),p(e,t),E(e)}function ee(e,t){h(e,t)}function v(e,t){p(e,t)}function y(e,t){e.invalidateQueries({queryKey:f.confidentialIsOperator.token(t)})}function b(e){return Array.isArray(e.queryKey)&&typeof e.queryKey[0]==`string`?e.queryKey[0].startsWith(`zama.`):!1}const x=i.z.enum([`balanceOf`,`confidentialBalanceOf`]),S=i.z.object({functionName:x}),C=i.z.object({contracts:i.z.array(i.z.unknown())});function w(e){if(S.safeParse(e).success)return!0;let t=C.safeParse(e);return t.success&&t.data.contracts.some(e=>S.safeParse(e).success)}function T(e){return Array.isArray(e.queryKey)&&e.queryKey.some(w)}function E(e){e.invalidateQueries({predicate:T})}function D(e){e.removeQueries({queryKey:f.decryption.all}),e.removeQueries({queryKey:f.hasPermit.all}),e.invalidateQueries({predicate:b}),E(e)}function O(t,n,r){let i=f.tokenMetadata.token(n);return{...s(r?.query??{}),queryKey:i,queryFn:async n=>{let[,{tokenAddress:r}]=n.queryKey,[i,a,o]=await Promise.all([t.provider.readContract(e.b(r)),t.provider.readContract(e.x(r)),t.provider.readContract(e.v(r))]);return{name:i,symbol:a,decimals:o}},staleTime:1/0,enabled:r?.query?.enabled!==!1}}function k(t,r,i){let a=f.isConfidential.token(r);return{...s(i?.query??{}),queryKey:a,queryFn:async r=>{let[,{tokenAddress:i}]=r.queryKey;try{return await t.provider.readContract(e.d(i))}catch(e){if(n.s(e))return!1;throw e}},staleTime:1/0,enabled:i?.query?.enabled!==!1}}function A(t,r,i){let a=f.isWrapper.token(r);return{...s(i?.query??{}),queryKey:a,queryFn:async r=>{let[,{tokenAddress:i}]=r.queryKey;try{return await t.provider.readContract(e.f(i))}catch(e){if(n.s(e))return!1;throw e}},staleTime:1/0,enabled:i?.query?.enabled!==!1}}function j(t,n,r){let i=f.totalSupply.token(n);return{...s(r?.query??{}),queryKey:i,queryFn:async n=>{let[,{tokenAddress:r}]=n.queryKey;return t.provider.readContract(e.k(r))},staleTime:3e4,enabled:r?.query?.enabled!==!1}}function M(e,t){let r=f.wrapperDiscovery.token(t.tokenAddress,t.erc20Address,t.registryAddress);return{...s(t.query??{}),queryKey:r,queryFn:async t=>{let[,{erc20Address:r}]=t.queryKey;n.r(r,`wrapperDiscoveryQueryOptions: erc20Address`);let i=await e.getConfidentialToken(r);return i?i.confidentialTokenAddress:null},staleTime:1/0,enabled:!!(t.tokenAddress&&t.erc20Address&&t.registryAddress)&&t.query?.enabled!==!1}}function N(t,r,i){let a=i.owner,o=i.query?.enabled!==!1,c=f.underlyingAllowance.scope(r,a);return{...s(i.query??{}),queryKey:c,queryFn:async r=>{let[,{tokenAddress:i,owner:a}]=r.queryKey;n.r(a,`underlyingAllowanceQueryOptions: owner`);let o=await t.provider.readContract(e.N(i));return t.provider.readContract(e.h(o,a,i))},staleTime:3e4,enabled:!!a&&o}}function P(t,r,i){let a=i.holder,o=i.spender,c=i.query?.enabled!==!1,l=f.confidentialIsOperator.scope(r,a,o);return{...s(i.query??{}),queryKey:l,queryFn:async r=>{let[,{tokenAddress:i,holder:a,spender:o}]=r.queryKey;return n.r(i,`confidentialIsOperatorQueryOptions: tokenAddress`),n.r(a,`confidentialIsOperatorQueryOptions: holder`),n.r(o,`confidentialIsOperatorQueryOptions: spender`),t.provider.readContract(e.A(i,a,o))},staleTime:3e4,enabled:!!(r&&a&&o)&&c}}function F(e,t,r={}){let i=t.query??{};return{...s(i),queryKey:f.confidentialBalance.owner(t.tokenAddress,t.account,r.walletAccount),queryFn:async t=>{let[,{owner:r}]=t.queryKey;return n.r(r,`confidentialBalanceQueryOptions: owner`),e.balanceOf(r)},enabled:!!t.account&&r.walletAccount!==void 0&&i?.enabled!==!1}}function I(e,r,i={}){let a=r?.account,o=i.walletAccount,c=r?.query??{},l=e.map(e=>e.address);return{...s(c),queryKey:f.confidentialBalances.tokens(l,a,o),queryFn:async r=>{let[,{owner:i}]=r.queryKey;return n.r(i,`confidentialBalancesQueryOptions: owner`),t.t.batchBalancesOf(e,i)},enabled:!!a&&e.length>0&&o!==void 0&&c?.enabled!==!1}}const L=86400*1e3;function R(t,n){let i=!!n.registryAddress&&n.query?.enabled!==!1,a=f.wrappersRegistry.tokenPairs(n.registryAddress??r.zeroAddress);return{...s(n.query??{}),queryKey:a,queryFn:async n=>{let[,{registryAddress:r}]=n.queryKey;return t.provider.readContract(e.i(r))},staleTime:L,enabled:i}}function z(t,n){let i=!!n.registryAddress&&!!n.tokenAddress&&n.query?.enabled!==!1,a=f.wrappersRegistry.confidentialTokenAddress(n.registryAddress??r.zeroAddress,n.tokenAddress??r.zeroAddress);return{...s(n.query??{}),queryKey:a,queryFn:async n=>{let[,{registryAddress:r,tokenAddress:i}]=n.queryKey;return t.provider.readContract(e.t(r,i))},staleTime:L,enabled:i}}function B(t,n){let i=!!n.registryAddress&&!!n.confidentialTokenAddress&&n.query?.enabled!==!1,a=f.wrappersRegistry.tokenAddress(n.registryAddress??r.zeroAddress,n.confidentialTokenAddress??r.zeroAddress);return{...s(n.query??{}),queryKey:a,queryFn:async n=>{let[,{registryAddress:r,confidentialTokenAddress:i}]=n.queryKey;return t.provider.readContract(e.n(r,i))},staleTime:L,enabled:i}}function V(t,n){let i=!!n.registryAddress&&n.query?.enabled!==!1,a=f.wrappersRegistry.tokenPairsLength(n.registryAddress??r.zeroAddress);return{...s(n.query??{}),queryKey:a,queryFn:async n=>{let[,{registryAddress:r}]=n.queryKey;return t.provider.readContract(e.a(r))},staleTime:L,enabled:i}}function te(t,n){let i=!!n.registryAddress&&n.fromIndex!==void 0&&n.toIndex!==void 0&&n.query?.enabled!==!1,a=f.wrappersRegistry.tokenPairsSlice(n.registryAddress??r.zeroAddress,String(n.fromIndex??0n),String(n.toIndex??0n));return{...s(n.query??{}),queryKey:a,queryFn:async n=>{let[,{registryAddress:r,fromIndex:i,toIndex:a}]=n.queryKey;return t.provider.readContract(e.o(r,BigInt(i),BigInt(a)))},staleTime:L,enabled:i}}function H(t,n){let i=!!n.registryAddress&&n.index!==void 0&&n.query?.enabled!==!1,a=f.wrappersRegistry.tokenPair(n.registryAddress??r.zeroAddress,String(n.index??0n));return{...s(n.query??{}),queryKey:a,queryFn:async n=>{let[,{registryAddress:r,index:i}]=n.queryKey;return t.provider.readContract(e.r(r,BigInt(i)))},staleTime:L,enabled:i}}function U(t,n){let i=!!n.registryAddress&&!!n.confidentialTokenAddress&&n.query?.enabled!==!1,a=f.wrappersRegistry.isConfidentialTokenValid(n.registryAddress??r.zeroAddress,n.confidentialTokenAddress??r.zeroAddress);return{...s(n.query??{}),queryKey:a,queryFn:async n=>{let[,{registryAddress:r,confidentialTokenAddress:i}]=n.queryKey;return t.provider.readContract(e.s(r,i))},staleTime:L,enabled:i}}function W(e,t){let n=!!t.registryAddress&&t.query?.enabled!==!1,i=f.wrappersRegistry.listPairs(t.registryAddress??r.zeroAddress,t.page??1,t.pageSize??100,t.metadata??!1);return{...s(t.query??{}),queryKey:i,queryFn:async t=>{let[,{page:n,pageSize:r,metadata:i}]=t.queryKey;return e.listPairs({page:n,pageSize:r,metadata:i})},staleTime:e.ttlMs,enabled:n}}function G(e){return{mutationKey:[`zama.shield`,e.address],mutationFn:async({amount:t,...n})=>e.shield(t,n)}}function K(e){return{mutationKey:[`zama.confidentialTransfer`,e.address],mutationFn:async({to:t,amount:n,...r})=>e.confidentialTransfer(t,n,r)}}function q(e){return{mutationKey:[`zama.confidentialTransferAndCall`,e.address],mutationFn:async({to:t,amount:n,data:r,...i})=>e.confidentialTransferAndCall(t,n,r,i)}}function J(e){return{mutationKey:[`zama.confidentialTransferFrom`,e.address],mutationFn:async({from:t,to:n,amount:r,callbacks:i})=>e.confidentialTransferFrom(t,n,r,i)}}function Y(e){return{mutationKey:[`zama.confidentialTransferFromAndCall`,e.address],mutationFn:async({from:t,to:n,amount:r,data:i,callbacks:a})=>e.confidentialTransferFromAndCall(t,n,r,i,a)}}function X(e){return{mutationKey:[`zama.confidentialSetOperator`,e.address],mutationFn:async({operator:t,until:n})=>e.setOperator(t,n)}}function Z(e){return{mutationKey:[`zama.approveUnderlying`,e.address],mutationFn:async({amount:t})=>e.approveUnderlying(t)}}function Q(e){return{mutationKey:[`zama.unshield`,e.address],mutationFn:async({amount:t,...n})=>e.unshield(t,n)}}function ne(e){return{mutationKey:[`zama.unshieldAll`,e.address],mutationFn:async t=>e.unshieldAll(t||void 0)}}function re(e){return{mutationKey:[`zama.resumeUnshield`,e.address],mutationFn:async({unwrapTxHash:t,...n})=>e.resumeUnshield(t,n)}}function ie(e){return{mutationKey:[`zama.unwrap`,e.address],mutationFn:async({amount:t})=>e.unwrap(t)}}function ae(e){return{mutationKey:[`zama.unwrapAll`,e.address],mutationFn:async()=>e.unwrapAll()}}function oe(e){return{mutationKey:[`zama.finalizeUnwrap`,e.address],mutationFn:async({unwrapRequestId:t})=>e.finalizeUnwrap(t)}}function se(e){return{mutationKey:[`zama.encrypt`],mutationFn:async t=>e.encrypt(t)}}function ce(e){return{mutationKey:[`zama.delegatedDecryptValues`],mutationFn:async t=>e.decryption.delegatedDecryptValues(t.encryptedInputs,t.delegatorAddress)}}function le(e){return{mutationKey:[`zama.decryptPublicValues`],mutationFn:async t=>e.decryption.decryptPublicValues(t),onSuccess:(e,t,n,r)=>{for(let[t,n]of Object.entries(e.clearValues))r.client.setQueryData(f.decryption.encryptedValue(t),n)}}}function ue(e){return{mutationKey:[`zama.grantPermit`],mutationFn:t=>e.permits.grantPermit(t)}}function de(e,t,n={}){let r=t.query?.enabled!==!1;return{...s(t?.query??{}),queryKey:f.hasPermit.scope(t.contractAddresses,n.walletAccount),queryFn:t=>{let[,{contractAddresses:n}]=t.queryKey;return e.permits.hasPermit(n)},staleTime:0,gcTime:0,refetchOnMount:`always`,refetchOnWindowFocus:!1,enabled:r&&n.walletAccount!==void 0&&t.contractAddresses.length>0}}function fe(e){return{mutationKey:[`zama.revokePermits`],mutationFn:t=>t===void 0?e.permits.revokePermits():e.permits.revokePermits(t)}}function pe(e){return{mutationKey:[`zama.clearCredentials`],mutationFn:()=>e.permits.clear()}}function $(e,t){return{mutationKey:[`zama.delegateDecryption`,t],mutationFn:async({delegateAddress:n,expirationDate:r})=>e.delegations.delegateDecryption({contractAddress:t,delegateAddress:n,expirationDate:r})}}function me(e,t,n={}){return{queryKey:f.decryption.encryptedInputs(t,n.walletAccount),queryFn:t=>{let[,{encryptedInputs:n}]=t.queryKey;return e.decryption.decryptValues(n)},staleTime:1/0,enabled:t.length>0&&n.walletAccount!==void 0}}function he(e){return{mutationKey:[`zama.decryptBalanceAs`,e.address],mutationFn:async({delegatorAddress:t,accountAddress:n})=>e.decryptBalanceAs({delegatorAddress:t,accountAddress:n})}}function ge(e){return{mutationKey:[`zama.batchDecryptBalancesAs`,...e.map(e=>e.address)],mutationFn:async n=>t.t.batchDecryptBalancesAs(e,n)}}function _e(e,t){return{mutationKey:[`zama.revokeDelegation`,t],mutationFn:async({delegateAddress:n})=>e.delegations.revokeDelegation({contractAddress:t,delegateAddress:n})}}function ve(e,r){return{...s(r.query??{}),queryKey:f.delegationStatus.scope(r.contractAddress,r.delegatorAddress,r.delegateAddress),queryFn:async r=>{let[,{contractAddress:i,delegatorAddress:a,delegateAddress:o}]=r.queryKey;n.r(i,`delegationStatusQueryOptions: contractAddress`),n.r(a,`delegationStatusQueryOptions: delegatorAddress`),n.r(o,`delegationStatusQueryOptions: delegateAddress`);let s=await e.relayer.getAclAddress(),c=await e.provider.readContract(t.d(s,a,o,i)),l;return l=c===0n?!1:c===t.l?!0:c>await e.provider.getBlockTimestamp(),{isActive:l,expiryTimestamp:c}},enabled:!!(r.contractAddress&&r.delegatorAddress&&r.delegateAddress)&&r.query?.enabled!==!1}}exports.ZamaSDKEvents=t.o,exports.approveUnderlyingMutationOptions=Z,exports.batchDecryptBalancesAsMutationOptions=ge,exports.clearCredentialsMutationOptions=pe,exports.confidentialBalanceQueryOptions=F,exports.confidentialBalancesQueryOptions=I,exports.confidentialIsOperatorQueryOptions=P,exports.confidentialSetOperatorMutationOptions=X,exports.confidentialTokenAddressQueryOptions=z,exports.confidentialTransferAndCallMutationOptions=q,exports.confidentialTransferFromAndCallMutationOptions=Y,exports.confidentialTransferFromMutationOptions=J,exports.confidentialTransferMutationOptions=K,exports.decryptBalanceAsMutationOptions=he,exports.decryptPublicValuesMutationOptions=le,exports.decryptValuesQueryOptions=me,exports.delegateDecryptionMutationOptions=$,exports.delegatedDecryptValuesMutationOptions=ce,exports.delegationStatusQueryOptions=ve,exports.encryptMutationOptions=se,exports.filterQueryOptions=s,exports.finalizeUnwrapMutationOptions=oe,exports.grantPermitMutationOptions=ue,exports.hasPermitQueryOptions=de,exports.hashFn=c,exports.invalidateAfterApproveUnderlying=v,exports.invalidateAfterSetOperator=y,exports.invalidateAfterShield=g,exports.invalidateAfterTransfer=ee,exports.invalidateAfterUnshield=_,exports.invalidateAfterUnwrap=m,exports.invalidateBalanceQueries=h,exports.invalidateWagmiBalanceQueries=E,exports.invalidateWalletLifecycleQueries=D,exports.isConfidentialQueryOptions=k,exports.isConfidentialTokenValidQueryOptions=U,exports.isWrapperQueryOptions=A,exports.listPairsQueryOptions=W,exports.resumeUnshieldMutationOptions=re,exports.revokeDelegationMutationOptions=_e,exports.revokePermitsMutationOptions=fe,exports.shieldMutationOptions=G,exports.tokenAddressQueryOptions=B,exports.tokenMetadataQueryOptions=O,exports.tokenPairQueryOptions=H,exports.tokenPairsLengthQueryOptions=V,exports.tokenPairsQueryOptions=R,exports.tokenPairsSliceQueryOptions=te,exports.totalSupplyQueryOptions=j,exports.underlyingAllowanceQueryOptions=N,exports.unshieldAllMutationOptions=ne,exports.unshieldMutationOptions=Q,exports.unwrapAllMutationOptions=ae,exports.unwrapMutationOptions=ie,exports.wrapperDiscoveryQueryOptions=M,exports.zamaQueryKeys=f;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|