@coinbase/cdp-sdk 1.43.1 → 1.44.0

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 (72) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +55 -0
  3. package/_cjs/actions/evm/sendUserOperation.js +23 -10
  4. package/_cjs/actions/evm/sendUserOperation.js.map +1 -1
  5. package/_cjs/actions/evm/transfer/utils.js.map +1 -1
  6. package/_cjs/auth/utils/hash.js +1 -1
  7. package/_cjs/auth/utils/hash.js.map +1 -1
  8. package/_cjs/auth/utils/http.js +4 -1
  9. package/_cjs/auth/utils/http.js.map +1 -1
  10. package/_cjs/client/end-user/endUser.js +87 -4
  11. package/_cjs/client/end-user/endUser.js.map +1 -1
  12. package/_cjs/client/end-user/toEndUserAccount.js +51 -0
  13. package/_cjs/client/end-user/toEndUserAccount.js.map +1 -0
  14. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +4 -2
  15. package/_cjs/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  16. package/_cjs/openapi-client/generated/end-user-accounts/end-user-accounts.js +43 -1
  17. package/_cjs/openapi-client/generated/end-user-accounts/end-user-accounts.js.map +1 -1
  18. package/_cjs/openapi-client/generated/webhooks/webhooks.js +8 -1
  19. package/_cjs/openapi-client/generated/webhooks/webhooks.js.map +1 -1
  20. package/_cjs/version.js +1 -1
  21. package/_esm/actions/evm/sendUserOperation.js +23 -10
  22. package/_esm/actions/evm/sendUserOperation.js.map +1 -1
  23. package/_esm/actions/evm/transfer/utils.js.map +1 -1
  24. package/_esm/auth/utils/hash.js +1 -1
  25. package/_esm/auth/utils/hash.js.map +1 -1
  26. package/_esm/auth/utils/http.js +4 -1
  27. package/_esm/auth/utils/http.js.map +1 -1
  28. package/_esm/client/end-user/endUser.js +88 -5
  29. package/_esm/client/end-user/endUser.js.map +1 -1
  30. package/_esm/client/end-user/toEndUserAccount.js +48 -0
  31. package/_esm/client/end-user/toEndUserAccount.js.map +1 -0
  32. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js +4 -2
  33. package/_esm/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.js.map +1 -1
  34. package/_esm/openapi-client/generated/end-user-accounts/end-user-accounts.js +39 -0
  35. package/_esm/openapi-client/generated/end-user-accounts/end-user-accounts.js.map +1 -1
  36. package/_esm/openapi-client/generated/webhooks/webhooks.js +8 -1
  37. package/_esm/openapi-client/generated/webhooks/webhooks.js.map +1 -1
  38. package/_esm/version.js +1 -1
  39. package/_types/actions/evm/sendUserOperation.d.ts.map +1 -1
  40. package/_types/actions/evm/transfer/utils.d.ts +2 -1
  41. package/_types/actions/evm/transfer/utils.d.ts.map +1 -1
  42. package/_types/auth/utils/http.d.ts.map +1 -1
  43. package/_types/client/end-user/endUser.d.ts +64 -6
  44. package/_types/client/end-user/endUser.d.ts.map +1 -1
  45. package/_types/client/end-user/endUser.types.d.ts +119 -1
  46. package/_types/client/end-user/endUser.types.d.ts.map +1 -1
  47. package/_types/client/end-user/toEndUserAccount.d.ts +20 -0
  48. package/_types/client/end-user/toEndUserAccount.d.ts.map +1 -0
  49. package/_types/index.d.ts +1 -1
  50. package/_types/index.d.ts.map +1 -1
  51. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts +62 -38
  52. package/_types/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.d.ts.map +1 -1
  53. package/_types/openapi-client/generated/end-user-accounts/end-user-accounts.d.ts +22 -1
  54. package/_types/openapi-client/generated/end-user-accounts/end-user-accounts.d.ts.map +1 -1
  55. package/_types/openapi-client/generated/webhooks/webhooks.d.ts +8 -1
  56. package/_types/openapi-client/generated/webhooks/webhooks.d.ts.map +1 -1
  57. package/_types/openapi-client/index.d.ts +3 -0
  58. package/_types/openapi-client/index.d.ts.map +1 -1
  59. package/_types/version.d.ts +1 -1
  60. package/actions/evm/sendUserOperation.ts +45 -11
  61. package/actions/evm/transfer/utils.ts +4 -2
  62. package/auth/utils/hash.ts +1 -1
  63. package/auth/utils/http.ts +5 -2
  64. package/client/end-user/endUser.ts +118 -13
  65. package/client/end-user/endUser.types.ts +135 -0
  66. package/client/end-user/toEndUserAccount.ts +80 -0
  67. package/index.ts +1 -1
  68. package/openapi-client/generated/coinbaseDeveloperPlatformAPIs.schemas.ts +74 -41
  69. package/openapi-client/generated/end-user-accounts/end-user-accounts.ts +75 -0
  70. package/openapi-client/generated/webhooks/webhooks.ts +8 -1
  71. package/package.json +1 -1
  72. package/version.ts +1 -1
