Skip to content

Commit cfe612c

Browse files
tniessenthedull
authored andcommitted
doc: make Web Crypto example spec compliant
subtle.sign is not supposed to support strings, and in most Web Crypto implementations, it does not. Passing a string as the 'data' argument only works in Node.js, and users should not rely on that oddity. The Web Crypto spec requires the data argument to be a BufferSource, i.e., an ArrayBuffer or an ArrayBufferView. PR-URL: nodejs#41556 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Filip Skokan <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent f365414 commit cfe612c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

doc/api/webcrypto.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ const { subtle } = require('crypto').webcrypto;
1919
length: 256
2020
}, true, ['sign', 'verify']);
2121

22+
const enc = new TextEncoder();
23+
const message = enc.encode('I love cupcakes');
24+
2225
const digest = await subtle.sign({
2326
name: 'HMAC'
24-
}, key, 'I love cupcakes');
27+
}, key, message);
2528

2629
})();
2730
```

0 commit comments

Comments
 (0)