crypto: start using hash.digest().
This commit is contained in:
parent
8332b93721
commit
f9eba3f5a6
@ -2,7 +2,7 @@
|
||||
|
||||
const ChaCha20 = require('bcrypto/lib/chacha20');
|
||||
const Poly1305 = require('bcrypto/lib/poly1305');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const hash256 = require('bcrypto/lib/hash256');
|
||||
const bench = require('./bench');
|
||||
|
||||
console.log('note: rate measured in kb/s');
|
||||
@ -51,6 +51,6 @@ poly.init(key);
|
||||
{
|
||||
const end = bench('sha256');
|
||||
for (let i = 0; i < 1000000; i++)
|
||||
digest.hash256(data);
|
||||
hash256.digest(data);
|
||||
end(1000000 * 32 / 1024);
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
const assert = require('assert');
|
||||
const EventEmitter = require('events');
|
||||
const bsock = require('bsock');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const hash256 = require('bcrypto/lib/hash256');
|
||||
const BufferWriter = require('bbuf/lib/writer');
|
||||
|
||||
function ProxySocket(uri) {
|
||||
@ -133,7 +133,7 @@ ProxySocket.prototype.connect = function connect(port, host) {
|
||||
nonce++;
|
||||
assert(nonce <= 0xffffffff, 'Could not create socket.');
|
||||
pow.writeUInt32LE(nonce, 0, true);
|
||||
} while (digest.hash256(pow).compare(this.target) > 0);
|
||||
} while (hash256.digest(pow).compare(this.target) > 0);
|
||||
|
||||
console.log('Solved proof of work: %d', nonce);
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ const assert = require('assert');
|
||||
const net = require('net');
|
||||
const EventEmitter = require('events');
|
||||
const bsock = require('bsock');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const hash256 = require('bcrypto/lib/hash256');
|
||||
const IP = require('binet');
|
||||
const BufferWriter = require('bbuf/lib/writer');
|
||||
|
||||
@ -100,7 +100,7 @@ WSProxy.prototype.handleConnect = function handleConnect(ws, port, host, nonce)
|
||||
|
||||
const pow = bw.render();
|
||||
|
||||
if (digest.hash256(pow).compare(this.target) > 0) {
|
||||
if (hash256.digest(pow).compare(this.target) > 0) {
|
||||
this.log('Client did not solve proof of work (%s).', state.host);
|
||||
ws.fire('tcp close');
|
||||
ws.destroy();
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
const assert = require('assert');
|
||||
const BN = require('bcrypto/lib/bn');
|
||||
const consensus = require('../protocol/consensus');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const hash256 = require('bcrypto/lib/hash256');
|
||||
const encoding = require('bbuf/lib/encoding');
|
||||
const BufferReader = require('bbuf/lib/reader');
|
||||
const StaticWriter = require('bbuf/lib/staticwriter');
|
||||
@ -241,7 +241,7 @@ ChainEntry.prototype.toRaw = function toRaw() {
|
||||
|
||||
ChainEntry.prototype.fromRaw = function fromRaw(data) {
|
||||
const br = new BufferReader(data, true);
|
||||
const hash = digest.hash256(br.readBytes(80));
|
||||
const hash = hash256.digest(br.readBytes(80));
|
||||
|
||||
br.seek(-80);
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const sha256 = require('bcrypto/lib/sha256');
|
||||
const cleanse = require('bcrypto/lib/cleanse');
|
||||
const random = require('bcrypto/lib/random');
|
||||
const pbkdf2 = require('bcrypto/lib/pbkdf2');
|
||||
@ -189,7 +189,7 @@ Mnemonic.prototype.getPhrase = function getPhrase() {
|
||||
|
||||
// Get entropy and checksum.
|
||||
const entropy = this.getEntropy();
|
||||
const chk = digest.sha256(entropy);
|
||||
const chk = sha256.digest(entropy);
|
||||
|
||||
// Append the hash to the entropy to
|
||||
// make things easy when grabbing
|
||||
@ -276,7 +276,7 @@ Mnemonic.prototype.fromPhrase = function fromPhrase(phrase) {
|
||||
const cbytes = Math.ceil(cbits / 8);
|
||||
const entropy = data.slice(0, data.length - cbytes);
|
||||
const chk1 = data.slice(data.length - cbytes);
|
||||
const chk2 = digest.sha256(entropy);
|
||||
const chk2 = sha256.digest(entropy);
|
||||
|
||||
// Verify checksum.
|
||||
for (let i = 0; i < cbits; i++) {
|
||||
|
||||
@ -7,15 +7,17 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const sha512 = require('bcrypto/lib/sha512');
|
||||
const hash160 = require('bcrypto/lib/hash160');
|
||||
const hash256 = require('bcrypto/lib/hash256');
|
||||
const cleanse = require('bcrypto/lib/cleanse');
|
||||
const random = require('bcrypto/lib/random');
|
||||
const secp256k1 = require('bcrypto/lib/secp256k1');
|
||||
const Network = require('../protocol/network');
|
||||
const StaticWriter = require('bbuf/lib/staticwriter');
|
||||
const BufferReader = require('bbuf/lib/reader');
|
||||
const base58 = require('bstr/lib/base58');
|
||||
const encoding = require('bbuf/lib/encoding');
|
||||
const base58 = require('bstr/lib/base58');
|
||||
const Network = require('../protocol/network');
|
||||
const common = require('./common');
|
||||
const Mnemonic = require('./mnemonic');
|
||||
const HDPublicKey = require('./public');
|
||||
@ -199,7 +201,7 @@ HDPrivateKey.prototype.derive = function derive(index, hardened) {
|
||||
|
||||
const data = bw.render();
|
||||
|
||||
const hash = digest.hmac('sha512', data, this.chainCode);
|
||||
const hash = sha512.mac(data, this.chainCode);
|
||||
const left = hash.slice(0, 32);
|
||||
const right = hash.slice(32, 64);
|
||||
|
||||
@ -211,7 +213,7 @@ HDPrivateKey.prototype.derive = function derive(index, hardened) {
|
||||
}
|
||||
|
||||
if (this.fingerPrint === -1) {
|
||||
const fp = digest.hash160(this.publicKey);
|
||||
const fp = hash160.digest(this.publicKey);
|
||||
this.fingerPrint = fp.readUInt32BE(0, true);
|
||||
}
|
||||
|
||||
@ -426,7 +428,7 @@ HDPrivateKey.prototype.fromSeed = function fromSeed(seed) {
|
||||
throw new Error('Entropy not in range.');
|
||||
}
|
||||
|
||||
const hash = digest.hmac('sha512', seed, SEED_SALT);
|
||||
const hash = sha512.mac(seed, SEED_SALT);
|
||||
const left = hash.slice(0, 32);
|
||||
const right = hash.slice(32, 64);
|
||||
|
||||
@ -570,7 +572,7 @@ HDPrivateKey.prototype.fromReader = function fromReader(br, network) {
|
||||
this.privateKey = br.readBytes(32);
|
||||
this.publicKey = secp256k1.publicKeyCreate(this.privateKey, true);
|
||||
|
||||
br.verifyChecksum(digest.hash256);
|
||||
br.verifyChecksum(hash256.digest);
|
||||
|
||||
return this;
|
||||
};
|
||||
@ -621,7 +623,7 @@ HDPrivateKey.prototype.toWriter = function toWriter(bw, network) {
|
||||
bw.writeBytes(this.chainCode);
|
||||
bw.writeU8(0);
|
||||
bw.writeBytes(this.privateKey);
|
||||
bw.writeChecksum(digest.hash256);
|
||||
bw.writeChecksum(hash256.digest);
|
||||
|
||||
return bw;
|
||||
};
|
||||
|
||||
@ -7,7 +7,9 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const sha512 = require('bcrypto/lib/sha512');
|
||||
const hash160 = require('bcrypto/lib/hash160');
|
||||
const hash256 = require('bcrypto/lib/hash256');
|
||||
const cleanse = require('bcrypto/lib/cleanse');
|
||||
const secp256k1 = require('bcrypto/lib/secp256k1');
|
||||
const Network = require('../protocol/network');
|
||||
@ -160,7 +162,7 @@ HDPublicKey.prototype.derive = function derive(index, hardened) {
|
||||
|
||||
const data = bw.render();
|
||||
|
||||
const hash = digest.hmac('sha512', data, this.chainCode);
|
||||
const hash = sha512.mac(data, this.chainCode);
|
||||
const left = hash.slice(0, 32);
|
||||
const right = hash.slice(32, 64);
|
||||
|
||||
@ -172,7 +174,7 @@ HDPublicKey.prototype.derive = function derive(index, hardened) {
|
||||
}
|
||||
|
||||
if (this.fingerPrint === -1) {
|
||||
const fp = digest.hash160(this.publicKey);
|
||||
const fp = hash160.digest(this.publicKey);
|
||||
this.fingerPrint = fp.readUInt32BE(0, true);
|
||||
}
|
||||
|
||||
@ -439,7 +441,7 @@ HDPublicKey.prototype.fromReader = function fromReader(br, network) {
|
||||
this.chainCode = br.readBytes(32);
|
||||
this.publicKey = br.readBytes(33);
|
||||
|
||||
br.verifyChecksum(digest.hash256);
|
||||
br.verifyChecksum(hash256.digest);
|
||||
|
||||
return this;
|
||||
};
|
||||
@ -480,7 +482,7 @@ HDPublicKey.prototype.toWriter = function toWriter(bw, network) {
|
||||
bw.writeU32BE(this.childIndex);
|
||||
bw.writeBytes(this.chainCode);
|
||||
bw.writeBytes(this.publicKey);
|
||||
bw.writeChecksum(digest.hash256);
|
||||
bw.writeChecksum(hash256.digest);
|
||||
|
||||
return bw;
|
||||
};
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const hash256 = require('bcrypto/lib/hash256');
|
||||
|
||||
/**
|
||||
* Hash until the nonce overflows.
|
||||
@ -27,11 +27,11 @@ function mine(data, target, min, max) {
|
||||
// The heart and soul of the miner: match the target.
|
||||
while (nonce <= max) {
|
||||
// Hash and test against the next target.
|
||||
if (rcmp(digest.hash256(data), target) <= 0)
|
||||
if (rcmp(hash256.digest(data), target) <= 0)
|
||||
return nonce;
|
||||
|
||||
// Increment the nonce to get a different hash.
|
||||
nonce++;
|
||||
nonce += 1;
|
||||
|
||||
// Update the raw buffer.
|
||||
data.writeUInt32LE(nonce, 76, true);
|
||||
|
||||
@ -15,7 +15,7 @@ const BufferReader = require('bbuf/lib/reader');
|
||||
const StaticWriter = require('bbuf/lib/staticwriter');
|
||||
const encoding = require('bbuf/lib/encoding');
|
||||
const consensus = require('../protocol/consensus');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const sha256 = require('bcrypto/lib/sha256');
|
||||
const siphash256 = require('bcrypto/lib/siphash').siphash256;
|
||||
const AbstractBlock = require('../primitives/abstractblock');
|
||||
const TX = require('../primitives/tx');
|
||||
@ -392,7 +392,7 @@ CompactBlock.prototype.hasIndex = function hasIndex(index) {
|
||||
|
||||
CompactBlock.prototype.getKey = function getKey() {
|
||||
const data = Buffer.concat([this.toHead(), this.keyNonce]);
|
||||
const hash = digest.sha256(data);
|
||||
const hash = sha256.digest(data);
|
||||
return hash.slice(0, 16);
|
||||
};
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
|
||||
const assert = require('assert');
|
||||
const Network = require('../protocol/network');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const hash256 = require('bcrypto/lib/hash256');
|
||||
|
||||
/**
|
||||
* Protocol packet framer
|
||||
@ -53,7 +53,7 @@ Framer.prototype.packet = function packet(cmd, payload, checksum) {
|
||||
msg.writeUInt32LE(payload.length, 16, true);
|
||||
|
||||
if (!checksum)
|
||||
checksum = digest.hash256(payload);
|
||||
checksum = hash256.digest(payload);
|
||||
|
||||
// Checksum
|
||||
checksum.copy(msg, 20, 0, 4);
|
||||
|
||||
@ -13,7 +13,7 @@ const assert = require('assert');
|
||||
const EventEmitter = require('events');
|
||||
const {format} = require('util');
|
||||
const Network = require('../protocol/network');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const hash256 = require('bcrypto/lib/hash256');
|
||||
const common = require('./common');
|
||||
const packets = require('./packets');
|
||||
|
||||
@ -95,7 +95,8 @@ Parser.prototype.parse = function parse(data) {
|
||||
return;
|
||||
}
|
||||
|
||||
const checksum = digest.hash256(data).readUInt32LE(0, true);
|
||||
const hash = hash256.digest(data);
|
||||
const checksum = hash.readUInt32LE(0, true);
|
||||
|
||||
if (checksum !== this.header.checksum) {
|
||||
this.waiting = 24;
|
||||
|
||||
@ -10,17 +10,17 @@
|
||||
const assert = require('assert');
|
||||
const path = require('path');
|
||||
const {Server} = require('bweb');
|
||||
const util = require('../utils/util');
|
||||
const base58 = require('bstr/lib/base58');
|
||||
const BloomFilter = require('bfilter/lib/bloom');
|
||||
const TX = require('../primitives/tx');
|
||||
const Outpoint = require('../primitives/outpoint');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const sha256 = require('bcrypto/lib/sha256');
|
||||
const random = require('bcrypto/lib/random');
|
||||
const ccmp = require('bcrypto/lib/ccmp');
|
||||
const Network = require('../protocol/network');
|
||||
const Validator = require('bval/lib/validator');
|
||||
const encoding = require('bbuf/lib/encoding');
|
||||
const base58 = require('bstr/lib/base58');
|
||||
const BloomFilter = require('bfilter/lib/bloom');
|
||||
const Validator = require('bval/lib/validator');
|
||||
const util = require('../utils/util');
|
||||
const TX = require('../primitives/tx');
|
||||
const Outpoint = require('../primitives/outpoint');
|
||||
const Network = require('../protocol/network');
|
||||
const pkg = require('../pkg');
|
||||
|
||||
class HTTP extends Server {
|
||||
@ -84,6 +84,7 @@ class HTTP extends Server {
|
||||
|
||||
if (!this.options.noAuth) {
|
||||
this.use(this.basicAuth({
|
||||
hash: sha256.digest,
|
||||
password: this.options.apiKey,
|
||||
realm: 'node'
|
||||
}));
|
||||
@ -110,6 +111,7 @@ class HTTP extends Server {
|
||||
this.get('/', async (req, res) => {
|
||||
const totalTX = this.mempool ? this.mempool.map.size : 0;
|
||||
const size = this.mempool ? this.mempool.getSize() : 0;
|
||||
|
||||
let addr = this.pool.hosts.getLocal();
|
||||
|
||||
if (!addr)
|
||||
@ -359,7 +361,7 @@ class HTTP extends Server {
|
||||
throw new Error('Invalid API key.');
|
||||
|
||||
const data = Buffer.from(key, 'ascii');
|
||||
const hash = digest.hash256(data);
|
||||
const hash = sha256.digest(data);
|
||||
|
||||
if (!ccmp(hash, this.options.apiHash))
|
||||
throw new Error('Invalid API key.');
|
||||
@ -675,7 +677,7 @@ class HTTPOptions {
|
||||
this.logger = null;
|
||||
this.node = null;
|
||||
this.apiKey = base58.encode(random.randomBytes(20));
|
||||
this.apiHash = digest.hash256(Buffer.from(this.apiKey, 'ascii'));
|
||||
this.apiHash = sha256.digest(Buffer.from(this.apiKey, 'ascii'));
|
||||
this.noAuth = false;
|
||||
|
||||
this.prefix = null;
|
||||
@ -717,7 +719,7 @@ class HTTPOptions {
|
||||
assert(options.apiKey.length <= 255,
|
||||
'API key must be under 256 bytes.');
|
||||
this.apiKey = options.apiKey;
|
||||
this.apiHash = digest.hash256(Buffer.from(this.apiKey, 'ascii'));
|
||||
this.apiHash = sha256.digest(Buffer.from(this.apiKey, 'ascii'));
|
||||
}
|
||||
|
||||
if (options.noAuth != null) {
|
||||
|
||||
@ -9,7 +9,8 @@
|
||||
const assert = require('assert');
|
||||
const bweb = require('bweb');
|
||||
const util = require('../utils/util');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const hash160 = require('bcrypto/lib/hash160');
|
||||
const hash256 = require('bcrypto/lib/hash256');
|
||||
const ccmp = require('bcrypto/lib/ccmp');
|
||||
const common = require('../blockchain/common');
|
||||
const secp256k1 = require('bcrypto/lib/secp256k1');
|
||||
@ -2103,14 +2104,14 @@ class RPC extends RPCBase {
|
||||
|
||||
const addr = parseAddress(b58, this.network);
|
||||
const msg = Buffer.from(MAGIC_STRING + str, 'utf8');
|
||||
const hash = digest.hash256(msg);
|
||||
const hash = hash256.digest(msg);
|
||||
|
||||
const key = secp256k1.recover(hash, sig, 0, true);
|
||||
|
||||
if (!key)
|
||||
return false;
|
||||
|
||||
return ccmp(digest.hash160(key), addr.hash);
|
||||
return ccmp(hash160.digest(key), addr.hash);
|
||||
}
|
||||
|
||||
async signMessageWithPrivkey(args, help) {
|
||||
@ -2125,7 +2126,7 @@ class RPC extends RPCBase {
|
||||
|
||||
const key = parseSecret(wif, this.network);
|
||||
const msg = Buffer.from(MAGIC_STRING + str, 'utf8');
|
||||
const hash = digest.hash256(msg);
|
||||
const hash = hash256.digest(msg);
|
||||
const sig = key.sign(hash);
|
||||
|
||||
return sig.toString('base64');
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const hash256 = require('bcrypto/lib/hash256');
|
||||
const BufferReader = require('bbuf/lib/reader');
|
||||
const StaticWriter = require('bbuf/lib/staticwriter');
|
||||
const InvItem = require('./invitem');
|
||||
@ -137,7 +137,7 @@ AbstractBlock.prototype.hash = function hash(enc) {
|
||||
let h = this._hash;
|
||||
|
||||
if (!h) {
|
||||
h = digest.hash256(this.toHead());
|
||||
h = hash256.digest(this.toHead());
|
||||
if (!this.mutable)
|
||||
this._hash = h;
|
||||
}
|
||||
|
||||
@ -10,7 +10,9 @@
|
||||
const assert = require('assert');
|
||||
const Network = require('../protocol/network');
|
||||
const encoding = require('bbuf/lib/encoding');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const sha256 = require('bcrypto/lib/sha256');
|
||||
const hash160 = require('bcrypto/lib/hash160');
|
||||
const hash256 = require('bcrypto/lib/hash256');
|
||||
const BufferReader = require('bbuf/lib/reader');
|
||||
const StaticWriter = require('bbuf/lib/staticwriter');
|
||||
const base58 = require('bstr/lib/base58');
|
||||
@ -205,7 +207,7 @@ Address.prototype.toRaw = function toRaw(network) {
|
||||
}
|
||||
|
||||
bw.writeBytes(this.hash);
|
||||
bw.writeChecksum(digest.hash256);
|
||||
bw.writeChecksum(hash256.digest);
|
||||
|
||||
return bw.render();
|
||||
};
|
||||
@ -335,7 +337,7 @@ Address.prototype.fromRaw = function fromRaw(data, network) {
|
||||
|
||||
const hash = br.readBytes(br.left() - 4);
|
||||
|
||||
br.verifyChecksum(digest.hash256);
|
||||
br.verifyChecksum(hash256.digest);
|
||||
|
||||
return this.fromHash(hash, type, version);
|
||||
};
|
||||
@ -422,7 +424,7 @@ Address.prototype.fromScript = function fromScript(script) {
|
||||
const pk = script.getPubkey();
|
||||
|
||||
if (pk) {
|
||||
this.hash = digest.hash160(pk);
|
||||
this.hash = hash160.digest(pk);
|
||||
this.type = Address.types.PUBKEYHASH;
|
||||
this.version = -1;
|
||||
return this;
|
||||
@ -478,7 +480,7 @@ Address.prototype.fromWitness = function fromWitness(witness) {
|
||||
// We're pretty much screwed here
|
||||
// since we can't get the version.
|
||||
if (pk) {
|
||||
this.hash = digest.hash160(pk);
|
||||
this.hash = hash160.digest(pk);
|
||||
this.type = Address.types.WITNESS;
|
||||
this.version = 0;
|
||||
return this;
|
||||
@ -487,7 +489,7 @@ Address.prototype.fromWitness = function fromWitness(witness) {
|
||||
const redeem = witness.getScripthashInput();
|
||||
|
||||
if (redeem) {
|
||||
this.hash = digest.sha256(redeem);
|
||||
this.hash = sha256.digest(redeem);
|
||||
this.type = Address.types.WITNESS;
|
||||
this.version = 0;
|
||||
return this;
|
||||
@ -506,7 +508,7 @@ Address.prototype.fromInputScript = function fromInputScript(script) {
|
||||
const [, pk] = script.getPubkeyhashInput();
|
||||
|
||||
if (pk) {
|
||||
this.hash = digest.hash160(pk);
|
||||
this.hash = hash160.digest(pk);
|
||||
this.type = Address.types.PUBKEYHASH;
|
||||
this.version = -1;
|
||||
return this;
|
||||
@ -515,7 +517,7 @@ Address.prototype.fromInputScript = function fromInputScript(script) {
|
||||
const redeem = script.getScripthashInput();
|
||||
|
||||
if (redeem) {
|
||||
this.hash = digest.hash160(redeem);
|
||||
this.hash = hash160.digest(redeem);
|
||||
this.type = Address.types.SCRIPTHASH;
|
||||
this.version = -1;
|
||||
return this;
|
||||
|
||||
@ -9,7 +9,8 @@
|
||||
|
||||
const assert = require('assert');
|
||||
const encoding = require('bbuf/lib/encoding');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const hash160 = require('bcrypto/lib/hash160');
|
||||
const hash256 = require('bcrypto/lib/hash256');
|
||||
const Network = require('../protocol/network');
|
||||
const BufferReader = require('bbuf/lib/reader');
|
||||
const StaticWriter = require('bbuf/lib/staticwriter');
|
||||
@ -281,7 +282,7 @@ KeyRing.prototype.toSecret = function toSecret(network) {
|
||||
if (this.publicKey.length === 33)
|
||||
bw.writeU8(1);
|
||||
|
||||
bw.writeChecksum(digest.hash256);
|
||||
bw.writeChecksum(hash256.digest);
|
||||
|
||||
return base58.encode(bw.render());
|
||||
};
|
||||
@ -309,7 +310,7 @@ KeyRing.prototype.fromSecret = function fromSecret(data, network) {
|
||||
compress = true;
|
||||
}
|
||||
|
||||
br.verifyChecksum(digest.hash256);
|
||||
br.verifyChecksum(hash256.digest);
|
||||
|
||||
return this.fromPrivate(key, compress);
|
||||
};
|
||||
@ -381,7 +382,7 @@ KeyRing.prototype.getProgram = function getProgram() {
|
||||
if (!this._program) {
|
||||
let program;
|
||||
if (!this.script) {
|
||||
const hash = digest.hash160(this.publicKey);
|
||||
const hash = hash160.digest(this.publicKey);
|
||||
program = Script.fromProgram(0, hash);
|
||||
} else {
|
||||
const hash = this.script.sha256();
|
||||
@ -524,7 +525,7 @@ KeyRing.prototype.getScriptAddress = function getScriptAddress(enc, network) {
|
||||
|
||||
KeyRing.prototype.getKeyHash = function getKeyHash(enc) {
|
||||
if (!this._keyHash)
|
||||
this._keyHash = digest.hash160(this.publicKey);
|
||||
this._keyHash = hash160.digest(this.publicKey);
|
||||
|
||||
return enc === 'hex'
|
||||
? this._keyHash.toString('hex')
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const hash256 = require('bcrypto/lib/hash256');
|
||||
const secp256k1 = require('bcrypto/lib/secp256k1');
|
||||
const util = require('../utils/util');
|
||||
const encoding = require('bbuf/lib/encoding');
|
||||
@ -176,7 +176,7 @@ TX.prototype.hash = function hash(enc) {
|
||||
let h = this._hash;
|
||||
|
||||
if (!h) {
|
||||
h = digest.hash256(this.toNormal());
|
||||
h = hash256.digest(this.toNormal());
|
||||
if (!this.mutable)
|
||||
this._hash = h;
|
||||
}
|
||||
@ -210,7 +210,7 @@ TX.prototype.witnessHash = function witnessHash(enc) {
|
||||
let hash = this._whash;
|
||||
|
||||
if (!hash) {
|
||||
hash = digest.hash256(this.toRaw());
|
||||
hash = hash256.digest(this.toRaw());
|
||||
if (!this.mutable)
|
||||
this._whash = hash;
|
||||
}
|
||||
@ -546,7 +546,7 @@ TX.prototype.signatureHashV0 = function signatureHashV0(index, prev, type) {
|
||||
// Append the hash type.
|
||||
bw.writeU32(type);
|
||||
|
||||
return digest.hash256(bw.render());
|
||||
return hash256.digest(bw.render());
|
||||
};
|
||||
|
||||
/**
|
||||
@ -622,7 +622,7 @@ TX.prototype.signatureHashV1 = function signatureHashV1(index, prev, value, type
|
||||
for (const input of this.inputs)
|
||||
input.prevout.toWriter(bw);
|
||||
|
||||
prevouts = digest.hash256(bw.render());
|
||||
prevouts = hash256.digest(bw.render());
|
||||
|
||||
if (!this.mutable)
|
||||
this._hashPrevouts = prevouts;
|
||||
@ -640,7 +640,7 @@ TX.prototype.signatureHashV1 = function signatureHashV1(index, prev, value, type
|
||||
for (const input of this.inputs)
|
||||
bw.writeU32(input.sequence);
|
||||
|
||||
sequences = digest.hash256(bw.render());
|
||||
sequences = hash256.digest(bw.render());
|
||||
|
||||
if (!this.mutable)
|
||||
this._hashSequence = sequences;
|
||||
@ -662,7 +662,7 @@ TX.prototype.signatureHashV1 = function signatureHashV1(index, prev, value, type
|
||||
for (const output of this.outputs)
|
||||
output.toWriter(bw);
|
||||
|
||||
outputs = digest.hash256(bw.render());
|
||||
outputs = hash256.digest(bw.render());
|
||||
|
||||
if (!this.mutable)
|
||||
this._hashOutputs = outputs;
|
||||
@ -670,7 +670,7 @@ TX.prototype.signatureHashV1 = function signatureHashV1(index, prev, value, type
|
||||
} else if ((type & 0x1f) === hashType.SINGLE) {
|
||||
if (index < this.outputs.length) {
|
||||
const output = this.outputs[index];
|
||||
outputs = digest.hash256(output.toRaw());
|
||||
outputs = hash256.digest(output.toRaw());
|
||||
}
|
||||
}
|
||||
|
||||
@ -689,7 +689,7 @@ TX.prototype.signatureHashV1 = function signatureHashV1(index, prev, value, type
|
||||
bw.writeU32(this.locktime);
|
||||
bw.writeU32(type);
|
||||
|
||||
return digest.hash256(bw.render());
|
||||
return hash256.digest(bw.render());
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -8,7 +8,11 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const ripemd160 = require('bcrypto/lib/ripemd160');
|
||||
const sha1 = require('bcrypto/lib/sha1');
|
||||
const sha256 = require('bcrypto/lib/sha256');
|
||||
const hash160 = require('bcrypto/lib/hash160');
|
||||
const hash256 = require('bcrypto/lib/hash256');
|
||||
const merkle = require('bcrypto/lib/merkle');
|
||||
const secp256k1 = require('bcrypto/lib/secp256k1');
|
||||
const consensus = require('../protocol/consensus');
|
||||
@ -26,6 +30,8 @@ const encoding = require('bbuf/lib/encoding');
|
||||
const Address = require('../primitives/address');
|
||||
const opcodes = common.opcodes;
|
||||
const scriptTypes = common.types;
|
||||
const Hash160 = hash160;
|
||||
const Sha256 = sha256;
|
||||
const EMPTY_BUFFER = Buffer.alloc(0);
|
||||
|
||||
/**
|
||||
@ -1111,35 +1117,35 @@ Script.prototype.execute = function execute(stack, flags, tx, index, value, vers
|
||||
if (stack.length === 0)
|
||||
throw new ScriptError('INVALID_STACK_OPERATION', op, ip);
|
||||
|
||||
stack.push(digest.ripemd160(stack.pop()));
|
||||
stack.push(ripemd160.digest(stack.pop()));
|
||||
break;
|
||||
}
|
||||
case opcodes.OP_SHA1: {
|
||||
if (stack.length === 0)
|
||||
throw new ScriptError('INVALID_STACK_OPERATION', op, ip);
|
||||
|
||||
stack.push(digest.sha1(stack.pop()));
|
||||
stack.push(sha1.digest(stack.pop()));
|
||||
break;
|
||||
}
|
||||
case opcodes.OP_SHA256: {
|
||||
if (stack.length === 0)
|
||||
throw new ScriptError('INVALID_STACK_OPERATION', op, ip);
|
||||
|
||||
stack.push(digest.sha256(stack.pop()));
|
||||
stack.push(sha256.digest(stack.pop()));
|
||||
break;
|
||||
}
|
||||
case opcodes.OP_HASH160: {
|
||||
if (stack.length === 0)
|
||||
throw new ScriptError('INVALID_STACK_OPERATION', op, ip);
|
||||
|
||||
stack.push(digest.hash160(stack.pop()));
|
||||
stack.push(hash160.digest(stack.pop()));
|
||||
break;
|
||||
}
|
||||
case opcodes.OP_HASH256: {
|
||||
if (stack.length === 0)
|
||||
throw new ScriptError('INVALID_STACK_OPERATION', op, ip);
|
||||
|
||||
stack.push(digest.hash256(stack.pop()));
|
||||
stack.push(hash256.digest(stack.pop()));
|
||||
break;
|
||||
}
|
||||
case opcodes.OP_CODESEPARATOR: {
|
||||
@ -1847,7 +1853,7 @@ Script.prototype.getAddress = function getAddress() {
|
||||
*/
|
||||
|
||||
Script.prototype.hash160 = function hash160(enc) {
|
||||
let hash = digest.hash160(this.toRaw());
|
||||
let hash = Hash160.digest(this.toRaw());
|
||||
if (enc === 'hex')
|
||||
hash = hash.toString('hex');
|
||||
return hash;
|
||||
@ -1860,7 +1866,7 @@ Script.prototype.hash160 = function hash160(enc) {
|
||||
*/
|
||||
|
||||
Script.prototype.sha256 = function sha256(enc) {
|
||||
let hash = digest.sha256(this.toRaw());
|
||||
let hash = Sha256.digest(this.toRaw());
|
||||
if (enc === 'hex')
|
||||
hash = hash.toString('hex');
|
||||
return hash;
|
||||
@ -2158,7 +2164,7 @@ Script.prototype.forWitness = function forWitness() {
|
||||
|
||||
const pk = this.getPubkey();
|
||||
if (pk) {
|
||||
const hash = digest.hash160(pk);
|
||||
const hash = hash160.digest(pk);
|
||||
return Script.fromProgram(0, hash);
|
||||
}
|
||||
|
||||
@ -3273,7 +3279,7 @@ Script.verifyProgram = function verifyProgram(witness, output, flags, tx, index,
|
||||
|
||||
const witnessScript = stack.pop();
|
||||
|
||||
if (!digest.sha256(witnessScript).equals(program.data))
|
||||
if (!sha256.digest(witnessScript).equals(program.data))
|
||||
throw new ScriptError('WITNESS_PROGRAM_MISMATCH');
|
||||
|
||||
redeem = Script.fromRaw(witnessScript);
|
||||
@ -3418,15 +3424,15 @@ Script.verifyMast = function verifyMast(program, stack, output, flags, tx, index
|
||||
if ((scripts.offset + script.length) > consensus.MAX_SCRIPT_SIZE)
|
||||
throw new ScriptError('SCRIPT_SIZE');
|
||||
}
|
||||
scriptRoot.writeBytes(digest.hash256(script));
|
||||
scriptRoot.writeBytes(hash256.digest(script));
|
||||
scripts.writeBytes(script);
|
||||
}
|
||||
|
||||
scriptRoot = digest.hash256(scriptRoot.render());
|
||||
scriptRoot = hash256.digest(scriptRoot.render());
|
||||
scriptRoot = merkle.verifyBranch(scriptRoot, path, pos);
|
||||
|
||||
mastRoot.writeBytes(scriptRoot);
|
||||
mastRoot = digest.hash256(mastRoot.render());
|
||||
mastRoot = hash256.digest(mastRoot.render());
|
||||
|
||||
if (!mastRoot.equals(program.data))
|
||||
throw new ScriptError('WITNESS_PROGRAM_MISMATCH');
|
||||
|
||||
@ -14,7 +14,7 @@ const base58 = require('bstr/lib/base58');
|
||||
const MTX = require('../primitives/mtx');
|
||||
const Outpoint = require('../primitives/outpoint');
|
||||
const Script = require('../script/script');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const sha256 = require('bcrypto/lib/sha256');
|
||||
const random = require('bcrypto/lib/random');
|
||||
const ccmp = require('bcrypto/lib/ccmp');
|
||||
const Network = require('../protocol/network');
|
||||
@ -81,6 +81,7 @@ class HTTP extends Server {
|
||||
|
||||
if (!this.options.noAuth) {
|
||||
this.use(this.basicAuth({
|
||||
hash: sha256.digest,
|
||||
password: this.options.apiKey,
|
||||
realm: 'wallet'
|
||||
}));
|
||||
@ -895,7 +896,7 @@ class HTTP extends Server {
|
||||
throw new Error('Invalid API key.');
|
||||
|
||||
const data = Buffer.from(key, 'utf8');
|
||||
const hash = digest.hash256(data);
|
||||
const hash = sha256.digest(data);
|
||||
|
||||
if (!ccmp(hash, this.options.apiHash))
|
||||
throw new Error('Invalid API key.');
|
||||
@ -979,7 +980,7 @@ class HTTPOptions {
|
||||
this.logger = null;
|
||||
this.node = null;
|
||||
this.apiKey = base58.encode(random.randomBytes(20));
|
||||
this.apiHash = digest.hash256(Buffer.from(this.apiKey, 'ascii'));
|
||||
this.apiHash = sha256.digest(Buffer.from(this.apiKey, 'ascii'));
|
||||
this.serviceHash = this.apiHash;
|
||||
this.noAuth = false;
|
||||
this.walletAuth = false;
|
||||
@ -1022,7 +1023,7 @@ class HTTPOptions {
|
||||
assert(options.apiKey.length <= 255,
|
||||
'API key must be under 255 bytes.');
|
||||
this.apiKey = options.apiKey;
|
||||
this.apiHash = digest.hash256(Buffer.from(this.apiKey, 'ascii'));
|
||||
this.apiHash = sha256.digest(Buffer.from(this.apiKey, 'ascii'));
|
||||
}
|
||||
|
||||
if (options.noAuth != null) {
|
||||
|
||||
@ -11,7 +11,7 @@ const bweb = require('bweb');
|
||||
const fs = require('bfile');
|
||||
const {format} = require('util');
|
||||
const util = require('../utils/util');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const hash256 = require('bcrypto/lib/hash256');
|
||||
const Amount = require('../btc/amount');
|
||||
const Script = require('../script/script');
|
||||
const Address = require('../primitives/address');
|
||||
@ -1464,7 +1464,7 @@ class RPC extends RPCBase {
|
||||
throw new RPCError(errs.WALLET_UNLOCK_NEEDED, 'Wallet is locked.');
|
||||
|
||||
const msg = Buffer.from(MAGIC_STRING + str, 'utf8');
|
||||
const hash = digest.hash256(msg);
|
||||
const hash = hash256.digest(msg);
|
||||
|
||||
const sig = ring.sign(hash);
|
||||
|
||||
|
||||
@ -12,7 +12,8 @@ const EventEmitter = require('events');
|
||||
const Network = require('../protocol/network');
|
||||
const encoding = require('bbuf/lib/encoding');
|
||||
const Lock = require('../utils/lock');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const hash160 = require('bcrypto/lib/hash160');
|
||||
const hash256 = require('bcrypto/lib/hash256');
|
||||
const cleanse = require('bcrypto/lib/cleanse');
|
||||
const BufferReader = require('bbuf/lib/reader');
|
||||
const StaticWriter = require('bbuf/lib/staticwriter');
|
||||
@ -537,14 +538,14 @@ Wallet.prototype.getID = function getID() {
|
||||
bw.writeBytes(key.publicKey);
|
||||
bw.writeU32(this.network.magic);
|
||||
|
||||
const hash = digest.hash160(bw.render());
|
||||
const hash = hash160.digest(bw.render());
|
||||
|
||||
const b58 = new StaticWriter(27);
|
||||
b58.writeU8(0x03);
|
||||
b58.writeU8(0xbe);
|
||||
b58.writeU8(0x04);
|
||||
b58.writeBytes(hash);
|
||||
b58.writeChecksum(digest.hash256);
|
||||
b58.writeChecksum(hash256.digest);
|
||||
|
||||
return base58.encode(b58.render());
|
||||
};
|
||||
@ -568,7 +569,7 @@ Wallet.prototype.getToken = function getToken(nonce) {
|
||||
bw.writeBytes(key.privateKey);
|
||||
bw.writeU32(nonce);
|
||||
|
||||
return digest.hash256(bw.render());
|
||||
return hash256.digest(bw.render());
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -18,7 +18,7 @@ if (process.argv.indexOf('-h') !== -1
|
||||
const assert = require('assert');
|
||||
const BDB = require('bdb');
|
||||
const encoding = require('bbuf/lib/encoding');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const hash256 = require('bcrypto/lib/hash256');
|
||||
const BN = require('bcrypto/lib/bn');
|
||||
const StaticWriter = require('bbuf/lib/staticwriter');
|
||||
const BufferReader = require('bbuf/lib/reader');
|
||||
@ -578,7 +578,7 @@ async function isMainChain(entry, tip) {
|
||||
|
||||
function entryFromRaw(data) {
|
||||
const br = new BufferReader(data, true);
|
||||
const hash = digest.hash256(br.readBytes(80));
|
||||
const hash = hash256.digest(br.readBytes(80));
|
||||
|
||||
br.seek(-80);
|
||||
|
||||
|
||||
@ -4,7 +4,7 @@ const assert = require('assert');
|
||||
const BDB = require('bdb');
|
||||
const encoding = require('bbuf/lib/encoding');
|
||||
const BufferReader = require('bbuf/lib/reader');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const hash256 = require('bcrypto/lib/hash256');
|
||||
const BN = require('bcrypto/lib/bn');
|
||||
const DUMMY = Buffer.from([0]);
|
||||
|
||||
@ -40,7 +40,7 @@ async function checkVersion() {
|
||||
|
||||
function entryFromRaw(data) {
|
||||
const p = new BufferReader(data, true);
|
||||
const hash = digest.hash256(p.readBytes(80));
|
||||
const hash = hash256.digest(p.readBytes(80));
|
||||
const entry = {};
|
||||
|
||||
p.seek(-80);
|
||||
|
||||
@ -7,7 +7,7 @@ const assert = require('./util/assert');
|
||||
const consensus = require('../lib/protocol/consensus');
|
||||
const util = require('../lib/utils/util');
|
||||
const encoding = require('bbuf/lib/encoding');
|
||||
const digest = require('bcrypto/lib/digest');
|
||||
const hash256 = require('bcrypto/lib/hash256');
|
||||
const random = require('bcrypto/lib/random');
|
||||
const WalletDB = require('../lib/wallet/walletdb');
|
||||
const WorkerPool = require('../lib/workers/workerpool');
|
||||
@ -46,9 +46,9 @@ function nextBlock(wdb) {
|
||||
}
|
||||
|
||||
function fakeBlock(height) {
|
||||
const prev = digest.hash256(u32((height - 1) >>> 0));
|
||||
const hash = digest.hash256(u32(height >>> 0));
|
||||
const root = digest.hash256(u32((height | 0x80000000) >>> 0));
|
||||
const prev = hash256.digest(u32((height - 1) >>> 0));
|
||||
const hash = hash256.digest(u32(height >>> 0));
|
||||
const root = hash256.digest(u32((height | 0x80000000) >>> 0));
|
||||
|
||||
return {
|
||||
hash: hash.toString('hex'),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user