@openfort/react-native 0.1.2 → 0.1.3
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.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hook for embedded Ethereum wallet functionality
|
|
3
3
|
*/
|
|
4
|
-
import { AccountTypeEnum, ChainTypeEnum, EmbeddedState, RecoveryMethod
|
|
4
|
+
import { AccountTypeEnum, ChainTypeEnum, EmbeddedState, RecoveryMethod } from '@openfort/openfort-js';
|
|
5
5
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
6
6
|
import { useOpenfortContext } from '../../core/context';
|
|
7
7
|
import { onError, onSuccess } from '../../lib/hookConsistency';
|
|
@@ -101,25 +101,6 @@ export function useWallets(hookOptions = {}) {
|
|
|
101
101
|
// Use the first supported chain as default
|
|
102
102
|
chainId = supportedChains[0].id;
|
|
103
103
|
}
|
|
104
|
-
// Create shield authentication object
|
|
105
|
-
let shieldAuthentication = null;
|
|
106
|
-
console.log('Using walletConfig:', walletConfig);
|
|
107
|
-
if (walletConfig) {
|
|
108
|
-
const accessToken = await client.getAccessToken();
|
|
109
|
-
if (!accessToken) {
|
|
110
|
-
throw new OpenfortError('Access token is required for shield authentication', OpenfortErrorType.WALLET_ERROR);
|
|
111
|
-
}
|
|
112
|
-
// Get encryption session from embedded wallet configuration
|
|
113
|
-
let encryptionSession;
|
|
114
|
-
if ('getEncryptionSession' in walletConfig && walletConfig.getEncryptionSession) {
|
|
115
|
-
encryptionSession = await walletConfig.getEncryptionSession();
|
|
116
|
-
}
|
|
117
|
-
shieldAuthentication = {
|
|
118
|
-
auth: ShieldAuthType.OPENFORT,
|
|
119
|
-
token: accessToken,
|
|
120
|
-
...(encryptionSession && { encryptionSession }),
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
104
|
const address = options?.address || wallets[0]?.address;
|
|
124
105
|
const embeddedAccountToRecover = embeddedAccounts.find(account => account.chainId === chainId && account.address === address);
|
|
125
106
|
let embeddedAccount;
|
|
@@ -139,11 +120,27 @@ export function useWallets(hookOptions = {}) {
|
|
|
139
120
|
// }
|
|
140
121
|
}
|
|
141
122
|
else {
|
|
123
|
+
let recoveryParams;
|
|
124
|
+
;
|
|
125
|
+
if (options?.recoveryPassword) {
|
|
126
|
+
recoveryParams = {
|
|
127
|
+
recoveryMethod: RecoveryMethod.PASSWORD,
|
|
128
|
+
password: options.recoveryPassword,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
else {
|
|
132
|
+
if (!walletConfig?.getEncryptionSession) {
|
|
133
|
+
throw new OpenfortError('Encryption session is required for automatic recovery', OpenfortErrorType.WALLET_ERROR);
|
|
134
|
+
}
|
|
135
|
+
recoveryParams = {
|
|
136
|
+
recoveryMethod: RecoveryMethod.AUTOMATIC,
|
|
137
|
+
encryptionSession: await walletConfig.getEncryptionSession()
|
|
138
|
+
};
|
|
139
|
+
}
|
|
142
140
|
// Recover the embedded wallet with shield authentication
|
|
143
141
|
embeddedAccount = await client.embeddedWallet.recover({
|
|
144
142
|
account: embeddedAccountToRecover.id,
|
|
145
|
-
|
|
146
|
-
recoveryParams: options?.recoveryPassword ? { password: options.recoveryPassword, recoveryMethod: RecoveryMethod.PASSWORD } : undefined
|
|
143
|
+
recoveryParams,
|
|
147
144
|
});
|
|
148
145
|
}
|
|
149
146
|
const wallet = {
|
|
@@ -255,34 +252,29 @@ export function useWallets(hookOptions = {}) {
|
|
|
255
252
|
throw new OpenfortError('No supported chains available for wallet creation', OpenfortErrorType.WALLET_ERROR);
|
|
256
253
|
}
|
|
257
254
|
console.log('Using chain ID for wallet creation:', chainId);
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
if (
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
encryptionSession = await walletConfig.getEncryptionSession();
|
|
270
|
-
console.log('Encryption session for shield authentication:', encryptionSession);
|
|
255
|
+
let recoveryParams;
|
|
256
|
+
;
|
|
257
|
+
if (options?.recoveryPassword) {
|
|
258
|
+
recoveryParams = {
|
|
259
|
+
recoveryMethod: RecoveryMethod.PASSWORD,
|
|
260
|
+
password: options.recoveryPassword,
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
if (!walletConfig?.getEncryptionSession) {
|
|
265
|
+
throw new OpenfortError('Encryption session is required for automatic recovery', OpenfortErrorType.WALLET_ERROR);
|
|
271
266
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
...(encryptionSession && { encryptionSession }),
|
|
267
|
+
recoveryParams = {
|
|
268
|
+
recoveryMethod: RecoveryMethod.AUTOMATIC,
|
|
269
|
+
encryptionSession: await walletConfig.getEncryptionSession()
|
|
276
270
|
};
|
|
277
271
|
}
|
|
278
|
-
console.log('Shield authentication object:', shieldAuthentication);
|
|
279
272
|
// Configure embedded wallet with shield authentication
|
|
280
273
|
const embeddedAccount = await client.embeddedWallet.create({
|
|
281
274
|
chainId,
|
|
282
|
-
accountType: AccountTypeEnum.SMART_ACCOUNT,
|
|
275
|
+
accountType: options?.accountType || walletConfig?.accountType || AccountTypeEnum.SMART_ACCOUNT,
|
|
283
276
|
chainType: options?.chainType || ChainTypeEnum.EVM,
|
|
284
|
-
|
|
285
|
-
recoveryParams: options?.recoveryPassword ? { password: options.recoveryPassword, recoveryMethod: RecoveryMethod.PASSWORD } : undefined
|
|
277
|
+
recoveryParams,
|
|
286
278
|
});
|
|
287
279
|
console.log('Embedded wallet configured with shield authentication');
|
|
288
280
|
// Get the Ethereum provider
|
|
@@ -334,21 +326,9 @@ export function useWallets(hookOptions = {}) {
|
|
|
334
326
|
status: 'loading',
|
|
335
327
|
});
|
|
336
328
|
// Set embedded wallet recovery method
|
|
337
|
-
|
|
338
|
-
await client.embeddedWallet.setEmbeddedRecovery({
|
|
339
|
-
recoveryMethod: RecoveryMethod.PASSWORD,
|
|
340
|
-
recoveryPassword: params.recoveryPassword
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
else {
|
|
344
|
-
await client.embeddedWallet.setEmbeddedRecovery({
|
|
345
|
-
recoveryMethod: RecoveryMethod.AUTOMATIC
|
|
346
|
-
});
|
|
347
|
-
}
|
|
329
|
+
await client.embeddedWallet.setRecoveryMethod(params.previousRecovery, params.newRecovery);
|
|
348
330
|
// Get the updated embedded account
|
|
349
331
|
const embeddedAccount = await client.embeddedWallet.get();
|
|
350
|
-
// Refresh user state to reflect recovery changes
|
|
351
|
-
await _internal.refreshUserState();
|
|
352
332
|
setStatus({ status: 'success' });
|
|
353
333
|
return onSuccess({
|
|
354
334
|
hookOptions,
|
|
@@ -376,7 +356,7 @@ export function useWallets(hookOptions = {}) {
|
|
|
376
356
|
error: new OpenfortError('Failed to set wallet recovery', OpenfortErrorType.WALLET_ERROR, { error: errorObj }),
|
|
377
357
|
});
|
|
378
358
|
}
|
|
379
|
-
}, [client,
|
|
359
|
+
}, [client, setStatus, hookOptions]);
|
|
380
360
|
return {
|
|
381
361
|
wallets,
|
|
382
362
|
activeWallet,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { RecoveryMethod, SDKOverrides } from '@openfort/openfort-js';
|
|
2
|
+
import { RecoveryMethod, SDKOverrides, AccountTypeEnum } from '@openfort/openfort-js';
|
|
3
3
|
/**
|
|
4
4
|
* Custom auth configuration
|
|
5
5
|
*/
|
|
@@ -14,6 +14,7 @@ export type CommonEmbeddedWalletConfiguration = {
|
|
|
14
14
|
/** Policy ID (pol_...) for the embedded signer */
|
|
15
15
|
ethereumProviderPolicyId?: string;
|
|
16
16
|
debug?: boolean;
|
|
17
|
+
accountType?: AccountTypeEnum;
|
|
17
18
|
};
|
|
18
19
|
export type EncryptionSession = {
|
|
19
20
|
/** Function to retrieve an encryption session using a session ID */
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hook for embedded Ethereum wallet functionality
|
|
3
3
|
*/
|
|
4
|
-
import { ChainTypeEnum, Provider,
|
|
4
|
+
import { AccountTypeEnum, ChainTypeEnum, Provider, RecoveryParams } from '@openfort/openfort-js';
|
|
5
5
|
import { Hex } from '../../types/hex';
|
|
6
6
|
import { OpenfortHookOptions } from '../../types/hookOption';
|
|
7
7
|
import { OpenfortError } from '../../types/openfortError';
|
|
@@ -22,11 +22,12 @@ type CreateWalletOptions = {
|
|
|
22
22
|
chainId?: number;
|
|
23
23
|
policyId?: string;
|
|
24
24
|
recoveryPassword?: string;
|
|
25
|
+
accountType?: AccountTypeEnum;
|
|
25
26
|
} & OpenfortHookOptions<CreateWalletResult>;
|
|
26
27
|
type RecoverEmbeddedWalletResult = SetActiveWalletResult;
|
|
27
28
|
type SetRecoveryOptions = {
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
previousRecovery: RecoveryParams;
|
|
30
|
+
newRecovery: RecoveryParams;
|
|
30
31
|
} & OpenfortHookOptions<CreateWalletResult>;
|
|
31
32
|
type WalletOptions = OpenfortHookOptions<SetActiveWalletResult | CreateWalletResult>;
|
|
32
33
|
/**
|
package/dist/types/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* @author Openfort
|
|
9
9
|
* @version 0.1.0
|
|
10
10
|
*/
|
|
11
|
-
export type { AuthPlayerResponse, OpenfortError,
|
|
11
|
+
export type { AuthPlayerResponse, OpenfortError, RecoveryMethod, Openfort as OpenfortClient, Provider, OpenfortConfiguration, ShieldConfiguration, EmbeddedState, } from '@openfort/openfort-js';
|
|
12
12
|
export { OAuthProvider, } from '@openfort/openfort-js';
|
|
13
13
|
export * from './types';
|
|
14
14
|
export * from './hooks';
|
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.
|
|
4
|
+
"version": "0.1.3",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "React Native SDK for Openfort platform integration",
|
|
7
7
|
"scripts": {
|
|
@@ -21,10 +21,8 @@
|
|
|
21
21
|
"types": "./dist/types/index.d.ts"
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
|
-
"dependencies": {
|
|
25
|
-
"@openfort/openfort-js": "^0.9.8"
|
|
26
|
-
},
|
|
27
24
|
"peerDependencies": {
|
|
25
|
+
"@openfort/openfort-js": "^0.10.1",
|
|
28
26
|
"expo-apple-authentication": "*",
|
|
29
27
|
"expo-crypto": "*",
|
|
30
28
|
"expo-linking": "*",
|
|
@@ -37,6 +35,7 @@
|
|
|
37
35
|
},
|
|
38
36
|
"devDependencies": {
|
|
39
37
|
"@eslint/js": "^9.17.0",
|
|
38
|
+
"@openfort/openfort-js": "^0.10.1",
|
|
40
39
|
"@types/react": "~18.3.12",
|
|
41
40
|
"@types/react-test-renderer": "^18.3.0",
|
|
42
41
|
"buffer": "^5.4.3",
|