mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-05 05:15:48 +00:00
Compare commits
91 Commits
v0.8.2-rc2
...
0.9.2-rc5
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66d21b24cd | ||
|
|
5a084ea3cc | ||
|
|
486944fa4c | ||
|
|
b63a76d298 | ||
|
|
31045039c0 | ||
|
|
6f5d1104aa | ||
|
|
3c9660203b | ||
|
|
29e1423f84 | ||
|
|
e42e67e259 | ||
|
|
ed018282c4 | ||
|
|
fbe015758c | ||
|
|
7e24a81764 | ||
|
|
9ab77e90fe | ||
|
|
ae3ed699db | ||
|
|
0c22a9753e | ||
|
|
a447f6b723 | ||
|
|
a8ef614b81 | ||
|
|
9025e8bfa8 | ||
|
|
722f4e175d | ||
|
|
1ad6e5a15f | ||
|
|
3554572db7 | ||
|
|
f1abff962f | ||
|
|
f05941fbc4 | ||
|
|
237c46d5a0 | ||
|
|
76cfb69d9f | ||
|
|
7610df0fbb | ||
|
|
8bc935aa62 | ||
|
|
24587fab9c | ||
|
|
0248475473 | ||
|
|
d2fa5c4b12 | ||
|
|
c60c0cb6e0 | ||
|
|
cdf1112666 | ||
|
|
d861bb2e34 | ||
|
|
006849a3d5 | ||
|
|
a3c1d06eba | ||
|
|
4bd1e7a2bc | ||
|
|
68643f3118 | ||
|
|
560dfc8ae6 | ||
|
|
b0459e096b | ||
|
|
2a0dfc4587 | ||
|
|
2dcd5f94fb | ||
|
|
13685d03e1 | ||
|
|
278df9025a | ||
|
|
cb608406f8 | ||
|
|
f4a55d03d3 | ||
|
|
d3b6b8127c | ||
|
|
bc1f9f8a28 | ||
|
|
9a5c9aea75 | ||
|
|
f1004c6db2 | ||
|
|
7708c64576 | ||
|
|
0527b8c981 | ||
|
|
13f89e2fcc | ||
|
|
69a0a473a6 | ||
|
|
4ab82d7e01 | ||
|
|
4be209e286 | ||
|
|
8b10325895 | ||
|
|
70bf600247 | ||
|
|
d42e06d48b | ||
|
|
9c080b6790 | ||
|
|
033257b03b | ||
|
|
39d8bcdfc2 | ||
|
|
2ddcb4e2b7 | ||
|
|
d972718a53 | ||
|
|
6abed8dd53 | ||
|
|
e74e697b45 | ||
|
|
26c59e8565 | ||
|
|
a5e83c4f23 | ||
|
|
900c4bbd2e | ||
|
|
947ec3edc2 | ||
|
|
957f10d9f1 | ||
|
|
89aa54dff8 | ||
|
|
bb76530e4b | ||
|
|
011e2cc1e3 | ||
|
|
4c594f8964 | ||
|
|
1fcfcf2392 | ||
|
|
6311abff81 | ||
|
|
ed2da57475 | ||
|
|
778ccd4805 | ||
|
|
327c35252f | ||
|
|
5e7af2fba4 | ||
|
|
dce15bc579 | ||
|
|
d5e32db954 | ||
|
|
bdfa83592b | ||
|
|
23e473b688 | ||
|
|
0dfd3a0ae0 | ||
|
|
d107092540 | ||
|
|
c2f379d3b3 | ||
|
|
57b70300f5 | ||
|
|
eeba86f9c5 | ||
|
|
e0d68e60ec | ||
|
|
254248486b |
68
HISTORY.md
68
HISTORY.md
@@ -1,8 +1,74 @@
|
||||
##0.9.2
|
||||
|
||||
+ [**Breaking change**: Change accountRequest method signature](https://github.com/ripple/ripple-lib/commit/6f5d1104aa3eb440c518ec4f39e264fdce15fa15)
|
||||
|
||||
+ [Add paging behavior for account requests, `account_lines` and `account_offers`](https://github.com/ripple/ripple-lib/commit/722f4e175dbbf378e51b49142d0285f87acb22d7)
|
||||
|
||||
+ [Add max_fee setter to transactions to set max fee the submitter is willing to pay] (https://github.com/ripple/ripple-lib/commit/24587fab9c8ad3840d7aa345a7037b48839e09d7)
|
||||
|
||||
+ [Fix: cap IOU Amounts to their max and min value] (https://github.com/ripple/ripple-lib/commit/f05941fbc46fdb7c6fe7ad72927af02d527ffeed)
|
||||
|
||||
Example on how to use paging with `account_offers`:
|
||||
```
|
||||
// A valid `ledger_index` or `ledger_hash` is required to provide a reliable result.
|
||||
// Results can change between ledger closes, so the provided ledger will be used as base.
|
||||
var options = {
|
||||
account: < rippleAccount >,
|
||||
limit: < Number between 10 and 400 >,
|
||||
ledger: < valid ledger_index or ledger_hash >
|
||||
}
|
||||
|
||||
// The `marker` comes back in an account request if there are more results than are returned
|
||||
// in the current response. The amount of results per response are determined by the `limit`.
|
||||
if (marker) {
|
||||
options.marker = < marker >;
|
||||
}
|
||||
|
||||
var request = remote.requestAccountOffers(options);
|
||||
```
|
||||
|
||||
[Full working example](https://github.com/geertweening/ripple-lib-scripts/blob/master/account_offers_paging.js)
|
||||
|
||||
|
||||
##0.9.1
|
||||
|
||||
+ Switch account requests to use ledgerSelect rather than ledgerChoose ([278df90](https://github.com/ripple/ripple-lib/commit/278df9025a20228de22379a53c76ca12d40fa591))
|
||||
|
||||
+ **Deprecated** setting `ident` and `account_index` on account requests ([278df90](https://github.com/ripple/ripple-lib/commit/278df9025a20228de22379a53c76ca12d40fa591))
|
||||
|
||||
+ Change initial account transaction sequence to 1 ([a3c1d06](https://github.com/ripple/ripple-lib/commit/a3c1d06eba883dc84fe2bfe700e4309795c84cac))
|
||||
|
||||
+ Fix: instance transaction withoute remote ([d3b6b81](https://github.com/ripple/ripple-lib/commit/d3b6b8127c7b01e416b400c25abf1719bdd008ca))
|
||||
|
||||
+ Fix: account root request ledger argument ([bc1f9f8](https://github.com/ripple/ripple-lib/commit/bc1f9f8a286b187d36ebaf552694e31e73742293))
|
||||
|
||||
+ Fix: rsign.js local signing and example ([d3b6b81](https://github.com/ripple/ripple-lib/commit/d3b6b8127c7b01e416b400c25abf1719bdd008ca) and [f1004c6](https://github.com/ripple/ripple-lib/commit/f1004c6db2a0ce59bbabbb8f2b355a9fd9995fd8))
|
||||
|
||||
|
||||
##0.9.0
|
||||
|
||||
+ Add routes to the vault client for KYC attestations ([ed2da574](https://github.com/ripple/ripple-lib/commit/ed2da57475acf5e9d2cf3373858f4274832bd83f))
|
||||
|
||||
+ Currency: add `show_interest` flag to show or hide interest in `Currency.to_human()` and `Currency.to_json()` [Example use in tests](https://github.com/ripple/ripple-lib/blob/947ec3edc2e7c8f1ef097e496bf552c74366e749/test/currency-test.js#L123)
|
||||
|
||||
+ Configurable maxAttempts for transaction submission ([d107092](https://github.com/ripple/ripple-lib/commit/d10709254061e9e4416d2cb78b5cac1ec0d7ffa5))
|
||||
|
||||
+ Binformat: added missing TransactionResult options ([6abed8d](https://github.com/ripple/ripple-lib/commit/6abed8dd5311765b2eb70505dadbdf5121439ca8))
|
||||
|
||||
+ **Breaking change:** make maxLoops in seed.get_key optional. [Example use in tests](https://github.com/ripple/ripple-lib/blob/23e473b6886c457781949c825b3ff48b3984e51f/test/seed-test.js) ([23e473b](https://github.com/ripple/ripple-lib/commit/23e473b6886c457781949c825b3ff48b3984e51f))
|
||||
|
||||
+ Shrinkwrap packages for dependency locking ([2dcd5f9](2dcd5f94fbc71200eb08a5044c76ef94f7971913))
|
||||
|
||||
+ Fix: Amount.to_human() precision bugs ([4be209e](https://github.com/ripple/ripple-lib/commit/4be209e286b5b209bec7bcd1212098985e15ff2f) and [7708c64](https://github.com/ripple/ripple-lib/commit/7708c64576e70ce3ac190442daceb30e4446aab7))
|
||||
|
||||
+ Fix: change handling of requestLedger options ([57b7030](https://github.com/ripple/ripple-lib/commit/57b70300f5f0c7534ede118ddbb5d8762668a4f8))
|
||||
|
||||
|
||||
##0.8.2
|
||||
|
||||
+ Currency: Allow mixed letters and numbers in currencies
|
||||
|
||||
+ Deprecate account_tx map/reduce/filter
|
||||
+ Deprecate account_tx map/reduce/filterg
|
||||
|
||||
+ Fix: correct requestLedger arguments
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ function ready() {
|
||||
function print_usage() {
|
||||
console.log(
|
||||
'Usage: rsign.js <secret> <json>\n\n',
|
||||
'Example: rsign.js ssq55ueDob4yV3kPVnNQLHB6icwpC',
|
||||
'Example: rsign.js ssq55ueDob4yV3kPVnNQLHB6icwpC','\''+
|
||||
JSON.stringify({
|
||||
TransactionType: 'Payment',
|
||||
Account: 'r3P9vH81KBayazSTrQj6S25jW6kDb779Gi',
|
||||
@@ -64,7 +64,7 @@ function print_usage() {
|
||||
Amount: '200000000',
|
||||
Fee: '10',
|
||||
Sequence: 1
|
||||
})
|
||||
})+'\''
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -111,11 +111,11 @@ See the [wiki](https://ripple.com/wiki/JSON_Messages#subscribe) for details on s
|
||||
//handle ledger
|
||||
});
|
||||
|
||||
remote.on('transaction', function onTransacstion(transaction) {
|
||||
request.on('transaction', function onTransacstion(transaction) {
|
||||
//handle transaction
|
||||
});
|
||||
|
||||
remote.request(function(err) {
|
||||
request.request(function(err) {
|
||||
if (err) {
|
||||
} else {
|
||||
}
|
||||
@@ -186,14 +186,7 @@ var Amount = require('ripple-lib').Amount;
|
||||
|
||||
var MY_ADDRESS = 'rrrMyAddress';
|
||||
var MY_SECRET = 'secret';
|
||||
|
||||
var BUY_AMOUNT = Amount.from_human('100XRP');
|
||||
var SELL_AMOUNT = Amount.from_human('1USD');
|
||||
|
||||
// EXPIRATION must be a Date object, leave undefined to submit offer that won't expire
|
||||
var now = new Date();
|
||||
var tomorrow = new Date(now.getTime() + (24 * 60 * 60 * 1000));
|
||||
var EXPIRATION = tomorrow;
|
||||
var GATEWAY = 'rrrGateWay';
|
||||
|
||||
var remote = new Remote({ /* Remote options */ });
|
||||
|
||||
@@ -202,9 +195,8 @@ remote.connect(function() {
|
||||
|
||||
var transaction = remote.createTransaction('OfferCreate', {
|
||||
account: MY_ADDRESS,
|
||||
buy: BUY_AMOUNT,
|
||||
sell: SELL_AMOUNT,
|
||||
expiration: EXPIRATION
|
||||
taker_pays: '1',
|
||||
taker_gets: '1/USD/' + GATEWAY
|
||||
});
|
||||
|
||||
transaction.submit(function(err, res) {
|
||||
|
||||
142
npm-shrinkwrap.json
generated
Normal file
142
npm-shrinkwrap.json
generated
Normal file
@@ -0,0 +1,142 @@
|
||||
{
|
||||
"name": "ripple-lib",
|
||||
"version": "0.9.0-rc5",
|
||||
"dependencies": {
|
||||
"async": {
|
||||
"version": "0.8.0",
|
||||
"from": "async@>=0.8.0 <0.9.0"
|
||||
},
|
||||
"extend": {
|
||||
"version": "1.2.1",
|
||||
"from": "extend@>=1.2.1 <1.3.0"
|
||||
},
|
||||
"lru-cache": {
|
||||
"version": "2.5.0",
|
||||
"from": "lru-cache@>=2.5.0 <2.6.0"
|
||||
},
|
||||
"ripple-wallet-generator": {
|
||||
"version": "1.0.1",
|
||||
"from": "ripple-wallet-generator@1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/ripple-wallet-generator/-/ripple-wallet-generator-1.0.1.tgz"
|
||||
},
|
||||
"superagent": {
|
||||
"version": "0.18.2",
|
||||
"from": "superagent@>=0.18.0 <0.19.0",
|
||||
"dependencies": {
|
||||
"qs": {
|
||||
"version": "0.6.6",
|
||||
"from": "qs@0.6.6",
|
||||
"resolved": "https://registry.npmjs.org/qs/-/qs-0.6.6.tgz"
|
||||
},
|
||||
"formidable": {
|
||||
"version": "1.0.14",
|
||||
"from": "formidable@1.0.14",
|
||||
"resolved": "https://registry.npmjs.org/formidable/-/formidable-1.0.14.tgz"
|
||||
},
|
||||
"mime": {
|
||||
"version": "1.2.11",
|
||||
"from": "mime@1.2.11",
|
||||
"resolved": "https://registry.npmjs.org/mime/-/mime-1.2.11.tgz"
|
||||
},
|
||||
"component-emitter": {
|
||||
"version": "1.1.2",
|
||||
"from": "component-emitter@1.1.2",
|
||||
"resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.1.2.tgz"
|
||||
},
|
||||
"methods": {
|
||||
"version": "1.0.1",
|
||||
"from": "methods@1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/methods/-/methods-1.0.1.tgz"
|
||||
},
|
||||
"cookiejar": {
|
||||
"version": "2.0.1",
|
||||
"from": "cookiejar@2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.0.1.tgz"
|
||||
},
|
||||
"debug": {
|
||||
"version": "1.0.4",
|
||||
"from": "debug@>=1.0.1 <1.1.0",
|
||||
"dependencies": {
|
||||
"ms": {
|
||||
"version": "0.6.2",
|
||||
"from": "ms@0.6.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-0.6.2.tgz"
|
||||
}
|
||||
}
|
||||
},
|
||||
"reduce-component": {
|
||||
"version": "1.0.1",
|
||||
"from": "reduce-component@1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/reduce-component/-/reduce-component-1.0.1.tgz"
|
||||
},
|
||||
"form-data": {
|
||||
"version": "0.1.3",
|
||||
"from": "form-data@0.1.3",
|
||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-0.1.3.tgz",
|
||||
"dependencies": {
|
||||
"combined-stream": {
|
||||
"version": "0.0.5",
|
||||
"from": "combined-stream@>=0.0.4 <0.1.0",
|
||||
"dependencies": {
|
||||
"delayed-stream": {
|
||||
"version": "0.0.5",
|
||||
"from": "delayed-stream@0.0.5",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-0.0.5.tgz"
|
||||
}
|
||||
}
|
||||
},
|
||||
"async": {
|
||||
"version": "0.9.0",
|
||||
"from": "async@>=0.9.0 <0.10.0"
|
||||
}
|
||||
}
|
||||
},
|
||||
"readable-stream": {
|
||||
"version": "1.0.27-1",
|
||||
"from": "readable-stream@1.0.27-1",
|
||||
"dependencies": {
|
||||
"core-util-is": {
|
||||
"version": "1.0.1",
|
||||
"from": "core-util-is@>=1.0.0 <1.1.0"
|
||||
},
|
||||
"isarray": {
|
||||
"version": "0.0.1",
|
||||
"from": "isarray@0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz"
|
||||
},
|
||||
"string_decoder": {
|
||||
"version": "0.10.31",
|
||||
"from": "string_decoder@>=0.10.0 <0.11.0"
|
||||
},
|
||||
"inherits": {
|
||||
"version": "2.0.1",
|
||||
"from": "inherits@>=2.0.1 <2.1.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"ws": {
|
||||
"version": "0.4.32",
|
||||
"from": "ws@>=0.4.31 <0.5.0",
|
||||
"dependencies": {
|
||||
"commander": {
|
||||
"version": "2.1.0",
|
||||
"from": "commander@>=2.1.0 <2.2.0"
|
||||
},
|
||||
"nan": {
|
||||
"version": "1.0.0",
|
||||
"from": "nan@>=1.0.0 <1.1.0"
|
||||
},
|
||||
"tinycolor": {
|
||||
"version": "0.0.1",
|
||||
"from": "tinycolor@>=0.0.0 <1.0.0"
|
||||
},
|
||||
"options": {
|
||||
"version": "0.0.6",
|
||||
"from": "options@>=0.0.5"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "ripple-lib",
|
||||
"version": "0.8.2-rc2",
|
||||
"description": "Ripple JavaScript client library",
|
||||
"version": "0.9.2-rc5",
|
||||
"description": "A JavaScript API for interacting with Ripple in Node.js and the browser",
|
||||
"files": [
|
||||
"src/js/*",
|
||||
"bin/*",
|
||||
@@ -20,7 +20,6 @@
|
||||
"extend": "~1.2.1",
|
||||
"lru-cache": "~2.5.0",
|
||||
"superagent": "^0.18.0",
|
||||
"gulp-bump": "~0.1.10",
|
||||
"ripple-wallet-generator": "1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
@@ -30,6 +29,7 @@
|
||||
"gulp-jshint": "~1.5.5",
|
||||
"gulp-uglify": "~0.3.0",
|
||||
"gulp-rename": "~1.2.0",
|
||||
"gulp-bump": "~0.1.10",
|
||||
"webpack": "~1.1.11",
|
||||
"map-stream": "~0.1.0",
|
||||
"istanbul": "~0.2.10",
|
||||
@@ -40,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/mocha/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": {
|
||||
|
||||
@@ -132,7 +132,7 @@ Account.prototype.isValid = function() {
|
||||
*/
|
||||
|
||||
Account.prototype.getInfo = function(callback) {
|
||||
return this._remote.request_account_info(this._account_id, callback);
|
||||
return this._remote.requestAccountInfo({account: this._account_id}, callback);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -174,8 +174,8 @@ Account.prototype.getNextSequence = function(callback) {
|
||||
|
||||
function accountInfo(err, info) {
|
||||
if (isNotFound(err)) {
|
||||
// New accounts will start out as sequence zero
|
||||
callback(null, 0);
|
||||
// New accounts will start out as sequence one
|
||||
callback(null, 1);
|
||||
} else if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
@@ -211,7 +211,7 @@ Account.prototype.lines = function(callback) {
|
||||
}
|
||||
}
|
||||
|
||||
this._remote.requestAccountLines(this._account_id, accountLines);
|
||||
this._remote.requestAccountLines({account: this._account_id}, accountLines);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -54,7 +54,9 @@ var consts = {
|
||||
|
||||
// Maximum possible amount for non-XRP currencies using the maximum mantissa
|
||||
// with maximum exponent. Corresponds to hex 0xEC6386F26FC0FFFF.
|
||||
max_value: '9999999999999999e80'
|
||||
max_value: '9999999999999999e80',
|
||||
// Minimum possible amount for non-XRP currencies.
|
||||
min_value: '-1000000000000000e-96'
|
||||
};
|
||||
|
||||
// Add constants to Amount class
|
||||
@@ -424,6 +426,33 @@ Amount.prototype.invert = function() {
|
||||
return this.copy()._invert();
|
||||
};
|
||||
|
||||
/**
|
||||
* Canonicalize amount value
|
||||
*
|
||||
* Mirrors rippled's internal Amount representation
|
||||
* From https://github.com/ripple/rippled/blob/develop/src/ripple/data/protocol/STAmount.h#L31-L40
|
||||
*
|
||||
* Internal form:
|
||||
* 1: If amount is zero, then value is zero and offset is -100
|
||||
* 2: Otherwise:
|
||||
* legal offset range is -96 to +80 inclusive
|
||||
* value range is 10^15 to (10^16 - 1) inclusive
|
||||
* amount = value * [10 ^ offset]
|
||||
*
|
||||
* -------------------
|
||||
*
|
||||
* The amount can be epxresses as A x 10^B
|
||||
* Where:
|
||||
* - A must be an integer between 10^15 and (10^16)-1 inclusive
|
||||
* - B must be between -96 and 80 inclusive
|
||||
*
|
||||
* This results
|
||||
* - minumum: 10^15 x 10^-96 -> 10^-81 -> -1e-81
|
||||
* - maximum: (10^16)-1 x 10^80 -> 9999999999999999e80
|
||||
*
|
||||
* @returns {Amount}
|
||||
* @throws {Error} if offset exceeds legal ranges, meaning the amount value is bigger than supported
|
||||
*/
|
||||
Amount.prototype.canonicalize = function() {
|
||||
if (!(this._value instanceof BigInteger)) {
|
||||
// NaN.
|
||||
@@ -447,9 +476,8 @@ Amount.prototype.canonicalize = function() {
|
||||
}
|
||||
}
|
||||
|
||||
// XXX Make sure not bigger than supported. Throw if so.
|
||||
} else if (this.is_zero()) {
|
||||
this._offset = -100;
|
||||
this._offset = Amount.cMinOffset;
|
||||
this._is_negative = false;
|
||||
} else {
|
||||
// Normalize mantissa to valid range.
|
||||
@@ -465,6 +493,16 @@ Amount.prototype.canonicalize = function() {
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure not bigger than supported. Throw if so.
|
||||
if (this.is_negative() && this._offset < Amount.cMinOffset) {
|
||||
throw new Error('Exceeding min value of ' + Amount.min_value);
|
||||
}
|
||||
|
||||
// Make sure not smaller than supported. Throw if so.
|
||||
if (!this.is_negative() && this._offset > Amount.cMaxOffset) {
|
||||
throw new Error('Exceeding max value of ' + Amount.max_value);
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -539,9 +577,7 @@ Amount.prototype.equals = function(d, ignore_issuer) {
|
||||
return this.equals(Amount.from_json(d));
|
||||
}
|
||||
|
||||
var result = true;
|
||||
|
||||
result = !((!this.is_valid() || !d.is_valid())
|
||||
var result = !((!this.is_valid() || !d.is_valid())
|
||||
|| (this._is_native !== d._is_native)
|
||||
|| (!this._value.equals(d._value) || this._offset !== d._offset)
|
||||
|| (this._is_negative !== d._is_negative)
|
||||
@@ -1109,12 +1145,26 @@ Amount.prototype.to_human = function(opts) {
|
||||
fraction_part = fraction_part.replace(/0*$/, '');
|
||||
|
||||
if (fraction_part.length || !opts.skip_empty_fraction) {
|
||||
|
||||
// Enforce the maximum number of decimal digits (precision)
|
||||
if (typeof opts.precision === 'number') {
|
||||
if (opts.precision === 0 && fraction_part.charCodeAt(0) >= 53) {
|
||||
if (opts.precision <= 0) {
|
||||
|
||||
// increment the int_part if the first decimal is 5 or higher
|
||||
if (fraction_part.charCodeAt(0) >= 53) {
|
||||
int_part = (Number(int_part) + 1).toString();
|
||||
}
|
||||
fraction_part = fraction_part.slice(0, opts.precision);
|
||||
fraction_part = '';
|
||||
} else {
|
||||
var precision = Math.min(opts.precision, fraction_part.length);
|
||||
fraction_part = Math.round(fraction_part / Math.pow(10, fraction_part.length - precision)).toString();
|
||||
|
||||
// because the division above will cut off the leading 0's we have to add them back again
|
||||
// XXX look for a more elegant alternative
|
||||
while (fraction_part.length < precision) {
|
||||
fraction_part = '0' + fraction_part;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Limit the number of significant digits (max_sig_digits)
|
||||
|
||||
@@ -382,23 +382,32 @@ exports.metadata = [
|
||||
];
|
||||
|
||||
exports.ter = {
|
||||
tesSUCCESS: 0,
|
||||
tecCLAIM: 100,
|
||||
tecPATH_PARTIAL: 101,
|
||||
tecUNFUNDED_ADD: 102,
|
||||
tecUNFUNDED_OFFER: 103,
|
||||
tecUNFUNDED_PAYMENT: 104,
|
||||
tecFAILED_PROCESSING: 105,
|
||||
tecDIR_FULL: 121,
|
||||
tecINSUF_RESERVE_LINE: 122,
|
||||
tecINSUF_RESERVE_OFFER: 123,
|
||||
tecNO_DST: 124,
|
||||
tecNO_DST_INSUF_XRP: 125,
|
||||
tecNO_LINE_INSUF_RESERVE: 126,
|
||||
tecNO_LINE_REDUNDANT: 127,
|
||||
tecPATH_DRY: 128,
|
||||
tecUNFUNDED: 129,
|
||||
tecMASTER_DISABLED: 130,
|
||||
tecNO_REGULAR_KEY: 131,
|
||||
tecOWNERS: 132
|
||||
tesSUCCESS : 0,
|
||||
tecCLAIM : 100,
|
||||
tecPATH_PARTIAL : 101,
|
||||
tecUNFUNDED_ADD : 102,
|
||||
tecUNFUNDED_OFFER : 103,
|
||||
tecUNFUNDED_PAYMENT : 104,
|
||||
tecFAILED_PROCESSING : 105,
|
||||
tecDIR_FULL : 121,
|
||||
tecINSUF_RESERVE_LINE : 122,
|
||||
tecINSUF_RESERVE_OFFER : 123,
|
||||
tecNO_DST : 124,
|
||||
tecNO_DST_INSUF_XRP : 125,
|
||||
tecNO_LINE_INSUF_RESERVE : 126,
|
||||
tecNO_LINE_REDUNDANT : 127,
|
||||
tecPATH_DRY : 128,
|
||||
tecUNFUNDED : 129, // Deprecated, old ambiguous unfunded.
|
||||
tecMASTER_DISABLED : 130,
|
||||
tecNO_REGULAR_KEY : 131,
|
||||
tecOWNERS : 132,
|
||||
tecNO_ISSUER : 133,
|
||||
tecNO_AUTH : 134,
|
||||
tecNO_LINE : 135,
|
||||
tecINSUFF_FEE : 136,
|
||||
tecFROZEN : 137,
|
||||
tecNO_TARGET : 138,
|
||||
tecNO_PERMISSION : 139,
|
||||
tecNO_ENTRY : 140,
|
||||
tecINSUFFICIENT_RESERVE : 141
|
||||
};
|
||||
|
||||
@@ -119,7 +119,9 @@ BlobObj.prototype.init = function(fn) {
|
||||
|
||||
self.revision = resp.body.revision;
|
||||
self.encrypted_secret = resp.body.encrypted_secret;
|
||||
self.identity_id = resp.body.identity_id;
|
||||
self.missing_fields = resp.body.missing_fields;
|
||||
//self.attestations = resp.body.attestation_summary;
|
||||
|
||||
if (!self.decrypt(resp.body.blob)) {
|
||||
return fn(new Error('Error while decrypting blob'));
|
||||
@@ -561,7 +563,6 @@ BlobObj.prototype.get2FA = function (fn) {
|
||||
* @params {boolean} options.enabled
|
||||
* @params {string} options.phone
|
||||
* @params {string} options.country_code
|
||||
* @params {string} options.via //sms, etc
|
||||
*/
|
||||
|
||||
BlobObj.prototype.set2FA = function(options, fn) {
|
||||
@@ -572,8 +573,7 @@ BlobObj.prototype.set2FA = function(options, fn) {
|
||||
data : {
|
||||
enabled : options.enabled,
|
||||
phone : options.phone,
|
||||
country_code : options.country_code,
|
||||
via : options.via
|
||||
country_code : options.country_code
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1115,48 +1115,6 @@ BlobClient.recoverBlob = function (opts, fn) {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* updateProfile
|
||||
* update information stored outside the blob - HMAC signed
|
||||
* @param {object}
|
||||
* @param {string} opts.url
|
||||
* @param {string} opts.username
|
||||
* @param {string} opts.auth_secret
|
||||
* @param {srring} opts.blob_id
|
||||
* @param {object} opts.profile
|
||||
* @param {string} opts.profile.phone - optional
|
||||
* @param {string} opts.profile.country - optional
|
||||
* @param {string} opts.profile.region - optional
|
||||
* @param {string} opts.profile.city - optional
|
||||
*/
|
||||
|
||||
BlobClient.updateProfile = function (opts, fn) {
|
||||
var config = {
|
||||
method: 'POST',
|
||||
url: opts.url + '/v1/user/' + opts.username + '/profile',
|
||||
dataType: 'json',
|
||||
data: opts.profile
|
||||
};
|
||||
|
||||
var signedRequest = new SignedRequest(config);
|
||||
var signed = signedRequest.signHmac(opts.auth_secret, opts.blob_id);
|
||||
|
||||
request.post(signed.url)
|
||||
.send(signed.data)
|
||||
.end(function(err, resp) {
|
||||
if (err) {
|
||||
log.error('updateProfile:', err);
|
||||
fn(new Error('Failed to update profile - XHR error'));
|
||||
} else if (resp.body && resp.body.result === 'success') {
|
||||
fn(null, resp.body);
|
||||
} else if (resp.body) {
|
||||
log.error('updateProfile:', resp.body);
|
||||
} else {
|
||||
fn(new Error('Failed to update profile'));
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* updateKeys
|
||||
@@ -1320,6 +1278,7 @@ BlobClient.create = function(options, fn) {
|
||||
if (err) {
|
||||
fn(err);
|
||||
} else if (resp.body && resp.body.result === 'success') {
|
||||
blob.identity_id = resp.body.identity_id;
|
||||
fn(null, blob, resp.body);
|
||||
} else if (resp.body && resp.body.result === 'error') {
|
||||
fn(new Error(resp.body.message));
|
||||
@@ -1363,4 +1322,263 @@ BlobClient.deleteBlob = function(options, fn) {
|
||||
});
|
||||
};
|
||||
|
||||
/*** identity related functions ***/
|
||||
|
||||
/**
|
||||
* updateProfile
|
||||
* update information stored outside the blob - HMAC signed
|
||||
* @param {object}
|
||||
* @param {string} opts.url
|
||||
* @param {string} opts.auth_secret
|
||||
* @param {srring} opts.blob_id
|
||||
* @param {object} opts.profile
|
||||
* @param {array} opts.profile.attributes (optional, array of attribute objects)
|
||||
* @param {array} opts.profile.addresses (optional, array of address objects)
|
||||
*
|
||||
* @param {string} attribute.id ... id of existing attribute
|
||||
* @param {string} attribute.name ... attribute name i.e. ripple_address
|
||||
* @param {string} attribute.type ... optional, sub-type of attribute
|
||||
* @param {string} attribute.value ... value of attribute
|
||||
* @param {string} attribute.domain ... corresponding domain
|
||||
* @param {string} attribute.status ... “current”, “removed”, etc.
|
||||
* @param {string} attribute.visibitlity ... “public”, ”private”
|
||||
*/
|
||||
|
||||
BlobClient.updateProfile = function (opts, fn) {
|
||||
var config = {
|
||||
method: 'POST',
|
||||
url: opts.url + '/v1/profile/',
|
||||
dataType: 'json',
|
||||
data: opts.profile
|
||||
};
|
||||
|
||||
var signedRequest = new SignedRequest(config);
|
||||
var signed = signedRequest.signHmac(opts.auth_secret, opts.blob_id);
|
||||
|
||||
request.post(signed.url)
|
||||
.send(signed.data)
|
||||
.end(function(err, resp) {
|
||||
|
||||
if (err) {
|
||||
log.error('updateProfile:', err);
|
||||
fn(new Error('Failed to update profile - XHR error'));
|
||||
} else if (resp.body && resp.body.result === 'success') {
|
||||
fn(null, resp.body);
|
||||
} else if (resp.body) {
|
||||
log.error('updateProfile:', resp.body);
|
||||
fn(new Error('Failed to update profile'));
|
||||
} else {
|
||||
fn(new Error('Failed to update profile'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* getProfile
|
||||
* @param {Object} opts
|
||||
* @param {string} opts.url
|
||||
* @param {string} opts.auth_secret
|
||||
* @param {srring} opts.blob_id
|
||||
*/
|
||||
|
||||
BlobClient.getProfile = function (opts, fn) {
|
||||
var config = {
|
||||
method: 'GET',
|
||||
url: opts.url + '/v1/profile/'
|
||||
};
|
||||
|
||||
var signedRequest = new SignedRequest(config);
|
||||
var signed = signedRequest.signHmac(opts.auth_secret, opts.blob_id);
|
||||
|
||||
request.get(signed.url)
|
||||
.send(signed.data)
|
||||
.end(function(err, resp) {
|
||||
|
||||
if (err) {
|
||||
log.error('getProfile:', err);
|
||||
fn(new Error('Failed to get profile - XHR error'));
|
||||
} else if (resp.body && resp.body.result === 'success') {
|
||||
fn(null, resp.body);
|
||||
} else if (resp.body) {
|
||||
log.error('getProfile:', resp.body);
|
||||
fn(new Error('Failed to get profile'));
|
||||
} else {
|
||||
fn(new Error('Failed to get profile'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* getAttestation
|
||||
* @param {Object} opts
|
||||
* @param {string} opts.url
|
||||
* @param {string} opts.auth_secret
|
||||
* @param {string} opts.blob_id
|
||||
* @param {string} opts.type (email,phone,basic_identity)
|
||||
* @param {object} opts.phone (required for type 'phone')
|
||||
* @param {string} opts.email (required for type 'email')
|
||||
*/
|
||||
|
||||
BlobClient.getAttestation = function (opts, fn) {
|
||||
var params = { };
|
||||
|
||||
if (opts.phone) params.phone = opts.phone;
|
||||
if (opts.email) params.email = opts.email;
|
||||
|
||||
var config = {
|
||||
method: 'POST',
|
||||
url: opts.url + '/v1/attestation/' + opts.type,
|
||||
dataType: 'json',
|
||||
data: params
|
||||
};
|
||||
|
||||
var signedRequest = new SignedRequest(config);
|
||||
var signed = signedRequest.signHmac(opts.auth_secret, opts.blob_id);
|
||||
|
||||
request.post(signed.url)
|
||||
.send(signed.data)
|
||||
.end(function(err, resp) {
|
||||
|
||||
if (err) {
|
||||
log.error('attest:', err);
|
||||
fn(new Error('attestation error - XHR error'));
|
||||
} else if (resp.body && resp.body.result === 'success') {
|
||||
if (resp.body.attestation) {
|
||||
resp.body.decoded = BlobClient.parseAttestation(resp.body.attestation);
|
||||
}
|
||||
|
||||
fn(null, resp.body);
|
||||
} else if (resp.body) {
|
||||
log.error('attestation:', resp.body);
|
||||
fn(new Error('attestation error: ' + resp.body.message || ""));
|
||||
} else {
|
||||
fn(new Error('attestation error'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* getAttestationSummary
|
||||
* @param {Object} opts
|
||||
* @param {string} opts.url
|
||||
* @param {string} opts.auth_secret
|
||||
* @param {string} opts.blob_id
|
||||
*/
|
||||
|
||||
BlobClient.getAttestationSummary = function (opts, fn) {
|
||||
|
||||
|
||||
var config = {
|
||||
method: 'GET',
|
||||
url: opts.url + '/v1/attestation/summary',
|
||||
dataType: 'json'
|
||||
};
|
||||
|
||||
if (opts.full) config.url += '?full=true';
|
||||
|
||||
var signedRequest = new SignedRequest(config);
|
||||
var signed = signedRequest.signHmac(opts.auth_secret, opts.blob_id);
|
||||
|
||||
request.get(signed.url)
|
||||
.send(signed.data)
|
||||
.end(function(err, resp) {
|
||||
|
||||
if (err) {
|
||||
log.error('attest:', err);
|
||||
fn(new Error('attestation error - XHR error'));
|
||||
} else if (resp.body && resp.body.result === 'success') {
|
||||
if (resp.body.attestation) {
|
||||
resp.body.decoded = BlobClient.parseAttestation(resp.body.attestation);
|
||||
}
|
||||
|
||||
fn(null, resp.body);
|
||||
} else if (resp.body) {
|
||||
log.error('attestation:', resp.body);
|
||||
fn(new Error('attestation error: ' + resp.body.message || ""));
|
||||
} else {
|
||||
fn(new Error('attestation error'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* updateAttestation
|
||||
* @param {Object} opts
|
||||
* @param {string} opts.url
|
||||
* @param {string} opts.auth_secret
|
||||
* @param {string} opts.blob_id
|
||||
* @param {string} opts.type (email,phone,profile,identity)
|
||||
* @param {object} opts.phone (required for type 'phone')
|
||||
* @param {object} opts.profile (required for type 'profile')
|
||||
* @param {string} opts.email (required for type 'email')
|
||||
* @param {string} opts.answers (required for type 'identity')
|
||||
* @param {string} opts.token (required for completing email or phone attestations)
|
||||
*/
|
||||
|
||||
BlobClient.updateAttestation = function (opts, fn) {
|
||||
|
||||
var params = { };
|
||||
|
||||
if (opts.phone) params.phone = opts.phone;
|
||||
if (opts.profile) params.profile = opts.profile;
|
||||
if (opts.email) params.email = opts.email;
|
||||
if (opts.token) params.token = opts.token;
|
||||
if (opts.answers) params.answers = opts.answers;
|
||||
|
||||
var config = {
|
||||
method: 'POST',
|
||||
url: opts.url + '/v1/attestation/' + opts.type + '/update',
|
||||
dataType: 'json',
|
||||
data: params
|
||||
};
|
||||
|
||||
var signedRequest = new SignedRequest(config);
|
||||
var signed = signedRequest.signHmac(opts.auth_secret, opts.blob_id);
|
||||
|
||||
request.post(signed.url)
|
||||
.send(signed.data)
|
||||
.end(function(err, resp) {
|
||||
|
||||
if (err) {
|
||||
log.error('attest:', err);
|
||||
fn(new Error('attestation error - XHR error'));
|
||||
} else if (resp.body && resp.body.result === 'success') {
|
||||
if (resp.body.attestation) {
|
||||
resp.body.decoded = BlobClient.parseAttestation(resp.body.attestation);
|
||||
}
|
||||
|
||||
fn(null, resp.body);
|
||||
} else if (resp.body) {
|
||||
log.error('attestation:', resp.body);
|
||||
fn(new Error('attestation error: ' + resp.body.message || ""));
|
||||
} else {
|
||||
fn(new Error('attestation error'));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* parseAttestation
|
||||
* @param {Object} attestation
|
||||
*/
|
||||
|
||||
BlobClient.parseAttestation = function (attestation) {
|
||||
var segments = decodeURIComponent(attestation).split('.');
|
||||
var decoded;
|
||||
|
||||
// base64 decode and parse JSON
|
||||
try {
|
||||
decoded = {
|
||||
header : JSON.parse(crypt.decodeBase64(segments[0])),
|
||||
payload : JSON.parse(crypt.decodeBase64(segments[1])),
|
||||
signature : segments[2]
|
||||
};
|
||||
|
||||
} catch (e) {
|
||||
console.log("invalid attestation:", e);
|
||||
}
|
||||
|
||||
return decoded;
|
||||
};
|
||||
|
||||
exports.BlobClient = BlobClient;
|
||||
|
||||
@@ -322,4 +322,12 @@ Crypt.base64UrlToBase64 = function(encodedData) {
|
||||
return encodedData;
|
||||
};
|
||||
|
||||
/**
|
||||
* base64 to UTF8
|
||||
*/
|
||||
|
||||
Crypt.decodeBase64 = function (data) {
|
||||
return sjcl.codec.utf8String.fromBits(sjcl.codec.base64.toBits(data));
|
||||
}
|
||||
|
||||
exports.Crypt = Crypt;
|
||||
|
||||
@@ -53,11 +53,7 @@ Currency.HEX_CURRENCY_BAD = '0000000000000000000000005852500000000000';
|
||||
Currency.prototype.human_RE = /^\s*([a-zA-Z0-9]{3})(\s*-\s*[- \w]+)?(\s*\(-?\d+\.?\d*%pa\))?\s*$/;
|
||||
|
||||
Currency.from_json = function(j, shouldInterpretXrpAsIou) {
|
||||
if (j instanceof this) {
|
||||
return j.clone();
|
||||
} else {
|
||||
return (new this()).parse_json(j, shouldInterpretXrpAsIou);
|
||||
}
|
||||
return (new Currency()).parse_json(j, shouldInterpretXrpAsIou);
|
||||
};
|
||||
|
||||
Currency.from_human = function(j, opts) {
|
||||
@@ -71,12 +67,9 @@ Currency.prototype.parse_json = function(j, shouldInterpretXrpAsIou) {
|
||||
switch (typeof j) {
|
||||
case 'string':
|
||||
|
||||
if (!j || /^(0|XRP)$/.test(j)) {
|
||||
if (shouldInterpretXrpAsIou) {
|
||||
this.parse_hex(Currency.HEX_CURRENCY_BAD);
|
||||
} else {
|
||||
this.parse_hex(Currency.HEX_ZERO);
|
||||
}
|
||||
// if an empty string is given, fall back to XRP
|
||||
if (!j) {
|
||||
this.parse_hex(shouldInterpretXrpAsIou ? Currency.HEX_CURRENCY_BAD : Currency.HEX_ZERO);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -86,6 +79,17 @@ Currency.prototype.parse_json = function(j, shouldInterpretXrpAsIou) {
|
||||
if (matches) {
|
||||
|
||||
var currencyCode = matches[1];
|
||||
|
||||
// for the currency 'XRP' case
|
||||
// we drop everything else that could have been provided
|
||||
// e.g. 'XRP - Ripple'
|
||||
if (!currencyCode || /^(0|XRP)$/.test(currencyCode)) {
|
||||
this.parse_hex(shouldInterpretXrpAsIou ? Currency.HEX_CURRENCY_BAD : Currency.HEX_ZERO);
|
||||
|
||||
// early break, we can't have interest on XRP
|
||||
break;
|
||||
}
|
||||
|
||||
// the full currency is matched as it is part of the valid currency format, but not stored
|
||||
// var full_currency = matches[2] || '';
|
||||
var interest = matches[3] || '';
|
||||
@@ -270,7 +274,7 @@ Currency.prototype.has_interest = function() {
|
||||
* @returns {number} - interest for provided interval, can be negative for demurred currencies
|
||||
*/
|
||||
Currency.prototype.get_interest_at = function(referenceDate, decimals) {
|
||||
if (!this.has_interest) {
|
||||
if (!this.has_interest()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -316,17 +320,17 @@ Currency.prototype.to_json = function(opts) {
|
||||
var opts = opts || {};
|
||||
|
||||
var currency;
|
||||
var fullName = opts && opts.full_name ? " - " + opts.full_name : "";
|
||||
var fullName = opts && opts.full_name ? ' - ' + opts.full_name : '';
|
||||
opts.show_interest = opts.show_interest !== void(0) ? opts.show_interest : this.has_interest();
|
||||
|
||||
// Any currency with standard properties and a valid code can be abbreviated
|
||||
// in the JSON wire format as the three character code.
|
||||
if (!opts.force_hex && /^[A-Z0-9]{3}$/.test(this._iso_code) && !this.has_interest()) {
|
||||
if (!opts.force_hex && /^[A-Z0-9]{3}$/.test(this._iso_code)) {
|
||||
currency = this._iso_code + fullName;
|
||||
if (opts.show_interest) {
|
||||
var decimals = !isNaN(opts.decimals) ? opts.decimals : void(0);
|
||||
var interestPercentage = this.has_interest() ? this.get_interest_percentage_at(this._interest_start + 3600 * 24 * 365, decimals) : 0;
|
||||
currency += ' (' + interestPercentage + '%pa)';
|
||||
}
|
||||
|
||||
// If there is interest, append the annual interest to the full currency name
|
||||
} else if (!opts.force_hex && this.has_interest()) {
|
||||
var decimals = opts ? opts.decimals : undefined;
|
||||
currency = this._iso_code + fullName + " (" + this.get_interest_percentage_at(this._interest_start + 3600 * 24 * 365, decimals) + "%pa)";
|
||||
} else {
|
||||
|
||||
// Fallback to returning the raw currency hex
|
||||
|
||||
@@ -344,7 +344,7 @@ OrderBook.prototype.requestTransferRate = function(callback) {
|
||||
return this.emit('transfer_rate', this._issuerTransferRate);
|
||||
}
|
||||
|
||||
this._remote.requestAccountInfo(issuer, function(err, info) {
|
||||
this._remote.requestAccountInfo({account: issuer}, function(err, info) {
|
||||
if (err) {
|
||||
// XXX What now?
|
||||
return callback(err);
|
||||
@@ -447,7 +447,7 @@ OrderBook.prototype.requestFundedAmount = function(account, callback) {
|
||||
}
|
||||
|
||||
function requestNativeBalance(callback) {
|
||||
self._remote.requestAccountInfo(account, function(err, info) {
|
||||
self._remote.requestAccountInfo({account: account}, function(err, info) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
} else {
|
||||
@@ -458,10 +458,11 @@ OrderBook.prototype.requestFundedAmount = function(account, callback) {
|
||||
|
||||
function requestLineBalance(callback) {
|
||||
var request = self._remote.requestAccountLines(
|
||||
account, // account
|
||||
void(0), // account index
|
||||
'VALIDATED', // ledger
|
||||
self._issuerGets //peer
|
||||
{
|
||||
account: account,
|
||||
ledger: 'validated',
|
||||
peer: self._issuerGets
|
||||
}
|
||||
);
|
||||
|
||||
request.request(function(err, res) {
|
||||
|
||||
@@ -23,6 +23,7 @@ var Server = require('./server').Server;
|
||||
var Amount = require('./amount').Amount;
|
||||
var Currency = require('./currency').Currency;
|
||||
var UInt160 = require('./uint160').UInt160;
|
||||
var UInt256 = require('./uint256').UInt256;
|
||||
var Transaction = require('./transaction').Transaction;
|
||||
var Account = require('./account').Account;
|
||||
var Meta = require('./meta').Meta;
|
||||
@@ -94,6 +95,8 @@ function Remote(opts, trace) {
|
||||
this.fee_cushion = (typeof opts.fee_cushion === 'number') ? opts.fee_cushion : 1.2;
|
||||
this.max_fee = (typeof opts.max_fee === 'number') ? opts.max_fee : Infinity;
|
||||
|
||||
this.max_attempts = (typeof opts.max_attempts === 'number') ? opts.max_attempts : 10;
|
||||
|
||||
this._ledger_current_index = void(0);
|
||||
this._ledger_hash = void(0);
|
||||
this._ledger_time = void(0);
|
||||
@@ -943,15 +946,24 @@ Remote.prototype.requestLedger = function(options, callback) {
|
||||
break;
|
||||
|
||||
case 'object':
|
||||
if (!options) break;
|
||||
|
||||
Object.keys(options).forEach(function(o) {
|
||||
switch (o) {
|
||||
case 'full':
|
||||
case 'expand':
|
||||
case 'transactions':
|
||||
case 'accounts':
|
||||
request.message[o] = true;
|
||||
break;
|
||||
case 'ledger_index':
|
||||
case 'ledger_hash':
|
||||
request.message[o] = true;
|
||||
request.message[o] = options[o];
|
||||
break;
|
||||
case 'closed' :
|
||||
case 'current' :
|
||||
case 'validated' :
|
||||
request.message.ledger_index = o;
|
||||
break;
|
||||
}
|
||||
}, options);
|
||||
@@ -1187,19 +1199,42 @@ Remote.prototype.requestTx = function(hash, callback) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Account request abstraction
|
||||
* Account Request
|
||||
*
|
||||
* @api private
|
||||
* Optional paging with limit and marker options
|
||||
* supported in rippled for 'account_lines' and 'account_offers'
|
||||
*
|
||||
* The paged responses aren't guaranteed to be reliable between
|
||||
* ledger closes. You have to supply a ledger_index or ledger_hash
|
||||
* when paging to ensure a complete response
|
||||
*
|
||||
* @param {String} type - request name, e.g. 'account_lines'
|
||||
* @param {String} account - ripple address
|
||||
* @param {Object} options - all optional
|
||||
* @param {String} peer - ripple address
|
||||
* @param [String|Number] ledger identifier
|
||||
* @param [Number] limit - max results per response
|
||||
* @param {String} marker - start position in response paging
|
||||
* @param [Function] callback
|
||||
* @return {Request}
|
||||
*/
|
||||
Remote.accountRequest = function(type, options, callback) {
|
||||
var account, ledger, peer, limit, marker;
|
||||
|
||||
Remote.accountRequest = function(type, account, accountIndex, ledger, peer, callback) {
|
||||
if (typeof account === 'object') {
|
||||
var options = account;
|
||||
callback = accountIndex;
|
||||
if (typeof options === 'object') {
|
||||
account = options.account;
|
||||
ledger = options.ledger;
|
||||
accountIndex = options.account_index || options.accountIndex;
|
||||
account = options.accountID || options.account;
|
||||
peer = options.peer;
|
||||
limit = options.limit;
|
||||
marker = options.marker;
|
||||
}
|
||||
|
||||
// if a marker is given, we need a ledger
|
||||
// check if a valid ledger_index or ledger_hash is provided
|
||||
if (marker) {
|
||||
if (!(Number(ledger) > 0) && !UInt256.is_valid(ledger)) {
|
||||
throw new Error('A ledger_index or ledger_hash must be provided when using a marker');
|
||||
}
|
||||
}
|
||||
|
||||
var lastArg = arguments[arguments.length - 1];
|
||||
@@ -1209,37 +1244,55 @@ Remote.accountRequest = function(type, account, accountIndex, ledger, peer, call
|
||||
}
|
||||
|
||||
var request = new Request(this, type);
|
||||
var account = UInt160.json_rewrite(account);
|
||||
|
||||
request.message.ident = account; //DEPRECATED;
|
||||
if (account) {
|
||||
account = UInt160.json_rewrite(account);
|
||||
request.message.account = account;
|
||||
|
||||
if (typeof accountIndex === 'number') {
|
||||
request.message.index = accountIndex;
|
||||
}
|
||||
|
||||
if (!/^(undefined|function)$/.test(typeof ledger)) {
|
||||
request.ledgerChoose(ledger);
|
||||
}
|
||||
request.ledgerSelect(ledger);
|
||||
|
||||
if (!/^(undefined|function)$/.test(typeof peer)) {
|
||||
if (UInt160.is_valid(peer)) {
|
||||
request.message.peer = UInt160.json_rewrite(peer);
|
||||
}
|
||||
|
||||
request.callback(callback);
|
||||
if (!isNaN(Number(limit))) {
|
||||
limit = Number(limit);
|
||||
|
||||
// max for 32-bit unsigned int is 4294967295
|
||||
// we'll clamp to 1e9
|
||||
if (limit > 1e9) {
|
||||
limit = 1e9;
|
||||
}
|
||||
// min for 32-bit unsigned int is 0
|
||||
// we'll clamp to 0
|
||||
if (limit < 0) {
|
||||
limit = 0;
|
||||
}
|
||||
|
||||
request.message.limit = limit;
|
||||
}
|
||||
|
||||
if (marker) {
|
||||
request.message.marker = marker;
|
||||
}
|
||||
|
||||
request.callback(callback);
|
||||
return request;
|
||||
};
|
||||
|
||||
/**
|
||||
* Request account_info
|
||||
*
|
||||
* @param {String} ripple address
|
||||
* @param {Object} options
|
||||
* @param {String} account - ripple address
|
||||
* @param {String} peer - ripple address
|
||||
* @param [String|Number] ledger identifier
|
||||
* @param [Function] callback
|
||||
* @return {Request}
|
||||
*/
|
||||
|
||||
Remote.prototype.requestAccountInfo = function(account, callback) {
|
||||
Remote.prototype.requestAccountInfo = function(options, callback) {
|
||||
var args = Array.prototype.concat.apply(['account_info'], arguments);
|
||||
return Remote.accountRequest.apply(this, args);
|
||||
};
|
||||
@@ -1247,12 +1300,15 @@ Remote.prototype.requestAccountInfo = function(account, callback) {
|
||||
/**
|
||||
* Request account_currencies
|
||||
*
|
||||
* @param {String} ripple address
|
||||
* @param {Object} options
|
||||
* @param {String} account - ripple address
|
||||
* @param {String} peer - ripple address
|
||||
* @param [String|Number] ledger identifier
|
||||
* @param [Function] callback
|
||||
* @return {Request}
|
||||
*/
|
||||
|
||||
Remote.prototype.requestAccountCurrencies = function(account, callback) {
|
||||
Remote.prototype.requestAccountCurrencies = function(options, callback) {
|
||||
var args = Array.prototype.concat.apply(['account_currencies'], arguments);
|
||||
return Remote.accountRequest.apply(this, args);
|
||||
};
|
||||
@@ -1260,15 +1316,24 @@ Remote.prototype.requestAccountCurrencies = function(account, callback) {
|
||||
/**
|
||||
* Request account_lines
|
||||
*
|
||||
* @param {String} ripple address
|
||||
* @param {Number] sub-account index
|
||||
* @param [String|Number] ledger
|
||||
* @param [String] peer
|
||||
* Requests for account_lines support paging, provide a limit and marker
|
||||
* to page through responses.
|
||||
*
|
||||
* The paged responses aren't guaranteed to be reliable between
|
||||
* ledger closes. You have to supply a ledger_index or ledger_hash
|
||||
* when paging to ensure a complete response
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {String} account - ripple address
|
||||
* @param {String} peer - ripple address
|
||||
* @param [String|Number] ledger identifier
|
||||
* @param [Number] limit - max results per response
|
||||
* @param {String} marker - start position in response paging
|
||||
* @param [Function] callback
|
||||
* @return {Request}
|
||||
*/
|
||||
|
||||
Remote.prototype.requestAccountLines = function(account, accountIndex, ledger, peer, callback) {
|
||||
Remote.prototype.requestAccountLines = function(options, callback) {
|
||||
// XXX Does this require the server to be trusted?
|
||||
//utils.assert(this.trusted);
|
||||
var args = Array.prototype.concat.apply(['account_lines'], arguments);
|
||||
@@ -1278,20 +1343,27 @@ Remote.prototype.requestAccountLines = function(account, accountIndex, ledger, p
|
||||
/**
|
||||
* Request account_offers
|
||||
*
|
||||
* @param {String} ripple address
|
||||
* @param {Number] sub-account index
|
||||
* @param [String|Number] ledger
|
||||
* @param [String] peer
|
||||
* Requests for account_offers support paging, provide a limit and marker
|
||||
* to page through responses.
|
||||
*
|
||||
* The paged responses aren't guaranteed to be reliable between
|
||||
* ledger closes. You have to supply a ledger_index or ledger_hash
|
||||
* when paging to ensure a complete response
|
||||
*
|
||||
* @param {Object} options
|
||||
* @param {String} account - ripple address
|
||||
* @param [String|Number] ledger identifier
|
||||
* @param [Number] limit - max results per response
|
||||
* @param {String} marker - start position in response paging
|
||||
* @param [Function] callback
|
||||
* @return {Request}
|
||||
*/
|
||||
|
||||
Remote.prototype.requestAccountOffers = function(account, accountIndex, ledger, callback) {
|
||||
Remote.prototype.requestAccountOffers = function(options, callback) {
|
||||
var args = Array.prototype.concat.apply(['account_offers'], arguments);
|
||||
return Remote.accountRequest.apply(this, args);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Request account_tx
|
||||
*
|
||||
@@ -1307,9 +1379,6 @@ Remote.prototype.requestAccountOffers = function(account, accountIndex, ledger,
|
||||
* @param [Number] offset, defaults to 0
|
||||
* @param [Number] limit
|
||||
*
|
||||
* @param [Function] filter
|
||||
* @param [Function] map
|
||||
* @param [Function] reduce
|
||||
* @param [Function] callback
|
||||
* @return {Request}
|
||||
*/
|
||||
@@ -1595,6 +1664,7 @@ Remote.prototype.requestLedgerAccept = function(callback) {
|
||||
/**
|
||||
* Account root request abstraction
|
||||
*
|
||||
* @this Remote
|
||||
* @api private
|
||||
*/
|
||||
|
||||
@@ -1614,7 +1684,7 @@ Remote.accountRootRequest = function(type, responseFilter, account, ledger, call
|
||||
var request = this.requestLedgerEntry('account_root');
|
||||
|
||||
request.accountRoot(account);
|
||||
request.ledgerChoose(ledger);
|
||||
request.ledgerSelect(ledger);
|
||||
|
||||
request.once('success', function(message) {
|
||||
request.emit(type, responseFilter(message));
|
||||
|
||||
@@ -208,6 +208,13 @@ Request.prototype.ledgerIndex = function(ledger_index) {
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Set either ledger_index or ledger_hash based on heuristic
|
||||
*
|
||||
* @param {Number|String} ledger identifier
|
||||
*/
|
||||
|
||||
Request.prototype.selectLedger =
|
||||
Request.prototype.ledgerSelect = function(ledger) {
|
||||
switch (ledger) {
|
||||
case 'current':
|
||||
@@ -217,10 +224,10 @@ Request.prototype.ledgerSelect = function(ledger) {
|
||||
break;
|
||||
|
||||
default:
|
||||
if (isNaN(ledger)) {
|
||||
if (Number(ledger)) {
|
||||
this.message.ledger_index = Number(ledger);
|
||||
} else if (/^[A-F0-9]+$/.test(ledger)) {
|
||||
this.message.ledger_hash = ledger;
|
||||
} else if ((ledger = Number(ledger))) {
|
||||
this.message.ledger_index = ledger;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -93,9 +93,14 @@ function SHA256_RIPEMD160(bits) {
|
||||
*
|
||||
* {Uint160} (from_json able), specifies the address matching the KeyPair
|
||||
* that is desired.
|
||||
*
|
||||
* @param maxLoops (optional)
|
||||
* {Number} specifies the amount of attempts taken to generate
|
||||
* a matching KeyPair
|
||||
*/
|
||||
Seed.prototype.get_key = function (account) {
|
||||
Seed.prototype.get_key = function (account, maxLoops) {
|
||||
var account_number = 0, address;
|
||||
var max_loops = maxLoops || 1;
|
||||
|
||||
if (!this.is_valid()) {
|
||||
throw new Error('Cannot generate keys from invalid seed!');
|
||||
@@ -103,6 +108,7 @@ Seed.prototype.get_key = function (account) {
|
||||
if (account) {
|
||||
if (typeof account === 'number') {
|
||||
account_number = account;
|
||||
max_loops = account_number+1;
|
||||
} else {
|
||||
address = UInt160.from_json(account);
|
||||
}
|
||||
@@ -121,9 +127,9 @@ Seed.prototype.get_key = function (account) {
|
||||
|
||||
var sec;
|
||||
var key_pair;
|
||||
var max_loops = 1000; // TODO
|
||||
|
||||
do {
|
||||
|
||||
i = 0;
|
||||
|
||||
do {
|
||||
@@ -135,14 +141,14 @@ Seed.prototype.get_key = function (account) {
|
||||
sec = sec.add(private_gen).mod(curve.r);
|
||||
key_pair = KeyPair.from_bn_secret(sec);
|
||||
|
||||
if (--max_loops <= 0) {
|
||||
if (max_loops-- <= 0) {
|
||||
// We are almost certainly looking for an account that would take same
|
||||
// value of $too_long {forever, ...}
|
||||
throw new Error('Too many loops looking for KeyPair yielding '+
|
||||
address.to_json() +' from ' + this.to_json());
|
||||
};
|
||||
} while (address && !key_pair.get_address().equals(address));
|
||||
}
|
||||
|
||||
} while (address && !key_pair.get_address().equals(address));
|
||||
return key_pair;
|
||||
};
|
||||
|
||||
|
||||
@@ -564,7 +564,7 @@ Server.prototype._handleServerStatus = function(message) {
|
||||
this._remote.emit('load', message, this);
|
||||
|
||||
var loadChanged = message.load_base !== this._load_base
|
||||
|| message.load_factor !== this._load_factor
|
||||
|| message.load_factor !== this._load_factor;
|
||||
|
||||
if (loadChanged) {
|
||||
this._load_base = message.load_base;
|
||||
|
||||
@@ -60,7 +60,7 @@ function Transaction(remote) {
|
||||
|
||||
var self = this;
|
||||
|
||||
var remote = remote || { };
|
||||
var remote = remote || void(0);
|
||||
|
||||
this.remote = remote;
|
||||
|
||||
@@ -69,7 +69,7 @@ function Transaction(remote) {
|
||||
|
||||
this._secret = void(0);
|
||||
this._build_path = false;
|
||||
this._maxFee = this.remote.max_fee;
|
||||
this._maxFee = (typeof remote === 'object') ? this.remote.max_fee : void(0);
|
||||
|
||||
this.state = 'unsubmitted';
|
||||
this.finalized = false;
|
||||
@@ -241,7 +241,7 @@ Transaction.prototype.finalize = function(message) {
|
||||
};
|
||||
|
||||
Transaction.prototype._accountSecret = function(account) {
|
||||
return this.remote.secrets[account];
|
||||
return this.remote ? this.remote.secrets[account] : void(0);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -266,6 +266,10 @@ Transaction.prototype.feeUnits = function() {
|
||||
*/
|
||||
|
||||
Transaction.prototype._computeFee = function() {
|
||||
if (!this.remote) {
|
||||
return void(0);
|
||||
}
|
||||
|
||||
var servers = this.remote._servers;
|
||||
var fees = [ ];
|
||||
|
||||
@@ -487,6 +491,23 @@ Transaction.prototype.lastLedger = function(sequence) {
|
||||
return this;
|
||||
};
|
||||
|
||||
/*
|
||||
* Set the transaction's proposed fee. No op when fee parameter
|
||||
* is not 0 or a positive number
|
||||
*
|
||||
* @param {Number} fee The proposed fee
|
||||
*
|
||||
* @returns {Transaction} calling instance for chaining
|
||||
*/
|
||||
Transaction.prototype.maxFee = function(fee) {
|
||||
if (typeof fee === 'number' && fee >= 0) {
|
||||
this._setMaxFee = true;
|
||||
this._maxFee = fee;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
Transaction._pathRewrite = function(path) {
|
||||
if (!Array.isArray(path)) {
|
||||
return;
|
||||
@@ -898,6 +919,10 @@ Transaction.prototype.submit = function(callback) {
|
||||
|
||||
var account = this.tx_json.Account;
|
||||
|
||||
if (!this.remote) {
|
||||
return this.emit('error', new Error('No remote found'));
|
||||
}
|
||||
|
||||
if (!UInt160.is_valid(account)) {
|
||||
return this.emit('error', new RippleError('tejInvalidAccount', 'Account is missing or invalid'));
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ function TransactionManager(account) {
|
||||
this._remote = account._remote;
|
||||
this._nextSequence = void(0);
|
||||
this._maxFee = this._remote.max_fee;
|
||||
this._maxAttempts = this._remote.max_attempts;
|
||||
this._submissionTimeout = this._remote._submission_timeout;
|
||||
this._pending = new PendingQueue();
|
||||
|
||||
@@ -344,7 +345,7 @@ TransactionManager.prototype._request = function(tx) {
|
||||
var self = this;
|
||||
var remote = this._remote;
|
||||
|
||||
if (tx.attempts > 10) {
|
||||
if (tx.attempts > this._maxAttempts) {
|
||||
return tx.emit('error', new RippleError('tejAttemptsExceeded'));
|
||||
}
|
||||
|
||||
|
||||
@@ -575,8 +575,6 @@ VaultClient.prototype.generateDeviceID = function () {
|
||||
|
||||
VaultClient.prototype.resendEmail = blobClient.resendEmail;
|
||||
|
||||
VaultClient.prototype.updateProfile = blobClient.updateProfile;
|
||||
|
||||
VaultClient.prototype.recoverBlob = blobClient.recoverBlob;
|
||||
|
||||
VaultClient.prototype.deleteBlob = blobClient.deleteBlob;
|
||||
@@ -585,5 +583,11 @@ VaultClient.prototype.requestToken = blobClient.requestToken;
|
||||
|
||||
VaultClient.prototype.verifyToken = blobClient.verifyToken;
|
||||
|
||||
VaultClient.prototype.getAttestation = blobClient.getAttestation;
|
||||
|
||||
VaultClient.prototype.updateAttestation = blobClient.updateAttestation;
|
||||
|
||||
VaultClient.prototype.getAttestationSummary = blobClient.getAttestationSummary;
|
||||
|
||||
//export by name
|
||||
exports.VaultClient = VaultClient;
|
||||
|
||||
@@ -29,13 +29,15 @@ describe('Account', function(){
|
||||
|
||||
});
|
||||
|
||||
// XXX: clean up the stubbed out remote methods
|
||||
|
||||
describe('#publicKeyIsActive()', function(){
|
||||
|
||||
it('should respond true if the public key corresponds to the account address and the master key IS NOT disabled', function(){
|
||||
|
||||
var account = new Account({
|
||||
on: function(){},
|
||||
request_account_info: function(address, callback) {
|
||||
requestAccountInfo: function(address, callback) {
|
||||
if (address === 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz') {
|
||||
callback(null, { account_data: {
|
||||
Account: 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz',
|
||||
@@ -56,7 +58,7 @@ describe('Account', function(){
|
||||
|
||||
var account = new Account({
|
||||
on: function(){},
|
||||
request_account_info: function(address, callback) {
|
||||
requestAccountInfo: function(address, callback) {
|
||||
if (address === 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz') {
|
||||
callback(null, { account_data: {
|
||||
Account: 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz',
|
||||
@@ -77,7 +79,7 @@ describe('Account', function(){
|
||||
|
||||
var account = new Account({
|
||||
on: function(){},
|
||||
request_account_info: function(address, callback) {
|
||||
requestAccountInfo: function(address, callback) {
|
||||
if (address === 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz') {
|
||||
callback(null, { account_data: {
|
||||
Account: 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz',
|
||||
@@ -99,7 +101,7 @@ describe('Account', function(){
|
||||
|
||||
var account = new Account({
|
||||
on: function(){},
|
||||
request_account_info: function(address, callback) {
|
||||
requestAccountInfo: function(address, callback) {
|
||||
if (address === 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz') {
|
||||
callback(null, { account_data: {
|
||||
Account: 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz',
|
||||
@@ -121,7 +123,7 @@ describe('Account', function(){
|
||||
|
||||
var account = new Account({
|
||||
on: function(){},
|
||||
request_account_info: function(address, callback) {
|
||||
requestAccountInfo: function(address, callback) {
|
||||
if (address === 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz') {
|
||||
callback(null, { account_data: {
|
||||
Account: 'rKXCummUHnenhYudNb9UoJ4mGBR75vFcgz',
|
||||
@@ -142,7 +144,7 @@ describe('Account', function(){
|
||||
|
||||
var account = new Account({
|
||||
on: function(){},
|
||||
request_account_info: function(address, callback) {
|
||||
requestAccountInfo: function(address, callback) {
|
||||
if (address === 'rLdfp6eoR948KVxfn6EpaaNTKwfwXhzSeQ') {
|
||||
callback({ error: 'remoteError',
|
||||
error_message: 'Remote reported an error.',
|
||||
|
||||
@@ -16,6 +16,92 @@ describe('Amount', function() {
|
||||
assert(Amount.from_json('1').is_positive());
|
||||
});
|
||||
});
|
||||
describe('Positives', function() {
|
||||
it('Number 1', function() {
|
||||
assert(Amount.from_json('1').is_positive());
|
||||
});
|
||||
});
|
||||
// also tested extensively in other cases
|
||||
describe('to_human', function() {
|
||||
it('12345.6789 XAU', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.6789 XAU").to_human(), '12,345.6789');
|
||||
});
|
||||
it('12345.678901234 XAU', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human(), '12,345.678901234');
|
||||
});
|
||||
it('to human, precision -1, should be ignored, precision needs to be >= 0', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human({precision:-1}), '12,346');
|
||||
});
|
||||
it('to human, precision 0', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human({precision:0}), '12,346');
|
||||
});
|
||||
it('to human, precision 1', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human({precision:1}), '12,345.7');
|
||||
});
|
||||
it('to human, precision 2', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human({precision:2}), '12,345.68');
|
||||
});
|
||||
it('to human, precision 3', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human({precision:3}), '12,345.679');
|
||||
});
|
||||
it('to human, precision 4', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human({precision:4}), '12,345.6789');
|
||||
});
|
||||
it('to human, precision 5', function() {
|
||||
assert.strictEqual(Amount.from_human("12345.678901234 XAU").to_human({precision:5}), '12,345.67890');
|
||||
});
|
||||
it('to human, precision -1, should be ignored, precision needs to be >= 0', function() {
|
||||
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:-1}), '0');
|
||||
});
|
||||
it('to human, precision 0', function() {
|
||||
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:0}), '0');
|
||||
});
|
||||
it('to human, precision 1', function() {
|
||||
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:1}), '0.0');
|
||||
});
|
||||
it('to human, precision 2', function() {
|
||||
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:2}), '0.00');
|
||||
});
|
||||
it('to human, precision 5', function() {
|
||||
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:5}), '0.00012');
|
||||
});
|
||||
it('to human, precision 6', function() {
|
||||
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:6}), '0.000123');
|
||||
});
|
||||
it('to human, precision 16', function() {
|
||||
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:16}), '0.00012345');
|
||||
});
|
||||
it('to human, precision 16, min_precision 16', function() {
|
||||
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:16, min_precision:16}), '0.0001234500000000');
|
||||
});
|
||||
it('to human, precision 16, min_precision 12', function() {
|
||||
assert.strictEqual(Amount.from_human("0.00012345 XAU").to_human({precision:16, min_precision:12}), '0.000123450000');
|
||||
});
|
||||
it('to human, precision 0, first decimal 4', function() {
|
||||
assert.strictEqual(Amount.from_human("0.4 XAU").to_human({precision:0}), '0');
|
||||
});
|
||||
it('to human, precision 0, first decimal 5', function() {
|
||||
assert.strictEqual(Amount.from_human("0.5 XAU").to_human({precision:0}), '1');
|
||||
});
|
||||
it('to human, precision 0, first decimal 8', function() {
|
||||
assert.strictEqual(Amount.from_human("0.8 XAU").to_human({precision:0}), '1');
|
||||
});
|
||||
it('to human, precision 0, precision 16', function() {
|
||||
assert.strictEqual(Amount.from_human("0.0 XAU").to_human({precision:16}), '0.0');
|
||||
});
|
||||
it('to human, precision 0, precision 8, min_precision 16', function() {
|
||||
assert.strictEqual(Amount.from_human("0.0 XAU").to_human({precision:8, min_precision:16}), '0.0000000000000000');
|
||||
});
|
||||
it('to human, precision 0, first decimal 8', function() {
|
||||
assert.strictEqual(Amount.from_human("0.8 XAU").to_human({precision:0}), '1');
|
||||
});
|
||||
it('to human, precision 6, min_precision 6, max_sig_digits 20', function() {
|
||||
assert.strictEqual(Amount.from_human("0.0 XAU").to_human({precision: 6, min_precision: 6, max_sig_digits: 20}), '0.000000');
|
||||
});
|
||||
it('to human, precision 16, min_precision 6, max_sig_digits 20', function() {
|
||||
assert.strictEqual(Amount.from_human("0.0 XAU").to_human({precision: 16, min_precision: 6, max_sig_digits: 20}), '0.000000');
|
||||
});
|
||||
});
|
||||
describe('from_human', function() {
|
||||
it('1 XRP', function() {
|
||||
assert.strictEqual(Amount.from_human("1 XRP").to_text_full(), '1/XRP');
|
||||
@@ -1076,4 +1162,80 @@ describe('Amount', function() {
|
||||
assert.strictEqual(demAmount.to_human_full(), '10.75853086191915/XAU (-0.5%pa)/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
});
|
||||
});
|
||||
|
||||
describe('amount limits', function() {
|
||||
it ('max JSON wire limite', function() {
|
||||
assert.strictEqual(Amount.bi_xns_max.toString(), '9000000000000000000');
|
||||
});
|
||||
|
||||
it ('max JSON wire limite', function() {
|
||||
assert.strictEqual(Amount.bi_xns_min.toString(), '-9000000000000000000');
|
||||
});
|
||||
|
||||
it('max mantissa value', function() {
|
||||
assert.strictEqual(Amount.bi_man_max_value.toString(), '9999999999999999');
|
||||
});
|
||||
|
||||
it('min mantissa value', function() {
|
||||
assert.strictEqual(Amount.bi_man_min_value.toString(), '1000000000000000');
|
||||
});
|
||||
|
||||
it ('from_json minimum XRP', function() {
|
||||
console.log('max', Amount.bi_xns_max.toString());
|
||||
var amt = Amount.from_json('-9000000000000000000');
|
||||
assert.strictEqual(amt.to_json(), '-9000000000000000000');
|
||||
});
|
||||
|
||||
it ('from_json maximum XRP', function() {
|
||||
var amt = Amount.from_json('-9000000000000000000');
|
||||
assert.strictEqual(amt.to_json(), '-9000000000000000000');
|
||||
});
|
||||
|
||||
it ('from_json less than minimum XRP', function() {
|
||||
var amt = Amount.from_json('-9000000000000000001');
|
||||
assert.strictEqual(amt.to_json(), '0');
|
||||
});
|
||||
|
||||
it ('from_json more than maximum XRP', function() {
|
||||
var amt = Amount.from_json('9000000000000000001');
|
||||
assert.strictEqual(amt.to_json(), '0');
|
||||
});
|
||||
|
||||
it ('from_json minimum IOU', function() {
|
||||
var amt = Amount.from_json('-1e-81/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
assert.strictEqual(amt._value.toString(), Amount.bi_man_min_value.toString());
|
||||
assert.strictEqual(amt.to_text(), '-1000000000000000e-96');
|
||||
assert.strictEqual(amt.to_text(), Amount.min_value);
|
||||
});
|
||||
|
||||
it('from_json exceed minimum IOU', function() {
|
||||
assert.throws(function() {
|
||||
Amount.from_json('-1e-82/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')
|
||||
}, 'Exceeding min value of ' + Amount.min_value);
|
||||
});
|
||||
|
||||
it ('from_json maximum IOU', function() {
|
||||
var amt = Amount.from_json('9999999999999999e80/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
assert.strictEqual(amt._value.toString(), Amount.bi_man_max_value.toString());
|
||||
assert.strictEqual(amt.to_text(), '9999999999999999e80');
|
||||
});
|
||||
|
||||
it ('from_json exceed maximum IOU', function() {
|
||||
assert.throws(function() {
|
||||
Amount.from_json('9999999999999999e81/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh')
|
||||
}, 'Exceeding max value of ' + Amount.max_value);
|
||||
});
|
||||
|
||||
it ('from_json normalize mantissa to valid max range, lost significant digits', function() {
|
||||
var amt = Amount.from_json('99999999999999999999999999999999/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
assert.strictEqual(amt._value.toString(), Amount.bi_man_max_value.toString());
|
||||
assert.strictEqual(amt.to_text(), '9999999999999999e16');
|
||||
});
|
||||
|
||||
it ('from_json normalize mantissa to min valid range, lost significant digits', function() {
|
||||
var amt = Amount.from_json('-0.0000000000000000000000001/USD/rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh');
|
||||
assert.strictEqual(amt._value.toString(), Amount.bi_man_min_value.toString());
|
||||
assert.strictEqual(amt.to_text(), '-1000000000000000e-40');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
var assert = require('assert');
|
||||
var utils = require('./testutils');
|
||||
var currency = utils.load_module('currency').Currency;
|
||||
var timeUtil = utils.load_module('utils').time;
|
||||
|
||||
describe('Currency', function() {
|
||||
describe('json_rewrite', function() {
|
||||
@@ -16,11 +17,22 @@ describe('Currency', function() {
|
||||
});
|
||||
});
|
||||
describe('from_json', function() {
|
||||
it('from_json().to_json() == "XRP"', function() {
|
||||
var r = currency.from_json();
|
||||
assert(!r.is_valid());
|
||||
assert.strictEqual('XRP', r.to_json());
|
||||
});
|
||||
it('from_json(NaN).to_json() == "XRP"', function() {
|
||||
var r = currency.from_json(NaN);
|
||||
assert(!r.is_valid());
|
||||
assert.strictEqual('XRP', r.to_json());
|
||||
});
|
||||
it('from_json().to_json("") == "XRP"', function() {
|
||||
var r = currency.from_json('');
|
||||
assert(r.is_valid());
|
||||
assert(r.is_native());
|
||||
assert.strictEqual('XRP', r.to_json());
|
||||
});
|
||||
it('from_json("XRP").to_json() == "XRP"', function() {
|
||||
var r = currency.from_json('XRP');
|
||||
assert(r.is_valid());
|
||||
@@ -82,6 +94,9 @@ describe('Currency', function() {
|
||||
var cur = currency.from_human('EUR (0.5361%pa)');
|
||||
assert.strictEqual(cur.to_json(), 'EUR (0.54%pa)');
|
||||
assert.strictEqual(cur.to_json({decimals:4, full_name:'Euro'}), 'EUR - Euro (0.5361%pa)');
|
||||
assert.strictEqual(cur.to_json({decimals:void(0), full_name:'Euro'}), 'EUR - Euro (0.54%pa)');
|
||||
assert.strictEqual(cur.to_json({decimals:undefined, full_name:'Euro'}), 'EUR - Euro (0.54%pa)');
|
||||
assert.strictEqual(cur.to_json({decimals:'henk', full_name:'Euro'}), 'EUR - Euro (0.54%pa)');
|
||||
assert.strictEqual(cur.get_interest_percentage_at(undefined, 4), 0.5361);
|
||||
});
|
||||
it('From human "TYX - 30-Year Treasuries (1.5%pa)"', function() {
|
||||
@@ -100,6 +115,16 @@ describe('Currency', function() {
|
||||
var cur = currency.from_human('INR - 30 Indian Rupees');
|
||||
assert.strictEqual(cur.to_json(), 'INR');
|
||||
});
|
||||
it('From human "XRP"', function() {
|
||||
var cur = currency.from_human('XRP');
|
||||
assert.strictEqual(cur.to_json(), 'XRP');
|
||||
assert(cur.is_native(), true);
|
||||
});
|
||||
it('From human "XRP - Ripples"', function() {
|
||||
var cur = currency.from_human('XRP - Ripples');
|
||||
assert.strictEqual(cur.to_json(), 'XRP');
|
||||
assert(cur.is_native(), true);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -111,8 +136,28 @@ describe('Currency', function() {
|
||||
assert.strictEqual('XRP', currency.from_json(NaN).to_human());
|
||||
});
|
||||
it('"015841551A748AD2C1F76FF6ECB0CCCD00000000") == "015841551A748AD2C1F76FF6ECB0CCCD00000000"', function() {
|
||||
assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human(),
|
||||
'XAU (-0.5%pa)');
|
||||
assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human(), 'XAU (-0.5%pa)');
|
||||
});
|
||||
it('"015841551A748AD2C1F76FF6ECB0CCCD00000000") == "015841551A748AD2C1F76FF6ECB0CCCD00000000"', function() {
|
||||
assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human({full_name:'Gold'}), 'XAU - Gold (-0.5%pa)');
|
||||
});
|
||||
it('to_human interest XAU with full name, do not show interest', function() {
|
||||
assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human({full_name:'Gold', show_interest:false}), 'XAU - Gold');
|
||||
});
|
||||
it('to_human interest XAU with full name, show interest', function() {
|
||||
assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human({full_name:'Gold', show_interest:true}), 'XAU - Gold (-0.5%pa)');
|
||||
});
|
||||
it('to_human interest XAU, do show interest', function() {
|
||||
assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human({show_interest:true}), 'XAU (-0.5%pa)');
|
||||
});
|
||||
it('to_human interest XAU, do not show interest', function() {
|
||||
assert.strictEqual(currency.from_json("015841551A748AD2C1F76FF6ECB0CCCD00000000").to_human({show_interest:false}), 'XAU');
|
||||
});
|
||||
it('to_human with full_name "USD - US Dollar show interest"', function() {
|
||||
assert.strictEqual(currency.from_json('USD').to_human({full_name:'US Dollar', show_interest:true}), 'USD - US Dollar (0%pa)');
|
||||
});
|
||||
it('to_human with full_name "USD - US Dollar do not show interest"', function() {
|
||||
assert.strictEqual(currency.from_json('USD').to_human({full_name:'US Dollar', show_interest:false}), 'USD - US Dollar');
|
||||
});
|
||||
it('to_human with full_name "USD - US Dollar"', function() {
|
||||
assert.strictEqual('USD - US Dollar', currency.from_json('USD').to_human({full_name:'US Dollar'}));
|
||||
@@ -128,6 +173,7 @@ describe('Currency', function() {
|
||||
var cur = currency.from_json("TIM");
|
||||
assert.strictEqual(cur.to_human({full_name: null}), "TIM");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('from_hex', function() {
|
||||
@@ -138,11 +184,21 @@ describe('Currency', function() {
|
||||
assert.strictEqual(cur.to_json(), cur.to_human());
|
||||
});
|
||||
});
|
||||
describe('parse_json(currency obj)', function() {
|
||||
describe('parse_json', function() {
|
||||
it('should parse a currency object', function() {
|
||||
assert.strictEqual('USD', new currency().parse_json(currency.from_json('USD')).to_json());
|
||||
|
||||
assert.strictEqual('USD (0.5%pa)', new currency().parse_json(currency.from_json('USD (0.5%pa)')).to_json());
|
||||
});
|
||||
it('should clone for parse_json on itself', function() {
|
||||
var cur = currency.from_json('USD');
|
||||
var cur2 = currency.from_json(cur);
|
||||
assert.strictEqual(cur.to_json(), cur2.to_json());
|
||||
|
||||
cur = currency.from_hex('015841551A748AD2C1F76FF6ECB0CCCD00000000');
|
||||
cur2 = currency.from_json(cur);
|
||||
assert.strictEqual(cur.to_json(), cur2.to_json());
|
||||
});
|
||||
});
|
||||
|
||||
describe('is_valid', function() {
|
||||
it('Currency.is_valid("XRP")', function() {
|
||||
@@ -183,14 +239,16 @@ describe('Currency', function() {
|
||||
return +(Math.round(num + "e+"+precision) + "e-"+precision);
|
||||
}
|
||||
describe('get_interest_at', function() {
|
||||
it('returns demurred value for demurrage currency', function() {
|
||||
it('should return demurred value for demurrage currency', function() {
|
||||
var cur = currency.from_json('015841551A748AD2C1F76FF6ECB0CCCD00000000');
|
||||
|
||||
// At start, no demurrage should occur
|
||||
assert.equal(1, cur.get_interest_at(443845330));
|
||||
assert.equal(1, precision(cur.get_interest_at(new Date(timeUtil.fromRipple(443845330))), 14));
|
||||
|
||||
// After one year, 0.5% should have occurred
|
||||
assert.equal(0.995, precision(cur.get_interest_at(443845330 + 31536000), 14));
|
||||
assert.equal(0.995, precision(cur.get_interest_at(new Date(timeUtil.fromRipple(443845330 + 31536000))), 14));
|
||||
|
||||
// After one demurrage period, 1/e should have occurred
|
||||
assert.equal(1/Math.E, cur.get_interest_at(443845330 + 6291418827.05));
|
||||
@@ -201,6 +259,11 @@ describe('Currency', function() {
|
||||
// One demurrage period before start, rate should be e
|
||||
assert.equal(Math.E, cur.get_interest_at(443845330 - 6291418827.05));
|
||||
});
|
||||
it('should return 0 for currency without interest', function() {
|
||||
var cur = currency.from_json('USD - US Dollar');
|
||||
assert.equal(0, cur.get_interest_at(443845330));
|
||||
assert.equal(0, cur.get_interest_at(443845330 + 31536000));
|
||||
});
|
||||
});
|
||||
describe('get_iso', function() {
|
||||
it('should get "XRP" iso_code', function() {
|
||||
|
||||
@@ -270,7 +270,8 @@ describe('Message', function(){
|
||||
//Remote.prototype.addServer = function(){};
|
||||
var test_remote = new Remote();
|
||||
test_remote.state = 'online';
|
||||
test_remote.request_account_info = function(account, callback) {
|
||||
test_remote.requestAccountInfo = function(options, callback) {
|
||||
var account = options.account;
|
||||
if (account === data.account) {
|
||||
callback(null, {
|
||||
"account_data": {
|
||||
@@ -306,7 +307,8 @@ describe('Message', function(){
|
||||
//Remote.prototype.addServer = function(){};
|
||||
var test_remote = new Remote();
|
||||
test_remote.state = 'online';
|
||||
test_remote.request_account_info = function(account, callback) {
|
||||
test_remote.requestAccountInfo = function(options, callback) {
|
||||
var account = options.account;
|
||||
if (account === data.account) {
|
||||
callback(null, {
|
||||
"account_data": {
|
||||
|
||||
@@ -276,7 +276,6 @@ describe('OrderBook', function() {
|
||||
assert.deepEqual(request.message, {
|
||||
command: 'account_info',
|
||||
id: void(0),
|
||||
ident: 'rrrrrrrrrrrrrrrrrrrrBZbvji',
|
||||
account: 'rrrrrrrrrrrrrrrrrrrrBZbvji'
|
||||
});
|
||||
request.emit('success', {
|
||||
@@ -1360,7 +1359,6 @@ describe('OrderBook', function() {
|
||||
assert.deepEqual(request.message, {
|
||||
command: 'account_info',
|
||||
id: undefined,
|
||||
ident: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B',
|
||||
account: 'rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B'
|
||||
});
|
||||
|
||||
|
||||
@@ -5,7 +5,14 @@ var Remote = utils.load_module('remote').Remote;
|
||||
var Server = utils.load_module('server').Server;
|
||||
var Request = utils.load_module('request').Request;
|
||||
|
||||
var options, spy, mock, stub, remote, callback, database, tx;
|
||||
var options, remote, callback, database, tx;
|
||||
|
||||
var ADDRESS = 'r4qLSAzv4LZ9TLsR7diphGwKnSEAMQTSjS';
|
||||
var PEER_ADDRESS = 'rfYv1TXnwgDDK4WQNbFALykYuEBnrR4pDX';
|
||||
var LEDGER_INDEX = 9592219;
|
||||
var LEDGER_HASH = 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE';
|
||||
var PAGING_MARKER = '29F992CC252056BF690107D1E8F2D9FBAFF29FF107B62B1D1F4E4E11ADF2CC73';
|
||||
|
||||
|
||||
describe('Remote', function () {
|
||||
beforeEach(function () {
|
||||
@@ -28,10 +35,10 @@ describe('Remote', function () {
|
||||
// 'bitcoin': 'localhost:3000'
|
||||
// 'bitcoin': 'https://www.bitstamp.net/ripple/bridge/out/bitcoin/'
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
};
|
||||
})
|
||||
});
|
||||
|
||||
it('remote server initialization - url object', function() {
|
||||
var remote = new Remote({
|
||||
@@ -144,7 +151,7 @@ describe('Remote', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('request constructors', function () {
|
||||
describe('request constructors', function () {
|
||||
beforeEach(function () {
|
||||
callback = function () {}
|
||||
remote = new Remote(options);
|
||||
@@ -184,7 +191,222 @@ describe('Remote', function () {
|
||||
var request = remote.request_unl_delete(null, {}, callback);
|
||||
assert(request instanceof Request);
|
||||
});
|
||||
})
|
||||
|
||||
it('request account currencies with ledger index', function() {
|
||||
var request = remote.requestAccountCurrencies({account: ADDRESS});
|
||||
assert.strictEqual(request.message.command, 'account_currencies');
|
||||
assert.strictEqual(request.message.account, ADDRESS);
|
||||
});
|
||||
|
||||
it('request account info with ledger index', function() {
|
||||
var request = remote.requestAccountInfo({account: ADDRESS, ledger: 9592219});
|
||||
assert.strictEqual(request.message.command, 'account_info');
|
||||
assert.strictEqual(request.message.account, ADDRESS);
|
||||
assert.strictEqual(request.message.ledger_index, 9592219);
|
||||
});
|
||||
it('request account info with ledger hash', function() {
|
||||
var request = remote.requestAccountInfo({account: ADDRESS, ledger: LEDGER_HASH});
|
||||
assert.strictEqual(request.message.command, 'account_info');
|
||||
assert.strictEqual(request.message.account, ADDRESS);
|
||||
assert.strictEqual(request.message.ledger_hash, LEDGER_HASH);
|
||||
});
|
||||
it('request account info with ledger identifier', function() {
|
||||
var request = remote.requestAccountInfo({account: ADDRESS, ledger: 'validated'});
|
||||
assert.strictEqual(request.message.command, 'account_info');
|
||||
assert.strictEqual(request.message.account, ADDRESS);
|
||||
assert.strictEqual(request.message.ledger_index, 'validated');
|
||||
});
|
||||
|
||||
it('request account balance with ledger index', function() {
|
||||
var request = remote.requestAccountBalance(ADDRESS, 9592219);
|
||||
assert.strictEqual(request.message.command, 'ledger_entry');
|
||||
assert.strictEqual(request.message.account_root, ADDRESS);
|
||||
assert.strictEqual(request.message.ledger_index, 9592219);
|
||||
});
|
||||
it('request account balance with ledger hash', function() {
|
||||
var request = remote.requestAccountBalance(ADDRESS, LEDGER_HASH);
|
||||
assert.strictEqual(request.message.command, 'ledger_entry');
|
||||
assert.strictEqual(request.message.account_root, ADDRESS);
|
||||
assert.strictEqual(request.message.ledger_hash, LEDGER_HASH);
|
||||
});
|
||||
it('request account balance with ledger identifier', function() {
|
||||
var request = remote.requestAccountBalance(ADDRESS, 'validated');
|
||||
assert.strictEqual(request.message.command, 'ledger_entry');
|
||||
assert.strictEqual(request.message.account_root, ADDRESS);
|
||||
assert.strictEqual(request.message.ledger_index, 'validated');
|
||||
});
|
||||
});
|
||||
|
||||
it('pagingAccountRequest', function() {
|
||||
var request = Remote.accountRequest('account_lines', {account: ADDRESS});
|
||||
assert.deepEqual(request.message, {
|
||||
command: 'account_lines',
|
||||
id: undefined,
|
||||
account: ADDRESS
|
||||
});
|
||||
});
|
||||
|
||||
it('pagingAccountRequest - limit', function() {
|
||||
var request = Remote.accountRequest('account_lines', {account: ADDRESS, limit: 100});
|
||||
assert.deepEqual(request.message, {
|
||||
command: 'account_lines',
|
||||
id: undefined,
|
||||
account: ADDRESS,
|
||||
limit: 100
|
||||
});
|
||||
});
|
||||
|
||||
it('pagingAccountRequest - limit, marker', function() {
|
||||
var request = Remote.accountRequest('account_lines', {account: ADDRESS, limit: 100, marker: PAGING_MARKER, ledger: 9592219});
|
||||
assert.deepEqual(request.message, {
|
||||
command: 'account_lines',
|
||||
id: undefined,
|
||||
account: ADDRESS,
|
||||
limit: 100,
|
||||
marker: PAGING_MARKER,
|
||||
ledger_index: 9592219
|
||||
});
|
||||
|
||||
assert(!request.requested);
|
||||
});
|
||||
|
||||
it('accountRequest - limit min', function() {
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: 0}).message.limit, 0);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: -1}).message.limit, 0);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: -1e9}).message.limit, 0);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: -1e24}).message.limit, 0);
|
||||
});
|
||||
|
||||
it('accountRequest - limit max', function() {
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: 1e9}).message.limit, 1e9);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: 1e9+1}).message.limit, 1e9);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: 1e10}).message.limit, 1e9);
|
||||
assert.strictEqual(Remote.accountRequest('account_lines', {account: ADDRESS, limit: 1e24}).message.limit, 1e9);
|
||||
});
|
||||
|
||||
it('accountRequest - a valid ledger is required when using a marker', function() {
|
||||
assert.throws(function() {
|
||||
Remote.accountRequest('account_lines', {account: ADDRESS, marker: PAGING_MARKER})
|
||||
},'A ledger_index or ledger_hash must be provided when using a marker');
|
||||
|
||||
assert.throws(function() {
|
||||
Remote.accountRequest('account_lines', {account: ADDRESS, marker: PAGING_MARKER, ledger:'validated'})
|
||||
},'A ledger_index or ledger_hash must be provided when using a marker');
|
||||
|
||||
assert.throws(function() {
|
||||
Remote.accountRequest('account_lines', {account: ADDRESS, marker: PAGING_MARKER, ledger:NaN})
|
||||
},'A ledger_index or ledger_hash must be provided when using a marker');
|
||||
|
||||
assert.throws(function() {
|
||||
Remote.accountRequest('account_lines', {account: ADDRESS, marker: PAGING_MARKER, ledger:LEDGER_HASH.substr(0,63)})
|
||||
},'A ledger_index or ledger_hash must be provided when using a marker');
|
||||
|
||||
assert.throws(function() {
|
||||
Remote.accountRequest('account_lines', {account: ADDRESS, marker: PAGING_MARKER, ledger:LEDGER_HASH+'F'})
|
||||
},'A ledger_index or ledger_hash must be provided when using a marker');
|
||||
});
|
||||
|
||||
it('requestAccountLines, account and callback', function() {
|
||||
var callback = function() {};
|
||||
var remote = new Remote({
|
||||
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
|
||||
});
|
||||
var request = remote.requestAccountLines(
|
||||
{account: ADDRESS},
|
||||
callback
|
||||
);
|
||||
|
||||
assert.deepEqual(request.message, {
|
||||
command: 'account_lines',
|
||||
id: undefined,
|
||||
account: ADDRESS
|
||||
});
|
||||
|
||||
assert(request.requested);
|
||||
});
|
||||
|
||||
it('requestAccountLines, ledger, peer', function() {
|
||||
var callback = function() {};
|
||||
var remote = new Remote({
|
||||
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
|
||||
});
|
||||
var request = remote.requestAccountLines(
|
||||
{
|
||||
account: ADDRESS,
|
||||
ledger: LEDGER_HASH,
|
||||
peer: PEER_ADDRESS
|
||||
},
|
||||
callback
|
||||
);
|
||||
|
||||
assert.deepEqual(request.message, {
|
||||
command: 'account_lines',
|
||||
id: undefined,
|
||||
account: ADDRESS,
|
||||
ledger_hash: LEDGER_HASH,
|
||||
peer: PEER_ADDRESS
|
||||
});
|
||||
|
||||
assert(request.requested);
|
||||
});
|
||||
|
||||
it('requestAccountLines, ledger, peer, limit and marker', function() {
|
||||
var callback = function() {};
|
||||
var remote = new Remote({
|
||||
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
|
||||
});
|
||||
var request = remote.requestAccountLines(
|
||||
{
|
||||
account: ADDRESS,
|
||||
ledger: LEDGER_INDEX,
|
||||
peer: PEER_ADDRESS,
|
||||
limit: 200,
|
||||
marker: PAGING_MARKER
|
||||
},
|
||||
callback
|
||||
);
|
||||
|
||||
assert.deepEqual(request.message, {
|
||||
command: 'account_lines',
|
||||
id: undefined,
|
||||
account: ADDRESS,
|
||||
ledger_index: LEDGER_INDEX,
|
||||
peer: PEER_ADDRESS,
|
||||
limit: 200,
|
||||
marker: PAGING_MARKER
|
||||
});
|
||||
|
||||
assert(request.requested);
|
||||
});
|
||||
|
||||
it('requestAccountOffers, ledger, peer, limit and marker', function() {
|
||||
var callback = function() {};
|
||||
var remote = new Remote({
|
||||
servers: [ { host: 's-west.ripple.com', port: 443, secure: true } ]
|
||||
});
|
||||
var request = remote.requestAccountOffers(
|
||||
{
|
||||
account: ADDRESS,
|
||||
ledger: LEDGER_HASH,
|
||||
peer: PEER_ADDRESS,
|
||||
limit: 32,
|
||||
marker: PAGING_MARKER
|
||||
},
|
||||
callback
|
||||
);
|
||||
|
||||
assert.deepEqual(request.message, {
|
||||
command: 'account_offers',
|
||||
id: undefined,
|
||||
account: ADDRESS,
|
||||
ledger_hash: LEDGER_HASH,
|
||||
peer: PEER_ADDRESS,
|
||||
limit: 32,
|
||||
marker: PAGING_MARKER
|
||||
});
|
||||
|
||||
assert(request.requested);
|
||||
});
|
||||
|
||||
it('create remote and get pending transactions', function() {
|
||||
before(function() {
|
||||
@@ -244,7 +466,7 @@ describe('Remote', function () {
|
||||
callback(null, tx);
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
it('should set transaction members correct ', function(done) {
|
||||
remote = new Remote(options);
|
||||
|
||||
@@ -326,6 +326,7 @@ describe('Request', function() {
|
||||
var request = new Request(remote, 'server_info');
|
||||
request.ledgerChoose();
|
||||
assert.strictEqual(request.message.ledger_hash, 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
|
||||
assert.strictEqual(request.message.ledger_index, void(0));
|
||||
});
|
||||
|
||||
it('Select ledger - identifier', function() {
|
||||
@@ -335,6 +336,7 @@ describe('Request', function() {
|
||||
var request = new Request(remote, 'server_info');
|
||||
request.ledgerSelect('validated');
|
||||
assert.strictEqual(request.message.ledger_index, 'validated');
|
||||
assert.strictEqual(request.message.ledger_hash, void(0));
|
||||
});
|
||||
|
||||
it('Select ledger - index', function() {
|
||||
@@ -344,6 +346,7 @@ describe('Request', function() {
|
||||
var request = new Request(remote, 'server_info');
|
||||
request.ledgerSelect(7016915);
|
||||
assert.strictEqual(request.message.ledger_index, 7016915);
|
||||
assert.strictEqual(request.message.ledger_hash, void(0));
|
||||
});
|
||||
|
||||
it('Select ledger - hash', function() {
|
||||
@@ -353,15 +356,23 @@ describe('Request', function() {
|
||||
var request = new Request(remote, 'server_info');
|
||||
request.ledgerSelect('B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
|
||||
assert.strictEqual(request.message.ledger_hash, 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
|
||||
assert.strictEqual(request.message.ledger_index, void(0));
|
||||
});
|
||||
|
||||
it('Select ledger - hash', function() {
|
||||
it('Select ledger - undefined', function() {
|
||||
var remote = new Remote();
|
||||
remote._connected = true;
|
||||
|
||||
var request = new Request(remote, 'server_info');
|
||||
request.ledgerSelect('B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
|
||||
assert.strictEqual(request.message.ledger_hash, 'B4FD84A73DBD8F0DA9E320D137176EBFED969691DC0AAC7882B76B595A0841AE');
|
||||
request.ledgerSelect();
|
||||
assert.strictEqual(request.message.ledger_hash, void(0));
|
||||
assert.strictEqual(request.message.ledger_index, void(0));
|
||||
request.ledgerSelect(null);
|
||||
assert.strictEqual(request.message.ledger_hash, void(0));
|
||||
assert.strictEqual(request.message.ledger_index, void(0));
|
||||
request.ledgerSelect(NaN);
|
||||
assert.strictEqual(request.message.ledger_hash, void(0));
|
||||
assert.strictEqual(request.message.ledger_index, void(0));
|
||||
});
|
||||
|
||||
it('Set account_root', function() {
|
||||
|
||||
@@ -5,7 +5,6 @@ var config = require('./testutils').get_config();
|
||||
|
||||
describe('Seed', function() {
|
||||
it('can generate many addresses', function () {
|
||||
var seed = Seed.from_json("masterpassphrase");
|
||||
|
||||
var test_data = [
|
||||
// Format:
|
||||
@@ -28,10 +27,10 @@ describe('Seed', function() {
|
||||
|
||||
function assert_helper(seed_json, address_or_nth, expected) {
|
||||
var seed = Seed.from_json(seed_json);
|
||||
var keypair = seed.get_key(address_or_nth);
|
||||
assert.strictEqual(keypair.to_hex_pub(),
|
||||
expected);
|
||||
var keypair = seed.get_key(address_or_nth, 500);
|
||||
assert.strictEqual(keypair.to_hex_pub(), expected);
|
||||
}
|
||||
|
||||
for (var nth = 0; nth < test_data.length; nth++) {
|
||||
var seed_json = test_data[nth][0];
|
||||
var address = test_data[nth][1];
|
||||
@@ -47,7 +46,30 @@ describe('Seed', function() {
|
||||
// This isn't too bad as it only needs to generate one keypair `seq`
|
||||
assert_helper(seed_json, nth_for_seed, expected);
|
||||
};
|
||||
|
||||
});
|
||||
|
||||
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);
|
||||
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');
|
||||
try {
|
||||
seed.get_key(address);
|
||||
assert(false, 'should throw an error');
|
||||
} catch(e) {
|
||||
assert.strictEqual(e.message, 'Too many loops looking for KeyPair yielding '+address+' from '+secret);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
// vim:sw=2:sts=2:ts=8:et
|
||||
|
||||
@@ -229,6 +229,11 @@ describe('Transaction', function() {
|
||||
assert.strictEqual(transaction._computeFee(), '72');
|
||||
});
|
||||
|
||||
it('Compute fee, no remote', function() {
|
||||
var transaction = new Transaction();
|
||||
assert.strictEqual(transaction._computeFee(10), void(0));
|
||||
});
|
||||
|
||||
it('Compute fee - no connected server', function() {
|
||||
var remote = new Remote();
|
||||
|
||||
@@ -371,6 +376,16 @@ describe('Transaction', function() {
|
||||
done();
|
||||
});
|
||||
|
||||
it('Complete transaction, local signing, no remote', function(done) {
|
||||
var transaction = new Transaction();
|
||||
transaction._secret = 'sh2pTicynUEG46jjR4EoexHcQEoij';
|
||||
transaction.tx_json.Account = 'rMWwx3Ma16HnqSd4H6saPisihX9aKpXxHJ';
|
||||
|
||||
assert(transaction.complete());
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
it('Complete transaction - untrusted', function(done) {
|
||||
var remote = new Remote();
|
||||
var transaction = new Transaction(remote);
|
||||
@@ -820,6 +835,20 @@ describe('Transaction', function() {
|
||||
assert(transaction._setLastLedger);
|
||||
});
|
||||
|
||||
it('Set Max Fee', function() {
|
||||
var transaction = new Transaction();
|
||||
|
||||
transaction.maxFee('a');
|
||||
assert(!transaction._setMaxFee);
|
||||
|
||||
transaction.maxFee(NaN);
|
||||
assert(!transaction._setMaxFee);
|
||||
|
||||
transaction.maxFee(1000);
|
||||
assert.strictEqual(transaction._maxFee, 1000);
|
||||
assert.strictEqual(transaction._setMaxFee, true);
|
||||
});
|
||||
|
||||
it('Rewrite transaction path', function() {
|
||||
var transaction = new Transaction();
|
||||
|
||||
@@ -1505,6 +1534,18 @@ describe('Transaction', function() {
|
||||
transaction.submit(submitCallback);
|
||||
});
|
||||
|
||||
it('Submit transaction - submission error, no remote', function(done) {
|
||||
var transaction = new Transaction();
|
||||
|
||||
transaction.once('error', function(error) {
|
||||
assert(error);
|
||||
assert.strictEqual(error.message, 'No remote found');
|
||||
done();
|
||||
});
|
||||
|
||||
transaction.submit();
|
||||
});
|
||||
|
||||
it('Submit transaction - invalid account', function(done) {
|
||||
var remote = new Remote();
|
||||
var transaction = new Transaction(remote).accountSet('r36xtKNKR43SeXnGn7kN4r4JdQzcrkqpWe');
|
||||
|
||||
@@ -20,6 +20,7 @@ var exampleData = {
|
||||
email_token : '77825040-9096-4695-9cbc-76720f6a8649',
|
||||
activateLink : 'https://staging.ripple.com/client/#/register/activate/',
|
||||
device_id : "ac1b6f6dbca98190eb9687ba06f0e066",
|
||||
identity_id : "17fddb71-a5c2-44ce-8b50-4b381339d4f2",
|
||||
blob: {
|
||||
url: 'https://id.staging.ripple.com',
|
||||
id: 'ef203d3e76552c0592384f909e6f61f1d1f02f61f07643ce015d8b0c9710dd2f',
|
||||
@@ -104,11 +105,28 @@ var recoverRes = {
|
||||
}
|
||||
}
|
||||
|
||||
var getProfileRes = {
|
||||
"result":"success",
|
||||
"addresses":[],
|
||||
"attributes":[{
|
||||
"attribute_id":"4034e477-ffc9-48c4-bcbc-058293f081d8",
|
||||
"identity_id":"17fddb71-a5c2-44ce-8b50-4b381339d4f2",
|
||||
"name":"email",
|
||||
"type":"default",
|
||||
"domain":null,
|
||||
"value":"example@example.com",
|
||||
"visibility":"public",
|
||||
"updated":null
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
var blob = new Blob();
|
||||
blob.url = exampleData.blob.url;
|
||||
blob.id = exampleData.blob.id;
|
||||
blob.device_id = exampleData.device_id;
|
||||
blob.key = exampleData.blob.key;
|
||||
blob.identity_id = exampleData.blob.identity_id;
|
||||
blob.data = exampleData.blob.data;
|
||||
blob.revision = exampleData.blob.data.revision;
|
||||
|
||||
@@ -133,14 +151,12 @@ var mockDelete;
|
||||
|
||||
if (!online) {
|
||||
mockRippleTxt = nock('https://ripple.com')
|
||||
.persist()
|
||||
.get('/ripple.txt')
|
||||
.reply(200, rippleTxtRes, {
|
||||
'Content-Type': 'text/plain'
|
||||
});
|
||||
|
||||
mockRippleTxt2 = nock('https://' + exampleData.domain)
|
||||
.persist()
|
||||
.get('/ripple.txt')
|
||||
.reply(200, rippleTxtRes, {
|
||||
'Content-Type': 'text/plain'
|
||||
@@ -153,21 +169,21 @@ if (!online) {
|
||||
'Content-Type': 'text/plain'
|
||||
});
|
||||
|
||||
mockRegister = nock('https://id.staging.ripple.com').persist();
|
||||
mockRegister = nock('https://id.staging.ripple.com');
|
||||
mockRegister.filteringPath(/(v1\/user\?signature(.+))/g, 'register/')
|
||||
.post('/register/')
|
||||
.reply(200, { result: 'error', message: 'User already exists' }, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
mockDelete = nock('https://id.staging.ripple.com').persist();
|
||||
mockDelete = nock('https://id.staging.ripple.com');
|
||||
mockDelete.filteringPath(/(v1\/user\/(.+))/g, 'delete/')
|
||||
.delete('/delete/')
|
||||
.reply(200, { result: 'success' }, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
mockBlob = nock('https://id.staging.ripple.com').persist();
|
||||
mockBlob = nock('https://id.staging.ripple.com');
|
||||
mockBlob.get('/v1/authinfo?domain=' + exampleData.domain + '&username=' + exampleData.username.toLowerCase())
|
||||
.reply(200, JSON.stringify(authInfoRes.body), {
|
||||
'Content-Type': 'application/json'
|
||||
@@ -185,47 +201,40 @@ if (!online) {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
mockRename = nock('https://id.staging.ripple.com/v1/user/').persist();
|
||||
mockRename = nock('https://id.staging.ripple.com/v1/user/');
|
||||
mockRename.filteringPath(/((.+)\/rename(.+))/g, 'rename/')
|
||||
.post('rename/')
|
||||
.reply(200, {result:'success',message:'rename'}, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
mockUpdate = nock('https://id.staging.ripple.com/v1/user/').persist();
|
||||
mockUpdate.filteringPath(/((.+)\/update(.+))/g, 'update/')
|
||||
mockUpdate = nock('https://id.staging.ripple.com/v1/user/');
|
||||
mockUpdate.filteringPath(/((.+)\/updatekeys(.+))/g, 'update/')
|
||||
.post('update/')
|
||||
.reply(200, {result:'success',message:'updateKeys'}, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
mockRecover = nock('https://id.staging.ripple.com/').persist();
|
||||
mockRecover = nock('https://id.staging.ripple.com/')
|
||||
mockRecover.filteringPath(/((.+)user\/recov\/(.+))/g, 'recov/')
|
||||
.get('recov/')
|
||||
.reply(200, recoverRes.body, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
mockVerify = nock('https://id.staging.ripple.com/v1/user/').persist();
|
||||
mockVerify = nock('https://id.staging.ripple.com/v1/user/');
|
||||
mockVerify.filteringPath(/((.+)\/verify(.+))/g, 'verify/')
|
||||
.get('verify/')
|
||||
.reply(200, {result:'error', message:'invalid token'}, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
mockEmail = nock('https://id.staging.ripple.com/v1/user').persist();
|
||||
mockEmail = nock('https://id.staging.ripple.com/v1/user');
|
||||
mockEmail.filteringPath(/((.+)\/email(.+))/g, 'email/')
|
||||
.post('email/')
|
||||
.reply(200, {result:'success'}, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
|
||||
mockProfile = nock('https://id.staging.ripple.com/v1/user').persist();
|
||||
mockProfile.filteringPath(/((.+)\/profile(.+))/g, 'profile/')
|
||||
.post('profile/')
|
||||
.reply(200, {result:'success'}, {
|
||||
'Content-Type': 'application/json'
|
||||
});
|
||||
}
|
||||
|
||||
describe('Ripple Txt', function () {
|
||||
@@ -419,6 +428,7 @@ describe('VaultClient', function () {
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
describe('#updateProfile', function () {
|
||||
it('should update profile parameters associated with a blob', function (done) {
|
||||
this.timeout(10000);
|
||||
@@ -442,7 +452,7 @@ describe('VaultClient', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
*/
|
||||
|
||||
});
|
||||
|
||||
@@ -694,6 +704,94 @@ describe('Blob', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('identityVault', function() {
|
||||
it('#identity - Get Attestation', function (done) {
|
||||
var options = {
|
||||
url : blob.url,
|
||||
auth_secret : blob.data.auth_secret,
|
||||
blob_id : blob.id,
|
||||
};
|
||||
|
||||
options.type = 'identity';
|
||||
|
||||
nock('https://id.staging.ripple.com')
|
||||
.filteringPath(/(v1\/attestation\/identity(.+))/g, '')
|
||||
.post('/')
|
||||
.reply(200, {
|
||||
result: 'success',
|
||||
status: 'verified',
|
||||
attestation: 'eyJ6IjoieiJ9.eyJ6IjoieiJ9.sig',
|
||||
blinded:'eyJ6IjoieiJ9.eyJ6IjoieiJ9.sig'
|
||||
}, {'Content-Type': 'application/json'});
|
||||
|
||||
client.getAttestation(options, function(err, resp) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(resp.result, 'success');
|
||||
assert.strictEqual(typeof resp.attestation, 'string');
|
||||
assert.strictEqual(typeof resp.blinded, 'string');
|
||||
assert.deepEqual(resp.decoded, {"header":{"z":"z"},"payload":{"z":"z"},"signature":"sig"})
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('#identity - Update Attestation', function (done) {
|
||||
|
||||
var options = {
|
||||
url : blob.url,
|
||||
auth_secret : blob.data.auth_secret,
|
||||
blob_id : blob.id,
|
||||
};
|
||||
|
||||
options.type = 'identity';
|
||||
|
||||
nock('https://id.staging.ripple.com')
|
||||
.filteringPath(/(v1\/attestation\/identity\/update(.+))/g, '')
|
||||
.post('/')
|
||||
.reply(200, {
|
||||
result: 'success',
|
||||
status: 'verified',
|
||||
attestation: 'eyJ6IjoieiJ9.eyJ6IjoieiJ9.sig',
|
||||
blinded:'eyJ6IjoieiJ9.eyJ6IjoieiJ9.sig'
|
||||
}, {'Content-Type': 'application/json'});
|
||||
|
||||
client.updateAttestation(options, function(err, resp) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(resp.result, 'success');
|
||||
assert.strictEqual(typeof resp.attestation, 'string');
|
||||
assert.strictEqual(typeof resp.blinded, 'string');
|
||||
assert.deepEqual(resp.decoded, {"header":{"z":"z"},"payload":{"z":"z"},"signature":"sig"})
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('#identity - Get Attestation Summary', function (done) {
|
||||
|
||||
var options = {
|
||||
url : blob.url,
|
||||
auth_secret : blob.data.auth_secret,
|
||||
blob_id : blob.id,
|
||||
};
|
||||
|
||||
nock('https://id.staging.ripple.com')
|
||||
.filteringPath(/(v1\/attestation\/summary(.+))/g, '')
|
||||
.get('/')
|
||||
.reply(200, {
|
||||
result: 'success',
|
||||
attestation: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjY2ZGI3MzgxIn0%3D.eyJwcm9maWxlX3ZlcmlmaWVkIjpmYWxzZSwiaWRlbnRpdHlfdmVyaWZpZWQiOmZhbHNlLCJpc3MiOiJodHRwczovL2lkLnJpcHBsZS5jb20iLCJzdWIiOiIwNDMzNTA0ZS0yYTRmLTQ1NjktODQwMi1lYWI2YTU0YTgzYjUiLCJleHAiOjE0MTI4MTc2NjksImlhdCI6MTQxMjgxNTgwOX0%3D.Jt14Y2TsM7fKqGWn0j16cPldlYqRr7%2F2dptBsdZuZhRGRTREO4TSpZZhBaU95WL3M9eXIfaoSs8f2pTOa%2BBGAYHZSZK4%2FLqeWdDH8zz8Bx9YFqGije1KmHQR%2FeoWSp1GTEfcq5Oho4nSHozHhGNN8IrDkl8woMvWb%2FE1938Y5Zl2vyv7wjlNUF4ND33XWzJkvQjzIK15uYfaB%2FUIsNW32udfHAdkigesdMDNm%2BRGBqHMDZeAMdVxzrDzE3m8oWKDMJXbcaLmk75COfJrLWYiZCHd7VcReyPEZegwEucetZJ9uDnoBcvw0%2B6hIRmjTN6Gy1eeBoJaiDYsWuOwInbIlw%3D%3D',
|
||||
}, {'Content-Type': 'application/json'});
|
||||
|
||||
client.getAttestationSummary(options, function(err, resp) {
|
||||
assert.ifError(err);
|
||||
assert.strictEqual(resp.result, 'success');
|
||||
assert.strictEqual(typeof resp.attestation, 'string');
|
||||
assert.strictEqual(typeof resp.decoded.header, 'object');
|
||||
assert.strictEqual(typeof resp.decoded.payload, 'object');
|
||||
assert.strictEqual(typeof resp.decoded.signature, 'string');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
//only do these offline
|
||||
if (!online) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user