lint: enforce function names.

This commit is contained in:
Christopher Jeffrey 2017-08-06 21:36:48 -07:00
parent 62152a1005
commit 3bc47f5a3c
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
28 changed files with 169 additions and 174 deletions

View File

@ -24,7 +24,7 @@
"eqeqeq": ["error", "always", { "eqeqeq": ["error", "always", {
"null": "ignore" "null": "ignore"
}], }],
"func-name-matching": "off", "func-name-matching": "error",
"indent": ["error", 2, { "indent": ["error", 2, {
"SwitchCase": 1, "SwitchCase": 1,
"CallExpression": { "CallExpression": {

View File

@ -63,10 +63,10 @@ AEAD.prototype.init = function init(key, iv) {
* @param {Buffer} aad * @param {Buffer} aad
*/ */
AEAD.prototype.aad = function _aad(aad) { AEAD.prototype.aad = function aad(data) {
assert(this.cipherLen === 0, 'Cannot update aad.'); assert(this.cipherLen === 0, 'Cannot update aad.');
this.poly1305.update(aad); this.poly1305.update(data);
this.aadLen += aad.length; this.aadLen += data.length;
}; };
/** /**

View File

@ -22,8 +22,8 @@ const native = require('../native').binding;
*/ */
exports.encipher = function encipher(data, key, iv) { exports.encipher = function encipher(data, key, iv) {
const cipher = crypto.createCipheriv('aes-256-cbc', key, iv); const ctx = crypto.createCipheriv('aes-256-cbc', key, iv);
return Buffer.concat([cipher.update(data), cipher.final()]); return Buffer.concat([ctx.update(data), ctx.final()]);
}; };
/** /**
@ -34,10 +34,10 @@ exports.encipher = function encipher(data, key, iv) {
* @returns {Buffer} * @returns {Buffer}
*/ */
exports.decipher = function _decipher(data, key, iv) { exports.decipher = function decipher(data, key, iv) {
const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv); const ctx = crypto.createDecipheriv('aes-256-cbc', key, iv);
try { try {
return Buffer.concat([decipher.update(data), decipher.final()]); return Buffer.concat([ctx.update(data), ctx.final()]);
} catch (e) { } catch (e) {
throw new Error('Bad key for decryption.'); throw new Error('Bad key for decryption.');
} }

View File

@ -13,7 +13,7 @@
const assert = require('assert'); const assert = require('assert');
const hashjs = require('hash.js'); const hashjs = require('hash.js');
const sha256 = require('./sha256'); const SHA256 = require('./sha256');
const POOL64 = Buffer.allocUnsafe(64); const POOL64 = Buffer.allocUnsafe(64);
/** /**
@ -23,15 +23,15 @@ const POOL64 = Buffer.allocUnsafe(64);
* @returns {Buffer} * @returns {Buffer}
*/ */
exports.hash = function _hash(alg, data) { exports.hash = function hash(alg, data) {
if (alg === 'sha256') if (alg === 'sha256')
return sha256.digest(data); return SHA256.digest(data);
const hash = hashjs[alg]; const algo = hashjs[alg];
assert(hash != null, 'Unknown algorithm.'); assert(algo != null, 'Unknown algorithm.');
return Buffer.from(hash().update(data).digest()); return Buffer.from(algo().update(data).digest());
}; };
/** /**
@ -60,8 +60,8 @@ exports.sha1 = function sha1(data) {
* @returns {Buffer} * @returns {Buffer}
*/ */
exports.sha256 = function _sha256(data) { exports.sha256 = function sha256(data) {
return sha256.digest(data); return SHA256.digest(data);
}; };
/** /**
@ -71,7 +71,7 @@ exports.sha256 = function _sha256(data) {
*/ */
exports.hash160 = function hash160(data) { exports.hash160 = function hash160(data) {
return exports.hash('ripemd160', sha256.digest(data)); return exports.hash('ripemd160', SHA256.digest(data));
}; };
/** /**
@ -81,7 +81,7 @@ exports.hash160 = function hash160(data) {
*/ */
exports.hash256 = function hash256(data) { exports.hash256 = function hash256(data) {
return sha256.hash256(data); return SHA256.hash256(data);
}; };
/** /**
@ -111,12 +111,12 @@ exports.root256 = function root256(left, right) {
* @returns {Buffer} HMAC * @returns {Buffer} HMAC
*/ */
exports.hmac = function _hmac(alg, data, key) { exports.hmac = function hmac(alg, data, key) {
const hash = hashjs[alg]; const algo = hashjs[alg];
assert(hash != null, 'Unknown algorithm.'); assert(algo != null, 'Unknown algorithm.');
const hmac = hashjs.hmac(hash, key); const ctx = hashjs.hmac(algo, key);
return Buffer.from(hmac.update(data).digest()); return Buffer.from(ctx.update(data).digest());
}; };

View File

@ -103,9 +103,9 @@ exports.root256 = function root256(left, right) {
* @returns {Buffer} HMAC * @returns {Buffer} HMAC
*/ */
exports.hmac = function _hmac(alg, data, key) { exports.hmac = function hmac(alg, data, key) {
const hmac = crypto.createHmac(alg, key); const ctx = crypto.createHmac(alg, key);
return hmac.update(data).digest(); return ctx.update(data).digest();
}; };
if (native) { if (native) {

View File

@ -28,7 +28,7 @@ const schnorr = exports;
* @returns {Buffer} * @returns {Buffer}
*/ */
schnorr.hash = function _hash(msg, r) { schnorr.hash = function hash(msg, r) {
const R = r.toBuffer('be', 32); const R = r.toBuffer('be', 32);
const B = POOL64; const B = POOL64;

View File

@ -480,8 +480,8 @@ LowlevelUp.prototype.range = async function range(options) {
* @returns {Promise} - Returns Array. * @returns {Promise} - Returns Array.
*/ */
LowlevelUp.prototype.keys = async function _keys(options) { LowlevelUp.prototype.keys = async function keys(options) {
const keys = []; const items = [];
const parse = options.parse; const parse = options.parse;
const iter = this.iterator({ const iter = this.iterator({
@ -509,10 +509,10 @@ LowlevelUp.prototype.keys = async function _keys(options) {
} }
if (key) if (key)
keys.push(key); items.push(key);
} }
return keys; return items;
}; };
/** /**
@ -522,8 +522,8 @@ LowlevelUp.prototype.keys = async function _keys(options) {
* @returns {Promise} - Returns Array. * @returns {Promise} - Returns Array.
*/ */
LowlevelUp.prototype.values = async function _values(options) { LowlevelUp.prototype.values = async function values(options) {
const values = []; const items = [];
const parse = options.parse; const parse = options.parse;
const iter = this.iterator({ const iter = this.iterator({
@ -551,10 +551,10 @@ LowlevelUp.prototype.values = async function _values(options) {
} }
if (value) if (value)
values.push(value); items.push(value);
} }
return values; return items;
}; };
/** /**

View File

@ -216,21 +216,21 @@ MemDB.prototype.del = function del(key, options, callback) {
* @param {Function} callback * @param {Function} callback
*/ */
MemDB.prototype.batch = function _batch(ops, options, callback) { MemDB.prototype.batch = function batch(ops, options, callback) {
if (!callback) { if (!callback) {
callback = options; callback = options;
options = null; options = null;
} }
const batch = new Batch(this, options); const b = new Batch(this, options);
if (ops) { if (ops) {
batch.ops = ops; b.ops = ops;
batch.write(callback); b.write(callback);
return undefined; return undefined;
} }
return batch; return b;
}; };
/** /**

View File

@ -1111,20 +1111,20 @@ Route.prototype.compile = function compile() {
this.regex = new RegExp('^' + path + '$'); this.regex = new RegExp('^' + path + '$');
}; };
Route.prototype.match = function _match(pathname) { Route.prototype.match = function match(pathname) {
this.compile(); this.compile();
assert(this.regex); assert(this.regex);
const match = this.regex.exec(pathname); const matches = this.regex.exec(pathname);
if (!match) if (!matches)
return null; return null;
const params = Object.create(null); const params = Object.create(null);
for (let i = 1; i < match.length; i++) { for (let i = 1; i < matches.length; i++) {
const item = match[i]; const item = matches[i];
const key = this.map[i - 1]; const key = this.map[i - 1];
if (key) if (key)

View File

@ -530,20 +530,20 @@ function request(options) {
options.buffer = true; options.buffer = true;
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const stream = new Request(options); const req = new Request(options);
stream.on('error', err => reject(err)); req.on('error', err => reject(err));
stream.on('end', () => resolve(stream)); req.on('end', () => resolve(req));
stream.start(); req.start();
stream.end(); req.end();
}); });
} }
request.stream = function _stream(options) { request.stream = function stream(options) {
const stream = new Request(options); const req = new Request(options);
stream.start(); req.start();
return stream; return req;
}; };
/* /*

View File

@ -185,7 +185,7 @@ RPC.prototype.getInfo = async function getInfo(args, help) {
}; };
}; };
RPC.prototype.help = async function _help(args, help) { RPC.prototype.help = async function help(args, _help) {
if (args.length === 0) if (args.length === 0)
return 'Select a command.'; return 'Select a command.';

View File

@ -1874,7 +1874,7 @@ Mempool.prototype.getSize = function getSize() {
* @param {Amount} fee * @param {Amount} fee
*/ */
Mempool.prototype.prioritise = function _prioritise(entry, pri, fee) { Mempool.prototype.prioritise = function prioritise(entry, pri, fee) {
if (-pri > entry.priority) if (-pri > entry.priority)
pri = -entry.priority; pri = -entry.priority;
@ -1886,12 +1886,12 @@ Mempool.prototype.prioritise = function _prioritise(entry, pri, fee) {
if (fee === 0) if (fee === 0)
return; return;
this.updateAncestors(entry, preprioritise); this.updateAncestors(entry, prePrioritise);
entry.deltaFee += fee; entry.deltaFee += fee;
entry.descFee += fee; entry.descFee += fee;
this.updateAncestors(entry, prioritise); this.updateAncestors(entry, postPrioritise);
}; };
/** /**
@ -2514,11 +2514,11 @@ function removeFee(parent, child) {
parent.descSize -= child.descSize; parent.descSize -= child.descSize;
} }
function preprioritise(parent, child) { function prePrioritise(parent, child) {
parent.descFee -= child.deltaFee; parent.descFee -= child.deltaFee;
} }
function prioritise(parent, child) { function postPrioritise(parent, child) {
parent.descFee += child.deltaFee; parent.descFee += child.deltaFee;
} }

View File

@ -595,7 +595,7 @@ BIP151.prototype.packetSize = function packetSize(cmd, body) {
* @returns {Buffer} Ciphertext payload * @returns {Buffer} Ciphertext payload
*/ */
BIP151.prototype.packet = function _packet(cmd, body) { BIP151.prototype.packet = function packet(cmd, body) {
const size = this.packetSize(cmd, body); const size = this.packetSize(cmd, body);
const bw = new StaticWriter(size); const bw = new StaticWriter(size);
const payloadSize = size - 20; const payloadSize = size - 20;
@ -606,17 +606,17 @@ BIP151.prototype.packet = function _packet(cmd, body) {
bw.writeBytes(body); bw.writeBytes(body);
bw.seek(16); bw.seek(16);
const packet = bw.render(); const msg = bw.render();
const payload = packet.slice(4, 4 + payloadSize); const payload = msg.slice(4, 4 + payloadSize);
this.maybeRekey(packet); this.maybeRekey(msg);
this.output.encryptSize(packet); this.output.encryptSize(msg);
this.output.encrypt(payload); this.output.encrypt(payload);
this.output.finish().copy(packet, 4 + payloadSize); this.output.finish().copy(msg, 4 + payloadSize);
this.output.sequence(); this.output.sequence();
return packet; return msg;
}; };
/** /**

View File

@ -29,37 +29,38 @@ function Framer(network) {
* Frame a payload with a header. * Frame a payload with a header.
* @param {String} cmd - Packet type. * @param {String} cmd - Packet type.
* @param {Buffer} payload * @param {Buffer} payload
* @param {Buffer?} checksum - Precomputed checksum.
* @returns {Buffer} Payload with header prepended. * @returns {Buffer} Payload with header prepended.
*/ */
Framer.prototype.packet = function _packet(cmd, payload, checksum) { Framer.prototype.packet = function packet(cmd, payload, checksum) {
assert(payload, 'No payload.'); assert(payload, 'No payload.');
assert(cmd.length < 12); assert(cmd.length < 12);
assert(payload.length <= 0xffffffff); assert(payload.length <= 0xffffffff);
const packet = Buffer.allocUnsafe(24 + payload.length); const msg = Buffer.allocUnsafe(24 + payload.length);
// Magic value // Magic value
packet.writeUInt32LE(this.network.magic, 0, true); msg.writeUInt32LE(this.network.magic, 0, true);
// Command // Command
packet.write(cmd, 4, 'ascii'); msg.write(cmd, 4, 'ascii');
for (let i = 4 + cmd.length; i < 16; i++) for (let i = 4 + cmd.length; i < 16; i++)
packet[i] = 0; msg[i] = 0;
// Payload length // Payload length
packet.writeUInt32LE(payload.length, 16, true); msg.writeUInt32LE(payload.length, 16, true);
if (!checksum) if (!checksum)
checksum = digest.hash256(payload); checksum = digest.hash256(payload);
// Checksum // Checksum
checksum.copy(packet, 20, 0, 4); checksum.copy(msg, 20, 0, 4);
payload.copy(packet, 24); payload.copy(msg, 24);
return packet; return msg;
}; };
/* /*

View File

@ -1309,16 +1309,15 @@ HostEntry.prototype.key = function key() {
* @returns {Number} * @returns {Number}
*/ */
HostEntry.prototype.chance = function _chance(now) { HostEntry.prototype.chance = function chance(now) {
const attempts = this.attempts; let c = 1;
let chance = 1;
if (now - this.lastAttempt < 60 * 10) if (now - this.lastAttempt < 60 * 10)
chance *= 0.01; c *= 0.01;
chance *= Math.pow(0.66, Math.min(attempts, 8)); c *= Math.pow(0.66, Math.min(this.attempts, 8));
return chance; return c;
}; };
/** /**

View File

@ -7,7 +7,7 @@
'use strict'; 'use strict';
const assert = require('assert'); const assert = require('assert');
const path = require('path'); const Path = require('path');
const os = require('os'); const os = require('os');
const fs = require('../utils/fs'); const fs = require('../utils/fs');
const util = require('../utils/util'); const util = require('../utils/util');
@ -29,7 +29,7 @@ function Config(module) {
this.module = module; this.module = module;
this.network = 'main'; this.network = 'main';
this.prefix = path.join(HOME, `.${module}`); this.prefix = Path.join(HOME, `.${module}`);
this.options = Object.create(null); this.options = Object.create(null);
this.data = Object.create(null); this.data = Object.create(null);
@ -601,7 +601,7 @@ Config.prototype.func = function func(key, fallback) {
* @returns {String|null} * @returns {String|null}
*/ */
Config.prototype.path = function _path(key, fallback) { Config.prototype.path = function path(key, fallback) {
let value = this.str(key); let value = this.str(key);
if (fallback === undefined) if (fallback === undefined)
@ -612,16 +612,16 @@ Config.prototype.path = function _path(key, fallback) {
switch (value[0]) { switch (value[0]) {
case '~': // home dir case '~': // home dir
value = path.join(HOME, value.substring(1)); value = Path.join(HOME, value.substring(1));
break; break;
case '@': // prefix case '@': // prefix
value = path.join(this.prefix, value.substring(1)); value = Path.join(this.prefix, value.substring(1));
break; break;
default: // cwd default: // cwd
break; break;
} }
return path.normalize(value); return Path.normalize(value);
}; };
/** /**
@ -671,21 +671,21 @@ Config.prototype.getPrefix = function getPrefix() {
if (prefix) { if (prefix) {
if (prefix[0] === '~') if (prefix[0] === '~')
prefix = path.join(HOME, prefix.substring(1)); prefix = Path.join(HOME, prefix.substring(1));
return prefix; return prefix;
} }
prefix = path.join(HOME, `.${this.module}`); prefix = Path.join(HOME, `.${this.module}`);
const network = this.str('network'); const network = this.str('network');
if (network) { if (network) {
assert(isAlpha(network), 'Bad network.'); assert(isAlpha(network), 'Bad network.');
if (network !== 'main') if (network !== 'main')
prefix = path.join(prefix, network); prefix = Path.join(prefix, network);
} }
return path.normalize(prefix); return Path.normalize(prefix);
}; };
/** /**
@ -701,7 +701,7 @@ Config.prototype.getFile = function getFile(file) {
if (name) if (name)
return name; return name;
return path.join(this.prefix, file); return Path.join(this.prefix, file);
}; };
/** /**
@ -723,7 +723,7 @@ Config.prototype.ensure = function ensure() {
*/ */
Config.prototype.location = function location(file) { Config.prototype.location = function location(file) {
return path.join(this.prefix, file); return Path.join(this.prefix, file);
}; };
/** /**

View File

@ -507,15 +507,15 @@ Logger.prototype.log = function log(level, module, args) {
* @returns {LoggerContext} * @returns {LoggerContext}
*/ */
Logger.prototype.context = function _context(module) { Logger.prototype.context = function context(module) {
let context = this.contexts[module]; let ctx = this.contexts[module];
if (!context) { if (!ctx) {
context = new LoggerContext(this, module); ctx = new LoggerContext(this, module);
this.contexts[module] = context; this.contexts[module] = ctx;
} }
return context; return ctx;
}; };
/** /**

View File

@ -134,26 +134,26 @@ AbstractBlock.prototype.refresh = function refresh() {
* @returns {Hash|Buffer} hash * @returns {Hash|Buffer} hash
*/ */
AbstractBlock.prototype.hash = function _hash(enc) { AbstractBlock.prototype.hash = function hash(enc) {
let hash = this._hash; let h = this._hash;
if (!hash) { if (!h) {
hash = digest.hash256(this.toHead()); h = digest.hash256(this.toHead());
if (!this.mutable) if (!this.mutable)
this._hash = hash; this._hash = h;
} }
if (enc === 'hex') { if (enc === 'hex') {
let hex = this._hhash; let hex = this._hhash;
if (!hex) { if (!hex) {
hex = hash.toString('hex'); hex = h.toString('hex');
if (!this.mutable) if (!this.mutable)
this._hhash = hex; this._hhash = hex;
} }
hash = hex; h = hex;
} }
return hash; return h;
}; };
/** /**

View File

@ -175,26 +175,26 @@ TX.prototype.refresh = function refresh() {
* @returns {Hash|Buffer} hash * @returns {Hash|Buffer} hash
*/ */
TX.prototype.hash = function _hash(enc) { TX.prototype.hash = function hash(enc) {
let hash = this._hash; let h = this._hash;
if (!hash) { if (!h) {
hash = digest.hash256(this.toNormal()); h = digest.hash256(this.toNormal());
if (!this.mutable) if (!this.mutable)
this._hash = hash; this._hash = h;
} }
if (enc === 'hex') { if (enc === 'hex') {
let hex = this._hhash; let hex = this._hhash;
if (!hex) { if (!hex) {
hex = hash.toString('hex'); hex = h.toString('hex');
if (!this.mutable) if (!this.mutable)
this._hhash = hex; this._hhash = hex;
} }
hash = hex; h = hex;
} }
return hash; return h;
}; };
/** /**

View File

@ -9,9 +9,8 @@
const assert = require('assert'); const assert = require('assert');
const Int64 = require('./int64'); const Int64 = require('./int64');
const digest = require('../crypto/digest'); const digest = require('../crypto/digest');
const siphash24 = require('../crypto/siphash'); const siphash = require('../crypto/siphash');
const SCRATCH = Buffer.allocUnsafe(64); const DUMMY = Buffer.alloc(0);
const DUMMY = Buffer.allocUnsafe(0);
const EOF = new Int64(-1); const EOF = new Int64(-1);
/** /**
@ -27,22 +26,18 @@ function GCSFilter() {
this.data = DUMMY; this.data = DUMMY;
} }
GCSFilter.prototype.hash = function _hash(enc) { GCSFilter.prototype.hash = function hash(enc) {
const hash = digest.hash256(this.data); const h = digest.hash256(this.data);
return enc === 'hex' ? hash.toString('hex') : hash; return enc === 'hex' ? h.toString('hex') : h;
}; };
GCSFilter.prototype.header = function header(prev) { GCSFilter.prototype.header = function header(prev) {
const data = SCRATCH; return digest.root256(this.hash(), prev);
const hash = this.hash();
hash.copy(data, 0);
prev.copy(data, 32);
return digest.hash256(data);
}; };
GCSFilter.prototype.match = function match(key, data) { GCSFilter.prototype.match = function match(key, data) {
const br = new BitReader(this.data); const br = new BitReader(this.data);
const term = siphash(data, key).imod(this.m); const term = siphash24(data, key).imod(this.m);
let last = new Int64(0); let last = new Int64(0);
while (last.lt(term)) { while (last.lt(term)) {
@ -70,7 +65,7 @@ GCSFilter.prototype.matchAny = function matchAny(key, items) {
const values = []; const values = [];
for (const item of items) { for (const item of items) {
const hash = siphash(item, key).imod(this.m); const hash = siphash24(item, key).imod(this.m);
values.push(hash); values.push(hash);
} }
@ -177,7 +172,7 @@ GCSFilter.prototype.fromItems = function fromItems(P, key, items) {
for (const item of items) { for (const item of items) {
assert(Buffer.isBuffer(item)); assert(Buffer.isBuffer(item));
const hash = siphash(item, key).imod(this.m); const hash = siphash24(item, key).imod(this.m);
values.push(hash); values.push(hash);
} }
@ -515,8 +510,8 @@ function compare(a, b) {
return a.cmp(b) < 0 ? -1 : 1; return a.cmp(b) < 0 ? -1 : 1;
} }
function siphash(data, key) { function siphash24(data, key) {
const [hi, lo] = siphash24(data, key); const [hi, lo] = siphash(data, key);
return new Int64().join(hi, lo); return new Int64().join(hi, lo);
} }

View File

@ -288,8 +288,8 @@ LRU.prototype._removeList = function _removeList(item) {
* @returns {String[]} * @returns {String[]}
*/ */
LRU.prototype.keys = function _keys() { LRU.prototype.keys = function keys() {
const keys = []; const items = [];
for (let item = this.head; item; item = item.next) { for (let item = this.head; item; item = item.next) {
if (item === this.head) if (item === this.head)
@ -298,10 +298,10 @@ LRU.prototype.keys = function _keys() {
assert(item === this.head); assert(item === this.head);
if (!item.next) if (!item.next)
assert(item === this.tail); assert(item === this.tail);
keys.push(item.key); items.push(item.key);
} }
return keys; return items;
}; };
/** /**
@ -309,13 +309,13 @@ LRU.prototype.keys = function _keys() {
* @returns {String[]} * @returns {String[]}
*/ */
LRU.prototype.values = function _values() { LRU.prototype.values = function values() {
const values = []; const items = [];
for (let item = this.head; item; item = item.next) for (let item = this.head; item; item = item.next)
values.push(item.value); items.push(item.value);
return values; return items;
}; };
/** /**

View File

@ -37,8 +37,8 @@ function ProtoReader(data, zeroCopy) {
Object.setPrototypeOf(ProtoReader.prototype, BufferReader.prototype); Object.setPrototypeOf(ProtoReader.prototype, BufferReader.prototype);
ProtoReader.prototype.readVarint = function _readVarint() { ProtoReader.prototype.readVarint = function readVarint() {
const {size, value} = readVarint(this.data, this.offset); const {size, value} = _readVarint(this.data, this.offset);
this.offset += size; this.offset += size;
return value; return value;
}; };
@ -159,7 +159,7 @@ ProtoReader.prototype.readField = function readField(tag, opt) {
* Encoding * Encoding
*/ */
function readVarint(data, off) { function _readVarint(data, off) {
let num = 0; let num = 0;
let ch = 0x80; let ch = 0x80;
let size = 0; let size = 0;

View File

@ -41,7 +41,7 @@ function ProtoWriter() {
Object.setPrototypeOf(ProtoWriter.prototype, BufferWriter.prototype); Object.setPrototypeOf(ProtoWriter.prototype, BufferWriter.prototype);
ProtoWriter.prototype.writeVarint = function _writeVarint(num) { ProtoWriter.prototype.writeVarint = function writeVarint(num) {
const size = sizeVarint(num); const size = sizeVarint(num);
// Avoid an extra allocation until // Avoid an extra allocation until
@ -83,7 +83,7 @@ ProtoWriter.prototype.writeVarint = function _writeVarint(num) {
} }
default: { default: {
const value = Buffer.allocUnsafe(size); const value = Buffer.allocUnsafe(size);
writeVarint(value, num, 0); _writeVarint(value, num, 0);
this.writeBytes(value); this.writeBytes(value);
break; break;
} }
@ -123,7 +123,7 @@ ProtoWriter.prototype.writeFieldString = function writeFieldString(tag, data, en
* Encoding * Encoding
*/ */
function writeVarint(data, num, off) { function _writeVarint(data, num, off) {
assert(Number.isSafeInteger(num), 'Number exceeds 2^53-1.'); assert(Number.isSafeInteger(num), 'Number exceeds 2^53-1.');
do { do {

View File

@ -446,31 +446,31 @@ util.random = function random(min, max) {
* @returns {Buffer} * @returns {Buffer}
*/ */
util.nonce = function _nonce(size) { util.nonce = function nonce(size) {
let n, nonce; let n, data;
if (!size) if (!size)
size = 8; size = 8;
switch (size) { switch (size) {
case 8: case 8:
nonce = Buffer.allocUnsafe(8); data = Buffer.allocUnsafe(8);
n = util.random(0, 0x100000000); n = util.random(0, 0x100000000);
nonce.writeUInt32LE(n, 0, true); data.writeUInt32LE(n, 0, true);
n = util.random(0, 0x100000000); n = util.random(0, 0x100000000);
nonce.writeUInt32LE(n, 4, true); data.writeUInt32LE(n, 4, true);
break; break;
case 4: case 4:
nonce = Buffer.allocUnsafe(4); data = Buffer.allocUnsafe(4);
n = util.random(0, 0x100000000); n = util.random(0, 0x100000000);
nonce.writeUInt32LE(n, 0, true); data.writeUInt32LE(n, 0, true);
break; break;
default: default:
assert(false, 'Bad nonce size.'); assert(false, 'Bad nonce size.');
break; break;
} }
return nonce; return data;
}; };
/** /**

View File

@ -169,12 +169,12 @@ MasterKey.fromOptions = function fromOptions(options) {
* @returns {Promise} - Returns {@link HDPrivateKey}. * @returns {Promise} - Returns {@link HDPrivateKey}.
*/ */
MasterKey.prototype.unlock = async function _unlock(passphrase, timeout) { MasterKey.prototype.unlock = async function unlock(passphrase, timeout) {
const unlock = await this.locker.lock(); const _unlock = await this.locker.lock();
try { try {
return await this._unlock(passphrase, timeout); return await this._unlock(passphrase, timeout);
} finally { } finally {
unlock(); _unlock();
} }
}; };
@ -310,7 +310,7 @@ MasterKey.prototype.decipher = function decipher(data, iv) {
* @returns {Promise} * @returns {Promise}
*/ */
MasterKey.prototype.lock = async function _lock() { MasterKey.prototype.lock = async function lock() {
const unlock = await this.locker.lock(); const unlock = await this.locker.lock();
try { try {
return await this._lock(); return await this._lock();

View File

@ -110,7 +110,7 @@ RPC.prototype.init = function init() {
this.add('setloglevel', this.setLogLevel); this.add('setloglevel', this.setLogLevel);
}; };
RPC.prototype.help = async function _help(args, help) { RPC.prototype.help = async function help(args, _help) {
if (args.length === 0) if (args.length === 0)
return 'Select a command.'; return 'Select a command.';

View File

@ -20,22 +20,22 @@ function Framer() {
return new Framer(); return new Framer();
} }
Framer.prototype.packet = function _packet(packet) { Framer.prototype.packet = function packet(payload) {
const size = 10 + packet.getSize(); const size = 10 + payload.getSize();
const bw = new StaticWriter(size); const bw = new StaticWriter(size);
bw.writeU32(packet.id); bw.writeU32(payload.id);
bw.writeU8(packet.cmd); bw.writeU8(payload.cmd);
bw.seek(4); bw.seek(4);
packet.toWriter(bw); payload.toWriter(bw);
bw.writeU8(0x0a); bw.writeU8(0x0a);
const data = bw.render(); const msg = bw.render();
data.writeUInt32LE(data.length - 10, 5, true); msg.writeUInt32LE(msg.length - 10, 5, true);
return data; return msg;
}; };
/* /*

View File

@ -7,8 +7,8 @@
'use strict'; 'use strict';
const secp256k1 = require('../crypto/secp256k1'); const secp256k1 = require('../crypto/secp256k1');
const scrypt = require('../crypto/scrypt'); const {derive} = require('../crypto/scrypt');
const mine = require('../mining/mine'); const hashcash = require('../mining/mine');
const packets = require('./packets'); const packets = require('./packets');
/** /**
@ -169,8 +169,8 @@ jobs.ecSign = function ecSign(msg, key) {
* @returns {Number} * @returns {Number}
*/ */
jobs.mine = function _mine(data, target, min, max) { jobs.mine = function mine(data, target, min, max) {
const nonce = mine(data, target, min, max); const nonce = hashcash(data, target, min, max);
return new packets.MineResultPacket(nonce); return new packets.MineResultPacket(nonce);
}; };
@ -186,7 +186,7 @@ jobs.mine = function _mine(data, target, min, max) {
* @returns {Buffer} * @returns {Buffer}
*/ */
jobs.scrypt = function _scrypt(passwd, salt, N, r, p, len) { jobs.scrypt = function scrypt(passwd, salt, N, r, p, len) {
const key = scrypt.derive(passwd, salt, N, r, p, len); const key = derive(passwd, salt, N, r, p, len);
return new packets.ScryptResultPacket(key); return new packets.ScryptResultPacket(key);
}; };