@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/src/store.ts CHANGED
@@ -10,7 +10,12 @@ import type { LocalAccount } from 'viem'
10
10
  import type { SmartAccount } from 'viem/account-abstraction'
11
11
  import { create } from 'zustand'
12
12
  import { persist, subscribeWithSelector } from 'zustand/middleware'
13
- import type { OAuthConfig } from './oauth.js'
13
+
14
+ // Internal OAuth config stored in the state (derived from connector params)
15
+ type InternalOAuthConfig = {
16
+ backendUrl: string
17
+ projectId: string
18
+ }
14
19
 
15
20
  export type ZeroDevWalletState = {
16
21
  // Core
@@ -19,15 +24,15 @@ export type ZeroDevWalletState = {
19
24
  session: ZeroDevWalletSession | null
20
25
 
21
26
  // Multi-chain support
22
- chainIds: number[] // [activeChain, ...otherChains]
27
+ activeChainId: number | null
23
28
  kernelAccounts: Map<number, SmartAccount<KernelSmartAccountImplementation>>
24
29
  kernelClients: Map<number, KernelAccountClient>
25
30
 
26
31
  // Session expiry
27
32
  isExpiring: boolean
28
33
 
29
- // OAuth config (optional)
30
- oauthConfig: OAuthConfig | null
34
+ // OAuth config (derived from connector params)
35
+ oauthConfig: InternalOAuthConfig | null
31
36
 
32
37
  // Actions
33
38
  setWallet: (wallet: ZeroDevWalletSDK) => void
@@ -38,9 +43,9 @@ export type ZeroDevWalletState = {
38
43
  ) => void
39
44
  setKernelClient: (chainId: number, client: KernelAccountClient) => void
40
45
  setSession: (session: ZeroDevWalletSession | null) => void
41
- setActiveChain: (chainId: number) => void
46
+ setActiveChainId: (chainId: number | null) => void
42
47
  setIsExpiring: (isExpiring: boolean) => void
43
- setOAuthConfig: (config: OAuthConfig | null) => void
48
+ setOAuthConfig: (config: InternalOAuthConfig | null) => void
44
49
  clear: () => void
45
50
  }
46
51
 
@@ -53,7 +58,7 @@ export const createZeroDevWalletStore = () =>
53
58
  wallet: null,
54
59
  eoaAccount: null,
55
60
  session: null,
56
- chainIds: [],
61
+ activeChainId: null,
57
62
  kernelAccounts: new Map(),
58
63
  kernelClients: new Map(),
59
64
  isExpiring: false,
@@ -78,13 +83,7 @@ export const createZeroDevWalletStore = () =>
78
83
 
79
84
  setSession: (session) => set({ session }),
80
85
 
81
- setActiveChain: (chainId) => {
82
- const { chainIds } = get()
83
- // Move chainId to front, remove duplicates
84
- set({
85
- chainIds: [chainId, ...chainIds.filter((id) => id !== chainId)],
86
- })
87
- },
86
+ setActiveChainId: (chainId) => set({ activeChainId: chainId }),
88
87
 
89
88
  setIsExpiring: (isExpiring) => set({ isExpiring }),
90
89
 
@@ -97,7 +96,7 @@ export const createZeroDevWalletStore = () =>
97
96
  kernelAccounts: new Map(),
98
97
  kernelClients: new Map(),
99
98
  isExpiring: false,
100
- chainIds: [],
99
+ activeChainId: null,
101
100
  }),
102
101
  }),
103
102
  {
@@ -105,7 +104,7 @@ export const createZeroDevWalletStore = () =>
105
104
  // Only persist session data, not clients or accounts
106
105
  partialize: (state) => ({
107
106
  session: state.session,
108
- chainIds: state.chainIds,
107
+ activeChainId: state.activeChainId,
109
108
  }),
110
109
  },
111
110
  ),