Fix eslint issues.

This commit is contained in:
Nicholas Dudfield
2015-05-20 13:37:11 +07:00
parent 4ecbf31898
commit c8e0fa85f3
9 changed files with 215 additions and 215 deletions

View File

@@ -1,7 +1,7 @@
'use strict';
var assert = require('assert');
var Base = require('ripple-lib').Base;
var fixtures = require('./fixtures/base58.json');
const assert = require('assert');
const Base = require('ripple-lib').Base;
const fixtures = require('./fixtures/base58.json');
function digitArray(str) {
return str.split('').map(function(d) {
@@ -10,8 +10,8 @@ function digitArray(str) {
}
function hexToByteArray(hex) {
var byteArray = [];
for (var i = 0; i < hex.length / 2; i++) {
const byteArray = [];
for (let i = 0; i < hex.length / 2; i++) {
byteArray.push(parseInt(hex.slice(2 * i, 2 * i + 2), 16));
}
return byteArray;
@@ -19,46 +19,46 @@ function hexToByteArray(hex) {
describe('Base', function() {
describe('encode_check', function() {
it('0', function () {
var encoded = Base.encode_check(0, digitArray('00000000000000000000'));
it('0', function() {
const encoded = Base.encode_check(0, digitArray('00000000000000000000'));
assert.strictEqual(encoded, 'rrrrrrrrrrrrrrrrrrrrrhoLvTp');
});
it('1', function () {
var encoded = Base.encode_check(0, digitArray('00000000000000000001'));
it('1', function() {
const encoded = Base.encode_check(0, digitArray('00000000000000000001'));
assert.strictEqual(encoded, 'rrrrrrrrrrrrrrrrrrrrBZbvji');
});
});
describe('decode_check', function() {
it('rrrrrrrrrrrrrrrrrrrrrhoLvTp', function() {
var decoded = Base.decode_check(0, 'rrrrrrrrrrrrrrrrrrrrrhoLvTp');
const decoded = Base.decode_check(0, 'rrrrrrrrrrrrrrrrrrrrrhoLvTp');
assert(decoded.equals(0));
});
it('rrrrrrrrrrrrrrrrrrrrBZbvji', function() {
var decoded = Base.decode_check(0, 'rrrrrrrrrrrrrrrrrrrrBZbvji');
const decoded = Base.decode_check(0, 'rrrrrrrrrrrrrrrrrrrrBZbvji');
assert(decoded.equals(1));
});
});
describe('decode-encode identity', function() {
it('rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', function() {
var decoded = Base.decode('rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
var encoded = Base.encode(decoded);
const decoded = Base.decode('rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
const encoded = Base.encode(decoded);
assert.strictEqual(encoded, 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
});
});
describe('encode', function() {
it('fixtures', function() {
for (var i = 0; i < fixtures.ripple.length; i++) {
var testCase = fixtures.ripple[i];
var encoded = Base.encode(hexToByteArray(testCase.hex));
for (let i = 0; i < fixtures.ripple.length; i++) {
const testCase = fixtures.ripple[i];
const encoded = Base.encode(hexToByteArray(testCase.hex));
assert.strictEqual(encoded, testCase.string);
}
});
});
describe('decode', function() {
it('fixtures', function() {
for (var i = 0; i < fixtures.ripple.length; i++) {
var testCase = fixtures.ripple[i];
var decoded = Base.decode(testCase.string);
for (let i = 0; i < fixtures.ripple.length; i++) {
const testCase = fixtures.ripple[i];
const decoded = Base.decode(testCase.string);
assert.deepEqual(decoded, hexToByteArray(testCase.hex));
}
});

View File

@@ -1,10 +1,10 @@
/* eslint-disable max-len */
'use strict';
var assert = require('assert');
var sjcl = require('ripple-lib').sjcl;
var Message = require('ripple-lib').Message;
var Seed = require('ripple-lib').Seed;
var Remote = require('ripple-lib').Remote;
const assert = require('assert');
const sjcl = require('ripple-lib').sjcl;
const Message = require('ripple-lib').Message;
const Seed = require('ripple-lib').Seed;
const Remote = require('ripple-lib').Remote;
describe('Message', function() {
@@ -12,11 +12,11 @@ describe('Message', function() {
it('should prepend the MAGIC_BYTES, call the hashFunction, and then call signHash', function() {
var normal_signHash = Message.signHash;
const normal_signHash = Message.signHash;
var message_text = 'Hello World!';
const message_text = 'Hello World!';
var signHash_called = false;
let signHash_called = false;
Message.signHash = function(hash) {
signHash_called = true;
assert.deepEqual(hash, Message.hashFunction(Message.MAGIC_BYTES + message_text));
@@ -35,22 +35,22 @@ describe('Message', function() {
it('should accept the hash as either a hex string or a bitArray', function() {
var normal_random = sjcl.random.randomWords;
const normal_random = sjcl.random.randomWords;
sjcl.random.randomWords = function(num_words) {
var words = [];
for (var w = 0; w < num_words; w++) {
const words = [];
for (let w = 0; w < num_words; w++) {
words.push(sjcl.codec.hex.toBits('00000000'));
}
return words;
};
var secret_string = 'safRpB5euNL52PZPTSqrE9gvuFwTC';
// var address = 'rLLzaq61D633b5hhbNXKM9CkrYHboobVv3';
var hash = 'e865bcc63a86ef21585ac8340a7cc8590ed85175a2a718c6fb2bfb2715d13778';
const secret_string = 'safRpB5euNL52PZPTSqrE9gvuFwTC';
// const address = 'rLLzaq61D633b5hhbNXKM9CkrYHboobVv3';
const hash = 'e865bcc63a86ef21585ac8340a7cc8590ed85175a2a718c6fb2bfb2715d13778';
var signature1 = Message.signHash(hash, secret_string);
var signature2 = Message.signHash(sjcl.codec.hex.toBits(hash), secret_string);
const signature1 = Message.signHash(hash, secret_string);
const signature2 = Message.signHash(sjcl.codec.hex.toBits(hash), secret_string);
assert.strictEqual(signature1, signature2);
@@ -60,22 +60,22 @@ describe('Message', function() {
it('should accept the secret as a string or scjl.ecc.ecdsa.secretKey object', function() {
var normal_random = sjcl.random.randomWords;
const normal_random = sjcl.random.randomWords;
sjcl.random.randomWords = function(num_words) {
var words = [];
for (var w = 0; w < num_words; w++) {
const words = [];
for (let w = 0; w < num_words; w++) {
words.push(sjcl.codec.hex.toBits('00000000'));
}
return words;
};
var secret_string = 'safRpB5euNL52PZPTSqrE9gvuFwTC';
// var address = 'rLLzaq61D633b5hhbNXKM9CkrYHboobVv3';
var hash = 'e865bcc63a86ef21585ac8340a7cc8590ed85175a2a718c6fb2bfb2715d13778';
const secret_string = 'safRpB5euNL52PZPTSqrE9gvuFwTC';
// const address = 'rLLzaq61D633b5hhbNXKM9CkrYHboobVv3';
const hash = 'e865bcc63a86ef21585ac8340a7cc8590ed85175a2a718c6fb2bfb2715d13778';
var signature1 = Message.signHash(hash, secret_string);
var signature2 = Message.signHash(hash, Seed.from_json(secret_string).get_key()._secret);
const signature1 = Message.signHash(hash, secret_string);
const signature2 = Message.signHash(hash, Seed.from_json(secret_string).get_key()._secret);
assert.strictEqual(signature1, signature2);
@@ -94,8 +94,8 @@ describe('Message', function() {
// The rest will be assumed to be a passphrase.
// This is a bad b58 seed
var secret_string = 'sbadsafRpB5euNL52PZPTSqrE9gvuFwTC';
var hash = 'e865bcc63a86ef21585ac8340a7cc8590ed85175a2a718c6fb2bfb2715d13778';
const secret_string = 'sbadsafRpB5euNL52PZPTSqrE9gvuFwTC';
const hash = 'e865bcc63a86ef21585ac8340a7cc8590ed85175a2a718c6fb2bfb2715d13778';
assert.throws(function() {
Message.signHash(hash, secret_string);
@@ -105,8 +105,8 @@ describe('Message', function() {
it('should throw an error if the parameters are reversed', function() {
var secret_string = 'safRpB5euNL52PZPTSqrE9gvuFwTC';
var hash = 'e865bcc63a86ef21585ac8340a7cc8590ed85175a2a718c6fb2bfb2715d13778';
const secret_string = 'safRpB5euNL52PZPTSqrE9gvuFwTC';
const hash = 'e865bcc63a86ef21585ac8340a7cc8590ed85175a2a718c6fb2bfb2715d13778';
assert.throws(function() {
Message.signHash(secret_string, hash);
@@ -127,23 +127,23 @@ describe('Message', function() {
});
it('should produce a base64-encoded signature', function() {
var REGEX_BASE64 = /^([A-Za-z0-9\+]{4})*([A-Za-z0-9\+]{2}==)|([A-Za-z0-9\+]{3}=)?$/;
const REGEX_BASE64 = /^([A-Za-z0-9\+]{4})*([A-Za-z0-9\+]{2}==)|([A-Za-z0-9\+]{3}=)?$/;
var normal_random = sjcl.random.randomWords;
const normal_random = sjcl.random.randomWords;
sjcl.random.randomWords = function(num_words) {
var words = [];
for (var w = 0; w < num_words; w++) {
const words = [];
for (let w = 0; w < num_words; w++) {
words.push(sjcl.codec.hex.toBits('00000000'));
}
return words;
};
var secret_string = 'safRpB5euNL52PZPTSqrE9gvuFwTC';
// var address = 'rLLzaq61D633b5hhbNXKM9CkrYHboobVv3';
var hash = 'e865bcc63a86ef21585ac8340a7cc8590ed85175a2a718c6fb2bfb2715d13778';
const secret_string = 'safRpB5euNL52PZPTSqrE9gvuFwTC';
// const address = 'rLLzaq61D633b5hhbNXKM9CkrYHboobVv3';
const hash = 'e865bcc63a86ef21585ac8340a7cc8590ed85175a2a718c6fb2bfb2715d13778';
var signature = Message.signHash(hash, secret_string);
const signature = Message.signHash(hash, secret_string);
assert(REGEX_BASE64.test(signature));
@@ -156,14 +156,14 @@ describe('Message', function() {
it('should prepend the MAGIC_BYTES, call the hashFunction, and then call verifyHashSignature', function() {
var normal_verifyHashSignature = Message.verifyHashSignature;
const normal_verifyHashSignature = Message.verifyHashSignature;
var data = {
const data = {
message: 'Hello world!',
signature: 'AAAAGzFa1pYjhssCpDFZgFSnYQ8qCnMkLaZrg0mXZyNQ2NxgMQ8z9U3ngYerxSZCEt3Q4raMIpt03db7jDNGbfmHy8I='
};
var verifyHashSignature_called = false;
let verifyHashSignature_called = false;
Message.verifyHashSignature = function(vhs_data, remote, callback) {
verifyHashSignature_called = true;
@@ -188,7 +188,7 @@ describe('Message', function() {
it('should throw an error if a callback function is not supplied', function() {
var data = {
const data = {
message: 'Hello world!',
hash: '861844d6704e8573fec34d967e20bcfef3d424cf48be04e6dc08f2bd58c729743371015ead891cc3cf1c9d34b49264b510751b1ff9e537937bc46b5d6ff4ecc8',
signature: 'AAAAHOUJQzG/7BO82fGNt1TNE+GGVXKuQQ0N2nTO+iJETE69PiHnaAkkOzovM177OosxbKjpt3KvwuJflgUB2YGvgjk=',
@@ -202,13 +202,13 @@ describe('Message', function() {
it('should respond with an error if the hash is missing or invalid', function(done) {
var data = {
const data = {
message: 'Hello world!',
signature: 'AAAAHOUJQzG/7BO82fGNt1TNE+GGVXKuQQ0N2nTO+iJETE69PiHnaAkkOzovM177OosxbKjpt3KvwuJflgUB2YGvgjk=',
account: 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz'
};
var test_remote = new Remote();
const test_remote = new Remote();
test_remote.state = 'online';
Message.verifyHashSignature(data, test_remote, function(err) {
@@ -220,13 +220,13 @@ describe('Message', function() {
it('should respond with an error if the account is missing or invalid', function(done) {
var data = {
const data = {
message: 'Hello world!',
hash: '861844d6704e8573fec34d967e20bcfef3d424cf48be04e6dc08f2bd58c729743371015ead891cc3cf1c9d34b49264b510751b1ff9e537937bc46b5d6ff4ecc8',
signature: 'AAAAHOUJQzG/7BO82fGNt1TNE+GGVXKuQQ0N2nTO+iJETE69PiHnaAkkOzovM177OosxbKjpt3KvwuJflgUB2YGvgjk='
};
var test_remote = new Remote();
const test_remote = new Remote();
test_remote.state = 'online';
Message.verifyHashSignature(data, test_remote, function(err) {
@@ -238,13 +238,13 @@ describe('Message', function() {
it('should respond with an error if the signature is missing or invalid', function(done) {
var data = {
const data = {
message: 'Hello world!',
hash: '861844d6704e8573fec34d967e20bcfef3d424cf48be04e6dc08f2bd58c729743371015ead891cc3cf1c9d34b49264b510751b1ff9e537937bc46b5d6ff4ecc8',
account: 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz'
};
var test_remote = new Remote();
const test_remote = new Remote();
test_remote.state = 'online';
Message.verifyHashSignature(data, test_remote, function(err) {
@@ -256,17 +256,17 @@ describe('Message', function() {
it('should respond true if the signature is valid and corresponds to an active public key for the account', function(done) {
var data = {
const data = {
message: 'Hello world!',
hash: 'e9a82ea40514787918959b1100481500a5d384030f8770575c6a587675025fe212e6623e25643f251666a7b8b23af476c2850a8ea92153de5724db432892c752',
account: 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz',
signature: 'AAAAHMIPCQGLgdnpX1Ccv1wHb56H4NggxIM6U08Qkb9mUjN2Vn9pZ3CHvq1yWLBi6NqpW+7kedLnmfu4VG2+y43p4Xs='
};
var test_remote = new Remote();
const test_remote = new Remote();
test_remote.state = 'online';
test_remote.requestAccountInfo = function(options, callback) {
var account = options.account;
const account = options.account;
if (account === data.account) {
callback(null, {
'account_data': {
@@ -292,17 +292,17 @@ describe('Message', function() {
it('should respond false if a key can be recovered from the signature but it does not correspond to an active public key', function(done) {
// Signature created by disabled master key
var data = {
const data = {
message: 'Hello world!',
hash: 'e9a82ea40514787918959b1100481500a5d384030f8770575c6a587675025fe212e6623e25643f251666a7b8b23af476c2850a8ea92153de5724db432892c752',
account: 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz',
signature: 'AAAAG+dB/rAjZ5m8eQ/opcqQOJsFbKxOu9jq9KrOAlNO4OdcBDXyCBlkZqS9Xr8oZI2uh0boVsgYOS3pOLJz+Dh3Otk='
};
var test_remote = new Remote();
const test_remote = new Remote();
test_remote.state = 'online';
test_remote.requestAccountInfo = function(options, callback) {
var account = options.account;
const account = options.account;
if (account === data.account) {
callback(null, {
'account_data': {

View File

@@ -1,26 +1,26 @@
/* eslint max-len: 0 */
'use strict';
var assert = require('assert');
var Seed = require('ripple-lib').Seed;
const assert = require('assert');
const Seed = require('ripple-lib').Seed;
function assert_helper(seed_json, address_or_nth, expected) {
var seed = Seed.from_json(seed_json);
var keypair = seed.get_key(address_or_nth, 500);
const seed = Seed.from_json(seed_json);
const keypair = seed.get_key(address_or_nth, 500);
assert.strictEqual(keypair.to_hex_pub(), expected);
}
describe('Seed', function() {
it('saESc82Vun7Ta5EJRzGJbrXb5HNYk', function () {
var seed = Seed.from_json('saESc82Vun7Ta5EJRzGJbrXb5HNYk');
it('saESc82Vun7Ta5EJRzGJbrXb5HNYk', function() {
const seed = Seed.from_json('saESc82Vun7Ta5EJRzGJbrXb5HNYk');
assert.strictEqual(seed.to_hex(), 'FF1CF838D02B2CF7B45BAC27F5F24F4F');
});
it('sp6iDHnmiPN7tQFHm5sCW59ax3hfE', function () {
var seed = Seed.from_json('sp6iDHnmiPN7tQFHm5sCW59ax3hfE');
it('sp6iDHnmiPN7tQFHm5sCW59ax3hfE', function() {
const seed = Seed.from_json('sp6iDHnmiPN7tQFHm5sCW59ax3hfE');
assert.strictEqual(seed.to_hex(), '00AD8DA764C3C8AF5F9B8D51C94B9E49');
});
it('can generate many addresses', function () {
it('can generate many addresses', function() {
var test_data = [
const test_data = [
// Format:
// [passphrase, address, nth-for-seed, expected-public-key]
['masterpassphrase', 'rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh', 0,
@@ -39,11 +39,11 @@ describe('Seed', function() {
'023A2876EA130CBE7BBA0573C2DB4C4CEB9A7547666915BD40366CDC6150CF54DC']
];
for (var nth = 0; nth < test_data.length; nth++) {
var seed_json = test_data[nth][0];
var address = test_data[nth][1];
var nth_for_seed = test_data[nth][2];
var expected = test_data[nth][3];
for (let nth = 0; nth < test_data.length; nth++) {
const seed_json = test_data[nth][0];
const address = test_data[nth][1];
const nth_for_seed = test_data[nth][2];
const expected = test_data[nth][3];
// `seed.get_key($ripple_address)` is arguably an ill concieved feature
// as it needs to generate `nth` many keypairs and generate hashed public
@@ -58,17 +58,17 @@ describe('Seed', function() {
});
it('should return the key_pair for a valid account and secret pair', function() {
var address = 'r3GgMwvgvP8h4yVWvjH1dPZNvC37TjzBBE';
var seed = Seed.from_json('shsWGZcmZz6YsWWmcnpfr6fLTdtFV');
var keyPair = seed.get_key(address);
const address = 'r3GgMwvgvP8h4yVWvjH1dPZNvC37TjzBBE';
const seed = Seed.from_json('shsWGZcmZz6YsWWmcnpfr6fLTdtFV');
const keyPair = seed.get_key(address);
assert.strictEqual(keyPair.get_address().to_json(), address);
assert.strictEqual(keyPair.to_hex_pub(), '02F89EAEC7667B30F33D0687BBA86C3FE2A08CCA40A9186C5BDE2DAA6FA97A37D8');
});
it('should not find a KeyPair for a secret that does not belong to the given account', function() {
var address = 'r3GgMwvgvP8h4yVWvjH1dPZNvC37TjzBBE';
var secret = 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb';
var seed = Seed.from_json('snoPBrXtMeMyMHUVTgbuqAfg1SUTb');
const address = 'r3GgMwvgvP8h4yVWvjH1dPZNvC37TjzBBE';
const secret = 'snoPBrXtMeMyMHUVTgbuqAfg1SUTb';
const seed = Seed.from_json('snoPBrXtMeMyMHUVTgbuqAfg1SUTb');
try {
seed.get_key(address);
assert(false, 'should throw an error');

View File

@@ -1,5 +1,7 @@
var assert = require('assert');
var Seed = require('ripple-lib').Seed;
'use strict';
const assert = require('assert');
const Seed = require('ripple-lib').Seed;
function _isNaN(n) {
return typeof n === 'number' && isNaN(n);
@@ -7,17 +9,21 @@ function _isNaN(n) {
describe('Signing', function() {
describe('Keys', function() {
it('SigningPubKey 1 (ripple-client issue #245)', function () {
var seed = Seed.from_json('saESc82Vun7Ta5EJRzGJbrXb5HNYk');
var key = seed.get_key('rBZ4j6MsoctipM6GEyHSjQKzXG3yambDnZ');
var pub = key.to_hex_pub();
assert.strictEqual(pub, '0396941B22791A448E5877A44CE98434DB217D6FB97D63F0DAD23BE49ED45173C9');
it('SigningPubKey 1 (ripple-client issue #245)', function() {
const seed = Seed.from_json('saESc82Vun7Ta5EJRzGJbrXb5HNYk');
const key = seed.get_key('rBZ4j6MsoctipM6GEyHSjQKzXG3yambDnZ');
const pub = key.to_hex_pub();
assert.strictEqual(
pub,
'0396941B22791A448E5877A44CE98434DB217D6FB97D63F0DAD23BE49ED45173C9');
});
it('SigningPubKey 2 (master seed)', function () {
var seed = Seed.from_json('snoPBrXtMeMyMHUVTgbuqAfg1SUTb');
var key = seed.get_key('rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
var pub = key.to_hex_pub();
assert.strictEqual(pub, '0330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD020');
it('SigningPubKey 2 (master seed)', function() {
const seed = Seed.from_json('snoPBrXtMeMyMHUVTgbuqAfg1SUTb');
const key = seed.get_key('rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
const pub = key.to_hex_pub();
assert.strictEqual(
pub,
'0330E7FC9D56BB25D6893BA3F317AE5BCF33B3291BD63DB32654A313222F7FD020');
});
});
describe('parse_json', function() {
@@ -26,12 +32,14 @@ describe('Signing', function() {
});
it('hex string', function() {
// 32 0s is a valid hex repr of seed bytes
var str = new Array(33).join('0');
assert.strictEqual((new Seed().parse_json(str).to_json()), 'sp6JS7f14BuwFY8Mw6bTtLKWauoUs');
const str = new Array(33).join('0');
assert.strictEqual((new Seed().parse_json(str).to_json()),
'sp6JS7f14BuwFY8Mw6bTtLKWauoUs');
});
it('passphrase', function() {
var str = new Array(60).join('0');
assert.strictEqual('snFRPnVL3secohdpwSie8ANXdFQvG', new Seed().parse_json(str).to_json());
const str = new Array(60).join('0');
assert.strictEqual('snFRPnVL3secohdpwSie8ANXdFQvG',
new Seed().parse_json(str).to_json());
});
it('null', function() {
assert(_isNaN(new Seed().parse_json(null).to_json()));
@@ -52,5 +60,3 @@ describe('Signing', function() {
});
});
});
// vim:sw=2:sts=2:ts=8:et