Skip to content

Commit

Permalink
Merge pull request bcoin-org#96 from bcoin-org/upgrade-deps2
Browse files Browse the repository at this point in the history
deps: upgrade to bcrypto 2.0, among other things.
  • Loading branch information
nodech authored Oct 18, 2018
2 parents 5c219ab + 60e36c3 commit a553951
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 45 deletions.
4 changes: 1 addition & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
# fallback to using the latest cache if no exact match is found
- v1-dependencies-
- run: npm install
- run: npm install eslint [email protected] codecov
- save_cache:
paths:
- node_modules
Expand All @@ -34,9 +35,6 @@ jobs:
- run:
name: Tests with coverage
command: npm run test-ci
- run:
name: Install codecov
command: npm i codecov
- run:
name: Submit coverage
command: ./node_modules/.bin/codecov
Expand Down
2 changes: 1 addition & 1 deletion lib/hd/private.js
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ class HDPrivateKey {
*/

static generate() {
const key = secp256k1.generatePrivateKey();
const key = secp256k1.privateKeyGenerate();
const entropy = random.randomBytes(32);
return HDPrivateKey.fromKey(key, entropy);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/net/bip151.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class BIP151Stream {

constructor(cipher) {
this.cipher = BIP151.ciphers.CHACHAPOLY;
this.privateKey = secp256k1.generatePrivateKey();
this.privateKey = secp256k1.privateKeyGenerate();
this.publicKey = null;
this.k1 = null;
this.k2 = null;
Expand Down Expand Up @@ -99,7 +99,7 @@ class BIP151Stream {

this.publicKey = publicKey;

const secret = secp256k1.ecdh(this.publicKey, this.privateKey).slice(1);
const secret = secp256k1.derive(this.publicKey, this.privateKey).slice(1);

const bw = bio.pool(33);

Expand Down
4 changes: 2 additions & 2 deletions lib/node/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {base58} = require('bstring');
const {BloomFilter} = require('bfilter');
const sha256 = require('bcrypto/lib/sha256');
const random = require('bcrypto/lib/random');
const ccmp = require('bcrypto/lib/ccmp');
const {safeEqual} = require('bcrypto/lib/safe');
const util = require('../utils/util');
const Address = require('../primitives/address');
const TX = require('../primitives/tx');
Expand Down Expand Up @@ -367,7 +367,7 @@ class HTTP extends Server {
const data = Buffer.from(key, 'ascii');
const hash = sha256.digest(data);

if (!ccmp(hash, this.options.apiHash))
if (!safeEqual(hash, this.options.apiHash))
throw new Error('Invalid API key.');
}

Expand Down
4 changes: 2 additions & 2 deletions lib/node/rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const Validator = require('bval');
const {BufferMap, BufferSet} = require('buffer-map');
const hash160 = require('bcrypto/lib/hash160');
const hash256 = require('bcrypto/lib/hash256');
const ccmp = require('bcrypto/lib/ccmp');
const {safeEqual} = require('bcrypto/lib/safe');
const secp256k1 = require('bcrypto/lib/secp256k1');
const util = require('../utils/util');
const common = require('../blockchain/common');
Expand Down Expand Up @@ -2053,7 +2053,7 @@ class RPC extends RPCBase {
if (!key)
return false;

return ccmp(hash160.digest(key), addr.hash);
return safeEqual(hash160.digest(key), addr.hash);
}

async signMessageWithPrivkey(args, help) {
Expand Down
2 changes: 1 addition & 1 deletion lib/primitives/keyring.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class KeyRing {
*/

generate(compress) {
const key = secp256k1.generatePrivateKey();
const key = secp256k1.privateKeyGenerate();
return this.fromKey(key, compress);
}

Expand Down
8 changes: 4 additions & 4 deletions lib/wallet/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Outpoint = require('../primitives/outpoint');
const Script = require('../script/script');
const sha256 = require('bcrypto/lib/sha256');
const random = require('bcrypto/lib/random');
const ccmp = require('bcrypto/lib/ccmp');
const {safeEqual} = require('bcrypto/lib/safe');
const Network = require('../protocol/network');
const Address = require('../primitives/address');
const KeyRing = require('../primitives/keyring');
Expand Down Expand Up @@ -102,7 +102,7 @@ class HTTP extends Server {
const valid = Validator.fromRequest(req);
const token = valid.buf('token');

if (token && ccmp(token, this.options.adminToken)) {
if (token && safeEqual(token, this.options.adminToken)) {
req.admin = true;
return;
}
Expand Down Expand Up @@ -938,7 +938,7 @@ class HTTP extends Server {
const data = Buffer.from(key, 'utf8');
const hash = sha256.digest(data);

if (!ccmp(hash, this.options.apiHash))
if (!safeEqual(hash, this.options.apiHash))
throw new Error('Invalid API key.');
}

Expand Down Expand Up @@ -970,7 +970,7 @@ class HTTP extends Server {
if (!this.options.walletAuth) {
socket.join('admin');
} else if (token) {
if (ccmp(token, this.options.adminToken))
if (safeEqual(token, this.options.adminToken))
socket.join('admin');
}

Expand Down
4 changes: 2 additions & 2 deletions lib/wallet/walletdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {BloomFilter} = require('bfilter');
const {Lock, MapLock} = require('bmutex');
const bdb = require('bdb');
const Logger = require('blgr');
const ccmp = require('bcrypto/lib/ccmp');
const {safeEqual} = require('bcrypto/lib/safe');
const aes = require('bcrypto/lib/aes');
const Network = require('../protocol/network');
const Path = require('./path');
Expand Down Expand Up @@ -1018,7 +1018,7 @@ class WalletDB extends EventEmitter {
return null;

// Compare in constant time:
if (!ccmp(token, wallet.token))
if (!safeEqual(token, wallet.token))
throw new Error('WDB: Authentication error.');

return wallet;
Expand Down
54 changes: 26 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,35 @@
"node": ">=8.0.0"
},
"dependencies": {
"bcfg": "~0.1.2",
"bclient": "~0.1.3",
"bcrypto": "~1.1.0",
"bdb": "~1.1.0",
"bdns": "~0.1.1",
"bevent": "~0.1.1",
"bfile": "~0.1.1",
"bfilter": "~1.0.0",
"bheep": "~0.1.1",
"binet": "~0.3.1",
"blgr": "~0.1.1",
"blru": "~0.1.2",
"blst": "~0.1.1",
"bmutex": "~0.1.2",
"bcfg": "~0.1.3",
"bclient": "~0.1.4",
"bcrypto": "~2.0.0",
"bdb": "~1.1.1",
"bdns": "~0.1.2",
"bevent": "~0.1.2",
"bfile": "~0.1.2",
"bfilter": "~1.0.1",
"bheep": "~0.1.2",
"binet": "~0.3.2",
"blgr": "~0.1.2",
"blru": "~0.1.3",
"blst": "~0.1.2",
"bmutex": "~0.1.3",
"bsert": "~0.0.4",
"bsip": "~0.1.1",
"bsock": "~0.1.2",
"bsocks": "~0.2.1",
"bstring": "~0.2.0",
"btcp": "~0.1.1",
"buffer-map": "~0.0.2",
"bufio": "~1.0.1",
"bupnp": "~0.2.2",
"bval": "~0.1.2",
"bweb": "~0.1.3",
"mrmr": "~0.1.1",
"n64": "~0.2.1"
"bsip": "~0.1.2",
"bsock": "~0.1.3",
"bsocks": "~0.2.2",
"bstring": "~0.3.0",
"btcp": "~0.1.2",
"buffer-map": "~0.0.3",
"bufio": "~1.0.2",
"bupnp": "~0.2.3",
"bval": "~0.1.3",
"bweb": "~0.1.4",
"mrmr": "~0.1.2",
"n64": "~0.2.2"
},
"devDependencies": {
"eslint": "^5.1.0",
"istanbul": "^1.1.0-alpha.1",
"mocha": "^5.2.0"
},
"main": "./lib/bcoin.js",
Expand Down

0 comments on commit a553951

Please sign in to comment.