@zerodev/wallet-react 0.0.1-alpha.1 → 0.0.1-alpha.11

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/README.md +30 -17
  3. package/dist/_cjs/actions.js +62 -24
  4. package/dist/_cjs/connector.js +82 -48
  5. package/dist/_cjs/hooks/useExportPrivateKey.js +18 -0
  6. package/dist/_cjs/hooks/useGetUserEmail.js +19 -0
  7. package/dist/_cjs/index.js +8 -1
  8. package/dist/_cjs/oauth.js +60 -55
  9. package/dist/_cjs/provider.js +5 -2
  10. package/dist/_cjs/store.js +4 -9
  11. package/dist/_esm/actions.js +74 -27
  12. package/dist/_esm/connector.js +98 -55
  13. package/dist/_esm/hooks/useExportPrivateKey.js +18 -0
  14. package/dist/_esm/hooks/useGetUserEmail.js +19 -0
  15. package/dist/_esm/index.js +3 -1
  16. package/dist/_esm/oauth.js +71 -53
  17. package/dist/_esm/provider.js +5 -2
  18. package/dist/_esm/store.js +4 -10
  19. package/dist/_types/actions.d.ts +35 -6
  20. package/dist/_types/actions.d.ts.map +1 -1
  21. package/dist/_types/connector.d.ts +0 -2
  22. package/dist/_types/connector.d.ts.map +1 -1
  23. package/dist/_types/hooks/useExportPrivateKey.d.ts +18 -0
  24. package/dist/_types/hooks/useExportPrivateKey.d.ts.map +1 -0
  25. package/dist/_types/hooks/useGetUserEmail.d.ts +18 -0
  26. package/dist/_types/hooks/useGetUserEmail.d.ts.map +1 -0
  27. package/dist/_types/index.d.ts +4 -2
  28. package/dist/_types/index.d.ts.map +1 -1
  29. package/dist/_types/oauth.d.ts +25 -12
  30. package/dist/_types/oauth.d.ts.map +1 -1
  31. package/dist/_types/provider.d.ts.map +1 -1
  32. package/dist/_types/store.d.ts +11 -7
  33. package/dist/_types/store.d.ts.map +1 -1
  34. package/dist/tsconfig.build.tsbuildinfo +1 -1
  35. package/package.json +2 -2
  36. package/src/actions.test.ts +895 -0
  37. package/src/actions.ts +124 -44
  38. package/src/connector.ts +117 -65
  39. package/src/hooks/useExportPrivateKey.ts +57 -0
  40. package/src/hooks/useGetUserEmail.ts +52 -0
  41. package/src/index.ts +9 -2
  42. package/src/oauth.test.ts +445 -0
  43. package/src/oauth.ts +97 -78
  44. package/src/provider.ts +5 -2
  45. package/src/store.ts +15 -16
  46. package/tsconfig.build.tsbuildinfo +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,79 @@
1
1
  # @zerodev/wallet-react
2
2
 
3
+ ## 0.0.1-alpha.11
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @zerodev/wallet-core@0.0.1-alpha.10
9
+
10
+ ## 0.0.1-alpha.10
11
+
12
+ ### Patch Changes
13
+
14
+ - fix: use session.token for getUserEmail auth headers
15
+ - Updated dependencies
16
+ - @zerodev/wallet-core@0.0.1-alpha.9
17
+
18
+ ## 0.0.1-alpha.9
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies
23
+ - @zerodev/wallet-core@0.0.1-alpha.8
24
+
25
+ ## 0.0.1-alpha.8
26
+
27
+ ### Patch Changes
28
+
29
+ - fix: use internal state for get user email
30
+
31
+ ## 0.0.1-alpha.7
32
+
33
+ ### Patch Changes
34
+
35
+ - Add OTP authentication via Turnkey Auth Proxy
36
+ - Add OAuth backend PKCE flow
37
+ - Add getUserEmail method and React hook
38
+ - Fix passkey login endpoint
39
+ - Fix signature verification with JSON canonicalization
40
+ - Rename turnkeySession to session in OAuth response
41
+ - Updated dependencies
42
+ - @zerodev/wallet-core@0.0.1-alpha.7
43
+
44
+ ## 0.0.1-alpha.6
45
+
46
+ ### Patch Changes
47
+
48
+ - feat: Added private key export feature
49
+ - Updated dependencies
50
+ - @zerodev/wallet-core@0.0.1-alpha.6
51
+
52
+ ## 0.0.1-alpha.5
53
+
54
+ ### Patch Changes
55
+
56
+ - refactor: Simplify chain state management by replacing chainIds array with activeChainId
57
+
58
+ ## 0.0.1-alpha.4
59
+
60
+ ### Patch Changes
61
+
62
+ - fix: kernel instance reinitialisation
63
+
64
+ ## 0.0.1-alpha.3
65
+
66
+ ### Patch Changes
67
+
68
+ - fix: removed lazy initialization of ZD wallet core
69
+
70
+ ## 0.0.1-alpha.2
71
+
72
+ ### Patch Changes
73
+
74
+ - Updated dependencies
75
+ - @zerodev/wallet-core@0.0.1-alpha.5
76
+
3
77
  ## 0.0.1-alpha.1
