From f6f17ace008ad9625bd6f66388dac81ad9db1547 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Thu, 15 Oct 2026 14:08:45 -0700 Subject: [PATCH] Fix verify_blocks output and truncate byte accessors description header. --- src/index.ts | 2 +- src/lib/bytes.ts | 43 ++++++++----------------------------------- 2 files changed, 9 insertions(+), 36 deletions(-) diff --git a/src/index.ts b/src/index.ts index ae2e472..af8c128 100644 --- a/src/index.ts +++ b/src/index.ts @@ -70,7 +70,7 @@ export function verify (sig: Bytes | string, msg: Bytes | string, pub: Bytes | s * @param {(Bytes | string)} blocks.hash - 32-byte block hash * @returns Array of results with, for each case, true if signature matches block hash and public key, else false */ -export function verify_blocks (publicKey: Bytes | string, blocks: { signature: Bytes | string, hash: Bytes | string }[]): boolean[] { +export function verify_blocks (publicKey: Bytes | string, blocks: { signature: Bytes | string, hash: Bytes | string }[]): readonly boolean[] { return nano25519.verify_blocks(publicKey, blocks) } diff --git a/src/lib/bytes.ts b/src/lib/bytes.ts index 0bfaeff..d0aa12c 100644 --- a/src/lib/bytes.ts +++ b/src/lib/bytes.ts @@ -4,41 +4,14 @@ import { Nano25519RangeError, Nano25519TypeError, } from './errors' /** - * Builtins captured once, when this module is evaluated, so that nothing on a - * call path resolves a global or a prototype method that hostile code could - * have replaced in the meantime. - * - * Two distinct protections are at work here and they need different captures: - * - * - Binding a constructor (`Bytes`) defends against later reassignment of the - * global, because call sites read this binding instead of looking up - * `Uint8Array` afresh on every call. - * - Binding a method or accessor defends against later patching of the - * prototype, because the function reference is frozen rather than resolved - * through the object at call time. - * - * Neither defends against code that runs *before* this module is evaluated. - * That is out of scope: a same-realm attacker who loads first can replace the - * package's exports outright, and no copy strategy inside the library changes - * that. What this does close is the caller-controlled surface — a hostile - * `Uint8Array` subclass reaching input validation through `Symbol.species`, an - * overridden `length`, or a spoofed `byteLength`. - * - * Accessors taken from `%TypedArray%.prototype` read internal slots, so a - * subclass cannot lie to them. Prefer them to the equivalent property access - * everywhere in this package. - * - * Only capture what is used *after* this module finishes evaluating. Anything - * used solely to build the tables below runs while the realm is still as - * trustworthy as it will ever be, so binding it first buys nothing — and - * pretending otherwise makes this file harder to audit, not safer. That is why - * `Object.getOwnPropertyDescriptor`, `Object.getPrototypeOf` and - * `Object.create` appear here as plain globals. - * - * This module must stay free of imports. It is the trust root, so it has to - * finish evaluating before anything that uses it: give it a dependency and the - * bundler will order that dependency first, and any call it makes into here - * during its own evaluation will read captures that are still unassigned. + * Prototype methods and accessors used on a call path, captured once when this + * module is evaluated and called through a bound `Function.prototype.call`, so + * that code patching a prototype afterwards cannot change what is validated, + * copied, scrubbed or decoded. The `%TypedArray%.prototype` getters also read + * internal slots, which a caller's subclass cannot override, so use these + * helpers on every typed array instead of its own properties. Global + * constructors and static functions are looked up at call time; replacing them, + * or running before this module, is out of scope. */ /** Type aliases for legibility. */ -- 2.52.0