Compare commits

..

31 Commits

Author SHA1 Message Date
Geert Weening
5a9a4be163 [TASK] bump version to 0.8.1-rc2 2014-09-10 17:54:11 -07:00
Geert Weening
4d1a31d3c9 Revert "[FOLD] Add postinstall step to build the sjcl.js"
This reverts commit 42c853dbf4.
2014-09-10 17:53:29 -07:00
Geert Weening
6e3ceec4e5 [TASK] update publish scripts 2014-09-10 17:33:52 -07:00
Geert Weening
bc7d3c0af8 [TASK] add release candidate publish script 2014-09-10 17:32:03 -07:00
Geert Weening
519ddee092 [TASK] bump version to 0.8.1-rc1 2014-09-10 17:28:34 -07:00
Geert Weening
3e0fcc5b8b [DOC] update release notes 2014-09-10 17:28:00 -07:00
wltsmrz
b1972985c4 Merge pull request #164 from geertweening/develop
[FIX] return null for _getServer if there's no connected server
2014-09-08 12:04:22 -07:00
Geert Weening
51c42e9257 [FIX] return null for _getServer if there's no connected server 2014-09-08 11:54:48 -07:00
Geert Weening
86dcbcc671 [TASK] add exit_on_error calls to publish script 2014-09-08 11:54:47 -07:00
wltsmrz
3b7cd9d84f Merge pull request #163 from stevenzeiler/wallet
[TASK] Update package.json for ripple-wallet-generator patch.
2014-09-06 02:18:08 -07:00
Steven Zeiler
1073ec6214 [TASK] Update package.json for ripple-wallet-generator patch.
Removed node_modules from git repo of ripple-wallet-generator
2014-09-05 21:19:09 -07:00
wltsmrz
14a5e42a63 Merge pull request #162 from sublimator/develop
Fix #160, Seed.parse_json of hex
2014-09-05 20:56:53 -07:00
Nicholas Dudfield
b4564a86b4 Fix #160, Seed.parse_json of hex 2014-09-06 10:45:26 +07:00
wltsmrz
03386a61e9 Merge pull request #161 from stevenzeiler/wallet
[FEATURE] Add Wallet class that generates wallets.
2014-09-05 18:22:55 -07:00
Steven Zeiler
8bb2623360 [FEATURE] Add Wallet class that generates wallets.
[DOC] Comment out logged wallet.

[FIX] Use var instead of const.
2014-09-05 18:20:46 -07:00
wltsmrz
ab0e4188b3 Merge pull request #159 from ximinez/ripd-549
Clean up
2014-09-05 13:03:48 -07:00
Edward Hennis
42c853dbf4 [FOLD] Add postinstall step to build the sjcl.js 2014-09-05 14:50:29 -04:00
Geert Weening
ce48a1793b Merge branch 'release' into develop 2014-09-05 10:24:05 -07:00
Geert Weening
6177543d98 [TASK] add publish script 2014-09-05 10:23:59 -07:00
Geert Weening
9697bfa817 [TASK] add publish to bower script 2014-09-05 10:23:59 -07:00
Geert Weening
70425ab5c8 [TASK] bump version to 0.8.0 2014-09-05 10:19:58 -07:00
wltsmrz
7cccb451d2 Show field name in serialization failure 2014-09-04 20:13:04 -07:00
wltsmrz
a39fb9d551 Minor cleanup 2014-09-04 19:53:16 -07:00
wltsmrz
8f7cdc6e4f Prevent setting LastLedgerSequence of NaN. Fixes a potential ambiguous serialization error 2014-09-04 19:50:56 -07:00
wltsmrz
8f7e365b03 Wait until remote is connected before emitting ledger_closed events 2014-09-04 18:51:00 -07:00
Edward Hennis
64735e523f Clean up
* Make npm test runnable in Windows.
* Fix paths in README.md
* Ignore all build output files
2014-09-04 20:05:04 -04:00
Geert Weening
f126610219 [TASK] add publish to bower script 2014-09-04 16:11:59 -07:00
Geert Weening
2caef539ce [TASK] bump version to 0.8.0-rc3 2014-09-04 15:43:01 -07:00
Geert Weening
468fb87749 [DOC] update release notes 2014-09-04 15:42:36 -07:00
Geert Weening
4f4808ff15 Merge pull request #158 from justmoon/amount_constants
Amount: Constants should be static fields on the class, not a separate export.
2014-09-04 15:30:12 -07:00
Stefan Thomas
e6bbca7df1 [TASK] Amount: Constants should be static fields on the class, not a separate export. 2014-09-04 15:12:14 -07:00
19 changed files with 265 additions and 4686 deletions