@@ -8,15 +8,19 @@ import {
8
8
  type CreateEndUserOptions,
9
9
  type GetEndUserOptions,
10
10
  type ImportEndUserOptions,
11
+ type AddEndUserEvmAccountOptions,
12
+ type AddEndUserEvmAccountResult,
13
+ type AddEndUserEvmSmartAccountOptions,
14
+ type AddEndUserEvmSmartAccountResult,
15
+ type AddEndUserSolanaAccountOptions,
16
+ type AddEndUserSolanaAccountResult,
17
+ type EndUserAccount,
11
18
  } from "./endUser.types.js";
19
+ import { toEndUserAccount } from "./toEndUserAccount.js";
12
20
  import { Analytics } from "../../analytics.js";
13
21
  import { ImportAccountPublicRSAKey } from "../../constants.js";
14
22
  import { UserInputValidationError } from "../../errors.js";
15
- import {
16
- CdpOpenApiClient,
17
- type EndUser,
18
- type ListEndUsers200,
19
- } from "../../openapi-client/index.js";
23
+ import { CdpOpenApiClient, type ListEndUsers200 } from "../../openapi-client/index.js";
20
24
 
21
25
  /**
22
26
  * The CDP end user client.
@@ -50,17 +54,19 @@ export class CDPEndUserClient {
50
54
  * });
51
55
  * ```
52
56
  */
