@liberfi.io/wallet-connector 0.1.1

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.
@@ -0,0 +1,131 @@
1
+ import { ChainNamespace, Chain } from '@liberfi.io/types';
2
+ import { DependencyList, PropsWithChildren } from 'react';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+
5
+ /**
6
+ * Wallet adapter interface
7
+ *
8
+ * Wallet adapter is used to adapt different wallet providers to the same interface.
9
+ */
10
+ interface WalletAdapter {
11
+ get chainNamespace(): ChainNamespace;
12
+ get chain(): Chain | undefined;
13
+ get address(): string;
14
+ get isConnected(): boolean;
15
+ get isCustodial(): boolean;
16
+ get connector(): string;
17
+ /**
18
+ * sign a message
19
+ * @param message
20
+ * @returns signature, string for evm wallets, base64 for solana wallets
21
+ */
22
+ signMessage(message: string): Promise<string>;
23
+ /**
24
+ * sign transaction
25
+ * @param serializedTx serialized transaction, hex for evm wallets, base64 for solana wallets
26
+ * @returns signed transaction
27
+ */
28
+ signTransaction(serializedTx: Uint8Array): Promise<Uint8Array>;
29
+ /**
30
+ * send transaction
31
+ * @param serializedTx serialized transaction, hex for evm wallets, base64 for solana wallets
32
+ * @returns transaction hash if successful, otherwise throws an error
33
+ */
34
+ sendTransaction(serializedTx: Uint8Array): Promise<string>;
35
+ }
36
+
37
+ interface AuthenticatedUser {
38
+ /** user id */
39
+ id: string;
40
+ /** wallets that the user has connected */
41
+ wallets: Array<WalletAdapter>;
42
+ /** user access token */
43
+ accessToken: string;
44
+ /** user profiles */
45
+ [key: string]: any;
46
+ }
47
+
48
+ /**
49
+ * The interface to an [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) provider,
50
+ * which is a standard used by most injected providers
51
+ */
52
+ interface Eip1193Provider {
53
+ request(request: {
54
+ method: string;
55
+ params?: Array<any> | Record<string, any>;
56
+ }): Promise<any>;
57
+ }
58
+ /**
59
+ * Evm wallet adapter interface
60
+ */
61
+ interface EvmWalletAdapter extends WalletAdapter {
62
+ /**
63
+ * export a standard EIP-1193 provider object.
64
+ */
65
+ getEip1193Provider(): Promise<Eip1193Provider | undefined>;
66
+ /**
67
+ * switch wallet's chain, unconnected wallets may throw an error
68
+ * @param chain chain to switch to
69
+ */
70
+ switchChain(chain: Chain): Promise<void>;
71
+ }
72
+
73
+ interface AuthContextValue {
74
+ /** authenticated user profile */
75
+ user: AuthenticatedUser | null;
76
+ /** authentication status */
77
+ status: "unauthenticated" | "authenticating" | "authenticated";
78
+ /** sign in to the IdP */
79
+ signIn: () => void | Promise<void>;
80
+ /** sign out from the IdP */
81
+ signOut: () => void | Promise<void>;
82
+ /** refresh the access token */
83
+ refreshAccessToken: () => void | Promise<void>;
84
+ }
85
+
86
+ declare function useAuth(): AuthContextValue;
87
+
88
+ declare function useAuthCallback<T extends (...args: any[]) => any>(callback: T, deps?: DependencyList): T;
89
+
90
+ interface WalletConnectorContextValue {
91
+ /**
92
+ * detecting: is detecting connected wallets
93
+ * connecting: is connecting to the first wallet
94
+ * connected: is connected to at least one wallet
95
+ * disconnecting: is disconnecting from the last connected wallet
96
+ * disconnected: is disconnected from all wallets
97
+ */
98
+ status: "detecting" | "connecting" | "connected" | "disconnecting" | "disconnected";
99
+ wallets: Array<WalletAdapter>;
100
+ connect: () => Promise<void>;
101
+ disconnect: () => Promise<void>;
102
+ }
103
+
104
+ /**
105
+ * use wallet connector hook
106
+ * @returns wallet connector
107
+ */
108
+ declare function useWalletConnector(): WalletConnectorContextValue;
109
+
110
+ /**
111
+ * use wallets hook
112
+ * @returns all wallets that can be used to take onchain actions
113
+ */
114
+ declare function useWallets(): WalletAdapter[];
115
+
116
+ type AuthProviderProps = PropsWithChildren<AuthContextValue>;
117
+ declare function AuthProvider({ children, ...value }: AuthProviderProps): react_jsx_runtime.JSX.Element;
118
+
119
+ type WalletConnectorProviderProps = PropsWithChildren<WalletConnectorContextValue>;
120
+ declare function WalletConnectorProvider({ children, ...value }: WalletConnectorProviderProps): react_jsx_runtime.JSX.Element;
121
+
122
+ declare global {
123
+ interface Window {
124
+ __LIBERFI_VERSION__?: {
125
+ [key: string]: string;
126
+ };
127
+ }
128
+ }
129
+ declare const _default: "0.1.0";
130
+
131
+ export { AuthProvider, type AuthProviderProps, type AuthenticatedUser, type Eip1193Provider, type EvmWalletAdapter, type WalletAdapter, WalletConnectorProvider, type WalletConnectorProviderProps, useAuth, useAuthCallback, useWalletConnector, useWallets, _default as version };
@@ -0,0 +1,131 @@
1
+ import { ChainNamespace, Chain } from '@liberfi.io/types';
2
+ import { DependencyList, PropsWithChildren } from 'react';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+
5
+ /**
6
+ * Wallet adapter interface
7
+ *
8
+ * Wallet adapter is used to adapt different wallet providers to the same interface.
9
+ */
10
+ interface WalletAdapter {
11
+ get chainNamespace(): ChainNamespace;
12
+ get chain(): Chain | undefined;
13
+ get address(): string;
14
+ get isConnected(): boolean;
15
+ get isCustodial(): boolean;
16
+ get connector(): string;
17
+ /**
18
+ * sign a message
19
+ * @param message
20
+ * @returns signature, string for evm wallets, base64 for solana wallets
21
+ */
22
+ signMessage(message: string): Promise<string>;
23
+ /**
24
+ * sign transaction
25
+ * @param serializedTx serialized transaction, hex for evm wallets, base64 for solana wallets
26
+ * @returns signed transaction
27
+ */
28
+ signTransaction(serializedTx: Uint8Array): Promise<Uint8Array>;
29
+ /**
30
+ * send transaction
31
+ * @param serializedTx serialized transaction, hex for evm wallets, base64 for solana wallets
32
+ * @returns transaction hash if successful, otherwise throws an error
33
+ */
34
+ sendTransaction(serializedTx: Uint8Array): Promise<string>;
35
+ }
36
+
37
+ interface AuthenticatedUser {
38
+ /** user id */
39
+ id: string;
40
+ /** wallets that the user has connected */
41
+ wallets: Array<WalletAdapter>;
42
+ /** user access token */
43
+ accessToken: string;
44
+ /** user profiles */
45
+ [key: string]: any;
46
+ }
47
+
48
+ /**
49
+ * The interface to an [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193) provider,
50
+ * which is a standard used by most injected providers
51
+ */
52
+ interface Eip1193Provider {
53
+ request(request: {
54
+ method: string;
55
+ params?: Array<any> | Record<string, any>;
56
+ }): Promise<any>;
57
+ }
58
+ /**
59
+ * Evm wallet adapter interface
60
+ */
61
+ interface EvmWalletAdapter extends WalletAdapter {
62
+ /**
63
+ * export a standard EIP-1193 provider object.
64
+ */
65
+ getEip1193Provider(): Promise<Eip1193Provider | undefined>;
66
+ /**
67
+ * switch wallet's chain, unconnected wallets may throw an error
68
+ * @param chain chain to switch to
69
+ */
70
+ switchChain(chain: Chain): Promise<void>;
71
+ }
72
+
73
+ interface AuthContextValue {
74
+ /** authenticated user profile */
75
+ user: AuthenticatedUser | null;
76
+ /** authentication status */
77
+ status: "unauthenticated" | "authenticating" | "authenticated";
78
+ /** sign in to the IdP */
79
+ signIn: () => void | Promise<void>;
80
+ /** sign out from the IdP */
81
+ signOut: () => void | Promise<void>;
82
+ /** refresh the access token */
83
+ refreshAccessToken: () => void | Promise<void>;
84
+ }
85
+
86
+ declare function useAuth(): AuthContextValue;
87
+
88
+ declare function useAuthCallback<T extends (...args: any[]) => any>(callback: T, deps?: DependencyList): T;
89
+
90
+ interface WalletConnectorContextValue {
91
+ /**
92
+ * detecting: is detecting connected wallets
93
+ * connecting: is connecting to the first wallet
94
+ * connected: is connected to at least one wallet
95
+ * disconnecting: is disconnecting from the last connected wallet
96
+ * disconnected: is disconnected from all wallets
97
+ */
98
+ status: "detecting" | "connecting" | "connected" | "disconnecting" | "disconnected";
99
+ wallets: Array<WalletAdapter>;
100
+ connect: () => Promise<void>;
101
+ disconnect: () => Promise<void>;
102
+ }
103
+
104
+ /**
105
+ * use wallet connector hook
106
+ * @returns wallet connector
107
+ */
108
+ declare function useWalletConnector(): WalletConnectorContextValue;
109
+
110
+ /**
111
+ * use wallets hook
112
+ * @returns all wallets that can be used to take onchain actions
113
+ */
114
+ declare function useWallets(): WalletAdapter[];
115
+
116
+ type AuthProviderProps = PropsWithChildren<AuthContextValue>;
117
+ declare function AuthProvider({ children, ...value }: AuthProviderProps): react_jsx_runtime.JSX.Element;
118
+
119
+ type WalletConnectorProviderProps = PropsWithChildren<WalletConnectorContextValue>;
120
+ declare function WalletConnectorProvider({ children, ...value }: WalletConnectorProviderProps): react_jsx_runtime.JSX.Element;
121
+
122
+ declare global {
123
+ interface Window {
124
+ __LIBERFI_VERSION__?: {
125
+ [key: string]: string;
126
+ };
127
+ }
128
+ }
129
+ declare const _default: "0.1.0";
130
+
131
+ export { AuthProvider, type AuthProviderProps, type AuthenticatedUser, type Eip1193Provider, type EvmWalletAdapter, type WalletAdapter, WalletConnectorProvider, type WalletConnectorProviderProps, useAuth, useAuthCallback, useWalletConnector, useWallets, _default as version };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ 'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');var o=react.createContext({});function s(){let t=react.useContext(o);if(!t)throw new Error("useAuth must be used within a AuthProvider");return t}function R(t,e){let{status:n,signIn:i}=s(),u=react.useRef(n);return u.current=n,react.useCallback(async(...l)=>{if(u.current!=="authenticated"){i();return}return t(...l)},[...e||[],i,t])}var r=react.createContext({});function a(){let t=react.useContext(r);if(!t)throw new Error("useWalletConnector must be used within a WalletConnectorProvider");return t}function N(){let{wallets:t}=a();return t}function J({children:t,...e}){return jsxRuntime.jsx(o.Provider,{value:e,children:t})}function Y({children:t,...e}){return jsxRuntime.jsx(r.Provider,{value:e,children:t})}typeof window<"u"&&(window.__LIBERFI_VERSION__=window.__LIBERFI_VERSION__||{},window.__LIBERFI_VERSION__["@liberfi.io/wallet-connector"]="0.1.0");var P="0.1.0";exports.AuthProvider=J;exports.WalletConnectorProvider=Y;exports.useAuth=s;exports.useAuthCallback=R;exports.useWalletConnector=a;exports.useWallets=N;exports.version=P;//# sourceMappingURL=index.js.map
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/providers/AuthContext.ts","../src/hooks/useAuth.ts","../src/hooks/useAuthCallback.ts","../src/providers/WalletConnectorContext.ts","../src/hooks/useWalletConnector.ts","../src/hooks/useWallets.ts","../src/providers/AuthProvider.tsx","../src/providers/WalletConnectorProvider.tsx","../src/version.ts"],"names":["AuthContext","createContext","useAuth","context","useContext","useAuthCallback","callback","deps","status","signIn","statusRef","useRef","useCallback","args","WalletConnectorContext","useWalletConnector","useWallets","wallets","AuthProvider","children","value","jsx","WalletConnectorProvider","version_default"],"mappings":"gFAgBO,IAAMA,CAAAA,CAAcC,mBAAAA,CACzB,EACF,CAAA,CCfO,SAASC,CAAAA,EAAU,CACxB,IAAMC,CAAAA,CAAUC,gBAAAA,CAAWJ,CAAW,CAAA,CACtC,GAAI,CAACG,EACH,MAAM,IAAI,MAAM,4CAA4C,CAAA,CAE9D,OAAOA,CACT,CCLO,SAASE,CAAAA,CACdC,CAAAA,CACAC,EACG,CACH,GAAM,CAAE,MAAA,CAAAC,CAAAA,CAAQ,MAAA,CAAAC,CAAO,CAAA,CAAIP,CAAAA,GAIrBQ,CAAAA,CAAYC,YAAAA,CAAeH,CAAM,CAAA,CACvC,OAAAE,EAAU,OAAA,CAAUF,CAAAA,CAETI,kBACT,MAAA,GAAUC,CAAAA,GAA4D,CACpE,GAAIH,CAAAA,CAAU,UAAY,eAAA,CAAiB,CACzCD,CAAAA,EAAO,CACP,MACF,CACA,OAAOH,CAAAA,CAAS,GAAGO,CAAI,CACzB,CAAA,CACA,CAAC,GAAIN,CAAAA,EAAQ,EAAC,CAAIE,CAAAA,CAAQH,CAAQ,CACpC,CAGF,CCFO,IAAMQ,EACXb,mBAAAA,CAA2C,EAAiC,CAAA,CCnBvE,SAASc,GAAqB,CACnC,IAAMZ,EAAUC,gBAAAA,CAAWU,CAAsB,EACjD,GAAI,CAACX,EACH,MAAM,IAAI,MACR,kEACF,CAAA,CAEF,OAAOA,CACT,CCTO,SAASa,GAAa,CAC3B,GAAM,CAAE,OAAA,CAAAC,CAAQ,EAAIF,CAAAA,EAAmB,CACvC,OAAOE,CACT,CCJO,SAASC,CAAAA,CAAa,CAAE,SAAAC,CAAAA,CAAU,GAAGC,CAAM,CAAA,CAAsB,CACtE,OAAOC,eAACrB,CAAAA,CAAY,QAAA,CAAZ,CAAqB,KAAA,CAAOoB,CAAAA,CAAQ,SAAAD,CAAAA,CAAS,CACvD,CCEO,SAASG,CAAAA,CAAwB,CACtC,QAAA,CAAAH,CAAAA,CACA,GAAGC,CACL,CAAA,CAAiC,CAC/B,OACEC,cAAAA,CAACP,CAAAA,CAAuB,SAAvB,CAAgC,KAAA,CAAOM,EACrC,QAAA,CAAAD,CAAAA,CACH,CAEJ,CCXI,OAAO,OAAW,GAAA,GACpB,MAAA,CAAO,oBAAsB,MAAA,CAAO,mBAAA,EAAuB,EAAC,CAC5D,MAAA,CAAO,oBAAoB,8BAA8B,CAAA,CAAI,OAAA,CAAA,CAG/D,IAAOI,CAAAA,CAAQ","file":"index.js","sourcesContent":["import { createContext } from \"react\";\nimport { AuthenticatedUser } from \"../types\";\n\nexport interface AuthContextValue {\n /** authenticated user profile */\n user: AuthenticatedUser | null;\n /** authentication status */\n status: \"unauthenticated\" | \"authenticating\" | \"authenticated\";\n /** sign in to the IdP */\n signIn: () => void | Promise<void>;\n /** sign out from the IdP */\n signOut: () => void | Promise<void>;\n /** refresh the access token */\n refreshAccessToken: () => void | Promise<void>;\n}\n\nexport const AuthContext = createContext<AuthContextValue>(\n {} as AuthContextValue,\n);\n","import { useContext } from \"react\";\nimport { AuthContext } from \"../providers/AuthContext\";\n\nexport function useAuth() {\n const context = useContext(AuthContext);\n if (!context) {\n throw new Error(\"useAuth must be used within a AuthProvider\");\n }\n return context;\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { DependencyList, useCallback, useRef } from \"react\";\nimport { useAuth } from \"./useAuth\";\n\nexport function useAuthCallback<T extends (...args: any[]) => any>(\n callback: T,\n deps?: DependencyList,\n): T {\n const { status, signIn } = useAuth();\n\n // statusRef will be updated to the latest on each render\n // avoid callback rebuild on status changes\n const statusRef = useRef<string>(status);\n statusRef.current = status;\n\n const cb = useCallback(\n async (...args: Parameters<T>): Promise<ReturnType<T> | undefined> => {\n if (statusRef.current !== \"authenticated\") {\n signIn();\n return;\n }\n return callback(...args);\n },\n [...(deps || []), signIn, callback],\n );\n\n return cb as T;\n}\n","import { createContext } from \"react\";\nimport { WalletAdapter } from \"../types\";\n\nexport interface WalletConnectorContextValue {\n /**\n * detecting: is detecting connected wallets\n * connecting: is connecting to the first wallet\n * connected: is connected to at least one wallet\n * disconnecting: is disconnecting from the last connected wallet\n * disconnected: is disconnected from all wallets\n */\n status:\n | \"detecting\"\n | \"connecting\"\n | \"connected\"\n | \"disconnecting\"\n | \"disconnected\";\n // all wallets that can be used to take onchain actions when connected\n wallets: Array<WalletAdapter>;\n // if no wallets are connected, connect one or multiple wallets\n connect: () => Promise<void>;\n // disconnect all wallets\n disconnect: () => Promise<void>;\n}\n\nexport const WalletConnectorContext =\n createContext<WalletConnectorContextValue>({} as WalletConnectorContextValue);\n","import { useContext } from \"react\";\nimport { WalletConnectorContext } from \"../providers/WalletConnectorContext\";\n\n/**\n * use wallet connector hook\n * @returns wallet connector\n */\nexport function useWalletConnector() {\n const context = useContext(WalletConnectorContext);\n if (!context) {\n throw new Error(\n \"useWalletConnector must be used within a WalletConnectorProvider\",\n );\n }\n return context;\n}\n","import { useWalletConnector } from \"./useWalletConnector\";\n\n/**\n * use wallets hook\n * @returns all wallets that can be used to take onchain actions\n */\nexport function useWallets() {\n const { wallets } = useWalletConnector();\n return wallets;\n}\n","import { PropsWithChildren } from \"react\";\nimport { AuthContext, AuthContextValue } from \"./AuthContext\";\n\nexport type AuthProviderProps = PropsWithChildren<AuthContextValue>;\n\nexport function AuthProvider({ children, ...value }: AuthProviderProps) {\n return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;\n}\n","import { PropsWithChildren } from \"react\";\nimport {\n WalletConnectorContext,\n WalletConnectorContextValue,\n} from \"./WalletConnectorContext\";\n\nexport type WalletConnectorProviderProps =\n PropsWithChildren<WalletConnectorContextValue>;\n\nexport function WalletConnectorProvider({\n children,\n ...value\n}: WalletConnectorProviderProps) {\n return (\n <WalletConnectorContext.Provider value={value}>\n {children}\n </WalletConnectorContext.Provider>\n );\n}\n","declare global {\n interface Window {\n __LIBERFI_VERSION__?: {\n [key: string]: string;\n };\n }\n}\nif (typeof window !== \"undefined\") {\n window.__LIBERFI_VERSION__ = window.__LIBERFI_VERSION__ || {};\n window.__LIBERFI_VERSION__[\"@liberfi.io/wallet-connector\"] = \"0.1.0\";\n}\n\nexport default \"0.1.0\";\n"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import {createContext,useContext,useRef,useCallback}from'react';import {jsx}from'react/jsx-runtime';var o=createContext({});function s(){let t=useContext(o);if(!t)throw new Error("useAuth must be used within a AuthProvider");return t}function R(t,e){let{status:n,signIn:i}=s(),u=useRef(n);return u.current=n,useCallback(async(...l)=>{if(u.current!=="authenticated"){i();return}return t(...l)},[...e||[],i,t])}var r=createContext({});function a(){let t=useContext(r);if(!t)throw new Error("useWalletConnector must be used within a WalletConnectorProvider");return t}function N(){let{wallets:t}=a();return t}function J({children:t,...e}){return jsx(o.Provider,{value:e,children:t})}function Y({children:t,...e}){return jsx(r.Provider,{value:e,children:t})}typeof window<"u"&&(window.__LIBERFI_VERSION__=window.__LIBERFI_VERSION__||{},window.__LIBERFI_VERSION__["@liberfi.io/wallet-connector"]="0.1.0");var P="0.1.0";export{J as AuthProvider,Y as WalletConnectorProvider,s as useAuth,R as useAuthCallback,a as useWalletConnector,N as useWallets,P as version};//# sourceMappingURL=index.mjs.map
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/providers/AuthContext.ts","../src/hooks/useAuth.ts","../src/hooks/useAuthCallback.ts","../src/providers/WalletConnectorContext.ts","../src/hooks/useWalletConnector.ts","../src/hooks/useWallets.ts","../src/providers/AuthProvider.tsx","../src/providers/WalletConnectorProvider.tsx","../src/version.ts"],"names":["AuthContext","createContext","useAuth","context","useContext","useAuthCallback","callback","deps","status","signIn","statusRef","useRef","useCallback","args","WalletConnectorContext","useWalletConnector","useWallets","wallets","AuthProvider","children","value","jsx","WalletConnectorProvider","version_default"],"mappings":"oGAgBO,IAAMA,CAAAA,CAAcC,aAAAA,CACzB,EACF,CAAA,CCfO,SAASC,CAAAA,EAAU,CACxB,IAAMC,CAAAA,CAAUC,UAAAA,CAAWJ,CAAW,CAAA,CACtC,GAAI,CAACG,EACH,MAAM,IAAI,MAAM,4CAA4C,CAAA,CAE9D,OAAOA,CACT,CCLO,SAASE,CAAAA,CACdC,CAAAA,CACAC,EACG,CACH,GAAM,CAAE,MAAA,CAAAC,CAAAA,CAAQ,MAAA,CAAAC,CAAO,CAAA,CAAIP,CAAAA,GAIrBQ,CAAAA,CAAYC,MAAAA,CAAeH,CAAM,CAAA,CACvC,OAAAE,EAAU,OAAA,CAAUF,CAAAA,CAETI,YACT,MAAA,GAAUC,CAAAA,GAA4D,CACpE,GAAIH,CAAAA,CAAU,UAAY,eAAA,CAAiB,CACzCD,CAAAA,EAAO,CACP,MACF,CACA,OAAOH,CAAAA,CAAS,GAAGO,CAAI,CACzB,CAAA,CACA,CAAC,GAAIN,CAAAA,EAAQ,EAAC,CAAIE,CAAAA,CAAQH,CAAQ,CACpC,CAGF,CCFO,IAAMQ,EACXb,aAAAA,CAA2C,EAAiC,CAAA,CCnBvE,SAASc,GAAqB,CACnC,IAAMZ,EAAUC,UAAAA,CAAWU,CAAsB,EACjD,GAAI,CAACX,EACH,MAAM,IAAI,MACR,kEACF,CAAA,CAEF,OAAOA,CACT,CCTO,SAASa,GAAa,CAC3B,GAAM,CAAE,OAAA,CAAAC,CAAQ,EAAIF,CAAAA,EAAmB,CACvC,OAAOE,CACT,CCJO,SAASC,CAAAA,CAAa,CAAE,SAAAC,CAAAA,CAAU,GAAGC,CAAM,CAAA,CAAsB,CACtE,OAAOC,IAACrB,CAAAA,CAAY,QAAA,CAAZ,CAAqB,KAAA,CAAOoB,CAAAA,CAAQ,SAAAD,CAAAA,CAAS,CACvD,CCEO,SAASG,CAAAA,CAAwB,CACtC,QAAA,CAAAH,CAAAA,CACA,GAAGC,CACL,CAAA,CAAiC,CAC/B,OACEC,GAAAA,CAACP,CAAAA,CAAuB,SAAvB,CAAgC,KAAA,CAAOM,EACrC,QAAA,CAAAD,CAAAA,CACH,CAEJ,CCXI,OAAO,OAAW,GAAA,GACpB,MAAA,CAAO,oBAAsB,MAAA,CAAO,mBAAA,EAAuB,EAAC,CAC5D,MAAA,CAAO,oBAAoB,8BAA8B,CAAA,CAAI,OAAA,CAAA,CAG/D,IAAOI,CAAAA,CAAQ","file":"index.mjs","sourcesContent":["import { createContext } from \"react\";\nimport { AuthenticatedUser } from \"../types\";\n\nexport interface AuthContextValue {\n /** authenticated user profile */\n user: AuthenticatedUser | null;\n /** authentication status */\n status: \"unauthenticated\" | \"authenticating\" | \"authenticated\";\n /** sign in to the IdP */\n signIn: () => void | Promise<void>;\n /** sign out from the IdP */\n signOut: () => void | Promise<void>;\n /** refresh the access token */\n refreshAccessToken: () => void | Promise<void>;\n}\n\nexport const AuthContext = createContext<AuthContextValue>(\n {} as AuthContextValue,\n);\n","import { useContext } from \"react\";\nimport { AuthContext } from \"../providers/AuthContext\";\n\nexport function useAuth() {\n const context = useContext(AuthContext);\n if (!context) {\n throw new Error(\"useAuth must be used within a AuthProvider\");\n }\n return context;\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { DependencyList, useCallback, useRef } from \"react\";\nimport { useAuth } from \"./useAuth\";\n\nexport function useAuthCallback<T extends (...args: any[]) => any>(\n callback: T,\n deps?: DependencyList,\n): T {\n const { status, signIn } = useAuth();\n\n // statusRef will be updated to the latest on each render\n // avoid callback rebuild on status changes\n const statusRef = useRef<string>(status);\n statusRef.current = status;\n\n const cb = useCallback(\n async (...args: Parameters<T>): Promise<ReturnType<T> | undefined> => {\n if (statusRef.current !== \"authenticated\") {\n signIn();\n return;\n }\n return callback(...args);\n },\n [...(deps || []), signIn, callback],\n );\n\n return cb as T;\n}\n","import { createContext } from \"react\";\nimport { WalletAdapter } from \"../types\";\n\nexport interface WalletConnectorContextValue {\n /**\n * detecting: is detecting connected wallets\n * connecting: is connecting to the first wallet\n * connected: is connected to at least one wallet\n * disconnecting: is disconnecting from the last connected wallet\n * disconnected: is disconnected from all wallets\n */\n status:\n | \"detecting\"\n | \"connecting\"\n | \"connected\"\n | \"disconnecting\"\n | \"disconnected\";\n // all wallets that can be used to take onchain actions when connected\n wallets: Array<WalletAdapter>;\n // if no wallets are connected, connect one or multiple wallets\n connect: () => Promise<void>;\n // disconnect all wallets\n disconnect: () => Promise<void>;\n}\n\nexport const WalletConnectorContext =\n createContext<WalletConnectorContextValue>({} as WalletConnectorContextValue);\n","import { useContext } from \"react\";\nimport { WalletConnectorContext } from \"../providers/WalletConnectorContext\";\n\n/**\n * use wallet connector hook\n * @returns wallet connector\n */\nexport function useWalletConnector() {\n const context = useContext(WalletConnectorContext);\n if (!context) {\n throw new Error(\n \"useWalletConnector must be used within a WalletConnectorProvider\",\n );\n }\n return context;\n}\n","import { useWalletConnector } from \"./useWalletConnector\";\n\n/**\n * use wallets hook\n * @returns all wallets that can be used to take onchain actions\n */\nexport function useWallets() {\n const { wallets } = useWalletConnector();\n return wallets;\n}\n","import { PropsWithChildren } from \"react\";\nimport { AuthContext, AuthContextValue } from \"./AuthContext\";\n\nexport type AuthProviderProps = PropsWithChildren<AuthContextValue>;\n\nexport function AuthProvider({ children, ...value }: AuthProviderProps) {\n return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;\n}\n","import { PropsWithChildren } from \"react\";\nimport {\n WalletConnectorContext,\n WalletConnectorContextValue,\n} from \"./WalletConnectorContext\";\n\nexport type WalletConnectorProviderProps =\n PropsWithChildren<WalletConnectorContextValue>;\n\nexport function WalletConnectorProvider({\n children,\n ...value\n}: WalletConnectorProviderProps) {\n return (\n <WalletConnectorContext.Provider value={value}>\n {children}\n </WalletConnectorContext.Provider>\n );\n}\n","declare global {\n interface Window {\n __LIBERFI_VERSION__?: {\n [key: string]: string;\n };\n }\n}\nif (typeof window !== \"undefined\") {\n window.__LIBERFI_VERSION__ = window.__LIBERFI_VERSION__ || {};\n window.__LIBERFI_VERSION__[\"@liberfi.io/wallet-connector\"] = \"0.1.0\";\n}\n\nexport default \"0.1.0\";\n"]}
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "@liberfi.io/wallet-connector",
3
+ "version": "0.1.1",
4
+ "description": "Base Wallet Connector for Liberfi React SDK",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "keywords": [],
9
+ "author": "liberfi.io",
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "dependencies": {
17
+ "react": "^19.1.1",
18
+ "react-dom": "^19.1.1",
19
+ "@liberfi.io/types": "0.1.8"
20
+ },
21
+ "devDependencies": {
22
+ "@types/react": "^19.1.13",
23
+ "@types/react-dom": "^19.1.9",
24
+ "rimraf": "^5.0.5",
25
+ "tsup": "^8.5.0",
26
+ "typescript": "^5.9.2",
27
+ "tsconfig": "0.1.4"
28
+ },
29
+ "peerDependencies": {
30
+ "react": ">=18",
31
+ "react-dom": ">=18"
32
+ },
33
+ "scripts": {
34
+ "build": "rimraf -rf dist && tsup",
35
+ "test": "echo \"Error: no test specified\" && exit 1"
36
+ }
37
+ }