@@ -31,6 +31,8 @@ export function deriveComponent(component: string, params: Map<string, string |
31
31
/**
32
32
* Components can be derived from requests or responses (which can also be bound to their request).
33
33
* The signature is essentially (component, params, signingSubject, supplementaryData)
34
+ *
35
+ * @todo - prefer pseudo-headers over parsed urls
34
36
*/
35
37
export function deriveComponent ( component : string , params : Map < string , string | number | boolean > , message : Request | Response , req ?: Request ) : string [ ] {
36
38
// switch the context of the signing data depending on if the `req` flag was passed
@@ -94,12 +96,6 @@ export function deriveComponent(component: string, params: Map<string, string |
94
96
// absent query params means use `?`
95
97
return [ decodeURI ( search ) || '?' ] ;
96
98
}
97
- case '@status' : {
98
- if ( isRequest ( context ) ) {
99
- throw new Error ( 'Cannot obtain @status component for requests' ) ;
100
- }
101
- return [ context . status . toString ( ) ] ;
102
- }
103
99
case '@query-param' : {
104
100
if ( ! isRequest ( context ) ) {
105
101
throw new Error ( 'Cannot derive @scheme on response' ) ;
@@ -114,6 +110,12 @@ export function deriveComponent(component: string, params: Map<string, string |
114
110
}
115
111
return searchParams . getAll ( name ) ;
116
112
}
113
+ case '@status' : {
114
+ if ( isRequest ( context ) ) {
115
+ throw new Error ( 'Cannot obtain @status component for requests' ) ;
116
+ }
117
+ return [ context . status . toString ( ) ] ;
118
+ }
117
119
default :
118
120
throw new Error ( `Unsupported component "${ component } "` ) ;
119
121
}
@@ -132,8 +134,8 @@ export function extractHeader(header: string, params: Map<string, string | numbe
132
134
throw new Error ( `No header "${ header } " found in headers` ) ;
133
135
}
134
136
const values = ( Array . isArray ( headerTuple [ 1 ] ) ? headerTuple [ 1 ] : [ headerTuple [ 1 ] ] ) ;
135
- if ( params . has ( 'bs' ) && params . has ( 'sf' ) ) {
136
- throw new Error ( 'Invalid combination of parameters' ) ;
137
+ if ( params . has ( 'bs' ) && ( params . has ( 'sf' ) || params . has ( 'key' ) ) ) {
138
+ throw new Error ( 'Cannot have both `bs` and (implicit) `sf` parameters' ) ;
137
139
}
138
140
if ( params . has ( 'sf' ) || params . has ( 'key' ) ) {
139
141
// strict encoding of field
@@ -234,6 +236,9 @@ export function createSigningParameters(config: SignConfig): Parameters {
234
236
break ;
235
237
}
236
238
case 'alg' : {
239
+ // if there is no alg, but it's listed as a required parameter, we should probably
240
+ // throw an error - the problem is that if it's in the default set of params, do we
241
+ // really want to throw if there's no keyid?
237
242
const alg = config . paramValues ?. alg ?? config . key . alg ?? null ;
238
243
if ( alg ) {
239
244
value = alg . toString ( ) ;
0 commit comments