8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 53f02cf commit c9747f1Copy full SHA for c9747f1
.eslintrc.js
@@ -239,6 +239,12 @@ module.exports = {
239
selector: "CallExpression[callee.name='isNaN']",
240
message: 'Use Number.isNaN() instead of the global isNaN() function.',
241
},
242
+ {
243
+ // TODO(@panva): move this to no-restricted-properties
244
+ // when https://github.com/eslint/eslint/issues/16412 is fixed
245
+ selector: "Identifier[name='webcrypto']",
246
+ message: 'Use `globalThis.crypto`.',
247
+ },
248
],
249
'no-return-await': 'error',
250
'no-self-compare': 'error',
benchmark/crypto/webcrypto-digest.js
@@ -1,11 +1,8 @@
1
'use strict';
2
3
const common = require('../common.js');
4
-const {
5
- createHash,
6
- webcrypto,
7
-} = require('crypto');
8
-const { subtle } = webcrypto;
+const { createHash } = require('crypto');
+const { subtle } = globalThis.crypto;
9
10
const bench = common.createBenchmark(main, {
11
sync: ['createHash', 'subtle'],
@@ -48,7 +45,7 @@ function measureSubtle(n, data, method) {
48
45
}
49
46
50
47
function main({ n, sync, data, method }) {
51
- data = webcrypto.getRandomValues(Buffer.alloc(data));
+ data = globalThis.crypto.getRandomValues(Buffer.alloc(data));
52
switch (sync) {
53
case 'createHash': return measureLegacy(n, data, method);
54
case 'subtle': return measureSubtle(n, data, method);
test/.eslintrc.yaml
@@ -49,6 +49,8 @@ rules:
message: Use 'test' as debuglog value in tests.
- selector: CallExpression:matches([callee.object.name="common"][callee.property.name=/^mustCall/],[callee.name="mustCall"],[callee.name="mustCallAtLeast"])>:first-child[type=/FunctionExpression$/][body.body.length=0]
message: Do not use an empty function, omit the parameter altogether.
+ - selector: Identifier[name='webcrypto']
+ message: Use `globalThis.crypto`.
55
# Custom rules in tools/eslint-rules
56
node-core/prefer-assert-iferror: error
test/parallel/test-crypto-psychic-signatures.js
@@ -80,14 +80,14 @@ for (const [encoding, signatures] of Object.entries(vectors)) {
80
);
81
82
// webcrypto
83
- crypto.webcrypto.subtle.importKey(
+ globalThis.crypto.subtle.importKey(
84
'spki',
85
keyPair.publicKey,
86
{ name: 'ECDSA', namedCurve: 'P-256' },
87
false,
88
['verify'],
89
).then((publicKey) => {
90
- return crypto.webcrypto.subtle.verify(
+ return globalThis.crypto.subtle.verify(
91
{ name: 'ECDSA', hash: 'SHA-256' },
92
publicKey,
93
signature,
test/parallel/test-crypto-random.js
@@ -28,7 +28,6 @@ if (!common.hasCrypto)
28
29
const assert = require('assert');
30
const crypto = require('crypto');
31
-const cryptop = require('crypto').webcrypto;
32
const { kMaxLength } = require('buffer');
33
34
const kMaxInt32 = 2 ** 31 - 1;
@@ -107,7 +106,7 @@ common.expectWarning('DeprecationWarning',
107
106
new Uint32Array(10),
108
].forEach((buf) => {
109
const before = Buffer.from(buf.buffer).toString('hex');
110
- cryptop.getRandomValues(buf);
+ globalThis.crypto.getRandomValues(buf);
111
const after = Buffer.from(buf.buffer).toString('hex');
112
assert.notStrictEqual(before, after);
113
});
test/parallel/test-crypto-subtle-zero-length.js
@@ -6,18 +6,18 @@ if (!common.hasCrypto)
common.skip('missing crypto');
-const crypto = require('crypto').webcrypto;
(async () => {
12
- const k = await crypto.subtle.importKey(
+ const k = await subtle.importKey(
13
'raw',
14
new Uint8Array(32),
15
{ name: 'AES-GCM' },
16
17
[ 'encrypt', 'decrypt' ]);
18
assert(k instanceof CryptoKey);
19
20
- const e = await crypto.subtle.encrypt({
+ const e = await subtle.encrypt({
21
name: 'AES-GCM',
22
iv: new Uint8Array(12),
23
}, k, new Uint8Array(0));
@@ -28,7 +28,7 @@ const crypto = require('crypto').webcrypto;
0x53, 0x0f, 0x8a, 0xfb, 0xc7, 0x45, 0x36, 0xb9,
0xa9, 0x63, 0xb4, 0xf1, 0xc4, 0xcb, 0x73, 0x8b ]));
- const v = await crypto.subtle.decrypt({
+ const v = await subtle.decrypt({
}, k, e);
test/parallel/test-crypto-webcrypto-aes-decrypt-tag-too-small.js
@@ -6,9 +6,9 @@ if (!common.hasCrypto)
-crypto.subtle.importKey(
+subtle.importKey(
{
@@ -18,7 +18,7 @@ crypto.subtle.importKey(
[ 'encrypt', 'decrypt' ])
.then((k) => {
assert.rejects(() => {
- return crypto.subtle.decrypt({
+ return subtle.decrypt({
24
test/parallel/test-global-webcrypto-classes.js
@@ -6,8 +6,9 @@ if (!common.hasCrypto)
-const webcrypto = require('internal/crypto/webcrypto');
+/* eslint-disable no-restricted-syntax */
+const webcrypto = require('internal/crypto/webcrypto');
assert.strictEqual(Crypto, webcrypto.Crypto);
assert.strictEqual(CryptoKey, webcrypto.CryptoKey);
assert.strictEqual(SubtleCrypto, webcrypto.SubtleCrypto);
test/parallel/test-global-webcrypto.js
@@ -7,6 +7,7 @@ if (!common.hasCrypto)
assert.strictEqual(globalThis.crypto, crypto.webcrypto);
assert.strictEqual(Crypto, crypto.webcrypto.constructor);
assert.strictEqual(SubtleCrypto, crypto.webcrypto.subtle.constructor);
test/parallel/test-webcrypto-constructors.js
@@ -6,6 +6,7 @@ if (!common.hasCrypto)
// Test CryptoKey constructor
@@ -137,15 +138,15 @@ const notSubtle = Reflect.construct(function() {}, [], SubtleCrypto);
137
138
139
140
- globalThis.crypto.subtle.importKey(
141
+ subtle.importKey(
142
143
globalThis.crypto.getRandomValues(new Uint8Array(4)),
144
'PBKDF2',
145
146
['deriveKey'],
147
).then((key) => {
- globalThis.crypto.subtle.importKey = common.mustNotCall();
148
- return globalThis.crypto.subtle.deriveKey({
+ subtle.importKey = common.mustNotCall();
149
+ return subtle.deriveKey({
150
name: 'PBKDF2',
151
hash: 'SHA-512',
152
salt: globalThis.crypto.getRandomValues(new Uint8Array()),