@zama-fhe/sdk 3.9.1-beta.2 → 3.9.1-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/cjs/base-signer.cjs +1 -1
  2. package/dist/cjs/base-signer.cjs.map +1 -1
  3. package/dist/cjs/index.cjs +1 -1
  4. package/dist/cjs/index.cjs.map +1 -1
  5. package/dist/cjs/telemetry.cjs +1 -1
  6. package/dist/esm/base-signer-DUflPI8d.js +2 -0
  7. package/dist/esm/base-signer-DUflPI8d.js.map +1 -0
  8. package/dist/esm/cleartext/index.js +1 -1
  9. package/dist/esm/{cleartext-C0DXenyT.js → cleartext-Dt_G8a-Y.js} +2 -2
  10. package/dist/esm/{cleartext-C0DXenyT.js.map → cleartext-Dt_G8a-Y.js.map} +1 -1
  11. package/dist/esm/{decryption-BvvhpFM2.d.ts → decryption-CMNWWt0M.d.ts} +6 -3
  12. package/dist/esm/ethers/index.js +1 -1
  13. package/dist/esm/{fhevm-relayer-DCQ-Oaa1.js → fhevm-relayer-BRF_qaSG.js} +2 -2
  14. package/dist/esm/{fhevm-relayer-DCQ-Oaa1.js.map → fhevm-relayer-BRF_qaSG.js.map} +1 -1
  15. package/dist/esm/{index-B7M2GEtA.d.ts → index-Dh3aBqpo.d.ts} +1 -1
  16. package/dist/esm/index.d.ts +2 -2
  17. package/dist/esm/index.js +1 -1
  18. package/dist/esm/index.js.map +1 -1
  19. package/dist/esm/internal/index.d.ts +1 -1
  20. package/dist/esm/internal/index.js +1 -1
  21. package/dist/esm/node/index.js +1 -1
  22. package/dist/esm/query/index.d.ts +2 -2
  23. package/dist/esm/{telemetry-CW2RgPxb.js → telemetry-DgZG8yT6.js} +2 -2
  24. package/dist/esm/{telemetry-CW2RgPxb.js.map → telemetry-DgZG8yT6.js.map} +1 -1
  25. package/dist/esm/vaults/index.d.ts +1 -1
  26. package/dist/esm/viem/index.js +1 -1
  27. package/dist/esm/web/index.js +1 -1
  28. package/package.json +1 -1
  29. package/dist/esm/base-signer-CysprC2L.js +0 -2
  30. package/dist/esm/base-signer-CysprC2L.js.map +0 -1
@@ -25222,11 +25222,14 @@ interface ZamaSDKOptions {
25222
25222
  * key import; it never touches your buffer, so zeroize yours after construction.
25223
25223
  * The SDK never persists or exposes this value. Omit for the default:
25224
25224
  * plaintext at rest, security delegated to the storage backend.
25225
+ *
25226
+ * Cached decrypted values stay readable in storage, but each is tagged with a key
25227
+ * derived from this secret, and a value whose tag does not verify is decrypted again.
25225
25228
  */
25226
25229
  transportKeyPairDerivationSecret?: string | Uint8Array;
25227
25230
  }
25228
25231
  /**
25229
- * ZamaSDK — composes a RelayerSDK with contract abstraction.
25232
+ * ZamaSDK composes a RelayerSDK with contract abstraction.
25230
25233
  *
25231
25234
  * Exposes domain namespaces for permits, delegations, decryption, offline
25232
25235
  * signing, and tokens, plus an unchanged registry, a top-level `encrypt`, and
@@ -25253,7 +25256,7 @@ declare class ZamaSDK {
25253
25256
  readonly delegations: Delegations;
25254
25257
  /** FHE decryption (user, delegated user, public). */
25255
25258
  readonly decryption: Decryption;
25256
- /** Offline-signing pipeline: `prepare` builds an unsigned tx the caller signs and broadcasts out-of-process — for HSM, policy-engine, and cross-process custody workflows. */
25259
+ /** Offline-signing pipeline: `prepare` builds an unsigned tx the caller signs and broadcasts out-of-process. Built for HSM, policy-engine, and cross-process custody workflows. */
25257
25260
  readonly offline: Offline;
25258
25261
  constructor(config: ZamaConfig, options?: ZamaSDKOptions);
