@openfort/react-native 0.1.24 → 0.1.25

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.
@@ -96,7 +96,7 @@ import { buildRecoveryParams } from './utils';
96
96
  * ```
97
97
  */
98
98
  export function useEmbeddedEthereumWallet(options = {}) {
99
- const { client, supportedChains, walletConfig, embeddedState } = useOpenfortContext();
99
+ const { client, supportedChains, walletConfig, embeddedState, user } = useOpenfortContext();
100
100
  const [embeddedAccounts, setEmbeddedAccounts] = useState([]);
101
101
  const [activeWalletId, setActiveWalletId] = useState(null);
102
102
  const [activeAccount, setActiveAccount] = useState(null);
@@ -250,7 +250,7 @@ export function useEmbeddedEthereumWallet(options = {}) {
250
250
  throw new OpenfortError('No supported chains available for wallet creation', OpenfortErrorType.WALLET_ERROR);
251
251
  }
252
252
  // Build recovery params
253
- const recoveryParams = await buildRecoveryParams(createOptions, walletConfig);
253
+ const recoveryParams = await buildRecoveryParams({ ...createOptions, userId: user?.id }, walletConfig);
254
254
  const accountType = createOptions?.accountType || walletConfig?.accountType || AccountTypeEnum.SMART_ACCOUNT;
255
255
  // Create embedded wallet
256
256
  const embeddedAccount = await client.embeddedWallet.create({
@@ -300,7 +300,7 @@ export function useEmbeddedEthereumWallet(options = {}) {
300
300
  }
301
301
  throw error;
302
302
  }
303
- }, [client, supportedChains, walletConfig, options, getEthereumProvider, fetchEmbeddedAccounts]);
303
+ }, [client, supportedChains, walletConfig, options, getEthereumProvider, fetchEmbeddedAccounts, user]);
304
304
  // Set active wallet action
305
305
  const setActive = useCallback(async (setActiveOptions) => {
306
306
  // Prevent concurrent recoveries
@@ -356,7 +356,7 @@ export function useEmbeddedEthereumWallet(options = {}) {
356
356
  throw new OpenfortError(errorMsg, OpenfortErrorType.WALLET_ERROR);
357
357
  }
358
358
  // Build recovery params
359
- const recoveryParams = await buildRecoveryParams(setActiveOptions, walletConfig);
359
+ const recoveryParams = await buildRecoveryParams({ ...setActiveOptions, userId: user?.id }, walletConfig);
360
360
  // Recover the embedded wallet
361
361
  const embeddedAccount = await client.embeddedWallet.recover({
362
362
  account: embeddedAccountToRecover.id,
@@ -415,7 +415,7 @@ export function useEmbeddedEthereumWallet(options = {}) {
415
415
  }
416
416
  })();
417
417
  await recoverPromiseRef.current;
418
- }, [client, supportedChains, walletConfig, embeddedAccounts, options, wallets.length, getEthereumProvider]);
418
+ }, [client, supportedChains, walletConfig, embeddedAccounts, options, wallets.length, getEthereumProvider, user]);
419
419
  // Set recovery method action
420
420
  const setRecovery = useCallback(async (params) => {
421
421
  try {
@@ -107,7 +107,7 @@ import { buildRecoveryParams } from './utils';
107
107
  * ```
108
108
  */
109
109
  export function useEmbeddedSolanaWallet(options = {}) {
110
- const { client, walletConfig, embeddedState } = useOpenfortContext();
110
+ const { client, walletConfig, embeddedState, user } = useOpenfortContext();
111
111
  const [embeddedAccounts, setEmbeddedAccounts] = useState([]);
112
112
  const [activeWalletId, setActiveWalletId] = useState(null);
113
113
  const [activeAccount, setActiveAccount] = useState(null);
@@ -266,8 +266,10 @@ export function useEmbeddedSolanaWallet(options = {}) {
266
266
  logger.info('Creating Solana wallet with options', createOptions);
267
267
  try {
268
268
  setStatus({ status: 'creating' });
269
- // Build recovery params (only use recoveryPassword, ignore createAdditional)
270
- const recoveryParams = await buildRecoveryParams(createOptions?.recoveryPassword ? { recoveryPassword: createOptions.recoveryPassword } : undefined, walletConfig);
269
+ // Build recovery params (only use recoveryPassword, otpCode, and userId, ignore createAdditional)
270
+ const recoveryParams = await buildRecoveryParams(createOptions?.recoveryPassword || createOptions?.otpCode || user?.id
271
+ ? { recoveryPassword: createOptions?.recoveryPassword, otpCode: createOptions?.otpCode, userId: user?.id }
272
+ : undefined, walletConfig);
271
273
  // Create embedded wallet
272
274
  const embeddedAccount = await client.embeddedWallet.create({
273
275
  chainType: ChainTypeEnum.SVM,
@@ -315,7 +317,7 @@ export function useEmbeddedSolanaWallet(options = {}) {
315
317
  }
316
318
  throw error;
317
319
  }
318
- }, [client, walletConfig, options, getSolanaProvider, fetchEmbeddedAccounts]);
320
+ }, [client, walletConfig, options, getSolanaProvider, fetchEmbeddedAccounts, user]);
319
321
  // Set active wallet action
