mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-28 06:53:42 +08:00
crypto.subtle.importKey('raw', ...) for HMAC keys, HMAC sign and verify,
and the SHA-1/SHA-2 digests compile through the crypto global, with
CryptoKey values as native handles. scr_webcrypto.c is only the WebCrypto
layer (Web IDL conversion, algorithm normalization, the CryptoKey handle,
promise wrapping and Node's TypeErrors and DOMExceptions) over node:crypto's
digest core and deferred promise queue. It links only into programs that
call these methods (the new webcrypto link feature). Other algorithms, the
jwk format and the other SubtleCrypto methods are SC2020 refusals.
The real jose@6.2.12 HS256 path (SignJWT, jwtVerify) now runs natively. It
also needed four compiler fixes: object patterns of positions and length
over arrays, the Uint8Array base64/hex feature probes, a compile-time
String.fromCharCode.apply, and structuredClone of a parameter whose default
is {}.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
19 lines
638 B
TypeScript
19 lines
638 B
TypeScript
// The native WebCrypto surface is HMAC importKey('raw'), sign and verify,
|
|
// and the SHA-1/SHA-2 digests, called directly on crypto.subtle. The 'jwk'
|
|
// key format and crypto.subtle or its methods taken as values are refused
|
|
// by name; the bundled declarations omit the other SubtleCrypto methods
|
|
// (node-types/fenced.ts pins their fence under @types/node).
|
|
const fromJwk = await crypto.subtle.importKey(
|
|
"jwk",
|
|
{ kty: "oct", k: "c2VjcmV0" },
|
|
{ name: "HMAC", hash: "SHA-256" },
|
|
false,
|
|
["sign"],
|
|
);
|
|
console.log(fromJwk.type);
|
|
|
|
const subtle = crypto.subtle;
|
|
console.log(typeof subtle);
|
|
|
|
console.log(typeof crypto.subtle.sign);
|