Skip to content

Commit 6b6d0c4

Browse files
tniessendanielleadams
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: #41556 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 8772d33 commit 6b6d0c4

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)