@@ -7,29 +7,30 @@ export default (QUnit: QUnit, lib: typeof jose, keys: typeof jose) => {
7
7
const { module, test } = QUnit
8
8
module ( 'jwk.ts' )
9
9
10
- type Vector = [ string , JsonWebKey , boolean ] | [ string , JsonWebKey , boolean , boolean ]
10
+ type Vector = [ string , JsonWebKey , boolean | [ boolean , boolean ] ]
11
+
11
12
const algorithms : Vector [ ] = [
12
13
[ 'ECDH-ES' , KEYS . P256 . jwk , true ] ,
13
14
[ 'ECDH-ES' , KEYS . P384 . jwk , true ] ,
14
- [ 'ECDH-ES' , KEYS . P521 . jwk , ! env . isDeno ] ,
15
+ [ 'ECDH-ES' , KEYS . P521 . jwk , env . isDeno ? [ true , false ] : true ] ,
15
16
[
16
17
'ECDH-ES' ,
17
18
KEYS . X25519 . jwk ,
18
- env . isDeno ||
19
- env . isNode ||
20
- env . isElectron ||
21
- env . isWorkerd ||
22
- env . isEdgeRuntime ||
23
- ( env . isGecko && env . isBrowserVersionAtLeast ( 130 ) ) ,
24
- env . isDeno ,
19
+ env . isDeno
20
+ ? [ true , false ]
21
+ : env . isNode ||
22
+ env . isElectron ||
23
+ env . isWorkerd ||
24
+ env . isEdgeRuntime ||
25
+ ( env . isGecko && env . isBrowserVersionAtLeast ( 130 ) ) ,
25
26
] ,
26
- [ 'ECDH-ES' , KEYS . X448 . jwk , env . isNode || env . isEdgeRuntime ] ,
27
+ [ 'ECDH-ES' , KEYS . X448 . jwk , env . isDeno ? [ true , false ] : env . isNode || env . isEdgeRuntime ] ,
27
28
[ 'EdDSA' , KEYS . Ed25519 . jwk , ! env . isBlink ] ,
28
29
[ 'EdDSA' , KEYS . Ed448 . jwk , env . isNode || env . isEdgeRuntime ] ,
29
30
[ 'ES256' , KEYS . P256 . jwk , true ] ,
30
31
[ 'ES256K' , KEYS . secp256k1 . jwk , lib . cryptoRuntime === 'node:crypto' && ! env . isElectron ] ,
31
32
[ 'ES384' , KEYS . P384 . jwk , true ] ,
32
- [ 'ES512' , KEYS . P521 . jwk , ! env . isDeno ] ,
33
+ [ 'ES512' , KEYS . P521 . jwk , env . isDeno ? [ true , false ] : true ] ,
33
34
[ 'PS256' , KEYS . RSA . jwk , true ] ,
34
35
[ 'PS384' , KEYS . RSA . jwk , true ] ,
35
36
[ 'PS512' , KEYS . RSA . jwk , true ] ,
@@ -48,7 +49,13 @@ export default (QUnit: QUnit, lib: typeof jose, keys: typeof jose) => {
48
49
}
49
50
50
51
for ( const vector of algorithms . slice ( ) ) {
51
- algorithms . push ( [ vector [ 0 ] , publicJwk ( vector [ 1 ] ) , vector [ 2 ] ] )
52
+ if ( typeof vector [ 2 ] !== 'boolean' ) {
53
+ let [ pub , priv ] = vector [ 2 ]
54
+ vector [ 2 ] = priv
55
+ algorithms . push ( [ vector [ 0 ] , publicJwk ( vector [ 1 ] ) , pub ] )
56
+ } else {
57
+ algorithms . push ( [ vector [ 0 ] , publicJwk ( vector [ 1 ] ) , vector [ 2 ] ] )
58
+ }
52
59
}
53
60
54
61
function title ( alg : string , jwk : JsonWebKey , works : boolean ) {
@@ -67,23 +74,19 @@ export default (QUnit: QUnit, lib: typeof jose, keys: typeof jose) => {
67
74
68
75
for ( const vector of algorithms ) {
69
76
const [ alg , jwk ] = vector
70
- const [ , , works , exportNotImplemented ] = vector
77
+ const [ , , works ] = vector
78
+
79
+ if ( typeof works !== 'boolean' ) {
80
+ throw new Error ( )
81
+ }
71
82
72
83
const execute = async ( t : typeof QUnit . assert ) => {
73
84
const key = await lib . importJWK ( { ...jwk , ext : true } , alg )
74
- if ( exportNotImplemented ) {
75
- try {
76
- await lib . exportJWK ( key )
77
- throw new Error ( )
78
- } catch ( err ) {
79
- t . strictEqual ( ( err as Error ) . name , 'NotSupportedError' )
80
- }
81
- } else {
82
- const exported = await lib . exportJWK ( key )
83
85
84
- for ( const prop of [ ...new Set ( [ ...Object . keys ( jwk ) , ...Object . keys ( exported ) ] ) ] ) {
85
- t . strictEqual ( exported [ prop ] , jwk [ prop as keyof JsonWebKey ] , `${ prop } mismatch` )
86
- }
86
+ const exported = await lib . exportJWK ( key )
87
+
88
+ for ( const prop of [ ...new Set ( [ ...Object . keys ( jwk ) , ...Object . keys ( exported ) ] ) ] ) {
89
+ t . strictEqual ( exported [ prop ] , jwk [ prop as keyof JsonWebKey ] , `${ prop } mismatch` )
87
90
}
88
91
89
92
t . ok ( 1 )
@@ -98,40 +101,40 @@ export default (QUnit: QUnit, lib: typeof jose, keys: typeof jose) => {
98
101
}
99
102
}
100
103
101
- test ( 'alg argument and jwk.alg is ignored for oct JWKs' , async ( t ) => {
102
- const oct = {
103
- k : 'FyCq1CKBflh3I5gikEjpYrdOXllzxB_yc02za8ERknI' ,
104
- kty : 'oct' ,
105
- }
106
- await lib . importJWK ( oct )
107
- t . ok ( 1 )
108
- } )
104
+ // test('alg argument and jwk.alg is ignored for oct JWKs', async (t) => {
105
+ // const oct = {
106
+ // k: 'FyCq1CKBflh3I5gikEjpYrdOXllzxB_yc02za8ERknI',
107
+ // kty: 'oct',
108
+ // }
109
+ // await lib.importJWK(oct)
110
+ // t.ok(1)
111
+ // })
109
112
110
- if ( lib . cryptoRuntime === 'node:crypto' ) {
111
- test ( 'alg argument is ignored if jwk does not have alg for asymmetric keys' , async ( t ) => {
112
- const jwk = {
113
- kty : 'EC' ,
114
- crv : 'P-256' ,
115
- x : 'jJ6Flys3zK9jUhnOHf6G49Dyp5hah6CNP84-gY-n9eo' ,
116
- y : 'nhI6iD5eFXgBTLt_1p3aip-5VbZeMhxeFSpjfEAf7Ww' ,
117
- }
118
- await lib . importJWK ( jwk )
119
- t . ok ( 1 )
120
- } )
121
- } else {
122
- test ( 'alg argument must be present if jwk does not have alg for asymmetric keys' , async ( t ) => {
123
- const jwk = {
124
- kty : 'EC' ,
125
- crv : 'P-256' ,
126
- x : 'jJ6Flys3zK9jUhnOHf6G49Dyp5hah6CNP84-gY-n9eo' ,
127
- y : 'nhI6iD5eFXgBTLt_1p3aip-5VbZeMhxeFSpjfEAf7Ww' ,
128
- }
129
- await t . rejects (
130
- lib . importJWK ( jwk ) ,
131
- '"alg" argument is required when "jwk.alg" is not present' ,
132
- )
133
- await lib . importJWK ( jwk , 'ES256' )
134
- await lib . importJWK ( { ...jwk , alg : 'ES256' } )
135
- } )
136
- }
113
+ // if (lib.cryptoRuntime === 'node:crypto') {
114
+ // test('alg argument is ignored if jwk does not have alg for asymmetric keys', async (t) => {
115
+ // const jwk = {
116
+ // kty: 'EC',
117
+ // crv: 'P-256',
118
+ // x: 'jJ6Flys3zK9jUhnOHf6G49Dyp5hah6CNP84-gY-n9eo',
119
+ // y: 'nhI6iD5eFXgBTLt_1p3aip-5VbZeMhxeFSpjfEAf7Ww',
120
+ // }
121
+ // await lib.importJWK(jwk)
122
+ // t.ok(1)
123
+ // })
124
+ // } else {
125
+ // test('alg argument must be present if jwk does not have alg for asymmetric keys', async (t) => {
126
+ // const jwk = {
127
+ // kty: 'EC',
128
+ // crv: 'P-256',
129
+ // x: 'jJ6Flys3zK9jUhnOHf6G49Dyp5hah6CNP84-gY-n9eo',
130
+ // y: 'nhI6iD5eFXgBTLt_1p3aip-5VbZeMhxeFSpjfEAf7Ww',
131
+ // }
132
+ // await t.rejects(
133
+ // lib.importJWK(jwk),
134
+ // '"alg" argument is required when "jwk.alg" is not present',
135
+ // )
136
+ // await lib.importJWK(jwk, 'ES256')
137
+ // await lib.importJWK({ ...jwk, alg: 'ES256' })
138
+ // })
139
+ // }
137
140
}
0 commit comments