return changetype<usize>(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<usize>(OUTPUT_DERIVE)
}
}
/**
- * 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`
*
* 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
/**
* 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 {
* 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
/**
* Signing using WebAssembly. To sign Nano blocks, the message should be a
* 32-byte block hash.
- * @param {Uint8Array<ArrayBuffer>} msg - Variable-byte-length message up to 32 KiB
+ * @param {Uint8Array<ArrayBuffer>} msg - Variable-byte-length message up to 64 KiB
* @param {Uint8Array<ArrayBuffer>} prv - 32-byte private key
* @param {Uint8Array<ArrayBuffer>} pub - 32-byte public key
* @returns 64-byte detached signature
/**
* 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
* 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<ArrayBuffer>} msg - Variable-byte-length message up to 32 KiB
+ * @param {Uint8Array<ArrayBuffer>} msg - Variable-byte-length message up to 64 KiB
* @param {Uint8Array<ArrayBuffer>} prv - 32-byte private key
* @param {Uint8Array<ArrayBuffer>} pub - 32-byte public key
* @param {Uint8Array<ArrayBuffer>} out - buffer to receive 64-byte detached signature
* Signature verification using WebAssembly. To verify Nano block signatures,
* use `verify_blocks()` instead.
* @param {Uint8Array<ArrayBuffer>} sig - 64-byte detached signature
- * @param {Uint8Array<ArrayBuffer>} msg - Variable-byte-length message up to 32 KiB
+ * @param {Uint8Array<ArrayBuffer>} msg - Variable-byte-length message up to 64 KiB
* @param {Uint8Array<ArrayBuffer>} pub - 32-byte public key
* @returns true if signature matches block hash and public key, else false
*/
* Signature verification using WebAssembly. To verify Nano block signatures,
* the message should be a 64-character block hash.
* @param {string} sig - 128-character hexadecimal detached signature
- * @param {string} msg - Variable-length message up to 32 KiB
+ * @param {string} msg - Variable-length message up to 64 KiB
* @param {string} pub - 64-character hexadecimal public key
* @returns true if signature matches block hash and public key, else false
*/
/**
* Nano block signature bulk verification using WebAssembly.
* @param {Uint8Array<ArrayBuffer>} 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<ArrayBuffer>} blocks.signature - 64-byte block signature
* @param {Uint8Array<ArrayBuffer>} 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
/**
* 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
const { INPUT_MSG, INPUT_PRV, INPUT_PUB, OUTPUT_SIGN, } = pointers
export function sign (msg: unknown, prv: unknown, pub: unknown, out?: unknown): string | Uint8Array<ArrayBuffer> | void {
- if (typeof out !== 'undefined' && !(isBytes(out) && out.byteLength === 64)) {
- throw new TypeError('Sign output buffer must be 64-byte Uint8Array<ArrayBuffer>')
+ if (typeof out !== 'undefined' && !(isBytes(out) && out.byteLength === SIGNATURE_BYTELENGTH)) {
+ throw new TypeError(`Sign output buffer must be ${SIGNATURE_BYTELENGTH}-byte Uint8Array<ArrayBuffer>`)
}
const message = normalize('message', 0, MAX_MESSAGE_BYTELENGTH, msg)
const privateKey = normalize('private key', KEY_BYTELENGTH, KEY_BYTELENGTH, prv)