Skip to content

Commit

Permalink
[DDW-130] implement all test vectors from specification
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikGuzei committed Mar 12, 2018
1 parent 1c6e28d commit cc494a4
Showing 1 changed file with 63 additions and 14 deletions.
77 changes: 63 additions & 14 deletions js/tests/paper-wallets-tests.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,80 @@
const expect = require('chai').expect;
const CardanoCrypto = require('../../dist/index.js');

const TEST_VECTORS = [
{
iv: new Uint8Array([0x00, 0x00, 0x00, 0x00]),
input: 'legal winner thank year wave sausage worth useful legal winner thank yellow',
passphrase: '',
scrambledWords: 'abandon abandon abandon win nest chef want salt join shove minor december miss oak name'
},
{
iv: new Uint8Array([0x00, 0x01, 0x02, 0x03]),
input: 'fold parrot feature figure stay blanket woman grain huge orphan key exile',
passphrase: 'Cardano Ada',
scrambledWords: 'abandon amount liar jump crouch mesh token control someone wheel purity initial choice bullet embark'
},
{
iv: new Uint8Array([0x2a, 0x2a, 0x2a, 0x2a]),
input: 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong',
passphrase: 'This is a very long passphrase. This is a very long passphrase. This is a very long passphrase. This is a very long passphrase.',
scrambledWords: 'clay eyebrow melt enroll lend fold card pledge allow bottom dirt road frame fatal arch'
}
];

describe('PaperWallet', function() {

describe('#scramble', function() {

it('generates 15 words mnenomics from 12 words input', function() {
const iv = new Uint8Array([0x00, 0x00, 0x00, 0x00]);
const input = 'legal winner thank year wave sausage worth useful legal winner thank yellow';
const passphrase = '';
describe('Test Vector 1: without passphrase', function() {

it('generates the correct 15 words mnenomics from 12 words input', function() {
const { iv, input, passphrase, scrambledWords } = TEST_VECTORS[0];
expect(CardanoCrypto.PaperWallet.scrambleStrings(iv, passphrase, input)).equal(scrambledWords);
});
});

describe('Test Vector 2: short passphrase', function() {

it('generates the correct 15 words mnenomics from 12 words input', function() {
const { iv, input, passphrase, scrambledWords } = TEST_VECTORS[1];
expect(CardanoCrypto.PaperWallet.scrambleStrings(iv, passphrase, input)).equal(scrambledWords);
});
});

describe('Test Vector 3: long passphrase', function() {

expect(CardanoCrypto.PaperWallet.scrambleStrings(iv, passphrase, input)).equal(
'abandon abandon abandon win nest chef want salt join shove minor december miss oak name'
);
it('generates the correct 15 words mnenomics from 12 words input', function() {
const { iv, input, passphrase, scrambledWords } = TEST_VECTORS[2];
expect(CardanoCrypto.PaperWallet.scrambleStrings(iv, passphrase, input)).equal(scrambledWords);
});
});
});

describe('#unscramble', function() {

it('retrieves the original 12 words mnenomics from scrambled 15 words input', function() {
const input = 'abandon abandon abandon win nest chef want salt join shove minor december miss oak name';
const passphrase = '';
describe('Test Vector 1: without passphrase', function() {

expect(CardanoCrypto.PaperWallet.unscrambleStrings(passphrase, input)).equal(
'legal winner thank year wave sausage worth useful legal winner thank yellow'
);
it('retrieves the original 12 words mnenomics from scrambled 15 words input', function() {
const { input, passphrase, scrambledWords } = TEST_VECTORS[0];
expect(CardanoCrypto.PaperWallet.unscrambleStrings(passphrase, scrambledWords)).equal(input);
});
});

describe('Test Vector 2: short passphrase', function() {

it('retrieves the original 12 words mnenomics from scrambled 15 words input', function() {
const { input, passphrase, scrambledWords } = TEST_VECTORS[1];
expect(CardanoCrypto.PaperWallet.unscrambleStrings(passphrase, scrambledWords)).equal(input);
});
});
});

describe('Test Vector 3: long passphrase', function() {

it('retrieves the original 12 words mnenomics from scrambled 15 words input', function() {
const { input, passphrase, scrambledWords } = TEST_VECTORS[2];
expect(CardanoCrypto.PaperWallet.unscrambleStrings(passphrase, scrambledWords)).equal(input);
});
});
});
});

0 comments on commit cc494a4

Please sign in to comment.