diff --git a/bench/buffer.js b/bench/buffer.js index 818d86d0..5c9ea92f 100644 --- a/bench/buffer.js +++ b/bench/buffer.js @@ -1,14 +1,11 @@ 'use strict'; -const fs = require('fs'); -const TX = require('../lib/primitives/tx'); const BufferWriter = require('../lib/utils/writer'); const StaticWriter = require('../lib/utils/staticwriter'); +const common = require('../test/util/common'); const bench = require('./bench'); -const hex = fs.readFileSync(`${__dirname}/../test/data/wtx.hex`, 'utf8'); -const raw = Buffer.from(hex.trim(), 'hex'); -const tx = TX.fromRaw(raw); +const {tx} = common.parseTX('data/tx5.hex'); { const end = bench('serialize (static-writer)'); @@ -16,7 +13,8 @@ const tx = TX.fromRaw(raw); tx.refresh(); const {size} = tx.getWitnessSizes(); const bw = new StaticWriter(size); - tx.toWitnessWriter(bw).render(); + tx.toWitnessWriter(bw); + bw.render(); } end(10000); } @@ -26,7 +24,8 @@ const tx = TX.fromRaw(raw); for (let i = 0; i < 10000; i++) { tx.refresh(); const bw = new BufferWriter(); - tx.toWitnessWriter(bw).render(); + tx.toWitnessWriter(bw); + bw.render(); } end(10000); } diff --git a/bench/coins.js b/bench/coins.js index 87028b2e..27e8ea0e 100644 --- a/bench/coins.js +++ b/bench/coins.js @@ -1,13 +1,11 @@ 'use strict'; -const fs = require('fs'); const Coins = require('../lib/coins/coins'); -const TX = require('../lib/primitives/tx'); +const common = require('../test/util/common'); const bench = require('./bench'); -const hex = fs.readFileSync(`${__dirname}/../test/data/wtx.hex`, 'utf8'); -const wtx = TX.fromRaw(hex.trim(), 'hex'); -const coins = Coins.fromTX(wtx, 1); +const {tx} = common.parseTX('data/tx5.hex'); +const coins = Coins.fromTX(tx, 1); const raw = coins.toRaw(); { diff --git a/bench/tx.js b/bench/tx.js index af9db303..49f307d0 100644 --- a/bench/tx.js +++ b/bench/tx.js @@ -1,3 +1,5 @@ +/* eslint max-len: "off" */ + 'use strict'; const fs = require('fs'); @@ -6,42 +8,23 @@ const Address = require('../lib/primitives/address'); const TX = require('../lib/primitives/tx'); const Script = require('../lib/script/script'); const MTX = require('../lib/primitives/mtx'); -const Coin = require('../lib/primitives/coin'); -const CoinView = require('../lib/coins/coinview'); const encoding = require('../lib/utils/encoding'); const random = require('../lib/crypto/random'); +const common = require('../test/util/common'); const bench = require('./bench'); -const json = require('../test/data/block300025.json'); -const block = Block.fromJSON(json); -const btx = { tx: block.txs[397], view: new CoinView() }; +const block300025 = fs.readFileSync(`${__dirname}/../test/data/block300025.raw`); +const undo300025 = fs.readFileSync(`${__dirname}/../test/data/undo300025.raw`); +const block = Block.fromRaw(block300025); +const undo = common.parseUndo(undo300025); +const btx = { + tx: block.txs[397], + view: common.applyUndo(block, undo) +}; -const tx3 = parseTX('../test/data/tx3.hex'); -const hex = fs.readFileSync(`${__dirname}/../test/data/wtx.hex`, 'utf8'); -const raw = Buffer.from(hex.trim(), 'hex'); -const tx = TX.fromRaw(raw); - -{ - const tx = json.txs[397]; - for (const input of tx.inputs) - btx.view.addCoin(Coin.fromJSON(input.coin)); -} - -function parseTX(file) { - const data = fs.readFileSync(`${__dirname}/${file}`, 'utf8'); - const parts = data.trim().split(/\n+/); - const raw = parts[0]; - const tx = TX.fromRaw(raw.trim(), 'hex'); - const view = new CoinView(); - - for (let i = 1; i < parts.length; i++) { - const raw = parts[i]; - const prev = TX.fromRaw(raw.trim(), 'hex'); - view.addTX(prev, -1); - } - - return { tx: tx, view: view }; -} +const tx3 = common.parseTX('data/tx3.hex'); +const tx5 = common.parseTX('data/tx5.hex'); +const raw = tx5.tx.toRaw(); { const end = bench('parse'); @@ -53,8 +36,8 @@ function parseTX(file) { { const end = bench('serialize'); for (let i = 0; i < 1000; i++) { - tx._raw = null; - tx.toRaw(); + tx5.tx._raw = null; + tx5.tx.toRaw(); } end(1000); } @@ -71,8 +54,8 @@ function parseTX(file) { { const end = bench('witness hash'); for (let i = 0; i < 3000; i++) { - tx.witnessHash(); - tx._whash = null; + tx5.tx.witnessHash(); + tx5.tx._whash = null; } end(3000); } @@ -80,28 +63,28 @@ function parseTX(file) { { const end = bench('sanity'); for (let i = 0; i < 1000; i++) - tx.isSane(); + tx5.tx.isSane(); end(1000); } { const end = bench('input hashes'); for (let i = 0; i < 1000; i++) - tx.getInputHashes(null, 'hex'); + tx5.tx.getInputHashes(null, 'hex'); end(1000); } { const end = bench('output hashes'); for (let i = 0; i < 1000; i++) - tx.getOutputHashes('hex'); + tx5.tx.getOutputHashes('hex'); end(1000); } { const end = bench('all hashes'); for (let i = 0; i < 1000; i++) - tx.getHashes(null, 'hex'); + tx5.tx.getHashes(null, 'hex'); end(1000); } diff --git a/test/bech32-test.js b/test/bech32-test.js index c1553105..1e4477d7 100644 --- a/test/bech32-test.js +++ b/test/bech32-test.js @@ -31,121 +31,119 @@ const assert = require('assert'); const bech32 = require('../lib/utils/bech32'); const Address = require('../lib/primitives/address'); +const validChecksums = [ + 'A12UEL5L', + 'an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs', + 'abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw', + '11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j', + 'split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w' +]; + +const validAddresses = [ + [ + 'BC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KV8F3T4', + Buffer.from([ + 0x00, 0x14, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, + 0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6 + ]) + ], + [ + 'tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7', + Buffer.from([ + 0x00, 0x20, 0x18, 0x63, 0x14, 0x3c, 0x14, 0xc5, 0x16, 0x68, 0x04, + 0xbd, 0x19, 0x20, 0x33, 0x56, 0xda, 0x13, 0x6c, 0x98, 0x56, 0x78, + 0xcd, 0x4d, 0x27, 0xa1, 0xb8, 0xc6, 0x32, 0x96, 0x04, 0x90, 0x32, + 0x62 + ]) + ], + [ + 'bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx', + Buffer.from([ + 0x81, 0x28, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, + 0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6, + 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94, 0x1c, + 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6 + ]) + ], + [ + 'BC1SW50QA3JX3S', + Buffer.from([ + 0x90, 0x02, 0x75, 0x1e + ]) + ], + [ + 'bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj', + Buffer.from([ + 0x82, 0x10, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, + 0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23 + ]) + ], + [ + 'tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy', + Buffer.from([ + 0x00, 0x20, 0x00, 0x00, 0x00, 0xc4, 0xa5, 0xca, 0xd4, 0x62, 0x21, + 0xb2, 0xa1, 0x87, 0x90, 0x5e, 0x52, 0x66, 0x36, 0x2b, 0x99, 0xd5, + 0xe9, 0x1c, 0x6c, 0xe2, 0x4d, 0x16, 0x5d, 0xab, 0x93, 0xe8, 0x64, + 0x33 + ]) + ] +]; + +const invalidAddresses = [ + 'tc1qw508d6qejxtdg4y5r3zarvary0c5xw7kg3g4ty', + 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t5', + 'BC13W508D6QEJXTDG4Y5R3ZARVARY0C5XW7KN40WF2', + 'bc1rw5uspcuh', + 'bc10w508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7kw5rljs90', + 'BC1QR508D6QEJXTDG4Y5R3ZARVARYV98GJ9P', + 'tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sL5k7', + 'tb1pw508d6qejxtdg4y5r3zarqfsj6c3', + 'tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3pjxtptv' +]; + +function fromAddress(hrp, addr) { + const dec = bech32.decode(addr); + + if (dec.hrp !== hrp) + throw new Error('Invalid bech32 prefix or data length.'); + + if (dec.version === 0 && dec.hash.length !== 20 && dec.hash.length !== 32) + throw new Error('Malformed witness program.'); + + return { + version: dec.version, + program: dec.hash + }; +} + +function toAddress(hrp, version, program) { + const ret = bech32.encode(hrp, version, program); + + fromAddress(hrp, ret); + + return ret; +} + +function createProgram(version, program) { + const ver = Buffer.from([version ? version + 0x80 : 0, program.length]); + return Buffer.concat([ver, program]); +} + describe('Bech32', function() { - const VALID_CHECKSUM = [ - 'A12UEL5L', - 'an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs', - 'abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw', - '11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j', - 'split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w' - ]; - - const VALID_ADDRESS = [ - [ - 'BC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KV8F3T4', - Buffer.from([ - 0x00, 0x14, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, - 0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6 - ]) - ], - [ - 'tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7', - Buffer.from([ - 0x00, 0x20, 0x18, 0x63, 0x14, 0x3c, 0x14, 0xc5, 0x16, 0x68, 0x04, - 0xbd, 0x19, 0x20, 0x33, 0x56, 0xda, 0x13, 0x6c, 0x98, 0x56, 0x78, - 0xcd, 0x4d, 0x27, 0xa1, 0xb8, 0xc6, 0x32, 0x96, 0x04, 0x90, 0x32, - 0x62 - ]) - ], - [ - 'bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7k7grplx', - Buffer.from([ - 0x81, 0x28, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, - 0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6, - 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, 0x94, 0x1c, - 0x45, 0xd1, 0xb3, 0xa3, 0x23, 0xf1, 0x43, 0x3b, 0xd6 - ]) - ], - [ - 'BC1SW50QA3JX3S', - Buffer.from([ - 0x90, 0x02, 0x75, 0x1e - ]) - ], - [ - 'bc1zw508d6qejxtdg4y5r3zarvaryvg6kdaj', - Buffer.from([ - 0x82, 0x10, 0x75, 0x1e, 0x76, 0xe8, 0x19, 0x91, 0x96, 0xd4, 0x54, - 0x94, 0x1c, 0x45, 0xd1, 0xb3, 0xa3, 0x23 - ]) - ], - [ - 'tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy', - Buffer.from([ - 0x00, 0x20, 0x00, 0x00, 0x00, 0xc4, 0xa5, 0xca, 0xd4, 0x62, 0x21, - 0xb2, 0xa1, 0x87, 0x90, 0x5e, 0x52, 0x66, 0x36, 0x2b, 0x99, 0xd5, - 0xe9, 0x1c, 0x6c, 0xe2, 0x4d, 0x16, 0x5d, 0xab, 0x93, 0xe8, 0x64, - 0x33 - ]) - ] - ]; - - const INVALID_ADDRESS = [ - 'tc1qw508d6qejxtdg4y5r3zarvary0c5xw7kg3g4ty', - 'bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t5', - 'BC13W508D6QEJXTDG4Y5R3ZARVARY0C5XW7KN40WF2', - 'bc1rw5uspcuh', - 'bc10w508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7kw5rljs90', - 'BC1QR508D6QEJXTDG4Y5R3ZARVARYV98GJ9P', - 'tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sL5k7', - 'tb1pw508d6qejxtdg4y5r3zarqfsj6c3', - 'tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3pjxtptv' - ]; - - function fromAddress(hrp, addr) { - const dec = bech32.decode(addr); - - if (dec.hrp !== hrp) - throw new Error('Invalid bech32 prefix or data length.'); - - if (dec.version === 0 && dec.hash.length !== 20 && dec.hash.length !== 32) - throw new Error('Malformed witness program.'); - - return { - version: dec.version, - program: dec.hash - }; - } - - function toAddress(hrp, version, program) { - const ret = bech32.encode(hrp, version, program); - - fromAddress(hrp, ret); - - return ret; - } - - function createProgram(version, program) { - const ver = Buffer.from([version ? version + 0x80 : 0, program.length]); - return Buffer.concat([ver, program]); - } - - VALID_CHECKSUM.forEach((test) => { - it(`should have valid checksum for ${test}`, () => { - const ret = bech32.deserialize(test); + for (const addr of validChecksums) { + it(`should have valid checksum for ${addr}`, () => { + const ret = bech32.deserialize(addr); assert(ret); }); - }); + } - VALID_ADDRESS.forEach((test) => { - const address = test[0]; - const scriptpubkey = test[1]; - it(`should have valid address for ${address}`, () => { + for (const [addr, script] of validAddresses) { + it(`should have valid address for ${addr}`, () => { let hrp = 'bc'; - let ret, ok, output, recreate; + let ret; try { - ret = fromAddress(hrp, address); + ret = fromAddress(hrp, addr); } catch (e) { ret = null; } @@ -153,40 +151,40 @@ describe('Bech32', function() { if (ret === null) { hrp = 'tb'; try { - ret = fromAddress(hrp, address); + ret = fromAddress(hrp, addr); } catch (e) { ret = null; } } - ok = ret !== null; + let ok = ret !== null; if (ok) { - output = createProgram(ret.version, ret.program); - ok = output.compare(scriptpubkey) === 0; + const output = createProgram(ret.version, ret.program); + ok = output.equals(script); } if (ok) { - recreate = toAddress(hrp, ret.version, ret.program); - ok = (recreate === address.toLowerCase()); + const recreate = toAddress(hrp, ret.version, ret.program); + ok = recreate === addr.toLowerCase(); } assert(ok); }); - }); - - INVALID_ADDRESS.forEach((test) => { - it(`should have invalid address for ${test}`, () => { - let ok1, ok2; + } + for (const addr of invalidAddresses) { + it(`should have invalid address for ${addr}`, () => { + let ok1; try { - ok1 = fromAddress('bc', test); + ok1 = fromAddress('bc', addr); } catch (e) { ok1 = null; } + let ok2; try { - ok2 = fromAddress('tb', test); + ok2 = fromAddress('tb', addr); } catch (e) { ok2 = null; } @@ -194,67 +192,59 @@ describe('Bech32', function() { const ok = ok1 === null && ok2 === null; assert(ok); }); - }); + } - VALID_ADDRESS.forEach((test, i) => { - const address = test[0]; - const scriptpubkey = test[1]; - - // TODO: Fix. (wrong length for program) - // Need to drop old segwit addrs. - if (i >= 2 && i <= 4) - return; - - it(`should have valid address for ${address}`, () => { - let ret, ok, output, recreate; + for (const [addr, script] of validAddresses) { + it(`should have valid address for ${addr}`, () => { + let ret; try { - ret = Address.fromBech32(address, 'main'); + ret = Address.fromBech32(addr, 'main'); } catch (e) { ret = null; } if (ret === null) { try { - ret = Address.fromBech32(address, 'testnet'); + ret = Address.fromBech32(addr, 'testnet'); } catch (e) { ret = null; } } - ok = ret !== null; + let ok = ret !== null; if (ok) { - output = createProgram(ret.version, ret.hash); - ok = output.compare(scriptpubkey) === 0; + const output = createProgram(ret.version, ret.hash); + ok = output.equals(script); } if (ok) { - recreate = ret.toBech32(); - ok = (recreate === address.toLowerCase()); + const recreate = ret.toBech32(); + ok = recreate === addr.toLowerCase(); } assert(ok); }); - }); - - INVALID_ADDRESS.forEach((test) => { - it(`should have invalid address for ${test}`, () => { - let ok1, ok2; + } + for (const addr of invalidAddresses) { + it(`should have invalid address for ${addr}`, () => { + let ok1; try { - ok1 = Address.fromBech32(test, 'main'); + ok1 = Address.fromBech32(addr, 'main'); } catch (e) { ok1 = null; } + let ok2; try { - ok2 = Address.fromBech32(test, 'testnet'); + ok2 = Address.fromBech32(addr, 'testnet'); } catch (e) { ok2 = null; } assert(!ok1 && !ok2); }); - }); + } }); diff --git a/test/bip70-test.js b/test/bip70-test.js index aa627501..a92bdb34 100644 --- a/test/bip70-test.js +++ b/test/bip70-test.js @@ -194,7 +194,7 @@ describe('BIP70', function() { assert(!req.pkiData); req.setChain([tests.ca.crt]); - req.sign(tests.ca.priv) + req.sign(tests.ca.priv); assert(req.pkiData); assert.equal(req.pkiType, 'x509+sha256'); diff --git a/test/block-test.js b/test/block-test.js index 75b23fc4..59dbcd8d 100644 --- a/test/block-test.js +++ b/test/block-test.js @@ -5,102 +5,43 @@ 'use strict'; const assert = require('assert'); +const fs = require('fs'); +const common = require('./util/common'); const Bloom = require('../lib/utils/bloom'); const Block = require('../lib/primitives/block'); const Headers = require('../lib/primitives/headers'); const MerkleBlock = require('../lib/primitives/merkleblock'); -const CoinView = require('../lib/coins/coinview'); -const Coin = require('../lib/primitives/coin'); const consensus = require('../lib/protocol/consensus'); const Script = require('../lib/script/script'); -const Output = require('../lib/primitives/output'); const encoding = require('../lib/utils/encoding'); const bip152 = require('../lib/net/bip152'); -const BufferReader = require('../lib/utils/reader'); -const fs = require('../lib/utils/fs'); const CompactBlock = bip152.CompactBlock; const TXRequest = bip152.TXRequest; const TXResponse = bip152.TXResponse; +// Block test vectors const block300025 = fs.readFileSync(`${__dirname}/data/block300025.raw`); const undo300025 = fs.readFileSync(`${__dirname}/data/undo300025.raw`); -const cmpct1 = fs.readFileSync(`${__dirname}/data/compact1.raw`); -const cmpct1block = fs.readFileSync(`${__dirname}/data/compact1-block.raw`); -const cmpct2 = fs.readFileSync(`${__dirname}/data/compact2.raw`); -const cmpct2block = fs.readFileSync(`${__dirname}/data/compact2-block.raw`); +// Merkle block test vectors +const merkle300025 = fs.readFileSync(`${__dirname}/data/merkle300025.raw`); -function parseUndo(data) { - const br = new BufferReader(data); - const undo = []; +// Compact block test vectors +const block426884 = fs.readFileSync(`${__dirname}/data/block426884.raw`); +const compact426884 = fs.readFileSync(`${__dirname}/data/compact426884.raw`); +const block898352 = fs.readFileSync(`${__dirname}/data/block898352.raw`); +const compact898352 = fs.readFileSync(`${__dirname}/data/compact898352.raw`); - while (br.left()) { - const output = Output.fromReader(br); - undo.push(output); - } - - return undo; -} - -function applyUndo(block, undo) { - const view = new CoinView(); - let i = 0; - - for (const tx of block.txs) { - if (tx.isCoinbase()) - continue; - - for (const {prevout} of tx.inputs) - view.addOutput(prevout, undo[i++]); - } - - assert(i === undo.length, 'Undo coins data inconsistency.'); - - return view; -} +// Sigops counting test vectors +const block928927 = fs.readFileSync(`${__dirname}/data/block928927.raw`); +const undo928927 = fs.readFileSync(`${__dirname}/data/undo928927.raw`); +const block928828 = fs.readFileSync(`${__dirname}/data/block928828.raw`); +const undo928828 = fs.readFileSync(`${__dirname}/data/undo928828.raw`); +const block1087400 = fs.readFileSync(`${__dirname}/data/block1087400.raw`); +const undo1087400 = fs.readFileSync(`${__dirname}/data/undo1087400.raw`); describe('Block', function() { - let mblock = new MerkleBlock({ - version: 2, - prevBlock: 'd1831d4411bdfda89d9d8c842b541beafd1437fc560dbe5c0000000000000000', - merkleRoot: '28bec1d35af480ba3884553d72694f6ba6c163a5c081d7e6edaec15f373f19af', - time: 1399713634, - bits: 419465580, - nonce: 1186968784, - totalTX: 461, - hashes: [ - '7d22e53bce1bbb3294d1a396c5acc45bdcc8f192cb492f0d9f55421fd4c62de1', - '9d6d585fdaf3737b9a54aaee1dd003f498328d699b7dfb42dd2b44b6ebde2333', - '8b61da3053d6f382f2145bdd856bc5dcf052c3a11c1784d3d51b2cbe0f6d0923', - 'd7bbaae4716cb0d329d755b707cee588cddc68601f99bc05fef1fabeb8dfe4a0', - '7393f84cd04ca8931975c66282ebf1847c78d8de6c2578d4f9bae23bc6f30857', - 'ec8c51de3170301430ec56f6703533d9ea5b05c6fa7068954bcb90eed8c2ee5c', - 'c7c152869db09a5ae2291fa03142912d9d7aba75be7d491a8ac4230ee9a920cb', - '5adbf04583354515a225f2c418de7c5cdac4cef211820c79717cd2c50412153f', - '1f5e46b9da3a8b1241f4a1501741d3453bafddf6135b600b926e3f4056c6d564', - '33825657ba32afe269819f01993bd77baba86379043168c94845d32370e53562' - ], - flags: Buffer.from([245, 122, 0]) - }); - - const raw = mblock.toRaw().toString('hex'); - - const raw2 = '02000000d1831d4411bdfda89d9d8c842b541beafd1437fc560dbe5c0' - + '00000000000000028bec1d35af480ba3884553d72694f6ba6c163a5c081d7e6edaec' - + '15f373f19af62ef6d536c890019d0b4bf46cd0100000a7d22e53bce1bbb3294d1a39' - + '6c5acc45bdcc8f192cb492f0d9f55421fd4c62de19d6d585fdaf3737b9a54aaee1dd' - + '003f498328d699b7dfb42dd2b44b6ebde23338b61da3053d6f382f2145bdd856bc5d' - + 'cf052c3a11c1784d3d51b2cbe0f6d0923d7bbaae4716cb0d329d755b707cee588cdd' - + 'c68601f99bc05fef1fabeb8dfe4a07393f84cd04ca8931975c66282ebf1847c78d8d' - + 'e6c2578d4f9bae23bc6f30857ec8c51de3170301430ec56f6703533d9ea5b05c6fa7' - + '068954bcb90eed8c2ee5cc7c152869db09a5ae2291fa03142912d9d7aba75be7d491' - + 'a8ac4230ee9a920cb5adbf04583354515a225f2c418de7c5cdac4cef211820c79717' - + 'cd2c50412153f1f5e46b9da3a8b1241f4a1501741d3453bafddf6135b600b926e3f4' - + '056c6d56433825657ba32afe269819f01993bd77baba86379043168c94845d32370e' - + '5356203f57a00'; - - mblock = MerkleBlock.fromRaw(raw2, 'hex'); - + const mblock = MerkleBlock.fromRaw(merkle300025); const block = Block.fromRaw(block300025); this.timeout(10000); @@ -125,29 +66,30 @@ describe('Block', function() { 'ec8c51de3170301430ec56f6703533d9ea5b05c6fa7068954bcb90eed8c2ee5c'); }); - it('should decode/encode with parser/framer', () => { - const b = MerkleBlock.fromRaw(raw, 'hex'); - assert.equal(b.toRaw().toString('hex'), raw); - assert.equal(raw, raw2); + it('should decode/encode merkle block', () => { + const merkle = MerkleBlock.fromRaw(merkle300025); + merkle.refresh(); + assert.deepEqual(merkle.toRaw(), merkle300025); + assert.deepEqual(merkle300025, mblock.toRaw()); }); - it('should be verifiable', () => { - const b = MerkleBlock.fromRaw(raw, 'hex'); - assert(b.verify()); + it('should be verify merkle block', () => { + const merkle = MerkleBlock.fromRaw(merkle300025); + assert(merkle.verify()); }); - it('should be serialized and deserialized and still verify', () => { + it('should be encoded/decoded and still verify', () => { const raw = mblock.toRaw(); - const b = MerkleBlock.fromRaw(raw); - assert.deepEqual(b.toRaw(), raw); - assert(b.verify()); + const merkle = MerkleBlock.fromRaw(raw); + assert.deepEqual(merkle.toRaw(), raw); + assert(merkle.verify()); }); - it('should be jsonified and unjsonified and still verify', () => { - const raw = mblock.toJSON(); - const b = MerkleBlock.fromJSON(raw); - assert.deepEqual(b.toJSON(), raw); - assert(b.verify()); + it('should be jsonified/unjsonified and still verify', () => { + const json = mblock.toJSON(); + const merkle = MerkleBlock.fromJSON(json); + assert.deepEqual(merkle.toJSON(), json); + assert(merkle.verify()); }); it('should calculate reward properly', () => { @@ -187,19 +129,18 @@ describe('Block', function() { filter.add(item1, 'hex'); filter.add(item2, 'hex'); - const mblock2 = MerkleBlock.fromBlock(block, filter); + const merkle = MerkleBlock.fromBlock(block, filter); - assert(mblock2.verifyBody()); - assert.deepEqual(mblock2.toRaw(), mblock.toRaw()); + assert(merkle.verifyBody()); + assert.deepEqual(merkle.toRaw(), mblock.toRaw()); }); it('should verify a historical block', () => { const block = Block.fromRaw(block300025); - const undo = parseUndo(undo300025); - const view = applyUndo(block, undo); + const undo = common.parseUndo(undo300025); + const view = common.applyUndo(block, undo); + const flags = Script.flags.VERIFY_P2SH | Script.flags.VERIFY_DERSIG; const height = 300025; - let sigops = 0; - let reward = 0; assert(block.verify()); assert(block.txs[0].isCoinbase()); @@ -207,7 +148,8 @@ describe('Block', function() { assert(!block.hasWitness()); assert.equal(block.getWeight(), 1136924); - const flags = Script.flags.VERIFY_P2SH | Script.flags.VERIFY_DERSIG; + let sigops = 0; + let reward = 0; for (let i = 1; i < block.txs.length; i++) { const tx = block.txs[i]; @@ -281,32 +223,25 @@ describe('Block', function() { }); it('should handle compact block', () => { - const block = Block.fromRaw(cmpct1block); - const cblock1 = CompactBlock.fromRaw(cmpct1); + const block = Block.fromRaw(block426884); + const cblock1 = CompactBlock.fromRaw(compact426884); const cblock2 = CompactBlock.fromBlock(block, false, cblock1.keyNonce); - const map = new Map(); assert(cblock1.init()); - assert.deepEqual(cblock1.toRaw(), cmpct1); - assert.deepEqual(cblock2.toRaw(), cmpct1); + assert.deepEqual(cblock1.toRaw(), compact426884); + assert.deepEqual(cblock2.toRaw(), compact426884); - for (let i = 0; i < block.txs.length; i++) { - const tx = block.txs[i]; + const map = new Map(); + + for (const tx of block.txs) map.set(tx.hash('hex'), { tx: tx }); - } - const mempool = { - map: map - }; + const full = cblock1.fillMempool(false, { map }); + assert(full); - assert.equal(cblock1.sid(block.txs[1].hash()), 125673511480291); - - const result = cblock1.fillMempool(false, mempool); - assert(result); - - for (let i = 0; i < cblock1.available.length; i++) - assert(cblock1.available[i]); + for (const tx of cblock1.available) + assert(tx); assert.equal( cblock1.toBlock().toRaw().toString('hex'), @@ -314,46 +249,39 @@ describe('Block', function() { }); it('should handle half-full compact block', () => { - const block = Block.fromRaw(cmpct1block); - const cblock1 = CompactBlock.fromRaw(cmpct1); + const block = Block.fromRaw(block426884); + const cblock1 = CompactBlock.fromRaw(compact426884); const cblock2 = CompactBlock.fromBlock(block, false, cblock1.keyNonce); - const map = new Map(); assert(cblock1.init()); - assert.deepEqual(cblock1.toRaw(), cmpct1); - assert.deepEqual(cblock2.toRaw(), cmpct1); + assert.deepEqual(cblock1.toRaw(), compact426884); + assert.deepEqual(cblock2.toRaw(), compact426884); - for (let i = 0; i < block.txs.length >>> 1; i++) { + const map = new Map(); + + for (let i = 0; i < (block.txs.length >>> 1); i++) { const tx = block.txs[i]; map.set(tx.hash('hex'), { tx: tx }); } - const mempool = { - map: map - }; - - assert.equal(cblock1.sid(block.txs[1].hash()), 125673511480291); - - let result = cblock1.fillMempool(false, mempool); - assert(!result); + const full = cblock1.fillMempool(false, { map }); + assert(!full); let req = cblock1.toRequest(); assert.equal(req.hash, cblock1.hash('hex')); - assert.deepEqual(req.indexes, [5, 6, 7, 8, 9]); req = TXRequest.fromRaw(req.toRaw()); assert.equal(req.hash, cblock1.hash('hex')); - assert.deepEqual(req.indexes, [5, 6, 7, 8, 9]); let res = TXResponse.fromBlock(block, req); res = TXResponse.fromRaw(res.toRaw()); - result = cblock1.fillMissing(res); - assert(result); + const filled = cblock1.fillMissing(res); + assert(filled); - for (let i = 0; i < cblock1.available.length; i++) - assert(cblock1.available[i]); + for (const tx of cblock1.available) + assert(tx); assert.equal( cblock1.toBlock().toRaw().toString('hex'), @@ -361,30 +289,27 @@ describe('Block', function() { }); it('should handle compact block', () => { - const block = Block.fromRaw(cmpct2block); - const cblock1 = CompactBlock.fromRaw(cmpct2); + const block = Block.fromRaw(block898352); + const cblock1 = CompactBlock.fromRaw(compact898352); const cblock2 = CompactBlock.fromBlock(block, false, cblock1.keyNonce); - const map = new Map(); assert(cblock1.init()); - assert.deepEqual(cblock1.toRaw(), cmpct2); - assert.deepEqual(cblock2.toRaw(), cmpct2); + assert.deepEqual(cblock1.toRaw(), compact898352); + assert.deepEqual(cblock2.toRaw(), compact898352); - for (let i = 0; i < block.txs.length; i++) { - const tx = block.txs[i]; + const map = new Map(); + + for (const tx of block.txs) map.set(tx.hash('hex'), { tx: tx }); - } - const mempool = { - map: map - }; + assert.equal(cblock1.sid(block.txs[1].hash()), 125673511480291); - const result = cblock1.fillMempool(false, mempool); - assert(result); + const full = cblock1.fillMempool(false, { map }); + assert(full); - for (let i = 0; i < cblock1.available.length; i++) - assert(cblock1.available[i]); + for (const tx of cblock1.available) + assert(tx); assert.equal( cblock1.toBlock().toRaw().toString('hex'), @@ -392,97 +317,86 @@ describe('Block', function() { }); it('should handle half-full compact block', () => { - const block = Block.fromRaw(cmpct2block); - const cblock1 = CompactBlock.fromRaw(cmpct2); + const block = Block.fromRaw(block898352); + const cblock1 = CompactBlock.fromRaw(compact898352); const cblock2 = CompactBlock.fromBlock(block, false, cblock1.keyNonce); - const map = new Map(); assert(cblock1.init()); - assert.deepEqual(cblock1.toRaw(), cmpct2); - assert.deepEqual(cblock2.toRaw(), cmpct2); + assert.deepEqual(cblock1.toRaw(), compact898352); + assert.deepEqual(cblock2.toRaw(), compact898352); - for (let i = 0; i < block.txs.length >>> 1; i++) { + const map = new Map(); + + for (let i = 0; i < (block.txs.length >>> 1); i++) { const tx = block.txs[i]; map.set(tx.hash('hex'), { tx: tx }); } - const mempool = { - map: map - }; + assert.equal(cblock1.sid(block.txs[1].hash()), 125673511480291); - let result = cblock1.fillMempool(false, mempool); - assert(!result); + const full = cblock1.fillMempool(false, { map }); + assert(!full); let req = cblock1.toRequest(); assert.equal(req.hash, cblock1.hash('hex')); + assert.deepEqual(req.indexes, [5, 6, 7, 8, 9]); req = TXRequest.fromRaw(req.toRaw()); assert.equal(req.hash, cblock1.hash('hex')); + assert.deepEqual(req.indexes, [5, 6, 7, 8, 9]); let res = TXResponse.fromBlock(block, req); res = TXResponse.fromRaw(res.toRaw()); - result = cblock1.fillMissing(res); - assert(result); + const filled = cblock1.fillMissing(res); + assert(filled); - for (let i = 0; i < cblock1.available.length; i++) - assert(cblock1.available[i]); + for (const tx of cblock1.available) + assert(tx); assert.equal( cblock1.toBlock().toRaw().toString('hex'), block.toRaw().toString('hex')); }); - it('should count sigops for block 928828 (testnet)', async () => { - const blockRaw = await fs.readFile(`${__dirname}/data/block928828.raw`); - const undoRaw = await fs.readFile(`${__dirname}/data/undo928828.raw`); - const block = Block.fromRaw(blockRaw); - const undo = parseUndo(undoRaw); - const view = applyUndo(block, undo); - let sigops = 0; + it('should count sigops for block 928927 (testnet)', () => { + const block = Block.fromRaw(block928927); + const undo = common.parseUndo(undo928927); + const view = common.applyUndo(block, undo); const flags = Script.flags.VERIFY_P2SH | Script.flags.VERIFY_WITNESS; - for (let i = 0; i < block.txs.length; i++) { - const tx = block.txs[i]; - sigops += tx.getSigopsCost(view, flags); - } - - assert.equal(sigops, 23236); - assert.equal(block.getWeight(), 2481560); - }); - - it('should count sigops for block 928927 (testnet)', async () => { - const blockRaw = await fs.readFile(`${__dirname}/data/block928927.raw`); - const undoRaw = await fs.readFile(`${__dirname}/data/undo928927.raw`); - const block = Block.fromRaw(blockRaw); - const undo = parseUndo(undoRaw); - const view = applyUndo(block, undo); let sigops = 0; - const flags = Script.flags.VERIFY_P2SH | Script.flags.VERIFY_WITNESS; - - for (let i = 0; i < block.txs.length; i++) { - const tx = block.txs[i]; + for (const tx of block.txs) sigops += tx.getSigopsCost(view, flags); - } assert.equal(sigops, 10015); assert.equal(block.getWeight(), 3992391); }); - it('should count sigops for block 1087400 (testnet)', async () => { - const blockRaw = await fs.readFile(`${__dirname}/data/block1087400.raw`); - const undoRaw = await fs.readFile(`${__dirname}/data/undo1087400.raw`); - const block = Block.fromRaw(blockRaw); - const undo = parseUndo(undoRaw); - const view = applyUndo(block, undo); - let sigops = 0; + it('should count sigops for block 928828 (testnet)', () => { + const block = Block.fromRaw(block928828); + const undo = common.parseUndo(undo928828); + const view = common.applyUndo(block, undo); const flags = Script.flags.VERIFY_P2SH | Script.flags.VERIFY_WITNESS; - for (let i = 0; i < block.txs.length; i++) { - const tx = block.txs[i]; + let sigops = 0; + for (const tx of block.txs) + sigops += tx.getSigopsCost(view, flags); + + assert.equal(sigops, 23236); + assert.equal(block.getWeight(), 2481560); + }); + + it('should count sigops for block 1087400 (testnet)', () => { + const block = Block.fromRaw(block1087400); + const undo = common.parseUndo(undo1087400); + const view = common.applyUndo(block, undo); + const flags = Script.flags.VERIFY_P2SH | Script.flags.VERIFY_WITNESS; + + let sigops = 0; + for (const tx of block.txs) sigops += tx.getSigopsCost(view, flags); - } assert.equal(sigops, 1298); assert.equal(block.getWeight(), 193331); diff --git a/test/bloom-test.js b/test/bloom-test.js index 02660802..15dbe398 100644 --- a/test/bloom-test.js +++ b/test/bloom-test.js @@ -8,57 +8,51 @@ const Bloom = require('../lib/utils/bloom'); const RollingFilter = require('../lib/utils/rollingfilter'); const murmur3 = require('../lib/utils/murmur3'); +function testMurmur(str, seed, expect, enc) { + assert.equal(murmur3(Buffer.from(str, enc || 'ascii'), seed), expect); +} + describe('Bloom', function() { - const filterHex = '' - + '000000000000000000000000000000000000000000000000088004000000000000000' - + '000000000200000000000000000000000000000000800000000000000000002000000' - + '000000000000002000000000000000000000000000000000000000000040000200000' - + '0000000001000000800000080000000'; - - function mm(str, seed, expect, enc) { - assert.equal(murmur3(Buffer.from(str, enc || 'ascii'), seed), expect); - } - this.timeout(20000); it('should do proper murmur3', () => { - mm('', 0, 0); - mm('', 0xfba4c795, 0x6a396f08); - mm('00', 0xfba4c795, 0x2a101837); - mm('hello world', 0, 0x5e928f0f); + testMurmur('', 0, 0); + testMurmur('', 0xfba4c795, 0x6a396f08); + testMurmur('00', 0xfba4c795, 0x2a101837); + testMurmur('hello world', 0, 0x5e928f0f); - mm('', 0x00000000, 0x00000000, 'hex'); - mm('', 0xfba4c795, 0x6a396f08, 'hex'); - mm('', 0xffffffff, 0x81f16f39, 'hex'); + testMurmur('', 0x00000000, 0x00000000, 'hex'); + testMurmur('', 0xfba4c795, 0x6a396f08, 'hex'); + testMurmur('', 0xffffffff, 0x81f16f39, 'hex'); - mm('00', 0x00000000, 0x514e28b7, 'hex'); - mm('00', 0xfba4c795, 0xea3f0b17, 'hex'); - mm('ff', 0x00000000, 0xfd6cf10d, 'hex'); + testMurmur('00', 0x00000000, 0x514e28b7, 'hex'); + testMurmur('00', 0xfba4c795, 0xea3f0b17, 'hex'); + testMurmur('ff', 0x00000000, 0xfd6cf10d, 'hex'); - mm('0011', 0x00000000, 0x16c6b7ab, 'hex'); - mm('001122', 0x00000000, 0x8eb51c3d, 'hex'); - mm('00112233', 0x00000000, 0xb4471bf8, 'hex'); - mm('0011223344', 0x00000000, 0xe2301fa8, 'hex'); - mm('001122334455', 0x00000000, 0xfc2e4a15, 'hex'); - mm('00112233445566', 0x00000000, 0xb074502c, 'hex'); - mm('0011223344556677', 0x00000000, 0x8034d2a0, 'hex'); - mm('001122334455667788', 0x00000000, 0xb4698def, 'hex'); + testMurmur('0011', 0x00000000, 0x16c6b7ab, 'hex'); + testMurmur('001122', 0x00000000, 0x8eb51c3d, 'hex'); + testMurmur('00112233', 0x00000000, 0xb4471bf8, 'hex'); + testMurmur('0011223344', 0x00000000, 0xe2301fa8, 'hex'); + testMurmur('001122334455', 0x00000000, 0xfc2e4a15, 'hex'); + testMurmur('00112233445566', 0x00000000, 0xb074502c, 'hex'); + testMurmur('0011223344556677', 0x00000000, 0x8034d2a0, 'hex'); + testMurmur('001122334455667788', 0x00000000, 0xb4698def, 'hex'); }); it('should test and add stuff', () => { - const b = new Bloom(512, 10, 156); + const filter = new Bloom(512, 10, 156); - b.add('hello', 'ascii'); - assert(b.test('hello', 'ascii')); - assert(!b.test('hello!', 'ascii')); - assert(!b.test('ping', 'ascii')); + filter.add('hello', 'ascii'); + assert(filter.test('hello', 'ascii')); + assert(!filter.test('hello!', 'ascii')); + assert(!filter.test('ping', 'ascii')); - b.add('hello!', 'ascii'); - assert(b.test('hello!', 'ascii')); - assert(!b.test('ping', 'ascii')); + filter.add('hello!', 'ascii'); + assert(filter.test('hello!', 'ascii')); + assert(!filter.test('ping', 'ascii')); - b.add('ping', 'ascii'); - assert(b.test('ping', 'ascii')); + filter.add('ping', 'ascii'); + assert(filter.test('ping', 'ascii')); }); it('should serialize to the correct format', () => { @@ -67,6 +61,11 @@ describe('Bloom', function() { const item2 = '047b00000078da0dca3b0ec2300c00d0ab4466ed10' + 'e763272c6c9ca052972c69e3884a9022084215e2eef' + '0e6f781656b5d5a87231cd4349e534b6dea55ad4ff55e'; + const filterHex = '' + + '000000000000000000000000000000000000000000000000088004000000000000000' + + '000000000200000000000000000000000000000000800000000000000000002000000' + + '000000000000002000000000000000000000000000000000000000000040000200000' + + '0000000001000000800000080000000'; filter.add(item1, 'hex'); filter.add(item2, 'hex'); assert.equal(filter.filter.toString('hex'), filterHex); @@ -74,17 +73,16 @@ describe('Bloom', function() { it('should handle 1m ops with regular filter', () => { const filter = Bloom.fromRate(210000, 0.00001, -1); - let i, j, str; filter.tweak = 0xdeadbeef; // ~1m operations - for (i = 0; i < 1000; i++) { - str = 'foobar' + i; + for (let i = 0; i < 1000; i++) { + const str = 'foobar' + i; + let j = i; filter.add(str, 'ascii'); - j = i; do { - str = 'foobar' + j; + const str = 'foobar' + j; assert(filter.test(str, 'ascii') === true); assert(filter.test(str + '-', 'ascii') === false); } while (j--); @@ -93,17 +91,16 @@ describe('Bloom', function() { it('should handle 1m ops with rolling filter', () => { const filter = new RollingFilter(210000, 0.00001); - let i, j, str; filter.tweak = 0xdeadbeef; // ~1m operations - for (i = 0; i < 1000; i++) { - str = 'foobar' + i; + for (let i = 0; i < 1000; i++) { + const str = 'foobar' + i; + let j = i; filter.add(str, 'ascii'); - j = i; do { - str = 'foobar' + j; + const str = 'foobar' + j; assert(filter.test(str, 'ascii') === true); assert(filter.test(str + '-', 'ascii') === false); } while (j--); @@ -112,61 +109,60 @@ describe('Bloom', function() { it('should handle rolling generations', () => { const filter = new RollingFilter(50, 0.00001); - let i, j, str; filter.tweak = 0xdeadbeee; - for (i = 0; i < 25; i++) { - str = 'foobar' + i; + for (let i = 0; i < 25; i++) { + const str = 'foobar' + i; + let j = i; filter.add(str, 'ascii'); - j = i; do { - str = 'foobar' + j; + const str = 'foobar' + j; assert(filter.test(str, 'ascii') === true); assert(filter.test(str + '-', 'ascii') === false); } while (j--); } - for (i = 25; i < 50; i++) { - str = 'foobar' + i; + for (let i = 25; i < 50; i++) { + const str = 'foobar' + i; + let j = i; filter.add(str, 'ascii'); - j = i; do { - str = 'foobar' + j; + const str = 'foobar' + j; assert(filter.test(str, 'ascii') === true, str); assert(filter.test(str + '-', 'ascii') === false, str); } while (j--); } - for (i = 50; i < 75; i++) { - str = 'foobar' + i; + for (let i = 50; i < 75; i++) { + const str = 'foobar' + i; + let j = i; filter.add(str, 'ascii'); - j = i; do { - str = 'foobar' + j; + const str = 'foobar' + j; assert(filter.test(str, 'ascii') === true, str); assert(filter.test(str + '-', 'ascii') === false, str); } while (j--); } - for (i = 75; i < 100; i++) { - str = 'foobar' + i; + for (let i = 75; i < 100; i++) { + const str = 'foobar' + i; + let j = i; filter.add(str, 'ascii'); - j = i; do { - str = 'foobar' + j; + const str = 'foobar' + j; assert(filter.test(str, 'ascii') === true, str); assert(filter.test(str + '-', 'ascii') === false, str); } while (j-- > 25); assert(filter.test('foobar 24', 'ascii') === false); } - for (i = 100; i < 125; i++) { - str = 'foobar' + i; + for (let i = 100; i < 125; i++) { + const str = 'foobar' + i; + let j = i; filter.add(str, 'ascii'); - j = i; do { - str = 'foobar' + j; + const str = 'foobar' + j; assert(filter.test(str, 'ascii') === true, str); assert(filter.test(str + '-', 'ascii') === false, str); } while (j-- > 50); diff --git a/test/chachapoly-test.js b/test/chachapoly-test.js index ec1f7bb9..397bc0ad 100644 --- a/test/chachapoly-test.js +++ b/test/chachapoly-test.js @@ -10,64 +10,59 @@ const AEAD = require('../lib/crypto/aead'); describe('ChaCha20 / Poly1305 / AEAD', function() { function testChaCha(options) { - let key = options.key; - let nonce = options.nonce; - let plain = options.plain; - let ciphertext = options.ciphertext; + const key = Buffer.from(options.key, 'hex'); + const nonce = Buffer.from(options.nonce, 'hex'); + const plain = Buffer.from(options.plain, 'hex'); + const ciphertext = Buffer.from(options.ciphertext, 'hex'); const counter = options.counter; - key = Buffer.from(key, 'hex'); - nonce = Buffer.from(nonce, 'hex'); - plain = Buffer.from(plain, 'hex'); - ciphertext = Buffer.from(ciphertext, 'hex'); + { + const chacha = new ChaCha20(); + chacha.init(key, nonce, counter); + const plainenc = Buffer.from(plain); + chacha.encrypt(plainenc); + assert.deepEqual(plainenc, ciphertext); + } - let chacha = new ChaCha20(); - chacha.init(key, nonce, counter); - const plainenc = Buffer.from(plain); - chacha.encrypt(plainenc); - assert.deepEqual(plainenc, ciphertext); - - chacha = new ChaCha20(); - chacha.init(key, nonce, counter); - chacha.encrypt(ciphertext); - assert.deepEqual(plain, ciphertext); + { + const chacha = new ChaCha20(); + chacha.init(key, nonce, counter); + chacha.encrypt(ciphertext); + assert.deepEqual(plain, ciphertext); + } } function testAEAD(options) { - let plain = options.plain; - let aad = options.aad; - let key = options.key; - let nonce = options.nonce; - let pk = options.pk; - let ciphertext = options.ciphertext; - let tag = options.tag; + const plain = Buffer.from(options.plain, 'hex'); + const aad = Buffer.from(options.aad, 'hex'); + const key = Buffer.from(options.key, 'hex'); + const nonce = Buffer.from(options.nonce, 'hex'); + const pk = Buffer.from(options.pk, 'hex'); + const ciphertext = Buffer.from(options.ciphertext, 'hex'); + const tag = Buffer.from(options.tag, 'hex'); - plain = Buffer.from(plain, 'hex'); - aad = Buffer.from(aad, 'hex'); - key = Buffer.from(key, 'hex'); - nonce = Buffer.from(nonce, 'hex'); - pk = Buffer.from(pk, 'hex'); - ciphertext = Buffer.from(ciphertext, 'hex'); - tag = Buffer.from(tag, 'hex'); + { + const aead = new AEAD(); + aead.init(key, nonce); + assert.equal(aead.chacha20.getCounter(), 1); + assert.deepEqual(aead.polyKey, pk); + aead.aad(aad); + const plainenc = Buffer.from(plain); + aead.encrypt(plainenc); + assert.deepEqual(plainenc, ciphertext); + assert.deepEqual(aead.finish(), tag); + } - let aead = new AEAD(); - aead.init(key, nonce); - assert.equal(aead.chacha20.getCounter(), 1); - assert.deepEqual(aead.polyKey, pk); - aead.aad(aad); - const plainenc = Buffer.from(plain); - aead.encrypt(plainenc); - assert.deepEqual(plainenc, ciphertext); - assert.deepEqual(aead.finish(), tag); - - aead = new AEAD(); - aead.init(key, nonce); - assert.equal(aead.chacha20.getCounter(), 1); - assert.deepEqual(aead.polyKey, pk); - aead.aad(aad); - aead.decrypt(ciphertext); - assert.deepEqual(ciphertext, plain); - assert.deepEqual(aead.finish(), tag); + { + const aead = new AEAD(); + aead.init(key, nonce); + assert.equal(aead.chacha20.getCounter(), 1); + assert.deepEqual(aead.polyKey, pk); + aead.aad(aad); + aead.decrypt(ciphertext); + assert.deepEqual(ciphertext, plain); + assert.deepEqual(aead.finish(), tag); + } } it('should perform chacha20', () => { @@ -177,14 +172,13 @@ describe('ChaCha20 / Poly1305 / AEAD', function() { }); it('should perform poly1305', () => { - let key = '85d6be7857556d337f4452fe42d506a' - + '80103808afb0db2fd4abff6af4149f51b'; - let msg = 'Cryptographic Forum Research Group'; - let tag = 'a8061dc1305136c6c22b8baf0c0127a9'; + const key = Buffer.from('' + + '85d6be7857556d337f4452fe42d506a' + + '80103808afb0db2fd4abff6af4149f51b', + 'hex'); - key = Buffer.from(key, 'hex'); - msg = Buffer.from(msg, 'ascii'); - tag = Buffer.from(tag, 'hex'); + const msg = Buffer.from('Cryptographic Forum Research Group', 'ascii'); + const tag = Buffer.from('a8061dc1305136c6c22b8baf0c0127a9', 'hex'); const mac = Poly1305.auth(msg, key); assert(Poly1305.verify(mac, tag)); diff --git a/test/coins-test.js b/test/coins-test.js index ae312006..53f6ada5 100644 --- a/test/coins-test.js +++ b/test/coins-test.js @@ -65,14 +65,14 @@ describe('Coins', function() { view.addTX(tx1, 1); - let coins = view.get(hash); + const coins = view.get(hash); assert(coins); + const length = coins.outputs.size; view.spendEntry(new Outpoint(hash, 0)); - coins = view.get(hash); - assert(coins); + assert(view.get(hash) === coins); const entry = coins.get(0); assert(entry); diff --git a/test/data/compact2-block.raw b/test/data/block426884.raw similarity index 100% rename from test/data/compact2-block.raw rename to test/data/block426884.raw diff --git a/test/data/compact1-block.raw b/test/data/block898352.raw similarity index 100% rename from test/data/compact1-block.raw rename to test/data/block898352.raw diff --git a/test/data/compact2.raw b/test/data/compact426884.raw similarity index 100% rename from test/data/compact2.raw rename to test/data/compact426884.raw diff --git a/test/data/compact1.raw b/test/data/compact898352.raw similarity index 100% rename from test/data/compact1.raw rename to test/data/compact898352.raw diff --git a/test/data/merkle300025.raw b/test/data/merkle300025.raw new file mode 100644 index 00000000..73153647 Binary files /dev/null and b/test/data/merkle300025.raw differ diff --git a/test/data/mnemonic-english.json b/test/data/mnemonic-english.json new file mode 100644 index 00000000..e650854a --- /dev/null +++ b/test/data/mnemonic-english.json @@ -0,0 +1,170 @@ +[ + [ + "00000000000000000000000000000000", + "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about", + "TREZOR", + "c55257c360c07c72029aebc1b53c05ed0362ada38ead3e3e9efa3708e53495531f09a6987599d18264c1e1c92f2cf141630c7a3c4ab7c81b2f001698e7463b04", + "xprv9s21ZrQH143K3h3fDYiay8mocZ3afhfULfb5GX8kCBdno77K4HiA15Tg23wpbeF1pLfs1c5SPmYHrEpTuuRhxMwvKDwqdKiGJS9XFKzUsAF" + ], + [ + "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f", + "legal winner thank year wave sausage worth useful legal winner thank yellow", + "TREZOR", + "2e8905819b8723fe2c1d161860e5ee1830318dbf49a83bd451cfb8440c28bd6fa457fe1296106559a3c80937a1c1069be3a3a5bd381ee6260e8d9739fce1f607", + "xprv9s21ZrQH143K2gA81bYFHqU68xz1cX2APaSq5tt6MFSLeXnCKV1RVUJt9FWNTbrrryem4ZckN8k4Ls1H6nwdvDTvnV7zEXs2HgPezuVccsq" + ], + [ + "80808080808080808080808080808080", + "letter advice cage absurd amount doctor acoustic avoid letter advice cage above", + "TREZOR", + "d71de856f81a8acc65e6fc851a38d4d7ec216fd0796d0a6827a3ad6ed5511a30fa280f12eb2e47ed2ac03b5c462a0358d18d69fe4f985ec81778c1b370b652a8", + "xprv9s21ZrQH143K2shfP28KM3nr5Ap1SXjz8gc2rAqqMEynmjt6o1qboCDpxckqXavCwdnYds6yBHZGKHv7ef2eTXy461PXUjBFQg6PrwY4Gzq" + ], + [ + "ffffffffffffffffffffffffffffffff", + "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong", + "TREZOR", + "ac27495480225222079d7be181583751e86f571027b0497b5b5d11218e0a8a13332572917f0f8e5a589620c6f15b11c61dee327651a14c34e18231052e48c069", + "xprv9s21ZrQH143K2V4oox4M8Zmhi2Fjx5XK4Lf7GKRvPSgydU3mjZuKGCTg7UPiBUD7ydVPvSLtg9hjp7MQTYsW67rZHAXeccqYqrsx8LcXnyd" + ], + [ + "000000000000000000000000000000000000000000000000", + "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon agent", + "TREZOR", + "035895f2f481b1b0f01fcf8c289c794660b289981a78f8106447707fdd9666ca06da5a9a565181599b79f53b844d8a71dd9f439c52a3d7b3e8a79c906ac845fa", + "xprv9s21ZrQH143K3mEDrypcZ2usWqFgzKB6jBBx9B6GfC7fu26X6hPRzVjzkqkPvDqp6g5eypdk6cyhGnBngbjeHTe4LsuLG1cCmKJka5SMkmU" + ], + [ + "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f", + "legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal will", + "TREZOR", + "f2b94508732bcbacbcc020faefecfc89feafa6649a5491b8c952cede496c214a0c7b3c392d168748f2d4a612bada0753b52a1c7ac53c1e93abd5c6320b9e95dd", + "xprv9s21ZrQH143K3Lv9MZLj16np5GzLe7tDKQfVusBni7toqJGcnKRtHSxUwbKUyUWiwpK55g1DUSsw76TF1T93VT4gz4wt5RM23pkaQLnvBh7" + ], + [ + "808080808080808080808080808080808080808080808080", + "letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter always", + "TREZOR", + "107d7c02a5aa6f38c58083ff74f04c607c2d2c0ecc55501dadd72d025b751bc27fe913ffb796f841c49b1d33b610cf0e91d3aa239027f5e99fe4ce9e5088cd65", + "xprv9s21ZrQH143K3VPCbxbUtpkh9pRG371UCLDz3BjceqP1jz7XZsQ5EnNkYAEkfeZp62cDNj13ZTEVG1TEro9sZ9grfRmcYWLBhCocViKEJae" + ], + [ + "ffffffffffffffffffffffffffffffffffffffffffffffff", + "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo when", + "TREZOR", + "0cd6e5d827bb62eb8fc1e262254223817fd068a74b5b449cc2f667c3f1f985a76379b43348d952e2265b4cd129090758b3e3c2c49103b5051aac2eaeb890a528", + "xprv9s21ZrQH143K36Ao5jHRVhFGDbLP6FCx8BEEmpru77ef3bmA928BxsqvVM27WnvvyfWywiFN8K6yToqMaGYfzS6Db1EHAXT5TuyCLBXUfdm" + ], + [ + "0000000000000000000000000000000000000000000000000000000000000000", + "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art", + "TREZOR", + "bda85446c68413707090a52022edd26a1c9462295029f2e60cd7c4f2bbd3097170af7a4d73245cafa9c3cca8d561a7c3de6f5d4a10be8ed2a5e608d68f92fcc8", + "xprv9s21ZrQH143K32qBagUJAMU2LsHg3ka7jqMcV98Y7gVeVyNStwYS3U7yVVoDZ4btbRNf4h6ibWpY22iRmXq35qgLs79f312g2kj5539ebPM" + ], + [ + "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f", + "legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth title", + "TREZOR", + "bc09fca1804f7e69da93c2f2028eb238c227f2e9dda30cd63699232578480a4021b146ad717fbb7e451ce9eb835f43620bf5c514db0f8add49f5d121449d3e87", + "xprv9s21ZrQH143K3Y1sd2XVu9wtqxJRvybCfAetjUrMMco6r3v9qZTBeXiBZkS8JxWbcGJZyio8TrZtm6pkbzG8SYt1sxwNLh3Wx7to5pgiVFU" + ], + [ + "8080808080808080808080808080808080808080808080808080808080808080", + "letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic bless", + "TREZOR", + "c0c519bd0e91a2ed54357d9d1ebef6f5af218a153624cf4f2da911a0ed8f7a09e2ef61af0aca007096df430022f7a2b6fb91661a9589097069720d015e4e982f", + "xprv9s21ZrQH143K3CSnQNYC3MqAAqHwxeTLhDbhF43A4ss4ciWNmCY9zQGvAKUSqVUf2vPHBTSE1rB2pg4avopqSiLVzXEU8KziNnVPauTqLRo" + ], + [ + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo vote", + "TREZOR", + "dd48c104698c30cfe2b6142103248622fb7bb0ff692eebb00089b32d22484e1613912f0a5b694407be899ffd31ed3992c456cdf60f5d4564b8ba3f05a69890ad", + "xprv9s21ZrQH143K2WFF16X85T2QCpndrGwx6GueB72Zf3AHwHJaknRXNF37ZmDrtHrrLSHvbuRejXcnYxoZKvRquTPyp2JiNG3XcjQyzSEgqCB" + ], + [ + "9e885d952ad362caeb4efe34a8e91bd2", + "ozone drill grab fiber curtain grace pudding thank cruise elder eight picnic", + "TREZOR", + "274ddc525802f7c828d8ef7ddbcdc5304e87ac3535913611fbbfa986d0c9e5476c91689f9c8a54fd55bd38606aa6a8595ad213d4c9c9f9aca3fb217069a41028", + "xprv9s21ZrQH143K2oZ9stBYpoaZ2ktHj7jLz7iMqpgg1En8kKFTXJHsjxry1JbKH19YrDTicVwKPehFKTbmaxgVEc5TpHdS1aYhB2s9aFJBeJH" + ], + [ + "6610b25967cdcca9d59875f5cb50b0ea75433311869e930b", + "gravity machine north sort system female filter attitude volume fold club stay feature office ecology stable narrow fog", + "TREZOR", + "628c3827a8823298ee685db84f55caa34b5cc195a778e52d45f59bcf75aba68e4d7590e101dc414bc1bbd5737666fbbef35d1f1903953b66624f910feef245ac", + "xprv9s21ZrQH143K3uT8eQowUjsxrmsA9YUuQQK1RLqFufzybxD6DH6gPY7NjJ5G3EPHjsWDrs9iivSbmvjc9DQJbJGatfa9pv4MZ3wjr8qWPAK" + ], + [ + "68a79eaca2324873eacc50cb9c6eca8cc68ea5d936f98787c60c7ebc74e6ce7c", + "hamster diagram private dutch cause delay private meat slide toddler razor book happy fancy gospel tennis maple dilemma loan word shrug inflict delay length", + "TREZOR", + "64c87cde7e12ecf6704ab95bb1408bef047c22db4cc7491c4271d170a1b213d20b385bc1588d9c7b38f1b39d415665b8a9030c9ec653d75e65f847d8fc1fc440", + "xprv9s21ZrQH143K2XTAhys3pMNcGn261Fi5Ta2Pw8PwaVPhg3D8DWkzWQwjTJfskj8ofb81i9NP2cUNKxwjueJHHMQAnxtivTA75uUFqPFeWzk" + ], + [ + "c0ba5a8e914111210f2bd131f3d5e08d", + "scheme spot photo card baby mountain device kick cradle pact join borrow", + "TREZOR", + "ea725895aaae8d4c1cf682c1bfd2d358d52ed9f0f0591131b559e2724bb234fca05aa9c02c57407e04ee9dc3b454aa63fbff483a8b11de949624b9f1831a9612", + "xprv9s21ZrQH143K3FperxDp8vFsFycKCRcJGAFmcV7umQmcnMZaLtZRt13QJDsoS5F6oYT6BB4sS6zmTmyQAEkJKxJ7yByDNtRe5asP2jFGhT6" + ], + [ + "6d9be1ee6ebd27a258115aad99b7317b9c8d28b6d76431c3", + "horn tenant knee talent sponsor spell gate clip pulse soap slush warm silver nephew swap uncle crack brave", + "TREZOR", + "fd579828af3da1d32544ce4db5c73d53fc8acc4ddb1e3b251a31179cdb71e853c56d2fcb11aed39898ce6c34b10b5382772db8796e52837b54468aeb312cfc3d", + "xprv9s21ZrQH143K3R1SfVZZLtVbXEB9ryVxmVtVMsMwmEyEvgXN6Q84LKkLRmf4ST6QrLeBm3jQsb9gx1uo23TS7vo3vAkZGZz71uuLCcywUkt" + ], + [ + "9f6a2878b2520799a44ef18bc7df394e7061a224d2c33cd015b157d746869863", + "panda eyebrow bullet gorilla call smoke muffin taste mesh discover soft ostrich alcohol speed nation flash devote level hobby quick inner drive ghost inside", + "TREZOR", + "72be8e052fc4919d2adf28d5306b5474b0069df35b02303de8c1729c9538dbb6fc2d731d5f832193cd9fb6aeecbc469594a70e3dd50811b5067f3b88b28c3e8d", + "xprv9s21ZrQH143K2WNnKmssvZYM96VAr47iHUQUTUyUXH3sAGNjhJANddnhw3i3y3pBbRAVk5M5qUGFr4rHbEWwXgX4qrvrceifCYQJbbFDems" + ], + [ + "23db8160a31d3e0dca3688ed941adbf3", + "cat swing flag economy stadium alone churn speed unique patch report train", + "TREZOR", + "deb5f45449e615feff5640f2e49f933ff51895de3b4381832b3139941c57b59205a42480c52175b6efcffaa58a2503887c1e8b363a707256bdd2b587b46541f5", + "xprv9s21ZrQH143K4G28omGMogEoYgDQuigBo8AFHAGDaJdqQ99QKMQ5J6fYTMfANTJy6xBmhvsNZ1CJzRZ64PWbnTFUn6CDV2FxoMDLXdk95DQ" + ], + [ + "8197a4a47f0425faeaa69deebc05ca29c0a5b5cc76ceacc0", + "light rule cinnamon wrap drastic word pride squirrel upgrade then income fatal apart sustain crack supply proud access", + "TREZOR", + "4cbdff1ca2db800fd61cae72a57475fdc6bab03e441fd63f96dabd1f183ef5b782925f00105f318309a7e9c3ea6967c7801e46c8a58082674c860a37b93eda02", + "xprv9s21ZrQH143K3wtsvY8L2aZyxkiWULZH4vyQE5XkHTXkmx8gHo6RUEfH3Jyr6NwkJhvano7Xb2o6UqFKWHVo5scE31SGDCAUsgVhiUuUDyh" + ], + [ + "066dca1a2bb7e8a1db2832148ce9933eea0f3ac9548d793112d9a95c9407efad", + "all hour make first leader extend hole alien behind guard gospel lava path output census museum junior mass reopen famous sing advance salt reform", + "TREZOR", + "26e975ec644423f4a4c4f4215ef09b4bd7ef924e85d1d17c4cf3f136c2863cf6df0a475045652c57eb5fb41513ca2a2d67722b77e954b4b3fc11f7590449191d", + "xprv9s21ZrQH143K3rEfqSM4QZRVmiMuSWY9wugscmaCjYja3SbUD3KPEB1a7QXJoajyR2T1SiXU7rFVRXMV9XdYVSZe7JoUXdP4SRHTxsT1nzm" + ], + [ + "f30f8c1da665478f49b001d94c5fc452", + "vessel ladder alter error federal sibling chat ability sun glass valve picture", + "TREZOR", + "2aaa9242daafcee6aa9d7269f17d4efe271e1b9a529178d7dc139cd18747090bf9d60295d0ce74309a78852a9caadf0af48aae1c6253839624076224374bc63f", + "xprv9s21ZrQH143K2QWV9Wn8Vvs6jbqfF1YbTCdURQW9dLFKDovpKaKrqS3SEWsXCu6ZNky9PSAENg6c9AQYHcg4PjopRGGKmdD313ZHszymnps" + ], + [ + "c10ec20dc3cd9f652c7fac2f1230f7a3c828389a14392f05", + "scissors invite lock maple supreme raw rapid void congress muscle digital elegant little brisk hair mango congress clump", + "TREZOR", + "7b4a10be9d98e6cba265566db7f136718e1398c71cb581e1b2f464cac1ceedf4f3e274dc270003c670ad8d02c4558b2f8e39edea2775c9e232c7cb798b069e88", + "xprv9s21ZrQH143K4aERa2bq7559eMCCEs2QmmqVjUuzfy5eAeDX4mqZffkYwpzGQRE2YEEeLVRoH4CSHxianrFaVnMN2RYaPUZJhJx8S5j6puX" + ], + [ + "f585c11aec520db57dd353c69554b21a89b20fb0650966fa0a9d6f74fd989d8f", + "void come effort suffer camp survey warrior heavy shoot primary clutch crush open amazing screen patrol group space point ten exist slush involve unfold", + "TREZOR", + "01f5bced59dec48e362f2c45b5de68b9fd6c92c6634f44d6d40aab69056506f0e35524a518034ddc1192e1dacd32c1ed3eaa3c3b131c88ed8e7e54c49a5d0998", + "xprv9s21ZrQH143K39rnQJknpH1WEPFJrzmAqqasiDcVrNuk926oizzJDDQkdiTvNPr2FYDYzWgiMiC63YmfPAa2oPyNB23r2g7d1yiK6WpqaQS" + ] +] diff --git a/test/data/mnemonic-japanese.json b/test/data/mnemonic-japanese.json new file mode 100644 index 00000000..a5764fdf --- /dev/null +++ b/test/data/mnemonic-japanese.json @@ -0,0 +1,170 @@ +[ + [ + "00000000000000000000000000000000", + "あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あおぞら", + "メートルガバヴァぱばぐゞちぢ十人十色", + "a262d6fb6122ecf45be09c50492b31f92e9beb7d9a845987a02cefda57a15f9c467a17872029a9e92299b5cbdf306e3a0ee620245cbd508959b6cb7ca637bd55", + "xprv9s21ZrQH143K258jAiWPAM6JYT9hLA91MV3AZUKfxmLZJCjCHeSjBvMbDy8C1mJ2FL5ytExyS97FAe6pQ6SD5Jt9SwHaLorA8i5Eojokfo1" + ], + [ + "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f", + "そつう れきだい ほんやく わかす りくつ ばいか ろせん やちん そつう れきだい ほんやく わかめ", + "メートルガバヴァぱばぐゞちぢ十人十色", + "aee025cbe6ca256862f889e48110a6a382365142f7d16f2b9545285b3af64e542143a577e9c144e101a6bdca18f8d97ec3366ebf5b088b1c1af9bc31346e60d9", + "xprv9s21ZrQH143K3ra1D6uGQyST9UqtUscH99GK8MBh5RrgPkrQo83QG4o6H2YktwSKvoZRVXDQZQrSyCDpHdA2j8i3PW5M9LkauaaTKwym1Wf" + ], + [ + "80808080808080808080808080808080", + "そとづら あまど おおう あこがれる いくぶん けいけん あたえる いよく そとづら あまど おおう あかちゃん", + "メートルガバヴァぱばぐゞちぢ十人十色", + "e51736736ebdf77eda23fa17e31475fa1d9509c78f1deb6b4aacfbd760a7e2ad769c714352c95143b5c1241985bcb407df36d64e75dd5a2b78ca5d2ba82a3544", + "xprv9s21ZrQH143K2aDKfG8hpfvRXzANmyBQWoqoUXWaSwVZcKtnmX5xTVkkHAdD9yykuuBcagjCFK6iLcBdHHxXC1g3TT9xHSu4PW6SRf3KvVy" + ], + [ + "ffffffffffffffffffffffffffffffff", + "われる われる われる われる われる われる われる われる われる われる われる ろんぶん", + "メートルガバヴァぱばぐゞちぢ十人十色", + "4cd2ef49b479af5e1efbbd1e0bdc117f6a29b1010211df4f78e2ed40082865793e57949236c43b9fe591ec70e5bb4298b8b71dc4b267bb96ed4ed282c8f7761c", + "xprv9s21ZrQH143K4WxYzpW3izjoq6e51NSZgN6AHxoKxZStsxBvtxuQDxPyvb8o4pSbxYPCyJGKewMxrHWvTBY6WEFX4svSzB2ezmatzzJW9wi" + ], + [ + "000000000000000000000000000000000000000000000000", + "あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あらいぐま", + "メートルガバヴァぱばぐゞちぢ十人十色", + "d99e8f1ce2d4288d30b9c815ae981edd923c01aa4ffdc5dee1ab5fe0d4a3e13966023324d119105aff266dac32e5cd11431eeca23bbd7202ff423f30d6776d69", + "xprv9s21ZrQH143K2pqcK1QdBVm9r4gL4yQX6KFTqHWctvfZa9Wjhxow63ZGpSB27mVo1BBH4D1NoTo3gVAHAeqmhm5Z9SuC8xJmFYBFz978rza" + ], + [ + "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f", + "そつう れきだい ほんやく わかす りくつ ばいか ろせん やちん そつう れきだい ほんやく わかす りくつ ばいか ろせん やちん そつう れいぎ", + "メートルガバヴァぱばぐゞちぢ十人十色", + "eaaf171efa5de4838c758a93d6c86d2677d4ccda4a064a7136344e975f91fe61340ec8a615464b461d67baaf12b62ab5e742f944c7bd4ab6c341fbafba435716", + "xprv9s21ZrQH143K34NWKwHe5cBVDYuoKZ6iiqWczDMwGA9Ut57iCCTksDTnxE5AH3qHHvfcgwpRhyj4G7Y6FEewjVoQqq4gHN6CetyFdd3q4CR" + ], + [ + "808080808080808080808080808080808080808080808080", + "そとづら あまど おおう あこがれる いくぶん けいけん あたえる いよく そとづら あまど おおう あこがれる いくぶん けいけん あたえる いよく そとづら いきなり", + "メートルガバヴァぱばぐゞちぢ十人十色", + "aec0f8d3167a10683374c222e6e632f2940c0826587ea0a73ac5d0493b6a632590179a6538287641a9fc9df8e6f24e01bf1be548e1f74fd7407ccd72ecebe425", + "xprv9s21ZrQH143K4RABcYmYKbZybgJrvpcnricsuNaZvsGVo7pupfELFY6TJw5G5XVswQodBzaRtfPkTi6aVCmC349A3yYzAZLfT7emP8m1RFX" + ], + [ + "ffffffffffffffffffffffffffffffffffffffffffffffff", + "われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる りんご", + "メートルガバヴァぱばぐゞちぢ十人十色", + "f0f738128a65b8d1854d68de50ed97ac1831fc3a978c569e415bbcb431a6a671d4377e3b56abd518daa861676c4da75a19ccb41e00c37d086941e471a4374b95", + "xprv9s21ZrQH143K2ThaKxBDxUByy4gNwULJyqKQzZXyF3aLyGdknnP18KvKVZwCvBJGXaAsKd7oh2ypLbjyDn4bDY1iiSPvNkKsVAGQGj7G3PZ" + ], + [ + "0000000000000000000000000000000000000000000000000000000000000000", + "あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん いってい", + "メートルガバヴァぱばぐゞちぢ十人十色", + "23f500eec4a563bf90cfda87b3e590b211b959985c555d17e88f46f7183590cd5793458b094a4dccc8f05807ec7bd2d19ce269e20568936a751f6f1ec7c14ddd", + "xprv9s21ZrQH143K3skSyXVw9CTTUHgKnsysvKiJw9MQjvTSY6ysTk4sFz58htMAcqHrjLdnUhqxRtmRy5AMJyWGeuQrDGSSfmcNh7cbfnrbDty" + ], + [ + "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f", + "そつう れきだい ほんやく わかす りくつ ばいか ろせん やちん そつう れきだい ほんやく わかす りくつ ばいか ろせん やちん そつう れきだい ほんやく わかす りくつ ばいか ろせん まんきつ", + "メートルガバヴァぱばぐゞちぢ十人十色", + "cd354a40aa2e241e8f306b3b752781b70dfd1c69190e510bc1297a9c5738e833bcdc179e81707d57263fb7564466f73d30bf979725ff783fb3eb4baa86560b05", + "xprv9s21ZrQH143K2y9p1D6KuxqypMjbiBKkiALERahpxvb46x9giqkvmv5KxGvGJZG2mdcMunmHaazYyEqYmkx9SnfndimSmgJv5EL24X1DGqV" + ], + [ + "8080808080808080808080808080808080808080808080808080808080808080", + "そとづら あまど おおう あこがれる いくぶん けいけん あたえる いよく そとづら あまど おおう あこがれる いくぶん けいけん あたえる いよく そとづら あまど おおう あこがれる いくぶん けいけん あたえる うめる", + "メートルガバヴァぱばぐゞちぢ十人十色", + "6b7cd1b2cdfeeef8615077cadd6a0625f417f287652991c80206dbd82db17bf317d5c50a80bd9edd836b39daa1b6973359944c46d3fcc0129198dc7dc5cd0e68", + "xprv9s21ZrQH143K2TuQM4HcbBBtvC19SaDgqn6cL16KTaPEazB26iCDfxABvBi9driWcbnF4rcLVpkx5iGG7zH2QcN7qNxL4cpb7mQ2G3ByAv7" + ], + [ + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる らいう", + "メートルガバヴァぱばぐゞちぢ十人十色", + "a44ba7054ac2f9226929d56505a51e13acdaa8a9097923ca07ea465c4c7e294c038f3f4e7e4b373726ba0057191aced6e48ac8d183f3a11569c426f0de414623", + "xprv9s21ZrQH143K3XTGpC53cWswvhg6GVQ1dE1yty6F9VhBcE7rnXmStuKwtaZNXRxw5N7tsh1REyAxun1S5BCYvhD5pNwxWUMMZaHwjTmXFdb" + ], + [ + "77c2b00716cec7213839159e404db50d", + "せまい うちがわ あずき かろう めずらしい だんち ますく おさめる ていぼう あたる すあな えしゃく", + "メートルガバヴァぱばぐゞちぢ十人十色", + "344cef9efc37d0cb36d89def03d09144dd51167923487eec42c487f7428908546fa31a3c26b7391a2b3afe7db81b9f8c5007336b58e269ea0bd10749a87e0193", + "xprv9s21ZrQH143K2fhvZfecKw8znj6QkGGV2F2t17BWA6VnanejVWBjQeV5DspseWdSvN49rrFpocPGt7aSGk9R5wJfC1LAwFMt6hV9qS7yGKR" + ], + [ + "b63a9c59a6e641f288ebc103017f1da9f8290b3da6bdef7b", + "ぬすむ ふっかつ うどん こうりつ しつじ りょうり おたがい せもたれ あつめる いちりゅう はんしゃ ごますり そんけい たいちょう らしんばん ぶんせき やすみ ほいく", + "メートルガバヴァぱばぐゞちぢ十人十色", + "b14e7d35904cb8569af0d6a016cee7066335a21c1c67891b01b83033cadb3e8a034a726e3909139ecd8b2eb9e9b05245684558f329b38480e262c1d6bc20ecc4", + "xprv9s21ZrQH143K25BDHG8fiLEPvKD9QCWqqs8V4yz2NeZXHbDgnAYW1EL5k8KWcn1kGKmsHrqbNvePJaYWEgkEMjJEepwTFfVzzyYRN7cyJgM" + ], + [ + "3e141609b97933b66a060dcddc71fad1d91677db872031e85f4c015c5e7e8982", + "くのう てぬぐい そんかい すろっと ちきゅう ほあん とさか はくしゅ ひびく みえる そざい てんすう たんぴん くしょう すいようび みけん きさらぎ げざん ふくざつ あつかう はやい くろう おやゆび こすう", + "メートルガバヴァぱばぐゞちぢ十人十色", + "32e78dce2aff5db25aa7a4a32b493b5d10b4089923f3320c8b287a77e512455443298351beb3f7eb2390c4662a2e566eec5217e1a37467af43b46668d515e41b", + "xprv9s21ZrQH143K2gbMb94GNwdogai6fA3vTrALH8eoNJKqPWn9KyeBMhUQLpsN5ePJkZdHsPmyDsECNLRaYiposqDDqsbk3ANk9hbsSgmVq7G" + ], + [ + "0460ef47585604c5660618db2e6a7e7f", + "あみもの いきおい ふいうち にげる ざんしょ じかん ついか はたん ほあん すんぽう てちがい わかめ", + "メートルガバヴァぱばぐゞちぢ十人十色", + "0acf902cd391e30f3f5cb0605d72a4c849342f62bd6a360298c7013d714d7e58ddf9c7fdf141d0949f17a2c9c37ced1d8cb2edabab97c4199b142c829850154b", + "xprv9s21ZrQH143K2Ec1okKMST9mN52SKEybSCeacWpAvPHMS5zFfMDfgwpJVXa96sd2sybGuJWE34CtSVYn42FBWLmFgmGeEmRvDriPnZVjWnU" + ], + [ + "72f60ebac5dd8add8d2a25a797102c3ce21bc029c200076f", + "すろっと にくしみ なやむ たとえる へいこう すくう きない けってい とくべつ ねっしん いたみ せんせい おくりがな まかい とくい けあな いきおい そそぐ", + "メートルガバヴァぱばぐゞちぢ十人十色", + "9869e220bec09b6f0c0011f46e1f9032b269f096344028f5006a6e69ea5b0b8afabbb6944a23e11ebd021f182dd056d96e4e3657df241ca40babda532d364f73", + "xprv9s21ZrQH143K2KKucNRqjGFooHw87xXFQpZGNZ1W7Vwtkr2YMkXFuxnMvqc8cegm8jkrVswEWuNEsGtFkaEedAG2cRTTtsz1bM6o8fCu3Pg" + ], + [ + "2c85efc7f24ee4573d2b81a6ec66cee209b2dcbd09d8eddc51e0215b0b68e416", + "かほご きうい ゆたか みすえる もらう がっこう よそう ずっと ときどき したうけ にんか はっこう つみき すうじつ よけい くげん もくてき まわり せめる げざい にげる にんたい たんそく ほそく", + "メートルガバヴァぱばぐゞちぢ十人十色", + "713b7e70c9fbc18c831bfd1f03302422822c3727a93a5efb9659bec6ad8d6f2c1b5c8ed8b0b77775feaf606e9d1cc0a84ac416a85514ad59f5541ff5e0382481", + "xprv9s21ZrQH143K2MXrVTP5hyWW9js9D8qipo9vVRTKYPCB8Mtw4XE57uepG7wuHRk3ZJLGAq1tdJ4So8hYHu4gBaJ4NANPjb1CJCpDd3e9H87" + ], + [ + "eaebabb2383351fd31d703840b32e9e2", + "めいえん さのう めだつ すてる きぬごし ろんぱ はんこ まける たいおう さかいし ねんいり はぶらし", + "メートルガバヴァぱばぐゞちぢ十人十色", + "06e1d5289a97bcc95cb4a6360719131a786aba057d8efd603a547bd254261c2a97fcd3e8a4e766d5416437e956b388336d36c7ad2dba4ee6796f0249b10ee961", + "xprv9s21ZrQH143K3ZVFWWSR9XVXY8EMqCNdj7YUx4DKdcCFitEsSH18aPcufobUfP3w9xz1XTUThwC4cYuf8VWvSwYWs8aTTAi7mr9jDsGHYLU" + ], + [ + "7ac45cfe7722ee6c7ba84fbc2d5bd61b45cb2fe5eb65aa78", + "せんぱい おしえる ぐんかん もらう きあい きぼう やおや いせえび のいず じゅしん よゆう きみつ さといも ちんもく ちわわ しんせいじ とめる はちみつ", + "メートルガバヴァぱばぐゞちぢ十人十色", + "1fef28785d08cbf41d7a20a3a6891043395779ed74503a5652760ee8c24dfe60972105ee71d5168071a35ab7b5bd2f8831f75488078a90f0926c8e9171b2bc4a", + "xprv9s21ZrQH143K3CXbNxjnq5iemN7AzZrtE71rvBAuZ4BnebovyS2hK3yjbAzsX6mrdxK8fa4kXPjnCC9FHpwgaPwZuCbrUJ4sj6xdPPYNeKK" + ], + [ + "4fa1a8bc3e6d80ee1316050e862c1812031493212b7ec3f3bb1b08f168cabeef", + "こころ いどう きあつ そうがんきょう へいあん せつりつ ごうせい はいち いびき きこく あんい おちつく きこえる けんとう たいこ すすめる はっけん ていど はんおん いんさつ うなぎ しねま れいぼう みつかる", + "メートルガバヴァぱばぐゞちぢ十人十色", + "43de99b502e152d4c198542624511db3007c8f8f126a30818e856b2d8a20400d29e7a7e3fdd21f909e23be5e3c8d9aee3a739b0b65041ff0b8637276703f65c2", + "xprv9s21ZrQH143K2WyZ5cAUSqkC89FeL4mrEG9N9VEhh9pR2g6SQjWbXNufkfBwwaZtMfpDzip9fZjm3huvMEJASWviaGqG1A6bDmoSQzd3YFy" + ], + [ + "18ab19a9f54a9274f03e5209a2ac8a91", + "うりきれ さいせい じゆう むろん とどける ぐうたら はいれつ ひけつ いずれ うちあわせ おさめる おたく", + "メートルガバヴァぱばぐゞちぢ十人十色", + "3d711f075ee44d8b535bb4561ad76d7d5350ea0b1f5d2eac054e869ff7963cdce9581097a477d697a2a9433a0c6884bea10a2193647677977c9820dd0921cbde", + "xprv9s21ZrQH143K49xMPBpnqsaXt6EECMPzVAvr18EiiJMHfgEedw28JiSCpB5DLGQB19NU2iiG4g7vVnLC6jn75B4n3LHCPwhpU6o7Srd6jYt" + ], + [ + "18a2e1d81b8ecfb2a333adcb0c17a5b9eb76cc5d05db91a4", + "うりきれ うねる せっさたくま きもち めんきょ へいたく たまご ぜっく びじゅつかん さんそ むせる せいじ ねくたい しはらい せおう ねんど たんまつ がいけん", + "メートルガバヴァぱばぐゞちぢ十人十色", + "753ec9e333e616e9471482b4b70a18d413241f1e335c65cd7996f32b66cf95546612c51dcf12ead6f805f9ee3d965846b894ae99b24204954be80810d292fcdd", + "xprv9s21ZrQH143K2WyY1Me9W7T8Wg7yQa9WFVAEn1vhoDkkP43dBVhsagabzEKMaz7UNtczbKkNowDLXSyVipJXVEBcpYJGBJ6ZaVDXNGoLStz" + ], + [ + "15da872c95a13dd738fbf50e427583ad61f18fd99f628c417a61cf8343c90419", + "うちゅう ふそく ひしょ がちょう うけもつ めいそう みかん そざい いばる うけとる さんま さこつ おうさま ぱんつ しひょう めした たはつ いちぶ つうじょう てさぎょう きつね みすえる いりぐち かめれおん", + "メートルガバヴァぱばぐゞちぢ十人十色", + "346b7321d8c04f6f37b49fdf062a2fddc8e1bf8f1d33171b65074531ec546d1d3469974beccb1a09263440fc92e1042580a557fdce314e27ee4eabb25fa5e5fe", + "xprv9s21ZrQH143K2qVq43Phs1xyVc6jSxXHWJ6CDJjod3cgyEin7hgeQV6Dkw6s1LSfMYxoah4bPAnW4wmXfDUS9ghBEM18xoY634CBtX8HPrA" + ] +] diff --git a/test/data/mnemonic1.json b/test/data/mnemonic1.json deleted file mode 100644 index 5c02e37c..00000000 --- a/test/data/mnemonic1.json +++ /dev/null @@ -1,148 +0,0 @@ -{ - "english": [ - [ - "00000000000000000000000000000000", - "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about", - "c55257c360c07c72029aebc1b53c05ed0362ada38ead3e3e9efa3708e53495531f09a6987599d18264c1e1c92f2cf141630c7a3c4ab7c81b2f001698e7463b04", - "xprv9s21ZrQH143K3h3fDYiay8mocZ3afhfULfb5GX8kCBdno77K4HiA15Tg23wpbeF1pLfs1c5SPmYHrEpTuuRhxMwvKDwqdKiGJS9XFKzUsAF" - ], - [ - "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f", - "legal winner thank year wave sausage worth useful legal winner thank yellow", - "2e8905819b8723fe2c1d161860e5ee1830318dbf49a83bd451cfb8440c28bd6fa457fe1296106559a3c80937a1c1069be3a3a5bd381ee6260e8d9739fce1f607", - "xprv9s21ZrQH143K2gA81bYFHqU68xz1cX2APaSq5tt6MFSLeXnCKV1RVUJt9FWNTbrrryem4ZckN8k4Ls1H6nwdvDTvnV7zEXs2HgPezuVccsq" - ], - [ - "80808080808080808080808080808080", - "letter advice cage absurd amount doctor acoustic avoid letter advice cage above", - "d71de856f81a8acc65e6fc851a38d4d7ec216fd0796d0a6827a3ad6ed5511a30fa280f12eb2e47ed2ac03b5c462a0358d18d69fe4f985ec81778c1b370b652a8", - "xprv9s21ZrQH143K2shfP28KM3nr5Ap1SXjz8gc2rAqqMEynmjt6o1qboCDpxckqXavCwdnYds6yBHZGKHv7ef2eTXy461PXUjBFQg6PrwY4Gzq" - ], - [ - "ffffffffffffffffffffffffffffffff", - "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong", - "ac27495480225222079d7be181583751e86f571027b0497b5b5d11218e0a8a13332572917f0f8e5a589620c6f15b11c61dee327651a14c34e18231052e48c069", - "xprv9s21ZrQH143K2V4oox4M8Zmhi2Fjx5XK4Lf7GKRvPSgydU3mjZuKGCTg7UPiBUD7ydVPvSLtg9hjp7MQTYsW67rZHAXeccqYqrsx8LcXnyd" - ], - [ - "000000000000000000000000000000000000000000000000", - "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon agent", - "035895f2f481b1b0f01fcf8c289c794660b289981a78f8106447707fdd9666ca06da5a9a565181599b79f53b844d8a71dd9f439c52a3d7b3e8a79c906ac845fa", - "xprv9s21ZrQH143K3mEDrypcZ2usWqFgzKB6jBBx9B6GfC7fu26X6hPRzVjzkqkPvDqp6g5eypdk6cyhGnBngbjeHTe4LsuLG1cCmKJka5SMkmU" - ], - [ - "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f", - "legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal will", - "f2b94508732bcbacbcc020faefecfc89feafa6649a5491b8c952cede496c214a0c7b3c392d168748f2d4a612bada0753b52a1c7ac53c1e93abd5c6320b9e95dd", - "xprv9s21ZrQH143K3Lv9MZLj16np5GzLe7tDKQfVusBni7toqJGcnKRtHSxUwbKUyUWiwpK55g1DUSsw76TF1T93VT4gz4wt5RM23pkaQLnvBh7" - ], - [ - "808080808080808080808080808080808080808080808080", - "letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter always", - "107d7c02a5aa6f38c58083ff74f04c607c2d2c0ecc55501dadd72d025b751bc27fe913ffb796f841c49b1d33b610cf0e91d3aa239027f5e99fe4ce9e5088cd65", - "xprv9s21ZrQH143K3VPCbxbUtpkh9pRG371UCLDz3BjceqP1jz7XZsQ5EnNkYAEkfeZp62cDNj13ZTEVG1TEro9sZ9grfRmcYWLBhCocViKEJae" - ], - [ - "ffffffffffffffffffffffffffffffffffffffffffffffff", - "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo when", - "0cd6e5d827bb62eb8fc1e262254223817fd068a74b5b449cc2f667c3f1f985a76379b43348d952e2265b4cd129090758b3e3c2c49103b5051aac2eaeb890a528", - "xprv9s21ZrQH143K36Ao5jHRVhFGDbLP6FCx8BEEmpru77ef3bmA928BxsqvVM27WnvvyfWywiFN8K6yToqMaGYfzS6Db1EHAXT5TuyCLBXUfdm" - ], - [ - "0000000000000000000000000000000000000000000000000000000000000000", - "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art", - "bda85446c68413707090a52022edd26a1c9462295029f2e60cd7c4f2bbd3097170af7a4d73245cafa9c3cca8d561a7c3de6f5d4a10be8ed2a5e608d68f92fcc8", - "xprv9s21ZrQH143K32qBagUJAMU2LsHg3ka7jqMcV98Y7gVeVyNStwYS3U7yVVoDZ4btbRNf4h6ibWpY22iRmXq35qgLs79f312g2kj5539ebPM" - ], - [ - "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f", - "legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth title", - "bc09fca1804f7e69da93c2f2028eb238c227f2e9dda30cd63699232578480a4021b146ad717fbb7e451ce9eb835f43620bf5c514db0f8add49f5d121449d3e87", - "xprv9s21ZrQH143K3Y1sd2XVu9wtqxJRvybCfAetjUrMMco6r3v9qZTBeXiBZkS8JxWbcGJZyio8TrZtm6pkbzG8SYt1sxwNLh3Wx7to5pgiVFU" - ], - [ - "8080808080808080808080808080808080808080808080808080808080808080", - "letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic bless", - "c0c519bd0e91a2ed54357d9d1ebef6f5af218a153624cf4f2da911a0ed8f7a09e2ef61af0aca007096df430022f7a2b6fb91661a9589097069720d015e4e982f", - "xprv9s21ZrQH143K3CSnQNYC3MqAAqHwxeTLhDbhF43A4ss4ciWNmCY9zQGvAKUSqVUf2vPHBTSE1rB2pg4avopqSiLVzXEU8KziNnVPauTqLRo" - ], - [ - "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo vote", - "dd48c104698c30cfe2b6142103248622fb7bb0ff692eebb00089b32d22484e1613912f0a5b694407be899ffd31ed3992c456cdf60f5d4564b8ba3f05a69890ad", - "xprv9s21ZrQH143K2WFF16X85T2QCpndrGwx6GueB72Zf3AHwHJaknRXNF37ZmDrtHrrLSHvbuRejXcnYxoZKvRquTPyp2JiNG3XcjQyzSEgqCB" - ], - [ - "9e885d952ad362caeb4efe34a8e91bd2", - "ozone drill grab fiber curtain grace pudding thank cruise elder eight picnic", - "274ddc525802f7c828d8ef7ddbcdc5304e87ac3535913611fbbfa986d0c9e5476c91689f9c8a54fd55bd38606aa6a8595ad213d4c9c9f9aca3fb217069a41028", - "xprv9s21ZrQH143K2oZ9stBYpoaZ2ktHj7jLz7iMqpgg1En8kKFTXJHsjxry1JbKH19YrDTicVwKPehFKTbmaxgVEc5TpHdS1aYhB2s9aFJBeJH" - ], - [ - "6610b25967cdcca9d59875f5cb50b0ea75433311869e930b", - "gravity machine north sort system female filter attitude volume fold club stay feature office ecology stable narrow fog", - "628c3827a8823298ee685db84f55caa34b5cc195a778e52d45f59bcf75aba68e4d7590e101dc414bc1bbd5737666fbbef35d1f1903953b66624f910feef245ac", - "xprv9s21ZrQH143K3uT8eQowUjsxrmsA9YUuQQK1RLqFufzybxD6DH6gPY7NjJ5G3EPHjsWDrs9iivSbmvjc9DQJbJGatfa9pv4MZ3wjr8qWPAK" - ], - [ - "68a79eaca2324873eacc50cb9c6eca8cc68ea5d936f98787c60c7ebc74e6ce7c", - "hamster diagram private dutch cause delay private meat slide toddler razor book happy fancy gospel tennis maple dilemma loan word shrug inflict delay length", - "64c87cde7e12ecf6704ab95bb1408bef047c22db4cc7491c4271d170a1b213d20b385bc1588d9c7b38f1b39d415665b8a9030c9ec653d75e65f847d8fc1fc440", - "xprv9s21ZrQH143K2XTAhys3pMNcGn261Fi5Ta2Pw8PwaVPhg3D8DWkzWQwjTJfskj8ofb81i9NP2cUNKxwjueJHHMQAnxtivTA75uUFqPFeWzk" - ], - [ - "c0ba5a8e914111210f2bd131f3d5e08d", - "scheme spot photo card baby mountain device kick cradle pact join borrow", - "ea725895aaae8d4c1cf682c1bfd2d358d52ed9f0f0591131b559e2724bb234fca05aa9c02c57407e04ee9dc3b454aa63fbff483a8b11de949624b9f1831a9612", - "xprv9s21ZrQH143K3FperxDp8vFsFycKCRcJGAFmcV7umQmcnMZaLtZRt13QJDsoS5F6oYT6BB4sS6zmTmyQAEkJKxJ7yByDNtRe5asP2jFGhT6" - ], - [ - "6d9be1ee6ebd27a258115aad99b7317b9c8d28b6d76431c3", - "horn tenant knee talent sponsor spell gate clip pulse soap slush warm silver nephew swap uncle crack brave", - "fd579828af3da1d32544ce4db5c73d53fc8acc4ddb1e3b251a31179cdb71e853c56d2fcb11aed39898ce6c34b10b5382772db8796e52837b54468aeb312cfc3d", - "xprv9s21ZrQH143K3R1SfVZZLtVbXEB9ryVxmVtVMsMwmEyEvgXN6Q84LKkLRmf4ST6QrLeBm3jQsb9gx1uo23TS7vo3vAkZGZz71uuLCcywUkt" - ], - [ - "9f6a2878b2520799a44ef18bc7df394e7061a224d2c33cd015b157d746869863", - "panda eyebrow bullet gorilla call smoke muffin taste mesh discover soft ostrich alcohol speed nation flash devote level hobby quick inner drive ghost inside", - "72be8e052fc4919d2adf28d5306b5474b0069df35b02303de8c1729c9538dbb6fc2d731d5f832193cd9fb6aeecbc469594a70e3dd50811b5067f3b88b28c3e8d", - "xprv9s21ZrQH143K2WNnKmssvZYM96VAr47iHUQUTUyUXH3sAGNjhJANddnhw3i3y3pBbRAVk5M5qUGFr4rHbEWwXgX4qrvrceifCYQJbbFDems" - ], - [ - "23db8160a31d3e0dca3688ed941adbf3", - "cat swing flag economy stadium alone churn speed unique patch report train", - "deb5f45449e615feff5640f2e49f933ff51895de3b4381832b3139941c57b59205a42480c52175b6efcffaa58a2503887c1e8b363a707256bdd2b587b46541f5", - "xprv9s21ZrQH143K4G28omGMogEoYgDQuigBo8AFHAGDaJdqQ99QKMQ5J6fYTMfANTJy6xBmhvsNZ1CJzRZ64PWbnTFUn6CDV2FxoMDLXdk95DQ" - ], - [ - "8197a4a47f0425faeaa69deebc05ca29c0a5b5cc76ceacc0", - "light rule cinnamon wrap drastic word pride squirrel upgrade then income fatal apart sustain crack supply proud access", - "4cbdff1ca2db800fd61cae72a57475fdc6bab03e441fd63f96dabd1f183ef5b782925f00105f318309a7e9c3ea6967c7801e46c8a58082674c860a37b93eda02", - "xprv9s21ZrQH143K3wtsvY8L2aZyxkiWULZH4vyQE5XkHTXkmx8gHo6RUEfH3Jyr6NwkJhvano7Xb2o6UqFKWHVo5scE31SGDCAUsgVhiUuUDyh" - ], - [ - "066dca1a2bb7e8a1db2832148ce9933eea0f3ac9548d793112d9a95c9407efad", - "all hour make first leader extend hole alien behind guard gospel lava path output census museum junior mass reopen famous sing advance salt reform", - "26e975ec644423f4a4c4f4215ef09b4bd7ef924e85d1d17c4cf3f136c2863cf6df0a475045652c57eb5fb41513ca2a2d67722b77e954b4b3fc11f7590449191d", - "xprv9s21ZrQH143K3rEfqSM4QZRVmiMuSWY9wugscmaCjYja3SbUD3KPEB1a7QXJoajyR2T1SiXU7rFVRXMV9XdYVSZe7JoUXdP4SRHTxsT1nzm" - ], - [ - "f30f8c1da665478f49b001d94c5fc452", - "vessel ladder alter error federal sibling chat ability sun glass valve picture", - "2aaa9242daafcee6aa9d7269f17d4efe271e1b9a529178d7dc139cd18747090bf9d60295d0ce74309a78852a9caadf0af48aae1c6253839624076224374bc63f", - "xprv9s21ZrQH143K2QWV9Wn8Vvs6jbqfF1YbTCdURQW9dLFKDovpKaKrqS3SEWsXCu6ZNky9PSAENg6c9AQYHcg4PjopRGGKmdD313ZHszymnps" - ], - [ - "c10ec20dc3cd9f652c7fac2f1230f7a3c828389a14392f05", - "scissors invite lock maple supreme raw rapid void congress muscle digital elegant little brisk hair mango congress clump", - "7b4a10be9d98e6cba265566db7f136718e1398c71cb581e1b2f464cac1ceedf4f3e274dc270003c670ad8d02c4558b2f8e39edea2775c9e232c7cb798b069e88", - "xprv9s21ZrQH143K4aERa2bq7559eMCCEs2QmmqVjUuzfy5eAeDX4mqZffkYwpzGQRE2YEEeLVRoH4CSHxianrFaVnMN2RYaPUZJhJx8S5j6puX" - ], - [ - "f585c11aec520db57dd353c69554b21a89b20fb0650966fa0a9d6f74fd989d8f", - "void come effort suffer camp survey warrior heavy shoot primary clutch crush open amazing screen patrol group space point ten exist slush involve unfold", - "01f5bced59dec48e362f2c45b5de68b9fd6c92c6634f44d6d40aab69056506f0e35524a518034ddc1192e1dacd32c1ed3eaa3c3b131c88ed8e7e54c49a5d0998", - "xprv9s21ZrQH143K39rnQJknpH1WEPFJrzmAqqasiDcVrNuk926oizzJDDQkdiTvNPr2FYDYzWgiMiC63YmfPAa2oPyNB23r2g7d1yiK6WpqaQS" - ] - ] -} diff --git a/test/data/mnemonic2.json b/test/data/mnemonic2.json deleted file mode 100644 index bd0ec471..00000000 --- a/test/data/mnemonic2.json +++ /dev/null @@ -1,193 +0,0 @@ -[ - { - "entropy": "00000000000000000000000000000000", - "mnemonic": "あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あおぞら", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "a262d6fb6122ecf45be09c50492b31f92e9beb7d9a845987a02cefda57a15f9c467a17872029a9e92299b5cbdf306e3a0ee620245cbd508959b6cb7ca637bd55", - "bip32_xprv": "xprv9s21ZrQH143K258jAiWPAM6JYT9hLA91MV3AZUKfxmLZJCjCHeSjBvMbDy8C1mJ2FL5ytExyS97FAe6pQ6SD5Jt9SwHaLorA8i5Eojokfo1" - }, - - { - "entropy": "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f", - "mnemonic": "そつう れきだい ほんやく わかす りくつ ばいか ろせん やちん そつう れきだい ほんやく わかめ", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "aee025cbe6ca256862f889e48110a6a382365142f7d16f2b9545285b3af64e542143a577e9c144e101a6bdca18f8d97ec3366ebf5b088b1c1af9bc31346e60d9", - "bip32_xprv": "xprv9s21ZrQH143K3ra1D6uGQyST9UqtUscH99GK8MBh5RrgPkrQo83QG4o6H2YktwSKvoZRVXDQZQrSyCDpHdA2j8i3PW5M9LkauaaTKwym1Wf" - }, - - { - "entropy": "80808080808080808080808080808080", - "mnemonic": "そとづら あまど おおう あこがれる いくぶん けいけん あたえる いよく そとづら あまど おおう あかちゃん", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "e51736736ebdf77eda23fa17e31475fa1d9509c78f1deb6b4aacfbd760a7e2ad769c714352c95143b5c1241985bcb407df36d64e75dd5a2b78ca5d2ba82a3544", - "bip32_xprv": "xprv9s21ZrQH143K2aDKfG8hpfvRXzANmyBQWoqoUXWaSwVZcKtnmX5xTVkkHAdD9yykuuBcagjCFK6iLcBdHHxXC1g3TT9xHSu4PW6SRf3KvVy" - }, - - { - "entropy": "ffffffffffffffffffffffffffffffff", - "mnemonic": "われる われる われる われる われる われる われる われる われる われる われる ろんぶん", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "4cd2ef49b479af5e1efbbd1e0bdc117f6a29b1010211df4f78e2ed40082865793e57949236c43b9fe591ec70e5bb4298b8b71dc4b267bb96ed4ed282c8f7761c", - "bip32_xprv": "xprv9s21ZrQH143K4WxYzpW3izjoq6e51NSZgN6AHxoKxZStsxBvtxuQDxPyvb8o4pSbxYPCyJGKewMxrHWvTBY6WEFX4svSzB2ezmatzzJW9wi" - }, - - { - "entropy": "000000000000000000000000000000000000000000000000", - "mnemonic": "あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あらいぐま", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "d99e8f1ce2d4288d30b9c815ae981edd923c01aa4ffdc5dee1ab5fe0d4a3e13966023324d119105aff266dac32e5cd11431eeca23bbd7202ff423f30d6776d69", - "bip32_xprv": "xprv9s21ZrQH143K2pqcK1QdBVm9r4gL4yQX6KFTqHWctvfZa9Wjhxow63ZGpSB27mVo1BBH4D1NoTo3gVAHAeqmhm5Z9SuC8xJmFYBFz978rza" - }, - - { - "entropy": "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f", - "mnemonic": "そつう れきだい ほんやく わかす りくつ ばいか ろせん やちん そつう れきだい ほんやく わかす りくつ ばいか ろせん やちん そつう れいぎ", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "eaaf171efa5de4838c758a93d6c86d2677d4ccda4a064a7136344e975f91fe61340ec8a615464b461d67baaf12b62ab5e742f944c7bd4ab6c341fbafba435716", - "bip32_xprv": "xprv9s21ZrQH143K34NWKwHe5cBVDYuoKZ6iiqWczDMwGA9Ut57iCCTksDTnxE5AH3qHHvfcgwpRhyj4G7Y6FEewjVoQqq4gHN6CetyFdd3q4CR" - }, - - { - "entropy": "808080808080808080808080808080808080808080808080", - "mnemonic": "そとづら あまど おおう あこがれる いくぶん けいけん あたえる いよく そとづら あまど おおう あこがれる いくぶん けいけん あたえる いよく そとづら いきなり", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "aec0f8d3167a10683374c222e6e632f2940c0826587ea0a73ac5d0493b6a632590179a6538287641a9fc9df8e6f24e01bf1be548e1f74fd7407ccd72ecebe425", - "bip32_xprv": "xprv9s21ZrQH143K4RABcYmYKbZybgJrvpcnricsuNaZvsGVo7pupfELFY6TJw5G5XVswQodBzaRtfPkTi6aVCmC349A3yYzAZLfT7emP8m1RFX" - }, - - { - "entropy": "ffffffffffffffffffffffffffffffffffffffffffffffff", - "mnemonic": "われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる りんご", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "f0f738128a65b8d1854d68de50ed97ac1831fc3a978c569e415bbcb431a6a671d4377e3b56abd518daa861676c4da75a19ccb41e00c37d086941e471a4374b95", - "bip32_xprv": "xprv9s21ZrQH143K2ThaKxBDxUByy4gNwULJyqKQzZXyF3aLyGdknnP18KvKVZwCvBJGXaAsKd7oh2ypLbjyDn4bDY1iiSPvNkKsVAGQGj7G3PZ" - }, - - { - "entropy": "0000000000000000000000000000000000000000000000000000000000000000", - "mnemonic": "あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん あいこくしん いってい", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "23f500eec4a563bf90cfda87b3e590b211b959985c555d17e88f46f7183590cd5793458b094a4dccc8f05807ec7bd2d19ce269e20568936a751f6f1ec7c14ddd", - "bip32_xprv": "xprv9s21ZrQH143K3skSyXVw9CTTUHgKnsysvKiJw9MQjvTSY6ysTk4sFz58htMAcqHrjLdnUhqxRtmRy5AMJyWGeuQrDGSSfmcNh7cbfnrbDty" - }, - - { - "entropy": "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f", - "mnemonic": "そつう れきだい ほんやく わかす りくつ ばいか ろせん やちん そつう れきだい ほんやく わかす りくつ ばいか ろせん やちん そつう れきだい ほんやく わかす りくつ ばいか ろせん まんきつ", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "cd354a40aa2e241e8f306b3b752781b70dfd1c69190e510bc1297a9c5738e833bcdc179e81707d57263fb7564466f73d30bf979725ff783fb3eb4baa86560b05", - "bip32_xprv": "xprv9s21ZrQH143K2y9p1D6KuxqypMjbiBKkiALERahpxvb46x9giqkvmv5KxGvGJZG2mdcMunmHaazYyEqYmkx9SnfndimSmgJv5EL24X1DGqV" - }, - - { - "entropy": "8080808080808080808080808080808080808080808080808080808080808080", - "mnemonic": "そとづら あまど おおう あこがれる いくぶん けいけん あたえる いよく そとづら あまど おおう あこがれる いくぶん けいけん あたえる いよく そとづら あまど おおう あこがれる いくぶん けいけん あたえる うめる", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "6b7cd1b2cdfeeef8615077cadd6a0625f417f287652991c80206dbd82db17bf317d5c50a80bd9edd836b39daa1b6973359944c46d3fcc0129198dc7dc5cd0e68", - "bip32_xprv": "xprv9s21ZrQH143K2TuQM4HcbBBtvC19SaDgqn6cL16KTaPEazB26iCDfxABvBi9driWcbnF4rcLVpkx5iGG7zH2QcN7qNxL4cpb7mQ2G3ByAv7" - }, - - { - "entropy": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", - "mnemonic": "われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる われる らいう", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "a44ba7054ac2f9226929d56505a51e13acdaa8a9097923ca07ea465c4c7e294c038f3f4e7e4b373726ba0057191aced6e48ac8d183f3a11569c426f0de414623", - "bip32_xprv": "xprv9s21ZrQH143K3XTGpC53cWswvhg6GVQ1dE1yty6F9VhBcE7rnXmStuKwtaZNXRxw5N7tsh1REyAxun1S5BCYvhD5pNwxWUMMZaHwjTmXFdb" - }, - - { - "entropy": "77c2b00716cec7213839159e404db50d", - "mnemonic": "せまい うちがわ あずき かろう めずらしい だんち ますく おさめる ていぼう あたる すあな えしゃく", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "344cef9efc37d0cb36d89def03d09144dd51167923487eec42c487f7428908546fa31a3c26b7391a2b3afe7db81b9f8c5007336b58e269ea0bd10749a87e0193", - "bip32_xprv": "xprv9s21ZrQH143K2fhvZfecKw8znj6QkGGV2F2t17BWA6VnanejVWBjQeV5DspseWdSvN49rrFpocPGt7aSGk9R5wJfC1LAwFMt6hV9qS7yGKR" - }, - - { - "entropy": "b63a9c59a6e641f288ebc103017f1da9f8290b3da6bdef7b", - "mnemonic": "ぬすむ ふっかつ うどん こうりつ しつじ りょうり おたがい せもたれ あつめる いちりゅう はんしゃ ごますり そんけい たいちょう らしんばん ぶんせき やすみ ほいく", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "b14e7d35904cb8569af0d6a016cee7066335a21c1c67891b01b83033cadb3e8a034a726e3909139ecd8b2eb9e9b05245684558f329b38480e262c1d6bc20ecc4", - "bip32_xprv": "xprv9s21ZrQH143K25BDHG8fiLEPvKD9QCWqqs8V4yz2NeZXHbDgnAYW1EL5k8KWcn1kGKmsHrqbNvePJaYWEgkEMjJEepwTFfVzzyYRN7cyJgM" - }, - - { - "entropy": "3e141609b97933b66a060dcddc71fad1d91677db872031e85f4c015c5e7e8982", - "mnemonic": "くのう てぬぐい そんかい すろっと ちきゅう ほあん とさか はくしゅ ひびく みえる そざい てんすう たんぴん くしょう すいようび みけん きさらぎ げざん ふくざつ あつかう はやい くろう おやゆび こすう", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "32e78dce2aff5db25aa7a4a32b493b5d10b4089923f3320c8b287a77e512455443298351beb3f7eb2390c4662a2e566eec5217e1a37467af43b46668d515e41b", - "bip32_xprv": "xprv9s21ZrQH143K2gbMb94GNwdogai6fA3vTrALH8eoNJKqPWn9KyeBMhUQLpsN5ePJkZdHsPmyDsECNLRaYiposqDDqsbk3ANk9hbsSgmVq7G" - }, - - { - "entropy": "0460ef47585604c5660618db2e6a7e7f", - "mnemonic": "あみもの いきおい ふいうち にげる ざんしょ じかん ついか はたん ほあん すんぽう てちがい わかめ", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "0acf902cd391e30f3f5cb0605d72a4c849342f62bd6a360298c7013d714d7e58ddf9c7fdf141d0949f17a2c9c37ced1d8cb2edabab97c4199b142c829850154b", - "bip32_xprv": "xprv9s21ZrQH143K2Ec1okKMST9mN52SKEybSCeacWpAvPHMS5zFfMDfgwpJVXa96sd2sybGuJWE34CtSVYn42FBWLmFgmGeEmRvDriPnZVjWnU" - }, - - { - "entropy": "72f60ebac5dd8add8d2a25a797102c3ce21bc029c200076f", - "mnemonic": "すろっと にくしみ なやむ たとえる へいこう すくう きない けってい とくべつ ねっしん いたみ せんせい おくりがな まかい とくい けあな いきおい そそぐ", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "9869e220bec09b6f0c0011f46e1f9032b269f096344028f5006a6e69ea5b0b8afabbb6944a23e11ebd021f182dd056d96e4e3657df241ca40babda532d364f73", - "bip32_xprv": "xprv9s21ZrQH143K2KKucNRqjGFooHw87xXFQpZGNZ1W7Vwtkr2YMkXFuxnMvqc8cegm8jkrVswEWuNEsGtFkaEedAG2cRTTtsz1bM6o8fCu3Pg" - }, - - { - "entropy": "2c85efc7f24ee4573d2b81a6ec66cee209b2dcbd09d8eddc51e0215b0b68e416", - "mnemonic": "かほご きうい ゆたか みすえる もらう がっこう よそう ずっと ときどき したうけ にんか はっこう つみき すうじつ よけい くげん もくてき まわり せめる げざい にげる にんたい たんそく ほそく", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "713b7e70c9fbc18c831bfd1f03302422822c3727a93a5efb9659bec6ad8d6f2c1b5c8ed8b0b77775feaf606e9d1cc0a84ac416a85514ad59f5541ff5e0382481", - "bip32_xprv": "xprv9s21ZrQH143K2MXrVTP5hyWW9js9D8qipo9vVRTKYPCB8Mtw4XE57uepG7wuHRk3ZJLGAq1tdJ4So8hYHu4gBaJ4NANPjb1CJCpDd3e9H87" - }, - - { - "entropy": "eaebabb2383351fd31d703840b32e9e2", - "mnemonic": "めいえん さのう めだつ すてる きぬごし ろんぱ はんこ まける たいおう さかいし ねんいり はぶらし", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "06e1d5289a97bcc95cb4a6360719131a786aba057d8efd603a547bd254261c2a97fcd3e8a4e766d5416437e956b388336d36c7ad2dba4ee6796f0249b10ee961", - "bip32_xprv": "xprv9s21ZrQH143K3ZVFWWSR9XVXY8EMqCNdj7YUx4DKdcCFitEsSH18aPcufobUfP3w9xz1XTUThwC4cYuf8VWvSwYWs8aTTAi7mr9jDsGHYLU" - }, - - { - "entropy": "7ac45cfe7722ee6c7ba84fbc2d5bd61b45cb2fe5eb65aa78", - "mnemonic": "せんぱい おしえる ぐんかん もらう きあい きぼう やおや いせえび のいず じゅしん よゆう きみつ さといも ちんもく ちわわ しんせいじ とめる はちみつ", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "1fef28785d08cbf41d7a20a3a6891043395779ed74503a5652760ee8c24dfe60972105ee71d5168071a35ab7b5bd2f8831f75488078a90f0926c8e9171b2bc4a", - "bip32_xprv": "xprv9s21ZrQH143K3CXbNxjnq5iemN7AzZrtE71rvBAuZ4BnebovyS2hK3yjbAzsX6mrdxK8fa4kXPjnCC9FHpwgaPwZuCbrUJ4sj6xdPPYNeKK" - }, - - { - "entropy": "4fa1a8bc3e6d80ee1316050e862c1812031493212b7ec3f3bb1b08f168cabeef", - "mnemonic": "こころ いどう きあつ そうがんきょう へいあん せつりつ ごうせい はいち いびき きこく あんい おちつく きこえる けんとう たいこ すすめる はっけん ていど はんおん いんさつ うなぎ しねま れいぼう みつかる", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "43de99b502e152d4c198542624511db3007c8f8f126a30818e856b2d8a20400d29e7a7e3fdd21f909e23be5e3c8d9aee3a739b0b65041ff0b8637276703f65c2", - "bip32_xprv": "xprv9s21ZrQH143K2WyZ5cAUSqkC89FeL4mrEG9N9VEhh9pR2g6SQjWbXNufkfBwwaZtMfpDzip9fZjm3huvMEJASWviaGqG1A6bDmoSQzd3YFy" - }, - - { - "entropy": "18ab19a9f54a9274f03e5209a2ac8a91", - "mnemonic": "うりきれ さいせい じゆう むろん とどける ぐうたら はいれつ ひけつ いずれ うちあわせ おさめる おたく", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "3d711f075ee44d8b535bb4561ad76d7d5350ea0b1f5d2eac054e869ff7963cdce9581097a477d697a2a9433a0c6884bea10a2193647677977c9820dd0921cbde", - "bip32_xprv": "xprv9s21ZrQH143K49xMPBpnqsaXt6EECMPzVAvr18EiiJMHfgEedw28JiSCpB5DLGQB19NU2iiG4g7vVnLC6jn75B4n3LHCPwhpU6o7Srd6jYt" - }, - - { - "entropy": "18a2e1d81b8ecfb2a333adcb0c17a5b9eb76cc5d05db91a4", - "mnemonic": "うりきれ うねる せっさたくま きもち めんきょ へいたく たまご ぜっく びじゅつかん さんそ むせる せいじ ねくたい しはらい せおう ねんど たんまつ がいけん", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "753ec9e333e616e9471482b4b70a18d413241f1e335c65cd7996f32b66cf95546612c51dcf12ead6f805f9ee3d965846b894ae99b24204954be80810d292fcdd", - "bip32_xprv": "xprv9s21ZrQH143K2WyY1Me9W7T8Wg7yQa9WFVAEn1vhoDkkP43dBVhsagabzEKMaz7UNtczbKkNowDLXSyVipJXVEBcpYJGBJ6ZaVDXNGoLStz" - }, - - { - "entropy": "15da872c95a13dd738fbf50e427583ad61f18fd99f628c417a61cf8343c90419", - "mnemonic": "うちゅう ふそく ひしょ がちょう うけもつ めいそう みかん そざい いばる うけとる さんま さこつ おうさま ぱんつ しひょう めした たはつ いちぶ つうじょう てさぎょう きつね みすえる いりぐち かめれおん", - "passphrase": "メートルガバヴァぱばぐゞちぢ十人十色", - "seed": "346b7321d8c04f6f37b49fdf062a2fddc8e1bf8f1d33171b65074531ec546d1d3469974beccb1a09263440fc92e1042580a557fdce314e27ee4eabb25fa5e5fe", - "bip32_xprv": "xprv9s21ZrQH143K2qVq43Phs1xyVc6jSxXHWJ6CDJjod3cgyEin7hgeQV6Dkw6s1LSfMYxoah4bPAnW4wmXfDUS9ghBEM18xoY634CBtX8HPrA" - } -] diff --git a/test/data/script_tests.json b/test/data/script-tests.json similarity index 100% rename from test/data/script_tests.json rename to test/data/script-tests.json diff --git a/test/data/sighash.json b/test/data/sighash-tests.json similarity index 100% rename from test/data/sighash.json rename to test/data/sighash-tests.json diff --git a/test/data/tx_invalid.json b/test/data/tx-invalid.json similarity index 100% rename from test/data/tx_invalid.json rename to test/data/tx-invalid.json diff --git a/test/data/tx_valid.json b/test/data/tx-valid.json similarity index 100% rename from test/data/tx_valid.json rename to test/data/tx-valid.json diff --git a/test/data/wtx.hex b/test/data/tx5.hex similarity index 100% rename from test/data/wtx.hex rename to test/data/tx5.hex diff --git a/test/data/coolest-tx-ever-sent.hex b/test/data/tx6.hex similarity index 100% rename from test/data/coolest-tx-ever-sent.hex rename to test/data/tx6.hex diff --git a/test/data/tx7.hex b/test/data/tx7.hex new file mode 100644 index 00000000..d318e8f7 --- /dev/null +++ b/test/data/tx7.hex @@ -0,0 +1,2 @@ +010000000125393c67cd4f581456dd0805fa8e9db3abdf90dbe1d4b53e286490f35d22b6f2010000006b483045022100f4fa5ced20d2dbd2f905809d79ebe34e03496ef2a48a04d0a9a1db436a211dd202203243d086398feb4ac21b3b79884079036cd5f3707ba153b383eabefa656512dd0121022ebabefede28804b331608d8ef11e1d65b5a920720db8a644f046d156b3a73c0ffffffff0254150000000000001976a9140740345f114e1a1f37ac1cc442b432b91628237e88ace7d27b00000000001976a91495ad422bb5911c2c9fe6ce4f82a13c85f03d9b2e88ac00000000 +01000000052fa236559f51f343f0905ea627a955f421a198541d928798b8186980273942ec010000006b483045022100ae27626778eba264d56883f5edc1a49897bf209e98f21c870a55d13bec916e1802204b66f4e3235143d11aef327d9454754cd1f28807c3bf9996c107900df9d19ea60121022ebabefede28804b331608d8ef11e1d65b5a920720db8a644f046d156b3a73c0ffffffffe2136f72e4a25e300137b98b402cda91db5c6db6373ba81c722ae1a85315b591000000006b483045022100f84293ea9bfb6d150f3a72d8b5ceb294a77b31442bf9d4ab2058f046a9b65a9f022075935dc0a6a628df26ebb7215634fd33b65f4da105665595028837680b87ea360121039708df196709c5041dc9a26457a0cfa303076329f389687bdc9709d5862fd664fffffffff6e67655a42a2f955ec8610940c983042516c32298e57684b3c29fcade7e637a000000006a47304402203bbfb53c3011d742f3f942db18a44d8c3dd111990ee7cc42959383dd7a3e8e8d02207f0f5ed3e165d9db81ac69d36c60a1a4a482f22cb0048dafefa5e704e84dd18e0121039708df196709c5041dc9a26457a0cfa303076329f389687bdc9709d5862fd664ffffffff9a02e72123a149570c11696d3c798593785e95b8a3c3fc49ae1d07d809d94d5a000000006b483045022100ad0e6f5f73221aa4eda9ad82c7074882298bcf668f34ae81126df0213b2961850220020ba23622d75fb8f95199063b804f62ba103545af4e16b5be0b6dc0cb51aac60121039708df196709c5041dc9a26457a0cfa303076329f389687bdc9709d5862fd664ffffffffd7db5a3872589ca8aa3cd5ebb0f22dbb3956f8d691e15dc010fe1093c045c3de000000006b48304502210082b91a67da1f02dcb0d00e63b67f10af8ba9639b165f9ff974862a9d4900e27c022069e4a58f591eb3fc7d7d0b176d64d59e90aef0c601b3c84382abad92f6973e630121039708df196709c5041dc9a26457a0cfa303076329f389687bdc9709d5862fd664ffffffff0254150000000000001976a9140740345f114e1a1f37ac1cc442b432b91628237e88ac4b0f7c00000000001976a91495ad422bb5911c2c9fe6ce4f82a13c85f03d9b2e88ac00000000 diff --git a/test/data/tx8.hex b/test/data/tx8.hex new file mode 100644 index 00000000..4025a019 --- /dev/null +++ b/test/data/tx8.hex @@ -0,0 +1 @@ +0100000004b124cca7e9686375380c845d0fd002ed704aef4472f4cc193fca4aa1b3404da400000000b400493046022100d3c9ba786488323c975fe61593df6a8041c5442736f361887abfe5c97175c72b022100ca61688f472f4c01ede05ffc50426d68db375f72937b5f39d67835b191b6402f014c67514104c4bee5e6dbb5c1651437cb4386c1515c7776c64535077204c6f24f05a37d04a32bc78beb2193b53b104c9954c44b0ce168bc78efd5f1e1c7db9d6c21b301659921027f10c31cb2ad7e0388cf5187924f1294082ba5d4c697bbca7fd83a6af61db7d552aeffffffffb124cca7e9686375380c845d0fd002ed704aef4472f4cc193fca4aa1b3404da401000000fd150100483045022100a35b7fc1973a0a8962c240a7336b501e149ef167491081e8df91dc761f4e96c2022004ee4d20983a1d0fb96e9bedf86de03b66d7bc50595295b1fb3b5fd2740df3c9014cc9514104c4bee5e6dbb5c1651437cb4386c1515c7776c64535077204c6f24f05a37d04a32bc78beb2193b53b104c9954c44b0ce168bc78efd5f1e1c7db9d6c21b3016599410495b62d1e76a915e5ed3694298c5017d2818d22acbf2a8bd9fa4cf635184e15247dc7e1a48beb82c1fdddc3b84ac58cec12c8f8b9ca83341ac90299c697fc94cb4104e3394f3eea40b7abe32f4ad376a80f5a213287d1361b5580e3fe70d13a5db0666e2593283b6b5abc01d98cfff5679d8c36b7caefa1c4df81b10bc45c3812de5f53aeffffffffb124cca7e9686375380c845d0fd002ed704aef4472f4cc193fca4aa1b3404da402000000fd5e01004730440220606d6187e0ade69192f4a447794cdabb8ea9a4e70df09aa8bc689242c7ffeded02204165ec8edfc9de19d8a94e5f487c8a030187ae16a11e575a955f532a81b631ad01493046022100f7764763d17757ffdeda3d66cfaa6ad3b8f759ddc95e8f73858dba872762658a0221009e903d526595ff9d6d53835889d816de4c47d78371d7a13223f47602b34bc71e014cc9524104c4bee5e6dbb5c1651437cb4386c1515c7776c64535077204c6f24f05a37d04a32bc78beb2193b53b104c9954c44b0ce168bc78efd5f1e1c7db9d6c21b3016599410495b62d1e76a915e5ed3694298c5017d2818d22acbf2a8bd9fa4cf635184e15247dc7e1a48beb82c1fdddc3b84ac58cec12c8f8b9ca83341ac90299c697fc94cb4104e3394f3eea40b7abe32f4ad376a80f5a213287d1361b5580e3fe70d13a5db0666e2593283b6b5abc01d98cfff5679d8c36b7caefa1c4df81b10bc45c3812de5f53aeffffffffb124cca7e9686375380c845d0fd002ed704aef4472f4cc193fca4aa1b3404da4040000008a473044022075c0666d413fc85cca94ea2f24adc0fedb61a3ba0fcfb240c1a4fd2587b03bf90220525ad4d92c6bf635f8b97c188ebf491c6e342b767a5432f318cbb0245a7f64be014104c4bee5e6dbb5c1651437cb4386c1515c7776c64535077204c6f24f05a37d04a32bc78beb2193b53b104c9954c44b0ce168bc78efd5f1e1c7db9d6c21b3016599ffffffff01a029de5c0500000017a9141d9ca71efa36d814424ea6ca1437e67287aebe348700000000 diff --git a/test/data/tx9.hex b/test/data/tx9.hex new file mode 100644 index 00000000..1497c187 --- /dev/null +++ b/test/data/tx9.hex @@ -0,0 +1 @@ +01000000019457e669dc6b344c0090d10eb22a0377022898d4607fbdf1e3cef2a323c13fa900000000b2004730440220440d67386a27d6776e102b82ce2d583e23d51f8ac3bb94749bd10c03ce71410e022041b46c5d46b14ef72af9d96fb814fa894077d534a4de1215363ee68fb8d4f501014c67514104c4bee5e6dbb5c1651437cb4386c1515c7776c64535077204c6f24f05a37d04a32bc78beb2193b53b104c9954c44b0ce168bc78efd5f1e1c7db9d6c21b301659921027f10c31cb2ad7e0388cf5187924f1294082ba5d4c697bbca7fd83a6af61db7d552aeffffffff0250c30000000000001976a9146167aeaeec59836b22447b8af2c5e61fb4f1b7b088ac00a3dc5c0500000017a9149eb21980dc9d413d8eac27314938b9da920ee53e8700000000 diff --git a/test/gcs-test.js b/test/gcs-test.js index 1ffa78d7..cafe5e68 100644 --- a/test/gcs-test.js +++ b/test/gcs-test.js @@ -17,7 +17,6 @@ const block = Block.fromRaw(raw); describe('GCS', function() { const key = random.randomBytes(16); const P = 20; - let filter1, filter2, filter3, filter4, filter5; const contents1 = [ Buffer.from('Alex', 'ascii'), @@ -78,6 +77,8 @@ describe('GCS', function() { const addr1 = new Address('bc1qmyrddmxglk49ye2wd29wefaavw7es8k5d555lx'); const addr2 = new Address('bc1q4645ycu0l9pnvxaxnhemushv0w4cd9flkqh95j'); + let filter1, filter2, filter3, filter4, filter5; + it('should test GCS filter build', () => { filter1 = GCSFilter.fromItems(P, key, contents1); assert(filter1); diff --git a/test/hd-test.js b/test/hd-test.js index 21596e41..05d4b622 100644 --- a/test/hd-test.js +++ b/test/hd-test.js @@ -21,7 +21,7 @@ function equal(a, b) { } describe('HD', function() { - let master, child1, child2, child3, child4, child5, child6; + let master, child; it('should create a pbkdf2 seed', () => { const seed = pbkdf2.derive( @@ -30,42 +30,45 @@ describe('HD', function() { }); it('should create master private key', () => { - master = HD.PrivateKey.fromSeed(Buffer.from(vectors.seed, 'hex')); - assert.equal(master.toBase58(), vectors.master_priv); - assert.equal(master.toPublic().toBase58(), vectors.master_pub); + const seed = Buffer.from(vectors.seed, 'hex'); + const key = HD.PrivateKey.fromSeed(seed); + assert.equal(key.toBase58(), vectors.master_priv); + assert.equal(key.toPublic().toBase58(), vectors.master_pub); + master = key; }); it('should derive(0) child from master', () => { - child1 = master.derive(0); + const child1 = master.derive(0); assert.equal(child1.toBase58(), vectors.child1_priv); assert.equal(child1.toPublic().toBase58(), vectors.child1_pub); }); it('should derive(1) child from master public key', () => { - child2 = master.toPublic().derive(1); + const child2 = master.toPublic().derive(1); assert.equal(child2.toBase58(), vectors.child2_pub); }); it('should derive(1) child from master', () => { - child3 = master.derive(1); + const child3 = master.derive(1); assert.equal(child3.toBase58(), vectors.child3_priv); assert.equal(child3.toPublic().toBase58(), vectors.child3_pub); }); it('should derive(2) child from master', () => { - child4 = master.derive(2); + const child4 = master.derive(2); assert.equal(child4.toBase58(), vectors.child4_priv); assert.equal(child4.toPublic().toBase58(), vectors.child4_pub); + child = child4; }); it('should derive(0) child from child(2)', () => { - child5 = child4.derive(0); + const child5 = child.derive(0); assert.equal(child5.toBase58(), vectors.child5_priv); assert.equal(child5.toPublic().toBase58(), vectors.child5_pub); }); it('should derive(1) child from child(2)', () => { - child6 = child4.derive(1); + const child6 = child.derive(1); assert.equal(child6.toBase58(), vectors.child6_priv); assert.equal(child6.toPublic().toBase58(), vectors.child6_pub); }); @@ -94,7 +97,7 @@ describe('HD', function() { assert.equal(HD.fromJSON(key.toJSON()).toBase58(), key.toBase58()); }); - [vector1, vector2].forEach((vector) => { + for (const vector of [vector1, vector2]) { let master; it('should create from a seed', () => { @@ -103,7 +106,7 @@ describe('HD', function() { equal(master.toPublic().toBase58(), vector.m.pub); }); - Object.keys(vector).forEach((path) => { + for (const path of Object.keys(vector)) { const kp = vector[path]; if (path === 'seed' || path === 'm') @@ -114,6 +117,6 @@ describe('HD', function() { equal(key.toBase58(), kp.prv); equal(key.toPublic().toBase58(), kp.pub); }); - }); - }); + } + } }); diff --git a/test/hkdf-test.js b/test/hkdf-test.js new file mode 100644 index 00000000..f2a04766 --- /dev/null +++ b/test/hkdf-test.js @@ -0,0 +1,75 @@ +/* eslint-env mocha */ +/* eslint prefer-arrow-callback: "off" */ + +'use strict'; + +const assert = require('assert'); +const hkdf = require('../lib/crypto/hkdf'); + +describe('HKDF', function() { + it('should do proper hkdf', () => { + // https://tools.ietf.org/html/rfc5869 + let alg = 'sha256'; + let ikm = '0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b'; + let salt = '000102030405060708090a0b0c'; + let info = 'f0f1f2f3f4f5f6f7f8f9'; + let len = 42; + + let prkE = '077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec8' + + '44ad7c2b3e5'; + let okmE = '3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1' + + 'a5a4c5db02d56ecc4c5bf34007208d5b887185865'; + + ikm = Buffer.from(ikm, 'hex'); + salt = Buffer.from(salt, 'hex'); + info = Buffer.from(info, 'hex'); + + let prk = hkdf.extract(ikm, salt, alg); + let okm = hkdf.expand(prk, info, len, alg); + + assert.equal(prk.toString('hex'), prkE); + assert.equal(okm.toString('hex'), okmE); + + alg = 'sha256'; + + ikm = '000102030405060708090a0b0c0d0e0f' + + '101112131415161718191a1b1c1d1e1f' + + '202122232425262728292a2b2c2d2e2f' + + '303132333435363738393a3b3c3d3e3f' + + '404142434445464748494a4b4c4d4e4f'; + + salt = '606162636465666768696a6b6c6d6e6f' + + '707172737475767778797a7b7c7d7e7f' + + '808182838485868788898a8b8c8d8e8f' + + '909192939495969798999a9b9c9d9e9f' + + 'a0a1a2a3a4a5a6a7a8a9aaabacadaeaf'; + + info = 'b0b1b2b3b4b5b6b7b8b9babbbcbdbebf' + + 'c0c1c2c3c4c5c6c7c8c9cacbcccdcecf' + + 'd0d1d2d3d4d5d6d7d8d9dadbdcdddedf' + + 'e0e1e2e3e4e5e6e7e8e9eaebecedeeef' + + 'f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff'; + + len = 82; + + prkE = '06a6b88c5853361a06104c9ceb35b45c' + + 'ef760014904671014a193f40c15fc244'; + + okmE = 'b11e398dc80327a1c8e7f78c596a4934' + + '4f012eda2d4efad8a050cc4c19afa97c' + + '59045a99cac7827271cb41c65e590e09' + + 'da3275600c2f09b8367793a9aca3db71' + + 'cc30c58179ec3e87c14c01d5c1f3434f' + + '1d87'; + + ikm = Buffer.from(ikm, 'hex'); + salt = Buffer.from(salt, 'hex'); + info = Buffer.from(info, 'hex'); + + prk = hkdf.extract(ikm, salt, alg); + okm = hkdf.expand(prk, info, len, alg); + + assert.equal(prk.toString('hex'), prkE); + assert.equal(okm.toString('hex'), okmE); + }); +}); diff --git a/test/http-test.js b/test/http-test.js index b6b1d025..22fa4499 100644 --- a/test/http-test.js +++ b/test/http-test.js @@ -16,8 +16,6 @@ const FullNode = require('../lib/node/fullnode'); const pkg = require('../lib/pkg'); describe('HTTP', function() { - let addr, hash; - const node = new FullNode({ network: 'regtest', apiKey: 'foo', @@ -33,6 +31,8 @@ describe('HTTP', function() { const wdb = node.require('walletdb'); + let addr, hash; + this.timeout(15000); it('should open node', async () => { diff --git a/test/key-address-test.js b/test/key-address-test.js index c238bc41..4b56fdef 100644 --- a/test/key-address-test.js +++ b/test/key-address-test.js @@ -9,6 +9,7 @@ const keyring = require('../lib/primitives/keyring'); describe('Keyring Address', function() { const ukey = keyring.fromSecret( '5KYZdUEo39z3FPrtuX2QbbwGnNP5zTd7yyr2SC1j299sBCnWjss'); + const ckey = keyring.fromSecret( 'L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrisoyY1'); diff --git a/test/mnemonic-test.js b/test/mnemonic-test.js index 276c0bc7..aae034f4 100644 --- a/test/mnemonic-test.js +++ b/test/mnemonic-test.js @@ -4,56 +4,44 @@ 'use strict'; const assert = require('assert'); -const HD = require('../lib/hd'); +const Mnemonic = require('../lib/hd/mnemonic'); +const HDPrivateKey = require('../lib/hd/private'); -const mnemonic1 = require('./data/mnemonic1').english; -const mnemonic2 = require('./data/mnemonic2'); +const tests = { + english: require('./data/mnemonic-english.json'), + japanese: require('./data/mnemonic-japanese.json') +}; describe('Mnemonic', function() { - mnemonic1.forEach((data, i) => { - const entropy = Buffer.from(data[0], 'hex'); - const phrase = data[1]; - const seed = Buffer.from(data[2], 'hex'); - const xpriv = data[3]; - it(`should create an english mnemonic (${i})`, () => { - const mnemonic = new HD.Mnemonic({ - language: 'english', - entropy: entropy, - passphrase: 'TREZOR' + for (const lang of Object.keys(tests)) { + const test = tests[lang]; + let i = 0; + + for (const data of test) { + const entropy = Buffer.from(data[0], 'hex'); + const phrase = data[1]; + const passphrase = data[2]; + const seed = Buffer.from(data[3], 'hex'); + const xpriv = data[4]; + it(`should create a ${lang} mnemonic (${i++})`, () => { + const mnemonic = new Mnemonic({ + language: lang, + entropy: entropy, + passphrase: passphrase + }); + + assert.equal(mnemonic.getPhrase(), phrase); + assert.equal(mnemonic.toSeed().toString('hex'), seed.toString('hex')); + + const key = HDPrivateKey.fromMnemonic(mnemonic); + assert.equal(key.toBase58(), xpriv); }); - - assert.equal(mnemonic.getPhrase(), phrase); - assert.equal(mnemonic.toSeed().toString('hex'), seed.toString('hex')); - - const key = HD.fromMnemonic(mnemonic); - assert.equal(key.toBase58(), xpriv); - }); - }); - - mnemonic2.forEach((data, i) => { - const entropy = Buffer.from(data.entropy, 'hex'); - const phrase = data.mnemonic; - const seed = Buffer.from(data.seed, 'hex'); - const passphrase = data.passphrase; - const xpriv = data.bip32_xprv; - it(`should create a japanese mnemonic (${i})`, () => { - const mnemonic = new HD.Mnemonic({ - language: 'japanese', - entropy: entropy, - passphrase: passphrase - }); - - assert.equal(mnemonic.getPhrase(), phrase); - assert.equal(mnemonic.toSeed().toString('hex'), seed.toString('hex')); - - const key = HD.fromMnemonic(mnemonic); - assert.equal(key.toBase58(), xpriv); - }); - }); + } + } it('should verify phrase', () => { - const m1 = new HD.Mnemonic(); - const m2 = HD.Mnemonic.fromPhrase(m1.getPhrase()); + const m1 = new Mnemonic(); + const m2 = Mnemonic.fromPhrase(m1.getPhrase()); assert.deepEqual(m2.getEntropy(), m1.getEntropy()); assert.equal(m2.bits, m1.bits); assert.equal(m2.language, m1.language); diff --git a/test/node-test.js b/test/node-test.js index e5a37e2e..6dbe5759 100644 --- a/test/node-test.js +++ b/test/node-test.js @@ -15,9 +15,6 @@ const TX = require('../lib/primitives/tx'); const Address = require('../lib/primitives/address'); describe('Node', function() { - let wallet, tip1, tip2, cb1, cb2; - let tx1, tx2; - const node = new FullNode({ db: 'memory', apiKey: 'foo', @@ -30,6 +27,9 @@ describe('Node', function() { const miner = node.miner; const wdb = node.require('walletdb'); + let wallet, tip1, tip2, cb1, cb2; + let tx1, tx2; + this.timeout(5000); async function mineBlock(tip, tx) { @@ -605,9 +605,6 @@ describe('Node', function() { }); it('should get a block template', async () => { - let fees = 0; - let weight = 0; - node.rpc.refreshBlock(); const json = await node.rpc.call({ @@ -623,8 +620,10 @@ describe('Node', function() { const result = json.result; - for (let i = 0; i < result.transactions.length; i++) { - const item = result.transactions[i]; + let fees = 0; + let weight = 0; + + for (const item of result.transactions) { fees += item.fee; weight += item.weight; } @@ -679,8 +678,7 @@ describe('Node', function() { const result = json.result; - for (let i = 0; i < result.transactions.length; i++) { - const item = result.transactions[i]; + for (const item of result.transactions) { fees += item.fee; weight += item.weight; } diff --git a/test/protocol-test.js b/test/protocol-test.js index 2be4f56f..399b1dbc 100644 --- a/test/protocol-test.js +++ b/test/protocol-test.js @@ -1,5 +1,6 @@ /* eslint-env mocha */ /* eslint prefer-arrow-callback: "off" */ +/* eslint indent: "off" */ 'use strict'; @@ -11,8 +12,12 @@ const TX = require('../lib/primitives/tx'); const Framer = require('../lib/net/framer'); const Parser = require('../lib/net/parser'); const packets = require('../lib/net/packets'); +const common = require('./util/common'); const network = Network.get('main'); +const tx8 = common.parseTX('data/tx8.hex'); +const tx9 = common.parseTX('data/tx9.hex'); + describe('Protocol', function() { const pkg = require('../lib/pkg'); const agent = `/bcoin:${pkg.version}/`; @@ -76,7 +81,6 @@ describe('Protocol', function() { packetTest('verack', new packets.VerackPacket(), (payload) => { }); - /* eslint indent: 0 */ const hosts = [ new NetAddress({ services: 1, @@ -107,105 +111,12 @@ describe('Protocol', function() { assert.equal(payload.items[1].port, hosts[1].port); }); - it('should include the raw data of only one transaction in a ' + - 'parsed transaction', () => { - const rawTwoTxs = Buffer.from( - '0100000004b124cca7e9686375380c845d0fd002ed704aef4472f4cc193' + - 'fca4aa1b3404da400000000b400493046022100d3c9ba786488323c975f' + - 'e61593df6a8041c5442736f361887abfe5c97175c72b022100ca61688f4' + - '72f4c01ede05ffc50426d68db375f72937b5f39d67835b191b6402f014c' + - '67514104c4bee5e6dbb5c1651437cb4386c1515c7776c64535077204c6f' + - '24f05a37d04a32bc78beb2193b53b104c9954c44b0ce168bc78efd5f1e1' + - 'c7db9d6c21b301659921027f10c31cb2ad7e0388cf5187924f1294082ba' + - '5d4c697bbca7fd83a6af61db7d552aeffffffffb124cca7e9686375380c' + - '845d0fd002ed704aef4472f4cc193fca4aa1b3404da401000000fd15010' + - '0483045022100a35b7fc1973a0a8962c240a7336b501e149ef167491081' + - 'e8df91dc761f4e96c2022004ee4d20983a1d0fb96e9bedf86de03b66d7b' + - 'c50595295b1fb3b5fd2740df3c9014cc9514104c4bee5e6dbb5c1651437' + - 'cb4386c1515c7776c64535077204c6f24f05a37d04a32bc78beb2193b53' + - 'b104c9954c44b0ce168bc78efd5f1e1c7db9d6c21b3016599410495b62d' + - '1e76a915e5ed3694298c5017d2818d22acbf2a8bd9fa4cf635184e15247' + - 'dc7e1a48beb82c1fdddc3b84ac58cec12c8f8b9ca83341ac90299c697fc' + - '94cb4104e3394f3eea40b7abe32f4ad376a80f5a213287d1361b5580e3f' + - 'e70d13a5db0666e2593283b6b5abc01d98cfff5679d8c36b7caefa1c4df' + - '81b10bc45c3812de5f53aeffffffffb124cca7e9686375380c845d0fd00' + - '2ed704aef4472f4cc193fca4aa1b3404da402000000fd5e010047304402' + - '20606d6187e0ade69192f4a447794cdabb8ea9a4e70df09aa8bc689242c' + - '7ffeded02204165ec8edfc9de19d8a94e5f487c8a030187ae16a11e575a' + - '955f532a81b631ad01493046022100f7764763d17757ffdeda3d66cfaa6' + - 'ad3b8f759ddc95e8f73858dba872762658a0221009e903d526595ff9d6d' + - '53835889d816de4c47d78371d7a13223f47602b34bc71e014cc9524104c' + - '4bee5e6dbb5c1651437cb4386c1515c7776c64535077204c6f24f05a37d' + - '04a32bc78beb2193b53b104c9954c44b0ce168bc78efd5f1e1c7db9d6c2' + - '1b3016599410495b62d1e76a915e5ed3694298c5017d2818d22acbf2a8b' + - 'd9fa4cf635184e15247dc7e1a48beb82c1fdddc3b84ac58cec12c8f8b9c' + - 'a83341ac90299c697fc94cb4104e3394f3eea40b7abe32f4ad376a80f5a' + - '213287d1361b5580e3fe70d13a5db0666e2593283b6b5abc01d98cfff56' + - '79d8c36b7caefa1c4df81b10bc45c3812de5f53aeffffffffb124cca7e9' + - '686375380c845d0fd002ed704aef4472f4cc193fca4aa1b3404da404000' + - '0008a473044022075c0666d413fc85cca94ea2f24adc0fedb61a3ba0fcf' + - 'b240c1a4fd2587b03bf90220525ad4d92c6bf635f8b97c188ebf491c6e3' + - '42b767a5432f318cbb0245a7f64be014104c4bee5e6dbb5c1651437cb43' + - '86c1515c7776c64535077204c6f24f05a37d04a32bc78beb2193b53b104' + - 'c9954c44b0ce168bc78efd5f1e1c7db9d6c21b3016599ffffffff01a029' + - 'de5c0500000017a9141d9ca71efa36d814424ea6ca1437e67287aebe348' + - '70000000001000000019457e669dc6b344c0090d10eb22a0377022898d4' + - '607fbdf1e3cef2a323c13fa900000000b2004730440220440d67386a27d' + - '6776e102b82ce2d583e23d51f8ac3bb94749bd10c03ce71410e022041b4' + - '6c5d46b14ef72af9d96fb814fa894077d534a4de1215363ee68fb8d4f50' + - '1014c67514104c4bee5e6dbb5c1651437cb4386c1515c7776c645350772' + - '04c6f24f05a37d04a32bc78beb2193b53b104c9954c44b0ce168bc78efd' + - '5f1e1c7db9d6c21b301659921027f10c31cb2ad7e0388cf5187924f1294' + - '082ba5d4c697bbca7fd83a6af61db7d552aeffffffff0250c3000000000' + - '0001976a9146167aeaeec59836b22447b8af2c5e61fb4f1b7b088ac00a3' + - 'dc5c0500000017a9149eb21980dc9d413d8eac27314938b9da920ee53e8' + - '700000000', 'hex'); + it('should include the raw data of only one transaction', () => { + const raw = Buffer.concat([tx8.tx.toRaw(), tx9.tx.toRaw()]); - const rawFirstTx = Buffer.from( - '0100000004b124cca7e9686375380c845d0fd002ed704aef4472f4cc193' + - 'fca4aa1b3404da400000000b400493046022100d3c9ba786488323c975f' + - 'e61593df6a8041c5442736f361887abfe5c97175c72b022100ca61688f4' + - '72f4c01ede05ffc50426d68db375f72937b5f39d67835b191b6402f014c' + - '67514104c4bee5e6dbb5c1651437cb4386c1515c7776c64535077204c6f' + - '24f05a37d04a32bc78beb2193b53b104c9954c44b0ce168bc78efd5f1e1' + - 'c7db9d6c21b301659921027f10c31cb2ad7e0388cf5187924f1294082ba' + - '5d4c697bbca7fd83a6af61db7d552aeffffffffb124cca7e9686375380c' + - '845d0fd002ed704aef4472f4cc193fca4aa1b3404da401000000fd15010' + - '0483045022100a35b7fc1973a0a8962c240a7336b501e149ef167491081' + - 'e8df91dc761f4e96c2022004ee4d20983a1d0fb96e9bedf86de03b66d7b' + - 'c50595295b1fb3b5fd2740df3c9014cc9514104c4bee5e6dbb5c1651437' + - 'cb4386c1515c7776c64535077204c6f24f05a37d04a32bc78beb2193b53' + - 'b104c9954c44b0ce168bc78efd5f1e1c7db9d6c21b3016599410495b62d' + - '1e76a915e5ed3694298c5017d2818d22acbf2a8bd9fa4cf635184e15247' + - 'dc7e1a48beb82c1fdddc3b84ac58cec12c8f8b9ca83341ac90299c697fc' + - '94cb4104e3394f3eea40b7abe32f4ad376a80f5a213287d1361b5580e3f' + - 'e70d13a5db0666e2593283b6b5abc01d98cfff5679d8c36b7caefa1c4df' + - '81b10bc45c3812de5f53aeffffffffb124cca7e9686375380c845d0fd00' + - '2ed704aef4472f4cc193fca4aa1b3404da402000000fd5e010047304402' + - '20606d6187e0ade69192f4a447794cdabb8ea9a4e70df09aa8bc689242c' + - '7ffeded02204165ec8edfc9de19d8a94e5f487c8a030187ae16a11e575a' + - '955f532a81b631ad01493046022100f7764763d17757ffdeda3d66cfaa6' + - 'ad3b8f759ddc95e8f73858dba872762658a0221009e903d526595ff9d6d' + - '53835889d816de4c47d78371d7a13223f47602b34bc71e014cc9524104c' + - '4bee5e6dbb5c1651437cb4386c1515c7776c64535077204c6f24f05a37d' + - '04a32bc78beb2193b53b104c9954c44b0ce168bc78efd5f1e1c7db9d6c2' + - '1b3016599410495b62d1e76a915e5ed3694298c5017d2818d22acbf2a8b' + - 'd9fa4cf635184e15247dc7e1a48beb82c1fdddc3b84ac58cec12c8f8b9c' + - 'a83341ac90299c697fc94cb4104e3394f3eea40b7abe32f4ad376a80f5a' + - '213287d1361b5580e3fe70d13a5db0666e2593283b6b5abc01d98cfff56' + - '79d8c36b7caefa1c4df81b10bc45c3812de5f53aeffffffffb124cca7e9' + - '686375380c845d0fd002ed704aef4472f4cc193fca4aa1b3404da404000' + - '0008a473044022075c0666d413fc85cca94ea2f24adc0fedb61a3ba0fcf' + - 'b240c1a4fd2587b03bf90220525ad4d92c6bf635f8b97c188ebf491c6e3' + - '42b767a5432f318cbb0245a7f64be014104c4bee5e6dbb5c1651437cb43' + - '86c1515c7776c64535077204c6f24f05a37d04a32bc78beb2193b53b104' + - 'c9954c44b0ce168bc78efd5f1e1c7db9d6c21b3016599ffffffff01a029' + - 'de5c0500000017a9141d9ca71efa36d814424ea6ca1437e67287aebe348' + - '700000000', 'hex'); + const tx = TX.fromRaw(raw); + tx.refresh(); - const tx = TX.fromRaw(rawTwoTxs); - tx._raw = null; - - assert.deepEqual(tx.toRaw(), rawFirstTx); + assert.deepEqual(tx.toRaw(), tx8.tx.toRaw()); }); }); diff --git a/test/schnorr-test.js b/test/schnorr-test.js new file mode 100644 index 00000000..1de62a5b --- /dev/null +++ b/test/schnorr-test.js @@ -0,0 +1,20 @@ +/* eslint-env mocha */ +/* eslint prefer-arrow-callback: "off" */ + +'use strict'; + +const assert = require('assert'); +const secp256k1 = require('../lib/crypto/secp256k1'); +const digest = require('../lib/crypto/digest'); +const schnorr = require('../lib/crypto/schnorr'); + +describe('Schnorr', function() { + it('should do proper schnorr', () => { + const key = secp256k1.generatePrivateKey(); + const pub = secp256k1.publicKeyCreate(key, true); + const msg = digest.hash256(Buffer.from('foo', 'ascii')); + const sig = schnorr.sign(msg, key); + assert(schnorr.verify(msg, sig, pub)); + assert.deepEqual(schnorr.recover(sig, msg), pub); + }); +}); diff --git a/test/script-test.js b/test/script-test.js index b5eb3a3a..8cb3a900 100644 --- a/test/script-test.js +++ b/test/script-test.js @@ -11,7 +11,7 @@ const TX = require('../lib/primitives/tx'); const encoding = require('../lib/utils/encoding'); const opcodes = Script.opcodes; -const scripts = require('./data/script_tests'); +const scripts = require('./data/script-tests.json'); function success(res, stack) { if (!res) @@ -26,6 +26,45 @@ function success(res, stack) { return true; } +function parseScriptTest(data) { + const witHex = Array.isArray(data[0]) ? data.shift() : []; + const inpHex = data[0] ? data[0].trim() : data[0] || ''; + const outHex = data[1] ? data[1].trim() : data[1] || ''; + const names = data[2] ? data[2].trim().split(/,\s*/) : []; + const expected = data[3] || ''; + let comments = Array.isArray(data[4]) ? data[4].join('. ') : data[4] || ''; + + if (!comments) + comments = outHex.slice(0, 60); + + comments += ` (${expected})`; + + let amount = 0; + if (witHex.length !== 0) + amount = witHex.pop() * 1e8; + + const witness = Witness.fromString(witHex); + const input = Script.fromString(inpHex); + const output = Script.fromString(outHex); + + let flags = 0; + for (const name of names) { + const flag = `VERIFY_${name}`; + assert(Script.flags[flag] != null, 'Unknown flag.'); + flags |= Script.flags[flag]; + } + + return { + witness: witness, + input: input, + output: output, + amount: amount, + flags: flags, + expected: expected, + comments: comments + }; +} + describe('Script', function() { it('should encode/decode script', () => { const src = '20' @@ -67,97 +106,108 @@ describe('Script', function() { }); it('should handle if statements correctly', () => { - let input = new Script([opcodes.OP_1, opcodes.OP_2]); + { + const input = new Script([opcodes.OP_1, opcodes.OP_2]); - let output = new Script([ - opcodes.OP_2, - opcodes.OP_EQUAL, - opcodes.OP_IF, - opcodes.OP_3, - opcodes.OP_ELSE, - opcodes.OP_4, - opcodes.OP_ENDIF, - opcodes.OP_5 - ]); + const output = new Script([ + opcodes.OP_2, + opcodes.OP_EQUAL, + opcodes.OP_IF, + opcodes.OP_3, + opcodes.OP_ELSE, + opcodes.OP_4, + opcodes.OP_ENDIF, + opcodes.OP_5 + ]); - let stack = new Stack(); + const stack = new Stack(); - input.execute(stack); + input.execute(stack); - let res = output.execute(stack); - assert(res); + const res = output.execute(stack); + assert(res); - assert.deepEqual(stack.items, [[1], [3], [5]]); + assert.deepEqual(stack.items, [[1], [3], [5]]); + } - input = new Script([opcodes.OP_1, opcodes.OP_2]); - output = new Script([ - opcodes.OP_9, - opcodes.OP_EQUAL, - opcodes.OP_IF, - opcodes.OP_3, - opcodes.OP_ELSE, - opcodes.OP_4, - opcodes.OP_ENDIF, - opcodes.OP_5 - ]); + { + const input = new Script([opcodes.OP_1, opcodes.OP_2]); + const output = new Script([ + opcodes.OP_9, + opcodes.OP_EQUAL, + opcodes.OP_IF, + opcodes.OP_3, + opcodes.OP_ELSE, + opcodes.OP_4, + opcodes.OP_ENDIF, + opcodes.OP_5 + ]); - stack = new Stack(); - input.execute(stack); + const stack = new Stack(); + input.execute(stack); - res = output.execute(stack); - assert(res); - assert.deepEqual(stack.items, [[1], [4], [5]]); + const res = output.execute(stack); + assert(res); + assert.deepEqual(stack.items, [[1], [4], [5]]); + } - input = new Script([opcodes.OP_1, opcodes.OP_2]); - output = new Script([ - opcodes.OP_2, - opcodes.OP_EQUAL, - opcodes.OP_IF, - opcodes.OP_3, - opcodes.OP_ENDIF, - opcodes.OP_5 - ]); + { + const input = new Script([opcodes.OP_1, opcodes.OP_2]); + const output = new Script([ + opcodes.OP_2, + opcodes.OP_EQUAL, + opcodes.OP_IF, + opcodes.OP_3, + opcodes.OP_ENDIF, + opcodes.OP_5 + ]); - stack = new Stack(); + const stack = new Stack(); - input.execute(stack); + input.execute(stack); - res = output.execute(stack); - assert(res); - assert.deepEqual(stack.items, [[1], [3], [5]]); + const res = output.execute(stack); + assert(res); + assert.deepEqual(stack.items, [[1], [3], [5]]); + } - input = new Script([opcodes.OP_1, opcodes.OP_2]); - output = new Script([ - opcodes.OP_9, - opcodes.OP_EQUAL, - opcodes.OP_IF, - opcodes.OP_3, - opcodes.OP_ENDIF, - opcodes.OP_5 - ]); + { + const input = new Script([opcodes.OP_1, opcodes.OP_2]); + const output = new Script([ + opcodes.OP_9, + opcodes.OP_EQUAL, + opcodes.OP_IF, + opcodes.OP_3, + opcodes.OP_ENDIF, + opcodes.OP_5 + ]); - stack = new Stack(); - input.execute(stack); + const stack = new Stack(); + input.execute(stack); - res = output.execute(stack); - assert(res); - assert.deepEqual(stack.items, [[1], [5]]); + const res = output.execute(stack); + assert(res); + assert.deepEqual(stack.items, [[1], [5]]); + } - input = new Script([opcodes.OP_1, opcodes.OP_2]); - output = new Script([ - opcodes.OP_9, - opcodes.OP_EQUAL, - opcodes.OP_NOTIF, - opcodes.OP_3, - opcodes.OP_ENDIF, - opcodes.OP_5 - ]); - stack = new Stack(); - input.execute(stack); + { + const input = new Script([opcodes.OP_1, opcodes.OP_2]); + const output = new Script([ + opcodes.OP_9, + opcodes.OP_EQUAL, + opcodes.OP_NOTIF, + opcodes.OP_3, + opcodes.OP_ENDIF, + opcodes.OP_5 + ]); - res = output.execute(stack); - assert(res); - assert.deepEqual(stack.items, [[1], [3], [5]]); + const stack = new Stack(); + input.execute(stack); + + const res = output.execute(stack); + assert(res); + assert.deepEqual(stack.items, [[1], [3], [5]]); + } }); it('should handle CScriptNums correctly', () => { @@ -221,39 +271,18 @@ describe('Script', function() { assert(success(output.execute(stack), stack)); }); - scripts.forEach((data) => { - let witness = Array.isArray(data[0]) ? data.shift() : []; - let input = data[0] ? data[0].trim() : data[0] || ''; - let output = data[1] ? data[1].trim() : data[1] || ''; - const names = data[2] ? data[2].trim().split(/,\s*/) : []; - const expected = data[3] || ''; - let comments = Array.isArray(data[4]) ? data[4].join('. ') : data[4] || ''; - let amount = 0; - let flags = 0; - + for (const data of scripts) { if (data.length === 1) - return; + continue; - if (!comments) - comments = output.slice(0, 60); + const test = parseScriptTest(data); + const {witness, input, output} = test; + const {amount, flags} = test; + const {expected, comments} = test; - comments += ` (${expected})`; - - if (witness.length !== 0) - amount = witness.pop() * 100000000; - - witness = Witness.fromString(witness); - input = Script.fromString(input); - output = Script.fromString(output); - - for (let name of names) { - name = `VERIFY_${name}`; - assert(Script.flags[name] != null, 'Unknown flag.'); - flags |= Script.flags[name]; - } - - [false, true].forEach((noCache) => { + for (const noCache of [false, true]) { const suffix = noCache ? 'without cache' : 'with cache'; + it(`should handle script test ${suffix}:${comments}`, () => { // Funding transaction. const prev = new TX({ @@ -318,6 +347,6 @@ describe('Script', function() { assert.ifError(err); assert(res); }); - }); - }); + } + } }); diff --git a/test/scrypt-test.js b/test/scrypt-test.js index 6ec18002..88999dba 100644 --- a/test/scrypt-test.js +++ b/test/scrypt-test.js @@ -49,4 +49,45 @@ describe('Scrypt', function() { // + 'ee9820adaa478e56fd8f4ba5d09ffa1c6d927c40f4c337304049' // + 'e8a952fbcbf45c6fa77a41a4'); // }); + + it('should perform scrypt with N=16 (async)', async () => { + const pass = Buffer.from(''); + const salt = Buffer.from(''); + const result = await scrypt.deriveAsync(pass, salt, 16, 1, 1, 64); + assert.equal(result.toString('hex'), '' + + '77d6576238657b203b19ca42c18a0497f16b4844e3074ae8dfdffa3f' + + 'ede21442fcd0069ded0948f8326a753a0fc81f17e8d3e0fb2e0d3628' + + 'cf35e20c38d18906'); + }); + + it('should perform scrypt with N=1024 (async)', async () => { + const pass = Buffer.from('password'); + const salt = Buffer.from('NaCl'); + const result = await scrypt.deriveAsync(pass, salt, 1024, 8, 16, 64); + assert.equal(result.toString('hex'), '' + + 'fdbabe1c9d3472007856e7190d01e9fe7c6ad7cbc8237830e773' + + '76634b3731622eaf30d92e22a3886ff109279d9830dac727afb9' + + '4a83ee6d8360cbdfa2cc0640'); + }); + + it('should perform scrypt with N=16384 (async)', async () => { + const pass = Buffer.from('pleaseletmein'); + const salt = Buffer.from('SodiumChloride'); + const result = await scrypt.deriveAsync(pass, salt, 16384, 8, 1, 64); + assert.equal(result.toString('hex'), '' + + '7023bdcb3afd7348461c06cd81fd38ebfda8fbba904f8e3ea9b54' + + '3f6545da1f2d5432955613f0fcf62d49705242a9af9e61e85dc0d' + + '651e40dfcf017b45575887'); + }); + + // Only enable if you want to wait a while. + // it('should perform scrypt with N=1048576 (async)', async () => { + // let pass = Buffer.from('pleaseletmein'); + // let salt = Buffer.from('SodiumChloride'); + // let result = await scrypt.deriveAsync(pass, salt, 1048576, 8, 1, 64); + // assert.equal(result.toString('hex'), '' + // + '2101cb9b6a511aaeaddbbe09cf70f881ec568d574a2ffd4dabe5' + // + 'ee9820adaa478e56fd8f4ba5d09ffa1c6d927c40f4c337304049' + // + 'e8a952fbcbf45c6fa77a41a4'); + // }); }); diff --git a/test/tx-test.js b/test/tx-test.js index 60fe8966..8d62a8e2 100644 --- a/test/tx-test.js +++ b/test/tx-test.js @@ -17,18 +17,20 @@ const Witness = require('../lib/script/witness'); const Input = require('../lib/primitives/input'); const CoinView = require('../lib/coins/coinview'); const KeyRing = require('../lib/primitives/keyring'); -const parseTX = require('./util/common').parseTX; +const common = require('./util/common'); const opcodes = Script.opcodes; -const valid = require('./data/tx_valid.json'); -const invalid = require('./data/tx_invalid.json'); -const sighash = require('./data/sighash.json'); -const tx1 = parseTX('data/tx1.hex'); -const tx2 = parseTX('data/tx2.hex'); -const tx3 = parseTX('data/tx3.hex'); -const tx4 = parseTX('data/tx4.hex'); -const wtx = parseTX('data/wtx.hex'); -const coolest = parseTX('data/coolest-tx-ever-sent.hex'); +const validTests = require('./data/tx-valid.json'); +const invalidTests = require('./data/tx-invalid.json'); +const sighashTests = require('./data/sighash-tests.json'); + +const tx1 = common.parseTX('data/tx1.hex'); +const tx2 = common.parseTX('data/tx2.hex'); +const tx3 = common.parseTX('data/tx3.hex'); +const tx4 = common.parseTX('data/tx4.hex'); +const tx5 = common.parseTX('data/tx5.hex'); +const tx6 = common.parseTX('data/tx6.hex'); +const tx7 = common.parseTX('data/tx7.hex'); const MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER; const MAX_SAFE_ADDITION = 0xfffffffffffff; @@ -41,27 +43,23 @@ function clearCache(tx, noCache) { tx.refresh(); } -function parseTest(data) { - let [coins, tx, names] = data; - const view = new CoinView(); +function parseTXTest(data) { + const [coins, hex, names] = data; + let flags = 0; - if (!names) - names = ''; - - tx = TX.fromRaw(tx, 'hex'); - names = names.trim().split(/,\s*/); - - for (let name of names) { - name = `VERIFY_${name}`; - assert(Script.flags[name] != null, 'Unknown flag.'); - flags |= Script.flags[name]; + for (const name of (names || '').trim().split(/,\s*/)) { + const flag = `VERIFY_${name}`; + assert(Script.flags[flag] != null, 'Unknown flag.'); + flags |= Script.flags[flag]; } - for (let [hash, index, script, value] of coins) { - hash = util.revHex(hash); - script = Script.fromString(script); - value = parseInt(value || '0', 10); + const view = new CoinView(); + + for (const [txid, index, str, amount] of coins) { + const hash = util.revHex(txid); + const script = Script.fromString(str); + const value = parseInt(amount || '0', 10); if (index === -1) continue; @@ -79,6 +77,9 @@ function parseTest(data) { view.addCoin(coin); } + const raw = Buffer.from(hex, 'hex'); + const tx = TX.fromRaw(raw); + const coin = view.getOutputFor(tx.inputs[0]); return { @@ -92,34 +93,93 @@ function parseTest(data) { }; } +function parseSighashTest(data) { + const [txHex, scriptHex, index, type, hash] = data; + + const tx = TX.fromRaw(txHex, 'hex'); + const script = Script.fromRaw(scriptHex, 'hex'); + + const expected = util.revHex(hash); + + let hex = type & 3; + + if (type & 0x80) + hex |= 0x80; + + hex = hex.toString(16); + + if (hex.length % 2 !== 0) + hex = '0' + hex; + + return { + tx: tx, + script: script, + index: index, + type: type, + hash: hash, + expected: expected, + hex: hex + }; +} + +function createInput(value, view) { + const hash = random.randomBytes(32).toString('hex'); + + const input = { + prevout: { + hash: hash, + index: 0 + } + }; + + const output = new Output(); + output.value = value; + + if (!view) + view = new CoinView(); + + view.addOutput(new Outpoint(hash, 0), output); + + return [input, view]; +}; + function sigopContext(scriptSig, witness, scriptPubkey) { - const view = new CoinView(); - - let input = new Input(); - let output = new Output(); - output.value = 1; - output.script = scriptPubkey; - const fund = new TX(); - fund.version = 1; - fund.inputs.push(input); - fund.outputs.push(output); - fund.refresh(); - input = new Input(); - input.prevout.hash = fund.hash('hex'); - input.prevout.index = 0; - input.script = scriptSig; - input.witness = witness; + { + fund.version = 1; - output = new Output(); - output.value = 1; + const input = new Input(); + fund.inputs.push(input); + + const output = new Output(); + output.value = 1; + output.script = scriptPubkey; + fund.outputs.push(output); + + fund.refresh(); + } const spend = new TX(); - spend.version = 1; - spend.inputs.push(input); - spend.outputs.push(output); - spend.refresh(); + + { + spend.version = 1; + + const input = new Input(); + input.prevout.hash = fund.hash('hex'); + input.prevout.index = 0; + input.script = scriptSig; + input.witness = witness; + spend.inputs.push(input); + + const output = new Output(); + output.value = 1; + spend.outputs.push(output); + + spend.refresh(); + } + + const view = new CoinView(); view.addTX(fund, 0); @@ -131,151 +191,96 @@ function sigopContext(scriptSig, witness, scriptPubkey) { } describe('TX', function() { - const raw = '010000000125393c67cd4f581456dd0805fa8e9db3abdf90dbe1d4b53e28' + - '6490f35d22b6f2010000006b483045022100f4fa5ced20d2dbd2f905809d' + - '79ebe34e03496ef2a48a04d0a9a1db436a211dd202203243d086398feb4a' + - 'c21b3b79884079036cd5f3707ba153b383eabefa656512dd0121022ebabe' + - 'fede28804b331608d8ef11e1d65b5a920720db8a644f046d156b3a73c0ff' + - 'ffffff0254150000000000001976a9140740345f114e1a1f37ac1cc442b4' + - '32b91628237e88ace7d27b00000000001976a91495ad422bb5911c2c9fe6' + - 'ce4f82a13c85f03d9b2e88ac00000000'; - const inp = '01000000052fa236559f51f343f0905ea627a955f421a198541d928798b8' + - '186980273942ec010000006b483045022100ae27626778eba264d56883f5' + - 'edc1a49897bf209e98f21c870a55d13bec916e1802204b66f4e3235143d1' + - '1aef327d9454754cd1f28807c3bf9996c107900df9d19ea60121022ebabe' + - 'fede28804b331608d8ef11e1d65b5a920720db8a644f046d156b3a73c0ff' + - 'ffffffe2136f72e4a25e300137b98b402cda91db5c6db6373ba81c722ae1' + - 'a85315b591000000006b483045022100f84293ea9bfb6d150f3a72d8b5ce' + - 'b294a77b31442bf9d4ab2058f046a9b65a9f022075935dc0a6a628df26eb' + - 'b7215634fd33b65f4da105665595028837680b87ea360121039708df1967' + - '09c5041dc9a26457a0cfa303076329f389687bdc9709d5862fd664ffffff' + - 'fff6e67655a42a2f955ec8610940c983042516c32298e57684b3c29fcade' + - '7e637a000000006a47304402203bbfb53c3011d742f3f942db18a44d8c3d' + - 'd111990ee7cc42959383dd7a3e8e8d02207f0f5ed3e165d9db81ac69d36c' + - '60a1a4a482f22cb0048dafefa5e704e84dd18e0121039708df196709c504' + - '1dc9a26457a0cfa303076329f389687bdc9709d5862fd664ffffffff9a02' + - 'e72123a149570c11696d3c798593785e95b8a3c3fc49ae1d07d809d94d5a' + - '000000006b483045022100ad0e6f5f73221aa4eda9ad82c7074882298bcf' + - '668f34ae81126df0213b2961850220020ba23622d75fb8f95199063b804f' + - '62ba103545af4e16b5be0b6dc0cb51aac60121039708df196709c5041dc9' + - 'a26457a0cfa303076329f389687bdc9709d5862fd664ffffffffd7db5a38' + - '72589ca8aa3cd5ebb0f22dbb3956f8d691e15dc010fe1093c045c3de0000' + - '00006b48304502210082b91a67da1f02dcb0d00e63b67f10af8ba9639b16' + - '5f9ff974862a9d4900e27c022069e4a58f591eb3fc7d7d0b176d64d59e90' + - 'aef0c601b3c84382abad92f6973e630121039708df196709c5041dc9a264' + - '57a0cfa303076329f389687bdc9709d5862fd664ffffffff025415000000' + - '0000001976a9140740345f114e1a1f37ac1cc442b432b91628237e88ac4b' + - '0f7c00000000001976a91495ad422bb5911c2c9fe6ce4f82a13c85f03d9b' + - '2e88ac00000000'; - - [false, true].forEach((noCache) => { + for (const noCache of [false, true]) { const suffix = noCache ? 'without cache' : 'with cache'; - it(`should decode/encode with parser/framer ${suffix}`, () => { - const tx = TX.fromRaw(raw, 'hex'); - clearCache(tx, noCache); - assert.equal(tx.toRaw().toString('hex'), raw); - }); - - it(`should be verifiable ${suffix}`, () => { - const tx = TX.fromRaw(raw, 'hex'); - const p = TX.fromRaw(inp, 'hex'); - const view = new CoinView(); - view.addTX(p, -1); - - clearCache(tx, noCache); - clearCache(p, noCache); - - assert(tx.verify(view)); - }); - it(`should verify non-minimal output ${suffix}`, () => { - clearCache(tx1.tx, noCache); - assert(tx1.tx.verify(tx1.view, Script.flags.VERIFY_P2SH)); + const {tx, view} = tx1; + clearCache(tx, noCache); + assert(tx.verify(view, Script.flags.VERIFY_P2SH)); }); it(`should verify tx.version == 0 ${suffix}`, () => { - clearCache(tx2.tx, noCache); - assert(tx2.tx.verify(tx2.view, Script.flags.VERIFY_P2SH)); + const {tx, view} = tx2; + clearCache(tx, noCache); + assert(tx.verify(view, Script.flags.VERIFY_P2SH)); }); it(`should verify sighash_single bug w/ findanddelete ${suffix}`, () => { - clearCache(tx3.tx, noCache); - assert(tx3.tx.verify(tx3.view, Script.flags.VERIFY_P2SH)); + const {tx, view} = tx3; + clearCache(tx, noCache); + assert(tx.verify(view, Script.flags.VERIFY_P2SH)); }); it(`should verify high S value with only DERSIG enabled ${suffix}`, () => { - const coin = tx4.view.getOutputFor(tx4.tx.inputs[0]); + const {tx, view} = tx4; + const coin = view.getOutputFor(tx.inputs[0]); const flags = Script.flags.VERIFY_P2SH | Script.flags.VERIFY_DERSIG; - clearCache(tx4.tx, noCache); - assert(tx4.tx.verifyInput(0, coin, flags)); - }); - - it(`should verify the coolest tx ever sent ${suffix}`, () => { - clearCache(coolest.tx, noCache); - assert(coolest.tx.verify(coolest.view, Script.flags.VERIFY_NONE)); + clearCache(tx, noCache); + assert(tx.verifyInput(0, coin, flags)); }); it(`should parse witness tx properly ${suffix}`, () => { - clearCache(wtx.tx, noCache); + const {tx} = tx5; + clearCache(tx, noCache); - assert.equal(wtx.tx.inputs.length, 5); - assert.equal(wtx.tx.outputs.length, 1980); - assert(wtx.tx.hasWitness()); - assert.notEqual(wtx.tx.hash('hex'), wtx.tx.witnessHash('hex')); - assert.equal(wtx.tx.witnessHash('hex'), + assert.equal(tx.inputs.length, 5); + assert.equal(tx.outputs.length, 1980); + assert(tx.hasWitness()); + assert.notEqual(tx.hash('hex'), tx.witnessHash('hex')); + assert.equal(tx.witnessHash('hex'), '088c919cd8408005f255c411f786928385688a9e8fdb2db4c9bc3578ce8c94cf'); - assert.equal(wtx.tx.getSize(), 62138); - assert.equal(wtx.tx.getVirtualSize(), 61813); - assert.equal(wtx.tx.getWeight(), 247250); + assert.equal(tx.getSize(), 62138); + assert.equal(tx.getVirtualSize(), 61813); + assert.equal(tx.getWeight(), 247250); - const raw1 = wtx.tx.toRaw(); - clearCache(wtx.tx, true); + const raw1 = tx.toRaw(); + clearCache(tx, true); - const raw2 = wtx.tx.toRaw(); + const raw2 = tx.toRaw(); assert.deepEqual(raw1, raw2); - const wtx2 = TX.fromRaw(raw2); - clearCache(wtx2, noCache); + const tx2 = TX.fromRaw(raw2); + clearCache(tx2, noCache); - assert.equal(wtx.tx.hash('hex'), wtx2.hash('hex')); - assert.equal(wtx.tx.witnessHash('hex'), wtx2.witnessHash('hex')); + assert.equal(tx.hash('hex'), tx2.hash('hex')); + assert.equal(tx.witnessHash('hex'), tx2.witnessHash('hex')); }); - [[valid, true], [invalid, false]].forEach((test) => { - const [arr, valid] = test; + it(`should verify the coolest tx ever sent ${suffix}`, () => { + const {tx, view} = tx6; + clearCache(tx, noCache); + assert(tx.verify(view, Script.flags.VERIFY_NONE)); + }); + + it(`should verify a historical transaction ${suffix}`, () => { + const {tx, view} = tx7; + clearCache(tx, noCache); + assert(tx.verify(view)); + }); + + for (const tests of [validTests, invalidTests]) { let comment = ''; - arr.forEach((json, i) => { + for (const json of tests) { if (json.length === 1) { comment += ' ' + json[0]; - return; + continue; } - const data = parseTest(json); - - if (!data) { - comment = ''; - return; - } - - const tx = data.tx; - const view = data.view; - const flags = data.flags; - let comments = comment.trim(); - - if (!comments) - comments = data.comments; + const data = parseTXTest(json); + const {tx, view, flags} = data; + const comments = comment.trim() || data.comments; comment = ''; - if (valid) { + if (tests === validTests) { if (comments.indexOf('Coinbase') === 0) { it(`should handle valid tx test ${suffix}: ${comments}`, () => { clearCache(tx, noCache); assert.ok(tx.isSane()); }); - return; + continue; } it(`should handle valid tx test ${suffix}: ${comments}`, () => { clearCache(tx, noCache); @@ -288,7 +293,7 @@ describe('TX', function() { assert.ok(tx.verify(view, flags)); assert.ok(!tx.isSane()); }); - return; + continue; } if (comments === 'Negative output') { it(`should handle invalid tx test ${suffix}: ${comments}`, () => { @@ -296,42 +301,30 @@ describe('TX', function() { assert.ok(tx.verify(view, flags)); assert.ok(!tx.isSane()); }); - return; + continue; } if (comments.indexOf('Coinbase') === 0) { it(`should handle invalid tx test ${suffix}: ${comments}`, () => { clearCache(tx, noCache); assert.ok(!tx.isSane()); }); - return; + continue; } it(`should handle invalid tx test ${suffix}: ${comments}`, () => { clearCache(tx, noCache); assert.ok(!tx.verify(view, flags)); }); } - }); - }); + } + } - sighash.forEach((data) => { - let [tx, script, index, type, hash] = data; + for (const json of sighashTests) { + if (json.length === 1) + continue; - if (data.length === 1) - return; - - tx = TX.fromRaw(tx, 'hex'); - script = Script.fromRaw(script, 'hex'); - - const expected = util.revHex(hash); - let hex = type & 3; - - if (type & 0x80) - hex |= 0x80; - - hex = hex.toString(16); - - if (hex.length % 2 !== 0) - hex = '0' + hex; + const test = parseSighashTest(json); + const {tx, script, index, type} = test; + const {hash, hex, expected} = test; clearCache(tx, noCache); @@ -340,28 +333,15 @@ describe('TX', function() { const hash = tx.signatureHash(index, subscript, 0, type, 0); assert.equal(hash.toString('hex'), expected); }); - }); - }); - - function createInput(value, view) { - const hash = random.randomBytes(32).toString('hex'); - const output = new Output(); - output.value = value; - view.addOutput(new Outpoint(hash, 0), output); - return { - prevout: { - hash: hash, - index: 0 - } - }; + } } it('should fail on >51 bit coin values', () => { - const view = new CoinView(); + const [input, view] = createInput(consensus.MAX_MONEY + 1); const tx = new TX({ version: 1, flag: 1, - inputs: [createInput(consensus.MAX_MONEY + 1, view)], + inputs: [input], outputs: [{ script: [], value: consensus.MAX_MONEY @@ -373,11 +353,11 @@ describe('TX', function() { }); it('should handle 51 bit coin values', () => { - const view = new CoinView(); + const [input, view] = createInput(consensus.MAX_MONEY); const tx = new TX({ version: 1, flag: 1, - inputs: [createInput(consensus.MAX_MONEY, view)], + inputs: [input], outputs: [{ script: [], value: consensus.MAX_MONEY @@ -389,11 +369,11 @@ describe('TX', function() { }); it('should fail on >51 bit output values', () => { - const view = new CoinView(); + const [input, view] = createInput(consensus.MAX_MONEY); const tx = new TX({ version: 1, flag: 1, - inputs: [createInput(consensus.MAX_MONEY, view)], + inputs: [input], outputs: [{ script: [], value: consensus.MAX_MONEY + 1 @@ -405,11 +385,11 @@ describe('TX', function() { }); it('should handle 51 bit output values', () => { - const view = new CoinView(); + const [input, view] = createInput(consensus.MAX_MONEY); const tx = new TX({ version: 1, flag: 1, - inputs: [createInput(consensus.MAX_MONEY, view)], + inputs: [input], outputs: [{ script: [], value: consensus.MAX_MONEY @@ -421,11 +401,11 @@ describe('TX', function() { }); it('should fail on >51 bit fees', () => { - const view = new CoinView(); + const [input, view] = createInput(consensus.MAX_MONEY + 1); const tx = new TX({ version: 1, flag: 1, - inputs: [createInput(consensus.MAX_MONEY + 1, view)], + inputs: [input], outputs: [{ script: [], value: 0 @@ -442,9 +422,9 @@ describe('TX', function() { version: 1, flag: 1, inputs: [ - createInput(Math.floor(consensus.MAX_MONEY / 2), view), - createInput(Math.floor(consensus.MAX_MONEY / 2), view), - createInput(Math.floor(consensus.MAX_MONEY / 2), view) + createInput(Math.floor(consensus.MAX_MONEY / 2), view)[0], + createInput(Math.floor(consensus.MAX_MONEY / 2), view)[0], + createInput(Math.floor(consensus.MAX_MONEY / 2), view)[0] ], outputs: [{ script: [], @@ -457,11 +437,11 @@ describe('TX', function() { }); it('should fail on >51 bit output values from multiple', () => { - const view = new CoinView(); + const [input, view] = createInput(consensus.MAX_MONEY); const tx = new TX({ version: 1, flag: 1, - inputs: [createInput(consensus.MAX_MONEY, view)], + inputs: [input], outputs: [ { script: [], @@ -488,9 +468,9 @@ describe('TX', function() { version: 1, flag: 1, inputs: [ - createInput(Math.floor(consensus.MAX_MONEY / 2), view), - createInput(Math.floor(consensus.MAX_MONEY / 2), view), - createInput(Math.floor(consensus.MAX_MONEY / 2), view) + createInput(Math.floor(consensus.MAX_MONEY / 2), view)[0], + createInput(Math.floor(consensus.MAX_MONEY / 2), view)[0], + createInput(Math.floor(consensus.MAX_MONEY / 2), view)[0] ], outputs: [{ script: [], @@ -503,14 +483,12 @@ describe('TX', function() { }); it('should fail to parse >53 bit values', () => { - const view = new CoinView(); + const [input] = createInput(Math.floor(consensus.MAX_MONEY / 2)); const tx = new TX({ version: 1, flag: 1, - inputs: [ - createInput(Math.floor(consensus.MAX_MONEY / 2), view) - ], + inputs: [input], outputs: [{ script: [], value: 0xdeadbeef @@ -522,9 +500,7 @@ describe('TX', function() { assert(encoding.readU64(raw, 47) === 0xdeadbeef); raw[54] = 0x7f; - assert.throws(() => { - TX.fromRaw(raw); - }); + assert.throws(() => TX.fromRaw(raw)); tx.outputs[0].value = 0; tx.refresh(); @@ -532,17 +508,15 @@ describe('TX', function() { raw = tx.toRaw(); assert(encoding.readU64(raw, 47) === 0x00); raw[54] = 0x80; - assert.throws(() => { - TX.fromRaw(raw); - }); + assert.throws(() => TX.fromRaw(raw)); }); it('should fail on 53 bit coin values', () => { - const view = new CoinView(); + const [input, view] = createInput(MAX_SAFE_INTEGER); const tx = new TX({ version: 1, flag: 1, - inputs: [createInput(MAX_SAFE_INTEGER, view)], + inputs: [input], outputs: [{ script: [], value: consensus.MAX_MONEY @@ -554,11 +528,11 @@ describe('TX', function() { }); it('should fail on 53 bit output values', () => { - const view = new CoinView(); + const [input, view] = createInput(consensus.MAX_MONEY); const tx = new TX({ version: 1, flag: 1, - inputs: [createInput(consensus.MAX_MONEY, view)], + inputs: [input], outputs: [{ script: [], value: MAX_SAFE_INTEGER @@ -570,11 +544,11 @@ describe('TX', function() { }); it('should fail on 53 bit fees', () => { - const view = new CoinView(); + const [input, view] = createInput(MAX_SAFE_INTEGER); const tx = new TX({ version: 1, flag: 1, - inputs: [createInput(MAX_SAFE_INTEGER, view)], + inputs: [input], outputs: [{ script: [], value: 0 @@ -592,9 +566,9 @@ describe('TX', function() { version: 1, flag: 1, inputs: [ - createInput(MAX, view), - createInput(MAX, view), - createInput(MAX, view) + createInput(MAX, view)[0], + createInput(MAX, view)[0], + createInput(MAX, view)[0] ], outputs: [{ script: [], @@ -607,11 +581,11 @@ describe('TX', function() { }); it('should fail on >53 bit output values from multiple', () => { - const view = new CoinView(); + const [input, view] = createInput(consensus.MAX_MONEY); const tx = new TX({ version: 1, flag: 1, - inputs: [createInput(consensus.MAX_MONEY, view)], + inputs: [input], outputs: [ { script: [], @@ -638,9 +612,9 @@ describe('TX', function() { version: 1, flag: 1, inputs: [ - createInput(MAX, view), - createInput(MAX, view), - createInput(MAX, view) + createInput(MAX, view)[0], + createInput(MAX, view)[0], + createInput(MAX, view)[0] ], outputs: [{ script: [], @@ -700,35 +674,40 @@ describe('TX', function() { const flags = Script.flags.VERIFY_WITNESS | Script.flags.VERIFY_P2SH; const key = KeyRing.generate(); - let output = Script.fromProgram(0, key.getKeyHash()); - - const input = new Script(); - const witness = new Witness([ Buffer.from([0]), Buffer.from([0]) ]); - let ctx = sigopContext(input, witness, output); + const input = new Script(); - assert.equal(ctx.spend.getSigopsCost(ctx.view, flags), 1); - assert.equal( - ctx.spend.getSigopsCost(ctx.view, flags & ~Script.flags.VERIFY_WITNESS), - 0); + { + const output = Script.fromProgram(0, key.getKeyHash()); + const ctx = sigopContext(input, witness, output); - output = Script.fromProgram(1, key.getKeyHash()); - ctx = sigopContext(input, witness, output); + assert.equal(ctx.spend.getSigopsCost(ctx.view, flags), 1); + assert.equal( + ctx.spend.getSigopsCost(ctx.view, flags & ~Script.flags.VERIFY_WITNESS), + 0); + } - assert.equal(ctx.spend.getSigopsCost(ctx.view, flags), 0); + { + const output = Script.fromProgram(1, key.getKeyHash()); + const ctx = sigopContext(input, witness, output); - output = Script.fromProgram(0, key.getKeyHash()); - ctx = sigopContext(input, witness, output); + assert.equal(ctx.spend.getSigopsCost(ctx.view, flags), 0); + } - ctx.spend.inputs[0].prevout.hash = encoding.NULL_HASH; - ctx.spend.inputs[0].prevout.index = 0xffffffff; - ctx.spend.refresh(); + { + const output = Script.fromProgram(0, key.getKeyHash()); + const ctx = sigopContext(input, witness, output); - assert.equal(ctx.spend.getSigopsCost(ctx.view, flags), 0); + ctx.spend.inputs[0].prevout.hash = encoding.NULL_HASH; + ctx.spend.inputs[0].prevout.index = 0xffffffff; + ctx.spend.refresh(); + + assert.equal(ctx.spend.getSigopsCost(ctx.view, flags), 0); + } }); it('should count sigops for nested p2wpkh', () => { diff --git a/test/util/common.js b/test/util/common.js index feea5424..6d157584 100644 --- a/test/util/common.js +++ b/test/util/common.js @@ -1,8 +1,11 @@ 'use strict'; +const assert = require('assert'); const fs = require('fs'); const TX = require('../../lib/primitives/tx'); +const Output = require('../../lib/primitives/output'); const CoinView = require('../../lib/coins/coinview'); +const BufferReader = require('../../lib/utils/reader'); exports.parseTX = function parseTX(file) { const data = fs.readFileSync(`${__dirname}/../${file}`, 'utf8'); @@ -25,3 +28,32 @@ exports.parseTX = function parseTX(file) { txs: txs }; }; + +exports.parseUndo = function parseUndo(data) { + const br = new BufferReader(data); + const undo = []; + + while (br.left()) { + const output = Output.fromReader(br); + undo.push(output); + } + + return undo; +}; + +exports.applyUndo = function applyUndo(block, undo) { + const view = new CoinView(); + let i = 0; + + for (const tx of block.txs) { + if (tx.isCoinbase()) + continue; + + for (const {prevout} of tx.inputs) + view.addOutput(prevout, undo[i++]); + } + + assert(i === undo.length, 'Undo coins data inconsistency.'); + + return view; +}; diff --git a/test/util/memwallet.js b/test/util/memwallet.js index a42fd4bd..a8e98b24 100644 --- a/test/util/memwallet.js +++ b/test/util/memwallet.js @@ -226,8 +226,6 @@ MemWallet.prototype.syncKey = function syncKey(path) { }; MemWallet.prototype.addBlock = function addBlock(entry, txs) { - let i, tx; - for (let i = 0; i < txs.length; i++) { const tx = txs[i]; this.addTX(tx, entry.height); diff --git a/test/utils-test.js b/test/utils-test.js index 5d10959e..45871d76 100644 --- a/test/utils-test.js +++ b/test/utils-test.js @@ -5,50 +5,45 @@ const assert = require('assert'); const BN = require('../lib/crypto/bn'); -const secp256k1 = require('../lib/crypto/secp256k1'); const base58 = require('../lib/utils/base58'); const encoding = require('../lib/utils/encoding'); -const digest = require('../lib/crypto/digest'); -const hkdf = require('../lib/crypto/hkdf'); -const schnorr = require('../lib/crypto/schnorr'); const Amount = require('../lib/btc/amount'); const consensus = require('../lib/protocol/consensus'); const Validator = require('../lib/utils/validator'); -describe('Utils', function() { - const vectors = [ - ['', ''], - ['61', '2g'], - ['626262', 'a3gV'], - ['636363', 'aPEr'], - [ - '73696d706c792061206c6f6e6720737472696e67', - '2cFupjhnEsSn59qHXstmK2ffpLv2' - ], - [ - '00eb15231dfceb60925886b67d065299925915aeb172c06647', - '1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L' - ], - ['516b6fcd0f', 'ABnLTmg'], - ['bf4f89001e670274dd', '3SEo3LWLoPntC'], - ['572e4794', '3EFU7m'], - ['ecac89cad93923c02321', 'EJDM8drfXA6uyA'], - ['10c8511e', 'Rt5zm'], - ['00000000000000000000', '1111111111'] - ]; +const base58Tests = [ + ['', ''], + ['61', '2g'], + ['626262', 'a3gV'], + ['636363', 'aPEr'], + [ + '73696d706c792061206c6f6e6720737472696e67', + '2cFupjhnEsSn59qHXstmK2ffpLv2' + ], + [ + '00eb15231dfceb60925886b67d065299925915aeb172c06647', + '1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L' + ], + ['516b6fcd0f', 'ABnLTmg'], + ['bf4f89001e670274dd', '3SEo3LWLoPntC'], + ['572e4794', '3EFU7m'], + ['ecac89cad93923c02321', 'EJDM8drfXA6uyA'], + ['10c8511e', 'Rt5zm'], + ['00000000000000000000', '1111111111'] +]; +describe('Utils', function() { it('should encode/decode base58', () => { const buf = Buffer.from('000000deadbeef', 'hex'); - const b = base58.encode(buf); + const str = base58.encode(buf); - assert.equal(b, '1116h8cQN'); - assert.deepEqual(base58.decode(b), buf); + assert.equal(str, '1116h8cQN'); + assert.deepEqual(base58.decode(str), buf); - for (let i = 0; i < vectors.length; i++) { - const r = Buffer.from(vectors[i][0], 'hex'); - const b = vectors[i][1]; - assert.equal(base58.encode(r), b); - assert.deepEqual(base58.decode(b), r); + for (const [hex, b58] of base58Tests) { + const data = Buffer.from(hex, 'hex'); + assert.equal(base58.encode(data), b58); + assert.deepEqual(base58.decode(b58), data); } }); @@ -200,12 +195,12 @@ describe('Utils', function() { new BN(1).ineg() ]; - unsigned.forEach((num) => { - const buf1 = Buffer.allocUnsafe(8); - const buf2 = Buffer.allocUnsafe(8); + for (const num of unsigned) { const bits = num.bitLength(); it(`should write+read a ${bits} bit unsigned int`, () => { + const buf1 = Buffer.allocUnsafe(8); + const buf2 = Buffer.allocUnsafe(8); encoding.writeU64BN(buf1, num, 0); encoding.writeU64(buf2, num.toNumber(), 0); assert.deepEqual(buf1, buf2); @@ -214,15 +209,15 @@ describe('Utils', function() { const n2 = encoding.readU64(buf2, 0); assert.equal(n1.toNumber(), n2); }); - }); + } - signed.forEach((num) => { - const buf1 = Buffer.allocUnsafe(8); - const buf2 = Buffer.allocUnsafe(8); + for (const num of signed) { const bits = num.bitLength(); const sign = num.isNeg() ? 'negative' : 'positive'; it(`should write+read a ${bits} bit ${sign} int`, () => { + const buf1 = Buffer.allocUnsafe(8); + const buf2 = Buffer.allocUnsafe(8); encoding.write64BN(buf1, num, 0); encoding.write64(buf2, num.toNumber(), 0); assert.deepEqual(buf1, buf2); @@ -233,6 +228,8 @@ describe('Utils', function() { }); it(`should write+read a ${bits} bit ${sign} int as unsigned`, () => { + const buf1 = Buffer.allocUnsafe(8); + const buf2 = Buffer.allocUnsafe(8); encoding.writeU64BN(buf1, num, 0); encoding.writeU64(buf2, num.toNumber(), 0); assert.deepEqual(buf1, buf2); @@ -245,82 +242,7 @@ describe('Utils', function() { assert.equal(n1.toNumber(), n2); } }); - }); - - it('should do proper hkdf', () => { - // https://tools.ietf.org/html/rfc5869 - let alg = 'sha256'; - let ikm = '0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b'; - let salt = '000102030405060708090a0b0c'; - let info = 'f0f1f2f3f4f5f6f7f8f9'; - let len = 42; - - let prkE = '077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec8' - + '44ad7c2b3e5'; - let okmE = '3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1' - + 'a5a4c5db02d56ecc4c5bf34007208d5b887185865'; - - ikm = Buffer.from(ikm, 'hex'); - salt = Buffer.from(salt, 'hex'); - info = Buffer.from(info, 'hex'); - - let prk = hkdf.extract(ikm, salt, alg); - let okm = hkdf.expand(prk, info, len, alg); - - assert.equal(prk.toString('hex'), prkE); - assert.equal(okm.toString('hex'), okmE); - - alg = 'sha256'; - - ikm = '000102030405060708090a0b0c0d0e0f' - + '101112131415161718191a1b1c1d1e1f' - + '202122232425262728292a2b2c2d2e2f' - + '303132333435363738393a3b3c3d3e3f' - + '404142434445464748494a4b4c4d4e4f'; - - salt = '606162636465666768696a6b6c6d6e6f' - + '707172737475767778797a7b7c7d7e7f' - + '808182838485868788898a8b8c8d8e8f' - + '909192939495969798999a9b9c9d9e9f' - + 'a0a1a2a3a4a5a6a7a8a9aaabacadaeaf'; - - info = 'b0b1b2b3b4b5b6b7b8b9babbbcbdbebf' - + 'c0c1c2c3c4c5c6c7c8c9cacbcccdcecf' - + 'd0d1d2d3d4d5d6d7d8d9dadbdcdddedf' - + 'e0e1e2e3e4e5e6e7e8e9eaebecedeeef' - + 'f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff'; - - len = 82; - - prkE = '06a6b88c5853361a06104c9ceb35b45c' - + 'ef760014904671014a193f40c15fc244'; - - okmE = 'b11e398dc80327a1c8e7f78c596a4934' - + '4f012eda2d4efad8a050cc4c19afa97c' - + '59045a99cac7827271cb41c65e590e09' - + 'da3275600c2f09b8367793a9aca3db71' - + 'cc30c58179ec3e87c14c01d5c1f3434f' - + '1d87'; - - ikm = Buffer.from(ikm, 'hex'); - salt = Buffer.from(salt, 'hex'); - info = Buffer.from(info, 'hex'); - - prk = hkdf.extract(ikm, salt, alg); - okm = hkdf.expand(prk, info, len, alg); - - assert.equal(prk.toString('hex'), prkE); - assert.equal(okm.toString('hex'), okmE); - }); - - it('should do proper schnorr', () => { - const key = secp256k1.generatePrivateKey(); - const pub = secp256k1.publicKeyCreate(key, true); - const msg = digest.hash256(Buffer.from('foo', 'ascii')); - const sig = schnorr.sign(msg, key); - assert(schnorr.verify(msg, sig, pub)); - assert.deepEqual(schnorr.recover(sig, msg), pub); - }); + } it('should validate integers 0 and 1 as booleans', () => { const validator = new Validator({shouldBeTrue: 1, shouldBeFalse: 0}); diff --git a/test/wallet-test.js b/test/wallet-test.js index 233aec05..25f3cadc 100644 --- a/test/wallet-test.js +++ b/test/wallet-test.js @@ -25,8 +25,8 @@ const KEY1 = 'xprv9s21ZrQH143K3Aj6xQBymM31Zb4BVc7wxqfUhMZrzewdDVCt' const KEY2 = 'xprv9s21ZrQH143K3mqiSThzPtWAabQ22Pjp3uSNnZ53A5bQ4udp' + 'faKekc2m4AChLYH1XDzANhrSdxHYWUeTWjYJwFwWFyHkTMnMeAcW4JyRCZa'; -let globalHeight = 1; const globalTime = util.now(); +let globalHeight = 1; function nextBlock(height) { if (height == null) @@ -54,15 +54,15 @@ function dummy(hash) { } describe('Wallet', function() { - let wallet, ewallet, ekey; - let doubleSpendWallet, doubleSpend; - const wdb = new WalletDB({ name: 'wallet-test', db: 'memory', verify: true }); + let wallet, ewallet, ekey; + let doubleSpendWallet, doubleSpend; + this.timeout(5000); it('should open walletdb', async () => {