4
.gitignore vendored
View File

@@ -17,7 +17,7 @@
# Ignore object files.
*.o
build/ripple*.js
build/*.js
tags
bin/rippled
Debug/*.*
@@ -51,4 +51,4 @@ test/config.js
npm-debug.log
# Ignore dist folder, build for bower
dist/
dist/

View File

@@ -1,3 +1,11 @@
##0.8.1
+ Wallet: Add Wallet class that generates wallets
+ Make npm test runnable in Windows.
+ Fix several stability issues, see merged PR's for details
##0.8.0
+ Orderbook: Added tracking of offer funds for determining when offers are not funded
@@ -18,6 +26,8 @@
+ Amount: Add a constant for the maximum canonical value that can be expressed as a Ripple value
+ Amount: Make Constants static fields on the class, instead of a seperate export
##0.7.39

View File

@@ -78,7 +78,7 @@ remote.connect(function() {
2. `cd` into the repository and install dependencies with `npm install`
3. `npm test` or `node_modules\.bin\mocha test\*-test.js`
3. `npm test` or `node_modules/.bin/mocha test/*-test.js`
**Generating code coverage**

File diff suppressed because it is too large Load Diff

View File

@@ -16,6 +16,17 @@ This file provides step-by-step walkthroughs for some of the most common usages
1. [The ripple-lib README](../README.md)
2. [The ripple-lib API Reference](REFERENCE.md)
##Generating a new Ripple Wallet
```js
var Wallet = require('ripple-lib').Wallet;
var wallet = Wallet.generate();
console.log(wallet);
// { address: 'rEf4sbVobiiDGExrNj2PkNHGMA8eS6jWh3',
// secret: 'shFh4a38EZpEdZxrLifEnVPAoBRce' }
```
##Connecting to the Ripple network
1. [Get ripple-lib](README.md#getting-ripple-lib)

View File

@@ -1,6 +1,6 @@
{
"name": "ripple-lib",
"version": "0.8.0-rc2",
"version": "0.8.1-rc2",
"description": "Ripple JavaScript client library",
"files": [
"src/js/*",
@@ -20,7 +20,8 @@
"extend": "~1.2.1",
"lru-cache": "~2.5.0",
"superagent": "^0.18.0",
"gulp-bump": "~0.1.10"
"gulp-bump": "~0.1.10",
"ripple-wallet-generator": "1.0.1"
},
"devDependencies": {
"mocha": "~1.14.0",
@@ -39,7 +40,7 @@
"scripts": {
"build": "node_modules/.bin/gulp",
"pretest": "node_modules/.bin/gulp concat-sjcl",
"test": "./node_modules/.bin/istanbul test -x build/sjcl.js -x src/js/jsbn/* ./node_modules/.bin/_mocha -- --reporter spec test/*-test.js",
"test": "./node_modules/.bin/istanbul test -x build/sjcl.js -x src/js/jsbn/* ./node_modules/mocha/bin/mocha -- --reporter spec test/*-test.js",
"coveralls": "cat ./coverage/lcov.info | ./node_modules/.bin/coveralls"
},
"repository": {

43
scripts/publish Normal file
View File

@@ -0,0 +1,43 @@
echo "PUBLISH"
function exit_on_error {
res=$?
[[ ${res:-99} -eq 0 ]] || exit $res
}
rm -rf build
npm install
gulp
npm test
exit_on_error
echo ""
echo "publish to npm"
npm publish
exit_on_error
rm -rf dist
echo ""
echo "publish to bower"
git clone git@github.com:ripple/bower-ripple.git dist
gulp bower
exit_on_error
cd dist
version=$(cat bower.json | grep -Eo '([0-9]\.?)+(-rc[0-9])?')
echo "version: $version"
git add ripple.js ripple-debug.js ripple-min.js bower.json
exit_on_error
git commit -m "[TASK] add v$version"
exit_on_error
git tag "v$version"
exit_on_error
git push origin master
git push --tags origin master
cd ..

43
scripts/publish_rc Normal file
View File

@@ -0,0 +1,43 @@
echo "PUBLISH RELEASE CANDIDATE"
function exit_on_error {
res=$?
[[ ${res:-99} -eq 0 ]] || exit $res
}
rm -rf build
npm install
gulp
npm test
exit_on_error
echo ""
echo "publish rc to npm"
npm publish --tag beta
exit_on_error
rm -rf dist
echo ""
echo "publish to bower"
git clone git@github.com:ripple/bower-ripple.git dist
gulp bower
exit_on_error
cd dist
version=$(cat bower.json | grep -Eo '([0-9]\.?)+(-rc[0-9])?')
echo "version: $version"
git add ripple.js ripple-debug.js ripple-min.js bower.json
exit_on_error
git commit -m "[TASK] add v$version"
exit_on_error
git tag "v$version"
exit_on_error
git push origin master
git push --tags origin master
cd ..

12
scripts/publish_to_bower Normal file
View File

@@ -0,0 +1,12 @@
rm -rf dist
git clone git@github.com:ripple/bower-ripple.git dist
gulp bower
cd dist
version=$(cat bower.json | grep -Eo '([0-9]\.?)+(-rc[0-9])?')
echo "version: $version"
git add ripple.js ripple-debug.js ripple-min.js bower.json
git commit -m "[TASK] add v$version"
git tag "v$version"
git push origin master
git push --tags origin master
cd ..

View File

@@ -12,7 +12,25 @@ var UInt160 = require('./uint160').UInt160;
var Seed = require('./seed').Seed;
var Currency = require('./currency').Currency;
var consts = exports.consts = {
//
// Amount class in the style of Java's BigInteger class
// http://docs.oracle.com/javase/1.3/docs/api/java/math/BigInteger.html
//
function Amount() {
// Json format:
// integer : XRP
// { 'value' : ..., 'currency' : ..., 'issuer' : ...}
this._value = new BigInteger(); // NaN for bad value. Always positive.
this._offset = 0; // Always 0 for XRP.
this._is_native = true; // Default to XRP. Only valid if value is not NaN.
this._is_negative = false;
this._currency = new Currency();
this._issuer = new UInt160();
};
var consts = {
currency_xns: 0,
currency_one: 1,
xns_precision: 6,
@@ -39,24 +57,11 @@ var consts = exports.consts = {
max_value: '9999999999999999e80'
};
// Add constants to Amount class
extend(Amount, consts);
//
// Amount class in the style of Java's BigInteger class
// http://docs.oracle.com/javase/1.3/docs/api/java/math/BigInteger.html
//
function Amount() {
// Json format:
// integer : XRP
// { 'value' : ..., 'currency' : ..., 'issuer' : ...}
this._value = new BigInteger(); // NaN for bad value. Always positive.
this._offset = 0; // Always 0 for XRP.
this._is_native = true; // Default to XRP. Only valid if value is not NaN.
this._is_negative = false;
this._currency = new Currency();
this._issuer = new UInt160();
};
// DEPRECATED: Use Amount instead, e.g. Amount.currency_xns
exports.consts = consts;
// Given '100/USD/mtgox' return the a string with mtgox remapped.
Amount.text_full_rewrite = function(j) {
@@ -136,12 +141,12 @@ Amount.prototype.add = function(v) {
var o2 = v._offset;
while (o1 < o2) {
v1 = v1.divide(consts.bi_10);
v1 = v1.divide(Amount.bi_10);
o1 += 1;
}
while (o2 < o1) {
v2 = v2.divide(consts.bi_10);
v2 = v2.divide(Amount.bi_10);
o2 += 1;
}
@@ -189,22 +194,22 @@ Amount.prototype.multiply = function(v) {
var o2 = v._offset;
if (this.is_native()) {
while (v1.compareTo(consts.bi_man_min_value) < 0) {
v1 = v1.multiply(consts.bi_10);
while (v1.compareTo(Amount.bi_man_min_value) < 0) {
v1 = v1.multiply(Amount.bi_10);
o1 -= 1;
}
}
if (v.is_native()) {
while (v2.compareTo(consts.bi_man_min_value) < 0) {
v2 = v2.multiply(consts.bi_10);
while (v2.compareTo(Amount.bi_man_min_value) < 0) {
v2 = v2.multiply(Amount.bi_10);
o2 -= 1;
}
}
result = new Amount();
result._offset = o1 + o2 + 14;
result._value = v1.multiply(v2).divide(consts.bi_1e14).add(consts.bi_7);
result._value = v1.multiply(v2).divide(Amount.bi_1e14).add(Amount.bi_7);
result._is_native = this._is_native;
result._is_negative = this._is_negative !== v._is_negative;
result._currency = this._currency;
@@ -238,8 +243,8 @@ Amount.prototype.divide = function(d) {
if (_n.is_native()) {
_n = _n.clone();
while (_n._value.compareTo(consts.bi_man_min_value) < 0) {
_n._value = _n._value.multiply(consts.bi_10);
while (_n._value.compareTo(Amount.bi_man_min_value) < 0) {
_n._value = _n._value.multiply(Amount.bi_10);
_n._offset -= 1;
}
}
@@ -249,15 +254,15 @@ Amount.prototype.divide = function(d) {
if (_d.is_native()) {
_d = _d.clone();
while (_d._value.compareTo(consts.bi_man_min_value) < 0) {
_d._value = _d._value.multiply(consts.bi_10);
while (_d._value.compareTo(Amount.bi_man_min_value) < 0) {
_d._value = _d._value.multiply(Amount.bi_10);
_d._offset -= 1;
}
}
result = new Amount();
result._offset = _n._offset - _d._offset - 17;
result._value = _n._value.multiply(consts.bi_1e17).divide(_d._value).add(consts.bi_5);
result._value = _n._value.multiply(Amount.bi_1e17).divide(_d._value).add(Amount.bi_5);
result._is_native = _n._is_native;
result._is_negative = _n._is_negative !== _d._is_negative;
result._currency = _n._currency;
@@ -331,7 +336,7 @@ Amount.prototype.ratio_human = function(denominator, opts) {
// To compensate, we multiply the numerator by 10^xns_precision.
if (denominator._is_native) {
numerator = numerator.clone();
numerator._value = numerator._value.multiply(consts.bi_xns_unit);
numerator._value = numerator._value.multiply(Amount.bi_xns_unit);
numerator.canonicalize();
}
@@ -389,7 +394,7 @@ Amount.prototype.product_human = function(factor, opts) {
//
// See also Amount#ratio_human.
if (factor._is_native) {
product._value = product._value.divide(consts.bi_xns_unit);
product._value = product._value.divide(Amount.bi_xns_unit);
product.canonicalize();
}
@@ -402,7 +407,7 @@ Amount.prototype.product_human = function(factor, opts) {
* @private
*/
Amount.prototype._invert = function() {
this._value = consts.bi_1e32.divide(this._value);
this._value = Amount.bi_1e32.divide(this._value);
this._offset = -32 - this._offset;
this.canonicalize();
@@ -432,12 +437,12 @@ Amount.prototype.canonicalize = function() {
// Normalize _offset to 0.
while (this._offset < 0) {
this._value = this._value.divide(consts.bi_10);
this._value = this._value.divide(Amount.bi_10);
this._offset += 1;
}
while (this._offset > 0) {
this._value = this._value.multiply(consts.bi_10);
this._value = this._value.multiply(Amount.bi_10);
this._offset -= 1;
}
}
@@ -449,13 +454,13 @@ Amount.prototype.canonicalize = function() {
} else {
// Normalize mantissa to valid range.
while (this._value.compareTo(consts.bi_man_min_value) < 0) {
this._value = this._value.multiply(consts.bi_10);
while (this._value.compareTo(Amount.bi_man_min_value) < 0) {
this._value = this._value.multiply(Amount.bi_10);
this._offset -= 1;
}
while (this._value.compareTo(consts.bi_man_max_value) > 0) {
this._value = this._value.divide(consts.bi_10);
while (this._value.compareTo(Amount.bi_man_max_value) > 0) {
this._value = this._value.divide(Amount.bi_10);
this._offset += 1;
}
}
@@ -673,14 +678,14 @@ Amount.prototype.parse_human = function(j, opts) {
fraction += '0';
}
this._is_native = true;
this._value = this._value.multiply(consts.bi_xns_unit).add(new BigInteger(fraction));
this._value = this._value.multiply(Amount.bi_xns_unit).add(new BigInteger(fraction));
} else {
// Other currencies have arbitrary precision
fraction = fraction.replace(/0+$/, '');
precision = fraction.length;
this._is_native = false;
var multiplier = consts.bi_10.clone().pow(precision);
var multiplier = Amount.bi_10.clone().pow(precision);
this._value = this._value.multiply(multiplier).add(new BigInteger(fraction));
this._offset = -precision;
@@ -879,8 +884,8 @@ Amount.prototype.parse_native = function(j) {
this._value = new BigInteger(m[2]);
} else {
// Float notation : values multiplied by 1,000,000.
var int_part = (new BigInteger(m[2])).multiply(consts.bi_xns_unit);
var fraction_part = (new BigInteger(m[3])).multiply(new BigInteger(String(Math.pow(10, 1+consts.xns_precision-m[3].length))));
var int_part = (new BigInteger(m[2])).multiply(Amount.bi_xns_unit);
var fraction_part = (new BigInteger(m[3])).multiply(new BigInteger(String(Math.pow(10, 1+Amount.xns_precision-m[3].length))));
this._value = int_part.add(fraction_part);
}
@@ -889,7 +894,7 @@ Amount.prototype.parse_native = function(j) {
this._offset = 0;
this._is_negative = !!m[1] && this._value.compareTo(BigInteger.ZERO) !== 0;
if (this._value.compareTo(consts.bi_xns_max) > 0) {
if (this._value.compareTo(Amount.bi_xns_max) > 0) {
this._value = NaN;
}
} else {
@@ -931,7 +936,7 @@ Amount.prototype.parse_value = function(j) {
var fraction = new BigInteger(d[3]);
var precision = d[3].length;
this._value = integer.multiply(consts.bi_10.clone().pow(precision)).add(fraction);
this._value = integer.multiply(Amount.bi_10.clone().pow(precision)).add(fraction);
this._offset = -precision;
this._is_negative = !!d[1];
@@ -982,7 +987,7 @@ Amount.prototype.to_text = function(allow_nan) {
var result = NaN;
if (this._is_native) {
if (this.is_valid() && this._value.compareTo(consts.bi_xns_max) <= 0){
if (this.is_valid() && this._value.compareTo(Amount.bi_xns_max) <= 0){
result = this._value.toString();
}
} else if (this.is_zero()) {
@@ -1090,8 +1095,8 @@ Amount.prototype.to_human = function(opts) {
ref = this.applyInterest(opts.reference_date);
}
var order = ref._is_native ? consts.xns_precision : -ref._offset;
var denominator = consts.bi_10.clone().pow(order);
var order = ref._is_native ? Amount.xns_precision : -ref._offset;
var denominator = Amount.bi_10.clone().pow(order);
var int_part = ref._value.divide(denominator).toString();
var fraction_part = ref._value.mod(denominator).toString();

View File

@@ -18,6 +18,7 @@ exports.RippleTxt = require('./rippletxt').RippleTxt;
exports.binformat = require('./binformat');
exports.utils = require('./utils');
exports.Server = require('./server').Server;
exports.Wallet = require('./wallet');
// 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

View File

@@ -15,6 +15,7 @@
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var assert = require('assert');
var LRU = require('lru-cache');
var Server = require('./server').Server;
var Request = require('./request').Request;
@@ -209,7 +210,7 @@ function Remote(opts, trace) {
function listenerAdded(type, listener) {
if (type === 'transaction_all') {
if (!self._transaction_subs && self._connected) {
if (!self._transaction_subs && self.isConnected()) {
self.request_subscribe('transactions').request();
}
self._transaction_subs += 1;
@@ -221,7 +222,7 @@ function Remote(opts, trace) {
function listenerRemoved(type, listener) {
if (type === 'transaction_all') {
self._transaction_subs -= 1;
if (!self._transaction_subs && self._connected) {
if (!self._transaction_subs && self.isConnected()) {
self.request_unsubscribe('transactions').request();
}
}
@@ -243,7 +244,7 @@ function Remote(opts, trace) {
};
if (opts.ping) {
this.once('connect', pingServers);
this.on('connect', pingServers);
}
function reconnect() {
@@ -338,13 +339,11 @@ Remote.isValidLedgerData = function(message) {
return (typeof message === 'object')
&& (typeof message.fee_base === 'number')
&& (typeof message.fee_ref === 'number')
&& (typeof message.fee_base === 'number')
&& (typeof message.ledger_hash === 'string')
&& (typeof message.ledger_index === 'number')
&& (typeof message.ledger_time === 'number')
&& (typeof message.reserve_base === 'number')
&& (typeof message.reserve_inc === 'number')
&& (typeof message.txn_count === 'number');
&& (typeof message.reserve_inc === 'number');
};
/**
@@ -514,12 +513,9 @@ Remote.prototype.reconnect = function() {
log.info('reconnecting');
;(function nextServer(i) {
self._servers[i].reconnect();
if (++i < self._servers.length) {
nextServer(i);
}
})(0);
this._servers.forEach(function(server) {
server.reconnect();
});
return this;
};
@@ -553,12 +549,9 @@ Remote.prototype.connect = function(online) {
this._should_connect = true;
;(function nextServer(i) {
self._servers[i].connect();
if (++i < self._servers.length) {
nextServer(i);
}
})(0);
this._servers.forEach(function(server) {
server.connect();
});
return this;
};
@@ -577,7 +570,7 @@ Remote.prototype.disconnect = function(callback) {
var callback = (typeof callback === 'function') ? callback : function(){};
if (!this._connected) {
if (!this.isConnected()) {
callback();
return this;
}
@@ -660,11 +653,19 @@ Remote.prototype._handleLedgerClosed = function(message) {
var ledgerAdvanced = message.ledger_index >= this._ledger_current_index;
if (ledgerAdvanced) {
if (isNaN(this._ledger_current_index) || ledgerAdvanced) {
this._ledger_time = message.ledger_time;
this._ledger_hash = message.ledger_hash;
this._ledger_current_index = message.ledger_index + 1;
this.emit('ledger_closed', message);
if (this.isConnected()) {
this.emit('ledger_closed', message);
} else {
this.once('connect', function() {
// Delay until server is 'online'
self.emit('ledger_closed', message);
});
}
}
};
@@ -819,6 +820,10 @@ Remote.prototype.getServer = function() {
}
var connectedServers = this.getConnectedServers();
if (connectedServers.length === 0 || !connectedServers[0]) {
return null;
}
var server = connectedServers[0];
var cScore = server._score + server._fee;
@@ -861,7 +866,7 @@ Remote.prototype.request = function(request) {
if (!this._servers.length) {
request.emit('error', new Error('No servers available'));
} else if (!this._connected) {
} else if (!this.isConnected()) {
this.once('connect', this.request.bind(this, request));
} else if (request.server === null) {
request.emit('error', new Error('Server does not exist'));
@@ -1608,12 +1613,7 @@ Remote.prototype._serverPrepareSubscribe = function(callback) {
self.emit('random', utils.hexToArray(message.random));
}
if (message.ledger_hash && message.ledger_index) {
self._ledger_time = message.ledger_time;
self._ledger_hash = message.ledger_hash;
self._ledger_current_index = message.ledger_index+1;
self.emit('ledger_closed', message);
}
self._handleLedgerClosed(message);
self.emit('subscribed');
};
@@ -2215,65 +2215,40 @@ Remote.prototype.requestConnect = function(ip, port, callback) {
/**
* Create a Transaction
*
* @param {String} source
* @param {String} TransactionType
* @param {Object} options
* @param [Function] callback
* @return {Request}
* @return {Transaction}
*/
Remote.prototype.transaction =
Remote.prototype.createTransaction = function(source, options, callback) {
Remote.prototype.createTransaction = function(type, options) {
if (arguments.length === 0) {
// Fallback
return new Transaction(this);
}
assert.strictEqual(typeof type, 'string', 'TransactionType must be a string');
assert.strictEqual(typeof options, 'object', 'Transaction options must be an object');
var transaction = new Transaction(this);
var transactionTypes = {
payment: 'payment',
accountset: 'accountSet',
trustset: 'trustSet',
offercreate: 'offerCreate',
offercancel: 'offerCancel',
claim: 'claim',
passwordfund: 'passwordFund',
passwordset: 'passwordSet',
setregularkey: 'setRegularKey',
walletadd: 'walletAdd',
sign: 'sign'
payment: 'payment',
accountset: 'accountSet',
trustset: 'trustSet',
offercreate: 'offerCreate',
offercancel: 'offerCancel',
setregularkey: 'setRegularKey',
sign: 'sign'
};
var transactionType;
var transactionConstructor = transactionTypes[type.toLowerCase()];
switch (typeof source) {
case 'object':
if (typeof source.type !== 'string') {
throw new Error('Missing transaction type');
}
transactionType = transactionTypes[source.type.toLowerCase()];
if (!transactionType) {
throw new Error('Invalid transaction type: ' + transactionType);
}
transaction = transaction[transactionType](source);
break;
case 'string':
transactionType = transactionTypes[source.toLowerCase()];
if (!transactionType) {
throw new Error('Invalid transaction type: ' + transactionType);
}
transaction = transaction[transactionType](options);
break;
if (!transactionConstructor) {
throw new Error('Invalid transaction type: ' + type);
}
var lastArg = arguments[arguments.length - 1];
if (typeof lastArg === 'function') {
transaction.submit(lastArg);
}
return transaction;
return transaction[transactionConstructor](options);
};
/**

View File

@@ -33,8 +33,8 @@ Seed.prototype.parse_json = function (j) {
// XXX Should actually always try and continue if it failed.
} else if (j[0] === 's') {
this._value = Base.decode_check(Base.VER_FAMILY_SEED, j);
} else if (j.length === 32) {
this._value = this.parse_hex(j);
} else if (/^[0-9a-fA-f]{32}$/.test(j)) {
this.parse_hex(j);
// XXX Should also try 1751
} else {
this.parse_passphrase(j);

View File

@@ -117,7 +117,7 @@ SerializedType.prototype.parse_varint = function (so) {
*/
function append_byte_array(so, val, bytes) {
if (!isNumber(val)) {
throw new Error('Value is not a number');
throw new Error('Value is not a number', bytes);
}
if (val < 0 || val >= Math.pow(256, bytes)) {
@@ -625,7 +625,13 @@ function serialize(so, field_name, value) {
// Get the serializer class (ST...) for a field based on the type bits.
var serialized_object_type = exports[binformat.types[type_bits]];
//do something with val[keys] and val[keys[i]];
serialized_object_type.serialize(so, value);
try {
serialized_object_type.serialize(so, value);
} catch (e) {
e.message += ' (' + field_name + ')';
throw e;
}
}
//Take the serialized object, figure out what type/field it is, and return the parsing of that.

View File

@@ -480,7 +480,7 @@ Transaction.prototype.clientID = function(id) {
};
Transaction.prototype.lastLedger = function(sequence) {
if (typeof sequence === 'number') {
if (typeof sequence === 'number' && isFinite(sequence)) {
this._setLastLedger = true;
this.tx_json.LastLedgerSequence = sequence;
}

8
src/js/ripple/wallet.js Normal file
View File

@@ -0,0 +1,8 @@
var sjcl = require('./utils').sjcl;
var WalletGenerator = require('ripple-wallet-generator')({
sjcl: sjcl
});
module.exports = WalletGenerator;

View File

@@ -82,8 +82,17 @@ describe('Message', function(){
});
it('should throw an error if given an invalid secret key', function(){
// Annoyingly non hex can be fed to the BigInteger(s, 16) constructor and
// it will parse as a number. Before the commit of this comment, this test
// involved a fixture of 32 chars, which was assumed to be hex. The test
// passed, but for the wrong wreasons. There was a bug in Seed.parse_json.
var secret_string = 'badsafRpB5euNL52PZPTSqrE9gvuFwTC';
// Seed.from_json only creates invalid seeds from empty strings or invalid
// base58 starting with an s, which it tries to base 58 decode/check sum.
// The rest will be assumed to be a passphrase.
// This is a bad b58 seed
var secret_string = 'sbadsafRpB5euNL52PZPTSqrE9gvuFwTC';
var hash = 'e865bcc63a86ef21585ac8340a7cc8590ed85175a2a718c6fb2bfb2715d13778';
assert.throws(function(){

View File

@@ -26,8 +26,9 @@ describe('Signing', function() {
assert(_isNaN(new Seed().parse_json('').to_json()));
});
it('hex string', function() {
// 32 0s is a valid hex repr of seed bytes
var str = new Array(33).join('0');
assert(_isNaN(new Seed().parse_json(str).to_json()));
assert.strictEqual((new Seed().parse_json(str).to_json()), 'sp6JS7f14BuwFY8Mw6bTtLKWauoUs');
});
it('passphrase', function() {
var str = new Array(60).join('0');

View File

@@ -811,6 +811,10 @@ describe('Transaction', function() {
assert.strictEqual(transaction.tx_json.LastLedgerSequence, void(0));
assert(!transaction._setLastLedger);
transaction.lastLedger(NaN);
assert.strictEqual(transaction.tx_json.LastLedgerSequence, void(0));
assert(!transaction._setLastLedger);
transaction.lastLedger(12);
assert.strictEqual(transaction.tx_json.LastLedgerSequence, 12);
assert(transaction._setLastLedger);