From e1e5115d167a3a6337f039620344137aeb9434b2 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 28 Aug 2026 23:47:19 -0700 Subject: [PATCH] Fix documentation of constants. --- src/assembly/index.ts | 14 +++++++------- src/index.ts | 14 +++++++------- src/lib/sign.ts | 4 ++-- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/assembly/index.ts b/src/assembly/index.ts index f8ed6c6..b827b8a 100644 --- a/src/assembly/index.ts +++ b/src/assembly/index.ts @@ -45,7 +45,7 @@ export function ptrInputSig (): usize { return changetype(INPUT_SIG) } -/** Returns a pointer to the derive() static output buffer (64 bytes). */ +/** Returns a pointer to the derive() static output buffer (32 bytes). */ export function ptrOutputDerive (): usize { return changetype(OUTPUT_DERIVE) } @@ -97,7 +97,7 @@ export function derive (): void { } /** - * Sign up to 32 KiB of data using a 64-byte secret key. Parameters are read as + * 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` @@ -105,7 +105,7 @@ export function derive (): void { * * 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 32768 + * @param {i32} mlen Byte length of message to be signed, up to 65536 */ export function sign (mlen: i32): void { // Clear output buffer so errors do not retain stale prior data @@ -146,7 +146,7 @@ export function sign (mlen: i32): void { /** * Verify a 64-byte detached signature for a variable-length message against a * 32-byte public key. Input parameters are read as bytes from separate buffers. - * @param {i32} mlen Byte length of message that was signed, up to 32768 + * @param {i32} mlen Byte length of message that was signed, up to 65536 * @returns {boolean} True if message was signed by public key's private key */ export function verify (mlen: i32): void { @@ -187,14 +187,14 @@ 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 ~8.5% the total - * verification time, so batching up to 32 block signature/hash pairs reaches + * 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. * * All pairs are verified against a single public key. The results are written * to the output buffer in the same order they were received. - * @param {i32} count Number of signatures to verify, up to 32 + * @param {i32} count Number of signatures to verify, up to 64 */ export function verify_blocks (count: i32): void { // Set all output to false so errors fail closed diff --git a/src/index.ts b/src/index.ts index c4ef6a9..8d00b9e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -32,7 +32,7 @@ export function derive (prv: string | Uint8Array, out?: Uint8Array< /** * Signing using WebAssembly. To sign Nano blocks, the message should be a * 32-byte block hash. - * @param {Uint8Array} msg - Variable-byte-length message up to 32 KiB + * @param {Uint8Array} msg - Variable-byte-length message up to 64 KiB * @param {Uint8Array} prv - 32-byte private key * @param {Uint8Array} pub - 32-byte public key * @returns 64-byte detached signature @@ -41,7 +41,7 @@ export function sign (msg: Uint8Array, prv: Uint8Array /** * Signing using WebAssembly. To sign Nano blocks, the message should be a * 64-character hexadecimal block hash. - * @param {string} msg - Variable-length hexadecimal message up to 32 KiB + * @param {string} msg - Variable-length hexadecimal message up to 64 KiB * @param {string} prv - 64-character hexadecimal private key * @param {string} pub - 64-character hexadecimal public key * @returns 128-character hexadecimal detached signature @@ -52,7 +52,7 @@ export function sign (msg: string, prv: string, pub: string): string * 32-byte block hash. Instead of allocating an output buffer internally for the * return value, signature bytes are written to the the user-supplied output * buffer. - * @param {Uint8Array} msg - Variable-byte-length message up to 32 KiB + * @param {Uint8Array} msg - Variable-byte-length message up to 64 KiB * @param {Uint8Array} prv - 32-byte private key * @param {Uint8Array} pub - 32-byte public key * @param {Uint8Array} out - buffer to receive 64-byte detached signature @@ -66,7 +66,7 @@ export function sign (msg: string | Uint8Array, prv: string | Uint8 * Signature verification using WebAssembly. To verify Nano block signatures, * use `verify_blocks()` instead. * @param {Uint8Array} sig - 64-byte detached signature - * @param {Uint8Array} msg - Variable-byte-length message up to 32 KiB + * @param {Uint8Array} msg - Variable-byte-length message up to 64 KiB * @param {Uint8Array} pub - 32-byte public key * @returns true if signature matches block hash and public key, else false */ @@ -75,7 +75,7 @@ export function verify (sig: Uint8Array, msg: Uint8Array, msg: string | Uin /** * Nano block signature bulk verification using WebAssembly. * @param {Uint8Array} publicKey - 32-byte public key - * @param {object[]} blocks - Array of up to 32 block signature/hash pairs + * @param {object[]} blocks - Array of up to 64 block signature/hash pairs * @param {Uint8Array} blocks.signature - 64-byte block signature * @param {Uint8Array} 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 @@ -96,7 +96,7 @@ export function verify_blocks (publicKey: Uint8Array, blocks: { has /** * Nano block signature bulk verification using WebAssembly. * @param {string} publicKey - 64-character hexadecimal public key - * @param {object[]} blocks - Array of up to 32 block signature/hash pairs + * @param {object[]} blocks - Array of up to 64 block signature/hash pairs * @param {string} blocks.signature - 128-character hexadecimal block signature * @param {string} blocks.hash - 64-character hexadecimal block hash * @returns Array of results with, for each case, true if signature matches block hash and public key, else false diff --git a/src/lib/sign.ts b/src/lib/sign.ts index 9b543e7..832e5a5 100644 --- a/src/lib/sign.ts +++ b/src/lib/sign.ts @@ -7,8 +7,8 @@ const { KEY_BYTELENGTH, MAX_MESSAGE_BYTELENGTH, SIGNATURE_BYTELENGTH, } = consta const { INPUT_MSG, INPUT_PRV, INPUT_PUB, OUTPUT_SIGN, } = pointers export function sign (msg: unknown, prv: unknown, pub: unknown, out?: unknown): string | Uint8Array | void { - if (typeof out !== 'undefined' && !(isBytes(out) && out.byteLength === 64)) { - throw new TypeError('Sign output buffer must be 64-byte Uint8Array') + if (typeof out !== 'undefined' && !(isBytes(out) && out.byteLength === SIGNATURE_BYTELENGTH)) { + throw new TypeError(`Sign output buffer must be ${SIGNATURE_BYTELENGTH}-byte Uint8Array`) } const message = normalize('message', 0, MAX_MESSAGE_BYTELENGTH, msg) const privateKey = normalize('private key', KEY_BYTELENGTH, KEY_BYTELENGTH, prv) -- 2.52.0