@zama-fhe/sdk 2.2.0 → 2.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.
@@ -1,2 +1,2 @@
1
- import{t as e}from"./relayer-DxMV-NQT.js";import{n as t,t as n}from"./encryption-CKqGKzHs.js";import{n as r}from"./relayer-utils-BeoTNDM4.js";import{concat as i,createPublicClient as a,custom as o,encodePacked as s,getAddress as c,http as l,keccak256 as u,pad as d,parseAbi as f,toBytes as p,toHex as m}from"viem";import{privateKeyToAccount as h}from"viem/accounts";import{mainnet as g,sepolia as _}from"viem/chains";const v=(e,t)=>({name:`InputVerification`,version:`1`,chainId:Number(e),verifyingContract:t}),y=(e,t)=>({name:`Decryption`,version:`1`,chainId:Number(e),verifyingContract:t}),b={domain:v,types:{CiphertextVerification:[{name:`ctHandles`,type:`bytes32[]`},{name:`userAddress`,type:`address`},{name:`contractAddress`,type:`address`},{name:`contractChainId`,type:`uint256`},{name:`extraData`,type:`bytes`}]}},x={domain:y,types:{PublicDecryptVerification:[{name:`ctHandles`,type:`bytes32[]`},{name:`decryptedResult`,type:`bytes`},{name:`extraData`,type:`bytes`}]}},S={domain:y,types:{UserDecryptRequestVerification:[{name:`publicKey`,type:`bytes`},{name:`contractAddresses`,type:`address[]`},{name:`startTimestamp`,type:`uint256`},{name:`durationDays`,type:`uint256`},{name:`extraData`,type:`bytes`}]}},C={domain:y,types:{DelegatedUserDecryptRequestVerification:[{name:`publicKey`,type:`bytes`},{name:`contractAddresses`,type:`address[]`},{name:`delegatorAddress`,type:`address`},{name:`startTimestamp`,type:`uint256`},{name:`durationDays`,type:`uint256`},{name:`extraData`,type:`bytes`}]}},w={ebool:0,euint8:2,euint16:3,euint32:4,euint64:5,euint128:6,eaddress:7,euint256:8},T={0:`ebool`,2:`euint8`,3:`euint16`,4:`euint32`,5:`euint64`,6:`euint128`,7:`eaddress`,8:`euint256`},E={0:2,2:8,3:16,4:32,5:64,6:128,7:160,8:256};Object.freeze(w),Object.freeze(T),Object.freeze(E),Object.freeze({2:0,8:2,16:3,32:4,64:5,128:6,160:7,256:8});function D(e){switch(e){case 0:case 2:case 3:case 4:case 5:case 6:case 7:case 8:return!0;default:return!1}}function O(e){return typeof e==`string`?e in w:!1}function k(e){if(!O(e))throw Error(`Invalid FheType name '${e}'`);return w[e]}function A(e){if(!D(e))throw Error(`Invalid FheType id '${e}'`);let t=E[e];if(t<2)throw Error(`Invalid FheType encryption bit width: ${t}. Minimum is 2 bits.`);return t}const j=p(`ZK-w_rct`),M=p(`ZK-w_hdl`);function N(e,t){let n=Math.ceil(A(t)/8);return p(d(m(e),{size:n}))}function P(e,n,r){if(r.length!==32)throw new t(`random32 must be exactly 32 bytes`);let a=N(n,e),o=u(i([m(new Uint8Array([e])),m(a),m(r)]));return u(i([m(j),o]))}function F(e,n,r,a,o){if(!Number.isInteger(n)||n<0||n>255)throw new t(`index must be an integer between 0 and 255`);let c=u(i([m(j),e])),l=u(s([`bytes`,`bytes32`,`uint8`,`address`,`uint256`],[m(M),c,n,a,o])),d=o&18446744073709551615n;return m(BigInt(l)&115792089237316195423570985008687907853269984665640254554447762662844404858880n|BigInt(n)<<80n|d<<16n|BigInt(r)<<8n|BigInt(0),{size:32})}const I=f([`function persistAllowed(bytes32 handle, address account) view returns (bool)`,`function isAllowedForDecryption(bytes32 handle) view returns (bool)`,`function isHandleDelegatedForUserDecryption(address delegator, address delegate, address contractAddress, bytes32 handle) view returns (bool)`]),L=f([`function plaintexts(bytes32 handle) view returns (uint256)`]),R=[{name:`name`,type:`string`},{name:`version`,type:`string`},{name:`chainId`,type:`uint256`},{name:`verifyingContract`,type:`address`}],z={EIP712Domain:R,UserDecryptRequestVerification:S.types.UserDecryptRequestVerification},B={EIP712Domain:R,DelegatedUserDecryptRequestVerification:C.types.DelegatedUserDecryptRequestVerification},V={EIP712Domain:R,PublicDecryptVerification:x.types.PublicDecryptVerification},H=new Set([g.id,_.id]);function U(e,t){let n=Number(BigInt(e)>>8n&255n);return n===0?t!==0n:n===7?m(t,{size:20}):t}function W(e){if(!O(e.type))throw new t(`Unsupported FHE type`);let n=k(e.type),r;if(e.type===`ebool`){if(typeof e.value==`boolean`)r=e.value?1n:0n;else if(r=e.value,r!==0n&&r!==1n)throw new t(`Bool value must be 0, 1, true, or false`)}else r=e.type===`eaddress`?BigInt(c(e.value)):e.value;if(r<0n)throw new t(`Only non-negative cleartext values are supported`);let i=A(n),a=(1n<<BigInt(i))-1n;if(r>a)throw new t(`Value ${r} exceeds max ${a} for FheType ${n}`);return{fheType:n,value:r}}var G=class{#e;#t;kmsSigner;inputSigner;constructor(t){if(H.has(t.chainId))throw new e(`Cleartext mode is not allowed on chain ${t.chainId}. It is intended for local development and testing only.`);this.#e=a({transport:typeof t.network==`string`?l(t.network):o(t.network)}),this.#t=t,this.kmsSigner=h(t.kmsSignerPrivateKey??`0x388b7680e4e1afa06efbfd45cdd1fe39f3c6af381df6555a19661f283b97de91`),this.inputSigner=h(t.inputSignerPrivateKey??`0x7ec8ada6642fc4ccfb7729bc29c17cf8d21b61abd5642d1db992c0b8672ab901`)}async generateKeypair(){let e=m(crypto.getRandomValues(new Uint8Array(32))),t=m(crypto.getRandomValues(new Uint8Array(32)));for(;t===e;)t=m(crypto.getRandomValues(new Uint8Array(32)));return{publicKey:e,privateKey:t}}async createEIP712(e,t,n,r=7){return{domain:S.domain(this.#t.chainId,this.#t.verifyingContractAddressDecryption),types:z,primaryType:`UserDecryptRequestVerification`,message:{publicKey:e,contractAddresses:t,startTimestamp:BigInt(n),durationDays:BigInt(r),extraData:`0x00`}}}async encrypt(e){let t=e.values.map(W),n=c(e.contractAddress),r=c(e.userAddress),a=t.map(({fheType:e,value:t})=>P(e,t,crypto.getRandomValues(new Uint8Array(32)))),o=u(a.length>0?i(a):`0x`),s=t.map(({fheType:e},t)=>F(o,t,e,this.#t.aclContractAddress,BigInt(this.#t.chainId))),l=t.map(({value:e})=>d(m(e),{size:32})),f=l.length>0?i(l):`0x`,h=await this.inputSigner.signTypedData({domain:b.domain(this.#t.gatewayChainId,this.#t.verifyingContractAddressInputVerification),types:{CiphertextVerification:b.types.CiphertextVerification},primaryType:`CiphertextVerification`,message:{ctHandles:s,userAddress:r,contractAddress:n,contractChainId:BigInt(this.#t.chainId),extraData:f}}),g=p(i([m(new Uint8Array([s.length])),m(new Uint8Array([1])),...s,h,f]));return{handles:s.map(e=>p(e)),inputProof:g}}async userDecrypt(e){return await this.#r(e.handles,c(e.signerAddress),c(e.contractAddress),`User`,`user decrypt`),this.#n(e.handles)}async publicDecrypt(e){let t=e,r=(await Promise.all(t.map(e=>this.#o(e)))).findIndex(e=>!e);if(r!==-1)throw new n(`Handle ${t[r]} is not allowed for public decryption`);let a=await Promise.all(t.map(e=>this.#s(e))),o=Object.fromEntries(t.map((e,t)=>[e,U(e,a[t])])),s=i(a.map(e=>d(m(e),{size:32}))),c=await this.kmsSigner.signTypedData({domain:x.domain(this.#t.gatewayChainId,this.#t.verifyingContractAddressDecryption),types:V,primaryType:`PublicDecryptVerification`,message:{ctHandles:t,decryptedResult:s,extraData:`0x`}});return{clearValues:o,abiEncodedClearValues:s,decryptionProof:i([m(new Uint8Array([1])),c])}}async createDelegatedUserDecryptEIP712(e,t,n,r,i=7){let a={publicKey:e,contractAddresses:t,delegatorAddress:c(n),startTimestamp:String(r),durationDays:String(i),extraData:`0x00`};return{domain:C.domain(BigInt(this.#t.chainId),this.#t.verifyingContractAddressDecryption),types:B,primaryType:`DelegatedUserDecryptRequestVerification`,message:a}}async delegatedUserDecrypt(e){return await this.#i(e.handles,c(e.delegatorAddress),c(e.delegateAddress),c(e.contractAddress)),this.#n(e.handles)}async requestZKProofVerification(t){throw new e(`Not implemented in cleartext mode`)}async getPublicKey(){return{publicKeyId:`mock-public-key-id`,publicKey:new Uint8Array([32])}}async getPublicParams(e){return{publicParams:new Uint8Array([32]),publicParamsId:`mock-public-params-id`}}async getAclAddress(){return this.#t.aclContractAddress}terminate(){}async#n(e){let t=await Promise.all(e.map(e=>this.#s(e)));return Object.fromEntries(e.map((e,n)=>[e,U(e,t[n])]))}async#r(e,t,r,i,a){if(t===r)throw new n(`${i} address ${t} must not equal contract address for ${a}`);let o=await Promise.all(e.flatMap(e=>[this.#a(e,t),this.#a(e,r)]));for(let s=0;s<e.length;s++){let c=o[s*2],l=o[s*2+1];if(!c)throw new n(`${i} ${t} is not authorized for ${a} of handle ${e[s]}`);if(!l)throw new n(`Contract ${r} is not authorized for ${a} of handle ${e[s]}`)}}async#i(e,t,r,i){let a=await Promise.all(e.map(e=>this.#e.readContract({address:this.#t.aclContractAddress,abi:I,functionName:`isHandleDelegatedForUserDecryption`,args:[t,r,i,e]})));for(let t=0;t<e.length;t++)if(!a[t])throw new n(`Handle ${e[t]} is not delegated for user decryption`)}async#a(e,t){return this.#e.readContract({address:this.#t.aclContractAddress,abi:I,functionName:`persistAllowed`,args:[e,t]})}async#o(e){return this.#e.readContract({address:this.#t.aclContractAddress,abi:I,functionName:`isAllowedForDecryption`,args:[e]})}async#s(e){return this.#e.readContract({address:this.#t.executorAddress,abi:L,functionName:`plaintexts`,args:[e]})}};const K={...r,executorAddress:`0xe3a9105a3a932253A70F126eb1E3b589C643dD24`},q={chainId:560048,network:`https://rpc.hoodi.ethpandaops.io`,gatewayChainId:r.gatewayChainId,aclContractAddress:`0x6D3FAf6f86e1fF9F3B0831Dda920AbA1cBd5bd68`,executorAddress:`0xC316692627de536368d82e9121F1D44a550894E6`,verifyingContractAddressDecryption:r.verifyingContractAddressDecryption,verifyingContractAddressInputVerification:r.verifyingContractAddressInputVerification,registryAddress:`0x1807aE2f693F8530DFB126D0eF98F2F2518F292f`};export{q as n,G as r,K as t};
2
- //# sourceMappingURL=cleartext-DuOGGACw.js.map
1
+ import{t as e}from"./relayer-DfjPWTBf.js";import{n as t,t as n}from"./encryption-UaXE1L_W.js";import{n as r}from"./relayer-utils-BeoTNDM4.js";import{concat as i,createPublicClient as a,custom as o,encodePacked as s,getAddress as c,http as l,keccak256 as u,pad as d,parseAbi as f,toBytes as p,toHex as m}from"viem";import{privateKeyToAccount as h}from"viem/accounts";import{mainnet as g,sepolia as _}from"viem/chains";const v=(e,t)=>({name:`InputVerification`,version:`1`,chainId:Number(e),verifyingContract:t}),y=(e,t)=>({name:`Decryption`,version:`1`,chainId:Number(e),verifyingContract:t}),b={domain:v,types:{CiphertextVerification:[{name:`ctHandles`,type:`bytes32[]`},{name:`userAddress`,type:`address`},{name:`contractAddress`,type:`address`},{name:`contractChainId`,type:`uint256`},{name:`extraData`,type:`bytes`}]}},x={domain:y,types:{PublicDecryptVerification:[{name:`ctHandles`,type:`bytes32[]`},{name:`decryptedResult`,type:`bytes`},{name:`extraData`,type:`bytes`}]}},S={domain:y,types:{UserDecryptRequestVerification:[{name:`publicKey`,type:`bytes`},{name:`contractAddresses`,type:`address[]`},{name:`startTimestamp`,type:`uint256`},{name:`durationDays`,type:`uint256`},{name:`extraData`,type:`bytes`}]}},C={domain:y,types:{DelegatedUserDecryptRequestVerification:[{name:`publicKey`,type:`bytes`},{name:`contractAddresses`,type:`address[]`},{name:`delegatorAddress`,type:`address`},{name:`startTimestamp`,type:`uint256`},{name:`durationDays`,type:`uint256`},{name:`extraData`,type:`bytes`}]}},w={ebool:0,euint8:2,euint16:3,euint32:4,euint64:5,euint128:6,eaddress:7,euint256:8},T={0:`ebool`,2:`euint8`,3:`euint16`,4:`euint32`,5:`euint64`,6:`euint128`,7:`eaddress`,8:`euint256`},E={0:2,2:8,3:16,4:32,5:64,6:128,7:160,8:256};Object.freeze(w),Object.freeze(T),Object.freeze(E),Object.freeze({2:0,8:2,16:3,32:4,64:5,128:6,160:7,256:8});function D(e){switch(e){case 0:case 2:case 3:case 4:case 5:case 6:case 7:case 8:return!0;default:return!1}}function O(e){return typeof e==`string`?e in w:!1}function k(e){if(!O(e))throw Error(`Invalid FheType name '${e}'`);return w[e]}function A(e){if(!D(e))throw Error(`Invalid FheType id '${e}'`);let t=E[e];if(t<2)throw Error(`Invalid FheType encryption bit width: ${t}. Minimum is 2 bits.`);return t}const j=p(`ZK-w_rct`),M=p(`ZK-w_hdl`);function N(e,t){let n=Math.ceil(A(t)/8);return p(d(m(e),{size:n}))}function P(e,n,r){if(r.length!==32)throw new t(`random32 must be exactly 32 bytes`);let a=N(n,e),o=u(i([m(new Uint8Array([e])),m(a),m(r)]));return u(i([m(j),o]))}function F(e,n,r,a,o){if(!Number.isInteger(n)||n<0||n>255)throw new t(`index must be an integer between 0 and 255`);let c=u(i([m(j),e])),l=u(s([`bytes`,`bytes32`,`uint8`,`address`,`uint256`],[m(M),c,n,a,o])),d=o&18446744073709551615n;return m(BigInt(l)&115792089237316195423570985008687907853269984665640254554447762662844404858880n|BigInt(n)<<80n|d<<16n|BigInt(r)<<8n|BigInt(0),{size:32})}const I=f([`function persistAllowed(bytes32 handle, address account) view returns (bool)`,`function isAllowedForDecryption(bytes32 handle) view returns (bool)`,`function isHandleDelegatedForUserDecryption(address delegator, address delegate, address contractAddress, bytes32 handle) view returns (bool)`]),L=f([`function plaintexts(bytes32 handle) view returns (uint256)`]),R=[{name:`name`,type:`string`},{name:`version`,type:`string`},{name:`chainId`,type:`uint256`},{name:`verifyingContract`,type:`address`}],z={EIP712Domain:R,UserDecryptRequestVerification:S.types.UserDecryptRequestVerification},B={EIP712Domain:R,DelegatedUserDecryptRequestVerification:C.types.DelegatedUserDecryptRequestVerification},V={EIP712Domain:R,PublicDecryptVerification:x.types.PublicDecryptVerification},H=new Set([g.id,_.id]);function U(e,t){let n=Number(BigInt(e)>>8n&255n);return n===0?t!==0n:n===7?m(t,{size:20}):t}function W(e){if(!O(e.type))throw new t(`Unsupported FHE type`);let n=k(e.type),r;if(e.type===`ebool`){if(typeof e.value==`boolean`)r=e.value?1n:0n;else if(r=e.value,r!==0n&&r!==1n)throw new t(`Bool value must be 0, 1, true, or false`)}else r=e.type===`eaddress`?BigInt(c(e.value)):e.value;if(r<0n)throw new t(`Only non-negative cleartext values are supported`);let i=A(n),a=(1n<<BigInt(i))-1n;if(r>a)throw new t(`Value ${r} exceeds max ${a} for FheType ${n}`);return{fheType:n,value:r}}var G=class{#e;#t;kmsSigner;inputSigner;constructor(t){if(H.has(t.chainId))throw new e(`Cleartext mode is not allowed on chain ${t.chainId}. It is intended for local development and testing only.`);this.#e=a({transport:typeof t.network==`string`?l(t.network):o(t.network)}),this.#t=t,this.kmsSigner=h(t.kmsSignerPrivateKey??`0x388b7680e4e1afa06efbfd45cdd1fe39f3c6af381df6555a19661f283b97de91`),this.inputSigner=h(t.inputSignerPrivateKey??`0x7ec8ada6642fc4ccfb7729bc29c17cf8d21b61abd5642d1db992c0b8672ab901`)}async generateKeypair(){let e=m(crypto.getRandomValues(new Uint8Array(32))),t=m(crypto.getRandomValues(new Uint8Array(32)));for(;t===e;)t=m(crypto.getRandomValues(new Uint8Array(32)));return{publicKey:e,privateKey:t}}async createEIP712(e,t,n,r=7){return{domain:S.domain(this.#t.chainId,this.#t.verifyingContractAddressDecryption),types:z,primaryType:`UserDecryptRequestVerification`,message:{publicKey:e,contractAddresses:t,startTimestamp:BigInt(n),durationDays:BigInt(r),extraData:`0x00`}}}async encrypt(e){let t=e.values.map(W),n=c(e.contractAddress),r=c(e.userAddress),a=t.map(({fheType:e,value:t})=>P(e,t,crypto.getRandomValues(new Uint8Array(32)))),o=u(a.length>0?i(a):`0x`),s=t.map(({fheType:e},t)=>F(o,t,e,this.#t.aclContractAddress,BigInt(this.#t.chainId))),l=t.map(({value:e})=>d(m(e),{size:32})),f=l.length>0?i(l):`0x`,h=await this.inputSigner.signTypedData({domain:b.domain(this.#t.gatewayChainId,this.#t.verifyingContractAddressInputVerification),types:{CiphertextVerification:b.types.CiphertextVerification},primaryType:`CiphertextVerification`,message:{ctHandles:s,userAddress:r,contractAddress:n,contractChainId:BigInt(this.#t.chainId),extraData:f}}),g=p(i([m(new Uint8Array([s.length])),m(new Uint8Array([1])),...s,h,f]));return{handles:s.map(e=>p(e)),inputProof:g}}async userDecrypt(e){return await this.#r(e.handles,c(e.signerAddress),c(e.contractAddress),`User`,`user decrypt`),this.#n(e.handles)}async publicDecrypt(e){let t=e,r=(await Promise.all(t.map(e=>this.#o(e)))).findIndex(e=>!e);if(r!==-1)throw new n(`Handle ${t[r]} is not allowed for public decryption`);let a=await Promise.all(t.map(e=>this.#s(e))),o=Object.fromEntries(t.map((e,t)=>[e,U(e,a[t])])),s=i(a.map(e=>d(m(e),{size:32}))),c=await this.kmsSigner.signTypedData({domain:x.domain(this.#t.gatewayChainId,this.#t.verifyingContractAddressDecryption),types:V,primaryType:`PublicDecryptVerification`,message:{ctHandles:t,decryptedResult:s,extraData:`0x`}});return{clearValues:o,abiEncodedClearValues:s,decryptionProof:i([m(new Uint8Array([1])),c])}}async createDelegatedUserDecryptEIP712(e,t,n,r,i=7){let a={publicKey:e,contractAddresses:t,delegatorAddress:c(n),startTimestamp:String(r),durationDays:String(i),extraData:`0x00`};return{domain:C.domain(BigInt(this.#t.chainId),this.#t.verifyingContractAddressDecryption),types:B,primaryType:`DelegatedUserDecryptRequestVerification`,message:a}}async delegatedUserDecrypt(e){return await this.#i(e.handles,c(e.delegatorAddress),c(e.delegateAddress),c(e.contractAddress)),this.#n(e.handles)}async requestZKProofVerification(t){throw new e(`Not implemented in cleartext mode`)}async getPublicKey(){return{publicKeyId:`mock-public-key-id`,publicKey:new Uint8Array([32])}}async getPublicParams(e){return{publicParams:new Uint8Array([32]),publicParamsId:`mock-public-params-id`}}async getAclAddress(){return this.#t.aclContractAddress}terminate(){}async#n(e){let t=await Promise.all(e.map(e=>this.#s(e)));return Object.fromEntries(e.map((e,n)=>[e,U(e,t[n])]))}async#r(e,t,r,i,a){if(t===r)throw new n(`${i} address ${t} must not equal contract address for ${a}`);let o=await Promise.all(e.flatMap(e=>[this.#a(e,t),this.#a(e,r)]));for(let s=0;s<e.length;s++){let c=o[s*2],l=o[s*2+1];if(!c)throw new n(`${i} ${t} is not authorized for ${a} of handle ${e[s]}`);if(!l)throw new n(`Contract ${r} is not authorized for ${a} of handle ${e[s]}`)}}async#i(e,t,r,i){let a=await Promise.all(e.map(e=>this.#e.readContract({address:this.#t.aclContractAddress,abi:I,functionName:`isHandleDelegatedForUserDecryption`,args:[t,r,i,e]})));for(let t=0;t<e.length;t++)if(!a[t])throw new n(`Handle ${e[t]} is not delegated for user decryption`)}async#a(e,t){return this.#e.readContract({address:this.#t.aclContractAddress,abi:I,functionName:`persistAllowed`,args:[e,t]})}async#o(e){return this.#e.readContract({address:this.#t.aclContractAddress,abi:I,functionName:`isAllowedForDecryption`,args:[e]})}async#s(e){return this.#e.readContract({address:this.#t.executorAddress,abi:L,functionName:`plaintexts`,args:[e]})}};const K={...r,executorAddress:`0xe3a9105a3a932253A70F126eb1E3b589C643dD24`},q={chainId:560048,network:`https://rpc.hoodi.ethpandaops.io`,gatewayChainId:r.gatewayChainId,aclContractAddress:`0x6D3FAf6f86e1fF9F3B0831Dda920AbA1cBd5bd68`,executorAddress:`0xC316692627de536368d82e9121F1D44a550894E6`,verifyingContractAddressDecryption:r.verifyingContractAddressDecryption,verifyingContractAddressInputVerification:r.verifyingContractAddressInputVerification,registryAddress:`0x1807aE2f693F8530DFB126D0eF98F2F2518F292f`};export{q as n,G as r,K as t};
2
+ //# sourceMappingURL=cleartext-BU7SYjBM.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cleartext-DuOGGACw.js","names":["#client","#config","#assertDecryptAuthorization","#decryptHandles","#isAllowedForDecryption","#readPlaintext","#assertDelegation","#persistAllowed"],"sources":["../../src/relayer/cleartext/eip712.ts","../../src/relayer/cleartext/constants.ts","../../src/relayer/cleartext/fhe-type.ts","../../src/relayer/cleartext/handle.ts","../../src/relayer/cleartext/relayer-cleartext.ts","../../src/relayer/cleartext/presets.ts"],"sourcesContent":["import type { Address, TypedDataDomain } from \"viem\";\nimport type {\n CoprocessorEIP712TypesType,\n KmsDelegatedUserDecryptEIP712TypesType,\n KmsPublicDecryptEIP712TypesType,\n KmsUserDecryptEIP712TypesType,\n} from \"@zama-fhe/relayer-sdk/bundle\";\n\ntype DomainFactory = (chainId: number | bigint, verifyingContract: Address) => TypedDataDomain;\n\nconst inputDomain: DomainFactory = (chainId, verifyingContract) => ({\n name: \"InputVerification\",\n version: \"1\",\n chainId: Number(chainId),\n verifyingContract,\n});\n\nconst decryptionDomain: DomainFactory = (chainId, verifyingContract) => ({\n name: \"Decryption\",\n version: \"1\",\n chainId: Number(chainId),\n verifyingContract,\n});\n\nexport const INPUT_VERIFICATION_EIP712 = {\n domain: inputDomain,\n types: {\n CiphertextVerification: [\n { name: \"ctHandles\", type: \"bytes32[]\" },\n { name: \"userAddress\", type: \"address\" },\n { name: \"contractAddress\", type: \"address\" },\n { name: \"contractChainId\", type: \"uint256\" },\n { name: \"extraData\", type: \"bytes\" },\n ],\n },\n} as const;\n\nexport const KMS_DECRYPTION_EIP712 = {\n domain: decryptionDomain,\n types: {\n PublicDecryptVerification: [\n { name: \"ctHandles\", type: \"bytes32[]\" },\n { name: \"decryptedResult\", type: \"bytes\" },\n { name: \"extraData\", type: \"bytes\" },\n ],\n },\n} as const;\n\nexport const USER_DECRYPT_EIP712 = {\n domain: decryptionDomain,\n types: {\n UserDecryptRequestVerification: [\n { name: \"publicKey\", type: \"bytes\" },\n { name: \"contractAddresses\", type: \"address[]\" },\n { name: \"startTimestamp\", type: \"uint256\" },\n { name: \"durationDays\", type: \"uint256\" },\n { name: \"extraData\", type: \"bytes\" },\n ],\n },\n} as const;\n\nexport const DELEGATED_USER_DECRYPT_EIP712 = {\n domain: decryptionDomain,\n types: {\n DelegatedUserDecryptRequestVerification: [\n { name: \"publicKey\", type: \"bytes\" },\n { name: \"contractAddresses\", type: \"address[]\" },\n { name: \"delegatorAddress\", type: \"address\" },\n { name: \"startTimestamp\", type: \"uint256\" },\n { name: \"durationDays\", type: \"uint256\" },\n { name: \"extraData\", type: \"bytes\" },\n ],\n },\n} as const;\n\n// ── Compile-time structural checks against relayer-sdk types ──────────\n// These assertions ensure our local EIP-712 type arrays stay in sync with\n// the relayer-sdk's canonical definitions. A mismatch will cause a build error.\ntype AssertFieldsMatch<\n Local extends readonly { readonly name: string; readonly type: string }[],\n Canonical extends readonly { readonly name: string; readonly type: string }[],\n> = [Local[\"length\"]] extends [Canonical[\"length\"]]\n ? {\n [K in keyof Local]: Local[K] extends { readonly name: infer N; readonly type: infer T }\n ? Canonical[K & keyof Canonical] extends { readonly name: N; readonly type: T }\n ? true\n : { error: `Field mismatch at index ${K & string}` }\n : never;\n }\n : { error: \"Field count mismatch\" };\n\n// Wrapping in readonly true[] ensures a mismatch produces a compile error\n// (not just an inert type alias that TypeScript silently accepts).\ntype AssertAllTrue<T extends readonly true[]> = T;\n\ntype _CheckInput = AssertAllTrue<\n AssertFieldsMatch<\n typeof INPUT_VERIFICATION_EIP712.types.CiphertextVerification,\n CoprocessorEIP712TypesType[\"CiphertextVerification\"]\n >\n>;\ntype _CheckPublicDecrypt = AssertAllTrue<\n AssertFieldsMatch<\n typeof KMS_DECRYPTION_EIP712.types.PublicDecryptVerification,\n KmsPublicDecryptEIP712TypesType[\"PublicDecryptVerification\"]\n >\n>;\ntype _CheckUserDecrypt = AssertAllTrue<\n AssertFieldsMatch<\n typeof USER_DECRYPT_EIP712.types.UserDecryptRequestVerification,\n KmsUserDecryptEIP712TypesType[\"UserDecryptRequestVerification\"]\n >\n>;\ntype _CheckDelegatedDecrypt = AssertAllTrue<\n AssertFieldsMatch<\n typeof DELEGATED_USER_DECRYPT_EIP712.types.DelegatedUserDecryptRequestVerification,\n KmsDelegatedUserDecryptEIP712TypesType[\"DelegatedUserDecryptRequestVerification\"]\n >\n>;\n","export const HANDLE_VERSION = 0;\n\nexport const PREHANDLE_MASK = 0xffffffffffffffffffffffffffffffffffffffffff0000000000000000000000n;\n\n// Constants used for instanciation of the cleartext FHEVM instance.\nexport const MOCK_INPUT_SIGNER_PK =\n \"0x7ec8ada6642fc4ccfb7729bc29c17cf8d21b61abd5642d1db992c0b8672ab901\";\nexport const MOCK_KMS_SIGNER_PK =\n \"0x388b7680e4e1afa06efbfd45cdd1fe39f3c6af381df6555a19661f283b97de91\";\n","// Copied from @zama-fhe/relayer-sdk/src/sdk/FheType.ts\n// Pure utility functions with zero WASM dependency.\n// Adapted to use simple errors instead of RelayerErrorBase hierarchy.\n\n////////////////////////////////////////////////////////////////////////////////\n// Types (from types/primitives.d.ts)\n////////////////////////////////////////////////////////////////////////////////\n\nexport interface FheTypeNameToIdMap {\n ebool: 0;\n //euint4: 1; deprecated\n euint8: 2;\n euint16: 3;\n euint32: 4;\n euint64: 5;\n euint128: 6;\n eaddress: 7;\n euint256: 8;\n}\n\nexport interface FheTypeIdToNameMap {\n 0: \"ebool\";\n //1: 'euint4'; deprecated\n 2: \"euint8\";\n 3: \"euint16\";\n 4: \"euint32\";\n 5: \"euint64\";\n 6: \"euint128\";\n 7: \"eaddress\";\n 8: \"euint256\";\n}\n\nexport interface FheTypeEncryptionBitwidthToIdMap {\n 2: FheTypeNameToIdMap[\"ebool\"];\n 8: FheTypeNameToIdMap[\"euint8\"];\n 16: FheTypeNameToIdMap[\"euint16\"];\n 32: FheTypeNameToIdMap[\"euint32\"];\n 64: FheTypeNameToIdMap[\"euint64\"];\n 128: FheTypeNameToIdMap[\"euint128\"];\n 160: FheTypeNameToIdMap[\"eaddress\"];\n 256: FheTypeNameToIdMap[\"euint256\"];\n}\n\nexport type FheTypeIdToEncryptionBitwidthMap = {\n [K in keyof FheTypeEncryptionBitwidthToIdMap as FheTypeEncryptionBitwidthToIdMap[K]]: K;\n};\n\ntype Prettify<T> = { [K in keyof T]: T[K] } & {};\n\nexport type FheTypeName = Prettify<keyof FheTypeNameToIdMap>;\nexport type FheTypeId = Prettify<keyof FheTypeIdToNameMap>;\nexport type EncryptionBits = Prettify<keyof FheTypeEncryptionBitwidthToIdMap>;\n\n////////////////////////////////////////////////////////////////////////////////\n// Lookup Maps\n////////////////////////////////////////////////////////////////////////////////\n\nconst MINIMUM_ENCRYPTION_BIT_WIDTH = 2;\n\nconst FheTypeNameToId: FheTypeNameToIdMap = {\n ebool: 0,\n //euint4: 1, deprecated\n euint8: 2,\n euint16: 3,\n euint32: 4,\n euint64: 5,\n euint128: 6,\n eaddress: 7,\n euint256: 8,\n} as const;\n\nconst FheTypeIdToName: FheTypeIdToNameMap = {\n 0: \"ebool\",\n //1: 'euint4', deprecated\n 2: \"euint8\",\n 3: \"euint16\",\n 4: \"euint32\",\n 5: \"euint64\",\n 6: \"euint128\",\n 7: \"eaddress\",\n 8: \"euint256\",\n} as const;\n\nconst FheTypeIdToEncryptionBitwidth: FheTypeIdToEncryptionBitwidthMap = {\n 0: 2,\n //1:?, euint4 deprecated\n 2: 8,\n 3: 16,\n 4: 32,\n 5: 64,\n 6: 128,\n 7: 160,\n 8: 256,\n} as const;\n\nconst EncryptionBitwidthToFheTypeId: FheTypeEncryptionBitwidthToIdMap = {\n 2: 0,\n 8: 2,\n 16: 3,\n 32: 4,\n 64: 5,\n 128: 6,\n 160: 7,\n 256: 8,\n} as const;\n\nObject.freeze(FheTypeNameToId);\nObject.freeze(FheTypeIdToName);\nObject.freeze(FheTypeIdToEncryptionBitwidth);\nObject.freeze(EncryptionBitwidthToFheTypeId);\n\n////////////////////////////////////////////////////////////////////////////////\n// Type Guards\n////////////////////////////////////////////////////////////////////////////////\n\nexport function isFheTypeId(value: unknown): value is FheTypeId {\n switch (value as FheTypeId) {\n case 0:\n case 2:\n case 3:\n case 4:\n case 5:\n case 6:\n case 7:\n case 8:\n return true;\n default:\n return false;\n }\n}\n\nexport function isFheTypeName(value: unknown): value is FheTypeName {\n if (typeof value !== \"string\") {\n return false;\n }\n return value in FheTypeNameToId;\n}\n\nexport function isEncryptionBits(value: unknown): value is EncryptionBits {\n if (typeof value !== \"number\") {\n return false;\n }\n return value in EncryptionBitwidthToFheTypeId;\n}\n\n////////////////////////////////////////////////////////////////////////////////\n// Converters\n////////////////////////////////////////////////////////////////////////////////\n\nexport function fheTypeIdFromEncryptionBits(bitwidth: number): FheTypeId {\n if (!isEncryptionBits(bitwidth)) {\n throw new Error(`Invalid encryption bits ${bitwidth}`);\n }\n return EncryptionBitwidthToFheTypeId[bitwidth];\n}\n\nexport function fheTypeIdFromName(name: string): FheTypeId {\n if (!isFheTypeName(name)) {\n throw new Error(`Invalid FheType name '${name}'`);\n }\n return FheTypeNameToId[name];\n}\n\nexport function fheTypeNameFromId(id: number): FheTypeName {\n if (!isFheTypeId(id)) {\n throw new Error(`Invalid FheType id '${id}'`);\n }\n return FheTypeIdToName[id];\n}\n\nexport function encryptionBitsFromFheTypeId(typeId: number): EncryptionBits {\n if (!isFheTypeId(typeId)) {\n throw new Error(`Invalid FheType id '${typeId}'`);\n }\n const bw = FheTypeIdToEncryptionBitwidth[typeId];\n if (bw < MINIMUM_ENCRYPTION_BIT_WIDTH) {\n throw new Error(\n `Invalid FheType encryption bit width: ${bw}. Minimum is ${MINIMUM_ENCRYPTION_BIT_WIDTH} bits.`,\n );\n }\n return bw;\n}\n\nexport function encryptionBitsFromFheTypeName(name: string): EncryptionBits {\n if (!isFheTypeName(name)) {\n throw new Error(`Invalid FheType name '${name}'`);\n }\n const bw = FheTypeIdToEncryptionBitwidth[FheTypeNameToId[name]];\n if (bw < MINIMUM_ENCRYPTION_BIT_WIDTH) {\n throw new Error(\n `Invalid FheType encryption bit width: ${bw}. Minimum is ${MINIMUM_ENCRYPTION_BIT_WIDTH} bits.`,\n );\n }\n return bw;\n}\n","import { concat, encodePacked, keccak256, pad, toBytes, toHex, type Address, type Hex } from \"viem\";\nimport { HANDLE_VERSION, PREHANDLE_MASK } from \"./constants\";\nimport { encryptionBitsFromFheTypeId, type FheTypeId } from \"./fhe-type\";\nimport { EncryptionFailedError } from \"../../errors\";\n\nconst RAW_CT_HASH_DOMAIN_SEPARATOR = toBytes(\"ZK-w_rct\");\nconst HANDLE_HASH_DOMAIN_SEPARATOR = toBytes(\"ZK-w_hdl\");\n\nfunction cleartextToBytes(cleartext: bigint, fheType: FheTypeId): Uint8Array {\n const byteLength = Math.ceil(encryptionBitsFromFheTypeId(fheType) / 8);\n return toBytes(pad(toHex(cleartext), { size: byteLength }));\n}\n\nexport function computeMockCiphertext(\n fheType: FheTypeId,\n cleartext: bigint,\n random32: Uint8Array,\n): Hex {\n if (random32.length !== 32) {\n throw new EncryptionFailedError(\"random32 must be exactly 32 bytes\");\n }\n\n const clearBytes = cleartextToBytes(cleartext, fheType);\n const inner = keccak256(\n concat([toHex(new Uint8Array([fheType])), toHex(clearBytes), toHex(random32)]),\n );\n\n return keccak256(concat([toHex(RAW_CT_HASH_DOMAIN_SEPARATOR), inner]));\n}\n\nexport function computeInputHandle(\n mockCiphertext: Hex,\n index: number,\n fheType: FheTypeId,\n aclAddress: Address,\n chainId: bigint,\n): Hex {\n if (!Number.isInteger(index) || index < 0 || index > 255) {\n throw new EncryptionFailedError(\"index must be an integer between 0 and 255\");\n }\n\n const blobHash = keccak256(concat([toHex(RAW_CT_HASH_DOMAIN_SEPARATOR), mockCiphertext]));\n const handleHash = keccak256(\n encodePacked(\n [\"bytes\", \"bytes32\", \"uint8\", \"address\", \"uint256\"],\n [toHex(HANDLE_HASH_DOMAIN_SEPARATOR), blobHash, index, aclAddress, chainId],\n ),\n );\n\n const chainId64 = chainId & 0xffff_ffff_ffff_ffffn;\n const handle =\n (BigInt(handleHash) & PREHANDLE_MASK) |\n (BigInt(index) << 80n) |\n (chainId64 << 16n) |\n (BigInt(fheType) << 8n) |\n BigInt(HANDLE_VERSION);\n\n return toHex(handle, { size: 32 });\n}\n","import type { PrivateKeyAccount } from \"viem/accounts\";\nimport { privateKeyToAccount } from \"viem/accounts\";\nimport {\n concat,\n createPublicClient,\n custom,\n getAddress,\n http,\n keccak256,\n pad,\n parseAbi,\n toBytes,\n toHex,\n type Address,\n type Hex,\n type PublicClient,\n} from \"viem\";\nimport { mainnet, sepolia } from \"viem/chains\";\nimport type {\n ClearValueType,\n InputProofBytesType,\n KeypairType,\n KmsDelegatedUserDecryptEIP712Type,\n KmsPublicDecryptEIP712Type,\n KmsUserDecryptEIP712Type,\n ZKProofLike,\n} from \"@zama-fhe/relayer-sdk/bundle\";\nimport type { RelayerSDK } from \"../relayer-sdk\";\nimport type {\n DelegatedUserDecryptParams,\n EIP712TypedData,\n EncryptParams,\n EncryptResult,\n Handle,\n PublicDecryptResult,\n UserDecryptParams,\n} from \"../relayer-sdk.types\";\nimport {\n DELEGATED_USER_DECRYPT_EIP712,\n INPUT_VERIFICATION_EIP712,\n KMS_DECRYPTION_EIP712,\n USER_DECRYPT_EIP712,\n} from \"./eip712\";\nimport { MOCK_INPUT_SIGNER_PK, MOCK_KMS_SIGNER_PK } from \"./constants\";\nimport {\n encryptionBitsFromFheTypeId,\n fheTypeIdFromName,\n isFheTypeName,\n type FheTypeId,\n} from \"./fhe-type\";\nimport { computeInputHandle, computeMockCiphertext } from \"./handle\";\nimport type { CleartextConfig } from \"./types\";\nimport { ConfigurationError, DecryptionFailedError, EncryptionFailedError } from \"../../errors\";\n\nconst ACL_ABI = parseAbi([\n \"function persistAllowed(bytes32 handle, address account) view returns (bool)\",\n \"function isAllowedForDecryption(bytes32 handle) view returns (bool)\",\n \"function isHandleDelegatedForUserDecryption(address delegator, address delegate, address contractAddress, bytes32 handle) view returns (bool)\",\n]);\n\nconst EXECUTOR_ABI = parseAbi([\"function plaintexts(bytes32 handle) view returns (uint256)\"]);\n\nconst STANDARD_EIP712_DOMAIN = [\n { name: \"name\", type: \"string\" },\n { name: \"version\", type: \"string\" },\n { name: \"chainId\", type: \"uint256\" },\n { name: \"verifyingContract\", type: \"address\" },\n] as const;\n\nconst USER_DECRYPT_TYPES = {\n EIP712Domain: STANDARD_EIP712_DOMAIN,\n UserDecryptRequestVerification: USER_DECRYPT_EIP712.types.UserDecryptRequestVerification,\n} satisfies KmsUserDecryptEIP712Type[\"types\"];\nconst DELEGATED_USER_DECRYPT_TYPES = {\n EIP712Domain: STANDARD_EIP712_DOMAIN,\n DelegatedUserDecryptRequestVerification:\n DELEGATED_USER_DECRYPT_EIP712.types.DelegatedUserDecryptRequestVerification,\n} satisfies KmsDelegatedUserDecryptEIP712Type[\"types\"];\nconst KMS_DECRYPTION_TYPES = {\n EIP712Domain: STANDARD_EIP712_DOMAIN,\n PublicDecryptVerification: KMS_DECRYPTION_EIP712.types.PublicDecryptVerification,\n} satisfies KmsPublicDecryptEIP712Type[\"types\"];\n\nconst FORBIDDEN_CHAIN_IDS = new Set<number>([mainnet.id, sepolia.id]);\n\n// FheTypeId constants for hot-path comparisons\nconst EBOOL_ID: FheTypeId = 0;\nconst EADDRESS_ID: FheTypeId = 7;\n\nfunction decodeClearValueType(handle: Handle, rawValue: bigint): ClearValueType {\n const typeByte = Number((BigInt(handle) >> 8n) & 0xffn);\n if (typeByte === EBOOL_ID) {\n return rawValue !== 0n;\n }\n if (typeByte === EADDRESS_ID) {\n return toHex(rawValue, { size: 20 });\n }\n return rawValue;\n}\n\nfunction normalizeEncryptValue(entry: EncryptParams[\"values\"][number]): {\n fheType: FheTypeId;\n value: bigint;\n} {\n if (!isFheTypeName(entry.type)) {\n throw new EncryptionFailedError(\"Unsupported FHE type\");\n }\n\n const fheType = fheTypeIdFromName(entry.type);\n\n let value: bigint;\n if (entry.type === \"ebool\") {\n if (typeof entry.value === \"boolean\") {\n value = entry.value ? 1n : 0n;\n } else {\n value = entry.value;\n if (value !== 0n && value !== 1n) {\n throw new EncryptionFailedError(\"Bool value must be 0, 1, true, or false\");\n }\n }\n } else if (entry.type === \"eaddress\") {\n value = BigInt(getAddress(entry.value));\n } else {\n value = entry.value;\n }\n\n if (value < 0n) {\n throw new EncryptionFailedError(\"Only non-negative cleartext values are supported\");\n }\n\n const bits = encryptionBitsFromFheTypeId(fheType);\n const maxValue = (1n << BigInt(bits)) - 1n;\n if (value > maxValue) {\n throw new EncryptionFailedError(\n `Value ${value} exceeds max ${maxValue} for FheType ${fheType}`,\n );\n }\n\n return { fheType, value };\n}\n\nexport class RelayerCleartext implements RelayerSDK {\n readonly #client: PublicClient;\n readonly #config: CleartextConfig;\n readonly kmsSigner: PrivateKeyAccount;\n readonly inputSigner: PrivateKeyAccount;\n\n constructor(config: CleartextConfig) {\n if (FORBIDDEN_CHAIN_IDS.has(config.chainId)) {\n throw new ConfigurationError(\n `Cleartext mode is not allowed on chain ${config.chainId}. ` +\n `It is intended for local development and testing only.`,\n );\n }\n this.#client = createPublicClient({\n transport: typeof config.network === \"string\" ? http(config.network) : custom(config.network),\n });\n this.#config = config;\n this.kmsSigner = privateKeyToAccount(config.kmsSignerPrivateKey ?? MOCK_KMS_SIGNER_PK);\n this.inputSigner = privateKeyToAccount(config.inputSignerPrivateKey ?? MOCK_INPUT_SIGNER_PK);\n }\n\n async generateKeypair(): Promise<KeypairType<Hex>> {\n const publicKey = toHex(crypto.getRandomValues(new Uint8Array(32)));\n let privateKey = toHex(crypto.getRandomValues(new Uint8Array(32)));\n\n while (privateKey === publicKey) {\n privateKey = toHex(crypto.getRandomValues(new Uint8Array(32)));\n }\n\n return { publicKey, privateKey };\n }\n\n async createEIP712(\n publicKey: Hex,\n contractAddresses: Address[],\n startTimestamp: number,\n durationDays = 7,\n ): Promise<EIP712TypedData> {\n return {\n domain: USER_DECRYPT_EIP712.domain(\n this.#config.chainId,\n this.#config.verifyingContractAddressDecryption,\n ) as EIP712TypedData[\"domain\"],\n types: USER_DECRYPT_TYPES,\n primaryType: \"UserDecryptRequestVerification\",\n message: {\n publicKey,\n contractAddresses,\n startTimestamp: BigInt(startTimestamp),\n durationDays: BigInt(durationDays),\n extraData: \"0x00\",\n },\n };\n }\n\n async encrypt(params: EncryptParams): Promise<EncryptResult> {\n const entries = params.values.map(normalizeEncryptValue);\n const contractAddress = getAddress(params.contractAddress);\n const userAddress = getAddress(params.userAddress);\n\n const mockCiphertexts = entries.map(({ fheType, value }) =>\n computeMockCiphertext(fheType, value, crypto.getRandomValues(new Uint8Array(32))),\n );\n\n const ciphertextBlob = keccak256(mockCiphertexts.length > 0 ? concat(mockCiphertexts) : \"0x\");\n\n const handles = entries.map(({ fheType }, index) =>\n computeInputHandle(\n ciphertextBlob,\n index,\n fheType,\n this.#config.aclContractAddress,\n BigInt(this.#config.chainId),\n ),\n );\n\n const cleartextParts = entries.map(({ value }) => pad(toHex(value), { size: 32 }));\n const cleartextBytes: Hex = cleartextParts.length > 0 ? concat(cleartextParts) : \"0x\";\n\n const signature = await this.inputSigner.signTypedData({\n domain: INPUT_VERIFICATION_EIP712.domain(\n this.#config.gatewayChainId,\n this.#config.verifyingContractAddressInputVerification,\n ),\n types: {\n CiphertextVerification: INPUT_VERIFICATION_EIP712.types.CiphertextVerification,\n },\n primaryType: \"CiphertextVerification\",\n message: {\n ctHandles: handles,\n userAddress,\n contractAddress,\n contractChainId: BigInt(this.#config.chainId),\n extraData: cleartextBytes,\n },\n });\n\n const inputProof = toBytes(\n concat([\n toHex(new Uint8Array([handles.length])),\n toHex(new Uint8Array([1])),\n ...handles,\n signature,\n cleartextBytes,\n ]),\n );\n\n return {\n handles: handles.map((handle) => toBytes(handle)),\n inputProof,\n };\n }\n\n async userDecrypt(params: UserDecryptParams): Promise<Readonly<Record<Handle, ClearValueType>>> {\n await this.#assertDecryptAuthorization(\n params.handles,\n getAddress(params.signerAddress),\n getAddress(params.contractAddress),\n \"User\",\n \"user decrypt\",\n );\n\n return this.#decryptHandles(params.handles);\n }\n\n async publicDecrypt(handles: Handle[]): Promise<PublicDecryptResult> {\n const normalizedHandles = handles;\n\n const allowedResults = await Promise.all(\n normalizedHandles.map((handle) => this.#isAllowedForDecryption(handle)),\n );\n const unauthorizedIndex = allowedResults.findIndex((isAllowed) => !isAllowed);\n if (unauthorizedIndex !== -1) {\n throw new DecryptionFailedError(\n `Handle ${normalizedHandles[unauthorizedIndex]!} is not allowed for public decryption`,\n );\n }\n\n const orderedValues = await Promise.all(\n normalizedHandles.map((handle) => this.#readPlaintext(handle)),\n );\n const clearValues: PublicDecryptResult[\"clearValues\"] = Object.fromEntries(\n normalizedHandles.map((handle, index) => [\n handle,\n decodeClearValueType(handle, orderedValues[index]!),\n ]),\n );\n\n const abiEncodedClearValues = concat(orderedValues.map((v) => pad(toHex(v), { size: 32 })));\n\n const signature = await this.kmsSigner.signTypedData({\n domain: KMS_DECRYPTION_EIP712.domain(\n this.#config.gatewayChainId,\n this.#config.verifyingContractAddressDecryption,\n ) as KmsPublicDecryptEIP712Type[\"domain\"],\n types: KMS_DECRYPTION_TYPES,\n primaryType: \"PublicDecryptVerification\",\n message: {\n ctHandles: normalizedHandles,\n decryptedResult: abiEncodedClearValues,\n extraData: \"0x\",\n },\n });\n\n const decryptionProof = concat([toHex(new Uint8Array([1])), signature]);\n\n return {\n clearValues,\n abiEncodedClearValues,\n decryptionProof,\n };\n }\n\n async createDelegatedUserDecryptEIP712(\n publicKey: Hex,\n contractAddresses: Address[],\n delegatorAddress: Address,\n startTimestamp: number,\n durationDays = 7,\n ): Promise<KmsDelegatedUserDecryptEIP712Type> {\n const message: KmsDelegatedUserDecryptEIP712Type[\"message\"] = {\n publicKey: publicKey as KmsDelegatedUserDecryptEIP712Type[\"message\"][\"publicKey\"],\n contractAddresses,\n delegatorAddress: getAddress(delegatorAddress),\n startTimestamp: String(startTimestamp),\n durationDays: String(durationDays),\n extraData: \"0x00\",\n };\n\n return {\n domain: DELEGATED_USER_DECRYPT_EIP712.domain(\n BigInt(this.#config.chainId),\n this.#config.verifyingContractAddressDecryption,\n ) as KmsDelegatedUserDecryptEIP712Type[\"domain\"],\n types: DELEGATED_USER_DECRYPT_TYPES,\n primaryType: \"DelegatedUserDecryptRequestVerification\",\n message,\n };\n }\n\n async delegatedUserDecrypt(\n params: DelegatedUserDecryptParams,\n ): Promise<Readonly<Record<Handle, ClearValueType>>> {\n await this.#assertDelegation(\n params.handles,\n getAddress(params.delegatorAddress),\n getAddress(params.delegateAddress),\n getAddress(params.contractAddress),\n );\n\n return this.#decryptHandles(params.handles);\n }\n\n async requestZKProofVerification(_zkProof: ZKProofLike): Promise<InputProofBytesType> {\n throw new ConfigurationError(\"Not implemented in cleartext mode\");\n }\n\n async getPublicKey(): Promise<{ publicKeyId: string; publicKey: Uint8Array } | null> {\n return { publicKeyId: \"mock-public-key-id\", publicKey: new Uint8Array([32]) };\n }\n\n async getPublicParams(\n _bits: number,\n ): Promise<{ publicParams: Uint8Array; publicParamsId: string } | null> {\n return { publicParams: new Uint8Array([32]), publicParamsId: \"mock-public-params-id\" };\n }\n\n async getAclAddress(): Promise<Address> {\n return this.#config.aclContractAddress;\n }\n\n terminate(): void {\n // No resources to release in cleartext mode.\n }\n\n async #decryptHandles(\n normalizedHandles: Handle[],\n ): Promise<Readonly<Record<Handle, ClearValueType>>> {\n const values = await Promise.all(\n normalizedHandles.map((handle) => this.#readPlaintext(handle)),\n );\n\n return Object.fromEntries(\n normalizedHandles.map((handle, index) => [\n handle,\n decodeClearValueType(handle, values[index]!),\n ]),\n );\n }\n\n async #assertDecryptAuthorization(\n normalizedHandles: Handle[],\n actorAddress: Address,\n contractAddress: Address,\n actorLabel: \"User\" | \"Delegator\",\n operationLabel: \"user decrypt\" | \"delegated decrypt\",\n ): Promise<void> {\n if (actorAddress === contractAddress) {\n throw new DecryptionFailedError(\n `${actorLabel} address ${actorAddress} must not equal contract address for ${operationLabel}`,\n );\n }\n\n const results = await Promise.all(\n normalizedHandles.flatMap((handle) => [\n this.#persistAllowed(handle, actorAddress),\n this.#persistAllowed(handle, contractAddress),\n ]),\n );\n\n for (let i = 0; i < normalizedHandles.length; i++) {\n const actorAllowed = results[i * 2];\n const contractAllowed = results[i * 2 + 1];\n if (!actorAllowed) {\n throw new DecryptionFailedError(\n `${actorLabel} ${actorAddress} is not authorized for ${operationLabel} of handle ${normalizedHandles[i]!}`,\n );\n }\n if (!contractAllowed) {\n throw new DecryptionFailedError(\n `Contract ${contractAddress} is not authorized for ${operationLabel} of handle ${normalizedHandles[i]!}`,\n );\n }\n }\n }\n\n async #assertDelegation(\n handles: Handle[],\n delegatorAddress: Address,\n delegateAddress: Address,\n contractAddress: Address,\n ): Promise<void> {\n const results = await Promise.all(\n handles.map((handle) =>\n this.#client.readContract({\n address: this.#config.aclContractAddress,\n abi: ACL_ABI,\n functionName: \"isHandleDelegatedForUserDecryption\",\n args: [delegatorAddress, delegateAddress, contractAddress, handle],\n }),\n ),\n );\n\n for (let i = 0; i < handles.length; i++) {\n if (!results[i]) {\n throw new DecryptionFailedError(\n `Handle ${handles[i]!} is not delegated for user decryption`,\n );\n }\n }\n }\n\n async #persistAllowed(handle: Handle, account: Address): Promise<boolean> {\n return this.#client.readContract({\n address: this.#config.aclContractAddress,\n abi: ACL_ABI,\n functionName: \"persistAllowed\",\n args: [handle, account],\n });\n }\n\n async #isAllowedForDecryption(handle: Handle): Promise<boolean> {\n return this.#client.readContract({\n address: this.#config.aclContractAddress,\n abi: ACL_ABI,\n functionName: \"isAllowedForDecryption\",\n args: [handle],\n });\n }\n\n async #readPlaintext(handle: Handle): Promise<bigint> {\n return this.#client.readContract({\n address: this.#config.executorAddress as Address,\n abi: EXECUTOR_ABI,\n functionName: \"plaintexts\",\n args: [handle],\n });\n }\n}\n","import { HardhatConfig } from \"../relayer-utils\";\nimport type { CleartextConfig } from \"./types\";\n\n/**\n * Hardhat local network configuration (chainId 31337).\n *\n * The addresses in this configuration must match those of your deployment.\n * Ensure that the executor address and other contract addresses correspond to\n * the contracts deployed on your Hardhat network.\n */\nexport const hardhatCleartextConfig = {\n ...HardhatConfig,\n executorAddress: \"0xe3a9105a3a932253A70F126eb1E3b589C643dD24\",\n} satisfies CleartextConfig;\n\nexport const hoodiCleartextConfig = {\n chainId: 560048,\n network: \"https://rpc.hoodi.ethpandaops.io\",\n gatewayChainId: HardhatConfig.gatewayChainId,\n aclContractAddress: \"0x6D3FAf6f86e1fF9F3B0831Dda920AbA1cBd5bd68\",\n executorAddress: \"0xC316692627de536368d82e9121F1D44a550894E6\",\n // The values used when configuring the deployments are the same as those used for a hardhat deployment, since there's no gateway chain.\n verifyingContractAddressDecryption: HardhatConfig.verifyingContractAddressDecryption,\n verifyingContractAddressInputVerification:\n HardhatConfig.verifyingContractAddressInputVerification,\n registryAddress: \"0x1807aE2f693F8530DFB126D0eF98F2F2518F292f\",\n} satisfies CleartextConfig;\n"],"mappings":"iaAUA,MAAM,GAA8B,EAAS,KAAuB,CAClE,KAAM,oBACN,QAAS,IACT,QAAS,OAAO,EAAQ,CACxB,oBACD,EAEK,GAAmC,EAAS,KAAuB,CACvE,KAAM,aACN,QAAS,IACT,QAAS,OAAO,EAAQ,CACxB,oBACD,EAEY,EAA4B,CACvC,OAAQ,EACR,MAAO,CACL,uBAAwB,CACtB,CAAE,KAAM,YAAa,KAAM,YAAa,CACxC,CAAE,KAAM,cAAe,KAAM,UAAW,CACxC,CAAE,KAAM,kBAAmB,KAAM,UAAW,CAC5C,CAAE,KAAM,kBAAmB,KAAM,UAAW,CAC5C,CAAE,KAAM,YAAa,KAAM,QAAS,CACrC,CACF,CACF,CAEY,EAAwB,CACnC,OAAQ,EACR,MAAO,CACL,0BAA2B,CACzB,CAAE,KAAM,YAAa,KAAM,YAAa,CACxC,CAAE,KAAM,kBAAmB,KAAM,QAAS,CAC1C,CAAE,KAAM,YAAa,KAAM,QAAS,CACrC,CACF,CACF,CAEY,EAAsB,CACjC,OAAQ,EACR,MAAO,CACL,+BAAgC,CAC9B,CAAE,KAAM,YAAa,KAAM,QAAS,CACpC,CAAE,KAAM,oBAAqB,KAAM,YAAa,CAChD,CAAE,KAAM,iBAAkB,KAAM,UAAW,CAC3C,CAAE,KAAM,eAAgB,KAAM,UAAW,CACzC,CAAE,KAAM,YAAa,KAAM,QAAS,CACrC,CACF,CACF,CAEY,EAAgC,CAC3C,OAAQ,EACR,MAAO,CACL,wCAAyC,CACvC,CAAE,KAAM,YAAa,KAAM,QAAS,CACpC,CAAE,KAAM,oBAAqB,KAAM,YAAa,CAChD,CAAE,KAAM,mBAAoB,KAAM,UAAW,CAC7C,CAAE,KAAM,iBAAkB,KAAM,UAAW,CAC3C,CAAE,KAAM,eAAgB,KAAM,UAAW,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d,KAAM,CAAC,EAAO,CACf,CAAC,CAGJ,MAAA,EAAqB,EAAiC,CACpD,OAAO,MAAA,EAAa,aAAa,CAC/B,QAAS,MAAA,EAAa,gBACtB,IAAK,EACL,aAAc,aACd,KAAM,CAAC,EAAO,CACf,CAAC,GCndN,MAAa,EAAyB,CACpC,GAAG,EACH,gBAAiB,6CAClB,CAEY,EAAuB,CAClC,QAAS,OACT,QAAS,mCACT,eAAgB,EAAc,eAC9B,mBAAoB,6CACpB,gBAAiB,6CAEjB,mCAAoC,EAAc,mCAClD,0CACE,EAAc,0CAChB,gBAAiB,6CAClB"}
1
+ {"version":3,"file":"cleartext-BU7SYjBM.js","names":["#client","#config","#assertDecryptAuthorization","#decryptHandles","#isAllowedForDecryption","#readPlaintext","#assertDelegation","#persistAllowed"],"sources":["../../src/relayer/cleartext/eip712.ts","../../src/relayer/cleartext/constants.ts","../../src/relayer/cleartext/fhe-type.ts","../../src/relayer/cleartext/handle.ts","../../src/relayer/cleartext/relayer-cleartext.ts","../../src/relayer/cleartext/presets.ts"],"sourcesContent":["import type { Address, TypedDataDomain } from \"viem\";\nimport type {\n CoprocessorEIP712TypesType,\n KmsDelegatedUserDecryptEIP712TypesType,\n KmsPublicDecryptEIP712TypesType,\n KmsUserDecryptEIP712TypesType,\n} from \"@zama-fhe/relayer-sdk/bundle\";\n\ntype DomainFactory = (chainId: number | bigint, verifyingContract: Address) => TypedDataDomain;\n\nconst inputDomain: DomainFactory = (chainId, verifyingContract) => ({\n name: \"InputVerification\",\n version: \"1\",\n chainId: Number(chainId),\n verifyingContract,\n});\n\nconst decryptionDomain: DomainFactory = (chainId, verifyingContract) => ({\n name: \"Decryption\",\n version: \"1\",\n chainId: Number(chainId),\n verifyingContract,\n});\n\nexport const INPUT_VERIFICATION_EIP712 = {\n domain: inputDomain,\n types: {\n CiphertextVerification: [\n { name: \"ctHandles\", type: \"bytes32[]\" },\n { name: \"userAddress\", type: \"address\" },\n { name: \"contractAddress\", type: \"address\" },\n { name: \"contractChainId\", type: \"uint256\" },\n { name: \"extraData\", type: \"bytes\" },\n ],\n },\n} as const;\n\nexport const KMS_DECRYPTION_EIP712 = {\n domain: decryptionDomain,\n types: {\n PublicDecryptVerification: [\n { name: \"ctHandles\", type: \"bytes32[]\" },\n { name: \"decryptedResult\", type: \"bytes\" },\n { name: \"extraData\", type: \"bytes\" },\n ],\n },\n} as const;\n\nexport const USER_DECRYPT_EIP712 = {\n domain: decryptionDomain,\n types: {\n UserDecryptRequestVerification: [\n { name: \"publicKey\", type: \"bytes\" },\n { name: \"contractAddresses\", type: \"address[]\" },\n { name: \"startTimestamp\", type: \"uint256\" },\n { name: \"durationDays\", type: \"uint256\" },\n { name: \"extraData\", type: \"bytes\" },\n ],\n },\n} as const;\n\nexport const DELEGATED_USER_DECRYPT_EIP712 = {\n domain: decryptionDomain,\n types: {\n DelegatedUserDecryptRequestVerification: [\n { name: \"publicKey\", type: \"bytes\" },\n { name: \"contractAddresses\", type: \"address[]\" },\n { name: \"delegatorAddress\", type: \"address\" },\n { name: \"startTimestamp\", type: \"uint256\" },\n { name: \"durationDays\", type: \"uint256\" },\n { name: \"extraData\", type: \"bytes\" },\n ],\n },\n} as const;\n\n// ── Compile-time structural checks against relayer-sdk types ──────────\n// These assertions ensure our local EIP-712 type arrays stay in sync with\n// the relayer-sdk's canonical definitions. A mismatch will cause a build error.\ntype AssertFieldsMatch<\n Local extends readonly { readonly name: string; readonly type: string }[],\n Canonical extends readonly { readonly name: string; readonly type: string }[],\n> = [Local[\"length\"]] extends [Canonical[\"length\"]]\n ? {\n [K in keyof Local]: Local[K] extends { readonly name: infer N; readonly type: infer T }\n ? Canonical[K & keyof Canonical] extends { readonly name: N; readonly type: T }\n ? true\n : { error: `Field mismatch at index ${K & string}` }\n : never;\n }\n : { error: \"Field count mismatch\" };\n\n// Wrapping in readonly true[] ensures a mismatch produces a compile error\n// (not just an inert type alias that TypeScript silently accepts).\ntype AssertAllTrue<T extends readonly true[]> = T;\n\ntype _CheckInput = AssertAllTrue<\n AssertFieldsMatch<\n typeof INPUT_VERIFICATION_EIP712.types.CiphertextVerification,\n CoprocessorEIP712TypesType[\"CiphertextVerification\"]\n >\n>;\ntype _CheckPublicDecrypt = AssertAllTrue<\n AssertFieldsMatch<\n typeof KMS_DECRYPTION_EIP712.types.PublicDecryptVerification,\n KmsPublicDecryptEIP712TypesType[\"PublicDecryptVerification\"]\n >\n>;\ntype _CheckUserDecrypt = AssertAllTrue<\n AssertFieldsMatch<\n typeof USER_DECRYPT_EIP712.types.UserDecryptRequestVerification,\n KmsUserDecryptEIP712TypesType[\"UserDecryptRequestVerification\"]\n >\n>;\ntype _CheckDelegatedDecrypt = AssertAllTrue<\n AssertFieldsMatch<\n typeof DELEGATED_USER_DECRYPT_EIP712.types.DelegatedUserDecryptRequestVerification,\n KmsDelegatedUserDecryptEIP712TypesType[\"DelegatedUserDecryptRequestVerification\"]\n >\n>;\n","export const HANDLE_VERSION = 0;\n\nexport const PREHANDLE_MASK = 0xffffffffffffffffffffffffffffffffffffffffff0000000000000000000000n;\n\n// Constants used for instanciation of the cleartext FHEVM instance.\nexport const MOCK_INPUT_SIGNER_PK =\n \"0x7ec8ada6642fc4ccfb7729bc29c17cf8d21b61abd5642d1db992c0b8672ab901\";\nexport const MOCK_KMS_SIGNER_PK =\n \"0x388b7680e4e1afa06efbfd45cdd1fe39f3c6af381df6555a19661f283b97de91\";\n","// Copied from @zama-fhe/relayer-sdk/src/sdk/FheType.ts\n// Pure utility functions with zero WASM dependency.\n// Adapted to use simple errors instead of RelayerErrorBase hierarchy.\n\n////////////////////////////////////////////////////////////////////////////////\n// Types (from types/primitives.d.ts)\n////////////////////////////////////////////////////////////////////////////////\n\nexport interface FheTypeNameToIdMap {\n ebool: 0;\n //euint4: 1; deprecated\n euint8: 2;\n euint16: 3;\n euint32: 4;\n euint64: 5;\n euint128: 6;\n eaddress: 7;\n euint256: 8;\n}\n\nexport interface FheTypeIdToNameMap {\n 0: \"ebool\";\n //1: 'euint4'; deprecated\n 2: \"euint8\";\n 3: \"euint16\";\n 4: \"euint32\";\n 5: \"euint64\";\n 6: \"euint128\";\n 7: \"eaddress\";\n 8: \"euint256\";\n}\n\nexport interface FheTypeEncryptionBitwidthToIdMap {\n 2: FheTypeNameToIdMap[\"ebool\"];\n 8: FheTypeNameToIdMap[\"euint8\"];\n 16: FheTypeNameToIdMap[\"euint16\"];\n 32: FheTypeNameToIdMap[\"euint32\"];\n 64: FheTypeNameToIdMap[\"euint64\"];\n 128: FheTypeNameToIdMap[\"euint128\"];\n 160: FheTypeNameToIdMap[\"eaddress\"];\n 256: FheTypeNameToIdMap[\"euint256\"];\n}\n\nexport type FheTypeIdToEncryptionBitwidthMap = {\n [K in keyof FheTypeEncryptionBitwidthToIdMap as FheTypeEncryptionBitwidthToIdMap[K]]: K;\n};\n\ntype Prettify<T> = { [K in keyof T]: T[K] } & {};\n\nexport type FheTypeName = Prettify<keyof FheTypeNameToIdMap>;\nexport type FheTypeId = Prettify<keyof FheTypeIdToNameMap>;\nexport type EncryptionBits = Prettify<keyof FheTypeEncryptionBitwidthToIdMap>;\n\n////////////////////////////////////////////////////////////////////////////////\n// Lookup Maps\n////////////////////////////////////////////////////////////////////////////////\n\nconst MINIMUM_ENCRYPTION_BIT_WIDTH = 2;\n\nconst FheTypeNameToId: FheTypeNameToIdMap = {\n ebool: 0,\n //euint4: 1, deprecated\n euint8: 2,\n euint16: 3,\n euint32: 4,\n euint64: 5,\n euint128: 6,\n eaddress: 7,\n euint256: 8,\n} as const;\n\nconst FheTypeIdToName: FheTypeIdToNameMap = {\n 0: \"ebool\",\n //1: 'euint4', deprecated\n 2: \"euint8\",\n 3: \"euint16\",\n 4: \"euint32\",\n 5: \"euint64\",\n 6: \"euint128\",\n 7: \"eaddress\",\n 8: \"euint256\",\n} as const;\n\nconst FheTypeIdToEncryptionBitwidth: FheTypeIdToEncryptionBitwidthMap = {\n 0: 2,\n //1:?, euint4 deprecated\n 2: 8,\n 3: 16,\n 4: 32,\n 5: 64,\n 6: 128,\n 7: 160,\n 8: 256,\n} as const;\n\nconst EncryptionBitwidthToFheTypeId: FheTypeEncryptionBitwidthToIdMap = {\n 2: 0,\n 8: 2,\n 16: 3,\n 32: 4,\n 64: 5,\n 128: 6,\n 160: 7,\n 256: 8,\n} as const;\n\nObject.freeze(FheTypeNameToId);\nObject.freeze(FheTypeIdToName);\nObject.freeze(FheTypeIdToEncryptionBitwidth);\nObject.freeze(EncryptionBitwidthToFheTypeId);\n\n////////////////////////////////////////////////////////////////////////////////\n// Type Guards\n////////////////////////////////////////////////////////////////////////////////\n\nexport function isFheTypeId(value: unknown): value is FheTypeId {\n switch (value as FheTypeId) {\n case 0:\n case 2:\n case 3:\n case 4:\n case 5:\n case 6:\n case 7:\n case 8:\n return true;\n default:\n return false;\n }\n}\n\nexport function isFheTypeName(value: unknown): value is FheTypeName {\n if (typeof value !== \"string\") {\n return false;\n }\n return value in FheTypeNameToId;\n}\n\nexport function isEncryptionBits(value: unknown): value is EncryptionBits {\n if (typeof value !== \"number\") {\n return false;\n }\n return value in EncryptionBitwidthToFheTypeId;\n}\n\n////////////////////////////////////////////////////////////////////////////////\n// Converters\n////////////////////////////////////////////////////////////////////////////////\n\nexport function fheTypeIdFromEncryptionBits(bitwidth: number): FheTypeId {\n if (!isEncryptionBits(bitwidth)) {\n throw new Error(`Invalid encryption bits ${bitwidth}`);\n }\n return EncryptionBitwidthToFheTypeId[bitwidth];\n}\n\nexport function fheTypeIdFromName(name: string): FheTypeId {\n if (!isFheTypeName(name)) {\n throw new Error(`Invalid FheType name '${name}'`);\n }\n return FheTypeNameToId[name];\n}\n\nexport function fheTypeNameFromId(id: number): FheTypeName {\n if (!isFheTypeId(id)) {\n throw new Error(`Invalid FheType id '${id}'`);\n }\n return FheTypeIdToName[id];\n}\n\nexport function encryptionBitsFromFheTypeId(typeId: number): EncryptionBits {\n if (!isFheTypeId(typeId)) {\n throw new Error(`Invalid FheType id '${typeId}'`);\n }\n const bw = FheTypeIdToEncryptionBitwidth[typeId];\n if (bw < MINIMUM_ENCRYPTION_BIT_WIDTH) {\n throw new Error(\n `Invalid FheType encryption bit width: ${bw}. Minimum is ${MINIMUM_ENCRYPTION_BIT_WIDTH} bits.`,\n );\n }\n return bw;\n}\n\nexport function encryptionBitsFromFheTypeName(name: string): EncryptionBits {\n if (!isFheTypeName(name)) {\n throw new Error(`Invalid FheType name '${name}'`);\n }\n const bw = FheTypeIdToEncryptionBitwidth[FheTypeNameToId[name]];\n if (bw < MINIMUM_ENCRYPTION_BIT_WIDTH) {\n throw new Error(\n `Invalid FheType encryption bit width: ${bw}. Minimum is ${MINIMUM_ENCRYPTION_BIT_WIDTH} bits.`,\n );\n }\n return bw;\n}\n","import { concat, encodePacked, keccak256, pad, toBytes, toHex, type Address, type Hex } from \"viem\";\nimport { HANDLE_VERSION, PREHANDLE_MASK } from \"./constants\";\nimport { encryptionBitsFromFheTypeId, type FheTypeId } from \"./fhe-type\";\nimport { EncryptionFailedError } from \"../../errors\";\n\nconst RAW_CT_HASH_DOMAIN_SEPARATOR = toBytes(\"ZK-w_rct\");\nconst HANDLE_HASH_DOMAIN_SEPARATOR = toBytes(\"ZK-w_hdl\");\n\nfunction cleartextToBytes(cleartext: bigint, fheType: FheTypeId): Uint8Array {\n const byteLength = Math.ceil(encryptionBitsFromFheTypeId(fheType) / 8);\n return toBytes(pad(toHex(cleartext), { size: byteLength }));\n}\n\nexport function computeMockCiphertext(\n fheType: FheTypeId,\n cleartext: bigint,\n random32: Uint8Array,\n): Hex {\n if (random32.length !== 32) {\n throw new EncryptionFailedError(\"random32 must be exactly 32 bytes\");\n }\n\n const clearBytes = cleartextToBytes(cleartext, fheType);\n const inner = keccak256(\n concat([toHex(new Uint8Array([fheType])), toHex(clearBytes), toHex(random32)]),\n );\n\n return keccak256(concat([toHex(RAW_CT_HASH_DOMAIN_SEPARATOR), inner]));\n}\n\nexport function computeInputHandle(\n mockCiphertext: Hex,\n index: number,\n fheType: FheTypeId,\n aclAddress: Address,\n chainId: bigint,\n): Hex {\n if (!Number.isInteger(index) || index < 0 || index > 255) {\n throw new EncryptionFailedError(\"index must be an integer between 0 and 255\");\n }\n\n const blobHash = keccak256(concat([toHex(RAW_CT_HASH_DOMAIN_SEPARATOR), mockCiphertext]));\n const handleHash = keccak256(\n encodePacked(\n [\"bytes\", \"bytes32\", \"uint8\", \"address\", \"uint256\"],\n [toHex(HANDLE_HASH_DOMAIN_SEPARATOR), blobHash, index, aclAddress, chainId],\n ),\n );\n\n const chainId64 = chainId & 0xffff_ffff_ffff_ffffn;\n const handle =\n (BigInt(handleHash) & PREHANDLE_MASK) |\n (BigInt(index) << 80n) |\n (chainId64 << 16n) |\n (BigInt(fheType) << 8n) |\n BigInt(HANDLE_VERSION);\n\n return toHex(handle, { size: 32 });\n}\n","import type { PrivateKeyAccount } from \"viem/accounts\";\nimport { privateKeyToAccount } from \"viem/accounts\";\nimport {\n concat,\n createPublicClient,\n custom,\n getAddress,\n http,\n keccak256,\n pad,\n parseAbi,\n toBytes,\n toHex,\n type Address,\n type Hex,\n type PublicClient,\n} from \"viem\";\nimport { mainnet, sepolia } from \"viem/chains\";\nimport type {\n ClearValueType,\n InputProofBytesType,\n KeypairType,\n KmsDelegatedUserDecryptEIP712Type,\n KmsPublicDecryptEIP712Type,\n KmsUserDecryptEIP712Type,\n ZKProofLike,\n} from \"@zama-fhe/relayer-sdk/bundle\";\nimport type { RelayerSDK } from \"../relayer-sdk\";\nimport type {\n DelegatedUserDecryptParams,\n EIP712TypedData,\n EncryptParams,\n EncryptResult,\n Handle,\n PublicDecryptResult,\n UserDecryptParams,\n} from \"../relayer-sdk.types\";\nimport {\n DELEGATED_USER_DECRYPT_EIP712,\n INPUT_VERIFICATION_EIP712,\n KMS_DECRYPTION_EIP712,\n USER_DECRYPT_EIP712,\n} from \"./eip712\";\nimport { MOCK_INPUT_SIGNER_PK, MOCK_KMS_SIGNER_PK } from \"./constants\";\nimport {\n encryptionBitsFromFheTypeId,\n fheTypeIdFromName,\n isFheTypeName,\n type FheTypeId,\n} from \"./fhe-type\";\nimport { computeInputHandle, computeMockCiphertext } from \"./handle\";\nimport type { CleartextConfig } from \"./types\";\nimport { ConfigurationError, DecryptionFailedError, EncryptionFailedError } from \"../../errors\";\n\nconst ACL_ABI = parseAbi([\n \"function persistAllowed(bytes32 handle, address account) view returns (bool)\",\n \"function isAllowedForDecryption(bytes32 handle) view returns (bool)\",\n \"function isHandleDelegatedForUserDecryption(address delegator, address delegate, address contractAddress, bytes32 handle) view returns (bool)\",\n]);\n\nconst EXECUTOR_ABI = parseAbi([\"function plaintexts(bytes32 handle) view returns (uint256)\"]);\n\nconst STANDARD_EIP712_DOMAIN = [\n { name: \"name\", type: \"string\" },\n { name: \"version\", type: \"string\" },\n { name: \"chainId\", type: \"uint256\" },\n { name: \"verifyingContract\", type: \"address\" },\n] as const;\n\nconst USER_DECRYPT_TYPES = {\n EIP712Domain: STANDARD_EIP712_DOMAIN,\n UserDecryptRequestVerification: USER_DECRYPT_EIP712.types.UserDecryptRequestVerification,\n} satisfies KmsUserDecryptEIP712Type[\"types\"];\nconst DELEGATED_USER_DECRYPT_TYPES = {\n EIP712Domain: STANDARD_EIP712_DOMAIN,\n DelegatedUserDecryptRequestVerification:\n DELEGATED_USER_DECRYPT_EIP712.types.DelegatedUserDecryptRequestVerification,\n} satisfies KmsDelegatedUserDecryptEIP712Type[\"types\"];\nconst KMS_DECRYPTION_TYPES = {\n EIP712Domain: STANDARD_EIP712_DOMAIN,\n PublicDecryptVerification: KMS_DECRYPTION_EIP712.types.PublicDecryptVerification,\n} satisfies KmsPublicDecryptEIP712Type[\"types\"];\n\nconst FORBIDDEN_CHAIN_IDS = new Set<number>([mainnet.id, sepolia.id]);\n\n// FheTypeId constants for hot-path comparisons\nconst EBOOL_ID: FheTypeId = 0;\nconst EADDRESS_ID: FheTypeId = 7;\n\nfunction decodeClearValueType(handle: Handle, rawValue: bigint): ClearValueType {\n const typeByte = Number((BigInt(handle) >> 8n) & 0xffn);\n if (typeByte === EBOOL_ID) {\n return rawValue !== 0n;\n }\n if (typeByte === EADDRESS_ID) {\n return toHex(rawValue, { size: 20 });\n }\n return rawValue;\n}\n\nfunction normalizeEncryptValue(entry: EncryptParams[\"values\"][number]): {\n fheType: FheTypeId;\n value: bigint;\n} {\n if (!isFheTypeName(entry.type)) {\n throw new EncryptionFailedError(\"Unsupported FHE type\");\n }\n\n const fheType = fheTypeIdFromName(entry.type);\n\n let value: bigint;\n if (entry.type === \"ebool\") {\n if (typeof entry.value === \"boolean\") {\n value = entry.value ? 1n : 0n;\n } else {\n value = entry.value;\n if (value !== 0n && value !== 1n) {\n throw new EncryptionFailedError(\"Bool value must be 0, 1, true, or false\");\n }\n }\n } else if (entry.type === \"eaddress\") {\n value = BigInt(getAddress(entry.value));\n } else {\n value = entry.value;\n }\n\n if (value < 0n) {\n throw new EncryptionFailedError(\"Only non-negative cleartext values are supported\");\n }\n\n const bits = encryptionBitsFromFheTypeId(fheType);\n const maxValue = (1n << BigInt(bits)) - 1n;\n if (value > maxValue) {\n throw new EncryptionFailedError(\n `Value ${value} exceeds max ${maxValue} for FheType ${fheType}`,\n );\n }\n\n return { fheType, value };\n}\n\nexport class RelayerCleartext implements RelayerSDK {\n readonly #client: PublicClient;\n readonly #config: CleartextConfig;\n readonly kmsSigner: PrivateKeyAccount;\n readonly inputSigner: PrivateKeyAccount;\n\n constructor(config: CleartextConfig) {\n if (FORBIDDEN_CHAIN_IDS.has(config.chainId)) {\n throw new ConfigurationError(\n `Cleartext mode is not allowed on chain ${config.chainId}. ` +\n `It is intended for local development and testing only.`,\n );\n }\n this.#client = createPublicClient({\n transport: typeof config.network === \"string\" ? http(config.network) : custom(config.network),\n });\n this.#config = config;\n this.kmsSigner = privateKeyToAccount(config.kmsSignerPrivateKey ?? MOCK_KMS_SIGNER_PK);\n this.inputSigner = privateKeyToAccount(config.inputSignerPrivateKey ?? MOCK_INPUT_SIGNER_PK);\n }\n\n async generateKeypair(): Promise<KeypairType<Hex>> {\n const publicKey = toHex(crypto.getRandomValues(new Uint8Array(32)));\n let privateKey = toHex(crypto.getRandomValues(new Uint8Array(32)));\n\n while (privateKey === publicKey) {\n privateKey = toHex(crypto.getRandomValues(new Uint8Array(32)));\n }\n\n return { publicKey, privateKey };\n }\n\n async createEIP712(\n publicKey: Hex,\n contractAddresses: Address[],\n startTimestamp: number,\n durationDays = 7,\n ): Promise<EIP712TypedData> {\n return {\n domain: USER_DECRYPT_EIP712.domain(\n this.#config.chainId,\n this.#config.verifyingContractAddressDecryption,\n ) as EIP712TypedData[\"domain\"],\n types: USER_DECRYPT_TYPES,\n primaryType: \"UserDecryptRequestVerification\",\n message: {\n publicKey,\n contractAddresses,\n startTimestamp: BigInt(startTimestamp),\n durationDays: BigInt(durationDays),\n extraData: \"0x00\",\n },\n };\n }\n\n async encrypt(params: EncryptParams): Promise<EncryptResult> {\n const entries = params.values.map(normalizeEncryptValue);\n const contractAddress = getAddress(params.contractAddress);\n const userAddress = getAddress(params.userAddress);\n\n const mockCiphertexts = entries.map(({ fheType, value }) =>\n computeMockCiphertext(fheType, value, crypto.getRandomValues(new Uint8Array(32))),\n );\n\n const ciphertextBlob = keccak256(mockCiphertexts.length > 0 ? concat(mockCiphertexts) : \"0x\");\n\n const handles = entries.map(({ fheType }, index) =>\n computeInputHandle(\n ciphertextBlob,\n index,\n fheType,\n this.#config.aclContractAddress,\n BigInt(this.#config.chainId),\n ),\n );\n\n const cleartextParts = entries.map(({ value }) => pad(toHex(value), { size: 32 }));\n const cleartextBytes: Hex = cleartextParts.length > 0 ? concat(cleartextParts) : \"0x\";\n\n const signature = await this.inputSigner.signTypedData({\n domain: INPUT_VERIFICATION_EIP712.domain(\n this.#config.gatewayChainId,\n this.#config.verifyingContractAddressInputVerification,\n ),\n types: {\n CiphertextVerification: INPUT_VERIFICATION_EIP712.types.CiphertextVerification,\n },\n primaryType: \"CiphertextVerification\",\n message: {\n ctHandles: handles,\n userAddress,\n contractAddress,\n contractChainId: BigInt(this.#config.chainId),\n extraData: cleartextBytes,\n },\n });\n\n const inputProof = toBytes(\n concat([\n toHex(new Uint8Array([handles.length])),\n toHex(new Uint8Array([1])),\n ...handles,\n signature,\n cleartextBytes,\n ]),\n );\n\n return {\n handles: handles.map((handle) => toBytes(handle)),\n inputProof,\n };\n }\n\n async userDecrypt(params: UserDecryptParams): Promise<Readonly<Record<Handle, ClearValueType>>> {\n await this.#assertDecryptAuthorization(\n params.handles,\n getAddress(params.signerAddress),\n getAddress(params.contractAddress),\n \"User\",\n \"user decrypt\",\n );\n\n return this.#decryptHandles(params.handles);\n }\n\n async publicDecrypt(handles: Handle[]): Promise<PublicDecryptResult> {\n const normalizedHandles = handles;\n\n const allowedResults = await Promise.all(\n normalizedHandles.map((handle) => this.#isAllowedForDecryption(handle)),\n );\n const unauthorizedIndex = allowedResults.findIndex((isAllowed) => !isAllowed);\n if (unauthorizedIndex !== -1) {\n throw new DecryptionFailedError(\n `Handle ${normalizedHandles[unauthorizedIndex]!} is not allowed for public decryption`,\n );\n }\n\n const orderedValues = await Promise.all(\n normalizedHandles.map((handle) => this.#readPlaintext(handle)),\n );\n const clearValues: PublicDecryptResult[\"clearValues\"] = Object.fromEntries(\n normalizedHandles.map((handle, index) => [\n handle,\n decodeClearValueType(handle, orderedValues[index]!),\n ]),\n );\n\n const abiEncodedClearValues = concat(orderedValues.map((v) => pad(toHex(v), { size: 32 })));\n\n const signature = await this.kmsSigner.signTypedData({\n domain: KMS_DECRYPTION_EIP712.domain(\n this.#config.gatewayChainId,\n this.#config.verifyingContractAddressDecryption,\n ) as KmsPublicDecryptEIP712Type[\"domain\"],\n types: KMS_DECRYPTION_TYPES,\n primaryType: \"PublicDecryptVerification\",\n message: {\n ctHandles: normalizedHandles,\n decryptedResult: abiEncodedClearValues,\n extraData: \"0x\",\n },\n });\n\n const decryptionProof = concat([toHex(new Uint8Array([1])), signature]);\n\n return {\n clearValues,\n abiEncodedClearValues,\n decryptionProof,\n };\n }\n\n async createDelegatedUserDecryptEIP712(\n publicKey: Hex,\n contractAddresses: Address[],\n delegatorAddress: Address,\n startTimestamp: number,\n durationDays = 7,\n ): Promise<KmsDelegatedUserDecryptEIP712Type> {\n const message: KmsDelegatedUserDecryptEIP712Type[\"message\"] = {\n publicKey: publicKey as KmsDelegatedUserDecryptEIP712Type[\"message\"][\"publicKey\"],\n contractAddresses,\n delegatorAddress: getAddress(delegatorAddress),\n startTimestamp: String(startTimestamp),\n durationDays: String(durationDays),\n extraData: \"0x00\",\n };\n\n return {\n domain: DELEGATED_USER_DECRYPT_EIP712.domain(\n BigInt(this.#config.chainId),\n this.#config.verifyingContractAddressDecryption,\n ) as KmsDelegatedUserDecryptEIP712Type[\"domain\"],\n types: DELEGATED_USER_DECRYPT_TYPES,\n primaryType: \"DelegatedUserDecryptRequestVerification\",\n message,\n };\n }\n\n async delegatedUserDecrypt(\n params: DelegatedUserDecryptParams,\n ): Promise<Readonly<Record<Handle, ClearValueType>>> {\n await this.#assertDelegation(\n params.handles,\n getAddress(params.delegatorAddress),\n getAddress(params.delegateAddress),\n getAddress(params.contractAddress),\n );\n\n return this.#decryptHandles(params.handles);\n }\n\n async requestZKProofVerification(_zkProof: ZKProofLike): Promise<InputProofBytesType> {\n throw new ConfigurationError(\"Not implemented in cleartext mode\");\n }\n\n async getPublicKey(): Promise<{ publicKeyId: string; publicKey: Uint8Array } | null> {\n return { publicKeyId: \"mock-public-key-id\", publicKey: new Uint8Array([32]) };\n }\n\n async getPublicParams(\n _bits: number,\n ): Promise<{ publicParams: Uint8Array; publicParamsId: string } | null> {\n return { publicParams: new Uint8Array([32]), publicParamsId: \"mock-public-params-id\" };\n }\n\n async getAclAddress(): Promise<Address> {\n return this.#config.aclContractAddress;\n }\n\n terminate(): void {\n // No resources to release in cleartext mode.\n }\n\n async #decryptHandles(\n normalizedHandles: Handle[],\n ): Promise<Readonly<Record<Handle, ClearValueType>>> {\n const values = await Promise.all(\n normalizedHandles.map((handle) => this.#readPlaintext(handle)),\n );\n\n return Object.fromEntries(\n normalizedHandles.map((handle, index) => [\n handle,\n decodeClearValueType(handle, values[index]!),\n ]),\n );\n }\n\n async #assertDecryptAuthorization(\n normalizedHandles: Handle[],\n actorAddress: Address,\n contractAddress: Address,\n actorLabel: \"User\" | \"Delegator\",\n operationLabel: \"user decrypt\" | \"delegated decrypt\",\n ): Promise<void> {\n if (actorAddress === contractAddress) {\n throw new DecryptionFailedError(\n `${actorLabel} address ${actorAddress} must not equal contract address for ${operationLabel}`,\n );\n }\n\n const results = await Promise.all(\n normalizedHandles.flatMap((handle) => [\n this.#persistAllowed(handle, actorAddress),\n this.#persistAllowed(handle, contractAddress),\n ]),\n );\n\n for (let i = 0; i < normalizedHandles.length; i++) {\n const actorAllowed = results[i * 2];\n const contractAllowed = results[i * 2 + 1];\n if (!actorAllowed) {\n throw new DecryptionFailedError(\n `${actorLabel} ${actorAddress} is not authorized for ${operationLabel} of handle ${normalizedHandles[i]!}`,\n );\n }\n if (!contractAllowed) {\n throw new DecryptionFailedError(\n `Contract ${contractAddress} is not authorized for ${operationLabel} of handle ${normalizedHandles[i]!}`,\n );\n }\n }\n }\n\n async #assertDelegation(\n handles: Handle[],\n delegatorAddress: Address,\n delegateAddress: Address,\n contractAddress: Address,\n ): Promise<void> {\n const results = await Promise.all(\n handles.map((handle) =>\n this.#client.readContract({\n address: this.#config.aclContractAddress,\n abi: ACL_ABI,\n functionName: \"isHandleDelegatedForUserDecryption\",\n args: [delegatorAddress, delegateAddress, contractAddress, handle],\n }),\n ),\n );\n\n for (let i = 0; i < handles.length; i++) {\n if (!results[i]) {\n throw new DecryptionFailedError(\n `Handle ${handles[i]!} is not delegated for user decryption`,\n );\n }\n }\n }\n\n async #persistAllowed(handle: Handle, account: Address): Promise<boolean> {\n return this.#client.readContract({\n address: this.#config.aclContractAddress,\n abi: ACL_ABI,\n functionName: \"persistAllowed\",\n args: [handle, account],\n });\n }\n\n async #isAllowedForDecryption(handle: Handle): Promise<boolean> {\n return this.#client.readContract({\n address: this.#config.aclContractAddress,\n abi: ACL_ABI,\n functionName: \"isAllowedForDecryption\",\n args: [handle],\n });\n }\n\n async #readPlaintext(handle: Handle): Promise<bigint> {\n return this.#client.readContract({\n address: this.#config.executorAddress as Address,\n abi: EXECUTOR_ABI,\n functionName: \"plaintexts\",\n args: [handle],\n });\n }\n}\n","import { HardhatConfig } from \"../relayer-utils\";\nimport type { CleartextConfig } from \"./types\";\n\n/**\n * Hardhat local network configuration (chainId 31337).\n *\n * The addresses in this configuration must match those of your deployment.\n * Ensure that the executor address and other contract addresses correspond to\n * the contracts deployed on your Hardhat network.\n */\nexport const hardhatCleartextConfig = {\n ...HardhatConfig,\n executorAddress: \"0xe3a9105a3a932253A70F126eb1E3b589C643dD24\",\n} satisfies CleartextConfig;\n\nexport const hoodiCleartextConfig = {\n chainId: 560048,\n network: \"https://rpc.hoodi.ethpandaops.io\",\n gatewayChainId: HardhatConfig.gatewayChainId,\n aclContractAddress: \"0x6D3FAf6f86e1fF9F3B0831Dda920AbA1cBd5bd68\",\n executorAddress: \"0xC316692627de536368d82e9121F1D44a550894E6\",\n // The values used when configuring the deployments are the same as those used for a hardhat deployment, since there's no gateway chain.\n verifyingContractAddressDecryption: HardhatConfig.verifyingContractAddressDecryption,\n verifyingContractAddressInputVerification:\n HardhatConfig.verifyingContractAddressInputVerification,\n registryAddress: \"0x1807aE2f693F8530DFB126D0eF98F2F2518F292f\",\n} satisfies CleartextConfig;\n"],"mappings":"iaAUA,MAAM,GAA8B,EAAS,KAAuB,CAClE,KAAM,oBACN,QAAS,IACT,QAAS,OAAO,EAAQ,CACxB,oBACD,EAEK,GAAmC,EAAS,KAAuB,CACvE,KAAM,aACN,QAAS,IACT,QAAS,OAAO,EAAQ,CACxB,oBACD,EAEY,EAA4B,CACvC,OAAQ,EACR,MAAO,CACL,uBAAwB,CACtB,CAAE,KAAM,YAAa,KAAM,YAAa,CACxC,CAAE,KAAM,cAAe,KAAM,UAAW,CACxC,CAAE,KAA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ends t{constructor(t,n){super(e.EncryptionFailed,t,n),this.name=`EncryptionFailedError`}},r=class extends t{constructor(t,n){super(e.DecryptionFailed,t,n),this.name=`DecryptionFailedError`}};export{n,r as t};
2
- //# sourceMappingURL=encryption-CKqGKzHs.js.map
1
+ import{i as e,r as t}from"./relayer-DfjPWTBf.js";var n=class extends t{constructor(t,n){super(e.EncryptionFailed,t,n),this.name=`EncryptionFailedError`}},r=class extends t{constructor(t,n){super(e.DecryptionFailed,t,n),this.name=`DecryptionFailedError`}};export{n,r as t};
2
+ //# sourceMappingURL=encryption-UaXE1L_W.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"encryption-CKqGKzHs.js","names":[],"sources":["../../src/errors/encryption.ts"],"sourcesContent":["import { ZamaError, ZamaErrorCode } from \"./base\";\n\n/** FHE encryption failed. */\nexport class EncryptionFailedError extends ZamaError {\n constructor(message: string, options?: ErrorOptions) {\n super(ZamaErrorCode.EncryptionFailed, message, options);\n this.name = \"EncryptionFailedError\";\n }\n}\n\n/** FHE decryption failed. */\nexport class DecryptionFailedError extends ZamaError {\n constructor(message: string, options?: ErrorOptions) {\n super(ZamaErrorCode.DecryptionFailed, message, options);\n this.name = \"DecryptionFailedError\";\n }\n}\n"],"mappings":"iDAGA,IAAa,EAAb,cAA2C,CAAU,CACnD,YAAY,EAAiB,EAAwB,CACnD,MAAM,EAAc,iBAAkB,EAAS,EAAQ,CACvD,KAAK,KAAO,0BAKH,EAAb,cAA2C,CAAU,CACnD,YAAY,EAAiB,EAAwB,CACnD,MAAM,EAAc,iBAAkB,EAAS,EAAQ,CACvD,KAAK,KAAO"}
1
+ {"version":3,"file":"encryption-UaXE1L_W.js","names":[],"sources":["../../src/errors/encryption.ts"],"sourcesContent":["import { ZamaError, ZamaErrorCode } from \"./base\";\n\n/** FHE encryption failed. */\nexport class EncryptionFailedError extends ZamaError {\n constructor(message: string, options?: ErrorOptions) {\n super(ZamaErrorCode.EncryptionFailed, message, options);\n this.name = \"EncryptionFailedError\";\n }\n}\n\n/** FHE decryption failed. */\nexport class DecryptionFailedError extends ZamaError {\n constructor(message: string, options?: ErrorOptions) {\n super(ZamaErrorCode.DecryptionFailed, message, options);\n this.name = \"DecryptionFailedError\";\n }\n}\n"],"mappings":"iDAGA,IAAa,EAAb,cAA2C,CAAU,CACnD,YAAY,EAAiB,EAAwB,CACnD,MAAM,EAAc,iBAAkB,EAAS,EAAQ,CACvD,KAAK,KAAO,0BAKH,EAAb,cAA2C,CAAU,CACnD,YAAY,EAAiB,EAAwB,CACnD,MAAM,EAAc,iBAAkB,EAAS,EAAQ,CACvD,KAAK,KAAO"}
@@ -1,5 +1,5 @@
1
1
  import { A as WriteContractConfig, E as ReadContractConfig, S as TransactionReceipt, b as SignerLifecycleCallbacks, n as EIP712TypedData, o as Handle, y as GenericSigner } from "../relayer-sdk.types-D7rylLS4.js";
2
- import { m as BatchTransferData } from "../index-IhsduS7h.js";
2
+ import { h as BatchTransferData } from "../index-j4Uv5iQi.js";
3
3
  import { Abi, Address, ContractFunctionArgs, ContractFunctionName, ContractFunctionReturnType, EIP1193EventMap, EIP1193Events, EIP1193Provider, EIP1193Provider as EIP1193Provider$1, Hex, ProviderConnectInfo, ProviderMessage, ProviderRpcError } from "viem";
4
4
  import { Signer, ethers } from "ethers";
5
5
 
@@ -28487,6 +28487,32 @@ declare function delegateForUserDecryptionContract(aclAddress: Address, delegate
28487
28487
  }];
28488
28488
  readonly stateMutability: "view";
28489
28489
  readonly type: "function";
28490
+ }, {
28491
+ readonly inputs: readonly [{
28492
+ readonly internalType: "address";
28493
+ readonly name: "delegator";
28494
+ readonly type: "address";
28495
+ }, {
28496
+ readonly internalType: "address";
28497
+ readonly name: "delegate";
28498
+ readonly type: "address";
28499
+ }, {
28500
+ readonly internalType: "address";
28501
+ readonly name: "contractAddress";
28502
+ readonly type: "address";
28503
+ }, {
28504
+ readonly internalType: "bytes32";
28505
+ readonly name: "handle";
28506
+ readonly type: "bytes32";
28507
+ }];
28508
+ readonly name: "isHandleDelegatedForUserDecryption";
28509
+ readonly outputs: readonly [{
28510
+ readonly internalType: "bool";
28511
+ readonly name: "";
28512
+ readonly type: "bool";
28513
+ }];
28514
+ readonly stateMutability: "view";
28515
+ readonly type: "function";
28490
28516
  }];
