@privy-io/react-auth
Version:
React client for the Privy Auth API
2 lines (1 loc) • 6.55 kB
JavaScript
import{jsx as o}from"react/jsx-runtime";import{useContext as e,useState as r,useEffect as i,createContext as t}from"react";import{u as n,g as c}from"./use-sign-with-user-signer-DYa7HrQH.mjs";import{o as a,w as l}from"./privy-provider-Ck8owl_s.mjs";import{P as s}from"./paths-DCwuPDUk.mjs";import{g as m}from"./getEmbeddedConnectedWallet-CSSBWE2p.mjs";import{u as p,g as h,a as u}from"./smart-wallets-BcIaFW29.mjs";import{u as d,a as g}from"./internal-context-qdNgTV5f.mjs";import"viem";import"mipd";import"react-device-detect";import"viem/utils";import"@privy-io/js-sdk-core";import"uuid";import"jose";import"eventemitter3";import"@coinbase/wallet-sdk";import"@privy-io/ethereum";import"@marsidev/react-turnstile";import"styled-components";import"tinycolor2";import"@heroicons/react/24/outline/DevicePhoneMobileIcon";import"@heroicons/react/24/outline/FingerPrintIcon";import"@heroicons/react/24/outline/PhoneIcon";import"@heroicons/react/24/outline/ShieldCheckIcon";import"@heroicons/react/24/outline/ArrowLeftIcon";import"@heroicons/react/24/outline/ArrowRightIcon";import"@heroicons/react/24/outline/QuestionMarkCircleIcon";import"@heroicons/react/24/outline/XMarkIcon";import"@heroicons/react/24/outline/CalendarIcon";import"@heroicons/react/24/outline/ExclamationTriangleIcon";import"@heroicons/react/24/outline/ChevronDownIcon";import"zustand";import"@headlessui/react";import"@heroicons/react/24/outline/CheckIcon";import"@heroicons/react/24/outline/Square2StackIcon";import"@walletconnect/ethereum-provider";import"fast-password-entropy";import"secure-password-utilities";import"secure-password-utilities/wordlists";import"@heroicons/react/24/outline/UserCircleIcon";import"@heroicons/react/24/outline/EnvelopeIcon";import"@heroicons/react/20/solid/CheckIcon";import"@heroicons/react/24/outline/WalletIcon";import"@heroicons/react/24/outline/ExclamationCircleIcon";import"@heroicons/react/24/outline/ArrowTopRightOnSquareIcon";import"@heroicons/react/24/solid/DocumentCheckIcon";import"@heroicons/react/24/solid/XCircleIcon";import"@heroicons/react/24/solid/CheckCircleIcon";import"@heroicons/react/24/outline";import"@tanstack/react-virtual";import"qrcode";import"@heroicons/react/24/solid/ArrowsRightLeftIcon";import"@heroicons/react/24/outline/ChevronRightIcon";import"@heroicons/react/24/outline/LockClosedIcon";import"@heroicons/react/24/outline/PencilSquareIcon";import"@heroicons/react/24/outline/ArrowPathIcon";import"@heroicons/react/24/outline/EyeIcon";import"@heroicons/react/24/outline/EyeSlashIcon";import"@heroicons/react/24/outline/KeyIcon";import"@heroicons/react/24/outline/ArrowDownTrayIcon";import"@heroicons/react/24/outline/ClipboardDocumentCheckIcon";import"@heroicons/react/24/outline/DocumentDuplicateIcon";import"@heroicons/react/24/solid/LockClosedIcon";import"@heroicons/react/24/outline/CheckCircleIcon";import"@heroicons/react/24/outline/InformationCircleIcon";import"@heroicons/react/24/outline/CreditCardIcon";import"@heroicons/react/24/outline/QrCodeIcon";import"@heroicons/react/24/outline/GlobeAltIcon";import"ofetch";import"@heroicons/react/24/outline/ClipboardDocumentIcon";import"@heroicons/react/24/outline/CloudArrowUpIcon";import"@heroicons/react/24/outline/NoSymbolIcon";import"@heroicons/react/24/outline/ClockIcon";import"@heroicons/react/24/outline/TrashIcon";import"@heroicons/react/24/solid/CheckBadgeIcon";import"@heroicons/react/24/solid/IdentificationIcon";import"@heroicons/react/24/outline/MinusCircleIcon";import"@heroicons/react/24/outline/ArrowRightEndOnRectangleIcon";import"@heroicons/react/24/solid/ShieldCheckIcon";import"js-cookie";import"permissionless";import"permissionless/accounts";import"permissionless/clients/pimlico";import"viem/account-abstraction";let C=/*#__PURE__*/t({client:void 0,getClientForChain:g});const I=({config:e,children:r})=>/*#__PURE__*/o(y,{children:/*#__PURE__*/o(k,{config:e,children:/*#__PURE__*/o(P,{children:r})})}),f=()=>{let{client:o,getClientForChain:r}=e(C);return{client:o,getClientForChain:r}};let w=/*#__PURE__*/t({config:void 0}),v=()=>{let{config:o}=e(w);return{config:o}},y=({children:e})=>{let[t,n]=r(void 0),{client:c}=d();return i((()=>{!t&&c&&(async()=>{try{if(!c)return void console.warn("No client found");let o=await c.getSmartWalletsConfig();n(o)}catch(o){console.warn("Error generating smart wallet config: ",o)}})()}),[!!c]),/*#__PURE__*/o(w.Provider,{value:{config:t},children:e})},k=({config:e,children:t})=>{let{config:u}=v(),{appId:g}=d(),{chains:C,defaultChain:I,rpcConfig:f}=a(),{wallets:w}=l(),{user:y}=n(),[k,P]=r(),{wrapSmartAccountClientWithUIs:S}=p(),b=c(y),A=m(w);i((()=>{(async()=>{if(!u?.enabled)return;let o=u.configuredNetworks.find((o=>o.chainId===`eip155:${I.id}`))?I:C.find((o=>u.configuredNetworks.map((o=>o.chainId)).includes(`eip155:${o.id}`)));if(!o)throw new s("Could not find smart wallets chain configurations for any Privy client configured chains. Please configure smart wallets for your chains in the Privy dashboard.");P(await h({chain:o,privyAppId:g,paymasterContext:e?.paymasterContext,rpcConfig:f,account:b,signer:await(A?.getEthereumProvider()),user:y,smartWalletsConfig:u}))})()}),[!!u?.enabled,!!y?.smartWallet,!!A,!!b]);/*#__PURE__*/return o(W.Provider,{value:{client:k,config:e,getClientForChain:async({id:o})=>{let r=await h({chain:C.find((e=>e.id===o)),privyAppId:g,paymasterContext:e?.paymasterContext,rpcConfig:f,account:b,signer:await(A?.getEthereumProvider()),user:y,smartWalletsConfig:u});if(!r)throw new s(`Failed to create smart wallet client for chain id: ${o}`);return S(r)}},children:t})},W=/*#__PURE__*/t({client:void 0,config:void 0,getClientForChain:g}),P=({children:r})=>{let{client:t,config:c,getClientForChain:a}=(()=>{let{client:o,config:r,getClientForChain:i}=e(W);return{client:o,config:r,getClientForChain:i}})(),{config:l}=v(),{wrapSmartAccountClient:s}=u({clientConfig:c,smartWalletsConfig:l}),{user:m}=n(),{generateSiweMessageForSmartWallet:p,linkSmartWallet:h,hideWalletUIs:g}=d();return i((()=>{(async()=>{if(t&&m&&!m?.smartWallet&&l?.enabled)try{let o=await p({address:t.account.address,chainId:`eip155:${t.chain.id}`});g.current=!0;let e=await t.signMessage({message:o});await h({signature:e,message:o,smartWalletType:l.smartWalletType,smartWalletVersion:l.smartWalletVersion})}catch(o){console.error("Error creating smart wallet:",o)}finally{g.current=!1}})()}),[!!t,!!m?.smartWallet,!!l?.enabled]),/*#__PURE__*/o(C.Provider,{value:{client:m?.smartWallet&&t?s(t):void 0,getClientForChain:a},children:r})};export{I as SmartWalletsProvider,f as useSmartWallets};