@coinbase/agentkit 0.0.0-nightly-20250717210412 → 0.0.0-nightly-20250724210458

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 (38) hide show
  1. package/README.md +9 -1
  2. package/dist/action-providers/cdp/index.d.ts +0 -3
  3. package/dist/action-providers/cdp/index.js +0 -3
  4. package/dist/action-providers/farcaster/farcasterActionProvider.js +2 -0
  5. package/dist/action-providers/farcaster/farcasterActionProvider.test.js +55 -0
  6. package/dist/action-providers/farcaster/schemas.d.ts +13 -0
  7. package/dist/action-providers/farcaster/schemas.js +6 -0
  8. package/dist/action-providers/twitter/schemas.d.ts +16 -0
  9. package/dist/action-providers/twitter/schemas.js +23 -1
  10. package/dist/action-providers/twitter/twitterActionProvider.d.ts +8 -1
  11. package/dist/action-providers/twitter/twitterActionProvider.js +56 -5
  12. package/dist/action-providers/twitter/twitterActionProvider.test.js +52 -2
  13. package/dist/action-providers/weth/constants.d.ts +9 -0
  14. package/dist/action-providers/weth/constants.js +12 -0
  15. package/dist/action-providers/weth/schemas.d.ts +7 -0
  16. package/dist/action-providers/weth/schemas.js +7 -1
  17. package/dist/action-providers/weth/wethActionProvider.d.ts +9 -1
  18. package/dist/action-providers/weth/wethActionProvider.js +50 -1
  19. package/dist/action-providers/weth/wethActionProvider.test.js +60 -0
  20. package/dist/action-providers/x402/schemas.d.ts +9 -45
  21. package/dist/action-providers/x402/schemas.js +53 -17
  22. package/dist/action-providers/x402/x402ActionProvider.js +24 -19
  23. package/dist/action-providers/x402/x402ActionProvider.test.js +4 -35
  24. package/dist/wallet-providers/cdpEvmWalletProvider.d.ts +4 -4
  25. package/dist/wallet-providers/cdpEvmWalletProvider.js +4 -4
  26. package/dist/wallet-providers/cdpShared.d.ts +2 -2
  27. package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +2 -2
  28. package/dist/wallet-providers/cdpSmartWalletProvider.js +11 -4
  29. package/dist/wallet-providers/cdpSmartWalletProvider.test.js +31 -11
  30. package/dist/wallet-providers/legacyCdpWalletProvider.d.ts +1 -1
  31. package/dist/wallet-providers/legacyCdpWalletProvider.js +1 -1
  32. package/package.json +2 -2
  33. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.d.ts +0 -17
  34. package/dist/action-providers/cdp/cdpEvmWalletActionProvider.js +0 -20
  35. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.d.ts +0 -17
  36. package/dist/action-providers/cdp/cdpSmartWalletActionProvider.js +0 -20
  37. package/dist/action-providers/cdp/cdpSolanaWalletActionProvider.d.ts +0 -17
  38. package/dist/action-providers/cdp/cdpSolanaWalletActionProvider.js +0 -20
@@ -21,6 +21,21 @@ describe("Wrap Eth Schema", () => {
21
21
  expect(result.success).toBe(false);
22
22
  });
23
23
  });
24
+ describe("Unwrap Eth Schema", () => {
25
+ it("should successfully parse valid input", () => {
26
+ const validInput = {
27
+ amountToUnwrap: MOCK_AMOUNT,
28
+ };
29
+ const result = schemas_1.UnwrapEthSchema.safeParse(validInput);
30
+ expect(result.success).toBe(true);
31
+ expect(result.data).toEqual(validInput);
32
+ });
33
+ it("should fail parsing empty input", () => {
34
+ const emptyInput = {};
35
+ const result = schemas_1.UnwrapEthSchema.safeParse(emptyInput);
36
+ expect(result.success).toBe(false);
37
+ });
38
+ });
24
39
  describe("Wrap Eth Action", () => {
25
40
  let mockWallet;
26
41
  const actionProvider = (0, wethActionProvider_1.wethActionProvider)();
@@ -66,6 +81,51 @@ describe("Wrap Eth Action", () => {
66
81
  expect(response).toContain(`Error wrapping ETH: ${error}`);
67
82
  });
68
83
  });
