mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-21 20:55:48 +00:00
Add new sjcl export for code coverage convenience
This commit is contained in:
8
Makefile
8
Makefile
@@ -1,4 +1,10 @@
|
|||||||
test:
|
test:
|
||||||
./node_modules/.bin/mocha test/*-test.js
|
mocha test/*-test.js
|
||||||
|
|
||||||
|
coverage:
|
||||||
|
rm -rf lib-cov
|
||||||
|
jscoverage src/js/ripple lib-cov
|
||||||
|
RIPPLE_LIB_COV=1 mocha --reporter html-cov test/*-test.js > coverage.html
|
||||||
|
rm -rf lib-cov
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
// Represent Ripple amounts and currencies.
|
// Represent Ripple amounts and currencies.
|
||||||
// - Numbers in hex are big-endian.
|
// - Numbers in hex are big-endian.
|
||||||
|
|
||||||
var sjcl = require('../../../build/sjcl');
|
|
||||||
var bn = sjcl.bn;
|
|
||||||
var utils = require('./utils');
|
var utils = require('./utils');
|
||||||
|
var sjcl = utils.sjcl;
|
||||||
|
var bn = sjcl.bn;
|
||||||
|
|
||||||
var jsbn = require('./jsbn');
|
var jsbn = require('./jsbn');
|
||||||
|
|
||||||
var BigInteger = jsbn.BigInteger;
|
var BigInteger = jsbn.BigInteger;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
var sjcl = require('../../../build/sjcl');
|
var sjcl = require('./utils').sjcl;
|
||||||
var utils = require('./utils');
|
var utils = require('./utils');
|
||||||
var jsbn = require('./jsbn');
|
var jsbn = require('./jsbn');
|
||||||
var extend = require('extend');
|
var extend = require('extend');
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ exports.Server = require('./server').Server;
|
|||||||
// However, for programs that are tied to a specific version of ripple.js like
|
// However, for programs that are tied to a specific version of ripple.js like
|
||||||
// the official client, it makes sense to expose the SJCL instance so we don't
|
// the official client, it makes sense to expose the SJCL instance so we don't
|
||||||
// have to include it twice.
|
// have to include it twice.
|
||||||
exports.sjcl = require('../../../build/sjcl');
|
exports.sjcl = require('./utils').sjcl;
|
||||||
|
|
||||||
exports.config = require('./config');
|
exports.config = require('./config');
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
var sjcl = require('../../../build/sjcl');
|
var sjcl = require('./utils').sjcl;
|
||||||
|
|
||||||
var UInt256 = require('./uint256').UInt256;
|
var UInt256 = require('./uint256').UInt256;
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ var RippleError = require('./rippleerror').RippleError;
|
|||||||
|
|
||||||
var utils = require('./utils');
|
var utils = require('./utils');
|
||||||
var config = require('./config');
|
var config = require('./config');
|
||||||
var sjcl = require('../../../build/sjcl');
|
var sjcl = require('./utils').sjcl;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Interface to manage the connection to a Ripple server.
|
Interface to manage the connection to a Ripple server.
|
||||||
@@ -762,8 +762,9 @@ Remote.prototype.request_tx = function (hash, callback) {
|
|||||||
|
|
||||||
Remote.prototype.request_account_info = function (accountID, callback) {
|
Remote.prototype.request_account_info = function (accountID, callback) {
|
||||||
var request = new Request(this, 'account_info');
|
var request = new Request(this, 'account_info');
|
||||||
request.message.ident = UInt160.json_rewrite(accountID); // DEPRECATED
|
var account = UInt160.json_rewrite(accountID);
|
||||||
request.message.account = UInt160.json_rewrite(accountID);
|
request.message.ident = account; //DEPRECATED;
|
||||||
|
request.message.account = account;
|
||||||
request.callback(callback);
|
request.callback(callback);
|
||||||
return request;
|
return request;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,17 +2,17 @@
|
|||||||
// Seed support
|
// Seed support
|
||||||
//
|
//
|
||||||
|
|
||||||
var sjcl = require('../../../build/sjcl');
|
var sjcl = require('./utils').sjcl;
|
||||||
var utils = require('./utils');
|
var utils = require('./utils');
|
||||||
var jsbn = require('./jsbn');
|
var jsbn = require('./jsbn');
|
||||||
var extend = require('extend');
|
var extend = require('extend');
|
||||||
|
|
||||||
var BigInteger = jsbn.BigInteger;
|
var BigInteger = jsbn.BigInteger;
|
||||||
|
|
||||||
var Base = require('./base').Base,
|
var Base = require('./base').Base;
|
||||||
UInt = require('./uint').UInt,
|
var UInt = require('./uint').UInt;
|
||||||
UInt256 = require('./uint256').UInt256,
|
var UInt256 = require('./uint256').UInt256;
|
||||||
KeyPair = require('./keypair').KeyPair;
|
var KeyPair = require('./keypair').KeyPair;
|
||||||
|
|
||||||
var Seed = extend(function () {
|
var Seed = extend(function () {
|
||||||
// Internal form: NaN or BigInteger
|
// Internal form: NaN or BigInteger
|
||||||
@@ -27,7 +27,7 @@ Seed.prototype.constructor = Seed;
|
|||||||
// value = NaN on error.
|
// value = NaN on error.
|
||||||
// One day this will support rfc1751 too.
|
// One day this will support rfc1751 too.
|
||||||
Seed.prototype.parse_json = function (j) {
|
Seed.prototype.parse_json = function (j) {
|
||||||
if ('string' === typeof j) {
|
if (typeof j === 'string') {
|
||||||
if (!j.length) {
|
if (!j.length) {
|
||||||
this._value = NaN;
|
this._value = NaN;
|
||||||
// XXX Should actually always try and continue if it failed.
|
// XXX Should actually always try and continue if it failed.
|
||||||
@@ -47,7 +47,7 @@ Seed.prototype.parse_json = function (j) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Seed.prototype.parse_passphrase = function (j) {
|
Seed.prototype.parse_passphrase = function (j) {
|
||||||
if ("string" !== typeof j) {
|
if (typeof j !== 'string') {
|
||||||
throw new Error("Passphrase must be a string");
|
throw new Error("Passphrase must be a string");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,8 +60,9 @@ Seed.prototype.parse_passphrase = function (j) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Seed.prototype.to_json = function () {
|
Seed.prototype.to_json = function () {
|
||||||
if (!(this._value instanceof BigInteger))
|
if (!(this._value instanceof BigInteger)) {
|
||||||
return NaN;
|
return NaN;
|
||||||
|
}
|
||||||
|
|
||||||
var output = Base.encode_check(Base.VER_FAMILY_SEED, this.to_bytes());
|
var output = Base.encode_check(Base.VER_FAMILY_SEED, this.to_bytes());
|
||||||
|
|
||||||
@@ -70,18 +71,18 @@ Seed.prototype.to_json = function () {
|
|||||||
|
|
||||||
function append_int(a, i) {
|
function append_int(a, i) {
|
||||||
return [].concat(a, i >> 24, (i >> 16) & 0xff, (i >> 8) & 0xff, i & 0xff);
|
return [].concat(a, i >> 24, (i >> 16) & 0xff, (i >> 8) & 0xff, i & 0xff);
|
||||||
}
|
};
|
||||||
|
|
||||||
function firstHalfOfSHA512(bytes) {
|
function firstHalfOfSHA512(bytes) {
|
||||||
return sjcl.bitArray.bitSlice(
|
return sjcl.bitArray.bitSlice(
|
||||||
sjcl.hash.sha512.hash(sjcl.codec.bytes.toBits(bytes)),
|
sjcl.hash.sha512.hash(sjcl.codec.bytes.toBits(bytes)),
|
||||||
0, 256
|
0, 256
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
function SHA256_RIPEMD160(bits) {
|
function SHA256_RIPEMD160(bits) {
|
||||||
return sjcl.hash.ripemd160.hash(sjcl.hash.sha256.hash(bits));
|
return sjcl.hash.ripemd160.hash(sjcl.hash.sha256.hash(bits));
|
||||||
}
|
};
|
||||||
|
|
||||||
Seed.prototype.get_key = function (account_id) {
|
Seed.prototype.get_key = function (account_id) {
|
||||||
if (!this.is_valid()) {
|
if (!this.is_valid()) {
|
||||||
@@ -89,11 +90,10 @@ Seed.prototype.get_key = function (account_id) {
|
|||||||
}
|
}
|
||||||
// XXX Should loop over keys until we find the right one
|
// XXX Should loop over keys until we find the right one
|
||||||
|
|
||||||
|
var private_gen, public_gen;
|
||||||
var curve = this._curve;
|
var curve = this._curve;
|
||||||
|
var seq = 0, i = 0;
|
||||||
|
|
||||||
var seq = 0;
|
|
||||||
|
|
||||||
var private_gen, public_gen, i = 0;
|
|
||||||
do {
|
do {
|
||||||
private_gen = sjcl.bn.fromBits(firstHalfOfSHA512(append_int(this.to_bytes(), i)));
|
private_gen = sjcl.bn.fromBits(firstHalfOfSHA512(append_int(this.to_bytes(), i)));
|
||||||
i++;
|
i++;
|
||||||
@@ -103,6 +103,7 @@ Seed.prototype.get_key = function (account_id) {
|
|||||||
|
|
||||||
var sec;
|
var sec;
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
sec = sjcl.bn.fromBits(firstHalfOfSHA512(append_int(append_int(public_gen.toBytesCompressed(), seq), i)));
|
sec = sjcl.bn.fromBits(firstHalfOfSHA512(append_int(append_int(public_gen.toBytesCompressed(), seq), i)));
|
||||||
i++;
|
i++;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
var binformat = require('./binformat');
|
var binformat = require('./binformat');
|
||||||
var sjcl = require('../../../build/sjcl');
|
var sjcl = require('./utils').sjcl;
|
||||||
var extend = require('extend');
|
var extend = require('extend');
|
||||||
var stypes = require('./serializedtypes');
|
var stypes = require('./serializedtypes');
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
var extend = require('extend');
|
var extend = require('extend');
|
||||||
var utils = require('./utils');
|
var utils = require('./utils');
|
||||||
var sjcl = require('../../../build/sjcl');
|
var sjcl = require('./utils').sjcl;
|
||||||
|
|
||||||
var amount = require('./amount');
|
var amount = require('./amount');
|
||||||
var UInt128 = require('./uint128').UInt128;
|
var UInt128 = require('./uint128').UInt128;
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
|
|
||||||
var sjcl = require('../../../build/sjcl');
|
var sjcl = require('./utils').sjcl;
|
||||||
|
|
||||||
var Amount = require('./amount').Amount;
|
var Amount = require('./amount').Amount;
|
||||||
var Currency = require('./amount').Currency;
|
var Currency = require('./amount').Currency;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
|
var sjcl = require('./utils').sjcl;
|
||||||
var sjcl = require('../../../build/sjcl');
|
|
||||||
var utils = require('./utils');
|
var utils = require('./utils');
|
||||||
var config = require('./config');
|
var config = require('./config');
|
||||||
var jsbn = require('./jsbn');
|
var jsbn = require('./jsbn');
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
|
var sjcl = require('./utils').sjcl;
|
||||||
var sjcl = require('../../../build/sjcl');
|
|
||||||
var utils = require('./utils');
|
var utils = require('./utils');
|
||||||
var config = require('./config');
|
var config = require('./config');
|
||||||
var jsbn = require('./jsbn');
|
var jsbn = require('./jsbn');
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
var sjcl = require('../../../build/sjcl');
|
var sjcl = require('./utils').sjcl;
|
||||||
var utils = require('./utils');
|
var utils = require('./utils');
|
||||||
var config = require('./config');
|
var config = require('./config');
|
||||||
var jsbn = require('./jsbn');
|
var jsbn = require('./jsbn');
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
|
var sjcl = require('./utils').sjcl;
|
||||||
var sjcl = require('../../../build/sjcl');
|
|
||||||
var utils = require('./utils');
|
var utils = require('./utils');
|
||||||
var config = require('./config');
|
var config = require('./config');
|
||||||
var jsbn = require('./jsbn');
|
var jsbn = require('./jsbn');
|
||||||
|
|||||||
@@ -140,5 +140,13 @@ exports.logObject = logObject;
|
|||||||
exports.assert = assert;
|
exports.assert = assert;
|
||||||
exports.arrayUnique = arrayUnique;
|
exports.arrayUnique = arrayUnique;
|
||||||
exports.toTimestamp = toTimestamp;
|
exports.toTimestamp = toTimestamp;
|
||||||
|
exports.sjcl = (function() {
|
||||||
|
try {
|
||||||
|
var sjcl = require('../../../build/sjcl');
|
||||||
|
} catch(e) {
|
||||||
|
var sjcl = require('../build/sjcl');
|
||||||
|
}
|
||||||
|
return sjcl;
|
||||||
|
})();
|
||||||
|
|
||||||
// vim:sw=2:sts=2:ts=8:et
|
// vim:sw=2:sts=2:ts=8:et
|
||||||
|
|||||||
Reference in New Issue
Block a user