Files
scriptc/tests/corpus/6296-array-position-patterns.ts
T
Malte UblandClaude Opus 5.5 2b8cd22423 Add WebCrypto HMAC: crypto.subtle importKey, sign, verify and digest
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>
2026-10-19 05:34:26 -07:00

24 lines
942 B
TypeScript

// Object patterns over arrays that name positions and `length` (jose's
// `const { 0: header, 1: payload, 2: signature, length } = jws.split(".")`):
// each position is the element or undefined past the end, defaults apply
// to missing positions, and `length` is the array's length.
const { 0: header, 1: payload, 2: signature, length } = "aaa.bbb.ccc".split(".");
console.log(header, payload, signature, length);
const short = "aaa.bbb".split(".");
const { 0: first, 2: third, length: count } = short;
console.log(first, third === undefined, count);
const { 1: second = "fallback", 3: fourth = "missing" } = short;
console.log(second, fourth);
function parts(values: number[]): string {
const { 0: a, 1: b, length: n } = values;
return `${a}:${b}:${n}`;
}
console.log(parts([1, 2, 3]), parts([7]));
let renamed = "";
for (const { 0: key, 1: value } of [["x", "1"], ["y", "2"]]) renamed += `${key}=${value};`;
console.log(renamed);