@zerodev/wallet-core 0.0.1-alpha.3

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 (250) hide show
  1. package/README.md +272 -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 +17 -0
  5. package/dist/_cjs/actions/auth/authenticateWithOAuth.js.map +1 -0
  6. package/dist/_cjs/actions/auth/getWhoami.js +15 -0
  7. package/dist/_cjs/actions/auth/getWhoami.js.map +1 -0
  8. package/dist/_cjs/actions/auth/index.js +18 -0
  9. package/dist/_cjs/actions/auth/index.js.map +1 -0
  10. package/dist/_cjs/actions/auth/loginWithOTP.js +17 -0
  11. package/dist/_cjs/actions/auth/loginWithOTP.js.map +1 -0
  12. package/dist/_cjs/actions/auth/loginWithStamp.js +29 -0
  13. package/dist/_cjs/actions/auth/loginWithStamp.js.map +1 -0
  14. package/dist/_cjs/actions/auth/registerWithOTP.js +17 -0
  15. package/dist/_cjs/actions/auth/registerWithOTP.js.map +1 -0
  16. package/dist/_cjs/actions/auth/registerWithPasskey.js +17 -0
  17. package/dist/_cjs/actions/auth/registerWithPasskey.js.map +1 -0
  18. package/dist/_cjs/actions/index.js +15 -0
  19. package/dist/_cjs/actions/index.js.map +1 -0
  20. package/dist/_cjs/actions/wallet/getUserWallet.js +13 -0
  21. package/dist/_cjs/actions/wallet/getUserWallet.js.map +1 -0
  22. package/dist/_cjs/actions/wallet/index.js +10 -0
  23. package/dist/_cjs/actions/wallet/index.js.map +1 -0
  24. package/dist/_cjs/actions/wallet/signRawPayload.js +26 -0
  25. package/dist/_cjs/actions/wallet/signRawPayload.js.map +1 -0
  26. package/dist/_cjs/actions/wallet/signTransaction.js +25 -0
  27. package/dist/_cjs/actions/wallet/signTransaction.js.map +1 -0
  28. package/dist/_cjs/adapters/viem.js +89 -0
  29. package/dist/_cjs/adapters/viem.js.map +1 -0
  30. package/dist/_cjs/client/createClient.js +45 -0
  31. package/dist/_cjs/client/createClient.js.map +1 -0
  32. package/dist/_cjs/client/decorators/client.js +21 -0
  33. package/dist/_cjs/client/decorators/client.js.map +1 -0
  34. package/dist/_cjs/client/index.js +9 -0
  35. package/dist/_cjs/client/index.js.map +1 -0
  36. package/dist/_cjs/client/transports/createTransport.js +29 -0
  37. package/dist/_cjs/client/transports/createTransport.js.map +1 -0
  38. package/dist/_cjs/client/transports/rest.js +86 -0
  39. package/dist/_cjs/client/transports/rest.js.map +1 -0
  40. package/dist/_cjs/client/types.js +3 -0
  41. package/dist/_cjs/client/types.js.map +1 -0
  42. package/dist/_cjs/constants.js +9 -0
  43. package/dist/_cjs/constants.js.map +1 -0
  44. package/dist/_cjs/core/createZeroDevWallet.js +330 -0
  45. package/dist/_cjs/core/createZeroDevWallet.js.map +1 -0
  46. package/dist/_cjs/errors/request.js +61 -0
  47. package/dist/_cjs/errors/request.js.map +1 -0
  48. package/dist/_cjs/index.js +31 -0
  49. package/dist/_cjs/index.js.map +1 -0
  50. package/dist/_cjs/package.json +1 -0
  51. package/dist/_cjs/polyfills/window.js +26 -0
  52. package/dist/_cjs/polyfills/window.js.map +1 -0
  53. package/dist/_cjs/stampers/iframeStamper.js +32 -0
  54. package/dist/_cjs/stampers/iframeStamper.js.map +1 -0
  55. package/dist/_cjs/stampers/index.js +10 -0
  56. package/dist/_cjs/stampers/index.js.map +1 -0
  57. package/dist/_cjs/stampers/indexedDbStamper.js +23 -0
  58. package/dist/_cjs/stampers/indexedDbStamper.js.map +1 -0
  59. package/dist/_cjs/stampers/types.js +3 -0
  60. package/dist/_cjs/stampers/types.js.map +1 -0
  61. package/dist/_cjs/stampers/webauthnStamper.js +17 -0
  62. package/dist/_cjs/stampers/webauthnStamper.js.map +1 -0
  63. package/dist/_cjs/storage/adapters.js +18 -0
  64. package/dist/_cjs/storage/adapters.js.map +1 -0
  65. package/dist/_cjs/storage/manager.js +108 -0
  66. package/dist/_cjs/storage/manager.js.map +1 -0
  67. package/dist/_cjs/types/session.js +9 -0
  68. package/dist/_cjs/types/session.js.map +1 -0
  69. package/dist/_cjs/utils/exportWallet.js +70 -0
  70. package/dist/_cjs/utils/exportWallet.js.map +1 -0
  71. package/dist/_cjs/utils/utils.js +75 -0
  72. package/dist/_cjs/utils/utils.js.map +1 -0
  73. package/dist/_esm/actions/auth/authenticateWithEmail.js +18 -0
  74. package/dist/_esm/actions/auth/authenticateWithEmail.js.map +1 -0
  75. package/dist/_esm/actions/auth/authenticateWithOAuth.js +31 -0
  76. package/dist/_esm/actions/auth/authenticateWithOAuth.js.map +1 -0
  77. package/dist/_esm/actions/auth/getWhoami.js +28 -0
  78. package/dist/_esm/actions/auth/getWhoami.js.map +1 -0
  79. package/dist/_esm/actions/auth/index.js +8 -0
  80. package/dist/_esm/actions/auth/index.js.map +1 -0
  81. package/dist/_esm/actions/auth/loginWithOTP.js +36 -0
  82. package/dist/_esm/actions/auth/loginWithOTP.js.map +1 -0
  83. package/dist/_esm/actions/auth/loginWithStamp.js +42 -0
  84. package/dist/_esm/actions/auth/loginWithStamp.js.map +1 -0
  85. package/dist/_esm/actions/auth/registerWithOTP.js +36 -0
  86. package/dist/_esm/actions/auth/registerWithOTP.js.map +1 -0
  87. package/dist/_esm/actions/auth/registerWithPasskey.js +36 -0
  88. package/dist/_esm/actions/auth/registerWithPasskey.js.map +1 -0
  89. package/dist/_esm/actions/index.js +5 -0
  90. package/dist/_esm/actions/index.js.map +1 -0
  91. package/dist/_esm/actions/wallet/getUserWallet.js +26 -0
  92. package/dist/_esm/actions/wallet/getUserWallet.js.map +1 -0
  93. package/dist/_esm/actions/wallet/index.js +4 -0
  94. package/dist/_esm/actions/wallet/index.js.map +1 -0
  95. package/dist/_esm/actions/wallet/signRawPayload.js +41 -0
  96. package/dist/_esm/actions/wallet/signRawPayload.js.map +1 -0
  97. package/dist/_esm/actions/wallet/signTransaction.js +40 -0
  98. package/dist/_esm/actions/wallet/signTransaction.js.map +1 -0
  99. package/dist/_esm/adapters/viem.js +91 -0
  100. package/dist/_esm/adapters/viem.js.map +1 -0
  101. package/dist/_esm/client/createClient.js +56 -0
  102. package/dist/_esm/client/createClient.js.map +1 -0
  103. package/dist/_esm/client/decorators/client.js +42 -0
  104. package/dist/_esm/client/decorators/client.js.map +1 -0
  105. package/dist/_esm/client/index.js +3 -0
  106. package/dist/_esm/client/index.js.map +1 -0
  107. package/dist/_esm/client/transports/createTransport.js +31 -0
  108. package/dist/_esm/client/transports/createTransport.js.map +1 -0
  109. package/dist/_esm/client/transports/rest.js +85 -0
  110. package/dist/_esm/client/transports/rest.js.map +1 -0
  111. package/dist/_esm/client/types.js +2 -0
  112. package/dist/_esm/client/types.js.map +1 -0
  113. package/dist/_esm/constants.js +6 -0
  114. package/dist/_esm/constants.js.map +1 -0
  115. package/dist/_esm/core/createZeroDevWallet.js +332 -0
  116. package/dist/_esm/core/createZeroDevWallet.js.map +1 -0
  117. package/dist/_esm/errors/request.js +60 -0
  118. package/dist/_esm/errors/request.js.map +1 -0
  119. package/dist/_esm/index.js +20 -0
  120. package/dist/_esm/index.js.map +1 -0
  121. package/dist/_esm/package.json +1 -0
  122. package/dist/_esm/polyfills/window.js +24 -0
  123. package/dist/_esm/polyfills/window.js.map +1 -0
  124. package/dist/_esm/stampers/iframeStamper.js +29 -0
  125. package/dist/_esm/stampers/iframeStamper.js.map +1 -0
  126. package/dist/_esm/stampers/index.js +4 -0
  127. package/dist/_esm/stampers/index.js.map +1 -0
  128. package/dist/_esm/stampers/indexedDbStamper.js +20 -0
  129. package/dist/_esm/stampers/indexedDbStamper.js.map +1 -0
  130. package/dist/_esm/stampers/types.js +2 -0
  131. package/dist/_esm/stampers/types.js.map +1 -0
  132. package/dist/_esm/stampers/webauthnStamper.js +15 -0
  133. package/dist/_esm/stampers/webauthnStamper.js.map +1 -0
  134. package/dist/_esm/storage/adapters.js +15 -0
  135. package/dist/_esm/storage/adapters.js.map +1 -0
  136. package/dist/_esm/storage/manager.js +118 -0
  137. package/dist/_esm/storage/manager.js.map +1 -0
  138. package/dist/_esm/types/session.js +6 -0
  139. package/dist/_esm/types/session.js.map +1 -0
  140. package/dist/_esm/utils/exportWallet.js +98 -0
  141. package/dist/_esm/utils/exportWallet.js.map +1 -0
  142. package/dist/_esm/utils/utils.js +105 -0
  143. package/dist/_esm/utils/utils.js.map +1 -0
  144. package/dist/_types/actions/auth/authenticateWithEmail.d.ts +33 -0
  145. package/dist/_types/actions/auth/authenticateWithEmail.d.ts.map +1 -0
  146. package/dist/_types/actions/auth/authenticateWithOAuth.d.ts +40 -0
  147. package/dist/_types/actions/auth/authenticateWithOAuth.d.ts.map +1 -0
  148. package/dist/_types/actions/auth/getWhoami.d.ts +35 -0
  149. package/dist/_types/actions/auth/getWhoami.d.ts.map +1 -0
  150. package/dist/_types/actions/auth/index.d.ts +8 -0
  151. package/dist/_types/actions/auth/index.d.ts.map +1 -0
  152. package/dist/_types/actions/auth/loginWithOTP.d.ts +41 -0
  153. package/dist/_types/actions/auth/loginWithOTP.d.ts.map +1 -0
  154. package/dist/_types/actions/auth/loginWithStamp.d.ts +35 -0
  155. package/dist/_types/actions/auth/loginWithStamp.d.ts.map +1 -0
  156. package/dist/_types/actions/auth/registerWithOTP.d.ts +52 -0
  157. package/dist/_types/actions/auth/registerWithOTP.d.ts.map +1 -0
  158. package/dist/_types/actions/auth/registerWithPasskey.d.ts +53 -0
  159. package/dist/_types/actions/auth/registerWithPasskey.d.ts.map +1 -0
  160. package/dist/_types/actions/index.d.ts +3 -0
  161. package/dist/_types/actions/index.d.ts.map +1 -0
  162. package/dist/_types/actions/wallet/getUserWallet.d.ts +32 -0
  163. package/dist/_types/actions/wallet/getUserWallet.d.ts.map +1 -0
  164. package/dist/_types/actions/wallet/index.d.ts +4 -0
  165. package/dist/_types/actions/wallet/index.d.ts.map +1 -0
  166. package/dist/_types/actions/wallet/signRawPayload.d.ts +37 -0
  167. package/dist/_types/actions/wallet/signRawPayload.d.ts.map +1 -0
  168. package/dist/_types/actions/wallet/signTransaction.d.ts +33 -0
  169. package/dist/_types/actions/wallet/signTransaction.d.ts.map +1 -0
  170. package/dist/_types/adapters/viem.d.ts +9 -0
  171. package/dist/_types/adapters/viem.d.ts.map +1 -0
  172. package/dist/_types/client/createClient.d.ts +18 -0
  173. package/dist/_types/client/createClient.d.ts.map +1 -0
  174. package/dist/_types/client/decorators/client.d.ts +73 -0
  175. package/dist/_types/client/decorators/client.d.ts.map +1 -0
  176. package/dist/_types/client/index.d.ts +4 -0
  177. package/dist/_types/client/index.d.ts.map +1 -0
  178. package/dist/_types/client/transports/createTransport.d.ts +17 -0
  179. package/dist/_types/client/transports/createTransport.d.ts.map +1 -0
  180. package/dist/_types/client/transports/rest.d.ts +30 -0
  181. package/dist/_types/client/transports/rest.d.ts.map +1 -0
  182. package/dist/_types/client/types.d.ts +60 -0
  183. package/dist/_types/client/types.d.ts.map +1 -0
  184. package/dist/_types/constants.d.ts +6 -0
  185. package/dist/_types/constants.d.ts.map +1 -0
  186. package/dist/_types/core/createZeroDevWallet.d.ts +55 -0
  187. package/dist/_types/core/createZeroDevWallet.d.ts.map +1 -0
  188. package/dist/_types/errors/request.d.ts +12 -0
  189. package/dist/_types/errors/request.d.ts.map +1 -0
  190. package/dist/_types/index.d.ts +17 -0
  191. package/dist/_types/index.d.ts.map +1 -0
  192. package/dist/_types/polyfills/window.d.ts +15 -0
  193. package/dist/_types/polyfills/window.d.ts.map +1 -0
  194. package/dist/_types/stampers/iframeStamper.d.ts +7 -0
  195. package/dist/_types/stampers/iframeStamper.d.ts.map +1 -0
  196. package/dist/_types/stampers/index.d.ts +5 -0
  197. package/dist/_types/stampers/index.d.ts.map +1 -0
  198. package/dist/_types/stampers/indexedDbStamper.d.ts +3 -0
  199. package/dist/_types/stampers/indexedDbStamper.d.ts.map +1 -0
  200. package/dist/_types/stampers/types.d.ts +23 -0
  201. package/dist/_types/stampers/types.d.ts.map +1 -0
  202. package/dist/_types/stampers/webauthnStamper.d.ts +5 -0
  203. package/dist/_types/stampers/webauthnStamper.d.ts.map +1 -0
  204. package/dist/_types/storage/adapters.d.ts +3 -0
  205. package/dist/_types/storage/adapters.d.ts.map +1 -0
  206. package/dist/_types/storage/manager.d.ts +19 -0
  207. package/dist/_types/storage/manager.d.ts.map +1 -0
  208. package/dist/_types/types/session.d.ts +17 -0
  209. package/dist/_types/types/session.d.ts.map +1 -0
  210. package/dist/_types/utils/exportWallet.d.ts +44 -0
  211. package/dist/_types/utils/exportWallet.d.ts.map +1 -0
  212. package/dist/_types/utils/utils.d.ts +52 -0
  213. package/dist/_types/utils/utils.d.ts.map +1 -0
  214. package/dist/tsconfig.build.tsbuildinfo +1 -0
  215. package/package.json +73 -0
  216. package/src/actions/auth/authenticateWithEmail.ts +52 -0
  217. package/src/actions/auth/authenticateWithOAuth.ts +58 -0
  218. package/src/actions/auth/getWhoami.ts +51 -0
  219. package/src/actions/auth/index.ts +40 -0
  220. package/src/actions/auth/loginWithOTP.ts +60 -0
  221. package/src/actions/auth/loginWithStamp.ts +68 -0
  222. package/src/actions/auth/registerWithOTP.ts +71 -0
  223. package/src/actions/auth/registerWithPasskey.ts +72 -0
  224. package/src/actions/index.ts +36 -0
  225. package/src/actions/wallet/getUserWallet.ts +46 -0
  226. package/src/actions/wallet/index.ts +17 -0
  227. package/src/actions/wallet/signRawPayload.ts +71 -0
  228. package/src/actions/wallet/signTransaction.ts +60 -0
  229. package/src/adapters/viem.ts +158 -0
  230. package/src/client/createClient.ts +95 -0
  231. package/src/client/decorators/client.ts +152 -0
  232. package/src/client/index.ts +12 -0
  233. package/src/client/transports/createTransport.ts +52 -0
  234. package/src/client/transports/rest.ts +121 -0
  235. package/src/client/types.ts +66 -0
  236. package/src/constants.ts +5 -0
  237. package/src/core/createZeroDevWallet.ts +477 -0
  238. package/src/errors/request.ts +36 -0
  239. package/src/index.ts +75 -0
  240. package/src/polyfills/window.ts +24 -0
  241. package/src/stampers/iframeStamper.ts +35 -0
  242. package/src/stampers/index.ts +8 -0
  243. package/src/stampers/indexedDbStamper.ts +22 -0
  244. package/src/stampers/types.ts +28 -0
  245. package/src/stampers/webauthnStamper.ts +21 -0
  246. package/src/storage/adapters.ts +20 -0
  247. package/src/storage/manager.ts +170 -0
  248. package/src/types/session.ts +18 -0
  249. package/src/utils/exportWallet.ts +124 -0
  250. package/src/utils/utils.ts +136 -0