84
+ describe("Unwrap Eth Action", () => {
85
+ let mockWallet;
86
+ const actionProvider = (0, wethActionProvider_1.wethActionProvider)();
87
+ beforeEach(async () => {
88
+ mockWallet = {
89
+ getAddress: jest.fn().mockReturnValue(MOCK_ADDRESS),
90
+ sendTransaction: jest.fn(),
91
+ waitForTransactionReceipt: jest.fn(),
92
+ };
93
+ });
94
+ it("should successfully respond", async () => {
95
+ const args = {
96
+ amountToUnwrap: MOCK_AMOUNT,
97
+ };
98
+ const hash = "0x1234567890123456789012345678901234567890";
99
+ mockWallet.sendTransaction.mockResolvedValue(hash);
100
+ const response = await actionProvider.unwrapEth(mockWallet, args);
101
+ expect(mockWallet.sendTransaction).toHaveBeenCalledWith({
102
+ to: constants_1.WETH_ADDRESS,
103
+ data: (0, viem_1.encodeFunctionData)({
104
+ abi: constants_1.WETH_ABI,
105
+ functionName: "withdraw",
106
+ args: [BigInt(MOCK_AMOUNT)],
107
+ }),
108
+ });
109
+ expect(response).toContain(`Unwrapped WETH with transaction hash: ${hash}`);
110
+ });
111
+ it("should fail with an error", async () => {
112
+ const args = {
113
+ amountToUnwrap: MOCK_AMOUNT,
114
+ };
115
+ const error = new Error("Failed to unwrap WETH");
116
+ mockWallet.sendTransaction.mockRejectedValue(error);
117
+ const response = await actionProvider.unwrapEth(mockWallet, args);
118
+ expect(mockWallet.sendTransaction).toHaveBeenCalledWith({
119
+ to: constants_1.WETH_ADDRESS,
120
+ data: (0, viem_1.encodeFunctionData)({
121
+ abi: constants_1.WETH_ABI,
122
+ functionName: "withdraw",
123
+ args: [BigInt(MOCK_AMOUNT)],
124
+ }),
125
+ });
126
+ expect(response).toContain(`Error unwrapping WETH: ${error}`);
127
+ });
128
+ });
69
129
  describe("supportsNetwork", () => {
70
130
  const actionProvider = (0, wethActionProvider_1.wethActionProvider)();
71
131
  it("should return true for base-mainnet", () => {
@@ -15,85 +15,49 @@ export declare const HttpRequestSchema: z.ZodObject<{
15
15
  body?: any;
16
16
  headers?: Record<string, string> | null | undefined;
17
17
  }>;
18
- export declare const RetryWithX402Schema: z.ZodObject<z.objectUtil.extendShape<{
18
+ export declare const RetryWithX402Schema: z.ZodObject<{
19
19
  url: z.ZodString;
20
20
  method: z.ZodDefault<z.ZodNullable<z.ZodEnum<["GET", "POST", "PUT", "DELETE", "PATCH"]>>>;
21
- headers: z.ZodNullable<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>>;
22
- body: z.ZodNullable<z.ZodOptional<z.ZodAny>>;
23
- }, {
24
- paymentOption: z.ZodObject<{
21
+ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
22
+ body: z.ZodOptional<z.ZodAny>;
23
+ selectedPaymentOption: z.ZodObject<{
25
24
  scheme: z.ZodString;
26
25
  network: z.ZodString;
27
26
  maxAmountRequired: z.ZodString;
28
- resource: z.ZodString;
29
- description: z.ZodString;
30
- mimeType: z.ZodString;
31
- outputSchema: z.ZodRecord<z.ZodString, z.ZodAny>;
32
- payTo: z.ZodString;
33
- maxTimeoutSeconds: z.ZodNumber;
34
27
  asset: z.ZodString;
35
- extra: z.ZodNullable<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>>;
36
28
  }, "strip", z.ZodTypeAny, {
37
- description: string;
38
29
  scheme: string;
39
30
  network: string;
40
31
  asset: string;
41
32
  maxAmountRequired: string;
42
- resource: string;
43
- mimeType: string;
44
- outputSchema: Record<string, any>;
45
- payTo: string;
46
- maxTimeoutSeconds: number;
47
- extra?: Record<string, any> | null | undefined;
48
33
  }, {
49
- description: string;
50
34
  scheme: string;
51
35
  network: string;
52
36
  asset: string;
53
37
  maxAmountRequired: string;
54
- resource: string;
55
- mimeType: string;
56
- outputSchema: Record<string, any>;
57
- payTo: string;
58
- maxTimeoutSeconds: number;
59
- extra?: Record<string, any> | null | undefined;
60
38
  }>;
61
- }>, "strip", z.ZodTypeAny, {
39
+ }, "strip", z.ZodTypeAny, {
62
40
  method: "POST" | "GET" | "PUT" | "DELETE" | "PATCH" | null;
63
41
  url: string;
64
- paymentOption: {
65
- description: string;
42
+ selectedPaymentOption: {
66
43
  scheme: string;
67
44
  network: string;
68
45
  asset: string;
69
46
  maxAmountRequired: string;
70
- resource: string;
71
- mimeType: string;
72
- outputSchema: Record<string, any>;
73
- payTo: string;
74
- maxTimeoutSeconds: number;
75
- extra?: Record<string, any> | null | undefined;
76
47
  };
77
48
  body?: any;
78
- headers?: Record<string, string> | null | undefined;
49
+ headers?: Record<string, string> | undefined;
79
50
  }, {
80
51
  url: string;
81
- paymentOption: {
82
- description: string;
52
+ selectedPaymentOption: {
83
53
  scheme: string;
84
54
  network: string;
85
55
  asset: string;
86
56
  maxAmountRequired: string;
87
- resource: string;
88
- mimeType: string;
89
- outputSchema: Record<string, any>;
90
- payTo: string;
91
- maxTimeoutSeconds: number;
92
- extra?: Record<string, any> | null | undefined;
93
57
  };
94
58
  method?: "POST" | "GET" | "PUT" | "DELETE" | "PATCH" | null | undefined;
95
59
  body?: any;
96
- headers?: Record<string, string> | null | undefined;
60
+ headers?: Record<string, string> | undefined;
97
61
  }>;
98
62
  export declare const DirectX402RequestSchema: z.ZodObject<{
99
63
  url: z.ZodString;
@@ -2,9 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DirectX402RequestSchema = exports.RetryWithX402Schema = exports.HttpRequestSchema = void 0;
4
4
  const zod_1 = require("zod");
5
- // Base schema for HTTP requests
6
- const BaseHttpRequestSchema = zod_1.z.object({
7
- url: zod_1.z.string().url().describe("The URL of the API endpoint (can be localhost for development)"),
5
+ // Schema for initial HTTP request
6
+ exports.HttpRequestSchema = zod_1.z
7
+ .object({
8
+ url: zod_1.z
9
+ .string()
10
+ .url()
11
+ .describe("The URL of the API endpoint (can be localhost for development)"),
8
12
  method: zod_1.z
9
13
  .enum(["GET", "POST", "PUT", "DELETE", "PATCH"])
10
14
  .nullable()
@@ -15,29 +19,61 @@ const BaseHttpRequestSchema = zod_1.z.object({
15
19
  .optional()
16
20
  .nullable()
17
21
  .describe("Optional headers to include in the request"),
18
- body: zod_1.z.any().optional().nullable().describe("Optional request body for POST/PUT/PATCH requests"),
19
- });
20
- // Schema for initial HTTP request
21
- exports.HttpRequestSchema = BaseHttpRequestSchema.strip().describe("Instructions for making a basic HTTP request");
22
+ body: zod_1.z
23
+ .any()
24
+ .optional()
25
+ .nullable()
26
+ .describe("Optional request body for POST/PUT/PATCH requests"),
27
+ })
28
+ .strip()
29
+ .describe("Instructions for making a basic HTTP request");
22
30
  // Schema for retrying a failed request with x402 payment
23
- exports.RetryWithX402Schema = BaseHttpRequestSchema.extend({
24
- paymentOption: zod_1.z
31
+ exports.RetryWithX402Schema = zod_1.z
32
+ .object({
33
+ url: zod_1.z
34
+ .string()
35
+ .url()
36
+ .describe("The URL of the API endpoint (can be localhost for development)"),
37
+ method: zod_1.z
38
+ .enum(["GET", "POST", "PUT", "DELETE", "PATCH"])
39
+ .nullable()
40
+ .default("GET")
41
+ .describe("The HTTP method to use for the request"),
42
+ headers: zod_1.z.record(zod_1.z.string()).optional().describe("Optional headers to include in the request"),
43
+ body: zod_1.z.any().optional().describe("Optional request body for POST/PUT/PATCH requests"),
44
+ selectedPaymentOption: zod_1.z
25
45
  .object({
26
46
  scheme: zod_1.z.string(),
27
47
  network: zod_1.z.string(),
28
48
  maxAmountRequired: zod_1.z.string(),
29
- resource: zod_1.z.string(),
30
- description: zod_1.z.string(),
31
- mimeType: zod_1.z.string(),
32
- outputSchema: zod_1.z.record(zod_1.z.any()),
33
- payTo: zod_1.z.string(),
34
- maxTimeoutSeconds: zod_1.z.number(),
35
49
  asset: zod_1.z.string(),
36
- extra: zod_1.z.record(zod_1.z.any()).optional().nullable(),
37
50
  })
38
51
  .describe("The payment option to use for this request"),
39
52
  })
40
53
  .strip()
41
54
  .describe("Instructions for retrying a request with x402 payment after receiving a 402 response");
42
55
  // Schema for direct x402 payment request (with warning)
43
- exports.DirectX402RequestSchema = BaseHttpRequestSchema.strip().describe("Instructions for making an HTTP request with automatic x402 payment handling. WARNING: This bypasses user confirmation - only use when explicitly told to skip confirmation!");
56
+ exports.DirectX402RequestSchema = zod_1.z
57
+ .object({
58
+ url: zod_1.z
59
+ .string()
60
+ .url()
61
+ .describe("The URL of the API endpoint (can be localhost for development)"),
62
+ method: zod_1.z
63
+ .enum(["GET", "POST", "PUT", "DELETE", "PATCH"])
64
+ .nullable()
65
+ .default("GET")
66
+ .describe("The HTTP method to use for the request"),
67
+ headers: zod_1.z
68
+ .record(zod_1.z.string())
69
+ .optional()
70
+ .nullable()
71
+ .describe("Optional headers to include in the request"),
72
+ body: zod_1.z
73
+ .any()
74
+ .optional()
75
+ .nullable()
76
+ .describe("Optional request body for POST/PUT/PATCH requests"),
77
+ })
78
+ .strip()
79
+ .describe("Instructions for making an HTTP request with automatic x402 payment handling. WARNING: This bypasses user confirmation - only use when explicitly told to skip confirmation!");
@@ -20,7 +20,6 @@ const schemas_1 = require("./schemas");
20
20
  const wallet_providers_1 = require("../../wallet-providers");
21
21
  const axios_1 = __importDefault(require("axios"));
22
22
  const x402_axios_1 = require("x402-axios");
23
- const types_1 = require("x402/types");
24
23
  const SUPPORTED_NETWORKS = ["base-mainnet", "base-sepolia"];
25
24
  /**
26
25
  * X402ActionProvider provides actions for making HTTP requests, with optional x402 payment handling.
@@ -65,13 +64,12 @@ class X402ActionProvider extends actionProvider_1.ActionProvider {
65
64
  data: response.data,
66
65
  }, null, 2);
67
66
  }
68
- const paymentRequirements = response.data.accepts.map(accept => types_1.PaymentRequirementsSchema.parse(accept));
69
67
  return JSON.stringify({
70
68
  status: "error_402_payment_required",
71
- acceptablePaymentOptions: paymentRequirements,
69
+ acceptablePaymentOptions: response.data.accepts,
72
70
  nextSteps: [
73
71
  "Inform the user that the requested server replied with a 402 Payment Required response.",
74
- `The payment options are: ${paymentRequirements.map(option => `${option.asset} ${option.maxAmountRequired} ${option.network}`).join(", ")}`,
72
+ `The payment options are: ${response.data.accepts.map(option => `${option.asset} ${option.maxAmountRequired} ${option.network}`).join(", ")}`,
75
73
  "Ask the user if they want to retry the request with payment.",
76
74
  `Use retry_http_request_with_x402 to retry the request with payment.`,
77
75
  ],
@@ -90,20 +88,27 @@ class X402ActionProvider extends actionProvider_1.ActionProvider {
90
88
  */
91
89
  async retryWithX402(walletProvider, args) {
92
90
  try {
93
- // Validate the payment option matches the URL
94
- if (args.paymentOption.resource !== args.url) {
95
- return JSON.stringify({
96
- status: "error_invalid_payment_option",
97
- message: "The payment option resource does not match the request URL",
98
- details: {
99
- expected: args.url,
100
- received: args.paymentOption.resource,
101
- },
102
- });
103
- }
104
91
  // Make the request with payment handling
105
92
  const account = walletProvider.toSigner();
106
- const api = (0, x402_axios_1.withPaymentInterceptor)(axios_1.default.create({}), account);
93
+ const paymentSelector = (accepts) => {
94
+ const { scheme, network, maxAmountRequired, asset } = args.selectedPaymentOption;
95
+ let paymentRequirements = accepts.find(accept => accept.scheme === scheme &&
96
+ accept.network === network &&
97
+ accept.maxAmountRequired <= maxAmountRequired &&
98
+ accept.asset === asset);
99
+ if (paymentRequirements) {
100
+ return paymentRequirements;
101
+ }
102
+ paymentRequirements = accepts.find(accept => accept.scheme === scheme &&
103
+ accept.network === network &&
104
+ accept.maxAmountRequired <= maxAmountRequired &&
105
+ accept.asset === asset);
106
+ if (paymentRequirements) {
107
+ return paymentRequirements;
108
+ }
109
+ return accepts[0];
110
+ };
111
+ const api = (0, x402_axios_1.withPaymentInterceptor)(axios_1.default.create({}), account, paymentSelector);
107
112
  const response = await api.request({
108
113
  url: args.url,
109
114
  method: args.method ?? "GET",
@@ -122,9 +127,9 @@ class X402ActionProvider extends actionProvider_1.ActionProvider {
122
127
  url: args.url,
123
128
  method: args.method,
124
129
  paymentUsed: {
125
- network: args.paymentOption.network,
126
- asset: args.paymentOption.asset,
127
- amount: args.paymentOption.maxAmountRequired,
130
+ network: args.selectedPaymentOption.network,
131
+ asset: args.selectedPaymentOption.asset,
132
+ amount: args.selectedPaymentOption.maxAmountRequired,
128
133
  },
129
134
  paymentProof: paymentProof
130
135
  ? {
@@ -225,20 +225,15 @@ describe("X402ActionProvider", () => {
225
225
  const result = await provider.retryWithX402(mockWalletProvider, {
226
226
  url: "https://www.x402.org/protected",
227
227
  method: "GET",
228
- paymentOption: {
228
+ selectedPaymentOption: {
229
229
  scheme: "exact",
230
230
  network: "base-sepolia",
231
231
  maxAmountRequired: "10000",
232
- resource: "https://www.x402.org/protected",
233
- description: "Access to protected content",
234
- mimeType: "application/json",
235
- payTo: "0x123",
236
- maxTimeoutSeconds: 300,
237
232
  asset: "0x456",
238
- outputSchema: {},
239
233
  },
240
234
  });
241
- expect(mockWithPaymentInterceptor).toHaveBeenCalledWith(mockAxiosInstance, "mock-signer");
235
+ // Update expectation to accept the payment selector function
236
+ expect(mockWithPaymentInterceptor).toHaveBeenCalledWith(mockAxiosInstance, "mock-signer", expect.any(Function));
242
237
  const parsedResult = JSON.parse(result);
243
238
  expect(parsedResult.status).toBe("success");
244
239
  expect(parsedResult.details.paymentProof).toEqual({
@@ -247,26 +242,6 @@ describe("X402ActionProvider", () => {
247
242
  payer: MOCK_PAYMENT_RESPONSE.payer,
248
243
  });
249
244
  });
250
- it("should reject if payment option resource doesn't match URL", async () => {
251
- const result = await provider.retryWithX402(mockWalletProvider, {
252
- url: "https://www.x402.org/protected",
253
- method: "GET",
254
- paymentOption: {
255
- scheme: "exact",
256
- network: "base-sepolia",
257
- maxAmountRequired: "10000",
258
- resource: "https://different.url/protected", // Mismatched URL
259
- description: "Access to protected content",
260
- mimeType: "application/json",
261
- payTo: "0x123",
262
- maxTimeoutSeconds: 300,
263
- asset: "0x456",
264
- outputSchema: {},
265
- },
266
- });
267
- const parsedResult = JSON.parse(result);
268
- expect(parsedResult.status).toBe("error_invalid_payment_option");
269
- });
270
245
  it("should handle network errors during payment", async () => {
271
246
  const error = new Error("Network error");
272
247
  error.isAxiosError = true;
@@ -275,17 +250,11 @@ describe("X402ActionProvider", () => {
275
250
  const result = await provider.retryWithX402(mockWalletProvider, {
276
251
  url: "https://www.x402.org/protected",
277
252
  method: "GET",
278
- paymentOption: {
253
+ selectedPaymentOption: {
279
254
  scheme: "exact",
280
255
  network: "base-sepolia",
281
256
  maxAmountRequired: "10000",
282
- resource: "https://www.x402.org/protected",
283
- description: "Access to protected content",
284
- mimeType: "application/json",
285
- payTo: "0x123",
286
- maxTimeoutSeconds: 300,
287
257
  asset: "0x456",
288
- outputSchema: {},
289
258
  },
290
259
  });
291
260
  const parsedResult = JSON.parse(result);
@@ -9,16 +9,16 @@ import { WalletProviderWithClient, CdpWalletProviderConfig } from "./cdpShared";
9
9
  export declare class CdpEvmWalletProvider extends EvmWalletProvider implements WalletProviderWithClient {
10
10
  #private;
11
11
  /**
12
- * Constructs a new CdpServerWalletProvider.
12
+ * Constructs a new CdpEvmWalletProvider.
13
13
  *
14
- * @param config - The configuration options for the CdpServerWalletProvider.
14
+ * @param config - The configuration options for the CdpEvmWalletProvider.
15
15
  */
16
16
  private constructor();
17
17
  /**
18
- * Configures a new CdpServerWalletProvider with a wallet.
18
+ * Configures a new CdpEvmWalletProvider with a wallet.
19
19
  *
20
20
  * @param config - Optional configuration parameters
21
- * @returns A Promise that resolves to a new CdpServerWalletProvider instance
21
+ * @returns A Promise that resolves to a new CdpEvmWalletProvider instance
22
22
  * @throws Error if required environment variables are missing or wallet initialization fails
23
23
  */
24
24
  static configureWithWallet(config?: CdpWalletProviderConfig): Promise<CdpEvmWalletProvider>;
@@ -22,9 +22,9 @@ const evmWalletProvider_1 = require("./evmWalletProvider");
22
22
  */
23
23
  class CdpEvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
24
24
  /**
25
- * Constructs a new CdpServerWalletProvider.
25
+ * Constructs a new CdpEvmWalletProvider.
26
26
  *
27
- * @param config - The configuration options for the CdpServerWalletProvider.
27
+ * @param config - The configuration options for the CdpEvmWalletProvider.
28
28
  */
29
29
  constructor(config) {
30
30
  super();
@@ -39,10 +39,10 @@ class CdpEvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
39
39
  __classPrivateFieldSet(this, _CdpEvmWalletProvider_network, config.network, "f");
40
40
  }
41
41
  /**
42
- * Configures a new CdpServerWalletProvider with a wallet.
42
+ * Configures a new CdpEvmWalletProvider with a wallet.
43
43
  *
44
44
  * @param config - Optional configuration parameters
45
- * @returns A Promise that resolves to a new CdpServerWalletProvider instance
45
+ * @returns A Promise that resolves to a new CdpEvmWalletProvider instance
46
46
  * @throws Error if required environment variables are missing or wallet initialization fails
47
47
  */
48
48
  static async configureWithWallet(config = {}) {
@@ -1,5 +1,5 @@
1
1
  import { CdpClient, type EvmServerAccount } from "@coinbase/cdp-sdk";
2
- import type { Address, PrivateKeyAccount } from "viem";
2
+ import type { Address, LocalAccount } from "viem";
3
3
  export interface CdpProviderConfig {
4
4
  /**
5
5
  * The CDP API Key ID.
@@ -35,7 +35,7 @@ export interface CdpSmartWalletProviderConfig extends CdpWalletProviderConfig {
35
35
  /**
36
36
  * The owner account of the smart wallet.
37
37
  */
38
- owner?: EvmServerAccount | PrivateKeyAccount | Address;
38
+ owner?: EvmServerAccount | LocalAccount | Address;
39
39
  /**
40
40
  * The name of the smart wallet.
41
41
  */
@@ -35,10 +35,10 @@ export declare class CdpSmartWalletProvider extends EvmWalletProvider implements
35
35
  /**
36
36
  * Signs a message using the owner account.
37
37
  *
38
- * @param message - The message to sign.
38
+ * @param _message - The message to sign.
39
39
  * @returns The signed message.
40
40
  */
41
- signMessage(message: string): Promise<Hex>;
41
+ signMessage(_message: string): Promise<Hex>;
42
42
  /**
43
43
  * Signs a typed data object using the owner account.
44
44
  *
@@ -117,11 +117,11 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
117
117
  /**
118
118
  * Signs a message using the owner account.
119
119
  *
120
- * @param message - The message to sign.
120
+ * @param _message - The message to sign.
121
121
  * @returns The signed message.
122
122
  */
123
- async signMessage(message) {
124
- return __classPrivateFieldGet(this, _CdpSmartWalletProvider_ownerAccount, "f").signMessage({ message });
123
+ async signMessage(_message) {
124
+ throw new Error("Direct message signing not supported for smart wallets. Use sendTransaction instead.");
125
125
  }
126
126
  /**
127
127
  * Signs a typed data object using the owner account.
@@ -131,7 +131,14 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
131
131
  */
132
132
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
133
133
  async signTypedData(typedData) {
134
- return __classPrivateFieldGet(this, _CdpSmartWalletProvider_ownerAccount, "f").signTypedData(typedData);
134
+ const { domain, types, primaryType, message } = typedData;
135
+ return await __classPrivateFieldGet(this, _CdpSmartWalletProvider_smartAccount, "f").signTypedData({
136
+ domain,
137
+ types,
138
+ primaryType,
139
+ message,
140
+ network: __classPrivateFieldGet(this, _CdpSmartWalletProvider_instances, "m", _CdpSmartWalletProvider_getCdpSdkNetwork).call(this),
141
+ });
135
142
  }
136
143
  /**
137
144
  * Signs a transaction using the owner account.
@@ -188,20 +188,40 @@ describe("CdpSmartWalletProvider", () => {
188
188
  // signing operation tests
189
189
  // =========================================================
190
190
  describe("signing operations", () => {
191
- it("should sign messages using owner account", async () => {
192
- const signature = await provider.signMessage("Hello, world!");
193
- expect(mockOwnerAccount.signMessage).toHaveBeenCalledWith({ message: "Hello, world!" });
194
- expect(signature).toBe(MOCK_SIGNATURE);
191
+ it("should throw error for direct message signing", async () => {
192
+ await expect(provider.signMessage("Hello, world!")).rejects.toThrow("Direct message signing not supported for smart wallets. Use sendTransaction instead.");
195
193
  });
196
- it("should sign typed data using owner account", async () => {
194
+ it("should sign typed data using smart account", async () => {
197
195
  const typedData = {
198
- domain: { name: "Example" },
199
- types: { Test: [{ name: "test", type: "string" }] },
200
- message: { test: "example" },
201
- primaryType: "Test",
196
+ domain: {
197
+ name: "Example",
198
+ version: "1",
199
+ chainId: 1,
200
+ verifyingContract: "0x1234567890123456789012345678901234567890",
201
+ },
202
+ types: {
203
+ Person: [
204
+ { name: "name", type: "string" },
205
+ { name: "wallet", type: "address" },
206
+ ],
207
+ },
208
+ primaryType: "Person",
209
+ message: {
210
+ name: "Bob",
211
+ wallet: "0x1234567890123456789012345678901234567890",
212
+ },
202
213
  };
214
+ // Mock the smart account's signTypedData method
215
+ mockSmartAccount.signTypedData = jest.fn().mockResolvedValue(MOCK_SIGNATURE);
203
216
  const signature = await provider.signTypedData(typedData);
204
- expect(mockOwnerAccount.signTypedData).toHaveBeenCalledWith(typedData);
217
+ // Verify the smart account was called with the correct parameters
218
+ expect(mockSmartAccount.signTypedData).toHaveBeenCalledWith({
219
+ domain: typedData.domain,
220
+ types: typedData.types,
221
+ primaryType: typedData.primaryType,
222
+ message: typedData.message,
223
+ network: MOCK_NETWORK.networkId,
224
+ });
205
225
  expect(signature).toBe(MOCK_SIGNATURE);
206
226
  });
207
227
  it("should throw error for direct transaction signing", async () => {
@@ -209,7 +229,7 @@ describe("CdpSmartWalletProvider", () => {
209
229
  to: "0x1234567890123456789012345678901234567890",
210
230
  value: BigInt(1000000000000000000),
211
231
  };
212
- await expect(provider.signTransaction(tx)).rejects.toThrow("Direct transaction signing not supported for smart wallets");
232
+ await expect(provider.signTransaction(tx)).rejects.toThrow("Direct transaction signing not supported for smart wallets. Use sendTransaction instead.");
213
233
  });
214
234
  });
215
235
  // =========================================================
@@ -67,7 +67,7 @@ interface ConfigureLegacyCdpAgentkitWithWalletOptions extends LegacyCdpWalletPro
67
67
  /**
68
68
  * A legacy wallet provider that uses the old Coinbase SDK.
69
69
  *
70
- * @deprecated Use CdpServerWalletProvider or CdpSmartWalletProvider instead
70
+ * @deprecated Use CdpEvmWalletProvider or CdpSmartWalletProvider instead
71
71
  */
72
72
  export declare class LegacyCdpWalletProvider extends EvmWalletProvider {
73
73
  #private;
@@ -23,7 +23,7 @@ const utils_1 = require("../utils");
23
23
  /**
24
24
  * A legacy wallet provider that uses the old Coinbase SDK.
25
25
  *
26
- * @deprecated Use CdpServerWalletProvider or CdpSmartWalletProvider instead
26
+ * @deprecated Use CdpEvmWalletProvider or CdpSmartWalletProvider instead
27
27
  */
28
28
  class LegacyCdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
29
29
  /**
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@coinbase/agentkit",
3
3
  "description": "Coinbase AgentKit core primitives",
4
4
  "repository": "https://github.com/coinbase/agentkit",
5
- "version": "0.0.0-nightly-20250717210412",
5
+ "version": "0.0.0-nightly-20250724210458",
6
6
  "author": "Coinbase Inc.",
7
7
  "license": "Apache-2.0",
8
8
  "main": "dist/index.js",
@@ -24,7 +24,7 @@
24
24
  "dependencies": {
25
25
  "@across-protocol/app-sdk": "^0.2.0",
26
26
  "@alloralabs/allora-sdk": "^0.1.0",
27
- "@coinbase/cdp-sdk": "^1.25.0",
27
+ "@coinbase/cdp-sdk": "^1.26.0",
28
28
  "@coinbase/coinbase-sdk": "^0.20.0",
29
29
  "@jup-ag/api": "^6.0.39",
30
30
  "@privy-io/public-api": "2.18.5",
@@ -1,17 +0,0 @@
1
- import { ActionProvider } from "../actionProvider";
2
- import { CdpEvmWalletProvider } from "../../wallet-providers";
3
- import { Network } from "../../network";
4
- /**
5
- * CdpEvmWalletActionProvider is an action provider for Cdp.
6
- *
7
- * This provider is used for any action that requires a CDP Wallet.
8
- */
9
- declare class CdpEvmWalletActionProvider extends ActionProvider<CdpEvmWalletProvider> {
10
- /**
11
- * Constructor for the CdpEvmWalletActionProvider class.
12
- */
13
- constructor();
14
- supportsNetwork: (network: Network) => boolean;
15
- }
16
- export declare const cdpEvmWalletActionProvider: () => CdpEvmWalletActionProvider;
17
- export {};
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cdpEvmWalletActionProvider = void 0;
4
- const actionProvider_1 = require("../actionProvider");
5
- /**
6
- * CdpEvmWalletActionProvider is an action provider for Cdp.
7
- *
8
- * This provider is used for any action that requires a CDP Wallet.
9
- */
10
- class CdpEvmWalletActionProvider extends actionProvider_1.ActionProvider {
11
- /**
12
- * Constructor for the CdpEvmWalletActionProvider class.
13
- */
14
- constructor() {
15
- super("cdp_evm", []);
16
- this.supportsNetwork = (network) => network.protocolFamily === "evm";
17
- }
18
- }
19
- const cdpEvmWalletActionProvider = () => new CdpEvmWalletActionProvider();
20
- exports.cdpEvmWalletActionProvider = cdpEvmWalletActionProvider;