@zerodev/wallet-core 0.0.1-alpha.5 → 0.0.1-alpha.7

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 (150) hide show
  1. package/README.md +43 -2
  2. package/dist/_cjs/actions/auth/authenticateWithOAuth.js +3 -7
  3. package/dist/_cjs/actions/auth/authenticateWithOAuth.js.map +1 -1
  4. package/dist/_cjs/actions/auth/getUserEmail.js +15 -0
  5. package/dist/_cjs/actions/auth/getUserEmail.js.map +1 -0
  6. package/dist/_cjs/actions/auth/index.js +3 -1
  7. package/dist/_cjs/actions/auth/index.js.map +1 -1
  8. package/dist/_cjs/actions/auth/loginWithOTP.js +3 -5
  9. package/dist/_cjs/actions/auth/loginWithOTP.js.map +1 -1
  10. package/dist/_cjs/actions/auth/loginWithStamp.js +4 -3
  11. package/dist/_cjs/actions/auth/loginWithStamp.js.map +1 -1
  12. package/dist/_cjs/actions/auth/registerWithOTP.js +1 -2
  13. package/dist/_cjs/actions/auth/registerWithOTP.js.map +1 -1
  14. package/dist/_cjs/actions/index.js +2 -1
  15. package/dist/_cjs/actions/index.js.map +1 -1
  16. package/dist/_cjs/actions/wallet/signRawPayload.js +13 -12
  17. package/dist/_cjs/actions/wallet/signRawPayload.js.map +1 -1
  18. package/dist/_cjs/actions/wallet/signTransaction.js +12 -11
  19. package/dist/_cjs/actions/wallet/signTransaction.js.map +1 -1
  20. package/dist/_cjs/adapters/viem.js +2 -0
  21. package/dist/_cjs/adapters/viem.js.map +1 -1
  22. package/dist/_cjs/client/authProxy.js +31 -0
  23. package/dist/_cjs/client/authProxy.js.map +1 -0
  24. package/dist/_cjs/client/decorators/client.js +1 -0
  25. package/dist/_cjs/client/decorators/client.js.map +1 -1
  26. package/dist/_cjs/client/index.js +3 -1
  27. package/dist/_cjs/client/index.js.map +1 -1
  28. package/dist/_cjs/client/transports/rest.js +3 -1
  29. package/dist/_cjs/client/transports/rest.js.map +1 -1
  30. package/dist/_cjs/constants.js +2 -1
  31. package/dist/_cjs/constants.js.map +1 -1
  32. package/dist/_cjs/core/createZeroDevWallet.js +22 -16
  33. package/dist/_cjs/core/createZeroDevWallet.js.map +1 -1
  34. package/dist/_cjs/index.js +5 -1
  35. package/dist/_cjs/index.js.map +1 -1
  36. package/dist/_cjs/stampers/iframeStamper.js +3 -0
  37. package/dist/_cjs/stampers/iframeStamper.js.map +1 -1
  38. package/dist/_cjs/utils/buildClientSignature.js +39 -0
  39. package/dist/_cjs/utils/buildClientSignature.js.map +1 -0
  40. package/dist/_cjs/utils/derToRawSignature.js +63 -0
  41. package/dist/_cjs/utils/derToRawSignature.js.map +1 -0
  42. package/dist/_cjs/utils/exportPrivateKey.js +55 -0
  43. package/dist/_cjs/utils/exportPrivateKey.js.map +1 -0
  44. package/dist/_esm/actions/auth/authenticateWithOAuth.js +8 -10
  45. package/dist/_esm/actions/auth/authenticateWithOAuth.js.map +1 -1
  46. package/dist/_esm/actions/auth/getUserEmail.js +28 -0
  47. package/dist/_esm/actions/auth/getUserEmail.js.map +1 -0
  48. package/dist/_esm/actions/auth/index.js +1 -0
  49. package/dist/_esm/actions/auth/index.js.map +1 -1
  50. package/dist/_esm/actions/auth/loginWithOTP.js +14 -12
  51. package/dist/_esm/actions/auth/loginWithOTP.js.map +1 -1
  52. package/dist/_esm/actions/auth/loginWithStamp.js +4 -3
  53. package/dist/_esm/actions/auth/loginWithStamp.js.map +1 -1
  54. package/dist/_esm/actions/auth/registerWithOTP.js +5 -6
  55. package/dist/_esm/actions/auth/registerWithOTP.js.map +1 -1
  56. package/dist/_esm/actions/index.js +1 -1
  57. package/dist/_esm/actions/index.js.map +1 -1
  58. package/dist/_esm/actions/wallet/signRawPayload.js +13 -12
  59. package/dist/_esm/actions/wallet/signRawPayload.js.map +1 -1
  60. package/dist/_esm/actions/wallet/signTransaction.js +12 -11
  61. package/dist/_esm/actions/wallet/signTransaction.js.map +1 -1
  62. package/dist/_esm/adapters/viem.js +2 -0
  63. package/dist/_esm/adapters/viem.js.map +1 -1
  64. package/dist/_esm/client/authProxy.js +41 -0
  65. package/dist/_esm/client/authProxy.js.map +1 -0
  66. package/dist/_esm/client/decorators/client.js +2 -1
  67. package/dist/_esm/client/decorators/client.js.map +1 -1
  68. package/dist/_esm/client/index.js +1 -0
  69. package/dist/_esm/client/index.js.map +1 -1
  70. package/dist/_esm/client/transports/rest.js +3 -1
  71. package/dist/_esm/client/transports/rest.js.map +1 -1
  72. package/dist/_esm/constants.js +1 -0
  73. package/dist/_esm/constants.js.map +1 -1
  74. package/dist/_esm/core/createZeroDevWallet.js +30 -18
  75. package/dist/_esm/core/createZeroDevWallet.js.map +1 -1
  76. package/dist/_esm/index.js +3 -0
  77. package/dist/_esm/index.js.map +1 -1
  78. package/dist/_esm/stampers/iframeStamper.js +4 -1
  79. package/dist/_esm/stampers/iframeStamper.js.map +1 -1
  80. package/dist/_esm/utils/buildClientSignature.js +64 -0
  81. package/dist/_esm/utils/buildClientSignature.js.map +1 -0
  82. package/dist/_esm/utils/derToRawSignature.js +89 -0
  83. package/dist/_esm/utils/derToRawSignature.js.map +1 -0
  84. package/dist/_esm/utils/exportPrivateKey.js +83 -0
  85. package/dist/_esm/utils/exportPrivateKey.js.map +1 -0
  86. package/dist/_types/actions/auth/authenticateWithOAuth.d.ts +6 -8
  87. package/dist/_types/actions/auth/authenticateWithOAuth.d.ts.map +1 -1
  88. package/dist/_types/actions/auth/getUserEmail.d.ts +29 -0
  89. package/dist/_types/actions/auth/getUserEmail.d.ts.map +1 -0
  90. package/dist/_types/actions/auth/index.d.ts +1 -0
  91. package/dist/_types/actions/auth/index.d.ts.map +1 -1
  92. package/dist/_types/actions/auth/loginWithOTP.d.ts +15 -15
  93. package/dist/_types/actions/auth/loginWithOTP.d.ts.map +1 -1
  94. package/dist/_types/actions/auth/loginWithStamp.d.ts.map +1 -1
  95. package/dist/_types/actions/auth/registerWithOTP.d.ts +5 -11
  96. package/dist/_types/actions/auth/registerWithOTP.d.ts.map +1 -1
  97. package/dist/_types/actions/index.d.ts +1 -1
  98. package/dist/_types/actions/index.d.ts.map +1 -1
  99. package/dist/_types/actions/wallet/signRawPayload.d.ts +2 -0
  100. package/dist/_types/actions/wallet/signRawPayload.d.ts.map +1 -1
  101. package/dist/_types/actions/wallet/signTransaction.d.ts +2 -0
  102. package/dist/_types/actions/wallet/signTransaction.d.ts.map +1 -1
  103. package/dist/_types/adapters/viem.d.ts.map +1 -1
  104. package/dist/_types/client/authProxy.d.ts +36 -0
  105. package/dist/_types/client/authProxy.d.ts.map +1 -0
  106. package/dist/_types/client/decorators/client.d.ts +5 -1
  107. package/dist/_types/client/decorators/client.d.ts.map +1 -1
  108. package/dist/_types/client/index.d.ts +1 -0
  109. package/dist/_types/client/index.d.ts.map +1 -1
  110. package/dist/_types/client/transports/rest.d.ts +2 -0
  111. package/dist/_types/client/transports/rest.d.ts.map +1 -1
  112. package/dist/_types/constants.d.ts +1 -0
  113. package/dist/_types/constants.d.ts.map +1 -1
  114. package/dist/_types/core/createZeroDevWallet.d.ts +0 -3
  115. package/dist/_types/core/createZeroDevWallet.d.ts.map +1 -1
  116. package/dist/_types/index.d.ts +3 -0
  117. package/dist/_types/index.d.ts.map +1 -1
  118. package/dist/_types/stampers/iframeStamper.d.ts.map +1 -1
  119. package/dist/_types/stampers/types.d.ts +2 -0
  120. package/dist/_types/stampers/types.d.ts.map +1 -1
  121. package/dist/_types/utils/buildClientSignature.d.ts +25 -0
  122. package/dist/_types/utils/buildClientSignature.d.ts.map +1 -0
  123. package/dist/_types/utils/derToRawSignature.d.ts +11 -0
  124. package/dist/_types/utils/derToRawSignature.d.ts.map +1 -0
  125. package/dist/_types/utils/exportPrivateKey.d.ts +47 -0
  126. package/dist/_types/utils/exportPrivateKey.d.ts.map +1 -0
  127. package/dist/tsconfig.build.tsbuildinfo +1 -1
  128. package/package.json +3 -2
  129. package/src/actions/auth/authenticateWithOAuth.ts +9 -15
  130. package/src/actions/auth/getUserEmail.ts +45 -0
  131. package/src/actions/auth/index.ts +5 -2
  132. package/src/actions/auth/loginWithOTP.ts +18 -21
  133. package/src/actions/auth/loginWithStamp.ts +4 -3
  134. package/src/actions/auth/registerWithOTP.ts +6 -13
  135. package/src/actions/index.ts +3 -0
  136. package/src/actions/wallet/signRawPayload.ts +15 -11
  137. package/src/actions/wallet/signTransaction.ts +15 -11
  138. package/src/adapters/viem.ts +2 -0
  139. package/src/client/authProxy.ts +78 -0
  140. package/src/client/decorators/client.ts +11 -0
  141. package/src/client/index.ts +7 -0
  142. package/src/client/transports/rest.ts +5 -1
  143. package/src/constants.ts +2 -0
  144. package/src/core/createZeroDevWallet.ts +34 -21
  145. package/src/index.ts +4 -0
  146. package/src/stampers/iframeStamper.ts +16 -2
  147. package/src/stampers/types.ts +7 -0
  148. package/src/utils/buildClientSignature.ts +86 -0
  149. package/src/utils/derToRawSignature.ts +103 -0
  150. package/src/utils/exportPrivateKey.ts +116 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerodev/wallet-core",
