@@ -2,15 +2,15 @@ import { UnauthorizedHttpError, type AlgJwk, BadRequestHttpError, InternalServer
22import { httpbis , type SigningKey , type Request as SignRequest } from 'http-message-signatures' ;
33import { verifyMessage } from 'http-message-signatures/lib/httpbis' ;
44import { type SignatureParameters , type VerifierFinder , type VerifyingKey } from 'http-message-signatures/lib/types' ;
5- import type { HttpHandlerRequest } from './http/models/HttpHandlerRequest ' ;
5+ import { HttpHandlerRequest } from './http/models/HttpHandler ' ;
66import buildGetJwks from 'get-jwks' ;
77import crypto from 'node:crypto' ;
88
99const authParserMod = import ( '@httpland/authorization-parser' ) ;
1010
1111export async function signRequest (
12- url : string ,
13- request : RequestInit & Omit < SignRequest , 'url' > ,
12+ url : string ,
13+ request : RequestInit & Omit < SignRequest , 'url' > ,
1414 jwk : AlgJwk
1515) : Promise < RequestInit & SignRequest > {
1616 const key : SigningKey = {
@@ -52,10 +52,10 @@ export async function verifyRequest(
5252 signer ?: string ,
5353) : Promise < boolean > {
5454 signer = signer ?? await extractRequestSigner ( request ) ;
55-
55+
5656 if ( signer . startsWith ( '"' ) ) signer = signer . slice ( 1 ) ;
5757 if ( signer . endsWith ( '"' ) ) signer = signer . slice ( 0 , - 1 ) ;
58-
58+
5959 const jwks = buildGetJwks ( ) ;
6060
6161 const keyLookup : VerifierFinder = async ( params : SignatureParameters ) => {
@@ -67,7 +67,7 @@ export async function verifyRequest(
6767 alg : alg ?? '' ,
6868 kid : keyid ?? '' ,
6969 } )
70-
70+
7171 if ( ! alg ) throw new BadRequestHttpError ( 'Invalid HTTP message Signature parameters.' ) ;
7272 // if (alg === 'EdDSA') throw new InternalServerError('EdDSA signing is not supported');
7373 // if (alg === 'ES256K') throw new InternalServerError('ES256K signing is not supported');
@@ -83,7 +83,7 @@ export async function verifyRequest(
8383 } catch ( err ) { console . log ( err ) ; return null }
8484 } ,
8585 } ;
86-
86+
8787 return verifier ;
8888
8989 } catch ( err ) {
@@ -111,4 +111,3 @@ const algMap: Record<string, AlgParams> = {
111111 'RS384' : { name : 'RSASSA-PKCS1-v1_5' , hash : 'SHA-384' } ,
112112 'RS512' : { name : 'RSASSA-PKCS1-v1_5' , hash : 'SHA-512' } ,
113113}
114-
0 commit comments