@@ -22,7 +22,7 @@ import { webcrypto } from 'crypto';
22
22
import * as assertions from '@opentdf/sdk/assertions' ;
23
23
import { attributeFQNsAsValues } from '@opentdf/sdk/nano' ;
24
24
import { base64 } from '@opentdf/sdk/encodings' ;
25
- import { importPKCS8 , importSPKI , KeyLike } from 'jose' ; // for RS256
25
+ import { type CryptoKey , importPKCS8 , importSPKI } from 'jose' ; // for RS256
26
26
27
27
type AuthToProcess = {
28
28
auth ?: string ;
@@ -143,20 +143,20 @@ async function parseAssertionVerificationKeys(
143
143
}
144
144
}
145
145
for ( const assertionName in u . Keys ) {
146
- const assertionKey = u . Keys [ assertionName ] ;
146
+ const assertionKey : assertions . AssertionKey = u . Keys [ assertionName ] ;
147
147
// Ensure each entry has the required 'key' and 'alg' fields
148
148
if ( typeof assertionKey !== 'object' || assertionKey === null ) {
149
149
throw new CLIError ( 'CRITICAL' , `Invalid assertion for ${ assertionName } : Must be an object` ) ;
150
150
}
151
151
152
- if ( typeof assertionKey . key !== 'string' || typeof assertionKey . alg !== 'string' ) {
152
+ if ( typeof assertionKey . alg !== 'string' ) {
153
153
throw new CLIError (
154
154
'CRITICAL' ,
155
155
`Invalid assertion for ${ assertionName } : Missing or invalid 'key' or 'alg'`
156
156
) ;
157
157
}
158
158
try {
159
- u . Keys [ assertionName ] . key = await correctAssertionKeys ( assertionKey . alg , assertionKey . key ) ;
159
+ u . Keys [ assertionName ] . key = await correctAssertionKeys ( assertionKey ) ;
160
160
} catch ( err ) {
161
161
throw new CLIError ( 'CRITICAL' , `Issue converting assertion key from string: ${ err . message } ` ) ;
162
162
}
@@ -182,10 +182,10 @@ async function parseReadOptions(argv: Partial<mainArgs>): Promise<ReadOptions> {
182
182
return r ;
183
183
}
184
184
185
- async function correctAssertionKeys (
186
- alg : string ,
187
- key : KeyLike | Uint8Array
188
- ) : Promise < KeyLike | Uint8Array > {
185
+ async function correctAssertionKeys ( {
186
+ alg,
187
+ key,
188
+ } : assertions . AssertionKey ) : Promise < CryptoKey | Uint8Array > {
189
189
if ( alg === 'HS256' ) {
190
190
// Convert key string to Uint8Array
191
191
if ( typeof key !== 'string' ) {
@@ -240,17 +240,17 @@ async function parseAssertionConfig(s: string): Promise<assertions.AssertionConf
240
240
if ( ! assertions . isAssertionConfig ( assertion ) ) {
241
241
throw new CLIError ( 'CRITICAL' , `invalid assertion config ${ JSON . stringify ( assertion ) } ` ) ;
242
242
}
243
- if ( assertion . signingKey ) {
244
- const { alg , key } = assertion . signingKey ;
245
- try {
246
- assertion . signingKey . key = await correctAssertionKeys ( alg , key ) ;
247
- } catch ( err ) {
248
- throw new CLIError (
249
- 'CRITICAL' ,
250
- `Issue converting assertion key from string: ${ err . message } ` ,
251
- err
252
- ) ;
253
- }
243
+ if ( ! assertion . signingKey ) {
244
+ continue ;
245
+ }
246
+ try {
247
+ assertion . signingKey . key = await correctAssertionKeys ( assertion . signingKey ) ;
248
+ } catch ( err ) {
249
+ throw new CLIError (
250
+ 'CRITICAL' ,
251
+ `Issue converting assertion key from string: ${ err . message } ` ,
252
+ err
253
+ ) ;
254
254
}
255
255
}
256
256
return a ;
0 commit comments