28491
28517
  readonly functionName: "delegateForUserDecryption";
28492
28518
  readonly args: readonly [`0x${string}`, `0x${string}`, bigint];
@@ -28557,6 +28583,32 @@ declare function revokeDelegationContract(aclAddress: Address, delegateAddress:
28557
28583
  }];
28558
28584
  readonly stateMutability: "view";
28559
28585
  readonly type: "function";
28586
+ }, {
28587
+ readonly inputs: readonly [{
28588
+ readonly internalType: "address";
28589
+ readonly name: "delegator";
28590
+ readonly type: "address";
28591
+ }, {
28592
+ readonly internalType: "address";
28593
+ readonly name: "delegate";
28594
+ readonly type: "address";
28595
+ }, {
28596
+ readonly internalType: "address";
28597
+ readonly name: "contractAddress";
28598
+ readonly type: "address";
28599
+ }, {
28600
+ readonly internalType: "bytes32";
28601
+ readonly name: "handle";
28602
+ readonly type: "bytes32";
28603
+ }];
28604
+ readonly name: "isHandleDelegatedForUserDecryption";
28605
+ readonly outputs: readonly [{
28606
+ readonly internalType: "bool";
28607
+ readonly name: "";
28608
+ readonly type: "bool";
28609
+ }];
28610
+ readonly stateMutability: "view";
28611
+ readonly type: "function";
28560
28612
  }];
