@zerodev/wallet-react 0.0.1-alpha.5 → 0.0.1-alpha.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerodev/wallet-react",
3
- "version": "0.0.1-alpha.5",
3
+ "version": "0.0.1-alpha.6",
4
4
  "description": "React hooks for ZeroDev Wallet SDK",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/_cjs/index.js",
@@ -30,7 +30,7 @@
30
30
  "wagmi": "^3.0.0",
31
31
  "zustand": "^5.0.3",
32
32
  "ox": "^0.3.0",
33
- "@zerodev/wallet-core": "0.0.1-alpha.5"
33
+ "@zerodev/wallet-core": "0.0.1-alpha.6"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@types/react": "^19",
package/src/actions.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import type { Config, Connector } from '@wagmi/core'
2
2
  import { connect as wagmiConnect } from '@wagmi/core/actions'
3
+ import {
4
+ createIframeStamper,
5
+ exportPrivateKey as exportPrivateKeySdk,
6
+ exportWallet as exportWalletSdk,
7
+ } from '@zerodev/wallet-core'
3
8
  import type { OAuthProvider } from './oauth.js'
4
9
  import {
5
10
  buildOAuthUrl,
@@ -362,10 +367,6 @@ export async function exportWallet(
362
367
 
363
368
  if (!wallet) throw new Error('Wallet not initialized')
364
369
 
365
- const { exportWallet: exportWalletSdk, createIframeStamper } = await import(
366
- '@zerodev/wallet-core'
367
- )
368
-
369
370
  const iframeContainer = document.getElementById(parameters.iframeContainerId)
370
371
  if (!iframeContainer) {
371
372
  throw new Error('Iframe container not found')
@@ -400,3 +401,62 @@ export declare namespace exportWallet {
400
401
  type ReturnType = void
401
402
  type ErrorType = Error
402
403
  }
404
+
405
+ /**
406
+ * Export private key
407
+ */
408
+ export async function exportPrivateKey(
409
+ config: Config,
410
+ parameters: {
411
+ iframeContainerId: string
412
+ address?: string
413
+ keyFormat?: 'Hexadecimal' | 'Solana'
414
+ connector?: Connector
415
+ },
416
+ ): Promise<void> {
417
+ const connector = parameters.connector ?? getZeroDevConnector(config)
418
+
419
+ // @ts-expect-error - getStore is a custom method
420
+ const store = await connector.getStore()
421
+ const wallet = store.getState().wallet
422
+
423
+ if (!wallet) throw new Error('Wallet not initialized')
424
+
425
+ const iframeContainer = document.getElementById(parameters.iframeContainerId)
426
+ if (!iframeContainer) {
427
+ throw new Error('Iframe container not found')
428
+ }
429
+
430
+ const iframeStamper = await createIframeStamper({
431
+ iframeUrl: 'https://export.turnkey.com',
432
+ iframeContainer,
433
+ iframeElementId: 'export-private-key-iframe',
434
+ })
435
+
436
+ const publicKey = await iframeStamper.init()
437
+ const { exportBundle, organizationId } = await exportPrivateKeySdk({
438
+ wallet,
439
+ targetPublicKey: publicKey,
440
+ ...(parameters.address && { address: parameters.address }),
441
+ })
442
+
443
+ const success = await iframeStamper.injectKeyExportBundle(
444
+ exportBundle,
445
+ organizationId,
446
+ parameters.keyFormat ?? 'Hexadecimal',
447
+ )
448
+ if (success !== true) {
449
+ throw new Error('Failed to inject export bundle')
450
+ }
451
+ }
452
+
453
+ export declare namespace exportPrivateKey {
454
+ type Parameters = {
455
+ iframeContainerId: string
456
+ address?: string
457
+ keyFormat?: 'Hexadecimal' | 'Solana'
458
+ connector?: Connector
459
+ }
460
+ type ReturnType = void
461
+ type ErrorType = Error
462
+ }
@@ -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 { exportPrivateKey } from '../actions.js'
10
+
11
+ type ConfigParameter<config extends Config = Config> = {
12
+ config?: Config | config | undefined
13
+ }
14
+
15
+ /**
16
+ * Hook to export private key
17
+ */
18
+ export function useExportPrivateKey<
19
+ config extends Config = ResolvedRegister['config'],
20
+ context = unknown,
21
+ >(
22
+ parameters: useExportPrivateKey.Parameters<config, context> = {},
23
+ ): useExportPrivateKey.ReturnType<context> {
24
+ const { mutation } = parameters
25
+ const config = useConfig(parameters)
26
+
27
+ return useMutation({
28
+ ...mutation,
29
+ async mutationFn(variables: exportPrivateKey.Parameters) {
30
+ return exportPrivateKey(config, variables)
31
+ },
32
+ mutationKey: ['exportPrivateKey'],
33
+ })
34
+ }
35
+
36
+ export declare namespace useExportPrivateKey {
37
+ type Parameters<
38
+ config extends Config = Config,
39
+ context = unknown,
40
+ > = ConfigParameter<config> & {
41
+ mutation?:
42
+ | UseMutationOptions<
43
+ exportPrivateKey.ReturnType,
44
+ exportPrivateKey.ErrorType,
45
+ exportPrivateKey.Parameters,
46
+ context
47
+ >
48
+ | undefined
49
+ }
50
+
51
+ type ReturnType<context = unknown> = UseMutationResult<
52
+ exportPrivateKey.ReturnType,
53
+ exportPrivateKey.ErrorType,
54
+ exportPrivateKey.Parameters,
55
+ context
56
+ >
57
+ }
package/src/index.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export type { ZeroDevWalletConnectorParams } from './connector.js'
2
2
  export { zeroDevWallet } from './connector.js'
3
3
  export { useAuthenticateOAuth } from './hooks/useAuthenticateOAuth.js'
4
+ export { useExportPrivateKey } from './hooks/useExportPrivateKey.js'
4
5
  export { useExportWallet } from './hooks/useExportWallet.js'
5
6
  export { useLoginPasskey } from './hooks/useLoginPasskey.js'
6
7
  export { useRefreshSession } from './hooks/useRefreshSession.js'