@zerodev/wallet-core 0.0.1-alpha.10

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 (292) hide show
  1. package/README.md +310 -0
  2. package/dist/_cjs/actions/auth/authenticateWithEmail.js +17 -0
  3. package/dist/_cjs/actions/auth/authenticateWithEmail.js.map +1 -0
  4. package/dist/_cjs/actions/auth/authenticateWithOAuth.js +13 -0
  5. package/dist/_cjs/actions/auth/authenticateWithOAuth.js.map +1 -0
  6. package/dist/_cjs/actions/auth/getAuthProxyConfigId.js +10 -0
  7. package/dist/_cjs/actions/auth/getAuthProxyConfigId.js.map +1 -0
  8. package/dist/_cjs/actions/auth/getUserEmail.js +19 -0
  9. package/dist/_cjs/actions/auth/getUserEmail.js.map +1 -0
  10. package/dist/_cjs/actions/auth/getWhoami.js +15 -0
  11. package/dist/_cjs/actions/auth/getWhoami.js.map +1 -0
  12. package/dist/_cjs/actions/auth/index.js +22 -0
  13. package/dist/_cjs/actions/auth/index.js.map +1 -0
  14. package/dist/_cjs/actions/auth/loginWithOTP.js +15 -0
  15. package/dist/_cjs/actions/auth/loginWithOTP.js.map +1 -0
  16. package/dist/_cjs/actions/auth/loginWithStamp.js +39 -0
  17. package/dist/_cjs/actions/auth/loginWithStamp.js.map +1 -0
  18. package/dist/_cjs/actions/auth/registerWithOTP.js +16 -0
  19. package/dist/_cjs/actions/auth/registerWithOTP.js.map +1 -0
  20. package/dist/_cjs/actions/auth/registerWithPasskey.js +17 -0
  21. package/dist/_cjs/actions/auth/registerWithPasskey.js.map +1 -0
  22. package/dist/_cjs/actions/index.js +17 -0
  23. package/dist/_cjs/actions/index.js.map +1 -0
  24. package/dist/_cjs/actions/wallet/getUserWallet.js +18 -0
  25. package/dist/_cjs/actions/wallet/getUserWallet.js.map +1 -0
  26. package/dist/_cjs/actions/wallet/index.js +10 -0
  27. package/dist/_cjs/actions/wallet/index.js.map +1 -0
  28. package/dist/_cjs/actions/wallet/signRawPayload.js +27 -0
  29. package/dist/_cjs/actions/wallet/signRawPayload.js.map +1 -0
  30. package/dist/_cjs/actions/wallet/signTransaction.js +26 -0
  31. package/dist/_cjs/actions/wallet/signTransaction.js.map +1 -0
  32. package/dist/_cjs/adapters/viem.js +92 -0
  33. package/dist/_cjs/adapters/viem.js.map +1 -0
  34. package/dist/_cjs/client/authProxy.js +31 -0
  35. package/dist/_cjs/client/authProxy.js.map +1 -0
  36. package/dist/_cjs/client/createClient.js +49 -0
  37. package/dist/_cjs/client/createClient.js.map +1 -0
  38. package/dist/_cjs/client/decorators/client.js +23 -0
  39. package/dist/_cjs/client/decorators/client.js.map +1 -0
  40. package/dist/_cjs/client/index.js +11 -0
  41. package/dist/_cjs/client/index.js.map +1 -0
  42. package/dist/_cjs/client/transports/createTransport.js +31 -0
  43. package/dist/_cjs/client/transports/createTransport.js.map +1 -0
  44. package/dist/_cjs/client/transports/rest.js +104 -0
  45. package/dist/_cjs/client/transports/rest.js.map +1 -0
  46. package/dist/_cjs/client/types.js +3 -0
  47. package/dist/_cjs/client/types.js.map +1 -0
  48. package/dist/_cjs/constants.js +9 -0
  49. package/dist/_cjs/constants.js.map +1 -0
  50. package/dist/_cjs/core/createZeroDevWallet.js +302 -0
  51. package/dist/_cjs/core/createZeroDevWallet.js.map +1 -0
  52. package/dist/_cjs/errors/request.js +61 -0
  53. package/dist/_cjs/errors/request.js.map +1 -0
  54. package/dist/_cjs/index.js +35 -0
  55. package/dist/_cjs/index.js.map +1 -0
  56. package/dist/_cjs/package.json +1 -0
  57. package/dist/_cjs/polyfills/window.js +26 -0
  58. package/dist/_cjs/polyfills/window.js.map +1 -0
  59. package/dist/_cjs/stampers/iframeStamper.js +35 -0
  60. package/dist/_cjs/stampers/iframeStamper.js.map +1 -0
  61. package/dist/_cjs/stampers/index.js +10 -0
  62. package/dist/_cjs/stampers/index.js.map +1 -0
  63. package/dist/_cjs/stampers/indexedDbStamper.js +23 -0
  64. package/dist/_cjs/stampers/indexedDbStamper.js.map +1 -0
  65. package/dist/_cjs/stampers/types.js +3 -0
  66. package/dist/_cjs/stampers/types.js.map +1 -0
  67. package/dist/_cjs/stampers/webauthnStamper.js +17 -0
  68. package/dist/_cjs/stampers/webauthnStamper.js.map +1 -0
  69. package/dist/_cjs/storage/adapters.js +18 -0
  70. package/dist/_cjs/storage/adapters.js.map +1 -0
  71. package/dist/_cjs/storage/manager.js +108 -0
  72. package/dist/_cjs/storage/manager.js.map +1 -0
  73. package/dist/_cjs/types/session.js +9 -0
  74. package/dist/_cjs/types/session.js.map +1 -0
  75. package/dist/_cjs/utils/buildClientSignature.js +39 -0
  76. package/dist/_cjs/utils/buildClientSignature.js.map +1 -0
  77. package/dist/_cjs/utils/derToRawSignature.js +63 -0
  78. package/dist/_cjs/utils/derToRawSignature.js.map +1 -0
  79. package/dist/_cjs/utils/exportPrivateKey.js +55 -0
  80. package/dist/_cjs/utils/exportPrivateKey.js.map +1 -0
  81. package/dist/_cjs/utils/exportWallet.js +70 -0
  82. package/dist/_cjs/utils/exportWallet.js.map +1 -0
  83. package/dist/_cjs/utils/utils.js +75 -0
  84. package/dist/_cjs/utils/utils.js.map +1 -0
  85. package/dist/_esm/actions/auth/authenticateWithEmail.js +18 -0
  86. package/dist/_esm/actions/auth/authenticateWithEmail.js.map +1 -0
  87. package/dist/_esm/actions/auth/authenticateWithOAuth.js +29 -0
  88. package/dist/_esm/actions/auth/authenticateWithOAuth.js.map +1 -0
  89. package/dist/_esm/actions/auth/getAuthProxyConfigId.js +13 -0
  90. package/dist/_esm/actions/auth/getAuthProxyConfigId.js.map +1 -0
  91. package/dist/_esm/actions/auth/getUserEmail.js +33 -0
  92. package/dist/_esm/actions/auth/getUserEmail.js.map +1 -0
  93. package/dist/_esm/actions/auth/getWhoami.js +28 -0
  94. package/dist/_esm/actions/auth/getWhoami.js.map +1 -0
  95. package/dist/_esm/actions/auth/index.js +10 -0
  96. package/dist/_esm/actions/auth/index.js.map +1 -0
  97. package/dist/_esm/actions/auth/loginWithOTP.js +38 -0
  98. package/dist/_esm/actions/auth/loginWithOTP.js.map +1 -0
  99. package/dist/_esm/actions/auth/loginWithStamp.js +52 -0
  100. package/dist/_esm/actions/auth/loginWithStamp.js.map +1 -0
  101. package/dist/_esm/actions/auth/registerWithOTP.js +35 -0
  102. package/dist/_esm/actions/auth/registerWithOTP.js.map +1 -0
  103. package/dist/_esm/actions/auth/registerWithPasskey.js +36 -0
  104. package/dist/_esm/actions/auth/registerWithPasskey.js.map +1 -0
  105. package/dist/_esm/actions/index.js +5 -0
  106. package/dist/_esm/actions/index.js.map +1 -0
  107. package/dist/_esm/actions/wallet/getUserWallet.js +31 -0
  108. package/dist/_esm/actions/wallet/getUserWallet.js.map +1 -0
  109. package/dist/_esm/actions/wallet/index.js +4 -0
  110. package/dist/_esm/actions/wallet/index.js.map +1 -0
  111. package/dist/_esm/actions/wallet/signRawPayload.js +42 -0
  112. package/dist/_esm/actions/wallet/signRawPayload.js.map +1 -0
  113. package/dist/_esm/actions/wallet/signTransaction.js +41 -0
  114. package/dist/_esm/actions/wallet/signTransaction.js.map +1 -0
  115. package/dist/_esm/adapters/viem.js +94 -0
  116. package/dist/_esm/adapters/viem.js.map +1 -0
  117. package/dist/_esm/client/authProxy.js +41 -0
  118. package/dist/_esm/client/authProxy.js.map +1 -0
  119. package/dist/_esm/client/createClient.js +60 -0
  120. package/dist/_esm/client/createClient.js.map +1 -0
  121. package/dist/_esm/client/decorators/client.js +44 -0
  122. package/dist/_esm/client/decorators/client.js.map +1 -0
  123. package/dist/_esm/client/index.js +4 -0
  124. package/dist/_esm/client/index.js.map +1 -0
  125. package/dist/_esm/client/transports/createTransport.js +33 -0
  126. package/dist/_esm/client/transports/createTransport.js.map +1 -0
  127. package/dist/_esm/client/transports/rest.js +103 -0
  128. package/dist/_esm/client/transports/rest.js.map +1 -0
  129. package/dist/_esm/client/types.js +2 -0
  130. package/dist/_esm/client/types.js.map +1 -0
  131. package/dist/_esm/constants.js +6 -0
  132. package/dist/_esm/constants.js.map +1 -0
  133. package/dist/_esm/core/createZeroDevWallet.js +308 -0
  134. package/dist/_esm/core/createZeroDevWallet.js.map +1 -0
  135. package/dist/_esm/errors/request.js +60 -0
  136. package/dist/_esm/errors/request.js.map +1 -0
  137. package/dist/_esm/index.js +23 -0
  138. package/dist/_esm/index.js.map +1 -0
  139. package/dist/_esm/package.json +1 -0
  140. package/dist/_esm/polyfills/window.js +24 -0
  141. package/dist/_esm/polyfills/window.js.map +1 -0
  142. package/dist/_esm/stampers/iframeStamper.js +32 -0
  143. package/dist/_esm/stampers/iframeStamper.js.map +1 -0
  144. package/dist/_esm/stampers/index.js +4 -0
  145. package/dist/_esm/stampers/index.js.map +1 -0
  146. package/dist/_esm/stampers/indexedDbStamper.js +20 -0
  147. package/dist/_esm/stampers/indexedDbStamper.js.map +1 -0
  148. package/dist/_esm/stampers/types.js +2 -0
  149. package/dist/_esm/stampers/types.js.map +1 -0
  150. package/dist/_esm/stampers/webauthnStamper.js +15 -0
  151. package/dist/_esm/stampers/webauthnStamper.js.map +1 -0
  152. package/dist/_esm/storage/adapters.js +15 -0
  153. package/dist/_esm/storage/adapters.js.map +1 -0
  154. package/dist/_esm/storage/manager.js +118 -0
  155. package/dist/_esm/storage/manager.js.map +1 -0
  156. package/dist/_esm/types/session.js +6 -0
  157. package/dist/_esm/types/session.js.map +1 -0
  158. package/dist/_esm/utils/buildClientSignature.js +64 -0
  159. package/dist/_esm/utils/buildClientSignature.js.map +1 -0
  160. package/dist/_esm/utils/derToRawSignature.js +89 -0
  161. package/dist/_esm/utils/derToRawSignature.js.map +1 -0
  162. package/dist/_esm/utils/exportPrivateKey.js +83 -0
  163. package/dist/_esm/utils/exportPrivateKey.js.map +1 -0
  164. package/dist/_esm/utils/exportWallet.js +98 -0
  165. package/dist/_esm/utils/exportWallet.js.map +1 -0
  166. package/dist/_esm/utils/utils.js +105 -0
  167. package/dist/_esm/utils/utils.js.map +1 -0
  168. package/dist/_types/actions/auth/authenticateWithEmail.d.ts +33 -0
  169. package/dist/_types/actions/auth/authenticateWithEmail.d.ts.map +1 -0
  170. package/dist/_types/actions/auth/authenticateWithOAuth.d.ts +38 -0
  171. package/dist/_types/actions/auth/authenticateWithOAuth.d.ts.map +1 -0
  172. package/dist/_types/actions/auth/getAuthProxyConfigId.d.ts +12 -0
  173. package/dist/_types/actions/auth/getAuthProxyConfigId.d.ts.map +1 -0
  174. package/dist/_types/actions/auth/getUserEmail.d.ts +32 -0
  175. package/dist/_types/actions/auth/getUserEmail.d.ts.map +1 -0
  176. package/dist/_types/actions/auth/getWhoami.d.ts +35 -0
  177. package/dist/_types/actions/auth/getWhoami.d.ts.map +1 -0
  178. package/dist/_types/actions/auth/index.d.ts +10 -0
  179. package/dist/_types/actions/auth/index.d.ts.map +1 -0
  180. package/dist/_types/actions/auth/loginWithOTP.d.ts +41 -0
  181. package/dist/_types/actions/auth/loginWithOTP.d.ts.map +1 -0
  182. package/dist/_types/actions/auth/loginWithStamp.d.ts +37 -0
  183. package/dist/_types/actions/auth/loginWithStamp.d.ts.map +1 -0
  184. package/dist/_types/actions/auth/registerWithOTP.d.ts +46 -0
  185. package/dist/_types/actions/auth/registerWithOTP.d.ts.map +1 -0
  186. package/dist/_types/actions/auth/registerWithPasskey.d.ts +53 -0
  187. package/dist/_types/actions/auth/registerWithPasskey.d.ts.map +1 -0
  188. package/dist/_types/actions/index.d.ts +3 -0
  189. package/dist/_types/actions/index.d.ts.map +1 -0
  190. package/dist/_types/actions/wallet/getUserWallet.d.ts +34 -0
  191. package/dist/_types/actions/wallet/getUserWallet.d.ts.map +1 -0
  192. package/dist/_types/actions/wallet/index.d.ts +4 -0
  193. package/dist/_types/actions/wallet/index.d.ts.map +1 -0
  194. package/dist/_types/actions/wallet/signRawPayload.d.ts +39 -0
  195. package/dist/_types/actions/wallet/signRawPayload.d.ts.map +1 -0
  196. package/dist/_types/actions/wallet/signTransaction.d.ts +35 -0
  197. package/dist/_types/actions/wallet/signTransaction.d.ts.map +1 -0
  198. package/dist/_types/adapters/viem.d.ts +10 -0
  199. package/dist/_types/adapters/viem.d.ts.map +1 -0
  200. package/dist/_types/client/authProxy.d.ts +36 -0
  201. package/dist/_types/client/authProxy.d.ts.map +1 -0
  202. package/dist/_types/client/createClient.d.ts +17 -0
  203. package/dist/_types/client/createClient.d.ts.map +1 -0
  204. package/dist/_types/client/decorators/client.d.ts +81 -0
  205. package/dist/_types/client/decorators/client.d.ts.map +1 -0
  206. package/dist/_types/client/index.d.ts +5 -0
  207. package/dist/_types/client/index.d.ts.map +1 -0
  208. package/dist/_types/client/transports/createTransport.d.ts +17 -0
  209. package/dist/_types/client/transports/createTransport.d.ts.map +1 -0
  210. package/dist/_types/client/transports/rest.d.ts +35 -0
  211. package/dist/_types/client/transports/rest.d.ts.map +1 -0
  212. package/dist/_types/client/types.d.ts +59 -0
  213. package/dist/_types/client/types.d.ts.map +1 -0
  214. package/dist/_types/constants.d.ts +6 -0
  215. package/dist/_types/constants.d.ts.map +1 -0
  216. package/dist/_types/core/createZeroDevWallet.d.ts +52 -0
  217. package/dist/_types/core/createZeroDevWallet.d.ts.map +1 -0
  218. package/dist/_types/errors/request.d.ts +12 -0
  219. package/dist/_types/errors/request.d.ts.map +1 -0
  220. package/dist/_types/index.d.ts +20 -0
  221. package/dist/_types/index.d.ts.map +1 -0
  222. package/dist/_types/polyfills/window.d.ts +15 -0
  223. package/dist/_types/polyfills/window.d.ts.map +1 -0
  224. package/dist/_types/stampers/iframeStamper.d.ts +7 -0
  225. package/dist/_types/stampers/iframeStamper.d.ts.map +1 -0
  226. package/dist/_types/stampers/index.d.ts +5 -0
  227. package/dist/_types/stampers/index.d.ts.map +1 -0
  228. package/dist/_types/stampers/indexedDbStamper.d.ts +3 -0
  229. package/dist/_types/stampers/indexedDbStamper.d.ts.map +1 -0
  230. package/dist/_types/stampers/types.d.ts +25 -0
  231. package/dist/_types/stampers/types.d.ts.map +1 -0
  232. package/dist/_types/stampers/webauthnStamper.d.ts +5 -0
  233. package/dist/_types/stampers/webauthnStamper.d.ts.map +1 -0
  234. package/dist/_types/storage/adapters.d.ts +3 -0
  235. package/dist/_types/storage/adapters.d.ts.map +1 -0
  236. package/dist/_types/storage/manager.d.ts +19 -0
  237. package/dist/_types/storage/manager.d.ts.map +1 -0
  238. package/dist/_types/types/session.d.ts +17 -0
  239. package/dist/_types/types/session.d.ts.map +1 -0
  240. package/dist/_types/utils/buildClientSignature.d.ts +25 -0
  241. package/dist/_types/utils/buildClientSignature.d.ts.map +1 -0
  242. package/dist/_types/utils/derToRawSignature.d.ts +11 -0
  243. package/dist/_types/utils/derToRawSignature.d.ts.map +1 -0
  244. package/dist/_types/utils/exportPrivateKey.d.ts +47 -0
  245. package/dist/_types/utils/exportPrivateKey.d.ts.map +1 -0
  246. package/dist/_types/utils/exportWallet.d.ts +44 -0
  247. package/dist/_types/utils/exportWallet.d.ts.map +1 -0
  248. package/dist/_types/utils/utils.d.ts +52 -0
  249. package/dist/_types/utils/utils.d.ts.map +1 -0
  250. package/dist/tsconfig.build.tsbuildinfo +1 -0
  251. package/package.json +74 -0
  252. package/src/actions/auth/authenticateWithEmail.ts +52 -0
  253. package/src/actions/auth/authenticateWithOAuth.ts +52 -0
  254. package/src/actions/auth/getAuthProxyConfigId.ts +20 -0
  255. package/src/actions/auth/getUserEmail.ts +52 -0
  256. package/src/actions/auth/getWhoami.ts +51 -0
  257. package/src/actions/auth/index.ts +47 -0
  258. package/src/actions/auth/loginWithOTP.ts +57 -0
  259. package/src/actions/auth/loginWithStamp.ts +79 -0
  260. package/src/actions/auth/registerWithOTP.ts +64 -0
  261. package/src/actions/auth/registerWithPasskey.ts +72 -0
  262. package/src/actions/index.ts +41 -0
  263. package/src/actions/wallet/getUserWallet.ts +53 -0
  264. package/src/actions/wallet/index.ts +17 -0
  265. package/src/actions/wallet/signRawPayload.ts +75 -0
  266. package/src/actions/wallet/signTransaction.ts +64 -0
  267. package/src/adapters/viem.ts +162 -0
  268. package/src/client/authProxy.ts +78 -0
  269. package/src/client/createClient.ts +90 -0
  270. package/src/client/decorators/client.ts +171 -0
  271. package/src/client/index.ts +19 -0
  272. package/src/client/transports/createTransport.ts +54 -0
  273. package/src/client/transports/rest.ts +138 -0
  274. package/src/client/types.ts +64 -0
  275. package/src/constants.ts +5 -0
  276. package/src/core/createZeroDevWallet.ts +447 -0
  277. package/src/errors/request.ts +36 -0
  278. package/src/index.ts +79 -0
  279. package/src/polyfills/window.ts +24 -0
  280. package/src/stampers/iframeStamper.ts +49 -0
  281. package/src/stampers/index.ts +8 -0
  282. package/src/stampers/indexedDbStamper.ts +22 -0
  283. package/src/stampers/types.ts +35 -0
  284. package/src/stampers/webauthnStamper.ts +21 -0
  285. package/src/storage/adapters.ts +20 -0
  286. package/src/storage/manager.ts +170 -0
  287. package/src/types/session.ts +18 -0
  288. package/src/utils/buildClientSignature.ts +86 -0
  289. package/src/utils/derToRawSignature.ts +103 -0
  290. package/src/utils/exportPrivateKey.ts +116 -0
  291. package/src/utils/exportWallet.ts +130 -0
  292. package/src/utils/utils.ts +136 -0
