@zama-fhe/sdk 1.2.0-alpha.2 → 1.2.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
- import { o as Handle } from "./relayer-sdk.types-7bIeWnws.js";
2
- import { b as OnChainEvent, d as StoredCredentials, h as UnshieldCallbacks, i as GenericStorage, l as ShieldCallbacks, m as TransferCallbacks, n as DelegatedStoredCredentials, p as TransactionResult, r as GenericSigner, u as SignerLifecycleCallbacks, x as RawLog } from "./token.types-CKH_X0ki.js";
3
- import { t as RelayerSDK } from "./relayer-sdk-DFUB0ULp.js";
1
+ import { o as Handle } from "./relayer-sdk.types-DI4WWkTB.js";
2
+ import { b as OnChainEvent, d as StoredCredentials, h as UnshieldCallbacks, i as GenericStorage, l as ShieldCallbacks, m as TransferCallbacks, n as DelegatedStoredCredentials, p as TransactionResult, r as GenericSigner, u as SignerLifecycleCallbacks, x as RawLog } from "./token.types-DDdIZEax.js";
3
+ import { t as RelayerSDK } from "./relayer-sdk-CVVR30IW.js";
4
4
  import { Address, Hex } from "viem";
5
5
 
6
6
  //#region src/events/sdk-events.d.ts
