@@ -211,17 +211,15 @@ export class JwsService {
211
211
}
212
212
213
213
private buildProtected ( options : JwsProtectedHeaderOptions ) {
214
- const x5cJwkCount = [ options . jwk , options . x5c ] . filter ( Boolean ) . length
215
-
216
214
// FIXME: checking for kid starting with '#' is not good.
217
215
// but now we don't really limit that kid (did key reference)
218
216
// cannot be combined with x5c/jwk
219
217
if ( options . kid ?. startsWith ( 'did:' ) ) {
220
- if ( x5cJwkCount > 0 ) {
218
+ if ( options . jwk || options . x5c ) {
221
219
throw new CredoError ( "When 'kid' is a did, 'jwk' and 'x5c' cannot be provided." )
222
220
}
223
- } else if ( x5cJwkCount > 1 || ( x5cJwkCount === 0 && ! options . kid ) ) {
224
- throw new CredoError ( "Header must contain one of 'kid' with a did value , 'x5c', or 'jwk' ." )
221
+ } else if ( ( options . jwk && options . x5c ) || ( ! options . jwk && ! options . x5c && ! options . kid ) ) {
222
+ throw new CredoError ( "Header must contain one of 'x5c' , 'jwk' or 'kid' with a did value ." )
225
223
}
226
224
227
225
return {
@@ -250,17 +248,15 @@ export class JwsService {
250
248
trustedCertificates : trustedCertificatesFromOptions = [ ] ,
251
249
} = options
252
250
253
- const x5cJwkCount = [ protectedHeader . jwk , protectedHeader . x5c ] . filter ( Boolean )
254
-
255
251
// FIXME: checking for kid starting with '#' is not good.
256
252
// but now we don't really limit that kid (did key reference)
257
253
// cannot be combined with x5c/jwk
258
254
if ( typeof protectedHeader . kid === 'string' && protectedHeader . kid ?. startsWith ( 'did:' ) ) {
259
- if ( x5cJwkCount . length > 0 ) {
255
+ if ( protectedHeader . jwk || protectedHeader . x5c ) {
260
256
throw new CredoError ( "When 'kid' is a did, 'jwk' and 'x5c' cannot be provided." )
261
257
}
262
- } else if ( x5cJwkCount . length > 1 ) {
263
- throw new CredoError ( "Header must contain one of 'kid' with a did value , 'x5c', or 'jwk' ." )
258
+ } else if ( protectedHeader . jwk && protectedHeader . x5c ) {
259
+ throw new CredoError ( "Header must contain one of 'x5c' , 'jwk' or 'kid' with a did value ." )
264
260
}
265
261
266
262
if ( protectedHeader . x5c ) {
0 commit comments