28561
28613
  readonly functionName: "revokeDelegationForUserDecryption";
28562
28614
  readonly args: readonly [`0x${string}`, `0x${string}`];
@@ -28627,10 +28679,132 @@ declare function getDelegationExpiryContract(aclAddress: Address, delegatorAddre
28627
28679
  }];
28628
28680
  readonly stateMutability: "view";
28629
28681
  readonly type: "function";
28682
+ }, {
28683
+ readonly inputs: readonly [{
28684
+ readonly internalType: "address";
28685
+ readonly name: "delegator";
28686
+ readonly type: "address";
28687
+ }, {
28688
+ readonly internalType: "address";
28689
+ readonly name: "delegate";
28690
+ readonly type: "address";
28691
+ }, {
28692
+ readonly internalType: "address";
28693
+ readonly name: "contractAddress";
28694
+ readonly type: "address";
28695
+ }, {
28696
+ readonly internalType: "bytes32";
28697
+ readonly name: "handle";
28698
+ readonly type: "bytes32";
28699
+ }];
28700
+ readonly name: "isHandleDelegatedForUserDecryption";
28701
+ readonly outputs: readonly [{
28702
+ readonly internalType: "bool";
28703
+ readonly name: "";
28704
+ readonly type: "bool";
28705
+ }];
28706
+ readonly stateMutability: "view";
28707
+ readonly type: "function";
28630
28708
  }];
