]> git.codecow.com Git - nano25519.git/commitdiff
Remove unused array and update documentation.
authorChris Duncan <chris@codecow.com>
Wed, 19 Aug 2026 23:16:58 +0000 (16:16 -0700)
committerChris Duncan <chris@codecow.com>
Wed, 19 Aug 2026 23:16:58 +0000 (16:16 -0700)
src/assembly/index.ts

index 42f0f2174af4a39157bdb6d57550e33e6e7f7350..87448d0a2d13ac5681f240f82fb19da2d0739383 100644 (file)
@@ -65,7 +65,6 @@ function crypto_derive (A: StaticArray<u8>, key: StaticArray<u8>): void {
        s.fill(0)
 }
 
-const crypto_sign_A = new StaticArray<u8>(32)
 const crypto_sign_h = new StaticArray<u8>(64)
 const crypto_sign_s = new StaticArray<u8>(32)
 const crypto_sign_prefix = new StaticArray<u8>(32)
@@ -86,10 +85,11 @@ const crypto_sign_S = new StaticArray<u8>(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<u8>} RS 64-byte output buffer for detached signature
+ * @param {StaticArray<u8>} M variable-length message to be signed
+ * @param {i32} mlen bytelength of `m`
+ * @param {StaticArray<u8>} key 32-byte private key from input buffer
+ * @param {StaticArray<u8>} A 32-byte public key from input buffer
  */
 function crypto_sign (RS: StaticArray<u8>, M: StaticArray<u8>, mlen: i32, key: StaticArray<u8>, A: StaticArray<u8>): void {
        const h = crypto_sign_h
@@ -185,24 +185,29 @@ function crypto_verify (s: StaticArray<u8>, 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<StaticArray<u8>>(OUTPUT_BUFFER)
@@ -216,11 +221,15 @@ const sign_s = new StaticArray<u8>(SIGNATURE_BYTES)
 const sign_prv = new StaticArray<u8>(PRIVATEKEY_BYTES)
 const sign_pub = new StaticArray<u8>(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<u8>(SIGNATURE_BYTES)
 const verify_k = new StaticArray<u8>(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')