25259
25262
  /**
@@ -25273,7 +25276,7 @@ declare class ZamaSDK {
25273
25276
  * // Addresses resolved from the SDK's chain configs
25274
25277
  * const registry = sdk.createWrappersRegistry();
25275
25278
  *
25276
- * // Hardhat or custom chain — override per chain for this registry instance
25279
+ * // Hardhat or custom chain: override per chain for this registry instance
25277
25280
  * const registry = sdk.createWrappersRegistry({ [31337]: "0xYourRegistry" });
25278
25281
  *
25279
25282
  * const pairs = await registry.getTokenPairs();
@@ -1,2 +1,2 @@
1
- import{i as e,t}from"../base-signer-CysprC2L.js";import{t as n}from"../relayer-Cki3j_Ba.js";import{A as r,B as i,F as a,G as o,H as s,I as c,M as l,N as u,R as d,S as f,T as p,W as m,X as h,d as g,k as _,r as v,y}from"../alignment-D1cVCzw8.js";import{a as b,i as x,n as S,o as C,r as w,s as T,t as E}from"../wrappers-registry-Cm3JJeqx.js";import{t as D}from"../eip1193-subscribe-DxAQh8dY.js";import{ProviderRpcError as ee,createClient as te,custom as ne,decodeFunctionResult as O,encodeFunctionData as k,getAddress as A,isHex as j}from"viem";import{BrowserProvider as M,Contract as N,Transaction as P,ethers as F}from"ethers";import{multicall as I}from"viem/actions";function L(e){return{to:e.address,data:k({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 R(e,t){let n=await e.call(L(t));if(!j(n))throw TypeError(`Expected hex string, got: ${n}`);return O({abi:t.abi,functionName:t.functionName,data:n})}async function z(e,t){let n=await e.sendTransaction(L(t));if(!j(n.hash))throw TypeError(`Expected hex string, got: ${n.hash}`);return n.hash}function B(e,t,n){return R(e,y(t,n))}function V(e,t){return R(e,r(t))}function H(e,t,n){return R(e,g(t,n))}function U(e,t,n,r,i){return z(e,f(t,n,r,i))}function W(e,t,n,r,i,a){return z(e,l(t,n,r,i,a))}function G(e,t,n,r,i){return z(e,u(t,n,r,i))}function K(e,t,n,r,i){return z(e,p(t,n,r,i))}function q(e,t,n,r){return z(e,_(t,n,r))}function J(e,t,n,r){return z(e,a(t,n,r))}function Y(e,t){return R(e,x(t))}function X(e,t){return R(e,b(t))}function re(e,t,n,r){return R(e,C(t,n,r))}function ie(e,t,n){return R(e,w(t,n))}function ae(e,t,n){return R(e,E(t,n))}function oe(e,t,n){return R(e,S(t,n))}function se(e,t,n){return R(e,T(t,n))}var Z=class{#e;#t=te({transport:ne({request:async({method:e,params:t})=>{if(e!==`eth_call`)throw Error(`EthersProvider.multicall does not send ${e}`);let[n,r]=t;return this.#e.call({to:n.to,data:n.data,blockTag:r})}})});constructor(e){this.#e=`ethereum`in e?new M(e.ethereum):e.provider}async getChainId(){let e=await this.#e.getNetwork();return Number(e.chainId)}async readContract(e){return await v(`EthersProvider`,e.chainId,()=>this.getChainId()),R(this.#e,{address:e.address,abi:e.abi,functionName:e.functionName,args:e.args})}async multicall(e){await v(`EthersProvider`,e.chainId,()=>this.getChainId());let t=await I(this.#t,{contracts:e.calls.map(({chainId:e,...t})=>t),deployless:!0});return await Promise.all(e.calls.map((e,n)=>{let r=t[n];return r?.status===`success`?r.result:this.readContract({...e,chainId:void 0})}))}async getBlockTimestamp(e){await v(`EthersProvider`,e,()=>this.getChainId());let t=await this.#e.getBlock(`latest`);if(!t)throw new n(`EthersProvider.getBlockTimestamp: failed to fetch latest block`);if(t.timestamp===null)throw new n(`EthersProvider.getBlockTimestamp: latest block has no timestamp`);return BigInt(t.timestamp)}async waitForTransactionReceipt(e){let t=await this.#e.waitForTransaction(e);if(!t)throw new h(`EthersProvider.waitForTransactionReceipt: no receipt found for tx ${e}. The transaction may have been dropped from the mempool, or the RPC's wait timeout elapsed.`);return Q(t)}async getTransactionReceipt(e){let t=await this.#e.getTransactionReceipt(e);return t&&Q(t)}async prepareTransaction(e){let{from:t,calldata:r}=e,i=new F.Interface(r.abi),a=[];i.forEachFunction(e=>{e.name===r.functionName&&a.push(e)});let o=r.args.length,s=a.length===1?a[0]:a.find(e=>e.inputs.length===o);if(!s)throw Error(`Function ${r.functionName}(${o} args) not found in ABI`);let c=i.encodeFunctionData(s,r.args);d(c,`data`);let l=r.value??0n,u=this.#e.getNetwork(),f=e.nonce===void 0?this.#e.getTransactionCount(t,`pending`):Promise.resolve(e.nonce),p=e.gasLimit===void 0?r.gas??this.#e.estimateGas({from:t,to:r.address,data:c,value:l}).catch(e=>{throw new h(`EthersProvider.prepareTransaction: gas estimation reverted for ${r.functionName} on ${r.address}`,{cause:e})}):Promise.resolve(e.gasLimit),m=e.fees??this.#e.getFeeData(),[g,_,v,y]=await Promise.all([u,f,p,m]),b=y.maxFeePerGas,x=y.maxPriorityFeePerGas;if(b===null||x===null)throw new n(`EthersProvider.prepareTransaction: EIP-1559 fee data unavailable (provider returned null maxFeePerGas). The connected chain may not support EIP-1559 type-2 transactions.`);return P.from({type:2,chainId:Number(g.chainId),nonce:_,to:r.address,data:c,value:l,gasLimit:v,maxFeePerGas:b,maxPriorityFeePerGas:x}).unsignedSerialized}};function Q(e){let t=e.status===null?void 0:e.status===1?`success`:`reverted`;return{logs:e.logs.map(e=>({address:e.address,topics:e.topics.filter(e=>e!==null),data:e.data})),...t&&{status:t}}}var $=class extends t{#e;#t;#n;#r;#i;constructor(e){super(),`ethereum`in e?(this.#e=new M(e.ethereum),this.#n=e.ethereum,this.#r=D({provider:e.ethereum,getInitialWalletAccount:()=>this.#l(),onWalletAccountChange:({next:e})=>{this.walletAccount.setSnapshot(e)}})):(this.#t=e.signer,this.#r=()=>{},c(`refresh wallet account`,async()=>{await this.refreshWalletAccount()}))}requireWalletAccount(e){let t=this.walletAccount.getSnapshot();if(!t&&!this.walletAccount.isReady())throw new m(e);if(!t)throw new o(e);return t}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 s(`resolveSigner`);return this.#e.getSigner()}async#o(e){let t=e.provider;if(!t)return;let[n,r]=await Promise.all([e.getAddress(),t.getNetwork()]);return{address:A(n),chainId:Number(r.chainId)}}async signTypedData(e){let t=await this.#a(),{domain:n,types:r,message:i}=e,{EIP712Domain:a,...o}=r,s=Object.fromEntries(Object.entries(o).map(([e,t])=>[e,[...t]])),c=await t.signTypedData(n,s,i);if(!j(c))throw TypeError(`Expected hex string, got: ${c}`);return c}async writeContract(e){let t=await this.#a(),n=new N(e.address,e.abi,t),r={};e.value!==void 0&&(r.value=e.value),e.gas!==void 0&&(r.gasLimit=e.gas);let i=await n.getFunction(e.functionName)(...e.args,r);if(!j(i.hash))throw TypeError(`Expected hex string, got: ${i.hash}`);return i.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 r=Number(n);if(!(!Number.isSafeInteger(r)||r<=0))return{address:A(t[0]),chainId:r}}};function ce(t){if(`signer`in t&&t.signer){let n=new $({signer:t.signer});if(!t.signer.provider)throw Error(`createConfig requires a Signer with an attached provider for chain reads`);let r=new Z({provider:t.signer.provider});return e(n,r,t)}let n=new $({ethereum:t.ethereum}),r=`provider`in t&&t.provider?new Z({provider:t.provider}):new Z({ethereum:t.ethereum});return e(n,r,t)}export{t as BaseSigner,Z as EthersProvider,$ as EthersSigner,ee as ProviderRpcError,i as ZamaSDKEvents,ce as createConfig,B as readConfidentialBalanceOfContract,ae as readConfidentialTokenAddressContract,se as readIsConfidentialTokenValidContract,H as readSupportsInterfaceContract,oe as readTokenAddressContract,ie as readTokenPairContract,Y as readTokenPairsContract,X as readTokenPairsLengthContract,re as readTokenPairsSliceContract,V as readUnderlyingTokenContract,U as writeConfidentialTransferContract,K as writeFinalizeUnwrapContract,q as writeSetOperatorContract,W as writeUnwrapContract,G as writeUnwrapFromBalanceContract,J as writeWrapContract};
1
+ import{i as e,t}from"../base-signer-DUflPI8d.js";import{t as n}from"../relayer-Cki3j_Ba.js";import{A as r,B as i,F as a,G as o,H as s,I as c,M as l,N as u,R as d,S as f,T as p,W as m,X as h,d as g,k as _,r as v,y}from"../alignment-D1cVCzw8.js";import{a as b,i as x,n as S,o as C,r as w,s as T,t as E}from"../wrappers-registry-Cm3JJeqx.js";import{t as D}from"../eip1193-subscribe-DxAQh8dY.js";import{ProviderRpcError as ee,createClient as te,custom as ne,decodeFunctionResult as O,encodeFunctionData as k,getAddress as A,isHex as j}from"viem";import{BrowserProvider as M,Contract as N,Transaction as P,ethers as F}from"ethers";import{multicall as I}from"viem/actions";function L(e){return{to:e.address,data:k({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 R(e,t){let n=await e.call(L(t));if(!j(n))throw TypeError(`Expected hex string, got: ${n}`);return O({abi:t.abi,functionName:t.functionName,data:n})}async function z(e,t){let n=await e.sendTransaction(L(t));if(!j(n.hash))throw TypeError(`Expected hex string, got: ${n.hash}`);return n.hash}function B(e,t,n){return R(e,y(t,n))}function V(e,t){return R(e,r(t))}function H(e,t,n){return R(e,g(t,n))}function U(e,t,n,r,i){return z(e,f(t,n,r,i))}function W(e,t,n,r,i,a){return z(e,l(t,n,r,i,a))}function G(e,t,n,r,i){return z(e,u(t,n,r,i))}function K(e,t,n,r,i){return z(e,p(t,n,r,i))}function q(e,t,n,r){return z(e,_(t,n,r))}function J(e,t,n,r){return z(e,a(t,n,r))}function Y(e,t){return R(e,x(t))}function X(e,t){return R(e,b(t))}function re(e,t,n,r){return R(e,C(t,n,r))}function ie(e,t,n){return R(e,w(t,n))}function ae(e,t,n){return R(e,E(t,n))}function oe(e,t,n){return R(e,S(t,n))}function se(e,t,n){return R(e,T(t,n))}var Z=class{#e;#t=te({transport:ne({request:async({method:e,params:t})=>{if(e!==`eth_call`)throw Error(`EthersProvider.multicall does not send ${e}`);let[n,r]=t;return this.#e.call({to:n.to,data:n.data,blockTag:r})}})});constructor(e){this.#e=`ethereum`in e?new M(e.ethereum):e.provider}async getChainId(){let e=await this.#e.getNetwork();return Number(e.chainId)}async readContract(e){return await v(`EthersProvider`,e.chainId,()=>this.getChainId()),R(this.#e,{address:e.address,abi:e.abi,functionName:e.functionName,args:e.args})}async multicall(e){await v(`EthersProvider`,e.chainId,()=>this.getChainId());let t=await I(this.#t,{contracts:e.calls.map(({chainId:e,...t})=>t),deployless:!0});return await Promise.all(e.calls.map((e,n)=>{let r=t[n];return r?.status===`success`?r.result:this.readContract({...e,chainId:void 0})}))}async getBlockTimestamp(e){await v(`EthersProvider`,e,()=>this.getChainId());let t=await this.#e.getBlock(`latest`);if(!t)throw new n(`EthersProvider.getBlockTimestamp: failed to fetch latest block`);if(t.timestamp===null)throw new n(`EthersProvider.getBlockTimestamp: latest block has no timestamp`);return BigInt(t.timestamp)}async waitForTransactionReceipt(e){let t=await this.#e.waitForTransaction(e);if(!t)throw new h(`EthersProvider.waitForTransactionReceipt: no receipt found for tx ${e}. The transaction may have been dropped from the mempool, or the RPC's wait timeout elapsed.`);return Q(t)}async getTransactionReceipt(e){let t=await this.#e.getTransactionReceipt(e);return t&&Q(t)}async prepareTransaction(e){let{from:t,calldata:r}=e,i=new F.Interface(r.abi),a=[];i.forEachFunction(e=>{e.name===r.functionName&&a.push(e)});let o=r.args.length,s=a.length===1?a[0]:a.find(e=>e.inputs.length===o);if(!s)throw Error(`Function ${r.functionName}(${o} args) not found in ABI`);let c=i.encodeFunctionData(s,r.args);d(c,`data`);let l=r.value??0n,u=this.#e.getNetwork(),f=e.nonce===void 0?this.#e.getTransactionCount(t,`pending`):Promise.resolve(e.nonce),p=e.gasLimit===void 0?r.gas??this.#e.estimateGas({from:t,to:r.address,data:c,value:l}).catch(e=>{throw new h(`EthersProvider.prepareTransaction: gas estimation reverted for ${r.functionName} on ${r.address}`,{cause:e})}):Promise.resolve(e.gasLimit),m=e.fees??this.#e.getFeeData(),[g,_,v,y]=await Promise.all([u,f,p,m]),b=y.maxFeePerGas,x=y.maxPriorityFeePerGas;if(b===null||x===null)throw new n(`EthersProvider.prepareTransaction: EIP-1559 fee data unavailable (provider returned null maxFeePerGas). The connected chain may not support EIP-1559 type-2 transactions.`);return P.from({type:2,chainId:Number(g.chainId),nonce:_,to:r.address,data:c,value:l,gasLimit:v,maxFeePerGas:b,maxPriorityFeePerGas:x}).unsignedSerialized}};function Q(e){let t=e.status===null?void 0:e.status===1?`success`:`reverted`;return{logs:e.logs.map(e=>({address:e.address,topics:e.topics.filter(e=>e!==null),data:e.data})),...t&&{status:t}}}var $=class extends t{#e;#t;#n;#r;#i;constructor(e){super(),`ethereum`in e?(this.#e=new M(e.ethereum),this.#n=e.ethereum,this.#r=D({provider:e.ethereum,getInitialWalletAccount:()=>this.#l(),onWalletAccountChange:({next:e})=>{this.walletAccount.setSnapshot(e)}})):(this.#t=e.signer,this.#r=()=>{},c(`refresh wallet account`,async()=>{await this.refreshWalletAccount()}))}requireWalletAccount(e){let t=this.walletAccount.getSnapshot();if(!t&&!this.walletAccount.isReady())throw new m(e);if(!t)throw new o(e);return t}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 s(`resolveSigner`);return this.#e.getSigner()}async#o(e){let t=e.provider;if(!t)return;let[n,r]=await Promise.all([e.getAddress(),t.getNetwork()]);return{address:A(n),chainId:Number(r.chainId)}}async signTypedData(e){let t=await this.#a(),{domain:n,types:r,message:i}=e,{EIP712Domain:a,...o}=r,s=Object.fromEntries(Object.entries(o).map(([e,t])=>[e,[...t]])),c=await t.signTypedData(n,s,i);if(!j(c))throw TypeError(`Expected hex string, got: ${c}`);return c}async writeContract(e){let t=await this.#a(),n=new N(e.address,e.abi,t),r={};e.value!==void 0&&(r.value=e.value),e.gas!==void 0&&(r.gasLimit=e.gas);let i=await n.getFunction(e.functionName)(...e.args,r);if(!j(i.hash))throw TypeError(`Expected hex string, got: ${i.hash}`);return i.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 r=Number(n);if(!(!Number.isSafeInteger(r)||r<=0))return{address:A(t[0]),chainId:r}}};function ce(t){if(`signer`in t&&t.signer){let n=new $({signer:t.signer});if(!t.signer.provider)throw Error(`createConfig requires a Signer with an attached provider for chain reads`);let r=new Z({provider:t.signer.provider});return e(n,r,t)}let n=new $({ethereum:t.ethereum}),r=`provider`in t&&t.provider?new Z({provider:t.provider}):new Z({ethereum:t.ethereum});return e(n,r,t)}export{t as BaseSigner,Z as EthersProvider,$ as EthersSigner,ee as ProviderRpcError,i as ZamaSDKEvents,ce as createConfig,B as readConfidentialBalanceOfContract,ae as readConfidentialTokenAddressContract,se as readIsConfidentialTokenValidContract,H as readSupportsInterfaceContract,oe as readTokenAddressContract,ie as readTokenPairContract,Y as readTokenPairsContract,X as readTokenPairsLengthContract,re as readTokenPairsSliceContract,V as readUnderlyingTokenContract,U as writeConfidentialTransferContract,K as writeFinalizeUnwrapContract,q as writeSetOperatorContract,W as writeUnwrapContract,G as writeUnwrapFromBalanceContract,J as writeWrapContract};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,8 +1,8 @@
1
- import{a as e,c as t,i as n,n as r,s as i}from"./telemetry-CW2RgPxb.js";import{S as a,b as o,t as s}from"./relayer-Cki3j_Ba.js";import{n as c}from"./encryption-QHaWnnx-.js";import{createPublicClient as l,custom as u,http as d}from"viem";import{createUnsignedLegacyDecryptionPermitEip712 as f}from"@fhevm/sdk/actions/base";import{createFhevmBaseClient as p,createFhevmDecryptClient as ee,createFhevmEncryptClient as te,hasFhevmRuntimeConfig as m}from"@fhevm/sdk/viem";import{createFhevmCleartextBaseClient as ne,createFhevmCleartextDecryptClient as h,createFhevmCleartextEncryptClient as re}from"@fhevm/sdk/viem/cleartext";function g(e){return{id:e.id,fhevm:{contracts:{acl:{address:e.aclContractAddress},inputVerifier:{address:e.inputVerifierContractAddress},kmsVerifier:{address:e.kmsContractAddress},protocolConfig:void 0,kmsGeneration:e.keyVerification&&`contract`in e.keyVerification?{address:e.keyVerification.contract}:void 0},relayerUrl:e.relayerUrl,gateway:{id:e.gatewayChainId,contracts:{decryption:{address:e.verifyingContractAddressDecryption},inputVerification:{address:e.verifyingContractAddressInputVerification}}}}}}
1
+ import{a as e,c as t,i as n,n as r,s as i}from"./telemetry-DgZG8yT6.js";import{S as a,b as o,t as s}from"./relayer-Cki3j_Ba.js";import{n as c}from"./encryption-QHaWnnx-.js";import{createPublicClient as l,custom as u,http as d}from"viem";import{createUnsignedLegacyDecryptionPermitEip712 as f}from"@fhevm/sdk/actions/base";import{createFhevmBaseClient as p,createFhevmDecryptClient as ee,createFhevmEncryptClient as te,hasFhevmRuntimeConfig as m}from"@fhevm/sdk/viem";import{createFhevmCleartextBaseClient as ne,createFhevmCleartextDecryptClient as h,createFhevmCleartextEncryptClient as re}from"@fhevm/sdk/viem/cleartext";function g(e){return{id:e.id,fhevm:{contracts:{acl:{address:e.aclContractAddress},inputVerifier:{address:e.inputVerifierContractAddress},kmsVerifier:{address:e.kmsContractAddress},protocolConfig:void 0,kmsGeneration:e.keyVerification&&`contract`in e.keyVerification?{address:e.keyVerification.contract}:void 0},relayerUrl:e.relayerUrl,gateway:{id:e.gatewayChainId,contracts:{decryption:{address:e.verifyingContractAddressDecryption},inputVerification:{address:e.verifyingContractAddressInputVerification}}}}}}
2
2
  /**
3
3
  * @license
4
4
  * Copyright 2019 Google LLC
5
5
  * SPDX-License-Identifier: Apache-2.0
6
6
  */