28631
28709
  readonly functionName: "getUserDecryptionDelegationExpirationDate";
28632
28710
  readonly args: readonly [`0x${string}`, `0x${string}`, `0x${string}`];
28633
28711
  };
28712
+ /**
28713
+ * Returns the contract config to check if a specific handle is delegated.
28714
+ *
28715
+ * @example
28716
+ * ```ts
28717
+ * const isDelegated = await signer.readContract(
28718
+ * isHandleDelegatedContract(aclAddress, delegatorAddress, delegateAddress, contractAddress, handle),
28719
+ * );
28720
+ * ```
28721
+ */
28722
+ declare function isHandleDelegatedContract(aclAddress: Address, delegatorAddress: Address, delegateAddress: Address, contractAddress: Address, handle: `0x${string}`): {
28723
+ readonly address: `0x${string}`;
28724
+ readonly abi: readonly [{
28725
+ readonly inputs: readonly [{
28726
+ readonly internalType: "address";
28727
+ readonly name: "delegate";
28728
+ readonly type: "address";
28729
+ }, {
28730
+ readonly internalType: "address";
28731
+ readonly name: "contractAddress";
28732
+ readonly type: "address";
28733
+ }, {
28734
+ readonly internalType: "uint64";
28735
+ readonly name: "expirationDate";
28736
+ readonly type: "uint64";
28737
+ }];
28738
+ readonly name: "delegateForUserDecryption";
28739
+ readonly outputs: readonly [];
28740
+ readonly stateMutability: "nonpayable";
28741
+ readonly type: "function";
28742
+ }, {
28743
+ readonly inputs: readonly [{
28744
+ readonly internalType: "address";
28745
+ readonly name: "delegate";
28746
+ readonly type: "address";
28747
+ }, {
28748
+ readonly internalType: "address";
28749
+ readonly name: "contractAddress";
28750
+ readonly type: "address";
28751
+ }];
28752
+ readonly name: "revokeDelegationForUserDecryption";
28753
+ readonly outputs: readonly [];
28754
+ readonly stateMutability: "nonpayable";
28755
+ readonly type: "function";
28756
+ }, {
28757
+ readonly inputs: readonly [{
28758
+ readonly internalType: "address";
28759
+ readonly name: "delegator";
28760
+ readonly type: "address";
28761
+ }, {
28762
+ readonly internalType: "address";
28763
+ readonly name: "delegate";
28764
+ readonly type: "address";
28765
+ }, {
28766
+ readonly internalType: "address";
28767
+ readonly name: "contractAddress";
28768
+ readonly type: "address";
28769
+ }];
28770
+ readonly name: "getUserDecryptionDelegationExpirationDate";
28771
+ readonly outputs: readonly [{
28772
+ readonly internalType: "uint64";
28773
+ readonly name: "";
28774
+ readonly type: "uint64";
28775
+ }];
28776
+ readonly stateMutability: "view";
28777
+ readonly type: "function";
28778
+ }, {
28779
+ readonly inputs: readonly [{
28780
+ readonly internalType: "address";
28781
+ readonly name: "delegator";
28782
+ readonly type: "address";
28783
+ }, {
28784
+ readonly internalType: "address";
28785
+ readonly name: "delegate";
28786
+ readonly type: "address";
28787
+ }, {
28788
+ readonly internalType: "address";
28789
+ readonly name: "contractAddress";
28790
+ readonly type: "address";
28791
+ }, {
28792
+ readonly internalType: "bytes32";
28793
+ readonly name: "handle";
28794
+ readonly type: "bytes32";
28795
+ }];
28796
+ readonly name: "isHandleDelegatedForUserDecryption";
28797
+ readonly outputs: readonly [{
28798
+ readonly internalType: "bool";
28799
+ readonly name: "";
28800
+ readonly type: "bool";
28801
+ }];
28802
+ readonly stateMutability: "view";
28803
+ readonly type: "function";
28804
+ }];
28805
+ readonly functionName: "isHandleDelegatedForUserDecryption";
28806
+ readonly args: readonly [`0x${string}`, `0x${string}`, `0x${string}`, `0x${string}`];
28807
+ };
28634
28808
  //#endregion
