@openfort/react-native 0.0.3 → 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.
- package/README.md +0 -85
- package/dist/components/AuthBoundary.js +83 -0
- package/dist/components/index.js +10 -0
- package/dist/constants/config.js +9 -0
- package/dist/constants/index.js +1 -0
- package/dist/core/client.js +78 -0
- package/dist/core/context.js +37 -0
- package/dist/core/index.js +10 -0
- package/dist/core/provider.js +224 -0
- package/dist/core/storage.js +141 -0
- package/dist/hooks/auth/index.js +14 -0
- package/dist/hooks/auth/useAuthCallback.js +1 -0
- package/dist/hooks/auth/useCreateWalletPostAuth.js +22 -0
- package/dist/hooks/auth/useEmailAuth.js +176 -0
- package/dist/hooks/auth/useGuestAuth.js +52 -0
- package/dist/hooks/auth/useOAuth.js +292 -0
- package/dist/hooks/auth/useSignOut.js +48 -0
- package/dist/hooks/auth/useWalletAuth.js +133 -0
- package/dist/hooks/core/index.js +9 -0
- package/dist/hooks/core/useOpenfort.js +50 -0
- package/dist/hooks/core/useOpenfortClient.js +29 -0
- package/dist/hooks/core/useUser.js +10 -0
- package/dist/hooks/index.js +15 -0
- package/dist/hooks/wallet/index.js +7 -0
- package/dist/hooks/wallet/useWallets.js +389 -0
- package/dist/index.js +24 -1
- package/dist/lib/hookConsistency.js +16 -0
- package/dist/native/index.js +6 -0
- package/dist/native/oauth.js +183 -0
- package/dist/native/storage.js +178 -0
- package/dist/native/webview.js +157 -0
- package/dist/types/auth.js +1 -0
- package/dist/types/baseFlowState.js +8 -0
- package/dist/types/components/AuthBoundary.d.ts +85 -0
- package/dist/types/components/index.d.ts +10 -0
- package/dist/types/config.js +1 -0
- package/dist/types/constants/config.d.ts +9 -0
- package/dist/types/constants/index.d.ts +1 -0
- package/dist/types/core/client.d.ts +24 -0
- package/dist/types/core/context.d.ts +61 -0
- package/dist/types/core/index.d.ts +8 -0
- package/dist/types/core/provider.d.ts +126 -0
- package/dist/types/core/storage.d.ts +34 -0
- package/dist/types/hex.js +1 -0
- package/dist/types/hookOption.js +1 -0
- package/dist/types/hooks/auth/index.d.ts +10 -0
- package/dist/types/hooks/auth/useAuthCallback.d.ts +0 -0
- package/dist/types/hooks/auth/useCreateWalletPostAuth.d.ts +6 -0
- package/dist/types/hooks/auth/useEmailAuth.d.ts +59 -0
- package/dist/types/hooks/auth/useGuestAuth.d.ts +39 -0
- package/dist/types/hooks/auth/useOAuth.d.ts +62 -0
- package/dist/types/hooks/auth/useSignOut.d.ts +9 -0
- package/dist/types/hooks/auth/useWalletAuth.d.ts +48 -0
- package/dist/types/hooks/core/index.d.ts +8 -0
- package/dist/types/hooks/core/useOpenfort.d.ts +38 -0
- package/dist/types/hooks/core/useOpenfortClient.d.ts +29 -0
- package/dist/types/hooks/core/useUser.d.ts +5 -0
- package/dist/types/hooks/index.d.ts +12 -0
- package/dist/types/hooks/wallet/index.d.ts +6 -0
- package/dist/types/hooks/wallet/useWallets.d.ts +74 -0
- package/dist/types/index.d.ts +18 -1
- package/dist/types/index.js +2 -0
- package/dist/types/lib/hookConsistency.d.ts +14 -0
- package/dist/types/native/index.d.ts +5 -0
- package/dist/types/native/oauth.d.ts +91 -0
- package/dist/types/native/storage.d.ts +50 -0
- package/dist/types/native/webview.d.ts +50 -0
- package/dist/types/oauth.js +8 -0
- package/dist/types/openfortError.js +27 -0
- package/dist/types/predicates.js +101 -0
- package/dist/types/state.js +1 -0
- package/dist/types/types/auth.d.ts +168 -0
- package/dist/types/types/baseFlowState.d.ts +14 -0
- package/dist/types/types/config.d.ts +71 -0
- package/dist/types/types/hex.d.ts +1 -0
- package/dist/types/types/hookOption.d.ts +9 -0
- package/dist/types/types/index.d.ts +38 -0
- package/dist/types/types/oauth.d.ts +74 -0
- package/dist/types/types/openfortError.d.ts +13 -0
- package/dist/types/types/predicates.d.ts +64 -0
- package/dist/types/types/state.d.ts +0 -0
- package/dist/types/types/wallet.d.ts +262 -0
- package/dist/types/wallet.js +1 -0
- package/package.json +33 -19
- package/dist/Iframe.js +0 -84
- package/dist/types/Iframe.d.ts +0 -6
- package/polyfills/index.ts +0 -89
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Openfort React Native SDK
|
|
3
|
+
*
|
|
4
|
+
* A comprehensive React Native SDK for integrating with the Openfort platform.
|
|
5
|
+
* This SDK provides authentication, embedded wallets, session management, and UI components
|
|
6
|
+
* for building decentralized applications on React Native.
|
|
7
|
+
*
|
|
8
|
+
* @author Openfort
|
|
9
|
+
* @version 0.1.0
|
|
10
|
+
*/
|
|
11
|
+
export type { AuthPlayerResponse, OpenfortError, ShieldAuthentication, ShieldAuthType, Openfort as OpenfortClient, Provider, OpenfortConfiguration, ShieldConfiguration, EmbeddedState, } from '@openfort/openfort-js';
|
|
12
|
+
export { OAuthProvider, } from '@openfort/openfort-js';
|
|
13
|
+
export * from './types';
|
|
14
|
+
export * from './hooks';
|
|
15
|
+
export * from './components';
|
|
16
|
+
export * from './core';
|
|
17
|
+
export * from './native';
|
|
18
|
+
export * from './constants';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
// Predicate functions (exported directly, not as types)
|
|
2
|
+
export { isConnected, isReconnecting, isConnecting, isDisconnected, isNotCreated, isCreating, hasError, needsRecovery, isLoading, isReady, needsUserAction, isStable, canTransact, getStateDescription, getActionText, } from './predicates';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OpenfortHookOptions } from "../types/hookOption";
|
|
2
|
+
import { OpenfortError } from "../types/openfortError";
|
|
3
|
+
export declare const onSuccess: <T>({ hookOptions, options, data, }: {
|
|
4
|
+
hookOptions?: OpenfortHookOptions<T>;
|
|
5
|
+
options?: OpenfortHookOptions<T>;
|
|
6
|
+
data: T;
|
|
7
|
+
}) => T;
|
|
8
|
+
export declare const onError: <T>({ hookOptions, options, error, }: {
|
|
9
|
+
hookOptions?: OpenfortHookOptions<T>;
|
|
10
|
+
options?: OpenfortHookOptions<T>;
|
|
11
|
+
error: OpenfortError;
|
|
12
|
+
}) => {
|
|
13
|
+
error: OpenfortError;
|
|
14
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { EmbeddedWalletWebView, WebViewUtils } from './webview';
|
|
2
|
+
export { isSecureStorageMessage, handleSecureStorageMessage, NativeStorageUtils, } from './storage';
|
|
3
|
+
export type { SecureStorageMessage, SecureStorageResponse, } from './storage';
|
|
4
|
+
export { openOAuthSession, authenticateWithApple, isAppleSignInAvailable, parseOAuthUrl, createOAuthRedirectUri, OAuthUtils, } from './oauth';
|
|
5
|
+
export type { OAuthResult, AppleAuthResult, OAuthSessionConfig, } from './oauth';
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import * as AppleAuthentication from 'expo-apple-authentication';
|
|
2
|
+
import { OAuthProvider as OAuthProviderType } from '@openfort/openfort-js';
|
|
3
|
+
/**
|
|
4
|
+
* OAuth authentication result
|
|
5
|
+
*/
|
|
6
|
+
export interface OAuthResult {
|
|
7
|
+
type: 'success' | 'cancel' | 'error';
|
|
8
|
+
url?: string;
|
|
9
|
+
error?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Apple Sign-In authentication result
|
|
13
|
+
*/
|
|
14
|
+
export interface AppleAuthResult {
|
|
15
|
+
authorizationCode: string;
|
|
16
|
+
state: string;
|
|
17
|
+
identityToken?: string;
|
|
18
|
+
email?: string;
|
|
19
|
+
fullName?: AppleAuthentication.AppleAuthenticationFullName;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* OAuth session configuration
|
|
23
|
+
*/
|
|
24
|
+
export interface OAuthSessionConfig {
|
|
25
|
+
/** OAuth provider URL */
|
|
26
|
+
url: string;
|
|
27
|
+
/** Redirect URI for OAuth flow */
|
|
28
|
+
redirectUri: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Opens an OAuth authentication session
|
|
32
|
+
*/
|
|
33
|
+
export declare function openOAuthSession(config: OAuthSessionConfig): Promise<OAuthResult>;
|
|
34
|
+
/**
|
|
35
|
+
* Handles Apple Sign-In authentication for iOS
|
|
36
|
+
*/
|
|
37
|
+
export declare function authenticateWithApple(options: {
|
|
38
|
+
state: string;
|
|
39
|
+
isLogin: boolean;
|
|
40
|
+
}): Promise<AppleAuthResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Checks if Apple Sign-In is available on the current device
|
|
43
|
+
*/
|
|
44
|
+
export declare function isAppleSignInAvailable(): Promise<boolean>;
|
|
45
|
+
/**
|
|
46
|
+
* Parses OAuth parameters from a URL
|
|
47
|
+
*/
|
|
48
|
+
export declare function parseOAuthUrl(url: string): {
|
|
49
|
+
access_token?: string;
|
|
50
|
+
refresh_token?: string;
|
|
51
|
+
player_id?: string;
|
|
52
|
+
error?: string;
|
|
53
|
+
errorDescription?: string;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Creates a redirect URI for OAuth flows
|
|
57
|
+
*/
|
|
58
|
+
export declare function createOAuthRedirectUri(path?: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* OAuth provider utilities
|
|
61
|
+
*/
|
|
62
|
+
export declare const OAuthUtils: {
|
|
63
|
+
/**
|
|
64
|
+
* Checks if a provider should use native authentication
|
|
65
|
+
*/
|
|
66
|
+
shouldUseNativeAuth(provider: OAuthProviderType, isLegacyAppleIosBehaviorEnabled?: boolean): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Gets platform-specific OAuth configuration
|
|
69
|
+
*/
|
|
70
|
+
getPlatformConfig(): {
|
|
71
|
+
supportsNativeApple: boolean;
|
|
72
|
+
platform: string;
|
|
73
|
+
supportsWebBrowser: boolean;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Validates OAuth provider support
|
|
77
|
+
*/
|
|
78
|
+
isProviderSupported(provider: OAuthProviderType): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Gets the appropriate OAuth URL for a provider
|
|
81
|
+
*/
|
|
82
|
+
getProviderUrl(provider: OAuthProviderType, baseUrl: string): string;
|
|
83
|
+
/**
|
|
84
|
+
* Handles OAuth session timeout
|
|
85
|
+
*/
|
|
86
|
+
createTimeoutPromise(timeoutMs?: number): Promise<never>;
|
|
87
|
+
/**
|
|
88
|
+
* Combines OAuth session with timeout
|
|
89
|
+
*/
|
|
90
|
+
withTimeout<T>(promise: Promise<T>, timeoutMs?: number): Promise<T>;
|
|
91
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as SecureStore from 'expo-secure-store';
|
|
2
|
+
/**
|
|
3
|
+
* Interface for secure storage message handling in WebView
|
|
4
|
+
*/
|
|
5
|
+
export interface SecureStorageMessage {
|
|
6
|
+
event: string;
|
|
7
|
+
id: string;
|
|
8
|
+
data: Record<string, any>;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Interface for secure storage response
|
|
12
|
+
*/
|
|
13
|
+
export interface SecureStorageResponse {
|
|
14
|
+
event: string;
|
|
15
|
+
id: string;
|
|
16
|
+
data: Record<string, any>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Checks if a message is a secure storage related message
|
|
20
|
+
*/
|
|
21
|
+
export declare function isSecureStorageMessage(message: unknown): message is SecureStorageMessage;
|
|
22
|
+
/**
|
|
23
|
+
* Handles secure storage operations from WebView messages
|
|
24
|
+
*/
|
|
25
|
+
export declare function handleSecureStorageMessage(message: SecureStorageMessage): Promise<SecureStorageResponse>;
|
|
26
|
+
/**
|
|
27
|
+
* Native storage utilities for platform-specific operations
|
|
28
|
+
*/
|
|
29
|
+
export declare const NativeStorageUtils: {
|
|
30
|
+
/**
|
|
31
|
+
* Checks if secure storage is available on the current platform
|
|
32
|
+
*/
|
|
33
|
+
isAvailable(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Gets the platform-specific storage options
|
|
36
|
+
*/
|
|
37
|
+
getStorageOptions(): SecureStore.SecureStoreOptions;
|
|
38
|
+
/**
|
|
39
|
+
* Safely checks if a key exists in secure storage
|
|
40
|
+
*/
|
|
41
|
+
keyExists(key: string): Promise<boolean>;
|
|
42
|
+
/**
|
|
43
|
+
* Gets all available storage information
|
|
44
|
+
*/
|
|
45
|
+
getStorageInfo(): Promise<{
|
|
46
|
+
isAvailable: boolean;
|
|
47
|
+
platform: string;
|
|
48
|
+
keychainAccessible: number;
|
|
49
|
+
}>;
|
|
50
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import WebView from 'react-native-webview';
|
|
3
|
+
import type { Openfort as OpenfortClient } from '@openfort/openfort-js';
|
|
4
|
+
/**
|
|
5
|
+
* Props for the EmbeddedWalletWebView component
|
|
6
|
+
*/
|
|
7
|
+
interface EmbeddedWalletWebViewProps {
|
|
8
|
+
/** Openfort client instance */
|
|
9
|
+
client: OpenfortClient;
|
|
10
|
+
/** Whether the client is ready and initialized */
|
|
11
|
+
isClientReady: boolean;
|
|
12
|
+
/** Callback when WebView proxy status changes */
|
|
13
|
+
onProxyStatusChange?: (status: 'loading' | 'loaded' | 'reloading') => void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* WebView component for embedded wallet integration
|
|
17
|
+
* Handles secure communication between React Native and the embedded wallet WebView
|
|
18
|
+
* This component is hidden and only used for wallet communication
|
|
19
|
+
*/
|
|
20
|
+
export declare const EmbeddedWalletWebView: React.FC<EmbeddedWalletWebViewProps>;
|
|
21
|
+
/**
|
|
22
|
+
* Utilities for WebView integration
|
|
23
|
+
*/
|
|
24
|
+
export declare const WebViewUtils: {
|
|
25
|
+
/**
|
|
26
|
+
* Checks if WebView is supported on the current platform
|
|
27
|
+
*/
|
|
28
|
+
isSupported(): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Gets platform-specific WebView configuration
|
|
31
|
+
*/
|
|
32
|
+
getPlatformConfig(): Partial<React.ComponentProps<typeof WebView>>;
|
|
33
|
+
/**
|
|
34
|
+
* Creates a secure message for WebView communication
|
|
35
|
+
*/
|
|
36
|
+
createSecureMessage(data: any): string;
|
|
37
|
+
/**
|
|
38
|
+
* Validates a message received from WebView
|
|
39
|
+
*/
|
|
40
|
+
validateMessage(message: string): {
|
|
41
|
+
isValid: boolean;
|
|
42
|
+
data?: any;
|
|
43
|
+
error?: string;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* Gets WebView user agent for the current platform
|
|
47
|
+
*/
|
|
48
|
+
getUserAgent(): string;
|
|
49
|
+
};
|
|
50
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export var OpenfortErrorType;
|
|
2
|
+
(function (OpenfortErrorType) {
|
|
3
|
+
OpenfortErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
|
|
4
|
+
OpenfortErrorType["WALLET_ERROR"] = "WALLET_ERROR";
|
|
5
|
+
})(OpenfortErrorType || (OpenfortErrorType = {}));
|
|
6
|
+
export class OpenfortError extends Error {
|
|
7
|
+
type;
|
|
8
|
+
data;
|
|
9
|
+
constructor(message, type, data) {
|
|
10
|
+
if (data?.error instanceof OpenfortError) {
|
|
11
|
+
super(data.error.message);
|
|
12
|
+
this.data = data.error.data;
|
|
13
|
+
this.type = data.error.type;
|
|
14
|
+
this.name = data.error.name;
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
else if (data?.error instanceof Error) {
|
|
18
|
+
super(data.error.message);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
super(message);
|
|
22
|
+
}
|
|
23
|
+
this.type = type;
|
|
24
|
+
this.data = data || {};
|
|
25
|
+
this.name = 'OpenfortError';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export function isConnected(s) {
|
|
2
|
+
return s.status === 'connected';
|
|
3
|
+
}
|
|
4
|
+
export function isReconnecting(s) {
|
|
5
|
+
return s.status === 'reconnecting';
|
|
6
|
+
}
|
|
7
|
+
export function isConnecting(s) {
|
|
8
|
+
return s.status === 'connecting';
|
|
9
|
+
}
|
|
10
|
+
export function isDisconnected(s) {
|
|
11
|
+
return s.status === 'disconnected';
|
|
12
|
+
}
|
|
13
|
+
export function isNotCreated(s) {
|
|
14
|
+
return s.status === 'disconnected';
|
|
15
|
+
}
|
|
16
|
+
export function isCreating(s) {
|
|
17
|
+
return s.status === 'creating';
|
|
18
|
+
}
|
|
19
|
+
export function hasError(s) {
|
|
20
|
+
return s.status === 'error';
|
|
21
|
+
}
|
|
22
|
+
export function needsRecovery(s) {
|
|
23
|
+
return s.status === 'needs-recovery';
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Additional utility predicates
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* Type guard to check if wallet is in a loading state (connecting, creating, reconnecting)
|
|
30
|
+
*/
|
|
31
|
+
export function isLoading(s) {
|
|
32
|
+
return s.status === 'connecting' || s.status === 'creating' || s.status === 'reconnecting';
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Type guard to check if wallet is ready for use
|
|
36
|
+
*/
|
|
37
|
+
export function isReady(s) {
|
|
38
|
+
return s.status === 'connected';
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Type guard to check if wallet needs user action
|
|
42
|
+
*/
|
|
43
|
+
export function needsUserAction(s) {
|
|
44
|
+
return s.status === 'disconnected' || s.status === 'needs-recovery' || s.status === 'error';
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Type guard to check if wallet state is stable (not in transition)
|
|
48
|
+
*/
|
|
49
|
+
export function isStable(s) {
|
|
50
|
+
return !isLoading(s);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Type guard to check if wallet can perform transactions
|
|
54
|
+
*/
|
|
55
|
+
export function canTransact(s) {
|
|
56
|
+
return s.status === 'connected';
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Gets a human-readable description of the wallet state
|
|
60
|
+
*/
|
|
61
|
+
export function getStateDescription(s) {
|
|
62
|
+
switch (s.status) {
|
|
63
|
+
case 'connected':
|
|
64
|
+
return 'Wallet is connected and ready to use';
|
|
65
|
+
case 'connecting':
|
|
66
|
+
return 'Connecting to wallet...';
|
|
67
|
+
case 'reconnecting':
|
|
68
|
+
return 'Reconnecting to wallet...';
|
|
69
|
+
case 'creating':
|
|
70
|
+
return 'Creating new wallet...';
|
|
71
|
+
case 'disconnected':
|
|
72
|
+
return 'Wallet is disconnected';
|
|
73
|
+
case 'needs-recovery':
|
|
74
|
+
return 'Wallet needs to be recovered';
|
|
75
|
+
case 'error':
|
|
76
|
+
return 'Wallet encountered an error';
|
|
77
|
+
default:
|
|
78
|
+
return 'Unknown wallet state';
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Gets appropriate action text for the current state
|
|
83
|
+
*/
|
|
84
|
+
export function getActionText(s) {
|
|
85
|
+
switch (s.status) {
|
|
86
|
+
case 'needs-recovery':
|
|
87
|
+
return 'Recover Wallet';
|
|
88
|
+
case 'error':
|
|
89
|
+
return 'Retry';
|
|
90
|
+
case 'disconnected':
|
|
91
|
+
return 'Create Wallet';
|
|
92
|
+
case 'connecting':
|
|
93
|
+
case 'creating':
|
|
94
|
+
case 'reconnecting':
|
|
95
|
+
return 'Please wait...';
|
|
96
|
+
case 'connected':
|
|
97
|
+
return 'Wallet Ready';
|
|
98
|
+
default:
|
|
99
|
+
return 'Unknown';
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import type { OpenfortError, AuthPlayerResponse as OpenfortUser } from '@openfort/openfort-js';
|
|
2
|
+
/**
|
|
3
|
+
* Password authentication flow state
|
|
4
|
+
*/
|
|
5
|
+
export type PasswordFlowState = {
|
|
6
|
+
status: 'initial';
|
|
7
|
+
} | {
|
|
8
|
+
status: 'error';
|
|
9
|
+
error: Error | null;
|
|
10
|
+
} | {
|
|
11
|
+
status: 'sending-verification-code';
|
|
12
|
+
} | {
|
|
13
|
+
status: 'awaiting-code-input';
|
|
14
|
+
} | {
|
|
15
|
+
status: 'submitting-code';
|
|
16
|
+
} | {
|
|
17
|
+
status: 'done';
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Sign-in with Ethereum (SIWE) flow state
|
|
21
|
+
*/
|
|
22
|
+
export type SiweFlowState = {
|
|
23
|
+
status: 'initial';
|
|
24
|
+
} | {
|
|
25
|
+
status: 'error';
|
|
26
|
+
error: Error | null;
|
|
27
|
+
} | {
|
|
28
|
+
status: 'generating-message';
|
|
29
|
+
} | {
|
|
30
|
+
status: 'awaiting-signature';
|
|
31
|
+
} | {
|
|
32
|
+
status: 'submitting-signature';
|
|
33
|
+
} | {
|
|
34
|
+
status: 'done';
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Recovery flow state
|
|
38
|
+
*/
|
|
39
|
+
export type RecoveryFlowState = {
|
|
40
|
+
status: 'initial' | 'creating-wallet' | 'upgrading-recovery' | 'recovering';
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Custom authentication flow state
|
|
44
|
+
*/
|
|
45
|
+
export type CustomAuthFlowState = {
|
|
46
|
+
status: 'initial';
|
|
47
|
+
} | {
|
|
48
|
+
status: 'loading';
|
|
49
|
+
} | {
|
|
50
|
+
status: 'not-enabled';
|
|
51
|
+
} | {
|
|
52
|
+
status: 'done';
|
|
53
|
+
} | {
|
|
54
|
+
status: 'error';
|
|
55
|
+
error: Error | null;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Authentication success callback
|
|
59
|
+
*/
|
|
60
|
+
export type AuthSuccessCallback = (user: OpenfortUser, isNewUser?: boolean) => void;
|
|
61
|
+
/**
|
|
62
|
+
* Authentication link success callback
|
|
63
|
+
*/
|
|
64
|
+
export type AuthLinkSuccessCallback = (user: OpenfortUser) => void;
|
|
65
|
+
/**
|
|
66
|
+
* Error callback
|
|
67
|
+
*/
|
|
68
|
+
export type ErrorCallback = (error: OpenfortError | Error) => void;
|
|
69
|
+
/**
|
|
70
|
+
* Email login hook options
|
|
71
|
+
*/
|
|
72
|
+
export interface EmailLoginHookOptions {
|
|
73
|
+
onError?: ErrorCallback;
|
|
74
|
+
onSuccess?: AuthSuccessCallback;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Email link hook options
|
|
78
|
+
*/
|
|
79
|
+
export interface EmailLinkHookOptions {
|
|
80
|
+
onError?: ErrorCallback;
|
|
81
|
+
onSuccess?: AuthLinkSuccessCallback;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Email login hook result
|
|
85
|
+
*/
|
|
86
|
+
export interface EmailLoginHookResult {
|
|
87
|
+
login: (credentials: {
|
|
88
|
+
email: string;
|
|
89
|
+
password: string;
|
|
90
|
+
}) => Promise<OpenfortUser | undefined>;
|
|
91
|
+
signup: (credentials: {
|
|
92
|
+
email: string;
|
|
93
|
+
password: string;
|
|
94
|
+
name?: string;
|
|
95
|
+
}) => Promise<OpenfortUser | undefined>;
|
|
96
|
+
state: PasswordFlowState;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Email link hook result
|
|
100
|
+
*/
|
|
101
|
+
export interface EmailLinkHookResult {
|
|
102
|
+
link: (credentials: {
|
|
103
|
+
email: string;
|
|
104
|
+
password: string;
|
|
105
|
+
}) => Promise<OpenfortUser | undefined>;
|
|
106
|
+
state: PasswordFlowState;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* SIWE message generation response
|
|
110
|
+
*/
|
|
111
|
+
export type GenerateSiweMessageResponse = Promise<string>;
|
|
112
|
+
/**
|
|
113
|
+
* SIWE message generation function
|
|
114
|
+
*/
|
|
115
|
+
export type GenerateSiweMessage = (opts: {
|
|
116
|
+
/** Wallet to request a Sign-In With Ethereum signature from */
|
|
117
|
+
wallet: any;
|
|
118
|
+
/**
|
|
119
|
+
* Required fields that describe origin of Sign-In With Ethereum signature request
|
|
120
|
+
*/
|
|
121
|
+
from: {
|
|
122
|
+
/** RFC 3986 authority that is requesting the signing */
|
|
123
|
+
domain: string;
|
|
124
|
+
/** RFC 3986 URI referring to the resource that is the subject of the signing */
|
|
125
|
+
uri: string;
|
|
126
|
+
};
|
|
127
|
+
}) => GenerateSiweMessageResponse;
|
|
128
|
+
/**
|
|
129
|
+
* SIWE login hook options
|
|
130
|
+
*/
|
|
131
|
+
export interface SiweLoginHookOptions {
|
|
132
|
+
onError?: ErrorCallback;
|
|
133
|
+
onSuccess?: AuthSuccessCallback;
|
|
134
|
+
onGenerateMessage?: (message: string) => void;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* SIWE link hook options
|
|
138
|
+
*/
|
|
139
|
+
export interface SiweLinkHookOptions {
|
|
140
|
+
onError?: ErrorCallback;
|
|
141
|
+
onSuccess?: AuthLinkSuccessCallback;
|
|
142
|
+
onGenerateMessage?: (message: string) => void;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* SIWE login hook result
|
|
146
|
+
*/
|
|
147
|
+
export interface SiweLoginHookResult {
|
|
148
|
+
generateSiweMessage: GenerateSiweMessage;
|
|
149
|
+
state: SiweFlowState;
|
|
150
|
+
loginWithSiwe: (opts: {
|
|
151
|
+
signature: string;
|
|
152
|
+
walletAddress: string;
|
|
153
|
+
messageOverride?: string;
|
|
154
|
+
disableSignup?: boolean;
|
|
155
|
+
}) => Promise<OpenfortUser>;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* SIWE link hook result
|
|
159
|
+
*/
|
|
160
|
+
export interface SiweLinkHookResult {
|
|
161
|
+
generateSiweMessage: GenerateSiweMessage;
|
|
162
|
+
state: SiweFlowState;
|
|
163
|
+
linkWithSiwe: (opts: {
|
|
164
|
+
signature: string;
|
|
165
|
+
messageOverride?: string;
|
|
166
|
+
walletAddress: string;
|
|
167
|
+
}) => Promise<OpenfortUser>;
|
|
168
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OpenfortError } from "./openfortError";
|
|
2
|
+
export type BaseFlowState = {
|
|
3
|
+
status: "idle" | 'awaiting-input' | 'loading' | 'success';
|
|
4
|
+
error?: never;
|
|
5
|
+
} | {
|
|
6
|
+
status: 'error';
|
|
7
|
+
error: OpenfortError | null;
|
|
8
|
+
};
|
|
9
|
+
export declare const mapStatus: (status: BaseFlowState) => {
|
|
10
|
+
isLoading: boolean;
|
|
11
|
+
isError: boolean;
|
|
12
|
+
isSuccess: boolean;
|
|
13
|
+
error: OpenfortError | null | undefined;
|
|
14
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Storage interface
|
|
3
|
+
*/
|
|
4
|
+
export interface Storage {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Chain configuration
|
|
9
|
+
*/
|
|
10
|
+
export interface Chain {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Custom authentication provider configuration
|
|
15
|
+
*/
|
|
16
|
+
export type CustomAuthProviderConfig = {
|
|
17
|
+
/**
|
|
18
|
+
* If true, enable custom authentication integration.
|
|
19
|
+
* This enables a JWT from a custom auth provider to be used to authenticate Openfort embedded wallets.
|
|
20
|
+
* Defaults to true.
|
|
21
|
+
*/
|
|
22
|
+
enabled?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* A callback that returns the user's custom auth provider's access token as a string.
|
|
25
|
+
* Can be left blank if using cookies to store and send access tokens
|
|
26
|
+
*/
|
|
27
|
+
getCustomAccessToken: () => Promise<string | undefined>;
|
|
28
|
+
/**
|
|
29
|
+
* Custom auth providers loading state
|
|
30
|
+
*/
|
|
31
|
+
isLoading: boolean;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Create guest account interface
|
|
35
|
+
*/
|
|
36
|
+
export interface UseGuestAuth {
|
|
37
|
+
create: () => Promise<import('@openfort/openfort-js').AuthPlayerResponse>;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Embedded wallet state change hook options
|
|
41
|
+
*/
|
|
42
|
+
export interface UseOnEmbeddedWalletStateChange {
|
|
43
|
+
onStateChange: (state: import('./wallet').EmbeddedWalletStatus) => void;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Set embedded wallet recovery parameters
|
|
47
|
+
*/
|
|
48
|
+
export type SetRecoveryParams = {
|
|
49
|
+
recoveryMethod: 'password';
|
|
50
|
+
password: string;
|
|
51
|
+
} | {
|
|
52
|
+
recoveryMethod: 'automatic';
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Set embedded wallet recovery result
|
|
56
|
+
*/
|
|
57
|
+
export interface UseSetEmbeddedWalletRecoveryResult {
|
|
58
|
+
/**
|
|
59
|
+
* The embedded account with the updated recovery method.
|
|
60
|
+
*/
|
|
61
|
+
account: import('@openfort/openfort-js').EmbeddedAccount;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Set embedded wallet recovery interface
|
|
65
|
+
*/
|
|
66
|
+
export interface UseSetEmbeddedWalletRecovery {
|
|
67
|
+
/**
|
|
68
|
+
* An async method to update the recovery method of the embedded wallet.
|
|
69
|
+
*/
|
|
70
|
+
setRecovery: (params: SetRecoveryParams) => Promise<import('@openfort/openfort-js').EmbeddedAccount>;
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Hex = `0x${string}`;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { OpenfortError } from "./openfortError";
|
|
2
|
+
export type OpenfortHookOptions<T = {
|
|
3
|
+
error?: OpenfortError;
|
|
4
|
+
}> = {
|
|
5
|
+
onSuccess?: (data: T) => void;
|
|
6
|
+
onError?: (error: OpenfortError) => void;
|
|
7
|
+
onSettled?: (data: T | undefined | null, error: OpenfortError | null) => void;
|
|
8
|
+
throwOnError?: boolean;
|
|
9
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Openfort hook interface
|
|
3
|
+
*/
|
|
4
|
+
export interface UseOpenfort {
|
|
5
|
+
/** The current authenticated user, or null when unauthenticated */
|
|
6
|
+
user: import('@openfort/openfort-js').AuthPlayerResponse | null;
|
|
7
|
+
/** Whether or not the SDK has initialized and is ready for use */
|
|
8
|
+
isReady: boolean;
|
|
9
|
+
/** Any error encountered during SDK initialization */
|
|
10
|
+
error: Error | null;
|
|
11
|
+
/** A function that logs the current user out and clears any stored tokens */
|
|
12
|
+
logout: () => Promise<void>;
|
|
13
|
+
/** A function that gets the current authenticated user's access token */
|
|
14
|
+
getAccessToken: () => Promise<string | null>;
|
|
15
|
+
}
|
|
16
|
+
export type { PasswordFlowState, SiweFlowState, RecoveryFlowState, CustomAuthFlowState, AuthSuccessCallback, AuthLinkSuccessCallback, ErrorCallback, EmailLoginHookOptions, EmailLinkHookOptions, EmailLoginHookResult, EmailLinkHookResult, SiweLoginHookOptions, SiweLinkHookOptions, SiweLoginHookResult, SiweLinkHookResult, GenerateSiweMessageResponse, GenerateSiweMessage, } from './auth';
|
|
17
|
+
export type { OAuthFlowState, OAuthTokens, UseOAuthTokensOptions, LoginWithOAuthInput, LinkWithOAuthInput, UseLoginWithOAuth, UseLinkWithOAuth, UnlinkOAuthOptions, UnlinkOAuthParams, } from './oauth';
|
|
18
|
+
export type { OpenfortEmbeddedWalletAccount, WalletRecoveryCallbacks, SolanaWalletRecoveryCallbacks, RecoveryMethodOptions, CreateSolanaEmbeddedWalletOpts, RecoverSolanaEmbeddedWalletOpts, EmbeddedEthereumWalletActions, EmbeddedEthereumWalletState, EmbeddedWalletStatus, ConnectedEmbeddedSolanaWallet, EmbeddedSolanaWalletActions, EmbeddedSolanaWalletConnectedState, EmbeddedSolanaWalletConnectingState, EmbeddedSolanaWalletReconnectingState, EmbeddedSolanaWalletDisconnectedState, EmbeddedSolanaWalletNeedsRecoveryState, EmbeddedSolanaWalletCreatingState, EmbeddedSolanaWalletErrorState, EmbeddedSolanaWalletState, EmbeddedSolanaWalletStatus, ConnectedEmbeddedEthereumWallet, UserWallet, } from './wallet';
|
|
19
|
+
export type { CustomAuthProviderConfig, UseGuestAuth, UseOnEmbeddedWalletStateChange, SetRecoveryParams, UseSetEmbeddedWalletRecoveryResult, UseSetEmbeddedWalletRecovery, } from './config';
|
|
20
|
+
export { isConnected, isReconnecting, isConnecting, isDisconnected, isNotCreated, isCreating, hasError, needsRecovery, isLoading, isReady, needsUserAction, isStable, canTransact, getStateDescription, getActionText, } from './predicates';
|
|
21
|
+
/**
|
|
22
|
+
* Embedded wallet hook options with callbacks
|
|
23
|
+
*/
|
|
24
|
+
export type UseEmbeddedEthereumWallet = {
|
|
25
|
+
onCreateWalletSuccess?: (provider: import('@openfort/openfort-js').Provider) => void;
|
|
26
|
+
onCreateWalletError?: (error: Error) => void;
|
|
27
|
+
onSetWalletRecoverySuccess?: (result: {
|
|
28
|
+
user: import('@openfort/openfort-js').AuthPlayerResponse;
|
|
29
|
+
}) => void;
|
|
30
|
+
onSetWalletRecoveryError?: (error: Error) => void;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Embedded Solana wallet hook options with callbacks
|
|
34
|
+
*/
|
|
35
|
+
export type UseEmbeddedSolanaWallet = {
|
|
36
|
+
onCreateWalletSuccess?: (account: import('@openfort/openfort-js').EmbeddedAccount) => void;
|
|
37
|
+
onCreateWalletError?: (error: Error) => void;
|
|
38
|
+
};
|