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}`)
}
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
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
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)) ?? [])
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
// 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)
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)
<label for="api">API</label>
<select id="api">
<option>nano25519</option>
- <option>nano25519 (async)</option>
<option>NanocurrencyWeb</option>
<option>Sodium</option>
<option>TweetNaCl.js</option>
privateKeyBytes: new Uint8Array([0x78, 0x11, 0x86, 0xFB, 0x9E, 0xF1, 0x7D, 0xB6, 0xE3, 0xD1, 0x05, 0x65, 0x50, 0xD9, 0xFA, 0xE5, 0xD5, 0xBB, 0xAD, 0xA6, 0xA6, 0xBC, 0x37, 0x0E, 0x4C, 0xBB, 0x93, 0x8B, 0x1D, 0xC7, 0x1D, 0xA3]),
publicKey: '3068BB1CA04525BB0E416C485FE6A67FD52540227D267CC8B6E8DA958A7FA039',
publicKeyBytes: new Uint8Array([0x30, 0x68, 0xBB, 0x1C, 0xA0, 0x45, 0x25, 0xBB, 0x0E, 0x41, 0x6C, 0x48, 0x5F, 0xE6, 0xA6, 0x7F, 0xD5, 0x25, 0x40, 0x22, 0x7D, 0x26, 0x7C, 0xC8, 0xB6, 0xE8, 0xDA, 0x95, 0x8A, 0x7F, 0xA0, 0x39]),
- secretKey: '781186FB9EF17DB6E3D1056550D9FAE5D5BBADA6A6BC370E4CBB938B1DC71DA33068BB1CA04525BB0E416C485FE6A67FD52540227D267CC8B6E8DA958A7FA039',
- secretKeyBytes: new Uint8Array([0x78, 0x11, 0x86, 0xFB, 0x9E, 0xF1, 0x7D, 0xB6, 0xE3, 0xD1, 0x05, 0x65, 0x50, 0xD9, 0xFA, 0xE5, 0xD5, 0xBB, 0xAD, 0xA6, 0xA6, 0xBC, 0x37, 0x0E, 0x4C, 0xBB, 0x93, 0x8B, 0x1D, 0xC7, 0x1D, 0xA3, 0x30, 0x68, 0xBB, 0x1C, 0xA0, 0x45, 0x25, 0xBB, 0x0E, 0x41, 0x6C, 0x48, 0x5F, 0xE6, 0xA6, 0x7F, 0xD5, 0x25, 0x40, 0x22, 0x7D, 0x26, 0x7C, 0xC8, 0xB6, 0xE8, 0xDA, 0x95, 0x8A, 0x7F, 0xA0, 0x39]),
signature: '74BCC59DBA39A1E34A5F75F96D6DE9154E3477AAD7DE30EA563DFCFE501A804228008F98DDF4A15FD35705102785C50EF76732C3A74B0FEC5B0DD67B574A5900',
signatureBytes: new Uint8Array([0x74, 0xBC, 0xC5, 0x9D, 0xBA, 0x39, 0xA1, 0xE3, 0x4A, 0x5F, 0x75, 0xF9, 0x6D, 0x6D, 0xE9, 0x15, 0x4E, 0x34, 0x77, 0xAA, 0xD7, 0xDE, 0x30, 0xEA, 0x56, 0x3D, 0xFC, 0xFE, 0x50, 0x1A, 0x80, 0x42, 0x28, 0x00, 0x8F, 0x98, 0xDD, 0xF4, 0xA1, 0x5F, 0xD3, 0x57, 0x05, 0x10, 0x27, 0x85, 0xC5, 0x0E, 0xF7, 0x67, 0x32, 0xC3, 0xA7, 0x4B, 0x0F, 0xEC, 0x5B, 0x0D, 0xD6, 0x7B, 0x57, 0x4A, 0x59, 0x00]),
badSignature: '74BCC59DBA39A1E34A5F75F96D6DE9154E3477AAD7DE30EA563DFCFE501A804215d484f5f757b4b7a9f4fcb2057fa423f76732c3a74b0fec5b0dd67b574a5910',