28635
28809
  //#region src/contracts/wrappers-registry.d.ts
28636
28810
  interface TokenWrapperPair {
@@ -29759,5 +29933,5 @@ declare function isConfidentialTokenValidContract(registry: Address, confidentia
29759
29933
  readonly args: readonly [`0x${string}`];
29760
29934
  };
29761
29935
  //#endregion
29762
- export { decimalsContract as A, confidentialTransferFromContract as B, isConfidentialWrapperContract as C, allowanceContract as D, wrapperExistsContract as E, wrapContract as F, setFinalizeUnwrapOperatorContract as G, isFinalizeUnwrapOperatorContract as H, wrapETHContract as I, unwrapContract as J, setOperatorContract as K, confidentialBalanceOfContract as L, symbolContract as M, finalizeUnwrapContract as N, approveContract as O, underlyingContract as P, confidentialTotalSupplyContract as R, isConfidentialTokenContract as S, getWrapperContract as T, isOperatorContract as U, deploymentCoordinatorContract as V, rateContract as W, unwrapFromBalanceContract as Y, getFeeRecipientContract as _, getTokenAddressContract as a, ERC7984_INTERFACE_ID as b, getTokenPairsLengthContract as c, delegateForUserDecryptionContract as d, getDelegationExpiryContract as f, getBatchTransferFeeContract as g, confidentialBatchTransferContract as h, getConfidentialTokenAddressContract as i, nameContract as j, balanceOfContract as k, getTokenPairsSliceContract as l, BatchTransferData as m, TokenWrapperPair as n, getTokenPairContract as o, revokeDelegationContract as p, totalSupplyContract as q, TokenWrapperPairWithMetadata as r, getTokenPairsContract as s, PaginatedResult as t, isConfidentialTokenValidContract as u, getUnwrapFeeContract as v, supportsInterfaceContract as w, ERC7984_WRAPPER_INTERFACE_ID as x, getWrapFeeContract as y, confidentialTransferContract as z };
29763
- //# sourceMappingURL=index-IhsduS7h.d.ts.map
29936
+ export { balanceOfContract as A, confidentialTransferContract as B, isConfidentialTokenContract as C, wrapperExistsContract as D, getWrapperContract as E, underlyingContract as F, rateContract as G, deploymentCoordinatorContract as H, wrapContract as I, totalSupplyContract as J, setFinalizeUnwrapOperatorContract as K, wrapETHContract as L, nameContract as M, symbolContract as N, allowanceContract as O, finalizeUnwrapContract as P, confidentialBalanceOfContract as R, ERC7984_WRAPPER_INTERFACE_ID as S, supportsInterfaceContract as T, isFinalizeUnwrapOperatorContract as U, confidentialTransferFromContract as V, isOperatorContract as W, unwrapFromBalanceContract as X, unwrapContract as Y, getBatchTransferFeeContract as _, getTokenAddressContract as a, getWrapFeeContract as b, getTokenPairsLengthContract as c, delegateForUserDecryptionContract as d, getDelegationExpiryContract as f, confidentialBatchTransferContract as g, BatchTransferData as h, getConfidentialTokenAddressContract as i, decimalsContract as j, approveContract as k, getTokenPairsSliceContract as l, revokeDelegationContract as m, TokenWrapperPair as n, getTokenPairContract as o, isHandleDelegatedContract as p, setOperatorContract as q, TokenWrapperPairWithMetadata as r, getTokenPairsContract as s, PaginatedResult as t, isConfidentialTokenValidContract as u, getFeeRecipientContract as v, isConfidentialWrapperContract as w, ERC7984_INTERFACE_ID as x, getUnwrapFeeContract as y, confidentialTotalSupplyContract as z };
29937
+ //# sourceMappingURL=index-j4Uv5iQi.d.ts.map
@@ -1,8 +1,8 @@
1
1
  import { A as WriteContractConfig, C as TransactionResult, D as ReadContractReturnType, E as ReadContractConfig, J as GenericLogger, O as ReadFunctionName, S as TransactionReceipt, T as ReadContractArgs, _ as StoredCredentials, a as EncryptResult, b as SignerLifecycleCallbacks, c as PublicDecryptResult, d as RelayerWebSecurityConfig, f as UserDecryptParams, g as DelegatedStoredCredentials, h as UnshieldCallbacks, i as EncryptParams, j as WriteFunctionName, k as WriteContractArgs, l as RelayerSDKStatus, m as TransferCallbacks, n as EIP712TypedData, o as Handle, p as ShieldCallbacks, r as EncryptInput, s as NetworkType, t as DelegatedUserDecryptParams, u as RelayerWebConfig, v as GenericStorage, w as ContractAbi, x as RawLog, y as GenericSigner } from "./relayer-sdk.types-D7rylLS4.js";
2
- import { A as decimalsContract, B as confidentialTransferFromContract, C as isConfidentialWrapperContract, D as allowanceContract, E as wrapperExistsContract, F as wrapContract, G as setFinalizeUnwrapOperatorContract, H as isFinalizeUnwrapOperatorContract, I as wrapETHContract, J as unwrapContract, K as setOperatorContract, L as confidentialBalanceOfContract, M as symbolContract, N as finalizeUnwrapContract, O as approveContract, P as underlyingContract, R as confidentialTotalSupplyContract, S as isConfidentialTokenContract, T as getWrapperContract, U as isOperatorContract, V as deploymentCoordinatorContract, W as rateContract, Y as unwrapFromBalanceContract, _ as getFeeRecipientContract, a as getTokenAddressContract, b as ERC7984_INTERFACE_ID, c as getTokenPairsLengthContract, d as delegateForUserDecryptionContract, f as getDelegationExpiryContract, g as getBatchTransferFeeContract, h as confidentialBatchTransferContract, i as getConfidentialTokenAddressContract, j as nameContract, k as balanceOfContract, l as getTokenPairsSliceContract, m as BatchTransferData, n as TokenWrapperPair, o as getTokenPairContract, p as revokeDelegationContract, q as totalSupplyContract, r as TokenWrapperPairWithMetadata, s as getTokenPairsContract, t as PaginatedResult, u as isConfidentialTokenValidContract, v as getUnwrapFeeContract, w as supportsInterfaceContract, x as ERC7984_WRAPPER_INTERFACE_ID, y as getWrapFeeContract, z as confidentialTransferContract } from "./index-IhsduS7h.js";
2
+ import { A as balanceOfContract, B as confidentialTransferContract, C as isConfidentialTokenContract, D as wrapperExistsContract, E as getWrapperContract, F as underlyingContract, G as rateContract, H as deploymentCoordinatorContract, I as wrapContract, J as totalSupplyContract, K as setFinalizeUnwrapOperatorContract, L as wrapETHContract, M as nameContract, N as symbolContract, O as allowanceContract, P as finalizeUnwrapContract, R as confidentialBalanceOfContract, S as ERC7984_WRAPPER_INTERFACE_ID, T as supportsInterfaceContract, U as isFinalizeUnwrapOperatorContract, V as confidentialTransferFromContract, W as isOperatorContract, X as unwrapFromBalanceContract, Y as unwrapContract, _ as getBatchTransferFeeContract, a as getTokenAddressContract, b as getWrapFeeContract, c as getTokenPairsLengthContract, d as delegateForUserDecryptionContract, f as getDelegationExpiryContract, g as confidentialBatchTransferContract, h as BatchTransferData, i as getConfidentialTokenAddressContract, j as decimalsContract, k as approveContract, l as getTokenPairsSliceContract, m as revokeDelegationContract, n as TokenWrapperPair, o as getTokenPairContract, p as isHandleDelegatedContract, q as setOperatorContract, r as TokenWrapperPairWithMetadata, s as getTokenPairsContract, t as PaginatedResult, u as isConfidentialTokenValidContract, v as getFeeRecipientContract, w as isConfidentialWrapperContract, x as ERC7984_INTERFACE_ID, y as getUnwrapFeeContract, z as confidentialTotalSupplyContract } from "./index-j4Uv5iQi.js";
3
3
  import { t as RelayerSDK } from "./relayer-sdk-CcIghrEq.js";
4
4
  import { n as MainnetConfig, r as SepoliaConfig, t as HardhatConfig } from "./relayer-utils-BcTAyZOr.js";
5
- import { $ as CredentialsCreatedEvent, A as ListPairsOptions, B as ReadonlyToken, C as decodeUnwrappedStarted, Ct as ZamaSDKEvent, D as ZamaSDK, Dt as ZamaSDKEvents, E as findWrapped, Et as ZamaSDKEventType, F as ZamaError, G as CredentialsManager, H as ZERO_HANDLE, I as ZamaErrorCode, J as ApproveUnderlyingSubmittedEvent, K as CredentialsManagerConfig, L as matchZamaError, M as WrappersRegistryConfig, N as Token, O as ZamaSDKConfig, P as TokenConfig, Q as CredentialsCorruptedEvent, R as BatchDecryptAsOptions, S as decodeUnwrappedFinalized, St as UnwrapSubmittedEvent, T as findUnwrapRequested, Tt as ZamaSDKEventListener, U as DelegatedCredentialsManager, V as ReadonlyTokenConfig, W as DelegatedCredentialsManagerConfig, X as CredentialsAllowedEvent, Y as BaseEvent, Z as CredentialsCachedEvent, _ as WrappedEvent, _t as TransferFromSubmittedEvent, a as ActivityType, at as DecryptEndEvent, b as decodeOnChainEvents, bt as UnshieldPhase2StartedEvent, c as parseActivityFeed, ct as DelegationSubmittedEvent, d as OnChainEvent, dt as EncryptStartEvent, et as CredentialsCreatingEvent, f as TOKEN_TOPICS, ft as FinalizeUnwrapSubmittedEvent, g as UnwrappedStartedEvent, gt as TransactionErrorEvent, h as UnwrappedFinalizedEvent, ht as ShieldSubmittedEvent, i as ActivityLogMetadata, it as CredentialsRevokedEvent, j as WrappersRegistry, k as DefaultRegistryAddresses, l as sortByBlockNumber, lt as EncryptEndEvent, m as UnwrapRequestedEvent, mt as SessionExpiredEvent, n as ActivityDirection, nt as CredentialsLoadingEvent, o as applyDecryptedValues, ot as DecryptErrorEvent, p as Topics, pt as RevokeDelegationSubmittedEvent, q as ApproveSubmittedEvent, r as ActivityItem, rt as CredentialsPersistFailedEvent, s as extractEncryptedHandles, st as DecryptStartEvent, t as ActivityAmount, tt as CredentialsExpiredEvent, u as ConfidentialTransferEvent, ut as EncryptErrorEvent, v as decodeConfidentialTransfer, vt as TransferSubmittedEvent, w as decodeWrapped, wt as ZamaSDKEventInput, x as decodeUnwrapRequested, xt as UnshieldPhase2SubmittedEvent, y as decodeOnChainEvent, yt as UnshieldPhase1SubmittedEvent, z as BatchDecryptOptions } from "./activity-CcKSL6Oe.js";
5
+ import { $ as ZERO_HANDLE, A as decodeUnwrapRequested, At as UnshieldPhase1SubmittedEvent, B as DefaultRegistryAddresses, C as decodeAclEvent, Ct as FinalizeUnwrapSubmittedEvent, D as decodeOnChainEvent, Dt as TransactionErrorEvent, E as decodeDelegatedForUserDecryption, Et as ShieldSubmittedEvent, F as findRevokedDelegationForUserDecryption, Ft as ZamaSDKEventInput, G as TokenConfig, H as WrappersRegistry, I as findUnwrapRequested, It as ZamaSDKEventListener, J as matchZamaError, K as ZamaError, L as findWrapped, Lt as ZamaSDKEventType, M as decodeUnwrappedStarted, Mt as UnshieldPhase2SubmittedEvent, N as decodeWrapped, Nt as UnwrapSubmittedEvent, O as decodeOnChainEvents, Ot as TransferFromSubmittedEvent, P as findDelegatedForUserDecryption, Pt as ZamaSDKEvent, Q as ReadonlyTokenConfig, R as ZamaSDK, Rt as ZamaSDKEvents, S as WrappedEvent, St as EncryptStartEvent, T as decodeConfidentialTransfer, Tt as SessionExpiredEvent, U as WrappersRegistryConfig, V as ListPairsOptions, W as Token, X as BatchDecryptOptions, Y as BatchDecryptAsOptions, Z as ReadonlyToken, _ as TOKEN_TOPICS, _t as DecryptErrorEvent, a as ActivityType, at as ApproveUnderlyingSubmittedEvent, b as UnwrappedFinalizedEvent, bt as EncryptEndEvent, c as parseActivityFeed, ct as CredentialsCachedEvent, d as AclEvent, dt as CredentialsCreatingEvent, et as DelegatedCredentialsManager, f as AclTopics, ft as CredentialsExpiredEvent, g as RevokedDelegationForUserDecryptionEvent, gt as DecryptEndEvent, h as OnChainEvent, ht as CredentialsRevokedEvent, i as ActivityLogMetadata, it as ApproveSubmittedEvent, j as decodeUnwrappedFinalized, jt as UnshieldPhase2StartedEvent, k as decodeRevokedDelegationForUserDecryption, kt as TransferSubmittedEvent, l as sortByBlockNumber, lt as CredentialsCorruptedEvent, m as DelegatedForUserDecryptionEvent, mt as CredentialsPersistFailedEvent, n as ActivityDirection, nt as CredentialsManager, o as applyDecryptedValues, ot as BaseEvent, p as ConfidentialTransferEvent, pt as CredentialsLoadingEvent, q as ZamaErrorCode, r as ActivityItem, rt as CredentialsManagerConfig, s as extractEncryptedHandles, st as CredentialsAllowedEvent, t as ActivityAmount, tt as DelegatedCredentialsManagerConfig, u as ACL_TOPICS, ut as CredentialsCreatedEvent, v as Topics, vt as DecryptStartEvent, w as decodeAclEvents, wt as RevokeDelegationSubmittedEvent, x as UnwrappedStartedEvent, xt as EncryptErrorEvent, y as UnwrapRequestedEvent, yt as DelegationSubmittedEvent, z as ZamaSDKConfig } from "./activity-q99hCR8n.js";
6
6
  import { Address, Address as Address$1, Hex, Hex as Hex$1 } from "viem";
7
7
  import { ClearValueType, ClearValueType as ClearValueType$1, FheTypeName, FhevmInstanceConfig, InputProofBytesType, InputProofBytesType as InputProofBytesType$1, KeypairType, KeypairType as KeypairType$1, KmsDelegatedUserDecryptEIP712Type, KmsDelegatedUserDecryptEIP712Type as KmsDelegatedUserDecryptEIP712Type$1, ZKProofLike, ZKProofLike as ZKProofLike$1 } from "@zama-fhe/relayer-sdk/bundle";
8
8
 
@@ -171,6 +171,26 @@ declare class DelegationNotFoundError extends ZamaError {
171
171
  declare class DelegationExpiredError extends ZamaError {
172
172
  constructor(message: string, options?: ErrorOptions);
173
173
  }
174
+ /** The new expiration date equals the current one. */
175
+ declare class DelegationExpiryUnchangedError extends ZamaError {
176
+ constructor(message: string, options?: ErrorOptions);
177
+ }
178
+ /** Delegate address cannot be the contract address. */
179
+ declare class DelegationDelegateEqualsContractError extends ZamaError {
180
+ constructor(message: string, options?: ErrorOptions);
181
+ }
182
+ /** Contract address cannot be the sender address. */
183
+ declare class DelegationContractIsSelfError extends ZamaError {
184
+ constructor(message: string, options?: ErrorOptions);
185
+ }
186
+ /** The ACL contract is paused. */
187
+ declare class AclPausedError extends ZamaError {
188
+ constructor(message: string, options?: ErrorOptions);
189
+ }
190
+ /** Expiration date is too soon (must be at least 1 hour in the future). */
191
+ declare class DelegationExpirationTooSoonError extends ZamaError {
192
+ constructor(message: string, options?: ErrorOptions);
193
+ }
174
194
  /**
175
195
  * Delegation exists on L1 but hasn't propagated to the gateway yet.
176
196
  *
@@ -191,6 +211,16 @@ declare class DelegationNotPropagatedError extends ZamaError {
191
211
  constructor(message: string, options?: ErrorOptions);
192
212
  }
193
213
  //#endregion
214
+ //#region src/errors/acl-revert.d.ts
215
+ /**
216
+ * Map known ACL Solidity revert error names to typed ZamaError subclasses.
217
+ * Prefers viem's structured `error.cause.data.errorName` when available,
218
+ * falling back to string-includes matching on the error message.
219
+ * Returns `null` if the revert reason is not recognized.
220
+ * @public
221
+ */
222
+ declare function matchAclRevert(error: unknown): ZamaError | null;
223
+ //#endregion
194
224
  //#region src/token/pending-unshield.d.ts
195
225
  /**
196
226
  * Persist the unwrap tx hash so an interrupted unshield can be resumed later
@@ -264,5 +294,5 @@ declare class ChromeSessionStorage implements GenericStorage {
264
294
  /** Default singleton for application-wide use. */
265
295
  declare const chromeSessionStorage: ChromeSessionStorage;
266
296
  //#endregion
267
- export { type ActivityAmount, type ActivityDirection, type ActivityItem, type ActivityLogMetadata, type ActivityType, type Address, ApprovalFailedError, type ApproveSubmittedEvent, type ApproveUnderlyingSubmittedEvent, type BaseEvent, type BatchDecryptAsOptions, type BatchDecryptOptions, type BatchTransferData, ChromeSessionStorage, type ClearValueType, type ConfidentialTransferEvent, ConfigurationError, type ContractAbi, type CredentialsAllowedEvent, type CredentialsCachedEvent, type CredentialsCorruptedEvent, type CredentialsCreatedEvent, type CredentialsCreatingEvent, type CredentialsExpiredEvent, type CredentialsLoadingEvent, CredentialsManager, type CredentialsManagerConfig, type CredentialsPersistFailedEvent, type CredentialsRevokedEvent, type DecryptEndEvent, type DecryptErrorEvent, type DecryptStartEvent, DecryptionFailedError, DefaultRegistryAddresses, DelegatedCredentialsManager, type DelegatedCredentialsManagerConfig, type DelegatedStoredCredentials, type DelegatedUserDecryptParams, DelegationCooldownError, DelegationExpiredError, DelegationNotFoundError, DelegationNotPropagatedError, DelegationSelfNotAllowedError, type DelegationSubmittedEvent, type EIP712TypedData, ERC7984_INTERFACE_ID, ERC7984_WRAPPER_INTERFACE_ID, type EncryptEndEvent, type EncryptErrorEvent, type EncryptInput, type EncryptParams, type EncryptResult, type EncryptStartEvent, EncryptionFailedError, type FheTypeName, type FhevmInstanceConfig, type FinalizeUnwrapSubmittedEvent, type GenericLogger, type GenericSigner, type GenericStorage, type Handle, HardhatConfig, type Hex, IndexedDBStorage, type InputProofBytesType, InvalidKeypairError, KeypairExpiredError, type KeypairType, type KmsDelegatedUserDecryptEIP712Type, type ListPairsOptions, MainnetConfig, MemoryStorage, type NetworkType, NoCiphertextError, type OnChainEvent, type PaginatedResult, type PublicDecryptResult, type RawLog, type ReadContractArgs, type ReadContractConfig, type ReadContractReturnType, type ReadFunctionName, ReadonlyToken, type ReadonlyTokenConfig, RelayerRequestFailedError, type RelayerSDK, type RelayerSDKStatus, RelayerWeb, type RelayerWebConfig, type RelayerWebSecurityConfig, type RevokeDelegationSubmittedEvent, SepoliaConfig, type SessionExpiredEvent, type ShieldCallbacks, type ShieldSubmittedEvent, type SignerLifecycleCallbacks, SigningFailedError, SigningRejectedError, type StoredCredentials, TOKEN_TOPICS, Token, type TokenConfig, type TokenWrapperPair, type TokenWrapperPairWithMetadata, Topics, type TransactionErrorEvent, type TransactionReceipt, type TransactionResult, TransactionRevertedError, type TransferCallbacks, type TransferFromSubmittedEvent, type TransferSubmittedEvent, type UnshieldCallbacks, type UnshieldPhase1SubmittedEvent, type UnshieldPhase2StartedEvent, type UnshieldPhase2SubmittedEvent, type UnwrapRequestedEvent, type UnwrapSubmittedEvent, type UnwrappedFinalizedEvent, type UnwrappedStartedEvent, type UserDecryptParams, type WrappedEvent, WrappersRegistry, type WrappersRegistryConfig, type WriteContractArgs, type WriteContractConfig, type WriteFunctionName, ZERO_HANDLE, type ZKProofLike, ZamaError, ZamaErrorCode, ZamaSDK, type ZamaSDKConfig, type ZamaSDKEvent, type ZamaSDKEventInput, type ZamaSDKEventListener, type ZamaSDKEventType, ZamaSDKEvents, allowanceContract, applyDecryptedValues, approveContract, balanceOfContract, chromeSessionStorage, clearPendingUnshield, confidentialBalanceOfContract, confidentialBatchTransferContract, confidentialTotalSupplyContract, confidentialTransferContract, confidentialTransferFromContract, decimalsContract, decodeConfidentialTransfer, decodeOnChainEvent, decodeOnChainEvents, decodeUnwrapRequested, decodeUnwrappedFinalized, decodeUnwrappedStarted, decodeWrapped, delegateForUserDecryptionContract, deploymentCoordinatorContract, extractEncryptedHandles, finalizeUnwrapContract, findUnwrapRequested, findWrapped, getBatchTransferFeeContract, getConfidentialTokenAddressContract, getDelegationExpiryContract, getFeeRecipientContract, getTokenAddressContract, getTokenPairContract, getTokenPairsContract, getTokenPairsLengthContract, getTokenPairsSliceContract, getUnwrapFeeContract, getWrapFeeContract, getWrapperContract, indexedDBStorage, isConfidentialTokenContract, isConfidentialTokenValidContract, isConfidentialWrapperContract, isFinalizeUnwrapOperatorContract, isOperatorContract, loadPendingUnshield, matchZamaError, memoryStorage, nameContract, parseActivityFeed, rateContract, revokeDelegationContract, savePendingUnshield, setFinalizeUnwrapOperatorContract, setOperatorContract, sortByBlockNumber, supportsInterfaceContract, symbolContract, totalSupplyContract, underlyingContract, unwrapContract, unwrapFromBalanceContract, wrapContract, wrapETHContract, wrapperExistsContract };
297
+ export { ACL_TOPICS, type AclEvent, AclPausedError, AclTopics, type ActivityAmount, type ActivityDirection, type ActivityItem, type ActivityLogMetadata, type ActivityType, type Address, ApprovalFailedError, type ApproveSubmittedEvent, type ApproveUnderlyingSubmittedEvent, type BaseEvent, type BatchDecryptAsOptions, type BatchDecryptOptions, type BatchTransferData, ChromeSessionStorage, type ClearValueType, type ConfidentialTransferEvent, ConfigurationError, type ContractAbi, type CredentialsAllowedEvent, type CredentialsCachedEvent, type CredentialsCorruptedEvent, type CredentialsCreatedEvent, type CredentialsCreatingEvent, type CredentialsExpiredEvent, type CredentialsLoadingEvent, CredentialsManager, type CredentialsManagerConfig, type CredentialsPersistFailedEvent, type CredentialsRevokedEvent, type DecryptEndEvent, type DecryptErrorEvent, type DecryptStartEvent, DecryptionFailedError, DefaultRegistryAddresses, DelegatedCredentialsManager, type DelegatedCredentialsManagerConfig, type DelegatedForUserDecryptionEvent, type DelegatedStoredCredentials, type DelegatedUserDecryptParams, DelegationContractIsSelfError, DelegationCooldownError, DelegationDelegateEqualsContractError, DelegationExpirationTooSoonError, DelegationExpiredError, DelegationExpiryUnchangedError, DelegationNotFoundError, DelegationNotPropagatedError, DelegationSelfNotAllowedError, type DelegationSubmittedEvent, type EIP712TypedData, ERC7984_INTERFACE_ID, ERC7984_WRAPPER_INTERFACE_ID, type EncryptEndEvent, type EncryptErrorEvent, type EncryptInput, type EncryptParams, type EncryptResult, type EncryptStartEvent, EncryptionFailedError, type FheTypeName, type FhevmInstanceConfig, type FinalizeUnwrapSubmittedEvent, type GenericLogger, type GenericSigner, type GenericStorage, type Handle, HardhatConfig, type Hex, IndexedDBStorage, type InputProofBytesType, InvalidKeypairError, KeypairExpiredError, type KeypairType, type KmsDelegatedUserDecryptEIP712Type, type ListPairsOptions, MainnetConfig, MemoryStorage, type NetworkType, NoCiphertextError, type OnChainEvent, type PaginatedResult, type PublicDecryptResult, type RawLog, type ReadContractArgs, type ReadContractConfig, type ReadContractReturnType, type ReadFunctionName, ReadonlyToken, type ReadonlyTokenConfig, RelayerRequestFailedError, type RelayerSDK, type RelayerSDKStatus, RelayerWeb, type RelayerWebConfig, type RelayerWebSecurityConfig, type RevokeDelegationSubmittedEvent, type RevokedDelegationForUserDecryptionEvent, SepoliaConfig, type SessionExpiredEvent, type ShieldCallbacks, type ShieldSubmittedEvent, type SignerLifecycleCallbacks, SigningFailedError, SigningRejectedError, type StoredCredentials, TOKEN_TOPICS, Token, type TokenConfig, type TokenWrapperPair, type TokenWrapperPairWithMetadata, Topics, type TransactionErrorEvent, type TransactionReceipt, type TransactionResult, TransactionRevertedError, type TransferCallbacks, type TransferFromSubmittedEvent, type TransferSubmittedEvent, type UnshieldCallbacks, type UnshieldPhase1SubmittedEvent, type UnshieldPhase2StartedEvent, type UnshieldPhase2SubmittedEvent, type UnwrapRequestedEvent, type UnwrapSubmittedEvent, type UnwrappedFinalizedEvent, type UnwrappedStartedEvent, type UserDecryptParams, type WrappedEvent, WrappersRegistry, type WrappersRegistryConfig, type WriteContractArgs, type WriteContractConfig, type WriteFunctionName, ZERO_HANDLE, type ZKProofLike, ZamaError, ZamaErrorCode, ZamaSDK, type ZamaSDKConfig, type ZamaSDKEvent, type ZamaSDKEventInput, type ZamaSDKEventListener, type ZamaSDKEventType, ZamaSDKEvents, allowanceContract, applyDecryptedValues, approveContract, balanceOfContract, chromeSessionStorage, clearPendingUnshield, confidentialBalanceOfContract, confidentialBatchTransferContract, confidentialTotalSupplyContract, confidentialTransferContract, confidentialTransferFromContract, decimalsContract, decodeAclEvent, decodeAclEvents, decodeConfidentialTransfer, decodeDelegatedForUserDecryption, decodeOnChainEvent, decodeOnChainEvents, decodeRevokedDelegationForUserDecryption, decodeUnwrapRequested, decodeUnwrappedFinalized, decodeUnwrappedStarted, decodeWrapped, delegateForUserDecryptionContract, deploymentCoordinatorContract, extractEncryptedHandles, finalizeUnwrapContract, findDelegatedForUserDecryption, findRevokedDelegationForUserDecryption, findUnwrapRequested, findWrapped, getBatchTransferFeeContract, getConfidentialTokenAddressContract, getDelegationExpiryContract, getFeeRecipientContract, getTokenAddressContract, getTokenPairContract, getTokenPairsContract, getTokenPairsLengthContract, getTokenPairsSliceContract, getUnwrapFeeContract, getWrapFeeContract, getWrapperContract, indexedDBStorage, isConfidentialTokenContract, isConfidentialTokenValidContract, isConfidentialWrapperContract, isFinalizeUnwrapOperatorContract, isHandleDelegatedContract, isOperatorContract, loadPendingUnshield, matchAclRevert, matchZamaError, memoryStorage, nameContract, parseActivityFeed, rateContract, revokeDelegationContract, savePendingUnshield, setFinalizeUnwrapOperatorContract, setOperatorContract, sortByBlockNumber, supportsInterfaceContract, symbolContract, totalSupplyContract, underlyingContract, unwrapContract, unwrapFromBalanceContract, wrapContract, wrapETHContract, wrapperExistsContract };
268
298
  //# sourceMappingURL=index.d.ts.map