@zama-fhe/sdk 1.2.0-alpha.1 → 1.2.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/activity-DmoozYof.js +2 -0
- package/dist/erc165-DhZSW9Ep.js +2 -0
- package/dist/ethers/index.d.ts +1 -1
- package/dist/ethers/index.js +1 -1
- package/dist/index-CKQy-JYP.d.ts +5382 -0
- package/dist/index.d.ts +2 -4599
- package/dist/index.js +1 -1
- package/dist/query/index.js +1 -1
- package/dist/transfer-batcher-BjcIUcH3.js +2 -0
- package/dist/viem/index.d.ts +1 -1
- package/dist/viem/index.js +1 -1
- package/package.json +3 -2
- package/dist/activity-CwG6y2Xv.js +0 -2
- package/dist/activity-CwG6y2Xv.js.map +0 -1
- package/dist/cleartext/index.js.map +0 -1
- package/dist/eip1193-subscribe-3FLcs1me.js.map +0 -1
- package/dist/erc165-D-aZRxzD.js +0 -2
- package/dist/erc165-D-aZRxzD.js.map +0 -1
- package/dist/errors-Cw9kKQJc.js.map +0 -1
- package/dist/ethers/index.js.map +0 -1
- package/dist/index-D9fL2J7A.d.ts +0 -28039
- package/dist/index.js.map +0 -1
- package/dist/node/index.js.map +0 -1
- package/dist/query/index.js.map +0 -1
- package/dist/relayer-sdk.node-worker.js.map +0 -1
- package/dist/relayer-sdk.worker.js.map +0 -1
- package/dist/relayer-utils-DZ0vfhG-.js.map +0 -1
- package/dist/transfer-batcher-rDbQ7mK5.js +0 -2
- package/dist/transfer-batcher-rDbQ7mK5.js.map +0 -1
- package/dist/utils-CJW850A2.js.map +0 -1
- package/dist/viem/index.js.map +0 -1
- package/dist/worker.base-client-DGGSkczN.js.map +0 -1
|
@@ -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{a as l,f as ee,l as u,n as d,o as f,s as p,t as te}from"./erc165-DhZSW9Ep.js";import{a as ne,i as m,n as h,o as g,r as _,s as v,t as re}from"./utils-CJW850A2.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 g(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){_(e,`Stored credentials`),m(e.publicKey,`credentials.publicKey`),re(e.contractAddresses,`credentials.contractAddresses`);for(let t of e.contractAddresses)h(typeof t==`string`&&x(t,{strict:!1}),`Expected each contractAddress to be a valid hex address`);_(e.encryptedPrivateKey,`credentials.encryptedPrivateKey`),m(e.encryptedPrivateKey.iv,`encryptedPrivateKey.iv`),m(e.encryptedPrivateKey.ciphertext,`encryptedPrivateKey.ciphertext`)}function ge(e){A(e);let t=e;h(typeof t.delegatorAddress==`string`&&x(t.delegatorAddress,{strict:!1}),`Expected credentials.delegatorAddress to be a valid address`),h(typeof t.delegateAddress==`string`&&x(t.delegateAddress,{strict:!1}),`Expected credentials.delegateAddress to be a valid address`),h(typeof t.startTimestamp==`number`,`Expected startTimestamp to be a number`),h(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)))].sort()}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){_(e,`Session entry`),m(e.signature,`session.signature`),h(typeof e.createdAt==`number`,`Expected session.createdAt to be a number`),h(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(l(this.address,te))===!0}async isWrapper(){return await this.signer.readContract(l(this.address,d))===!0}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:l}=e,ee=t[0],u=n??await Promise.all(t.map(e=>e.readConfidentialBalanceOf(r)));if(t.length!==u.length)throw new s(`tokens.length (${t.length}) must equal handles.length (${u.length})`);let d=ee.storage,f=new Map,p=[],te=await Promise.all(t.map((e,t)=>{let n=u[t];return e.isZeroHandle(n)?Promise.resolve(BigInt(0)):B({storage:d,tokenAddress:e.address,owner:r,handle:n})}));for(let e=0;e<t.length;e++){let n=t[e],r=u[e],i=te[e];if(i!=null){f.set(n.address,i);continue}p.push({token:n,handle:r})}if(p.length===0)return f;e.preFlightCheck&&await e.preFlightCheck();let m=await o(p.map(e=>e.token.address)),h=[],g=[];for(let{token:e,handle:t}of p)g.push(()=>c(m,t,e.address).then(async n=>{let i=n[t];if(i===void 0)throw new s(`${l} returned no value for handle ${t} on token ${e.address}`);f.set(e.address,i);try{await V({storage:d,tokenAddress:e.address,owner:r,handle:t,value:i})}catch{}}).catch(t=>{let n=v(t);if(i)try{f.set(e.address,i(n,e.address))}catch(t){h.push({address:e.address,error:v(t)})}else h.push({address:e.address,error:n})}));if(await ne(g,a),h.length>0){let e=h.map(e=>`${e.address}: ${e.error.message}`).join(`; `);throw new s(`${l} failed for ${h.length} token(s): ${e}`)}return f}async discoverWrapper(e){let t=b(e);return await this.signer.readContract(p(t,this.address))?this.signer.readContract(f(t,this.address)):null}async underlyingToken(){return this.signer.readContract(u(this.address))}async allowance(e,t){let n=b(e),r=await this.signer.readContract(u(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(ee(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:v(e),durationMs:Date.now()-o}),H(e,`Failed to decrypt delegated balance`)}}async decryptBalance(e,t){if(this.isZeroHandle(e))return BigInt(0);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:v(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,BigInt(0)):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:v(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(g(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(g(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 g(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].sort((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-DmoozYof.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
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
|
package/dist/ethers/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as EIP712TypedData, o as Handle } from "../relayer-sdk.types-7bIeWnws.js";
|
|
2
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-
|
|
3
|
+
import { i as BatchTransferData } from "../index-CKQy-JYP.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
|
|
package/dist/ethers/index.js
CHANGED
|
@@ -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-
|
|
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};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|