mirror of
https://github.com/nodejs/node.git
synced 2024-11-24 20:29:23 +01:00
b9a6ab5c48
PR-URL: https://github.com/nodejs/node/pull/49221 Refs: https://github.com/nodejs/node/issues/49202 Refs: https://github.com/nodejs/node/issues/41206 Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
36 lines
1017 B
JavaScript
36 lines
1017 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
if (!common.hasCrypto)
|
|
common.skip('missing crypto');
|
|
|
|
const assert = require('assert');
|
|
const {
|
|
generateKeyPair,
|
|
} = require('crypto');
|
|
|
|
// Test async elliptic curve key generation with 'jwk' encoding and named
|
|
// curve.
|
|
['P-384', 'P-256', 'P-521', 'secp256k1'].forEach((curve) => {
|
|
generateKeyPair('ec', {
|
|
namedCurve: curve,
|
|
publicKeyEncoding: {
|
|
format: 'jwk'
|
|
},
|
|
privateKeyEncoding: {
|
|
format: 'jwk'
|
|
}
|
|
}, common.mustSucceed((publicKey, privateKey) => {
|
|
assert.strictEqual(typeof publicKey, 'object');
|
|
assert.strictEqual(typeof privateKey, 'object');
|
|
assert.strictEqual(publicKey.x, privateKey.x);
|
|
assert.strictEqual(publicKey.y, privateKey.y);
|
|
assert(!publicKey.d);
|
|
assert(privateKey.d);
|
|
assert.strictEqual(publicKey.kty, 'EC');
|
|
assert.strictEqual(publicKey.kty, privateKey.kty);
|
|
assert.strictEqual(publicKey.crv, curve);
|
|
assert.strictEqual(publicKey.crv, privateKey.crv);
|
|
}));
|
|
});
|