@@ -1461,4 +1461,4 @@ declare function applyDecryptedValues(items: readonly ActivityItem[], decryptedM
1461
1461
  declare function sortByBlockNumber(items: readonly ActivityItem[]): ActivityItem[];
1462
1462
  //#endregion
1463
1463
  export { DecryptStartEvent as $, ZamaErrorCode as A, CredentialsManagerConfig as B, KeypairExpiredError as C, SigningRejectedError as D, SigningFailedError as E, ReadonlyTokenConfig as F, CredentialsCachedEvent as G, ApproveUnderlyingSubmittedEvent as H, ZERO_HANDLE as I, CredentialsExpiredEvent as J, CredentialsCreatedEvent as K, DelegatedCredentialsManager as L, BatchDecryptAsOptions as M, BatchDecryptOptions as N, TransactionRevertedError as O, ReadonlyToken as P, DecryptErrorEvent as Q, DelegatedCredentialsManagerConfig as R, InvalidKeypairError as S, RelayerRequestFailedError as T, BaseEvent as U, ApproveSubmittedEvent as V, CredentialsAllowedEvent as W, CredentialsRevokedEvent as X, CredentialsLoadingEvent as Y, DecryptEndEvent as Z, DelegationCooldownError as _, ZamaSDKEvents as _t, ActivityType as a, ShieldSubmittedEvent as at, DelegationSelfNotAllowedError as b, parseActivityFeed as c, TransferSubmittedEvent as ct, ZamaSDKConfig as d, UnshieldPhase2SubmittedEvent as dt, EncryptEndEvent as et, Token as f, UnwrapSubmittedEvent as ft, DecryptionFailedError as g, ZamaSDKEventType as gt, ConfigurationError as h, ZamaSDKEventListener as ht, ActivityLogMetadata as i, SessionExpiredEvent as it, matchZamaError as j, ZamaError as k, sortByBlockNumber as l, UnshieldPhase1SubmittedEvent as lt, ApprovalFailedError as m, ZamaSDKEventInput as mt, ActivityDirection as n, EncryptStartEvent as nt, applyDecryptedValues as o, TransactionErrorEvent as ot, TokenConfig as p, ZamaSDKEvent as pt, CredentialsCreatingEvent as q, ActivityItem as r, FinalizeUnwrapSubmittedEvent as rt, extractEncryptedHandles as s, TransferFromSubmittedEvent as st, ActivityAmount as t, EncryptErrorEvent as tt, ZamaSDK as u, UnshieldPhase2StartedEvent as ut, DelegationExpiredError as v, NoCiphertextError as w, EncryptionFailedError as x, DelegationNotFoundError as y, CredentialsManager as z };
1464
- //# sourceMappingURL=activity-jvpqohOy.d.ts.map
1464
+ //# sourceMappingURL=activity-CV1NDmFr.d.ts.map
@@ -0,0 +1,2 @@
1
+ import{a as e,d as t,f as n,m as r,n as i,o as a,p as o,r as s,y as c}from"./errors-Cw9kKQJc.js";import{c as l,i as u,n as d,o as ee,r as f,s as p,t as m}from"./utils-eIBZNA_w.js";import{a as h,f as te,l as g,n as _,o as v,s as ne,t as re}from"./erc165-BZgfzGxL.js";import{erc20Abi as y,getAddress as b,isAddress as x}from"viem";function ie(e){return{address:e,abi:y,functionName:`name`,args:[]}}function S(e){return{address:e,abi:y,functionName:`symbol`,args:[]}}function C(e){return{address:e,abi:y,functionName:`decimals`,args:[]}}function ae(e,t){return{address:e,abi:y,functionName:`balanceOf`,args:[t]}}function w(e,t,n){return{address:e,abi:y,functionName:`allowance`,args:[t,n]}}function oe(e,t,n){return{address:e,abi:y,functionName:`approve`,args:[t,n]}}const T=[{inputs:[{internalType:`uint256`,name:`amount`,type:`uint256`},{internalType:`address`,name:`wrapFrom`,type:`address`},{internalType:`address`,name:`wrapTo`,type:`address`}],name:`getWrapFee`,outputs:[{internalType:`uint256`,name:``,type:`uint256`}],stateMutability:`view`,type:`function`},{inputs:[{internalType:`uint64`,name:`amount`,type:`uint64`},{internalType:`address`,name:`unwrapFrom`,type:`address`},{internalType:`address`,name:`unwrapTo`,type:`address`}],name:`getUnwrapFee`,outputs:[{internalType:`uint64`,name:``,type:`uint64`}],stateMutability:`view`,type:`function`},{inputs:[],name:`getBatchTransferFee`,outputs:[{internalType:`uint64`,name:``,type:`uint64`}],stateMutability:`view`,type:`function`},{inputs:[],name:`getFeeRecipient`,outputs:[{internalType:`address`,name:``,type:`address`}],stateMutability:`view`,type:`function`}];function se(e,t,n,r){return{address:e,abi:T,functionName:`getWrapFee`,args:[t,n,r]}}function ce(e,t,n,r){return{address:e,abi:T,functionName:`getUnwrapFee`,args:[t,n,r]}}function le(e){return{address:e,abi:T,functionName:`getBatchTransferFee`,args:[]}}function ue(e){return{address:e,abi:T,functionName:`getFeeRecipient`,args:[]}}const E=[{inputs:[{internalType:`address`,name:`delegate`,type:`address`},{internalType:`address`,name:`contractAddress`,type:`address`},{internalType:`uint64`,name:`expirationDate`,type:`uint64`}],name:`delegateForUserDecryption`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`address`,name:`delegate`,type:`address`},{internalType:`address`,name:`contractAddress`,type:`address`}],name:`revokeDelegationForUserDecryption`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`address`,name:`delegator`,type:`address`},{internalType:`address`,name:`delegate`,type:`address`},{internalType:`address`,name:`contractAddress`,type:`address`}],name:`getUserDecryptionDelegationExpirationDate`,outputs:[{internalType:`uint64`,name:``,type:`uint64`}],stateMutability:`view`,type:`function`}];function de(e,t,n,r){return{address:e,abi:E,functionName:`delegateForUserDecryption`,args:[t,n,r]}}function fe(e,t,n){return{address:e,abi:E,functionName:`revokeDelegationForUserDecryption`,args:[t,n]}}function pe(e,t,n,r){return{address:e,abi:E,functionName:`getUserDecryptionDelegationExpirationDate`,args:[t,n,r]}}const D=2n**64n-1n,O={CredentialsLoading:`credentials:loading`,CredentialsCached:`credentials:cached`,CredentialsExpired:`credentials:expired`,CredentialsCreating:`credentials:creating`,CredentialsCreated:`credentials:created`,CredentialsRevoked:`credentials:revoked`,CredentialsAllowed:`credentials:allowed`,SessionExpired:`session:expired`,EncryptStart:`encrypt:start`,EncryptEnd:`encrypt:end`,EncryptError:`encrypt:error`,DecryptStart:`decrypt:start`,DecryptEnd:`decrypt:end`,DecryptError:`decrypt:error`,TransactionError:`transaction:error`,ShieldSubmitted:`shield:submitted`,TransferSubmitted:`transfer:submitted`,TransferFromSubmitted:`transferFrom:submitted`,ApproveSubmitted:`approve:submitted`,ApproveUnderlyingSubmitted:`approveUnderlying:submitted`,UnwrapSubmitted:`unwrap:submitted`,FinalizeUnwrapSubmitted:`finalizeUnwrap:submitted`,DelegationSubmitted:`delegation:submitted`,RevokeDelegationSubmitted:`revokeDelegation:submitted`,UnshieldPhase1Submitted:`unshield:phase1_submitted`,UnshieldPhase2Started:`unshield:phase2_started`,UnshieldPhase2Submitted:`unshield:phase2_submitted`};var k=class{#e=new Map;async get(e){return this.#e.get(e)??null}async set(e,t){this.#e.set(e,t)}async delete(e){this.#e.delete(e)}};const me=new k;var he=class{#e=null;#t=null;clearCache(){this.#e=null,this.#t=null}async encrypt(e,t,n){let r=await this.#n(t,n),i=crypto.getRandomValues(new Uint8Array(12)),a=new TextEncoder,o=await crypto.subtle.encrypt({name:`AES-GCM`,iv:i},r,a.encode(e));return{iv:btoa(String.fromCharCode(...i)),ciphertext:btoa(String.fromCharCode(...new Uint8Array(o)))}}async decrypt(e,t,n){let r=await this.#n(t,n),i=Uint8Array.from(atob(e.iv),e=>e.charCodeAt(0)),a=Uint8Array.from(atob(e.ciphertext),e=>e.charCodeAt(0)),o=await crypto.subtle.decrypt({name:`AES-GCM`,iv:i},r,a);return p(new TextDecoder().decode(o))}async#n(e,t){let n=`${e}:${t}`;if(this.#e&&this.#t===n)return this.#e;let r=new TextEncoder,i=await crypto.subtle.importKey(`raw`,r.encode(e),`PBKDF2`,!1,[`deriveKey`]),a=await crypto.subtle.deriveKey({name:`PBKDF2`,salt:r.encode(t),iterations:6e5,hash:`SHA-256`},i,{name:`AES-GCM`,length:256},!1,[`encrypt`,`decrypt`]);return this.#t=n,this.#e=a,a}};function A(e){f(e,`Stored credentials`),u(e.publicKey,`credentials.publicKey`),m(e.contractAddresses,`credentials.contractAddresses`);for(let t of e.contractAddresses)d(typeof t==`string`&&x(t,{strict:!1}),`Expected each contractAddress to be a valid hex address`);f(e.encryptedPrivateKey,`credentials.encryptedPrivateKey`),u(e.encryptedPrivateKey.iv,`encryptedPrivateKey.iv`),u(e.encryptedPrivateKey.ciphertext,`encryptedPrivateKey.ciphertext`)}function ge(e){A(e);let t=e;d(typeof t.delegatorAddress==`string`&&x(t.delegatorAddress,{strict:!1}),`Expected credentials.delegatorAddress to be a valid address`),d(typeof t.delegateAddress==`string`&&x(t.delegateAddress,{strict:!1}),`Expected credentials.delegateAddress to be a valid address`),d(typeof t.startTimestamp==`number`,`Expected startTimestamp to be a number`),d(typeof t.durationDays==`number`,`Expected durationDays to be a number`)}function j(e){return Math.floor(Date.now()/1e3)<e.startTimestamp+e.durationDays*86400}function M(e,t){let n=new Set(t.map(e=>b(e))),r=new Set(e.map(e=>b(e)));return n.isSubsetOf(r)}function N(e,t){return j(e)?M(e.contractAddresses,t):!1}function P(e){return[...new Set(e.map(e=>b(e)))].toSorted()}async function F(...e){let t=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e.map(String).join(`:`)));return Array.from(new Uint8Array(t)).map(e=>e.toString(16).padStart(2,`0`)).join(``).slice(0,32)}var _e=class{#e;constructor(e){this.#e=e}#t(e){f(e,`Session entry`),u(e.signature,`session.signature`),d(typeof e.createdAt==`number`,`Expected session.createdAt to be a number`),d(typeof e.ttl==`number`||e.ttl===`infinite`,`Expected session.ttl to be a number or "infinite"`)}async get(e){let t=await this.#e.get(e);return t===null?null:(this.#t(t),t)}async set(e){let t={signature:e.signature,createdAt:Math.floor(Date.now()/1e3),ttl:e.ttl};await this.#e.set(e.key,t)}async delete(e){await this.#e.delete(e)}isExpired(e){return e.ttl===`infinite`?!1:e.ttl===0?!0:Math.floor(Date.now()/1e3)-e.createdAt>=e.ttl}},I=class{signer;storage;sessionSignatures;crypto;keypairTTL;sessionTTL;#e;#t=null;#n=null;#r=null;constructor(e){if(this.signer=e.signer,this.storage=e.storage,this.sessionSignatures=new _e(e.sessionStorage),this.crypto=new he,this.keypairTTL=e.keypairTTL??86400,this.sessionTTL=e.sessionTTL??2592e3,this.#e=e.onEvent??(()=>{}),typeof this.keypairTTL==`number`&&this.keypairTTL<0)throw Error(`keypairTTL must be >= 0`);if(typeof this.sessionTTL==`number`&&this.sessionTTL<0)throw Error(`sessionTTL must be >= 0`)}emit(e){this.#e({...e,timestamp:Date.now()})}async resolveCredentials({key:e,contracts:t,createKey:n,createFn:i}){this.emit({type:O.CredentialsLoading,contractAddresses:t});try{let n=await this.storage.get(e);if(n){this.assertEncrypted(n);let r=await this.sessionSignatures.get(e);if(r)if(this.sessionSignatures.isExpired(r))await this.sessionSignatures.delete(e),this.emit({type:O.SessionExpired,reason:`ttl`});else{let i=await this.decryptCredentials(n,r.signature);if(N(i,t))return this.emit({type:O.CredentialsCached,contractAddresses:t}),this.emit({type:O.CredentialsAllowed,contractAddresses:t}),i;if(j(i))return this.#i({key:e,credentials:i,requiredContracts:t});this.emit({type:O.CredentialsExpired,contractAddresses:t})}if(j(n)){if(M(n.contractAddresses,t)){let r=await this.signForContracts(n,n.contractAddresses);await this.sessionSignatures.set({key:e,signature:r,ttl:this.sessionTTL});let i=await this.decryptCredentials(n,r);return this.emit({type:O.CredentialsCached,contractAddresses:t}),this.emit({type:O.CredentialsAllowed,contractAddresses:t}),i}let r=await this.signForContracts(n,n.contractAddresses),i=await this.decryptCredentials(n,r);return this.#i({key:e,credentials:i,requiredContracts:t})}this.emit({type:O.CredentialsExpired,contractAddresses:t})}}catch(t){if(t instanceof r||t instanceof o)throw t;console.warn(`[zama-sdk] Credential resolution failed, recreating:`,t),await this.#o(e)}return(!this.#t||this.#n!==n)&&(this.#n=n,this.#t=i().then(e=>(this.emit({type:O.CredentialsAllowed,contractAddresses:t}),e)).finally(()=>{this.#t=null,this.#n=null})),this.#t}async checkExpired(e,t){try{let n=await this.storage.get(e);return n?(this.assertEncrypted(n),!N(n,t?[t]:[])):!1}catch(e){return console.warn(`[zama-sdk] isExpired check failed, treating as expired:`,e),!0}}async revokeSession(e,t){await this.sessionSignatures.delete(e),this.clearCaches(),this.emit({type:O.CredentialsRevoked,...t?{contractAddresses:t}:{}})}async checkAllowed(e){let t=await this.sessionSignatures.get(e);return t===null?!1:!this.sessionSignatures.isExpired(t)}async clearAll(e){await this.sessionSignatures.delete(e),this.clearCaches(),await this.#o(e)}clearCaches(){this.crypto.clearCache()}async createCredentials({key:e,contractAddresses:t,createFn:n,errorContext:r}){this.emit({type:O.CredentialsCreating,contractAddresses:t});try{let r=await n();return await this.persistCredentials(e,r),await this.sessionSignatures.set({key:e,signature:r.signature,ttl:this.sessionTTL}),this.emit({type:O.CredentialsCreated,contractAddresses:t}),r}catch(e){c(e,r)}}async#i({key:e,credentials:t,requiredContracts:n}){if(this.#r){let e=await this.#r;if(M(e.contractAddresses,n))return this.emit({type:O.CredentialsAllowed,contractAddresses:n}),e;t=e}let r=this.#a({key:e,credentials:t,requiredContracts:n});this.#r=r;try{return await r}finally{this.#r===r&&(this.#r=null)}}async#a({key:e,credentials:t,requiredContracts:n}){let r=P([...t.contractAddresses,...n]),i=await this.signForContracts(t,r),a={...t,contractAddresses:r,signature:i};return await this.persistCredentials(e,a),await this.sessionSignatures.set({key:e,signature:i,ttl:this.sessionTTL}),this.emit({type:O.CredentialsAllowed,contractAddresses:n}),a}async persistCredentials(e,t){try{let n=await this.encryptCredentials(t);await this.storage.set(e,n)}catch(e){console.warn(`[zama-sdk] Failed to encrypt credentials for persistence:`,e);return}}async#o(e){try{await this.storage.delete(e)}catch(e){console.warn(`[zama-sdk] Failed to delete credentials:`,e)}}};function ve(e){if(typeof e!=`object`||!e)return!1;let t=Reflect.get(e,`runtime`);return typeof t!=`object`||!t?!1:typeof Reflect.get(t,`id`)==`string`}var L=class e extends I{#e;#t=null;#n=null;static async computeStoreKey(e,t){return F(b(e),t)}constructor(e){super(e),this.#e=e.relayer,ve(typeof globalThis<`u`?Reflect.get(globalThis,`chrome`):void 0)&&e.sessionStorage instanceof k&&console.warn(`[zama-sdk] Detected Chrome extension context with in-memory session storage. Session signatures will be lost on service worker restart and won't be shared across contexts. Consider using chromeSessionStorage instead. `)}async allow(...e){let t=P(e),n=await this.#r();return this.resolveCredentials({key:n,contracts:t,createKey:t.join(`,`),createFn:()=>this.create(t)})}async isExpired(e){return this.checkExpired(await this.#r(),e)}async revoke(...e){await this.revokeSession(await this.#r(),e.length>0?e:void 0)}async isAllowed(){return this.checkAllowed(await this.#r())}async clear(){await this.clearAll(await this.#r())}async create(e){let t=P(e),n=await this.#r();return this.createCredentials({key:n,contractAddresses:t,createFn:async()=>{let e=await this.#e.generateKeypair(),n=Math.floor(Date.now()/1e3),r=Math.ceil(this.keypairTTL/86400),i=await this.#e.createEIP712(e.publicKey,t,n,r),a=await this.signer.signTypedData(i);return{publicKey:e.publicKey,privateKey:e.privateKey,signature:a,contractAddresses:t,startTimestamp:n,durationDays:r}},errorContext:`Failed to create decrypt credentials`})}assertEncrypted(e){A(e)}async signForContracts(e,t){let n=await this.#e.createEIP712(e.publicKey,t,e.startTimestamp,e.durationDays);return this.signer.signTypedData(n)}async encryptCredentials(e){let t=await this.signer.getAddress(),n=await this.crypto.encrypt(e.privateKey,e.signature,t),{privateKey:r,signature:i,...a}=e;return{...a,encryptedPrivateKey:n}}async decryptCredentials(e,t){let n=await this.signer.getAddress(),r=await this.crypto.decrypt(e.encryptedPrivateKey,t,n),{encryptedPrivateKey:i,...a}=e;return{...a,privateKey:r,signature:t}}clearCaches(){this.#t=null,this.#n=null,super.clearCaches()}async#r(){let t=await this.signer.getAddress(),n=await this.signer.getChainId(),r=`${b(t)}:${n}`;if(this.#t&&this.#n===r)return this.#t;let i=await e.computeStoreKey(t,n);return this.#n=r,this.#t=i,i}},R=class e extends I{#e;#t=null;#n=null;static async computeStoreKey(e,t,n){return F(b(e),b(t),n)}constructor(e){super(e),this.#e=e.relayer}async allow(e,...t){let n=b(e),r=P(t),i=await this.#i(n);return this.resolveCredentials({key:i,contracts:r,createKey:`${n}:${r.join(`,`)}`,createFn:()=>this.#r(n,r)})}async isExpired(e,t){return this.checkExpired(await this.#i(b(e)),t)}async revoke(e){await this.revokeSession(await this.#i(b(e)))}async isAllowed(e){return this.checkAllowed(await this.#i(b(e)))}async clear(e){await this.clearAll(await this.#i(b(e)))}async#r(e,t){let n=await this.#i(e);return this.createCredentials({key:n,contractAddresses:t,createFn:async()=>{let n=await this.#e.generateKeypair(),r=await this.signer.getAddress(),i=Math.floor(Date.now()/1e3),a=Math.ceil(this.keypairTTL/86400),o={publicKey:n.publicKey,startTimestamp:i,durationDays:a,delegatorAddress:e},s=await this.#a(o,t);return{publicKey:n.publicKey,privateKey:n.privateKey,signature:s,contractAddresses:t,startTimestamp:i,durationDays:a,delegatorAddress:e,delegateAddress:r}},errorContext:`Failed to create delegated decrypt credentials`})}assertEncrypted(e){ge(e)}async signForContracts(e,t){return this.#a(e,t)}async encryptCredentials(e){let t=await this.signer.getAddress(),n=await this.crypto.encrypt(e.privateKey,e.signature,t),{privateKey:r,signature:i,...a}=e;return{...a,encryptedPrivateKey:n}}async decryptCredentials(e,t){let n=await this.signer.getAddress(),r=await this.crypto.decrypt(e.encryptedPrivateKey,t,n),{encryptedPrivateKey:i,...a}=e;return{...a,privateKey:r,signature:t}}clearCaches(){this.#t=null,this.#n=null,super.clearCaches()}async#i(t){let n=await this.signer.getAddress(),r=await this.signer.getChainId(),i=`${b(n)}:${b(t)}:${r}`;if(this.#t&&this.#n===i)return this.#t;let a=await e.computeStoreKey(n,t,r);return this.#n=i,this.#t=a,a}async#a(e,t){let n=await this.#e.createDelegatedUserDecryptEIP712(e.publicKey,t,e.delegatorAddress,e.startTimestamp,e.durationDays);return this.signer.signTypedData({domain:{...n.domain,chainId:Number(n.domain.chainId)},types:n.types,message:{...n.message,startTimestamp:BigInt(n.message.startTimestamp),durationDays:BigInt(n.message.durationDays)}})}};const z=`zama:balances`;function ye(e,t,n){return`zama:balance:${b(e)}:${b(t)}:${n.toLowerCase()}`}async function B({storage:e,tokenAddress:t,owner:n,handle:r}){try{let i=await e.get(ye(t,n,r));return i===null?null:BigInt(i)}catch(e){return console.warn(`[zama-sdk] Balance cache read failed:`,e),null}}async function V(e){let{storage:t,tokenAddress:n,owner:r,handle:i,value:a}=e,o=ye(n,r,i);try{await t.set(o,a.toString()),await xe(t,o)}catch{}}const be=new WeakMap;async function xe(e,t){let n=(be.get(e)??Promise.resolve()).then(async()=>{let n=await e.get(z),r=n?JSON.parse(n):[];r.includes(t)||(r.push(t),await e.set(z,JSON.stringify(r)))});return be.set(e,n.catch(()=>{})),n}const Se=`0x0000000000000000000000000000000000000000000000000000000000000000`;var Ce=class t{credentials;delegatedCredentials;relayer;signer;address;storage;#e;constructor(e){let t={relayer:e.relayer,signer:e.signer,storage:e.storage,sessionStorage:e.sessionStorage,keypairTTL:e.keypairTTL??86400,sessionTTL:e.sessionTTL??2592e3,onEvent:e.onEvent};this.credentials=e.credentials??new L(t),this.delegatedCredentials=e.delegatedCredentials??new R(t),this.relayer=e.relayer,this.signer=e.signer,this.address=b(e.address),this.storage=e.storage,this.#e=e.onEvent}emit(e){this.#e?.({...e,tokenAddress:this.address,timestamp:Date.now()})}async balanceOf(e){let t=e?b(e):await this.signer.getAddress(),n=await this.readConfidentialBalanceOf(t);return this.decryptBalance(n,t)}async confidentialBalanceOf(e){let t=e?b(e):await this.signer.getAddress();return this.readConfidentialBalanceOf(t)}async isConfidential(){return await this.signer.readContract(h(this.address,re))}async isWrapper(){return await this.signer.readContract(h(this.address,_))}static async batchDecryptBalances(e,n){if(e.length===0)return new Map;let{handles:r,owner:i,onError:a,maxConcurrency:o}=n??{},s=e[0],c=t.assertSameRelayer(e),l=i??await s.signer.getAddress();return t.#t({tokens:e,handles:r,ownerAddress:l,onError:a,maxConcurrency:o,obtainCreds:e=>s.credentials.allow(...e),decrypt:(e,t,n)=>c.userDecrypt({handles:[t],contractAddress:n,signedContractAddresses:e.contractAddresses,privateKey:e.privateKey,publicKey:e.publicKey,signature:e.signature,signerAddress:l,startTimestamp:e.startTimestamp,durationDays:e.durationDays}),errorPrefix:`Batch decryption`})}static async batchDecryptBalancesAs(e,n){if(e.length===0)return new Map;let{delegatorAddress:r,handles:i,owner:a,onError:o,maxConcurrency:s}=n,c=a??r,l=e[0];return t.assertSameRelayer(e),t.#t({tokens:e,handles:i,ownerAddress:c,onError:o,maxConcurrency:s,preFlightCheck:()=>l.#n(r),obtainCreds:e=>l.delegatedCredentials.allow(r,...e),decrypt:(e,t,n)=>l.relayer.delegatedUserDecrypt({handles:[t],contractAddress:n,signedContractAddresses:e.contractAddresses,privateKey:e.privateKey,publicKey:e.publicKey,signature:e.signature,delegatorAddress:e.delegatorAddress,delegateAddress:e.delegateAddress,startTimestamp:e.startTimestamp,durationDays:e.durationDays}),errorPrefix:`Batch delegated decryption`})}static async#t(e){let{tokens:t,handles:n,ownerAddress:r,onError:i,maxConcurrency:a,obtainCreds:o,decrypt:c,errorPrefix:u}=e,d=t[0],f=n??await Promise.all(t.map(e=>e.readConfidentialBalanceOf(r)));if(t.length!==f.length)throw new s(`tokens.length (${t.length}) must equal handles.length (${f.length})`);let p=d.storage,m=new Map,h=[],te=await Promise.all(t.map((e,t)=>{let n=f[t];return e.isZeroHandle(n)?0n:B({storage:p,tokenAddress:e.address,owner:r,handle:n})}));for(let e=0;e<t.length;e++){let n=t[e],r=f[e],i=te[e];if(i!=null){m.set(n.address,i);continue}h.push({token:n,handle:r})}if(h.length===0)return m;e.preFlightCheck&&await e.preFlightCheck();let g=await o(h.map(e=>e.token.address)),_=[],v=[];for(let{token:e,handle:t}of h)v.push(()=>c(g,t,e.address).then(async n=>{let i=n[t];if(i===void 0)throw new s(`${u} returned no value for handle ${t} on token ${e.address}`);m.set(e.address,i);try{await V({storage:p,tokenAddress:e.address,owner:r,handle:t,value:i})}catch{}}).catch(t=>{let n=l(t);if(i)try{m.set(e.address,i(n,e.address))}catch(t){_.push({address:e.address,error:l(t)})}else _.push({address:e.address,error:n})}));if(await ee(v,a),_.length>0){let e=_.map(e=>`${e.address}: ${e.error.message}`).join(`; `);throw new s(`${u} failed for ${_.length} token(s): ${e}`)}return m}async discoverWrapper(e){let t=b(e);return await this.signer.readContract(ne(t,this.address))?this.signer.readContract(v(t,this.address)):null}async underlyingToken(){return this.signer.readContract(g(this.address))}async allowance(e,t){let n=b(e),r=await this.signer.readContract(g(n)),i=t?b(t):await this.signer.getAddress();return this.signer.readContract(w(r,i,n))}async name(){return this.signer.readContract(ie(this.address))}async symbol(){return this.signer.readContract(S(this.address))}async decimals(){return this.signer.readContract(C(this.address))}async allow(){await this.credentials.allow(this.address)}async isAllowed(){return this.credentials.isAllowed()}async revoke(...e){await this.credentials.revoke(...e)}static async allow(...e){if(e.length===0)return;let t=e.map(e=>e.address);await e[0].credentials.allow(...t)}async getAclAddress(){return this.relayer.getAclAddress()}async isDelegated(e){let t=await this.getDelegationExpiry(e);return t===0n?!1:t===D?!0:t>await this.signer.getBlockTimestamp()}async getDelegationExpiry({delegatorAddress:e,delegateAddress:t}){let n=await this.getAclAddress();return this.signer.readContract(pe(n,b(e),b(t),this.address))}async#n(t){let n=await this.signer.getAddress(),r=await this.getDelegationExpiry({delegatorAddress:t,delegateAddress:n});if(r===0n)throw new a(`No active delegation from ${t} to ${n} for ${this.address}`);if(r!==D&&r<=await this.signer.getBlockTimestamp())throw new e(`Delegation from ${t} to ${n} for ${this.address} has expired`)}async readConfidentialBalanceOf(e){return await this.signer.readContract(te(this.address,e))}isZeroHandle(e){return e===`0x0000000000000000000000000000000000000000000000000000000000000000`||e===`0x`}async decryptBalanceAs({delegatorAddress:e,owner:t}){let n=b(e),r=t?b(t):n,i=await this.readConfidentialBalanceOf(r);if(this.isZeroHandle(i))return 0n;let a=await B({storage:this.storage,tokenAddress:this.address,owner:r,handle:i});if(a!==null)return a;await this.#n(n);let o=Date.now();try{this.emit({type:O.DecryptStart});let e=await this.delegatedCredentials.allow(n,this.address),t=await this.relayer.delegatedUserDecrypt({handles:[i],contractAddress:this.address,signedContractAddresses:e.contractAddresses,privateKey:e.privateKey,publicKey:e.publicKey,signature:e.signature,delegatorAddress:e.delegatorAddress,delegateAddress:e.delegateAddress,startTimestamp:e.startTimestamp,durationDays:e.durationDays});this.emit({type:O.DecryptEnd,durationMs:Date.now()-o});let a=t[i];if(a===void 0)throw new s(`Delegated decryption returned no value for handle ${i}`);try{await V({storage:this.storage,tokenAddress:this.address,owner:r,handle:i,value:a})}catch{}return a}catch(e){throw this.emit({type:O.DecryptError,error:l(e),durationMs:Date.now()-o}),H(e,`Failed to decrypt delegated balance`)}}async decryptBalance(e,t){if(this.isZeroHandle(e))return 0n;let n=t??await this.signer.getAddress(),r=await B({storage:this.storage,tokenAddress:this.address,owner:n,handle:e});if(r!==null)return r;let i=await this.credentials.allow(this.address),a=Date.now();try{this.emit({type:O.DecryptStart});let t=await this.relayer.userDecrypt({handles:[e],contractAddress:this.address,signedContractAddresses:i.contractAddresses,privateKey:i.privateKey,publicKey:i.publicKey,signature:i.signature,signerAddress:n,startTimestamp:i.startTimestamp,durationDays:i.durationDays});this.emit({type:O.DecryptEnd,durationMs:Date.now()-a});let r=t[e];if(r===void 0)throw new s(`Decryption returned no value for handle ${e}`);try{await V({storage:this.storage,tokenAddress:this.address,owner:n,handle:e,value:r})}catch{}return r}catch(e){throw this.emit({type:O.DecryptError,error:l(e),durationMs:Date.now()-a}),H(e,`Failed to decrypt balance`)}}async decryptHandles(e,t){let n=new Map,r=[];for(let t of e)this.isZeroHandle(t)?n.set(t,0n):r.push(t);if(r.length===0)return n;let i=await this.credentials.allow(this.address),a=Date.now();try{this.emit({type:O.DecryptStart});let e=await this.relayer.userDecrypt({handles:r,contractAddress:this.address,signedContractAddresses:i.contractAddresses,privateKey:i.privateKey,publicKey:i.publicKey,signature:i.signature,signerAddress:t??await this.signer.getAddress(),startTimestamp:i.startTimestamp,durationDays:i.durationDays});this.emit({type:O.DecryptEnd,durationMs:Date.now()-a});for(let t of r){let r=e[t];if(r===void 0)throw new s(`Decryption returned no value for handle ${t}`);n.set(t,r)}}catch(e){throw this.emit({type:O.DecryptError,error:l(e),durationMs:Date.now()-a}),H(e,`Failed to decrypt handles`)}return n}static assertSameRelayer(e){let t=e[0].relayer;for(let n=1;n<e.length;n++)if(e[n].relayer!==t)throw new i(`All tokens in a batch operation must share the same relayer instance`);return t}};function H(e,i){if(e instanceof s||e instanceof t||e instanceof n||e instanceof r||e instanceof o)return e;let a=typeof e==`object`&&e&&`statusCode`in e&&typeof e.statusCode==`number`?e.statusCode:void 0;return a===400?new t(e instanceof Error?e.message:`No ciphertext for this account`,{cause:e}):a===void 0?new s(i,{cause:e}):new n(e instanceof Error?e.message:i,a,{cause:e})}const U={ConfidentialTransfer:`0x67500e8d0ed826d2194f514dd0d8124f35648ab6e3fb5e6ed867134cffe661e9`,Wrapped:`0x1f7907f4d84043abe0fb7c74e8865ee5fe93fe4f691c54a7b8fa9d6fb17c7cba`,UnwrapRequested:`0x77d02d353c5629272875d11f1b34ec4c65d7430b075575b78cd2502034c469ee`,UnwrappedFinalized:`0xc64e7c81b18b674fc5b037d8a0041bfe3332d86c780a4688f404ee01fbabb152`,UnwrappedStarted:`0x3838891d4843c6d7f9f494570b6fd8843f4e3c3ddb817c1411760bd31b819806`};function W(e){return b(p(e.slice(-40)))}function G(e){return BigInt(e)}function we(e){return e}function K(e,t){let n=2+t*64,r=e.slice(n,n+64);return r.length===64?r:r.padEnd(64,`0`)}function Te(e,t){return b(p(K(e,t).slice(-40)))}function q(e,t){return BigInt(`0x`+K(e,t))}function J(e,t){return BigInt(`0x`+K(e,t))!==0n}function Y(e,t){return p(K(e,t))}function Ee(e){return e.topics[0]!==U.ConfidentialTransfer||e.topics.length<4?null:{eventName:`ConfidentialTransfer`,from:W(e.topics[1]),to:W(e.topics[2]),encryptedAmountHandle:we(e.topics[3])}}function X(e){return e.topics[0]!==U.Wrapped||e.topics.length<3?null:{eventName:`Wrapped`,to:W(e.topics[1]),mintTxId:G(e.topics[2]),mintAmount:q(e.data,0),amountIn:q(e.data,1),feeAmount:q(e.data,2)}}function Z(e){return e.topics[0]!==U.UnwrapRequested||e.topics.length<2?null:{eventName:`UnwrapRequested`,receiver:W(e.topics[1]),encryptedAmount:Y(e.data,0)}}function De(e){return e.topics[0]!==U.UnwrappedFinalized||e.topics.length<3?null:{eventName:`UnwrappedFinalized`,burntAmountHandle:we(e.topics[1]),nextTxId:G(e.topics[2]),finalizeSuccess:J(e.data,0),feeTransferSuccess:J(e.data,1),burnAmount:q(e.data,2),unwrapAmount:q(e.data,3),feeAmount:q(e.data,4)}}function Oe(e){return e.topics[0]!==U.UnwrappedStarted||e.topics.length<4?null:{eventName:`UnwrappedStarted`,requestId:G(e.topics[1]),txId:G(e.topics[2]),to:W(e.topics[3]),returnVal:J(e.data,0),refund:Te(e.data,1),requestedAmount:Y(e.data,2),burnAmount:Y(e.data,3)}}function Q(e){return Ee(e)??X(e)??Z(e)??De(e)??Oe(e)}function ke(e){let t=[];for(let n of e){let e=Q(n);e&&t.push(e)}return t}function Ae(e){for(let t of e){let e=Z(t);if(e)return e}return null}function je(e){for(let t of e){let e=X(t);if(e)return e}return null}const Me=[U.ConfidentialTransfer,U.Wrapped,U.UnwrapRequested,U.UnwrappedFinalized,U.UnwrappedStarted];function Ne(e,t){return e.toLowerCase()===t.toLowerCase()}function $(e,t,n){let r=t!==void 0&&Ne(e,t),i=n!==void 0&&Ne(e,n);return r&&i?`self`:r?`outgoing`:`incoming`}function Pe(e,t,n){switch(e.eventName){case`ConfidentialTransfer`:return Fe(e,t,n);case`Wrapped`:return Ie(e,t,n);case`UnwrapRequested`:return Le(e,t,n);case`UnwrappedStarted`:return Re(e,t,n);case`UnwrappedFinalized`:return ze(e,n)}}function Fe(e,t,n){return{type:`transfer`,direction:$(t,e.from,e.to),amount:{type:`encrypted`,handle:e.encryptedAmountHandle},from:e.from,to:e.to,metadata:n,rawEvent:e}}function Ie(e,t,n){return{type:`shield`,direction:$(t,void 0,e.to),amount:{type:`clear`,value:e.amountIn},to:e.to,fee:e.feeAmount,metadata:n,rawEvent:e}}function Le(e,t,n){return{type:`unshield_requested`,direction:$(t,void 0,e.receiver),amount:{type:`encrypted`,handle:e.encryptedAmount},to:e.receiver,metadata:n,rawEvent:e}}function Re(e,t,n){return{type:`unshield_started`,direction:$(t,void 0,e.to),amount:{type:`encrypted`,handle:e.requestedAmount},to:e.to,success:e.returnVal,metadata:n,rawEvent:e}}function ze(e,t){return{type:`unshield_finalized`,direction:`incoming`,amount:{type:`clear`,value:e.unwrapAmount},fee:e.feeAmount,success:e.finalizeSuccess,metadata:t,rawEvent:e}}function Be(e,t){let n=[];for(let r of e){let e=Q(r);if(!e)continue;let i={transactionHash:r.transactionHash,blockNumber:r.blockNumber,logIndex:r.logIndex};n.push(Pe(e,t,i))}return n}function Ve(e){let t=new Set;for(let n of e)if(n.amount.type===`encrypted`&&n.amount.decryptedValue===void 0){let e=n.amount.handle;e!==`0x`&&e!==`0x0000000000000000000000000000000000000000000000000000000000000000`&&t.add(e)}return[...t]}function He(e,t){return e.map(e=>{if(e.amount.type!==`encrypted`)return e;let n=t.get(e.amount.handle);return n===void 0?e:{...e,amount:{type:`encrypted`,handle:e.amount.handle,decryptedValue:n}}})}function Ue(e){return[...e].toSorted((e,t)=>{let n=e.metadata.blockNumber,r=t.metadata.blockNumber;if(n===void 0&&r===void 0)return 0;if(n===void 0)return-1;if(r===void 0)return 1;let i=typeof n==`bigint`?n:BigInt(n),a=typeof r==`bigint`?r:BigInt(r);if(a>i)return 1;if(a<i)return-1;let o=e.metadata.logIndex??0;return(t.metadata.logIndex??0)-o})}export{se as A,D as C,le as D,fe as E,ie as F,S as I,oe as M,ae as N,ue as O,C as P,O as S,pe as T,Se as _,Me as a,k as b,Q as c,De as d,Oe as f,Ce as g,je as h,Ue as i,w as j,ce as k,ke as l,Ae as m,Ve as n,U as o,X as p,Be as r,Ee as s,He as t,Z as u,R as v,de as w,me as x,L as y};
2
+ //# sourceMappingURL=activity-DEoxFQLE.js.map
@@ -1,5 +1,5 @@
1
- import { a as EncryptResult, c as PublicDecryptResult, f as UserDecryptParams, i as EncryptParams, n as EIP712TypedData, o as Handle, t as DelegatedUserDecryptParams } from "../relayer-sdk.types-7bIeWnws.js";
2
- import { t as RelayerSDK } from "../relayer-sdk-DFUB0ULp.js";
1
+ import { a as EncryptResult, c as PublicDecryptResult, f as UserDecryptParams, i as EncryptParams, n as EIP712TypedData, o as Handle, t as DelegatedUserDecryptParams } from "../relayer-sdk.types-DI4WWkTB.js";
2
+ import { t as RelayerSDK } from "../relayer-sdk-CVVR30IW.js";
3
3
  import { Address, EIP1193Provider, Hex } from "viem";
4
4
  import { PrivateKeyAccount } from "viem/accounts";
5
5
  import { ClearValueType, InputProofBytesType, KeypairType, KmsDelegatedUserDecryptEIP712Type, ZKProofLike } from "@zama-fhe/relayer-sdk/bundle";
@@ -1,2 +1,2 @@
1
- import{c as e,n as t,r as n}from"../errors-Cw9kKQJc.js";import{n as r}from"../relayer-utils-DZ0vfhG-.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(t,n,r){if(r.length!==32)throw new e(`random32 must be exactly 32 bytes`);let a=N(n,t),o=u(i([m(new Uint8Array([t])),m(a),m(r)]));return u(i([m(j),o]))}function F(t,n,r,a,o){if(!Number.isInteger(n)||n<0||n>255)throw new e(`index must be an integer between 0 and 255`);let c=u(i([m(j),t])),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(t){if(!O(t.type))throw new e(`Unsupported FHE type: ${t.type}`);let n=k(t.type),r;if(t.type===`ebool`){if(typeof t.value==`boolean`)r=t.value?1n:0n;else if(r=t.value,r!==0n&&r!==1n)throw new e(`Bool value must be 0, 1, true, or false`)}else r=t.type===`eaddress`?BigInt(c(t.value)):t.value;if(r<0n)throw new e(`Only non-negative cleartext values are supported`);let i=A(n),a=(1n<<BigInt(i))-1n;if(r>a)throw new e(`Value ${r} exceeds max ${a} for FheType ${n}`);return{fheType:n,value:r}}var G=class{#e;#t;kmsSigner;inputSigner;constructor(e){if(H.has(e.chainId))throw new t(`Cleartext mode is not allowed on chain ${e.chainId}. It is intended for local development and testing only.`);this.#e=a({transport:typeof e.network==`string`?l(e.network):o(e.network)}),this.#t=e,this.kmsSigner=h(e.kmsSignerPrivateKey??`0x388b7680e4e1afa06efbfd45cdd1fe39f3c6af381df6555a19661f283b97de91`),this.inputSigner=h(e.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(e){throw new t(`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};export{G as RelayerCleartext,K as hardhatCleartextConfig,q as hoodiCleartextConfig};
1
+ import{c as e,n as t,r as n}from"../errors-Cw9kKQJc.js";import{n as r}from"../relayer-utils-CpHWf9Jl.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(t,n,r){if(r.length!==32)throw new e(`random32 must be exactly 32 bytes`);let a=N(n,t),o=u(i([m(new Uint8Array([t])),m(a),m(r)]));return u(i([m(j),o]))}function F(t,n,r,a,o){if(!Number.isInteger(n)||n<0||n>255)throw new e(`index must be an integer between 0 and 255`);let c=u(i([m(j),t])),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(t){if(!O(t.type))throw new e(`Unsupported FHE type`);let n=k(t.type),r;if(t.type===`ebool`){if(typeof t.value==`boolean`)r=t.value?1n:0n;else if(r=t.value,r!==0n&&r!==1n)throw new e(`Bool value must be 0, 1, true, or false`)}else r=t.type===`eaddress`?BigInt(c(t.value)):t.value;if(r<0n)throw new e(`Only non-negative cleartext values are supported`);let i=A(n),a=(1n<<BigInt(i))-1n;if(r>a)throw new e(`Value ${r} exceeds max ${a} for FheType ${n}`);return{fheType:n,value:r}}var G=class{#e;#t;kmsSigner;inputSigner;constructor(e){if(H.has(e.chainId))throw new t(`Cleartext mode is not allowed on chain ${e.chainId}. It is intended for local development and testing only.`);this.#e=a({transport:typeof e.network==`string`?l(e.network):o(e.network)}),this.#t=e,this.kmsSigner=h(e.kmsSignerPrivateKey??`0x388b7680e4e1afa06efbfd45cdd1fe39f3c6af381df6555a19661f283b97de91`),this.inputSigner=h(e.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(e){throw new t(`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};export{G as RelayerCleartext,K as hardhatCleartextConfig,q as hoodiCleartextConfig};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,2 +1,2 @@
1
1
  import{toHex as e}from"viem";const t=[{inputs:[{internalType:`address`,name:`account`,type:`address`}],name:`confidentialBalanceOf`,outputs:[{internalType:`euint64`,name:``,type:`bytes32`}],stateMutability:`view`,type:`function`},{inputs:[{internalType:`address`,name:`to`,type:`address`},{internalType:`externalEuint64`,name:`encryptedAmount`,type:`bytes32`},{internalType:`bytes`,name:`inputProof`,type:`bytes`}],name:`confidentialTransfer`,outputs:[{internalType:`euint64`,name:``,type:`bytes32`}],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`address`,name:`to`,type:`address`},{internalType:`euint64`,name:`amount`,type:`bytes32`}],name:`confidentialTransfer`,outputs:[{internalType:`euint64`,name:``,type:`bytes32`}],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`address`,name:`from`,type:`address`},{internalType:`address`,name:`to`,type:`address`},{internalType:`externalEuint64`,name:`encryptedAmount`,type:`bytes32`},{internalType:`bytes`,name:`inputProof`,type:`bytes`}],name:`confidentialTransferFrom`,outputs:[{internalType:`euint64`,name:`transferred`,type:`bytes32`}],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`address`,name:`from`,type:`address`},{internalType:`address`,name:`to`,type:`address`},{internalType:`euint64`,name:`amount`,type:`bytes32`}],name:`confidentialTransferFrom`,outputs:[{internalType:`euint64`,name:`transferred`,type:`bytes32`}],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`address`,name:`holder`,type:`address`},{internalType:`address`,name:`spender`,type:`address`}],name:`isOperator`,outputs:[{internalType:`bool`,name:``,type:`bool`}],stateMutability:`view`,type:`function`},{inputs:[{internalType:`address`,name:`operator`,type:`address`},{internalType:`uint48`,name:`until`,type:`uint48`}],name:`setOperator`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`address`,name:`from`,type:`address`},{internalType:`address`,name:`to`,type:`address`},{internalType:`externalEuint64`,name:`encryptedAmount`,type:`bytes32`},{internalType:`bytes`,name:`inputProof`,type:`bytes`}],name:`unwrap`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`address`,name:`from`,type:`address`},{internalType:`address`,name:`to`,type:`address`},{internalType:`euint64`,name:`amount`,type:`bytes32`}],name:`unwrap`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[],name:`confidentialTotalSupply`,outputs:[{internalType:`euint64`,name:``,type:`bytes32`}],stateMutability:`view`,type:`function`},{inputs:[],name:`totalSupply`,outputs:[{internalType:`uint256`,name:``,type:`uint256`}],stateMutability:`view`,type:`function`},{inputs:[],name:`rate`,outputs:[{internalType:`uint256`,name:``,type:`uint256`}],stateMutability:`view`,type:`function`},{inputs:[],name:`deploymentCoordinator`,outputs:[{internalType:`contract IDeploymentCoordinator`,name:``,type:`address`}],stateMutability:`view`,type:`function`},{inputs:[{internalType:`address`,name:`holder`,type:`address`},{internalType:`address`,name:`operator`,type:`address`}],name:`isFinalizeUnwrapOperator`,outputs:[{internalType:`bool`,name:``,type:`bool`}],stateMutability:`view`,type:`function`},{inputs:[{internalType:`address`,name:`operator`,type:`address`},{internalType:`uint48`,name:`until`,type:`uint48`}],name:`setFinalizeUnwrapOperator`,outputs:[],stateMutability:`nonpayable`,type:`function`}];function n(e,n){return{address:e,abi:t,functionName:`confidentialBalanceOf`,args:[n]}}function r(n,r,i,a){return{address:n,abi:t,functionName:`confidentialTransfer`,args:[r,e(i),e(a)]}}function i(n,r,i,a,o){return{address:n,abi:t,functionName:`confidentialTransferFrom`,args:[r,i,e(a),e(o)]}}function a(e,n,r){return{address:e,abi:t,functionName:`isOperator`,args:[n,r]}}function o(e,n,r){return{address:e,abi:t,functionName:`setOperator`,args:[n,r??Math.floor(Date.now()/1e3)+3600]}}function s(n,r,i,a,o){return{address:n,abi:t,functionName:`unwrap`,args:[r,i,e(a),e(o)]}}function c(e,n,r,i){return{address:e,abi:t,functionName:`unwrap`,args:[n,r,i]}}function l(e){return{address:e,abi:t,functionName:`confidentialTotalSupply`,args:[]}}function u(e){return{address:e,abi:t,functionName:`totalSupply`,args:[]}}function d(e){return{address:e,abi:t,functionName:`rate`,args:[]}}function f(e){return{address:e,abi:t,functionName:`deploymentCoordinator`,args:[]}}function p(e,n,r){return{address:e,abi:t,functionName:`isFinalizeUnwrapOperator`,args:[n,r]}}function m(e,n,r){return{address:e,abi:t,functionName:`setFinalizeUnwrapOperator`,args:[n,r??Math.floor(Date.now()/1e3)+3600]}}const h=[{inputs:[{internalType:`euint64`,name:`burntAmount`,type:`bytes32`},{internalType:`uint64`,name:`burntAmountCleartext`,type:`uint64`},{internalType:`bytes`,name:`decryptionProof`,type:`bytes`}],name:`finalizeUnwrap`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[],name:`underlying`,outputs:[{internalType:`address`,name:``,type:`address`}],stateMutability:`view`,type:`function`},{inputs:[{internalType:`address`,name:`to`,type:`address`},{internalType:`uint256`,name:`amount`,type:`uint256`}],name:`wrap`,outputs:[],stateMutability:`nonpayable`,type:`function`},{inputs:[{internalType:`address`,name:`to`,type:`address`},{internalType:`uint256`,name:`amount`,type:`uint256`}],name:`wrapETH`,outputs:[],stateMutability:`payable`,type:`function`}];function g(e,t,n,r){return{address:e,abi:h,functionName:`finalizeUnwrap`,args:[t,n,r]}}function _(e){return{address:e,abi:h,functionName:`underlying`,args:[]}}function v(e,t,n){return{address:e,abi:h,functionName:`wrap`,args:[t,n]}}function y(e,t,n,r){return{address:e,abi:h,functionName:`wrapETH`,args:[t,n],value:r}}const b=[{inputs:[{internalType:`address`,name:`originalToken`,type:`address`}],name:`getWrapper`,outputs:[{internalType:`address`,name:``,type:`address`}],stateMutability:`view`,type:`function`},{inputs:[{internalType:`address`,name:`originalToken`,type:`address`}],name:`wrapperExists`,outputs:[{internalType:`bool`,name:``,type:`bool`}],stateMutability:`view`,type:`function`}];function x(e,t){return{address:e,abi:b,functionName:`getWrapper`,args:[t]}}function S(e,t){return{address:e,abi:b,functionName:`wrapperExists`,args:[t]}}const C=[{inputs:[{internalType:`bytes4`,name:`interfaceId`,type:`bytes4`}],name:`supportsInterface`,outputs:[{internalType:`bool`,name:``,type:`bool`}],stateMutability:`view`,type:`function`}],w=`0x4958f2a4`,T=`0xd04584ba`;function E(e,t){return{address:e,abi:C,functionName:`supportsInterface`,args:[t]}}function D(e){return E(e,w)}function O(e){return E(e,T)}export{s as C,u as S,p as _,E as a,m as b,g as c,y as d,n as f,f as g,i as h,O as i,_ as l,r as m,T as n,x as o,l as p,D as r,S as s,w as t,v as u,a as v,c as w,o as x,d as y};
