@zerodev/wallet-react 0.0.1-alpha.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.
- package/CHANGELOG.md +9 -0
- package/dist/_cjs/actions.js +193 -0
- package/dist/_cjs/connector.js +221 -0
- package/dist/_cjs/constants.js +4 -0
- package/dist/_cjs/hooks/useAuthenticateOAuth.js +18 -0
- package/dist/_cjs/hooks/useExportWallet.js +18 -0
- package/dist/_cjs/hooks/useLoginPasskey.js +18 -0
- package/dist/_cjs/hooks/useRefreshSession.js +18 -0
- package/dist/_cjs/hooks/useRegisterPasskey.js +18 -0
- package/dist/_cjs/hooks/useSendOTP.js +18 -0
- package/dist/_cjs/hooks/useVerifyOTP.js +18 -0
- package/dist/_cjs/index.js +23 -0
- package/dist/_cjs/oauth.js +84 -0
- package/dist/_cjs/package.json +1 -0
- package/dist/_cjs/provider.js +163 -0
- package/dist/_cjs/store.js +51 -0
- package/dist/_cjs/utils/aaUtils.js +7 -0
- package/dist/_cjs/utils/timers.js +50 -0
- package/dist/_esm/actions.js +225 -0
- package/dist/_esm/connector.js +248 -0
- package/dist/_esm/constants.js +1 -0
- package/dist/_esm/hooks/useAuthenticateOAuth.js +18 -0
- package/dist/_esm/hooks/useExportWallet.js +18 -0
- package/dist/_esm/hooks/useLoginPasskey.js +18 -0
- package/dist/_esm/hooks/useRefreshSession.js +18 -0
- package/dist/_esm/hooks/useRegisterPasskey.js +18 -0
- package/dist/_esm/hooks/useSendOTP.js +18 -0
- package/dist/_esm/hooks/useVerifyOTP.js +18 -0
- package/dist/_esm/index.js +10 -0
- package/dist/_esm/oauth.js +77 -0
- package/dist/_esm/package.json +1 -0
- package/dist/_esm/provider.js +169 -0
- package/dist/_esm/store.js +51 -0
- package/dist/_esm/utils/aaUtils.js +4 -0
- package/dist/_esm/utils/timers.js +55 -0
- package/dist/_types/actions.d.ts +124 -0
- package/dist/_types/actions.d.ts.map +1 -0
- package/dist/_types/connector.d.ts +18 -0
- package/dist/_types/connector.d.ts.map +1 -0
- package/dist/_types/constants.d.ts +2 -0
- package/dist/_types/constants.d.ts.map +1 -0
- package/dist/_types/hooks/useAuthenticateOAuth.d.ts +18 -0
- package/dist/_types/hooks/useAuthenticateOAuth.d.ts.map +1 -0
- package/dist/_types/hooks/useExportWallet.d.ts +18 -0
- package/dist/_types/hooks/useExportWallet.d.ts.map +1 -0
- package/dist/_types/hooks/useLoginPasskey.d.ts +18 -0
- package/dist/_types/hooks/useLoginPasskey.d.ts.map +1 -0
- package/dist/_types/hooks/useRefreshSession.d.ts +18 -0
- package/dist/_types/hooks/useRefreshSession.d.ts.map +1 -0
- package/dist/_types/hooks/useRegisterPasskey.d.ts +18 -0
- package/dist/_types/hooks/useRegisterPasskey.d.ts.map +1 -0
- package/dist/_types/hooks/useSendOTP.d.ts +18 -0
- package/dist/_types/hooks/useSendOTP.d.ts.map +1 -0
- package/dist/_types/hooks/useVerifyOTP.d.ts +18 -0
- package/dist/_types/hooks/useVerifyOTP.d.ts.map +1 -0
- package/dist/_types/index.d.ts +15 -0
- package/dist/_types/index.d.ts.map +1 -0
- package/dist/_types/oauth.d.ts +21 -0
- package/dist/_types/oauth.d.ts.map +1 -0
- package/dist/_types/provider.d.ts +19 -0
- package/dist/_types/provider.d.ts.map +1 -0
- package/dist/_types/store.d.ts +52 -0
- package/dist/_types/store.d.ts.map +1 -0
- package/dist/_types/utils/aaUtils.d.ts +2 -0
- package/dist/_types/utils/aaUtils.d.ts.map +1 -0
- package/dist/_types/utils/timers.d.ts +22 -0
- package/dist/_types/utils/timers.d.ts.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +48 -0
- package/package.json.type +1 -0
- package/src/actions.ts +402 -0
- package/src/connector.ts +336 -0
- package/src/constants.ts +1 -0
- package/src/hooks/useAuthenticateOAuth.ts +57 -0
- package/src/hooks/useExportWallet.ts +57 -0
- package/src/hooks/useLoginPasskey.ts +57 -0
- package/src/hooks/useRefreshSession.ts +57 -0
- package/src/hooks/useRegisterPasskey.ts +57 -0
- package/src/hooks/useSendOTP.ts +57 -0
- package/src/hooks/useVerifyOTP.ts +57 -0
- package/src/index.ts +14 -0
- package/src/oauth.ts +124 -0
- package/src/provider.ts +235 -0
- package/src/store.ts +113 -0
- package/src/utils/aaUtils.ts +5 -0
- package/src/utils/timers.ts +80 -0
- package/tsconfig.build.json +10 -0
- package/tsconfig.build.tsbuildinfo +1 -0
package/src/connector.ts
ADDED
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { type CreateConnectorFn, createConnector } from '@wagmi/core'
|
|
2
|
+
import {
|
|
3
|
+
createKernelAccount,
|
|
4
|
+
createKernelAccountClient,
|
|
5
|
+
createZeroDevPaymasterClient,
|
|
6
|
+
} from '@zerodev/sdk'
|
|
7
|
+
import { getEntryPoint, KERNEL_V3_3 } from '@zerodev/sdk/constants'
|
|
8
|
+
import type { StorageAdapter } from '@zerodev/wallet-core'
|
|
9
|
+
import { createZeroDevWallet } from '@zerodev/wallet-core'
|
|
10
|
+
import { type Chain, createPublicClient, http } from 'viem'
|
|
11
|
+
import type { OAuthConfig } from './oauth.js'
|
|
12
|
+
import { createProvider } from './provider.js'
|
|
13
|
+
import { createZeroDevWalletStore } from './store.js'
|
|
14
|
+
import { getAAUrl } from './utils/aaUtils.js'
|
|
15
|
+
|
|
16
|
+
export type ZeroDevWalletConnectorParams = {
|
|
17
|
+
projectId: string
|
|
18
|
+
organizationId?: string
|
|
19
|
+
proxyBaseUrl?: string
|
|
20
|
+
aaUrl: string // Bundler/paymaster URL
|
|
21
|
+
chains: readonly Chain[]
|
|
22
|
+
rpId?: string
|
|
23
|
+
sessionStorage?: StorageAdapter
|
|
24
|
+
autoRefreshSession?: boolean
|
|
25
|
+
sessionWarningThreshold?: number
|
|
26
|
+
oauthConfig?: OAuthConfig
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function zeroDevWallet(
|
|
30
|
+
params: ZeroDevWalletConnectorParams,
|
|
31
|
+
): CreateConnectorFn {
|
|
32
|
+
type Provider = ReturnType<typeof createProvider>
|
|
33
|
+
type Properties = {
|
|
34
|
+
connect<withCapabilities extends boolean = false>(parameters?: {
|
|
35
|
+
chainId?: number | undefined
|
|
36
|
+
isReconnecting?: boolean | undefined
|
|
37
|
+
withCapabilities?: withCapabilities | boolean | undefined
|
|
38
|
+
}): Promise<{
|
|
39
|
+
accounts: withCapabilities extends true
|
|
40
|
+
? readonly {
|
|
41
|
+
address: `0x${string}`
|
|
42
|
+
capabilities: Record<string, unknown>
|
|
43
|
+
}[]
|
|
44
|
+
: readonly `0x${string}`[]
|
|
45
|
+
chainId: number
|
|
46
|
+
}>
|
|
47
|
+
getStore(): Promise<ReturnType<typeof createZeroDevWalletStore>>
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return createConnector<Provider, Properties>((wagmiConfig) => {
|
|
51
|
+
let store: ReturnType<typeof createZeroDevWalletStore>
|
|
52
|
+
let provider: ReturnType<typeof createProvider>
|
|
53
|
+
let initPromise: Promise<void> | undefined
|
|
54
|
+
|
|
55
|
+
// Get transports from Wagmi config (uses user's RPC URLs)
|
|
56
|
+
const transports = wagmiConfig.transports
|
|
57
|
+
|
|
58
|
+
// Lazy initialization - only runs on client side
|
|
59
|
+
const initialize = async () => {
|
|
60
|
+
initPromise ??= (async () => {
|
|
61
|
+
console.log('Initializing ZeroDevWallet connector...')
|
|
62
|
+
|
|
63
|
+
// Initialize wallet SDK
|
|
64
|
+
const wallet = await createZeroDevWallet({
|
|
65
|
+
projectId: params.projectId,
|
|
66
|
+
...(params.organizationId && {
|
|
67
|
+
organizationId: params.organizationId,
|
|
68
|
+
}),
|
|
69
|
+
...(params.proxyBaseUrl && { proxyBaseUrl: params.proxyBaseUrl }),
|
|
70
|
+
...(params.sessionStorage && {
|
|
71
|
+
sessionStorage: params.sessionStorage,
|
|
72
|
+
}),
|
|
73
|
+
...(params.rpId && { rpId: params.rpId }),
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
// Create store
|
|
77
|
+
store = createZeroDevWalletStore()
|
|
78
|
+
store.getState().setWallet(wallet)
|
|
79
|
+
|
|
80
|
+
// Initialize chainIds
|
|
81
|
+
const chainIds = params.chains.map((c) => c.id)
|
|
82
|
+
store.setState({ chainIds })
|
|
83
|
+
|
|
84
|
+
// Store OAuth config if provided
|
|
85
|
+
if (params.oauthConfig) {
|
|
86
|
+
store.getState().setOAuthConfig(params.oauthConfig)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Create EIP-1193 provider
|
|
90
|
+
provider = createProvider({
|
|
91
|
+
store,
|
|
92
|
+
config: params,
|
|
93
|
+
chains: Array.from(params.chains),
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
// Check for existing session (page reload)
|
|
97
|
+
const session = await wallet.getSession()
|
|
98
|
+
if (session) {
|
|
99
|
+
console.log('Found existing session, restoring...')
|
|
100
|
+
const eoaAccount = await wallet.toAccount()
|
|
101
|
+
store.getState().setEoaAccount(eoaAccount)
|
|
102
|
+
store.getState().setSession(session)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
console.log('ZeroDevWallet connector initialized')
|
|
106
|
+
})()
|
|
107
|
+
|
|
108
|
+
return initPromise
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
id: 'zerodev-wallet',
|
|
113
|
+
name: 'ZeroDevWallet',
|
|
114
|
+
type: 'injected' as const,
|
|
115
|
+
|
|
116
|
+
async setup() {
|
|
117
|
+
// Initialize on client-side mount (setup only runs client-side)
|
|
118
|
+
if (typeof window !== 'undefined') {
|
|
119
|
+
await initialize()
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
async connect({ chainId, ...rest } = {}) {
|
|
124
|
+
const withCapabilities =
|
|
125
|
+
('withCapabilities' in rest && rest.withCapabilities) || false
|
|
126
|
+
const isReconnecting =
|
|
127
|
+
('isReconnecting' in rest && rest.isReconnecting) || false
|
|
128
|
+
|
|
129
|
+
// Ensure wallet is initialized (lazy init on first connect)
|
|
130
|
+
await initialize()
|
|
131
|
+
|
|
132
|
+
console.log(
|
|
133
|
+
isReconnecting
|
|
134
|
+
? 'Reconnecting ZeroDevWallet...'
|
|
135
|
+
: 'Connecting ZeroDevWallet...',
|
|
136
|
+
)
|
|
137
|
+
const state = store.getState()
|
|
138
|
+
|
|
139
|
+
// Determine active chain
|
|
140
|
+
const activeChainId = chainId || state.chainIds[0]
|
|
141
|
+
if (!activeChainId) {
|
|
142
|
+
throw new Error('No chain configured')
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// If reconnecting and already have kernel account, return immediately
|
|
146
|
+
if (isReconnecting && state.kernelAccounts.has(activeChainId)) {
|
|
147
|
+
const kernelAccount = state.kernelAccounts.get(activeChainId)
|
|
148
|
+
if (kernelAccount?.address) {
|
|
149
|
+
console.log('Already connected:', kernelAccount.address)
|
|
150
|
+
return {
|
|
151
|
+
accounts: [kernelAccount.address] as never,
|
|
152
|
+
chainId: activeChainId,
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (!state.eoaAccount) {
|
|
158
|
+
throw new Error(
|
|
159
|
+
'Not authenticated. Please authenticate first using passkey, OAuth, or OTP.',
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Create KernelAccount for this chain if doesn't exist
|
|
164
|
+
if (!state.kernelAccounts.has(activeChainId)) {
|
|
165
|
+
const chain = params.chains.find((c) => c.id === activeChainId)
|
|
166
|
+
if (!chain) {
|
|
167
|
+
throw new Error(`Chain ${activeChainId} not found in config`)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
// Use transport from Wagmi config (has user's RPC URL)
|
|
171
|
+
const transport = transports?.[activeChainId] ?? http()
|
|
172
|
+
const publicClient = createPublicClient({
|
|
173
|
+
chain,
|
|
174
|
+
transport,
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
console.log(`Creating kernel account for chain ${activeChainId}...`)
|
|
178
|
+
const kernelAccount = await createKernelAccount(publicClient, {
|
|
179
|
+
entryPoint: getEntryPoint('0.7'),
|
|
180
|
+
kernelVersion: KERNEL_V3_3,
|
|
181
|
+
eip7702Account: state.eoaAccount,
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
// Store kernel account for this chain
|
|
185
|
+
store.getState().setKernelAccount(activeChainId, kernelAccount)
|
|
186
|
+
|
|
187
|
+
// Create and store kernel client for transactions
|
|
188
|
+
const kernelClient = createKernelAccountClient({
|
|
189
|
+
account: kernelAccount,
|
|
190
|
+
bundlerTransport: http(getAAUrl(activeChainId, params.aaUrl)),
|
|
191
|
+
chain,
|
|
192
|
+
client: publicClient,
|
|
193
|
+
paymaster: createZeroDevPaymasterClient({
|
|
194
|
+
chain,
|
|
195
|
+
transport: http(getAAUrl(activeChainId, params.aaUrl)),
|
|
196
|
+
}),
|
|
197
|
+
})
|
|
198
|
+
store.getState().setKernelClient(activeChainId, kernelClient)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// Set as active chain
|
|
202
|
+
store.getState().setActiveChain(activeChainId)
|
|
203
|
+
|
|
204
|
+
// Get fresh state after updates
|
|
205
|
+
const freshState = store.getState()
|
|
206
|
+
const kernelAccount = freshState.kernelAccounts.get(activeChainId)!
|
|
207
|
+
|
|
208
|
+
console.log('ZeroDevWallet connected:', kernelAccount.address)
|
|
209
|
+
|
|
210
|
+
const address = kernelAccount.address
|
|
211
|
+
return {
|
|
212
|
+
accounts: (withCapabilities
|
|
213
|
+
? [{ address, capabilities: {} }]
|
|
214
|
+
: [address]) as never,
|
|
215
|
+
chainId: activeChainId,
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
|
|
219
|
+
async disconnect() {
|
|
220
|
+
console.log('Disconnecting ZeroDevWallet...')
|
|
221
|
+
if (!store) return
|
|
222
|
+
const wallet = store.getState().wallet
|
|
223
|
+
|
|
224
|
+
// Cleanup provider (clears timers)
|
|
225
|
+
provider?.destroy()
|
|
226
|
+
|
|
227
|
+
await wallet?.logout()
|
|
228
|
+
store.getState().clear()
|
|
229
|
+
},
|
|
230
|
+
|
|
231
|
+
async getAccounts() {
|
|
232
|
+
if (!store) return []
|
|
233
|
+
const { eoaAccount, kernelAccounts, chainIds } = store.getState()
|
|
234
|
+
|
|
235
|
+
// Return EOA address if we have it (EIP-7702: EOA address = kernel address)
|
|
236
|
+
if (eoaAccount) {
|
|
237
|
+
return [eoaAccount.address]
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Fallback: check kernel accounts
|
|
241
|
+
const activeAccount = chainIds[0]
|
|
242
|
+
? kernelAccounts.get(chainIds[0])
|
|
243
|
+
: null
|
|
244
|
+
return activeAccount ? [activeAccount.address] : []
|
|
245
|
+
},
|
|
246
|
+
|
|
247
|
+
async getChainId() {
|
|
248
|
+
if (!store) return params.chains[0].id
|
|
249
|
+
return store.getState().chainIds[0] || params.chains[0].id
|
|
250
|
+
},
|
|
251
|
+
|
|
252
|
+
async getProvider() {
|
|
253
|
+
await initialize()
|
|
254
|
+
return provider
|
|
255
|
+
},
|
|
256
|
+
|
|
257
|
+
async switchChain({ chainId }) {
|
|
258
|
+
await initialize()
|
|
259
|
+
console.log(`Switching to chain ${chainId}...`)
|
|
260
|
+
const state = store.getState()
|
|
261
|
+
|
|
262
|
+
if (!state.eoaAccount) {
|
|
263
|
+
throw new Error('Not authenticated')
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// Update active chain
|
|
267
|
+
store.getState().setActiveChain(chainId)
|
|
268
|
+
|
|
269
|
+
// Create kernel account for new chain if doesn't exist
|
|
270
|
+
if (!state.kernelAccounts.has(chainId)) {
|
|
271
|
+
const chain = params.chains.find((c) => c.id === chainId)
|
|
272
|
+
if (!chain) {
|
|
273
|
+
throw new Error(`Chain ${chainId} not found in config`)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Use transport from Wagmi config (has user's RPC URL)
|
|
277
|
+
const transport = transports?.[chainId] ?? http()
|
|
278
|
+
const publicClient = createPublicClient({
|
|
279
|
+
chain,
|
|
280
|
+
transport,
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
console.log(`Creating kernel account for chain ${chainId}...`)
|
|
284
|
+
const kernelAccount = await createKernelAccount(publicClient, {
|
|
285
|
+
entryPoint: getEntryPoint('0.7'),
|
|
286
|
+
kernelVersion: KERNEL_V3_3,
|
|
287
|
+
eip7702Account: state.eoaAccount,
|
|
288
|
+
})
|
|
289
|
+
|
|
290
|
+
store.getState().setKernelAccount(chainId, kernelAccount)
|
|
291
|
+
const kernelClient = createKernelAccountClient({
|
|
292
|
+
account: kernelAccount,
|
|
293
|
+
bundlerTransport: http(getAAUrl(chainId, params.aaUrl)),
|
|
294
|
+
chain,
|
|
295
|
+
client: publicClient,
|
|
296
|
+
paymaster: createZeroDevPaymasterClient({
|
|
297
|
+
chain,
|
|
298
|
+
transport: http(getAAUrl(chainId, params.aaUrl)),
|
|
299
|
+
}),
|
|
300
|
+
})
|
|
301
|
+
store.getState().setKernelClient(chainId, kernelClient)
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return params.chains.find((c) => c.id === chainId)!
|
|
305
|
+
},
|
|
306
|
+
|
|
307
|
+
async isAuthorized() {
|
|
308
|
+
// Just check if we have a session - don't initialize here (too slow)
|
|
309
|
+
if (!store) return false
|
|
310
|
+
return !!store.getState().eoaAccount
|
|
311
|
+
},
|
|
312
|
+
|
|
313
|
+
// Custom method for hooks to access store
|
|
314
|
+
async getStore() {
|
|
315
|
+
await initialize()
|
|
316
|
+
return store
|
|
317
|
+
},
|
|
318
|
+
|
|
319
|
+
// Event listeners
|
|
320
|
+
onAccountsChanged() {
|
|
321
|
+
// Not applicable for this wallet type
|
|
322
|
+
},
|
|
323
|
+
onChainChanged() {
|
|
324
|
+
// Handled by Wagmi
|
|
325
|
+
},
|
|
326
|
+
onConnect() {
|
|
327
|
+
// Handled by Wagmi
|
|
328
|
+
},
|
|
329
|
+
onDisconnect() {
|
|
330
|
+
console.log('Disconnect event')
|
|
331
|
+
provider?.destroy()
|
|
332
|
+
store.getState().clear()
|
|
333
|
+
},
|
|
334
|
+
}
|
|
335
|
+
})
|
|
336
|
+
}
|
package/src/constants.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const ZERODEV_AA_URL = 'https://rpc.zerodev.app/api/v3/'
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type UseMutationOptions,
|
|
5
|
+
type UseMutationResult,
|
|
6
|
+
useMutation,
|
|
7
|
+
} from '@tanstack/react-query'
|
|
8
|
+
import { type Config, type ResolvedRegister, useConfig } from 'wagmi'
|
|
9
|
+
import { authenticateOAuth } from '../actions.js'
|
|
10
|
+
|
|
11
|
+
type ConfigParameter<config extends Config = Config> = {
|
|
12
|
+
config?: Config | config | undefined
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Hook to authenticate with OAuth (opens popup)
|
|
17
|
+
*/
|
|
18
|
+
export function useAuthenticateOAuth<
|
|
19
|
+
config extends Config = ResolvedRegister['config'],
|
|
20
|
+
context = unknown,
|
|
21
|
+
>(
|
|
22
|
+
parameters: useAuthenticateOAuth.Parameters<config, context> = {},
|
|
23
|
+
): useAuthenticateOAuth.ReturnType<context> {
|
|
24
|
+
const { mutation } = parameters
|
|
25
|
+
const config = useConfig(parameters)
|
|
26
|
+
|
|
27
|
+
return useMutation({
|
|
28
|
+
...mutation,
|
|
29
|
+
async mutationFn(variables: authenticateOAuth.Parameters) {
|
|
30
|
+
return authenticateOAuth(config, variables)
|
|
31
|
+
},
|
|
32
|
+
mutationKey: ['authenticateOAuth'],
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export declare namespace useAuthenticateOAuth {
|
|
37
|
+
type Parameters<
|
|
38
|
+
config extends Config = Config,
|
|
39
|
+
context = unknown,
|
|
40
|
+
> = ConfigParameter<config> & {
|
|
41
|
+
mutation?:
|
|
42
|
+
| UseMutationOptions<
|
|
43
|
+
authenticateOAuth.ReturnType,
|
|
44
|
+
authenticateOAuth.ErrorType,
|
|
45
|
+
authenticateOAuth.Parameters,
|
|
46
|
+
context
|
|
47
|
+
>
|
|
48
|
+
| undefined
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type ReturnType<context = unknown> = UseMutationResult<
|
|
52
|
+
authenticateOAuth.ReturnType,
|
|
53
|
+
authenticateOAuth.ErrorType,
|
|
54
|
+
authenticateOAuth.Parameters,
|
|
55
|
+
context
|
|
56
|
+
>
|
|
57
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type UseMutationOptions,
|
|
5
|
+
type UseMutationResult,
|
|
6
|
+
useMutation,
|
|
7
|
+
} from '@tanstack/react-query'
|
|
8
|
+
import { type Config, type ResolvedRegister, useConfig } from 'wagmi'
|
|
9
|
+
import { exportWallet } from '../actions.js'
|
|
10
|
+
|
|
11
|
+
type ConfigParameter<config extends Config = Config> = {
|
|
12
|
+
config?: Config | config | undefined
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Hook to export wallet seed phrase
|
|
17
|
+
*/
|
|
18
|
+
export function useExportWallet<
|
|
19
|
+
config extends Config = ResolvedRegister['config'],
|
|
20
|
+
context = unknown,
|
|
21
|
+
>(
|
|
22
|
+
parameters: useExportWallet.Parameters<config, context> = {},
|
|
23
|
+
): useExportWallet.ReturnType<context> {
|
|
24
|
+
const { mutation } = parameters
|
|
25
|
+
const config = useConfig(parameters)
|
|
26
|
+
|
|
27
|
+
return useMutation({
|
|
28
|
+
...mutation,
|
|
29
|
+
async mutationFn(variables: exportWallet.Parameters) {
|
|
30
|
+
return exportWallet(config, variables)
|
|
31
|
+
},
|
|
32
|
+
mutationKey: ['exportWallet'],
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export declare namespace useExportWallet {
|
|
37
|
+
type Parameters<
|
|
38
|
+
config extends Config = Config,
|
|
39
|
+
context = unknown,
|
|
40
|
+
> = ConfigParameter<config> & {
|
|
41
|
+
mutation?:
|
|
42
|
+
| UseMutationOptions<
|
|
43
|
+
exportWallet.ReturnType,
|
|
44
|
+
exportWallet.ErrorType,
|
|
45
|
+
exportWallet.Parameters,
|
|
46
|
+
context
|
|
47
|
+
>
|
|
48
|
+
| undefined
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type ReturnType<context = unknown> = UseMutationResult<
|
|
52
|
+
exportWallet.ReturnType,
|
|
53
|
+
exportWallet.ErrorType,
|
|
54
|
+
exportWallet.Parameters,
|
|
55
|
+
context
|
|
56
|
+
>
|
|
57
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type UseMutationOptions,
|
|
5
|
+
type UseMutationResult,
|
|
6
|
+
useMutation,
|
|
7
|
+
} from '@tanstack/react-query'
|
|
8
|
+
import { type Config, type ResolvedRegister, useConfig } from 'wagmi'
|
|
9
|
+
import { loginPasskey } from '../actions.js'
|
|
10
|
+
|
|
11
|
+
type ConfigParameter<config extends Config = Config> = {
|
|
12
|
+
config?: Config | config | undefined
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Hook to login with passkey
|
|
17
|
+
*/
|
|
18
|
+
export function useLoginPasskey<
|
|
19
|
+
config extends Config = ResolvedRegister['config'],
|
|
20
|
+
context = unknown,
|
|
21
|
+
>(
|
|
22
|
+
parameters: useLoginPasskey.Parameters<config, context> = {},
|
|
23
|
+
): useLoginPasskey.ReturnType<context> {
|
|
24
|
+
const { mutation } = parameters
|
|
25
|
+
const config = useConfig(parameters)
|
|
26
|
+
|
|
27
|
+
return useMutation({
|
|
28
|
+
...mutation,
|
|
29
|
+
async mutationFn(variables: loginPasskey.Parameters) {
|
|
30
|
+
return loginPasskey(config, variables)
|
|
31
|
+
},
|
|
32
|
+
mutationKey: ['loginPasskey'],
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export declare namespace useLoginPasskey {
|
|
37
|
+
type Parameters<
|
|
38
|
+
config extends Config = Config,
|
|
39
|
+
context = unknown,
|
|
40
|
+
> = ConfigParameter<config> & {
|
|
41
|
+
mutation?:
|
|
42
|
+
| UseMutationOptions<
|
|
43
|
+
loginPasskey.ReturnType,
|
|
44
|
+
loginPasskey.ErrorType,
|
|
45
|
+
loginPasskey.Parameters,
|
|
46
|
+
context
|
|
47
|
+
>
|
|
48
|
+
| undefined
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type ReturnType<context = unknown> = UseMutationResult<
|
|
52
|
+
loginPasskey.ReturnType,
|
|
53
|
+
loginPasskey.ErrorType,
|
|
54
|
+
loginPasskey.Parameters,
|
|
55
|
+
context
|
|
56
|
+
>
|
|
57
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type UseMutationOptions,
|
|
5
|
+
type UseMutationResult,
|
|
6
|
+
useMutation,
|
|
7
|
+
} from '@tanstack/react-query'
|
|
8
|
+
import { type Config, type ResolvedRegister, useConfig } from 'wagmi'
|
|
9
|
+
import { refreshSession } from '../actions.js'
|
|
10
|
+
|
|
11
|
+
type ConfigParameter<config extends Config = Config> = {
|
|
12
|
+
config?: Config | config | undefined
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Hook to manually refresh session
|
|
17
|
+
*/
|
|
18
|
+
export function useRefreshSession<
|
|
19
|
+
config extends Config = ResolvedRegister['config'],
|
|
20
|
+
context = unknown,
|
|
21
|
+
>(
|
|
22
|
+
parameters: useRefreshSession.Parameters<config, context> = {},
|
|
23
|
+
): useRefreshSession.ReturnType<context> {
|
|
24
|
+
const { mutation } = parameters
|
|
25
|
+
const config = useConfig(parameters)
|
|
26
|
+
|
|
27
|
+
return useMutation({
|
|
28
|
+
...mutation,
|
|
29
|
+
async mutationFn(variables: refreshSession.Parameters) {
|
|
30
|
+
return refreshSession(config, variables)
|
|
31
|
+
},
|
|
32
|
+
mutationKey: ['refreshSession'],
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export declare namespace useRefreshSession {
|
|
37
|
+
type Parameters<
|
|
38
|
+
config extends Config = Config,
|
|
39
|
+
context = unknown,
|
|
40
|
+
> = ConfigParameter<config> & {
|
|
41
|
+
mutation?:
|
|
42
|
+
| UseMutationOptions<
|
|
43
|
+
refreshSession.ReturnType,
|
|
44
|
+
refreshSession.ErrorType,
|
|
45
|
+
refreshSession.Parameters,
|
|
46
|
+
context
|
|
47
|
+
>
|
|
48
|
+
| undefined
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type ReturnType<context = unknown> = UseMutationResult<
|
|
52
|
+
refreshSession.ReturnType,
|
|
53
|
+
refreshSession.ErrorType,
|
|
54
|
+
refreshSession.Parameters,
|
|
55
|
+
context
|
|
56
|
+
>
|
|
57
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type UseMutationOptions,
|
|
5
|
+
type UseMutationResult,
|
|
6
|
+
useMutation,
|
|
7
|
+
} from '@tanstack/react-query'
|
|
8
|
+
import { type Config, type ResolvedRegister, useConfig } from 'wagmi'
|
|
9
|
+
import { registerPasskey } from '../actions.js'
|
|
10
|
+
|
|
11
|
+
type ConfigParameter<config extends Config = Config> = {
|
|
12
|
+
config?: Config | config | undefined
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Hook to register with passkey
|
|
17
|
+
*/
|
|
18
|
+
export function useRegisterPasskey<
|
|
19
|
+
config extends Config = ResolvedRegister['config'],
|
|
20
|
+
context = unknown,
|
|
21
|
+
>(
|
|
22
|
+
parameters: useRegisterPasskey.Parameters<config, context> = {},
|
|
23
|
+
): useRegisterPasskey.ReturnType<context> {
|
|
24
|
+
const { mutation } = parameters
|
|
25
|
+
const config = useConfig(parameters)
|
|
26
|
+
|
|
27
|
+
return useMutation({
|
|
28
|
+
...mutation,
|
|
29
|
+
async mutationFn(variables: registerPasskey.Parameters) {
|
|
30
|
+
return registerPasskey(config, variables)
|
|
31
|
+
},
|
|
32
|
+
mutationKey: ['registerPasskey'],
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export declare namespace useRegisterPasskey {
|
|
37
|
+
type Parameters<
|
|
38
|
+
config extends Config = Config,
|
|
39
|
+
context = unknown,
|
|
40
|
+
> = ConfigParameter<config> & {
|
|
41
|
+
mutation?:
|
|
42
|
+
| UseMutationOptions<
|
|
43
|
+
registerPasskey.ReturnType,
|
|
44
|
+
registerPasskey.ErrorType,
|
|
45
|
+
registerPasskey.Parameters,
|
|
46
|
+
context
|
|
47
|
+
>
|
|
48
|
+
| undefined
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type ReturnType<context = unknown> = UseMutationResult<
|
|
52
|
+
registerPasskey.ReturnType,
|
|
53
|
+
registerPasskey.ErrorType,
|
|
54
|
+
registerPasskey.Parameters,
|
|
55
|
+
context
|
|
56
|
+
>
|
|
57
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type UseMutationOptions,
|
|
5
|
+
type UseMutationResult,
|
|
6
|
+
useMutation,
|
|
7
|
+
} from '@tanstack/react-query'
|
|
8
|
+
import { type Config, type ResolvedRegister, useConfig } from 'wagmi'
|
|
9
|
+
import { sendOTP } from '../actions.js'
|
|
10
|
+
|
|
11
|
+
type ConfigParameter<config extends Config = Config> = {
|
|
12
|
+
config?: Config | config | undefined
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Hook to send OTP via email
|
|
17
|
+
*/
|
|
18
|
+
export function useSendOTP<
|
|
19
|
+
config extends Config = ResolvedRegister['config'],
|
|
20
|
+
context = unknown,
|
|
21
|
+
>(
|
|
22
|
+
parameters: useSendOTP.Parameters<config, context> = {},
|
|
23
|
+
): useSendOTP.ReturnType<context> {
|
|
24
|
+
const { mutation } = parameters
|
|
25
|
+
const config = useConfig(parameters)
|
|
26
|
+
|
|
27
|
+
return useMutation({
|
|
28
|
+
...mutation,
|
|
29
|
+
async mutationFn(variables: sendOTP.Parameters) {
|
|
30
|
+
return sendOTP(config, variables)
|
|
31
|
+
},
|
|
32
|
+
mutationKey: ['sendOTP'],
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export declare namespace useSendOTP {
|
|
37
|
+
type Parameters<
|
|
38
|
+
config extends Config = Config,
|
|
39
|
+
context = unknown,
|
|
40
|
+
> = ConfigParameter<config> & {
|
|
41
|
+
mutation?:
|
|
42
|
+
| UseMutationOptions<
|
|
43
|
+
sendOTP.ReturnType,
|
|
44
|
+
sendOTP.ErrorType,
|
|
45
|
+
sendOTP.Parameters,
|
|
46
|
+
context
|
|
47
|
+
>
|
|
48
|
+
| undefined
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type ReturnType<context = unknown> = UseMutationResult<
|
|
52
|
+
sendOTP.ReturnType,
|
|
53
|
+
sendOTP.ErrorType,
|
|
54
|
+
sendOTP.Parameters,
|
|
55
|
+
context
|
|
56
|
+
>
|
|
57
|
+
}
|