diff --git a/lib/hd/private.js b/lib/hd/private.js index 27f3a19d92..ad50a7cce8 100644 --- a/lib/hd/private.js +++ b/lib/hd/private.js @@ -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'); diff --git a/lib/hd/public.js b/lib/hd/public.js index 1bfd2fc3cd..2ab27a55cb 100644 --- a/lib/hd/public.js +++ b/lib/hd/public.js @@ -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'); diff --git a/lib/net/bip152.js b/lib/net/bip152.js index 76794aed23..3c9828efb6 100644 --- a/lib/net/bip152.js +++ b/lib/net/bip152.js @@ -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'); diff --git a/lib/net/hostlist.js b/lib/net/hostlist.js index ed31350356..41924826be 100644 --- a/lib/net/hostlist.js +++ b/lib/net/hostlist.js @@ -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'); diff --git a/lib/node/http.js b/lib/node/http.js index 01de675fb3..ef48ade122 100644 --- a/lib/node/http.js +++ b/lib/node/http.js @@ -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'); diff --git a/lib/primitives/address.js b/lib/primitives/address.js index 6bb618c736..a036d175d2 100644 --- a/lib/primitives/address.js +++ b/lib/primitives/address.js @@ -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'); @@ -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); } /** diff --git a/lib/primitives/keyring.js b/lib/primitives/keyring.js index de55880511..d766d51a79 100644 --- a/lib/primitives/keyring.js +++ b/lib/primitives/keyring.js @@ -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'); diff --git a/lib/utils/help.js b/lib/utils/help.js new file mode 100644 index 0000000000..2f333858e5 --- /dev/null +++ b/lib/utils/help.js @@ -0,0 +1,69 @@ +'use strict'; + +exports.formatTX = (tx) => { + let res = ` +TX: ${tx.txid().toString('hex')} + Outputs: ${tx.outputs.length} + Inputs: ${tx.inputs.length}\n`; + + for (const {prevout} of tx.inputs) + res += ` ${prevout.hash.toString('hex')}/${prevout.index}\n`; + + return res; +}; + +exports.logTX = function (tx) { + console.log(exports.formatTX(tx)); +}; + +exports.formatBlock = (block) => { + let res = ` +Block: ${block.hash().toString('hex')} +TXs: ${block.txs.length}\n`; + + for (const tx of block.txs) + res += ` ${tx.txid().toString('hex')}\n`; + + return res; +}; + +exports.logBlock = (block) => { + console.log(exports.formatBlock(block)); +}; + +exports.formatEntry = (entry, txs) => { + let res = `Entry: ${entry.hash.toString('hex')} +TXs: ${txs.length}\n`; + + for (const tx of txs) + res += ` ${tx.txid().toString('hex')}\n`; + + return res; +}; +exports.logEntry =(entry, txs) => { + console.log(exports.formatEntry(entry, txs)); +}; + +const lockedRegistry = new Map(); + +exports.hackLocker = (locker, name) => { + const _lock = locker.lock; + + locker.lock = async (...args) => { + const _unlock = await _lock.call(locker, ...args); + lockedRegistry.set(locker, name); + + return (...args) => { + lockedRegistry.delete(locker); + _unlock.call(...args); + }; + }; + + return locker; +}; + +exports.logLocks = () => { + const locks = Array.from(lockedRegistry.values()); + + console.log(locks.join(', ')); +}; diff --git a/lib/wallet/http.js b/lib/wallet/http.js index 0dc6232b08..4ff6dcc5a5 100644 --- a/lib/wallet/http.js +++ b/lib/wallet/http.js @@ -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'); diff --git a/lib/wallet/wallet.js b/lib/wallet/wallet.js index b424695354..c9ac424426 100644 --- a/lib/wallet/wallet.js +++ b/lib/wallet/wallet.js @@ -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'); diff --git a/package-lock.json b/package-lock.json index abdf2f0b07..8d8052f56f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,9 +23,9 @@ } }, "bcrypto": { - "version": "3.1.11", - "resolved": "https://registry.npmjs.org/bcrypto/-/bcrypto-3.1.11.tgz", - "integrity": "sha512-XHsle+v0aYjCyHZSwd3Insnu8GUe4cuf3+f07Z/mO+GLq60YqUyEIvpaSv4LAAJ4uf8UNYMSSQ0LslsV0r4tug==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/bcrypto/-/bcrypto-4.0.1.tgz", + "integrity": "sha512-aLH/BmVyasy9iQkrmQTg+9MRU+77zOpEBiBflaXFC4YQJNICG/NjkEEluinnvAOQWGiM4HsGcfrVFJNJQz8jxQ==", "requires": { "bsert": "~0.0.10", "bufio": "~1.0.6", @@ -159,16 +159,6 @@ "resolved": "https://registry.npmjs.org/bsert/-/bsert-0.0.10.tgz", "integrity": "sha512-NHNwlac+WPy4t2LoNh8pXk8uaIGH3NSaIUbTTRXGpE2WEbq0te/tDykYHkFK57YKLPjv/aGHmbqvnGeVWDz57Q==" }, - "bsip": { - "version": "0.1.9", - "resolved": "https://registry.npmjs.org/bsip/-/bsip-0.1.9.tgz", - "integrity": "sha512-i7cVEfCthASPB3BYKS/pZN/D4kh4vToIlSAFcVBLNjzYl1UirT3E2PIGSfNnYR2qZ3UW1qnDavrWEHhLeSKt2A==", - "requires": { - "bsert": "~0.0.10", - "loady": "~0.0.1", - "nan": "^2.13.1" - } - }, "bsock": { "version": "0.1.9", "resolved": "https://registry.npmjs.org/bsock/-/bsock-0.1.9.tgz", @@ -186,16 +176,6 @@ "bsert": "~0.0.10" } }, - "bstring": { - "version": "0.3.9", - "resolved": "https://registry.npmjs.org/bstring/-/bstring-0.3.9.tgz", - "integrity": "sha512-D95flI7SXL+UsQi9mW+hH+AK2AFfafIJi+3GbbyTAWMe2FqwR9keBxsjGiGd/JM+77Y9WsC+M4EhZVNVcym9jw==", - "requires": { - "bsert": "~0.0.10", - "loady": "~0.0.1", - "nan": "^2.13.1" - } - }, "btcp": { "version": "0.1.5", "resolved": "https://registry.npmjs.org/btcp/-/btcp-0.1.5.tgz", diff --git a/package.json b/package.json index c8f0f7b44e..26332f0f36 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": { diff --git a/test/hd-test.js b/test/hd-test.js index d92cf97a9b..b091253a6e 100644 --- a/test/hd-test.js +++ b/test/hd-test.js @@ -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'); diff --git a/test/utils-test.js b/test/utils-test.js index e01bb4c950..f3d6bedc42 100644 --- a/test/utils-test.js +++ b/test/utils-test.js @@ -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');