From 2520824d321db5923213ffa3bab11b83ce7b745e Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 9 Oct 2026 22:43:58 -0700 Subject: [PATCH] Fix documentation. --- scripts/blake2b-gen.mjs | 3 +-- src/assembly/index.ts | 23 ++++++++++------------- src/lib/wasm.ts | 16 +++++++++------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/scripts/blake2b-gen.mjs b/scripts/blake2b-gen.mjs index ef53f62..607027e 100644 --- a/scripts/blake2b-gen.mjs +++ b/scripts/blake2b-gen.mjs @@ -165,8 +165,7 @@ function ROUND (r) { /** * Builds string of code that first initializes the BLAKE2b state vectors and - * then compresses the input message. For Nano proof-of-work, the input is - * only 40 bytes, so compression only happens once. + * then compresses the input message. * * @type {string} API-specific code executing 12 rounds of G mixing */ diff --git a/src/assembly/index.ts b/src/assembly/index.ts index 37dda5d..921047d 100644 --- a/src/assembly/index.ts +++ b/src/assembly/index.ts @@ -9,7 +9,7 @@ import { raise, } from './env' import { BUFFER_INPUT_MSG, BUFFER_INPUT_PRV, BUFFER_INPUT_PUB, BUFFER_INPUT_SIG, BUFFER_OUTPUT_DERIVE, BUFFER_OUTPUT_SIGN, BUFFER_OUTPUT_VERIFY, ERROR_EQUALBYTES_SELFTEST_XFAIL_ONE, ERROR_EQUALBYTES_SELFTEST_XFAIL_PAIR, ERROR_EQUALBYTES_SELFTEST_XPASS, ERROR_FE_ISZERO_SELFTEST_XFAIL, ERROR_FE_ISZERO_SELFTEST_XPASS, ERROR_GE_IS_CANONICAL_SELFTEST_XFAIL, ERROR_GE_IS_CANONICAL_SELFTEST_XPASS, ERROR_INDEX_OUT_OF_RANGE, ERROR_INVALID_BLOCK_COUNT, ERROR_INVALID_MESSAGE_LENGTH, ERROR_INVALID_PUBLIC_KEY, ERROR_UNKNOWN, } from './errors' import './tests' -export { BLOCKHASH_BYTELENGTH, BUFFER_INPUT_MSG, BUFFER_INPUT_PRV, BUFFER_INPUT_PUB, BUFFER_INPUT_SIG, BUFFER_OUTPUT_DERIVE, BUFFER_OUTPUT_SIGN, BUFFER_OUTPUT_VERIFY, ERROR_INDEX_OUT_OF_RANGE, ERROR_INVALID_BLOCK_COUNT, ERROR_INVALID_MESSAGE_LENGTH, ERROR_INVALID_PUBLIC_KEY, ERROR_EQUALBYTES_SELFTEST_XFAIL_ONE, ERROR_EQUALBYTES_SELFTEST_XFAIL_PAIR, ERROR_EQUALBYTES_SELFTEST_XPASS, ERROR_FE_ISZERO_SELFTEST_XFAIL, ERROR_FE_ISZERO_SELFTEST_XPASS, ERROR_GE_IS_CANONICAL_SELFTEST_XFAIL, ERROR_GE_IS_CANONICAL_SELFTEST_XPASS, ERROR_UNKNOWN, KEY_BYTELENGTH, MAX_MESSAGE_BYTELENGTH, MAX_VERIFY_BLOCKS, MAX_VERIFY_BLOCKS_BYTELENGTH, SIGNATURE_BYTELENGTH } +export { BLOCKHASH_BYTELENGTH, BUFFER_INPUT_MSG, BUFFER_INPUT_PRV, BUFFER_INPUT_PUB, BUFFER_INPUT_SIG, BUFFER_OUTPUT_DERIVE, BUFFER_OUTPUT_SIGN, BUFFER_OUTPUT_VERIFY, ERROR_EQUALBYTES_SELFTEST_XFAIL_ONE, ERROR_EQUALBYTES_SELFTEST_XFAIL_PAIR, ERROR_EQUALBYTES_SELFTEST_XPASS, ERROR_FE_ISZERO_SELFTEST_XFAIL, ERROR_FE_ISZERO_SELFTEST_XPASS, ERROR_GE_IS_CANONICAL_SELFTEST_XFAIL, ERROR_GE_IS_CANONICAL_SELFTEST_XPASS, ERROR_INDEX_OUT_OF_RANGE, ERROR_INVALID_BLOCK_COUNT, ERROR_INVALID_MESSAGE_LENGTH, ERROR_INVALID_PUBLIC_KEY, ERROR_UNKNOWN, KEY_BYTELENGTH, MAX_MESSAGE_BYTELENGTH, MAX_VERIFY_BLOCKS, MAX_VERIFY_BLOCKS_BYTELENGTH, SIGNATURE_BYTELENGTH } // Static I/O buffers const INPUT_MSG = new StaticArray(MAX_MESSAGE_BYTELENGTH) @@ -142,14 +142,11 @@ export function derive (): void { } /** - * Sign up to 64 KiB of data using a 64-byte secret key. Parameters are read as - * bytes from the input buffer in the following order: - * - * - `[0,31]: private key` - * - `[32,63]: public key` - * - * The message itself is read from a separate buffer. The signature is detached - * from the message and written to the output buffer. + * Sign up to 64 KiB of data using a 32-byte private key. The 32-byte public key + * is also required for data integrity. Parameters are read as bytes from + * specific input buffers, and the message itself is read from a separate + * buffer. The signature is detached from the message and written to the output + * buffer. * @param {i32} mlen Byte length of message to be signed, up to 65536 */ export function sign (mlen: i32): void { @@ -233,10 +230,10 @@ export function verify (mlen: i32): void { * concatenated value. The performance gain of verifying in bulk scales as * `(1-(1/n)) x (k/(k+r))` where `n` is block count, `k` is the time required to * verify the public key, and `r` is the time required to compute all the - * remaining verification steps. Testing shows `k` to be ~12% the total - * verification time, so batching up to 64 block signature/hash pairs reaches - * ~96% of that gain; any more blocks would simply add latency returning the - * final results. + * remaining verification steps. Testing shows public key derivation to be ~12% + * the total verification time, so batching up to 64 block signature/hash pairs + * reaches ~96% of that gain; any more blocks would simply add latency returning + * the final results. * * All pairs are verified against a single public key. The results are written * to the output buffer in the same order they were received. diff --git a/src/lib/wasm.ts b/src/lib/wasm.ts index 4685b82..c7997e1 100644 --- a/src/lib/wasm.ts +++ b/src/lib/wasm.ts @@ -149,13 +149,15 @@ const setInputMsgEndian = isLE ? setInputMsgWords : setInputMsgShift * written in one pass rather than looped over an intermediate array because * allocating costs more than the copy itself. * - * Whole 32-byte chunks are read a word at a time through a `Uint32Array` view. - * A `Uint32Array` is laid out little-endian on every platform that can run - * WASM, so a word read is already in the order the module's `store` wants - * and needs no shifting — measured over 64 KiB, that takes the loop from ~45 µs - * to ~13 µs, which is the cost of the 2048 boundary crossings alone. The - * remaining bytes, fewer than 32, go through `setInputMsgBytes`, which handles - * the zero padding. + * On little-endian systems, the message input is first read in 32-byte chunks + * as 4-byte words through a `Uint32Array` view, and any remaining bytes are + * read individually through a `Uint8Array`. Big-endian systems read the input + * one byte at a time for the entire message since byte order must be reversed + * to meet WASM spec which is little-endian by definition. + * + * The vast majority of hardware is little-endian and will benefit from the + * word-based capture: measured over 64 KiB, it reduces copy time by ~66% which + * is the cost of the 2048 boundary crossings alone. */ function setInputMsg (message: Bytes): void { const mlen = byteLength(message) -- 2.52.0