@@ -0,0 +1,52 @@
1
+ import type { Client } from '../../client/types.js'
2
+
3
+ export type EmailCustomization = {
4
+ /** A template for the URL to be used in a magic link button, e.g. `https://dapp.xyz/%s`. The auth bundle will be interpolated into the `%s`. */
5
+ magicLinkTemplate?: string
6
+ }
7
+
8
+ export type AuthenticateWithEmailParameters = {
9
+ /** The email address to authenticate */
10
+ email: string
11
+ /** The project ID for the request */
12
+ projectId: string
13
+ /** Target public key for authentication */
14
+ targetPublicKey: string
15
+ /** Optional email customization settings */
16
+ emailCustomization?: EmailCustomization
17
+ }
18
+
19
+ export type AuthenticateWithEmailReturnType = {
20
+ /** The user ID */
21
+ userId?: string
22
+ /** The wallet address */
23
+ walletAddress?: string
24
+ /** The sub-organization ID */
25
+ subOrganizationId?: string
26
+ /** Whether magic link is required */
27
+ requiresMagicLink?: boolean
28
+ /** The Turnkey session if available */
29
+ turnkeySession?: string
30
+ }
31
+
32
+ /**
33
+ * @deprecated Use {@link registerWithOTP} instead
34
+ * See {@link registerWithOTP} for more details on how to authenticate with email.
35
+ */
36
+ export async function authenticateWithEmail(
37
+ client: Client,
38
+ params: AuthenticateWithEmailParameters,
39
+ ): Promise<AuthenticateWithEmailReturnType> {
40
+ const { email, projectId, targetPublicKey, emailCustomization } = params
41
+
42
+ return await client.request({
43
+ path: `${projectId}/auth/email-magic`,
44
+ method: 'POST',
45
+ body: {
46
+ email,
47
+ emailCustomization,
48
+ targetPublicKey,
49
+ projectId,
50
+ },
51
+ })
52
+ }
@@ -0,0 +1,58 @@
1
+ import type { Client } from '../../client/types.js'
2
+
3
+ export type AuthenticateWithOAuthParameters = {
4
+ /** The OAuth credential/token */
5
+ oidcToken: string
6
+ /** The OAuth provider (e.g., 'google') */
7
+ provider: string
8
+ /** The project ID for the request */
9
+ projectId: string
10
+ /** Target public key for authentication */
11
+ targetPublicKey: string
12
+ }
13
+
14
+ export type AuthenticateWithOAuthReturnType = {
15
+ /** The user ID */
16
+ userId?: string
17
+ /** The wallet address */
18
+ walletAddress?: string
19
+ /** The sub-organization ID */
20
+ subOrganizationId?: string
21
+ /** The Turnkey session */
22
+ turnkeySession?: string
23
+ }
24
+
25
+ /**
26
+ * Authenticates a user with OAuth credentials
27
+ *
28
+ * @param client - The ZeroDev Wallet client
29
+ * @param params - The parameters for OAuth authentication
30
+ * @returns The authentication result
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const result = await authenticateWithOAuth(client, {
35
+ * oidcToken: 'oauth_token_here',
36
+ * provider: 'google',
37
+ * projectId: 'proj_456',
38
+ * targetPublicKey: '0x...'
39
+ * });
40
+ * ```
41
+ */
42
+ export async function authenticateWithOAuth(
43
+ client: Client,
44
+ params: AuthenticateWithOAuthParameters,
45
+ ): Promise<AuthenticateWithOAuthReturnType> {
46
+ const { oidcToken, provider, projectId, targetPublicKey } = params
47
+
48
+ return await client.request({
49
+ path: `${projectId}/auth/oauth`,
50
+ method: 'POST',
51
+ body: {
52
+ oidcToken,
53
+ provider,
54
+ targetPublicKey,
55
+ projectId,
56
+ },
57
+ })
58
+ }
@@ -0,0 +1,51 @@
1
+ import type { Client } from '../../client/types.js'
2
+
3
+ export type GetWhoamiParameters = {
4
+ /** The organization ID to query */
5
+ organizationId: string
6
+ /** The project ID for the request */
7
+ projectId: string
8
+ }
9
+
10
+ export type GetWhoamiReturnType = {
11
+ /** The user's ID */
12
+ userId: string
13
+ /** The organization ID */
14
+ organizationId: string
15
+ /** The organization name */
16
+ organizationName?: string
17
+ /** The username */
18
+ username?: string
19
+ }
20
+
21
+ /**
22
+ * Gets the current user information
23
+ *
24
+ * @param client - The ZeroDev Wallet client
25
+ * @param params - The parameters for the whoami request
26
+ * @returns The user information
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const userInfo = await getWhoami(client, {
31
+ * organizationId: 'org_123',
32
+ * projectId: 'proj_456'
33
+ * });
34
+ * console.log(userInfo.userId); // 'user_789'
35
+ * ```
36
+ */
37
+ export async function getWhoami(
38
+ client: Client,
39
+ params: GetWhoamiParameters,
40
+ ): Promise<GetWhoamiReturnType> {
41
+ const { organizationId, projectId } = params
42
+
43
+ return await client.request({
44
+ path: `${projectId}/whoami`,
45
+ method: 'POST',
46
+ body: {
47
+ organizationId,
48
+ },
49
+ stamp: true,
50
+ })
51
+ }
@@ -0,0 +1,40 @@
1
+ export {
2
+ type AuthenticateWithEmailParameters,
3
+ type AuthenticateWithEmailReturnType,
4
+ authenticateWithEmail,
5
+ type EmailCustomization,
6
+ } from './authenticateWithEmail.js'
7
+
8
+ export {
9
+ type AuthenticateWithOAuthParameters,
10
+ type AuthenticateWithOAuthReturnType,
11
+ authenticateWithOAuth,
12
+ } from './authenticateWithOAuth.js'
13
+
14
+ export {
15
+ type GetWhoamiParameters,
16
+ type GetWhoamiReturnType,
17
+ getWhoami,
18
+ } from './getWhoami.js'
19
+ export {
20
+ type LoginWithOTPParameters,
21
+ type LoginWithOTPReturnType,
22
+ loginWithOTP,
23
+ } from './loginWithOTP.js'
24
+ export {
25
+ type LoginWithStampParameters,
26
+ type LoginWithStampReturnType,
27
+ loginWithStamp,
28
+ } from './loginWithStamp.js'
29
+
30
+ export {
31
+ type OtpContact,
32
+ type RegisterWithOTPParameters,
33
+ type RegisterWithOTPReturnType,
34
+ registerWithOTP,
35
+ } from './registerWithOTP.js'
36
+ export {
37
+ type RegisterWithPasskeyParameters,
38
+ type RegisterWithPasskeyReturnType,
39
+ registerWithPasskey,
40
+ } from './registerWithPasskey.js'
@@ -0,0 +1,60 @@
1
+ import type { Client } from '../../client/types.js'
2
+
3
+ export type LoginWithOTPParameters = {
4
+ /** The OTP ID received from registration */
5
+ otpId: string
6
+ /** The OTP code received via email/sms */
7
+ otpCode: string
8
+ /** The sub-organization ID from registration */
9
+ subOrganizationId: string
10
+ /** The encoded public key for authentication */
11
+ encodedPublicKey: string
12
+ /** The project ID for the request */
13
+ projectId: string
14
+ }
15
+
16
+ export type LoginWithOTPReturnType = {
17
+ /** The Turnkey session token */
18
+ session: string
19
+ }
20
+
21
+ /**
22
+ * Logs in a user with OTP (One-Time Password) authentication
23
+ * This verifies the OTP code and returns a session token
24
+ *
25
+ * @param client - The ZeroDev Wallet client
26
+ * @param params - The parameters for OTP login
27
+ * @returns The login result with session token
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * // After receiving OTP code via email
32
+ * const result = await loginWithOTP(client, {
33
+ * otpId: 'otp_123456',
34
+ * otpCode: '123456',
35
+ * subOrganizationId: 'org_abc',
36
+ * encodedPublicKey: '0x...',
37
+ * projectId: 'proj_456'
38
+ * });
39
+ *
40
+ * // Use result.session for authenticated requests
41
+ * ```
42
+ */
43
+ export async function loginWithOTP(
44
+ client: Client,
45
+ params: LoginWithOTPParameters,
46
+ ): Promise<LoginWithOTPReturnType> {
47
+ const { otpId, otpCode, subOrganizationId, encodedPublicKey, projectId } =
48
+ params
49
+
50
+ return await client.request({
51
+ path: `${projectId}/auth/login/otp`,
52
+ method: 'POST',
53
+ body: {
54
+ otpId,
55
+ otpCode,
56
+ subOrganizationId,
57
+ encodedPublicKey,
58
+ },
59
+ })
60
+ }
@@ -0,0 +1,68 @@
1
+ import type { Client } from '../../client/types.js'
2
+
3
+ export type EmailCustomization = {
4
+ /** A template for the URL to be used in a magic link button, e.g. `https://dapp.xyz/%s`. The auth bundle will be interpolated into the `%s`. */
5
+ magicLinkTemplate?: string
6
+ }
7
+
8
+ export type LoginWithStampParameters = {
9
+ /** The project ID for the request */
10
+ projectId: string
11
+ /** The organization ID for the request */
12
+ organizationId: string
13
+ /** The encoded public key for the request */
14
+ targetPublicKey: string
15
+ }
16
+
17
+ export type LoginWithStampReturnType = {
18
+ /** The session */
19
+ session: string
20
+ }
21
+
22
+ /**
23
+ * Logs in a user with a stamp
24
+ *
25
+ * @param client - The ZeroDev Wallet client
26
+ * @param params - The parameters for login with a stamp
27
+ * @returns The login result
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * const result = await loginWithStamp(client, {
32
+ * organizationId: 'org_456',
33
+ * projectId: 'proj_456',
34
+ * targetPublicKey: 'encodedPublicKey',
35
+ * });
36
+ * ```
37
+ */
38
+ export async function loginWithStamp(
39
+ client: Client,
40
+ params: LoginWithStampParameters,
41
+ ): Promise<LoginWithStampReturnType> {
42
+ const { projectId, targetPublicKey, organizationId } = params
43
+
44
+ const timestampMs = Date.now()
45
+ const timestampMsString = timestampMs.toString()
46
+ const timestampIso = new Date(timestampMs).toISOString()
47
+
48
+ const stampPayload = `${JSON.stringify({
49
+ organizationId,
50
+ parameters: {
51
+ publicKey: targetPublicKey,
52
+ },
53
+ timestampMs: timestampMsString,
54
+ type: 'ACTIVITY_TYPE_STAMP_LOGIN',
55
+ })}\n`
56
+ const stamp = await client.stamper.stamp(stampPayload)
57
+
58
+ return client.request({
59
+ path: `${projectId}/auth/login/passkey`,
60
+ method: 'POST',
61
+ body: {
62
+ subOrganizationId: organizationId,
63
+ targetPublicKey,
64
+ timestamp: timestampIso,
65
+ stamp,
66
+ },
67
+ })
68
+ }
@@ -0,0 +1,71 @@
1
+ import type { Client } from '../../client/types.js'
2
+ import type { EmailCustomization } from './authenticateWithEmail.js'
3
+
4
+ export type OtpContact = {
5
+ /** The OTP delivery type (currently only 'email' is supported) */
6
+ type: 'email' | 'sms'
7
+ /** The contact information (email address or phone number) */
8
+ contact: string
9
+ }
10
+
11
+ export type RegisterWithOTPParameters = {
12
+ /** The email address to register */
13
+ email: string
14
+ /** The contact information for OTP delivery */
15
+ contact: OtpContact
16
+ /** The project ID for the request */
17
+ projectId: string
18
+ /** Optional email customization settings */
19
+ emailCustomization?: EmailCustomization
20
+ }
21
+
22
+ export type RegisterWithOTPReturnType = {
23
+ /** The user ID */
24
+ userId: string
25
+ /** The wallet address */
26
+ walletAddress: string
27
+ /** The sub-organization ID */
28
+ subOrganizationId: string
29
+ /** The OTP ID needed for login */
30
+ otpId: string
31
+ }
32
+
33
+ /**
34
+ * Registers a user with OTP (One-Time Password) authentication
35
+ * This will send an OTP code to the specified contact method
36
+ *
37
+ * @param client - The ZeroDev Wallet client
38
+ * @param params - The parameters for OTP registration
39
+ * @returns The registration result including otpId needed for login
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * const result = await registerWithOTP(client, {
44
+ * email: 'user@example.com',
45
+ * contact: {
46
+ * type: 'email',
47
+ * contact: 'user@example.com'
48
+ * },
49
+ * projectId: 'proj_456'
50
+ * });
51
+ *
52
+ * // Use result.otpId for the login step
53
+ * ```
54
+ */
55
+ export async function registerWithOTP(
56
+ client: Client,
57
+ params: RegisterWithOTPParameters,
58
+ ): Promise<RegisterWithOTPReturnType> {
59
+ const { email, contact, projectId, emailCustomization } = params
60
+
61
+ return await client.request({
62
+ path: `${projectId}/auth/register/otp`,
63
+ method: 'POST',
64
+ body: {
65
+ email,
66
+ contact,
67
+ projectId,
68
+ emailCustomization,
69
+ },
70
+ })
71
+ }
@@ -0,0 +1,72 @@
1
+ import type { Client } from '../../client/types.js'
2
+
3
+ export type EmailCustomization = {
4
+ /** A template for the URL to be used in a magic link button, e.g. `https://dapp.xyz/%s`. The auth bundle will be interpolated into the `%s`. */
5
+ magicLinkTemplate?: string
6
+ }
7
+
8
+ export type RegisterWithPasskeyParameters = {
9
+ /** The email address to authenticate */
10
+ email: string
11
+ /** The project ID for the request */
12
+ projectId: string
13
+ /** The challenge for the request */
14
+ challenge: string
15
+ /** The attestation for the request */
16
+ attestation: {
17
+ attestationObject: string
18
+ clientDataJson: string
19
+ credentialId: string
20
+ }
21
+ /** The encoded public key for the request */
22
+ encodedPublicKey: string
23
+ }
24
+
25
+ export type RegisterWithPasskeyReturnType = {
26
+ /** The user ID */
27
+ userId: string
28
+ /** The wallet address */
29
+ walletAddress: string
30
+ /** The sub-organization ID */
31
+ subOrganizationId: string
32
+ }
33
+
34
+ /**
35
+ * Registers a passkey with the user's wallet
36
+ *
37
+ * @param client - The ZeroDev Wallet client
38
+ * @param params - The parameters for passkey registration
39
+ * @returns The passkey registration result
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * const result = await registerWithPasskey(client, {
44
+ * email: 'user@example.com',
45
+ * projectId: 'proj_456',
46
+ * challenge: 'challenge',
47
+ * attestation: {
48
+ * attestationObject: 'attestationObject',
49
+ * clientDataJson: 'clientDataJson',
50
+ * credentialId: 'credentialId'
51
+ * },
52
+ * encodedPublicKey: 'encodedPublicKey'
53
+ * });
54
+ * ```
55
+ */
56
+ export async function registerWithPasskey(
57
+ client: Client,
58
+ params: RegisterWithPasskeyParameters,
59
+ ): Promise<RegisterWithPasskeyReturnType> {
60
+ const { email, projectId, challenge, attestation, encodedPublicKey } = params
61
+
62
+ return client.request({
63
+ path: `${projectId}/auth/register/passkey`,
64
+ method: 'POST',
65
+ body: {
66
+ email,
67
+ attestation,
68
+ challenge,
69
+ encodedPublicKey,
70
+ },
71
+ })
72
+ }
@@ -0,0 +1,36 @@
1
+ // Auth actions
2
+ export {
3
+ type AuthenticateWithEmailParameters,
4
+ type AuthenticateWithEmailReturnType,
5
+ type AuthenticateWithOAuthParameters,
6
+ type AuthenticateWithOAuthReturnType,
7
+ authenticateWithEmail,
8
+ authenticateWithOAuth,
9
+ type EmailCustomization,
10
+ type GetWhoamiParameters,
11
+ type GetWhoamiReturnType,
12
+ getWhoami,
13
+ type LoginWithOTPParameters,
14
+ type LoginWithOTPReturnType,
15
+ loginWithOTP,
16
+ type OtpContact,
17
+ type RegisterWithOTPParameters,
18
+ type RegisterWithOTPReturnType,
19
+ type RegisterWithPasskeyParameters,
20
+ type RegisterWithPasskeyReturnType,
21
+ registerWithOTP,
22
+ registerWithPasskey,
23
+ } from './auth/index.js'
24
+
25
+ // Wallet actions
26
+ export {
27
+ type GetUserWalletParameters,
28
+ type GetUserWalletReturnType,
29
+ getUserWallet,
30
+ type SignRawPayloadParameters,
31
+ type SignRawPayloadReturnType,
32
+ type SignTransactionParameters,
33
+ type SignTransactionReturnType,
34
+ signRawPayload,
35
+ signTransaction,
36
+ } from './wallet/index.js'
@@ -0,0 +1,46 @@
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
+ }
10
+
11
+ export type GetUserWalletReturnType = {
12
+ /** The wallet address */
13
+ walletAddress: Hex
14
+ /** The user ID */
15
+ userId?: string
16
+ }
17
+
18
+ /**
19
+ * Gets the user's wallet information
20
+ *
21
+ * @param client - The ZeroDev Wallet client
22
+ * @param params - The parameters for getting wallet info
23
+ * @returns The wallet information
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * const wallet = await getUserWallet(client, {
28
+ * organizationId: 'org_123',
29
+ * projectId: 'proj_456'
30
+ * });
31
+ * console.log(wallet.walletAddress); // '0x...'
32
+ * ```
33
+ */
34
+ export async function getUserWallet(
35
+ client: Client,
36
+ params: GetUserWalletParameters,
37
+ ): Promise<GetUserWalletReturnType> {
38
+ const { organizationId, projectId } = params
39
+
40
+ return await client.request({
41
+ path: `${projectId}/user-wallet`,
42
+ body: {
43
+ organizationId,
44
+ },
45
+ })
46
+ }
@@ -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,71 @@
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 address to sign with */
10
+ address: Hex
11
+ /** The payload hash to sign (without 0x prefix) */
12
+ payload: string
13
+ /** The encoding type */
14
+ encoding?: 'PAYLOAD_ENCODING_HEXADECIMAL' | 'PAYLOAD_ENCODING_EIP712'
15
+ /** The hash function type */
16
+ hashFunction?: 'HASH_FUNCTION_NO_OP'
17
+ }
18
+
19
+ export type SignRawPayloadReturnType = Hex
20
+
21
+ /**
22
+ * Signs a raw payload with the user's wallet
23
+ *
24
+ * @param client - The ZeroDev Wallet client
25
+ * @param params - The parameters for signing
26
+ * @returns The signature
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const result = await signRawPayload(client, {
31
+ * organizationId: 'org_123',
32
+ * projectId: 'proj_456',
33
+ * address: '0x123...',
34
+ * payload: 'abc123...',
35
+ * });
36
+ * console.log(result.signature); // '0x...'
37
+ * ```
38
+ */
39
+ export async function signRawPayload(
40
+ client: Client,
41
+ params: SignRawPayloadParameters,
42
+ ): Promise<SignRawPayloadReturnType> {
43
+ const {
44
+ organizationId,
45
+ projectId,
46
+ address,
47
+ payload,
48
+ encoding = 'PAYLOAD_ENCODING_HEXADECIMAL',
49
+ hashFunction = 'HASH_FUNCTION_NO_OP',
50
+ } = params
51
+
52
+ const { signature } = await client.request({
53
+ path: `${projectId}/sign/raw-payload`,
54
+ body: {
55
+ body: {
56
+ type: 'ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2',
57
+ timestampMs: Date.now().toString(),
58
+ organizationId,
59
+ parameters: {
60
+ signWith: address,
61
+ payload,
62
+ encoding,
63
+ hashFunction,
64
+ },
65
+ },
66
+ apiUrl: 'https://api.turnkey.com/public/v1/submit/sign_raw_payload',
67
+ },
68
+ stamp: true,
69
+ })
70
+ return signature as Hex
71
+ }