@zerodev/wallet-core 0.0.1-alpha.20 → 0.0.1-alpha.22

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 (100) hide show
  1. package/README.md +56 -0
  2. package/dist/_cjs/core/{createZeroDevWallet.js → createZeroDevWalletCore.js} +7 -10
  3. package/dist/_cjs/core/createZeroDevWalletCore.js.map +1 -0
  4. package/dist/_cjs/index.js +9 -7
  5. package/dist/_cjs/index.js.map +1 -1
  6. package/dist/_cjs/index.native.js +39 -0
  7. package/dist/_cjs/index.native.js.map +1 -0
  8. package/dist/_cjs/native/createZeroDevWallet.js +13 -0
  9. package/dist/_cjs/native/createZeroDevWallet.js.map +1 -0
  10. package/dist/_cjs/native/stampers/passkey.js +30 -0
  11. package/dist/_cjs/native/stampers/passkey.js.map +1 -0
  12. package/dist/_cjs/native/stampers/secureStore.js +112 -0
  13. package/dist/_cjs/native/stampers/secureStore.js.map +1 -0
  14. package/dist/_cjs/native/storage/asyncStorage.js +11 -0
  15. package/dist/_cjs/native/storage/asyncStorage.js.map +1 -0
  16. package/dist/_cjs/stampers/noopPasskeyStamper.js +16 -0
  17. package/dist/_cjs/stampers/noopPasskeyStamper.js.map +1 -0
  18. package/dist/_cjs/stubs/native-on-web.js +12 -0
  19. package/dist/_cjs/stubs/native-on-web.js.map +1 -0
  20. package/dist/_cjs/utils/exportWallet.js +52 -57
  21. package/dist/_cjs/utils/exportWallet.js.map +1 -1
  22. package/dist/_cjs/utils/platform.js +19 -0
  23. package/dist/_cjs/utils/platform.js.map +1 -0
  24. package/dist/_cjs/web/createZeroDevWallet.js +21 -0
  25. package/dist/_cjs/web/createZeroDevWallet.js.map +1 -0
  26. package/dist/_esm/core/{createZeroDevWallet.js → createZeroDevWalletCore.js} +6 -9
  27. package/dist/_esm/core/createZeroDevWalletCore.js.map +1 -0
  28. package/dist/_esm/index.js +11 -3
  29. package/dist/_esm/index.js.map +1 -1
  30. package/dist/_esm/index.native.js +19 -0
  31. package/dist/_esm/index.native.js.map +1 -0
  32. package/dist/_esm/native/createZeroDevWallet.js +10 -0
  33. package/dist/_esm/native/createZeroDevWallet.js.map +1 -0
  34. package/dist/_esm/native/stampers/passkey.js +27 -0
  35. package/dist/_esm/native/stampers/passkey.js.map +1 -0
  36. package/dist/_esm/native/stampers/secureStore.js +120 -0
  37. package/dist/_esm/native/stampers/secureStore.js.map +1 -0
  38. package/dist/_esm/native/storage/asyncStorage.js +13 -0
  39. package/dist/_esm/native/storage/asyncStorage.js.map +1 -0
  40. package/dist/_esm/stampers/noopPasskeyStamper.js +18 -0
  41. package/dist/_esm/stampers/noopPasskeyStamper.js.map +1 -0
  42. package/dist/_esm/stubs/native-on-web.js +25 -0
  43. package/dist/_esm/stubs/native-on-web.js.map +1 -0
  44. package/dist/_esm/utils/exportWallet.js +52 -57
  45. package/dist/_esm/utils/exportWallet.js.map +1 -1
  46. package/dist/_esm/utils/platform.js +16 -0
  47. package/dist/_esm/utils/platform.js.map +1 -0
  48. package/dist/_esm/web/createZeroDevWallet.js +18 -0
  49. package/dist/_esm/web/createZeroDevWallet.js.map +1 -0
  50. package/dist/_types/core/{createZeroDevWallet.d.ts → createZeroDevWalletCore.d.ts} +6 -6
  51. package/dist/_types/core/createZeroDevWalletCore.d.ts.map +1 -0
  52. package/dist/_types/index.d.ts +3 -3
  53. package/dist/_types/index.d.ts.map +1 -1
  54. package/dist/_types/index.native.d.ts +19 -0
  55. package/dist/_types/index.native.d.ts.map +1 -0
  56. package/dist/_types/native/createZeroDevWallet.d.ts +12 -0
  57. package/dist/_types/native/createZeroDevWallet.d.ts.map +1 -0
  58. package/dist/_types/native/stampers/passkey.d.ts +5 -0
  59. package/dist/_types/native/stampers/passkey.d.ts.map +1 -0
  60. package/dist/_types/native/stampers/secureStore.d.ts +3 -0
  61. package/dist/_types/native/stampers/secureStore.d.ts.map +1 -0
  62. package/dist/_types/native/storage/asyncStorage.d.ts +3 -0
  63. package/dist/_types/native/storage/asyncStorage.d.ts.map +1 -0
  64. package/dist/_types/stampers/noopPasskeyStamper.d.ts +8 -0
  65. package/dist/_types/stampers/noopPasskeyStamper.d.ts.map +1 -0
  66. package/dist/_types/stubs/native-on-web.d.ts +6 -0
  67. package/dist/_types/stubs/native-on-web.d.ts.map +1 -0
  68. package/dist/_types/utils/exportPrivateKey.d.ts +1 -1
  69. package/dist/_types/utils/exportPrivateKey.d.ts.map +1 -1
  70. package/dist/_types/utils/exportWallet.d.ts +1 -1
  71. package/dist/_types/utils/exportWallet.d.ts.map +1 -1
  72. package/dist/_types/utils/platform.d.ts +2 -0
  73. package/dist/_types/utils/platform.d.ts.map +1 -0
  74. package/dist/_types/web/createZeroDevWallet.d.ts +18 -0
  75. package/dist/_types/web/createZeroDevWallet.d.ts.map +1 -0
  76. package/dist/tsconfig.build.tsbuildinfo +1 -1
  77. package/package.json +96 -11
  78. package/src/core/{createZeroDevWallet.ts → createZeroDevWalletCore.ts} +11 -18
  79. package/src/index.native.ts +103 -0
  80. package/src/index.ts +19 -9
  81. package/src/native/createZeroDevWallet.ts +26 -0
  82. package/src/native/stampers/passkey.ts +39 -0
  83. package/src/native/stampers/secureStore.ts +139 -0
  84. package/src/native/storage/asyncStorage.ts +18 -0
  85. package/src/stampers/noopPasskeyStamper.ts +21 -0
  86. package/src/stubs/native-on-web.ts +29 -0
  87. package/src/utils/exportPrivateKey.ts +1 -1
  88. package/src/utils/exportWallet.ts +66 -71
  89. package/src/utils/platform.ts +21 -0
  90. package/src/web/createZeroDevWallet.ts +45 -0
  91. package/dist/_cjs/core/createZeroDevWallet.js.map +0 -1
  92. package/dist/_cjs/stampers/index.js +0 -10
  93. package/dist/_cjs/stampers/index.js.map +0 -1
  94. package/dist/_esm/core/createZeroDevWallet.js.map +0 -1
  95. package/dist/_esm/stampers/index.js +0 -4
  96. package/dist/_esm/stampers/index.js.map +0 -1
  97. package/dist/_types/core/createZeroDevWallet.d.ts.map +0 -1
  98. package/dist/_types/stampers/index.d.ts +0 -5
  99. package/dist/_types/stampers/index.d.ts.map +0 -1
  100. package/src/stampers/index.ts +0 -8
