@@ -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
0 commit comments