2
- //# sourceMappingURL=erc165-DhZSW9Ep.js.map
2
+ //# sourceMappingURL=erc165-BZgfzGxL.js.map
@@ -1,6 +1,6 @@
1
- import { n as EIP712TypedData, o as Handle } from "../relayer-sdk.types-7bIeWnws.js";
2
- import { _ as WriteContractConfig, f as TransactionReceipt, o as ReadContractConfig, r as GenericSigner, u as SignerLifecycleCallbacks } from "../token.types-CKH_X0ki.js";
3
- import { i as BatchTransferData } from "../index-CKQy-JYP.js";
1
+ import { n as EIP712TypedData, o as Handle } from "../relayer-sdk.types-DI4WWkTB.js";
2
+ import { _ as WriteContractConfig, f as TransactionReceipt, o as ReadContractConfig, r as GenericSigner, u as SignerLifecycleCallbacks } from "../token.types-DDdIZEax.js";
3
+ import { i as BatchTransferData } from "../index-BFPpJ8wt.js";
4
4
  import { Abi, Address, ContractFunctionArgs, ContractFunctionName, ContractFunctionReturnType, EIP1193EventMap, EIP1193Events, EIP1193Provider, EIP1193Provider as EIP1193Provider$1, Hex, ProviderConnectInfo, ProviderMessage, ProviderRpcError } from "viem";
