mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-05 05:15:48 +00:00
Compare commits
11 Commits
v0.8.3-rc1
...
v0.9.0-rc2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e74e697b45 | ||
|
|
26c59e8565 | ||
|
|
a5e83c4f23 | ||
|
|
900c4bbd2e | ||
|
|
947ec3edc2 | ||
|
|
957f10d9f1 | ||
|
|
89aa54dff8 | ||
|
|
bb76530e4b | ||
|
|
011e2cc1e3 | ||
|
|
4c594f8964 | ||
|
|
23e473b688 |
@@ -1,11 +1,15 @@
|
||||
##0.8.3
|
||||
##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))
|
||||
|
||||
+ Fix: change handling of requestLedger options ([57b7030](https://github.com/ripple/ripple-lib/commit/57b70300f5f0c7534ede118ddbb5d8762668a4f8))
|
||||
|
||||
+ **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))
|
||||
|
||||
##0.8.2
|
||||
|
||||
+ Currency: Allow mixed letters and numbers in currencies
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ripple-lib",
|
||||
"version": "0.8.3-rc1",
|
||||
"version": "0.9.0-rc2",
|
||||
"description": "Ripple JavaScript client library",
|
||||
"files": [
|
||||
"src/js/*",
|
||||
@@ -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": {
|
||||
|
||||
@@ -1563,7 +1563,7 @@ BlobClient.updateAttestation = function (opts, fn) {
|
||||
*/
|
||||
|
||||
BlobClient.parseAttestation = function (attestation) {
|
||||
var segments = attestation.split('.');
|
||||
var segments = decodeURIComponent(attestation).split('.');
|
||||
var decoded;
|
||||
|
||||
// base64 decode and parse JSON
|
||||
|
||||
@@ -316,17 +316,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
|
||||
|
||||
@@ -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,15 +141,15 @@ 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));
|
||||
}
|
||||
|
||||
return key_pair;
|
||||
} while (address && !key_pair.get_address().equals(address));
|
||||
return key_pair;
|
||||
};
|
||||
|
||||
exports.Seed = Seed;
|
||||
|
||||
@@ -82,6 +82,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() {
|
||||
@@ -111,8 +114,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 +151,7 @@ describe('Currency', function() {
|
||||
var cur = currency.from_json("TIM");
|
||||
assert.strictEqual(cur.to_human({full_name: null}), "TIM");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('from_hex', 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
|
||||
|
||||
@@ -777,14 +777,16 @@ describe('Blob', function () {
|
||||
.get('/')
|
||||
.reply(200, {
|
||||
result: 'success',
|
||||
attestation: 'eyJ6IjoieiJ9.eyJ6IjoieiJ9.sig',
|
||||
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.deepEqual(resp.decoded, {"header":{"z":"z"},"payload":{"z":"z"},"signature":"sig"})
|
||||
assert.strictEqual(typeof resp.decoded.header, 'object');
|
||||
assert.strictEqual(typeof resp.decoded.payload, 'object');
|
||||
assert.strictEqual(typeof resp.decoded.signature, 'string');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user