Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
16 changes: 16 additions & 0 deletions .eslintfiles
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
bench/
bin/cli
bin/node
bin/spvnode
bin/wallet
browser/server.js
browser/wsproxy.js
examples/
lib/
migrate/
scripts/
test/
webpack/
webpack.browser.js
webpack.compat.js
webpack.node.js
95 changes: 76 additions & 19 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,98 @@
{
"extends": "eslint:recommended",
"env": {
"browser": true,
"es6": true,
"node": true,
"mocha": true
"node": true
},
"extends": "eslint:recommended",
"parserOptions": {
"ecmaVersion": 8
},
"root": true,
"rules": {
"strict": 2,
"indent": ["error", 2, {
"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": "error",
"indent": ["off", 2, {
"SwitchCase": 1,
"CallExpression": {
"arguments": "off"
},
"ArrayExpression": "off"
}],
"handle-callback-err": "off",
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"semi": ["error", "always"],
"no-console": 0,
"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-extra-semi": "off",
"no-fallthrough": "off",
"no-func-assign": "off",
"no-implicit-coercion": "error",
"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",
"ignoreRestSiblings": false
}],
"no-func-assign": 0,
"no-cond-assign": 0,
"no-unreachable": 0,
"no-fallthrough": 0,
"no-useless-escape": 0,
"no-unsafe-finally": 0,
"no-extra-semi": 0,
"handle-callback-err": 0,
"no-buffer-constructor": 2,
"no-tabs": 2
"no-use-before-define": ["error", {
"functions": false,
"classes": false
}],
"no-useless-escape": "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",
"unicode-bom": ["error", "never"],
"valid-jsdoc": "error",
"wrap-iife": ["error", "inside"]
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules/
docs/reference/
docker_data/
browser/bcoin*
package-lock.json
npm-debug.log
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ docker_data/
test/
node_modules/
browser/bcoin*
package-lock.json
npm-debug.log
33 changes: 17 additions & 16 deletions bench/bech32.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@
const Address = require('../lib/primitives/address');
const random = require('../lib/crypto/random');
const bench = require('./bench');
const addrs = [];

let i, end, addr;

let addrs = [];

end = bench('serialize');
for (i = 0; i < 100000; i++) {
addr = Address.fromProgram(0, random.randomBytes(20));
addrs.push(addr.toBech32());
{
const end = bench('serialize');
for (let i = 0; i < 100000; i++) {
const addr = Address.fromProgram(0, random.randomBytes(20));
addrs.push(addr.toBech32());
}
end(100000);
}
end(i);

end = bench('parse');
for (i = 0; i < 100000; i++) {
addr = addrs[i];
addr = Address.fromBech32(addr);
addrs[i] = addr;
{
const end = bench('parse');
for (let i = 0; i < 100000; i++) {
const b32 = addrs[i];
const addr = Address.fromBech32(b32);
addrs[i] = addr;
}
end(100000);
}
end(i);

console.error(addrs);
console.error(addrs[0][0]);
8 changes: 4 additions & 4 deletions bench/bench.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
'use strict';

module.exports = function bench(name) {
let start = process.hrtime();
const start = process.hrtime();
return function end(ops) {
let elapsed = process.hrtime(start);
let time = elapsed[0] + elapsed[1] / 1e9;
let rate = ops / time;
const elapsed = process.hrtime(start);
const time = elapsed[0] + elapsed[1] / 1e9;
const rate = ops / time;

console.log('%s: ops=%d, time=%d, rate=%s',
name, ops, time, rate.toFixed(5));
Expand Down
44 changes: 23 additions & 21 deletions bench/buffer.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
'use strict';

const fs = require('fs');
const TX = require('../lib/primitives/tx');
const BufferWriter = require('../lib/utils/writer');
const StaticWriter = require('../lib/utils/staticwriter');
const common = require('../test/util/common');
const bench = require('./bench');

let wtx = fs.readFileSync(`${__dirname}/../test/data/wtx.hex`, 'utf8');
let i, tx, end;
const tx5 = common.readTX('tx5');

wtx = Buffer.from(wtx.trim(), 'hex');
tx = TX.fromRaw(wtx);

end = bench('serialize (static-writer)');
for (i = 0; i < 10000; i++) {
tx._raw = null;
tx._size = -1;
tx._witness = -1;
tx.writeWitness(new StaticWriter(tx.getWitnessSizes().total)).render();
{
const [tx] = tx5.getTX();
const end = bench('serialize (static-writer)');
for (let i = 0; i < 10000; i++) {
tx.refresh();
const {size} = tx.getWitnessSizes();
const bw = new StaticWriter(size);
tx.toWitnessWriter(bw);
bw.render();
}
end(10000);
}
end(i);

end = bench('serialize (buffer-writer)');
for (i = 0; i < 10000; i++) {
tx._raw = null;
tx._size = -1;
tx._witness = -1;
tx.writeWitness(new BufferWriter()).render();
{
const [tx] = tx5.getTX();
const end = bench('serialize (buffer-writer)');
for (let i = 0; i < 10000; i++) {
tx.refresh();
const bw = new BufferWriter();
tx.toWitnessWriter(bw);
bw.render();
}
end(10000);
}
end(i);
72 changes: 39 additions & 33 deletions bench/chacha.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,53 @@ const ChaCha20 = require('../lib/crypto/chacha20');
const Poly1305 = require('../lib/crypto/poly1305');
const digest = require('../lib/crypto/digest');
const bench = require('./bench');
let i, chacha, iv, poly, key, data, end;

console.log('note: rate measured in kb/s');

chacha = new ChaCha20();
key = Buffer.allocUnsafe(32);
key.fill(2);
iv = Buffer.from('0102030405060708', 'hex');
const chacha = new ChaCha20();
const poly = new Poly1305();
const key = Buffer.alloc(32, 0x02);
const iv = Buffer.from('0102030405060708', 'hex');
const chunk = Buffer.allocUnsafe(32);
const data = Buffer.allocUnsafe(32);

for (let i = 0; i < 32; i++)
chunk[i] = i;

for (let i = 0; i < 32; i++)
data[i] = i & 0xff;

chacha.init(key, iv, 0);
data = Buffer.allocUnsafe(32);
for (i = 0; i < 32; i++)
data[i] = i;
end = bench('encrypt');
for (i = 0; i < 1000000; i++)
chacha.encrypt(data);
end(i * 32 / 1024);

poly = new Poly1305();
key = Buffer.allocUnsafe(32);
key.fill(2);
poly.init(key);

data = Buffer.allocUnsafe(32);
for (i = 0; i < 32; i++)
data[i] = i & 0xff;
{
const end = bench('encrypt');
for (let i = 0; i < 1000000; i++)
chacha.encrypt(chunk);
end(1000000 * 32 / 1024);
}

end = bench('update');
for (i = 0; i < 1000000; i++)
poly.update(data);
end(i * 32 / 1024);
{
const end = bench('update');
for (let i = 0; i < 1000000; i++)
poly.update(data);
end(1000000 * 32 / 1024);
}

end = bench('finish');
for (i = 0; i < 1000000; i++) {
poly.init(key);
poly.update(data);
poly.finish();
{
const end = bench('finish');
for (let i = 0; i < 1000000; i++) {
poly.init(key);
poly.update(data);
poly.finish();
}
end(1000000 * 32 / 1024);
}
end(i * 32 / 1024);

// For reference:
end = bench('sha256');
for (i = 0; i < 1000000; i++)
digest.hash256(data);
end(i * 32 / 1024);
{
const end = bench('sha256');
for (let i = 0; i < 1000000; i++)
digest.hash256(data);
end(1000000 * 32 / 1024);
}
39 changes: 0 additions & 39 deletions bench/coins-old.js

This file was deleted.

Loading