@privy-io/js-sdk-core
Version:
Vanilla JS client for the Privy Auth API
2 lines • 2.92 kB
JavaScript
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require("viem"),t=require("permissionless"),n=require("permissionless/accounts"),r=require("permissionless/clients/pimlico"),i=require("viem/account-abstraction");const a={address:i.entryPoint06Address,version:`0.6`},o={address:i.entryPoint07Address,version:`0.7`},s=({owner:e,smartWalletType:t,smartWalletVersion:r,publicClient:i})=>{switch(t){case`safe`:return(0,n.toSafeSmartAccount)({client:i,entryPoint:o,owners:[e],version:`1.4.1`});case`kernel`:return(0,n.toKernelSmartAccount)({client:i,version:`0.3.1`,entryPoint:o,useMetaFactory:`optional`,owners:[e]});case`biconomy`:return(0,n.toBiconomySmartAccount)({client:i,owners:[e],entryPoint:a});case`light_account`:return(0,n.toLightSmartAccount)({client:i,entryPoint:a,owner:e,version:`1.1.0`});case`coinbase_smart_wallet`:return l({client:i,owner:e,version:r??`1`});case`thirdweb`:return(0,n.toThirdwebSmartAccount)({client:i,entryPoint:o,owner:e});case`nexus`:return(0,n.toNexusSmartAccount)({client:i,owners:[e],version:`1.0.0`,entryPoint:o});default:throw Error(`Invalid smart account type: ${t}.`)}},c=async({owner:n,smartWalletType:i,smartWalletVersion:a,chain:o,publicClient:c,bundlerUrl:l,paymasterUrl:u,paymasterContext:d})=>{let f=await s({owner:n,smartWalletType:i,smartWalletVersion:a,publicClient:c}),p=(0,r.createPimlicoClient)({transport:(0,e.http)(l),entryPoint:f.entryPoint});return(0,t.createSmartAccountClient)({account:f,chain:o,paymaster:u?(0,r.createPimlicoClient)({transport:(0,e.http)(u),entryPoint:f.entryPoint}):void 0,paymasterContext:d,bundlerTransport:(0,e.http)(l),userOperation:{estimateFeesPerGas:async()=>{if([`public.pimlico.io`,`api.pimlico.io`].some(e=>l.includes(e)))return await p.getUserOperationGasPrice().then(e=>e.fast);if([`rpc.zerodev.app`].some(e=>l.includes(e)))return(await p.request({method:`zd_getUserOperationGasPrice`,params:[]})).fast;if([`g.alchemy.com`].some(e=>l.includes(e))){let[e,t]=await Promise.all([c.getBlock({blockTag:`latest`}),p.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 c.estimateFeesPerGas(),t=l.includes(`api.developer.coinbase.com`)?175n:150n;return{...e,maxFeePerGas:e.maxFeePerGas*t/100n,maxPriorityFeePerGas:e.maxPriorityFeePerGas*t/100n}}}}})};async function l({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(0,i.toCoinbaseSmartAccount)({client:e,owners:[{type:`local`,source:`privy`,address:r,sign:async({hash:e})=>await t.request({method:`secp256k1_sign`,params:[e]})}],version:n})}exports.signerToSmartAccountClient=c;
//# sourceMappingURL=smart-wallets.js.map