@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
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { OAuthProvider } from '@openfort/openfort-js';
|
|
2
|
+
import type { AuthSuccessCallback, ErrorCallback } from './auth';
|
|
3
|
+
/**
|
|
4
|
+
* OAuth authentication flow state
|
|
5
|
+
*/
|
|
6
|
+
export type OAuthFlowState = {
|
|
7
|
+
status: 'initial' | 'loading' | 'awaiting-redirect' | 'done';
|
|
8
|
+
error?: never;
|
|
9
|
+
} | {
|
|
10
|
+
status: 'error';
|
|
11
|
+
error: Error | null;
|
|
12
|
+
};
|
|
13
|
+
export declare const mapOAuthStatus: (status: OAuthFlowState) => {
|
|
14
|
+
isLoading: boolean;
|
|
15
|
+
isError: boolean;
|
|
16
|
+
isSuccess: boolean;
|
|
17
|
+
error: Error | null | undefined;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* OAuth tokens interface
|
|
21
|
+
*/
|
|
22
|
+
export interface OAuthTokens {
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* OAuth tokens hook options
|
|
27
|
+
*/
|
|
28
|
+
export interface UseOAuthTokensOptions {
|
|
29
|
+
/**
|
|
30
|
+
* Callback function triggered when OAuth tokens are granted to the user after any OAuth Authorization flow.
|
|
31
|
+
* @param tokens - The set of OAuth tokens granted to the user.
|
|
32
|
+
*/
|
|
33
|
+
onOAuthTokenGrant: (tokens: OAuthTokens) => void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Login with OAuth input parameters
|
|
37
|
+
*/
|
|
38
|
+
export type LoginWithOAuthInput = LinkWithOAuthInput;
|
|
39
|
+
/**
|
|
40
|
+
* Link with OAuth input parameters
|
|
41
|
+
*/
|
|
42
|
+
export type LinkWithOAuthInput = {
|
|
43
|
+
provider: OAuthProvider;
|
|
44
|
+
redirectUri?: string | undefined;
|
|
45
|
+
isLegacyAppleIosBehaviorEnabled?: boolean;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Login with OAuth hook interface
|
|
49
|
+
*/
|
|
50
|
+
export interface UseLoginWithOAuth {
|
|
51
|
+
state: OAuthFlowState;
|
|
52
|
+
login: (input: LoginWithOAuthInput) => Promise<import('@openfort/openfort-js').AuthPlayerResponse | undefined>;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Link with OAuth hook interface
|
|
56
|
+
*/
|
|
57
|
+
export interface UseLinkWithOAuth {
|
|
58
|
+
state: OAuthFlowState;
|
|
59
|
+
link: (input: LinkWithOAuthInput) => Promise<import('@openfort/openfort-js').AuthPlayerResponse | undefined>;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Unlink OAuth hook options
|
|
63
|
+
*/
|
|
64
|
+
export interface UnlinkOAuthOptions {
|
|
65
|
+
onError?: ErrorCallback;
|
|
66
|
+
onSuccess?: AuthSuccessCallback;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Unlink OAuth parameters
|
|
70
|
+
*/
|
|
71
|
+
export interface UnlinkOAuthParams {
|
|
72
|
+
provider: OAuthProvider;
|
|
73
|
+
subject: string;
|
|
74
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare enum OpenfortErrorType {
|
|
2
|
+
AUTHENTICATION_ERROR = "AUTHENTICATION_ERROR",
|
|
3
|
+
WALLET_ERROR = "WALLET_ERROR"
|
|
4
|
+
}
|
|
5
|
+
interface Data {
|
|
6
|
+
[key: string]: any;
|
|
7
|
+
}
|
|
8
|
+
export declare class OpenfortError extends Error {
|
|
9
|
+
type: OpenfortErrorType;
|
|
10
|
+
data: Data;
|
|
11
|
+
constructor(message: string, type: OpenfortErrorType, data?: Data);
|
|
12
|
+
}
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { EmbeddedEthereumWalletState, EmbeddedSolanaWalletState, EmbeddedSolanaWalletConnectedState, EmbeddedSolanaWalletConnectingState, EmbeddedSolanaWalletReconnectingState, EmbeddedSolanaWalletDisconnectedState, EmbeddedSolanaWalletNeedsRecoveryState, EmbeddedSolanaWalletCreatingState, EmbeddedSolanaWalletErrorState } from './wallet';
|
|
2
|
+
/**
|
|
3
|
+
* Type guard to check if embedded wallet is connected
|
|
4
|
+
*/
|
|
5
|
+
export declare function isConnected(s: EmbeddedSolanaWalletState): s is EmbeddedSolanaWalletConnectedState;
|
|
6
|
+
/**
|
|
7
|
+
* Type guard to check if embedded wallet is reconnecting
|
|
8
|
+
*/
|
|
9
|
+
export declare function isReconnecting(s: EmbeddedSolanaWalletState): s is EmbeddedSolanaWalletReconnectingState;
|
|
10
|
+
/**
|
|
11
|
+
* Type guard to check if embedded wallet is connecting
|
|
12
|
+
*/
|
|
13
|
+
export declare function isConnecting(s: EmbeddedSolanaWalletState): s is EmbeddedSolanaWalletConnectingState;
|
|
14
|
+
/**
|
|
15
|
+
* Type guard to check if embedded wallet is disconnected
|
|
16
|
+
*/
|
|
17
|
+
export declare function isDisconnected(s: EmbeddedSolanaWalletState): s is EmbeddedSolanaWalletDisconnectedState;
|
|
18
|
+
/**
|
|
19
|
+
* Type guard to check if embedded wallet is not created
|
|
20
|
+
*/
|
|
21
|
+
export declare function isNotCreated(s: EmbeddedSolanaWalletState): s is EmbeddedSolanaWalletDisconnectedState;
|
|
22
|
+
/**
|
|
23
|
+
* Type guard to check if embedded wallet is being created
|
|
24
|
+
*/
|
|
25
|
+
export declare function isCreating(s: EmbeddedSolanaWalletState): s is EmbeddedSolanaWalletCreatingState;
|
|
26
|
+
/**
|
|
27
|
+
* Type guard to check if embedded wallet has an error
|
|
28
|
+
*/
|
|
29
|
+
export declare function hasError(s: EmbeddedSolanaWalletState): s is EmbeddedSolanaWalletErrorState;
|
|
30
|
+
/**
|
|
31
|
+
* Type guard to check if embedded wallet needs recovery
|
|
32
|
+
*/
|
|
33
|
+
export declare function needsRecovery(s: EmbeddedSolanaWalletState): s is EmbeddedSolanaWalletNeedsRecoveryState;
|
|
34
|
+
/**
|
|
35
|
+
* Additional utility predicates
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* Type guard to check if wallet is in a loading state (connecting, creating, reconnecting)
|
|
39
|
+
*/
|
|
40
|
+
export declare function isLoading(s: EmbeddedEthereumWalletState | EmbeddedSolanaWalletState): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Type guard to check if wallet is ready for use
|
|
43
|
+
*/
|
|
44
|
+
export declare function isReady(s: EmbeddedEthereumWalletState | EmbeddedSolanaWalletState): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Type guard to check if wallet needs user action
|
|
47
|
+
*/
|
|
48
|
+
export declare function needsUserAction(s: EmbeddedEthereumWalletState | EmbeddedSolanaWalletState): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Type guard to check if wallet state is stable (not in transition)
|
|
51
|
+
*/
|
|
52
|
+
export declare function isStable(s: EmbeddedEthereumWalletState | EmbeddedSolanaWalletState): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Type guard to check if wallet can perform transactions
|
|
55
|
+
*/
|
|
56
|
+
export declare function canTransact(s: EmbeddedEthereumWalletState | EmbeddedSolanaWalletState): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Gets a human-readable description of the wallet state
|
|
59
|
+
*/
|
|
60
|
+
export declare function getStateDescription(s: EmbeddedEthereumWalletState | EmbeddedSolanaWalletState): string;
|
|
61
|
+
/**
|
|
62
|
+
* Gets appropriate action text for the current state
|
|
63
|
+
*/
|
|
64
|
+
export declare function getActionText(s: EmbeddedEthereumWalletState | EmbeddedSolanaWalletState): string;
|
|
File without changes
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
export interface OpenfortEmbeddedEthereumWalletProvider {
|
|
2
|
+
request: (args: {
|
|
3
|
+
method: string;
|
|
4
|
+
params?: any[];
|
|
5
|
+
}) => Promise<any>;
|
|
6
|
+
on: (event: string, handler: (...args: any[]) => void) => void;
|
|
7
|
+
removeListener: (event: string, handler: (...args: any[]) => void) => void;
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
10
|
+
export interface OpenfortEmbeddedSolanaWalletProvider {
|
|
11
|
+
signTransaction: (transaction: any) => Promise<any>;
|
|
12
|
+
signAllTransactions: (transactions: any[]) => Promise<any[]>;
|
|
13
|
+
publicKey: string;
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}
|
|
16
|
+
export interface OpenfortEthereumEmbeddedWalletAccount {
|
|
17
|
+
address: string;
|
|
18
|
+
ownerAddress?: string;
|
|
19
|
+
implementationType?: string;
|
|
20
|
+
chainType: 'ethereum';
|
|
21
|
+
walletIndex: number;
|
|
22
|
+
}
|
|
23
|
+
export interface OpenfortSolanaEmbeddedWalletAccount {
|
|
24
|
+
address: string;
|
|
25
|
+
chainType: 'solana';
|
|
26
|
+
walletIndex: number;
|
|
27
|
+
}
|
|
28
|
+
import { ChainTypeEnum } from '@openfort/openfort-js';
|
|
29
|
+
import type { ErrorCallback } from './auth';
|
|
30
|
+
import { Hex } from './hex';
|
|
31
|
+
/**
|
|
32
|
+
* Openfort embedded wallet account union type
|
|
33
|
+
*/
|
|
34
|
+
export type OpenfortEmbeddedWalletAccount = OpenfortEthereumEmbeddedWalletAccount | OpenfortSolanaEmbeddedWalletAccount;
|
|
35
|
+
/**
|
|
36
|
+
* Wallet recovery callbacks
|
|
37
|
+
*/
|
|
38
|
+
export type WalletRecoveryCallbacks = {
|
|
39
|
+
onError?: ErrorCallback;
|
|
40
|
+
onSuccess?: (provider: OpenfortEmbeddedEthereumWalletProvider) => void;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Solana wallet recovery callbacks
|
|
44
|
+
*/
|
|
45
|
+
export type SolanaWalletRecoveryCallbacks = {
|
|
46
|
+
onError?: ErrorCallback;
|
|
47
|
+
onSuccess?: (provider: OpenfortEmbeddedSolanaWalletProvider) => void;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Recovery method options
|
|
51
|
+
*/
|
|
52
|
+
export type RecoveryMethodOptions = string | undefined | {
|
|
53
|
+
recoveryMethod: 'automatic';
|
|
54
|
+
} | {
|
|
55
|
+
recoveryMethod: 'password';
|
|
56
|
+
password: string;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Solana wallet creation options
|
|
60
|
+
*/
|
|
61
|
+
export type CreateSolanaEmbeddedWalletOpts = (undefined | {
|
|
62
|
+
recoveryMethod: 'automatic';
|
|
63
|
+
}) & {
|
|
64
|
+
createAdditional?: boolean;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Solana wallet recovery options
|
|
68
|
+
*/
|
|
69
|
+
export type RecoverSolanaEmbeddedWalletOpts = undefined | {
|
|
70
|
+
recoveryMethod: 'automatic';
|
|
71
|
+
} | {
|
|
72
|
+
recoveryMethod: 'password';
|
|
73
|
+
password: string;
|
|
74
|
+
};
|
|
75
|
+
export type UserWallet = {
|
|
76
|
+
address: Hex;
|
|
77
|
+
ownerAddress?: string;
|
|
78
|
+
implementationType?: string;
|
|
79
|
+
chainType: ChainTypeEnum;
|
|
80
|
+
isActive?: boolean;
|
|
81
|
+
isConnecting?: boolean;
|
|
82
|
+
getProvider: () => Promise<OpenfortEmbeddedEthereumWalletProvider>;
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Connected embedded wallet state
|
|
86
|
+
*/
|
|
87
|
+
interface IEmbeddedEthereumWalletConnectedState {
|
|
88
|
+
status: 'connected';
|
|
89
|
+
provider: OpenfortEmbeddedEthereumWalletProvider;
|
|
90
|
+
activeWallet: UserWallet;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Connecting embedded wallet state
|
|
94
|
+
*/
|
|
95
|
+
interface IEmbeddedEthereumWalletConnectingState {
|
|
96
|
+
status: 'connecting';
|
|
97
|
+
activeWallet: UserWallet;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Reconnecting embedded wallet state
|
|
101
|
+
*/
|
|
102
|
+
interface IEmbeddedEthereumWalletReconnectingState {
|
|
103
|
+
status: 'reconnecting';
|
|
104
|
+
activeWallet: UserWallet;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Disconnected embedded wallet state
|
|
108
|
+
*/
|
|
109
|
+
interface IEmbeddedEthereumWalletDisconnectedState {
|
|
110
|
+
status: 'disconnected';
|
|
111
|
+
activeWallet: null;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Needs recovery embedded wallet state
|
|
115
|
+
*/
|
|
116
|
+
interface IEmbeddedEthereumWalletNeedsRecoveryState {
|
|
117
|
+
status: 'needs-recovery';
|
|
118
|
+
activeWallet: UserWallet;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Creating embedded wallet state
|
|
122
|
+
*/
|
|
123
|
+
interface IEmbeddedEthereumWalletCreatingState {
|
|
124
|
+
status: 'creating';
|
|
125
|
+
activeWallet: null;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Error embedded wallet state
|
|
129
|
+
*/
|
|
130
|
+
interface IEmbeddedEthereumWalletErrorState {
|
|
131
|
+
status: 'error';
|
|
132
|
+
activeWallet: UserWallet | null;
|
|
133
|
+
error: string;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Embedded wallet actions
|
|
137
|
+
*/
|
|
138
|
+
export type EmbeddedEthereumWalletActions = {
|
|
139
|
+
/**
|
|
140
|
+
* Configure an embedded wallet for this user.
|
|
141
|
+
*/
|
|
142
|
+
create: (args?: {
|
|
143
|
+
chainId?: number;
|
|
144
|
+
recoveryPassword?: string;
|
|
145
|
+
policyId?: string;
|
|
146
|
+
}) => Promise<import('@openfort/openfort-js').EmbeddedAccount>;
|
|
147
|
+
/**
|
|
148
|
+
* List of embedded ethereum wallets at each derived HD index.
|
|
149
|
+
*/
|
|
150
|
+
wallets: ConnectedEmbeddedEthereumWallet[];
|
|
151
|
+
};
|
|
152
|
+
export type EthereumWalletState = IEmbeddedEthereumWalletConnectedState | IEmbeddedEthereumWalletConnectingState | IEmbeddedEthereumWalletReconnectingState | IEmbeddedEthereumWalletDisconnectedState | IEmbeddedEthereumWalletNeedsRecoveryState | IEmbeddedEthereumWalletCreatingState | IEmbeddedEthereumWalletErrorState;
|
|
153
|
+
/**
|
|
154
|
+
* Main embedded wallet state union
|
|
155
|
+
*/
|
|
156
|
+
export type EmbeddedEthereumWalletState = EthereumWalletState & EmbeddedEthereumWalletActions;
|
|
157
|
+
/**
|
|
158
|
+
* Embedded wallet status
|
|
159
|
+
*/
|
|
160
|
+
export type EmbeddedWalletStatus = EmbeddedEthereumWalletState['status'];
|
|
161
|
+
/**
|
|
162
|
+
* Connected embedded Solana wallet state
|
|
163
|
+
*/
|
|
164
|
+
interface IEmbeddedSolanaWalletConnectedState {
|
|
165
|
+
status: 'connected';
|
|
166
|
+
activeWallet: OpenfortSolanaEmbeddedWalletAccount;
|
|
167
|
+
provider: OpenfortEmbeddedEthereumWalletProvider;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Connecting embedded Solana wallet state
|
|
171
|
+
*/
|
|
172
|
+
interface IEmbeddedSolanaWalletConnectingState {
|
|
173
|
+
status: 'connecting';
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Reconnecting embedded Solana wallet state
|
|
177
|
+
*/
|
|
178
|
+
interface IEmbeddedSolanaWalletReconnectingState {
|
|
179
|
+
status: 'reconnecting';
|
|
180
|
+
activeWallet: OpenfortSolanaEmbeddedWalletAccount;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Disconnected embedded Solana wallet state
|
|
184
|
+
*/
|
|
185
|
+
interface IEmbeddedSolanaWalletDisconnectedState {
|
|
186
|
+
status: 'disconnected';
|
|
187
|
+
activeWallet: null;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Needs recovery embedded Solana wallet state
|
|
191
|
+
*/
|
|
192
|
+
interface IEmbeddedSolanaWalletNeedsRecoveryState {
|
|
193
|
+
status: 'needs-recovery';
|
|
194
|
+
activeWallet: OpenfortSolanaEmbeddedWalletAccount;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Creating embedded Solana wallet state
|
|
198
|
+
*/
|
|
199
|
+
interface IEmbeddedSolanaWalletCreatingState {
|
|
200
|
+
status: 'creating';
|
|
201
|
+
activeWallet: null;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Error embedded Solana wallet state
|
|
205
|
+
*/
|
|
206
|
+
interface IEmbeddedSolanaWalletErrorState {
|
|
207
|
+
status: 'error';
|
|
208
|
+
activeWallet: OpenfortSolanaEmbeddedWalletAccount | null;
|
|
209
|
+
error: string;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Connected embedded Solana wallet
|
|
213
|
+
*/
|
|
214
|
+
export type ConnectedEmbeddedSolanaWallet = {
|
|
215
|
+
address: string;
|
|
216
|
+
chainType: 'solana';
|
|
217
|
+
walletIndex: number;
|
|
218
|
+
getProvider: () => Promise<OpenfortEmbeddedSolanaWalletProvider>;
|
|
219
|
+
};
|
|
220
|
+
/**
|
|
221
|
+
* Embedded Solana wallet actions
|
|
222
|
+
*/
|
|
223
|
+
export type EmbeddedSolanaWalletActions = {
|
|
224
|
+
/**
|
|
225
|
+
* Configure an embedded wallet for this user.
|
|
226
|
+
*/
|
|
227
|
+
create: (args?: {
|
|
228
|
+
chainId?: number;
|
|
229
|
+
recoveryPassword?: string;
|
|
230
|
+
}) => Promise<import('@openfort/openfort-js').EmbeddedAccount>;
|
|
231
|
+
/**
|
|
232
|
+
* List of embedded solana wallets
|
|
233
|
+
*/
|
|
234
|
+
wallets: ConnectedEmbeddedSolanaWallet[];
|
|
235
|
+
};
|
|
236
|
+
export type EmbeddedSolanaWalletConnectedState = EmbeddedSolanaWalletActions & IEmbeddedSolanaWalletConnectedState;
|
|
237
|
+
export type EmbeddedSolanaWalletConnectingState = EmbeddedSolanaWalletActions & IEmbeddedSolanaWalletConnectingState;
|
|
238
|
+
export type EmbeddedSolanaWalletReconnectingState = EmbeddedSolanaWalletActions & IEmbeddedSolanaWalletReconnectingState;
|
|
239
|
+
export type EmbeddedSolanaWalletDisconnectedState = Partial<EmbeddedSolanaWalletActions> & IEmbeddedSolanaWalletDisconnectedState;
|
|
240
|
+
export type EmbeddedSolanaWalletNeedsRecoveryState = EmbeddedSolanaWalletActions & IEmbeddedSolanaWalletNeedsRecoveryState;
|
|
241
|
+
export type EmbeddedSolanaWalletCreatingState = EmbeddedSolanaWalletActions & IEmbeddedSolanaWalletCreatingState;
|
|
242
|
+
export type EmbeddedSolanaWalletErrorState = EmbeddedSolanaWalletActions & IEmbeddedSolanaWalletErrorState;
|
|
243
|
+
/**
|
|
244
|
+
* Main embedded Solana wallet state union
|
|
245
|
+
*/
|
|
246
|
+
export type EmbeddedSolanaWalletState = EmbeddedSolanaWalletConnectedState | EmbeddedSolanaWalletConnectingState | EmbeddedSolanaWalletReconnectingState | EmbeddedSolanaWalletDisconnectedState | EmbeddedSolanaWalletNeedsRecoveryState | EmbeddedSolanaWalletCreatingState | EmbeddedSolanaWalletErrorState;
|
|
247
|
+
/**
|
|
248
|
+
* Embedded Solana wallet status
|
|
249
|
+
*/
|
|
250
|
+
export type EmbeddedSolanaWalletStatus = EmbeddedSolanaWalletState['status'];
|
|
251
|
+
/**
|
|
252
|
+
* Connected Ethereum wallet
|
|
253
|
+
*/
|
|
254
|
+
export type ConnectedEmbeddedEthereumWallet = {
|
|
255
|
+
address: string;
|
|
256
|
+
ownerAddress?: string;
|
|
257
|
+
implementationType?: string;
|
|
258
|
+
chainType: 'ethereum';
|
|
259
|
+
walletIndex: number;
|
|
260
|
+
getProvider: () => Promise<OpenfortEmbeddedEthereumWalletProvider>;
|
|
261
|
+
};
|
|
262
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,43 +1,57 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfort/react-native",
|
|
3
3
|
"main": "dist/index.js",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.1.1",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"description": "React Native SDK for Openfort platform integration",
|
|
6
7
|
"scripts": {
|
|
7
8
|
"build": "rimraf dist && tsc",
|
|
8
|
-
"lint": "eslint . --ignore-pattern dist"
|
|
9
|
+
"lint": "eslint . --ignore-pattern dist",
|
|
10
|
+
"link": "yarn link",
|
|
11
|
+
"unlink": "yarn unlink"
|
|
9
12
|
},
|
|
10
13
|
"types": "dist/types/index.d.ts",
|
|
11
14
|
"files": [
|
|
12
|
-
"dist"
|
|
13
|
-
"polyfills"
|
|
15
|
+
"dist"
|
|
14
16
|
],
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"require": "./dist/index.js",
|
|
20
|
+
"import": "./dist/index.js",
|
|
21
|
+
"types": "./dist/types/index.d.ts"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
15
24
|
"dependencies": {
|
|
16
|
-
"
|
|
17
|
-
"jsrsasign": "^11.1.0",
|
|
18
|
-
"react-native-get-random-values": "^1.11.0",
|
|
19
|
-
"react-native-mmkv": "^3.2.0",
|
|
20
|
-
"react-native-randombytes": "^3.6.1",
|
|
21
|
-
"react-native-webview": "^13.13.5",
|
|
22
|
-
"text-encoding": "^0.7.0",
|
|
23
|
-
"uuid": "^11.1.0"
|
|
25
|
+
"@openfort/openfort-js": "^0.9.8"
|
|
24
26
|
},
|
|
25
27
|
"peerDependencies": {
|
|
26
|
-
"
|
|
28
|
+
"expo-apple-authentication": "*",
|
|
29
|
+
"expo-crypto": "*",
|
|
30
|
+
"expo-linking": "*",
|
|
31
|
+
"expo-secure-store": "*",
|
|
32
|
+
"expo-web-browser": "*",
|
|
27
33
|
"react": "*",
|
|
28
|
-
"
|
|
34
|
+
"expo-application": "*",
|
|
35
|
+
"react-native": "*",
|
|
36
|
+
"react-native-webview": "*"
|
|
29
37
|
},
|
|
30
38
|
"devDependencies": {
|
|
31
39
|
"@eslint/js": "^9.17.0",
|
|
32
|
-
"@types/jsrsasign": "^10.5.15",
|
|
33
40
|
"@types/react": "~18.3.12",
|
|
34
41
|
"@types/react-test-renderer": "^18.3.0",
|
|
42
|
+
"buffer": "^5.4.3",
|
|
35
43
|
"eslint": "^9.17.0",
|
|
36
44
|
"eslint-plugin-react": "^7.37.3",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
45
|
+
"expo-apple-authentication": "^7.2.4",
|
|
46
|
+
"expo-application": "^6.1.4",
|
|
47
|
+
"expo-crypto": "14.0.2",
|
|
48
|
+
"expo-linking": "^7.1.5",
|
|
49
|
+
"expo-secure-store": "^14.2.3",
|
|
50
|
+
"expo-web-browser": "^14.1.6",
|
|
51
|
+
"react": "^18.3.1",
|
|
52
|
+
"react-native": "0.77.1",
|
|
53
|
+
"react-native-webview": "^13.15.0",
|
|
54
|
+
"typescript": "^5.5.3",
|
|
41
55
|
"typescript-eslint": "^8.19.0"
|
|
42
56
|
},
|
|
43
57
|
"private": false,
|
package/dist/Iframe.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useRef, useState } from 'react';
|
|
2
|
-
import { Platform, Text, View } from "react-native";
|
|
3
|
-
import WebView from "react-native-webview";
|
|
4
|
-
const debugInjectedCode = `
|
|
5
|
-
console.log = function(...message) {
|
|
6
|
-
const safeMessage = JSON.stringify({ ...message, type: "log" });
|
|
7
|
-
window.ReactNativeWebView.postMessage(safeMessage);
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
console.warn = console.log;
|
|
11
|
-
console.error = console.log;
|
|
12
|
-
console.info = console.log;
|
|
13
|
-
console.debug = console.log;
|
|
14
|
-
|
|
15
|
-
console.log("injecting Code");
|
|
16
|
-
`;
|
|
17
|
-
const injectedCode = `
|
|
18
|
-
window.parent = {};
|
|
19
|
-
window.parent.postMessage = (msg) => {console.log("---", msg); window.ReactNativeWebView.postMessage(JSON.stringify(msg))}
|
|
20
|
-
|
|
21
|
-
window.isAndroid = ${Platform.OS === 'android' ? 'true' : 'false'};
|
|
22
|
-
`;
|
|
23
|
-
export default function Iframe({ customUri, debug, debugVisible }) {
|
|
24
|
-
const webViewRef = useRef(null);
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
26
|
-
const fnCallbackRef = useRef(null); // Ref to store the callback
|
|
27
|
-
const [loaded, setLoaded] = useState(false);
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
if (!global.openfort)
|
|
30
|
-
throw new Error("Openfort SDK not initialized. Please make sure to add `import '@openfort/react-native/polyfills';` at the top of you app before using the SDK.");
|
|
31
|
-
global.openfort.iframeListener = (fn) => {
|
|
32
|
-
fnCallbackRef.current = fn; // Store the callback in the ref
|
|
33
|
-
};
|
|
34
|
-
global.openfort.iframePostMessage = (message) => {
|
|
35
|
-
setLoaded(true);
|
|
36
|
-
if (!webViewRef.current) {
|
|
37
|
-
if (debug)
|
|
38
|
-
console.log("WebView is not initialized, trying to send message:", message);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
if (debug)
|
|
42
|
-
console.log("[Send message to web view]", message);
|
|
43
|
-
webViewRef.current.postMessage(JSON.stringify(message));
|
|
44
|
-
};
|
|
45
|
-
}, [webViewRef?.current]);
|
|
46
|
-
const handleMessage = (event) => {
|
|
47
|
-
// Trigger the stored callback, if any
|
|
48
|
-
if (fnCallbackRef.current) {
|
|
49
|
-
const origin = event.nativeEvent.url.endsWith('/') ? event.nativeEvent.url.slice(0, -1) : event.nativeEvent.url;
|
|
50
|
-
try {
|
|
51
|
-
const data = JSON.parse(event.nativeEvent.data);
|
|
52
|
-
if (data?.type === "log") {
|
|
53
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
54
|
-
const { type, ...dataWithoutType } = data;
|
|
55
|
-
if (debug)
|
|
56
|
-
console.log("[Webview LOG]", Object.values(dataWithoutType).join(", "));
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
if (debug)
|
|
60
|
-
console.log("[Webview message received]", data);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
catch {
|
|
64
|
-
if (debug)
|
|
65
|
-
console.log("[Webview message received]", event.nativeEvent.data);
|
|
66
|
-
}
|
|
67
|
-
fnCallbackRef.current({ origin, data: event.nativeEvent.data });
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
if (!loaded)
|
|
71
|
-
return null;
|
|
72
|
-
const uri = customUri ? customUri : "https://embedded.openfort.xyz";
|
|
73
|
-
const finalUri = new URL(uri);
|
|
74
|
-
if (debug) {
|
|
75
|
-
finalUri.searchParams.set('debug', 'true');
|
|
76
|
-
}
|
|
77
|
-
const uriWithParams = finalUri.toString();
|
|
78
|
-
return (React.createElement(View, { style: { flex: debugVisible ? 1 : 0 } },
|
|
79
|
-
debugVisible &&
|
|
80
|
-
React.createElement(Text, null,
|
|
81
|
-
"Debug: ",
|
|
82
|
-
uriWithParams),
|
|
83
|
-
React.createElement(WebView, { ref: webViewRef, source: { uri: uriWithParams }, onMessage: handleMessage, injectedJavaScript: injectedCode + (debug ? debugInjectedCode : "") })));
|
|
84
|
-
}
|
package/dist/types/Iframe.d.ts
DELETED
package/polyfills/index.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { polyfillGlobal } from "react-native/Libraries/Utilities/PolyfillFunctions"
|
|
2
|
-
import { KEYUTIL, KJUR } from 'jsrsasign';
|
|
3
|
-
|
|
4
|
-
// This is a workaround to fix the issue with process.version
|
|
5
|
-
if (process.version === undefined) {
|
|
6
|
-
Object.defineProperty(process, 'version', {
|
|
7
|
-
value: "", // Set the desired version (you can use any string)
|
|
8
|
-
writable: false,
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// Crypto module needs getRandomValues
|
|
13
|
-
import 'react-native-get-random-values';
|
|
14
|
-
|
|
15
|
-
crypto.randomUUID = require('uuid').v4;
|
|
16
|
-
|
|
17
|
-
const MMKVStorage = require("react-native-mmkv").MMKV;
|
|
18
|
-
|
|
19
|
-
// Initialize MMKVStorage
|
|
20
|
-
const MMKV = new MMKVStorage();
|
|
21
|
-
|
|
22
|
-
const localStorage: Storage = {
|
|
23
|
-
getItem: (key: string): string | null => {
|
|
24
|
-
try {
|
|
25
|
-
const value = MMKV.getString(key);
|
|
26
|
-
// console.log("getItem", key, value);
|
|
27
|
-
return value !== undefined ? value : null; // Ensure it returns string or null
|
|
28
|
-
} catch (e) {
|
|
29
|
-
console.error('Error reading value from localStorage polyfill', e);
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
setItem: (key: string, value: string) => {
|
|
34
|
-
try {
|
|
35
|
-
// console.log("setItem", key, value);
|
|
36
|
-
MMKV.set(key, value); // Sets value synchronously
|
|
37
|
-
} catch (e) {
|
|
38
|
-
console.error('Error saving value to localStorage polyfill', e);
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
removeItem: (key: string) => {
|
|
42
|
-
try {
|
|
43
|
-
// console.log("removeItem", key);
|
|
44
|
-
MMKV.delete(key); // Removes item synchronously
|
|
45
|
-
} catch (e) {
|
|
46
|
-
console.error('Error removing value from localStorage polyfill', e);
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
clear: () => {
|
|
50
|
-
try {
|
|
51
|
-
// console.log("clear");
|
|
52
|
-
MMKV.clearAll(); // Clears store synchronously
|
|
53
|
-
} catch (e) {
|
|
54
|
-
console.error('Error clearing localStorage polyfill', e);
|
|
55
|
-
}
|
|
56
|
-
},
|
|
57
|
-
key: (index: number): string | null => {
|
|
58
|
-
return MMKV.getAllKeys()[index] || null;
|
|
59
|
-
},
|
|
60
|
-
get length(): number {
|
|
61
|
-
try {
|
|
62
|
-
return MMKV.getAllKeys().length;
|
|
63
|
-
} catch {
|
|
64
|
-
console.error('Error: localStorage.length is not supported');
|
|
65
|
-
return -1;
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
global.localStorage = localStorage;
|
|
71
|
-
global.sessionStorage = localStorage;
|
|
72
|
-
|
|
73
|
-
global.openfort = {}
|
|
74
|
-
global.openfort.jwk = {
|
|
75
|
-
getKey: KEYUTIL.getKey,
|
|
76
|
-
parse: KJUR.jws.JWS.parse,
|
|
77
|
-
verifyJWT: KJUR.jws.JWS.verifyJWT,
|
|
78
|
-
getNow: KJUR.jws.IntDate.getNow,
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
// for TextEncoder and TextDecoder
|
|
82
|
-
const applyGlobalPolyfills = () => {
|
|
83
|
-
const { TextEncoder, TextDecoder } = require("text-encoding")
|
|
84
|
-
|
|
85
|
-
polyfillGlobal("TextEncoder", () => TextEncoder)
|
|
86
|
-
polyfillGlobal("TextDecoder", () => TextDecoder)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
applyGlobalPolyfills()
|