320
322
  const setActive = useCallback(async (setActiveOptions) => {
321
323
  // Prevent concurrent recoveries
@@ -346,7 +348,7 @@ export function useEmbeddedSolanaWallet(options = {}) {
346
348
  throw new OpenfortError(`No embedded Solana account found for address ${setActiveOptions.address}`, OpenfortErrorType.WALLET_ERROR);
347
349
  }
348
350
  // Build recovery params
349
- const recoveryParams = await buildRecoveryParams(setActiveOptions, walletConfig);
351
+ const recoveryParams = await buildRecoveryParams({ ...setActiveOptions, userId: user?.id }, walletConfig);
350
352
  // Recover the embedded wallet
351
353
  const embeddedAccount = await client.embeddedWallet.recover({
352
354
  account: embeddedAccountToRecover.id,
@@ -402,7 +404,7 @@ export function useEmbeddedSolanaWallet(options = {}) {
402
404
  }
403
405
  })();
404
406
  await recoverPromiseRef.current;
405
- }, [client, walletConfig, embeddedAccounts, options, wallets.length, getSolanaProvider]);
407
+ }, [client, walletConfig, embeddedAccounts, options, wallets.length, getSolanaProvider, user]);
406
408
  // Build active wallet from embeddedWallet.get()
407
409
  const activeWallet = useMemo(() => {
408
410
  if (!activeWalletId || !activeAccount)
@@ -7,18 +7,20 @@ import { OpenfortError, OpenfortErrorType } from '../../types/openfortError';
7
7
  * It supports both callback-based session retrieval and endpoint-based session creation.
8
8
  *
9
9
  * @param walletConfig - The embedded wallet configuration from the provider
10
+ * @param otpCode - Optional OTP code for Shield verification
11
+ * @param userId - Optional user ID for the encryption session
10
12
  * @returns A promise that resolves to the encryption session string
11
13
  * @throws {OpenfortError} When wallet config is missing or session cannot be retrieved
12
14
  *
13
15
  * @internal
14
16
  */
15
- async function resolveEncryptionSession(walletConfig) {
17
+ async function resolveEncryptionSession(walletConfig, otpCode, userId) {
16
18
  if (!walletConfig) {
17
19
  throw new OpenfortError('Encryption session configuration is required', OpenfortErrorType.WALLET_ERROR);
18
20
  }
19
21
  // Try callback-based session retrieval first
20
22
  if (walletConfig.getEncryptionSession) {
21
- return await walletConfig.getEncryptionSession();
23
+ return await walletConfig.getEncryptionSession({ otpCode, userId });
22
24
  }
23
25
  // Try endpoint-based session creation
24
26
  if (walletConfig.createEncryptedSessionEndpoint) {
@@ -28,6 +30,7 @@ async function resolveEncryptionSession(walletConfig) {
28
30
  headers: {
29
31
  'Content-Type': 'application/json',
30
32
  },
33
+ body: JSON.stringify({ otp_code: otpCode, user_id: userId }),
31
34
  });
32
35
  if (!response.ok) {
33
36
  throw new OpenfortError('Failed to create encryption session', OpenfortErrorType.WALLET_ERROR, {
@@ -55,7 +58,7 @@ async function resolveEncryptionSession(walletConfig) {
55
58
  * This utility constructs the appropriate RecoveryParams object based on whether
56
59
  * a recovery password is provided or automatic recovery should be used.
57
60
  *
58
- * @param options - Options containing optional recovery password
61
+ * @param options - Options containing optional recovery password, OTP code, and/or user ID
59
62
  * @param walletConfig - The embedded wallet configuration from the provider
60
63
  * @returns A promise that resolves to RecoveryParams for the SDK
61
64
  *
@@ -70,6 +73,6 @@ export async function buildRecoveryParams(options, walletConfig) {
70
73
  }
71
74
  return {
72
75
  recoveryMethod: RecoveryMethod.AUTOMATIC,
73
- encryptionSession: await resolveEncryptionSession(walletConfig),
76
+ encryptionSession: await resolveEncryptionSession(walletConfig, options?.otpCode, options?.userId),
74
77
  };
75
78
  }
@@ -3,6 +3,6 @@ export { RecoveryMethod } from '@openfort/openfort-js';
3
3
  export { createOpenfortClient } from './client';
4
4
  export type { OpenfortContextValue } from './context';
5
5
  export { isOpenfortContextValue, OpenfortContext, useOpenfortContext, useOpenfortContextSafe } from './context';
6
- export type { CommonEmbeddedWalletConfiguration, EmbeddedWalletConfiguration, EncryptionSession, OpenfortProviderProps, } from './provider';
6
+ export type { CommonEmbeddedWalletConfiguration, EmbeddedWalletConfiguration, EncryptionSession, EncryptionSessionParams, OpenfortProviderProps, } from './provider';
7
7
  export { OpenfortProvider } from './provider';
8
8
  export { createNormalizedStorage, SecureStorageAdapter } from './storage';
@@ -11,9 +11,18 @@ export type CommonEmbeddedWalletConfiguration = {
11
11
  /** Recovery method for the embedded wallet: 'automatic' or 'password' */
12
12
  recoveryMethod?: 'automatic' | 'password';
13
13
  };
14
+ /**
15
+ * Parameters passed to the encryption session callback
16
+ */
17
+ export type EncryptionSessionParams = {
18
+ /** OTP code for Shield verification (if required) */
19
+ otpCode?: string;
20
+ /** User ID for the encryption session */
21
+ userId?: string;
22
+ };
14
23
  export type EncryptionSession = {
15
- /** Function to retrieve an encryption session using a session ID */
16
- getEncryptionSession?: () => Promise<string>;
24
+ /** Function to retrieve an encryption session, optionally with OTP verification */
25
+ getEncryptionSession?: (params?: EncryptionSessionParams) => Promise<string>;
17
26
  createEncryptedSessionEndpoint?: never;
18
27
  } | {
19
28
  /** API endpoint for creating an encrypted session */
@@ -6,7 +6,7 @@ import type { EmbeddedWalletConfiguration } from '../../core/provider';
6
6
  * This utility constructs the appropriate RecoveryParams object based on whether
7
7
  * a recovery password is provided or automatic recovery should be used.
8
8
  *
9
- * @param options - Options containing optional recovery password
9
+ * @param options - Options containing optional recovery password, OTP code, and/or user ID
10
10
  * @param walletConfig - The embedded wallet configuration from the provider
11
11
  * @returns A promise that resolves to RecoveryParams for the SDK
12
12
  *
@@ -14,4 +14,6 @@ import type { EmbeddedWalletConfiguration } from '../../core/provider';
14
14
  */
15
15
  export declare function buildRecoveryParams(options: {
16
16
  recoveryPassword?: string;
17
+ otpCode?: string;
18
+ userId?: string;
17
19
  } | undefined, walletConfig?: EmbeddedWalletConfiguration): Promise<RecoveryParams>;
@@ -135,6 +135,8 @@ export type CreateEthereumWalletResult = {
135
135
  export type CreateEthereumWalletOptions = {
136
136
  chainId?: number;
137
137
  recoveryPassword?: string;
138
+ /** OTP code for Shield verification when using automatic recovery */
139
+ otpCode?: string;
138
140
  accountType?: AccountTypeEnum;
139
141
  policyId?: string;
140
142
  } & OpenfortHookOptions<CreateEthereumWalletResult>;
@@ -153,6 +155,8 @@ export type SetActiveEthereumWalletOptions = {
153
155
  address: Hex;
154
156
  chainId?: number;
155
157
  recoveryPassword?: string;
158
+ /** OTP code for Shield verification when using automatic recovery */
159
+ otpCode?: string;
156
160
  } & OpenfortHookOptions<SetActiveEthereumWalletResult>;
157
161
  /**
158
162
  * Result of setting recovery method
@@ -176,6 +180,10 @@ export type CreateSolanaEmbeddedWalletOpts = {
176
180
  * If omitted, automatic recovery will be used.
177
181
  */
178
182
  recoveryPassword?: string;
183
+ /**
184
+ * OTP code for Shield verification when using automatic recovery
185
+ */
186
+ otpCode?: string;
179
187
  /**
180
188
  * Create additional wallet if one already exists
181
189
  */
@@ -207,6 +215,8 @@ export type SetActiveSolanaWalletResult = {
207
215
  export type SetActiveSolanaWalletOptions = {
208
216
  address: string;
209
217
  recoveryPassword?: string;
218
+ /** OTP code for Shield verification when using automatic recovery */
219
+ otpCode?: string;
210
220
  } & OpenfortHookOptions<SetActiveSolanaWalletResult>;
211
221
  /**
212
222
  * Common actions available on all Ethereum wallet states
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@openfort/react-native",
3
3
  "main": "dist/index.js",
4
- "version": "0.1.24",
4
+ "version": "0.1.25",
5
5
  "license": "MIT",
6
6
  "description": "React Native SDK for Openfort platform integration",
7
7
  "types": "dist/types/index.d.ts",