Skip to content

Commit

Permalink
pkg: update bcrypto.
Browse files Browse the repository at this point in the history
use mrmr, bstring and bsip from bcrypto
  • Loading branch information
nodech committed Jun 25, 2019
1 parent fb753a4 commit 1a87b9f
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 76 deletions.
2 changes: 1 addition & 1 deletion lib/hd/private.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

const assert = require('bsert');
const bio = require('bufio');
const {base58} = require('bstring');
const base58 = require('bcrypto/lib/encoding/base58');
const sha512 = require('bcrypto/lib/sha512');
const hash160 = require('bcrypto/lib/hash160');
const hash256 = require('bcrypto/lib/hash256');
Expand Down
2 changes: 1 addition & 1 deletion lib/hd/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

const assert = require('bsert');
const bio = require('bufio');
const {base58} = require('bstring');
const base58 = require('bcrypto/lib/encoding/base58');
const sha512 = require('bcrypto/lib/sha512');
const hash160 = require('bcrypto/lib/hash160');
const hash256 = require('bcrypto/lib/hash256');
Expand Down
2 changes: 1 addition & 1 deletion lib/net/bip152.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const assert = require('bsert');
const bio = require('bufio');
const consensus = require('../protocol/consensus');
const sha256 = require('bcrypto/lib/sha256');
const {siphash} = require('bsip');
const {siphash} = require('bcrypto/lib/siphash');
const AbstractBlock = require('../primitives/abstractblock');
const TX = require('../primitives/tx');
const Headers = require('../primitives/headers');
Expand Down
2 changes: 1 addition & 1 deletion lib/net/hostlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const fs = require('bfile');
const IP = require('binet');
const dns = require('bdns');
const Logger = require('blgr');
const murmur3 = require('mrmr');
const murmur3 = require('bcrypto/lib/murmur3');
const List = require('blst');
const util = require('../utils/util');
const Network = require('../protocol/network');
Expand Down
2 changes: 1 addition & 1 deletion lib/node/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const assert = require('bsert');
const path = require('path');
const {Server} = require('bweb');
const Validator = require('bval');
const {base58} = require('bstring');
const base58 = require('bcrypto/lib/encoding/base58');
const {BloomFilter} = require('bfilter');
const sha256 = require('bcrypto/lib/sha256');
const random = require('bcrypto/lib/random');
Expand Down
9 changes: 5 additions & 4 deletions lib/primitives/address.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

const assert = require('bsert');
const bio = require('bufio');
const {base58, bech32} = require('bstring');
const base58 = require('bcrypto/lib/encoding/base58');
const bech32 = require('bcrypto/lib/encoding/bech32');
const sha256 = require('bcrypto/lib/sha256');
const hash160 = require('bcrypto/lib/hash160');
const hash256 = require('bcrypto/lib/hash256');
Expand Down Expand Up @@ -383,12 +384,12 @@ class Address {

assert(typeof data === 'string');

const addr = bech32.decode(data);
const [hrp, version, hash] = bech32.decode(data);

// make sure HRP is correct.
Network.fromBech32(addr.hrp, network);
Network.fromBech32(hrp, network);

return this.fromHash(addr.hash, type, addr.version);
return this.fromHash(hash, type, version);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/primitives/keyring.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
'use strict';

const assert = require('bsert');
const {base58} = require('bstring');
const base58 = require('bcrypto/lib/encoding/base58');
const bio = require('bufio');
const hash160 = require('bcrypto/lib/hash160');
const hash256 = require('bcrypto/lib/hash256');
Expand Down
2 changes: 1 addition & 1 deletion lib/wallet/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const assert = require('bsert');
const path = require('path');
const {Server} = require('bweb');
const Validator = require('bval');
const {base58} = require('bstring');
const base58 = require('bcrypto/lib/encoding/base58');
const MTX = require('../primitives/mtx');
const Outpoint = require('../primitives/outpoint');
const Script = require('../script/script');
Expand Down
2 changes: 1 addition & 1 deletion lib/wallet/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
const assert = require('bsert');
const EventEmitter = require('events');
const {Lock} = require('bmutex');
const {base58} = require('bstring');
const base58 = require('bcrypto/lib/encoding/base58');
const bio = require('bufio');
const hash160 = require('bcrypto/lib/hash160');
const hash256 = require('bcrypto/lib/hash256');
Expand Down
26 changes: 3 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"dependencies": {
"bcfg": "~0.1.6",
"bclient": "~0.1.7",
"bcrypto": "~3.1.11",
"bcrypto": "~4.0.1",
"bdb": "~1.1.7",
"bdns": "~0.1.5",
"bevent": "~0.1.5",
Expand All @@ -38,17 +38,14 @@
"blst": "~0.1.5",
"bmutex": "~0.1.6",
"bsert": "~0.0.10",
"bsip": "~0.1.9",
"bsock": "~0.1.9",
"bsocks": "~0.2.5",
"bstring": "~0.3.9",
"btcp": "~0.1.5",
"buffer-map": "~0.0.7",
"bufio": "~1.0.6",
"bupnp": "~0.2.6",
"bval": "~0.1.6",
"bweb": "~0.1.9",
"mrmr": "~0.1.8",
"n64": "~0.2.10"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion test/hd-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

'use strict';

const {base58} = require('bstring');
const base58 = require('bcrypto/lib/encoding/base58');
const pbkdf2 = require('bcrypto/lib/pbkdf2');
const sha512 = require('bcrypto/lib/sha512');
const assert = require('bsert');
Expand Down
36 changes: 0 additions & 36 deletions test/utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,12 @@
'use strict';

const Validator = require('bval');
const {base58} = require('bstring');
const {encoding} = require('bufio');
const assert = require('bsert');
const Amount = require('../lib/btc/amount');
const fixed = require('../lib/utils/fixed');

const base58Tests = [
['', ''],
['61', '2g'],
['626262', 'a3gV'],
['636363', 'aPEr'],
[
'73696d706c792061206c6f6e6720737472696e67',
'2cFupjhnEsSn59qHXstmK2ffpLv2'
],
[
'00eb15231dfceb60925886b67d065299925915aeb172c06647',
'1NS17iag9jJgTHD1VXjvLCEnZuQ3rJDE9L'
],
['516b6fcd0f', 'ABnLTmg'],
['bf4f89001e670274dd', '3SEo3LWLoPntC'],
['572e4794', '3EFU7m'],
['ecac89cad93923c02321', 'EJDM8drfXA6uyA'],
['10c8511e', 'Rt5zm'],
['00000000000000000000', '1111111111']
];

describe('Utils', function() {
it('should encode/decode base58', () => {
const buf = Buffer.from('000000deadbeef', 'hex');
const str = base58.encode(buf);

assert.strictEqual(str, '1116h8cQN');
assert.bufferEqual(base58.decode(str), buf);

for (const [hex, b58] of base58Tests) {
const data = Buffer.from(hex, 'hex');
assert.strictEqual(base58.encode(data), b58);
assert.bufferEqual(base58.decode(b58), data);
}
});

it('should convert satoshi to btc', () => {
assert.strictEqual(Amount.btc(5460), '0.0000546');
assert.strictEqual(Amount.btc(54678 * 1000000), '546.78');
Expand Down

0 comments on commit 1a87b9f

Please sign in to comment.