@@ -0,0 +1,53 @@
1
+ import type { Hex } from 'viem'
2
+ import type { Client } from '../../client/types.js'
3
+
4
+ export type GetUserWalletParameters = {
5
+ /** The organization ID */
6
+ organizationId: string
7
+ /** The project ID for the request */
8
+ projectId: string
9
+ /** The token for the request */
10
+ token: string
11
+ }
12
+
13
+ export type GetUserWalletReturnType = {
14
+ /** The wallet address */
15
+ walletAddresses: Hex[]
16
+ /** The user ID */
17
+ userId?: string
18
+ }
19
+
20
+ /**
21
+ * Gets the user's wallet information
22
+ *
23
+ * @param client - The ZeroDev Wallet client
24
+ * @param params - The parameters for getting wallet info
25
+ * @returns The wallet information
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * const wallet = await getUserWallet(client, {
30
+ * organizationId: 'org_123',
31
+ * projectId: 'proj_456'
32
+ * });
33
+ * console.log(wallet.walletAddresses); // ['0x...', '0x...']
34
+ * ```
35
+ */
36
+ export async function getUserWallet(
37
+ client: Client,
38
+ params: GetUserWalletParameters,
39
+ ): Promise<GetUserWalletReturnType> {
40
+ const { organizationId, projectId, token } = params
41
+
42
+ return await client.request({
43
+ path: `${projectId}/user-wallet`,
44
+ body: {
45
+ organizationId,
46
+ },
47
+ headers: {
48
+ Authorization: `Bearer ${token}`,
49
+ },
50
+ stamp: true,
51
+ stampPostion: 'headers',
52
+ })
53
+ }
@@ -0,0 +1,17 @@
1
+ export {
2
+ type GetUserWalletParameters,
3
+ type GetUserWalletReturnType,
4
+ getUserWallet,
5
+ } from './getUserWallet.js'
6
+
7
+ export {
8
+ type SignRawPayloadParameters,
9
+ type SignRawPayloadReturnType,
10
+ signRawPayload,
11
+ } from './signRawPayload.js'
12
+
13
+ export {
14
+ type SignTransactionParameters,
15
+ type SignTransactionReturnType,
16
+ signTransaction,
17
+ } from './signTransaction.js'
@@ -0,0 +1,75 @@
1
+ import type { Hex } from 'viem'
2
+ import type { Client } from '../../client/types.js'
3
+
4
+ export type SignRawPayloadParameters = {
5
+ /** The organization ID */
6
+ organizationId: string
7
+ /** The project ID for the request */
8
+ projectId: string
9
+ /** The session token for authorization */
10
+ token: string
11
+ /** The address to sign with */
12
+ address: Hex
13
+ /** The payload hash to sign (without 0x prefix) */
14
+ payload: string
15
+ /** The encoding type */
16
+ encoding?: 'PAYLOAD_ENCODING_HEXADECIMAL' | 'PAYLOAD_ENCODING_EIP712'
17
+ /** The hash function type */
18
+ hashFunction?: 'HASH_FUNCTION_NO_OP'
19
+ }
20
+
21
+ export type SignRawPayloadReturnType = Hex
22
+
23
+ /**
24
+ * Signs a raw payload with the user's wallet
25
+ *
26
+ * @param client - The ZeroDev Wallet client
27
+ * @param params - The parameters for signing
28
+ * @returns The signature
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * const result = await signRawPayload(client, {
33
+ * organizationId: 'org_123',
34
+ * projectId: 'proj_456',
35
+ * address: '0x123...',
36
+ * payload: 'abc123...',
37
+ * });
38
+ * console.log(result.signature); // '0x...'
39
+ * ```
40
+ */
41
+ export async function signRawPayload(
42
+ client: Client,
43
+ params: SignRawPayloadParameters,
44
+ ): Promise<SignRawPayloadReturnType> {
45
+ const {
46
+ organizationId,
47
+ projectId,
48
+ token,
49
+ address,
50
+ payload,
51
+ encoding = 'PAYLOAD_ENCODING_HEXADECIMAL',
52
+ hashFunction = 'HASH_FUNCTION_NO_OP',
53
+ } = params
54
+
55
+ const { signature } = await client.request({
56
+ path: `${projectId}/sign/raw-payload`,
57
+ body: {
58
+ type: 'ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2',
59
+ timestampMs: Date.now().toString(),
60
+ organizationId,
61
+ parameters: {
62
+ signWith: address,
63
+ payload,
64
+ encoding,
65
+ hashFunction,
66
+ },
67
+ },
68
+ headers: {
69
+ Authorization: `Bearer ${token}`,
70
+ },
71
+ stamp: true,
72
+ stampPostion: 'headers',
73
+ })
74
+ return signature as Hex
75
+ }
@@ -0,0 +1,64 @@
1
+ import type { Hex } from 'viem'
2
+ import type { Client } from '../../client/types.js'
3
+
4
+ export type SignTransactionParameters = {
5
+ /** The organization ID */
6
+ organizationId: string
7
+ /** The project ID for the request */
8
+ projectId: string
9
+ /** The session token for authorization */
10
+ token: string
11
+ /** The address to sign with */
12
+ address: Hex
13
+ /** The unsigned transaction to sign */
14
+ unsignedTransaction: string
15
+ }
16
+
17
+ export type SignTransactionReturnType = Hex
18
+
19
+ /**
20
+ * Signs a raw transaction with the user's wallet
21
+ *
22
+ * @param client - The ZeroDev Wallet client
23
+ * @param params - The parameters for signing
24
+ * @returns The signature
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * const result = await signTransaction(client, {
29
+ * organizationId: 'org_123',
30
+ * projectId: 'proj_456',
31
+ * address: '0x123...',
32
+ * unsignedTransaction: 'abc123...',
33
+ * });
34
+ * console.log(result.signature); // '0x...'
35
+ * ```
36
+ */
37
+ export async function signTransaction(
38
+ client: Client,
39
+ params: SignTransactionParameters,
40
+ ): Promise<SignTransactionReturnType> {
41
+ const { organizationId, projectId, token, address, unsignedTransaction } =
42
+ params
43
+
44
+ const { signature } = await client.request({
45
+ path: `${projectId}/sign/transaction`,
46
+ body: {
47
+ type: 'ACTIVITY_TYPE_SIGN_TRANSACTION_V2',
48
+ timestampMs: Date.now().toString(),
49
+ organizationId,
50
+ parameters: {
51
+ signWith: address,
52
+ type: 'TRANSACTION_TYPE_ETHEREUM',
53
+ unsignedTransaction,
54
+ },
55
+ },
56
+ headers: {
57
+ Authorization: `Bearer ${token}`,
58
+ },
59
+ stamp: true,
60
+ stampPostion: 'headers',
61
+ })
62
+
63
+ return `0x${signature}` as Hex
64
+ }
@@ -0,0 +1,162 @@
1
+ import {
2
+ type Hex,
3
+ hashMessage,
4
+ type LocalAccount,
5
+ parseSignature,
6
+ parseTransaction,
7
+ type SerializeTransactionFn,
8
+ type SignableMessage,
9
+ serializeTransaction,
10
+ serializeTypedData,
11
+ type TransactionSerializable,
12
+ zeroAddress,
13
+ } from 'viem'
14
+ import type {
15
+ SignAuthorizationParameters,
16
+ SignAuthorizationReturnType,
17
+ } from 'viem/accounts'
18
+ import { toAccount } from 'viem/accounts'
19
+ import { hashAuthorization } from 'viem/utils'
20
+ import type { signRawPayload } from '../actions/index.js'
21
+ import type { ZeroDevWalletClient } from '../client/index.js'
22
+
23
+ export interface ToViemAccountParams {
24
+ client: ZeroDevWalletClient
25
+ organizationId: string
26
+ projectId: string
27
+ token: string
28
+ }
29
+
30
+ export async function toViemAccount(
31
+ params: ToViemAccountParams,
32
+ ): Promise<LocalAccount> {
33
+ const { client, organizationId, projectId, token } = params
34
+
35
+ let address: Hex = zeroAddress
36
+
37
+ try {
38
+ const walletResponse = await client.getUserWallet({
39
+ organizationId,
40
+ projectId,
41
+ token,
42
+ })
43
+ address = walletResponse.walletAddresses[0]
44
+ } catch {
45
+ address = zeroAddress
46
+ }
47
+ const signRawPayloadInternal = async (
48
+ payload: string,
49
+ encoding: Parameters<
50
+ typeof signRawPayload
51
+ >[1]['encoding'] = 'PAYLOAD_ENCODING_HEXADECIMAL',
52
+ ) => {
53
+ return await client.signRawPayload({
54
+ organizationId,
55
+ projectId,
56
+ token,
57
+ address,
58
+ payload,
59
+ encoding,
60
+ })
61
+ }
62
+
63
+ // Modified from: https://github.com/tkhq/sdk/blob/4e439bf2973ea13b51d981d7c24a4841d4e5fd5f/packages/viem/src/index.ts#L419-L461
64
+ const signTransactionInternal = async <
65
+ TTransactionSerializable extends TransactionSerializable,
66
+ >(
67
+ transaction: TTransactionSerializable,
68
+ serializer: SerializeTransactionFn<TTransactionSerializable>,
69
+ ): Promise<Hex> => {
70
+ // Note: for Type 3 transactions, we are specifically handling parsing for payloads containing only the transaction payload body, without any wrappers around blobs, commitments, or proofs.
71
+ // See more: https://github.com/wevm/viem/blob/3ef19eac4963014fb20124d1e46d1715bed5509f/src/accounts/utils/signTransaction.ts#L54-L55
72
+ const signableTransaction =
73
+ transaction.type === 'eip4844'
74
+ ? { ...transaction, sidecars: false }
75
+ : transaction
76
+
77
+ const serializedTx = await serializer(signableTransaction)
78
+ const nonHexPrefixedSerializedTx = serializedTx.replace(/^0x/, '')
79
+ const signature = await client.signTransaction({
80
+ organizationId,
81
+ projectId,
82
+ token,
83
+ address,
84
+ unsignedTransaction: nonHexPrefixedSerializedTx,
85
+ })
86
+
87
+ if (transaction.type === 'eip4844') {
88
+ // Grab components of the signature
89
+ const { r, s, v } = parseTransaction(signature)
90
+
91
+ // Recombine with the original transaction
92
+ return serializeTransaction(transaction, {
93
+ r: r!,
94
+ s: s!,
95
+ v: v!,
96
+ })
97
+ }
98
+
99
+ return signature
100
+ }
101
+
102
+ return toAccount({
103
+ address,
104
+
105
+ async signMessage({ message }: { message: SignableMessage }): Promise<Hex> {
106
+ const hashedMessage = hashMessage(message)
107
+ return signRawPayloadInternal(hashedMessage)
108
+ },
109
+
110
+ signTransaction: async <
111
+ TTransactionSerializable extends TransactionSerializable,
112
+ >(
113
+ transaction: TTransactionSerializable,
114
+ options?: {
115
+ serializer?:
116
+ | SerializeTransactionFn<TTransactionSerializable>
117
+ | undefined
118
+ },
119
+ ) => {
120
+ const serializer: SerializeTransactionFn<TTransactionSerializable> =
121
+ options?.serializer ??
122
+ (serializeTransaction as SerializeTransactionFn<TTransactionSerializable>)
123
+ return signTransactionInternal(transaction, serializer)
124
+ },
125
+ signTypedData: async (typedData) => {
126
+ const serializedTypedData = serializeTypedData(typedData)
127
+ return signRawPayloadInternal(
128
+ serializedTypedData,
129
+ 'PAYLOAD_ENCODING_EIP712',
130
+ )
131
+ },
132
+
133
+ async signAuthorization(
134
+ parameters: Omit<SignAuthorizationParameters, 'privateKey'>,
135
+ ): Promise<SignAuthorizationReturnType> {
136
+ const { chainId, nonce } = parameters
137
+ const authAddress = parameters.contractAddress ?? parameters.address
138
+
139
+ if (!authAddress) {
140
+ throw new Error('Unable to sign authorization: address is undefined')
141
+ }
142
+
143
+ const hashedAuthorization = hashAuthorization({
144
+ address: authAddress,
145
+ chainId,
146
+ nonce,
147
+ })
148
+
149
+ const signature = await signRawPayloadInternal(hashedAuthorization)
150
+
151
+ const parsedSignature = parseSignature(signature)
152
+
153
+ return {
154
+ address: authAddress,
155
+ chainId,
156
+ nonce,
157
+ ...parsedSignature,
158
+ yParity: parsedSignature.v === BigInt(27) ? 0 : 1,
159
+ } as SignAuthorizationReturnType
160
+ },
161
+ })
162
+ }
@@ -0,0 +1,78 @@
1
+ const AUTH_PROXY_BASE_URL = 'https://authproxy.turnkey.com'
2
+
3
+ export type AuthProxyClientConfig = {
4
+ /** The Auth Proxy Config ID from the backend */
5
+ authProxyConfigId: string
6
+ /** Optional base URL override (for testing) */
7
+ baseUrl?: string
8
+ }
9
+
10
+ export type AuthProxyVerifyOtpRequest = {
11
+ /** The OTP ID from registration */
12
+ otpId: string
13
+ /** The OTP code entered by the user */
14
+ otpCode: string
15
+ /** The public key to associate with the verification */
16
+ public_key: string
17
+ }
18
+
19
+ export type AuthProxyVerifyOtpResponse = {
20
+ /** The verification token to use for login */
21
+ verificationToken: string
22
+ }
23
+
24
+ /**
25
+ * Creates an Auth Proxy client for making requests to Turnkey's Auth Proxy
26
+ *
27
+ * Note: This client only handles OTP verification. The actual OTP login
28
+ * is handled by the backend (/auth/login/otp) which manages sub-organization
29
+ * creation and session handling.
30
+ */
31
+ export function createAuthProxyClient(config: AuthProxyClientConfig) {
32
+ const { authProxyConfigId, baseUrl = AUTH_PROXY_BASE_URL } = config
33
+
34
+ async function request<T>(
35
+ path: string,
36
+ body: unknown,
37
+ method: 'POST' | 'GET' = 'POST',
38
+ ): Promise<T> {
39
+ const fetchOptions: RequestInit = {
40
+ method,
41
+ headers: {
42
+ 'Content-Type': 'application/json',
43
+ 'X-Auth-Proxy-Config-Id': authProxyConfigId,
44
+ },
45
+ }
46
+
47
+ if (method !== 'GET') {
48
+ fetchOptions.body = JSON.stringify(body)
49
+ }
50
+
51
+ const response = await fetch(`${baseUrl}${path}`, fetchOptions)
52
+
53
+ if (!response.ok) {
54
+ const errorText = await response.text()
55
+ throw new Error(
56
+ `Auth Proxy request failed: ${response.status} ${response.statusText} - ${errorText}`,
57
+ )
58
+ }
59
+
60
+ return response.json()
61
+ }
62
+
63
+ return {
64
+ /**
65
+ * Verifies an OTP code with Turnkey's Auth Proxy
66
+ *
67
+ * Returns a verificationToken that should be passed to the backend's
68
+ * /auth/login/otp endpoint along with a client signature.
69
+ */
70
+ async verifyOtp(
71
+ params: AuthProxyVerifyOtpRequest,
72
+ ): Promise<AuthProxyVerifyOtpResponse> {
73
+ return request<AuthProxyVerifyOtpResponse>('/v1/otp_verify', params)
74
+ },
75
+ }
76
+ }
77
+
78
+ export type AuthProxyClient = ReturnType<typeof createAuthProxyClient>
@@ -0,0 +1,90 @@
1
+ import {
2
+ type ZeroDevWalletActions,
3
+ zeroDevWalletActions,
4
+ } from './decorators/client.js'
5
+ import type { Client, ClientConfig } from './types.js'
6
+
7
+ let clientId = 0
8
+
9
+ /**
10
+ * Creates a base ZeroDev Wallet client.
11
+ * This is the foundation client without any pre-loaded actions.
12
+ * Use createClient() for a client with ZeroDev Wallet actions pre-loaded.
13
+ */
14
+ export function createBaseClient<
15
+ extended extends Record<string, unknown> | undefined = undefined,
16
+ >(config: ClientConfig): Client<extended> {
17
+ const {
18
+ transport,
19
+ indexedDbStamper,
20
+ webauthnStamper,
21
+ organizationId,
22
+ key = 'zeroDevWallet',
23
+ name = 'ZeroDev Wallet Client',
24
+ } = config
25
+
26
+ // Initialize the transport with stamper
27
+ const {
28
+ config: transportConfig,
29
+ request,
30
+ value,
31
+ } = transport({
32
+ indexedDbStamper,
33
+ webauthnStamper,
34
+ })
35
+ const transportInstance = { ...transportConfig, ...value }
36
+
37
+ const uid = `${key}-${++clientId}`
38
+
39
+ const client = {
40
+ transport: transportInstance,
41
+ request,
42
+ indexedDbStamper,
43
+ webauthnStamper,
44
+ organizationId,
45
+ key,
46
+ name,
47
+ type: 'zeroDevWallet',
48
+ uid,
49
+ } as const
50
+
51
+ function extend(base: typeof client) {
52
+ type ExtendFn = (base: typeof client) => Record<string, unknown>
53
+ return (extendFn: ExtendFn) => {
54
+ const extended = extendFn(base) as Record<string, unknown>
55
+
56
+ // Remove base properties from extended to avoid conflicts
57
+ for (const key in client) {
58
+ delete extended[key]
59
+ }
60
+
61
+ // Combine base client with extensions
62
+ const combined = { ...base, ...extended }
63
+
64
+ // Return new client with updated extend function
65
+ return Object.assign(combined, { extend: extend(combined as any) })
66
+ }
67
+ }
68
+
69
+ return Object.assign(client, {
70
+ extend: extend(client) as any,
71
+ }) as Client<extended>
72
+ }
73
+
74
+ export type ZeroDevWalletClient = Client<ZeroDevWalletActions>
75
+
76
+ /**
77
+ * Creates a ZeroDev Wallet client with ZeroDev Wallet actions pre-loaded.
78
+ * This is equivalent to calling createBaseClient(config).extend(zeroDevWalletActions).
79
+ *
80
+ * For a client without pre-loaded actions, use createBaseClient().
81
+ */
82
+ export function createClient(config: ClientConfig): ZeroDevWalletClient {
83
+ const { key = 'zeroDevWallet', name = 'ZeroDev Wallet Client' } = config
84
+ const client = createBaseClient({
85
+ ...config,
86
+ key,
87
+ name,
88
+ })
89
+ return client.extend(zeroDevWalletActions) as ZeroDevWalletClient
90
+ }