export const MESSAGE_BUFFER_BYTELENGTH: i32 = BLOCKHASH_BYTELENGTH << 10
export const PRV_BUFFER_BYTELENGTH: i32 = KEY_BYTELENGTH
export const PUB_BUFFER_BYTELENGTH: i32 = KEY_BYTELENGTH
-export const OUTPUT_BUFFER_BYTELENGTH: i32 = 256
+export const OUTPUT_BUFFER_BYTELENGTH: i32 = 341
export const SIGNATURE_BUFFER_BYTELENGTH: i32 = SIGNATURE_BYTELENGTH
// Static I/O buffers
return changetype<usize>(MESSAGE_BUFFER)
}
-/** Returns the pointer to the static output buffer (256 bytes). */
+/** Returns the pointer to the static output buffer (341 bytes). */
export function getOutputPointer (): usize {
return changetype<usize>(OUTPUT_BUFFER)
}
*
* The message buffer holds both the block hash and the signature buffer as a
* 96-byte concatenated value. The 32 KiB message buffer cannot be divided
- * evenly by 96, so a conservative 24 KiB is used which supports up to 256 block
- * hash/signature pairs.
+ * evenly by 96, so up to 341 block hash/signature pairs are supported with an
+ * extra 32 bytes left at the end.
*
* 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 256
+ * @param {i32} count Number of signatures to verify, up to 341
*/
export function verify_blocks (count: i32): void {
if (count < 1 || OUTPUT_BUFFER_BYTELENGTH < count) {
/**
* Nano block signature bulk verification using WebAssembly.
* @param {Uint8Array<ArrayBuffer>} publicKey - 32-byte public key
- * @param {object[]} blocks - Array of up to 256 block hash/signature pairs
+ * @param {object[]} blocks - Array of up to 341 block hash/signature pairs
* @param {Uint8Array<ArrayBuffer>} blocks.hash - 32-byte block hash
* @param {Uint8Array<ArrayBuffer>} blocks.signature - 64-byte block signature
* @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 256 block hash/signature pairs
+ * @param {object[]} blocks - Array of up to 341 block hash/signature pairs
* @param {string} blocks.hash - 64-character hexadecimal block hash
* @param {string} blocks.signature - 128-character hexadecimal block signature
* @returns Array of results with, for each case, true if signature matches block hash and public key, else false
publicKey = derive(privateKey, 'nano25519')
signature = sign(blockHash, privateKey, publicKey, 'nano25519')
const blocks = []
- for (let i = 0; i < 256; i++) {
+ for (let i = 0; i < 341; i++) {
blocks[i] = { hash: blockHash, signature }
}
start = performance.now()
if (verified.some(v => v !== true)) {
throw new Error(`invalid result\nsignature: ${signature}\nblock hash: ${blockHash}\npublic key: ${publicKey}`)
}
- duration = (end - start) / 256
+ duration = (end - start) / 341
deriveTimes[i].push(0)
signTimes[i].push(0)
verifyTimes[i].push(duration)
try {
const blocks = []
- for (let i = 0; i < 256; i++) {
+ for (let i = 0; i < 341; i++) {
blocks[i] = { hash: NANO_ORG_VECTOR.blockHashBytes, signature: NANO_ORG_VECTOR.signatureBytes }
}
const verified = verify_blocks(NANO_ORG_VECTOR.publicKeyBytes, blocks)
result = false
}
test = result === true
-check(`verify_blocks 256 max`, test)
+check(`verify_blocks 341 max`, test)
passes += +test
failures += +!test
try {
const blocks = []
- for (let i = 0; i < 257; i++) {
+ for (let i = 0; i < 342; i++) {
blocks[i] = { hash: NANO_ORG_VECTOR.blockHashBytes, signature: NANO_ORG_VECTOR.signatureBytes }
}
verify_blocks(NANO_ORG_VECTOR.publicKeyBytes, blocks)
result = false
} catch (err) {
if (err != null && typeof err === 'object' && 'message' in err) {
- result = err.message === 'Bulk Nano block verification must be no more than 256 blocks'
+ result = err.message === 'Bulk Nano block verification must be no more than 341 blocks'
} else {
result = false
}