UNPKG

@privy-io/js-sdk-core

Version:

Vanilla JS client for the Privy Auth API

2 lines 2.83 kB
import{http as e}from"viem";import{createSmartAccountClient as t}from"permissionless";import{toBiconomySmartAccount as n,toKernelSmartAccount as r,toLightSmartAccount as i,toNexusSmartAccount as a,toSafeSmartAccount as o,toThirdwebSmartAccount as s}from"permissionless/accounts";import{createPimlicoClient as c}from"permissionless/clients/pimlico";import{entryPoint06Address as l,entryPoint07Address as u,toCoinbaseSmartAccount as d}from"viem/account-abstraction";const f={address:l,version:`0.6`},p={address:u,version:`0.7`},m=({owner:e,smartWalletType:t,smartWalletVersion:c,publicClient:l})=>{switch(t){case`safe`:return o({client:l,entryPoint:p,owners:[e],version:`1.4.1`});case`kernel`:return r({client:l,version:`0.3.1`,entryPoint:p,useMetaFactory:`optional`,owners:[e]});case`biconomy`:return n({client:l,owners:[e],entryPoint:f});case`light_account`:return i({client:l,entryPoint:f,owner:e,version:`1.1.0`});case`coinbase_smart_wallet`:return g({client:l,owner:e,version:c??`1`});case`thirdweb`:return s({client:l,entryPoint:p,owner:e});case`nexus`:return a({client:l,owners:[e],version:`1.0.0`,entryPoint:p});default:throw Error(`Invalid smart account type: ${t}.`)}},h=async({owner:n,smartWalletType:r,smartWalletVersion:i,chain:a,publicClient:o,bundlerUrl:s,paymasterUrl:l,paymasterContext:u})=>{let d=await m({owner:n,smartWalletType:r,smartWalletVersion:i,publicClient:o}),f=c({transport:e(s),entryPoint:d.entryPoint});return t({account:d,chain:a,paymaster:l?c({transport:e(l),entryPoint:d.entryPoint}):void 0,paymasterContext:u,bundlerTransport:e(s),userOperation:{estimateFeesPerGas:async()=>{if([`public.pimlico.io`,`api.pimlico.io`].some(e=>s.includes(e)))return await f.getUserOperationGasPrice().then(e=>e.fast);if([`rpc.zerodev.app`].some(e=>s.includes(e)))return(await f.request({method:`zd_getUserOperationGasPrice`,params:[]})).fast;if([`g.alchemy.com`].some(e=>s.includes(e))){let[e,t]=await Promise.all([o.getBlock({blockTag:`latest`}),f.request({method:`rundler_maxPriorityFeePerGas`,params:[]})]);if(!e.baseFeePerGas||!t)throw Error(`Failed to get block or maxPriorityFeePerGasEstimate`);return{maxFeePerGas:e.baseFeePerGas*150n/100n+BigInt(t.toString()),maxPriorityFeePerGas:BigInt(t.toString())}}else{let e=await o.estimateFeesPerGas(),t=s.includes(`api.developer.coinbase.com`)?175n:150n;return{...e,maxFeePerGas:e.maxFeePerGas*t/100n,maxPriorityFeePerGas:e.maxPriorityFeePerGas*t/100n}}}}})};async function g({client:e,owner:t,version:n}){let[r]=await t.request({method:`eth_accounts`});if(!r)throw Error(`Unable to request embedded owner for eth_accounts`);return await d({client:e,owners:[{type:`local`,source:`privy`,address:r,sign:async({hash:e})=>await t.request({method:`secp256k1_sign`,params:[e]})}],version:n})}export{h as signerToSmartAccountClient}; //# sourceMappingURL=smart-wallets.mjs.map