ran js-beautify on all bitcore source
js-beautify -s 2 -r *.js ...did not run on bundles, only on source.
This commit is contained in:
parent
bba0945581
commit
ca67786a77
31
bitcore.js
31
bitcore.js
|
@ -7,19 +7,27 @@ Instead, we can set the 'get' property of each class to only require them when
|
||||||
they are accessed, saving memory if they are not used in a given project.
|
they are accessed, saving memory if they are not used in a given project.
|
||||||
*/
|
*/
|
||||||
var requireWhenAccessed = function(name, file) {
|
var requireWhenAccessed = function(name, file) {
|
||||||
Object.defineProperty(module.exports, name, {get: function() {return require(file)}});
|
Object.defineProperty(module.exports, name, {
|
||||||
|
get: function() {
|
||||||
|
return require(file)
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
requireWhenAccessed('Bignum', 'bignum');
|
requireWhenAccessed('Bignum', 'bignum');
|
||||||
Object.defineProperty(module.exports, 'bignum', {get: function() {
|
Object.defineProperty(module.exports, 'bignum', {
|
||||||
|
get: function() {
|
||||||
console.log('bignum (with a lower-case "b") is deprecated. Use bitcore.Bignum (capital "B") instead.');
|
console.log('bignum (with a lower-case "b") is deprecated. Use bitcore.Bignum (capital "B") instead.');
|
||||||
return require('bignum');
|
return require('bignum');
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
requireWhenAccessed('Base58', './lib/Base58');
|
requireWhenAccessed('Base58', './lib/Base58');
|
||||||
Object.defineProperty(module.exports, 'base58', {get: function() {
|
Object.defineProperty(module.exports, 'base58', {
|
||||||
|
get: function() {
|
||||||
console.log('base58 (with a lower-case "b") is deprecated. Use bitcore.Base58 (capital "B") instead.');
|
console.log('base58 (with a lower-case "b") is deprecated. Use bitcore.Base58 (capital "B") instead.');
|
||||||
return require('./lib/Base58');
|
return require('./lib/Base58');
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
requireWhenAccessed('bufferput', 'bufferput');
|
requireWhenAccessed('bufferput', 'bufferput');
|
||||||
requireWhenAccessed('buffertools', 'buffertools');
|
requireWhenAccessed('buffertools', 'buffertools');
|
||||||
requireWhenAccessed('Buffers.monkey', './patches/Buffers.monkey');
|
requireWhenAccessed('Buffers.monkey', './patches/Buffers.monkey');
|
||||||
|
@ -38,10 +46,12 @@ requireWhenAccessed('VersionedData', './util/VersionedData');
|
||||||
requireWhenAccessed('BinaryParser', './util/BinaryParser');
|
requireWhenAccessed('BinaryParser', './util/BinaryParser');
|
||||||
requireWhenAccessed('Address', './lib/Address');
|
requireWhenAccessed('Address', './lib/Address');
|
||||||
requireWhenAccessed('HierarchicalKey', './lib/HierarchicalKey');
|
requireWhenAccessed('HierarchicalKey', './lib/HierarchicalKey');
|
||||||
Object.defineProperty(module.exports, 'BIP32', {get: function() {
|
Object.defineProperty(module.exports, 'BIP32', {
|
||||||
|
get: function() {
|
||||||
console.log('BIP32 is deprecated. Use bitcore.HierarchicalKey instead.');
|
console.log('BIP32 is deprecated. Use bitcore.HierarchicalKey instead.');
|
||||||
return require('./lib/HierarchicalKey');
|
return require('./lib/HierarchicalKey');
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
requireWhenAccessed('BIP39', './lib/BIP39');
|
requireWhenAccessed('BIP39', './lib/BIP39');
|
||||||
requireWhenAccessed('BIP39WordlistEn', './lib/BIP39WordlistEn');
|
requireWhenAccessed('BIP39WordlistEn', './lib/BIP39WordlistEn');
|
||||||
requireWhenAccessed('Point', './lib/Point');
|
requireWhenAccessed('Point', './lib/Point');
|
||||||
|
@ -55,10 +65,12 @@ requireWhenAccessed('Block', './lib/Block');
|
||||||
requireWhenAccessed('ScriptInterpreter', './lib/ScriptInterpreter');
|
requireWhenAccessed('ScriptInterpreter', './lib/ScriptInterpreter');
|
||||||
requireWhenAccessed('Bloom', './lib/Bloom');
|
requireWhenAccessed('Bloom', './lib/Bloom');
|
||||||
requireWhenAccessed('Key', './lib/Key');
|
requireWhenAccessed('Key', './lib/Key');
|
||||||
Object.defineProperty(module.exports, 'KeyModule', {get: function() {
|
Object.defineProperty(module.exports, 'KeyModule', {
|
||||||
|
get: function() {
|
||||||
console.log('KeyModule is deprecated.');
|
console.log('KeyModule is deprecated.');
|
||||||
return require('bindings')('KeyModule');
|
return require('bindings')('KeyModule');
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
requireWhenAccessed('SINKey', './lib/SINKey');
|
requireWhenAccessed('SINKey', './lib/SINKey');
|
||||||
requireWhenAccessed('SIN', './lib/SIN');
|
requireWhenAccessed('SIN', './lib/SIN');
|
||||||
requireWhenAccessed('PrivateKey', './lib/PrivateKey');
|
requireWhenAccessed('PrivateKey', './lib/PrivateKey');
|
||||||
|
@ -70,4 +82,3 @@ requireWhenAccessed('Message', './lib/Message');
|
||||||
requireWhenAccessed('Electrum', './lib/Electrum');
|
requireWhenAccessed('Electrum', './lib/Electrum');
|
||||||
requireWhenAccessed('Armory', './lib/Armory');
|
requireWhenAccessed('Armory', './lib/Armory');
|
||||||
module.exports.Buffer = Buffer;
|
module.exports.Buffer = Buffer;
|
||||||
|
|
||||||
|
|
14
const.js
14
const.js
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
MSG = {
|
MSG = {
|
||||||
TX: 1,
|
TX: 1,
|
||||||
BLOCK: 2,
|
BLOCK: 2,
|
||||||
|
@ -7,12 +6,15 @@ MSG = {
|
||||||
|
|
||||||
MSG.to_str = function(t) {
|
MSG.to_str = function(t) {
|
||||||
switch (t) {
|
switch (t) {
|
||||||
case MSG.TX: return 'transaction';
|
case MSG.TX:
|
||||||
case MSG.BLOCK: return 'block';
|
return 'transaction';
|
||||||
case MSG.FILTERED_BLOCK: return 'filtered block';
|
case MSG.BLOCK:
|
||||||
default: return 'unknown';
|
return 'block';
|
||||||
|
case MSG.FILTERED_BLOCK:
|
||||||
|
return 'filtered block';
|
||||||
|
default:
|
||||||
|
return 'unknown';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.MSG = MSG;
|
exports.MSG = MSG;
|
||||||
|
|
||||||
|
|
|
@ -63,4 +63,3 @@ for (var i = 0; i < 5; i++) {
|
||||||
console.log(Address.fromPubKey(b.pubkey).as('base58'));
|
console.log(Address.fromPubKey(b.pubkey).as('base58'));
|
||||||
b = b.next();
|
b = b.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,10 @@ dns.resolve('dnsseed.bluematt.me', function(err, seeds) {
|
||||||
// but specify a socks5 proxy to create a socket
|
// but specify a socks5 proxy to create a socket
|
||||||
// that's bound to that proxy in it's place
|
// that's bound to that proxy in it's place
|
||||||
var connection = new Connection(null, peer, {
|
var connection = new Connection(null, peer, {
|
||||||
proxy: { host: '127.0.0.1', port: 9050 }
|
proxy: {
|
||||||
|
host: '127.0.0.1',
|
||||||
|
port: 9050
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
connection.open();
|
connection.open();
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
|
|
||||||
var run = function() {
|
var run = function() {
|
||||||
bitcore = typeof(bitcore) === 'undefined' ? require('../bitcore') : bitcore;
|
bitcore = typeof(bitcore) === 'undefined' ? require('../bitcore') : bitcore;
|
||||||
var networks = require('../networks');
|
var networks = require('../networks');
|
||||||
var WalletKey = bitcore.WalletKey;
|
var WalletKey = bitcore.WalletKey;
|
||||||
var Builder = bitcore.TransactionBuilder;
|
var Builder = bitcore.TransactionBuilder;
|
||||||
var opts = {network: networks.testnet};
|
var opts = {
|
||||||
|
network: networks.testnet
|
||||||
|
};
|
||||||
|
|
||||||
console.log('## Network: ' + opts.network.name);
|
console.log('## Network: ' + opts.network.name);
|
||||||
|
|
||||||
|
@ -13,8 +14,7 @@ var run = function() {
|
||||||
input.priv = "cS62Ej4SobZnpFQYN1PEEBr2KWf5sgRYYnELtumcG6WVCfxno39V";
|
input.priv = "cS62Ej4SobZnpFQYN1PEEBr2KWf5sgRYYnELtumcG6WVCfxno39V";
|
||||||
|
|
||||||
// Complete with the corresponding UTXO you want to use
|
// Complete with the corresponding UTXO you want to use
|
||||||
var utxos = [
|
var utxos = [{
|
||||||
{
|
|
||||||
address: input.addr,
|
address: input.addr,
|
||||||
txid: "39c71ebda371f75f4b854a720eaf9898b237facf3c2b101b58cd4383a44a6adc",
|
txid: "39c71ebda371f75f4b854a720eaf9898b237facf3c2b101b58cd4383a44a6adc",
|
||||||
vout: 1,
|
vout: 1,
|
||||||
|
@ -22,8 +22,7 @@ var run = function() {
|
||||||
scriptPubKey: "76a914e867aad8bd361f57c50adc37a0c018692b5b0c9a88ac",
|
scriptPubKey: "76a914e867aad8bd361f57c50adc37a0c018692b5b0c9a88ac",
|
||||||
amount: 0.4296,
|
amount: 0.4296,
|
||||||
confirmations: 2
|
confirmations: 2
|
||||||
}
|
}];
|
||||||
];
|
|
||||||
|
|
||||||
var privs = [
|
var privs = [
|
||||||
"cP6JBHuQf7yqeqtdKRd22ibF3VehDv7G6BdzxSNABgrv3jFJUGoN",
|
"cP6JBHuQf7yqeqtdKRd22ibF3VehDv7G6BdzxSNABgrv3jFJUGoN",
|
||||||
|
@ -36,12 +35,18 @@ var run = function() {
|
||||||
var pubkeys = []
|
var pubkeys = []
|
||||||
privs.forEach(function(p) {
|
privs.forEach(function(p) {
|
||||||
var wk = new WalletKey(opts);
|
var wk = new WalletKey(opts);
|
||||||
wk.fromObj({priv: p});
|
wk.fromObj({
|
||||||
|
priv: p
|
||||||
|
});
|
||||||
pubkeys.push(bitcore.buffertools.toHex(wk.privKey.public));
|
pubkeys.push(bitcore.buffertools.toHex(wk.privKey.public));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
var outs = [{nreq:3, pubkeys:pubkeys, amount:0.05}];
|
var outs = [{
|
||||||
|
nreq: 3,
|
||||||
|
pubkeys: pubkeys,
|
||||||
|
amount: 0.05
|
||||||
|
}];
|
||||||
var tx = new Builder(opts)
|
var tx = new Builder(opts)
|
||||||
.setUnspent(utxos)
|
.setUnspent(utxos)
|
||||||
.setOutputs(outs)
|
.setOutputs(outs)
|
||||||
|
@ -59,8 +64,7 @@ var run = function() {
|
||||||
*
|
*
|
||||||
* REDDEEM TX
|
* REDDEEM TX
|
||||||
*/
|
*/
|
||||||
var utxos2 = [
|
var utxos2 = [{
|
||||||
{
|
|
||||||
address: input.addr,
|
address: input.addr,
|
||||||
txid: "e4bc22d8c519d3cf848d710619f8480be56176a4a6548dfbe865ab3886b578b5",
|
txid: "e4bc22d8c519d3cf848d710619f8480be56176a4a6548dfbe865ab3886b578b5",
|
||||||
vout: 0,
|
vout: 0,
|
||||||
|
@ -68,10 +72,12 @@ var run = function() {
|
||||||
scriptPubKey: scriptPubKey,
|
scriptPubKey: scriptPubKey,
|
||||||
amount: 0.05,
|
amount: 0.05,
|
||||||
confirmations: 2
|
confirmations: 2
|
||||||
}
|
}];
|
||||||
];
|
|
||||||
|
|
||||||
outs = [{address:input.addr, amount:0.04}];
|
outs = [{
|
||||||
|
address: input.addr,
|
||||||
|
amount: 0.04
|
||||||
|
}];
|
||||||
var b = new Builder(opts)
|
var b = new Builder(opts)
|
||||||
.setUnspent(utxos2)
|
.setUnspent(utxos2)
|
||||||
.setOutputs(outs)
|
.setOutputs(outs)
|
||||||
|
@ -100,4 +106,3 @@ if (typeof module !== 'undefined') {
|
||||||
}
|
}
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var run = function() {
|
var run = function() {
|
||||||
bitcore = typeof(bitcore) === 'undefined' ? require('../bitcore') : bitcore;
|
bitcore = typeof(bitcore) === 'undefined' ? require('../bitcore') : bitcore;
|
||||||
|
|
||||||
|
@ -23,9 +20,16 @@ var run = function() {
|
||||||
console.log('Unspends Outputs:', utxos);
|
console.log('Unspends Outputs:', utxos);
|
||||||
|
|
||||||
|
|
||||||
var outs = [{address:toAddress, amount:amt}];
|
var outs = [{
|
||||||
|
address: toAddress,
|
||||||
|
amount: amt
|
||||||
|
}];
|
||||||
var keys = [priv];
|
var keys = [priv];
|
||||||
var opts = {remainderOut: {address: changeAddressString}};
|
var opts = {
|
||||||
|
remainderOut: {
|
||||||
|
address: changeAddressString
|
||||||
|
}
|
||||||
|
};
|
||||||
var Builder = bitcore.TransactionBuilder;
|
var Builder = bitcore.TransactionBuilder;
|
||||||
|
|
||||||
var tx = new Builder(opts)
|
var tx = new Builder(opts)
|
||||||
|
@ -67,4 +71,3 @@ if (typeof module !== 'undefined') {
|
||||||
}
|
}
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,9 @@ var run = function() {
|
||||||
var WalletKey = bitcore.WalletKey;
|
var WalletKey = bitcore.WalletKey;
|
||||||
var Script = bitcore.Script;
|
var Script = bitcore.Script;
|
||||||
var Builder = bitcore.TransactionBuilder;
|
var Builder = bitcore.TransactionBuilder;
|
||||||
var opts = {network: networks.testnet};
|
var opts = {
|
||||||
|
network: networks.testnet
|
||||||
|
};
|
||||||
|
|
||||||
console.log('## Network: ' + opts.network.name);
|
console.log('## Network: ' + opts.network.name);
|
||||||
|
|
||||||
|
@ -13,8 +15,7 @@ var run = function() {
|
||||||
input.priv = "cS62Ej4SobZnpFQYN1PEEBr2KWf5sgRYYnELtumcG6WVCfxno39V";
|
input.priv = "cS62Ej4SobZnpFQYN1PEEBr2KWf5sgRYYnELtumcG6WVCfxno39V";
|
||||||
|
|
||||||
// Complete with the corresponding UTXO you want to use
|
// Complete with the corresponding UTXO you want to use
|
||||||
var utxos = [
|
var utxos = [{
|
||||||
{
|
|
||||||
address: "n2hoFVbPrYQf7RJwiRy1tkbuPPqyhAEfbp",
|
address: "n2hoFVbPrYQf7RJwiRy1tkbuPPqyhAEfbp",
|
||||||
txid: "e4bc22d8c519d3cf848d710619f8480be56176a4a6548dfbe865ab3886b578b5",
|
txid: "e4bc22d8c519d3cf848d710619f8480be56176a4a6548dfbe865ab3886b578b5",
|
||||||
vout: 1,
|
vout: 1,
|
||||||
|
@ -22,8 +23,7 @@ var run = function() {
|
||||||
scriptPubKey: "76a914e867aad8bd361f57c50adc37a0c018692b5b0c9a88ac",
|
scriptPubKey: "76a914e867aad8bd361f57c50adc37a0c018692b5b0c9a88ac",
|
||||||
amount: 0.3795,
|
amount: 0.3795,
|
||||||
confirmations: 7
|
confirmations: 7
|
||||||
}
|
}];
|
||||||
];
|
|
||||||
|
|
||||||
var privs = [
|
var privs = [
|
||||||
"cMpKwGr5oxEacN95WFKNEq6tTcvi11regFwS3muHvGYVxMPJX8JA",
|
"cMpKwGr5oxEacN95WFKNEq6tTcvi11regFwS3muHvGYVxMPJX8JA",
|
||||||
|
@ -36,12 +36,17 @@ var run = function() {
|
||||||
var pubkeys = []
|
var pubkeys = []
|
||||||
privs.forEach(function(p) {
|
privs.forEach(function(p) {
|
||||||
var wk = new WalletKey(opts);
|
var wk = new WalletKey(opts);
|
||||||
wk.fromObj({priv: p});
|
wk.fromObj({
|
||||||
|
priv: p
|
||||||
|
});
|
||||||
pubkeys.push(bitcore.buffertools.toHex(wk.privKey.public));
|
pubkeys.push(bitcore.buffertools.toHex(wk.privKey.public));
|
||||||
});
|
});
|
||||||
|
|
||||||
// multisig p2sh
|
// multisig p2sh
|
||||||
var opts = {nreq:3, pubkeys:pubkeys};
|
var opts = {
|
||||||
|
nreq: 3,
|
||||||
|
pubkeys: pubkeys
|
||||||
|
};
|
||||||
|
|
||||||
// p2scriphash p2sh
|
// p2scriphash p2sh
|
||||||
//var opts = [{address: an_address}];
|
//var opts = [{address: an_address}];
|
||||||
|
@ -51,7 +56,10 @@ var run = function() {
|
||||||
var p2shAddress = info.address;
|
var p2shAddress = info.address;
|
||||||
|
|
||||||
|
|
||||||
var outs = [{address:p2shAddress, amount:0.05}];
|
var outs = [{
|
||||||
|
address: p2shAddress,
|
||||||
|
amount: 0.05
|
||||||
|
}];
|
||||||
var tx = new Builder(opts)
|
var tx = new Builder(opts)
|
||||||
.setUnspent(utxos)
|
.setUnspent(utxos)
|
||||||
.setOutputs(outs)
|
.setOutputs(outs)
|
||||||
|
@ -72,8 +80,7 @@ var run = function() {
|
||||||
*
|
*
|
||||||
* REDDEEM TX
|
* REDDEEM TX
|
||||||
*/
|
*/
|
||||||
var utxos2 = [
|
var utxos2 = [{
|
||||||
{
|
|
||||||
address: p2shAddress,
|
address: p2shAddress,
|
||||||
txid: "c2e50d1c8c581d8c4408378b751633f7eb86687fc5f0502be7b467173f275ae7",
|
txid: "c2e50d1c8c581d8c4408378b751633f7eb86687fc5f0502be7b467173f275ae7",
|
||||||
vout: 0,
|
vout: 0,
|
||||||
|
@ -81,10 +88,12 @@ var run = function() {
|
||||||
scriptPubKey: scriptPubKey,
|
scriptPubKey: scriptPubKey,
|
||||||
amount: 0.05,
|
amount: 0.05,
|
||||||
confirmations: 1
|
confirmations: 1
|
||||||
}
|
}];
|
||||||
];
|
|
||||||
|
|
||||||
outs = [{address:input.addr, amount:0.04}];
|
outs = [{
|
||||||
|
address: input.addr,
|
||||||
|
amount: 0.04
|
||||||
|
}];
|
||||||
|
|
||||||
var hashMap = {};
|
var hashMap = {};
|
||||||
hashMap[p2shAddress] = p2shScript;
|
hashMap[p2shAddress] = p2shScript;
|
||||||
|
|
|
@ -8,7 +8,9 @@ var run = function() {
|
||||||
var networks = require('../networks');
|
var networks = require('../networks');
|
||||||
var WalletKey = bitcore.WalletKey;
|
var WalletKey = bitcore.WalletKey;
|
||||||
|
|
||||||
var opts = {network: networks.testnet};
|
var opts = {
|
||||||
|
network: networks.testnet
|
||||||
|
};
|
||||||
|
|
||||||
function print(wk) {
|
function print(wk) {
|
||||||
|
|
||||||
|
@ -32,7 +34,9 @@ var run = function() {
|
||||||
|
|
||||||
//Generate from private Key WIF. Compressed status taken from WIF.
|
//Generate from private Key WIF. Compressed status taken from WIF.
|
||||||
var wk2 = new WalletKey(opts);
|
var wk2 = new WalletKey(opts);
|
||||||
wk2.fromObj({priv:'cMpKwGr5oxEacN95WFKNEq6tTcvi11regFwS3muHvGYVxMPJX8JA'});
|
wk2.fromObj({
|
||||||
|
priv: 'cMpKwGr5oxEacN95WFKNEq6tTcvi11regFwS3muHvGYVxMPJX8JA'
|
||||||
|
});
|
||||||
print(wk2);
|
print(wk2);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,9 @@ var run = function() {
|
||||||
var buffertools = bitcore.buffertools;
|
var buffertools = bitcore.buffertools;
|
||||||
var Address = bitcore.Address;
|
var Address = bitcore.Address;
|
||||||
var util = bitcore.util;
|
var util = bitcore.util;
|
||||||
var opts = {network: networks.testnet};
|
var opts = {
|
||||||
|
network: networks.testnet
|
||||||
|
};
|
||||||
|
|
||||||
var p = console.log;
|
var p = console.log;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
var PeerManager = require('../lib/PeerManager');
|
var PeerManager = require('../lib/PeerManager');
|
||||||
var peerman = new PeerManager();
|
var peerman = new PeerManager();
|
||||||
|
|
||||||
peerman.discover({ limit: 12 }).start();
|
peerman.discover({
|
||||||
|
limit: 12
|
||||||
|
}).start();
|
||||||
|
|
|
@ -19,7 +19,8 @@ var socket = peer.createConnection();
|
||||||
var con = new Connection(socket, peer);
|
var con = new Connection(socket, peer);
|
||||||
|
|
||||||
con.on('error', function(msg) {
|
con.on('error', function(msg) {
|
||||||
var peer = msg.peer, err = msg.err;
|
var peer = msg.peer,
|
||||||
|
err = msg.err;
|
||||||
console.error('Error connecting to peer', peer.host + ':' + peer.port, '(' + err.message + ')');
|
console.error('Error connecting to peer', peer.host + ':' + peer.port, '(' + err.message + ')');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -69,4 +70,3 @@ listen('inv', function (event, log) {
|
||||||
log('Received message inv (%s invs)', event.message.count);
|
log('Received message inv (%s invs)', event.message.count);
|
||||||
console.log(event.message.invs);
|
console.log(event.message.invs);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -105,7 +105,8 @@ Address.fromScriptPubKey = function(scriptPubKey, network) {
|
||||||
if (!network)
|
if (!network)
|
||||||
network = 'livenet';
|
network = 'livenet';
|
||||||
|
|
||||||
var ret=[], version;
|
var ret = [],
|
||||||
|
version;
|
||||||
var payload = scriptPubKey.capture();
|
var payload = scriptPubKey.capture();
|
||||||
|
|
||||||
if (payload) {
|
if (payload) {
|
||||||
|
|
|
@ -15,8 +15,7 @@ var pbkdf2Sync_sha512 = function(password, salt, iterations, keylen) {
|
||||||
return sjcl.codec.hex.fromBits(derivedKey)
|
return sjcl.codec.hex.fromBits(derivedKey)
|
||||||
};
|
};
|
||||||
|
|
||||||
var BIP39 = function() {
|
var BIP39 = function() {};
|
||||||
};
|
|
||||||
|
|
||||||
BIP39.mnemonic = function(wordlist, bits) {
|
BIP39.mnemonic = function(wordlist, bits) {
|
||||||
if (!bits)
|
if (!bits)
|
||||||
|
|
|
@ -35,7 +35,8 @@ var base58 = {
|
||||||
var j = 0;
|
var j = 0;
|
||||||
while (buf[j] == 0) {
|
while (buf[j] == 0) {
|
||||||
str[i] = ALPHABET_BUF[0];
|
str[i] = ALPHABET_BUF[0];
|
||||||
j++; i--;
|
j++;
|
||||||
|
i--;
|
||||||
}
|
}
|
||||||
|
|
||||||
return str.slice(i + 1, str.length).toString('ascii');
|
return str.slice(i + 1, str.length).toString('ascii');
|
||||||
|
|
27
lib/Block.js
27
lib/Block.js
|
@ -17,8 +17,7 @@ var BlockRules = {
|
||||||
largestHash: Bignum(2).pow(256)
|
largestHash: Bignum(2).pow(256)
|
||||||
};
|
};
|
||||||
|
|
||||||
function Block(data)
|
function Block(data) {
|
||||||
{
|
|
||||||
if ("object" !== typeof data) {
|
if ("object" !== typeof data) {
|
||||||
data = {};
|
data = {};
|
||||||
}
|
}
|
||||||
|
@ -39,12 +38,18 @@ function Block(data)
|
||||||
Block.prototype.getHeader = function getHeader() {
|
Block.prototype.getHeader = function getHeader() {
|
||||||
var buf = new Buffer(80);
|
var buf = new Buffer(80);
|
||||||
var ofs = 0;
|
var ofs = 0;
|
||||||
buf.writeUInt32LE(this.version, ofs); ofs += 4;
|
buf.writeUInt32LE(this.version, ofs);
|
||||||
this.prev_hash.copy(buf, ofs); ofs += 32;
|
ofs += 4;
|
||||||
this.merkle_root.copy(buf, ofs); ofs += 32;
|
this.prev_hash.copy(buf, ofs);
|
||||||
buf.writeUInt32LE(this.timestamp, ofs); ofs += 4;
|
ofs += 32;
|
||||||
buf.writeUInt32LE(this.bits, ofs); ofs += 4;
|
this.merkle_root.copy(buf, ofs);
|
||||||
buf.writeUInt32LE(this.nonce, ofs); ofs += 4;
|
ofs += 32;
|
||||||
|
buf.writeUInt32LE(this.timestamp, ofs);
|
||||||
|
ofs += 4;
|
||||||
|
buf.writeUInt32LE(this.bits, ofs);
|
||||||
|
ofs += 4;
|
||||||
|
buf.writeUInt32LE(this.nonce, ofs);
|
||||||
|
ofs += 4;
|
||||||
return buf;
|
return buf;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -234,8 +239,7 @@ Block.prototype.toString = function toString() {
|
||||||
|
|
||||||
|
|
||||||
Block.prototype.createCoinbaseTx =
|
Block.prototype.createCoinbaseTx =
|
||||||
function createCoinbaseTx(beneficiary)
|
function createCoinbaseTx(beneficiary) {
|
||||||
{
|
|
||||||
var tx = new Transaction();
|
var tx = new Transaction();
|
||||||
tx.ins.push(new TransactionIn({
|
tx.ins.push(new TransactionIn({
|
||||||
s: util.EMPTY_BUFFER,
|
s: util.EMPTY_BUFFER,
|
||||||
|
@ -259,8 +263,7 @@ Block.prototype.solve = function solve(miner, callback) {
|
||||||
* Returns an object with the same field names as jgarzik's getblock patch.
|
* Returns an object with the same field names as jgarzik's getblock patch.
|
||||||
*/
|
*/
|
||||||
Block.prototype.getStandardizedObject =
|
Block.prototype.getStandardizedObject =
|
||||||
function getStandardizedObject(txs)
|
function getStandardizedObject(txs) {
|
||||||
{
|
|
||||||
var block = {
|
var block = {
|
||||||
hash: util.formatHashFull(this.getHash()),
|
hash: util.formatHashFull(this.getHash()),
|
||||||
version: this.version,
|
version: this.version,
|
||||||
|
|
|
@ -47,9 +47,12 @@ Bloom.prototype.hash = function(hashNum, data) {
|
||||||
var k1 = 0;
|
var k1 = 0;
|
||||||
|
|
||||||
switch (data.length & 3) {
|
switch (data.length & 3) {
|
||||||
case 3: k1 ^= tail[2] << 16;
|
case 3:
|
||||||
case 2: k1 ^= tail[1] << 8;
|
k1 ^= tail[2] << 16;
|
||||||
case 1: k1 ^= tail[0];
|
case 2:
|
||||||
|
k1 ^= tail[1] << 8;
|
||||||
|
case 1:
|
||||||
|
k1 ^= tail[0];
|
||||||
k1 *= c1;
|
k1 *= c1;
|
||||||
k1 = ROTL32(k1, 15);
|
k1 = ROTL32(k1, 15);
|
||||||
k1 *= c2;
|
k1 *= c2;
|
||||||
|
|
|
@ -399,10 +399,11 @@ Connection.prototype.processData = function () {
|
||||||
var checksumConfirm = doubleSha256(payload).slice(0, 4);
|
var checksumConfirm = doubleSha256(payload).slice(0, 4);
|
||||||
if (buffertools.compare(checksumConfirm, checksum) !== 0) {
|
if (buffertools.compare(checksumConfirm, checksum) !== 0) {
|
||||||
log.err('[' + this.peer + '] ' +
|
log.err('[' + this.peer + '] ' +
|
||||||
'Checksum failed',
|
'Checksum failed', {
|
||||||
{ cmd: command,
|
cmd: command,
|
||||||
expected: checksumConfirm.toString('hex'),
|
expected: checksumConfirm.toString('hex'),
|
||||||
actual: checksum.toString('hex') });
|
actual: checksum.toString('hex')
|
||||||
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -552,8 +553,9 @@ Connection.prototype.parseMessage = function (command, payload) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
log.err('Connection.parseMessage(): Command not implemented',
|
log.err('Connection.parseMessage(): Command not implemented', {
|
||||||
{cmd: command});
|
cmd: command
|
||||||
|
});
|
||||||
|
|
||||||
// This tells the calling function not to issue an event
|
// This tells the calling function not to issue an event
|
||||||
return null;
|
return null;
|
||||||
|
|
15
lib/Curve.js
15
lib/Curve.js
|
@ -3,11 +3,12 @@ var imports = require('soop');
|
||||||
var bignum = imports.bignum || require('bignum');
|
var bignum = imports.bignum || require('bignum');
|
||||||
var Point = imports.Point || require('./Point');
|
var Point = imports.Point || require('./Point');
|
||||||
|
|
||||||
var n = bignum.fromBuffer(new Buffer("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 'hex'), {size: 32});
|
var n = bignum.fromBuffer(new Buffer("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 'hex'), {
|
||||||
|
size: 32
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
var Curve = function() {
|
var Curve = function() {};
|
||||||
};
|
|
||||||
|
|
||||||
/* secp256k1 curve */
|
/* secp256k1 curve */
|
||||||
var G;
|
var G;
|
||||||
|
@ -16,8 +17,12 @@ Curve.getG = function() {
|
||||||
// when Point is not loaded yet
|
// when Point is not loaded yet
|
||||||
|
|
||||||
// use cached version if available
|
// use cached version if available
|
||||||
G = G || new Point(bignum.fromBuffer(new Buffer("79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", 'hex'), {size: 32}),
|
G = G || new Point(bignum.fromBuffer(new Buffer("79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", 'hex'), {
|
||||||
bignum.fromBuffer(new Buffer("483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8", 'hex'), {size: 32}));
|
size: 32
|
||||||
|
}),
|
||||||
|
bignum.fromBuffer(new Buffer("483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8", 'hex'), {
|
||||||
|
size: 32
|
||||||
|
}));
|
||||||
return G;
|
return G;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
|
exports.intFromCompact = function(c) {
|
||||||
exports.intFromCompact = function(c)
|
|
||||||
{
|
|
||||||
var bytes = ((c >>> 24) & 0xff) >>> 0;
|
var bytes = ((c >>> 24) & 0xff) >>> 0;
|
||||||
var v = ((c & 0xffffff) << (8 * (bytes - 3))) >>> 0;
|
var v = ((c & 0xffffff) << (8 * (bytes - 3))) >>> 0;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,12 @@ Electrum.prototype.getSequence = function (for_change, n) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Electrum.prototype.generatePubKey = function(n, for_change) {
|
Electrum.prototype.generatePubKey = function(n, for_change) {
|
||||||
var x = bignum.fromBuffer(this.mpk.slice(0, 32), { size: 32 });
|
var x = bignum.fromBuffer(this.mpk.slice(0, 32), {
|
||||||
var y = bignum.fromBuffer(this.mpk.slice(32, 64), { size: 32 });
|
size: 32
|
||||||
|
});
|
||||||
|
var y = bignum.fromBuffer(this.mpk.slice(32, 64), {
|
||||||
|
size: 32
|
||||||
|
});
|
||||||
var mpk_pt = new Point(x, y);
|
var mpk_pt = new Point(x, y);
|
||||||
|
|
||||||
var sequence = this.getSequence(for_change, n);
|
var sequence = this.getSequence(for_change, n);
|
||||||
|
@ -37,8 +41,12 @@ Electrum.prototype.generatePubKey = function (n, for_change) {
|
||||||
|
|
||||||
pt = Point.add(mpk_pt, sequence_pt);
|
pt = Point.add(mpk_pt, sequence_pt);
|
||||||
|
|
||||||
var xbuf = pt.x.toBuffer({ size: 32 });
|
var xbuf = pt.x.toBuffer({
|
||||||
var ybuf = pt.y.toBuffer({ size: 32 });
|
size: 32
|
||||||
|
});
|
||||||
|
var ybuf = pt.y.toBuffer({
|
||||||
|
size: 32
|
||||||
|
});
|
||||||
var prefix = new Buffer([0x04]);
|
var prefix = new Buffer([0x04]);
|
||||||
|
|
||||||
var key = new Key();
|
var key = new Key();
|
||||||
|
|
|
@ -19,8 +19,7 @@ var HierarchicalKey = function(bytes) {
|
||||||
if (typeof bytes == 'undefined' || bytes == 'mainnet' || bytes == 'livenet') {
|
if (typeof bytes == 'undefined' || bytes == 'mainnet' || bytes == 'livenet') {
|
||||||
bytes = 'livenet';
|
bytes = 'livenet';
|
||||||
this.version = networks['livenet'].hkeyPrivateVersion;
|
this.version = networks['livenet'].hkeyPrivateVersion;
|
||||||
}
|
} else if (bytes == 'testnet') {
|
||||||
else if (bytes == 'testnet') {
|
|
||||||
this.version = networks['testnet'].hkeyPrivateVersion;
|
this.version = networks['testnet'].hkeyPrivateVersion;
|
||||||
}
|
}
|
||||||
if (bytes == 'livenet' || bytes == 'testnet') {
|
if (bytes == 'livenet' || bytes == 'testnet') {
|
||||||
|
@ -265,18 +264,24 @@ HierarchicalKey.prototype.deriveChild = function(i) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var hash = coinUtil.sha512hmac(data, this.chainCode);
|
var hash = coinUtil.sha512hmac(data, this.chainCode);
|
||||||
var il = bignum.fromBuffer(hash.slice(0, 32), {size: 32});
|
var il = bignum.fromBuffer(hash.slice(0, 32), {
|
||||||
|
size: 32
|
||||||
|
});
|
||||||
var ir = hash.slice(32, 64);
|
var ir = hash.slice(32, 64);
|
||||||
|
|
||||||
// ki = IL + kpar (mod n).
|
// ki = IL + kpar (mod n).
|
||||||
var priv = bignum.fromBuffer(this.eckey.private, {size: 32});
|
var priv = bignum.fromBuffer(this.eckey.private, {
|
||||||
|
size: 32
|
||||||
|
});
|
||||||
var k = il.add(priv).mod(secp256k1_n);
|
var k = il.add(priv).mod(secp256k1_n);
|
||||||
|
|
||||||
ret = new HierarchicalKey(null);
|
ret = new HierarchicalKey(null);
|
||||||
ret.chainCode = ir;
|
ret.chainCode = ir;
|
||||||
|
|
||||||
ret.eckey = new Key();
|
ret.eckey = new Key();
|
||||||
ret.eckey.private = k.toBuffer({size: 32});
|
ret.eckey.private = k.toBuffer({
|
||||||
|
size: 32
|
||||||
|
});
|
||||||
ret.eckey.regenerateSync();
|
ret.eckey.regenerateSync();
|
||||||
ret.hasPrivateKey = true;
|
ret.hasPrivateKey = true;
|
||||||
|
|
||||||
|
@ -334,9 +339,20 @@ function uint(f, size) {
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
function u8(f) {return uint(f,1);}
|
function u8(f) {
|
||||||
function u16(f) {return uint(f,2);}
|
return uint(f, 1);
|
||||||
function u32(f) {return uint(f,4);}
|
}
|
||||||
function u64(f) {return uint(f,8);}
|
|
||||||
|
function u16(f) {
|
||||||
|
return uint(f, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
function u32(f) {
|
||||||
|
return uint(f, 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
function u64(f) {
|
||||||
|
return uint(f, 8);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = require('soop')(HierarchicalKey);
|
module.exports = require('soop')(HierarchicalKey);
|
||||||
|
|
|
@ -3,8 +3,7 @@ var imports = require('soop').imports();
|
||||||
var coinUtil = imports.coinUtil || require('../util');
|
var coinUtil = imports.coinUtil || require('../util');
|
||||||
var Key = imports.Key || require('./Key');
|
var Key = imports.Key || require('./Key');
|
||||||
|
|
||||||
var Message = function() {
|
var Message = function() {};
|
||||||
};
|
|
||||||
|
|
||||||
Message.sign = function(str, key) {
|
Message.sign = function(str, key) {
|
||||||
var hash = Message.magicHash(str);
|
var hash = Message.magicHash(str);
|
||||||
|
|
|
@ -64,8 +64,9 @@ PeerManager.prototype.addPeer = function(peer, port) {
|
||||||
} else if ("string" == typeof peer) {
|
} else if ("string" == typeof peer) {
|
||||||
this.addPeer(new Peer(peer, port));
|
this.addPeer(new Peer(peer, port));
|
||||||
} else {
|
} else {
|
||||||
log.err('Node.addPeer(): Invalid value provided for peer',
|
log.err('Node.addPeer(): Invalid value provided for peer', {
|
||||||
{val: peer});
|
val: peer
|
||||||
|
});
|
||||||
throw 'Node.addPeer(): Invalid value provided for peer.';
|
throw 'Node.addPeer(): Invalid value provided for peer.';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
16
lib/Point.js
16
lib/Point.js
|
@ -28,15 +28,23 @@ Point.multiply = function(p1, x) {
|
||||||
//convert the public key of a Key into a Point
|
//convert the public key of a Key into a Point
|
||||||
Point.fromUncompressedPubKey = function(pubkey) {
|
Point.fromUncompressedPubKey = function(pubkey) {
|
||||||
var point = new Point();
|
var point = new Point();
|
||||||
point.x = bignum.fromBuffer(pubkey.slice(1, 33), {size: 32});
|
point.x = bignum.fromBuffer(pubkey.slice(1, 33), {
|
||||||
point.y = bignum.fromBuffer(pubkey.slice(33, 65), {size: 32});
|
size: 32
|
||||||
|
});
|
||||||
|
point.y = bignum.fromBuffer(pubkey.slice(33, 65), {
|
||||||
|
size: 32
|
||||||
|
});
|
||||||
return point;
|
return point;
|
||||||
};
|
};
|
||||||
|
|
||||||
//convert the Point into the Key containing a compressed public key
|
//convert the Point into the Key containing a compressed public key
|
||||||
Point.prototype.toUncompressedPubKey = function() {
|
Point.prototype.toUncompressedPubKey = function() {
|
||||||
var xbuf = this.x.toBuffer({size: 32});
|
var xbuf = this.x.toBuffer({
|
||||||
var ybuf = this.y.toBuffer({size: 32});
|
size: 32
|
||||||
|
});
|
||||||
|
var ybuf = this.y.toBuffer({
|
||||||
|
size: 32
|
||||||
|
});
|
||||||
var prefix = new Buffer([0x04]);
|
var prefix = new Buffer([0x04]);
|
||||||
var pubkey = Buffer.concat([prefix, xbuf, ybuf]);
|
var pubkey = Buffer.concat([prefix, xbuf, ybuf]);
|
||||||
return pubkey;
|
return pubkey;
|
||||||
|
|
|
@ -26,7 +26,9 @@ PrivateKey.prototype.validate = function() {
|
||||||
// overloaded from VersionedData
|
// overloaded from VersionedData
|
||||||
PrivateKey.prototype.payload = function(data) {
|
PrivateKey.prototype.payload = function(data) {
|
||||||
if (data) {
|
if (data) {
|
||||||
this.doAsBinary(function() {data.copy(this.data,1);});
|
this.doAsBinary(function() {
|
||||||
|
data.copy(this.data, 1);
|
||||||
|
});
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
var buf = this.as('binary');
|
var buf = this.as('binary');
|
||||||
|
@ -50,8 +52,7 @@ PrivateKey.prototype.compressed = function(compressed) {
|
||||||
this.data = this.data.slice(0, len - 1);
|
this.data = this.data.slice(0, len - 1);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
var len = 1 + 32 + 1;
|
var len = 1 + 32 + 1;
|
||||||
var data = this.as('binary');
|
var data = this.as('binary');
|
||||||
if (data.length == len && data[len - 1] == 1)
|
if (data.length == len && data[len - 1] == 1)
|
||||||
|
|
|
@ -107,18 +107,33 @@ function generateRPCMethods(constructor, apiCalls, rpc) {
|
||||||
if (argMap[i]) arguments[i] = argMap[i](arguments[i]);
|
if (argMap[i]) arguments[i] = argMap[i](arguments[i]);
|
||||||
};
|
};
|
||||||
if (this.batchedCalls) {
|
if (this.batchedCalls) {
|
||||||
this.batchedCalls.push({jsonrpc: '2.0', method: methodName, params: slice(arguments)});
|
this.batchedCalls.push({
|
||||||
|
jsonrpc: '2.0',
|
||||||
|
method: methodName,
|
||||||
|
params: slice(arguments)
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
rpc.call(this, {method: methodName, params: slice(arguments, 0, arguments.length - 1)}, arguments[arguments.length - 1]);
|
rpc.call(this, {
|
||||||
|
method: methodName,
|
||||||
|
params: slice(arguments, 0, arguments.length - 1)
|
||||||
|
}, arguments[arguments.length - 1]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
var types = {
|
var types = {
|
||||||
str: function(arg) {return arg.toString();},
|
str: function(arg) {
|
||||||
int: function(arg) {return parseFloat(arg);},
|
return arg.toString();
|
||||||
float: function(arg) {return parseFloat(arg);},
|
},
|
||||||
bool: function(arg) {return (arg === true || arg == '1' || arg == 'true' || arg.toString().toLowerCase() == 'true');},
|
int: function(arg) {
|
||||||
|
return parseFloat(arg);
|
||||||
|
},
|
||||||
|
float: function(arg) {
|
||||||
|
return parseFloat(arg);
|
||||||
|
},
|
||||||
|
bool: function(arg) {
|
||||||
|
return (arg === true || arg == '1' || arg == 'true' || arg.toString().toLowerCase() == 'true');
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
for (var k in apiCalls) {
|
for (var k in apiCalls) {
|
||||||
|
@ -205,4 +220,3 @@ function rpc(request, callback) {
|
||||||
generateRPCMethods(RpcClient, callspec, rpc);
|
generateRPCMethods(RpcClient, callspec, rpc);
|
||||||
|
|
||||||
module.exports = require('soop')(RpcClient);
|
module.exports = require('soop')(RpcClient);
|
||||||
|
|
||||||
|
|
12
lib/SIN.js
12
lib/SIN.js
|
@ -22,7 +22,9 @@ SIN.SIN_EPHEM = 0x02; // generate off-net at any time
|
||||||
// get or set the prefix data (the first byte of the address)
|
// get or set the prefix data (the first byte of the address)
|
||||||
SIN.prototype.prefix = function(num) {
|
SIN.prototype.prefix = function(num) {
|
||||||
if (num || (num === 0)) {
|
if (num || (num === 0)) {
|
||||||
this.doAsBinary(function() {this.data.writeUInt8(num, 0);});
|
this.doAsBinary(function() {
|
||||||
|
this.data.writeUInt8(num, 0);
|
||||||
|
});
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
return this.as('binary').readUInt8(0);
|
return this.as('binary').readUInt8(0);
|
||||||
|
@ -31,7 +33,9 @@ SIN.prototype.prefix = function(num) {
|
||||||
// get or set the SIN-type data (the second byte of the address)
|
// get or set the SIN-type data (the second byte of the address)
|
||||||
SIN.prototype.type = function(num) {
|
SIN.prototype.type = function(num) {
|
||||||
if (num || (num === 0)) {
|
if (num || (num === 0)) {
|
||||||
this.doAsBinary(function() {this.data.writeUInt8(num, 1);});
|
this.doAsBinary(function() {
|
||||||
|
this.data.writeUInt8(num, 1);
|
||||||
|
});
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
return this.as('binary').readUInt8(1);
|
return this.as('binary').readUInt8(1);
|
||||||
|
@ -40,7 +44,9 @@ SIN.prototype.type = function(num) {
|
||||||
// get or set the payload data (as a Buffer object)
|
// get or set the payload data (as a Buffer object)
|
||||||
SIN.prototype.payload = function(data) {
|
SIN.prototype.payload = function(data) {
|
||||||
if (data) {
|
if (data) {
|
||||||
this.doAsBinary(function() {data.copy(this.data, 2);});
|
this.doAsBinary(function() {
|
||||||
|
data.copy(this.data, 2);
|
||||||
|
});
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
return this.as('binary').slice(1);
|
return this.as('binary').slice(1);
|
||||||
|
|
|
@ -110,7 +110,9 @@ function isSmallIntOp(opcode) {
|
||||||
Script.prototype.isMultiSig = function() {
|
Script.prototype.isMultiSig = function() {
|
||||||
return (this.chunks.length > 3 &&
|
return (this.chunks.length > 3 &&
|
||||||
isSmallIntOp(this.chunks[0]) &&
|
isSmallIntOp(this.chunks[0]) &&
|
||||||
this.chunks.slice(1,this.chunks.length-2).every(function(i){return Buffer.isBuffer(i);}) &&
|
this.chunks.slice(1, this.chunks.length - 2).every(function(i) {
|
||||||
|
return Buffer.isBuffer(i);
|
||||||
|
}) &&
|
||||||
isSmallIntOp(this.chunks[this.chunks.length - 2]) &&
|
isSmallIntOp(this.chunks[this.chunks.length - 2]) &&
|
||||||
this.chunks[this.chunks.length - 1] == Opcode.map.OP_CHECKMULTISIG);
|
this.chunks[this.chunks.length - 1] == Opcode.map.OP_CHECKMULTISIG);
|
||||||
};
|
};
|
||||||
|
@ -137,8 +139,7 @@ Script.prototype.countSignatures = function() {
|
||||||
// Multisig?
|
// Multisig?
|
||||||
if (this.isMultiSigScriptSig()) {
|
if (this.isMultiSigScriptSig()) {
|
||||||
ret = l - 1;
|
ret = l - 1;
|
||||||
}
|
} else if (this.isP2shScriptSig()) {
|
||||||
else if (this.isP2shScriptSig()) {
|
|
||||||
ret = l - 2;
|
ret = l - 2;
|
||||||
}
|
}
|
||||||
// p2pubkey or p2pubkeyhash
|
// p2pubkey or p2pubkeyhash
|
||||||
|
@ -161,8 +162,7 @@ Script.prototype.countMissingSignatures = function() {
|
||||||
var redeemScript = new Script(this.chunks[l - 1]);
|
var redeemScript = new Script(this.chunks[l - 1]);
|
||||||
if (!isSmallIntOp(redeemScript.chunks[0])) {
|
if (!isSmallIntOp(redeemScript.chunks[0])) {
|
||||||
log.debug("Unrecognized script type");
|
log.debug("Unrecognized script type");
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
var nreq = redeemScript.chunks[0] - 80; //see OP_2-OP_16
|
var nreq = redeemScript.chunks[0] - 80; //see OP_2-OP_16
|
||||||
ret = nreq - (l - 2); // 2-> marked 0 + redeemScript
|
ret = nreq - (l - 2); // 2-> marked 0 + redeemScript
|
||||||
}
|
}
|
||||||
|
|
11
lib/Sign.js
11
lib/Sign.js
|
@ -1,6 +1,4 @@
|
||||||
|
function signOne(hash, addrStr, keys) {
|
||||||
function signOne(hash, addrStr, keys)
|
|
||||||
{
|
|
||||||
var keyObj = keys[addrStr];
|
var keyObj = keys[addrStr];
|
||||||
var rawPrivKey = new Buffer(keyObj.priv, 'hex');
|
var rawPrivKey = new Buffer(keyObj.priv, 'hex');
|
||||||
var key = new KeyModule.Key();
|
var key = new KeyModule.Key();
|
||||||
|
@ -10,8 +8,7 @@ function signOne(hash, addrStr, keys)
|
||||||
return signature;
|
return signature;
|
||||||
}
|
}
|
||||||
|
|
||||||
function signTxIn(nIn, tx, txInputs, network, keys, scripts)
|
function signTxIn(nIn, tx, txInputs, network, keys, scripts) {
|
||||||
{
|
|
||||||
// locate TX input needing a signature
|
// locate TX input needing a signature
|
||||||
var txin = tx.ins[nIn];
|
var txin = tx.ins[nIn];
|
||||||
var scriptSig = txin.getScript();
|
var scriptSig = txin.getScript();
|
||||||
|
@ -125,9 +122,7 @@ function signTxIn(nIn, tx, txInputs, network, keys, scripts)
|
||||||
scriptSig.writeBytes(subscriptRaw);
|
scriptSig.writeBytes(subscriptRaw);
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.Transaction = function Transaction(tx, txInputs, network, keys, scripts)
|
exports.Transaction = function Transaction(tx, txInputs, network, keys, scripts) {
|
||||||
{
|
|
||||||
for (var i = 0; i < tx.ins.length; i++)
|
for (var i = 0; i < tx.ins.length; i++)
|
||||||
signTxIn(i, tx, txInputs, network, keys, scripts);
|
signTxIn(i, tx, txInputs, network, keys, scripts);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -344,7 +344,8 @@ TransactionBuilder.prototype._setRemainder = function(txobj, remainderIndex) {
|
||||||
TransactionBuilder.prototype._setFeeAndRemainder = function(txobj) {
|
TransactionBuilder.prototype._setFeeAndRemainder = function(txobj) {
|
||||||
|
|
||||||
/* starting size estimation */
|
/* starting size estimation */
|
||||||
var size = 500, maxSizeK, remainderIndex = txobj.outs.length;
|
var size = 500,
|
||||||
|
maxSizeK, remainderIndex = txobj.outs.length;
|
||||||
do {
|
do {
|
||||||
/* based on https://en.bitcoin.it/wiki/Transaction_fees */
|
/* based on https://en.bitcoin.it/wiki/Transaction_fees */
|
||||||
maxSizeK = parseInt(size / 1000) + 1;
|
maxSizeK = parseInt(size / 1000) + 1;
|
||||||
|
@ -422,13 +423,15 @@ TransactionBuilder._mapKeys = function(keys) {
|
||||||
|
|
||||||
if (typeof k === 'string') {
|
if (typeof k === 'string') {
|
||||||
var pk = new PrivateKey(k);
|
var pk = new PrivateKey(k);
|
||||||
wk = new WalletKey({ network: pk.network() });
|
wk = new WalletKey({
|
||||||
wk.fromObj({ priv: k });
|
network: pk.network()
|
||||||
}
|
});
|
||||||
else if (k instanceof WalletKey) {
|
wk.fromObj({
|
||||||
|
priv: k
|
||||||
|
});
|
||||||
|
} else if (k instanceof WalletKey) {
|
||||||
wk = k;
|
wk = k;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
throw new Error('argument must be an array of strings (WIF format) or WalletKey objects');
|
throw new Error('argument must be an array of strings (WIF format) or WalletKey objects');
|
||||||
}
|
}
|
||||||
walletKeyMap[wk.storeObj().addr] = wk;
|
walletKeyMap[wk.storeObj().addr] = wk;
|
||||||
|
@ -437,7 +440,8 @@ TransactionBuilder._mapKeys = function(keys) {
|
||||||
};
|
};
|
||||||
|
|
||||||
TransactionBuilder._signHashAndVerify = function(wk, txSigHash) {
|
TransactionBuilder._signHashAndVerify = function(wk, txSigHash) {
|
||||||
var triesLeft = 10, sigRaw;
|
var triesLeft = 10,
|
||||||
|
sigRaw;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
sigRaw = wk.privKey.signSync(txSigHash);
|
sigRaw = wk.privKey.signSync(txSigHash);
|
||||||
|
@ -475,11 +479,9 @@ TransactionBuilder.prototype._findWalletKey = function(walletKeyMap, input) {
|
||||||
|
|
||||||
if (input.address) {
|
if (input.address) {
|
||||||
wk = walletKeyMap[input.address];
|
wk = walletKeyMap[input.address];
|
||||||
}
|
} else if (input.pubKeyHash) {
|
||||||
else if (input.pubKeyHash) {
|
|
||||||
wk = this._multiFindKey(walletKeyMap, input.pubKeyHash);
|
wk = this._multiFindKey(walletKeyMap, input.pubKeyHash);
|
||||||
}
|
} else if (input.pubKeyBuf) {
|
||||||
else if (input.pubKeyBuf) {
|
|
||||||
var pubKeyHash = util.sha256ripe160(input.pubKeyBuf);
|
var pubKeyHash = util.sha256ripe160(input.pubKeyBuf);
|
||||||
wk = this._multiFindKey(walletKeyMap, pubKeyHash);
|
wk = this._multiFindKey(walletKeyMap, pubKeyHash);
|
||||||
} else {
|
} else {
|
||||||
|
@ -502,7 +504,11 @@ TransactionBuilder.prototype._signPubKey = function(walletKeyMap, input, txSigHa
|
||||||
var scriptSig = new Script();
|
var scriptSig = new Script();
|
||||||
scriptSig.chunks.push(sig);
|
scriptSig.chunks.push(sig);
|
||||||
scriptSig.updateBuffer();
|
scriptSig.updateBuffer();
|
||||||
return {inputFullySigned: true, signaturesAdded: 1, script: scriptSig.getBuffer()};
|
return {
|
||||||
|
inputFullySigned: true,
|
||||||
|
signaturesAdded: 1,
|
||||||
|
script: scriptSig.getBuffer()
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
TransactionBuilder.prototype._signPubKeyHash = function(walletKeyMap, input, txSigHash) {
|
TransactionBuilder.prototype._signPubKeyHash = function(walletKeyMap, input, txSigHash) {
|
||||||
|
@ -521,7 +527,11 @@ TransactionBuilder.prototype._signPubKeyHash = function(walletKeyMap, input, txS
|
||||||
scriptSig.chunks.push(sig);
|
scriptSig.chunks.push(sig);
|
||||||
scriptSig.chunks.push(wk.privKey.public);
|
scriptSig.chunks.push(wk.privKey.public);
|
||||||
scriptSig.updateBuffer();
|
scriptSig.updateBuffer();
|
||||||
return {inputFullySigned: true, signaturesAdded: 1, script: scriptSig.getBuffer()};
|
return {
|
||||||
|
inputFullySigned: true,
|
||||||
|
signaturesAdded: 1,
|
||||||
|
script: scriptSig.getBuffer()
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/* FOR TESTING
|
/* FOR TESTING
|
||||||
|
@ -618,7 +628,9 @@ TransactionBuilder.prototype._signMultiSig = function(walletKeyMap, input, txSig
|
||||||
var signaturesAdded = 0;
|
var signaturesAdded = 0;
|
||||||
|
|
||||||
for (var j = 0; j < l && scriptSig.countSignatures() < nreq; j++) {
|
for (var j = 0; j < l && scriptSig.countSignatures() < nreq; j++) {
|
||||||
var wk = this._findWalletKey(walletKeyMap, {pubKeyBuf: pubkeys[j]});
|
var wk = this._findWalletKey(walletKeyMap, {
|
||||||
|
pubKeyBuf: pubkeys[j]
|
||||||
|
});
|
||||||
if (!wk) continue;
|
if (!wk) continue;
|
||||||
|
|
||||||
var newScriptSig = this._updateMultiSig(j, wk, scriptSig, txSigHash, pubkeys);
|
var newScriptSig = this._updateMultiSig(j, wk, scriptSig, txSigHash, pubkeys);
|
||||||
|
@ -855,8 +867,7 @@ TransactionBuilder.prototype._checkMergeability = function(b) {
|
||||||
.forEach(function(k) {
|
.forEach(function(k) {
|
||||||
|
|
||||||
if (self[k].toString() !== b[k].toString()) {
|
if (self[k].toString() !== b[k].toString()) {
|
||||||
throw new Error('mismatch at TransactionBuilder match: '
|
throw new Error('mismatch at TransactionBuilder match: ' + k + ': ' + self[k] + ' vs. ' + b[k]);
|
||||||
+ k + ': ' + self[k] + ' vs. ' + b[k]);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -872,7 +883,8 @@ TransactionBuilder.prototype._checkMergeability = function(b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var err = 0, i=0;;
|
var err = 0,
|
||||||
|
i = 0;;
|
||||||
self.selectedUtxos.forEach(function(u) {
|
self.selectedUtxos.forEach(function(u) {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
var v = b.selectedUtxos[i++];
|
var v = b.selectedUtxos[i++];
|
||||||
|
@ -888,7 +900,8 @@ TransactionBuilder.prototype._checkMergeability = function(b) {
|
||||||
throw new Error('mismatch at TransactionBuilder selectedUtxos #' + i - 1 + ' Key:' + err);
|
throw new Error('mismatch at TransactionBuilder selectedUtxos #' + i - 1 + ' Key:' + err);
|
||||||
|
|
||||||
|
|
||||||
err = 0; i=0;;
|
err = 0;
|
||||||
|
i = 0;;
|
||||||
self.inputMap.forEach(function(u) {
|
self.inputMap.forEach(function(u) {
|
||||||
if (!err) {
|
if (!err) {
|
||||||
var v = b.inputMap[i++];
|
var v = b.inputMap[i++];
|
||||||
|
@ -969,8 +982,7 @@ TransactionBuilder.prototype._mergeInputSig = function(index, s0buf, s1buf) {
|
||||||
log.debug('Merging two signed inputs type:' +
|
log.debug('Merging two signed inputs type:' +
|
||||||
input.scriptPubKey.getRawOutType() + '. Signatures differs. Using the first version.');
|
input.scriptPubKey.getRawOutType() + '. Signatures differs. Using the first version.');
|
||||||
return s0buf;
|
return s0buf;
|
||||||
}
|
} else if (type !== Script.TX_SCRIPTHASH) {
|
||||||
else if (type!== Script.TX_SCRIPTHASH) {
|
|
||||||
// No support for normal multisig or strange txs.
|
// No support for normal multisig or strange txs.
|
||||||
throw new Error('Script type:' + input.scriptPubKey.getRawOutType() + 'not supported at #merge');
|
throw new Error('Script type:' + input.scriptPubKey.getRawOutType() + 'not supported at #merge');
|
||||||
}
|
}
|
||||||
|
@ -1013,8 +1025,7 @@ TransactionBuilder.prototype.merge = function(b) {
|
||||||
|
|
||||||
// Does this tX have any signature already?
|
// Does this tX have any signature already?
|
||||||
if (this.tx || b.tx) {
|
if (this.tx || b.tx) {
|
||||||
if (this.tx.getNormalizedHash().toString('hex')
|
if (this.tx.getNormalizedHash().toString('hex') !== b.tx.getNormalizedHash().toString('hex'))
|
||||||
!== b.tx.getNormalizedHash().toString('hex'))
|
|
||||||
throw new Error('mismatch at TransactionBuilder NTXID');
|
throw new Error('mismatch at TransactionBuilder NTXID');
|
||||||
|
|
||||||
this._mergeTx(b.tx);
|
this._mergeTx(b.tx);
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
var imports = require('soop').imports();
|
var imports = require('soop').imports();
|
||||||
|
|
||||||
var hex = function(hex) {return new Buffer(hex, 'hex');};
|
var hex = function(hex) {
|
||||||
|
return new Buffer(hex, 'hex');
|
||||||
|
};
|
||||||
|
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var EncFile = require('../util/EncFile');
|
var EncFile = require('../util/EncFile');
|
||||||
|
@ -137,4 +139,3 @@ Wallet.prototype.addScript = function(script) {
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = require('soop')(Wallet);
|
module.exports = require('soop')(Wallet);
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,9 @@ var MAX = 1E9, // 0 to 1e+9
|
||||||
outOfRange,
|
outOfRange,
|
||||||
id = 0,
|
id = 0,
|
||||||
isValid = /^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,
|
isValid = /^-?(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i,
|
||||||
trim = String.prototype.trim || function () {return this.replace(/^\s+|\s+$/g, '')},
|
trim = String.prototype.trim || function() {
|
||||||
|
return this.replace(/^\s+|\s+$/g, '')
|
||||||
|
},
|
||||||
ONE = BigNumber(1);
|
ONE = BigNumber(1);
|
||||||
|
|
||||||
|
|
||||||
|
@ -238,8 +240,7 @@ function BigNumber( n, b ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine leading zeros.
|
// Determine leading zeros.
|
||||||
for ( i = 0; n.charAt(i) == '0'; i++ ) {
|
for (i = 0; n.charAt(i) == '0'; i++) {}
|
||||||
}
|
|
||||||
|
|
||||||
b = n.length;
|
b = n.length;
|
||||||
|
|
||||||
|
@ -265,15 +266,13 @@ function BigNumber( n, b ) {
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Determine trailing zeros.
|
// Determine trailing zeros.
|
||||||
for ( ; n.charAt(--b) == '0'; ) {
|
for (; n.charAt(--b) == '0';) {}
|
||||||
}
|
|
||||||
|
|
||||||
x['e'] = e;
|
x['e'] = e;
|
||||||
x['c'] = [];
|
x['c'] = [];
|
||||||
|
|
||||||
// Convert string to array of digits (without leading and trailing zeros).
|
// Convert string to array of digits (without leading and trailing zeros).
|
||||||
for ( e = 0; i <= b; x['c'][e++] = +n.charAt(i++) ) {
|
for (e = 0; i <= b; x['c'][e++] = +n.charAt(i++)) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,16 +297,15 @@ BigNumber['fromBuffer'] = function (buf, opts) {
|
||||||
|
|
||||||
if (!opts) opts = {};
|
if (!opts) opts = {};
|
||||||
|
|
||||||
var endian = { 1 : 'big', '-1' : 'little' }[opts.endian]
|
var endian = {
|
||||||
|| opts.endian || 'big'
|
1: 'big',
|
||||||
;
|
'-1': 'little'
|
||||||
|
}[opts.endian] || opts.endian || 'big';
|
||||||
|
|
||||||
var size = opts.size === 'auto' ? Math.ceil(buf.length) : (opts.size || 1);
|
var size = opts.size === 'auto' ? Math.ceil(buf.length) : (opts.size || 1);
|
||||||
|
|
||||||
if (buf.length % size !== 0) {
|
if (buf.length % size !== 0) {
|
||||||
throw new RangeError('Buffer length (' + buf.length + ')'
|
throw new RangeError('Buffer length (' + buf.length + ')' + ' must be a multiple of size (' + size + ')');
|
||||||
+ ' must be a multiple of size (' + size + ')'
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var hex = [];
|
var hex = [];
|
||||||
|
@ -356,9 +354,11 @@ BigNumber['config'] = function () {
|
||||||
return !((outOfRange = n < lo || n > hi) ||
|
return !((outOfRange = n < lo || n > hi) ||
|
||||||
parse(n) != n && n !== 0);
|
parse(n) != n && n !== 0);
|
||||||
},
|
},
|
||||||
has = o && typeof o == 'object'
|
has = o && typeof o == 'object' ? function() {
|
||||||
? function () {if ( o.hasOwnProperty(p) ) return ( v = o[p] ) != null}
|
if (o.hasOwnProperty(p)) return (v = o[p]) != null
|
||||||
: function () {if ( a.length > i ) return ( v = a[i++] ) != null};
|
} : function() {
|
||||||
|
if (a.length > i) return (v = a[i++]) != null
|
||||||
|
};
|
||||||
|
|
||||||
// [DECIMAL_PLACES] {number} Integer, 0 to MAX inclusive.
|
// [DECIMAL_PLACES] {number} Integer, 0 to MAX inclusive.
|
||||||
if (has(p = 'DECIMAL_PLACES')) {
|
if (has(p = 'DECIMAL_PLACES')) {
|
||||||
|
@ -433,9 +433,7 @@ BigNumber['config'] = function () {
|
||||||
if (has(p = 'ERRORS')) {
|
if (has(p = 'ERRORS')) {
|
||||||
|
|
||||||
if (v === !!v || v === 1 || v === 0) {
|
if (v === !!v || v === 1 || v === 0) {
|
||||||
parse = ( outOfRange = id = 0, ERRORS = !!v )
|
parse = (outOfRange = id = 0, ERRORS = !!v) ? parseInt : parseFloat;
|
||||||
? parseInt
|
|
||||||
: parseFloat;
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// 'config() ERRORS not a boolean or binary digit: {v}'
|
// 'config() ERRORS not a boolean or binary digit: {v}'
|
||||||
|
@ -466,14 +464,9 @@ function ifExceptionsThrow( arg, i, j, isArray, isRange, isErrors) {
|
||||||
method + ' number type has more than 15 significant digits',
|
method + ' number type has more than 15 significant digits',
|
||||||
method + ' not a base ' + j + ' number',
|
method + ' not a base ' + j + ' number',
|
||||||
method + ' base' + message,
|
method + ' base' + message,
|
||||||
method + ' not a number' ][i] ||
|
method + ' not a number'
|
||||||
j + '() ' + i + ( isErrors
|
][i] ||
|
||||||
? ' not a boolean or binary digit'
|
j + '() ' + i + (isErrors ? ' not a boolean or binary digit' : message + (isArray ? ' or not [' + (outOfRange ? ' negative, positive' : ' integer, integer') + ' ]' : ''))) + ': ' + arg;
|
||||||
: message + ( isArray
|
|
||||||
? ' or not [' + ( outOfRange
|
|
||||||
? ' negative, positive'
|
|
||||||
: ' integer, integer' ) + ' ]'
|
|
||||||
: '' ) ) ) + ': ' + arg;
|
|
||||||
|
|
||||||
outOfRange = id = 0;
|
outOfRange = id = 0;
|
||||||
error = new Error(message);
|
error = new Error(message);
|
||||||
|
@ -502,12 +495,9 @@ function convert( nStr, baseOut, baseIn, sign ) {
|
||||||
|
|
||||||
for (bIn = bIn || baseIn; i < strL; i++) {
|
for (bIn = bIn || baseIn; i < strL; i++) {
|
||||||
|
|
||||||
for ( arrL = arr.length, j = 0; j < arrL; arr[j] *= bIn, j++ ) {
|
for (arrL = arr.length, j = 0; j < arrL; arr[j] *= bIn, j++) {}
|
||||||
}
|
|
||||||
|
|
||||||
for ( arr[0] += DIGITS.indexOf( str.charAt(i) ), j = 0;
|
for (arr[0] += DIGITS.indexOf(str.charAt(i)), j = 0; j < arr.length; j++) {
|
||||||
j < arr.length;
|
|
||||||
j++ ) {
|
|
||||||
|
|
||||||
if (arr[j] > baseOut - 1) {
|
if (arr[j] > baseOut - 1) {
|
||||||
|
|
||||||
|
@ -530,8 +520,7 @@ function convert( nStr, baseOut, baseIn, sign ) {
|
||||||
arrL = arr.length,
|
arrL = arr.length,
|
||||||
str = '';
|
str = '';
|
||||||
|
|
||||||
for ( ; i < arrL; str += DIGITS.charAt( arr[i++] ) ) {
|
for (; i < arrL; str += DIGITS.charAt(arr[i++])) {}
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
@ -576,8 +565,7 @@ function convert( nStr, baseOut, baseIn, sign ) {
|
||||||
if (e = fracBN['e']) {
|
if (e = fracBN['e']) {
|
||||||
|
|
||||||
// Append zeros according to the exponent of the result.
|
// Append zeros according to the exponent of the result.
|
||||||
for ( ; ++e; fracArr.unshift(0) ) {
|
for (; ++e; fracArr.unshift(0)) {}
|
||||||
}
|
|
||||||
|
|
||||||
// Append the fraction part to the converted integer part.
|
// Append the fraction part to the converted integer part.
|
||||||
nStr = arrToStr(nArr) + '.' + arrToStr(fracArr);
|
nStr = arrToStr(nArr) + '.' + arrToStr(fracArr);
|
||||||
|
@ -625,8 +613,7 @@ function divide( dvd, dvs, exp, s, base, isOdd ) {
|
||||||
s = dig < 0 ? 0 : dig;
|
s = dig < 0 ? 0 : dig;
|
||||||
|
|
||||||
// Add zeros to make remainder as long as divisor.
|
// Add zeros to make remainder as long as divisor.
|
||||||
for ( ; remL++ < dvsL; rem.push(0) ) {
|
for (; remL++ < dvsL; rem.push(0)) {}
|
||||||
}
|
|
||||||
|
|
||||||
// Create version of divisor with leading zero.
|
// Create version of divisor with leading zero.
|
||||||
dvsZ.unshift(0);
|
dvsZ.unshift(0);
|
||||||
|
@ -658,17 +645,13 @@ function divide( dvd, dvs, exp, s, base, isOdd ) {
|
||||||
|
|
||||||
if (rem[--remL] < dvsT[remL]) {
|
if (rem[--remL] < dvsT[remL]) {
|
||||||
|
|
||||||
for ( remI = remL;
|
for (remI = remL; remI && !rem[--remI]; rem[remI] = base - 1) {}
|
||||||
remI && !rem[--remI];
|
|
||||||
rem[remI] = base - 1 ) {
|
|
||||||
}
|
|
||||||
--rem[remI];
|
--rem[remI];
|
||||||
rem[remL] += base;
|
rem[remL] += base;
|
||||||
}
|
}
|
||||||
rem[remL] -= dvsT[remL];
|
rem[remL] -= dvsT[remL];
|
||||||
}
|
}
|
||||||
for ( ; !rem[0]; rem.shift() ) {
|
for (; !rem[0]; rem.shift()) {}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -678,9 +661,7 @@ function divide( dvd, dvs, exp, s, base, isOdd ) {
|
||||||
qc[qi++] = cmp ? next : ++next;
|
qc[qi++] = cmp ? next : ++next;
|
||||||
|
|
||||||
// Update the remainder.
|
// Update the remainder.
|
||||||
rem[0] && cmp
|
rem[0] && cmp ? (rem[remL] = dvd[dvdI] || 0) : (rem = [dvd[dvdI]]);
|
||||||
? ( rem[remL] = dvd[dvdI] || 0 )
|
|
||||||
: ( rem = [ dvd[dvdI] ] );
|
|
||||||
|
|
||||||
} while ((dvdI++ < dvdL || rem[0] != null) && s--);
|
} while ((dvdI++ < dvdL || rem[0] != null) && s--);
|
||||||
|
|
||||||
|
@ -742,8 +723,7 @@ function format( n, d, exp ) {
|
||||||
i = c[0] == 0 ? i + 1 : exp ? d : n['e'] + i + 1;
|
i = c[0] == 0 ? i + 1 : exp ? d : n['e'] + i + 1;
|
||||||
|
|
||||||
// Append zeros?
|
// Append zeros?
|
||||||
for ( ; c.length < i; c.push(0) ) {
|
for (; c.length < i; c.push(0)) {}
|
||||||
}
|
|
||||||
i = n['e'];
|
i = n['e'];
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -754,9 +734,7 @@ function format( n, d, exp ) {
|
||||||
return exp == 1 || exp == 2 && (--d < i || i <= TO_EXP_NEG)
|
return exp == 1 || exp == 2 && (--d < i || i <= TO_EXP_NEG)
|
||||||
|
|
||||||
// Exponential notation.
|
// Exponential notation.
|
||||||
? ( n['s'] < 0 && c[0] ? '-' : '' ) + ( c.length > 1
|
? (n['s'] < 0 && c[0] ? '-' : '') + (c.length > 1 ? (c.splice(1, 0, '.'), c.join('')) : c[0]) + (i < 0 ? 'e' : 'e+') + i
|
||||||
? ( c.splice( 1, 0, '.' ), c.join('') )
|
|
||||||
: c[0] ) + ( i < 0 ? 'e' : 'e+' ) + i
|
|
||||||
|
|
||||||
// Normal notation.
|
// Normal notation.
|
||||||
: n['toS']();
|
: n['toS']();
|
||||||
|
@ -784,12 +762,10 @@ function rnd( x, dp, base, isOdd, r ) {
|
||||||
*/
|
*/
|
||||||
more = r || i < 0 || xc[i + 1] != null;
|
more = r || i < 0 || xc[i + 1] != null;
|
||||||
|
|
||||||
r = ROUNDING_MODE < 4
|
r = ROUNDING_MODE < 4 ? (next != null || more) &&
|
||||||
? ( next != null || more ) &&
|
|
||||||
(ROUNDING_MODE == 0 ||
|
(ROUNDING_MODE == 0 ||
|
||||||
ROUNDING_MODE == 2 && !isNeg ||
|
ROUNDING_MODE == 2 && !isNeg ||
|
||||||
ROUNDING_MODE == 3 && isNeg )
|
ROUNDING_MODE == 3 && isNeg) : next > half || next == half &&
|
||||||
: next > half || next == half &&
|
|
||||||
(ROUNDING_MODE == 4 || more ||
|
(ROUNDING_MODE == 4 || more ||
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -837,8 +813,7 @@ function rnd( x, dp, base, isOdd, r ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove trailing zeros.
|
// Remove trailing zeros.
|
||||||
for ( i = xc.length; !xc[--i]; xc.pop() ) {
|
for (i = xc.length; !xc[--i]; xc.pop()) {}
|
||||||
}
|
|
||||||
|
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
@ -1152,12 +1127,10 @@ P['minus'] = P['sub'] = function ( y, b ) {
|
||||||
if (!xc[0] || !yc[0]) {
|
if (!xc[0] || !yc[0]) {
|
||||||
|
|
||||||
// y is non-zero?
|
// y is non-zero?
|
||||||
return yc[0]
|
return yc[0] ? (y['s'] = -b, y)
|
||||||
? ( y['s'] = -b, y )
|
|
||||||
|
|
||||||
// x is non-zero?
|
// x is non-zero?
|
||||||
: new BigNumber( xc[0]
|
: new BigNumber(xc[0] ? x
|
||||||
? x
|
|
||||||
|
|
||||||
// Both are zero.
|
// Both are zero.
|
||||||
// IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity
|
// IEEE 754 (2008) 6.3: n - n = -0 when rounding to -Infinity
|
||||||
|
@ -1170,8 +1143,7 @@ P['minus'] = P['sub'] = function ( y, b ) {
|
||||||
if (xc = xc.slice(), a = xe - ye) {
|
if (xc = xc.slice(), a = xe - ye) {
|
||||||
d = (xLTy = a < 0) ? (a = -a, xc) : (ye = xe, yc);
|
d = (xLTy = a < 0) ? (a = -a, xc) : (ye = xe, yc);
|
||||||
|
|
||||||
for ( d.reverse(), b = a; b--; d.push(0) ) {
|
for (d.reverse(), b = a; b--; d.push(0)) {}
|
||||||
}
|
|
||||||
d.reverse();
|
d.reverse();
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
@ -1199,8 +1171,7 @@ P['minus'] = P['sub'] = function ( y, b ) {
|
||||||
*/
|
*/
|
||||||
if ((b = -((j = xc.length) - yc.length)) > 0) {
|
if ((b = -((j = xc.length) - yc.length)) > 0) {
|
||||||
|
|
||||||
for ( ; b--; xc[j++] = 0 ) {
|
for (; b--; xc[j++] = 0) {}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subtract yc from xc.
|
// Subtract yc from xc.
|
||||||
|
@ -1208,8 +1179,7 @@ P['minus'] = P['sub'] = function ( y, b ) {
|
||||||
|
|
||||||
if (xc[--b] < yc[b]) {
|
if (xc[--b] < yc[b]) {
|
||||||
|
|
||||||
for ( i = b; i && !xc[--i]; xc[i] = 9 ) {
|
for (i = b; i && !xc[--i]; xc[i] = 9) {}
|
||||||
}
|
|
||||||
--xc[i];
|
--xc[i];
|
||||||
xc[b] += 10;
|
xc[b] += 10;
|
||||||
}
|
}
|
||||||
|
@ -1217,12 +1187,10 @@ P['minus'] = P['sub'] = function ( y, b ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove trailing zeros.
|
// Remove trailing zeros.
|
||||||
for ( ; xc[--j] == 0; xc.pop() ) {
|
for (; xc[--j] == 0; xc.pop()) {}
|
||||||
}
|
|
||||||
|
|
||||||
// Remove leading zeros and adjust exponent accordingly.
|
// Remove leading zeros and adjust exponent accordingly.
|
||||||
for ( ; xc[0] == 0; xc.shift(), --ye ) {
|
for (; xc[0] == 0; xc.shift(), --ye) {}
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* No need to check for Infinity as +x - +y != Infinity && -x - -y != Infinity
|
* No need to check for Infinity as +x - +y != Infinity && -x - -y != Infinity
|
||||||
|
@ -1280,9 +1248,7 @@ P['modulo'] = P['mod'] = function ( y, b ) {
|
||||||
b = y['cmp'](x) == 1;
|
b = y['cmp'](x) == 1;
|
||||||
x['s'] = i, y['s'] = j;
|
x['s'] = i, y['s'] = j;
|
||||||
|
|
||||||
return b
|
return b ? new BigNumber(x) : (i = DECIMAL_PLACES, j = ROUNDING_MODE,
|
||||||
? new BigNumber(x)
|
|
||||||
: ( i = DECIMAL_PLACES, j = ROUNDING_MODE,
|
|
||||||
DECIMAL_PLACES = 0, ROUNDING_MODE = 1,
|
DECIMAL_PLACES = 0, ROUNDING_MODE = 1,
|
||||||
x = x['div'](y),
|
x = x['div'](y),
|
||||||
DECIMAL_PLACES = i, ROUNDING_MODE = j,
|
DECIMAL_PLACES = i, ROUNDING_MODE = j,
|
||||||
|
@ -1356,12 +1322,10 @@ P['plus'] = P['add'] = function ( y, b ) {
|
||||||
if (!xc[0] || !yc[0]) {
|
if (!xc[0] || !yc[0]) {
|
||||||
|
|
||||||
// y is non-zero?
|
// y is non-zero?
|
||||||
return yc[0]
|
return yc[0] ? y
|
||||||
? y
|
|
||||||
|
|
||||||
// x is non-zero?
|
// x is non-zero?
|
||||||
: new BigNumber( xc[0]
|
: new BigNumber(xc[0] ? x
|
||||||
? x
|
|
||||||
|
|
||||||
// Both are zero. Return zero.
|
// Both are zero. Return zero.
|
||||||
: a * 0);
|
: a * 0);
|
||||||
|
@ -1373,8 +1337,7 @@ P['plus'] = P['add'] = function ( y, b ) {
|
||||||
if (xc = xc.slice(), a = xe - ye) {
|
if (xc = xc.slice(), a = xe - ye) {
|
||||||
d = a > 0 ? (ye = xe, yc) : (a = -a, xc);
|
d = a > 0 ? (ye = xe, yc) : (a = -a, xc);
|
||||||
|
|
||||||
for ( d.reverse(); a--; d.push(0) ) {
|
for (d.reverse(); a--; d.push(0)) {}
|
||||||
}
|
|
||||||
d.reverse();
|
d.reverse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1387,9 +1350,7 @@ P['plus'] = P['add'] = function ( y, b ) {
|
||||||
* Only start adding at yc.length - 1 as the
|
* Only start adding at yc.length - 1 as the
|
||||||
* further digits of xc can be left as they are.
|
* further digits of xc can be left as they are.
|
||||||
*/
|
*/
|
||||||
for ( a = yc.length, b = 0; a;
|
for (a = yc.length, b = 0; a; b = (xc[--a] = xc[a] + yc[a] + b) / 10 ^ 0, xc[a] %= 10) {}
|
||||||
b = ( xc[--a] = xc[a] + yc[a] + b ) / 10 ^ 0, xc[a] %= 10 ) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// No need to check for zero, as +x + +y != 0 && -x + -y != 0
|
// No need to check for zero, as +x + +y != 0 && -x + -y != 0
|
||||||
|
|
||||||
|
@ -1405,8 +1366,7 @@ P['plus'] = P['add'] = function ( y, b ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove trailing zeros.
|
// Remove trailing zeros.
|
||||||
for ( a = xc.length; xc[--a] == 0; xc.pop() ) {
|
for (a = xc.length; xc[--a] == 0; xc.pop()) {}
|
||||||
}
|
|
||||||
|
|
||||||
return y['c'] = xc, y['e'] = ye, y;
|
return y['c'] = xc, y['e'] = ye, y;
|
||||||
};
|
};
|
||||||
|
@ -1494,9 +1454,7 @@ P['round'] = function ( dp, rm ) {
|
||||||
|
|
||||||
// 'round() decimal places out of range: {dp}'
|
// 'round() decimal places out of range: {dp}'
|
||||||
// 'round() decimal places not an integer: {dp}'
|
// 'round() decimal places not an integer: {dp}'
|
||||||
!ifExceptionsThrow( dp, 'decimal places', 'round' ) )
|
!ifExceptionsThrow(dp, 'decimal places', 'round')) ? 0 : dp | 0;
|
||||||
? 0
|
|
||||||
: dp | 0;
|
|
||||||
|
|
||||||
rm = rm == null || (((outOfRange = rm < 0 || rm > 8) ||
|
rm = rm == null || (((outOfRange = rm < 0 || rm > 8) ||
|
||||||
|
|
||||||
|
@ -1505,9 +1463,7 @@ P['round'] = function ( dp, rm ) {
|
||||||
|
|
||||||
// 'round() mode not an integer: {rm}'
|
// 'round() mode not an integer: {rm}'
|
||||||
// 'round() mode out of range: {rm}'
|
// 'round() mode out of range: {rm}'
|
||||||
!ifExceptionsThrow( rm, 'mode', 'round' ) )
|
!ifExceptionsThrow(rm, 'mode', 'round')) ? ROUNDING_MODE : rm | 0;
|
||||||
? ROUNDING_MODE
|
|
||||||
: rm | 0;
|
|
||||||
|
|
||||||
return setMode(this, dp, rm);
|
return setMode(this, dp, rm);
|
||||||
};
|
};
|
||||||
|
@ -1537,9 +1493,7 @@ P['squareRoot'] = P['sqrt'] = function () {
|
||||||
// Negative/NaN/Infinity/zero?
|
// Negative/NaN/Infinity/zero?
|
||||||
if (s !== 1 || !c || !c[0]) {
|
if (s !== 1 || !c || !c[0]) {
|
||||||
|
|
||||||
return new BigNumber( !s || s < 0 && ( !c || c[0] )
|
return new BigNumber(!s || s < 0 && (!c || c[0]) ? NaN : c ? x : 1 / 0);
|
||||||
? NaN
|
|
||||||
: c ? x : 1 / 0 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initial estimate.
|
// Initial estimate.
|
||||||
|
@ -1705,18 +1659,14 @@ P['times'] = P['mul'] = function ( y, b ) {
|
||||||
c = xc, xc = yc, yc = c, j = a, a = b, b = j;
|
c = xc, xc = yc, yc = c, j = a, a = b, b = j;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( j = a + b, c = []; j--; c.push(0) ) {
|
for (j = a + b, c = []; j--; c.push(0)) {}
|
||||||
}
|
|
||||||
|
|
||||||
// Multiply!
|
// Multiply!
|
||||||
for (i = b - 1; i > -1; i--) {
|
for (i = b - 1; i > -1; i--) {
|
||||||
|
|
||||||
for ( b = 0, j = a + i;
|
for (b = 0, j = a + i; j > i; b = c[j] + yc[i] * xc[j - i - 1] + b,
|
||||||
j > i;
|
|
||||||
b = c[j] + yc[i] * xc[j - i - 1] + b,
|
|
||||||
c[j--] = b % 10 | 0,
|
c[j--] = b % 10 | 0,
|
||||||
b = b / 10 | 0 ) {
|
b = b / 10 | 0) {}
|
||||||
}
|
|
||||||
|
|
||||||
if (b) {
|
if (b) {
|
||||||
c[j] = (c[j] + b) % 10;
|
c[j] = (c[j] + b) % 10;
|
||||||
|
@ -1729,8 +1679,7 @@ P['times'] = P['mul'] = function ( y, b ) {
|
||||||
!c[0] && c.shift();
|
!c[0] && c.shift();
|
||||||
|
|
||||||
// Remove trailing zeros.
|
// Remove trailing zeros.
|
||||||
for ( j = c.length; !c[--j]; c.pop() ) {
|
for (j = c.length; !c[--j]; c.pop()) {}
|
||||||
}
|
|
||||||
|
|
||||||
// No zero check needed as only x * 0 == 0 etc.
|
// No zero check needed as only x * 0 == 0 etc.
|
||||||
|
|
||||||
|
@ -1761,7 +1710,10 @@ P['toBuffer'] = function ( opts ) {
|
||||||
if (opts !== 'mpint') return 'Unsupported Buffer representation';
|
if (opts !== 'mpint') return 'Unsupported Buffer representation';
|
||||||
|
|
||||||
var abs = this.abs();
|
var abs = this.abs();
|
||||||
var buf = abs.toBuffer({ size : 1, endian : 'big' });
|
var buf = abs.toBuffer({
|
||||||
|
size: 1,
|
||||||
|
endian: 'big'
|
||||||
|
});
|
||||||
var len = buf.length === 1 && buf[0] === 0 ? 0 : buf.length;
|
var len = buf.length === 1 && buf[0] === 0 ? 0 : buf.length;
|
||||||
if (buf[0] & 0x80) len++;
|
if (buf[0] & 0x80) len++;
|
||||||
|
|
||||||
|
@ -1789,9 +1741,10 @@ P['toBuffer'] = function ( opts ) {
|
||||||
|
|
||||||
if (!opts) opts = {};
|
if (!opts) opts = {};
|
||||||
|
|
||||||
var endian = { 1 : 'big', '-1' : 'little' }[opts.endian]
|
var endian = {
|
||||||
|| opts.endian || 'big'
|
1: 'big',
|
||||||
;
|
'-1': 'little'
|
||||||
|
}[opts.endian] || opts.endian || 'big';
|
||||||
|
|
||||||
var hex = this.toString(16);
|
var hex = this.toString(16);
|
||||||
if (hex.charAt(0) === '-') throw new Error(
|
if (hex.charAt(0) === '-') throw new Error(
|
||||||
|
@ -1808,8 +1761,9 @@ P['toBuffer'] = function ( opts ) {
|
||||||
|
|
||||||
var hx = hex
|
var hx = hex
|
||||||
.split(new RegExp('(.{' + (2 * size) + '})'))
|
.split(new RegExp('(.{' + (2 * size) + '})'))
|
||||||
.filter(function (s) { return s.length > 0 })
|
.filter(function(s) {
|
||||||
;
|
return s.length > 0
|
||||||
|
});
|
||||||
|
|
||||||
hx.forEach(function(chunk, i) {
|
hx.forEach(function(chunk, i) {
|
||||||
for (var j = 0; j < size; j++) {
|
for (var j = 0; j < size; j++) {
|
||||||
|
@ -1830,8 +1784,7 @@ P['toBuffer'] = function ( opts ) {
|
||||||
*/
|
*/
|
||||||
P['toExponential'] = P['toE'] = function(dp) {
|
P['toExponential'] = P['toE'] = function(dp) {
|
||||||
|
|
||||||
return format( this,
|
return format(this, (dp == null || ((outOfRange = dp < 0 || dp > MAX) ||
|
||||||
( dp == null || ( ( outOfRange = dp < 0 || dp > MAX ) ||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Include '&& dp !== 0' because with Opera -0 == parseFloat(-0) is
|
* Include '&& dp !== 0' because with Opera -0 == parseFloat(-0) is
|
||||||
|
@ -1841,9 +1794,7 @@ P['toExponential'] = P['toE'] = function ( dp ) {
|
||||||
|
|
||||||
// 'toE() decimal places not an integer: {dp}'
|
// 'toE() decimal places not an integer: {dp}'
|
||||||
// 'toE() decimal places out of range: {dp}'
|
// 'toE() decimal places out of range: {dp}'
|
||||||
!ifExceptionsThrow( dp, 'decimal places', 'toE' ) ) && this['c']
|
!ifExceptionsThrow(dp, 'decimal places', 'toE')) && this['c'] ? this['c'].length - 1 : dp | 0, 1);
|
||||||
? this['c'].length - 1
|
|
||||||
: dp | 0, 1 );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -1981,9 +1932,7 @@ P['toFraction'] = P['toFr'] = function ( maxD ) {
|
||||||
|
|
||||||
// Determine which fraction is closer to x, n0 / d0 or n1 / d1?
|
// Determine which fraction is closer to x, n0 / d0 or n1 / d1?
|
||||||
frac = n1['div'](d1)['minus'](x)['abs']()['cmp'](
|
frac = n1['div'](d1)['minus'](x)['abs']()['cmp'](
|
||||||
n0['div'](d0)['minus'](x)['abs']() ) < 1
|
n0['div'](d0)['minus'](x)['abs']()) < 1 ? [n1['toS'](), d1['toS']()] : [n0['toS'](), d0['toS']()];
|
||||||
? [ n1['toS'](), d1['toS']() ]
|
|
||||||
: [ n0['toS'](), d0['toS']() ];
|
|
||||||
|
|
||||||
return MAX_EXP = exp, DECIMAL_PLACES = dp, frac;
|
return MAX_EXP = exp, DECIMAL_PLACES = dp, frac;
|
||||||
};
|
};
|
||||||
|
@ -2009,9 +1958,7 @@ P['toPrecision'] = P['toP'] = function ( sd ) {
|
||||||
|
|
||||||
// 'toP() precision not an integer: {sd}'
|
// 'toP() precision not an integer: {sd}'
|
||||||
// 'toP() precision out of range: {sd}'
|
// 'toP() precision out of range: {sd}'
|
||||||
!ifExceptionsThrow( sd, 'precision', 'toP' ) )
|
!ifExceptionsThrow(sd, 'precision', 'toP')) ? this['toS']() : format(this, --sd | 0, 2);
|
||||||
? this['toS']()
|
|
||||||
: format( this, --sd | 0, 2 );
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -2044,8 +1991,7 @@ P['toString'] = P['toS'] = function ( b ) {
|
||||||
if (xe < 0) {
|
if (xe < 0) {
|
||||||
|
|
||||||
// Prepend zeros.
|
// Prepend zeros.
|
||||||
for ( ; ++xe; str = '0' + str ) {
|
for (; ++xe; str = '0' + str) {}
|
||||||
}
|
|
||||||
str = '0.' + str;
|
str = '0.' + str;
|
||||||
|
|
||||||
// Positive exponent?
|
// Positive exponent?
|
||||||
|
@ -2054,8 +2000,7 @@ P['toString'] = P['toS'] = function ( b ) {
|
||||||
if (++xe > strL) {
|
if (++xe > strL) {
|
||||||
|
|
||||||
// Append zeros.
|
// Append zeros.
|
||||||
for ( xe -= strL; xe-- ; str += '0' ) {
|
for (xe -= strL; xe--; str += '0') {}
|
||||||
}
|
|
||||||
} else if (xe < strL) {
|
} else if (xe < strL) {
|
||||||
str = str.slice(0, xe) + '.' + str.slice(xe);
|
str = str.slice(0, xe) + '.' + str.slice(xe);
|
||||||
}
|
}
|
||||||
|
@ -2118,6 +2063,9 @@ P['valueOf'] = function () {
|
||||||
|
|
||||||
|
|
||||||
// EXPORT
|
// EXPORT
|
||||||
BigNumber.config({EXPONENTIAL_AT: 9999999, DECIMAL_PLACES: 0, ROUNDING_MODE: 1});
|
BigNumber.config({
|
||||||
|
EXPONENTIAL_AT: 9999999,
|
||||||
|
DECIMAL_PLACES: 0,
|
||||||
|
ROUNDING_MODE: 1
|
||||||
|
});
|
||||||
module.exports = BigNumber;
|
module.exports = BigNumber;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,13 @@ ECIES.symmetricEncrypt = function(key, iv, message) {
|
||||||
var smessage = sjcl.codec.hex.toBits(message.toString('hex'));
|
var smessage = sjcl.codec.hex.toBits(message.toString('hex'));
|
||||||
|
|
||||||
sjcl.beware["CBC mode is dangerous because it doesn't protect message integrity."]();
|
sjcl.beware["CBC mode is dangerous because it doesn't protect message integrity."]();
|
||||||
var params = {iv: siv, ks: 256, ts: 128, iter: 1000, mode: 'cbc'};
|
var params = {
|
||||||
|
iv: siv,
|
||||||
|
ks: 256,
|
||||||
|
ts: 128,
|
||||||
|
iter: 1000,
|
||||||
|
mode: 'cbc'
|
||||||
|
};
|
||||||
var encrypted = sjcl.encrypt(skey, smessage, params);
|
var encrypted = sjcl.encrypt(skey, smessage, params);
|
||||||
var enchex = sjcl.codec.hex.fromBits(sjcl.codec.base64.toBits(JSON.parse(encrypted).ct));
|
var enchex = sjcl.codec.hex.fromBits(sjcl.codec.base64.toBits(JSON.parse(encrypted).ct));
|
||||||
|
|
||||||
|
@ -29,7 +35,17 @@ ECIES.symmetricDecrypt = function(key, encrypted) {
|
||||||
var sct = sjcl.codec.base64.fromBits(sjcl.codec.hex.toBits(todecrypt.toString('hex')));
|
var sct = sjcl.codec.base64.fromBits(sjcl.codec.hex.toBits(todecrypt.toString('hex')));
|
||||||
|
|
||||||
sjcl.beware["CBC mode is dangerous because it doesn't protect message integrity."]();
|
sjcl.beware["CBC mode is dangerous because it doesn't protect message integrity."]();
|
||||||
var obj = {iv: siv, v: 1, iter: 1000, ks: 256, ts: 128, mode: 'cbc', adata: '', cipher: 'aes', ct: sct};
|
var obj = {
|
||||||
|
iv: siv,
|
||||||
|
v: 1,
|
||||||
|
iter: 1000,
|
||||||
|
ks: 256,
|
||||||
|
ts: 128,
|
||||||
|
mode: 'cbc',
|
||||||
|
adata: '',
|
||||||
|
cipher: 'aes',
|
||||||
|
ct: sct
|
||||||
|
};
|
||||||
var str = JSON.stringify(obj);
|
var str = JSON.stringify(obj);
|
||||||
|
|
||||||
var decrypted = sjcl.decrypt(skey, str);
|
var decrypted = sjcl.decrypt(skey, str);
|
||||||
|
|
|
@ -61,7 +61,9 @@ Key.generateSync = function() {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
privbuf = SecureRandom.getRandomBuffer(32);
|
privbuf = SecureRandom.getRandomBuffer(32);
|
||||||
if ((bignum.fromBuffer(privbuf, {size: 32})).cmp(Curve.getN()) < 0)
|
if ((bignum.fromBuffer(privbuf, {
|
||||||
|
size: 32
|
||||||
|
})).cmp(Curve.getN()) < 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,17 +19,25 @@ var Point = function(x, y) {
|
||||||
Point.add = function(p1, p2) {
|
Point.add = function(p1, p2) {
|
||||||
var ecparams = getSECCurveByName('secp256k1');
|
var ecparams = getSECCurveByName('secp256k1');
|
||||||
|
|
||||||
var p1xhex = p1.x.toBuffer({size: 32}).toString('hex');
|
var p1xhex = p1.x.toBuffer({
|
||||||
|
size: 32
|
||||||
|
}).toString('hex');
|
||||||
var p1x = new BigInteger(p1xhex, 16);
|
var p1x = new BigInteger(p1xhex, 16);
|
||||||
var p1yhex = p1.y.toBuffer({size: 32}).toString('hex');
|
var p1yhex = p1.y.toBuffer({
|
||||||
|
size: 32
|
||||||
|
}).toString('hex');
|
||||||
var p1y = new BigInteger(p1yhex, 16);
|
var p1y = new BigInteger(p1yhex, 16);
|
||||||
var p1px = new ECFieldElementFp(ecparams.getCurve().getQ(), p1x);
|
var p1px = new ECFieldElementFp(ecparams.getCurve().getQ(), p1x);
|
||||||
var p1py = new ECFieldElementFp(ecparams.getCurve().getQ(), p1y);
|
var p1py = new ECFieldElementFp(ecparams.getCurve().getQ(), p1y);
|
||||||
var p1p = new ECPointFp(ecparams.getCurve(), p1px, p1py);
|
var p1p = new ECPointFp(ecparams.getCurve(), p1px, p1py);
|
||||||
|
|
||||||
var p2xhex = p2.x.toBuffer({size: 32}).toString('hex');
|
var p2xhex = p2.x.toBuffer({
|
||||||
|
size: 32
|
||||||
|
}).toString('hex');
|
||||||
var p2x = new BigInteger(p2xhex, 16);
|
var p2x = new BigInteger(p2xhex, 16);
|
||||||
var p2yhex = p2.y.toBuffer({size: 32}).toString('hex');
|
var p2yhex = p2.y.toBuffer({
|
||||||
|
size: 32
|
||||||
|
}).toString('hex');
|
||||||
var p2y = new BigInteger(p2yhex, 16);
|
var p2y = new BigInteger(p2yhex, 16);
|
||||||
var p2px = new ECFieldElementFp(ecparams.getCurve().getQ(), p2x);
|
var p2px = new ECFieldElementFp(ecparams.getCurve().getQ(), p2x);
|
||||||
var p2py = new ECFieldElementFp(ecparams.getCurve().getQ(), p2y);
|
var p2py = new ECFieldElementFp(ecparams.getCurve().getQ(), p2y);
|
||||||
|
@ -39,11 +47,15 @@ Point.add = function(p1, p2) {
|
||||||
|
|
||||||
var point = new Point();
|
var point = new Point();
|
||||||
var pointxbuf = new Buffer(p.getX().toBigInteger().toByteArrayUnsigned());
|
var pointxbuf = new Buffer(p.getX().toBigInteger().toByteArrayUnsigned());
|
||||||
point.x = bignum.fromBuffer(pointxbuf, {size: pointxbuf.length});
|
point.x = bignum.fromBuffer(pointxbuf, {
|
||||||
|
size: pointxbuf.length
|
||||||
|
});
|
||||||
assert(pointxbuf.length <= 32);
|
assert(pointxbuf.length <= 32);
|
||||||
var pointybuf = new Buffer(p.getY().toBigInteger().toByteArrayUnsigned());
|
var pointybuf = new Buffer(p.getY().toBigInteger().toByteArrayUnsigned());
|
||||||
assert(pointybuf.length <= 32);
|
assert(pointybuf.length <= 32);
|
||||||
point.y = bignum.fromBuffer(pointybuf, {size: pointybuf.length});
|
point.y = bignum.fromBuffer(pointybuf, {
|
||||||
|
size: pointybuf.length
|
||||||
|
});
|
||||||
|
|
||||||
return point;
|
return point;
|
||||||
};
|
};
|
||||||
|
@ -53,9 +65,13 @@ Point.multiply = function(p1, x) {
|
||||||
|
|
||||||
var ecparams = getSECCurveByName('secp256k1');
|
var ecparams = getSECCurveByName('secp256k1');
|
||||||
|
|
||||||
var p1xhex = p1.x.toBuffer({size: 32}).toString('hex');
|
var p1xhex = p1.x.toBuffer({
|
||||||
|
size: 32
|
||||||
|
}).toString('hex');
|
||||||
var p1x = new BigInteger(p1xhex, 16);
|
var p1x = new BigInteger(p1xhex, 16);
|
||||||
var p1yhex = p1.y.toBuffer({size: 32}).toString('hex');
|
var p1yhex = p1.y.toBuffer({
|
||||||
|
size: 32
|
||||||
|
}).toString('hex');
|
||||||
var p1y = new BigInteger(p1yhex, 16);
|
var p1y = new BigInteger(p1yhex, 16);
|
||||||
var p1px = new ECFieldElementFp(ecparams.getCurve().getQ(), p1x);
|
var p1px = new ECFieldElementFp(ecparams.getCurve().getQ(), p1x);
|
||||||
var p1py = new ECFieldElementFp(ecparams.getCurve().getQ(), p1y);
|
var p1py = new ECFieldElementFp(ecparams.getCurve().getQ(), p1y);
|
||||||
|
@ -65,11 +81,15 @@ Point.multiply = function(p1, x) {
|
||||||
|
|
||||||
var point = new Point();
|
var point = new Point();
|
||||||
var pointxbuf = new Buffer(p.getX().toBigInteger().toByteArrayUnsigned());
|
var pointxbuf = new Buffer(p.getX().toBigInteger().toByteArrayUnsigned());
|
||||||
point.x = bignum.fromBuffer(pointxbuf, {size: pointxbuf.length});
|
point.x = bignum.fromBuffer(pointxbuf, {
|
||||||
|
size: pointxbuf.length
|
||||||
|
});
|
||||||
assert(pointxbuf.length <= 32);
|
assert(pointxbuf.length <= 32);
|
||||||
var pointybuf = new Buffer(p.getY().toBigInteger().toByteArrayUnsigned());
|
var pointybuf = new Buffer(p.getY().toBigInteger().toByteArrayUnsigned());
|
||||||
assert(pointybuf.length <= 32);
|
assert(pointybuf.length <= 32);
|
||||||
point.y = bignum.fromBuffer(pointybuf, {size: pointybuf.length});
|
point.y = bignum.fromBuffer(pointybuf, {
|
||||||
|
size: pointybuf.length
|
||||||
|
});
|
||||||
|
|
||||||
return point;
|
return point;
|
||||||
};
|
};
|
||||||
|
@ -77,15 +97,23 @@ Point.multiply = function(p1, x) {
|
||||||
//convert the public key of a Key into a Point
|
//convert the public key of a Key into a Point
|
||||||
Point.fromUncompressedPubKey = function(pubkey) {
|
Point.fromUncompressedPubKey = function(pubkey) {
|
||||||
var point = new Point();
|
var point = new Point();
|
||||||
point.x = bignum.fromBuffer((new Buffer(pubkey)).slice(1, 33), {size: 32});
|
point.x = bignum.fromBuffer((new Buffer(pubkey)).slice(1, 33), {
|
||||||
point.y = bignum.fromBuffer((new Buffer(pubkey)).slice(33, 65), {size: 32});
|
size: 32
|
||||||
|
});
|
||||||
|
point.y = bignum.fromBuffer((new Buffer(pubkey)).slice(33, 65), {
|
||||||
|
size: 32
|
||||||
|
});
|
||||||
return point;
|
return point;
|
||||||
};
|
};
|
||||||
|
|
||||||
//convert the Point into the Key containing a compressed public key
|
//convert the Point into the Key containing a compressed public key
|
||||||
Point.prototype.toUncompressedPubKey = function() {
|
Point.prototype.toUncompressedPubKey = function() {
|
||||||
var xbuf = this.x.toBuffer({size: 32});
|
var xbuf = this.x.toBuffer({
|
||||||
var ybuf = this.y.toBuffer({size: 32});
|
size: 32
|
||||||
|
});
|
||||||
|
var ybuf = this.y.toBuffer({
|
||||||
|
size: 32
|
||||||
|
});
|
||||||
var prefix = new Buffer([0x04]);
|
var prefix = new Buffer([0x04]);
|
||||||
var pub = Buffer.concat([prefix, xbuf, ybuf]);
|
var pub = Buffer.concat([prefix, xbuf, ybuf]);
|
||||||
return pub;
|
return pub;
|
||||||
|
|
|
@ -6,8 +6,7 @@ var SecureRandom = imports.SecureRandom || require('../SecureRandom');
|
||||||
var Key = imports.Key || require('../Key');
|
var Key = imports.Key || require('../Key');
|
||||||
|
|
||||||
// http://en.wikipedia.org/wiki/Integrated_Encryption_Scheme
|
// http://en.wikipedia.org/wiki/Integrated_Encryption_Scheme
|
||||||
var ECIES = function() {
|
var ECIES = function() {};
|
||||||
};
|
|
||||||
|
|
||||||
ECIES.encryptObj = function(pubkey, message, r, iv) {
|
ECIES.encryptObj = function(pubkey, message, r, iv) {
|
||||||
var ecies = new ECIES();
|
var ecies = new ECIES();
|
||||||
|
@ -42,7 +41,9 @@ ECIES.decryptObj = function(ecies) {
|
||||||
var c = ecies.c;
|
var c = ecies.c;
|
||||||
var d = ecies.d;
|
var d = ecies.d;
|
||||||
var P = Point.multiply(R, kB);
|
var P = Point.multiply(R, kB);
|
||||||
var S = P.x.toBuffer({size: 32});
|
var S = P.x.toBuffer({
|
||||||
|
size: 32
|
||||||
|
});
|
||||||
var buf = ECIES.kdf(S);
|
var buf = ECIES.kdf(S);
|
||||||
var kE = ecies.kE = buf.slice(0, 32);
|
var kE = ecies.kE = buf.slice(0, 32);
|
||||||
var kM = ecies.kM = buf.slice(32, 64);
|
var kM = ecies.kM = buf.slice(32, 64);
|
||||||
|
@ -98,7 +99,9 @@ ECIES.prototype.getSfromPubkey = function() {
|
||||||
key2.compressed = false;
|
key2.compressed = false;
|
||||||
var KBP = Point.fromUncompressedPubKey(key2.public);
|
var KBP = Point.fromUncompressedPubKey(key2.public);
|
||||||
this.P = Point.multiply(KBP, this.r);
|
this.P = Point.multiply(KBP, this.r);
|
||||||
this.S = this.P.x.toBuffer({size: 32});
|
this.S = this.P.x.toBuffer({
|
||||||
|
size: 32
|
||||||
|
});
|
||||||
return this.S;
|
return this.S;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -106,7 +109,9 @@ ECIES.prototype.getSfromPrivkey = function() {
|
||||||
var R = this.R;
|
var R = this.R;
|
||||||
var kB = this.kB;
|
var kB = this.kB;
|
||||||
var SP = Point.multiply(R, kB);
|
var SP = Point.multiply(R, kB);
|
||||||
var S = SP.x.toBuffer({size: 32});
|
var S = SP.x.toBuffer({
|
||||||
|
size: 32
|
||||||
|
});
|
||||||
return S;
|
return S;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
var imports = require('soop');
|
var imports = require('soop');
|
||||||
|
|
||||||
var SecureRandom = function() {
|
var SecureRandom = function() {};
|
||||||
};
|
|
||||||
|
|
||||||
/* secure random bytes that sometimes throws an error due to lack of entropy */
|
/* secure random bytes that sometimes throws an error due to lack of entropy */
|
||||||
SecureRandom.getRandomBuffer = function() {};
|
SecureRandom.getRandomBuffer = function() {};
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
var Put = require('bufferput');
|
var Put = require('bufferput');
|
||||||
var buffertools = require('buffertools');
|
var buffertools = require('buffertools');
|
||||||
var hex = function(hex) {return new Buffer(hex, 'hex');};
|
var hex = function(hex) {
|
||||||
|
return new Buffer(hex, 'hex');
|
||||||
|
};
|
||||||
|
|
||||||
exports.livenet = {
|
exports.livenet = {
|
||||||
name: 'livenet',
|
name: 'livenet',
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var imports = require('soop').imports();
|
var imports = require('soop').imports();
|
||||||
function Parser(buffer)
|
|
||||||
{
|
function Parser(buffer) {
|
||||||
this.subject = buffer;
|
this.subject = buffer;
|
||||||
this.pos = 0;
|
this.pos = 0;
|
||||||
};
|
};
|
||||||
|
@ -102,26 +102,19 @@ function getDecoder(len, fn) {
|
||||||
[1, 2, 4, 8].forEach(function(bytes) {
|
[1, 2, 4, 8].forEach(function(bytes) {
|
||||||
var bits = bytes * 8;
|
var bits = bytes * 8;
|
||||||
|
|
||||||
Parser.prototype['word' + bits + 'le']
|
Parser.prototype['word' + bits + 'le'] = Parser.prototype['word' + bits + 'lu'] = getDecoder(bytes, decodeLEu);
|
||||||
= Parser.prototype['word' + bits + 'lu']
|
|
||||||
= getDecoder(bytes, decodeLEu);
|
|
||||||
|
|
||||||
Parser.prototype['word' + bits + 'ls']
|
Parser.prototype['word' + bits + 'ls'] = getDecoder(bytes, decodeLEs);
|
||||||
= getDecoder(bytes, decodeLEs);
|
|
||||||
|
|
||||||
Parser.prototype['word' + bits + 'be']
|
Parser.prototype['word' + bits + 'be'] = Parser.prototype['word' + bits + 'bu'] = getDecoder(bytes, decodeBEu);
|
||||||
= Parser.prototype['word' + bits + 'bu']
|
|
||||||
= getDecoder(bytes, decodeBEu);
|
|
||||||
|
|
||||||
Parser.prototype['word' + bits + 'bs']
|
Parser.prototype['word' + bits + 'bs'] = getDecoder(bytes, decodeBEs);
|
||||||
= getDecoder(bytes, decodeBEs);
|
|
||||||
|
|
||||||
Parser.prototype.word8 = Parser.prototype.word8u = Parser.prototype.word8be;
|
Parser.prototype.word8 = Parser.prototype.word8u = Parser.prototype.word8be;
|
||||||
Parser.prototype.word8s = Parser.prototype.word8bs;
|
Parser.prototype.word8s = Parser.prototype.word8bs;
|
||||||
});
|
});
|
||||||
|
|
||||||
Parser.prototype.varInt = function ()
|
Parser.prototype.varInt = function() {
|
||||||
{
|
|
||||||
var firstByte = this.word8();
|
var firstByte = this.word8();
|
||||||
switch (firstByte) {
|
switch (firstByte) {
|
||||||
case 0xFD:
|
case 0xFD:
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
|
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var crypto = require('crypto');
|
var crypto = require('crypto');
|
||||||
|
|
||||||
exports.readFileSync = function(enc_method, enc_passphrase, filename)
|
exports.readFileSync = function(enc_method, enc_passphrase, filename) {
|
||||||
{
|
|
||||||
// read entire file into memory
|
// read entire file into memory
|
||||||
var fileData = fs.readFileSync(filename, 'binary');
|
var fileData = fs.readFileSync(filename, 'binary');
|
||||||
if (fileData.length < 32)
|
if (fileData.length < 32)
|
||||||
|
@ -28,14 +26,12 @@ exports.readFileSync = function(enc_method, enc_passphrase, filename)
|
||||||
return dec;
|
return dec;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.readJFileSync = function(enc_method, enc_passphrase, filename)
|
exports.readJFileSync = function(enc_method, enc_passphrase, filename) {
|
||||||
{
|
|
||||||
var raw = this.readFileSync(enc_method, enc_passphrase, filename);
|
var raw = this.readFileSync(enc_method, enc_passphrase, filename);
|
||||||
return JSON.parse(raw);
|
return JSON.parse(raw);
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.writeFileSync = function(enc_method, enc_passphrase, filename, data)
|
exports.writeFileSync = function(enc_method, enc_passphrase, filename, data) {
|
||||||
{
|
|
||||||
// encrypt to ciphertext
|
// encrypt to ciphertext
|
||||||
var cipher = crypto.createCipher(enc_method, enc_passphrase);
|
var cipher = crypto.createCipher(enc_method, enc_passphrase);
|
||||||
var crypted = cipher.update(data, 'binary', 'binary');
|
var crypted = cipher.update(data, 'binary', 'binary');
|
||||||
|
@ -51,9 +47,7 @@ exports.writeFileSync = function(enc_method, enc_passphrase, filename, data)
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.writeJFileSync = function(enc_method, enc_passphrase, filename, obj)
|
exports.writeJFileSync = function(enc_method, enc_passphrase, filename, obj) {
|
||||||
{
|
|
||||||
var raw = JSON.stringify(obj);
|
var raw = JSON.stringify(obj);
|
||||||
return this.writeFileSync(enc_method, enc_passphrase, filename, raw);
|
return this.writeFileSync(enc_method, enc_passphrase, filename, raw);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -129,7 +129,9 @@ var encodings = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
var no_conversion = function() {return this.data;};
|
var no_conversion = function() {
|
||||||
|
return this.data;
|
||||||
|
};
|
||||||
for (var k in encodings) {
|
for (var k in encodings) {
|
||||||
if (encodings.hasOwnProperty(k)) {
|
if (encodings.hasOwnProperty(k)) {
|
||||||
if (!encodings[k].converters[k])
|
if (!encodings[k].converters[k])
|
||||||
|
@ -155,4 +157,3 @@ EncodedData.applyEncodingsTo = function(aClass) {
|
||||||
EncodedData.applyEncodingsTo(EncodedData);
|
EncodedData.applyEncodingsTo(EncodedData);
|
||||||
|
|
||||||
module.exports = require('soop')(EncodedData);
|
module.exports = require('soop')(EncodedData);
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,9 @@ parent.applyEncodingsTo(VersionedData);
|
||||||
// get or set the version data (the first byte of the address)
|
// get or set the version data (the first byte of the address)
|
||||||
VersionedData.prototype.version = function(num) {
|
VersionedData.prototype.version = function(num) {
|
||||||
if (num || (num === 0)) {
|
if (num || (num === 0)) {
|
||||||
this.doAsBinary(function() {this.data.writeUInt8(num, 0);});
|
this.doAsBinary(function() {
|
||||||
|
this.data.writeUInt8(num, 0);
|
||||||
|
});
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
return this.as('binary').readUInt8(0);
|
return this.as('binary').readUInt8(0);
|
||||||
|
@ -29,7 +31,9 @@ VersionedData.prototype.version = function(num) {
|
||||||
// get or set the payload data (as a Buffer object)
|
// get or set the payload data (as a Buffer object)
|
||||||
VersionedData.prototype.payload = function(data) {
|
VersionedData.prototype.payload = function(data) {
|
||||||
if (data) {
|
if (data) {
|
||||||
this.doAsBinary(function() {data.copy(this.data,1);});
|
this.doAsBinary(function() {
|
||||||
|
data.copy(this.data, 1);
|
||||||
|
});
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
return this.as('binary').slice(1);
|
return this.as('binary').slice(1);
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used during transcation verification when a source txout is missing.
|
* Used during transcation verification when a source txout is missing.
|
||||||
*
|
*
|
||||||
|
|
21
util/log.js
21
util/log.js
|
@ -6,9 +6,24 @@ var cl = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
var loggers = {
|
var loggers = {
|
||||||
none: {info: noop, warn: noop, err: noop, debug: noop},
|
none: {
|
||||||
normal: {info: cl, warn: cl, err: cl, debug: noop},
|
info: noop,
|
||||||
debug: {info: cl, warn: cl, err: cl, debug: cl},
|
warn: noop,
|
||||||
|
err: noop,
|
||||||
|
debug: noop
|
||||||
|
},
|
||||||
|
normal: {
|
||||||
|
info: cl,
|
||||||
|
warn: cl,
|
||||||
|
err: cl,
|
||||||
|
debug: noop
|
||||||
|
},
|
||||||
|
debug: {
|
||||||
|
info: cl,
|
||||||
|
warn: cl,
|
||||||
|
err: cl,
|
||||||
|
debug: cl
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
var config = require('../config');
|
var config = require('../config');
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
|
|
||||||
// current time, in seconds
|
// current time, in seconds
|
||||||
exports.curtime = function curtime()
|
exports.curtime = function curtime() {
|
||||||
{
|
|
||||||
return Math.round(Date.now() / 1000);
|
return Math.round(Date.now() / 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue