Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions doc/api/webcrypto.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,16 @@ filled with random values, and a reference to `typedArray` is returned.

An error will be thrown if the given `typedArray` is larger than 65,536 bytes.

### `crypto.randomUUID()`
<!-- YAML
added: REPLACEME
-->

* Returns: {string}

Generates a random [RFC 4122][] Version 4 UUID. The UUID is generated using a
cryptographic pseudorandom number generator.

## Class: `CryptoKey`
<!-- YAML
added: v15.0.0
Expand Down Expand Up @@ -1771,4 +1781,5 @@ added: v15.0.0

[JSON Web Key]: https://tools.ietf.org/html/rfc7517
[Key usages]: #webcrypto_cryptokey_usages
[RFC 4122]: https://www.rfc-editor.org/rfc/rfc4122.txt
[Web Crypto API]: https://www.w3.org/TR/WebCryptoAPI/
2 changes: 1 addition & 1 deletion lib/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ ObjectDefineProperties(module.exports, {
webcrypto: {
configurable: false,
enumerable: true,
get() { return lazyRequire('internal/crypto/webcrypto'); }
get() { return lazyRequire('internal/crypto/webcrypto').crypto; }
},

// Aliases for randomBytes are deprecated.
Expand Down
15 changes: 14 additions & 1 deletion lib/internal/crypto/webcrypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ const {

const {
getRandomValues,
randomUUID: _randomUUID,
} = require('internal/crypto/random');

const randomUUID = () => _randomUUID();

async function generateKey(
algorithm,
extractable,
Expand Down Expand Up @@ -705,6 +708,12 @@ ObjectDefineProperties(
writable: true,
value: getRandomValues,
},
randomUUID: {
enumerable: true,
configurable: true,
writable: true,
value: randomUUID,
},
CryptoKey: {
enumerable: true,
configurable: true,
Expand Down Expand Up @@ -795,4 +804,8 @@ ObjectDefineProperties(
}
});

module.exports = crypto;
module.exports = {
Crypto,
SubtleCrypto,
crypto,
};
3 changes: 2 additions & 1 deletion test/fixtures/wpt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ Last update:
- html/webappapis/atob: https://github.com/web-platform-tests/wpt/tree/f267e1dca6/html/webappapis/atob
- html/webappapis/microtask-queuing: https://github.com/web-platform-tests/wpt/tree/2c5c3c4c27/html/webappapis/microtask-queuing
- html/webappapis/timers: https://github.com/web-platform-tests/wpt/tree/5873f2d8f1/html/webappapis/timers
- interfaces: https://github.com/web-platform-tests/wpt/tree/80a4176623/interfaces
- interfaces: https://github.com/web-platform-tests/wpt/tree/fc086c82d5/interfaces
- performance-timeline: https://github.com/web-platform-tests/wpt/tree/17ebc3aea0/performance-timeline
- resources: https://github.com/web-platform-tests/wpt/tree/972ca5b669/resources
- streams: https://github.com/web-platform-tests/wpt/tree/8f60d94439/streams
- url: https://github.com/web-platform-tests/wpt/tree/77d54aa9e0/url
- user-timing: https://github.com/web-platform-tests/wpt/tree/df24fb604e/user-timing
- WebCryptoAPI: https://github.com/web-platform-tests/wpt/tree/cdd0f03df4/WebCryptoAPI

[Web Platform Tests]: https://github.com/web-platform-tests/wpt
[`git node wpt`]: https://github.com/nodejs/node-core-utils/blob/main/docs/git-node.md#git-node-wpt
3 changes: 3 additions & 0 deletions test/fixtures/wpt/WebCryptoAPI/META.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
spec: https://w3c.github.io/webcrypto/
suggested_reviewers:
- twiss
1 change: 1 addition & 0 deletions test/fixtures/wpt/WebCryptoAPI/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Directory for Crypto API tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// META: title=WebCryptoAPI: deriveBits() Using ECDH
// META: script=ecdh_bits.js

// Define subtests from a `promise_test` to ensure the harness does not
// complete before the subtests are available. `explicit_done` cannot be used
// for this purpose because the global `done` function is automatically invoked
// by the WPT infrastructure in dedicated worker tests defined using the
// "multi-global" pattern.
promise_test(define_tests, 'setup - define tests');
268 changes: 268 additions & 0 deletions test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/ecdh_bits.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// META: title=WebCryptoAPI: deriveKey() Using ECDH
// META: script=ecdh_keys.js

// Define subtests from a `promise_test` to ensure the harness does not
// complete before the subtests are available. `explicit_done` cannot be used
// for this purpose because the global `done` function is automatically invoked
// by the WPT infrastructure in dedicated worker tests defined using the
// "multi-global" pattern.
promise_test(define_tests, 'setup - define tests');
237 changes: 237 additions & 0 deletions test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/ecdh_keys.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions test/fixtures/wpt/WebCryptoAPI/derive_bits_keys/hkdf.https.any.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// META: title=WebCryptoAPI: deriveBits() and deriveKey() Using HKDF
// META: variant=?1-1000
// META: variant=?1001-2000
// META: variant=?2001-3000
// META: variant=?3001-last
// META: script=/common/subset-tests.js
// META: script=hkdf_vectors.js
// META: script=hkdf.js

// Define subtests from a `promise_test` to ensure the harness does not
// complete before the subtests are available. `explicit_done` cannot be used
// for this purpose because the global `done` function is automatically invoked
// by the WPT infrastructure in dedicated worker tests defined using the
// "multi-global" pattern.
promise_test(define_tests, 'setup - define tests');
Loading