@openfort/react 1.0.14 → 1.0.16
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/build/core/ConnectionStrategy.d.ts +2 -6
- package/build/core/strategies/EthereumBridgeStrategy.js +18 -16
- package/build/core/strategies/EthereumBridgeStrategy.js.map +1 -1
- package/build/core/strategies/EthereumEmbeddedStrategy.js +18 -16
- package/build/core/strategies/EthereumEmbeddedStrategy.js.map +1 -1
- package/build/ethereum/hooks/useEthereumEmbeddedWallet.js +66 -1
- package/build/ethereum/hooks/useEthereumEmbeddedWallet.js.map +1 -1
- package/build/ethereum/types.d.ts +3 -1
- package/build/openfort/CoreOpenfortProvider.js +3 -14
- package/build/openfort/CoreOpenfortProvider.js.map +1 -1
- package/build/shared/types.d.ts +8 -0
- package/build/solana/hooks/useSolanaEmbeddedWallet.js +58 -1
- package/build/solana/hooks/useSolanaEmbeddedWallet.js.map +1 -1
- package/build/solana/types.d.ts +3 -1
- package/build/version.d.ts +1 -1
- package/build/version.js +1 -1
- package/package.json +2 -2
|
@@ -25,11 +25,7 @@ export interface ConnectionStrategy {
|
|
|
25
25
|
getConnectRoutes(): ConnectRoute[];
|
|
26
26
|
/** External wallet connectors; only when wagmi/bridge exists. Otherwise []. */
|
|
27
27
|
getConnectors(): ExternalConnectorProps[];
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
* @param activeEmbeddedAddress - Active embedded account address. When undefined, EVM strategies skip
|
|
31
|
-
* `wallet_switchEthereumChain` to avoid sending `account: null` to /v2/accounts/switch-chain (422).
|
|
32
|
-
*/
|
|
33
|
-
initProvider(openfort: Openfort, walletConfig: OpenfortWalletConfig, chainId?: number, activeEmbeddedAddress?: string): Promise<void>;
|
|
28
|
+
/** @param chainId - Current chain for EVM; when provided, uses this for fee sponsorship/rpc instead of config default. */
|
|
29
|
+
initProvider(openfort: Openfort, walletConfig: OpenfortWalletConfig, chainId?: number): Promise<void>;
|
|
34
30
|
disconnect(openfort: Openfort): Promise<void>;
|
|
35
31
|
}
|
|
@@ -32,7 +32,7 @@ function createEthereumBridgeStrategy(bridge, connectors) {
|
|
|
32
32
|
getConnectors() {
|
|
33
33
|
return connectors;
|
|
34
34
|
},
|
|
35
|
-
async initProvider(openfort, walletConfig, chainIdOverride
|
|
35
|
+
async initProvider(openfort, walletConfig, chainIdOverride) {
|
|
36
36
|
const chainId = chainIdOverride !== null && chainIdOverride !== void 0 ? chainIdOverride : bridge.chainId;
|
|
37
37
|
const feeSponsorshipObj = chainId != null ? resolveEthereumFeeSponsorship(walletConfig, chainId) : undefined;
|
|
38
38
|
const rpcUrls = bridge.config.chains.reduce((acc, ch) => {
|
|
@@ -53,21 +53,23 @@ function createEthereumBridgeStrategy(bridge, connectors) {
|
|
|
53
53
|
},
|
|
54
54
|
});
|
|
55
55
|
// Tell the provider which chain is active (EIP-1193). Keeps provider in sync with wagmi.
|
|
56
|
-
//
|
|
57
|
-
//
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
56
|
+
// Real iframe-state check: throws when Account.fromStorage is empty (signer not yet
|
|
57
|
+
// configured by configure/create/recover). Avoids spurious /v2/accounts/switch-chain
|
|
58
|
+
// calls (422 with account=null) and redundant calls when already on target chain.
|
|
59
|
+
if (chainId == null || chainId === lastInitChainId)
|
|
60
|
+
return;
|
|
61
|
+
const wallet = await openfort.embeddedWallet.get().catch(() => null);
|
|
62
|
+
if (!(wallet === null || wallet === void 0 ? void 0 : wallet.address) || wallet.chainId === chainId)
|
|
63
|
+
return;
|
|
64
|
+
try {
|
|
65
|
+
await provider.request({
|
|
66
|
+
method: 'wallet_switchEthereumChain',
|
|
67
|
+
params: [{ chainId: `0x${chainId.toString(16)}` }],
|
|
68
|
+
});
|
|
69
|
+
lastInitChainId = chainId;
|
|
70
|
+
}
|
|
71
|
+
catch (switchErr) {
|
|
72
|
+
logger.warn('[@openfort/react] wallet_switchEthereumChain failed — provider may be on wrong chain', switchErr);
|
|
71
73
|
}
|
|
72
74
|
},
|
|
73
75
|
async disconnect(openfort) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumBridgeStrategy.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EthereumBridgeStrategy.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -44,7 +44,7 @@ function createEthereumEmbeddedStrategy(walletConfig) {
|
|
|
44
44
|
getConnectors() {
|
|
45
45
|
return [];
|
|
46
46
|
},
|
|
47
|
-
async initProvider(openfort, config, chainIdOverride
|
|
47
|
+
async initProvider(openfort, config, chainIdOverride) {
|
|
48
48
|
var _a, _b;
|
|
49
49
|
const ethereum = config === null || config === void 0 ? void 0 : config.ethereum;
|
|
50
50
|
const chainId = (_a = chainIdOverride !== null && chainIdOverride !== void 0 ? chainIdOverride : ethereum === null || ethereum === void 0 ? void 0 : ethereum.chainId) !== null && _a !== void 0 ? _a : DEFAULT_DEV_CHAIN_ID;
|
|
@@ -56,21 +56,23 @@ function createEthereumEmbeddedStrategy(walletConfig) {
|
|
|
56
56
|
});
|
|
57
57
|
// Tell the provider which chain is active (EIP-1193). Without this, the provider
|
|
58
58
|
// stays on its initial chain (e.g. 80002) while fee sponsorship resolution is per-chain.
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
59
|
+
// Real iframe-state check: throws when Account.fromStorage is empty (signer not yet
|
|
60
|
+
// configured by configure/create/recover). Avoids spurious /v2/accounts/switch-chain
|
|
61
|
+
// calls (422 with account=null) and redundant calls when already on target chain.
|
|
62
|
+
if (chainId === lastInitChainId)
|
|
63
|
+
return;
|
|
64
|
+
const wallet = await openfort.embeddedWallet.get().catch(() => null);
|
|
65
|
+
if (!(wallet === null || wallet === void 0 ? void 0 : wallet.address) || wallet.chainId === chainId)
|
|
66
|
+
return;
|
|
67
|
+
try {
|
|
68
|
+
await provider.request({
|
|
69
|
+
method: 'wallet_switchEthereumChain',
|
|
70
|
+
params: [{ chainId: `0x${chainId.toString(16)}` }],
|
|
71
|
+
});
|
|
72
|
+
lastInitChainId = chainId;
|
|
73
|
+
}
|
|
74
|
+
catch (switchErr) {
|
|
75
|
+
logger.warn('[@openfort/react] wallet_switchEthereumChain failed — provider may be on wrong chain', switchErr);
|
|
74
76
|
}
|
|
75
77
|
},
|
|
76
78
|
async disconnect(openfort) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EthereumEmbeddedStrategy.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EthereumEmbeddedStrategy.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -179,6 +179,70 @@ function useEthereumEmbeddedWallet(options) {
|
|
|
179
179
|
updateEmbeddedAccounts,
|
|
180
180
|
setActiveEmbeddedAddress,
|
|
181
181
|
]);
|
|
182
|
+
const importWallet = useCallback(async (importOptions) => {
|
|
183
|
+
var _a, _b, _c, _d, _e, _f;
|
|
184
|
+
setState((s) => ({ ...s, status: 'creating', error: null }));
|
|
185
|
+
try {
|
|
186
|
+
if (!walletConfig) {
|
|
187
|
+
throw new OpenfortError('Wallet config not found', OpenfortReactErrorType.CONFIGURATION_ERROR);
|
|
188
|
+
}
|
|
189
|
+
const recoveryParams = await buildRecoveryParams({
|
|
190
|
+
recoveryMethod: importOptions.recoveryMethod,
|
|
191
|
+
passkeyId: importOptions.passkeyId,
|
|
192
|
+
password: importOptions.password,
|
|
193
|
+
otpCode: importOptions.otpCode,
|
|
194
|
+
}, {
|
|
195
|
+
walletConfig,
|
|
196
|
+
getAccessToken: () => client.getAccessToken(),
|
|
197
|
+
getUserId: async () => {
|
|
198
|
+
const user = await client.user.get();
|
|
199
|
+
return user === null || user === void 0 ? void 0 : user.id;
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
const accountType = (_c = (_a = importOptions.accountType) !== null && _a !== void 0 ? _a : (_b = walletConfig === null || walletConfig === void 0 ? void 0 : walletConfig.ethereum) === null || _b === void 0 ? void 0 : _b.accountType) !== null && _c !== void 0 ? _c : DEFAULT_ACCOUNT_TYPE;
|
|
203
|
+
const account = await client.embeddedWallet.import({
|
|
204
|
+
privateKey: importOptions.privateKey,
|
|
205
|
+
chainType: ChainTypeEnum.EVM,
|
|
206
|
+
accountType,
|
|
207
|
+
...(accountType !== DEFAULT_ACCOUNT_TYPE && { chainId: (_d = importOptions.chainId) !== null && _d !== void 0 ? _d : creationChainId }),
|
|
208
|
+
recoveryParams,
|
|
209
|
+
});
|
|
210
|
+
setActiveEmbeddedAddress(account.address);
|
|
211
|
+
await updateEmbeddedAccounts({ silent: true });
|
|
212
|
+
const provider = await getEmbeddedEthereumProvider();
|
|
213
|
+
const connectedWallet = buildConnectedWallet(account, 0, async () => provider, {
|
|
214
|
+
isActive: true,
|
|
215
|
+
isConnecting: false,
|
|
216
|
+
});
|
|
217
|
+
setState({
|
|
218
|
+
status: 'connected',
|
|
219
|
+
activeWallet: connectedWallet,
|
|
220
|
+
provider,
|
|
221
|
+
error: null,
|
|
222
|
+
});
|
|
223
|
+
(_e = importOptions.onSuccess) === null || _e === void 0 ? void 0 : _e.call(importOptions, { account });
|
|
224
|
+
return account;
|
|
225
|
+
}
|
|
226
|
+
catch (err) {
|
|
227
|
+
const error = err instanceof OpenfortError
|
|
228
|
+
? err
|
|
229
|
+
: new OpenfortError('Failed to import Ethereum wallet', OpenfortReactErrorType.WALLET_ERROR, { error: err });
|
|
230
|
+
setState((s) => ({
|
|
231
|
+
...s,
|
|
232
|
+
status: 'error',
|
|
233
|
+
error: error.message,
|
|
234
|
+
}));
|
|
235
|
+
(_f = importOptions.onError) === null || _f === void 0 ? void 0 : _f.call(importOptions, error);
|
|
236
|
+
throw error;
|
|
237
|
+
}
|
|
238
|
+
}, [
|
|
239
|
+
client,
|
|
240
|
+
walletConfig,
|
|
241
|
+
creationChainId,
|
|
242
|
+
getEmbeddedEthereumProvider,
|
|
243
|
+
updateEmbeddedAccounts,
|
|
244
|
+
setActiveEmbeddedAddress,
|
|
245
|
+
]);
|
|
182
246
|
const setActive = useCallback(async (activeOptions) => {
|
|
183
247
|
const run = async () => {
|
|
184
248
|
var _a, _b, _c, _d, _e;
|
|
@@ -302,11 +366,12 @@ function useEthereumEmbeddedWallet(options) {
|
|
|
302
366
|
}, [client]);
|
|
303
367
|
const actions = useMemo(() => ({
|
|
304
368
|
create,
|
|
369
|
+
import: importWallet,
|
|
305
370
|
wallets,
|
|
306
371
|
setActive,
|
|
307
372
|
setRecovery,
|
|
308
373
|
exportPrivateKey,
|
|
309
|
-
}), [create, wallets, setActive, setRecovery, exportPrivateKey]);
|
|
374
|
+
}), [create, importWallet, wallets, setActive, setRecovery, exportPrivateKey]);
|
|
310
375
|
// Use refs for values that should NOT re-trigger the sync effect.
|
|
311
376
|
const stateRef = useRef(state);
|
|
312
377
|
stateRef.current = state;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEthereumEmbeddedWallet.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useEthereumEmbeddedWallet.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { AccountTypeEnum, ChainTypeEnum, EmbeddedAccount, RecoveryMethod, RecoveryParams } from '@openfort/openfort-js';
|
|
7
7
|
import type { Hex } from 'viem';
|
|
8
|
-
import type { ConnectedWalletState, CreateEmbeddedWalletOptions, SetActiveEmbeddedWalletOptionsBase, SetRecoveryOptions as SharedSetRecoveryOptions, WalletDerived } from '../shared/types';
|
|
8
|
+
import type { ConnectedWalletState, CreateEmbeddedWalletOptions, ImportEmbeddedWalletOptions, SetActiveEmbeddedWalletOptionsBase, SetRecoveryOptions as SharedSetRecoveryOptions, WalletDerived } from '../shared/types';
|
|
9
9
|
export type FeeSponsorshipConfig = string | Record<number, string>;
|
|
10
10
|
export type EthereumConfig = {
|
|
11
11
|
/** Initial chain ID for the embedded wallet provider.
|
|
@@ -70,6 +70,8 @@ export type SetActiveEthereumWalletOptions = SetActiveEmbeddedWalletOptionsBase
|
|
|
70
70
|
export interface EthereumWalletActions {
|
|
71
71
|
/** Create a new Ethereum embedded wallet */
|
|
72
72
|
create(options?: CreateEmbeddedWalletOptions): Promise<EmbeddedAccount>;
|
|
73
|
+
/** Import an Ethereum embedded wallet from a hex-encoded private key */
|
|
74
|
+
import(options: ImportEmbeddedWalletOptions): Promise<EmbeddedAccount>;
|
|
73
75
|
/** List of available Ethereum wallets */
|
|
74
76
|
wallets: ConnectedEmbeddedEthereumWallet[];
|
|
75
77
|
/** Set the active wallet */
|
|
@@ -245,24 +245,13 @@ const CoreOpenfortProvider = ({ children, onConnect, onDisconnect, openfortConfi
|
|
|
245
245
|
}
|
|
246
246
|
// Skip if we already initialized with the same parameters
|
|
247
247
|
const feeSponsorshipPolicy = evmChainId != null ? (_a = resolveEthereumFeeSponsorship(walletConfig, evmChainId)) === null || _a === void 0 ? void 0 : _a.policy : undefined;
|
|
248
|
-
|
|
249
|
-
// from absent → present, we re-init so wallet_switchEthereumChain can finally fire
|
|
250
|
-
// (openfort-js needs the active account set, otherwise it sends `account: null` → 422).
|
|
251
|
-
const hasActiveEmbeddedAddress = !!storeActiveEmbeddedAddress;
|
|
252
|
-
const initKey = {
|
|
253
|
-
kind: strategy.kind,
|
|
254
|
-
chainType: strategy.chainType,
|
|
255
|
-
evmChainId,
|
|
256
|
-
feeSponsorshipPolicy,
|
|
257
|
-
hasActiveEmbeddedAddress,
|
|
258
|
-
};
|
|
248
|
+
const initKey = { kind: strategy.kind, chainType: strategy.chainType, evmChainId, feeSponsorshipPolicy };
|
|
259
249
|
const prev = lastInitRef.current;
|
|
260
250
|
if (prev &&
|
|
261
251
|
prev.kind === initKey.kind &&
|
|
262
252
|
prev.chainType === initKey.chainType &&
|
|
263
253
|
prev.evmChainId === initKey.evmChainId &&
|
|
264
|
-
prev.feeSponsorshipPolicy === initKey.feeSponsorshipPolicy
|
|
265
|
-
prev.hasActiveEmbeddedAddress === initKey.hasActiveEmbeddedAddress) {
|
|
254
|
+
prev.feeSponsorshipPolicy === initKey.feeSponsorshipPolicy) {
|
|
266
255
|
return;
|
|
267
256
|
}
|
|
268
257
|
// Prevent concurrent initProvider calls
|
|
@@ -272,7 +261,7 @@ const CoreOpenfortProvider = ({ children, onConnect, onDisconnect, openfortConfi
|
|
|
272
261
|
initInProgressRef.current = true;
|
|
273
262
|
let cancelled = false;
|
|
274
263
|
strategy
|
|
275
|
-
.initProvider(openfort, walletConfig, evmChainId
|
|
264
|
+
.initProvider(openfort, walletConfig, evmChainId)
|
|
276
265
|
.then(() => {
|
|
277
266
|
if (cancelled)
|
|
278
267
|
return;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CoreOpenfortProvider.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CoreOpenfortProvider.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/build/shared/types.d.ts
CHANGED
|
@@ -63,3 +63,11 @@ export type CreateEmbeddedWalletOptions = {
|
|
|
63
63
|
/** Fee sponsorship ID for gas sponsorship */
|
|
64
64
|
feeSponsorshipId?: string;
|
|
65
65
|
} & OpenfortHookOptions<CreateEmbeddedWalletResult>;
|
|
66
|
+
/**
|
|
67
|
+
* Options for importing an embedded wallet from a raw private key.
|
|
68
|
+
* EVM expects a hex-encoded private key; Solana expects a base58-encoded secret key.
|
|
69
|
+
*/
|
|
70
|
+
export type ImportEmbeddedWalletOptions = CreateEmbeddedWalletOptions & {
|
|
71
|
+
/** Raw private key (hex for EVM, base58 for Solana). */
|
|
72
|
+
privateKey: string;
|
|
73
|
+
};
|
|
@@ -156,6 +156,62 @@ function useSolanaEmbeddedWallet(options) {
|
|
|
156
156
|
throw error;
|
|
157
157
|
}
|
|
158
158
|
}, [client, walletConfig, createProviderForAccount, updateEmbeddedAccounts, setActiveEmbeddedAddress]);
|
|
159
|
+
const importWallet = useCallback(async (importOptions) => {
|
|
160
|
+
var _a, _b;
|
|
161
|
+
setState((s) => ({ ...s, status: 'creating', error: null }));
|
|
162
|
+
try {
|
|
163
|
+
if (!walletConfig) {
|
|
164
|
+
throw new OpenfortError('Wallet config not found', OpenfortReactErrorType.CONFIGURATION_ERROR);
|
|
165
|
+
}
|
|
166
|
+
const recoveryParams = await buildRecoveryParams({
|
|
167
|
+
recoveryMethod: importOptions.recoveryMethod,
|
|
168
|
+
passkeyId: importOptions.passkeyId,
|
|
169
|
+
password: importOptions.password,
|
|
170
|
+
otpCode: importOptions.otpCode,
|
|
171
|
+
}, {
|
|
172
|
+
walletConfig,
|
|
173
|
+
getAccessToken: () => client.getAccessToken(),
|
|
174
|
+
getUserId: () => client.user.get().then((u) => u === null || u === void 0 ? void 0 : u.id),
|
|
175
|
+
});
|
|
176
|
+
const account = await client.embeddedWallet.import({
|
|
177
|
+
privateKey: importOptions.privateKey,
|
|
178
|
+
chainType: ChainTypeEnum.SVM,
|
|
179
|
+
accountType: AccountTypeEnum.EOA,
|
|
180
|
+
recoveryParams,
|
|
181
|
+
});
|
|
182
|
+
setActiveEmbeddedAddress(account.address);
|
|
183
|
+
await updateEmbeddedAccounts({ silent: true });
|
|
184
|
+
const provider = createProviderForAccount(account);
|
|
185
|
+
const connectedWallet = {
|
|
186
|
+
id: account.id,
|
|
187
|
+
address: account.address,
|
|
188
|
+
chainType: ChainTypeEnum.SVM,
|
|
189
|
+
walletIndex: 0,
|
|
190
|
+
recoveryMethod: account.recoveryMethod,
|
|
191
|
+
getProvider: async () => provider,
|
|
192
|
+
};
|
|
193
|
+
setState({
|
|
194
|
+
status: 'connected',
|
|
195
|
+
activeWallet: connectedWallet,
|
|
196
|
+
provider,
|
|
197
|
+
error: null,
|
|
198
|
+
});
|
|
199
|
+
(_a = importOptions.onSuccess) === null || _a === void 0 ? void 0 : _a.call(importOptions, { account });
|
|
200
|
+
return account;
|
|
201
|
+
}
|
|
202
|
+
catch (err) {
|
|
203
|
+
const error = err instanceof OpenfortError
|
|
204
|
+
? err
|
|
205
|
+
: new OpenfortError('Failed to import Solana wallet', OpenfortReactErrorType.WALLET_ERROR, { error: err });
|
|
206
|
+
setState((s) => ({
|
|
207
|
+
...s,
|
|
208
|
+
status: 'error',
|
|
209
|
+
error: error.message,
|
|
210
|
+
}));
|
|
211
|
+
(_b = importOptions.onError) === null || _b === void 0 ? void 0 : _b.call(importOptions, error);
|
|
212
|
+
throw error;
|
|
213
|
+
}
|
|
214
|
+
}, [client, walletConfig, createProviderForAccount, updateEmbeddedAccounts, setActiveEmbeddedAddress]);
|
|
159
215
|
const setActive = useCallback(async (activeOptions) => {
|
|
160
216
|
const run = async () => {
|
|
161
217
|
const accounts = solanaAccountsRef.current;
|
|
@@ -261,11 +317,12 @@ function useSolanaEmbeddedWallet(options) {
|
|
|
261
317
|
}, [client]);
|
|
262
318
|
const actions = useMemo(() => ({
|
|
263
319
|
create,
|
|
320
|
+
import: importWallet,
|
|
264
321
|
wallets,
|
|
265
322
|
setActive,
|
|
266
323
|
setRecovery,
|
|
267
324
|
exportPrivateKey,
|
|
268
|
-
}), [create, wallets, setActive, setRecovery, exportPrivateKey]);
|
|
325
|
+
}), [create, importWallet, wallets, setActive, setRecovery, exportPrivateKey]);
|
|
269
326
|
// Clear local state when core clears activeEmbeddedAddress (e.g. logout).
|
|
270
327
|
useEffect(() => {
|
|
271
328
|
if (!activeEmbeddedAddress && (state.status === 'connected' || state.status === 'needs-recovery')) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSolanaEmbeddedWallet.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useSolanaEmbeddedWallet.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/build/solana/types.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type { ChainTypeEnum, EmbeddedAccount, RecoveryMethod, RecoveryParams } from '@openfort/openfort-js';
|
|
7
7
|
import type React from 'react';
|
|
8
|
-
import type { ConnectedWalletState, CreateEmbeddedWalletOptions, SetActiveEmbeddedWalletOptionsBase, SetRecoveryOptions as SetRecoveryOptionsBase, WalletDerived } from '../shared/types';
|
|
8
|
+
import type { ConnectedWalletState, CreateEmbeddedWalletOptions, ImportEmbeddedWalletOptions, SetActiveEmbeddedWalletOptionsBase, SetRecoveryOptions as SetRecoveryOptionsBase, WalletDerived } from '../shared/types';
|
|
9
9
|
/**
|
|
10
10
|
* Solana cluster identifier
|
|
11
11
|
*/
|
|
@@ -177,6 +177,8 @@ export type SetActiveSolanaWalletOptions = SetActiveEmbeddedWalletOptionsBase &
|
|
|
177
177
|
export interface SolanaWalletActions {
|
|
178
178
|
/** Create a new Solana embedded wallet */
|
|
179
179
|
create(options?: CreateEmbeddedWalletOptions): Promise<EmbeddedAccount>;
|
|
180
|
+
/** Import a Solana embedded wallet from a base58-encoded secret key */
|
|
181
|
+
import(options: ImportEmbeddedWalletOptions): Promise<EmbeddedAccount>;
|
|
180
182
|
/** List of available Solana wallets */
|
|
181
183
|
wallets: ConnectedEmbeddedSolanaWallet[];
|
|
182
184
|
/** Set the active wallet */
|
package/build/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const OPENFORT_VERSION = "1.0.
|
|
1
|
+
export declare const OPENFORT_VERSION = "1.0.16";
|
package/build/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openfort/react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16",
|
|
4
4
|
"author": "Openfort (https://www.openfort.io)",
|
|
5
5
|
"license": "BSD-2-Clause license",
|
|
6
6
|
"description": "The easiest way to integrate Openfort to your project.",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"react"
|
|
66
66
|
],
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"@openfort/openfort-js": "
|
|
68
|
+
"@openfort/openfort-js": "1.3.4",
|
|
69
69
|
"buffer": "^6.0.3",
|
|
70
70
|
"detect-browser": "^5.3.0",
|
|
71
71
|
"fast-password-entropy": "^1.1.1",
|