From: Chris Duncan Date: Thu, 15 Oct 2026 22:22:01 +0000 (-0700) Subject: Restore typed array captures. X-Git-Tag: v2.0.0~1^2~13 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=c9b5245c832fa90d3404d00553944b54086b613c;p=nano25519.git Restore typed array captures. --- diff --git a/src/lib/bytes.ts b/src/lib/bytes.ts index d0aa12c..2a431ef 100644 --- a/src/lib/bytes.ts +++ b/src/lib/bytes.ts @@ -18,10 +18,12 @@ import { Nano25519RangeError, Nano25519TypeError, } from './errors' export type Bytes = Uint8Array export type Words = Uint32Array -const TypedArray = Object.getPrototypeOf(Uint8Array.prototype) +const Bytes = Uint8Array +const Words = Uint32Array +const TypedArray = Object.getPrototypeOf(Bytes.prototype) -const bytesSet = Function.prototype.call.bind(Uint8Array.prototype.set) -const bytesFill = Function.prototype.call.bind(Uint8Array.prototype.fill) +const bytesSet = Function.prototype.call.bind(Bytes.prototype.set) +const bytesFill = Function.prototype.call.bind(Bytes.prototype.fill) /** An accessor's getter, taking the object to read as its argument. */ function getter (target: object, key: PropertyKey): (self: unknown) => any { @@ -77,7 +79,7 @@ export function isBytes (a: unknown): a is Bytes { } /** True on little-endian system which aligns with WASM spec. */ -export const isLE = new Uint8Array(getBuffer(new Uint32Array([1])))[0] === 1 +export const isLE = new Bytes(getBuffer(new Words([1])))[0] === 1 /** * Enables reading multiple bytes in a single load which is more efficient than @@ -95,7 +97,7 @@ export function words (bytes: Bytes): Words { if (offset !== 0) { throw new Nano25519RangeError('Unexpected byte offset', { cause: offset }) } - return new Uint32Array(getBuffer(bytes) as ArrayBuffer, offset, getByteLength(bytes) >> 2) + return new Words(getBuffer(bytes) as ArrayBuffer, offset, getByteLength(bytes) >> 2) } const charCodeAt = Function.prototype.call.bind(String.prototype.charCodeAt) @@ -173,7 +175,7 @@ export function normalize (name: string, byteLengthMin: number, byteLengthMax: n if (value.length < (byteLengthMin << 1) || value.length > (byteLengthMax << 1)) { throw new Nano25519TypeError(`Invalid hexadecimal length ${value.length} for ${name}`) } - if (typeof out === 'undefined') out = new Uint8Array(value.length >> 1) + if (typeof out === 'undefined') out = new Bytes(value.length >> 1) hexToBytes(out, value) return out } @@ -186,7 +188,7 @@ export function normalize (name: string, byteLengthMin: number, byteLengthMax: n if (byteLength > byteLengthMax) { throw new Nano25519TypeError(`${name} must be no more than ${byteLengthMax} bytes`) } - if (typeof out === 'undefined') out = new Uint8Array(byteLength) + if (typeof out === 'undefined') out = new Bytes(byteLength) copy(out, value) return out }