This repository was archived by the owner on Mar 18, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -50,6 +50,13 @@ export class ChainhooksDO extends DurableObject<Env> {
5050 } ) ;
5151 }
5252
53+ // Check authentication
54+ if ( ! this . validateAuthToken ( request ) ) {
55+ throw new ApiError ( ErrorCode . UNAUTHORIZED , {
56+ reason : 'Invalid or missing authentication token' ,
57+ } ) ;
58+ }
59+
5360 return await this . handlePostEvent ( request ) ;
5461 }
5562
@@ -187,4 +194,26 @@ export class ChainhooksDO extends DurableObject<Env> {
187194 } ) ;
188195 }
189196 }
197+
198+ /**
199+ * Validates the authentication token from the request
200+ *
201+ * @param request - The incoming request
202+ * @returns boolean indicating if the token is valid
203+ */
204+ private validateAuthToken ( request : Request ) : boolean {
205+ // Extract the Authorization header
206+ const authHeader = request . headers . get ( 'Authorization' ) ;
207+
208+ // Check if the header exists and has the correct format
209+ if ( ! authHeader || ! authHeader . startsWith ( 'Bearer ' ) ) {
210+ return false ;
211+ }
212+
213+ // Extract the token
214+ const token = authHeader . replace ( 'Bearer ' , '' ) ;
215+
216+ // Compare with the stored token
217+ return token === this . env . CHAINHOOKS_AUTH_TOKEN ;
218+ }
190219}
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ export interface Env {
55 HIRO_API_KEY : string ;
66 SUPABASE_URL : string ;
77 SUPABASE_SERVICE_KEY : string ;
8+ CHAINHOOKS_AUTH_TOKEN : string ; // Auth token for chainhooks POST endpoint
89 BNS_API_DO : DurableObjectNamespace < import ( './src/index' ) . BnsApiDO > ;
910 HIRO_API_DO : DurableObjectNamespace < import ( './src/index' ) . HiroApiDO > ;
1011 STX_CITY_DO : DurableObjectNamespace < import ( './src/index' ) . StxCityDO > ;
You can’t perform that action at this time.
0 commit comments