diff --git a/test/BasicVectorTest.template.ts b/test/BasicVectorTest.template.ts index 5acd377..ef4f705 100644 --- a/test/BasicVectorTest.template.ts +++ b/test/BasicVectorTest.template.ts @@ -94,43 +94,54 @@ export const AddressMosaicIdTester = ( }); }; -export const CipherVectorTester = (testCipherVectorFile: string): void => { - describe('cipher - test vector', () => { +export const NemCipherVectorTester = (testCipherVectorFile: string): void => { + describe('nem cipher - test vector', () => { tester.run( testCipherVectorFile, - (item: { - privateKey: string; - otherPublicKey: string; - tag: string; - salt: string; - iv: string; - cipherText: string; - clearText: string; - }) => { + (item: { privateKey: string; otherPublicKey: string; salt: string; iv: string; cipherText: string; clearText: string }) => { // Arrange: const privateKey = Key.createFromHex(item.privateKey); const otherPublicKey = Key.createFromHex(item.otherPublicKey); const clearText = Converter.hexToUint8(item.clearText); const iv = Converter.hexToUint8(item.iv); - const salt = item.salt ? Converter.hexToUint8(item.salt) : undefined; + const salt = Converter.hexToUint8(item.salt); // Act: - const encoded = salt - ? NemCrypto.encode(privateKey, otherPublicKey, clearText, iv, salt) - : encode(privateKey, otherPublicKey, clearText, iv); + const payload = item.salt + item.iv + item.cipherText; + const encoded = NemCrypto.encode(privateKey, otherPublicKey, clearText, iv, salt); + const decoded = NemCrypto.decode(privateKey, otherPublicKey, Converter.hexToUint8(payload)); - const decoded = salt - ? NemCrypto.decode(privateKey, otherPublicKey, Converter.hexToUint8(item.salt + item.iv + item.cipherText)) - : decode(privateKey, otherPublicKey, encoded); + // Assert: + const message = ` from ${item.clearText}`; + expect(Converter.uint8ToHex(encoded), `nem cipher encode ${message}`).equal(payload); + expect(Converter.uint8ToHex(decoded), `nem cipher decoded ${message}`).equal(item.clearText); + }, + 'nem cipher test', + ); + }); +}; + +export const SymbolCipherVectorTester = (testCipherVectorFile: string): void => { + describe('symbol cipher - test vector', () => { + tester.run( + testCipherVectorFile, + (item: { privateKey: string; otherPublicKey: string; tag: string; iv: string; cipherText: string; clearText: string }) => { + // Arrange: + const privateKey = Key.createFromHex(item.privateKey); + const otherPublicKey = Key.createFromHex(item.otherPublicKey); + const clearText = Converter.hexToUint8(item.clearText); + const iv = Converter.hexToUint8(item.iv); + + // Act: + const encoded = encode(privateKey, otherPublicKey, clearText, iv); + const decoded = decode(privateKey, otherPublicKey, encoded); // Assert: const message = ` from ${item.clearText}`; - expect(Converter.uint8ToHex(encoded), `cipher encode ${message}`).equal( - `${salt ? item.salt : item.tag}${item.iv}${item.cipherText}`, - ); - expect(Converter.uint8ToHex(decoded), `cipher decoded ${message}`).equal(item.clearText); + expect(Converter.uint8ToHex(encoded), `symbol cipher encode ${message}`).equal(`${item.tag}${item.iv}${item.cipherText}`); + expect(Converter.uint8ToHex(decoded), `symbol cipher decoded ${message}`).equal(item.clearText); }, - 'cipher test', + 'symbol cipher test', ); }); }; diff --git a/test/vector-tests/AllTests.vector.ts b/test/vector-tests/AllTests.vector.ts index 949ee9e..50bb357 100644 --- a/test/vector-tests/AllTests.vector.ts +++ b/test/vector-tests/AllTests.vector.ts @@ -1,11 +1,12 @@ import { NemKeyPair, NemNetwork, SymbolKeyPair, SymbolNetwork } from '@core'; import { AddressMosaicIdTester, - CipherVectorTester, DeriveVectorTester, KeyPairVectorTester, + NemCipherVectorTester, SignAndVerifyTester, -} from 'test/BasicVectorTest.template'; + SymbolCipherVectorTester, +} from '../BasicVectorTest.template'; import path = require('path'); describe('Nem', () => { @@ -27,7 +28,7 @@ describe('Nem', () => { describe('test-cipher vector', () => { const vectorFile = path.join(__dirname, '../test-vector/nem/4.test-cipher.json'); - CipherVectorTester(vectorFile); + NemCipherVectorTester(vectorFile); }); }); @@ -61,6 +62,6 @@ describe('Symbol', () => { describe('test-cipher vector', () => { const vectorFile = path.join(__dirname, '../test-vector/symbol/4.test-cipher.json'); - CipherVectorTester(vectorFile); + SymbolCipherVectorTester(vectorFile); }); });