3
- "version": "0.0.1-alpha.5",
3
+ "version": "0.0.1-alpha.7",
4
4
  "description": "ZeroDev Wallet SDK built on Turnkey",
5
5
  "main": "./dist/_cjs/index.js",
6
6
  "module": "./dist/_esm/index.js",
@@ -52,7 +52,8 @@
52
52
  "@turnkey/http": "^3.12.1",
53
53
  "@turnkey/iframe-stamper": "^2.5.0",
54
54
  "@turnkey/indexed-db-stamper": "^1.1.1",
55
- "@turnkey/webauthn-stamper": "^0.6.0"
55
+ "@turnkey/webauthn-stamper": "^0.6.0",
56
+ "json-canonicalize": "^2.0.0"
56
57
  },
57
58
  "peerDependencies": {
58
59
  "viem": "^2.38.0"
@@ -1,14 +1,10 @@
1
1
  import type { Client } from '../../client/types.js'
2
2
 
3
3
  export type AuthenticateWithOAuthParameters = {
4
- /** The OAuth credential/token */
5
- oidcToken: string
6
4
  /** The OAuth provider (e.g., 'google') */
7
5
  provider: string
8
6
  /** The project ID for the request */
9
7
  projectId: string
10
- /** Target public key for authentication */
11
- targetPublicKey: string
12
8
  }
13
9
 
14
10
  export type AuthenticateWithOAuthReturnType = {
@@ -19,11 +15,15 @@ export type AuthenticateWithOAuthReturnType = {
19
15
  /** The sub-organization ID */
20
16
  subOrganizationId?: string
21
17
  /** The Turnkey session */
22
- turnkeySession?: string
18
+ session?: string
23
19
  }
24
20
 
25
21
  /**
26
- * Authenticates a user with OAuth credentials
22
+ * Authenticates a user with OAuth using cookie-based backend flow
23
+ *
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.
27
27
  *
28
28
  * @param client - The ZeroDev Wallet client
29
29
  * @param params - The parameters for OAuth authentication
@@ -32,10 +32,8 @@ export type AuthenticateWithOAuthReturnType = {
32
32
  * @example
33
33
  * ```ts
34
34
  * const result = await authenticateWithOAuth(client, {
35
- * oidcToken: 'oauth_token_here',
36
35
  * provider: 'google',
37
36
  * projectId: 'proj_456',
38
- * targetPublicKey: '0x...'
39
37
  * });
40
38
  * ```
41
39
  */
@@ -43,16 +41,12 @@ export async function authenticateWithOAuth(
43
41
  client: Client,
44
42
  params: AuthenticateWithOAuthParameters,
45
43
  ): Promise<AuthenticateWithOAuthReturnType> {
46
- const { oidcToken, provider, projectId, targetPublicKey } = params
44
+ const { projectId } = params
47
45
 
48
46
  return await client.request({
49
47
  path: `${projectId}/auth/oauth`,
50
48
  method: 'POST',
51
- body: {
52
- oidcToken,
53
- provider,
54
- targetPublicKey,
55
- projectId,
56
- },
49
+ body: null,
50
+ credentials: 'include',
57
51
  })
58
52
  }
@@ -0,0 +1,45 @@
1
+ import type { Client } from '../../client/types.js'
2
+
3
+ export type GetUserEmailParameters = {
4
+ /** The organization ID to query */
5
+ organizationId: string
6
+ /** The project ID for the request */
7
+ projectId: string
8
+ }
9
+
10
+ export type GetUserEmailReturnType = {
11
+ /** The user's email address */
12
+ email: string
13
+ }
14
+
15
+ /**
16
+ * Gets the user's email address
17
+ *
18
+ * @param client - The ZeroDev Wallet client
19
+ * @param params - The parameters for the user email request
20
+ * @returns The user's email address
21
+ *
22
+ * @example
23
+ * ```ts
24
+ * const userEmail = await getUserEmail(client, {
25
+ * organizationId: 'org_123',
26
+ * projectId: 'proj_456'
27
+ * });
28
+ * console.log(userEmail.email); // 'user@example.com'
29
+ * ```
30
+ */
31
+ export async function getUserEmail(
32
+ client: Client,
33
+ params: GetUserEmailParameters,
34
+ ): Promise<GetUserEmailReturnType> {
35
+ const { organizationId, projectId } = params
36
+
37
+ return await client.request({
38
+ path: `${projectId}/user-email`,
39
+ method: 'POST',
40
+ body: {
41
+ organizationId,
42
+ },
43
+ stamp: true,
44
+ })
45
+ }
@@ -10,7 +10,11 @@ export {
10
10
  type AuthenticateWithOAuthReturnType,
11
11
  authenticateWithOAuth,
12
12
  } from './authenticateWithOAuth.js'
13
-
13
+ export {
14
+ type GetUserEmailParameters,
15
+ type GetUserEmailReturnType,
16
+ getUserEmail,
17
+ } from './getUserEmail.js'
14
18
  export {
15
19
  type GetWhoamiParameters,
16
20
  type GetWhoamiReturnType,
@@ -26,7 +30,6 @@ export {
26
30
  type LoginWithStampReturnType,
27
31
  loginWithStamp,
28
32
  } from './loginWithStamp.js'
29
-
30
33
  export {
31
34
  type OtpContact,
32
35
  type RegisterWithOTPParameters,
@@ -1,14 +1,10 @@
1
1
  import type { Client } from '../../client/types.js'
2
2
 
3
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
4
+ /** The verification token JWT from Auth Proxy's verifyOtp */
5
+ verificationToken: string
6
+ /** The raw r||s signature hex (64 bytes = 128 chars) */
7
+ clientSignature: string
12
8
  /** The project ID for the request */
13
9
  projectId: string
14
10
  }
@@ -19,8 +15,14 @@ export type LoginWithOTPReturnType = {
19
15
  }
20
16
 
21
17
  /**
22
- * Logs in a user with OTP (One-Time Password) authentication
23
- * This verifies the OTP code and returns a session token
18
+ * Logs in a user with OTP (One-Time Password) authentication via the backend.
19
+ *
20
+ * The backend handles:
21
+ * 1. Parsing the verificationToken JWT to extract email and publicKey
22
+ * 2. Creating/retrieving sub-organization for (projectId, email)
23
+ * 3. Reconstructing the message for signature verification
24
+ * 4. Calling Turnkey.OtpLogin with the appropriate parameters
25
+ * 5. Returning the session to the SDK
24
26
  *
25
27
  * @param client - The ZeroDev Wallet client
26
28
  * @param params - The parameters for OTP login
@@ -28,12 +30,10 @@ export type LoginWithOTPReturnType = {
28
30
  *
29
31
  * @example
30
32
  * ```ts
31
- * // After receiving OTP code via email
33
+ * // After verifying OTP via Auth Proxy and building client signature
32
34
  * const result = await loginWithOTP(client, {
33
- * otpId: 'otp_123456',
34
- * otpCode: '123456',
35
- * subOrganizationId: 'org_abc',
36
- * encodedPublicKey: '0x...',
35
+ * verificationToken: '<jwt-from-auth-proxy>',
36
+ * clientSignature: '<raw-signature-hex>',
37
37
  * projectId: 'proj_456'
38
38
  * });
39
39
  *
@@ -44,17 +44,14 @@ export async function loginWithOTP(
44
44
  client: Client,
45
45
  params: LoginWithOTPParameters,
46
46
  ): Promise<LoginWithOTPReturnType> {
47
- const { otpId, otpCode, subOrganizationId, encodedPublicKey, projectId } =
48
- params
47
+ const { verificationToken, clientSignature, projectId } = params
49
48
 
50
49
  return await client.request({
51
50
  path: `${projectId}/auth/login/otp`,
52
51
  method: 'POST',
53
52
  body: {
54
- otpId,
55
- otpCode,
56
- subOrganizationId,
57
- encodedPublicKey,
53
+ verificationToken,
54
+ clientSignature,
58
55
  },
59
56
  })
60
57
  }
@@ -1,3 +1,4 @@
1
+ import { canonicalizeEx } from 'json-canonicalize'
1
2
  import type { Client } from '../../client/types.js'
2
3
  import type { Stamp } from '../../stampers/types.js'
3
4
 
@@ -48,14 +49,14 @@ export async function loginWithStamp(
48
49
  const timestampMsString = timestampMs.toString()
49
50
  const timestampIso = new Date(timestampMs).toISOString()
50
51
 
51
- const stampPayload = `${JSON.stringify({
52
+ const stampPayload = canonicalizeEx({
52
53
  organizationId,
53
54
  parameters: {
54
55
  publicKey: targetPublicKey,
55
56
  },
56
57
  timestampMs: timestampMsString,
57
58
  type: 'ACTIVITY_TYPE_STAMP_LOGIN',
58
- })}\n`
59
+ })
59
60
  let stamp: Stamp
60
61
  if (stampWith === 'indexedDb') {
61
62
  stamp = await client.indexedDbStamper.stamp(stampPayload)
@@ -66,7 +67,7 @@ export async function loginWithStamp(
66
67
  }
67
68
 
68
69
  return client.request({
69
- path: `${projectId}/auth/login/passkey`,
70
+ path: `${projectId}/auth/login/stamp`,
70
71
  method: 'POST',
71
72
  body: {
72
73
  subOrganizationId: organizationId,
@@ -20,23 +20,17 @@ export type RegisterWithOTPParameters = {
20
20
  }
21
21
 
22
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 */
23
+ /** The OTP ID needed for verification */
30
24
  otpId: string
31
25
  }
32
26
 
33
27
  /**
34
- * Registers a user with OTP (One-Time Password) authentication
28
+ * Initiates OTP (One-Time Password) authentication
35
29
  * This will send an OTP code to the specified contact method
36
30
  *
37
31
  * @param client - The ZeroDev Wallet client
38
- * @param params - The parameters for OTP registration
39
- * @returns The registration result including otpId needed for login
32
+ * @param params - The parameters for OTP initiation
33
+ * @returns The result including otpId needed for verification
40
34
  *
41
35
  * @example
42
36
  * ```ts
@@ -49,7 +43,7 @@ export type RegisterWithOTPReturnType = {
49
43
  * projectId: 'proj_456'
50
44
  * });
51
45
  *
52
- * // Use result.otpId for the login step
46
+ * // Use result.otpId for the verification step
53
47
  * ```
54
48
  */
55
49
  export async function registerWithOTP(
@@ -59,12 +53,11 @@ export async function registerWithOTP(
59
53
  const { email, contact, projectId, emailCustomization } = params
60
54
 
61
55
  return await client.request({
62
- path: `${projectId}/auth/register/otp`,
56
+ path: `${projectId}/auth/init/otp`,
63
57
  method: 'POST',
64
58
  body: {
65
59
  email,
66
60
  contact,
67
- projectId,
68
61
  emailCustomization,
69
62
  },
70
63
  })
@@ -7,8 +7,11 @@ export {
7
7
  authenticateWithEmail,
8
8
  authenticateWithOAuth,
9
9
  type EmailCustomization,
10
+ type GetUserEmailParameters,
11
+ type GetUserEmailReturnType,
10
12
  type GetWhoamiParameters,
11
13
  type GetWhoamiReturnType,
14
+ getUserEmail,
12
15
  getWhoami,
13
16
  type LoginWithOTPParameters,
14
17
  type LoginWithOTPReturnType,
@@ -6,6 +6,8 @@ export type SignRawPayloadParameters = {
6
6
  organizationId: string
7
7
  /** The project ID for the request */
8
8
  projectId: string
9
+ /** The session token for authorization */
10
+ token: string
9
11
  /** The address to sign with */
10
12
  address: Hex
11
13
  /** The payload hash to sign (without 0x prefix) */
@@ -43,6 +45,7 @@ export async function signRawPayload(
43
45
  const {
44
46
  organizationId,
45
47
  projectId,
48
+ token,
46
49
  address,
47
50
  payload,
48
51
  encoding = 'PAYLOAD_ENCODING_HEXADECIMAL',
@@ -52,20 +55,21 @@ export async function signRawPayload(
52
55
  const { signature } = await client.request({
53
56
  path: `${projectId}/sign/raw-payload`,
54
57
  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
- },
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,
65
66
  },
66
- apiUrl: 'https://api.turnkey.com/public/v1/submit/sign_raw_payload',
67
+ },
68
+ headers: {
69
+ Authorization: `Bearer ${token}`,
67
70
  },
68
71
  stamp: true,
72
+ stampPostion: 'headers',
69
73
  })
70
74
  return signature as Hex
71
75
  }
@@ -6,6 +6,8 @@ export type SignTransactionParameters = {
6
6
  organizationId: string
7
7
  /** The project ID for the request */
8
8
  projectId: string
9
+ /** The session token for authorization */
10
+ token: string
9
11
  /** The address to sign with */
10
12
  address: Hex
11
13
  /** The unsigned transaction to sign */
@@ -36,24 +38,26 @@ export async function signTransaction(
36
38
  client: Client,
37
39
  params: SignTransactionParameters,
38
40
  ): Promise<SignTransactionReturnType> {
39
- const { organizationId, projectId, address, unsignedTransaction } = params
41
+ const { organizationId, projectId, token, address, unsignedTransaction } =
42
+ params
40
43
 
41
44
  const { signature } = await client.request({
42
45
  path: `${projectId}/sign/transaction`,
43
46
  body: {
44
- body: {
45
- type: 'ACTIVITY_TYPE_SIGN_TRANSACTION_V2',
46
- timestampMs: Date.now().toString(),
47
- organizationId,
48
- parameters: {
49
- signWith: address,
50
- type: 'TRANSACTION_TYPE_ETHEREUM',
51
- unsignedTransaction,
52
- },
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,
53
54
  },
54
- apiUrl: 'https://api.turnkey.com/public/v1/submit/sign_transaction',
55
+ },
56
+ headers: {
57
+ Authorization: `Bearer ${token}`,
55
58
  },
56
59
  stamp: true,
60
+ stampPostion: 'headers',
57
61
  })
58
62
 
59
63
  return `0x${signature}` as Hex
@@ -53,6 +53,7 @@ export async function toViemAccount(
53
53
  return await client.signRawPayload({
54
54
  organizationId,
55
55
  projectId,
56
+ token,
56
57
  address,
57
58
  payload,
58
59
  encoding,
@@ -78,6 +79,7 @@ export async function toViemAccount(
78
79
  const signature = await client.signTransaction({
79
80
  organizationId,
80
81
  projectId,
82
+ token,
81
83
  address,
82
84
  unsignedTransaction: nonHexPrefixedSerializedTx,
83
85
  })
@@ -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>
@@ -10,10 +10,13 @@ import {
10
10
  type AuthenticateWithOAuthReturnType,
11
11
  authenticateWithEmail,
12
12
  authenticateWithOAuth,
13
+ type GetUserEmailParameters,
14
+ type GetUserEmailReturnType,
13
15
  type GetUserWalletParameters,
14
16
  type GetUserWalletReturnType,
15
17
  type GetWhoamiParameters,
16
18
  type GetWhoamiReturnType,
19
+ getUserEmail,
17
20
  getUserWallet,
18
21
  getWhoami,
19
22
  type LoginWithOTPParameters,
@@ -60,6 +63,13 @@ export type ZeroDevWalletActions = {
60
63
  */
61
64
  getWhoami: (params: GetWhoamiParameters) => Promise<GetWhoamiReturnType>
62
65
 
66
+ /**
67
+ * Gets the user's email address
68
+ */
69
+ getUserEmail: (
70
+ params: GetUserEmailParameters,
71
+ ) => Promise<GetUserEmailReturnType>
72
+
63
73
  // Wallet actions
64
74
  /**
65
75
  * Gets the user's wallet information
@@ -139,6 +149,7 @@ export function zeroDevWalletActions(client: Client): ZeroDevWalletActions {
139
149
  authenticateWithEmail: (params) => authenticateWithEmail(client, params),
140
150
  authenticateWithOAuth: (params) => authenticateWithOAuth(client, params),
141
151
  getWhoami: (params) => getWhoami(client, params),
152
+ getUserEmail: (params) => getUserEmail(client, params),
142
153
 
143
154
  // Wallet actions
144
155
  getUserWallet: (params) => getUserWallet(client, params),
@@ -1,3 +1,10 @@
1
+ export {
2
+ type AuthProxyClient,
3
+ type AuthProxyClientConfig,
4
+ type AuthProxyVerifyOtpRequest,
5
+ type AuthProxyVerifyOtpResponse,
6
+ createAuthProxyClient,
7
+ } from './authProxy.js'
1
8
  export {
2
9
  createBaseClient,
3
10
  createClient,
@@ -1,3 +1,4 @@
1
+ import { canonicalizeEx } from 'json-canonicalize'
1
2
  import { RestRequestError, RestTimeoutError } from '../../errors/request.js'
2
3
  import type { IndexedDbStamper, WebauthnStamper } from '../../stampers/types.js'
3
4
 
@@ -9,6 +10,8 @@ export type RestRequestArgs = {
9
10
  stamp?: boolean
10
11
  stampWith?: 'indexedDb' | 'webAuthn'
11
12
  stampPostion?: 'body' | 'headers'
13
+ /** Include credentials (cookies) in the request */
14
+ credentials?: RequestCredentials
12
15
  }
13
16
 
14
17
  export type RestRequestFn = <T = any>(args: RestRequestArgs) => Promise<T>
@@ -62,7 +65,7 @@ export function rest(url: string, cfg: RestTransportConfig): RestTransport {
62
65
  stamper = cfg.indexedDbStamper
63
66
  }
64
67
  const { body, apiUrl } = args.body
65
- const bodyString = `${JSON.stringify(body ?? args.body)}\n`
68
+ const bodyString = canonicalizeEx(body ?? args.body)
66
69
  const stamp = await stamper.stamp(bodyString)
67
70
 
68
71
  // Restructure request body to match backend expectation
@@ -97,6 +100,7 @@ export function rest(url: string, cfg: RestTransportConfig): RestTransport {
97
100
  headers: requestHeaders,
98
101
  body: requestBody != null ? JSON.stringify(requestBody) : null,
99
102
  signal: controller.signal,
103
+ ...(args.credentials && { credentials: args.credentials }),
100
104
  }
101
105
 
102
106
  const finalInit = (await cfg.onRequest?.(fullUrl, init)) ?? init
package/src/constants.ts CHANGED
@@ -2,4 +2,6 @@ export const DEFAULT_SESSION_EXPIRATION_IN_SECONDS = '900' // default to 15 minu
2
2
  export const DEFAULT_IFRAME_CONTAINER_ID = 'turnkey-auth-iframe-container-id'
3
3
  export const DEFAULT_IFRAME_ELEMENT_ID = 'turnkey-default-iframe-element-id'
4
4
  export const DEFAULT_ORGANIZATION_ID = '6254bb1d-0d0d-4f7e-96b8-77c94fe0b0c1'
5
+ export const DEFAULT_AUTH_PROXY_CONFIG_ID =
6
+ 'f69f6246-a814-43c6-90e6-2a8d947853d3'
5
7
  export const KMS_SERVER_URL = 'https://kms.dev.zerodev.app'