53
- async createEndUser(options: CreateEndUserOptions): Promise<EndUser> {
57
+ async createEndUser(options: CreateEndUserOptions): Promise<EndUserAccount> {
54
58
  Analytics.trackAction({
55
59
  action: "create_end_user",
56
60
  });
57
61
 
58
62
  const userId = options.userId ?? randomUUID();
59
63
 
60
- return CdpOpenApiClient.createEndUser({
64
+ const endUser = await CdpOpenApiClient.createEndUser({
61
65
  ...options,
62
66
  userId,
63
67
  });
68
+
69
+ return toEndUserAccount(CdpOpenApiClient, { endUser });
64
70
  }
65
71
 
66
72
  /**
@@ -124,14 +130,109 @@ export class CDPEndUserClient {
124
130
  * console.log(endUser.userId);
125
131
  * ```
126
132
  */
127
- async getEndUser(options: GetEndUserOptions): Promise<EndUser> {
133
+ async getEndUser(options: GetEndUserOptions): Promise<EndUserAccount> {
128
134
  Analytics.trackAction({
129
135
  action: "get_end_user",
130
136
  });
131
137
 
132
138
  const { userId } = options;
133
139
 
134
- return CdpOpenApiClient.getEndUser(userId);
140
+ const endUser = await CdpOpenApiClient.getEndUser(userId);
141
+
142
+ return toEndUserAccount(CdpOpenApiClient, { endUser });
143
+ }
144
+
145
+ /**
146
+ * Adds an EVM EOA (Externally Owned Account) to an existing end user. End users can have up to 10 EVM accounts.
147
+ *
148
+ * @param options - The options for adding an EVM account.
149
+ *
150
+ * @returns A promise that resolves to the newly created EVM EOA account.
151
+ *
152
+ * @example **Add an EVM EOA account to an existing end user**
153
+ * ```ts
154
+ * const result = await cdp.endUser.addEndUserEvmAccount({
155
+ * userId: "user-123"
156
+ * });
157
+ * console.log(result.evmAccount.address);
158
+ * ```
159
+ */
160
+ async addEndUserEvmAccount(
161
+ options: AddEndUserEvmAccountOptions,
162
+ ): Promise<AddEndUserEvmAccountResult> {
163
+ Analytics.trackAction({
164
+ action: "add_end_user_evm_account",
165
+ });
166
+
167
+ const { userId } = options;
168
+
169
+ return CdpOpenApiClient.addEndUserEvmAccount(userId, {});
170
+ }
171
+
172
+ /**
173
+ * Adds an EVM smart account to an existing end user. This also creates a new EVM EOA account to serve as the owner of the smart account.
174
+ *
175
+ * @param options - The options for adding an EVM smart account.
176
+ *
177
+ * @returns A promise that resolves to the newly created EVM smart account.
178
+ *
179
+ * @example **Add an EVM smart account to an existing end user**
180
+ * ```ts
181
+ * const result = await cdp.endUser.addEndUserEvmSmartAccount({
182
+ * userId: "user-123",
183
+ * enableSpendPermissions: false
184
+ * });
185
+ * console.log(result.evmSmartAccount.address);
186
+ * ```
187
+ *
188
+ * @example **Add an EVM smart account with spend permissions enabled**
189
+ * ```ts
190
+ * const result = await cdp.endUser.addEndUserEvmSmartAccount({
191
+ * userId: "user-123",
192
+ * enableSpendPermissions: true
193
+ * });
194
+ * console.log(result.evmSmartAccount.address);
195
+ * ```
196
+ */
197
+ async addEndUserEvmSmartAccount(
198
+ options: AddEndUserEvmSmartAccountOptions,
199
+ ): Promise<AddEndUserEvmSmartAccountResult> {
200
+ Analytics.trackAction({
201
+ action: "add_end_user_evm_smart_account",
202
+ });
203
+
204
+ const { userId, enableSpendPermissions } = options;
205
+
206
+ return CdpOpenApiClient.addEndUserEvmSmartAccount(userId, {
207
+ enableSpendPermissions,
208
+ });
209
+ }
210
+
211
+ /**
212
+ * Adds a Solana account to an existing end user. End users can have up to 10 Solana accounts.
213
+ *
214
+ * @param options - The options for adding a Solana account.
215
+ *
216
+ * @returns A promise that resolves to the newly created Solana account.
217
+ *
218
+ * @example **Add a Solana account to an existing end user**
219
+ * ```ts
220
+ * const result = await cdp.endUser.addEndUserSolanaAccount({
221
+ * userId: "user-123"
222
+ * });
223
+ * console.log(result.solanaAccount.address);
224
+ * ```
225
+ */
226
+ async addEndUserSolanaAccount(
227
+ options: AddEndUserSolanaAccountOptions,
228
+ ): Promise<AddEndUserSolanaAccountResult> {
229
+ Analytics.trackAction({
230
+ action: "add_end_user_solana_account",
231
+ });
232
+
233
+ const { userId } = options;
234
+
235
+ return CdpOpenApiClient.addEndUserSolanaAccount(userId, {});
135
236
  }
136
237
 
137
238
  /**
@@ -141,16 +242,18 @@ export class CDPEndUserClient {
141
242
  *
142
243
  * @returns The end user object if the access token is valid.
143
244
  */
144
- async validateAccessToken(options: ValidateAccessTokenOptions): Promise<EndUser> {
245
+ async validateAccessToken(options: ValidateAccessTokenOptions): Promise<EndUserAccount> {
145
246
  Analytics.trackAction({
146
247
  action: "validate_access_token",
147
248
  });
148
249
 
149
250
  const { accessToken } = options;
150
251
 
151
- return CdpOpenApiClient.validateEndUserAccessToken({
252
+ const endUser = await CdpOpenApiClient.validateEndUserAccessToken({
152
253
  accessToken,
153
254
  });
255
+
256
+ return toEndUserAccount(CdpOpenApiClient, { endUser });
154
257
  }
155
258
 
156
259
  /**
@@ -182,7 +285,7 @@ export class CDPEndUserClient {
182
285
  * });
183
286
  * ```
184
287
  */
185
- async importEndUser(options: ImportEndUserOptions): Promise<EndUser> {
288
+ async importEndUser(options: ImportEndUserOptions): Promise<EndUserAccount> {
186
289
  Analytics.trackAction({
187
290
  action: "import_end_user",
188
291
  });
@@ -232,11 +335,13 @@ export class CDPEndUserClient {
232
335
  privateKeyBytes,
233
336
  );
234
337
 
235
- return CdpOpenApiClient.importEndUser({
338
+ const endUser = await CdpOpenApiClient.importEndUser({
236
339
  userId,
237
340
  authenticationMethods: options.authenticationMethods,
238
341
  encryptedPrivateKey: encryptedPrivateKey.toString("base64"),
239
342
  keyType: options.keyType,
240
343
  });
344
+
345
+ return toEndUserAccount(CdpOpenApiClient, { endUser });
241
346
  }
242
347
  }
@@ -3,7 +3,12 @@ import type {
3
3
  ListEndUsersParams,
4
4
  ImportEndUserBodyKeyType,
5
5
  AuthenticationMethods,
6
+ AddEndUserEvmAccount201,
7
+ AddEndUserEvmSmartAccount201,
8
+ AddEndUserSolanaAccount201,
9
+ EndUser as OpenAPIEndUser,
6
10
  } from "../../openapi-client/index.js";
11
+ import type { Prettify } from "../../types/utils.js";
7
12
 
8
13
  /**
9
14
  * The options for validating an access token.
@@ -35,6 +40,55 @@ export type ListEndUsersOptions = ListEndUsersParams;
35
40
  */
36
41
  export type CreateEndUserOptions = CreateEndUserBody;
37
42
 
43
+ /**
44
+ * The options for adding an EVM account to an end user.
45
+ */
46
+ export interface AddEndUserEvmAccountOptions {
47
+ /**
48
+ * The unique identifier of the end user.
49
+ */
50
+ userId: string;
51
+ }
52
+
53
+ /**
54
+ * The result of adding an EVM account to an end user.
55
+ */
56
+ export type AddEndUserEvmAccountResult = AddEndUserEvmAccount201;
57
+
58
+ /**
59
+ * The options for adding an EVM smart account to an end user.
60
+ */
61
+ export interface AddEndUserEvmSmartAccountOptions {
62
+ /**
63
+ * The unique identifier of the end user.
64
+ */
65
+ userId: string;
66
+ /**
67
+ * If true, enables spend permissions for the EVM smart account.
68
+ */
69
+ enableSpendPermissions: boolean;
70
+ }
71
+
72
+ /**
73
+ * The result of adding an EVM smart account to an end user.
74
+ */
75
+ export type AddEndUserEvmSmartAccountResult = AddEndUserEvmSmartAccount201;
76
+
77
+ /**
78
+ * The options for adding a Solana account to an end user.
79
+ */
80
+ export interface AddEndUserSolanaAccountOptions {
81
+ /**
82
+ * The unique identifier of the end user.
83
+ */
84
+ userId: string;
85
+ }
86
+
87
+ /**
88
+ * The result of adding a Solana account to an end user.
89
+ */
90
+ export type AddEndUserSolanaAccountResult = AddEndUserSolanaAccount201;
91
+
38
92
  /**
39
93
  * The options for importing an end user.
40
94
  */
@@ -65,3 +119,84 @@ export interface ImportEndUserOptions {
65
119
  */
66
120
  encryptionPublicKey?: string;
67
121
  }
122
+
123
+ /**
124
+ * The options for adding an EVM smart account to an EndUser object.
125
+ */
126
+ export interface AddEvmSmartAccountOptions {
127
+ /**
128
+ * If true, enables spend permissions for the EVM smart account.
129
+ */
130
+ enableSpendPermissions: boolean;
131
+ }
132
+
133
+ /**
134
+ * Actions that can be performed on an EndUser object.
135
+ */
136
+ export type EndUserAccountActions = {
137
+ /**
138
+ * Adds an EVM EOA (Externally Owned Account) to this end user.
139
+ * End users can have up to 10 EVM accounts.
140
+ *
141
+ * @returns A promise that resolves to the newly created EVM EOA account.
142
+ *
143
+ * @example
144
+ * ```ts
145
+ * const endUser = await cdp.endUser.createEndUser({
146
+ * authenticationMethods: [{ type: "email", email: "user@example.com" }]
147
+ * });
148
+ *
149
+ * const result = await endUser.addEvmAccount();
150
+ * console.log(result.evmAccount.address);
151
+ * ```
152
+ */
153
+ addEvmAccount: () => Promise<AddEndUserEvmAccountResult>;
154
+
155
+ /**
156
+ * Adds an EVM smart account to this end user.
157
+ * This also creates a new EVM EOA account to serve as the owner of the smart account.
158
+ *
159
+ * @param options - The options for adding the EVM smart account.
160
+ *
161
+ * @returns A promise that resolves to the newly created EVM smart account.
162
+ *
163
+ * @example
164
+ * ```ts
165
+ * const endUser = await cdp.endUser.createEndUser({
166
+ * authenticationMethods: [{ type: "email", email: "user@example.com" }]
167
+ * });
168
+ *
169
+ * const result = await endUser.addEvmSmartAccount({ enableSpendPermissions: true });
170
+ * console.log(result.evmSmartAccount.address);
171
+ * ```
172
+ */
173
+ addEvmSmartAccount: (
174
+ options: AddEvmSmartAccountOptions,
175
+ ) => Promise<AddEndUserEvmSmartAccountResult>;
176
+
177
+ /**
178
+ * Adds a Solana account to this end user.
179
+ * End users can have up to 10 Solana accounts.
180
+ *
181
+ * @returns A promise that resolves to the newly created Solana account.
182
+ *
183
+ * @example
184
+ * ```ts
185
+ * const endUser = await cdp.endUser.createEndUser({
186
+ * authenticationMethods: [{ type: "email", email: "user@example.com" }]
187
+ * });
188
+ *
189
+ * const result = await endUser.addSolanaAccount();
190
+ * console.log(result.solanaAccount.address);
191
+ * ```
192
+ */
193
+ addSolanaAccount: () => Promise<AddEndUserSolanaAccountResult>;
194
+ };
195
+
196
+ /**
197
+ * An end user with actions that can be performed directly on the object.
198
+ *
199
+ * @see {@link OpenAPIEndUser}
200
+ * @see {@link EndUserAccountActions}
201
+ */
202
+ export type EndUserAccount = Prettify<OpenAPIEndUser & EndUserAccountActions>;
@@ -0,0 +1,80 @@
1
+ import { Analytics } from "../../analytics.js";
2
+
3
+ import type {
4
+ EndUserAccount,
5
+ AddEndUserEvmAccountResult,
6
+ AddEndUserEvmSmartAccountResult,
7
+ AddEndUserSolanaAccountResult,
8
+ AddEvmSmartAccountOptions,
9
+ } from "./endUser.types.js";
10
+ import type {
11
+ CdpOpenApiClientType,
12
+ EndUser as OpenAPIEndUser,
13
+ } from "../../openapi-client/index.js";
14
+
15
+ /**
16
+ * Options for converting an OpenAPI EndUser to an EndUserAccount with actions.
17
+ */
18
+ export type ToEndUserAccountOptions = {
19
+ /** The end user from the API response. */
20
+ endUser: OpenAPIEndUser;
21
+ };
22
+
23
+ /**
24
+ * Creates an EndUserAccount instance with actions from an existing OpenAPI EndUser.
25
+ * This wraps the raw API response and adds convenience methods for adding accounts.
26
+ *
27
+ * @param apiClient - The API client.
28
+ * @param options - Configuration options.
29
+ * @param options.endUser - The end user from the API response.
30
+ * @returns An EndUserAccount instance with action methods.
31
+ */
32
+ export function toEndUserAccount(
33
+ apiClient: CdpOpenApiClientType,
34
+ options: ToEndUserAccountOptions,
35
+ ): EndUserAccount {
36
+ const endUserAccount: EndUserAccount = {
37
+ // Pass through all properties from the OpenAPI EndUser
38
+ userId: options.endUser.userId,
39
+ authenticationMethods: options.endUser.authenticationMethods,
40
+ mfaMethods: options.endUser.mfaMethods,
41
+ evmAccounts: options.endUser.evmAccounts,
42
+ evmAccountObjects: options.endUser.evmAccountObjects,
43
+ evmSmartAccounts: options.endUser.evmSmartAccounts,
44
+ evmSmartAccountObjects: options.endUser.evmSmartAccountObjects,
45
+ solanaAccounts: options.endUser.solanaAccounts,
46
+ solanaAccountObjects: options.endUser.solanaAccountObjects,
47
+ createdAt: options.endUser.createdAt,
48
+
49
+ // Add action methods
50
+ async addEvmAccount(): Promise<AddEndUserEvmAccountResult> {
51
+ Analytics.trackAction({
52
+ action: "end_user_add_evm_account",
53
+ });
54
+
55
+ return apiClient.addEndUserEvmAccount(options.endUser.userId, {});
56
+ },
57
+
58
+ async addEvmSmartAccount(
59
+ smartAccountOptions: AddEvmSmartAccountOptions,
60
+ ): Promise<AddEndUserEvmSmartAccountResult> {
61
+ Analytics.trackAction({
62
+ action: "end_user_add_evm_smart_account",
63
+ });
64
+
65
+ return apiClient.addEndUserEvmSmartAccount(options.endUser.userId, {
66
+ enableSpendPermissions: smartAccountOptions.enableSpendPermissions,
67
+ });
68
+ },
69
+
70
+ async addSolanaAccount(): Promise<AddEndUserSolanaAccountResult> {
71
+ Analytics.trackAction({
72
+ action: "end_user_add_solana_account",
73
+ });
74
+
75
+ return apiClient.addEndUserSolanaAccount(options.endUser.userId, {});
76
+ },
77
+ };
78
+
79
+ return endUserAccount;
80
+ }
package/index.ts CHANGED
@@ -10,7 +10,7 @@ export {
10
10
  export { NetworkError } from "./openapi-client/errors.js";
11
11
  export type { SpendPermission, SpendPermissionInput } from "./spend-permissions/types.js";
12
12
  export type { SpendPermissionNetwork, ListEndUsers200, EndUser } from "./openapi-client/index.js";
13
- export type { ListEndUsersOptions } from "./client/end-user/endUser.types.js";
13
+ export type { ListEndUsersOptions, EndUserAccount } from "./client/end-user/endUser.types.js";
14
14
  export {
15
15
  SPEND_PERMISSION_MANAGER_ABI as spendPermissionManagerAbi,
16
16
  SPEND_PERMISSION_MANAGER_ADDRESS as spendPermissionManagerAddress,