From: Chris Duncan Date: Tue, 25 Aug 2026 12:50:13 +0000 (-0700) Subject: Remove async test calls and concatenated secret key vectors. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=5850a3684479c43f68b75a63bd50dfe00f315d58;p=nano25519.git Remove async test calls and concatenated secret key vectors. --- diff --git a/test/index.html b/test/index.html index d5c8e0f..37bfd2f 100644 --- a/test/index.html +++ b/test/index.html @@ -208,19 +208,13 @@ SPDX-License-Identifier: GPL-3.0-or-later async function sequenceDeriveSignVerify(api, blockHash, privateKey) { let start = 0, end = 0, publicKey = null, signature = null, isValid = false - if (api === 'nano25519 (async)') { - start = performance.now() - publicKey = await derive(privateKey, api) - signature = await sign(blockHash, privateKey, publicKey, api) - isValid = await verify(signature, blockHash, publicKey, api) - end = performance.now() - } else { - start = performance.now() - publicKey = derive(privateKey, api) - signature = sign(blockHash, privateKey, publicKey, api) - isValid = verify(signature, blockHash, publicKey, api) - end = performance.now() - } + + start = performance.now() + publicKey = derive(privateKey, api) + signature = sign(blockHash, privateKey, publicKey, api) + isValid = verify(signature, blockHash, publicKey, api) + end = performance.now() + if (!isValid) { throw new Error(`invalid result\nblock hash: ${blockHash}\nsignature: ${signature}\npublic key: ${publicKey}`) } @@ -257,39 +251,39 @@ SPDX-License-Identifier: GPL-3.0-or-later let result, test, passes = 0, failures = 0 // PASS - result = await nano25519.deriveAsync(NANO_ORG_VECTOR.privateKey) + result = nano25519.derive(NANO_ORG_VECTOR.privateKey) test = result.toLowerCase() === NANO_ORG_VECTOR.publicKey.toLowerCase() - check(`async derive from ${NANO_ORG_VECTOR.privateKey}`, test) + check(`derive from string ${NANO_ORG_VECTOR.privateKey}`, test) passes += +test failures += +!test - result = await nano25519.signAsync(NANO_ORG_VECTOR.blockHash, NANO_ORG_VECTOR.secretKey) + result = nano25519.sign(NANO_ORG_VECTOR.blockHash, NANO_ORG_VECTOR.privateKey, NANO_ORG_VECTOR.publicKey) test = result.toLowerCase() === NANO_ORG_VECTOR.signature.toLowerCase() - check(`async sign message ${NANO_ORG_VECTOR.blockHash}`, test) + check(`sign message string ${NANO_ORG_VECTOR.blockHash}`, test) passes += +test failures += +!test - result = await nano25519.verifyAsync(NANO_ORG_VECTOR.signature, NANO_ORG_VECTOR.blockHash, NANO_ORG_VECTOR.publicKey) + result = nano25519.verify(NANO_ORG_VECTOR.signature, NANO_ORG_VECTOR.blockHash, NANO_ORG_VECTOR.publicKey) test = result === true - check(`async verify signature ${NANO_ORG_VECTOR.signature}`, test) + check(`verify signature string ${NANO_ORG_VECTOR.signature}`, test) passes += +test failures += +!test result = nano25519.derive(NANO_ORG_VECTOR.privateKeyBytes) test = [...result].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === NANO_ORG_VECTOR.publicKey.toLowerCase() - check(`derive from ${NANO_ORG_VECTOR.privateKey}`, test) + check(`derive from bytes ${NANO_ORG_VECTOR.privateKey}`, test) passes += +test failures += +!test - result = nano25519.sign(NANO_ORG_VECTOR.blockHashBytes, NANO_ORG_VECTOR.secretKeyBytes) + result = nano25519.sign(NANO_ORG_VECTOR.blockHashBytes, NANO_ORG_VECTOR.privateKeyBytes, NANO_ORG_VECTOR.publicKeyBytes) test = [...result].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === NANO_ORG_VECTOR.signature.toLowerCase() - check(`sign message ${NANO_ORG_VECTOR.blockHash}`, test) + check(`sign message bytes ${NANO_ORG_VECTOR.blockHash}`, test) passes += +test failures += +!test result = nano25519.verify(NANO_ORG_VECTOR.signatureBytes, NANO_ORG_VECTOR.blockHashBytes, NANO_ORG_VECTOR.publicKeyBytes) test = result === true - check(`verify signature ${NANO_ORG_VECTOR.signature}`, test) + check(`verify signature bytes ${NANO_ORG_VECTOR.signature}`, test) passes += +test failures += +!test @@ -301,7 +295,7 @@ SPDX-License-Identifier: GPL-3.0-or-later passes += +test failures += +!test - result = nano25519.sign(message, privateKey + publicKey) + result = nano25519.sign(message, privateKey, publicKey) test = result.toLowerCase() === signature.slice(0, 128) check(`sign message ${message}`, test) passes += +test @@ -315,7 +309,6 @@ SPDX-License-Identifier: GPL-3.0-or-later const privateKeyBytes = new Uint8Array(privateKey.match(/.{2}/g)?.map(b => parseInt(b, 16)) ?? []) const publicKeyBytes = new Uint8Array(publicKey.match(/.{2}/g)?.map(b => parseInt(b, 16)) ?? []) - const secretKeyBytes = new Uint8Array([...privateKeyBytes, ...publicKeyBytes]) const messageBytes = new Uint8Array(message.match(/.{2}/g)?.map(b => parseInt(b, 16)) ?? []) const signatureBytes = new Uint8Array(signature.match(/.{2}/g)?.slice(0, 64).map(b => parseInt(b, 16)) ?? []) @@ -325,7 +318,7 @@ SPDX-License-Identifier: GPL-3.0-or-later passes += +test failures += +!test - result = nano25519.sign(messageBytes, secretKeyBytes) + result = nano25519.sign(messageBytes, privateKeyBytes, publicKeyBytes) test = [...result].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === signature.slice(0, 128) check(`sign message ${message}`, test) passes += +test @@ -341,7 +334,7 @@ SPDX-License-Identifier: GPL-3.0-or-later // XFAIL try { test = false - result = await nano25519.verifyAsync(NANO_ORG_VECTOR.signature, NANO_ORG_VECTOR.invalidMessageLength, NANO_ORG_VECTOR.publicKey) + result = nano25519.verify(NANO_ORG_VECTOR.signature, NANO_ORG_VECTOR.invalidMessageLength, NANO_ORG_VECTOR.publicKey) } catch (err) { test = true console.log(err) @@ -351,35 +344,35 @@ SPDX-License-Identifier: GPL-3.0-or-later failures += +!test } - result = await nano25519.verifyAsync(NANO_ORG_VECTOR.badSignature, NANO_ORG_VECTOR.blockHash, NANO_ORG_VECTOR.publicKey) + result = nano25519.verify(NANO_ORG_VECTOR.badSignature, NANO_ORG_VECTOR.blockHash, NANO_ORG_VECTOR.publicKey) console.log(result) test = result === false check(`verify() output for non-canonical signature`, test) passes += +test failures += +!test - result = await nano25519.verifyAsync(NANO_ORG_VECTOR.signature, random(), NANO_ORG_VECTOR.publicKey) + result = nano25519.verify(NANO_ORG_VECTOR.signature, random(), NANO_ORG_VECTOR.publicKey) console.log(result) test = result === false check(`verify() output for random block hash`, test) passes += +test failures += +!test - result = await nano25519.verifyAsync(NANO_ORG_VECTOR.signature, zeroes, NANO_ORG_VECTOR.publicKey) + result = nano25519.verify(NANO_ORG_VECTOR.signature, zeroes, NANO_ORG_VECTOR.publicKey) console.log(result) test = result === false check(`verify() output for bad block hash`, test) passes += +test failures += +!test - result = await nano25519.verifyAsync(`${zeroes}${zeroes}`, NANO_ORG_VECTOR.blockHash, NANO_ORG_VECTOR.publicKey) + result = nano25519.verify(`${zeroes}${zeroes}`, NANO_ORG_VECTOR.blockHash, NANO_ORG_VECTOR.publicKey) console.log(result) test = result === false check(`verify() output for bad signature`, test) passes += +test failures += +!test - result = await nano25519.verifyAsync(NANO_ORG_VECTOR.signature, NANO_ORG_VECTOR.blockHash, zeroes) + result = nano25519.verify(NANO_ORG_VECTOR.signature, NANO_ORG_VECTOR.blockHash, zeroes) console.log(result) test = result === false check(`verify() output for bad public key`, test) @@ -508,7 +501,6 @@ SPDX-License-Identifier: GPL-3.0-or-later