7
7
  const _=Symbol(`Comlink.proxy`),ie=Symbol(`Comlink.endpoint`),ae=Symbol(`Comlink.releaseProxy`),v=Symbol(`Comlink.finalizer`),y=Symbol(`Comlink.thrown`),b=e=>typeof e==`object`&&!!e||typeof e==`function`,x=/* @__PURE__ */ new Map([[`proxy`,{canHandle:e=>b(e)&&e[_],serialize(e){let{port1:t,port2:n}=new MessageChannel;return S(e,t),[n,[n]]},deserialize(e){return e.start(),T(e)}}],[`throw`,{canHandle:e=>b(e)&&y in e,serialize({value:e}){let t;return t=e instanceof Error?{isError:!0,value:{message:e.message,name:e.name,stack:e.stack}}:{isError:!1,value:e},[t,[]]},deserialize(e){throw e.isError?Object.assign(Error(e.value.message),e.value):e.value}}]]);function oe(e,t){for(let n of e)if(t===n||n===`*`||n instanceof RegExp&&n.test(t))return!0;return!1}function S(e,t=globalThis,n=[`*`]){t.addEventListener(`message`,function r(i){if(!i||!i.data)return;if(!oe(n,i.origin)){console.warn(`Invalid origin '${i.origin}' for comlink proxy`);return}let{id:a,type:o,path:s}=Object.assign({path:[]},i.data),c=(i.data.argumentList||[]).map(L),l;try{let t=s.slice(0,-1).reduce((e,t)=>e[t],e),n=s.reduce((e,t)=>e[t],e);switch(o){case`GET`:l=n;break;case`SET`:t[s.slice(-1)[0]]=L(i.data.value),l=!0;break;case`APPLY`:l=n.apply(t,c);break;case`CONSTRUCT`:l=F(new n(...c));break;case`ENDPOINT`:{let{port1:t,port2:n}=new MessageChannel;S(e,n),l=P(t,[t])}break;case`RELEASE`:l=void 0;break;default:return}}catch(e){l={value:e,[y]:0}}Promise.resolve(l).catch(e=>({value:e,[y]:0})).then(n=>{let[i,s]=I(n);t.postMessage(Object.assign(Object.assign({},i),{id:a}),s),o===`RELEASE`&&(t.removeEventListener(`message`,r),w(t),v in e&&typeof e[v]==`function`&&e[v]())}).catch(e=>{let[n,r]=I({value:/* @__PURE__ */ TypeError(`Unserializable return value`),[y]:0});t.postMessage(Object.assign(Object.assign({},n),{id:a}),r)})}),t.start&&t.start()}function C(e){return e.constructor.name===`MessagePort`}function w(e){C(e)&&e.close()}function T(e,t){let n=/* @__PURE__ */ new Map;return e.addEventListener(`message`,function(e){let{data:t}=e;if(!t||!t.id)return;let r=n.get(t.id);if(r)try{r(t)}finally{n.delete(t.id)}}),j(e,n,[],t)}function E(e){if(e)throw Error(`Proxy has been released and is not useable`)}function D(e){return R(e,/* @__PURE__ */ new Map,{type:`RELEASE`}).then(()=>{w(e)})}const O=/* @__PURE__ */ new WeakMap,k=`FinalizationRegistry`in globalThis&&new FinalizationRegistry(e=>{let t=(O.get(e)||0)-1;O.set(e,t),t===0&&D(e)});function se(e,t){let n=(O.get(t)||0)+1;O.set(t,n),k&&k.register(e,t,e)}function A(e){k&&k.unregister(e)}function j(e,t,n=[],r=function(){}){let i=!1,a=new Proxy(r,{get(r,o){if(E(i),o===ae)return()=>{A(a),D(e),t.clear(),i=!0};if(o===`then`){if(n.length===0)return{then:()=>a};let r=R(e,t,{type:`GET`,path:n.map(e=>e.toString())}).then(L);return r.then.bind(r)}return j(e,t,[...n,o])},set(r,a,o){E(i);let[s,c]=I(o);return R(e,t,{type:`SET`,path:[...n,a].map(e=>e.toString()),value:s},c).then(L)},apply(r,a,o){E(i);let s=n[n.length-1];if(s===ie)return R(e,t,{type:`ENDPOINT`}).then(L);if(s===`bind`)return j(e,t,n.slice(0,-1));let[c,l]=M(o);return R(e,t,{type:`APPLY`,path:n.map(e=>e.toString()),argumentList:c},l).then(L)},construct(r,a){E(i);let[o,s]=M(a);return R(e,t,{type:`CONSTRUCT`,path:n.map(e=>e.toString()),argumentList:o},s).then(L)}});return se(a,e),a}function ce(e){return Array.prototype.concat.apply([],e)}function M(e){let t=e.map(I);return[t.map(e=>e[0]),ce(t.map(e=>e[1]))]}const N=/* @__PURE__ */ new WeakMap;function P(e,t){return N.set(e,t),e}function F(e){return Object.assign(e,{[_]:!0})}function I(e){for(let[t,n]of x)if(n.canHandle(e)){let[r,i]=n.serialize(e);return[{type:`HANDLER`,name:t,value:r},i]}return[{type:`RAW`,value:e},N.get(e)||[]]}function L(e){switch(e.type){case`HANDLER`:return x.get(e.name).deserialize(e.value);case`RAW`:return e.value}}function R(e,t,n,r){return new Promise(i=>{let a=le();t.set(a,i),e.start&&e.start(),e.postMessage(Object.assign({id:a},n),r)})}function le(){return[,,,,].fill(0).map(()=>Math.floor(Math.random()*(2**53-1)).toString(16)).join(`-`)}function z(e){return typeof e==`object`&&!!e&&e.wireError===!0}const B=[`statusCode`,`status`,`retryAfter`,`timeoutMs`,`relayerApiError`,`code`,`data`,`shortMessage`,`details`,`error`,`info`];function V(e){try{return structuredClone(e),!0}catch{return!1}}function H(e){let t=e.response;return a(t?.headers)}function U(e){try{return JSON.stringify(e)??String(e)}catch{return String(e)}}function W(e){let t={};for(let n of B){let r=e[n];r!==void 0&&V(r)&&(t[n]=r)}if(!o(t.retryAfter)){let n=H(e);n!==void 0&&(t.retryAfter=n)}return t}function G(e,t=6){if(z(e))return e;let n=e=>t>0&&e!==void 0?G(e,t-1):void 0;if(e instanceof Error)return{wireError:!0,name:e.name,message:e.message,stack:e.stack,props:W(e),cause:n(e.cause)};if(typeof e==`object`&&e){let{message:t,cause:r}=e;return{wireError:!0,name:`Error`,message:typeof t==`string`?t:U(e),stack:void 0,props:W(e),cause:n(r)}}return{wireError:!0,name:`Error`,message:typeof e==`string`?e:U(e),stack:void 0,props:{},cause:void 0}}function K(e){let t=Error(e.message,e.cause?{cause:K(e.cause)}:{});return t.name=e.name,e.stack!==void 0&&(t.stack=e.stack),Object.assign(t,e.props),t}function ue(){return new Worker(new URL(`./encrypt.worker.js`,import.meta.url),{type:`module`,name:`zama-fhe-encrypt`})}const q={spawn:1e4,init:3e5},J=/* @__PURE__ */ new WeakSet;var Y=class extends Error{crashed;constructor(e,t){super(e,t),this.name=`WorkerUnavailableError`,this.crashed=t?.crashed??!1}};function de(e){if(typeof e!=`object`||!e)return!1;let{name:t,message:n}=e;return t===`DataCloneError`||t===`TypeError`&&typeof n==`string`&&n.includes(`Unserializable return value`)}function X(e){if(e?.aborted)throw e.reason??new DOMException(`The operation was aborted.`,`AbortError`)}const Z={count:0,last:void 0,warnedFor:-1};function fe(e){if(e===void 0)return{key:e,transfers:[]};let t=e.publicKeyBytes.bytes,n=e.crsBytes.bytes;if(!(t instanceof Uint8Array)||!(n instanceof Uint8Array))return{key:e,transfers:[]};let r=t.slice(),i=n.slice();return{key:{...e,publicKeyBytes:{...e.publicKeyBytes,bytes:r},crsBytes:{...e.crsBytes,bytes:i}},transfers:[r.buffer,i.buffer]}}function pe(){let e,t=new Promise((t,n)=>{e=n});return t.catch(()=>{}),{initPromise:void 0,worker:void 0,api:void 0,doomed:t,doom:e}}var me=class{#e;#t;#n=!1;#r=Z;#i=0;#a=/* @__PURE__ */ new Map;#o;#s=0;#c=!1;constructor(e){this.#e=e}init=()=>{let e=this.#t??=pe();if(e.initPromise===void 0){let t=this.#f(()=>this.#u(e)).catch(n=>{throw e.initPromise===t&&(e.initPromise=void 0),n});e.initPromise=t}return e.initPromise};encryptValue=e=>this.#f(()=>this.#l(t=>t.encryptValue(e),(t,n,r)=>t.encryptValue(n,{...e,options:r}),e.options));encryptValues=e=>this.#f(()=>this.#l(t=>t.encryptValues(e),(t,n,r)=>t.encryptValues(n,{...e,options:r}),e.options));dispose(){this.#c=!0,this.#p()}async#l(e,t,n){let{signal:r,onProgress:i,...a}=n??{};X(r),await this.init(),X(r);let o=this.#t,s=o?.api;if(this.#o!==void 0&&(this.#n||s===void 0))return e(await this.#o);if(o===void 0||s===void 0)return e(await this.#b(o,this.#r.last??new Y(`Encrypt worker not running.`)));let c=this.#i++,l=()=>void s.abort(c).catch(()=>{});r?.addEventListener(`abort`,l,{once:!0}),i&&this.#a.set(c,i);try{let e=await this.#v(o,t(s,c,a));return this.#r=Z,e}catch(t){if(t instanceof Y)return e(await this.#b(o,t));throw t}finally{this.#a.delete(c),r?.removeEventListener(`abort`,l)}}async#u(e){if(this.#n)return;let t=this.#e.blockedReason;if(t!==void 0){await this.#b(e,new Y(t));return}let n=await this.#e.prefetchKey();try{let t=await this.#h(e),{network:r,keyVerification:i}=this.#e,a=typeof r==`string`?null:F(async e=>{try{return await r.request(e)}catch(e){throw G(e)}}),o=F((e,t)=>{try{this.#e.logger[e](t)}catch(e){this.#d(`logger`,e)}}),s=F((e,t)=>{try{this.#a.get(e)?.(t)}catch(e){this.#d(`onProgress`,e)}}),c=fe(n);await this.#v(e,t.init(P({...this.#e.initPayload,clientOptions:{...this.#e.initPayload.clientOptions,fheEncryptionKey:c.key},rpcUrl:typeof r==`string`?r:void 0,keyVerification:i&&typeof i.network==`string`?{chain:i.chain,rpcUrl:i.network}:void 0},c.transfers),a,o,s),{ms:this.#e.timeouts.init,operation:`init`}),e.api=t,this.#r={...this.#r,last:void 0}}catch(t){if(!(t instanceof Y))throw this.#y(e,new Y(`Encrypt worker init failed.`)),t;await this.#b(e,t)}}#d(e,t){let n=t instanceof Error?t.message:String(t);try{this.#e.logger.warn(`Encrypt offload ${e} callback threw: ${n}`)}catch{}}async#f(e){this.#s++;try{return await e()}finally{this.#s--,this.#p()}}#p(){!this.#c||this.#s>0||(this.#c=!1,this.#t?.worker?.terminate(),this.#t=void 0,this.#o=void 0,this.#n=!1,this.#r=Z)}#m(){let e=this.#e.workerSource;if(e===void 0)return ue();if(typeof e==`function`){let t=e();return J.has(t)&&this.#e.logger.warnAlways(`The offloadWorker factory returned a worker it already handed out; each call must construct a fresh Worker.`),J.add(t),t}return new Worker(e,{type:`module`,name:`zama-fhe-encrypt`})}async#h(e){let t;try{t=this.#m()}catch(e){throw new Y(e instanceof Error?e.message:String(e),{cause:e})}e.worker=t;let n=await this.#g(e,t);return this.#_(e,t),n}#g(e,t){return new Promise((n,r)=>{let i=()=>{clearTimeout(a),t.removeEventListener(`message`,o),t.removeEventListener(`error`,s)},a=setTimeout(()=>{i(),r(new Y(`Encrypt worker did not start within ${this.#e.timeouts.spawn}ms.`))},this.#e.timeouts.spawn),o=e=>{e.data===`zama-encrypt-worker-ready`&&(i(),n(T(t)))},s=t=>{i();let n=t.message||`Encrypt worker error.`;r(new Y(n)),this.#y(e,new Y(n))};t.addEventListener(`message`,o),t.addEventListener(`error`,s)})}#_(e,t){t.addEventListener(`error`,t=>{if(this.#t!==e)return;let n=new Y(t.message||`Encrypt worker error.`,{crashed:!0});this.#r={...this.#r,count:this.#r.count+1,last:n},this.#y(e,n)})}async#v(e,t,n){let r=n===void 0?void 0:setTimeout(()=>{this.#y(e,new Y(`Encrypt worker ${n.operation} timed out after ${n.ms}ms.`))},n.ms);try{return await Promise.race([t.catch(e=>{let t=z(e)?K(e):e;throw de(t)?new Y(t.message,{cause:t}):t}),e.doomed])}finally{r!==void 0&&clearTimeout(r)}}#y(e,t){e!==void 0&&(this.#t===e&&(this.#t=void 0),e.worker?.terminate(),e.worker=void 0,e.api=void 0,e.initPromise=void 0,e.doom(t))}async#b(e,t){let n=t instanceof Error?t.message:String(t);if(this.#e.strict)throw this.#y(e,new Y(`Encrypt worker unavailable.`)),new c(`Encrypt offload required (offloadEncrypt: true) but unavailable: ${n}`,{cause:t});let{transient:r,pinning:i}=this.#x(t);if(this.#n||=!r,this.#y(e,new Y(`Encrypt worker degraded to inline.`)),this.#S(n,r,i),this.#o===void 0){let e=(async()=>{let e=this.#e.createInlineClient();return await e.init(),e})().catch(t=>{throw this.#o===e&&(this.#o=void 0),this.#e.logger.warnAlways(`Encrypt inline fallback failed to initialize: ${t instanceof Error?t.message:String(t)}`),t});this.#o=e}return this.#o}#x(e){let t=e instanceof Y&&e.crashed&&this.#r.count<2;return{transient:t,pinning:!t&&!this.#n}}#S(e,t,n){if(!n&&this.#r.warnedFor===this.#r.count)return;this.#r={...this.#r,warnedFor:this.#r.count};let r=t?`in-flight encryption falls back`:`encryption falls back`;this.#e.logger.warnAlways(`Encrypt offload unavailable, ${r} to the calling thread: ${e}`)}},he=class{#e;#t;#n;#r;#i;#a;#o;constructor(e){e.cleartext||i(e.chain),this.#e=e.chain;let{timeout:n,debug:r,batchRpcCalls:a,moduleVersions:o,fheEncryptionKey:s}=e.options??{},c=this.#e.auth?$(this.#e.auth):void 0,u=t(this.#e),d={publicClient:l({transport:Q(this.#e.network)}),chain:g(this.#e),options:{batchRpcCalls:a,moduleVersions:o,fheEncryptionKey:s,keyVerification:u&&{chain:g(u),client:l({transport:Q(u.network)})}}};this.#i={...c!==void 0&&{auth:c},...n!==void 0&&{timeout:n},...r!==void 0&&{debug:r}},this.#a=e.telemetry;let f=()=>this.#t.fetchFheEncryptionKeyBytes({options:this.#c(void 0)}),m=e=>({init:async()=>{await f(),await e.init()},encryptValue:t=>e.encryptValue(t),encryptValues:t=>e.encryptValues(t),fetchFheEncryptionKeyBytes:t=>e.fetchFheEncryptionKeyBytes(t)});e.cleartext?(this.#t=ne(d),this.#n=h(d),this.#r=m(re(d))):(this.#t=p(d),this.#n=ee(d),this.#r=this.#s(e,d,{prefetchKey:f,createInlineClient:()=>m(te(d))}))}#s(e,r,i){let a=e.offloadEncrypt??!1,o=a===!0,s=typeof Worker==`function`&&(e.offloadWorker!==void 0||!0);if(a===!1||!(o||s))return i.createInlineClient();let c=n(),{keyVerification:l,...u}=r.options,d=t(this.#e),f=_e(c,d?.network);if(f!==void 0&&!o)return e.logger.warnAlways(`Encryption runs on the calling thread: ${f}.`),i.createInlineClient();let p=new me({initPayload:{chain:r.chain,clientOptions:u,runtime:c??{}},network:this.#e.network,keyVerification:d&&{chain:g(d),network:d.network},prefetchKey:i.prefetchKey,createInlineClient:i.createInlineClient,logger:e.logger,timeouts:e.offloadTimeouts??q,workerSource:e.offloadWorker,blockedReason:f,strict:o});return{init:()=>p.init(),encryptValue:e=>p.encryptValue(e),encryptValues:e=>p.encryptValues(e),fetchFheEncryptionKeyBytes:e=>this.#t.fetchFheEncryptionKeyBytes(e),dispose:()=>p.dispose()}}get chain(){return this.#e}#c(e){let{operation:t,...n}={...this.#i,...e};if(this.#a===void 0)return n;let{headers:i,query:a}=r(this.#a,t);return{...n,...i&&{headers:{...n.headers,...i}},...a&&{query:{...n.query,...a}}}}#l=()=>(this.#o??=this.#r.init().catch(e=>{throw this.#o=void 0,e}),this.#o);dispose=()=>{this.#o=void 0,this.#r.dispose?.()};decryptPublicValue=async e=>(await this.#t.init(),this.#t.decryptPublicValue({...e,options:this.#c(e.options)}));decryptPublicValues=async e=>(await this.#t.init(),this.#t.decryptPublicValues({...e,options:this.#c(e.options)}));decryptPublicValuesWithSignatures=async e=>(await this.#t.init(),this.#t.decryptPublicValuesWithSignatures({...e,options:this.#c(e.options)}));encryptValue=async e=>(await this.#l(),this.#r.encryptValue({...e,options:this.#c(e.options)}));encryptValues=async e=>(await this.#l(),this.#r.encryptValues({...e,options:this.#c(e.options)}));decryptValue=async e=>(await this.#n.init(),this.#n.decryptValue({...e,options:this.#c(e.options)}));decryptValues=async e=>(await this.#n.init(),this.#n.decryptValues({...e,options:this.#c(e.options)}));decryptValuesFromPairs=async e=>(await this.#n.init(),this.#n.decryptValuesFromPairs({...e,options:this.#c(e.options)}));fetchFheEncryptionKeyBytes=async e=>(await this.#t.init(),this.#t.fetchFheEncryptionKeyBytes({...e,options:this.#c(e?.options)}));signDecryptionPermit=async e=>(await this.#t.init(),this.#t.signDecryptionPermit(e));createUnsignedLegacyDecryptionPermitEip712=e=>f(this.#t,e);serializeTransportKeyPair=e=>this.#n.serializeTransportKeyPair(e);serializeSignedDecryptionPermit=e=>this.#t.serializeSignedDecryptionPermit(e);parseTransportKeyPair=async e=>(await this.#n.init(),this.#n.parseTransportKeyPair(e));parseSignedDecryptionPermit=async e=>{await this.#t.init();let{serializedPermit:t}=e;return this.#t.parseSignedDecryptionPermit({...e,serializedPermit:{...t,signature:ge(t.signature)}})};generateTransportKeyPair=async()=>(await this.#n.init(),this.#n.generateTransportKeyPair())};function ge(e){if(e.length!==132)return e;let t=parseInt(e.slice(130),16);return t!==0&&t!==1?e:`${e.slice(0,130)}${t===0?`1b`:`1c`}`}function Q(e){return typeof e==`string`?d(e):u(e)}function _e(t,n){if(e())return`a runtime locateFile cannot cross the encrypt worker boundary`;if(t===void 0&&m())return`a runtime config set outside createConfig cannot be replicated in the encrypt worker realm`;if(n!==void 0&&typeof n!=`string`)return`an EIP-1193 provider on the keyVerification chain cannot cross the encrypt worker boundary`}function $(e){let t=e.__type;switch(t){case`ApiKeyHeader`:return{type:t,value:e.value,header:e.header};case`BearerToken`:return{type:t,token:e.token};default:throw new s(`Unknown auth type: ${String(t)}`)}}export{$ as n,q as r,he as t};
8
- //# sourceMappingURL=fhevm-relayer-DCQ-Oaa1.js.map
8
+ //# sourceMappingURL=fhevm-relayer-BRF_qaSG.js.map