eslint: more style rules.
This commit is contained in:
parent
ddda6c9dbd
commit
6ba8eb9951
@ -8,7 +8,22 @@
|
||||
"ecmaVersion": 8
|
||||
},
|
||||
"rules": {
|
||||
"array-bracket-spacing": ["error", "never"],
|
||||
"arrow-parens": ["error", "as-needed", {
|
||||
"requireForBlockBody": true
|
||||
}],
|
||||
"arrow-spacing": "error",
|
||||
"block-spacing": ["error", "always"],
|
||||
"brace-style": ["error", "1tbs"],
|
||||
"camelcase": ["error", {
|
||||
"properties": "never"
|
||||
}],
|
||||
"comma-dangle": ["error", "never"],
|
||||
"consistent-return": "error",
|
||||
"eol-last": ["error", "always"],
|
||||
"eqeqeq": ["error", "always", {
|
||||
"null": "ignore"
|
||||
}],
|
||||
"func-name-matching": "off",
|
||||
"indent": ["error", 2, {
|
||||
"SwitchCase": 1,
|
||||
@ -19,15 +34,36 @@
|
||||
}],
|
||||
"handle-callback-err": "off",
|
||||
"linebreak-style": ["error", "unix"],
|
||||
"max-len": ["error", {
|
||||
"code": 80,
|
||||
"ignorePattern": "function \\w+\\(",
|
||||
"ignoreUrls": true
|
||||
}],
|
||||
"max-statements-per-line": ["error", {
|
||||
"max": 1
|
||||
}],
|
||||
"new-cap": ["error", {
|
||||
"newIsCap": true,
|
||||
"capIsNew": false
|
||||
}],
|
||||
"new-parens": "error",
|
||||
"no-buffer-constructor": "error",
|
||||
"no-console": "off",
|
||||
"no-cond-assign": "off",
|
||||
"no-extra-semi": "off",
|
||||
"no-fallthrough": "off",
|
||||
"no-func-assign": "off",
|
||||
"no-implicit-coercion": "off",
|
||||
"no-multi-assign": "error",
|
||||
"no-multiple-empty-lines": ["error", {
|
||||
"max": 1
|
||||
}],
|
||||
"no-nested-ternary": "error",
|
||||
"no-param-reassign": "off",
|
||||
"no-return-assign": "error",
|
||||
"no-return-await": "off",
|
||||
"no-shadow-restricted-names": "error",
|
||||
"no-tabs": "error",
|
||||
"no-trailing-spaces": "error",
|
||||
"no-unused-vars": ["error", {
|
||||
"vars": "all",
|
||||
"args": "none",
|
||||
@ -37,17 +73,25 @@
|
||||
"functions": false,
|
||||
"classes": false
|
||||
}],
|
||||
"no-unreachable": "off",
|
||||
"no-useless-escape": "off",
|
||||
"no-unsafe-finally": "off",
|
||||
"no-var": "error",
|
||||
"nonblock-statement-body-position": ["error", "below"],
|
||||
"padded-blocks": ["error", "never"],
|
||||
"prefer-arrow-callback": "error",
|
||||
"prefer-const": ["error", {
|
||||
"destructuring": "all",
|
||||
"ignoreReadBeforeAssign": true
|
||||
}],
|
||||
"prefer-template": "off",
|
||||
"quotes": ["error", "single"],
|
||||
"semi": ["error", "always"],
|
||||
"spaced-comment": ["error", "always", {
|
||||
"exceptions": ["!"]
|
||||
}],
|
||||
"space-before-blocks": "error",
|
||||
"strict": "error",
|
||||
"valid-jsdoc": "error"
|
||||
"unicode-bom": ["error", "never"],
|
||||
"valid-jsdoc": "error",
|
||||
"wrap-iife": ["error", "inside"]
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,25 +12,29 @@ const raw = coins.toRaw();
|
||||
|
||||
{
|
||||
const end = bench('serialize');
|
||||
for (let i = 0; i < 10000; i++) {
|
||||
|
||||
for (let i = 0; i < 10000; i++)
|
||||
coins.toRaw();
|
||||
}
|
||||
|
||||
end(10000);
|
||||
}
|
||||
|
||||
{
|
||||
const end = bench('parse');
|
||||
for (let i = 0; i < 10000; i++) {
|
||||
|
||||
for (let i = 0; i < 10000; i++)
|
||||
Coins.fromRaw(raw);
|
||||
}
|
||||
|
||||
end(10000);
|
||||
}
|
||||
|
||||
{
|
||||
const end = bench('get');
|
||||
|
||||
for (let i = 0; i < 10000; i++) {
|
||||
for (let j = 0; j < coins.outputs.length; j++)
|
||||
coins.get(j);
|
||||
}
|
||||
|
||||
end(10000 * coins.outputs.length);
|
||||
}
|
||||
|
||||
2
bin/cli
2
bin/cli
@ -633,7 +633,7 @@ CLI.prototype.handleWallet = async function handleWallet() {
|
||||
this.log(' $ unlock [passphrase] [timeout?]: Unlock wallet.');
|
||||
this.log(' $ resend: Resend pending transactions.');
|
||||
this.log('Other Options:');
|
||||
this.log(' --passphrase [passphrase]: For signing and account creation.');
|
||||
this.log(' --passphrase [passphrase]: For signing & account creation.');
|
||||
this.log(' --account [account-name]: Account name.');
|
||||
break;
|
||||
}
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
/* eslint new-cap: "off" */
|
||||
|
||||
const bcoin = require('bcoin');
|
||||
const assert = require('assert');
|
||||
|
||||
@ -39,9 +41,9 @@ const assert = require('assert');
|
||||
value: 10000
|
||||
});
|
||||
|
||||
// Now that we've created the output, we can do some coin selection (the output
|
||||
// must be added first so we know how much money is needed and also so we can
|
||||
// accurately estimate the size for fee calculation).
|
||||
// Now that we've created the output, we can do some coin selection (the
|
||||
// output must be added first so we know how much money is needed and also so
|
||||
// we can accurately estimate the size for fee calculation).
|
||||
|
||||
// Select coins from our array and add inputs.
|
||||
// Calculate fee and add a change output.
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
|
||||
@ -31,6 +31,8 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* eslint camelcase: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
|
||||
@ -58,8 +58,8 @@ function LowlevelUp(backend, location, options) {
|
||||
*/
|
||||
|
||||
LowlevelUp.prototype.init = function init() {
|
||||
const backend = this.backend;
|
||||
let db = new backend(this.location);
|
||||
const Backend = this.backend;
|
||||
let db = new Backend(this.location);
|
||||
let binding = db;
|
||||
|
||||
// Stay as close to the metal as possible.
|
||||
|
||||
@ -343,7 +343,7 @@ BIP150.prototype.destroy = function destroy() {
|
||||
* @returns {Job}
|
||||
*/
|
||||
|
||||
BIP150.prototype.cleanup = function cleanup(err) {
|
||||
BIP150.prototype.cleanup = function cleanup() {
|
||||
const job = this.job;
|
||||
|
||||
assert(!this.completed, 'Already completed.');
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
/* eslint nonblock-statement-body-position: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
const EventEmitter = require('events');
|
||||
|
||||
@ -491,7 +491,7 @@ XMLElement.fromRaw = function fromRaw(xml) {
|
||||
let decl = false;
|
||||
|
||||
while (xml.length > 0) {
|
||||
let m = null;
|
||||
let m;
|
||||
|
||||
m = /^<\?xml[^<>]*\?>/i.exec(xml);
|
||||
if (m) {
|
||||
|
||||
@ -127,7 +127,8 @@ main.genesis = {
|
||||
version: 1,
|
||||
hash: '6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000',
|
||||
prevBlock: '0000000000000000000000000000000000000000000000000000000000000000',
|
||||
merkleRoot: '3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a',
|
||||
merkleRoot:
|
||||
'3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a',
|
||||
time: 1231006505,
|
||||
bits: 486604799,
|
||||
nonce: 2083236893,
|
||||
@ -519,7 +520,8 @@ testnet.genesis = {
|
||||
version: 1,
|
||||
hash: '43497fd7f826957108f4a30fd9cec3aeba79972084e90ead01ea330900000000',
|
||||
prevBlock: '0000000000000000000000000000000000000000000000000000000000000000',
|
||||
merkleRoot: '3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a',
|
||||
merkleRoot:
|
||||
'3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a',
|
||||
time: 1296688602,
|
||||
bits: 486604799,
|
||||
nonce: 414098458,
|
||||
@ -679,7 +681,8 @@ regtest.genesis = {
|
||||
version: 1,
|
||||
hash: '06226e46111a0b59caaf126043eb5bbf28c34f3a5e332a1fc7b2b73cf188910f',
|
||||
prevBlock: '0000000000000000000000000000000000000000000000000000000000000000',
|
||||
merkleRoot: '3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a',
|
||||
merkleRoot:
|
||||
'3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a',
|
||||
time: 1296688602,
|
||||
bits: 545259519,
|
||||
nonce: 2,
|
||||
@ -731,7 +734,7 @@ regtest.bip30 = {};
|
||||
|
||||
regtest.activationThreshold = 108; // 75% for testchains
|
||||
|
||||
regtest.minerWindow = 144; // Faster than normal for regtest (144 instead of 2016)
|
||||
regtest.minerWindow = 144; // Faster than normal for regtest
|
||||
|
||||
regtest.deployments = {
|
||||
csv: {
|
||||
@ -840,7 +843,8 @@ simnet.genesis = {
|
||||
version: 1,
|
||||
hash: 'f67ad7695d9b662a72ff3d8edbbb2de0bfa67b13974bb9910d116d5cbd863e68',
|
||||
prevBlock: '0000000000000000000000000000000000000000000000000000000000000000',
|
||||
merkleRoot: '3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a',
|
||||
merkleRoot:
|
||||
'3ba3edfd7a7b12b27ac72c3e67768f617fc81bc3888a51323a9fb8aa4b1e5e4a',
|
||||
time: 1401292357,
|
||||
bits: 545259519,
|
||||
nonce: 2,
|
||||
|
||||
@ -451,13 +451,15 @@ exports.isCompressedEncoding = function isCompressedEncoding(key) {
|
||||
exports.isSignatureEncoding = function isSignatureEncoding(sig) {
|
||||
assert(Buffer.isBuffer(sig));
|
||||
|
||||
// Format: 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S] [sighash]
|
||||
// Format:
|
||||
// 0x30 [total-length] 0x02 [R-length] [R] 0x02 [S-length] [S] [sighash]
|
||||
// * total-length: 1-byte length descriptor of everything that follows,
|
||||
// excluding the sighash byte.
|
||||
// * R-length: 1-byte length descriptor of the R value that follows.
|
||||
// * R: arbitrary-length big-endian encoded R value. It must use the shortest
|
||||
// possible encoding for a positive integers (which means no null bytes at
|
||||
// the start, except a single one when the next byte has its highest bit set).
|
||||
// the start, except a single one when the next byte has its highest bit
|
||||
// set).
|
||||
// * S-length: 1-byte length descriptor of the S value that follows.
|
||||
// * S: arbitrary-length big-endian encoded S value. The same rules apply.
|
||||
// * sighash: 1-byte value indicating what data is hashed (not part of the DER
|
||||
@ -750,7 +752,7 @@ exports.num = function num(value, minimal, size) {
|
||||
* assert.deepEqual(Script.array(0), Buffer.alloc(0));
|
||||
* assert.deepEqual(Script.array(0xffee), Buffer.from('eeff00', 'hex'));
|
||||
* assert.deepEqual(Script.array(new BN(0xffee)), Buffer.from('eeff00', 'hex'));
|
||||
* assert.deepEqual(Script.array(new BN(0x1e).ineg()), Buffer.from('9e', 'hex'));
|
||||
* assert.deepEqual(Script.array(new BN(0x1e).neg()), Buffer.from('9e', 'hex'));
|
||||
* @param {Number|BN} value
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
@ -126,7 +126,8 @@ Script.prototype.__defineGetter__('length', function() {
|
||||
*/
|
||||
|
||||
Script.prototype.__defineSetter__('length', function(length) {
|
||||
return this.code.length = length;
|
||||
this.code.length = length;
|
||||
return length;
|
||||
});
|
||||
|
||||
/**
|
||||
@ -1174,7 +1175,13 @@ Script.prototype.execute = function execute(stack, flags, tx, index, value, vers
|
||||
|
||||
if (sig.length > 0) {
|
||||
const type = sig[sig.length - 1];
|
||||
const hash = tx.signatureHash(index, subscript, value, type, version);
|
||||
const hash = tx.signatureHash(
|
||||
index,
|
||||
subscript,
|
||||
value,
|
||||
type,
|
||||
version
|
||||
);
|
||||
|
||||
if (checksig(hash, sig, key)) {
|
||||
isig++;
|
||||
@ -1277,7 +1284,7 @@ Script.num = function num(value, minimal, size) {
|
||||
* assert.deepEqual(Script.array(0), Buffer.alloc(0));
|
||||
* assert.deepEqual(Script.array(0xffee), Buffer.from('eeff00', 'hex'));
|
||||
* assert.deepEqual(Script.array(new BN(0xffee)), Buffer.from('eeff00', 'hex'));
|
||||
* assert.deepEqual(Script.array(new BN(0x1e).ineg()), Buffer.from('9e', 'hex'));
|
||||
* assert.deepEqual(Script.array(new BN(0x1e).neg()), Buffer.from('9e', 'hex'));
|
||||
* @param {Number|BN} value
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
|
||||
@ -47,7 +47,8 @@ Stack.prototype.__defineGetter__('length', function() {
|
||||
*/
|
||||
|
||||
Stack.prototype.__defineSetter__('length', function(length) {
|
||||
return this.items.length = length;
|
||||
this.items.length = length;
|
||||
return length;
|
||||
});
|
||||
|
||||
/**
|
||||
@ -250,7 +251,9 @@ Stack.prototype.set = function set(i, value) {
|
||||
if (i < 0)
|
||||
i = this.items.length + i;
|
||||
|
||||
return this.items[i] = value;
|
||||
this.items[i] = value;
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -66,7 +66,8 @@ Witness.prototype.__defineGetter__('length', function() {
|
||||
*/
|
||||
|
||||
Witness.prototype.__defineSetter__('length', function(length) {
|
||||
return this.items.length = length;
|
||||
this.items.length = length;
|
||||
return length;
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@ -104,7 +104,7 @@ function isPromise(obj) {
|
||||
*/
|
||||
|
||||
function wait() {
|
||||
return new Promise((resolve) => setImmediate(resolve));
|
||||
return new Promise(resolve => setImmediate(resolve));
|
||||
};
|
||||
|
||||
/**
|
||||
@ -114,7 +114,7 @@ function wait() {
|
||||
*/
|
||||
|
||||
function timeout(time) {
|
||||
return new Promise((resolve) => setTimeout(resolve, time));
|
||||
return new Promise(resolve => setTimeout(resolve, time));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -9,6 +9,8 @@
|
||||
* Copyright (c) 2012, Fedor Indutny (MIT License).
|
||||
*/
|
||||
|
||||
/* eslint no-unreachable: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
|
||||
@ -29,13 +29,15 @@ PEM.parse = function parse(pem) {
|
||||
while (pem.length) {
|
||||
let m;
|
||||
|
||||
if (m = /^-----BEGIN ([^\-]+)-----/.exec(pem)) {
|
||||
m = /^-----BEGIN ([^\-]+)-----/.exec(pem);
|
||||
if (m) {
|
||||
pem = pem.substring(m[0].length);
|
||||
tag = m[1];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m = /^-----END ([^\-]+)-----/.exec(pem)) {
|
||||
m = /^-----END ([^\-]+)-----/.exec(pem);
|
||||
if (m) {
|
||||
pem = pem.substring(m[0].length);
|
||||
|
||||
assert(tag === m[1], 'Tag mismatch.');
|
||||
@ -55,13 +57,15 @@ PEM.parse = function parse(pem) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m = /^[a-zA-Z0-9\+=\/]+/.exec(pem)) {
|
||||
m = /^[a-zA-Z0-9\+=\/]+/.exec(pem);
|
||||
if (m) {
|
||||
pem = pem.substring(m[0].length);
|
||||
chunk += m[0];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m = /^\s+/.exec(pem)) {
|
||||
m = /^\s+/.exec(pem);
|
||||
if (m) {
|
||||
pem = pem.substring(m[0].length);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -75,29 +75,75 @@ BufferWriter.prototype.render = function render(keep) {
|
||||
|
||||
for (const op of this.ops) {
|
||||
switch (op.type) {
|
||||
case SEEK: off += op.value; break;
|
||||
case UI8: off = data.writeUInt8(op.value, off, true); break;
|
||||
case UI16: off = data.writeUInt16LE(op.value, off, true); break;
|
||||
case UI16BE: off = data.writeUInt16BE(op.value, off, true); break;
|
||||
case UI32: off = data.writeUInt32LE(op.value, off, true); break;
|
||||
case UI32BE: off = data.writeUInt32BE(op.value, off, true); break;
|
||||
case UI64: off = encoding.writeU64(data, op.value, off); break;
|
||||
case UI64BE: off = encoding.writeU64BE(data, op.value, off); break;
|
||||
case I8: off = data.writeInt8(op.value, off, true); break;
|
||||
case I16: off = data.writeInt16LE(op.value, off, true); break;
|
||||
case I16BE: off = data.writeInt16BE(op.value, off, true); break;
|
||||
case I32: off = data.writeInt32LE(op.value, off, true); break;
|
||||
case I32BE: off = data.writeInt32BE(op.value, off, true); break;
|
||||
case I64: off = encoding.write64(data, op.value, off); break;
|
||||
case I64BE: off = encoding.write64BE(data, op.value, off); break;
|
||||
case FL: off = data.writeFloatLE(op.value, off, true); break;
|
||||
case FLBE: off = data.writeFloatBE(op.value, off, true); break;
|
||||
case DBL: off = data.writeDoubleLE(op.value, off, true); break;
|
||||
case DBLBE: off = data.writeDoubleBE(op.value, off, true); break;
|
||||
case VARINT: off = encoding.writeVarint(data, op.value, off); break;
|
||||
case VARINT2: off = encoding.writeVarint2(data, op.value, off); break;
|
||||
case BYTES: off += op.value.copy(data, off); break;
|
||||
case STR: off += data.write(op.value, off, op.enc); break;
|
||||
case SEEK:
|
||||
off += op.value;
|
||||
break;
|
||||
case UI8:
|
||||
off = data.writeUInt8(op.value, off, true);
|
||||
break;
|
||||
case UI16:
|
||||
off = data.writeUInt16LE(op.value, off, true);
|
||||
break;
|
||||
case UI16BE:
|
||||
off = data.writeUInt16BE(op.value, off, true);
|
||||
break;
|
||||
case UI32:
|
||||
off = data.writeUInt32LE(op.value, off, true);
|
||||
break;
|
||||
case UI32BE:
|
||||
off = data.writeUInt32BE(op.value, off, true);
|
||||
break;
|
||||
case UI64:
|
||||
off = encoding.writeU64(data, op.value, off);
|
||||
break;
|
||||
case UI64BE:
|
||||
off = encoding.writeU64BE(data, op.value, off);
|
||||
break;
|
||||
case I8:
|
||||
off = data.writeInt8(op.value, off, true);
|
||||
break;
|
||||
case I16:
|
||||
off = data.writeInt16LE(op.value, off, true);
|
||||
break;
|
||||
case I16BE:
|
||||
off = data.writeInt16BE(op.value, off, true);
|
||||
break;
|
||||
case I32:
|
||||
off = data.writeInt32LE(op.value, off, true);
|
||||
break;
|
||||
case I32BE:
|
||||
off = data.writeInt32BE(op.value, off, true);
|
||||
break;
|
||||
case I64:
|
||||
off = encoding.write64(data, op.value, off);
|
||||
break;
|
||||
case I64BE:
|
||||
off = encoding.write64BE(data, op.value, off);
|
||||
break;
|
||||
case FL:
|
||||
off = data.writeFloatLE(op.value, off, true);
|
||||
break;
|
||||
case FLBE:
|
||||
off = data.writeFloatBE(op.value, off, true);
|
||||
break;
|
||||
case DBL:
|
||||
off = data.writeDoubleLE(op.value, off, true);
|
||||
break;
|
||||
case DBLBE:
|
||||
off = data.writeDoubleBE(op.value, off, true);
|
||||
break;
|
||||
case VARINT:
|
||||
off = encoding.writeVarint(data, op.value, off);
|
||||
break;
|
||||
case VARINT2:
|
||||
off = encoding.writeVarint2(data, op.value, off);
|
||||
break;
|
||||
case BYTES:
|
||||
off += op.value.copy(data, off);
|
||||
break;
|
||||
case STR:
|
||||
off += data.write(op.value, off, op.enc);
|
||||
break;
|
||||
case CHECKSUM:
|
||||
off += digest.hash256(data.slice(0, off)).copy(data, off, 0, 4);
|
||||
break;
|
||||
|
||||
@ -889,7 +889,7 @@ RPC.prototype._listReceived = async function _listReceived(minconf, empty, watch
|
||||
account: path.name,
|
||||
amount: 0,
|
||||
confirmations: -1,
|
||||
label: '',
|
||||
label: ''
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -1546,7 +1546,8 @@ Wallet.prototype.createTX = async function createTX(options, force) {
|
||||
|
||||
// Consensus sanity checks.
|
||||
assert(mtx.isSane(), 'TX failed sanity check.');
|
||||
assert(mtx.verifyInputs(this.db.state.height + 1), 'TX failed context check.');
|
||||
assert(mtx.verifyInputs(this.db.state.height + 1),
|
||||
'TX failed context check.');
|
||||
|
||||
const total = await this.template(mtx);
|
||||
|
||||
|
||||
@ -694,7 +694,6 @@ SignInputResultPacket.fromRaw = function fromRaw(data) {
|
||||
return packet;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* ECVerifyPacket
|
||||
* @constructor
|
||||
|
||||
@ -5,6 +5,8 @@
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
/* eslint no-nested-ternary: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
|
||||
@ -8,6 +8,7 @@ const Path = require('../lib/wallet/path');
|
||||
const MasterKey = require('../lib/wallet/masterkey');
|
||||
const Account = require('../lib/wallet/account');
|
||||
const Wallet = require('../lib/wallet/wallet');
|
||||
const KeyRing = require('../lib/primitives/keyring');
|
||||
const BufferReader = require('../lib/utils/reader');
|
||||
const BufferWriter = require('../lib/utils/writer');
|
||||
const layout = walletdb.layout;
|
||||
@ -85,7 +86,7 @@ async function updatePathMap() {
|
||||
continue;
|
||||
}
|
||||
const ring = keyFromRaw(path.data);
|
||||
path.data = new bcoin.keyring(ring).toRaw();
|
||||
path.data = new KeyRing(ring).toRaw();
|
||||
}
|
||||
batch.put(layout.P(key, hash), path.toRaw());
|
||||
}
|
||||
|
||||
@ -60,7 +60,7 @@
|
||||
"scripts": {
|
||||
"clean": "rm -f {browser/,}{bcoin.js,bcoin-worker.js}",
|
||||
"docs": "jsdoc -c jsdoc.json",
|
||||
"lint": "eslint lib/ test/ migrate/ examples/ bench/ scripts/*.js bin/cli bin/node bin/spvnode || exit 0",
|
||||
"lint": "eslint lib/ test/ migrate/ examples/ bench/ scripts/*.js bin/{cli,node,spvnode,wallet} || exit 0",
|
||||
"lint-file": "eslint",
|
||||
"test": "mocha --reporter spec test/*-test.js",
|
||||
"test-browser": "BCOIN_NO_NATIVE=1 BCOIN_NO_SECP256K1=1 mocha --reporter spec test/*-test.js",
|
||||
|
||||
@ -10,7 +10,8 @@ const Outpoint = require('../lib/primitives/outpoint');
|
||||
const TX = require('../lib/primitives/tx');
|
||||
const random = require('../lib/crypto/random');
|
||||
|
||||
const MANDATORY = Script.flags.MANDATORY_VERIFY_FLAGS | Script.flags.VERIFY_WITNESS;
|
||||
const MANDATORY = Script.flags.MANDATORY_VERIFY_FLAGS
|
||||
| Script.flags.VERIFY_WITNESS;
|
||||
const STANDARD = Script.flags.STANDARD_VERIFY_FLAGS;
|
||||
|
||||
function randomOutpoint() {
|
||||
@ -429,7 +430,9 @@ function fuzzLess(flags) {
|
||||
}
|
||||
|
||||
function main() {
|
||||
const flags = process.argv.indexOf('--standard') !== -1 ? STANDARD : MANDATORY;
|
||||
const flags = process.argv.indexOf('--standard') !== -1
|
||||
? STANDARD
|
||||
: MANDATORY;
|
||||
|
||||
switch (process.argv[2]) {
|
||||
case 'simple':
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
@ -6,11 +7,12 @@ const assert = require('assert');
|
||||
const digest = require('../lib/crypto/digest');
|
||||
const aes = require('../lib/crypto/aes');
|
||||
const pbkdf2 = require('../lib/crypto/pbkdf2');
|
||||
const nativeCrypto = require('crypto');
|
||||
const ncrypto = require('crypto');
|
||||
|
||||
describe('AES', function() {
|
||||
function pbkdf2key(passphrase, iterations, dkLen, ivLen, alg) {
|
||||
const key = pbkdf2.derive(passphrase, '', iterations, dkLen + ivLen, 'sha512');
|
||||
const key = pbkdf2.derive(
|
||||
passphrase, '', iterations, dkLen + ivLen, 'sha512');
|
||||
return {
|
||||
key: key.slice(0, dkLen),
|
||||
iv: key.slice(dkLen, dkLen + ivLen)
|
||||
@ -18,7 +20,7 @@ describe('AES', function() {
|
||||
}
|
||||
|
||||
function nencrypt(data, passphrase) {
|
||||
assert(nativeCrypto, 'No crypto module available.');
|
||||
assert(ncrypto, 'No crypto module available.');
|
||||
assert(passphrase, 'No passphrase.');
|
||||
|
||||
if (typeof data === 'string')
|
||||
@ -28,7 +30,7 @@ describe('AES', function() {
|
||||
passphrase = Buffer.from(passphrase, 'utf8');
|
||||
|
||||
const key = pbkdf2key(passphrase, 2048, 32, 16);
|
||||
const cipher = nativeCrypto.createCipheriv('aes-256-cbc', key.key, key.iv);
|
||||
const cipher = ncrypto.createCipheriv('aes-256-cbc', key.key, key.iv);
|
||||
|
||||
return Buffer.concat([
|
||||
cipher.update(data),
|
||||
@ -37,7 +39,7 @@ describe('AES', function() {
|
||||
}
|
||||
|
||||
function ndecrypt(data, passphrase) {
|
||||
assert(nativeCrypto, 'No crypto module available.');
|
||||
assert(ncrypto, 'No crypto module available.');
|
||||
assert(passphrase, 'No passphrase.');
|
||||
|
||||
if (typeof data === 'string')
|
||||
@ -47,7 +49,7 @@ describe('AES', function() {
|
||||
passphrase = Buffer.from(passphrase, 'utf8');
|
||||
|
||||
const key = pbkdf2key(passphrase, 2048, 32, 16);
|
||||
const decipher = nativeCrypto.createDecipheriv('aes-256-cbc', key.key, key.iv);
|
||||
const decipher = ncrypto.createDecipheriv('aes-256-cbc', key.key, key.iv);
|
||||
|
||||
return Buffer.concat([
|
||||
decipher.update(data),
|
||||
@ -56,7 +58,7 @@ describe('AES', function() {
|
||||
}
|
||||
|
||||
function bencrypt(data, passphrase) {
|
||||
assert(nativeCrypto, 'No crypto module available.');
|
||||
assert(ncrypto, 'No crypto module available.');
|
||||
assert(passphrase, 'No passphrase.');
|
||||
|
||||
if (typeof data === 'string')
|
||||
@ -70,7 +72,7 @@ describe('AES', function() {
|
||||
}
|
||||
|
||||
function bdecrypt(data, passphrase) {
|
||||
assert(nativeCrypto, 'No crypto module available.');
|
||||
assert(ncrypto, 'No crypto module available.');
|
||||
assert(passphrase, 'No passphrase.');
|
||||
|
||||
if (typeof data === 'string')
|
||||
@ -84,7 +86,7 @@ describe('AES', function() {
|
||||
}
|
||||
|
||||
function encrypt(data, passphrase) {
|
||||
assert(nativeCrypto, 'No crypto module available.');
|
||||
assert(ncrypto, 'No crypto module available.');
|
||||
assert(passphrase, 'No passphrase.');
|
||||
|
||||
if (typeof data === 'string')
|
||||
@ -99,7 +101,7 @@ describe('AES', function() {
|
||||
}
|
||||
|
||||
function decrypt(data, passphrase) {
|
||||
assert(nativeCrypto, 'No crypto module available.');
|
||||
assert(ncrypto, 'No crypto module available.');
|
||||
assert(passphrase, 'No passphrase.');
|
||||
|
||||
if (typeof data === 'string')
|
||||
@ -133,11 +135,17 @@ describe('AES', function() {
|
||||
});
|
||||
|
||||
it('should encrypt and decrypt a hash with uneven blocks', () => {
|
||||
const hash = Buffer.concat([digest.sha256(Buffer.alloc(0)), Buffer.from([1,2,3])]);
|
||||
const hash = Buffer.concat([
|
||||
digest.sha256(Buffer.alloc(0)),
|
||||
Buffer.from([1,2,3])]);
|
||||
|
||||
const enchash = encrypt(hash, 'foo');
|
||||
const dechash = decrypt(enchash, 'foo');
|
||||
|
||||
const hash2 = Buffer.concat([digest.sha256(Buffer.alloc(0)), Buffer.from([1,2,3])]);
|
||||
const hash2 = Buffer.concat([
|
||||
digest.sha256(Buffer.alloc(0)),
|
||||
Buffer.from([1,2,3])]);
|
||||
|
||||
const enchash2 = nencrypt(hash2, 'foo');
|
||||
const dechash2 = ndecrypt(enchash2, 'foo');
|
||||
|
||||
|
||||
@ -22,6 +22,8 @@
|
||||
// THE SOFTWARE.
|
||||
|
||||
/* eslint-env mocha */
|
||||
/* eslint max-len: "off" */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
@ -97,7 +99,7 @@ describe('Bech32', function() {
|
||||
'BC1QR508D6QEJXTDG4Y5R3ZARVARYV98GJ9P',
|
||||
'tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sL5k7',
|
||||
'tb1pw508d6qejxtdg4y5r3zarqfsj6c3',
|
||||
'tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3pjxtptv',
|
||||
'tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3pjxtptv'
|
||||
];
|
||||
|
||||
function fromAddress(hrp, addr) {
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
@ -39,7 +40,9 @@ describe('BIP70', function() {
|
||||
assert(request.verify());
|
||||
}
|
||||
|
||||
x509.verifyTime = function() { return true; };
|
||||
x509.verifyTime = function() {
|
||||
return true;
|
||||
};
|
||||
|
||||
it('should parse and verify a payment request', () => {
|
||||
testRequest(tests.valid);
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint max-len: "off" */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
@ -16,6 +18,9 @@ const encoding = require('../lib/utils/encoding');
|
||||
const bip152 = require('../lib/net/bip152');
|
||||
const BufferReader = require('../lib/utils/reader');
|
||||
const fs = require('../lib/utils/fs');
|
||||
const CompactBlock = bip152.CompactBlock;
|
||||
const TXRequest = bip152.TXRequest;
|
||||
const TXResponse = bip152.TXResponse;
|
||||
|
||||
const block300025 = require('./data/block300025.json');
|
||||
const cmpct2block = fs.readFileSync(`${__dirname}/data/cmpct2.bin`);
|
||||
@ -285,8 +290,8 @@ describe('Block', function() {
|
||||
|
||||
it('should handle compact block', () => {
|
||||
const block = Block.fromRaw(cmpct1[1], 'hex');
|
||||
const cblock1 = bip152.CompactBlock.fromRaw(cmpct1[0], 'hex');
|
||||
const cblock2 = bip152.CompactBlock.fromBlock(block, false, cblock1.keyNonce);
|
||||
const cblock1 = CompactBlock.fromRaw(cmpct1[0], 'hex');
|
||||
const cblock2 = CompactBlock.fromBlock(block, false, cblock1.keyNonce);
|
||||
const map = new Map();
|
||||
|
||||
assert(cblock1.init());
|
||||
@ -318,8 +323,8 @@ describe('Block', function() {
|
||||
|
||||
it('should handle half-full compact block', () => {
|
||||
const block = Block.fromRaw(cmpct1[1], 'hex');
|
||||
const cblock1 = bip152.CompactBlock.fromRaw(cmpct1[0], 'hex');
|
||||
const cblock2 = bip152.CompactBlock.fromBlock(block, false, cblock1.keyNonce);
|
||||
const cblock1 = CompactBlock.fromRaw(cmpct1[0], 'hex');
|
||||
const cblock2 = CompactBlock.fromBlock(block, false, cblock1.keyNonce);
|
||||
const map = new Map();
|
||||
|
||||
assert(cblock1.init());
|
||||
@ -345,12 +350,12 @@ describe('Block', function() {
|
||||
assert.equal(req.hash, cblock1.hash('hex'));
|
||||
assert.deepEqual(req.indexes, [5, 6, 7, 8, 9]);
|
||||
|
||||
req = bip152.TXRequest.fromRaw(req.toRaw());
|
||||
req = TXRequest.fromRaw(req.toRaw());
|
||||
assert.equal(req.hash, cblock1.hash('hex'));
|
||||
assert.deepEqual(req.indexes, [5, 6, 7, 8, 9]);
|
||||
|
||||
let res = bip152.TXResponse.fromBlock(block, req);
|
||||
res = bip152.TXResponse.fromRaw(res.toRaw());
|
||||
let res = TXResponse.fromBlock(block, req);
|
||||
res = TXResponse.fromRaw(res.toRaw());
|
||||
|
||||
result = cblock1.fillMissing(res);
|
||||
assert(result);
|
||||
@ -365,8 +370,8 @@ describe('Block', function() {
|
||||
|
||||
it('should handle compact block', () => {
|
||||
const block = Block.fromRaw(cmpct2block);
|
||||
const cblock1 = bip152.CompactBlock.fromRaw(cmpct2, 'hex');
|
||||
const cblock2 = bip152.CompactBlock.fromBlock(block, false, cblock1.keyNonce);
|
||||
const cblock1 = CompactBlock.fromRaw(cmpct2, 'hex');
|
||||
const cblock2 = CompactBlock.fromBlock(block, false, cblock1.keyNonce);
|
||||
const map = new Map();
|
||||
|
||||
assert(cblock1.init());
|
||||
@ -396,8 +401,8 @@ describe('Block', function() {
|
||||
|
||||
it('should handle half-full compact block', () => {
|
||||
const block = Block.fromRaw(cmpct2block);
|
||||
const cblock1 = bip152.CompactBlock.fromRaw(cmpct2, 'hex');
|
||||
const cblock2 = bip152.CompactBlock.fromBlock(block, false, cblock1.keyNonce);
|
||||
const cblock1 = CompactBlock.fromRaw(cmpct2, 'hex');
|
||||
const cblock2 = CompactBlock.fromBlock(block, false, cblock1.keyNonce);
|
||||
const map = new Map();
|
||||
|
||||
assert(cblock1.init());
|
||||
@ -420,11 +425,11 @@ describe('Block', function() {
|
||||
let req = cblock1.toRequest();
|
||||
assert.equal(req.hash, cblock1.hash('hex'));
|
||||
|
||||
req = bip152.TXRequest.fromRaw(req.toRaw());
|
||||
req = TXRequest.fromRaw(req.toRaw());
|
||||
assert.equal(req.hash, cblock1.hash('hex'));
|
||||
|
||||
let res = bip152.TXResponse.fromBlock(block, req);
|
||||
res = bip152.TXResponse.fromRaw(res.toRaw());
|
||||
let res = TXResponse.fromBlock(block, req);
|
||||
res = TXResponse.fromRaw(res.toRaw());
|
||||
|
||||
result = cblock1.fillMissing(res);
|
||||
assert(result);
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
@ -96,7 +97,8 @@ describe('ChaCha20 / Poly1305 / AEAD', function() {
|
||||
+ '0000000000000000000000000000000000000000000000000000000000000000',
|
||||
ciphertext: ''
|
||||
+ '76b8e0ada0f13d90405d6ae55386bd28bdd219b8a08ded1aa836efcc8b77'
|
||||
+ '0dc7da41597c5157488d7724e03fb8d84a376a43b8f41518a11cc387b669b2ee6586',
|
||||
+ '0dc7da41597c5157488d7724e03fb8d84a376a43b8f41518a11cc387b669'
|
||||
+ 'b2ee6586',
|
||||
counter: 0
|
||||
});
|
||||
});
|
||||
@ -175,7 +177,8 @@ describe('ChaCha20 / Poly1305 / AEAD', function() {
|
||||
});
|
||||
|
||||
it('should perform poly1305', () => {
|
||||
let key = '85d6be7857556d337f4452fe42d506a80103808afb0db2fd4abff6af4149f51b';
|
||||
let key = '85d6be7857556d337f4452fe42d506a'
|
||||
+ '80103808afb0db2fd4abff6af4149f51b';
|
||||
let msg = 'Cryptographic Forum Research Group';
|
||||
let tag = 'a8061dc1305136c6c22b8baf0c0127a9';
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
@ -23,7 +24,8 @@ describe('HD', function() {
|
||||
let master, child1, child2, child3, child4, child5, child6;
|
||||
|
||||
it('should create a pbkdf2 seed', () => {
|
||||
const seed = pbkdf2.derive(vectors.phrase, 'mnemonicfoo', 2048, 64, 'sha512');
|
||||
const seed = pbkdf2.derive(
|
||||
vectors.phrase, 'mnemonicfoo', 2048, 64, 'sha512');
|
||||
assert.equal(seed.toString('hex'), vectors.seed);
|
||||
});
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
@ -184,15 +185,17 @@ describe('HTTP', function() {
|
||||
it('should get a block template', async () => {
|
||||
const json = await wallet.client.rpc.execute('getblocktemplate', []);
|
||||
assert.deepStrictEqual(json, {
|
||||
capabilities: [ 'proposal' ],
|
||||
mutable: [ 'time', 'transactions', 'prevblock' ],
|
||||
capabilities: ['proposal'],
|
||||
mutable: ['time', 'transactions', 'prevblock'],
|
||||
version: 536870912,
|
||||
rules: [],
|
||||
vbavailable: {},
|
||||
vbrequired: 0,
|
||||
height: 1,
|
||||
previousblockhash: '0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206',
|
||||
target: '7fffff0000000000000000000000000000000000000000000000000000000000',
|
||||
previousblockhash:
|
||||
'0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206',
|
||||
target:
|
||||
'7fffff0000000000000000000000000000000000000000000000000000000000',
|
||||
bits: '207fffff',
|
||||
noncerange: '00000000ffffffff',
|
||||
curtime: json.curtime,
|
||||
@ -201,7 +204,9 @@ describe('HTTP', function() {
|
||||
expires: json.expires,
|
||||
sigoplimit: 20000,
|
||||
sizelimit: 1000000,
|
||||
longpollid: '0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e22060000000000',
|
||||
longpollid:
|
||||
'0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206'
|
||||
+ '0000000000',
|
||||
submitold: false,
|
||||
coinbaseaux: { flags: '6d696e65642062792062636f696e' },
|
||||
coinbasevalue: 5000000000,
|
||||
@ -221,7 +226,9 @@ describe('HTTP', function() {
|
||||
});
|
||||
|
||||
it('should validate an address', async () => {
|
||||
const json = await wallet.client.rpc.execute('validateaddress', [addr.toString()]);
|
||||
const json = await wallet.client.rpc.execute('validateaddress', [
|
||||
addr.toString()
|
||||
]);
|
||||
assert.deepStrictEqual(json, {
|
||||
isvalid: true,
|
||||
address: addr.toString(),
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
@ -6,8 +7,10 @@ const assert = require('assert');
|
||||
const keyring = require('../lib/primitives/keyring');
|
||||
|
||||
describe('Keyring Address', function() {
|
||||
const ukey = keyring.fromSecret('5KYZdUEo39z3FPrtuX2QbbwGnNP5zTd7yyr2SC1j299sBCnWjss');
|
||||
const ckey = keyring.fromSecret('L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrisoyY1');
|
||||
const ukey = keyring.fromSecret(
|
||||
'5KYZdUEo39z3FPrtuX2QbbwGnNP5zTd7yyr2SC1j299sBCnWjss');
|
||||
const ckey = keyring.fromSecret(
|
||||
'L4rK1yDtCWekvXuE6oXD9jCYfFNV2cWRpVuPLBcCU2z8TrisoyY1');
|
||||
|
||||
it('check uncompressed public key', () => {
|
||||
assert.equal(
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
@ -62,7 +63,8 @@ describe('Mempool', function() {
|
||||
|
||||
const prev = Script.fromPubkey(kp.publicKey);
|
||||
t1.addCoin(dummy(prev));
|
||||
const sig = t1.signature(0, prev, 70000, kp.privateKey, Script.hashType.ALL, 0);
|
||||
const sig = t1.signature(
|
||||
0, prev, 70000, kp.privateKey, Script.hashType.ALL, 0);
|
||||
t1.inputs[0].script = new Script([sig]);
|
||||
|
||||
// balance: 51000
|
||||
@ -166,7 +168,8 @@ describe('Mempool', function() {
|
||||
|
||||
chain.tip.height = 200;
|
||||
|
||||
const sig = tx.signature(0, prev, 70000, kp.privateKey, Script.hashType.ALL, 0);
|
||||
const sig = tx.signature(
|
||||
0, prev, 70000, kp.privateKey, Script.hashType.ALL, 0);
|
||||
tx.inputs[0].script = new Script([sig]);
|
||||
|
||||
tx = tx.toTX();
|
||||
@ -190,7 +193,8 @@ describe('Mempool', function() {
|
||||
tx.setLocktime(200);
|
||||
chain.tip.height = 200 - 1;
|
||||
|
||||
const sig = tx.signature(0, prev, 70000, kp.privateKey, Script.hashType.ALL, 0);
|
||||
const sig = tx.signature(
|
||||
0, prev, 70000, kp.privateKey, Script.hashType.ALL, 0);
|
||||
tx.inputs[0].script = new Script([sig]);
|
||||
tx = tx.toTX();
|
||||
|
||||
@ -223,7 +227,8 @@ describe('Mempool', function() {
|
||||
|
||||
const prevs = Script.fromPubkeyhash(kp.getKeyHash());
|
||||
|
||||
const sig = tx.signature(0, prevs, 70000, kp.privateKey, Script.hashType.ALL, 1);
|
||||
const sig = tx.signature(
|
||||
0, prevs, 70000, kp.privateKey, Script.hashType.ALL, 1);
|
||||
sig[sig.length - 1] = 0;
|
||||
|
||||
tx.inputs[0].witness = new Witness([sig, kp.publicKey]);
|
||||
@ -253,7 +258,8 @@ describe('Mempool', function() {
|
||||
|
||||
tx.addCoin(dummy(prev, prevHash));
|
||||
|
||||
const sig = tx.signature(0, prev, 70000, kp.privateKey, Script.hashType.ALL, 0);
|
||||
const sig = tx.signature(
|
||||
0, prev, 70000, kp.privateKey, Script.hashType.ALL, 0);
|
||||
tx.inputs[0].script = new Script([sig]);
|
||||
tx.inputs[0].witness.push(Buffer.alloc(0));
|
||||
tx = tx.toTX();
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
@ -183,7 +184,7 @@ describe('Node', function() {
|
||||
assert(chain.tip === tip);
|
||||
});
|
||||
|
||||
it('should fail to mine a block with coins on an alternate chain', async () => {
|
||||
it('should fail to mine block with coins on an alternate chain', async () => {
|
||||
const block = await mineBlock(null, cb1);
|
||||
const tip = chain.tip;
|
||||
let err;
|
||||
@ -467,15 +468,16 @@ describe('Node', function() {
|
||||
|
||||
assert.deepStrictEqual(json, {
|
||||
result: {
|
||||
capabilities: [ 'proposal' ],
|
||||
mutable: [ 'time', 'transactions', 'prevblock' ],
|
||||
capabilities: ['proposal'],
|
||||
mutable: ['time', 'transactions', 'prevblock'],
|
||||
version: 536870912,
|
||||
rules: [ 'csv', '!segwit', 'testdummy' ],
|
||||
rules: ['csv', '!segwit', 'testdummy'],
|
||||
vbavailable: {},
|
||||
vbrequired: 0,
|
||||
height: 437,
|
||||
previousblockhash: node.chain.tip.rhash(),
|
||||
target: '7fffff0000000000000000000000000000000000000000000000000000000000',
|
||||
target:
|
||||
'7fffff0000000000000000000000000000000000000000000000000000000000',
|
||||
bits: '207fffff',
|
||||
noncerange: '00000000ffffffff',
|
||||
curtime: json.result.curtime,
|
||||
@ -490,7 +492,9 @@ describe('Node', function() {
|
||||
coinbaseaux: { flags: '6d696e65642062792062636f696e' },
|
||||
coinbasevalue: 1250000000,
|
||||
coinbasetxn: undefined,
|
||||
default_witness_commitment: '6a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962b48bebd836974e8cf9',
|
||||
default_witness_commitment:
|
||||
'6a24aa21a9ede2f61c3f71d1defd3fa999dfa36953755c690689799962'
|
||||
+ 'b48bebd836974e8cf9',
|
||||
transactions: []
|
||||
},
|
||||
error: null,
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
@ -270,7 +271,7 @@ describe('TX', function() {
|
||||
|
||||
if (valid) {
|
||||
if (comments.indexOf('Coinbase') === 0) {
|
||||
it(`should handle valid coinbase ${suffix}: ${comments}`, () => {
|
||||
it(`should handle valid tx test ${suffix}: ${comments}`, () => {
|
||||
clearCache(tx, noCache);
|
||||
assert.ok(tx.isSane());
|
||||
});
|
||||
@ -282,7 +283,7 @@ describe('TX', function() {
|
||||
});
|
||||
} else {
|
||||
if (comments === 'Duplicate inputs') {
|
||||
it(`should handle duplicate input test ${suffix}: ${comments}`, () => {
|
||||
it(`should handle invalid tx test ${suffix}: ${comments}`, () => {
|
||||
clearCache(tx, noCache);
|
||||
assert.ok(tx.verify(view, flags));
|
||||
assert.ok(!tx.isSane());
|
||||
@ -290,7 +291,7 @@ describe('TX', function() {
|
||||
return;
|
||||
}
|
||||
if (comments === 'Negative output') {
|
||||
it(`should handle invalid tx (negative) ${suffix}: ${comments}`, () => {
|
||||
it(`should handle invalid tx test ${suffix}: ${comments}`, () => {
|
||||
clearCache(tx, noCache);
|
||||
assert.ok(tx.verify(view, flags));
|
||||
assert.ok(!tx.isSane());
|
||||
@ -298,7 +299,7 @@ describe('TX', function() {
|
||||
return;
|
||||
}
|
||||
if (comments.indexOf('Coinbase') === 0) {
|
||||
it(`should handle invalid coinbase ${suffix}: ${comments}`, () => {
|
||||
it(`should handle invalid tx test ${suffix}: ${comments}`, () => {
|
||||
clearCache(tx, noCache);
|
||||
assert.ok(!tx.isSane());
|
||||
});
|
||||
|
||||
@ -17,7 +17,7 @@ function NodeContext(network, size) {
|
||||
this.init();
|
||||
};
|
||||
|
||||
NodeContext.prototype.init = function() {
|
||||
NodeContext.prototype.init = function init() {
|
||||
let i, port, last, node;
|
||||
|
||||
for (i = 0; i < this.size; i++) {
|
||||
@ -46,7 +46,7 @@ NodeContext.prototype.init = function() {
|
||||
]
|
||||
});
|
||||
|
||||
node.on('error', function(err) {
|
||||
node.on('error', (err) => {
|
||||
node.logger.error(err);
|
||||
});
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
@ -254,7 +255,8 @@ describe('Utils', function() {
|
||||
let info = 'f0f1f2f3f4f5f6f7f8f9';
|
||||
let len = 42;
|
||||
|
||||
let prkE = '077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5';
|
||||
let prkE = '077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec8'
|
||||
+ '44ad7c2b3e5';
|
||||
let okmE = '3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1'
|
||||
+ 'a5a4c5db02d56ecc4c5bf34007208d5b887185865';
|
||||
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
/* eslint-env mocha */
|
||||
/* eslint prefer-arrow-callback: "off" */
|
||||
|
||||
'use strict';
|
||||
|
||||
@ -127,15 +128,15 @@ describe('Wallet', function() {
|
||||
assert(tx.verify(flags));
|
||||
}
|
||||
|
||||
it('should sign/verify pubkeyhash tx', async () => {
|
||||
it('should sign/verify p2pkh tx', async () => {
|
||||
await testP2PKH(false, false);
|
||||
});
|
||||
|
||||
it('should sign/verify witnesspubkeyhash tx', async () => {
|
||||
it('should sign/verify p2wpkh tx', async () => {
|
||||
await testP2PKH(true, false);
|
||||
});
|
||||
|
||||
it('should sign/verify witnesspubkeyhash tx with bullshit nesting', async () => {
|
||||
it('should sign/verify p2wpkh tx w/ nested bullshit', async () => {
|
||||
await testP2PKH(true, true);
|
||||
});
|
||||
|
||||
@ -730,15 +731,15 @@ describe('Wallet', function() {
|
||||
assert.equal(send.getFee(view), 10000);
|
||||
}
|
||||
|
||||
it('should verify 2-of-3 scripthash tx', async () => {
|
||||
it('should verify 2-of-3 p2sh tx', async () => {
|
||||
await testMultisig(false, false);
|
||||
});
|
||||
|
||||
it('should verify 2-of-3 witnessscripthash tx', async () => {
|
||||
it('should verify 2-of-3 p2wsh tx', async () => {
|
||||
await testMultisig(true, false);
|
||||
});
|
||||
|
||||
it('should verify 2-of-3 witnessscripthash tx with bullshit nesting', async () => {
|
||||
it('should verify 2-of-3 p2wsh tx w/ nested bullshit', async () => {
|
||||
await testMultisig(true, true);
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user