From a1ed6f589ef07fb4fb74177d2be94efdb5dace9d Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sat, 17 Oct 2026 00:19:01 -0700 Subject: [PATCH] Force V8 copy of small buffer from the heap at instantiation while buffer is zero-initialized. --- src/lib/bytes.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/lib/bytes.ts b/src/lib/bytes.ts index 567650a..5be3e6c 100644 --- a/src/lib/bytes.ts +++ b/src/lib/bytes.ts @@ -19,6 +19,7 @@ import { Nano25519RangeError, Nano25519TypeError, } from './errors' export type Bytes = Uint8Array export type Words = Uint32Array +const Buffer = ArrayBuffer const Bytes = Uint8Array const Words = Uint32Array const TypedArray = Object.getPrototypeOf(Bytes.prototype) @@ -40,7 +41,7 @@ const getTag = getter(TypedArray, Symbol.toStringTag) /** Reads internal slot `[[ViewedArrayBuffer]]`. */ const getBuffer = getter(TypedArray, 'buffer') /** Throws if passed `SharedArrayBuffer`, distinguishing it from `ArrayBuffer`. */ -const getBufferByteLength = getter(ArrayBuffer.prototype, 'byteLength') +const getBufferByteLength = getter(Buffer.prototype, 'byteLength') /** Reads internal slot `[[ByteLength]]`. */ const getByteLength = getter(TypedArray, 'byteLength') /** Reads internal slot `[[ByteOffset]]`. */ @@ -61,7 +62,8 @@ export function allocate (byteLength: number): Bytes { if (typeof length !== 'number') { throw new Nano25519TypeError('Invalid byte length') } - return new Bytes(length) + const buffer = new Buffer(length) + return new Bytes(buffer) } /** Captured version of `Uint8Array.prototype.byteLength`. */ -- 2.52.0