From: Chris Duncan Date: Wed, 19 Aug 2026 23:16:58 +0000 (-0700) Subject: Remove unused array and update documentation. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=62f9f6f6696e99df361a5099b2701ab87f5b0575;p=nano25519.git Remove unused array and update documentation. --- diff --git a/src/assembly/index.ts b/src/assembly/index.ts index 42f0f21..87448d0 100644 --- a/src/assembly/index.ts +++ b/src/assembly/index.ts @@ -65,7 +65,6 @@ function crypto_derive (A: StaticArray, key: StaticArray): void { s.fill(0) } -const crypto_sign_A = new StaticArray(32) const crypto_sign_h = new StaticArray(64) const crypto_sign_s = new StaticArray(32) const crypto_sign_prefix = new StaticArray(32) @@ -86,10 +85,11 @@ const crypto_sign_S = new StaticArray(64) * * https://www.rfc-editor.org/info/rfc8032/#section-5.1.6 * - * @param RS 64-byte output buffer for detached signature - * @param M variable-length message to be signed - * @param mlen bytelength of `m` - * @param sk 64-byte input buffer of private+public key concatenation + * @param {StaticArray} RS 64-byte output buffer for detached signature + * @param {StaticArray} M variable-length message to be signed + * @param {i32} mlen bytelength of `m` + * @param {StaticArray} key 32-byte private key from input buffer + * @param {StaticArray} A 32-byte public key from input buffer */ function crypto_sign (RS: StaticArray, M: StaticArray, mlen: i32, key: StaticArray, A: StaticArray): void { const h = crypto_sign_h @@ -185,24 +185,29 @@ function crypto_verify (s: StaticArray, m: usize, mlen: i32, pub: StaticArra return ge_has_small_order(check) - 1 } -// Returns the pointer to the static output buffer (64 bytes). +/** Returns the pointer to the static output buffer (64 bytes). */ export function getOutputPointer (): usize { return OUTPUT_BUFFER } -// Returns the pointer to the static input buffer (128 bytes). +/** Returns the pointer to the static input buffer (128 bytes). */ export function getInputPointer (): usize { return INPUT_BUFFER } -// Returns the pointer to the static message buffer (32 KiB). +/** Returns the pointer to the static message buffer (32 KiB). */ export function getMessagePointer (): usize { return MESSAGE_BUFFER } /** - * Uses a private key to derive a Nano public key which is then written to the - * static output buffer. + * Derive a 32-byte Nano public key from a 32-byte private key. Parameters are + * read as bytes from the input buffer in the following order: + * + * - `[0,31]: private key` + * - `[32,63]: public key` + * + * The public key is written to the output buffer. */ export function derive (): void { const pub = changetype>(OUTPUT_BUFFER) @@ -216,11 +221,15 @@ const sign_s = new StaticArray(SIGNATURE_BYTES) const sign_prv = new StaticArray(PRIVATEKEY_BYTES) const sign_pub = new StaticArray(PUBLICKEY_BYTES) /** - * Retrieve up to 32 KiB of data from the message buffer and a 64-byte secret - * key from the input buffer, and then sign the message using a secret key. The - * signature is detached from the message and written to the output buffer. + * Sign up to 32 KiB of data using a 64-byte secret key. Parameters are read as + * bytes from the input buffer in the following order: * - * @param {i32} mlen - Byte length of message, up to 32768 + * - `[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. + * @param {i32} mlen Byte length of message to be signed, up to 32768 */ export function sign (mlen: i32): void { if (mlen < 0 || mlen > 32768) throw new Error() @@ -242,11 +251,16 @@ export function sign (mlen: i32): void { const verify_s = new StaticArray(SIGNATURE_BYTES) const verify_k = new StaticArray(PUBLICKEY_BYTES) /** - * Verify a detached signature for a message against a public key. + * Verify a 64-byte detached signature for a variable-length message against a + * 32-byte public key. Parameters are read as bytes from the input buffer in the + * following order: + * + * - `[0,63]: signature` + * - `[64,95]: public key` * - * @param {u64} s - 64-byte signature - * @param {u64} m - Message that was signed (variable byte-length up to 32 KiB) - * @param {u64} k - 32-byte public key + * The message itself is read from a separate buffer. + * @param {u64} mlen Byte length of message that was signed, up to 32768 + * @returns {boolean} True if message was signed by public key's private key */ export function verify (mlen: i32): i32 { if (mlen < 0 || mlen > 32768) throw new Error('invalid message length')