4
78
 
5
79
  ### Patch Changes
package/README.md CHANGED
@@ -36,12 +36,7 @@ const config = createConfig({
36
36
  connectors: [
37
37
  zeroDevWallet({
38
38
  projectId: 'YOUR_PROJECT_ID',
39
- aaUrl: 'YOUR_AA_PROVIDER_URL',
40
39
  chains: [sepolia],
41
- oauthConfig: {
42
- googleClientId: 'YOUR_GOOGLE_CLIENT_ID',
43
- redirectUri: 'http://localhost:3000',
44
- },
45
40
  })
46
41
  ],
47
42
  transports: {
@@ -150,7 +145,8 @@ await loginPasskey.mutateAsync({ email: 'user@example.com' })
150
145
  ```typescript
151
146
  const authenticateOAuth = useAuthenticateOAuth()
152
147
 
153
- // Opens popup automatically, handles token exchange
148
+ // Opens popup, backend handles PKCE and token exchange
149
+ // No callback page or OAuth library needed - SDK handles everything
154
150
  await authenticateOAuth.mutateAsync({
155
151
  provider: OAUTH_PROVIDERS.GOOGLE
156
152
  })
@@ -163,7 +159,7 @@ const sendOTP = useSendOTP()
163
159
  const verifyOTP = useVerifyOTP()
164
160
 
165
161
  // Send OTP code
166
- const { otpId, subOrganizationId } = await sendOTP.mutateAsync({
162
+ const { otpId } = await sendOTP.mutateAsync({
167
163
  email: 'user@example.com'
168
164
  })
169
165
 
@@ -171,7 +167,6 @@ const { otpId, subOrganizationId } = await sendOTP.mutateAsync({
171
167
  await verifyOTP.mutateAsync({
172
168
  code: '123456',
173
169
  otpId,
174
- subOrganizationId
175
170
  })
176
171
  ```
177
172
 
@@ -182,18 +177,11 @@ type ZeroDevWalletConnectorParams = {
182
177
  projectId: string // Required: Your ZeroDev project ID
183
178
  organizationId?: string // Optional: Turnkey organization ID
184
179
  proxyBaseUrl?: string // Optional: KMS proxy URL
185
- aaUrl: string // Required: Bundler/paymaster URL
186
180
  chains: readonly Chain[] // Required: Supported chains
187
181
  rpId?: string // Optional: WebAuthn RP ID
188
182
  sessionStorage?: StorageAdapter // Optional: Custom session storage
189
183
  autoRefreshSession?: boolean // Optional: Auto-refresh (default: true)
190
184
  sessionWarningThreshold?: number // Optional: Refresh threshold in ms (default: 60000)
191
- oauthConfig?: OAuthConfig // Optional: OAuth configuration
192
- }
193
-
194
- type OAuthConfig = {
195
- googleClientId?: string
196
- redirectUri: string
197
185
  }
198
186
  ```
199
187
 
@@ -224,16 +212,40 @@ const refreshSession = useRefreshSession()
224
212
  await refreshSession.mutateAsync({})
225
213
  ```
226
214
 
227
- ### Export Wallet
215
+ ### Export Wallet (Seed Phrase)
228
216
 
229
217
  ```typescript
230
218
  const exportWallet = useExportWallet()
231
219
 
220
+ // Container element must exist: <div id="export-container" />
232
221
  await exportWallet.mutateAsync({
233
222
  iframeContainerId: 'export-container'
234
223
  })
235
224
  ```
236
225
 
226
+ ### Export Private Key
227
+
228
+ ```typescript
229
+ const exportPrivateKey = useExportPrivateKey()
230
+
231
+ // Container element must exist: <div id="export-container" />
232
+ await exportPrivateKey.mutateAsync({
233
+ iframeContainerId: 'export-container'
234
+ })
235
+ ```
236
+
237
+ ### Get User Email
238
+
239
+ ```typescript
240
+ const getUserEmail = useGetUserEmail()
241
+
242
+ // Fetch user's email from the backend
243
+ const { email } = await getUserEmail.mutateAsync({
244
+ organizationId: session.organizationId,
245
+ projectId: 'your-project-id'
246
+ })
247
+ ```
248
+
237
249
  ## API Reference
238
250
 
239
251
  ### Hooks
@@ -247,6 +259,8 @@ All hooks follow the TanStack Query mutation pattern:
247
259
  - `useVerifyOTP()` - Verify OTP code
248
260
  - `useRefreshSession()` - Manually refresh session
249
261
  - `useExportWallet()` - Export wallet seed phrase
262
+ - `useExportPrivateKey()` - Export wallet private key
263
+ - `useGetUserEmail()` - Get user's email address
250
264
 
251
265
  ### Connector
252
266
 
@@ -259,7 +273,6 @@ All hooks follow the TanStack Query mutation pattern:
259
273
  ### Types
260
274
 
261
275
  - `OAuthProvider` - OAuth provider type
262
- - `OAuthConfig` - OAuth configuration type
263
276
  - `ZeroDevWalletConnectorParams` - Connector parameters
264
277
  - `ZeroDevWalletState` - Store state type
265
278
  - `ZeroDevProvider` - EIP-1193 provider type
@@ -6,8 +6,11 @@ exports.authenticateOAuth = authenticateOAuth;
6
6
  exports.sendOTP = sendOTP;
7
7
  exports.verifyOTP = verifyOTP;
8
8
  exports.refreshSession = refreshSession;
9
+ exports.getUserEmail = getUserEmail;
9
10
  exports.exportWallet = exportWallet;
11
+ exports.exportPrivateKey = exportPrivateKey;
10
12
  const actions_1 = require("@wagmi/core/actions");
13
+ const wallet_core_1 = require("@zerodev/wallet-core");
11
14
  const oauth_js_1 = require("./oauth.js");
12
15
  function getZeroDevConnector(config) {
13
16
  const connector = config.connectors.find((c) => c.id === 'zerodev-wallet');
@@ -62,40 +65,29 @@ async function authenticateOAuth(config, parameters) {
62
65
  if (!wallet)
63
66
  throw new Error('Wallet not initialized');
64
67
  if (!oauthConfig) {
65
- throw new Error('OAuth is not configured. Please provide oauthConfig to zeroDevWallet connector.');
66
- }
67
- let clientId = parameters.clientId;
68
- if (!clientId) {
69
- clientId = oauthConfig.googleClientId;
70
- }
71
- if (!clientId) {
72
- throw new Error(`Client ID not configured for ${parameters.provider}`);
73
- }
74
- if (!oauthConfig.redirectUri) {
75
- throw new Error('OAuth redirect URI is not configured.');
68
+ throw new Error('Wallet not initialized. Please wait for connector setup.');
76
69
  }
77
70
  const publicKey = await wallet.getPublicKey();
78
71
  if (!publicKey) {
79
72
  throw new Error('Failed to get wallet public key');
80
73
  }
81
- const nonce = (0, oauth_js_1.generateOAuthNonce)(publicKey);
82
- const oauthUrl = (0, oauth_js_1.buildOAuthUrl)({
74
+ const oauthUrl = (0, oauth_js_1.buildBackendOAuthUrl)({
83
75
  provider: parameters.provider,
84
- clientId,
85
- redirectUri: oauthConfig.redirectUri,
86
- nonce,
76
+ backendUrl: oauthConfig.backendUrl,
77
+ projectId: oauthConfig.projectId,
78
+ publicKey,
79
+ returnTo: `${window.location.origin}?oauth_success=true&oauth_provider=${parameters.provider}`,
87
80
  });
88
81
  const authWindow = (0, oauth_js_1.openOAuthPopup)(oauthUrl);
89
82
  if (!authWindow) {
90
83
  throw new Error(`Failed to open ${parameters.provider} login window.`);
91
84
  }
92
85
  return new Promise((resolve, reject) => {
93
- (0, oauth_js_1.pollOAuthPopup)(authWindow, window.location.origin, async (idToken) => {
86
+ const cleanup = (0, oauth_js_1.listenForOAuthMessage)(authWindow, window.location.origin, async () => {
94
87
  try {
95
88
  await wallet.auth({
96
89
  type: 'oauth',
97
90
  provider: parameters.provider,
98
- credential: idToken,
99
91
  });
100
92
  const [session, eoaAccount] = await Promise.all([
101
93
  wallet.getSession(),
@@ -109,7 +101,10 @@ async function authenticateOAuth(config, parameters) {
109
101
  catch (err) {
110
102
  reject(err);
111
103
  }
112
- }, reject);
104
+ }, (error) => {
105
+ cleanup();
106
+ reject(error);
107
+ });
113
108
  });
114
109
  }
115
110
  async function sendOTP(config, parameters) {
@@ -129,7 +124,6 @@ async function sendOTP(config, parameters) {
129
124
  });
130
125
  return {
131
126
  otpId: result.otpId,
132
- subOrganizationId: result.subOrganizationId,
133
127
  };
134
128
  }
135
129
  async function verifyOTP(config, parameters) {
@@ -143,7 +137,6 @@ async function verifyOTP(config, parameters) {
143
137
  mode: 'verifyOtp',
144
138
  otpId: parameters.otpId,
145
139
  otpCode: parameters.code,
146
- subOrganizationId: parameters.subOrganizationId,
147
140
  });
148
141
  const [session, eoaAccount] = await Promise.all([
149
142
  wallet.getSession(),
@@ -165,24 +158,43 @@ async function refreshSession(config, parameters = {}) {
165
158
  store.getState().setSession(newSession || null);
166
159
  return newSession;
167
160
  }
161
+ async function getUserEmail(config) {
162
+ const connector = getZeroDevConnector(config);
163
+ const store = await connector.getStore();
164
+ const wallet = store.getState().wallet;
165
+ if (!wallet)
166
+ throw new Error('Wallet not initialized');
167
+ const oauthConfig = store.getState().oauthConfig;
168
+ if (!oauthConfig) {
169
+ throw new Error('Wallet not initialized. Please wait for connector setup.');
170
+ }
171
+ const session = store.getState().session;
172
+ if (!session) {
173
+ throw new Error('No active session');
174
+ }
175
+ return await wallet.client.getUserEmail({
176
+ organizationId: session.organizationId,
177
+ projectId: oauthConfig.projectId,
178
+ token: session.token,
179
+ });
180
+ }
168
181
  async function exportWallet(config, parameters) {
169
182
  const connector = parameters.connector ?? getZeroDevConnector(config);
170
183
  const store = await connector.getStore();
171
184
  const wallet = store.getState().wallet;
172
185
  if (!wallet)
173
186
  throw new Error('Wallet not initialized');
174
- const { exportWallet: exportWalletSdk, createIframeStamper } = await Promise.resolve().then(() => require('@zerodev/wallet-core'));
175
187
  const iframeContainer = document.getElementById(parameters.iframeContainerId);
176
188
  if (!iframeContainer) {
177
189
  throw new Error('Iframe container not found');
178
190
  }
179
- const iframeStamper = await createIframeStamper({
191
+ const iframeStamper = await (0, wallet_core_1.createIframeStamper)({
180
192
  iframeUrl: 'https://export.turnkey.com',
181
193
  iframeContainer,
182
194
  iframeElementId: 'export-wallet-iframe',
183
195
  });
184
196
  const publicKey = await iframeStamper.init();
185
- const { exportBundle, organizationId } = await exportWalletSdk({
197
+ const { exportBundle, organizationId } = await (0, wallet_core_1.exportWallet)({
186
198
  wallet,
187
199
  targetPublicKey: publicKey,
188
200
  });
@@ -191,3 +203,29 @@ async function exportWallet(config, parameters) {
191
203
  throw new Error('Failed to inject export bundle');
192
204
  }
193
205
  }
206
+ async function exportPrivateKey(config, parameters) {
207
+ const connector = parameters.connector ?? getZeroDevConnector(config);
208
+ const store = await connector.getStore();
209
+ const wallet = store.getState().wallet;
210
+ if (!wallet)
211
+ throw new Error('Wallet not initialized');
212
+ const iframeContainer = document.getElementById(parameters.iframeContainerId);
213
+ if (!iframeContainer) {
214
+ throw new Error('Iframe container not found');
215
+ }
216
+ const iframeStamper = await (0, wallet_core_1.createIframeStamper)({
217
+ iframeUrl: 'https://export.turnkey.com',
218
+ iframeContainer,
219
+ iframeElementId: 'export-private-key-iframe',
220
+ });
221
+ const publicKey = await iframeStamper.init();
222
+ const { exportBundle, organizationId } = await (0, wallet_core_1.exportPrivateKey)({
223
+ wallet,
224
+ targetPublicKey: publicKey,
225
+ ...(parameters.address && { address: parameters.address }),
226
+ });
227
+ const success = await iframeStamper.injectKeyExportBundle(exportBundle, organizationId, parameters.keyFormat ?? 'Hexadecimal');
228
+ if (success !== true) {
229
+ throw new Error('Failed to inject export bundle');
230
+ }
231
+ }
@@ -6,51 +6,86 @@ const sdk_1 = require("@zerodev/sdk");
6
6
  const constants_1 = require("@zerodev/sdk/constants");
7
7
  const wallet_core_1 = require("@zerodev/wallet-core");
8
8
  const viem_1 = require("viem");
9
+ const oauth_js_1 = require("./oauth.js");
9
10
  const provider_js_1 = require("./provider.js");
10
11
  const store_js_1 = require("./store.js");
11
12
  const aaUtils_js_1 = require("./utils/aaUtils.js");
13
+ const OAUTH_SUCCESS_PARAM = 'oauth_success';
14
+ const OAUTH_PROVIDER_PARAM = 'oauth_provider';
15
+ async function detectAndHandleOAuthCallback(wallet, store) {
16
+ if (typeof window === 'undefined')
17
+ return false;
18
+ const params = new URLSearchParams(window.location.search);
19
+ const isOAuthCallback = params.get(OAUTH_SUCCESS_PARAM) === 'true';
20
+ if (!isOAuthCallback)
21
+ return false;
22
+ if (window.opener) {
23
+ (0, oauth_js_1.handleOAuthCallback)(OAUTH_SUCCESS_PARAM);
24
+ return true;
25
+ }
26
+ console.log('OAuth callback detected, completing authentication...');
27
+ const provider = (params.get(OAUTH_PROVIDER_PARAM) ||
28
+ 'google');
29
+ try {
30
+ await wallet.auth({ type: 'oauth', provider });
31
+ const [session, eoaAccount] = await Promise.all([
32
+ wallet.getSession(),
33
+ wallet.toAccount(),
34
+ ]);
35
+ store.getState().setEoaAccount(eoaAccount);
36
+ store.getState().setSession(session || null);
37
+ params.delete(OAUTH_SUCCESS_PARAM);
38
+ params.delete(OAUTH_PROVIDER_PARAM);
39
+ const newUrl = params.toString()
40
+ ? `${window.location.pathname}?${params.toString()}`
41
+ : window.location.pathname;
42
+ window.history.replaceState({}, '', newUrl);
43
+ console.log('OAuth authentication completed');
44
+ return true;
45
+ }
46
+ catch (error) {
47
+ console.error('OAuth authentication failed:', error);
48
+ return false;
49
+ }
50
+ }
12
51
  function zeroDevWallet(params) {
13
52
  return (0, core_1.createConnector)((wagmiConfig) => {
14
53
  let store;
15
54
  let provider;
16
- let initPromise;
17
55
  const transports = wagmiConfig.transports;
18
56
  const initialize = async () => {
19
- initPromise ??= (async () => {
20
- console.log('Initializing ZeroDevWallet connector...');
21
- const wallet = await (0, wallet_core_1.createZeroDevWallet)({
22
- projectId: params.projectId,
23
- ...(params.organizationId && {
24
- organizationId: params.organizationId,
25
- }),
26
- ...(params.proxyBaseUrl && { proxyBaseUrl: params.proxyBaseUrl }),
27
- ...(params.sessionStorage && {
28
- sessionStorage: params.sessionStorage,
29
- }),
30
- ...(params.rpId && { rpId: params.rpId }),
31
- });
32
- store = (0, store_js_1.createZeroDevWalletStore)();
33
- store.getState().setWallet(wallet);
34
- const chainIds = params.chains.map((c) => c.id);
35
- store.setState({ chainIds });
36
- if (params.oauthConfig) {
37
- store.getState().setOAuthConfig(params.oauthConfig);
38
- }
39
- provider = (0, provider_js_1.createProvider)({
40
- store,
41
- config: params,
42
- chains: Array.from(params.chains),
43
- });
44
- const session = await wallet.getSession();
45
- if (session) {
46
- console.log('Found existing session, restoring...');
47
- const eoaAccount = await wallet.toAccount();
48
- store.getState().setEoaAccount(eoaAccount);
49
- store.getState().setSession(session);
50
- }
51
- console.log('ZeroDevWallet connector initialized');
52
- })();
53
- return initPromise;
57
+ console.log('Initializing ZeroDevWallet connector...');
58
+ const wallet = await (0, wallet_core_1.createZeroDevWallet)({
59
+ projectId: params.projectId,
60
+ ...(params.organizationId && {
61
+ organizationId: params.organizationId,
62
+ }),
63
+ ...(params.proxyBaseUrl && { proxyBaseUrl: params.proxyBaseUrl }),
64
+ ...(params.sessionStorage && {
65
+ sessionStorage: params.sessionStorage,
66
+ }),
67
+ ...(params.rpId && { rpId: params.rpId }),
68
+ });
69
+ store = (0, store_js_1.createZeroDevWalletStore)();
70
+ store.getState().setWallet(wallet);
71
+ store.getState().setOAuthConfig({
72
+ backendUrl: params.proxyBaseUrl || `${wallet_core_1.KMS_SERVER_URL}/api/v1`,
73
+ projectId: params.projectId,
74
+ });
75
+ provider = (0, provider_js_1.createProvider)({
76
+ store,
77
+ config: params,
78
+ chains: Array.from(params.chains),
79
+ });
80
+ const session = await wallet.getSession();
81
+ if (session) {
82
+ console.log('Found existing session, restoring...');
83
+ const eoaAccount = await wallet.toAccount();
84
+ store.getState().setEoaAccount(eoaAccount);
85
+ store.getState().setSession(session);
86
+ }
87
+ await detectAndHandleOAuthCallback(wallet, store);
88
+ console.log('ZeroDevWallet connector initialized');
54
89
  };
55
90
  return {
56
91
  id: 'zerodev-wallet',
@@ -69,10 +104,7 @@ function zeroDevWallet(params) {
69
104
  ? 'Reconnecting ZeroDevWallet...'
70
105
  : 'Connecting ZeroDevWallet...');
71
106
  const state = store.getState();
72
- const activeChainId = chainId || state.chainIds[0];
73
- if (!activeChainId) {
74
- throw new Error('No chain configured');
75
- }
107
+ const activeChainId = chainId ?? state.activeChainId ?? params.chains[0].id;
76
108
  if (isReconnecting && state.kernelAccounts.has(activeChainId)) {
77
109
  const kernelAccount = state.kernelAccounts.get(activeChainId);
78
110
  if (kernelAccount?.address) {
@@ -115,7 +147,7 @@ function zeroDevWallet(params) {
115
147
  });
116
148
  store.getState().setKernelClient(activeChainId, kernelClient);
117
149
  }
118
- store.getState().setActiveChain(activeChainId);
150
+ store.getState().setActiveChainId(activeChainId);
119
151
  const freshState = store.getState();
120
152
  const kernelAccount = freshState.kernelAccounts.get(activeChainId);
121
153
  console.log('ZeroDevWallet connected:', kernelAccount.address);
@@ -139,32 +171,33 @@ function zeroDevWallet(params) {
139
171
  async getAccounts() {
140
172
  if (!store)
141
173
  return [];
142
- const { eoaAccount, kernelAccounts, chainIds } = store.getState();
174
+ const { eoaAccount, kernelAccounts, activeChainId } = store.getState();
143
175
  if (eoaAccount) {
144
176
  return [eoaAccount.address];
145
177
  }
146
- const activeAccount = chainIds[0]
147
- ? kernelAccounts.get(chainIds[0])
178
+ const activeAccount = activeChainId
179
+ ? kernelAccounts.get(activeChainId)
148
180
  : null;
149
181
  return activeAccount ? [activeAccount.address] : [];
150
182
  },
151
183
  async getChainId() {
152
184
  if (!store)
153
185
  return params.chains[0].id;
154
- return store.getState().chainIds[0] || params.chains[0].id;
186
+ return store.getState().activeChainId ?? params.chains[0].id;
155
187
  },
156
188
  async getProvider() {
157
- await initialize();
189
+ if (!provider) {
190
+ await initialize();
191
+ }
158
192
  return provider;
159
193
  },
160
194
  async switchChain({ chainId }) {
161
- await initialize();
162
195
  console.log(`Switching to chain ${chainId}...`);
163
196
  const state = store.getState();
164
197
  if (!state.eoaAccount) {
165
198
  throw new Error('Not authenticated');
166
199
  }
167
- store.getState().setActiveChain(chainId);
200
+ store.getState().setActiveChainId(chainId);
168
201
  if (!state.kernelAccounts.has(chainId)) {
169
202
  const chain = params.chains.find((c) => c.id === chainId);
170
203
  if (!chain) {
@@ -194,6 +227,7 @@ function zeroDevWallet(params) {
194
227
  });
195
228
  store.getState().setKernelClient(chainId, kernelClient);
196
229
  }
230
+ wagmiConfig.emitter.emit('change', { chainId });
197
231
  return params.chains.find((c) => c.id === chainId);
198
232
  },
199
233
  async isAuthorized() {
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ 'use client';
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.useExportPrivateKey = useExportPrivateKey;
5
+ const react_query_1 = require("@tanstack/react-query");
6
+ const wagmi_1 = require("wagmi");
7
+ const actions_js_1 = require("../actions.js");
8
+ function useExportPrivateKey(parameters = {}) {
9
+ const { mutation } = parameters;
10
+ const config = (0, wagmi_1.useConfig)(parameters);
11
+ return (0, react_query_1.useMutation)({
12
+ ...mutation,
13
+ async mutationFn(variables) {
14
+ return (0, actions_js_1.exportPrivateKey)(config, variables);
15
+ },
16
+ mutationKey: ['exportPrivateKey'],
17
+ });
18
+ }
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ 'use client';
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.useGetUserEmail = useGetUserEmail;
5
+ const react_query_1 = require("@tanstack/react-query");
6
+ const wagmi_1 = require("wagmi");
7
+ const actions_js_1 = require("../actions.js");
8
+ function useGetUserEmail(parameters) {
9
+ const { query } = parameters;
10
+ const config = (0, wagmi_1.useConfig)(parameters);
11
+ return (0, react_query_1.useQuery)({
12
+ ...query,
13
+ queryKey: ['getUserEmail'],
14
+ queryFn: async () => {
15
+ return (0, actions_js_1.getUserEmail)(config);
16
+ },
17
+ enabled: Boolean(config),
18
+ });
19
+ }
@@ -1,12 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createZeroDevWalletStore = exports.OAUTH_PROVIDERS = exports.useVerifyOTP = exports.useSendOTP = exports.useRegisterPasskey = exports.useRefreshSession = exports.useLoginPasskey = exports.useExportWallet = exports.useAuthenticateOAuth = exports.zeroDevWallet = void 0;
3
+ exports.createZeroDevWalletStore = exports.OAUTH_PROVIDERS = exports.listenForOAuthMessage = exports.handleOAuthCallback = exports.buildBackendOAuthUrl = exports.useVerifyOTP = exports.useSendOTP = exports.useRegisterPasskey = exports.useRefreshSession = exports.useLoginPasskey = exports.useGetUserEmail = exports.useExportWallet = exports.useExportPrivateKey = exports.useAuthenticateOAuth = exports.zeroDevWallet = void 0;
4
4
  var connector_js_1 = require("./connector.js");
5
5
  Object.defineProperty(exports, "zeroDevWallet", { enumerable: true, get: function () { return connector_js_1.zeroDevWallet; } });
6
6
  var useAuthenticateOAuth_js_1 = require("./hooks/useAuthenticateOAuth.js");
7
7
  Object.defineProperty(exports, "useAuthenticateOAuth", { enumerable: true, get: function () { return useAuthenticateOAuth_js_1.useAuthenticateOAuth; } });
8
+ var useExportPrivateKey_js_1 = require("./hooks/useExportPrivateKey.js");
9
+ Object.defineProperty(exports, "useExportPrivateKey", { enumerable: true, get: function () { return useExportPrivateKey_js_1.useExportPrivateKey; } });
8
10
  var useExportWallet_js_1 = require("./hooks/useExportWallet.js");
9
11
  Object.defineProperty(exports, "useExportWallet", { enumerable: true, get: function () { return useExportWallet_js_1.useExportWallet; } });
12
+ var useGetUserEmail_js_1 = require("./hooks/useGetUserEmail.js");
13
+ Object.defineProperty(exports, "useGetUserEmail", { enumerable: true, get: function () { return useGetUserEmail_js_1.useGetUserEmail; } });
10
14
  var useLoginPasskey_js_1 = require("./hooks/useLoginPasskey.js");
11
15
  Object.defineProperty(exports, "useLoginPasskey", { enumerable: true, get: function () { return useLoginPasskey_js_1.useLoginPasskey; } });
12
16
  var useRefreshSession_js_1 = require("./hooks/useRefreshSession.js");
@@ -18,6 +22,9 @@ Object.defineProperty(exports, "useSendOTP", { enumerable: true, get: function (
18
22
  var useVerifyOTP_js_1 = require("./hooks/useVerifyOTP.js");
19
23
  Object.defineProperty(exports, "useVerifyOTP", { enumerable: true, get: function () { return useVerifyOTP_js_1.useVerifyOTP; } });
20
24
  var oauth_js_1 = require("./oauth.js");
25
+ Object.defineProperty(exports, "buildBackendOAuthUrl", { enumerable: true, get: function () { return oauth_js_1.buildBackendOAuthUrl; } });
26
+ Object.defineProperty(exports, "handleOAuthCallback", { enumerable: true, get: function () { return oauth_js_1.handleOAuthCallback; } });
27
+ Object.defineProperty(exports, "listenForOAuthMessage", { enumerable: true, get: function () { return oauth_js_1.listenForOAuthMessage; } });
21
28
  Object.defineProperty(exports, "OAUTH_PROVIDERS", { enumerable: true, get: function () { return oauth_js_1.OAUTH_PROVIDERS; } });
22
29
  var store_js_1 = require("./store.js");
23
30
  Object.defineProperty(exports, "createZeroDevWalletStore", { enumerable: true, get: function () { return store_js_1.createZeroDevWalletStore; } });