Skip to content

Commit

Permalink
Remove sjcl-extended. Use hash.js & lite sjcl build
Browse files Browse the repository at this point in the history
  • Loading branch information
sublimator committed Aug 13, 2015
1 parent 6a2a246 commit e7f14e5
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 57 deletions.
27 changes: 15 additions & 12 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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-lib-transactionparser": "^0.5.0",
"ripple-wallet-generator": "^1.0.3",
"sjcl-extended": "ripple/sjcl-extended#1.0.3",
"sjcl": "^1.0.3",
"ws": "~0.7.1"
},
"devDependencies": {
Expand Down Expand Up @@ -60,6 +60,7 @@
"watch": "babel -w -D --optional runtime -d dist/npm/ src/",
"compile-with-source-maps": "babel -D --optional runtime -s -t -d dist/npm/ src/",
"prepublish": "npm run clean && npm run compile",
"postinstall": "cd node_modules/sjcl; ./configure --without-all --with-codecBytes --with-bitArray --with-codecString --with-codecHex --compress=none; make",
"test": "istanbul test _mocha",
"coveralls": "cat ./coverage/lcov.info | coveralls",
"lint": "if ! [ -f eslintrc ]; then curl -o eslintrc 'https://raw.githubusercontent.com/ripple/javascript-style-guide/es6/eslintrc'; echo 'plugins:\n - flowtype' >> eslintrc; fi; eslint -c eslintrc src/",
Expand Down
1 change: 1 addition & 0 deletions src/api/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions src/api/common/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand All @@ -27,6 +28,11 @@ function toRippledAmount(amount: Amount): string|Amount {
};
}

function generateWallet(options) {

This comment has been minimized.

Copy link
@sublimator

sublimator Aug 13, 2015

Author Contributor

@clark800

The second last commit also removes the ripple-wallet-generator module and uses generateWallet from ripple-keypairs for the api.generateWallet.

The flow type check seems to be crying about these changes:



/home/ubuntu/ripple-lib/build/flow/api/common/utils.js:8:16,41: index.js
Required module not found

/home/ubuntu/ripple-lib/build/flow/api/common/utils.js:31:25,31: parameter options
Missing annotation

/home/ubuntu/ripple-lib/build/flow/api/common/utils.js:31:33,33: return
Missing annotation

Found 3 errors

This comment has been minimized.

Copy link
@clark800

clark800 Aug 13, 2015

Contributor

@sublimator is this still a problem? if so, where is this error happening?

const {accountID, seed} = keypairs.generateWallet(options);
return {secret: seed, address: accountID};
}

type AsyncFunction = (...x: any) => void

function wrapCatch(asyncFunction: AsyncFunction): AsyncFunction {
Expand Down Expand Up @@ -95,6 +101,7 @@ module.exports = {
dropsToXrp,
xrpToDrops,
toRippledAmount,
generateWallet,
composeAsync,
wrapCatch,
convertExceptions,
Expand Down
2 changes: 1 addition & 1 deletion src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {}) {
Expand Down
24 changes: 10 additions & 14 deletions src/core/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,7 +42,7 @@ function Account(remote, account) {
this._entry = { };

function listenerAdded(type) {
if (~Account.subscribeEvents.indexOf(type)) {
if (Account.subscribeEvents.indexOf(type) !== -1) {
if (!self._subs && self._remote._connected) {
self._remote.requestSubscribe()
.addAccount(self._account_id)
Expand All @@ -54,7 +55,7 @@ function Account(remote, account) {
this.on('newListener', listenerAdded);

function listenerRemoved(type) {
if (~Account.subscribeEvents.indexOf(type)) {
if (Account.subscribeEvents.indexOf(type) !== -1) {
self._subs -= 1;
if (!self._subs && self._remote._connected) {
self._remote.requestUnsubscribe()
Expand Down Expand Up @@ -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)) {
Expand Down
1 change: 0 additions & 1 deletion src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,4 @@ exports._test = {
// 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');
10 changes: 5 additions & 5 deletions src/core/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ const {KeyPair, KeyType} = require('ripple-keypairs');
const codec = require('ripple-address-codec');
const extend = require('extend');
const BN = require('bn.js');
const hashjs = require('hash.js');
const utils = require('./utils');

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);
Expand Down Expand Up @@ -74,10 +74,10 @@ 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 codecs = sjcl.codec;
const phraseBytes = codecs.bytes.fromBits(codecs.utf8String.toBits(j));
const hash = hashjs.sha512().update(phraseBytes).digest();
this.parse_bytes(hash.slice(0, 16));

return this;
};
Expand Down
7 changes: 3 additions & 4 deletions src/core/serializedobject.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const assert = require('assert');
const extend = require('extend');
const BN = require('bn.js');
const hashjs = require('hash.js');
const binformat = require('./binformat');
const stypes = require('./serializedtypes');
const utils = require('./utils');
Expand Down Expand Up @@ -302,11 +303,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
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,6 @@ exports.fromTimestamp = fromTimestamp;
exports.getMantissaDecimalString = getMantissaDecimalString;
exports.getMantissa16FromString = getMantissa16FromString;

exports.sjcl = require('sjcl-extended');
exports.sjcl = require('sjcl');

// vim:sw=2:sts=2:ts=8:et
8 changes: 5 additions & 3 deletions test/api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,11 @@ describe('RippleAPI', function() {
});

it('generateWallet', function() {
withDeterministicPRNG(() => {
assert.deepEqual(this.api.generateWallet(), responses.generateWallet);
});
function rand() {
return _.fill(Array(16), 0);
}
assert.deepEqual(this.api.generateWallet({randGen: rand}),
responses.generateWallet);
});

it('getSettings', function() {
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/api/responses/generate-wallet.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"address": "ra2d1wnhDFyZGFz62wT3GSRhAEjpLuqfnj",
"secret": "ss4JedFMSQJa4mHQz3VZ58ZG4TYWg"
"address": "rGCkuB7PBr5tNy68tPEABEtcdno4hE6Y7f",
"secret": "sp6JS7f14BuwFY8Mw6bTtLKWauoUs"
}
6 changes: 0 additions & 6 deletions test/transaction-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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});

Expand Down
6 changes: 0 additions & 6 deletions test/transaction-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit e7f14e5

Please sign in to comment.