@coinbase/agentkit 0.0.0-nightly-20250916210427 → 0.0.0-nightly-20250917210422
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/README.md +9 -1
- package/dist/action-providers/pyth/pythActionProvider.d.ts +2 -2
- package/dist/action-providers/pyth/pythActionProvider.js +83 -31
- package/dist/action-providers/pyth/pythActionProvider.test.js +178 -26
- package/dist/action-providers/pyth/schemas.d.ts +6 -0
- package/dist/action-providers/pyth/schemas.js +9 -1
- package/dist/action-providers/x402/schemas.d.ts +7 -0
- package/dist/action-providers/x402/schemas.js +11 -1
- package/dist/action-providers/x402/utils.d.ts +55 -0
- package/dist/action-providers/x402/utils.js +160 -0
- package/dist/action-providers/x402/x402ActionProvider.d.ts +9 -9
- package/dist/action-providers/x402/x402ActionProvider.js +158 -39
- package/dist/action-providers/x402/x402ActionProvider.test.js +116 -10
- package/dist/wallet-providers/cdpEvmWalletProvider.d.ts +7 -0
- package/dist/wallet-providers/cdpEvmWalletProvider.js +9 -0
- package/dist/wallet-providers/cdpEvmWalletProvider.test.js +7 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.d.ts +7 -0
- package/dist/wallet-providers/cdpSmartWalletProvider.js +13 -1
- package/dist/wallet-providers/cdpSmartWalletProvider.test.js +6 -2
- package/dist/wallet-providers/evmWalletProvider.d.ts +9 -2
- package/dist/wallet-providers/evmWalletProvider.js +4 -0
- package/dist/wallet-providers/legacyCdpSmartWalletProvider.d.ts +9 -0
- package/dist/wallet-providers/legacyCdpSmartWalletProvider.js +11 -0
- package/dist/wallet-providers/legacyCdpWalletProvider.d.ts +7 -0
- package/dist/wallet-providers/legacyCdpWalletProvider.js +16 -0
- package/dist/wallet-providers/legacyCdpWalletProvider.test.js +6 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.d.ts +7 -0
- package/dist/wallet-providers/privyEvmDelegatedEmbeddedWalletProvider.js +27 -0
- package/dist/wallet-providers/privyEvmWalletProvider.test.js +11 -0
- package/dist/wallet-providers/viemWalletProvider.d.ts +7 -0
- package/dist/wallet-providers/viemWalletProvider.js +16 -0
- package/dist/wallet-providers/viemWalletProvider.test.js +9 -0
- package/dist/wallet-providers/zeroDevWalletProvider.d.ts +7 -0
- package/dist/wallet-providers/zeroDevWalletProvider.js +12 -0
- package/dist/wallet-providers/zeroDevWalletProvider.test.js +10 -0
- package/package.json +5 -4
|
@@ -39,9 +39,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
39
39
|
const x402ActionProvider_1 = require("./x402ActionProvider");
|
|
40
40
|
const axios_1 = __importDefault(require("axios"));
|
|
41
41
|
const x402axios = __importStar(require("x402-axios"));
|
|
42
|
+
const x402Verify = __importStar(require("x402/verify"));
|
|
43
|
+
// Mock external facilitator dependency
|
|
44
|
+
jest.mock("@coinbase/x402", () => ({
|
|
45
|
+
facilitator: {},
|
|
46
|
+
}));
|
|
42
47
|
// Mock modules
|
|
43
48
|
jest.mock("axios");
|
|
44
49
|
jest.mock("x402-axios");
|
|
50
|
+
jest.mock("x402/verify");
|
|
45
51
|
// Create mock functions
|
|
46
52
|
const mockRequest = jest.fn();
|
|
47
53
|
// Create a complete mock axios instance
|
|
@@ -83,6 +89,7 @@ const mockAxios = {
|
|
|
83
89
|
};
|
|
84
90
|
const mockWithPaymentInterceptor = jest.fn().mockReturnValue(mockAxiosInstance);
|
|
85
91
|
const mockDecodeXPaymentResponse = jest.fn();
|
|
92
|
+
const mockUseFacilitator = jest.fn();
|
|
86
93
|
// Override the mocked modules
|
|
87
94
|
axios_1.default.create = mockAxios.create;
|
|
88
95
|
axios_1.default.request = mockRequest;
|
|
@@ -90,10 +97,12 @@ axios_1.default.isAxiosError = mockAxios.isAxiosError;
|
|
|
90
97
|
// Mock x402-axios functions
|
|
91
98
|
jest.mocked(x402axios.withPaymentInterceptor).mockImplementation(mockWithPaymentInterceptor);
|
|
92
99
|
jest.mocked(x402axios.decodeXPaymentResponse).mockImplementation(mockDecodeXPaymentResponse);
|
|
100
|
+
jest.mocked(x402Verify.useFacilitator).mockImplementation(mockUseFacilitator);
|
|
93
101
|
// Mock wallet provider
|
|
94
|
-
const
|
|
102
|
+
const makeMockWalletProvider = (networkId) => ({
|
|
95
103
|
toSigner: jest.fn().mockReturnValue("mock-signer"),
|
|
96
|
-
}
|
|
104
|
+
getNetwork: jest.fn().mockReturnValue({ protocolFamily: "evm", networkId }),
|
|
105
|
+
});
|
|
97
106
|
// Sample responses based on real examples
|
|
98
107
|
const MOCK_PAYMENT_INFO_RESPONSE = {
|
|
99
108
|
paymentRequired: true,
|
|
@@ -171,7 +180,7 @@ describe("X402ActionProvider", () => {
|
|
|
171
180
|
headers: {},
|
|
172
181
|
config: {},
|
|
173
182
|
});
|
|
174
|
-
const result = await provider.makeHttpRequest(
|
|
183
|
+
const result = await provider.makeHttpRequest(makeMockWalletProvider("base-sepolia"), {
|
|
175
184
|
url: "https://api.example.com/free",
|
|
176
185
|
method: "GET",
|
|
177
186
|
});
|
|
@@ -187,7 +196,7 @@ describe("X402ActionProvider", () => {
|
|
|
187
196
|
headers: {},
|
|
188
197
|
config: {},
|
|
189
198
|
});
|
|
190
|
-
const result = await provider.makeHttpRequest(
|
|
199
|
+
const result = await provider.makeHttpRequest(makeMockWalletProvider("base-sepolia"), {
|
|
191
200
|
url: "https://www.x402.org/protected",
|
|
192
201
|
method: "GET",
|
|
193
202
|
});
|
|
@@ -201,7 +210,7 @@ describe("X402ActionProvider", () => {
|
|
|
201
210
|
error.isAxiosError = true;
|
|
202
211
|
error.request = {};
|
|
203
212
|
mockRequest.mockRejectedValue(error);
|
|
204
|
-
const result = await provider.makeHttpRequest(
|
|
213
|
+
const result = await provider.makeHttpRequest(makeMockWalletProvider("base-sepolia"), {
|
|
205
214
|
url: "https://api.example.com/endpoint",
|
|
206
215
|
method: "GET",
|
|
207
216
|
});
|
|
@@ -210,6 +219,103 @@ describe("X402ActionProvider", () => {
|
|
|
210
219
|
expect(parsedResult.message).toContain("Network error");
|
|
211
220
|
});
|
|
212
221
|
});
|
|
222
|
+
describe("listX402Services", () => {
|
|
223
|
+
it("should list services without filters", async () => {
|
|
224
|
+
const mockList = jest.fn().mockResolvedValue({
|
|
225
|
+
items: [
|
|
226
|
+
{
|
|
227
|
+
resource: "https://example.com/service1",
|
|
228
|
+
metadata: { category: "test" },
|
|
229
|
+
accepts: [
|
|
230
|
+
{
|
|
231
|
+
asset: "0xUSDC",
|
|
232
|
+
maxAmountRequired: "90000",
|
|
233
|
+
network: "base-sepolia",
|
|
234
|
+
scheme: "exact",
|
|
235
|
+
description: "Test service 1",
|
|
236
|
+
outputSchema: { type: "object" },
|
|
237
|
+
extra: { name: "USDC" },
|
|
238
|
+
},
|
|
239
|
+
],
|
|
240
|
+
},
|
|
241
|
+
],
|
|
242
|
+
});
|
|
243
|
+
mockUseFacilitator.mockReturnValue({ list: mockList });
|
|
244
|
+
const result = await provider.discoverX402Services(makeMockWalletProvider("base-sepolia"), {});
|
|
245
|
+
const parsed = JSON.parse(result);
|
|
246
|
+
expect(parsed.success).toBe(true);
|
|
247
|
+
expect(parsed.total).toBe(1);
|
|
248
|
+
expect(parsed.returned).toBe(1);
|
|
249
|
+
expect(parsed.items.length).toBe(1);
|
|
250
|
+
});
|
|
251
|
+
it("should filter services by asset and maxPrice", async () => {
|
|
252
|
+
const mockList = jest.fn().mockResolvedValue({
|
|
253
|
+
items: [
|
|
254
|
+
{
|
|
255
|
+
resource: "https://example.com/service1",
|
|
256
|
+
metadata: { category: "test" },
|
|
257
|
+
accepts: [
|
|
258
|
+
{
|
|
259
|
+
asset: "0x036CbD53842c5426634e7929541eC2318f3dCF7e", // Real USDC address for base-sepolia
|
|
260
|
+
maxAmountRequired: "90000", // 0.09 USDC (should pass 0.1 filter)
|
|
261
|
+
network: "base-sepolia",
|
|
262
|
+
scheme: "exact",
|
|
263
|
+
description: "Test service 1",
|
|
264
|
+
outputSchema: { type: "object" },
|
|
265
|
+
extra: { name: "USDC" },
|
|
266
|
+
},
|
|
267
|
+
],
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
resource: "https://example.com/service2",
|
|
271
|
+
metadata: { category: "test" },
|
|
272
|
+
accepts: [
|
|
273
|
+
{
|
|
274
|
+
asset: "0x036CbD53842c5426634e7929541eC2318f3dCF7e", // Real USDC address for base-sepolia
|
|
275
|
+
maxAmountRequired: "150000", // 0.15 USDC (should fail 0.1 filter)
|
|
276
|
+
network: "base-sepolia",
|
|
277
|
+
scheme: "exact",
|
|
278
|
+
description: "Test service 2",
|
|
279
|
+
outputSchema: { type: "object" },
|
|
280
|
+
extra: { name: "USDC" },
|
|
281
|
+
},
|
|
282
|
+
],
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
resource: "https://example.com/service3",
|
|
286
|
+
metadata: { category: "test" },
|
|
287
|
+
accepts: [
|
|
288
|
+
{
|
|
289
|
+
asset: "0x036CbD53842c5426634e7929541eC2318f3dCF7e", // Real USDC address for base-sepolia
|
|
290
|
+
maxAmountRequired: "50000", // 0.05 USDC (should pass 0.1 filter)
|
|
291
|
+
network: "base-sepolia",
|
|
292
|
+
scheme: "exact",
|
|
293
|
+
description: "Test service 3",
|
|
294
|
+
outputSchema: { type: "object" },
|
|
295
|
+
extra: { name: "USDC" },
|
|
296
|
+
},
|
|
297
|
+
],
|
|
298
|
+
},
|
|
299
|
+
],
|
|
300
|
+
});
|
|
301
|
+
mockUseFacilitator.mockReturnValue({ list: mockList });
|
|
302
|
+
const result = await provider.discoverX402Services(makeMockWalletProvider("base-sepolia"), {
|
|
303
|
+
maxUsdcPrice: 0.1,
|
|
304
|
+
});
|
|
305
|
+
const parsed = JSON.parse(result);
|
|
306
|
+
expect(parsed.success).toBe(true);
|
|
307
|
+
expect(parsed.returned).toBe(2);
|
|
308
|
+
expect(parsed.items.map(item => item.resource)).toEqual(expect.arrayContaining(["https://example.com/service1", "https://example.com/service3"]));
|
|
309
|
+
});
|
|
310
|
+
it("should handle errors from facilitator", async () => {
|
|
311
|
+
const mockList = jest.fn().mockRejectedValue(new Error("boom"));
|
|
312
|
+
mockUseFacilitator.mockReturnValue({ list: mockList });
|
|
313
|
+
const result = await provider.discoverX402Services(makeMockWalletProvider("base-sepolia"), {});
|
|
314
|
+
const parsed = JSON.parse(result);
|
|
315
|
+
expect(parsed.error).toBe(true);
|
|
316
|
+
expect(parsed.message).toContain("Failed to list x402 services");
|
|
317
|
+
});
|
|
318
|
+
});
|
|
213
319
|
describe("retryHttpRequestWithX402", () => {
|
|
214
320
|
it("should successfully retry with payment", async () => {
|
|
215
321
|
mockDecodeXPaymentResponse.mockReturnValue(MOCK_PAYMENT_RESPONSE);
|
|
@@ -222,7 +328,7 @@ describe("X402ActionProvider", () => {
|
|
|
222
328
|
},
|
|
223
329
|
config: {},
|
|
224
330
|
});
|
|
225
|
-
const result = await provider.retryWithX402(
|
|
331
|
+
const result = await provider.retryWithX402(makeMockWalletProvider("base-sepolia"), {
|
|
226
332
|
url: "https://www.x402.org/protected",
|
|
227
333
|
method: "GET",
|
|
228
334
|
selectedPaymentOption: {
|
|
@@ -247,7 +353,7 @@ describe("X402ActionProvider", () => {
|
|
|
247
353
|
error.isAxiosError = true;
|
|
248
354
|
error.request = {};
|
|
249
355
|
mockRequest.mockRejectedValue(error);
|
|
250
|
-
const result = await provider.retryWithX402(
|
|
356
|
+
const result = await provider.retryWithX402(makeMockWalletProvider("base-sepolia"), {
|
|
251
357
|
url: "https://www.x402.org/protected",
|
|
252
358
|
method: "GET",
|
|
253
359
|
selectedPaymentOption: {
|
|
@@ -274,7 +380,7 @@ describe("X402ActionProvider", () => {
|
|
|
274
380
|
},
|
|
275
381
|
config: {},
|
|
276
382
|
});
|
|
277
|
-
const result = await provider.makeHttpRequestWithX402(
|
|
383
|
+
const result = await provider.makeHttpRequestWithX402(makeMockWalletProvider("base-sepolia"), {
|
|
278
384
|
url: "https://www.x402.org/protected",
|
|
279
385
|
method: "GET",
|
|
280
386
|
});
|
|
@@ -296,7 +402,7 @@ describe("X402ActionProvider", () => {
|
|
|
296
402
|
headers: {},
|
|
297
403
|
config: {},
|
|
298
404
|
});
|
|
299
|
-
const result = await provider.makeHttpRequestWithX402(
|
|
405
|
+
const result = await provider.makeHttpRequestWithX402(makeMockWalletProvider("base-sepolia"), {
|
|
300
406
|
url: "https://api.example.com/free",
|
|
301
407
|
method: "GET",
|
|
302
408
|
});
|
|
@@ -310,7 +416,7 @@ describe("X402ActionProvider", () => {
|
|
|
310
416
|
error.isAxiosError = true;
|
|
311
417
|
error.request = {};
|
|
312
418
|
mockRequest.mockRejectedValue(error);
|
|
313
|
-
const result = await provider.makeHttpRequestWithX402(
|
|
419
|
+
const result = await provider.makeHttpRequestWithX402(makeMockWalletProvider("base-sepolia"), {
|
|
314
420
|
url: "https://api.example.com/endpoint",
|
|
315
421
|
method: "GET",
|
|
316
422
|
});
|
|
@@ -35,6 +35,13 @@ export declare class CdpEvmWalletProvider extends EvmWalletProvider implements W
|
|
|
35
35
|
name: string | undefined;
|
|
36
36
|
address: `0x${string}`;
|
|
37
37
|
}>;
|
|
38
|
+
/**
|
|
39
|
+
* Signs a raw hash.
|
|
40
|
+
*
|
|
41
|
+
* @param hash - The hash to sign.
|
|
42
|
+
* @returns The signed hash.
|
|
43
|
+
*/
|
|
44
|
+
sign(hash: `0x${string}`): Promise<Hex>;
|
|
38
45
|
/**
|
|
39
46
|
* Signs a message.
|
|
40
47
|
*
|
|
@@ -89,6 +89,15 @@ class CdpEvmWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
89
89
|
address: __classPrivateFieldGet(this, _CdpEvmWalletProvider_serverAccount, "f").address,
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Signs a raw hash.
|
|
94
|
+
*
|
|
95
|
+
* @param hash - The hash to sign.
|
|
96
|
+
* @returns The signed hash.
|
|
97
|
+
*/
|
|
98
|
+
async sign(hash) {
|
|
99
|
+
return __classPrivateFieldGet(this, _CdpEvmWalletProvider_serverAccount, "f").sign({ hash });
|
|
100
|
+
}
|
|
92
101
|
/**
|
|
93
102
|
* Signs a message.
|
|
94
103
|
*
|
|
@@ -114,6 +114,7 @@ describe("CdpEvmWalletProvider", () => {
|
|
|
114
114
|
});
|
|
115
115
|
mockServerAccount = {
|
|
116
116
|
address: MOCK_ADDRESS,
|
|
117
|
+
sign: jest.fn().mockResolvedValue(MOCK_SIGNATURE),
|
|
117
118
|
signMessage: jest.fn().mockResolvedValue(MOCK_SIGNATURE),
|
|
118
119
|
signTypedData: jest.fn().mockResolvedValue(MOCK_SIGNATURE),
|
|
119
120
|
};
|
|
@@ -214,6 +215,12 @@ describe("CdpEvmWalletProvider", () => {
|
|
|
214
215
|
// signing operation tests
|
|
215
216
|
// =========================================================
|
|
216
217
|
describe("signing operations", () => {
|
|
218
|
+
it("should sign a hash", async () => {
|
|
219
|
+
const testHash = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
220
|
+
const signature = await provider.sign(testHash);
|
|
221
|
+
expect(mockServerAccount.sign).toHaveBeenCalledWith({ hash: testHash });
|
|
222
|
+
expect(signature).toBe(MOCK_SIGNATURE);
|
|
223
|
+
});
|
|
217
224
|
it("should sign messages", async () => {
|
|
218
225
|
const signature = await provider.signMessage("Hello, world!");
|
|
219
226
|
expect(mockServerAccount.signMessage).toHaveBeenCalledWith({ message: "Hello, world!" });
|
|
@@ -38,6 +38,13 @@ export declare class CdpSmartWalletProvider extends EvmWalletProvider implements
|
|
|
38
38
|
address: Address;
|
|
39
39
|
ownerAddress: Address;
|
|
40
40
|
}>;
|
|
41
|
+
/**
|
|
42
|
+
* Signs a raw hash using the owner account.
|
|
43
|
+
*
|
|
44
|
+
* @param _hash - The hash to sign.
|
|
45
|
+
* @returns The signed hash.
|
|
46
|
+
*/
|
|
47
|
+
sign(_hash: Hex): Promise<Hex>;
|
|
41
48
|
/**
|
|
42
49
|
* Signs a message using the owner account.
|
|
43
50
|
*
|
|
@@ -116,6 +116,18 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
116
116
|
ownerAddress: this.ownerAccount.address,
|
|
117
117
|
};
|
|
118
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Signs a raw hash using the owner account.
|
|
121
|
+
*
|
|
122
|
+
* @param _hash - The hash to sign.
|
|
123
|
+
* @returns The signed hash.
|
|
124
|
+
*/
|
|
125
|
+
async sign(_hash) {
|
|
126
|
+
if (!this.ownerAccount.sign) {
|
|
127
|
+
throw new Error("Owner account does not support raw hash signing");
|
|
128
|
+
}
|
|
129
|
+
return this.ownerAccount.sign({ hash: _hash });
|
|
130
|
+
}
|
|
119
131
|
/**
|
|
120
132
|
* Signs a message using the owner account.
|
|
121
133
|
*
|
|
@@ -123,7 +135,7 @@ class CdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
123
135
|
* @returns The signed message.
|
|
124
136
|
*/
|
|
125
137
|
async signMessage(_message) {
|
|
126
|
-
|
|
138
|
+
return this.ownerAccount.signMessage({ message: _message });
|
|
127
139
|
}
|
|
128
140
|
/**
|
|
129
141
|
* Signs a typed data object using the owner account.
|
|
@@ -109,6 +109,7 @@ describe("CdpSmartWalletProvider", () => {
|
|
|
109
109
|
});
|
|
110
110
|
mockOwnerAccount = {
|
|
111
111
|
address: MOCK_ADDRESS,
|
|
112
|
+
sign: jest.fn().mockResolvedValue(MOCK_SIGNATURE),
|
|
112
113
|
signMessage: jest.fn().mockResolvedValue(MOCK_SIGNATURE),
|
|
113
114
|
signTypedData: jest.fn().mockResolvedValue(MOCK_SIGNATURE),
|
|
114
115
|
};
|
|
@@ -188,8 +189,11 @@ describe("CdpSmartWalletProvider", () => {
|
|
|
188
189
|
// signing operation tests
|
|
189
190
|
// =========================================================
|
|
190
191
|
describe("signing operations", () => {
|
|
191
|
-
it("should
|
|
192
|
-
|
|
192
|
+
it("should sign a hash using owner account", async () => {
|
|
193
|
+
const testHash = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
194
|
+
const signature = await provider.sign(testHash);
|
|
195
|
+
expect(mockOwnerAccount.sign).toHaveBeenCalledWith({ hash: testHash });
|
|
196
|
+
expect(signature).toBe(MOCK_SIGNATURE);
|
|
193
197
|
});
|
|
194
198
|
it("should sign typed data using smart account", async () => {
|
|
195
199
|
const typedData = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WalletProvider } from "./walletProvider";
|
|
2
|
-
import { TransactionRequest, ReadContractParameters, ReadContractReturnType, ContractFunctionName, Abi, ContractFunctionArgs,
|
|
2
|
+
import { TransactionRequest, ReadContractParameters, ReadContractReturnType, ContractFunctionName, Abi, ContractFunctionArgs, PublicClient, LocalAccount } from "viem";
|
|
3
3
|
/**
|
|
4
4
|
* EvmWalletProvider is the abstract base class for all EVM wallet providers.
|
|
5
5
|
*
|
|
@@ -11,7 +11,14 @@ export declare abstract class EvmWalletProvider extends WalletProvider {
|
|
|
11
11
|
*
|
|
12
12
|
* @returns The signer.
|
|
13
13
|
*/
|
|
14
|
-
toSigner():
|
|
14
|
+
toSigner(): LocalAccount;
|
|
15
|
+
/**
|
|
16
|
+
* Sign a raw hash.
|
|
17
|
+
*
|
|
18
|
+
* @param hash - The hash to sign.
|
|
19
|
+
* @returns The signed hash.
|
|
20
|
+
*/
|
|
21
|
+
abstract sign(hash: `0x${string}`): Promise<`0x${string}`>;
|
|
15
22
|
/**
|
|
16
23
|
* Sign a message.
|
|
17
24
|
*
|
|
@@ -18,7 +18,11 @@ class EvmWalletProvider extends walletProvider_1.WalletProvider {
|
|
|
18
18
|
*/
|
|
19
19
|
toSigner() {
|
|
20
20
|
return (0, accounts_1.toAccount)({
|
|
21
|
+
type: "local",
|
|
21
22
|
address: this.getAddress(),
|
|
23
|
+
sign: async ({ hash }) => {
|
|
24
|
+
return this.sign(hash);
|
|
25
|
+
},
|
|
22
26
|
signMessage: async ({ message }) => {
|
|
23
27
|
return this.signMessage(message);
|
|
24
28
|
},
|
|
@@ -47,6 +47,15 @@ export declare class LegacyCdpSmartWalletProvider extends EvmWalletProvider {
|
|
|
47
47
|
* ```
|
|
48
48
|
*/
|
|
49
49
|
static configureWithWallet(config: ConfigureLegacyCdpSmartWalletOptions): Promise<LegacyCdpSmartWalletProvider>;
|
|
50
|
+
/**
|
|
51
|
+
* Stub for hash signing
|
|
52
|
+
*
|
|
53
|
+
* @throws as signing hashes is not implemented for SmartWallets.
|
|
54
|
+
*
|
|
55
|
+
* @param _ - The hash to sign.
|
|
56
|
+
* @returns The signed hash.
|
|
57
|
+
*/
|
|
58
|
+
sign(_: `0x${string}`): Promise<Hex>;
|
|
50
59
|
/**
|
|
51
60
|
* Stub for message signing
|
|
52
61
|
*
|
|
@@ -111,6 +111,17 @@ class LegacyCdpSmartWalletProvider extends evmWalletProvider_1.EvmWalletProvider
|
|
|
111
111
|
});
|
|
112
112
|
return legacyCdpSmartWalletProvider;
|
|
113
113
|
}
|
|
114
|
+
/**
|
|
115
|
+
* Stub for hash signing
|
|
116
|
+
*
|
|
117
|
+
* @throws as signing hashes is not implemented for SmartWallets.
|
|
118
|
+
*
|
|
119
|
+
* @param _ - The hash to sign.
|
|
120
|
+
* @returns The signed hash.
|
|
121
|
+
*/
|
|
122
|
+
async sign(_) {
|
|
123
|
+
throw new Error("Not implemented");
|
|
124
|
+
}
|
|
114
125
|
/**
|
|
115
126
|
* Stub for message signing
|
|
116
127
|
*
|
|
@@ -89,6 +89,13 @@ export declare class LegacyCdpWalletProvider extends EvmWalletProvider {
|
|
|
89
89
|
* @throws Error if required environment variables are missing or wallet initialization fails
|
|
90
90
|
*/
|
|
91
91
|
static configureWithWallet(config?: ConfigureLegacyCdpAgentkitWithWalletOptions): Promise<LegacyCdpWalletProvider>;
|
|
92
|
+
/**
|
|
93
|
+
* Signs a raw hash.
|
|
94
|
+
*
|
|
95
|
+
* @param hash - The hash to sign.
|
|
96
|
+
* @returns The signed hash.
|
|
97
|
+
*/
|
|
98
|
+
sign(hash: `0x${string}`): Promise<`0x${string}`>;
|
|
92
99
|
/**
|
|
93
100
|
* Signs a message.
|
|
94
101
|
*
|
|
@@ -106,6 +106,22 @@ class LegacyCdpWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
106
106
|
});
|
|
107
107
|
return cdpWalletProvider;
|
|
108
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Signs a raw hash.
|
|
111
|
+
*
|
|
112
|
+
* @param hash - The hash to sign.
|
|
113
|
+
* @returns The signed hash.
|
|
114
|
+
*/
|
|
115
|
+
async sign(hash) {
|
|
116
|
+
if (!__classPrivateFieldGet(this, _LegacyCdpWalletProvider_cdpWallet, "f")) {
|
|
117
|
+
throw new Error("Wallet not initialized");
|
|
118
|
+
}
|
|
119
|
+
const payload = await __classPrivateFieldGet(this, _LegacyCdpWalletProvider_cdpWallet, "f").createPayloadSignature(hash);
|
|
120
|
+
if (payload.getStatus() === "pending" && payload?.wait) {
|
|
121
|
+
await payload.wait(); // needed for Server-Signers
|
|
122
|
+
}
|
|
123
|
+
return payload.getSignature();
|
|
124
|
+
}
|
|
109
125
|
/**
|
|
110
126
|
* Signs a message.
|
|
111
127
|
*
|
|
@@ -268,6 +268,12 @@ describe("LegacyCdpWalletProvider", () => {
|
|
|
268
268
|
// signing operation tests
|
|
269
269
|
// =========================================================
|
|
270
270
|
describe("signing operations", () => {
|
|
271
|
+
it("should sign a hash", async () => {
|
|
272
|
+
const testHash = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
273
|
+
const signature = await provider.sign(testHash);
|
|
274
|
+
expect(mockWalletObj.createPayloadSignature).toHaveBeenCalledWith(testHash);
|
|
275
|
+
expect(signature).toBe(MOCK_SIGNATURE);
|
|
276
|
+
});
|
|
271
277
|
it("should sign messages", async () => {
|
|
272
278
|
const signature = await provider.signMessage("Hello, world!");
|
|
273
279
|
expect(mockWalletObj.createPayloadSignature).toHaveBeenCalled();
|
|
@@ -78,6 +78,13 @@ export declare class PrivyEvmDelegatedEmbeddedWalletProvider extends WalletProvi
|
|
|
78
78
|
* @returns The balance of the wallet in wei
|
|
79
79
|
*/
|
|
80
80
|
getBalance(): Promise<bigint>;
|
|
81
|
+
/**
|
|
82
|
+
* Signs a raw hash.
|
|
83
|
+
*
|
|
84
|
+
* @param hash - The hash to sign.
|
|
85
|
+
* @returns The signed hash.
|
|
86
|
+
*/
|
|
87
|
+
sign(hash: `0x${string}`): Promise<Hex>;
|
|
81
88
|
/**
|
|
82
89
|
* Signs a message.
|
|
83
90
|
*
|
|
@@ -170,6 +170,33 @@ class PrivyEvmDelegatedEmbeddedWalletProvider extends walletProvider_1.WalletPro
|
|
|
170
170
|
throw new Error("Error getting balance");
|
|
171
171
|
}
|
|
172
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Signs a raw hash.
|
|
175
|
+
*
|
|
176
|
+
* @param hash - The hash to sign.
|
|
177
|
+
* @returns The signed hash.
|
|
178
|
+
*/
|
|
179
|
+
async sign(hash) {
|
|
180
|
+
const body = {
|
|
181
|
+
address: __classPrivateFieldGet(this, _PrivyEvmDelegatedEmbeddedWalletProvider_address, "f"),
|
|
182
|
+
chain_type: "ethereum",
|
|
183
|
+
method: "personal_sign",
|
|
184
|
+
params: {
|
|
185
|
+
message: hash,
|
|
186
|
+
encoding: "hex",
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
try {
|
|
190
|
+
const response = await this.executePrivyRequest(body);
|
|
191
|
+
return response.data?.signature;
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
if (error instanceof Error) {
|
|
195
|
+
throw new Error(`Hash signing failed: ${error.message}`);
|
|
196
|
+
}
|
|
197
|
+
throw new Error("Hash signing failed");
|
|
198
|
+
}
|
|
199
|
+
}
|
|
173
200
|
/**
|
|
174
201
|
* Signs a message.
|
|
175
202
|
*
|
|
@@ -14,6 +14,10 @@ const MOCK_TRANSACTION_HASH = "0xef01";
|
|
|
14
14
|
const MOCK_SIGNATURE_HASH_1 = "0x1234";
|
|
15
15
|
const MOCK_SIGNATURE_HASH_2 = "0x5678";
|
|
16
16
|
const MOCK_SIGNATURE_HASH_3 = "0xabcd";
|
|
17
|
+
const MOCK_HASH_SIGNATURE = "0xhash";
|
|
18
|
+
jest.mock("../analytics", () => ({
|
|
19
|
+
sendAnalyticsEvent: jest.fn().mockImplementation(() => Promise.resolve()),
|
|
20
|
+
}));
|
|
17
21
|
jest.mock("@privy-io/server-auth", () => ({
|
|
18
22
|
PrivyClient: jest.fn().mockImplementation(() => ({
|
|
19
23
|
appId: "mock-app-id",
|
|
@@ -65,6 +69,7 @@ jest.mock("@privy-io/server-auth/viem", () => ({
|
|
|
65
69
|
createViemAccount: jest.fn().mockResolvedValue({
|
|
66
70
|
address: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
|
|
67
71
|
type: "local",
|
|
72
|
+
sign: jest.fn().mockResolvedValue("0xhash"),
|
|
68
73
|
signMessage: jest.fn().mockResolvedValue("0x1234"),
|
|
69
74
|
signTypedData: jest.fn().mockResolvedValue("0x5678"),
|
|
70
75
|
signTransaction: jest.fn().mockResolvedValue("0xabcd"),
|
|
@@ -120,6 +125,7 @@ jest.mock("viem", () => {
|
|
|
120
125
|
createWalletClient: jest.fn().mockReturnValue({
|
|
121
126
|
account: {
|
|
122
127
|
address: "0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
|
|
128
|
+
sign: jest.fn().mockResolvedValue("0xhash"),
|
|
123
129
|
},
|
|
124
130
|
chain: {
|
|
125
131
|
id: 1,
|
|
@@ -214,6 +220,11 @@ describe("PrivyEvmWalletProvider", () => {
|
|
|
214
220
|
it("should get the provider name", () => {
|
|
215
221
|
expect(provider.getName()).toBe("privy_evm_wallet_provider");
|
|
216
222
|
});
|
|
223
|
+
it("should sign a hash", async () => {
|
|
224
|
+
const testHash = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
225
|
+
const result = await provider.sign(testHash);
|
|
226
|
+
expect(result).toBe(MOCK_HASH_SIGNATURE);
|
|
227
|
+
});
|
|
217
228
|
it("should sign a message", async () => {
|
|
218
229
|
const result = await provider.signMessage("Hello, world!");
|
|
219
230
|
expect(result).toBe(MOCK_SIGNATURE_HASH_1);
|
|
@@ -30,6 +30,13 @@ export declare class ViemWalletProvider extends EvmWalletProvider {
|
|
|
30
30
|
* @param gasConfig - Configuration for gas multipliers.
|
|
31
31
|
*/
|
|
32
32
|
constructor(walletClient: ViemWalletClient, gasConfig?: ViemWalletProviderGasConfig);
|
|
33
|
+
/**
|
|
34
|
+
* Signs a raw hash.
|
|
35
|
+
*
|
|
36
|
+
* @param hash - The hash to sign.
|
|
37
|
+
* @returns The signed hash.
|
|
38
|
+
*/
|
|
39
|
+
sign(hash: `0x${string}`): Promise<`0x${string}`>;
|
|
33
40
|
/**
|
|
34
41
|
* Signs a message.
|
|
35
42
|
*
|
|
@@ -44,6 +44,22 @@ class ViemWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
44
44
|
__classPrivateFieldSet(this, _ViemWalletProvider_gasLimitMultiplier, Math.max(gasConfig?.gasLimitMultiplier ?? 1.2, 1), "f");
|
|
45
45
|
__classPrivateFieldSet(this, _ViemWalletProvider_feePerGasMultiplier, Math.max(gasConfig?.feePerGasMultiplier ?? 1, 1), "f");
|
|
46
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Signs a raw hash.
|
|
49
|
+
*
|
|
50
|
+
* @param hash - The hash to sign.
|
|
51
|
+
* @returns The signed hash.
|
|
52
|
+
*/
|
|
53
|
+
async sign(hash) {
|
|
54
|
+
const account = __classPrivateFieldGet(this, _ViemWalletProvider_walletClient, "f").account;
|
|
55
|
+
if (!account) {
|
|
56
|
+
throw new Error("Account not found");
|
|
57
|
+
}
|
|
58
|
+
if (!account.sign) {
|
|
59
|
+
throw new Error("Account does not support raw hash signing");
|
|
60
|
+
}
|
|
61
|
+
return account.sign({ hash });
|
|
62
|
+
}
|
|
47
63
|
/**
|
|
48
64
|
* Signs a message.
|
|
49
65
|
*
|
|
@@ -119,6 +119,7 @@ describe("ViemWalletProvider", () => {
|
|
|
119
119
|
jest.clearAllMocks();
|
|
120
120
|
const mockAccount = {
|
|
121
121
|
address: MOCK_ADDRESS,
|
|
122
|
+
sign: jest.fn().mockResolvedValue(MOCK_SIGNATURE),
|
|
122
123
|
};
|
|
123
124
|
mockPublicClient = {
|
|
124
125
|
chain: MOCK_CHAIN,
|
|
@@ -209,6 +210,14 @@ describe("ViemWalletProvider", () => {
|
|
|
209
210
|
});
|
|
210
211
|
});
|
|
211
212
|
describe("signing operations", () => {
|
|
213
|
+
it("should sign a hash", async () => {
|
|
214
|
+
const testHash = "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef";
|
|
215
|
+
const signature = await provider.sign(testHash);
|
|
216
|
+
expect(mockWalletClient.account?.sign).toHaveBeenCalledWith({
|
|
217
|
+
hash: testHash,
|
|
218
|
+
});
|
|
219
|
+
expect(signature).toBe(MOCK_SIGNATURE);
|
|
220
|
+
});
|
|
212
221
|
it("should sign a message", async () => {
|
|
213
222
|
const signature = await provider.signMessage(MOCK_MESSAGE);
|
|
214
223
|
expect(mockWalletClient.signMessage).toHaveBeenCalledWith({
|
|
@@ -53,6 +53,13 @@ export declare class ZeroDevWalletProvider extends EvmWalletProvider {
|
|
|
53
53
|
* @returns A Promise that resolves to a new ZeroDevWalletProvider instance.
|
|
54
54
|
*/
|
|
55
55
|
static configureWithWallet(config: ZeroDevWalletProviderConfig): Promise<ZeroDevWalletProvider>;
|
|
56
|
+
/**
|
|
57
|
+
* Signs a raw hash using the Kernel account.
|
|
58
|
+
*
|
|
59
|
+
* @param hash - The hash to sign.
|
|
60
|
+
* @returns The signed hash.
|
|
61
|
+
*/
|
|
62
|
+
sign(hash: `0x${string}`): Promise<Hex>;
|
|
56
63
|
/**
|
|
57
64
|
* Signs a message using the Kernel account.
|
|
58
65
|
*
|
|
@@ -105,6 +105,18 @@ class ZeroDevWalletProvider extends evmWalletProvider_1.EvmWalletProvider {
|
|
|
105
105
|
});
|
|
106
106
|
return new ZeroDevWalletProvider(config, kernelAccount, intentClient);
|
|
107
107
|
}
|
|
108
|
+
/**
|
|
109
|
+
* Signs a raw hash using the Kernel account.
|
|
110
|
+
*
|
|
111
|
+
* @param hash - The hash to sign.
|
|
112
|
+
* @returns The signed hash.
|
|
113
|
+
*/
|
|
114
|
+
async sign(hash) {
|
|
115
|
+
if (!__classPrivateFieldGet(this, _ZeroDevWalletProvider_kernelAccount, "f").sign) {
|
|
116
|
+
throw new Error("Kernel account does not support raw hash signing");
|
|
117
|
+
}
|
|
118
|
+
return __classPrivateFieldGet(this, _ZeroDevWalletProvider_kernelAccount, "f").sign({ hash });
|
|
119
|
+
}
|
|
108
120
|
/**
|
|
109
121
|
* Signs a message using the Kernel account.
|
|
110
122
|
*
|