package/package.json CHANGED
@@ -1,15 +1,69 @@
1
1
  {
2
2
  "name": "@zerodev/wallet-core",
3
- "version": "0.0.1-alpha.20",
3
+ "version": "0.0.1-alpha.22",
4
4
  "description": "ZeroDev Wallet SDK built on Turnkey",
5
+ "sideEffects": false,
5
6
  "main": "./dist/_cjs/index.js",
6
7
  "module": "./dist/_esm/index.js",
7
8
  "types": "./dist/_types/index.d.ts",
8
9
  "exports": {
9
10
  ".": {
10
- "types": "./dist/_types/index.d.ts",
11
- "import": "./dist/_esm/index.js",
12
- "require": "./dist/_cjs/index.js"
11
+ "react-native": {
12
+ "types": "./dist/_types/index.native.d.ts",
13
+ "default": "./dist/_esm/index.native.js"
14
+ },
15
+ "browser": {
16
+ "types": "./dist/_types/index.d.ts",
17
+ "default": "./dist/_esm/index.js"
18
+ },
19
+ "import": {
20
+ "types": "./dist/_types/index.d.ts",
21
+ "default": "./dist/_esm/index.js"
22
+ },
23
+ "require": {
24
+ "types": "./dist/_types/index.d.ts",
25
+ "default": "./dist/_cjs/index.js"
26
+ },
27
+ "default": {
28
+ "types": "./dist/_types/index.d.ts",
29
+ "default": "./dist/_esm/index.js"
30
+ }
31
+ },
32
+ "./react-native": {
33
+ "browser": "./dist/_esm/stubs/native-on-web.js",
34
+ "node": "./dist/_esm/stubs/native-on-web.js",
35
+ "import": {
36
+ "types": "./dist/_types/index.native.d.ts",
37
+ "default": "./dist/_esm/index.native.js"
38
+ },
39
+ "default": "./dist/_esm/index.native.js"
40
+ },
41
+ "./react-native/stampers/secure-store": {
42
+ "browser": "./dist/_esm/stubs/native-on-web.js",
43
+ "node": "./dist/_esm/stubs/native-on-web.js",
44
+ "import": {
45
+ "types": "./dist/_types/native/stampers/secureStore.d.ts",
46
+ "default": "./dist/_esm/native/stampers/secureStore.js"
47
+ },
48
+ "default": "./dist/_esm/native/stampers/secureStore.js"
49
+ },
50
+ "./react-native/stampers/passkey": {
51
+ "browser": "./dist/_esm/stubs/native-on-web.js",
52
+ "node": "./dist/_esm/stubs/native-on-web.js",
53
+ "import": {
54
+ "types": "./dist/_types/native/stampers/passkey.d.ts",
55
+ "default": "./dist/_esm/native/stampers/passkey.js"
56
+ },
57
+ "default": "./dist/_esm/native/stampers/passkey.js"
58
+ },
59
+ "./react-native/storage/async-storage": {
60
+ "browser": "./dist/_esm/stubs/native-on-web.js",
61
+ "node": "./dist/_esm/stubs/native-on-web.js",
62
+ "import": {
63
+ "types": "./dist/_types/native/storage/asyncStorage.d.ts",
64
+ "default": "./dist/_esm/native/storage/asyncStorage.js"
65
+ },
66
+ "default": "./dist/_esm/native/storage/asyncStorage.js"
13
67
  },
14
68
  "./viem": {
15
69
  "types": "./dist/_types/adapters/viem.d.ts",
@@ -20,11 +74,6 @@
20
74
  "types": "./dist/_types/actions/index.d.ts",
21
75
  "import": "./dist/_esm/actions/index.js",
22
76
  "require": "./dist/_cjs/actions/index.js"
23
- },
24
- "./stampers": {
25
- "types": "./dist/_types/stampers/index.d.ts",
26
- "import": "./dist/_esm/stampers/index.js",
27
- "require": "./dist/_cjs/stampers/index.js"
28
77
  }
29
78
  },
30
79
  "files": [
@@ -59,12 +108,48 @@
59
108
  "json-canonicalize": "^2.0.0"
60
109
  },
61
110
  "peerDependencies": {
62
- "viem": "^2.38.0"
111
+ "viem": "^2.38.0",
112
+ "@react-native-async-storage/async-storage": ">=2.0.0",
113
+ "@turnkey/api-key-stamper": ">=0.6.0",
114
+ "@turnkey/crypto": ">=2.8.0",
115
+ "@turnkey/react-native-passkey-stamper": ">=1.2.0",
116
+ "expo-secure-store": ">=14.0.0",
117
+ "react-native": ">=0.73.0",
118
+ "uuid": ">=11.0.0"
119
+ },
120
+ "peerDependenciesMeta": {
121
+ "@react-native-async-storage/async-storage": {
122
+ "optional": true
123
+ },
124
+ "@turnkey/api-key-stamper": {
125
+ "optional": true
126
+ },
127
+ "@turnkey/crypto": {
128
+ "optional": true
129
+ },
130
+ "@turnkey/react-native-passkey-stamper": {
131
+ "optional": true
132
+ },
133
+ "expo-secure-store": {
134
+ "optional": true
135
+ },
136
+ "react-native": {
137
+ "optional": true
138
+ },
139
+ "uuid": {
140
+ "optional": true
141
+ }
63
142
  },
64
143
  "devDependencies": {
65
144
  "@hpke/core": "^1.9.0",
145
+ "@react-native-async-storage/async-storage": "2.2.0",
146
+ "@turnkey/api-key-stamper": "0.6.4",
147
+ "@turnkey/crypto": "2.8.13",
148
+ "@turnkey/react-native-passkey-stamper": "1.2.12",
66
149
  "@types/node": "^20.0.0",
67
- "typescript": "5.9.3"
150
+ "expo-secure-store": "55.0.9",
151
+ "typescript": "5.9.3",
152
+ "uuid": "^13.0.0"
68
153
  },
69
154
  "scripts": {
70
155
  "build": "pnpm run clean && pnpm run build:cjs && pnpm run build:esm && pnpm run build:types",
@@ -16,10 +16,8 @@ import {
16
16
  DEFAULT_SESSION_EXPIRATION_IN_SECONDS,
17
17
  KMS_SERVER_URL,
18
18
  } from '../constants.js'
19
- import { createIndexedDbStamper } from '../stampers/indexedDbStamper.js'
19
+ import { createNoopPasskeyStamper } from '../stampers/noopPasskeyStamper.js'
20
20
  import type { ApiKeyStamper, PasskeyStamper } from '../stampers/types.js'
21
- import { createWebauthnStamper } from '../stampers/webauthnStamper.js'
22
- import { createWebStorageAdapter } from '../storage/adapters.js'
23
21
  import {
24
22
  createStorageManager,
25
23
  type StorageAdapter,
@@ -28,13 +26,13 @@ import { SessionType, type ZeroDevWalletSession } from '../types/session.js'
28
26
  import { buildClientSignature } from '../utils/buildClientSignature.js'
29
27
  import { encryptOtpAttempt } from '../utils/encryptOtpAttempt.js'
30
28
  import { humanReadableDateTime, parseSession } from '../utils/utils.js'
31
- export interface ZeroDevWalletConfig {
29
+ export interface ZeroDevWalletConfigCore {
32
30
  organizationId?: string
33
31
  proxyBaseUrl?: string
34
32
  projectId: string
35
- sessionStorage?: StorageAdapter
36
- rpId?: string
37
- apiKeyStamper?: ApiKeyStamper
33
+ sessionStorage: StorageAdapter
34
+ rpId: string
35
+ apiKeyStamper: ApiKeyStamper
38
36
  passkeyStamper?: PasskeyStamper
39
37
  fetchOptions?: CreateTransportOptions['fetchOptions']
40
38
  }
@@ -118,24 +116,19 @@ export interface ZeroDevWalletSDK {
118
116
  toAccount: () => Promise<LocalAccount>
119
117
  }
120
118
 
121
- export async function createZeroDevWallet(
122
- config: ZeroDevWalletConfig,
119
+ export async function createZeroDevWalletCore(
120
+ config: ZeroDevWalletConfigCore,
123
121
  ): Promise<ZeroDevWalletSDK> {
124
122
  const {
125
123
  projectId,
126
124
  sessionStorage,
127
- rpId = window.location.hostname,
125
+ rpId,
126
+ apiKeyStamper,
128
127
  organizationId = DEFAULT_ORGANIZATION_ID,
129
128
  } = config
129
+ const passkeyStamper = config.passkeyStamper ?? createNoopPasskeyStamper()
130
130
 
131
- const sessionStorageManager = createStorageManager(
132
- sessionStorage || createWebStorageAdapter(),
133
- )
134
-
135
- const apiKeyStamper = config.apiKeyStamper ?? (await createIndexedDbStamper())
136
-
137
- const passkeyStamper =
138
- config.passkeyStamper ?? (await createWebauthnStamper({ rpId }))
131
+ const sessionStorageManager = createStorageManager(sessionStorage)
139
132
 
140
133
  const client = createClient({
141
134
  apiKeyStamper,
@@ -0,0 +1,103 @@
1
+ import { isReactNative } from './utils/platform.js'
2
+
3
+ if (!isReactNative()) {
4
+ // biome-ignore lint/suspicious/noConsole: Warning users if they try to use the web entry on React Native.
5
+ console.warn(
6
+ '@zerodev/wallet-core/react-native: the React Native entry was loaded outside a React Native runtime. If this is a non-RN context, import `@zerodev/wallet-core` (the bare specifier) instead.',
7
+ )
8
+ }
9
+
10
+ // Re-export shared API surface. Note: we intentionally do NOT re-export the
11
+ // web stamper factories (createIndexedDbStamper, createWebauthnStamper,
12
+ // createIframeStamper) here — they're web-only. The native adapter factories
13
+ // live behind their own granular subpaths so consumers using alternative
14
+ // adapters (Keychain, MMKV, custom) skip the unused peer-dep installs.
15
+ export type {
16
+ ApiKeyAuthenticator,
17
+ AuthenticateWithEmailParameters,
18
+ AuthenticateWithEmailReturnType,
19
+ AuthenticateWithOAuthParameters,
20
+ AuthenticateWithOAuthReturnType,
21
+ EmailContact,
22
+ EmailCustomization,
23
+ GetAuthenticatorsParameters,
24
+ GetAuthenticatorsReturnType,
25
+ GetUserWalletParameters,
26
+ GetUserWalletReturnType,
27
+ GetWhoamiParameters,
28
+ GetWhoamiReturnType,
29
+ LoginWithOTPParameters,
30
+ LoginWithOTPReturnType,
31
+ OAuthAuthenticator,
32
+ OtpContact,
33
+ PasskeyAuthenticator,
34
+ RegisterWithOTPParameters,
35
+ RegisterWithOTPReturnType,
36
+ Sign7702AuthorizationParameters,
37
+ Sign7702AuthorizationReturnType,
38
+ SignMessageParameters,
39
+ SignMessageReturnType,
40
+ SignTransactionParameters,
41
+ SignTransactionReturnType,
42
+ SignTypedDataV4Parameters,
43
+ SignTypedDataV4ReturnType,
44
+ SignUserOperationParameters,
45
+ SignUserOperationReturnType,
46
+ } from './actions/index.js'
47
+ export {
48
+ authenticateWithEmail,
49
+ authenticateWithOAuth,
50
+ getAuthenticators,
51
+ getUserWallet,
52
+ getWhoami,
53
+ loginWithOTP,
54
+ registerWithOTP,
55
+ sign7702Authorization,
56
+ signMessage,
57
+ signTransaction,
58
+ signTypedDataV4,
59
+ signUserOperation,
60
+ } from './actions/index.js'
61
+ export type { ToViemAccountParams } from './adapters/viem.js'
62
+ export { toViemAccount } from './adapters/viem.js'
63
+ export type { ZeroDevWalletActions } from './client/decorators/client.js'
64
+ export { zeroDevWalletActions } from './client/decorators/client.js'
65
+ export type {
66
+ Client,
67
+ ClientConfig,
68
+ CreateTransportOptions,
69
+ Transport,
70
+ } from './client/index.js'
71
+ export {
72
+ createBaseClient,
73
+ createClient,
74
+ type ZeroDevWalletClient,
75
+ zeroDevWalletTransport,
76
+ } from './client/index.js'
77
+ export { KMS_SERVER_URL } from './constants.js'
78
+ export type {
79
+ AuthParams,
80
+ ZeroDevWalletSDK,
81
+ } from './core/createZeroDevWalletCore.js'
82
+ // RN entry re-exports through a thin wrapper that auto-injects the
83
+ // `Origin: https://${rpId}` header on Turnkey requests. `ZeroDevWalletConfig`
84
+ // matches the strict `ZeroDevWalletConfigCore` shape, so RN consumers still
85
+ // get compile-time enforcement of the four required adapter fields.
86
+ export {
87
+ createZeroDevWallet,
88
+ type ZeroDevWalletConfig,
89
+ } from './native/createZeroDevWallet.js'
90
+ export type {
91
+ ApiKeyStamper,
92
+ Attestation,
93
+ IframeStamper,
94
+ PasskeyRegistrationOptions,
95
+ PasskeyRegistrationResult,
96
+ PasskeyStamper,
97
+ } from './stampers/types.js'
98
+ export type { StorageAdapter, StorageManager } from './storage/manager.js'
99
+ export type { StamperType, ZeroDevWalletSession } from './types/session.js'
100
+ export type { KeyFormat } from './utils/exportPrivateKey.js'
101
+ export { exportPrivateKey } from './utils/exportPrivateKey.js'
102
+ export { exportWallet } from './utils/exportWallet.js'
103
+ export { normalizeTimestamp } from './utils/utils.js'
package/src/index.ts CHANGED
@@ -1,3 +1,12 @@
1
+ import { isReactNative } from './utils/platform.js'
2
+
3
+ if (isReactNative()) {
4
+ // biome-ignore lint/suspicious/noConsole: Warning users if they try to use the web entry on React Native.
5
+ console.warn(
6
+ '@zerodev/wallet-core: the web entry was loaded in a React Native runtime. Check that your metro.config.js has `unstable_enablePackageExports: true` and `"react-native"` in `unstable_conditionNames`.',
7
+ )
8
+ }
9
+
1
10
  export type {
2
11
  // Auth types
3
12
  ApiKeyAuthenticator,
@@ -73,17 +82,10 @@ export {
73
82
  export { KMS_SERVER_URL } from './constants.js'
74
83
  export type {
75
84
  AuthParams,
76
- ZeroDevWalletConfig,
77
85
  ZeroDevWalletSDK,
78
- } from './core/createZeroDevWallet.js'
79
- // Core
80
- export { createZeroDevWallet } from './core/createZeroDevWallet.js'
86
+ } from './core/createZeroDevWalletCore.js'
81
87
  // Stampers
82
- export {
83
- createIframeStamper,
84
- createIndexedDbStamper,
85
- createWebauthnStamper,
86
- } from './stampers/index.js'
88
+ export { createIframeStamper } from './stampers/iframeStamper.js'
87
89
  export type {
88
90
  ApiKeyStamper,
89
91
  Attestation,
@@ -101,3 +103,11 @@ export { exportPrivateKey } from './utils/exportPrivateKey.js'
101
103
  export { exportWallet } from './utils/exportWallet.js'
102
104
  // Utils
103
105
  export { normalizeTimestamp } from './utils/utils.js'
106
+ // Core — bare specifier resolves web defaults (IndexedDB, WebAuthn, session
107
+ // storage, hostname-derived rpId) before forwarding to the shared factory.
108
+ // RN consumers go through `@zerodev/wallet-core/react-native`, which exposes
109
+ // the strict `ZeroDevWalletConfig` (= core's required-fields shape) directly.
110
+ export {
111
+ createZeroDevWallet,
112
+ type ZeroDevWalletConfig,
113
+ } from './web/createZeroDevWallet.js'
@@ -0,0 +1,26 @@
1
+ import {
2
+ createZeroDevWalletCore,
3
+ type ZeroDevWalletConfigCore,
4
+ type ZeroDevWalletSDK,
5
+ } from '../core/createZeroDevWalletCore.js'
6
+
7
+ /**
8
+ * React Native config — mirrors `web/createZeroDevWallet.ts`'s wrapper
9
+ * pattern. RN consumers must supply all four adapter fields up front
10
+ * (no platform-native defaults exist for IndexedDB/WebAuthn). The only
11
+ * RN-specific defaulting is `fetchOptions`: when omitted, we set
12
+ * `Origin: https://${rpId}` so Turnkey's ACL accepts the request. Power
13
+ * users wanting a different Origin can pass `fetchOptions` explicitly.
14
+ */
15
+ export type ZeroDevWalletConfig = ZeroDevWalletConfigCore
16
+
17
+ export async function createZeroDevWallet(
18
+ config: ZeroDevWalletConfig,
19
+ ): Promise<ZeroDevWalletSDK> {
20
+ return createZeroDevWalletCore({
21
+ ...config,
22
+ fetchOptions: config.fetchOptions ?? {
23
+ headers: { Origin: `https://${config.rpId}` },
24
+ },
25
+ })
26
+ }
@@ -0,0 +1,39 @@
1
+ import {
2
+ createPasskey,
3
+ PasskeyStamper as TurnkeyPasskeyStamper,
4
+ } from '@turnkey/react-native-passkey-stamper'
5
+ import { v4 as uuidv4 } from 'uuid'
6
+ import type {
7
+ PasskeyRegistrationOptions,
8
+ PasskeyStamper,
9
+ } from '../../stampers/types.js'
10
+
11
+ export async function createReactNativePasskeyStamper({
12
+ rpId,
13
+ }: {
14
+ rpId: string
15
+ }): Promise<PasskeyStamper> {
16
+ const inner = new TurnkeyPasskeyStamper({ rpId })
17
+
18
+ return {
19
+ async stamp(payload: string) {
20
+ return await inner.stamp(payload)
21
+ },
22
+ async clear() {},
23
+ async register({ rp, userName }: PasskeyRegistrationOptions) {
24
+ const { attestation, challenge: encodedChallenge } = await createPasskey({
25
+ rp: {
26
+ id: rp.id,
27
+ name: rp.name ?? 'Turnkey',
28
+ },
29
+ user: {
30
+ id: uuidv4(),
31
+ name: userName,
32
+ displayName: userName,
33
+ },
34
+ authenticatorName: userName ?? 'End-User Passkey',
35
+ })
36
+ return { attestation, encodedChallenge }
37
+ },
38
+ }
39
+ }
@@ -0,0 +1,139 @@
1
+ import { ApiKeyStamper, SignatureFormat } from '@turnkey/api-key-stamper'
2
+ import { generateP256KeyPair } from '@turnkey/crypto'
3
+ import * as SecureStore from 'expo-secure-store'
4
+ import type { ApiKeyStamper as ZDApiKeyStamper } from '../../stampers/types.js'
5
+
6
+ const PUBLIC_KEY = 'zerodev.publicKey'
7
+ const PRIVATE_KEY = 'zerodev.privateKey'
8
+
9
+ class SecureStoreStamperInner {
10
+ private publicKeyHex: string | null = null
11
+
12
+ async init(): Promise<void> {
13
+ const publicKey = await SecureStore.getItemAsync(PUBLIC_KEY)
14
+ const privateKey = await SecureStore.getItemAsync(PRIVATE_KEY)
15
+
16
+ if (publicKey && privateKey) {
17
+ this.publicKeyHex = publicKey
18
+ } else {
19
+ await this.resetKeyPair()
20
+ }
21
+ }
22
+
23
+ async getPublicKey(): Promise<string | null> {
24
+ return this.publicKeyHex
25
+ }
26
+
27
+ async resetKeyPair(externalKeyPair?: {
28
+ publicKey: string
29
+ privateKey: string
30
+ }): Promise<void> {
31
+ await this.clear()
32
+
33
+ const pair = externalKeyPair ?? generateP256KeyPair()
34
+
35
+ await SecureStore.setItemAsync(PUBLIC_KEY, pair.publicKey)
36
+ await SecureStore.setItemAsync(PRIVATE_KEY, pair.privateKey)
37
+
38
+ this.publicKeyHex = pair.publicKey
39
+ }
40
+
41
+ private async getTurnkeyApiKeyStamper(): Promise<ApiKeyStamper> {
42
+ if (!this.publicKeyHex) {
43
+ throw new Error(
44
+ 'Key not initialized. Call init() or resetKeyPair() first.',
45
+ )
46
+ }
47
+
48
+ const privateKey = await SecureStore.getItemAsync(PRIVATE_KEY)
49
+ if (!privateKey) {
50
+ throw new Error('No private key found in secure store.')
51
+ }
52
+
53
+ return new ApiKeyStamper({
54
+ apiPublicKey: this.publicKeyHex,
55
+ apiPrivateKey: privateKey,
56
+ })
57
+ }
58
+
59
+ async stamp(
60
+ payload: string,
61
+ ): Promise<{ stampHeaderName: string; stampHeaderValue: string }> {
62
+ const stamper = await this.getTurnkeyApiKeyStamper()
63
+ const { stampHeaderName, stampHeaderValue } = await stamper.stamp(payload)
64
+ return { stampHeaderName, stampHeaderValue }
65
+ }
66
+
67
+ async sign(payload: string): Promise<string> {
68
+ const stamper = await this.getTurnkeyApiKeyStamper()
69
+ return stamper.sign(payload, SignatureFormat.Der)
70
+ }
71
+
72
+ async clear(): Promise<void> {
73
+ await SecureStore.deleteItemAsync(PUBLIC_KEY)
74
+ await SecureStore.deleteItemAsync(PRIVATE_KEY)
75
+ this.publicKeyHex = null
76
+ }
77
+ }
78
+
79
+ async function warmApiKeyStamperForMetroDev(
80
+ inner: SecureStoreStamperInner,
81
+ ): Promise<void> {
82
+ // `__DEV__` is a global set by React Native's Metro; read it via globalThis
83
+ // so this file needs no ambient `.d.ts` (which would conflict with RN's own
84
+ // typings when both happen to be in scope, e.g. in the editor).
85
+ if (!(globalThis as { __DEV__?: boolean }).__DEV__) return
86
+
87
+ // In Expo dev, Turnkey's API key stamper loads its React Native signer with a
88
+ // dynamic import the first time `stamp()` runs. OTP verification is usually
89
+ // the first code path that stamps a payload, and if the app was backgrounded
90
+ // while the user copied the code, Metro can serve that lazy module after
91
+ // foregrounding and trigger a full JS reload. Warming the stamper during dev
92
+ // startup makes Metro load the signer while the app is foregrounded; production
93
+ // builds do not use Metro and skip this block via `__DEV__`.
94
+ try {
95
+ await inner.stamp('{"purpose":"metro-dev-warmup"}')
96
+ } catch (error) {
97
+ // biome-ignore lint/suspicious/noConsole: This only runs in dev mode
98
+ console.warn('Failed to warm API key stamper in dev:', error)
99
+ }
100
+ }
101
+
102
+ export async function createSecureStoreStamper(): Promise<ZDApiKeyStamper> {
103
+ const inner = new SecureStoreStamperInner()
104
+ await inner.init()
105
+ await warmApiKeyStamperForMetroDev(inner)
106
+
107
+ let pendingKeyPair: { publicKey: string; privateKey: string } | null = null
108
+
109
+ return {
110
+ async getPublicKey() {
111
+ return inner.getPublicKey()
112
+ },
113
+ async stamp(payload: string) {
114
+ return inner.stamp(payload)
115
+ },
116
+ async sign(payload: string) {
117
+ return inner.sign(payload)
118
+ },
119
+ async clear() {
120
+ await inner.clear()
121
+ },
122
+ async resetKeyPair() {
123
+ pendingKeyPair = null
124
+ await inner.resetKeyPair()
125
+ },
126
+ async prepareKeyRotation() {
127
+ const keyPair = generateP256KeyPair()
128
+ pendingKeyPair = keyPair
129
+ return keyPair.publicKey
130
+ },
131
+ async commitKeyRotation() {
132
+ if (!pendingKeyPair) {
133
+ throw new Error('No pending key rotation to commit')
134
+ }
135
+ await inner.resetKeyPair(pendingKeyPair)
136
+ pendingKeyPair = null
137
+ },
138
+ }
139
+ }
@@ -0,0 +1,18 @@
1
+ import type { AsyncStorageStatic } from '@react-native-async-storage/async-storage'
2
+ import * as AsyncStorageNS from '@react-native-async-storage/async-storage'
3
+ import type { StorageAdapter } from '../../storage/manager.js'
4
+
5
+ // CJS package whose `.d.ts` declares `export default AsyncStorage`. Our tsconfig
6
+ // keeps `esModuleInterop: false` (and `verbatimModuleSyntax: true`), so a plain
7
+ // `import AsyncStorage from '...'` types as the module namespace instead of
8
+ // the default. Unwrap explicitly. At runtime Metro returns the default object
9
+ // either way; this only affects the static type.
10
+ const AsyncStorage: AsyncStorageStatic = (
11
+ AsyncStorageNS as unknown as { default: AsyncStorageStatic }
12
+ ).default
13
+
14
+ export const asyncStorageAdapter: StorageAdapter = {
15
+ getItem: (key) => AsyncStorage.getItem(key),
16
+ setItem: (key, value) => AsyncStorage.setItem(key, value),
17
+ removeItem: (key) => AsyncStorage.removeItem(key),
18
+ }
@@ -0,0 +1,21 @@
1
+ import type { PasskeyStamper } from './types.js'
2
+
3
+ const NOT_CONFIGURED_MESSAGE =
4
+ 'passkeyStamper is not configured. Pass passkeyStamper to zeroDevWallet({ ... }) — use createReactNativePasskeyStamper({ rpId }) on React Native or createWebauthnStamper({ rpId }) on web.'
5
+
6
+ /**
7
+ * Internal fallback used when a consumer doesn't supply a `passkeyStamper`.
8
+ * Methods throw on use, so passkey register/login fails with an actionable
9
+ * message — all other flows (apiKey signing, OAuth, OTP) are unaffected.
10
+ */
11
+ export function createNoopPasskeyStamper(): PasskeyStamper {
12
+ return {
13
+ async stamp() {
14
+ throw new Error(NOT_CONFIGURED_MESSAGE)
15
+ },
16
+ async register() {
17
+ throw new Error(NOT_CONFIGURED_MESSAGE)
18
+ },
19
+ async clear() {},
20
+ }
21
+ }
@@ -0,0 +1,29 @@
1
+ // Catch-all stub used by every `./react-native/*` subpath in this package
2
+ // under the `browser` and `node` exports conditions. Both are needed for
3
+ // Expo web: the client bundle resolves with `browser` active, while Expo
4
+ // Router's SSR/RSC route render drops platform conditions (no `browser`)
5
+ // and turns on `node` instead — so the web stub has to be gated on both or
6
+ // the SSR pass falls through to the native impl. Imports must be safe on web
7
+ // (some route files are bundled even when they aren't rendered) so we expose
8
+ // the RN-only symbols as throw-on-use functions instead of throwing at
9
+ // module-init time.
10
+ //
11
+ // Anyone who *uses* these on web gets a clear actionable error; anyone who
12
+ // merely imports them (typically because their universal app bundles the
13
+ // native variant too) is unaffected.
14
+
15
+ const message =
16
+ '@zerodev/wallet-core react-native subpaths cannot be imported in a web environment. Use the bare specifier (`import { ... } from "@zerodev/wallet-core"`) instead.'
17
+
18
+ function throwOnUse(): never {
19
+ throw new Error(message)
20
+ }
21
+
22
+ export const createSecureStoreStamper = throwOnUse
23
+ export const createReactNativePasskeyStamper = throwOnUse
24
+ export const asyncStorageAdapter = throwOnUse
25
+
26
+ // For the broad `./react-native` entry: any consumer reaching it on web is
27
+ // already off-pattern (they should use the bare specifier). Default export
28
+ // covers `import X from '...'`.
29
+ export default throwOnUse
@@ -1,4 +1,4 @@
1
- import type { ZeroDevWalletSDK } from '../core/createZeroDevWallet.js'
1
+ import type { ZeroDevWalletSDK } from '../core/createZeroDevWalletCore.js'
2
2
  import type { KeyFormat } from '../stampers/types.js'
3
3
 
4
4
  export type ExportPrivateKeyParameters = {