5
5
  import { Signer, ethers } from "ethers";
6
6
 
@@ -1,2 +1,2 @@
1
- import{C as e,a as t,c as n,d as r,f as i,l as a,m as o,o as s,s as c,u as l,w as u,x as d}from"../erc165-DhZSW9Ep.js";import{t as f}from"../transfer-batcher-BjcIUcH3.js";import{t as p}from"../eip1193-subscribe-3FLcs1me.js";import{ProviderRpcError as m,decodeFunctionResult as h,encodeFunctionData as g,getAddress as _,isHex as v}from"viem";import{BrowserProvider as y,ethers as b}from"ethers";var x=class{#e;#t;#n;constructor(e){if(`ethereum`in e){let t=new y(e.ethereum);this.#e=t.getSigner(),this.#t=t,this.#n=e.ethereum}else `signer`in e?(this.#e=Promise.resolve(e.signer),this.#t=e.signer.provider??void 0):this.#t=e.provider}async#r(){if(!this.#e)throw TypeError(`No signer configured — read-only mode`);return this.#e}#i(){if(!this.#t)throw TypeError(`Signer has no provider`);return this.#t}async getChainId(){let e=await this.#i().getNetwork();return Number(e.chainId)}async getAddress(){return _(await(await this.#r()).getAddress())}async signTypedData(e){let t=await this.#r(),{domain:n,types:r,message:i}=e,{EIP712Domain:a,...o}=r,s=Object.fromEntries(Object.entries(o).map(([e,t])=>[e,[...t]])),c=await t.signTypedData(n,s,i);if(!v(c))throw TypeError(`Expected hex string, got: ${c}`);return c}async writeContract(e){let t=await this.#r(),n=new b.Contract(e.address,e.abi,t),r={};e.value!==void 0&&(r.value=e.value),e.gas!==void 0&&(r.gasLimit=e.gas);let i=await n[e.functionName](...e.args,r);if(!v(i.hash))throw TypeError(`Expected hex string, got: ${i.hash}`);return i.hash}async readContract(e){let t=this.#i();return new b.Contract(e.address,e.abi,t)[e.functionName](...e.args)}async getBlockTimestamp(){let e=await this.#i().getBlock(`latest`);if(!e)throw Error(`Failed to fetch latest block`);if(e.timestamp==null)throw Error(`Latest block has no timestamp`);return BigInt(e.timestamp)}async waitForTransactionReceipt(e){let t=await this.#i().waitForTransaction(e);if(!t)throw Error(`Transaction receipt not found`);return{logs:t.logs.map(e=>({topics:e.topics.filter(e=>e!==null),data:e.data}))}}subscribe(e){return p(this.#n,()=>this.getAddress(),e)}};function S(e){return{to:e.address,data:g({abi:e.abi,functionName:e.functionName,args:e.args}),...e.gas===void 0?{}:{gasLimit:e.gas},...e.value===void 0?{}:{value:e.value}}}async function C(e,t){let n=await e.call(S(t));if(!v(n))throw TypeError(`Expected hex string, got: ${n}`);return h({abi:t.abi,functionName:t.functionName,data:n})}async function w(e,t){let n=await e.sendTransaction(S(t));if(!v(n.hash))throw TypeError(`Expected hex string, got: ${n.hash}`);return n.hash}function T(e,t,n){return C(e,i(t,n))}function E(e,t,n){return C(e,s(t,n))}function D(e,t){return C(e,a(t))}function O(e,t,n){return C(e,c(t,n))}function k(e,n,r){return C(e,t(n,r))}function A(e,t,n,r,i){return w(e,o(t,n,r,i))}function j(e,t,n,r,i,a){return w(e,f(t,n,r,i,a))}function M(t,n,r,i,a,o){return w(t,e(n,r,i,a,o))}function N(e,t,n,r,i){return w(e,u(t,n,r,i))}function P(e,t,r,i,a){return w(e,n(t,r,i,a))}function F(e,t,n,r){return w(e,d(t,n,r))}function I(e,t,n,r){return w(e,l(t,n,r))}function L(e,t,n,i,a){return w(e,r(t,n,i,a))}export{x as EthersSigner,m as ProviderRpcError,T as readConfidentialBalanceOfContract,k as readSupportsInterfaceContract,D as readUnderlyingTokenContract,O as readWrapperExistsContract,E as readWrapperForTokenContract,j as writeConfidentialBatchTransferContract,A as writeConfidentialTransferContract,P as writeFinalizeUnwrapContract,F as writeSetOperatorContract,M as writeUnwrapContract,N as writeUnwrapFromBalanceContract,I as writeWrapContract,L as writeWrapETHContract};
1
+ import{C as e,a as t,c as n,d as r,f as i,l as a,m as o,o as s,s as c,u as l,w as u,x as d}from"../erc165-BZgfzGxL.js";import{t as f}from"../transfer-batcher-uEcB2HJO.js";import{t as p}from"../eip1193-subscribe-3FLcs1me.js";import{ProviderRpcError as m,decodeFunctionResult as h,encodeFunctionData as g,getAddress as _,isHex as v}from"viem";import{BrowserProvider as y,ethers as b}from"ethers";var x=class{#e;#t;#n;constructor(e){if(`ethereum`in e){let t=new y(e.ethereum);this.#e=t.getSigner(),this.#t=t,this.#n=e.ethereum}else `signer`in e?(this.#e=Promise.resolve(e.signer),this.#t=e.signer.provider??void 0):this.#t=e.provider}async#r(){if(!this.#e)throw TypeError(`No signer configured — read-only mode`);return this.#e}#i(){if(!this.#t)throw TypeError(`Signer has no provider`);return this.#t}async getChainId(){let e=await this.#i().getNetwork();return Number(e.chainId)}async getAddress(){return _(await(await this.#r()).getAddress())}async signTypedData(e){let t=await this.#r(),{domain:n,types:r,message:i}=e,{EIP712Domain:a,...o}=r,s=Object.fromEntries(Object.entries(o).map(([e,t])=>[e,[...t]])),c=await t.signTypedData(n,s,i);if(!v(c))throw TypeError(`Expected hex string, got: ${c}`);return c}async writeContract(e){let t=await this.#r(),n=new b.Contract(e.address,e.abi,t),r={};e.value!==void 0&&(r.value=e.value),e.gas!==void 0&&(r.gasLimit=e.gas);let i=await n[e.functionName](...e.args,r);if(!v(i.hash))throw TypeError(`Expected hex string, got: ${i.hash}`);return i.hash}async readContract(e){let t=this.#i();return new b.Contract(e.address,e.abi,t)[e.functionName](...e.args)}async getBlockTimestamp(){let e=await this.#i().getBlock(`latest`);if(!e)throw Error(`Failed to fetch latest block`);if(e.timestamp===null)throw Error(`Latest block has no timestamp`);return BigInt(e.timestamp)}async waitForTransactionReceipt(e){let t=await this.#i().waitForTransaction(e);if(!t)throw Error(`Transaction receipt not found`);return{logs:t.logs.map(e=>({topics:e.topics.filter(e=>e!==null),data:e.data}))}}subscribe(e){return p(this.#n,()=>this.getAddress(),e)}};function S(e){return{to:e.address,data:g({abi:e.abi,functionName:e.functionName,args:e.args}),...e.gas===void 0?{}:{gasLimit:e.gas},...e.value===void 0?{}:{value:e.value}}}async function C(e,t){let n=await e.call(S(t));if(!v(n))throw TypeError(`Expected hex string, got: ${n}`);return h({abi:t.abi,functionName:t.functionName,data:n})}async function w(e,t){let n=await e.sendTransaction(S(t));if(!v(n.hash))throw TypeError(`Expected hex string, got: ${n.hash}`);return n.hash}function T(e,t,n){return C(e,i(t,n))}function E(e,t,n){return C(e,s(t,n))}function D(e,t){return C(e,a(t))}function O(e,t,n){return C(e,c(t,n))}function k(e,n,r){return C(e,t(n,r))}function A(e,t,n,r,i){return w(e,o(t,n,r,i))}function j(e,t,n,r,i,a){return w(e,f(t,n,r,i,a))}function M(t,n,r,i,a,o){return w(t,e(n,r,i,a,o))}function N(e,t,n,r,i){return w(e,u(t,n,r,i))}function P(e,t,r,i,a){return w(e,n(t,r,i,a))}function F(e,t,n,r){return w(e,d(t,n,r))}function I(e,t,n,r){return w(e,l(t,n,r))}function L(e,t,n,i,a){return w(e,r(t,n,i,a))}export{x as EthersSigner,m as ProviderRpcError,T as readConfidentialBalanceOfContract,k as readSupportsInterfaceContract,D as readUnderlyingTokenContract,O as readWrapperExistsContract,E as readWrapperForTokenContract,j as writeConfidentialBatchTransferContract,A as writeConfidentialTransferContract,P as writeFinalizeUnwrapContract,F as writeSetOperatorContract,M as writeUnwrapContract,N as writeUnwrapFromBalanceContract,I as writeWrapContract,L as writeWrapETHContract};
2
2
  //# sourceMappingURL=index.js.map
@@ -1,4 +1,4 @@
1
- import { o as Handle } from "./relayer-sdk.types-7bIeWnws.js";
1
+ import { o as Handle } from "./relayer-sdk.types-DI4WWkTB.js";
2
2
  import { Address, Hex } from "viem";
3
3
 
4
4
  //#region src/contracts/encrypted.d.ts
@@ -5379,4 +5379,4 @@ declare function getDelegationExpiryContract(aclAddress: Address, delegatorAddre
5379
5379
  };
5380
5380
  //#endregion
5381
5381
  export { confidentialTransferFromContract as A, finalizeUnwrapContract as C, confidentialBalanceOfContract as D, wrapETHContract as E, setFinalizeUnwrapOperatorContract as F, setOperatorContract as I, totalSupplyContract as L, isFinalizeUnwrapOperatorContract as M, isOperatorContract as N, confidentialTotalSupplyContract as O, rateContract as P, unwrapContract as R, symbolContract as S, wrapContract as T, allowanceContract as _, confidentialBatchTransferContract as a, decimalsContract as b, getUnwrapFeeContract as c, ERC7984_WRAPPER_INTERFACE_ID as d, isConfidentialTokenContract as f, wrapperExistsContract as g, getWrapperContract as h, BatchTransferData as i, deploymentCoordinatorContract as j, confidentialTransferContract as k, getWrapFeeContract as l, supportsInterfaceContract as m, getDelegationExpiryContract as n, getBatchTransferFeeContract as o, isConfidentialWrapperContract as p, revokeDelegationContract as r, getFeeRecipientContract as s, delegateForUserDecryptionContract as t, ERC7984_INTERFACE_ID as u, approveContract as v, underlyingContract as w, nameContract as x, balanceOfContract as y, unwrapFromBalanceContract as z };
5382
- //# sourceMappingURL=index-CKQy-JYP.d.ts.map
5382
+ //# sourceMappingURL=index-BFPpJ8wt.d.ts.map
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { a as EncryptResult, c as PublicDecryptResult, d as RelayerWebSecurityConfig, f as UserDecryptParams, i as EncryptParams, k as GenericLogger, l as RelayerSDKStatus, n as EIP712TypedData, o as Handle, r as EncryptInput, s as NetworkType, t as DelegatedUserDecryptParams, u as RelayerWebConfig } from "./relayer-sdk.types-7bIeWnws.js";
2
- import { A as decodeOnChainEvents, C as Topics, D as WrappedEvent, E as UnwrappedStartedEvent, F as findUnwrapRequested, I as findWrapped, M as decodeUnwrappedFinalized, N as decodeUnwrappedStarted, O as decodeConfidentialTransfer, P as decodeWrapped, S as TOKEN_TOPICS, T as UnwrappedFinalizedEvent, _ as WriteContractConfig, a as ReadContractArgs, b as OnChainEvent, c as ReadFunctionName, d as StoredCredentials, f as TransactionReceipt, g as WriteContractArgs, h as UnshieldCallbacks, i as GenericStorage, j as decodeUnwrapRequested, k as decodeOnChainEvent, l as ShieldCallbacks, m as TransferCallbacks, n as DelegatedStoredCredentials, o as ReadContractConfig, p as TransactionResult, r as GenericSigner, s as ReadContractReturnType, t as ContractAbi, u as SignerLifecycleCallbacks, v as WriteFunctionName, w as UnwrapRequestedEvent, x as RawLog, y as ConfidentialTransferEvent } from "./token.types-CKH_X0ki.js";
3
- import { A as confidentialTransferFromContract, C as finalizeUnwrapContract, D as confidentialBalanceOfContract, E as wrapETHContract, F as setFinalizeUnwrapOperatorContract, I as setOperatorContract, L as totalSupplyContract, M as isFinalizeUnwrapOperatorContract, N as isOperatorContract, O as confidentialTotalSupplyContract, P as rateContract, R as unwrapContract, S as symbolContract, T as wrapContract, _ as allowanceContract, a as confidentialBatchTransferContract, b as decimalsContract, c as getUnwrapFeeContract, d as ERC7984_WRAPPER_INTERFACE_ID, f as isConfidentialTokenContract, g as wrapperExistsContract, h as getWrapperContract, i as BatchTransferData, j as deploymentCoordinatorContract, k as confidentialTransferContract, l as getWrapFeeContract, m as supportsInterfaceContract, n as getDelegationExpiryContract, o as getBatchTransferFeeContract, p as isConfidentialWrapperContract, r as revokeDelegationContract, s as getFeeRecipientContract, t as delegateForUserDecryptionContract, u as ERC7984_INTERFACE_ID, v as approveContract, w as underlyingContract, x as nameContract, y as balanceOfContract, z as unwrapFromBalanceContract } from "./index-CKQy-JYP.js";
4
- import { t as RelayerSDK } from "./relayer-sdk-DFUB0ULp.js";
1
+ import { a as EncryptResult, c as PublicDecryptResult, d as RelayerWebSecurityConfig, f as UserDecryptParams, i as EncryptParams, k as GenericLogger, l as RelayerSDKStatus, n as EIP712TypedData, o as Handle, r as EncryptInput, s as NetworkType, t as DelegatedUserDecryptParams, u as RelayerWebConfig } from "./relayer-sdk.types-DI4WWkTB.js";
2
+ import { A as decodeOnChainEvents, C as Topics, D as WrappedEvent, E as UnwrappedStartedEvent, F as findUnwrapRequested, I as findWrapped, M as decodeUnwrappedFinalized, N as decodeUnwrappedStarted, O as decodeConfidentialTransfer, P as decodeWrapped, S as TOKEN_TOPICS, T as UnwrappedFinalizedEvent, _ as WriteContractConfig, a as ReadContractArgs, b as OnChainEvent, c as ReadFunctionName, d as StoredCredentials, f as TransactionReceipt, g as WriteContractArgs, h as UnshieldCallbacks, i as GenericStorage, j as decodeUnwrapRequested, k as decodeOnChainEvent, l as ShieldCallbacks, m as TransferCallbacks, n as DelegatedStoredCredentials, o as ReadContractConfig, p as TransactionResult, r as GenericSigner, s as ReadContractReturnType, t as ContractAbi, u as SignerLifecycleCallbacks, v as WriteFunctionName, w as UnwrapRequestedEvent, x as RawLog, y as ConfidentialTransferEvent } from "./token.types-DDdIZEax.js";
3
+ import { A as confidentialTransferFromContract, C as finalizeUnwrapContract, D as confidentialBalanceOfContract, E as wrapETHContract, F as setFinalizeUnwrapOperatorContract, I as setOperatorContract, L as totalSupplyContract, M as isFinalizeUnwrapOperatorContract, N as isOperatorContract, O as confidentialTotalSupplyContract, P as rateContract, R as unwrapContract, S as symbolContract, T as wrapContract, _ as allowanceContract, a as confidentialBatchTransferContract, b as decimalsContract, c as getUnwrapFeeContract, d as ERC7984_WRAPPER_INTERFACE_ID, f as isConfidentialTokenContract, g as wrapperExistsContract, h as getWrapperContract, i as BatchTransferData, j as deploymentCoordinatorContract, k as confidentialTransferContract, l as getWrapFeeContract, m as supportsInterfaceContract, n as getDelegationExpiryContract, o as getBatchTransferFeeContract, p as isConfidentialWrapperContract, r as revokeDelegationContract, s as getFeeRecipientContract, t as delegateForUserDecryptionContract, u as ERC7984_INTERFACE_ID, v as approveContract, w as underlyingContract, x as nameContract, y as balanceOfContract, z as unwrapFromBalanceContract } from "./index-BFPpJ8wt.js";
4
+ import { t as RelayerSDK } from "./relayer-sdk-CVVR30IW.js";
5
5
  import { n as MainnetConfig, r as SepoliaConfig, t as HardhatConfig } from "./relayer-utils-DsivYLt_.js";
6
- import { $ as DecryptStartEvent, A as ZamaErrorCode, B as CredentialsManagerConfig, C as KeypairExpiredError, D as SigningRejectedError, E as SigningFailedError, F as ReadonlyTokenConfig, G as CredentialsCachedEvent, H as ApproveUnderlyingSubmittedEvent, I as ZERO_HANDLE, J as CredentialsExpiredEvent, K as CredentialsCreatedEvent, L as DelegatedCredentialsManager, M as BatchDecryptAsOptions, N as BatchDecryptOptions, O as TransactionRevertedError, P as ReadonlyToken, Q as DecryptErrorEvent, R as DelegatedCredentialsManagerConfig, S as InvalidKeypairError, T as RelayerRequestFailedError, U as BaseEvent, V as ApproveSubmittedEvent, W as CredentialsAllowedEvent, X as CredentialsRevokedEvent, Y as CredentialsLoadingEvent, Z as DecryptEndEvent, _ as DelegationCooldownError, _t as ZamaSDKEvents, a as ActivityType, at as ShieldSubmittedEvent, b as DelegationSelfNotAllowedError, c as parseActivityFeed, ct as TransferSubmittedEvent, d as ZamaSDKConfig, dt as UnshieldPhase2SubmittedEvent, et as EncryptEndEvent, f as Token, ft as UnwrapSubmittedEvent, g as DecryptionFailedError, gt as ZamaSDKEventType, h as ConfigurationError, ht as ZamaSDKEventListener, i as ActivityLogMetadata, it as SessionExpiredEvent, j as matchZamaError, k as ZamaError, l as sortByBlockNumber, lt as UnshieldPhase1SubmittedEvent, m as ApprovalFailedError, mt as ZamaSDKEventInput, n as ActivityDirection, nt as EncryptStartEvent, o as applyDecryptedValues, ot as TransactionErrorEvent, p as TokenConfig, pt as ZamaSDKEvent, q as CredentialsCreatingEvent, r as ActivityItem, rt as FinalizeUnwrapSubmittedEvent, s as extractEncryptedHandles, st as TransferFromSubmittedEvent, t as ActivityAmount, tt as EncryptErrorEvent, u as ZamaSDK, ut as UnshieldPhase2StartedEvent, v as DelegationExpiredError, w as NoCiphertextError, x as EncryptionFailedError, y as DelegationNotFoundError, z as CredentialsManager } from "./activity-jvpqohOy.js";
6
+ import { $ as DecryptStartEvent, A as ZamaErrorCode, B as CredentialsManagerConfig, C as KeypairExpiredError, D as SigningRejectedError, E as SigningFailedError, F as ReadonlyTokenConfig, G as CredentialsCachedEvent, H as ApproveUnderlyingSubmittedEvent, I as ZERO_HANDLE, J as CredentialsExpiredEvent, K as CredentialsCreatedEvent, L as DelegatedCredentialsManager, M as BatchDecryptAsOptions, N as BatchDecryptOptions, O as TransactionRevertedError, P as ReadonlyToken, Q as DecryptErrorEvent, R as DelegatedCredentialsManagerConfig, S as InvalidKeypairError, T as RelayerRequestFailedError, U as BaseEvent, V as ApproveSubmittedEvent, W as CredentialsAllowedEvent, X as CredentialsRevokedEvent, Y as CredentialsLoadingEvent, Z as DecryptEndEvent, _ as DelegationCooldownError, _t as ZamaSDKEvents, a as ActivityType, at as ShieldSubmittedEvent, b as DelegationSelfNotAllowedError, c as parseActivityFeed, ct as TransferSubmittedEvent, d as ZamaSDKConfig, dt as UnshieldPhase2SubmittedEvent, et as EncryptEndEvent, f as Token, ft as UnwrapSubmittedEvent, g as DecryptionFailedError, gt as ZamaSDKEventType, h as ConfigurationError, ht as ZamaSDKEventListener, i as ActivityLogMetadata, it as SessionExpiredEvent, j as matchZamaError, k as ZamaError, l as sortByBlockNumber, lt as UnshieldPhase1SubmittedEvent, m as ApprovalFailedError, mt as ZamaSDKEventInput, n as ActivityDirection, nt as EncryptStartEvent, o as applyDecryptedValues, ot as TransactionErrorEvent, p as TokenConfig, pt as ZamaSDKEvent, q as CredentialsCreatingEvent, r as ActivityItem, rt as FinalizeUnwrapSubmittedEvent, s as extractEncryptedHandles, st as TransferFromSubmittedEvent, t as ActivityAmount, tt as EncryptErrorEvent, u as ZamaSDK, ut as UnshieldPhase2StartedEvent, v as DelegationExpiredError, w as NoCiphertextError, x as EncryptionFailedError, y as DelegationNotFoundError, z as CredentialsManager } from "./activity-CV1NDmFr.js";
7
7
  import { Address, Address as Address$1, Hex, Hex as Hex$1 } from "viem";
8
8
  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";
9
9