@moon-x/react-sdk 0.1.0

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/index.css ADDED
@@ -0,0 +1,169 @@
1
+ /* src/styles.css */
2
+ @font-face {
3
+ font-family: "Sons";
4
+ src: url("./assets/Sons-Thin.ttf") format("truetype");
5
+ font-weight: 100;
6
+ font-style: normal;
7
+ font-display: swap;
8
+ }
9
+ @font-face {
10
+ font-family: "Sons";
11
+ src: url("./assets/Sons-Light.ttf") format("truetype");
12
+ font-weight: 300;
13
+ font-style: normal;
14
+ font-display: swap;
15
+ }
16
+ @font-face {
17
+ font-family: "Sons";
18
+ src: url("./assets/Sons-Regular.ttf") format("truetype");
19
+ font-weight: 400;
20
+ font-style: normal;
21
+ font-display: swap;
22
+ }
23
+ @font-face {
24
+ font-family: "Sons";
25
+ src: url("./assets/Sons-Medium.ttf") format("truetype");
26
+ font-weight: 500;
27
+ font-style: normal;
28
+ font-display: swap;
29
+ }
30
+ @font-face {
31
+ font-family: "Sons";
32
+ src: url("./assets/Sons-Semibold.ttf") format("truetype");
33
+ font-weight: 600;
34
+ font-style: normal;
35
+ font-display: swap;
36
+ }
37
+ @font-face {
38
+ font-family: "Sons";
39
+ src: url("./assets/Sons-Bold.ttf") format("truetype");
40
+ font-weight: 700;
41
+ font-style: normal;
42
+ font-display: swap;
43
+ }
44
+ @font-face {
45
+ font-family: "Sons";
46
+ src: url("./assets/Sons-Extrabold.ttf") format("truetype");
47
+ font-weight: 800;
48
+ font-style: normal;
49
+ font-display: swap;
50
+ }
51
+ @font-face {
52
+ font-family: "Sons";
53
+ src: url("./assets/Sons-Black.ttf") format("truetype");
54
+ font-weight: 900;
55
+ font-style: normal;
56
+ font-display: swap;
57
+ }
58
+ :root {
59
+ --moonkey-font-family:
60
+ "Sons",
61
+ -apple-system,
62
+ BlinkMacSystemFont,
63
+ "Segoe UI",
64
+ "Roboto",
65
+ "Oxygen",
66
+ "Ubuntu",
67
+ "Cantarell",
68
+ "Fira Sans",
69
+ "Droid Sans",
70
+ "Helvetica Neue",
71
+ sans-serif;
72
+ --moonkey-border-radius-sm: 0.375rem;
73
+ --moonkey-border-radius-md: 0.5rem;
74
+ --moonkey-border-radius-lg: 0.75rem;
75
+ --moonkey-border-radius-full: 9999px;
76
+ --moonkey-color-background: #ffffff;
77
+ --moonkey-color-background-2: #f9fafb;
78
+ --moonkey-color-background-3: #f3f4f6;
79
+ --moonkey-color-foreground: #111827;
80
+ --moonkey-color-foreground-2: #374151;
81
+ --moonkey-color-foreground-3: #6b7280;
82
+ --moonkey-color-foreground-4: #9ca3af;
83
+ --moonkey-color-foreground-accent: #4f46e5;
84
+ --moonkey-color-accent: #6366f1;
85
+ --moonkey-color-accent-foreground: #ffffff;
86
+ --moonkey-color-accent-light: #818cf8;
87
+ --moonkey-color-accent-lightest: #c7d2fe;
88
+ --moonkey-color-accent-dark: #4338ca;
89
+ --moonkey-color-accent-darkest: #3730a3;
90
+ --moonkey-color-success: #10b981;
91
+ --moonkey-color-success-foreground: #ffffff;
92
+ --moonkey-color-error: #ef4444;
93
+ --moonkey-color-error-foreground: #ffffff;
94
+ --moonkey-color-error-light: #fca5a5;
95
+ --moonkey-color-border: #e5e7eb;
96
+ }
97
+ .moonkey-animate-in {
98
+ animation: moonkey-enter 0.2s ease-out;
99
+ }
100
+ .moonkey-fade-in-0 {
101
+ --tw-enter-opacity: initial;
102
+ --tw-enter-scale: initial;
103
+ --tw-enter-rotate: initial;
104
+ --tw-enter-translate-x: initial;
105
+ --tw-enter-translate-y: initial;
106
+ }
107
+ .moonkey-zoom-in-95 {
108
+ --tw-enter-scale: .95;
109
+ }
110
+ .moonkey-duration-200 {
111
+ animation-duration: 0.2s;
112
+ }
113
+ .moonkey-center-y {
114
+ top: 50%;
115
+ transform: translateY(-50%);
116
+ }
117
+ .moonkey-animate-spin {
118
+ animation: moonkey-spin 1s linear infinite;
119
+ }
120
+ .moonkey-modal-overlay {
121
+ position: fixed;
122
+ top: 0;
123
+ left: 0;
124
+ right: 0;
125
+ bottom: 0;
126
+ width: 100vw;
127
+ height: 100vh;
128
+ background-color: var(--moonkey-color-background-3);
129
+ backdrop-filter: blur(4px);
130
+ z-index: 50;
131
+ }
132
+ .moonkey-modal-container {
133
+ position: fixed;
134
+ top: 0;
135
+ left: 0;
136
+ right: 0;
137
+ bottom: 0;
138
+ width: 100vw;
139
+ height: 100vh;
140
+ display: flex;
141
+ align-items: center;
142
+ justify-content: center;
143
+ padding: 1rem;
144
+ z-index: 51;
145
+ }
146
+ .moonkey-input::placeholder {
147
+ opacity: 0.3;
148
+ }
149
+ .moonkey-scrollbar-none {
150
+ scrollbar-width: none;
151
+ -ms-overflow-style: none;
152
+ }
153
+ .moonkey-scrollbar-none::-webkit-scrollbar {
154
+ display: none;
155
+ }
156
+ @keyframes moonkey-enter {
157
+ from {
158
+ opacity: 0;
159
+ transform: translate3d(var(--tw-enter-translate-x, 0), var(--tw-enter-translate-y, 0), 0) scale3d(var(--tw-enter-scale, 1), var(--tw-enter-scale, 1), var(--tw-enter-scale, 1)) rotate(var(--tw-enter-rotate, 0));
160
+ }
161
+ }
162
+ @keyframes moonkey-spin {
163
+ from {
164
+ transform: rotate(0deg);
165
+ }
166
+ to {
167
+ transform: rotate(360deg);
168
+ }
169
+ }
@@ -0,0 +1,298 @@
1
+ export { LoginWithEmailState, PasskeyStatusEntry, RegisterPasskeyResult, UseAddPasskeyResult, UseLoginWithEmailCallbacks, UsePasskeyStatusResult, UseRemovePasskeyResult, useAddPasskey, useLoginWithEmail, usePasskeyStatus, useRegisterPasskey, useRemovePasskey, useUser } from '@moon-x/core/react';
2
+ import { WalletListEntry, AuthAppearance, PrefillConfig, WalletChainType, MoonKeyThemeConfig, PasskeyEnrollConfig, SignMessageConfig, ExportKeyConfig, SignTransactionConfig, SendTransactionConfig, Chain, LogoutResponse, EmailOtpFlowState, Wallet } from '@moon-x/core/types';
3
+ export { Chain, Factor, IdpProvider, Network, PublicEthereumWallet, PublicWallet, WalletConnectConfig, WalletListEntry } from '@moon-x/core/types';
4
+ import React$1, { ReactNode } from 'react';
5
+ export { e as ethereum } from './ethereum-DobH9IQl.mjs';
6
+ export { s as solana } from './solana-CzXRbze_.mjs';
7
+ export { estimateEvmGas, estimateEvmGasReserve, getChainById, getDefaultChain, getEvmGasPrice, getEvmMaxPriorityFeePerGas, getEvmNonce, getRpcUrl, isChainSupported, setChainRpcUrl, validateChainConfig } from '@moon-x/core/lib';
8
+ export { arbitrum, arbitrumSepolia, avalanche, avalancheFuji, base, baseSepolia, bsc, bscTestnet, goerli, holesky, mainnet, optimism, optimismSepolia, polygon, polygonAmoy, sepolia } from 'viem/chains';
9
+ import './base-wallet-CzJLpndu.mjs';
10
+ import '@moon-x/core';
11
+
12
+ type OAuthProvider$1 = "google" | "apple";
13
+ interface OAuthAttachResult {
14
+ created_at: number;
15
+ expires_at: number;
16
+ last_active_at: number;
17
+ publishable_key: string;
18
+ access_token: string;
19
+ refresh_token: string;
20
+ user_id: string;
21
+ }
22
+ interface AttachOAuthState {
23
+ status: "initial" | "loading" | "done" | "error";
24
+ error: Error | null;
25
+ result: OAuthAttachResult | null;
26
+ }
27
+ interface UseAttachOAuthCallbacks {
28
+ onSuccess?: (result: OAuthAttachResult) => void;
29
+ onError?: (error: Error) => void;
30
+ }
31
+ interface UseAttachOAuth {
32
+ state: AttachOAuthState;
33
+ ready: boolean;
34
+ attachOAuth: (options: {
35
+ provider: OAuthProvider$1;
36
+ }) => Promise<void>;
37
+ }
38
+ declare function useAttachOAuth(options?: UseAttachOAuthCallbacks): UseAttachOAuth;
39
+
40
+ interface BaseConnectedEthereumWallet {
41
+ public_address: string;
42
+ wallet_type: "ethereum";
43
+ chain_id?: string;
44
+ connector?: any;
45
+ }
46
+ interface BaseConnectedSolanaWallet {
47
+ public_address: string;
48
+ wallet_type: "solana";
49
+ chain_id?: string;
50
+ }
51
+ interface ConnectWalletParams {
52
+ description?: string;
53
+ walletList?: WalletListEntry[];
54
+ walletChainType?: "ethereum" | "solana" | "ethereum-and-solana";
55
+ mode?: "signIn" | "link";
56
+ }
57
+
58
+ interface ConnectWalletCallbacks {
59
+ onSuccess?: (params: {
60
+ wallet: BaseConnectedEthereumWallet | BaseConnectedSolanaWallet;
61
+ }) => void;
62
+ onError?: (error: Error) => void;
63
+ onClose?: () => void;
64
+ }
65
+ interface UseConnectWallet {
66
+ connectWallet: (params?: ConnectWalletParams) => Promise<void>;
67
+ isConnecting: boolean;
68
+ }
69
+ declare function useConnectWallet(callbacks?: ConnectWalletCallbacks): UseConnectWallet;
70
+
71
+ interface DetachOAuthResult {
72
+ success: boolean;
73
+ message?: string;
74
+ }
75
+ interface DetachOAuthState {
76
+ status: "initial" | "loading" | "done" | "error";
77
+ error: Error | null;
78
+ result: DetachOAuthResult | null;
79
+ }
80
+ interface UseDetachOAuthCallbacks {
81
+ onSuccess?: (result: DetachOAuthResult) => void;
82
+ onError?: (error: Error) => void;
83
+ }
84
+ interface UseDetachOAuth {
85
+ state: DetachOAuthState;
86
+ loading: boolean;
87
+ detachOAuth: (idpUserId: string) => Promise<void>;
88
+ }
89
+ declare function useDetachOAuth(options?: UseDetachOAuthCallbacks): UseDetachOAuth;
90
+
91
+ type OAuthProvider = "google" | "apple";
92
+ interface OAuthUser {
93
+ created_at: number;
94
+ expires_at: number;
95
+ last_active_at: number;
96
+ publishable_key: string;
97
+ access_token: string;
98
+ refresh_token: string;
99
+ user_id: string;
100
+ }
101
+ interface OAuthState {
102
+ status: "initial" | "loading" | "done" | "error";
103
+ error: Error | null;
104
+ user: OAuthUser | null;
105
+ }
106
+ interface UseLoginWithOAuthCallbacks {
107
+ onSuccess?: (result: OAuthUser) => void;
108
+ onError?: (error: Error) => void;
109
+ }
110
+ interface UseLoginWithOAuth {
111
+ state: OAuthState;
112
+ ready: boolean;
113
+ initOAuth: (options: {
114
+ provider: OAuthProvider;
115
+ }) => Promise<void>;
116
+ }
117
+ declare function useLoginWithOAuth(options?: UseLoginWithOAuthCallbacks): UseLoginWithOAuth;
118
+
119
+ interface MoonKeyConfig {
120
+ appearance?: AuthAppearance;
121
+ loginMethods?: ("email" | "google" | "apple" | "wallet")[];
122
+ /**
123
+ * Security-policy knobs. Safe defaults (the entire `security` object
124
+ * can be omitted for the strictest posture).
125
+ */
126
+ security?: {
127
+ /**
128
+ * TTL in milliseconds for the parent-side passkey assertion cache.
129
+ *
130
+ * Default: 0 (no cache — every sensitive op forces a fresh
131
+ * biometric prompt). This is the safe-by-default posture; the raw
132
+ * userHandle (the AES-GCM KEK that unwraps the user's DEK) never
133
+ * lingers in the parent JS heap past the moment of use.
134
+ *
135
+ * Set to a positive number (e.g. 5 * 60 * 1000) only if the
136
+ * integrating app has a UX that genuinely benefits from skipping
137
+ * the OS passkey prompt on routine ops within a window. The
138
+ * trade-off: during the warm window, parent-coresident JS that
139
+ * can reach the SDK can drive wallet ops without re-prompting.
140
+ *
141
+ * Sensitive operations (export, addPasskey, removePasskey, and
142
+ * any call passing `requireFreshAssertion: true`) bypass the
143
+ * cache regardless of this setting.
144
+ */
145
+ assertionCacheTtlMs?: number;
146
+ };
147
+ prefill?: PrefillConfig;
148
+ walletChainType?: WalletChainType;
149
+ isDark?: boolean;
150
+ theme?: MoonKeyThemeConfig;
151
+ emailConfig?: {
152
+ skipVerifiedSuccess?: boolean;
153
+ expiresIn?: number;
154
+ verifiedDisplayTime?: number;
155
+ verifyEmailTitle?: string;
156
+ verifyEmailResendTitle?: string;
157
+ resendCodeTime?: number;
158
+ verifiedNewUserMessage?: string;
159
+ verifiedExistingUserMessage?: string;
160
+ verifiedSuccessMessage?: string;
161
+ };
162
+ passkeyEnrollConfig?: PasskeyEnrollConfig;
163
+ signMessageConfig?: SignMessageConfig;
164
+ exportKeyConfig?: ExportKeyConfig;
165
+ signTransactionConfig?: SignTransactionConfig;
166
+ sendTransactionConfig?: SendTransactionConfig;
167
+ walletConnect?: {
168
+ projectId: string;
169
+ };
170
+ defaultChain?: Chain;
171
+ supportedChains?: Chain[];
172
+ solana?: {
173
+ rpcs: {
174
+ [key: string]: {
175
+ rpc: string;
176
+ rpcSubscriptions?: string;
177
+ };
178
+ };
179
+ };
180
+ }
181
+ interface MoonKeyProviderProps$1 {
182
+ publishableKey: string;
183
+ config?: MoonKeyConfig;
184
+ children: React.ReactNode;
185
+ onClose?: () => void;
186
+ }
187
+ interface MoonKeyInstance {
188
+ ready: boolean;
189
+ isAuthenticated: boolean;
190
+ user: any | null;
191
+ getCurrentSession: () => Promise<any>;
192
+ getUser: () => Promise<any>;
193
+ logout: () => Promise<LogoutResponse>;
194
+ flowState: EmailOtpFlowState;
195
+ /**
196
+ * Get the current user's three-token bundle from IndexedDB. The access
197
+ * token is short-lived (~1h, ES256-signed, JWKS-verifiable by your
198
+ * backend). The identity token carries linked-account metadata. The
199
+ * refresh token is opaque and rotates on every use.
200
+ * @returns Promise with the bundle, or null if not authenticated
201
+ * @example
202
+ * const tokens = await getSessionTokens();
203
+ * if (tokens) {
204
+ * fetch('/api/protected', {
205
+ * headers: { 'X-MoonX-Access-Token': tokens.accessToken }
206
+ * });
207
+ * }
208
+ */
209
+ getSessionTokens: () => Promise<{
210
+ accessToken: string;
211
+ identityToken: string;
212
+ refreshToken: string;
213
+ expiresAt: number;
214
+ } | null>;
215
+ /**
216
+ * Start authentication flow (UI-based)
217
+ * @param params - Optional configuration to override provider-level config
218
+ * @param params.loginMethods - Login methods to show in UI
219
+ * @param params.prefill - Pre-fill email/phone in UI
220
+ * @param params.disableSignup - Disable signup for new users
221
+ * @param params.walletChainType - Which wallet type to create on login
222
+ */
223
+ start: (params?: {
224
+ loginMethods?: ("email" | "google" | "apple" | "wallet")[];
225
+ prefill?: {
226
+ type: "email" | "phone";
227
+ value: string;
228
+ };
229
+ disableSignup?: boolean;
230
+ walletChainType?: "ethereum" | "solana" | "ethereum-or-solana";
231
+ }) => Promise<any>;
232
+ onError: (callback: (error: Error) => void) => void;
233
+ onClose: (callback: () => void) => void;
234
+ /**
235
+ * Dynamically update the appearance configuration
236
+ * @param appearance - Appearance configuration including displayMode, backgroundColor, and accentColor
237
+ * @example
238
+ * const { setAppearance } = useMoonKey();
239
+ * const colorScheme = useColorScheme(); // React Native
240
+ * setAppearance({ displayMode: colorScheme === 'dark' ? 'dark' : 'light' });
241
+ */
242
+ setAppearance: (appearance: AuthAppearance) => void;
243
+ publishableKey: string;
244
+ sendCode: (params: {
245
+ email: string;
246
+ disableSignup?: boolean;
247
+ }) => Promise<void>;
248
+ loginWithCode: (params: {
249
+ code: string;
250
+ }) => Promise<void>;
251
+ }
252
+ interface WalletInstance {
253
+ wallets: () => Promise<Wallet[]>;
254
+ signMessage: (message: string) => Promise<any>;
255
+ getAddress: () => Promise<string>;
256
+ getBalance: () => Promise<string>;
257
+ }
258
+ interface WalletConfig {
259
+ network: "mainnet" | "testnet" | "devnet";
260
+ rpcUrl?: string;
261
+ }
262
+ type WalletType = "solana" | "ethereum";
263
+
264
+ declare const useMoonKey: () => MoonKeyInstance;
265
+
266
+ interface UseOAuthCompletionOptions {
267
+ onSuccess?: (data: any) => void;
268
+ onError?: (error: Error) => void;
269
+ }
270
+ declare function useOAuthCompletion(options?: UseOAuthCompletionOptions): void;
271
+
272
+ interface MoonKeyProviderProps {
273
+ publishableKey: string;
274
+ embeddableId?: string;
275
+ config?: MoonKeyConfig;
276
+ children: ReactNode;
277
+ }
278
+ declare const MoonKeyProvider: React$1.FC<MoonKeyProviderProps>;
279
+
280
+ declare class SessionExpiredError extends Error {
281
+ walletType: string;
282
+ walletAddress?: string;
283
+ requiresReconnection: boolean;
284
+ constructor(walletType: string, walletAddress?: string, message?: string);
285
+ }
286
+ declare class SessionNotFoundError extends Error {
287
+ walletType: string;
288
+ walletAddress?: string;
289
+ requiresReconnection: boolean;
290
+ constructor(walletType: string, walletAddress?: string, message?: string);
291
+ }
292
+ declare const requiresReconnection: (error: any) => boolean;
293
+ declare const getReconnectionInfo: (error: any) => {
294
+ walletType?: string;
295
+ walletAddress?: string;
296
+ } | null;
297
+
298
+ export { type AttachOAuthState, type BaseConnectedEthereumWallet, type BaseConnectedSolanaWallet, type ConnectWalletCallbacks, type ConnectWalletParams, type DetachOAuthResult, type DetachOAuthState, type MoonKeyConfig, type MoonKeyInstance, MoonKeyProvider, type MoonKeyProviderProps$1 as MoonKeyProviderProps, type OAuthAttachResult, type OAuthProvider, type OAuthState, type OAuthUser, SessionExpiredError, SessionNotFoundError, type UseAttachOAuth, type UseAttachOAuthCallbacks, type UseConnectWallet, type UseDetachOAuth, type UseDetachOAuthCallbacks, type UseLoginWithOAuth, type UseLoginWithOAuthCallbacks, type WalletConfig, type WalletInstance, type WalletType, getReconnectionInfo, requiresReconnection, useAttachOAuth, useConnectWallet, useDetachOAuth, useLoginWithOAuth, useMoonKey, useOAuthCompletion };