node/test/parallel/test-webcrypto-internal-slots.mjs
Filip Skokan d30090b427 crypto: return cached copies from CryptoKey algorithm and usages getters
Fixes: https://github.com/nodejs/node/issues/59534
PR-URL: https://github.com/nodejs/node/pull/59538
Fixes: https://github.com/nodejs/node/issues/59535
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2025-08-21 14:14:57 +00:00

22 lines
831 B
JavaScript

import * as common from '../common/index.mjs';
if (!common.hasCrypto)
common.skip('missing crypto');
import * as assert from 'node:assert';
import * as util from 'node:util';
const { subtle } = globalThis.crypto;
const kp = await subtle.generateKey('Ed25519', true, ['sign', 'verify']);
assert.notStrictEqual(kp.publicKey.algorithm, kp.privateKey.algorithm);
assert.notStrictEqual(kp.publicKey.usages, kp.privateKey.usages);
kp.publicKey.algorithm.name = 'ed25519';
assert.strictEqual(kp.publicKey.algorithm.name, 'ed25519');
kp.publicKey.usages.push('foo');
assert.ok(kp.publicKey.usages.includes('foo'));
assert.ok(util.inspect(kp.publicKey).includes("algorithm: { name: 'Ed25519' }"));
assert.ok(util.inspect(kp.publicKey).includes("usages: [ 'verify' ]"));
await subtle.sign('Ed25519', kp.privateKey, Buffer.alloc(32));