@use-glyph/sdk-react 2.0.0-rc.5 → 2.0.1-rc.5
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/EIP1193Strategy.js.map +1 -1
- package/dist/PrivyStrategy.js +46 -49
- package/dist/PrivyStrategy.js.map +1 -1
- package/dist/assets/sdk-react.css +1 -1
- package/dist/glyph-widget.umd.js +30 -30
- package/dist/glyph-widget.umd.js.map +1 -1
- package/dist/index.js +3324 -3335
- package/dist/index.js.map +1 -1
- package/dist/types/hooks/useGlyph.d.ts +6 -0
- package/dist/types/hooks/useTokenBalance.d.ts +2 -3
- package/dist/types/lib/constants.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EIP1193Strategy.js","sources":["../src/context/strategies/EIP1193Strategy.tsx"],"sourcesContent":["import { SignTypedDataParams, UnsignedTransactionRequest } from \"@privy-io/react-auth\";\nimport react, { useCallback, useEffect, useState } from \"react\";\nimport {\n useAccount,\n useAccountEffect,\n useDisconnect,\n useSendTransaction,\n useSignMessage,\n useSignTypedData\n} from \"wagmi\";\nimport { WIDGET_API_BASE_URL } from \"../../lib/constants\";\nimport { createLogger } from \"../../lib/utils\";\nimport { BaseGlyphProviderOptionsWithSignature } from \"../../types\";\nimport { GlyphApiFetch, GlyphContext, createApiFetch } from \"../GlyphContext\";\n\ntype GlyphSigningMsgResponse = { message: string; nonce: string };\ntype GlyphSignatureVerifyResponse = { token: string };\n\nconst TOKEN_KEY = \"__glyph-widget-token__\";\nconst NONCE_KEY = \"__glyph-widget-nonce__\";\nconst logger = createLogger(\"EIP1193Strategy\");\n\nconst EIP1193Strategy: react.FC<BaseGlyphProviderOptionsWithSignature> = ({\n children,\n glyphUrl,\n onLogin,\n onLogout,\n askForSignature = true\n}) => {\n const [loading, setLoading] = useState(false);\n const [apiFetch, setApiFetch] = useState<GlyphApiFetch | null>(null);\n const { address, isConnected, chainId } = useAccount(); // detect wallet connection\n const { disconnectAsync } = useDisconnect(); // disconnect the wallet\n const { signMessageAsync } = useSignMessage(); // signing messages with the wallet\n const { signTypedDataAsync } = useSignTypedData(); // signing typed data with the wallet\n const { sendTransactionAsync } = useSendTransaction(); // sending transactions with the wallet\n\n logger.log({ address, isConnected });\n\n // Fetch authentication token from session storage\n const [token, setToken] = useState<string | null>(() => {\n if (typeof window === \"undefined\") {\n return null;\n }\n try {\n return localStorage.getItem(TOKEN_KEY);\n } catch (error) {\n logger.warn(\"Error reading session token\", error);\n return null;\n }\n });\n\n const [message, setMessage] = useState<string | null>(null);\n\n // fetch nonce from session storage\n const [sessNonce, setSessNonce] = useState<string | null>(() => {\n if (typeof window === \"undefined\") {\n return null;\n }\n try {\n return localStorage.getItem(NONCE_KEY);\n } catch (error) {\n logger.warn(\"Error reading session nonce\", error);\n return null;\n }\n });\n\n // Keep token and nonce updated in session storage\n useEffect(() => {\n try {\n if (!token || !sessNonce) {\n localStorage.removeItem(TOKEN_KEY);\n localStorage.removeItem(NONCE_KEY);\n } else {\n localStorage.setItem(TOKEN_KEY, token!);\n localStorage.setItem(NONCE_KEY, sessNonce!);\n }\n } catch (error) {\n logger.error(\"Error saving session token\", error);\n }\n }, [sessNonce, token]);\n\n const fetchMessageToSign = useCallback(\n async (address: string): Promise<GlyphSigningMsgResponse> => {\n try {\n const payload = (await fetch(\n `${glyphUrl || WIDGET_API_BASE_URL}/api/widget/auth/message/${address}`\n ).then((resp) => resp.json())) as GlyphSigningMsgResponse;\n\n return payload;\n } catch (error) {\n logger.error(\"Can't fetch message to sign\", error);\n throw new Error(\"Failed to fetch the message to sign.\");\n }\n },\n [glyphUrl]\n );\n\n const verifySignature = useCallback(\n async (address: string, signature: string, nonce: string): Promise<GlyphSignatureVerifyResponse> => {\n try {\n const payload = await fetch(`${glyphUrl || WIDGET_API_BASE_URL}/api/widget/auth/verify/${address}`, {\n method: \"POST\",\n body: JSON.stringify({ signature, nonce })\n }).then((resp) => resp.json());\n return payload as unknown as GlyphSignatureVerifyResponse;\n } catch (error) {\n logger.error(\"Can't verify signature\", error);\n throw new Error(\"Signature verification failed.\");\n }\n },\n [glyphUrl]\n );\n\n useEffect(() => {\n if (!address || !isConnected) return;\n if (sessNonce) return;\n\n setLoading(true);\n fetchMessageToSign(address)\n .then(({ message, nonce }) => {\n setMessage(message);\n setSessNonce(nonce);\n setLoading(false);\n })\n .finally(() => {\n setLoading(false);\n });\n }, [address, isConnected, fetchMessageToSign, sessNonce]);\n\n useEffect(() => {\n if (!token || !sessNonce) return;\n\n const glyphApiFetch = createApiFetch(glyphUrl || WIDGET_API_BASE_URL, async () => token, {\n \"x-evm-address\": address!,\n \"x-glyph-nonce\": sessNonce!\n });\n setApiFetch(() => glyphApiFetch);\n }, [token, address, glyphUrl, sessNonce]);\n\n const disconnect = useCallback(async () => {\n await disconnectAsync();\n }, [disconnectAsync]);\n\n const authenticate = useCallback(async () => {\n logger.log(\"authenticate\");\n if (!address) {\n logger.error(\"no wallet connected.\");\n return;\n }\n\n try {\n if (!address || !isConnected || !message || !sessNonce) {\n setApiFetch(null);\n setLoading(false);\n return;\n }\n\n // Sign a message with the wallet to authenticate\n setLoading(true);\n\n const userSignature = await signMessageAsync({ account: address, message: message });\n console.log(sessNonce, message, userSignature);\n\n const token = (await verifySignature(address, userSignature, sessNonce))?.token;\n\n setToken(token);\n } catch (error) {\n logger.error(\"Authentication failed\", error);\n if (!(error as Error)?.message?.toLowerCase?.().includes?.(\"user rejected\")) {\n await alert(\n \"Authentication failed - your browser could be blocking the popups. Allow popups or try to manually click sign in.\"\n );\n }\n setApiFetch(null);\n setToken(null);\n setSessNonce(null);\n } finally {\n setLoading(false);\n onLogin?.();\n }\n }, [address, isConnected, message, sessNonce, signMessageAsync, verifySignature]);\n\n const logoutSideEffect = useCallback(async () => {\n setSessNonce(null);\n setToken(null);\n setLoading(false);\n setApiFetch(null);\n onLogout?.();\n }, []);\n\n const signMessage = useCallback(\n async ({ message }: { message: string }) => {\n if (!address || !isConnected) {\n throw new Error(\"Wallet not connected\");\n }\n return signMessageAsync({ account: address, message });\n },\n [address, isConnected, signMessageAsync]\n );\n\n const signTypedData = useCallback(\n async ({ data }: { data: SignTypedDataParams }) => {\n if (!address || !isConnected) {\n throw new Error(\"Wallet not connected\");\n }\n const types = data.types;\n const primaryType = data.primaryType as string;\n const message = data.message;\n return signTypedDataAsync({ types, primaryType, message });\n },\n [address, isConnected, signTypedDataAsync]\n );\n\n const sendTransaction = useCallback(\n async ({ transaction }: { transaction: UnsignedTransactionRequest }) => {\n if (!address || !isConnected) throw new Error(\"Wallet not connected\");\n\n return sendTransactionAsync({ ...transaction, chainId: transaction.chainId || chainId } as any);\n },\n [address, isConnected, sendTransactionAsync, chainId]\n );\n\n const [tryAuthenticate, setTryAuthenticate] = useState<boolean>(false);\n // Perform graceful logout when the wallet is disconnected from anywhere within the app\n useAccountEffect({\n onConnect: () => {\n if (askForSignature) {\n // Perform initial authentication when the wallet is connected\n setTryAuthenticate(true);\n }\n },\n onDisconnect: () => {\n logoutSideEffect();\n }\n });\n useEffect(() => {\n if (askForSignature && isConnected && address && tryAuthenticate && sessNonce && message) {\n // Initial authentication\n authenticate();\n setTryAuthenticate(false);\n }\n }, [isConnected, address, authenticate, tryAuthenticate, sessNonce, message, askForSignature]);\n\n return (\n <GlyphContext.Provider\n value={{\n ready: !loading && !!sessNonce,\n authenticated: isConnected && !!address && token !== null,\n glyphUrl: glyphUrl as string, // Pass as string to avoid type error (we are passing fallback value in useGlyph hook at a common place)\n hideWidget: !isConnected || !address,\n login: authenticate,\n logout: disconnect, // on disconnect, logoutSideEffect is called and clears states\n signMessage,\n signTypedData,\n sendTransaction,\n apiFetch: apiFetch!\n }}\n children={children}\n />\n );\n};\n\nexport default EIP1193Strategy;\n"],"names":["TOKEN_KEY","NONCE_KEY","logger","createLogger","EIP1193Strategy","children","glyphUrl","onLogin","onLogout","askForSignature","loading","setLoading","useState","apiFetch","setApiFetch","address","isConnected","chainId","useAccount","disconnectAsync","useDisconnect","signMessageAsync","useSignMessage","signTypedDataAsync","useSignTypedData","sendTransactionAsync","useSendTransaction","token","setToken","error","message","setMessage","sessNonce","setSessNonce","useEffect","fetchMessageToSign","useCallback","WIDGET_API_BASE_URL","resp","verifySignature","signature","nonce","glyphApiFetch","createApiFetch","disconnect","authenticate","userSignature","logoutSideEffect","signMessage","signTypedData","data","types","primaryType","sendTransaction","transaction","tryAuthenticate","setTryAuthenticate","useAccountEffect","jsx","GlyphContext"],"mappings":";;;;AAkBA,MAAMA,IAAY,0BACZC,IAAY,0BACZC,IAASC,EAAa,iBAAiB,GAEvCC,KAAmE,CAAC;AAAA,EACtE,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,SAAAC;AAAA,EACA,UAAAC;AAAA,EACA,iBAAAC,IAAkB;AACtB,MAAM;AACF,QAAM,CAACC,GAASC,CAAU,IAAIC,EAAS,EAAK,GACtC,CAACC,GAAUC,CAAW,IAAIF,EAA+B,IAAI,GAC7D,EAAE,SAAAG,GAAS,aAAAC,GAAa,SAAAC,EAAA,IAAYC,EAAA,GACpC,EAAE,iBAAAC,EAAA,IAAoBC,EAAA,GACtB,EAAE,kBAAAC,EAAA,IAAqBC,EAAA,GACvB,EAAE,oBAAAC,EAAA,IAAuBC,EAAA,GACzB,EAAE,sBAAAC,EAAA,IAAyBC,EAAA;AAEjC,EAAAxB,EAAO,IAAI,EAAE,SAAAa,GAAS,aAAAC,EAAA,CAAa;AAGnC,QAAM,CAACW,GAAOC,CAAQ,IAAIhB,EAAwB,MAAM;AACpD,QAAI,OAAO,SAAW;AAClB,aAAO;AAEX,QAAI;AACA,aAAO,aAAa,QAAQZ,CAAS;AAAA,IACzC,SAAS6B,GAAO;AACZ,aAAA3B,EAAO,KAAK,+BAA+B2B,CAAK,GACzC;AAAA,IACX;AAAA,EACJ,CAAC,GAEK,CAACC,GAASC,CAAU,IAAInB,EAAwB,IAAI,GAGpD,CAACoB,GAAWC,CAAY,IAAIrB,EAAwB,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,EAAqB,EAAE,GAAG6B,GAAa,SAASA,EAAY,WAAWrC,GAAgB;AAAA,IAClG;AAAA,IACA,CAACF,GAASC,GAAaS,GAAsBR,CAAO;AAAA,EAAA,GAGlD,CAACsC,GAAiBC,CAAkB,IAAI5C,EAAkB,EAAK;AAErE,SAAA6C,EAAiB;AAAA,IACb,WAAW,MAAM;AACb,MAAIhD,KAEA+C,EAAmB,EAAI;AAAA,IAE/B;AAAA,IACA,cAAc,MAAM;AAChB,MAAAT,EAAA;AAAA,IACJ;AAAA,EAAA,CACH,GACDb,EAAU,MAAM;AACZ,IAAIzB,KAAmBO,KAAeD,KAAWwC,KAAmBvB,KAAaF,MAE7Ee,EAAA,GACAW,EAAmB,EAAK;AAAA,EAEhC,GAAG,CAACxC,GAAaD,GAAS8B,GAAcU,GAAiBvB,GAAWF,GAASrB,CAAe,CAAC,GAGzF,gBAAAiD;AAAA,IAACC,EAAa;AAAA,IAAb;AAAA,MACG,OAAO;AAAA,QACH,OAAO,CAACjD,KAAW,CAAC,CAACsB;AAAA,QACrB,eAAehB,KAAe,CAAC,CAACD,KAAWY,MAAU;AAAA,QACrD,UAAArB;AAAA;AAAA,QACA,YAAY,CAACU,KAAe,CAACD;AAAA,QAC7B,OAAO8B;AAAA,QACP,QAAQD;AAAA;AAAA,QACR,aAAAI;AAAA,QACA,eAAAC;AAAA,QACA,iBAAAI;AAAA,QACA,UAAAxC;AAAA,MAAA;AAAA,MAEJ,UAAAR;AAAA,IAAA;AAAA,EAAA;AAGZ;"}
|
|
1
|
+
{"version":3,"file":"EIP1193Strategy.js","sources":["../src/context/strategies/EIP1193Strategy.tsx"],"sourcesContent":["import { SignTypedDataParams, UnsignedTransactionRequest } from \"@privy-io/react-auth\";\nimport react, { useCallback, useEffect, useState } from \"react\";\nimport {\n useAccount,\n useAccountEffect,\n useDisconnect,\n useSendTransaction,\n useSignMessage,\n useSignTypedData,\n} from \"wagmi\";\nimport { WIDGET_API_BASE_URL } from \"../../lib/constants\";\nimport { createLogger } from \"../../lib/utils\";\nimport { BaseGlyphProviderOptionsWithSignature } from \"../../types\";\nimport { GlyphApiFetch, GlyphContext, createApiFetch } from \"../GlyphContext\";\n\ntype GlyphSigningMsgResponse = { message: string; nonce: string };\ntype GlyphSignatureVerifyResponse = { token: string };\n\nconst TOKEN_KEY = \"__glyph-widget-token__\";\nconst NONCE_KEY = \"__glyph-widget-nonce__\";\nconst logger = createLogger(\"EIP1193Strategy\");\n\nconst EIP1193Strategy: react.FC<BaseGlyphProviderOptionsWithSignature> = ({\n children,\n glyphUrl,\n onLogin,\n onLogout,\n askForSignature = true\n}) => {\n const [loading, setLoading] = useState(false);\n const [apiFetch, setApiFetch] = useState<GlyphApiFetch | null>(null);\n const { address, isConnected, chainId } = useAccount(); // detect wallet connection\n const { disconnectAsync } = useDisconnect(); // disconnect the wallet\n const { signMessageAsync } = useSignMessage(); // signing messages with the wallet\n const { signTypedDataAsync } = useSignTypedData(); // signing typed data with the wallet\n const { sendTransactionAsync } = useSendTransaction(); // sending transactions with the wallet\n\n logger.log({ address, isConnected });\n\n // Fetch authentication token from session storage\n const [token, setToken] = useState<string | null>(() => {\n if (typeof window === \"undefined\") {\n return null;\n }\n try {\n return localStorage.getItem(TOKEN_KEY);\n } catch (error) {\n logger.warn(\"Error reading session token\", error);\n return null;\n }\n });\n\n const [message, setMessage] = useState<string | null>(null);\n\n // fetch nonce from session storage\n const [sessNonce, setSessNonce] = useState<string | null>(() => {\n if (typeof window === \"undefined\") {\n return null;\n }\n try {\n return localStorage.getItem(NONCE_KEY);\n } catch (error) {\n logger.warn(\"Error reading session nonce\", error);\n return null;\n }\n });\n\n // Keep token and nonce updated in session storage\n useEffect(() => {\n try {\n if (!token || !sessNonce) {\n localStorage.removeItem(TOKEN_KEY);\n localStorage.removeItem(NONCE_KEY);\n } else {\n localStorage.setItem(TOKEN_KEY, token!);\n localStorage.setItem(NONCE_KEY, sessNonce!);\n }\n } catch (error) {\n logger.error(\"Error saving session token\", error);\n }\n }, [sessNonce, token]);\n\n const fetchMessageToSign = useCallback(\n async (address: string): Promise<GlyphSigningMsgResponse> => {\n try {\n const payload = (await fetch(\n `${glyphUrl || WIDGET_API_BASE_URL}/api/widget/auth/message/${address}`\n ).then((resp) => resp.json())) as GlyphSigningMsgResponse;\n\n return payload;\n } catch (error) {\n logger.error(\"Can't fetch message to sign\", error);\n throw new Error(\"Failed to fetch the message to sign.\");\n }\n },\n [glyphUrl]\n );\n\n const verifySignature = useCallback(\n async (address: string, signature: string, nonce: string): Promise<GlyphSignatureVerifyResponse> => {\n try {\n const payload = await fetch(`${glyphUrl || WIDGET_API_BASE_URL}/api/widget/auth/verify/${address}`, {\n method: \"POST\",\n body: JSON.stringify({ signature, nonce })\n }).then((resp) => resp.json());\n return payload as unknown as GlyphSignatureVerifyResponse;\n } catch (error) {\n logger.error(\"Can't verify signature\", error);\n throw new Error(\"Signature verification failed.\");\n }\n },\n [glyphUrl]\n );\n\n useEffect(() => {\n if (!address || !isConnected) return;\n if (sessNonce) return;\n\n setLoading(true);\n fetchMessageToSign(address)\n .then(({ message, nonce }) => {\n setMessage(message);\n setSessNonce(nonce);\n setLoading(false);\n })\n .finally(() => {\n setLoading(false);\n });\n }, [address, isConnected, fetchMessageToSign, sessNonce]);\n\n useEffect(() => {\n if (!token || !sessNonce) return;\n\n const glyphApiFetch = createApiFetch(glyphUrl || WIDGET_API_BASE_URL, async () => token, {\n \"x-evm-address\": address!,\n \"x-glyph-nonce\": sessNonce!\n });\n setApiFetch(() => glyphApiFetch);\n }, [token, address, glyphUrl, sessNonce]);\n\n const disconnect = useCallback(async () => {\n await disconnectAsync();\n }, [disconnectAsync]);\n\n const authenticate = useCallback(async () => {\n logger.log(\"authenticate\");\n if (!address) {\n logger.error(\"no wallet connected.\");\n return;\n }\n\n try {\n if (!address || !isConnected || !message || !sessNonce) {\n setApiFetch(null);\n setLoading(false);\n return;\n }\n\n // Sign a message with the wallet to authenticate\n setLoading(true);\n\n const userSignature = await signMessageAsync({ account: address, message: message });\n console.log(sessNonce, message, userSignature);\n\n const token = (await verifySignature(address, userSignature, sessNonce))?.token;\n\n setToken(token);\n } catch (error) {\n logger.error(\"Authentication failed\", error);\n if (!(error as Error)?.message?.toLowerCase?.().includes?.(\"user rejected\")) {\n await alert(\n \"Authentication failed - your browser could be blocking the popups. Allow popups or try to manually click sign in.\"\n );\n }\n setApiFetch(null);\n setToken(null);\n setSessNonce(null);\n } finally {\n setLoading(false);\n onLogin?.();\n }\n }, [address, isConnected, message, sessNonce, signMessageAsync, verifySignature]);\n\n const logoutSideEffect = useCallback(async () => {\n setSessNonce(null);\n setToken(null);\n setLoading(false);\n setApiFetch(null);\n onLogout?.();\n }, []);\n\n const signMessage = useCallback(\n async ({ message }: { message: string }) => {\n if (!address || !isConnected) {\n throw new Error(\"Wallet not connected\");\n }\n return signMessageAsync({ account: address, message });\n },\n [address, isConnected, signMessageAsync]\n );\n\n const signTypedData = useCallback(\n async ({ data }: { data: SignTypedDataParams }) => {\n if (!address || !isConnected) {\n throw new Error(\"Wallet not connected\");\n }\n const types = data.types;\n const primaryType = data.primaryType as string;\n const message = data.message;\n return signTypedDataAsync({ types, primaryType, message });\n },\n [address, isConnected, signTypedDataAsync]\n );\n\n const sendTransaction = useCallback(\n async ({ transaction }: { transaction: UnsignedTransactionRequest }) => {\n if (!address || !isConnected) throw new Error(\"Wallet not connected\");\n\n return sendTransactionAsync({ ...transaction, chainId: transaction.chainId || chainId } as any);\n },\n [address, isConnected, sendTransactionAsync, chainId]\n );\n\n const [tryAuthenticate, setTryAuthenticate] = useState<boolean>(false);\n // Perform graceful logout when the wallet is disconnected from anywhere within the app\n useAccountEffect({\n onConnect: () => {\n if (askForSignature) {\n // Perform initial authentication when the wallet is connected\n setTryAuthenticate(true);\n }\n },\n onDisconnect: () => {\n logoutSideEffect();\n }\n });\n useEffect(() => {\n if (askForSignature && isConnected && address && tryAuthenticate && sessNonce && message) {\n // Initial authentication\n authenticate();\n setTryAuthenticate(false);\n }\n }, [isConnected, address, authenticate, tryAuthenticate, sessNonce, message, askForSignature]);\n\n return (\n <GlyphContext.Provider\n value={{\n ready: !loading && !!sessNonce,\n authenticated: isConnected && !!address && token !== null,\n glyphUrl: glyphUrl as string, // Pass as string to avoid type error (we are passing fallback value in useGlyph hook at a common place)\n hideWidget: !isConnected || !address,\n login: authenticate,\n logout: disconnect, // on disconnect, logoutSideEffect is called and clears states\n signMessage,\n signTypedData,\n sendTransaction,\n apiFetch: apiFetch!\n }}\n children={children}\n />\n );\n};\n\nexport default EIP1193Strategy;\n"],"names":["TOKEN_KEY","NONCE_KEY","logger","createLogger","EIP1193Strategy","children","glyphUrl","onLogin","onLogout","askForSignature","loading","setLoading","useState","apiFetch","setApiFetch","address","isConnected","chainId","useAccount","disconnectAsync","useDisconnect","signMessageAsync","useSignMessage","signTypedDataAsync","useSignTypedData","sendTransactionAsync","useSendTransaction","token","setToken","error","message","setMessage","sessNonce","setSessNonce","useEffect","fetchMessageToSign","useCallback","WIDGET_API_BASE_URL","resp","verifySignature","signature","nonce","glyphApiFetch","createApiFetch","disconnect","authenticate","userSignature","logoutSideEffect","signMessage","signTypedData","data","types","primaryType","sendTransaction","transaction","tryAuthenticate","setTryAuthenticate","useAccountEffect","jsx","GlyphContext"],"mappings":";;;;AAkBA,MAAMA,IAAY,0BACZC,IAAY,0BACZC,IAASC,EAAa,iBAAiB,GAEvCC,KAAmE,CAAC;AAAA,EACtE,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,SAAAC;AAAA,EACA,UAAAC;AAAA,EACA,iBAAAC,IAAkB;AACtB,MAAM;AACF,QAAM,CAACC,GAASC,CAAU,IAAIC,EAAS,EAAK,GACtC,CAACC,GAAUC,CAAW,IAAIF,EAA+B,IAAI,GAC7D,EAAE,SAAAG,GAAS,aAAAC,GAAa,SAAAC,EAAA,IAAYC,EAAA,GACpC,EAAE,iBAAAC,EAAA,IAAoBC,EAAA,GACtB,EAAE,kBAAAC,EAAA,IAAqBC,EAAA,GACvB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7B,OAAO8B;AAAA,QACP,QAAQD;AAAA;AAAA,QACR,aAAAI;AAAA,QACA,eAAAC;AAAA,QACA,iBAAAI;AAAA,QACA,UAAAxC;AAAA,MAAA;AAAA,MAEJ,UAAAR;AAAA,IAAA;AAAA,EAAA;AAGZ;"}
|
package/dist/PrivyStrategy.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { usePrivy as
|
|
3
|
-
import { memo as
|
|
4
|
-
import { useChainId as
|
|
5
|
-
import { c as
|
|
6
|
-
const t =
|
|
1
|
+
import { jsx as $ } from "react/jsx-runtime";
|
|
2
|
+
import { usePrivy as q, useCrossAppAccounts as z } from "@privy-io/react-auth";
|
|
3
|
+
import { memo as J, useState as l, useEffect as K, useCallback as i } from "react";
|
|
4
|
+
import { useChainId as O } from "wagmi";
|
|
5
|
+
import { c as Q, i as X, S as W, G as x, a as Z, b as ss, W as es } from "./index.js";
|
|
6
|
+
const t = Q("PrivyStrategy"), ts = ({
|
|
7
7
|
children: L,
|
|
8
8
|
glyphUrl: p,
|
|
9
9
|
onLogin: m,
|
|
10
10
|
onLogout: v,
|
|
11
11
|
useStagingTenant: u
|
|
12
12
|
}) => {
|
|
13
|
-
const [F, y] = l(!0), [N, g] = l(null), [a, R] = l(null), [
|
|
13
|
+
const [F, y] = l(!0), [N, g] = l(null), [a, R] = l(null), [r, V] = l(!1), w = O(), {
|
|
14
14
|
ready: o,
|
|
15
15
|
authenticated: d,
|
|
16
16
|
user: c,
|
|
@@ -20,14 +20,12 @@ const t = Z("PrivyStrategy"), ns = ({
|
|
|
20
20
|
signMessage: T,
|
|
21
21
|
signTypedData: b,
|
|
22
22
|
sendTransaction: E
|
|
23
|
-
} =
|
|
23
|
+
} = q(), {
|
|
24
24
|
signMessage: G,
|
|
25
25
|
signTypedData: I,
|
|
26
26
|
sendTransaction: S
|
|
27
|
-
} =
|
|
28
|
-
t.debug(o, d, !!c)
|
|
29
|
-
const { wallets: Y } = K();
|
|
30
|
-
Q(() => {
|
|
27
|
+
} = z();
|
|
28
|
+
t.debug(o, d, !!c), K(() => {
|
|
31
29
|
if (!o) {
|
|
32
30
|
g(null), y(!0);
|
|
33
31
|
return;
|
|
@@ -37,28 +35,28 @@ const t = Z("PrivyStrategy"), ns = ({
|
|
|
37
35
|
return;
|
|
38
36
|
}
|
|
39
37
|
let s;
|
|
40
|
-
const
|
|
38
|
+
const n = c.linkedAccounts?.find(
|
|
41
39
|
(e) => e.type === "wallet" && e.chainType === "ethereum" && e.walletClientType === "privy"
|
|
42
|
-
), D =
|
|
43
|
-
D && t.debug("Privy (main) EVM embedded wallet",
|
|
44
|
-
const
|
|
45
|
-
(e) => e.providerApp?.id !== (u ?
|
|
40
|
+
), D = n && X(n.address);
|
|
41
|
+
D && t.debug("Privy (main) EVM embedded wallet", n.address), t.debug("finding cross-app accounts...");
|
|
42
|
+
const k = c.linkedAccounts?.filter?.((e) => e.type === "cross_app") || [], C = k.filter(
|
|
43
|
+
(e) => e.providerApp?.id !== (u ? W : x)
|
|
46
44
|
);
|
|
47
|
-
t.debug("linked accounts - non-Glyph", { accounts:
|
|
48
|
-
const f =
|
|
45
|
+
t.debug("linked accounts - non-Glyph", { accounts: C });
|
|
46
|
+
const f = C.map((e) => e.embeddedWallets[0].address);
|
|
49
47
|
f.length > 0 && (s = f[0], t.log("using cross_app (non-Glyph) account"), f.length > 1 && t.warn("too many cross_app accounts"));
|
|
50
|
-
const
|
|
51
|
-
(e) => e.providerApp?.id === (u ?
|
|
48
|
+
const M = k.filter(
|
|
49
|
+
(e) => e.providerApp?.id === (u ? W : x)
|
|
52
50
|
);
|
|
53
|
-
t.debug("linked accounts - Glyph", { accounts:
|
|
54
|
-
const A =
|
|
55
|
-
A.length > 0 && (s = A[0], t.log("using cross_app (Glyph) account"), A.length > 1 && t.warn("too many cross_app accounts")), s ? (V(!0), t.log("using cross_app account", s)) : D && (s =
|
|
51
|
+
t.debug("linked accounts - Glyph", { accounts: M });
|
|
52
|
+
const A = M.map((e) => e.embeddedWallets[0].address);
|
|
53
|
+
A.length > 0 && (s = A[0], t.log("using cross_app (Glyph) account"), A.length > 1 && t.warn("too many cross_app accounts")), s ? (V(!0), t.log("using cross_app account", s)) : D && (s = n.address, t.log("using Privy (main) EVM embedded wallet", s)), R(s ?? null), (async () => {
|
|
56
54
|
if (!s) {
|
|
57
55
|
t.error("user has no wallet");
|
|
58
56
|
return;
|
|
59
57
|
}
|
|
60
|
-
const e =
|
|
61
|
-
p ||
|
|
58
|
+
const e = ss(
|
|
59
|
+
p || es,
|
|
62
60
|
async () => await P(),
|
|
63
61
|
{ "x-evm-address": s }
|
|
64
62
|
);
|
|
@@ -70,56 +68,55 @@ const t = Z("PrivyStrategy"), ns = ({
|
|
|
70
68
|
o,
|
|
71
69
|
c,
|
|
72
70
|
u,
|
|
73
|
-
|
|
74
|
-
Y,
|
|
71
|
+
r,
|
|
75
72
|
a,
|
|
76
73
|
P,
|
|
77
74
|
h
|
|
78
75
|
]);
|
|
79
|
-
const
|
|
76
|
+
const Y = i(async () => {
|
|
80
77
|
await _(), m?.();
|
|
81
|
-
}, [m, _]),
|
|
78
|
+
}, [m, _]), U = i(async () => {
|
|
82
79
|
h(), v?.();
|
|
83
|
-
}, [v, h]),
|
|
80
|
+
}, [v, h]), H = i(
|
|
84
81
|
async ({ message: s }) => {
|
|
85
82
|
if (!a) throw new Error("No wallet address found");
|
|
86
|
-
return
|
|
83
|
+
return r ? G(s, { address: a }) : (await T({ message: s })).signature;
|
|
87
84
|
},
|
|
88
|
-
[a,
|
|
89
|
-
),
|
|
85
|
+
[a, r, G, T]
|
|
86
|
+
), j = i(
|
|
90
87
|
async ({ data: s }) => {
|
|
91
88
|
if (!a) throw new Error("No wallet address found");
|
|
92
|
-
return
|
|
89
|
+
return r ? I(s, { address: a }) : (await b(s)).signature;
|
|
93
90
|
},
|
|
94
|
-
[a,
|
|
95
|
-
),
|
|
91
|
+
[a, r, I, b]
|
|
92
|
+
), B = i(
|
|
96
93
|
async ({ transaction: s }) => {
|
|
97
94
|
if (!a) throw new Error("No wallet address found");
|
|
98
|
-
const
|
|
99
|
-
return
|
|
95
|
+
const n = { ...s, chainId: s.chainId || w };
|
|
96
|
+
return r ? S(n, { address: a }) : (await E(n, { address: a })).hash;
|
|
100
97
|
},
|
|
101
|
-
[w,
|
|
98
|
+
[w, r, a, S, E]
|
|
102
99
|
);
|
|
103
|
-
return /* @__PURE__ */
|
|
104
|
-
|
|
100
|
+
return /* @__PURE__ */ $(
|
|
101
|
+
Z.Provider,
|
|
105
102
|
{
|
|
106
103
|
value: {
|
|
107
104
|
ready: o && !F,
|
|
108
105
|
authenticated: o && d,
|
|
109
106
|
glyphUrl: p,
|
|
110
107
|
// Pass as string to avoid type error (we are passing fallback value in useGlyph hook at a common place)
|
|
111
|
-
login:
|
|
112
|
-
logout:
|
|
113
|
-
signMessage:
|
|
114
|
-
signTypedData:
|
|
115
|
-
sendTransaction:
|
|
108
|
+
login: Y,
|
|
109
|
+
logout: U,
|
|
110
|
+
signMessage: H,
|
|
111
|
+
signTypedData: j,
|
|
112
|
+
sendTransaction: B,
|
|
116
113
|
apiFetch: N
|
|
117
114
|
},
|
|
118
115
|
children: L
|
|
119
116
|
}
|
|
120
117
|
);
|
|
121
|
-
},
|
|
118
|
+
}, ds = J(ts);
|
|
122
119
|
export {
|
|
123
|
-
|
|
120
|
+
ds as default
|
|
124
121
|
};
|
|
125
122
|
//# sourceMappingURL=PrivyStrategy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrivyStrategy.js","sources":["../src/context/strategies/PrivyStrategy.tsx"],"sourcesContent":["import {\n SignTypedDataParams,\n UnsignedTransactionRequest,\n useCrossAppAccounts,\n usePrivy,\n useWallets,\n WalletWithMetadata\n} from \"@privy-io/react-auth\";\nimport react, { memo, useCallback, useEffect, useState } from \"react\";\nimport { useChainId } from \"wagmi\";\nimport { GLYPH_PRIVY_APP_ID, STAGING_GLYPH_PRIVY_APP_ID, WIDGET_API_BASE_URL } from \"../../lib/constants\";\nimport { createLogger, isEthereumAddress } from \"../../lib/utils\";\nimport { BaseGlyphProviderOptions } from \"../../types\";\nimport { createApiFetch, GlyphApiFetch, GlyphContext } from \"../GlyphContext\";\n\nconst logger = createLogger(\"PrivyStrategy\");\n\nconst PrivyStrategy: react.FC<BaseGlyphProviderOptions> = ({\n children,\n glyphUrl,\n onLogin,\n onLogout,\n useStagingTenant\n}) => {\n const [loading, setLoading] = useState<boolean>(true);\n const [apiFetch, setApiFetch] = useState<GlyphApiFetch | null>(null);\n const [walletAddress, setWalletAddress] = useState<string | null>(null);\n const [usesCrossapp, setUsesCrossapp] = useState<boolean>(false);\n const chainId = useChainId();\n\n const {\n ready: privyReady,\n authenticated: privyAuthenticated,\n user: privyUser,\n getAccessToken: getPrivyAccessToken,\n login: privyLogin,\n logout: privyLogout,\n signMessage: privySignMessage,\n signTypedData: privySignTypedData,\n sendTransaction: privySendTransaction\n } = usePrivy();\n\n const {\n signMessage: crossAppSignMessage,\n signTypedData: crossAppSignTypedData,\n sendTransaction: crossAppSendTransaction\n } = useCrossAppAccounts();\n\n logger.debug(privyReady, privyAuthenticated, !!privyUser);\n const { wallets } = useWallets();\n\n useEffect(() => {\n // If Privy is not ready, reset widget state (loading: true)\n if (!privyReady) {\n setApiFetch(null);\n setLoading(true);\n return;\n }\n\n // If user is not authenticated, reset widget state (loading: false)\n if (!privyAuthenticated || !privyUser) {\n setApiFetch(null);\n setLoading(false);\n return;\n }\n\n let address: string | undefined;\n\n const privyEvmWallet = privyUser!.linkedAccounts?.find(\n (w) => w.type === \"wallet\" && w.chainType === \"ethereum\" && w.walletClientType === \"privy\"\n ) as WalletWithMetadata | undefined;\n\n const hasPrivyEvmWallet = privyEvmWallet && isEthereumAddress(privyEvmWallet.address);\n if (hasPrivyEvmWallet) logger.debug(\"Privy (main) EVM embedded wallet\", privyEvmWallet.address);\n\n logger.debug(\"finding cross-app accounts...\");\n // Cross-app accounts are always EVM addresses\n const crossAppAccounts = privyUser!.linkedAccounts?.filter?.((account) => account.type === \"cross_app\") || [];\n\n const otherAccounts = crossAppAccounts.filter(\n (account) =>\n account.providerApp?.id !== (useStagingTenant ? STAGING_GLYPH_PRIVY_APP_ID : GLYPH_PRIVY_APP_ID)\n );\n logger.debug(\"linked accounts - non-Glyph\", { accounts: otherAccounts });\n const otherAddresses = otherAccounts.map((account) => account.embeddedWallets[0].address);\n if (otherAddresses.length > 0) {\n address = otherAddresses[0];\n logger.log(\"using cross_app (non-Glyph) account\");\n if (otherAddresses.length > 1) {\n logger.warn(\"too many cross_app accounts\");\n }\n }\n\n const glyphAccounts = crossAppAccounts.filter(\n (account) =>\n account.providerApp?.id === (useStagingTenant ? STAGING_GLYPH_PRIVY_APP_ID : GLYPH_PRIVY_APP_ID)\n );\n logger.debug(\"linked accounts - Glyph\", { accounts: glyphAccounts });\n const glyphAddresses = glyphAccounts.map((account) => account.embeddedWallets[0].address);\n if (glyphAddresses.length > 0) {\n address = glyphAddresses[0];\n logger.log(\"using cross_app (Glyph) account\");\n if (glyphAddresses.length > 1) {\n logger.warn(\"too many cross_app accounts\");\n }\n }\n\n if (address) {\n setUsesCrossapp(true);\n logger.log(\"using cross_app account\", address);\n } else if (hasPrivyEvmWallet) {\n address = privyEvmWallet.address;\n logger.log(\"using Privy (main) EVM embedded wallet\", address);\n }\n\n setWalletAddress(address ?? null);\n\n // Fetch user data from Glyph API\n const fetchUserData = async () => {\n // If no address is found, stop here\n if (!address) {\n logger.error(\"user has no wallet\");\n return;\n }\n\n const glyphApiFetch = createApiFetch(\n glyphUrl || WIDGET_API_BASE_URL,\n async () => (await getPrivyAccessToken())!,\n { \"x-evm-address\": address }\n );\n setApiFetch(() => glyphApiFetch);\n setLoading(false);\n };\n\n fetchUserData();\n }, [\n glyphUrl,\n privyAuthenticated,\n privyReady,\n privyUser,\n useStagingTenant,\n usesCrossapp,\n wallets,\n walletAddress,\n getPrivyAccessToken,\n privyLogout\n ]);\n\n const authenticate = useCallback(async () => {\n await privyLogin();\n onLogin?.();\n }, [onLogin, privyLogin]);\n\n const logout = useCallback(async () => {\n privyLogout();\n onLogout?.();\n }, [onLogout, privyLogout]);\n\n const signMessage = useCallback(\n async ({ message }: { message: string }) => {\n if (!walletAddress) throw new Error(\"No wallet address found\");\n\n return usesCrossapp\n ? crossAppSignMessage(message, { address: walletAddress })\n : (await privySignMessage({ message })).signature;\n },\n [walletAddress, usesCrossapp, crossAppSignMessage, privySignMessage]\n );\n\n const signTypedData = useCallback(\n async ({ data }: { data: SignTypedDataParams }) => {\n if (!walletAddress) throw new Error(\"No wallet address found\");\n return usesCrossapp\n ? crossAppSignTypedData(data, { address: walletAddress })\n : (await privySignTypedData(data)).signature;\n },\n [walletAddress, usesCrossapp, crossAppSignTypedData, privySignTypedData]\n );\n\n const sendTransaction = useCallback(\n async ({ transaction }: { transaction: UnsignedTransactionRequest }) => {\n if (!walletAddress) throw new Error(\"No wallet address found\");\n const tx = { ...transaction, chainId: transaction.chainId || chainId };\n\n return usesCrossapp\n ? crossAppSendTransaction(tx, { address: walletAddress })\n : (await privySendTransaction(tx, { address: walletAddress })).hash;\n },\n [chainId, usesCrossapp, walletAddress, crossAppSendTransaction, privySendTransaction]\n );\n\n return (\n <GlyphContext.Provider\n value={{\n ready: privyReady && !loading,\n authenticated: privyReady && privyAuthenticated,\n glyphUrl: glyphUrl as string, // Pass as string to avoid type error (we are passing fallback value in useGlyph hook at a common place)\n login: authenticate,\n logout,\n signMessage,\n signTypedData,\n sendTransaction,\n apiFetch: apiFetch!\n }}\n >\n {children}\n </GlyphContext.Provider>\n );\n};\n\nexport default memo(PrivyStrategy);\n"],"names":["logger","createLogger","PrivyStrategy","children","glyphUrl","onLogin","onLogout","useStagingTenant","loading","setLoading","useState","apiFetch","setApiFetch","walletAddress","setWalletAddress","usesCrossapp","setUsesCrossapp","chainId","useChainId","privyReady","privyAuthenticated","privyUser","getPrivyAccessToken","privyLogin","privyLogout","privySignMessage","privySignTypedData","privySendTransaction","usePrivy","crossAppSignMessage","crossAppSignTypedData","crossAppSendTransaction","useCrossAppAccounts","wallets","useWallets","useEffect","address","privyEvmWallet","w","hasPrivyEvmWallet","isEthereumAddress","crossAppAccounts","account","otherAccounts","STAGING_GLYPH_PRIVY_APP_ID","GLYPH_PRIVY_APP_ID","otherAddresses","glyphAccounts","glyphAddresses","glyphApiFetch","createApiFetch","WIDGET_API_BASE_URL","authenticate","useCallback","logout","signMessage","message","signTypedData","data","sendTransaction","transaction","tx","jsx","GlyphContext","PrivyStrategy$1","memo"],"mappings":";;;;;AAeA,MAAMA,IAASC,EAAa,eAAe,GAErCC,KAAoD,CAAC;AAAA,EACvD,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,SAAAC;AAAA,EACA,UAAAC;AAAA,EACA,kBAAAC;AACJ,MAAM;AACF,QAAM,CAACC,GAASC,CAAU,IAAIC,EAAkB,EAAI,GAC9C,CAACC,GAAUC,CAAW,IAAIF,EAA+B,IAAI,GAC7D,CAACG,GAAeC,CAAgB,IAAIJ,EAAwB,IAAI,GAChE,CAACK,GAAcC,CAAe,IAAIN,EAAkB,EAAK,GACzDO,IAAUC,EAAA,GAEV;AAAA,IACF,OAAOC;AAAA,IACP,eAAeC;AAAA,IACf,MAAMC;AAAA,IACN,gBAAgBC;AAAA,IAChB,OAAOC;AAAA,IACP,QAAQC;AAAA,IACR,aAAaC;AAAA,IACb,eAAeC;AAAA,IACf,iBAAiBC;AAAA,EAAA,IACjBC,EAAA,GAEE;AAAA,IACF,aAAaC;AAAA,IACb,eAAeC;AAAA,IACf,iBAAiBC;AAAA,EAAA,IACjBC,EAAA;AAEJ,EAAAhC,EAAO,MAAMmB,GAAYC,GAAoB,CAAC,CAACC,CAAS;AACxD,QAAM,EAAE,SAAAY,EAAA,IAAYC,EAAA;AAEpB,EAAAC,EAAU,MAAM;AAEZ,QAAI,CAAChB,GAAY;AACb,MAAAP,EAAY,IAAI,GAChBH,EAAW,EAAI;AACf;AAA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D,aAAOE,IACDe,EAAsB4B,GAAM,EAAE,SAAS7C,EAAA,CAAe,KACrD,MAAMa,EAAmBgC,CAAI,GAAG;AAAA,IAC3C;AAAA,IACA,CAAC7C,GAAeE,GAAce,GAAuBJ,CAAkB;AAAA,EAAA,GAGrEiC,IAAkBN;AAAA,IACpB,OAAO,EAAE,aAAAO,EAAA,MAA+D;AACpE,UAAI,CAAC/C,EAAe,OAAM,IAAI,MAAM,yBAAyB;AAC7D,YAAMgD,IAAK,EAAE,GAAGD,GAAa,SAASA,EAAY,WAAW3C,EAAA;AAE7D,aAAOF,IACDgB,EAAwB8B,GAAI,EAAE,SAAShD,EAAA,CAAe,KACrD,MAAMc,EAAqBkC,GAAI,EAAE,SAAShD,EAAA,CAAe,GAAG;AAAA,IACvE;AAAA,IACA,CAACI,GAASF,GAAcF,GAAekB,GAAyBJ,CAAoB;AAAA,EAAA;AAGxF,SACI,gBAAAmC;AAAA,IAACC,GAAa;AAAA,IAAb;AAAA,MACG,OAAO;AAAA,QACH,OAAO5C,KAAc,CAACX;AAAA,QACtB,eAAeW,KAAcC;AAAA,QAC7B,UAAAhB;AAAA;AAAA,QACA,OAAOgD;AAAA,QACP,QAAAE;AAAA,QACA,aAAAC;AAAA,QACA,eAAAE;AAAA,QACA,iBAAAE;AAAA,QACA,UAAAhD;AAAA,MAAA;AAAA,MAGH,UAAAR;AAAA,IAAA;AAAA,EAAA;AAGb,GAEA6D,KAAeC,EAAK/D,EAAa;"}
|
|
1
|
+
{"version":3,"file":"PrivyStrategy.js","sources":["../src/context/strategies/PrivyStrategy.tsx"],"sourcesContent":["import {\n SignTypedDataParams,\n UnsignedTransactionRequest,\n useCrossAppAccounts,\n usePrivy,\n WalletWithMetadata\n} from \"@privy-io/react-auth\";\nimport react, { memo, useCallback, useEffect, useState } from \"react\";\nimport { useChainId, useConfig } from \"wagmi\";\nimport { GLYPH_PRIVY_APP_ID, STAGING_GLYPH_PRIVY_APP_ID, WIDGET_API_BASE_URL } from \"../../lib/constants\";\nimport { createLogger, isEthereumAddress } from \"../../lib/utils\";\nimport { BaseGlyphProviderOptions } from \"../../types\";\nimport { createApiFetch, GlyphApiFetch, GlyphContext } from \"../GlyphContext\";\n\nconst logger = createLogger(\"PrivyStrategy\");\n\nconst PrivyStrategy: react.FC<BaseGlyphProviderOptions> = ({\n children,\n glyphUrl,\n onLogin,\n onLogout,\n useStagingTenant\n}) => {\n const [loading, setLoading] = useState<boolean>(true);\n const [apiFetch, setApiFetch] = useState<GlyphApiFetch | null>(null);\n const [walletAddress, setWalletAddress] = useState<string | null>(null);\n const [usesCrossapp, setUsesCrossapp] = useState<boolean>(false);\n const chainId = useChainId();\n\n const {\n ready: privyReady,\n authenticated: privyAuthenticated,\n user: privyUser,\n getAccessToken: getPrivyAccessToken,\n login: privyLogin,\n logout: privyLogout,\n signMessage: privySignMessage,\n signTypedData: privySignTypedData,\n sendTransaction: privySendTransaction,\n } = usePrivy();\n\n const {\n signMessage: crossAppSignMessage,\n signTypedData: crossAppSignTypedData,\n sendTransaction: crossAppSendTransaction\n } = useCrossAppAccounts();\n\n logger.debug(privyReady, privyAuthenticated, !!privyUser);\n\n useEffect(() => {\n // If Privy is not ready, reset widget state (loading: true)\n if (!privyReady) {\n setApiFetch(null);\n setLoading(true);\n return;\n }\n\n // If user is not authenticated, reset widget state (loading: false)\n if (!privyAuthenticated || !privyUser) {\n setApiFetch(null);\n setLoading(false);\n return;\n }\n\n let address: string | undefined;\n\n const privyEvmWallet = privyUser!.linkedAccounts?.find(\n (w) => w.type === \"wallet\" && w.chainType === \"ethereum\" && w.walletClientType === \"privy\"\n ) as WalletWithMetadata | undefined;\n\n const hasPrivyEvmWallet = privyEvmWallet && isEthereumAddress(privyEvmWallet.address);\n if (hasPrivyEvmWallet) logger.debug(\"Privy (main) EVM embedded wallet\", privyEvmWallet.address);\n\n logger.debug(\"finding cross-app accounts...\");\n // Cross-app accounts are always EVM addresses\n const crossAppAccounts = privyUser!.linkedAccounts?.filter?.((account) => account.type === \"cross_app\") || [];\n\n const otherAccounts = crossAppAccounts.filter(\n (account) =>\n account.providerApp?.id !== (useStagingTenant ? STAGING_GLYPH_PRIVY_APP_ID : GLYPH_PRIVY_APP_ID)\n );\n logger.debug(\"linked accounts - non-Glyph\", { accounts: otherAccounts });\n const otherAddresses = otherAccounts.map((account) => account.embeddedWallets[0].address);\n if (otherAddresses.length > 0) {\n address = otherAddresses[0];\n logger.log(\"using cross_app (non-Glyph) account\");\n if (otherAddresses.length > 1) {\n logger.warn(\"too many cross_app accounts\");\n }\n }\n\n const glyphAccounts = crossAppAccounts.filter(\n (account) =>\n account.providerApp?.id === (useStagingTenant ? STAGING_GLYPH_PRIVY_APP_ID : GLYPH_PRIVY_APP_ID)\n );\n logger.debug(\"linked accounts - Glyph\", { accounts: glyphAccounts });\n const glyphAddresses = glyphAccounts.map((account) => account.embeddedWallets[0].address);\n if (glyphAddresses.length > 0) {\n address = glyphAddresses[0];\n logger.log(\"using cross_app (Glyph) account\");\n if (glyphAddresses.length > 1) {\n logger.warn(\"too many cross_app accounts\");\n }\n }\n\n if (address) {\n setUsesCrossapp(true);\n logger.log(\"using cross_app account\", address);\n } else if (hasPrivyEvmWallet) {\n address = privyEvmWallet.address;\n logger.log(\"using Privy (main) EVM embedded wallet\", address);\n }\n\n setWalletAddress(address ?? null);\n\n // Fetch user data from Glyph API\n const fetchUserData = async () => {\n // If no address is found, stop here\n if (!address) {\n logger.error(\"user has no wallet\");\n return;\n }\n\n const glyphApiFetch = createApiFetch(\n glyphUrl || WIDGET_API_BASE_URL,\n async () => (await getPrivyAccessToken())!,\n { \"x-evm-address\": address }\n );\n setApiFetch(() => glyphApiFetch);\n setLoading(false);\n };\n\n fetchUserData();\n }, [\n glyphUrl,\n privyAuthenticated,\n privyReady,\n privyUser,\n useStagingTenant,\n usesCrossapp,\n walletAddress,\n getPrivyAccessToken,\n privyLogout\n ]);\n\n const authenticate = useCallback(async () => {\n await privyLogin();\n onLogin?.();\n }, [onLogin, privyLogin]);\n\n const logout = useCallback(async () => {\n privyLogout();\n onLogout?.();\n }, [onLogout, privyLogout]);\n\n const signMessage = useCallback(\n async ({ message }: { message: string }) => {\n if (!walletAddress) throw new Error(\"No wallet address found\");\n\n return usesCrossapp\n ? crossAppSignMessage(message, { address: walletAddress })\n : (await privySignMessage({ message })).signature;\n },\n [walletAddress, usesCrossapp, crossAppSignMessage, privySignMessage]\n );\n\n const signTypedData = useCallback(\n async ({ data }: { data: SignTypedDataParams }) => {\n if (!walletAddress) throw new Error(\"No wallet address found\");\n return usesCrossapp\n ? crossAppSignTypedData(data, { address: walletAddress })\n : (await privySignTypedData(data)).signature;\n },\n [walletAddress, usesCrossapp, crossAppSignTypedData, privySignTypedData]\n );\n\n const sendTransaction = useCallback(\n async ({ transaction }: { transaction: UnsignedTransactionRequest }) => {\n if (!walletAddress) throw new Error(\"No wallet address found\");\n const tx = { ...transaction, chainId: transaction.chainId || chainId };\n\n return usesCrossapp\n ? crossAppSendTransaction(tx, { address: walletAddress })\n : (await privySendTransaction(tx, { address: walletAddress })).hash;\n },\n [chainId, usesCrossapp, walletAddress, crossAppSendTransaction, privySendTransaction]\n );\n\n\n return (\n <GlyphContext.Provider\n value={{\n ready: privyReady && !loading,\n authenticated: privyReady && privyAuthenticated,\n glyphUrl: glyphUrl as string, // Pass as string to avoid type error (we are passing fallback value in useGlyph hook at a common place)\n login: authenticate,\n logout,\n signMessage,\n signTypedData,\n sendTransaction,\n apiFetch: apiFetch!\n }}\n >\n {children}\n </GlyphContext.Provider>\n );\n};\n\nexport default memo(PrivyStrategy);\n"],"names":["logger","createLogger","PrivyStrategy","children","glyphUrl","onLogin","onLogout","useStagingTenant","loading","setLoading","useState","apiFetch","setApiFetch","walletAddress","setWalletAddress","usesCrossapp","setUsesCrossapp","chainId","useChainId","privyReady","privyAuthenticated","privyUser","getPrivyAccessToken","privyLogin","privyLogout","privySignMessage","privySignTypedData","privySendTransaction","usePrivy","crossAppSignMessage","crossAppSignTypedData","crossAppSendTransaction","useCrossAppAccounts","useEffect","address","privyEvmWallet","w","hasPrivyEvmWallet","isEthereumAddress","crossAppAccounts","account","otherAccounts","STAGING_GLYPH_PRIVY_APP_ID","GLYPH_PRIVY_APP_ID","otherAddresses","glyphAccounts","glyphAddresses","glyphApiFetch","createApiFetch","WIDGET_API_BASE_URL","authenticate","useCallback","logout","signMessage","message","signTypedData","data","sendTransaction","transaction","tx","jsx","GlyphContext","PrivyStrategy$1","memo"],"mappings":";;;;;AAcA,MAAMA,IAASC,EAAa,eAAe,GAErCC,KAAoD,CAAC;AAAA,EACvD,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,SAAAC;AAAA,EACA,UAAAC;AAAA,EACA,kBAAAC;AACJ,MAAM;AACF,QAAM,CAACC,GAASC,CAAU,IAAIC,EAAkB,EAAI,GAC9C,CAACC,GAAUC,CAAW,IAAIF,EAA+B,IAAI,GAC7D,CAACG,GAAeC,CAAgB,IAAIJ,EAAwB,IAAI,GAChE,CAACK,GAAcC,CAAe,IAAIN,EAAkB,EAAK,GACzDO,IAAUC,EAAA,GAEV;AAAA,IACF,OAAOC;AAAA,IACP,eAAeC;AAAA,IACf,MAAMC;AAAA,IACN,gBAAgBC;AAAA,IAChB,OAAOC;AAAA,IACP,QAAQC;AAAA,IACR,aAAaC;AAAA,IACb,eAAeC;AAAA,IACf,iBAAiBC;AAAA,EAAA,IACjBC,EAAA,GAEE;AAAA,IACF,aAAaC;AAAA,IACb,eAAeC;AAAA,IACf,iBAAiBC;AAAA,EAAA,IACjBC,EAAA;AAEJ,EAAAhC,EAAO,MAAMmB,GAAYC,GAAoB,CAAC,CAACC,CAAS,GAExDY,EAAU,MAAM;AAEZ,QAAI,CAACd,GAAY;AACb,MAAAP,EAAY,IAAI,GAChBH,EAAW,EAAI;AACf;AAAA,IACJ;AAGA,QAAI,CAACW,KAAsB,CAACC,GAAW;AACnC,MAAAT,EAAY,IAAI,GAChBH,EAAW,EAAK;AAChB;AAAA,IACJ;AAEA,QAAI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