@@ -9,92 +9,32 @@ const {
99 generateKeyPair,
1010} = require ( 'crypto' ) ;
1111
12- // Test async elliptic curve key generation with 'jwk' encoding
12+ // Test async elliptic curve key generation with 'jwk' encoding.
1313{
1414 [
15- [ 'ec' , [ 'P-384' , 'P-256' , 'P-521' , 'secp256k1' ] ] ,
16- [ 'rsa' ] ,
17- [ 'ed25519' ] ,
18- [ 'ed448' ] ,
19- [ 'x25519' ] ,
20- [ 'x448' ] ,
21- ] . forEach ( ( types ) => {
22- const [ type , options ] = types ;
23- switch ( type ) {
24- case 'ec' : {
25- return options . forEach ( ( curve ) => {
26- generateKeyPair ( type , {
27- namedCurve : curve ,
28- publicKeyEncoding : {
29- format : 'jwk'
30- } ,
31- privateKeyEncoding : {
32- format : 'jwk'
33- }
34- } , common . mustSucceed ( ( publicKey , privateKey ) => {
35- assert . strictEqual ( typeof publicKey , 'object' ) ;
36- assert . strictEqual ( typeof privateKey , 'object' ) ;
37- assert . strictEqual ( publicKey . x , privateKey . x ) ;
38- assert . strictEqual ( publicKey . y , privateKey . y ) ;
39- assert ( ! publicKey . d ) ;
40- assert ( privateKey . d ) ;
41- assert . strictEqual ( publicKey . kty , 'EC' ) ;
42- assert . strictEqual ( publicKey . kty , privateKey . kty ) ;
43- assert . strictEqual ( publicKey . crv , curve ) ;
44- assert . strictEqual ( publicKey . crv , privateKey . crv ) ;
45- } ) ) ;
46- } ) ;
15+ 'ed25519' ,
16+ 'ed448' ,
17+ 'x25519' ,
18+ 'x448' ,
19+ ] . forEach ( ( type ) => {
20+ generateKeyPair ( type , {
21+ publicKeyEncoding : {
22+ format : 'jwk'
23+ } ,
24+ privateKeyEncoding : {
25+ format : 'jwk'
4726 }
48- case 'rsa' : {
49- return generateKeyPair ( type , {
50- modulusLength : 4096 ,
51- publicKeyEncoding : {
52- format : 'jwk'
53- } ,
54- privateKeyEncoding : {
55- format : 'jwk'
56- }
57- } , common . mustSucceed ( ( publicKey , privateKey ) => {
58- assert . strictEqual ( typeof publicKey , 'object' ) ;
59- assert . strictEqual ( typeof privateKey , 'object' ) ;
60- assert . strictEqual ( publicKey . kty , 'RSA' ) ;
61- assert . strictEqual ( publicKey . kty , privateKey . kty ) ;
62- assert . strictEqual ( typeof publicKey . n , 'string' ) ;
63- assert . strictEqual ( publicKey . n , privateKey . n ) ;
64- assert . strictEqual ( typeof publicKey . e , 'string' ) ;
65- assert . strictEqual ( publicKey . e , privateKey . e ) ;
66- assert . strictEqual ( typeof privateKey . d , 'string' ) ;
67- assert . strictEqual ( typeof privateKey . p , 'string' ) ;
68- assert . strictEqual ( typeof privateKey . q , 'string' ) ;
69- assert . strictEqual ( typeof privateKey . dp , 'string' ) ;
70- assert . strictEqual ( typeof privateKey . dq , 'string' ) ;
71- assert . strictEqual ( typeof privateKey . qi , 'string' ) ;
72- } ) ) ;
73- }
74- case 'ed25519' :
75- case 'ed448' :
76- case 'x25519' :
77- case 'x448' : {
78- generateKeyPair ( type , {
79- publicKeyEncoding : {
80- format : 'jwk'
81- } ,
82- privateKeyEncoding : {
83- format : 'jwk'
84- }
85- } , common . mustSucceed ( ( publicKey , privateKey ) => {
86- assert . strictEqual ( typeof publicKey , 'object' ) ;
87- assert . strictEqual ( typeof privateKey , 'object' ) ;
88- assert . strictEqual ( publicKey . x , privateKey . x ) ;
89- assert ( ! publicKey . d ) ;
90- assert ( privateKey . d ) ;
91- assert . strictEqual ( publicKey . kty , 'OKP' ) ;
92- assert . strictEqual ( publicKey . kty , privateKey . kty ) ;
93- const expectedCrv = `${ type . charAt ( 0 ) . toUpperCase ( ) } ${ type . slice ( 1 ) } ` ;
94- assert . strictEqual ( publicKey . crv , expectedCrv ) ;
95- assert . strictEqual ( publicKey . crv , privateKey . crv ) ;
96- } ) ) ;
97- }
98- }
27+ } , common . mustSucceed ( ( publicKey , privateKey ) => {
28+ assert . strictEqual ( typeof publicKey , 'object' ) ;
29+ assert . strictEqual ( typeof privateKey , 'object' ) ;
30+ assert . strictEqual ( publicKey . x , privateKey . x ) ;
31+ assert ( ! publicKey . d ) ;
32+ assert ( privateKey . d ) ;
33+ assert . strictEqual ( publicKey . kty , 'OKP' ) ;
34+ assert . strictEqual ( publicKey . kty , privateKey . kty ) ;
35+ const expectedCrv = `${ type . charAt ( 0 ) . toUpperCase ( ) } ${ type . slice ( 1 ) } ` ;
36+ assert . strictEqual ( publicKey . crv , expectedCrv ) ;
37+ assert . strictEqual ( publicKey . crv , privateKey . crv ) ;
38+ } ) ) ;
9939 } ) ;
10040}
0 commit comments