@devries-cameron20 / composio-1 / commits / 233d99d65
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

feat(ts): [breaking] remove node:crypto usage from triggers, composio.triggers.verifyWebhook is now async

jkomyno committed Jan 22, 2026 at 18:47 UTC 233d99d65f01c2e51e029f88520fe2771100d4bc
6 files changed +171 -135
ts/docs/advanced/webhook-verification.md
+7 -7
@@ -102,9 +102,9 @@ const app = express();
102 const composio = new Composio({ apiKey: process.env.COMPOSIO_API_KEY });
103
104 // Important: Use express.raw() to get the raw body as a string
105 -app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
105 +app.post('/webhook', express.raw({ type: 'application/json' }), async (req, res) => {
106 try {
107 - const result = composio.triggers.verifyWebhook({
107 + const result = await composio.triggers.verifyWebhook({
108 payload: req.body.toString(),
109 signature: req.headers['webhook-signature'] as string,
110 id: req.headers['webhook-id'] as string,
@@ -145,7 +145,7 @@ export async function POST(request: NextRequest) {
145 try {
146 const payload = await request.text();
147
148 - const result = composio.triggers.verifyWebhook({
148 + const result = await composio.triggers.verifyWebhook({
149 payload,
150 signature: request.headers.get('webhook-signature')!,
151 id: request.headers.get('webhook-id')!,
@@ -184,7 +184,7 @@ fastify.addContentTypeParser(
184
185 fastify.post('/webhook', async (request, reply) => {
186 try {
187 - const result = composio.triggers.verifyWebhook({
187 + const result = await composio.triggers.verifyWebhook({
188 payload: request.body as string,
189 signature: request.headers['webhook-signature'] as string,
190 id: request.headers['webhook-id'] as string,
@@ -227,19 +227,19 @@ By default, webhooks older than 5 minutes are rejected to prevent replay attacks
227
228 ```typescript
229 // Strict: 1 minute tolerance
230 -const result = composio.triggers.verifyWebhook({
230 +const result = await composio.triggers.verifyWebhook({
231 ...params,
232 tolerance: 60,
233 });
234
235 // Lenient: 10 minute tolerance
236 -const result = composio.triggers.verifyWebhook({
236 +const result = await composio.triggers.verifyWebhook({
237 ...params,
238 tolerance: 600,
239 });
240
241 // Disable timestamp validation (not recommended for production)
242 -const result = composio.triggers.verifyWebhook({
242 +const result = await composio.triggers.verifyWebhook({
243 ...params,
244 tolerance: 0,
245 });
ts/examples/triggers/src/webhook-server.ts
+1 -1
@@ -61,7 +61,7 @@ const server = Bun.serve({
61 console.log(` webhook-signature: ${webhookSignature.substring(0, 30)}...`);
62
63 // Verify the webhook
64 - const result = composio.triggers.verifyWebhook({
64 + const result = await composio.triggers.verifyWebhook({
65 id: webhookId,
66 timestamp: webhookTimestamp,
67 signature: webhookSignature,
ts/packages/core/src/models/Triggers.ts
+10 -19
@@ -1,4 +1,3 @@
1 -import * as crypto from 'node:crypto';
1 import ComposioClient, { APIError } from '@composio/client';
2 import { TriggersTypeRetrieveEnumResponse } from '@composio/client/resources/index';
3 import {
@@ -45,9 +44,10 @@ import {
44 transformTriggerTypeListResponse,
45 transformTriggerTypeRetrieveResponse,
46 } from '../utils/transformers/triggers';
48 -import { ToolkitVersion, ToolkitVersionParam } from '../types/tool.types';
47 +import { ToolkitVersionParam } from '../types/tool.types';
48 import { ComposioConfig } from '../composio';
49 import { BaseComposioProvider } from '../provider/BaseProvider';
50 +import { hmacSha256Base64, timingSafeEqual } from '../utils/crypto';
51 /**
52 * Trigger (Instance) class
53 * /api/v3/trigger_instances
@@ -493,9 +493,9 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
493 * @example
494 * ```ts
495 * // In an Express.js webhook handler
496 - * app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
496 + * app.post('/webhook', express.raw({ type: 'application/json' }), async (req, res) => {
497 * try {
498 - * const result = composio.triggers.verifyWebhook({
498 + * const result = await composio.triggers.verifyWebhook({
499 * payload: req.body.toString(),
500 * signature: req.headers['webhook-signature'] as string,
501 * webhookId: req.headers['webhook-id'] as string,
@@ -514,7 +514,7 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
514 * });
515 * ```
516 */
517 - verifyWebhook(params: VerifyWebhookParams): VerifyWebhookResult {
517 + async verifyWebhook(params: VerifyWebhookParams): Promise<VerifyWebhookResult> {
518 // Validate input parameters
519 const parsedParams = VerifyWebhookParamsSchema.safeParse(params);
520 if (!parsedParams.success) {
@@ -538,7 +538,7 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
538 }
539
540 // Verify signature using the correct format: msgId.timestamp.payload
541 - this.verifyWebhookSignature(webhookId, webhookTimestamp, payload, signature, secret);
541 + await this.verifyWebhookSignature(webhookId, webhookTimestamp, payload, signature, secret);
542
543 // Parse the payload and detect version
544 const { version, rawPayload, normalizedPayload } = this.parseWebhookPayload(payload);
@@ -732,13 +732,13 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
732 * The signing input is: `${msgId}.${timestamp}.${payload}`
733 * @private
734 */
735 - private verifyWebhookSignature(
735 + private async verifyWebhookSignature(
736 webhookId: string,
737 webhookTimestamp: string,
738 payload: string,
739 signature: string,
740 secret: string
741 - ): void {
741 + ): Promise<void> {
742 if (payload.length === 0) {
743 throw new ComposioWebhookSignatureVerificationError('No webhook payload was provided.');
744 }
@@ -787,21 +787,12 @@ export class Triggers<TProvider extends BaseComposioProvider<unknown, unknown, u
787
788 // Compute expected signature: HMAC-SHA256(msgId.timestamp.payload, secret) -> base64
789 const toSign = `${webhookId}.${webhookTimestamp}.${payload}`;
790 - const expectedSignature = crypto
791 - .createHmac('sha256', secret)
792 - .update(toSign, 'utf8')
793 - .digest('base64');
790 + const expectedSignature = await hmacSha256Base64(secret, toSign);
791
792 // Check if any of the provided signatures match
793 let isValid = false;
794 for (const providedSignature of v1Signatures) {
798 - const signatureBuffer = Buffer.from(providedSignature);
799 - const expectedBuffer = Buffer.from(expectedSignature);
800 -
801 - if (
802 - signatureBuffer.length === expectedBuffer.length &&
803 - crypto.timingSafeEqual(signatureBuffer, expectedBuffer)
804 - ) {
795 + if (timingSafeEqual(providedSignature, expectedSignature)) {
796 isValid = true;
797 break;
798 }
ts/packages/core/src/utils/buffer.ts new
+11
@@ -0,0 +1,11 @@
1 +/**
2 + * Convert ArrayBuffer to base64.
3 + */
4 +export function arrayBufferToBase64(buffer: ArrayBuffer) {
5 + const bytes = new Uint8Array(buffer);
6 + let binary = '';
7 + for (let i = 0; i < bytes.length; i++) {
8 + binary += String.fromCharCode(bytes[i]);
9 + }
10 + return btoa(binary);
11 +}
ts/packages/core/src/utils/crypto.ts new
+34
@@ -0,0 +1,34 @@
1 +import { arrayBufferToBase64 } from './buffer';
2 +
3 +/**
4 + * Computes HMAC-SHA256 using Web Crypto API
5 + */
6 +export async function hmacSha256Base64(secret: string, message: string): Promise<string> {
7 + const encoder = new TextEncoder();
8 + const keyData = encoder.encode(secret);
9 + const key = await globalThis.crypto.subtle.importKey(
10 + 'raw',
11 + keyData,
12 + { name: 'HMAC', hash: 'SHA-256' },
13 + false,
14 + ['sign']
15 + );
16 + const signatureData = encoder.encode(message);
17 + const signatureBuffer = await globalThis.crypto.subtle.sign('HMAC', key, signatureData);
18 +
19 + return arrayBufferToBase64(signatureBuffer);
20 +}
21 +
22 +/**
23 + * Constant-time comparison of two strings to prevent timing attacks
24 + */
25 +export function timingSafeEqual(a: string, b: string): boolean {
26 + if (a.length !== b.length) {
27 + return false;
28 + }
29 + let result = 0;
30 + for (let i = 0; i < a.length; i++) {
31 + result |= a.charCodeAt(i) ^ b.charCodeAt(i);
32 + }
33 + return result === 0;
34 +}
ts/packages/core/test/models/verifyWebhook.test.ts
+108 -108
@@ -118,12 +118,12 @@ describe('Triggers.verifyWebhook', () => {
118 });
119
120 describe('successful verification with V3 payload', () => {
121 - it('should verify a valid V3 webhook payload and signature', () => {
121 + it('should verify a valid V3 webhook payload and signature', async () => {
122 const v3Payload = createMockV3Payload();
123 const payloadStr = JSON.stringify(v3Payload);
124 const signature = createSignature(testWebhookId, testTimestamp, payloadStr, testSecret);
125
126 - const result = triggers.verifyWebhook({
126 + const result = await triggers.verifyWebhook({
127 payload: payloadStr,
128 signature,
129 secret: testSecret,
@@ -138,12 +138,12 @@ describe('Triggers.verifyWebhook', () => {
138 expect(result.rawPayload).toEqual(v3Payload);
139 });
140
141 - it('should correctly normalize V3 payload to IncomingTriggerPayload format', () => {
141 + it('should correctly normalize V3 payload to IncomingTriggerPayload format', async () => {
142 const v3Payload = createMockV3Payload();
143 const payloadStr = JSON.stringify(v3Payload);
144 const signature = createSignature(testWebhookId, testTimestamp, payloadStr, testSecret);
145
146 - const result = triggers.verifyWebhook({
146 + const result = await triggers.verifyWebhook({
147 payload: payloadStr,
148 signature,
149 secret: testSecret,
@@ -163,12 +163,12 @@ describe('Triggers.verifyWebhook', () => {
163 });
164
165 describe('successful verification with V2 payload', () => {
166 - it('should verify a valid V2 webhook payload and signature', () => {
166 + it('should verify a valid V2 webhook payload and signature', async () => {
167 const v2Payload = createMockV2Payload();
168 const payloadStr = JSON.stringify(v2Payload);
169 const signature = createSignature(testWebhookId, testTimestamp, payloadStr, testSecret);
170
171 - const result = triggers.verifyWebhook({
171 + const result = await triggers.verifyWebhook({
172 payload: payloadStr,
173 signature,
174 secret: testSecret,
@@ -184,12 +184,12 @@ describe('Triggers.verifyWebhook', () => {
184 });
185
186 describe('successful verification with V1 payload', () => {
187 - it('should verify a valid V1 webhook payload and signature', () => {
187 + it('should verify a valid V1 webhook payload and signature', async () => {
188 const v1Payload = createMockV1Payload();
189 const payloadStr = JSON.stringify(v1Payload);
190 const signature = createSignature(testWebhookId, testTimestamp, payloadStr, testSecret);
191
192 - const result = triggers.verifyWebhook({
192 + const result = await triggers.verifyWebhook({
193 payload: payloadStr,
194 signature,
195 secret: testSecret,
@@ -205,14 +205,14 @@ describe('Triggers.verifyWebhook', () => {
205 });
206
207 describe('tolerance settings', () => {
208 - it('should verify webhook with tolerance set to 0 (skip timestamp validation)', () => {
208 + it('should verify webhook with tolerance set to 0 (skip timestamp validation)', async () => {
209 const v3Payload = createMockV3Payload();
210 const payloadStr = JSON.stringify(v3Payload);
211 // Use an old timestamp
212 const oldTimestamp = Math.floor((Date.now() - 60 * 60 * 1000) / 1000).toString();
213 const signature = createSignature(testWebhookId, oldTimestamp, payloadStr, testSecret);
214
215 - const result = triggers.verifyWebhook({
215 + const result = await triggers.verifyWebhook({
216 payload: payloadStr,
217 signature,
218 secret: testSecret,
@@ -225,12 +225,12 @@ describe('Triggers.verifyWebhook', () => {
225 expect(result.version).toBe(WebhookVersions.V3);
226 });
227
228 - it('should verify webhook with custom tolerance', () => {
228 + it('should verify webhook with custom tolerance', async () => {
229 const v3Payload = createMockV3Payload();
230 const payloadStr = JSON.stringify(v3Payload);
231 const signature = createSignature(testWebhookId, testTimestamp, payloadStr, testSecret);
232
233 - const result = triggers.verifyWebhook({
233 + const result = await triggers.verifyWebhook({
234 payload: payloadStr,
235 signature,
236 secret: testSecret,
@@ -244,8 +244,8 @@ describe('Triggers.verifyWebhook', () => {
244 });
245
246 describe('signature verification errors', () => {
247 - it('should throw error when payload is empty', () => {
248 - expect(() =>
247 + it('should throw error when payload is empty', async () => {
248 + await expect(() =>
249 triggers.verifyWebhook({
250 payload: '',
251 signature: 'v1,somesignature',
@@ -253,9 +253,9 @@ describe('Triggers.verifyWebhook', () => {
253 id: testWebhookId,
254 timestamp: testTimestamp,
255 })
256 - ).toThrow(ComposioWebhookSignatureVerificationError);
256 + ).rejects.toThrow(ComposioWebhookSignatureVerificationError);
257
258 - expect(() =>
258 + await expect(() =>
259 triggers.verifyWebhook({
260 payload: '',
261 signature: 'v1,somesignature',
@@ -263,13 +263,13 @@ describe('Triggers.verifyWebhook', () => {
263 id: testWebhookId,
264 timestamp: testTimestamp,
265 })
266 - ).toThrow('No webhook payload was provided.');
266 + ).rejects.toThrow('No webhook payload was provided.');
267 });
268
269 - it('should throw error when signature is empty', () => {
269 + it('should throw error when signature is empty', async () => {
270 const payloadStr = JSON.stringify(createMockV3Payload());
271
272 - expect(() =>
272 + await expect(() =>
273 triggers.verifyWebhook({
274 payload: payloadStr,
275 signature: '',
@@ -277,9 +277,9 @@ describe('Triggers.verifyWebhook', () => {
277 id: testWebhookId,
278 timestamp: testTimestamp,
279 })
280 - ).toThrow(ComposioWebhookSignatureVerificationError);
280 + ).rejects.toThrow(ComposioWebhookSignatureVerificationError);
281
282 - expect(() =>
282 + await expect(() =>
283 triggers.verifyWebhook({
284 payload: payloadStr,
285 signature: '',
@@ -287,13 +287,13 @@ describe('Triggers.verifyWebhook', () => {
287 id: testWebhookId,
288 timestamp: testTimestamp,
289 })
290 - ).toThrow('No signature header value was provided.');
290 + ).rejects.toThrow('No signature header value was provided.');
291 });
292
293 - it('should throw error when secret is empty', () => {
293 + it('should throw error when secret is empty', async () => {
294 const payloadStr = JSON.stringify(createMockV3Payload());
295
296 - expect(() =>
296 + await expect(() =>
297 triggers.verifyWebhook({
298 payload: payloadStr,
299 signature: 'v1,somesignature',
@@ -301,9 +301,9 @@ describe('Triggers.verifyWebhook', () => {
301 id: testWebhookId,
302 timestamp: testTimestamp,
303 })
304 - ).toThrow(ComposioWebhookSignatureVerificationError);
304 + ).rejects.toThrow(ComposioWebhookSignatureVerificationError);
305
306 - expect(() =>
306 + await expect(() =>
307 triggers.verifyWebhook({
308 payload: payloadStr,
309 signature: 'v1,somesignature',
@@ -311,13 +311,13 @@ describe('Triggers.verifyWebhook', () => {
311 id: testWebhookId,
312 timestamp: testTimestamp,
313 })
314 - ).toThrow('No webhook secret was provided.');
314 + ).rejects.toThrow('No webhook secret was provided.');
315 });
316
317 - it('should throw error when webhookId is empty', () => {
317 + it('should throw error when webhookId is empty', async () => {
318 const payloadStr = JSON.stringify(createMockV3Payload());
319
320 - expect(() =>
320 + await expect(() =>
321 triggers.verifyWebhook({
322 payload: payloadStr,
323 signature: 'v1,somesignature',
@@ -325,9 +325,9 @@ describe('Triggers.verifyWebhook', () => {
325 id: '',
326 timestamp: testTimestamp,
327 })
328 - ).toThrow(ComposioWebhookSignatureVerificationError);
328 + ).rejects.toThrow(ComposioWebhookSignatureVerificationError);
329
330 - expect(() =>
330 + await expect(() =>
331 triggers.verifyWebhook({
332 payload: payloadStr,
333 signature: 'v1,somesignature',
@@ -335,14 +335,14 @@ describe('Triggers.verifyWebhook', () => {
335 id: '',
336 timestamp: testTimestamp,
337 })
338 - ).toThrow('No webhook ID was provided.');
338 + ).rejects.toThrow('No webhook ID was provided.');
339 });
340
341 - it('should throw error when webhookTimestamp is empty', () => {
341 + it('should throw error when webhookTimestamp is empty', async () => {
342 const payloadStr = JSON.stringify(createMockV3Payload());
343
344 // Empty timestamp is treated as invalid timestamp format (parseInt('') = NaN)
345 - expect(() =>
345 + await expect(() =>
346 triggers.verifyWebhook({
347 payload: payloadStr,
348 signature: 'v1,somesignature',
@@ -350,9 +350,9 @@ describe('Triggers.verifyWebhook', () => {
350 id: testWebhookId,
351 timestamp: '',
352 })
353 - ).toThrow(ComposioWebhookPayloadError);
353 + ).rejects.toThrow(ComposioWebhookPayloadError);
354
355 - expect(() =>
355 + await expect(() =>
356 triggers.verifyWebhook({
357 payload: payloadStr,
358 signature: 'v1,somesignature',
@@ -360,13 +360,13 @@ describe('Triggers.verifyWebhook', () => {
360 id: testWebhookId,
361 timestamp: '',
362 })
363 - ).toThrow('Invalid webhook timestamp');
363 + ).rejects.toThrow('Invalid webhook timestamp');
364 });
365
366 - it('should throw error when signature format is invalid (no v1 prefix)', () => {
366 + it('should throw error when signature format is invalid (no v1 prefix)', async () => {
367 const payloadStr = JSON.stringify(createMockV3Payload());
368
369 - expect(() =>
369 + await expect(() =>
370 triggers.verifyWebhook({
371 payload: payloadStr,
372 signature: 'invalid-signature-no-prefix',
@@ -374,9 +374,9 @@ describe('Triggers.verifyWebhook', () => {
374 id: testWebhookId,
375 timestamp: testTimestamp,
376 })
377 - ).toThrow(ComposioWebhookSignatureVerificationError);
377 + ).rejects.toThrow(ComposioWebhookSignatureVerificationError);
378
379 - expect(() =>
379 + await expect(() =>
380 triggers.verifyWebhook({
381 payload: payloadStr,
382 signature: 'invalid-signature-no-prefix',
@@ -384,13 +384,13 @@ describe('Triggers.verifyWebhook', () => {
384 id: testWebhookId,
385 timestamp: testTimestamp,
386 })
387 - ).toThrow('No valid v1 signature found');
387 + ).rejects.toThrow('No valid v1 signature found');
388 });
389
390 - it('should throw error when signature is invalid', () => {
390 + it('should throw error when signature is invalid', async () => {
391 const payloadStr = JSON.stringify(createMockV3Payload());
392
393 - expect(() =>
393 + await expect(() =>
394 triggers.verifyWebhook({
395 payload: payloadStr,
396 signature: 'v1,invalidbase64signature==',
@@ -398,9 +398,9 @@ describe('Triggers.verifyWebhook', () => {
398 id: testWebhookId,
399 timestamp: testTimestamp,
400 })
401 - ).toThrow(ComposioWebhookSignatureVerificationError);
401 + ).rejects.toThrow(ComposioWebhookSignatureVerificationError);
402
403 - expect(() =>
403 + await expect(() =>
404 triggers.verifyWebhook({
405 payload: payloadStr,
406 signature: 'v1,invalidbase64signature==',
@@ -408,10 +408,10 @@ describe('Triggers.verifyWebhook', () => {
408 id: testWebhookId,
409 timestamp: testTimestamp,
410 })
411 - ).toThrow('The signature provided is invalid.');
411 + ).rejects.toThrow('The signature provided is invalid.');
412 });
413
414 - it('should throw error when signature was created with different secret', () => {
414 + it('should throw error when signature was created with different secret', async () => {
415 const payloadStr = JSON.stringify(createMockV3Payload());
416 const signatureWithDifferentSecret = createSignature(
417 testWebhookId,
@@ -420,7 +420,7 @@ describe('Triggers.verifyWebhook', () => {
420 'different-secret'
421 );
422
423 - expect(() =>
423 + await expect(() =>
424 triggers.verifyWebhook({
425 payload: payloadStr,
426 signature: signatureWithDifferentSecret,
@@ -428,10 +428,10 @@ describe('Triggers.verifyWebhook', () => {
428 id: testWebhookId,
429 timestamp: testTimestamp,
430 })
431 - ).toThrow(ComposioWebhookSignatureVerificationError);
431 + ).rejects.toThrow(ComposioWebhookSignatureVerificationError);
432 });
433
434 - it('should throw error when payload was modified after signing', () => {
434 + it('should throw error when payload was modified after signing', async () => {
435 const originalPayload = createMockV3Payload();
436 const payloadStr = JSON.stringify(originalPayload);
437 const signature = createSignature(testWebhookId, testTimestamp, payloadStr, testSecret);
@@ -441,7 +441,7 @@ describe('Triggers.verifyWebhook', () => {
441 data: { modified: true },
442 });
443
444 - expect(() =>
444 + await expect(() =>
445 triggers.verifyWebhook({
446 payload: modifiedPayload,
447 signature,
@@ -449,16 +449,16 @@ describe('Triggers.verifyWebhook', () => {
449 id: testWebhookId,
450 timestamp: testTimestamp,
451 })
452 - ).toThrow(ComposioWebhookSignatureVerificationError);
452 + ).rejects.toThrow(ComposioWebhookSignatureVerificationError);
453 });
454 });
455
456 describe('payload parsing errors', () => {
457 - it('should throw error when payload is not valid JSON', () => {
457 + it('should throw error when payload is not valid JSON', async () => {
458 const invalidJson = 'not-valid-json{';
459 const signature = createSignature(testWebhookId, testTimestamp, invalidJson, testSecret);
460
461 - expect(() =>
461 + await expect(() =>
462 triggers.verifyWebhook({
463 payload: invalidJson,
464 signature,
@@ -466,9 +466,9 @@ describe('Triggers.verifyWebhook', () => {
466 id: testWebhookId,
467 timestamp: testTimestamp,
468 })
469 - ).toThrow(ComposioWebhookPayloadError);
469 + ).rejects.toThrow(ComposioWebhookPayloadError);
470
471 - expect(() =>
471 + await expect(() =>
472 triggers.verifyWebhook({
473 payload: invalidJson,
474 signature,
@@ -476,14 +476,14 @@ describe('Triggers.verifyWebhook', () => {
476 id: testWebhookId,
477 timestamp: testTimestamp,
478 })
479 - ).toThrow('Failed to parse webhook payload as JSON');
479 + ).rejects.toThrow('Failed to parse webhook payload as JSON');
480 });
481
482 - it('should throw error for unrecognized payload format', () => {
482 + it('should throw error for unrecognized payload format', async () => {
483 const unknownPayload = JSON.stringify({ unknown: 'format' });
484 const signature = createSignature(testWebhookId, testTimestamp, unknownPayload, testSecret);
485
486 - expect(() =>
486 + await expect(() =>
487 triggers.verifyWebhook({
488 payload: unknownPayload,
489 signature,
@@ -491,9 +491,9 @@ describe('Triggers.verifyWebhook', () => {
491 id: testWebhookId,
492 timestamp: testTimestamp,
493 })
494 - ).toThrow(ComposioWebhookPayloadError);
494 + ).rejects.toThrow(ComposioWebhookPayloadError);
495
496 - expect(() =>
496 + await expect(() =>
497 triggers.verifyWebhook({
498 payload: unknownPayload,
499 signature,
@@ -501,18 +501,18 @@ describe('Triggers.verifyWebhook', () => {
501 id: testWebhookId,
502 timestamp: testTimestamp,
503 })
504 - ).toThrow('does not match any known version');
504 + ).rejects.toThrow('does not match any known version');
505 });
506 });
507
508 describe('timestamp validation', () => {
509 - it('should pass when webhook timestamp is within tolerance', () => {
509 + it('should pass when webhook timestamp is within tolerance', async () => {
510 const v3Payload = createMockV3Payload();
511 const payloadStr = JSON.stringify(v3Payload);
512 const recentTimestamp = Math.floor(Date.now() / 1000).toString();
513 const signature = createSignature(testWebhookId, recentTimestamp, payloadStr, testSecret);
514
515 - const result = triggers.verifyWebhook({
515 + const result = await triggers.verifyWebhook({
516 payload: payloadStr,
517 signature,
518 secret: testSecret,
@@ -524,14 +524,14 @@ describe('Triggers.verifyWebhook', () => {
524 expect(result).toBeDefined();
525 });
526
527 - it('should throw error when webhook timestamp is outside tolerance', () => {
527 + it('should throw error when webhook timestamp is outside tolerance', async () => {
528 const v3Payload = createMockV3Payload();
529 const payloadStr = JSON.stringify(v3Payload);
530 // 10 minutes ago
531 const oldTimestamp = Math.floor((Date.now() - 10 * 60 * 1000) / 1000).toString();
532 const signature = createSignature(testWebhookId, oldTimestamp, payloadStr, testSecret);
533
534 - expect(() =>
534 + await expect(() =>
535 triggers.verifyWebhook({
536 payload: payloadStr,
537 signature,
@@ -540,9 +540,9 @@ describe('Triggers.verifyWebhook', () => {
540 timestamp: oldTimestamp,
541 tolerance: 300, // 5 minutes
542 })
543 - ).toThrow(ComposioWebhookSignatureVerificationError);
543 + ).rejects.toThrow(ComposioWebhookSignatureVerificationError);
544
545 - expect(() =>
545 + await expect(() =>
546 triggers.verifyWebhook({
547 payload: payloadStr,
548 signature,
@@ -551,16 +551,16 @@ describe('Triggers.verifyWebhook', () => {
551 timestamp: oldTimestamp,
552 tolerance: 300,
553 })
554 - ).toThrow('The webhook timestamp is outside the allowed tolerance');
554 + ).rejects.toThrow('The webhook timestamp is outside the allowed tolerance');
555 });
556
557 - it('should throw error for invalid timestamp format', () => {
557 + it('should throw error for invalid timestamp format', async () => {
558 const v3Payload = createMockV3Payload();
559 const payloadStr = JSON.stringify(v3Payload);
560 const invalidTimestamp = 'not-a-timestamp';
561 const signature = createSignature(testWebhookId, invalidTimestamp, payloadStr, testSecret);
562
563 - expect(() =>
563 + await expect(() =>
564 triggers.verifyWebhook({
565 payload: payloadStr,
566 signature,
@@ -569,9 +569,9 @@ describe('Triggers.verifyWebhook', () => {
569 timestamp: invalidTimestamp,
570 tolerance: 300,
571 })
572 - ).toThrow(ComposioWebhookPayloadError);
572 + ).rejects.toThrow(ComposioWebhookPayloadError);
573
574 - expect(() =>
574 + await expect(() =>
575 triggers.verifyWebhook({
576 payload: payloadStr,
577 signature,
@@ -580,68 +580,68 @@ describe('Triggers.verifyWebhook', () => {
580 timestamp: invalidTimestamp,
581 tolerance: 300,
582 })
583 - ).toThrow('Invalid webhook timestamp');
583 + ).rejects.toThrow('Invalid webhook timestamp');
584 });
585 });
586
587 describe('input validation', () => {
588 - it('should throw ValidationError for missing payload parameter', () => {
589 - expect(() =>
588 + it('should throw ValidationError for missing payload parameter', async () => {
589 + await expect(() =>
590 triggers.verifyWebhook({
591 signature: 'v1,sig',
592 secret: testSecret,
593 webhookId: testWebhookId,
594 webhookTimestamp: testTimestamp,
595 } as any)
596 - ).toThrow(ValidationError);
596 + ).rejects.toThrow(ValidationError);
597 });
598
599 - it('should throw ValidationError for missing signature parameter', () => {
600 - expect(() =>
599 + it('should throw ValidationError for missing signature parameter', async () => {
600 + await expect(() =>
601 triggers.verifyWebhook({
602 payload: '{}',
603 secret: testSecret,
604 webhookId: testWebhookId,
605 webhookTimestamp: testTimestamp,
606 } as any)
607 - ).toThrow(ValidationError);
607 + ).rejects.toThrow(ValidationError);
608 });
609
610 - it('should throw ValidationError for missing secret parameter', () => {
611 - expect(() =>
610 + it('should throw ValidationError for missing secret parameter', async () => {
611 + await expect(() =>
612 triggers.verifyWebhook({
613 payload: '{}',
614 signature: 'v1,sig',
615 webhookId: testWebhookId,
616 webhookTimestamp: testTimestamp,
617 } as any)
618 - ).toThrow(ValidationError);
618 + ).rejects.toThrow(ValidationError);
619 });
620
621 - it('should throw ValidationError for missing webhookId parameter', () => {
622 - expect(() =>
621 + it('should throw ValidationError for missing webhookId parameter', async () => {
622 + await expect(() =>
623 triggers.verifyWebhook({
624 payload: '{}',
625 signature: 'v1,sig',
626 secret: testSecret,
627 webhookTimestamp: testTimestamp,
628 } as any)
629 - ).toThrow(ValidationError);
629 + ).rejects.toThrow(ValidationError);
630 });
631
632 - it('should throw ValidationError for missing webhookTimestamp parameter', () => {
633 - expect(() =>
632 + it('should throw ValidationError for missing webhookTimestamp parameter', async () => {
633 + await expect(() =>
634 triggers.verifyWebhook({
635 payload: '{}',
636 signature: 'v1,sig',
637 secret: testSecret,
638 webhookId: testWebhookId,
639 } as any)
640 - ).toThrow(ValidationError);
640 + ).rejects.toThrow(ValidationError);
641 });
642
643 - it('should throw ValidationError for invalid tolerance type', () => {
644 - expect(() =>
643 + it('should throw ValidationError for invalid tolerance type', async () => {
644 + await expect(() =>
645 triggers.verifyWebhook({
646 payload: '{}',
647 signature: 'v1,sig',
@@ -650,18 +650,18 @@ describe('Triggers.verifyWebhook', () => {
650 timestamp: testTimestamp,
651 tolerance: 'invalid' as any,
652 })
653 - ).toThrow(ValidationError);
653 + ).rejects.toThrow(ValidationError);
654 });
655 });
656
657 describe('security considerations', () => {
658 - it('should use timing-safe comparison for signatures', () => {
658 + it('should use timing-safe comparison for signatures', async () => {
659 const v3Payload = createMockV3Payload();
660 const payloadStr = JSON.stringify(v3Payload);
661 const validSignature = createSignature(testWebhookId, testTimestamp, payloadStr, testSecret);
662
663 // Valid signature should work
664 - expect(() =>
664 + await expect(
665 triggers.verifyWebhook({
666 payload: payloadStr,
667 signature: validSignature,
@@ -669,11 +669,11 @@ describe('Triggers.verifyWebhook', () => {
669 id: testWebhookId,
670 timestamp: testTimestamp,
671 })
672 - ).not.toThrow();
672 + ).resolves.toBeDefined();
673
674 // Invalid signature with same format should fail
675 const invalidSignature = 'v1,' + 'a'.repeat(44); // base64 SHA256 is 44 chars
676 - expect(() =>
676 + await expect(() =>
677 triggers.verifyWebhook({
678 payload: payloadStr,
679 signature: invalidSignature,
@@ -681,15 +681,15 @@ describe('Triggers.verifyWebhook', () => {
681 id: testWebhookId,
682 timestamp: testTimestamp,
683 })
684 - ).toThrow(ComposioWebhookSignatureVerificationError);
684 + ).rejects.toThrow(ComposioWebhookSignatureVerificationError);
685 });
686
687 - it('should handle unicode in payload correctly', () => {
687 + it('should handle unicode in payload correctly', async () => {
688 const v3Payload = createMockV3Payload({ data: { message: '你好世界 🌍 مرحبا' } });
689 const payloadStr = JSON.stringify(v3Payload);
690 const signature = createSignature(testWebhookId, testTimestamp, payloadStr, testSecret);
691
692 - const result = triggers.verifyWebhook({
692 + const result = await triggers.verifyWebhook({
693 payload: payloadStr,
694 signature,
695 secret: testSecret,
@@ -701,13 +701,13 @@ describe('Triggers.verifyWebhook', () => {
701 expect(result.payload.payload).toEqual({ message: '你好世界 🌍 مرحبا' });
702 });
703
704 - it('should handle special characters in secret', () => {
704 + it('should handle special characters in secret', async () => {
705 const specialSecret = 'secret!@#$%^&*()_+-=[]{}|;:,.<>?';
706 const v3Payload = createMockV3Payload();
707 const payloadStr = JSON.stringify(v3Payload);
708 const signature = createSignature(testWebhookId, testTimestamp, payloadStr, specialSecret);
709
710 - const result = triggers.verifyWebhook({
710 + const result = await triggers.verifyWebhook({
711 payload: payloadStr,
712 signature,
713 secret: specialSecret,
@@ -718,14 +718,14 @@ describe('Triggers.verifyWebhook', () => {
718 expect(result).toBeDefined();
719 });
720
721 - it('should support multiple signatures in header', () => {
721 + it('should support multiple signatures in header', async () => {
722 const v3Payload = createMockV3Payload();
723 const payloadStr = JSON.stringify(v3Payload);
724 const validSignature = createSignature(testWebhookId, testTimestamp, payloadStr, testSecret);
725 // Multiple signatures space-separated
726 const multipleSignatures = `v1,invalidsig== ${validSignature}`;
727
728 - const result = triggers.verifyWebhook({
728 + const result = await triggers.verifyWebhook({
729 payload: payloadStr,
730 signature: multipleSignatures,
731 secret: testSecret,
@@ -738,11 +738,11 @@ describe('Triggers.verifyWebhook', () => {
738 });
739
740 describe('error properties', () => {
741 - it('should include proper error class for signature verification error', () => {
741 + it('should include proper error class for signature verification error', async () => {
742 const payloadStr = JSON.stringify(createMockV3Payload());
743
744 try {
745 - triggers.verifyWebhook({
745 + await triggers.verifyWebhook({
746 payload: payloadStr,
747 signature: 'v1,invalid',
748 secret: testSecret,
@@ -758,12 +758,12 @@ describe('Triggers.verifyWebhook', () => {
758 }
759 });
760
761 - it('should include proper error class for payload error', () => {
761 + it('should include proper error class for payload error', async () => {
762 const invalidPayload = 'not-json';
763 const signature = createSignature(testWebhookId, testTimestamp, invalidPayload, testSecret);
764
765 try {
766 - triggers.verifyWebhook({
766 + await triggers.verifyWebhook({
767 payload: invalidPayload,
768 signature,
769 secret: testSecret,