@zerodev/wallet-core 0.0.1-alpha.13 → 0.0.1-alpha.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerodev/wallet-core",
3
- "version": "0.0.1-alpha.13",
3
+ "version": "0.0.1-alpha.14",
4
4
  "description": "ZeroDev Wallet SDK built on Turnkey",
5
5
  "main": "./dist/_cjs/index.js",
6
6
  "module": "./dist/_esm/index.js",
@@ -5,6 +5,8 @@ export type AuthenticateWithOAuthParameters = {
5
5
  provider: string
6
6
  /** The project ID for the request */
7
7
  projectId: string
8
+ /** The session ID from the OAuth callback URL */
9
+ sessionId: string
8
10
  }
9
11
 
10
12
  export type AuthenticateWithOAuthReturnType = {
@@ -19,11 +21,11 @@ export type AuthenticateWithOAuthReturnType = {
19
21
  }
20
22
 
21
23
  /**
22
- * Authenticates a user with OAuth using cookie-based backend flow
24
+ * Authenticates a user with OAuth using a server-side session ID
23
25
  *
24
- * The backend reads the OAuth session from a cookie set during the OAuth flow.
25
- * This requires the OAuth popup flow to complete first via the backend's
26
- * /oauth/google/login endpoint.
26
+ * The backend stores the OAuth session server-side and returns a session ID
27
+ * via the callback URL. The SDK extracts this session ID and sends it in
28
+ * the request body.
27
29
  *
28
30
  * @param client - The ZeroDev Wallet client
29
31
  * @param params - The parameters for OAuth authentication
@@ -34,6 +36,7 @@ export type AuthenticateWithOAuthReturnType = {
34
36
  * const result = await authenticateWithOAuth(client, {
35
37
  * provider: 'google',
36
38
  * projectId: 'proj_456',
39
+ * sessionId: 'abc123',
37
40
  * });
38
41
  * ```
39
42
  */
@@ -41,12 +44,11 @@ export async function authenticateWithOAuth(
41
44
  client: Client,
42
45
  params: AuthenticateWithOAuthParameters,
43
46
  ): Promise<AuthenticateWithOAuthReturnType> {
44
- const { projectId } = params
47
+ const { projectId, sessionId } = params
45
48
 
46
49
  return await client.request({
47
50
  path: `${projectId}/auth/oauth`,
48
51
  method: 'POST',
49
- body: null,
50
- credentials: 'include',
52
+ body: { sessionId },
51
53
  })
52
54
  }
@@ -1,3 +1,4 @@
1
+ import { canonicalizeEx } from 'json-canonicalize'
1
2
  import type { Client } from '../../client/types.js'
2
3
 
3
4
  export type GetWhoamiParameters = {
@@ -5,6 +6,8 @@ export type GetWhoamiParameters = {
5
6
  organizationId: string
6
7
  /** The project ID for the request */
7
8
  projectId: string
9
+ /** The session token for authorization (required for session-based auth) */
10
+ token?: string
8
11
  }
9
12
 
10
13
  export type GetWhoamiReturnType = {
@@ -19,7 +22,11 @@ export type GetWhoamiReturnType = {
19
22
  }
20
23
 
21
24
  /**
22
- * Gets the current user information
25
+ * Gets the current user information.
26
+ *
27
+ * The whoami endpoint requires two stamps:
28
+ * 1. An inner stamp over the payload (for Turnkey verification) embedded in the body
29
+ * 2. An outer stamp over the full body (for KMS middleware) in the X-Stamp header
23
30
  *
24
31
  * @param client - The ZeroDev Wallet client
25
32
  * @param params - The parameters for the whoami request
@@ -29,7 +36,8 @@ export type GetWhoamiReturnType = {
29
36
  * ```ts
30
37
  * const userInfo = await getWhoami(client, {
31
38
  * organizationId: 'org_123',
32
- * projectId: 'proj_456'
39
+ * projectId: 'proj_456',
40
+ * token: 'session_token',
33
41
  * });
34
42
  * console.log(userInfo.userId); // 'user_789'
35
43
  * ```
@@ -38,14 +46,33 @@ export async function getWhoami(
38
46
  client: Client,
39
47
  params: GetWhoamiParameters,
40
48
  ): Promise<GetWhoamiReturnType> {
41
- const { organizationId, projectId } = params
49
+ const { organizationId, projectId, token } = params
50
+
51
+ // Step 1: Inner stamp over the payload (for Turnkey verification)
52
+ const innerBody = { organizationId }
53
+ const innerBodyString = canonicalizeEx(innerBody)
54
+ const innerStamp = await client.indexedDbStamper.stamp(innerBodyString)
55
+
56
+ // Step 2: Build full body with inner stamp embedded
57
+ const fullBody = {
58
+ ...innerBody,
59
+ stamp: {
60
+ stampHeaderName: innerStamp.stampHeaderName,
61
+ stampHeaderValue: innerStamp.stampHeaderValue,
62
+ },
63
+ }
64
+
65
+ // Step 3: Outer stamp over full body (for KMS middleware)
66
+ const fullBodyString = canonicalizeEx(fullBody)
67
+ const outerStamp = await client.indexedDbStamper.stamp(fullBodyString)
42
68
 
43
69
  return await client.request({
44
70
  path: `${projectId}/whoami`,
45
71
  method: 'POST',
46
- body: {
47
- organizationId,
72
+ body: fullBody,
73
+ headers: {
74
+ [outerStamp.stampHeaderName]: outerStamp.stampHeaderValue,
75
+ ...(token && { Authorization: `Bearer ${token}` }),
48
76
  },
49
- stamp: true,
50
77
  })
51
78
  }
@@ -50,6 +50,7 @@ export type AuthParams =
50
50
  | {
51
51
  type: 'oauth'
52
52
  provider: string
53
+ sessionId: string
53
54
  }
54
55
  | {
55
56
  type: 'passkey'
@@ -219,11 +220,10 @@ export async function createZeroDevWallet(
219
220
  async auth(params: AuthParams) {
220
221
  switch (params.type) {
221
222
  case 'oauth': {
222
- // Backend OAuth flow - the backend reads the OAuth session from a cookie
223
- // set during the OAuth popup flow via /oauth/google/login
224
223
  const data = await client.authenticateWithOAuth({
225
224
  provider: params.provider,
226
225
  projectId,
226
+ sessionId: params.sessionId,
227
227
  })
228
228
 
229
229
  if (data.session) {