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