Skip to content

Commit bff0d1c

Browse files
committed
cleanup
1 parent f9bf0a1 commit bff0d1c

File tree

3 files changed

+10
-16
lines changed

3 files changed

+10
-16
lines changed

src/lib/bin/commands/listen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ export const listen = new Command('listen')
121121
const promises = queue.current.map(async (update) => {
122122
const body = JSON.stringify(update);
123123

124-
const signature = await createWebhookSignature({
124+
const signature = createWebhookSignature({
125125
payload: update.payload,
126126
timestamp: update.timestamp,
127127
secret,

src/lib/webhooks.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,18 @@ export async function verifyWebhookEventSignature(
7979
return { ok: false };
8080
}
8181

82-
const e = event.data;
83-
84-
// Create message in the same format as Python: timestamp.payload
85-
// Note: Using JSON.stringify with separators and sort_keys equivalent
86-
const dump = stringify(e.payload);
87-
const message = `${evt.timestamp}.${dump}`;
88-
89-
// Create HMAC with SHA-256 using the secret
90-
const hmac = createHmac('sha256', cfg.secret);
91-
hmac.update(message);
92-
const signature = hmac.digest('hex');
82+
const signature = createWebhookSignature({
83+
payload: event.data.payload,
84+
timestamp: evt.timestamp,
85+
secret: cfg.secret,
86+
});
9387

9488
// Compare signatures using timing-safe comparison
9589
if (evt.signature !== signature) {
9690
return { ok: false };
9791
}
9892

99-
return { ok: true, event: e };
93+
return { ok: true, event: event.data };
10094
} catch (err) {
10195
console.error(err);
10296
return { ok: false };
@@ -106,15 +100,15 @@ export async function verifyWebhookEventSignature(
106100
/**
107101
* Creates a webhook signature for the given payload, timestamp, and secret.
108102
*/
109-
export async function createWebhookSignature({
103+
export function createWebhookSignature({
110104
payload,
111105
timestamp,
112106
secret,
113107
}: {
114108
payload: unknown;
115109
timestamp: string;
116110
secret: string;
117-
}): Promise<string> {
111+
}): string {
118112
const dump = stringify(payload);
119113
const message = `${timestamp}.${dump}`;
120114

tests/lib/webhooks.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('webhooks', () => {
7373
},
7474
};
7575

76-
const signature = await createWebhookSignature({
76+
const signature = createWebhookSignature({
7777
payload: MOCK.payload,
7878
secret: 'secret',
7979
timestamp,

0 commit comments

Comments
 (0)