@openfort/react 1.0.15 → 1.1.0

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.
@@ -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 */
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -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 */
@@ -1 +1 @@
1
- export declare const OPENFORT_VERSION = "1.0.15";
1
+ export declare const OPENFORT_VERSION = "1.1.0";
package/build/version.js CHANGED
@@ -1,4 +1,4 @@
1
- const OPENFORT_VERSION = '1.0.15';
1
+ const OPENFORT_VERSION = '1.1.0';
2
2
 
3
3
  export { OPENFORT_VERSION };
4
4
  //# sourceMappingURL=version.js.map
@@ -13,7 +13,6 @@ const defaultConnectors = ({ app, walletConnectProjectId, coinbaseWalletPreferen
13
13
  connectors.push(coinbaseWallet({
14
14
  appName: app.name,
15
15
  appLogoUrl: app.icon,
16
- overrideIsMetaMask: false,
17
16
  preference: coinbaseWalletPreference,
18
17
  }));
19
18
  if (walletConnectProjectId) {
@@ -1 +1 @@
1
- {"version":3,"file":"defaultConnectors.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"defaultConnectors.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -62,6 +62,20 @@ function embeddedWalletConnector() {
62
62
  async getProvider() {
63
63
  return _provider !== null && _provider !== void 0 ? _provider : undefined;
64
64
  },
65
+ async switchChain({ chainId }) {
66
+ const provider = _provider;
67
+ if (!provider)
68
+ throw new Error('Embedded wallet provider not ready');
69
+ const chain = config.chains.find((c) => c.id === chainId);
70
+ if (!chain)
71
+ throw new Error(`Chain ${chainId} is not configured`);
72
+ await provider.request({
73
+ method: 'wallet_switchEthereumChain',
74
+ params: [{ chainId: `0x${chainId.toString(16)}` }],
75
+ });
76
+ config.emitter.emit('change', { chainId });
77
+ return chain;
78
+ },
65
79
  async isAuthorized() {
66
80
  if (!_provider)
67
81
  return false;
@@ -1 +1 @@
1
- {"version":3,"file":"embeddedConnector.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"embeddedConnector.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfort/react",
3
- "version": "1.0.15",
3
+ "version": "1.1.0",
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,47 +65,55 @@
65
65
  "react"
66
66
  ],
67
67
  "dependencies": {
68
- "@openfort/openfort-js": "1.3.3",
68
+ "@openfort/openfort-js": "^1.3.5",
69
69
  "buffer": "^6.0.3",
70
70
  "detect-browser": "^5.3.0",
71
71
  "fast-password-entropy": "^1.1.1",
72
72
  "framer-motion": "^6.3.11",
73
73
  "qrcode": "^1.5.0",
74
74
  "react-international-phone": "^4.6.0",
75
- "react-is": "^19.1.0",
75
+ "react-is": "^19.2.7",
76
76
  "react-transition-state": "^1.1.4",
77
77
  "react-use-measure": "^2.1.1",
78
78
  "resize-observer-polyfill": "^1.5.1",
79
79
  "styled-components": "^5.3.5",
80
- "zustand": "^5.0.11"
80
+ "zustand": "^5.0.14"
81
81
  },
82
82
  "peerDependencies": {
83
+ "@coinbase/wallet-sdk": "^4.3.6",
84
+ "@safe-global/safe-apps-provider": "~0.18.6",
85
+ "@safe-global/safe-apps-sdk": "^9.1.0",
83
86
  "@solana/kit": "^2.0.0 || ^5.0.0",
87
+ "@walletconnect/ethereum-provider": "^2.21.1",
84
88
  "react": "17.x || 18.x || 19.x",
85
89
  "react-dom": "17.x || 18.x || 19.x",
86
90
  "viem": "2.x",
87
- "wagmi": "2.x"
91
+ "wagmi": "3.x"
88
92
  },
89
93
  "devDependencies": {
90
- "@biomejs/biome": "^2.3.8",
91
- "@tanstack/react-query": "^5.90.21",
94
+ "@biomejs/biome": "^2.4.16",
95
+ "@coinbase/wallet-sdk": "^4.3.7",
96
+ "@safe-global/safe-apps-provider": "~0.18.6",
97
+ "@safe-global/safe-apps-sdk": "^9.1.0",
98
+ "@tanstack/react-query": "^5.101.0",
92
99
  "@testing-library/react": "^16.3.2",
93
100
  "@testing-library/react-hooks": "^8.0.1",
94
- "@types/node": "18.7.18",
101
+ "@types/node": "^25.9.2",
95
102
  "@types/qrcode": "^1.4.2",
96
103
  "@types/react": "^18.0.6",
97
104
  "@types/react-dom": "^18.0.2",
98
105
  "@types/styled-components": "^5.1.25",
99
- "@wagmi/connectors": "^6.2.0",
100
- "@wagmi/core": "^2.22.1",
101
- "happy-dom": "^20.8.9",
102
- "jsdom": "^28.1.0",
106
+ "@wagmi/connectors": "^8.0.15",
107
+ "@wagmi/core": "^3.5.0",
108
+ "@walletconnect/ethereum-provider": "^2.23.9",
109
+ "happy-dom": "^20.10.2",
110
+ "jsdom": "^29.1.1",
103
111
  "rollup-plugin-peer-deps-external": "^2.2.4",
104
- "rollup-plugin-typescript2": "^0.36.0",
105
- "typescript": "^5.0.4",
112
+ "rollup-plugin-typescript2": "^0.37.0",
113
+ "typescript": "^5.9.3",
106
114
  "typescript-plugin-styled-components": "^2.0.0",
107
- "vitest": "^2.0.0",
108
- "wagmi": "^2.18.2"
115
+ "vitest": "^4.1.0",
116
+ "wagmi": "^3.6.16"
109
117
  },
110
118
  "peerDependenciesMeta": {
111
119
  "@solana/kit": {
@@ -114,6 +122,18 @@
114
122
  "wagmi": {
115
123
  "optional": true
116
124
  },
125
+ "@coinbase/wallet-sdk": {
126
+ "optional": true
127
+ },
128
+ "@walletconnect/ethereum-provider": {
129
+ "optional": true
130
+ },
131
+ "@safe-global/safe-apps-provider": {
132
+ "optional": true
133
+ },
134
+ "@safe-global/safe-apps-sdk": {
135
+ "optional": true
136
+ },
117
137
  "@tanstack/react-query": {
118
138
  "optional": true
119
139
  }