From: Chris Duncan Date: Tue, 25 Aug 2026 13:01:34 +0000 (-0700) Subject: Update node tests to deprecate secret key format. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=b127a5c3df9a020e7b491689b2029680d1d743bb;p=nano25519.git Update node tests to deprecate secret key format. --- diff --git a/test/node.mjs b/test/node.mjs index 7ba55a7..7eb0dc9 100644 --- a/test/node.mjs +++ b/test/node.mjs @@ -50,7 +50,7 @@ passes += +test failures += +!test try { - result = sign(NANO_ORG_VECTOR.blockHash + '0', NANO_ORG_VECTOR.secretKey) + result = sign(NANO_ORG_VECTOR.blockHash + '0', NANO_ORG_VECTOR.privateKey, NANO_ORG_VECTOR.publicKey) result = false } catch (err) { if (err != null && typeof err === 'object' && 'message' in err) { @@ -65,7 +65,7 @@ passes += +test failures += +!test try { - result = sign('1'.repeat(65538), NANO_ORG_VECTOR.secretKey) + result = sign('1'.repeat(65538), NANO_ORG_VECTOR.privateKey, NANO_ORG_VECTOR.publicKey) result = false } catch (err) { if (err != null && typeof err === 'object' && 'message' in err) { @@ -145,7 +145,7 @@ passes += +test failures += +!test try { - result = sign(NANO_ORG_VECTOR.blockHash + '0', NANO_ORG_VECTOR.secretKey) + result = sign(NANO_ORG_VECTOR.blockHash + '0', NANO_ORG_VECTOR.privateKey, NANO_ORG_VECTOR.publicKey) result = false } catch (err) { if (err != null && typeof err === 'object' && 'message' in err) { @@ -160,7 +160,7 @@ passes += +test failures += +!test try { - result = sign('1'.repeat(65538), NANO_ORG_VECTOR.secretKey) + result = sign('1'.repeat(65538), NANO_ORG_VECTOR.privateKey, NANO_ORG_VECTOR.publicKey) result = false } catch (err) { if (err != null && typeof err === 'object' && 'message' in err) { @@ -200,7 +200,7 @@ failures += +!test try { outbuf = new Uint8Array(65) - result = sign(NANO_ORG_VECTOR.blockHashBytes, NANO_ORG_VECTOR.secretKeyBytes, outbuf) + result = sign(NANO_ORG_VECTOR.blockHashBytes, NANO_ORG_VECTOR.privateKeyBytes, NANO_ORG_VECTOR.publicKeyBytes, outbuf) result = false } catch (err) { if (err != null && typeof err === 'object' && 'message' in err) { @@ -214,14 +214,14 @@ check(`sign offset outbuf wrong length`, test) passes += +test failures += +!test -// Check sync imports with string inputs +// Check string inputs result = derive(NANO_ORG_VECTOR.privateKey) test = result.toLowerCase() === NANO_ORG_VECTOR.publicKey.toLowerCase() check(`derive from private key string ${NANO_ORG_VECTOR.privateKey}`, test) passes += +test failures += +!test -result = sign(NANO_ORG_VECTOR.blockHash, NANO_ORG_VECTOR.secretKey) +result = sign(NANO_ORG_VECTOR.blockHash, NANO_ORG_VECTOR.privateKey, NANO_ORG_VECTOR.publicKey) test = result.toLowerCase() === NANO_ORG_VECTOR.signature.toLowerCase() check(`sign message string ${NANO_ORG_VECTOR.blockHash}`, test) passes += +test @@ -233,14 +233,14 @@ check(`verify signature string ${NANO_ORG_VECTOR.signature}`, test) passes += +test failures += +!test -// Check sync imports with byte inputs +// Check byte inputs result = 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 private key bytes ${NANO_ORG_VECTOR.privateKey}`, test) passes += +test failures += +!test -result = sign(NANO_ORG_VECTOR.blockHashBytes, NANO_ORG_VECTOR.secretKeyBytes) +result = 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 bytes ${NANO_ORG_VECTOR.blockHash}`, test) passes += +test @@ -252,7 +252,7 @@ check(`verify signature bytes ${NANO_ORG_VECTOR.signature}`, test) passes += +test failures += +!test -// Check sync imports with byte inputs and preallocated output buffer +// Check byte inputs and preallocated output buffer inbuf = new Uint8Array(bigBuf.buffer.slice(), 0, 32) inbuf.set(NANO_ORG_VECTOR.privateKeyBytes) outbuf = new Uint8Array(32) @@ -262,10 +262,10 @@ check(`derive from private key bytes ${NANO_ORG_VECTOR.privateKey} and allocate passes += +test failures += +!test -inbuf = new Uint8Array(bigBuf.buffer.slice(), 0, 64) -inbuf.set(NANO_ORG_VECTOR.secretKeyBytes) +inbuf = new Uint8Array(bigBuf.buffer.slice(), 0, 32) +inbuf.set(NANO_ORG_VECTOR.privateKeyBytes) outbuf = new Uint8Array(64) -sign(NANO_ORG_VECTOR.blockHashBytes, inbuf, outbuf) +sign(NANO_ORG_VECTOR.blockHashBytes, inbuf, NANO_ORG_VECTOR.publicKeyBytes, outbuf) test = [...outbuf].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === NANO_ORG_VECTOR.signature.toLowerCase() check(`sign message bytes ${NANO_ORG_VECTOR.blockHash} and allocate result to output buffer`, test) passes += +test @@ -282,10 +282,10 @@ check(`derive from private key bytes ${NANO_ORG_VECTOR.privateKey} and allocate passes += +test failures += +!test -inbuf = new Uint8Array(bigBuf.buffer.slice(), 1, 64) -inbuf.set(NANO_ORG_VECTOR.secretKeyBytes) +inbuf = new Uint8Array(bigBuf.buffer.slice(), 1, 32) +inbuf.set(NANO_ORG_VECTOR.privateKeyBytes) outbuf = new Uint8Array(bigBuf.buffer.slice(), 0, 64) -sign(NANO_ORG_VECTOR.blockHashBytes, inbuf, outbuf) +sign(NANO_ORG_VECTOR.blockHashBytes, inbuf, NANO_ORG_VECTOR.publicKeyBytes, outbuf) test = [...outbuf].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === NANO_ORG_VECTOR.signature.toLowerCase() test &&= [...new Uint8Array(outbuf.buffer, 0, 64)].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === NANO_ORG_VECTOR.signature.toLowerCase() test &&= [...new Uint8Array(outbuf.buffer, 64, 64)].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === 'ff'.repeat(64) @@ -293,7 +293,7 @@ check(`sign message bytes ${NANO_ORG_VECTOR.blockHash} and allocate result to ou passes += +test failures += +!test -// Check sync imports with byte inputs and offset output buffer +// Check byte inputs and offset output buffer outbuf = new Uint8Array(new ArrayBuffer(128), 32, 32) derive(NANO_ORG_VECTOR.privateKeyBytes, outbuf) test = [...outbuf].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === NANO_ORG_VECTOR.publicKey.toLowerCase() @@ -304,7 +304,7 @@ passes += +test failures += +!test outbuf = new Uint8Array(new ArrayBuffer(128), 64, 64) -sign(NANO_ORG_VECTOR.blockHashBytes, NANO_ORG_VECTOR.secretKeyBytes, outbuf) +sign(NANO_ORG_VECTOR.blockHashBytes, NANO_ORG_VECTOR.privateKeyBytes, NANO_ORG_VECTOR.publicKeyBytes, outbuf) test = [...outbuf].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === NANO_ORG_VECTOR.signature.toLowerCase() test &&= [...new Uint8Array(outbuf.buffer, 0, 64)].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === '00'.repeat(64) test &&= [...new Uint8Array(outbuf.buffer, 64, 64)].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === NANO_ORG_VECTOR.signature.toLowerCase() @@ -320,7 +320,7 @@ for (const { privateKey, publicKey, message, signature } of PYTHON_ED25519_BLAKE passes += +test failures += +!test - result = sign(message, privateKey + publicKey) + result = sign(message, privateKey, publicKey) test = result.toLowerCase() === signature.slice(0, 128) check(`sign message string ${message}`, test) passes += +test @@ -334,7 +334,6 @@ for (const { privateKey, publicKey, message, signature } of PYTHON_ED25519_BLAKE 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)) ?? []) @@ -344,7 +343,7 @@ for (const { privateKey, publicKey, message, signature } of PYTHON_ED25519_BLAKE passes += +test failures += +!test - result = sign(messageBytes, secretKeyBytes) + result = sign(messageBytes, privateKeyBytes, publicKeyBytes) test = [...result].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === signature.slice(0, 128) check(`sign message bytes ${message}`, test) passes += +test