GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — crypto: alias webcrypto.subtle and webcrypto.getRandomValues on crypto · nodejs/node@d62fe31

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • crypto.md
  • lib
    • crypto.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/crypto.md‎

Copy file name to clipboardExpand all lines: doc/api/crypto.md
+23Lines changed: 23 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -4051,6 +4051,17 @@ const {
40514051
console.log(getHashes()); // ['DSA', 'DSA-SHA', 'DSA-SHA1', ...]
40524052
```
40534053

4054+
### `crypto.getRandomValues(typedArray)`
4055+
4056+
<!-- YAML
4057+
added: REPLACEME
4058+
-->
4059+
4060+
* `typedArray` {Buffer|TypedArray|DataView|ArrayBuffer}
4061+
* Returns: {Buffer|TypedArray|DataView|ArrayBuffer} Returns `typedArray`.
4062+
4063+
A convenient alias for [`crypto.webcrypto.getRandomValues()`][].
4064+
40544065
### `crypto.hkdf(digest, ikm, salt, info, keylen, callback)`
40554066

40564067
<!-- YAML
@@ -5230,6 +5241,16 @@ additional properties can be passed:
52305241

52315242
If the `callback` function is provided this function uses libuv's threadpool.
52325243

5244+
### `crypto.subtle`
5245+
5246+
<!-- YAML
5247+
added: REPLACEME
5248+
-->
5249+
5250+
* Type: {SubtleCrypto}
5251+
5252+
A convenient alias for [`crypto.webcrypto.subtle`][].
5253+
52335254
### `crypto.timingSafeEqual(a, b)`
52345255

52355256
<!-- YAML
@@ -5945,6 +5966,8 @@ See the [list of SSL OP Flags][] for details.
59455966
[`crypto.randomBytes()`]: #cryptorandombytessize-callback
59465967
[`crypto.randomFill()`]: #cryptorandomfillbuffer-offset-size-callback
59475968
[`crypto.scrypt()`]: #cryptoscryptpassword-salt-keylen-options-callback
5969+
[`crypto.webcrypto.getRandomValues()`]: webcrypto.md#cryptogetrandomvaluestypedarray
5970+
[`crypto.webcrypto.subtle`]: webcrypto.md#class-subtlecrypto
59485971
[`decipher.final()`]: #decipherfinaloutputencoding
59495972
[`decipher.update()`]: #decipherupdatedata-inputencoding-outputencoding
59505973
[`diffieHellman.setPublicKey()`]: #diffiehellmansetpublickeypublickey-encoding
Collapse file

‎lib/crypto.js‎

Copy file name to clipboardExpand all lines: lib/crypto.js
+22-2Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,16 @@ const {
119119
getHashes,
120120
setDefaultEncoding,
121121
setEngine,
122-
lazyRequire,
123122
secureHeapUsed,
124123
} = require('internal/crypto/util');
125124
const Certificate = require('internal/crypto/certificate');
126125

126+
let webcrypto;
127+
function lazyWebCrypto() {
128+
webcrypto ??= require('internal/crypto/webcrypto');
129+
return webcrypto;
130+
}
131+
127132
// These helper functions are needed because the constructors can
128133
// use new, in which case V8 cannot inline the recursive constructor call
129134
function createHash(algorithm, options) {
@@ -284,7 +289,22 @@ ObjectDefineProperties(module.exports, {
284289
webcrypto: {
285290
configurable: false,
286291
enumerable: true,
287-
get() { return lazyRequire('internal/crypto/webcrypto').crypto; }
292+
get() { return lazyWebCrypto().crypto; },
293+
set: undefined,
294+
},
295+
296+
subtle: {
297+
configurable: false,
298+
enumerable: true,
299+
get() { return lazyWebCrypto().crypto.subtle; },
300+
set: undefined,
301+
},
302+
303+
getRandomValues: {
304+
configurable: false,
305+
enumerable: true,
306+
get() { return lazyWebCrypto().crypto.getRandomValues; },
307+
set: undefined,
288308
},
289309

290310
// Aliases for randomBytes are deprecated.

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.