diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 20e33ec670..96c1721e96 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -41,6 +41,18 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/extend/-/extend-1.2.1.tgz" }, + "hash.js": { + "version": "1.0.3", + "from": "hash.js@*", + "resolved": "https://registry.npmjs.org/hash.js/-/hash.js-1.0.3.tgz", + "dependencies": { + "inherits": { + "version": "2.0.1", + "from": "inherits@>=2.0.1 <3.0.0", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.1.tgz" + } + } + }, "https-proxy-agent": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-1.0.0.tgz", @@ -138,8 +150,8 @@ } }, "ripple-keypairs": { - "version": "0.7.3", - "from": "ripple-keypairs@>=0.7.3 <0.8.0", + "version": "0.8.0", + "from": "ripple-keypairs@>=0.8.0 <0.9.0", "dependencies": { "bn.js": { "version": "3.1.1", @@ -187,19 +199,9 @@ } } }, - "ripple-wallet-generator": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/ripple-wallet-generator/-/ripple-wallet-generator-1.0.3.tgz" - }, - "sjcl-extended": { - "version": "1.0.3", - "resolved": "git://github.com/ripple/sjcl-extended.git#d8cf8b22e7d97193c54e1f65113e3edcf200ca17", - "dependencies": { - "sjcl": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/sjcl/-/sjcl-1.0.3.tgz" - } - } + "sjcl-codec": { + "version": "0.1.0", + "from": "sjcl-codec@*" }, "ws": { "version": "0.7.2", diff --git a/package.json b/package.json index 78a29dfe8f..9fd0286201 100644 --- a/package.json +++ b/package.json @@ -21,15 +21,15 @@ "bn.js": "^3.1.1", "es6-promisify": "^2.0.0", "extend": "~1.2.1", + "hash.js": "^1.0.3", "https-proxy-agent": "^1.0.0", "is-my-json-valid": "^2.12.0", "lodash": "^3.1.0", "lru-cache": "~2.5.0", "ripple-address-codec": "^1.6.0", - "ripple-keypairs": "^0.7.3", + "ripple-keypairs": "^0.8.0", "ripple-lib-transactionparser": "^0.5.0", - "ripple-wallet-generator": "^1.0.3", - "sjcl-extended": "ripple/sjcl-extended#1.0.3", + "sjcl-codec": "0.1.0", "ws": "~0.7.1" }, "devDependencies": { diff --git a/src/api/common/index.js b/src/api/common/index.js index 2ae6c4129e..676cd6a0ab 100644 --- a/src/api/common/index.js +++ b/src/api/common/index.js @@ -9,6 +9,7 @@ module.exports = { dropsToXrp: utils.dropsToXrp, xrpToDrops: utils.xrpToDrops, toRippledAmount: utils.toRippledAmount, + generateWallet: utils.generateWallet, composeAsync: utils.composeAsync, wrapCatch: utils.wrapCatch, convertExceptions: utils.convertExceptions, diff --git a/src/api/common/utils.js b/src/api/common/utils.js index 7df942624b..d565f6331e 100644 --- a/src/api/common/utils.js +++ b/src/api/common/utils.js @@ -5,6 +5,7 @@ const BigNumber = require('bignumber.js'); const core = require('../../core'); const errors = require('./errors'); const es6promisify = require('es6-promisify'); +const keypairs = require('ripple-keypairs'); type Amount = {currency: string, issuer: string, value: string} @@ -27,6 +28,11 @@ function toRippledAmount(amount: Amount): string|Amount { }; } +function generateWallet(options?: Object): Object { + const {accountID, seed} = keypairs.generateWallet(options); + return {secret: seed, address: accountID}; +} + type AsyncFunction = (...x: any) => void function wrapCatch(asyncFunction: AsyncFunction): AsyncFunction { @@ -95,6 +101,7 @@ module.exports = { dropsToXrp, xrpToDrops, toRippledAmount, + generateWallet, composeAsync, wrapCatch, convertExceptions, diff --git a/src/api/index.js b/src/api/index.js index 4f4e99bad8..89c4dcdcb0 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -28,7 +28,7 @@ const sign = require('./transaction/sign'); const submit = require('./transaction/submit'); const errors = require('./common').errors; const convertExceptions = require('./common').convertExceptions; -const generateWallet = convertExceptions(common.core.Wallet.generate); +const generateWallet = convertExceptions(common.generateWallet); const getLedgerHeader = require('./ledger/ledger-header'); function RippleAPI(options: {}) { diff --git a/src/core/account.js b/src/core/account.js index 3f262bcb6f..e4133d92b3 100644 --- a/src/core/account.js +++ b/src/core/account.js @@ -12,13 +12,14 @@ const _ = require('lodash'); const async = require('async'); -const util = require('util'); const extend = require('extend'); -const EventEmitter = require('events').EventEmitter; -const UInt160 = require('./uint160').UInt160; -const TransactionManager = require('./transactionmanager').TransactionManager; -const sjcl = require('./utils').sjcl; -const Base = require('./base').Base; +const util = require('util'); +const {createAccountID} = require('ripple-keypairs'); +const {encodeAccountID} = require('ripple-address-codec'); +const {EventEmitter} = require('events'); +const {hexToArray} = require('./utils'); +const {TransactionManager} = require('./transactionmanager'); +const {UInt160} = require('./uint160'); /** * @constructor Account @@ -41,7 +42,7 @@ function Account(remote, account) { this._entry = { }; function listenerAdded(type) { - if (~Account.subscribeEvents.indexOf(type)) { + if (_.includes(Account.subscribeEvents, type)) { if (!self._subs && self._remote._connected) { self._remote.requestSubscribe() .addAccount(self._account_id) @@ -54,7 +55,7 @@ function Account(remote, account) { this.on('newListener', listenerAdded); function listenerRemoved(type) { - if (~Account.subscribeEvents.indexOf(type)) { + if (_.includes(Account.subscribeEvents, type)) { self._subs -= 1; if (!self._subs && self._remote._connected) { self._remote.requestUnsubscribe() @@ -376,12 +377,7 @@ Account.prototype.publicKeyIsActive = function(public_key, callback) { Account._publicKeyToAddress = function(public_key) { // Based on functions in /src/js/ripple/keypair.js function hexToUInt160(publicKey) { - const bits = sjcl.codec.hex.toBits(publicKey); - const hash = sjcl.hash.ripemd160.hash(sjcl.hash.sha256.hash(bits)); - const address = UInt160.from_bits(hash); - address.set_version(Base.VER_ACCOUNT_ID); - - return address.to_json(); + return encodeAccountID(createAccountID(hexToArray(publicKey))); } if (UInt160.is_valid(public_key)) { diff --git a/src/core/index.js b/src/core/index.js index 3a83379954..a27c94de9a 100644 --- a/src/core/index.js +++ b/src/core/index.js @@ -27,13 +27,4 @@ exports._test = { RangeSet: require('./rangeset').RangeSet }; -// Important: We do not guarantee any specific version of SJCL or for any -// specific features to be included. The version and configuration may change at -// any time without warning. -// -// However, for programs that are tied to a specific version of ripple.js like -// the official client, it makes sense to expose the SJCL instance so we don't -// have to include it twice. -exports.sjcl = require('./utils').sjcl; -exports.Wallet = require('ripple-wallet-generator')({sjcl: exports.sjcl}); exports.types = require('./serializedtypes'); diff --git a/src/core/seed.js b/src/core/seed.js index d6f0141452..2e0f011572 100644 --- a/src/core/seed.js +++ b/src/core/seed.js @@ -5,16 +5,15 @@ // const {KeyPair, KeyType} = require('ripple-keypairs'); -const codec = require('ripple-address-codec'); +const {decodeSeed, encodeSeed} = require('ripple-address-codec'); const extend = require('extend'); +const sjclcodec = require('sjcl-codec'); const BN = require('bn.js'); -const utils = require('./utils'); +const hashjs = require('hash.js'); -const sjcl = utils.sjcl; const UInt = require('./uint').UInt; const Seed = extend(function() { - this._curve = sjcl.ecc.curves.k256; this._value = NaN; this._type = KeyType.secp256k1; }, UInt); @@ -54,7 +53,7 @@ Seed.prototype.parse_base58 = function(j) { this._value = NaN; } else { try { - const {bytes, type} = codec.decodeSeed(j); + const {bytes, type} = decodeSeed(j); this._value = new BN(bytes); this._type = type; } catch (e) { @@ -74,10 +73,9 @@ Seed.prototype.parse_passphrase = function(j) { throw new Error('Passphrase must be a string'); } - const hash = sjcl.hash.sha512.hash(sjcl.codec.utf8String.toBits(j)); - const bits = sjcl.bitArray.bitSlice(hash, 0, 128); - - this.parse_bits(bits); + const phraseBytes = sjclcodec.bytes.fromBits(sjclcodec.utf8String.toBits(j)); + const hash = hashjs.sha512().update(phraseBytes).digest(); + this.parse_bytes(hash.slice(0, 16)); return this; }; @@ -86,7 +84,7 @@ Seed.prototype.to_json = function() { if (!(this.is_valid())) { return NaN; } - return codec.encodeSeed(this.to_bytes(), this._type); + return encodeSeed(this.to_bytes(), this._type); }; Seed.prototype.get_key = function() { diff --git a/src/core/serializedobject.js b/src/core/serializedobject.js index f68cd11186..fc06cf967a 100644 --- a/src/core/serializedobject.js +++ b/src/core/serializedobject.js @@ -3,13 +3,13 @@ const assert = require('assert'); const extend = require('extend'); const BN = require('bn.js'); +const hashjs = require('hash.js'); +const sjclcodec = require('sjcl-codec'); const binformat = require('./binformat'); const stypes = require('./serializedtypes'); const utils = require('./utils'); const UInt256 = require('./uint256').UInt256; -const sjcl = utils.sjcl; - const TRANSACTION_TYPES = { }; Object.keys(binformat.tx).forEach(function(key) { @@ -37,7 +37,7 @@ function SerializedObject(buf) { if (Array.isArray(buf) || (Buffer && Buffer.isBuffer(buf))) { this.buffer = buf; } else if (typeof buf === 'string') { - this.buffer = sjcl.codec.bytes.fromBits(sjcl.codec.hex.toBits(buf)); + this.buffer = sjclcodec.bytes.fromBits(sjclcodec.hex.toBits(buf)); } else if (!buf) { this.buffer = []; } else { @@ -201,11 +201,11 @@ SerializedObject.prototype.read = readOrPeek(true); SerializedObject.prototype.peek = readOrPeek(false); SerializedObject.prototype.to_bits = function() { - return sjcl.codec.bytes.toBits(this.buffer); + return sjclcodec.bytes.toBits(this.buffer); }; SerializedObject.prototype.to_hex = function() { - return sjcl.codec.hex.fromBits(this.to_bits()).toUpperCase(); + return sjclcodec.hex.fromBits(this.to_bits()).toUpperCase(); }; SerializedObject.prototype.to_json = function() { @@ -302,11 +302,9 @@ SerializedObject.prototype.hash = function(prefix) { // Copy buffer to temporary buffer sign_buffer.append(this.buffer); + const bytes = hashjs.sha512().update(sign_buffer.buffer).digest(); - const bits = sjcl.codec.bytes.toBits(sign_buffer.buffer); - const sha512hex = sjcl.codec.hex.fromBits(sjcl.hash.sha512.hash(bits)); - - return UInt256.from_hex(sha512hex.substr(0, 64).toUpperCase()); + return UInt256.from_bytes(bytes.slice(0, 32)); }; // DEPRECATED diff --git a/src/core/serializedtypes.js b/src/core/serializedtypes.js index ed01d0e832..1d74e5e206 100644 --- a/src/core/serializedtypes.js +++ b/src/core/serializedtypes.js @@ -12,11 +12,11 @@ const assert = require('assert'); const extend = require('extend'); const BN = require('bn.js'); const GlobalBigNumber = require('bignumber.js'); +const sjclcodec = require('sjcl-codec'); const Amount = require('./amount').Amount; const Currency = require('./currency').Currency; const binformat = require('./binformat'); const utils = require('./utils'); -const sjcl = utils.sjcl; const UInt128 = require('./uint128').UInt128; const UInt160 = require('./uint160').UInt160; @@ -56,8 +56,8 @@ function serializeHex(so, hexData, noLength) { } function convertHexToString(hexString) { - const bits = sjcl.codec.hex.toBits(hexString); - return sjcl.codec.utf8String.fromBits(bits); + const bits = sjclcodec.hex.toBits(hexString); + return sjclcodec.utf8String.fromBits(bits); } function sort_fields(keys) { @@ -432,7 +432,7 @@ exports.Quality = new SerializedType({ lo = parseInt(mantissaHex.slice(-8), 16); } - const valueBytes = sjcl.codec.bytes.fromBits([hi, lo]); + const valueBytes = sjclcodec.bytes.fromBits([hi, lo]); so.append(valueBytes); } @@ -472,7 +472,7 @@ const STAmount = exports.Amount = new SerializedType({ valueHex = '0' + valueHex; } - valueBytes = sjcl.codec.bytes.fromBits(sjcl.codec.hex.toBits(valueHex)); + valueBytes = sjclcodec.bytes.fromBits(sjclcodec.hex.toBits(valueHex)); // Clear most significant two bits - these bits should already be 0 if // Amount enforces the range correctly, but we'll clear them anyway just // so this code can make certain guarantees about the encoded value. @@ -506,7 +506,7 @@ const STAmount = exports.Amount = new SerializedType({ lo = parseInt(mantissaHex.slice(-8), 16); } - valueBytes = sjcl.codec.bytes.fromBits([hi, lo]); + valueBytes = sjclcodec.bytes.fromBits([hi, lo]); } so.append(valueBytes); diff --git a/src/core/transaction.js b/src/core/transaction.js index 23176acb9b..d99c3b4239 100644 --- a/src/core/transaction.js +++ b/src/core/transaction.js @@ -4,7 +4,7 @@ const util = require('util'); const lodash = require('lodash'); const EventEmitter = require('events').EventEmitter; const utils = require('./utils'); -const sjcl = require('./utils').sjcl; +const sjclcodec = require('sjcl-codec'); const Amount = require('./amount').Amount; const Currency = require('./amount').Currency; const UInt160 = require('./amount').UInt160; @@ -779,8 +779,8 @@ Transaction.prototype.addMemo = function(options_) { } function convertStringToHex(string) { - const utf8String = sjcl.codec.utf8String.toBits(string); - return sjcl.codec.hex.fromBits(utf8String).toUpperCase(); + const utf8String = sjclcodec.utf8String.toBits(string); + return sjclcodec.hex.fromBits(utf8String).toUpperCase(); } const memo = {}; diff --git a/src/core/uint.js b/src/core/uint.js index ebddd5d6dc..542312027e 100644 --- a/src/core/uint.js +++ b/src/core/uint.js @@ -4,11 +4,10 @@ const assert = require('assert'); const lodash = require('lodash'); +const sjclcodec = require('sjcl-codec'); const utils = require('./utils'); const BN = require('bn.js'); -const sjcl = utils.sjcl; - // // Abstract UInt class // @@ -217,16 +216,7 @@ UInt.prototype.parse_hex = function(j) { }; UInt.prototype.parse_bits = function(j) { - if (sjcl.bitArray.bitLength(j) === this.constructor.width * 8) { - const bytes = sjcl.codec.bytes.fromBits(j); - this.parse_bytes(bytes); - } else { - this._value = NaN; - } - - this._update(); - - return this; + return this.parse_bytes(sjclcodec.bytes.fromBits(j)); }; UInt.prototype.parse_bytes = function(j) { @@ -280,7 +270,7 @@ UInt.prototype.to_bits = function() { return null; } - return sjcl.codec.bytes.toBits(this.to_bytes()); + return sjclcodec.bytes.toBits(this.to_bytes()); }; exports.UInt = UInt; diff --git a/src/core/utils.js b/src/core/utils.js index a9441a0b93..a1ebd8cb15 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -166,6 +166,4 @@ exports.fromTimestamp = fromTimestamp; exports.getMantissaDecimalString = getMantissaDecimalString; exports.getMantissa16FromString = getMantissa16FromString; -exports.sjcl = require('sjcl-extended'); - // vim:sw=2:sts=2:ts=8:et diff --git a/test/api-test.js b/test/api-test.js index ced042bd4e..1e1a945ed6 100644 --- a/test/api-test.js +++ b/test/api-test.js @@ -11,8 +11,6 @@ const requests = fixtures.requests; const responses = fixtures.responses; const addresses = require('./fixtures/addresses'); const hashes = require('./fixtures/hashes'); -const MockPRNG = require('./mock-prng'); -const sjcl = common.core.sjcl; const address = addresses.ACCOUNT; const validate = common.validate; const utils = RippleAPI._PRIVATE.ledgerUtils; @@ -38,13 +36,6 @@ function checkResult(expected, schemaName, response) { } } -function withDeterministicPRNG(f) { - const prng = sjcl.random; - sjcl.random = new MockPRNG(); - f(); - sjcl.random = prng; -} - describe('RippleAPI', function() { const instructions = {maxLedgerVersionOffset: 100}; beforeEach(setupAPI.setup); @@ -413,9 +404,11 @@ describe('RippleAPI', function() { }); it('generateWallet', function() { - withDeterministicPRNG(() => { - assert.deepEqual(this.api.generateWallet(), responses.generateWallet); - }); + function random() { + return _.fill(Array(16), 0); + } + assert.deepEqual(this.api.generateWallet({random}), + responses.generateWallet); }); it('getSettings', function() { @@ -749,9 +742,7 @@ describe('RippleAPI - offline', function() { }; return api.prepareSettings(address, settings, instructions).then(txJSON => { assert.deepEqual(txJSON, responses.prepareSettings.flags); - withDeterministicPRNG(() => { - assert.deepEqual(api.sign(txJSON, secret), responses.sign); - }); + assert.deepEqual(api.sign(txJSON, secret), responses.sign); }); }); }); diff --git a/test/fixtures/api/responses/generate-wallet.json b/test/fixtures/api/responses/generate-wallet.json index ba97f559ba..0ecead333d 100644 --- a/test/fixtures/api/responses/generate-wallet.json +++ b/test/fixtures/api/responses/generate-wallet.json @@ -1,4 +1,4 @@ { - "address": "ra2d1wnhDFyZGFz62wT3GSRhAEjpLuqfnj", - "secret": "ss4JedFMSQJa4mHQz3VZ58ZG4TYWg" + "address": "rGCkuB7PBr5tNy68tPEABEtcdno4hE6Y7f", + "secret": "sp6JS7f14BuwFY8Mw6bTtLKWauoUs" } diff --git a/test/mock-prng.js b/test/mock-prng.js deleted file mode 100644 index 2d09cab496..0000000000 --- a/test/mock-prng.js +++ /dev/null @@ -1,30 +0,0 @@ -'use strict'; -const _ = require('lodash'); - -const SEED = - '3045022100A58B0460BC5092CB4F96155C19125A4E079C870663F1D5E8BBC9BD0'; - -function MockPRNG(seed) { - if (seed && seed.length < 8) { - throw new Error('seed must be a hex string of at least 8 characters'); - } - this.position = 0; - this.seed = seed || SEED; -} - -/* eslint-disable no-unused-vars */ -MockPRNG.prototype.addEntropy = function(data, estimatedEntropy, source) {}; -/* eslint-enable no-unused-vars */ - -MockPRNG.prototype.randomWord = function() { - const i = this.position; - this.position = (i + 8) % this.seed.length; - const data = this.seed + this.seed.slice(8); - return parseInt(data.slice(i, i + 8), 16); -}; - -MockPRNG.prototype.randomWords = function(n) { - return _.times(n, () => this.randomWord()); -}; - -module.exports = MockPRNG; diff --git a/test/serializedobject-test.js b/test/serializedobject-test.js index 1b45eb226b..f5449acd65 100644 --- a/test/serializedobject-test.js +++ b/test/serializedobject-test.js @@ -6,11 +6,11 @@ const assert = require('assert'); const lodash = require('lodash'); const SerializedObject = require('ripple-lib').SerializedObject; const Amount = require('ripple-lib').Amount; -const sjcl = require('ripple-lib').sjcl; +const sjclcodec = require('sjcl-codec'); // Shortcuts -const hex = sjcl.codec.hex; -const utf8 = sjcl.codec.utf8String; +const hex = sjclcodec.hex; +const utf8 = sjclcodec.utf8String; describe('Serialized object', function() { @@ -20,7 +20,7 @@ describe('Serialized object', function() { describe('#from_json(v).to_json() == v', function() { it('outputs same as passed to from_json', function() { - let input_json = { + const input_json = { Account: 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', Amount: '274579388', Destination: 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', @@ -50,14 +50,14 @@ describe('Serialized object', function() { TransactionType: 'Payment', TxnSignature: '30450221009DA3A42DD25E3B22EC45AD8BA8FC7A954264264A816D300B2DF69F814D7D4DD2022072C9627F97EEC6DA13DE841E06E2CD985EF06A0FBB15DDBF0800D0730C8986BF' }; - let output_json = SerializedObject.from_json(input_json).to_json(); + const output_json = SerializedObject.from_json(input_json).to_json(); assert.deepEqual(input_json, output_json); }); }); describe('#from_json(v).to_json() == v -- invalid amount', function() { it('outputs same as passed to from_json', function() { - let input_json = { + const input_json = { Account: 'rUR9gTCcrUY9fMkz9rwcM9urPREh3LKXoW', Fee: '10', Flags: 0, @@ -81,7 +81,7 @@ describe('Serialized object', function() { describe('#from_json(v).to_json() == v -- invalid amount, strict_mode = false', function() { it('outputs same as passed to from_json', function() { - let input_json = { + const input_json = { Account: 'rUR9gTCcrUY9fMkz9rwcM9urPREh3LKXoW', Fee: '10', Flags: 0, @@ -97,9 +97,9 @@ describe('Serialized object', function() { TxnSignature: 'FFFFFF210085C6AE945643150E6D450CF796E45D74FB24B4E03E964A29CC6AFFEB346C77C80221009BE1B6678CF6C2E61F8F2696144C75AFAF66DF4FC0733DF9118EDEFEEFE33243' }; - let strictMode = Amount.strict_mode; + const strictMode = Amount.strict_mode; Amount.strict_mode = false; - let output_json = SerializedObject.from_json(input_json).to_json(); + const output_json = SerializedObject.from_json(input_json).to_json(); assert.deepEqual(input_json, output_json); Amount.strict_mode = strictMode; }); @@ -107,7 +107,7 @@ describe('Serialized object', function() { describe('#from_json', function() { it('understands TransactionType as a Number', function() { - let input_json = { + const input_json = { // no non required fields Account: 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', Amount: '274579388', @@ -117,14 +117,14 @@ describe('Serialized object', function() { SigningPubKey: '02',// VL field ;) TransactionType: 0 // }; - let output_json = SerializedObject.from_json(input_json).to_json(); + const output_json = SerializedObject.from_json(input_json).to_json(); assert.equal(0, input_json.TransactionType); assert.equal('Payment', output_json.TransactionType); }); it('understands LedgerEntryType as a Number', function() { - let input_json = { + const input_json = { // no, non required fields LedgerEntryType: 100, Flags: 0, @@ -132,13 +132,13 @@ describe('Serialized object', function() { RootIndex: '000360186E008422E06B72D5B275E29EE3BE9D87A370F424E0E7BF613C465909' }; - let output_json = SerializedObject.from_json(input_json).to_json(); + const output_json = SerializedObject.from_json(input_json).to_json(); assert.equal(100, input_json.LedgerEntryType); assert.equal('DirectoryNode', output_json.LedgerEntryType); }); it('checks for missing required fields', function() { - let input_json = { + const input_json = { TransactionType: 'Payment', // no non required fields Account: 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', @@ -150,7 +150,7 @@ describe('Serialized object', function() { }; Object.keys(input_json).slice(1).forEach(function(k) { - let bad_json = lodash.merge({}, input_json); + const bad_json = lodash.merge({}, input_json); delete bad_json[k]; assert.strictEqual(bad_json[k], undefined); @@ -161,7 +161,7 @@ describe('Serialized object', function() { }); }); it('checks for unknown fields', function() { - let input_json = { + const input_json = { TransactionType: 'Payment', // no non required fields Account: 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', @@ -173,7 +173,7 @@ describe('Serialized object', function() { }; Object.keys(input_json).slice(1).forEach(function(k) { - let bad_json = lodash.merge({}, input_json); + const bad_json = lodash.merge({}, input_json); bad_json[k + 'z'] = bad_json[k]; assert.throws(function() { @@ -187,7 +187,7 @@ describe('Serialized object', function() { // Peercover actually had a problem submitting transactions without a `Fee` // and rippled was only informing of 'transaction is invalid' it('should throw an Error when there is a missing field', function() { - let input_json = { + const input_json = { Account: 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', Amount: '274579388', Destination: 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS', @@ -234,7 +234,7 @@ describe('Serialized object', function() { } ]; - let so = SerializedObject.from_json(input_json).to_json(); + const so = SerializedObject.from_json(input_json).to_json(); input_json.Memos[0].Memo.parsed_memo_type = 'test'; input_json.Memos[0].Memo.parsed_memo_format = 'text'; input_json.Memos[0].Memo.parsed_memo_data = 'some data'; @@ -257,7 +257,7 @@ describe('Serialized object', function() { } ]; - let so = SerializedObject.from_json(input_json).to_json(); + const so = SerializedObject.from_json(input_json).to_json(); input_json.Memos[0].Memo.parsed_memo_type = 'test'; input_json.Memos[0].Memo.parsed_memo_format = 'application/json'; input_json.Memos[0].Memo.MemoType = convertStringToHex('test'); @@ -280,7 +280,7 @@ describe('Serialized object', function() { } ]; - let so = SerializedObject.from_json(input_json).to_json(); + const so = SerializedObject.from_json(input_json).to_json(); delete input_json.Memos[0].Memo.ignored; input_json.Memos[0].Memo.parsed_memo_type = 'test'; input_json.Memos[0].Memo.parsed_memo_format = 'json'; @@ -338,7 +338,7 @@ describe('Serialized object', function() { TxnSignature: '304402206B53EDFA6EFCF6FE5BA76C81BABB60A3B55E9DE8A1462DEDC5F387879575E498022015AE7B59AA49E735D7F2E252802C4406CD00689BCE5057C477FE979D38D2DAC9' }; - let serializedHex = '12000022800000002400000126201B009EC2FF614000000000000001684000000000002EE0732103D642E6457B8AB4D140E2C66EB4C484FAFB1BF267CB578EC4815FE6CD06379C517446304402206B53EDFA6EFCF6FE5BA76C81BABB60A3B55E9DE8A1462DEDC5F387879575E498022015AE7B59AA49E735D7F2E252802C4406CD00689BCE5057C477FE979D38D2DAC9811426C4CFB3BD05A9AA23936F2E81634C66A9820C9483143DD06317D19C6110CAFF150AE528F58843BE2CA1F9EA7C05696D616765E1F1'; + const serializedHex = '12000022800000002400000126201B009EC2FF614000000000000001684000000000002EE0732103D642E6457B8AB4D140E2C66EB4C484FAFB1BF267CB578EC4815FE6CD06379C517446304402206B53EDFA6EFCF6FE5BA76C81BABB60A3B55E9DE8A1462DEDC5F387879575E498022015AE7B59AA49E735D7F2E252802C4406CD00689BCE5057C477FE979D38D2DAC9811426C4CFB3BD05A9AA23936F2E81634C66A9820C9483143DD06317D19C6110CAFF150AE528F58843BE2CA1F9EA7C05696D616765E1F1'; assert.strictEqual(SerializedObject.from_json(input_json).to_hex(), serializedHex); }); diff --git a/test/transaction-manager-test.js b/test/transaction-manager-test.js index f521e48e08..841eee372f 100644 --- a/test/transaction-manager-test.js +++ b/test/transaction-manager-test.js @@ -5,7 +5,6 @@ const ws = require('ws'); const lodash = require('lodash'); const assert = require('assert-diff'); -const sjcl = require('ripple-lib').sjcl; const Remote = require('ripple-lib').Remote; const SerializedObject = require('ripple-lib').SerializedObject; const Transaction = require('ripple-lib').Transaction; @@ -48,11 +47,6 @@ describe('TransactionManager', function() { let account; let transactionManager; - before(function() { - sjcl.random.addEntropy( - '3045022100A58B0460BC5092CB4F96155C19125A4E079C870663F1D5E8BBC9BD', 256); - }); - beforeEach(function(done) { rippled = new ws.Server({port: 5763}); diff --git a/test/transaction-test.js b/test/transaction-test.js index e3dd4a0520..ca8e09d0c4 100644 --- a/test/transaction-test.js +++ b/test/transaction-test.js @@ -8,7 +8,6 @@ const Transaction = require('ripple-lib').Transaction; const TransactionQueue = require('ripple-lib').TransactionQueue; const Remote = require('ripple-lib').Remote; const Server = require('ripple-lib').Server; -const sjcl = require('ripple-lib').sjcl; const transactionResult = { engine_result: 'tesSUCCESS', @@ -54,11 +53,6 @@ for (let i = 0; i <= 127; i++) { } describe('Transaction', function() { - before(function() { - sjcl.random.addEntropy( - '3045022100A58B0460BC5092CB4F96155C19125A4E079C870663F1D5E8BBC9BD', 256); - }); - it('Success listener', function(done) { const transaction = new Transaction();