refactor: avoid using new Buffer() due to its new perf implications.
This commit is contained in:
parent
8763600e53
commit
28cd43045d
@ -11,7 +11,7 @@ var tx3 = parseTX('../test/data/tx3.hex');
|
||||
var wtx = fs.readFileSync(__dirname + '/../test/data/wtx.hex', 'utf8');
|
||||
var i, tx, end, raw;
|
||||
|
||||
wtx = new Buffer(wtx.trim(), 'hex');
|
||||
wtx = Buffer.from(wtx.trim(), 'hex');
|
||||
tx = TX.fromRaw(wtx);
|
||||
|
||||
function parseTX(file) {
|
||||
|
||||
@ -8,11 +8,11 @@ var i, chacha, iv, poly, key, data, end;
|
||||
console.log('note: rate measured in kb/s');
|
||||
|
||||
chacha = new chachapoly.ChaCha20();
|
||||
key = new Buffer(32);
|
||||
key = Buffer.allocUnsafe(32);
|
||||
key.fill(2);
|
||||
iv = new Buffer('0102030405060708', 'hex');
|
||||
iv = Buffer.from('0102030405060708', 'hex');
|
||||
chacha.init(key, iv, 0);
|
||||
data = new Buffer(32);
|
||||
data = Buffer.allocUnsafe(32);
|
||||
for (i = 0; i < 32; i++)
|
||||
data[i] = i;
|
||||
end = bench('encrypt');
|
||||
@ -21,11 +21,11 @@ for (i = 0; i < 1000000; i++)
|
||||
end(i * 32 / 1024);
|
||||
|
||||
poly = new chachapoly.Poly1305();
|
||||
key = new Buffer(32);
|
||||
key = Buffer.allocUnsafe(32);
|
||||
key.fill(2);
|
||||
poly.init(key);
|
||||
|
||||
data = new Buffer(32);
|
||||
data = Buffer.allocUnsafe(32);
|
||||
for (i = 0; i < 32; i++)
|
||||
data[i] = i & 0xff;
|
||||
|
||||
|
||||
@ -20,7 +20,7 @@ var tx3 = parseTX('../test/data/tx3.hex');
|
||||
var wtx = fs.readFileSync(__dirname + '/../test/data/wtx.hex', 'utf8');
|
||||
var i, tx, raw, end, flags, input;
|
||||
|
||||
wtx = new Buffer(wtx.trim(), 'hex');
|
||||
wtx = Buffer.from(wtx.trim(), 'hex');
|
||||
|
||||
tx = json.txs[397];
|
||||
for (i = 0; i < tx.inputs.length; i++) {
|
||||
@ -116,7 +116,7 @@ for (i = 0; i < 100; i++) {
|
||||
index: 0
|
||||
},
|
||||
script: [
|
||||
new Buffer(9),
|
||||
Buffer.allocUnsafe(9),
|
||||
crypto.randomBytes(33)
|
||||
]
|
||||
});
|
||||
|
||||
@ -31,13 +31,13 @@ function transformer(file, process) {
|
||||
stream._transform = function(chunk, encoding, callback) {
|
||||
assert(Buffer.isBuffer(chunk));
|
||||
str += decoder.write(chunk);
|
||||
callback(null, new Buffer(0));
|
||||
callback(null, Buffer.allocUnsafe(0));
|
||||
};
|
||||
|
||||
stream._flush = function(callback) {
|
||||
str = process(str);
|
||||
|
||||
stream.push(new Buffer(str, 'utf8'));
|
||||
stream.push(Buffer.from(str, 'utf8'));
|
||||
|
||||
callback();
|
||||
};
|
||||
|
||||
@ -10,7 +10,7 @@ var BufferWriter = require('../lib/utils/writer');
|
||||
|
||||
var NAME_REGEX = /^[a-z0-9\-\.]+?\.(?:be|me|org|com|net|ch|de)$/i;
|
||||
|
||||
var TARGET = new Buffer(
|
||||
var TARGET = Buffer.from(
|
||||
'0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
||||
'hex');
|
||||
|
||||
@ -185,7 +185,7 @@ WSProxy.prototype._handleConnect = function _handleConnect(ws, port, host, nonce
|
||||
ws.on('tcp data', function(data) {
|
||||
if (typeof data !== 'string')
|
||||
return;
|
||||
socket.write(new Buffer(data, 'hex'));
|
||||
socket.write(Buffer.from(data, 'hex'));
|
||||
});
|
||||
|
||||
ws.on('tcp keep alive', function(enable, delay) {
|
||||
|
||||
@ -145,7 +145,7 @@ Payment.prototype.fromRaw = function fromRaw(data) {
|
||||
|
||||
Payment.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new Payment().fromRaw(data);
|
||||
};
|
||||
|
||||
|
||||
@ -85,7 +85,7 @@ PaymentACK.prototype.fromRaw = function fromRaw(data) {
|
||||
|
||||
PaymentACK.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new PaymentACK().fromRaw(data);
|
||||
};
|
||||
|
||||
|
||||
@ -127,11 +127,11 @@ PaymentDetails.prototype.setData = function setData(data, enc) {
|
||||
|
||||
if (typeof data !== 'string') {
|
||||
assert(!enc || enc === 'json');
|
||||
this.merchantData = new Buffer(JSON.stringify(data), 'utf8');
|
||||
this.merchantData = Buffer.from(JSON.stringify(data), 'utf8');
|
||||
return;
|
||||
}
|
||||
|
||||
this.merchantData = new Buffer(data, enc);
|
||||
this.merchantData = Buffer.from(data, enc);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -200,7 +200,7 @@ PaymentDetails.prototype.fromRaw = function fromRaw(data) {
|
||||
|
||||
PaymentDetails.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new PaymentDetails().fromRaw(data);
|
||||
};
|
||||
|
||||
|
||||
@ -116,7 +116,7 @@ PaymentRequest.prototype.fromRaw = function fromRaw(data) {
|
||||
|
||||
PaymentRequest.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new PaymentRequest().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -179,7 +179,7 @@ PaymentRequest.prototype.signatureData = function signatureData() {
|
||||
var signature = this.signature;
|
||||
var data;
|
||||
|
||||
this.signature = new Buffer(0);
|
||||
this.signature = Buffer.alloc(0);
|
||||
|
||||
data = this.toRaw();
|
||||
|
||||
|
||||
@ -176,7 +176,7 @@ x509.setFingerprints = function setFingerprints(hashes) {
|
||||
hash = hashes[i];
|
||||
|
||||
if (typeof hash === 'string')
|
||||
hash = new Buffer(hash, 'hex');
|
||||
hash = Buffer.from(hash, 'hex');
|
||||
|
||||
assert(Buffer.isBuffer(hash), 'Fingerprint must be a buffer.');
|
||||
assert(hash.length === 32, 'Fingerprint must be a sha256 hash.');
|
||||
|
||||
@ -28,7 +28,7 @@ var ChainEntry = require('./chainentry');
|
||||
var TXMeta = require('../primitives/txmeta');
|
||||
var U8 = encoding.U8;
|
||||
var U32 = encoding.U32;
|
||||
var DUMMY = new Buffer([0]);
|
||||
var DUMMY = Buffer.from([0]);
|
||||
|
||||
/**
|
||||
* The database backend for the {@link Chain} object.
|
||||
@ -2137,7 +2137,7 @@ ChainState.prototype.spend = function spend(coin) {
|
||||
|
||||
ChainState.prototype.commit = function commit(hash) {
|
||||
if (typeof hash === 'string')
|
||||
hash = new Buffer(hash, 'hex');
|
||||
hash = Buffer.from(hash, 'hex');
|
||||
this.tip = hash;
|
||||
this.committed = true;
|
||||
return this.toRaw();
|
||||
|
||||
@ -29,9 +29,9 @@
|
||||
|
||||
var layout = {
|
||||
binary: true,
|
||||
R: new Buffer([0x52]),
|
||||
O: new Buffer([0x4f]),
|
||||
V: new Buffer([0x76]),
|
||||
R: Buffer.from([0x52]),
|
||||
O: Buffer.from([0x4f]),
|
||||
V: Buffer.from([0x76]),
|
||||
e: function e(hash) {
|
||||
return pair(0x65, hash);
|
||||
},
|
||||
@ -60,7 +60,7 @@ var layout = {
|
||||
return pair(0x75, hash);
|
||||
},
|
||||
v: function v(bit, hash) {
|
||||
var key = new Buffer(1 + 1 + 32);
|
||||
var key = Buffer.allocUnsafe(1 + 1 + 32);
|
||||
key[0] = 0x76;
|
||||
key[1] = bit;
|
||||
write(key, hash, 2);
|
||||
@ -77,12 +77,12 @@ var layout = {
|
||||
len /= 2;
|
||||
|
||||
if (len === 32) {
|
||||
key = new Buffer(65);
|
||||
key = Buffer.allocUnsafe(65);
|
||||
key[0] = 0xab; // W + T
|
||||
write(key, address, 1);
|
||||
write(key, hash, 33);
|
||||
} else {
|
||||
key = new Buffer(53);
|
||||
key = Buffer.allocUnsafe(53);
|
||||
key[0] = 0x54; // T
|
||||
write(key, address, 1);
|
||||
write(key, hash, 21);
|
||||
@ -98,13 +98,13 @@ var layout = {
|
||||
len /= 2;
|
||||
|
||||
if (len === 32) {
|
||||
key = new Buffer(69);
|
||||
key = Buffer.allocUnsafe(69);
|
||||
key[0] = 0x9a; // W + C
|
||||
write(key, address, 1);
|
||||
write(key, hash, 33);
|
||||
key.writeUInt32BE(index, 65, true);
|
||||
} else {
|
||||
key = new Buffer(57);
|
||||
key = Buffer.allocUnsafe(57);
|
||||
key[0] = 0x43; // C
|
||||
write(key, address, 1);
|
||||
write(key, hash, 21);
|
||||
@ -147,14 +147,14 @@ function write(data, str, off) {
|
||||
}
|
||||
|
||||
function pair(prefix, hash) {
|
||||
var key = new Buffer(33);
|
||||
var key = Buffer.allocUnsafe(33);
|
||||
key[0] = prefix;
|
||||
write(key, hash, 1);
|
||||
return key;
|
||||
}
|
||||
|
||||
function ipair(prefix, num) {
|
||||
var key = new Buffer(5);
|
||||
var key = Buffer.allocUnsafe(5);
|
||||
key[0] = prefix;
|
||||
key.writeUInt32BE(num, 1, true);
|
||||
return key;
|
||||
|
||||
@ -21,7 +21,7 @@ var consensus = require('../protocol/consensus');
|
||||
*/
|
||||
|
||||
var COMPRESS_TYPES = 10; // Space for 4 extra.
|
||||
var EMPTY_BUFFER = new Buffer(0);
|
||||
var EMPTY_BUFFER = Buffer.alloc(0);
|
||||
|
||||
/**
|
||||
* Compress a script, write directly to the buffer.
|
||||
|
||||
@ -357,7 +357,7 @@ AESKey.prototype.encryptBlock = function encryptBlock(input) {
|
||||
^ (TE1[(t2 >>> 0) & 0xff] & 0x000000ff)
|
||||
^ key[kp + 3];
|
||||
|
||||
output = new Buffer(16);
|
||||
output = Buffer.allocUnsafe(16);
|
||||
writeU32(output, s0, 0);
|
||||
writeU32(output, s1, 4);
|
||||
writeU32(output, s2, 8);
|
||||
@ -462,7 +462,7 @@ AESKey.prototype.decryptBlock = function decryptBlock(input) {
|
||||
^ (TD4[(t0 >>> 0) & 0xff] << 0)
|
||||
^ key[kp + 3];
|
||||
|
||||
output = new Buffer(16);
|
||||
output = Buffer.allocUnsafe(16);
|
||||
writeU32(output, s0, 0);
|
||||
writeU32(output, s1, 4);
|
||||
writeU32(output, s2, 8);
|
||||
@ -536,12 +536,12 @@ AESCipher.prototype.final = function final() {
|
||||
|
||||
// Handle padding on the last block.
|
||||
if (!this.waiting) {
|
||||
block = new Buffer(16);
|
||||
block = Buffer.allocUnsafe(16);
|
||||
block.fill(16);
|
||||
} else {
|
||||
block = this.waiting;
|
||||
left = 16 - block.length;
|
||||
pad = new Buffer(left);
|
||||
pad = Buffer.allocUnsafe(left);
|
||||
pad.fill(left);
|
||||
block = concat(block, pad);
|
||||
}
|
||||
@ -652,7 +652,7 @@ AESDecipher.prototype.final = function final() {
|
||||
// Slice off the padding unless
|
||||
// the entire block was padding.
|
||||
if (n === 16)
|
||||
return new Buffer(0);
|
||||
return Buffer.alloc(0);
|
||||
|
||||
block = block.slice(0, -n);
|
||||
|
||||
@ -771,7 +771,7 @@ AES.decipher = AES.cbc.decrypt;
|
||||
*/
|
||||
|
||||
function xor(v1, v2) {
|
||||
var out = new Buffer(v1.length);
|
||||
var out = Buffer.allocUnsafe(v1.length);
|
||||
for (var i = 0; i < v1.length; i++)
|
||||
out[i] = v1[i] ^ v2[i];
|
||||
return out;
|
||||
@ -792,7 +792,7 @@ function writeU32(data, value, i) {
|
||||
}
|
||||
|
||||
function concat(a, b) {
|
||||
var data = new Buffer(a.length + b.length);
|
||||
var data = Buffer.allocUnsafe(a.length + b.length);
|
||||
a.copy(data, 0);
|
||||
b.copy(data, a.length);
|
||||
return data;
|
||||
|
||||
@ -30,7 +30,7 @@ backend.hash = function hash(alg, data) {
|
||||
|
||||
assert(hash != null, 'Unknown algorithm.');
|
||||
|
||||
return new Buffer(hash().update(data).digest());
|
||||
return Buffer.from(hash().update(data).digest());
|
||||
};
|
||||
|
||||
backend.ripemd160 = function ripemd160(data) {
|
||||
@ -61,7 +61,7 @@ backend.hmac = function _hmac(alg, data, key) {
|
||||
|
||||
hmac = hashjs.hmac(hash, key);
|
||||
|
||||
return new Buffer(hmac.update(data).digest());
|
||||
return Buffer.from(hmac.update(data).digest());
|
||||
};
|
||||
|
||||
/*
|
||||
@ -69,11 +69,11 @@ backend.hmac = function _hmac(alg, data, key) {
|
||||
*/
|
||||
|
||||
backend.pbkdf2 = function pbkdf2(key, salt, iter, len, alg) {
|
||||
var size = backend.hash(alg, new Buffer(0)).length;
|
||||
var size = backend.hash(alg, Buffer.alloc(0)).length;
|
||||
var blocks = Math.ceil(len / size);
|
||||
var out = new Buffer(len);
|
||||
var buf = new Buffer(salt.length + 4);
|
||||
var block = new Buffer(size);
|
||||
var out = Buffer.allocUnsafe(len);
|
||||
var buf = Buffer.allocUnsafe(salt.length + 4);
|
||||
var block = Buffer.allocUnsafe(size);
|
||||
var pos = 0;
|
||||
var i, j, k, mac;
|
||||
|
||||
@ -114,7 +114,7 @@ backend.pbkdf2Async = function pbkdf2Async(key, salt, iter, len, alg) {
|
||||
return promise.then(function(key) {
|
||||
return subtle.deriveBits(options, key, length);
|
||||
}).then(function(result) {
|
||||
return new Buffer(result);
|
||||
return Buffer.from(result);
|
||||
});
|
||||
};
|
||||
|
||||
@ -144,13 +144,13 @@ backend.decipher = function decipher(data, key, iv) {
|
||||
backend.randomBytes = function randomBytes(n) {
|
||||
var data = new Uint8Array(n);
|
||||
crypto.getRandomValues(data);
|
||||
return new Buffer(data.buffer);
|
||||
return Buffer.from(data.buffer);
|
||||
};
|
||||
|
||||
if (!crypto.getRandomValues) {
|
||||
// Out of luck here. Use bad randomness for now.
|
||||
backend.randomBytes = function randomBytes(n) {
|
||||
var data = new Buffer(n);
|
||||
var data = Buffer.allocUnsafe(n);
|
||||
var i;
|
||||
|
||||
for (i = 0; i < data.length; i++)
|
||||
|
||||
@ -31,7 +31,7 @@ function ChaCha20() {
|
||||
this.bytes = new Uint8Array(this.stream.buffer);
|
||||
|
||||
if (BIG_ENDIAN)
|
||||
this.bytes = new Buffer(64);
|
||||
this.bytes = Buffer.allocUnsafe(64);
|
||||
|
||||
this.pos = 0;
|
||||
this.ivSize = 0;
|
||||
@ -223,7 +223,7 @@ function Poly1305() {
|
||||
this.pad = new Uint16Array(8);
|
||||
this.fin = 0;
|
||||
this.leftover = 0;
|
||||
this.buffer = new Buffer(16);
|
||||
this.buffer = Buffer.allocUnsafe(16);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -382,7 +382,7 @@ Poly1305.prototype.update = function update(data) {
|
||||
*/
|
||||
|
||||
Poly1305.prototype.finish = function finish() {
|
||||
var mac = new Buffer(16);
|
||||
var mac = Buffer.allocUnsafe(16);
|
||||
var g = new Uint16Array(10);
|
||||
var c, mask, f, i;
|
||||
|
||||
@ -527,7 +527,7 @@ function AEAD() {
|
||||
*/
|
||||
|
||||
AEAD.prototype.init = function init(key, iv) {
|
||||
var polyKey = new Buffer(32);
|
||||
var polyKey = Buffer.allocUnsafe(32);
|
||||
polyKey.fill(0);
|
||||
|
||||
this.chacha20.init(key, iv);
|
||||
@ -536,7 +536,7 @@ AEAD.prototype.init = function init(key, iv) {
|
||||
|
||||
// We need to encrypt a full block
|
||||
// to get the cipher in the correct state.
|
||||
this.chacha20.encrypt(new Buffer(32));
|
||||
this.chacha20.encrypt(Buffer.allocUnsafe(32));
|
||||
|
||||
// Counter should be one.
|
||||
assert(this.chacha20.getCounter() === 1);
|
||||
@ -613,7 +613,7 @@ AEAD.prototype.auth = function auth(data) {
|
||||
*/
|
||||
|
||||
AEAD.prototype.finish = function finish() {
|
||||
var len = new Buffer(16);
|
||||
var len = Buffer.allocUnsafe(16);
|
||||
var lo, hi;
|
||||
|
||||
// The RFC says these are supposed to be
|
||||
@ -652,7 +652,7 @@ AEAD.prototype.pad16 = function pad16(size) {
|
||||
if (size === 0)
|
||||
return;
|
||||
|
||||
pad = new Buffer(16 - size);
|
||||
pad = Buffer.allocUnsafe(16 - size);
|
||||
pad.fill(0);
|
||||
|
||||
this.poly1305.update(pad);
|
||||
|
||||
@ -160,19 +160,19 @@ crypto.hkdfExtract = function hkdfExtract(ikm, key, alg) {
|
||||
*/
|
||||
|
||||
crypto.hkdfExpand = function hkdfExpand(prk, info, len, alg) {
|
||||
var size = crypto.hash(alg, new Buffer(0)).length;
|
||||
var size = crypto.hash(alg, Buffer.alloc(0)).length;
|
||||
var blocks = Math.ceil(len / size);
|
||||
var i, okm, buf, out;
|
||||
|
||||
if (blocks > 255)
|
||||
throw new Error('Too many blocks.');
|
||||
|
||||
okm = new Buffer(len);
|
||||
okm = Buffer.allocUnsafe(len);
|
||||
|
||||
if (blocks === 0)
|
||||
return okm;
|
||||
|
||||
buf = new Buffer(size + info.length + 1);
|
||||
buf = Buffer.allocUnsafe(size + info.length + 1);
|
||||
|
||||
// First round:
|
||||
info.copy(buf, size);
|
||||
@ -204,13 +204,13 @@ crypto.createMerkleTree = function createMerkleTree(leaves) {
|
||||
var i, j, k, hash, left, right, lr;
|
||||
|
||||
if (size === 0) {
|
||||
hash = new Buffer(32);
|
||||
hash = Buffer.allocUnsafe(32);
|
||||
hash.fill(0);
|
||||
nodes.push(hash);
|
||||
return new MerkleTree(nodes, malleated);
|
||||
}
|
||||
|
||||
lr = new Buffer(64);
|
||||
lr = Buffer.allocUnsafe(64);
|
||||
|
||||
for (j = 0; size > 1; size = ((size + 1) / 2) | 0) {
|
||||
for (i = 0; i < size; i += 2) {
|
||||
@ -290,7 +290,7 @@ crypto.verifyMerkleBranch = function verifyMerkleBranch(hash, branch, index) {
|
||||
if (branch.length === 0)
|
||||
return hash;
|
||||
|
||||
lr = new Buffer(64);
|
||||
lr = Buffer.allocUnsafe(64);
|
||||
|
||||
for (i = 0; i < branch.length; i++) {
|
||||
otherside = branch[i];
|
||||
|
||||
@ -54,7 +54,7 @@ ec.publicKeyCreate = function publicKeyCreate(priv, compressed) {
|
||||
key = secp256k1.keyPair({ priv: priv });
|
||||
key = key.getPublic(compressed !== false, 'array');
|
||||
|
||||
return new Buffer(key);
|
||||
return Buffer.from(key);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -65,7 +65,7 @@ ec.publicKeyCreate = function publicKeyCreate(priv, compressed) {
|
||||
|
||||
ec.publicKeyConvert = function publicKeyConvert(key, compressed) {
|
||||
var point = curve.decodePoint(key);
|
||||
return new Buffer(point.encode('array', compressed !== false));
|
||||
return Buffer.from(point.encode('array', compressed !== false));
|
||||
};
|
||||
|
||||
/**
|
||||
@ -98,7 +98,7 @@ ec.privateKeyTweakAdd = function privateKeyTweakAdd(privateKey, tweak) {
|
||||
ec.publicKeyTweakAdd = function publicKeyTweakAdd(publicKey, tweak, compressed) {
|
||||
var key = curve.decodePoint(publicKey);
|
||||
var point = curve.g.mul(new BN(tweak)).add(key);
|
||||
var pub = new Buffer(point.encode('array', compressed !== false));
|
||||
var pub = Buffer.from(point.encode('array', compressed !== false));
|
||||
|
||||
if (!ec.publicKeyVerify(pub))
|
||||
throw new Error('Public key is invalid.');
|
||||
@ -142,7 +142,7 @@ ec.recover = function recover(msg, sig, j, compressed) {
|
||||
|
||||
key = point.encode('array', compressed !== false);
|
||||
|
||||
return new Buffer(key);
|
||||
return Buffer.from(key);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -233,7 +233,7 @@ ec.sign = function sign(msg, key) {
|
||||
sig = secp256k1.sign(msg, key, { canonical: true });
|
||||
|
||||
// Convert to DER array
|
||||
return new Buffer(sig.toDER());
|
||||
return Buffer.from(sig.toDER());
|
||||
};
|
||||
|
||||
/**
|
||||
@ -248,7 +248,7 @@ ec.fromDER = function fromDER(sig) {
|
||||
assert(Buffer.isBuffer(sig));
|
||||
|
||||
sig = new Signature(sig);
|
||||
out = new Buffer(64);
|
||||
out = Buffer.allocUnsafe(64);
|
||||
|
||||
sig.r.toArrayLike(Buffer, 'be', 32).copy(out, 0);
|
||||
sig.s.toArrayLike(Buffer, 'be', 32).copy(out, 32);
|
||||
@ -272,7 +272,7 @@ ec.toDER = function toDER(sig) {
|
||||
s: new BN(sig.slice(32, 64), 'be')
|
||||
});
|
||||
|
||||
return new Buffer(out.toDER());
|
||||
return Buffer.from(out.toDER());
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -22,12 +22,12 @@ var ec = exports;
|
||||
* Constants
|
||||
*/
|
||||
|
||||
var ZERO_S = new Buffer(
|
||||
var ZERO_S = Buffer.from(
|
||||
'0000000000000000000000000000000000000000000000000000000000000000',
|
||||
'hex'
|
||||
);
|
||||
|
||||
var HALF_ORDER = new Buffer(
|
||||
var HALF_ORDER = Buffer.from(
|
||||
'7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0',
|
||||
'hex');
|
||||
|
||||
|
||||
@ -33,13 +33,13 @@ rsa = {};
|
||||
*/
|
||||
|
||||
rsa.prefixes = {
|
||||
md5: new Buffer('3020300c06082a864886f70d020505000410', 'hex'),
|
||||
sha1: new Buffer('3021300906052b0e03021a05000414', 'hex'),
|
||||
sha224: new Buffer('302d300d06096086480165030402040500041c', 'hex'),
|
||||
sha256: new Buffer('3031300d060960864801650304020105000420', 'hex'),
|
||||
sha384: new Buffer('3041300d060960864801650304020205000430', 'hex'),
|
||||
sha512: new Buffer('3051300d060960864801650304020305000440', 'hex'),
|
||||
ripemd160: new Buffer('30203008060628cf060300310414', 'hex')
|
||||
md5: Buffer.from('3020300c06082a864886f70d020505000410', 'hex'),
|
||||
sha1: Buffer.from('3021300906052b0e03021a05000414', 'hex'),
|
||||
sha224: Buffer.from('302d300d06096086480165030402040500041c', 'hex'),
|
||||
sha256: Buffer.from('3031300d060960864801650304020105000420', 'hex'),
|
||||
sha384: Buffer.from('3041300d060960864801650304020205000430', 'hex'),
|
||||
sha512: Buffer.from('3051300d060960864801650304020305000440', 'hex'),
|
||||
ripemd160: Buffer.from('30203008060628cf060300310414', 'hex')
|
||||
};
|
||||
|
||||
/**
|
||||
@ -114,7 +114,7 @@ rsa.sign = function sign(alg, msg, key) {
|
||||
if (k < len + 11)
|
||||
throw new Error('Message too long.');
|
||||
|
||||
em = new Buffer(k);
|
||||
em = Buffer.allocUnsafe(k);
|
||||
em.fill(0);
|
||||
|
||||
em[1] = 0x01;
|
||||
@ -214,7 +214,7 @@ ecdsa.sign = function sign(curve, alg, msg, key) {
|
||||
ec = elliptic.ec(curve);
|
||||
hash = backend.hash(alg, msg);
|
||||
|
||||
return new Buffer(ec.sign(hash, key));
|
||||
return Buffer.from(ec.sign(hash, key));
|
||||
};
|
||||
|
||||
/*
|
||||
@ -228,7 +228,7 @@ function leftpad(input, size) {
|
||||
if (n > size)
|
||||
n = size;
|
||||
|
||||
out = new Buffer(size);
|
||||
out = Buffer.allocUnsafe(size);
|
||||
out.fill(0);
|
||||
|
||||
input.copy(out, out.length - n);
|
||||
|
||||
@ -100,7 +100,7 @@ ecdsa.sign = function sign(curve, alg, msg, key) {
|
||||
ec = elliptic.ec(curve);
|
||||
hash = backend.hash(alg, msg);
|
||||
|
||||
return new Buffer(ec.sign(hash, key));
|
||||
return Buffer.from(ec.sign(hash, key));
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@ -32,7 +32,7 @@ var schnorr = exports;
|
||||
|
||||
schnorr.hash = function _hash(msg, r, hash) {
|
||||
var R = r.toArrayLike(Buffer, 'be', 32);
|
||||
var B = new Buffer(64);
|
||||
var B = Buffer.allocUnsafe(64);
|
||||
var H;
|
||||
|
||||
if (!hash)
|
||||
@ -211,7 +211,7 @@ schnorr.recover = function recover(signature, msg, hash) {
|
||||
if (rl.getX().cmp(sig.r) !== 0)
|
||||
throw new Error('Could not recover pubkey.');
|
||||
|
||||
return new Buffer(k.encode('array', true));
|
||||
return Buffer.from(k.encode('array', true));
|
||||
};
|
||||
|
||||
/**
|
||||
@ -273,7 +273,7 @@ schnorr.combineKeys = function combineKeys(keys) {
|
||||
point = point.add(key);
|
||||
}
|
||||
|
||||
return new Buffer(point.encode('array', true));
|
||||
return Buffer.from(point.encode('array', true));
|
||||
};
|
||||
|
||||
/**
|
||||
@ -309,7 +309,7 @@ schnorr.partialSign = function partialSign(msg, priv, privnonce, pubs, hash) {
|
||||
* @const {Buffer}
|
||||
*/
|
||||
|
||||
schnorr.alg = new Buffer('Schnorr+SHA256 ', 'ascii');
|
||||
schnorr.alg = Buffer.from('Schnorr+SHA256 ', 'ascii');
|
||||
|
||||
/**
|
||||
* Instantiate an HMAC-DRBG.
|
||||
@ -320,7 +320,7 @@ schnorr.alg = new Buffer('Schnorr+SHA256 ', 'ascii');
|
||||
*/
|
||||
|
||||
schnorr.drbg = function drbg(msg, priv, data) {
|
||||
var kdata = new Buffer(112);
|
||||
var kdata = Buffer.allocUnsafe(112);
|
||||
var prv, pers;
|
||||
|
||||
kdata.fill(0);
|
||||
@ -356,7 +356,7 @@ schnorr.drbg = function drbg(msg, priv, data) {
|
||||
schnorr.rfc6979 = function rfc6979(msg, priv, data) {
|
||||
var drbg = schnorr.drbg(msg, priv, data);
|
||||
var bytes = drbg.generate(curve.n.byteLength());
|
||||
return new Buffer(bytes);
|
||||
return Buffer.from(bytes);
|
||||
};
|
||||
|
||||
/**
|
||||
@ -397,7 +397,7 @@ schnorr.generateNoncePair = function generateNoncePair(msg, priv, data, ncb) {
|
||||
if (k.cmp(curve.n) >= 0)
|
||||
throw new Error('Bad nonce.');
|
||||
|
||||
return new Buffer(curve.g.mul(k).encode('array', true));
|
||||
return Buffer.from(curve.g.mul(k).encode('array', true));
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@ -70,8 +70,8 @@ function scrypt(passwd, salt, N, r, p, len) {
|
||||
if (N > 0xffffffff)
|
||||
throw new Error('EINVAL');
|
||||
|
||||
XY = new Buffer(256 * r);
|
||||
V = new Buffer(128 * r * N);
|
||||
XY = Buffer.allocUnsafe(256 * r);
|
||||
V = Buffer.allocUnsafe(128 * r * N);
|
||||
|
||||
B = backend.pbkdf2(passwd, salt, 1, p * 128 * r, 'sha256');
|
||||
|
||||
@ -149,7 +149,7 @@ function R(a, b) {
|
||||
}
|
||||
|
||||
function blockmix_salsa8(B, Y, Yo, r) {
|
||||
var X = new Buffer(64);
|
||||
var X = Buffer.allocUnsafe(64);
|
||||
var i;
|
||||
|
||||
blkcpy(X, B, 0, (2 * r - 1) * 64, 64);
|
||||
@ -227,8 +227,8 @@ scryptAsync = co(function* scryptAsync(passwd, salt, N, r, p, len) {
|
||||
if (N > 0xffffffff)
|
||||
throw new Error('EINVAL');
|
||||
|
||||
XY = new Buffer(256 * r);
|
||||
V = new Buffer(128 * r * N);
|
||||
XY = Buffer.allocUnsafe(256 * r);
|
||||
V = Buffer.allocUnsafe(128 * r * N);
|
||||
|
||||
B = yield backend.pbkdf2Async(passwd, salt, 1, p * 128 * r, 'sha256');
|
||||
|
||||
|
||||
@ -16,12 +16,12 @@
|
||||
* Constants
|
||||
*/
|
||||
|
||||
var DESC = new Buffer(8);
|
||||
var BUFFER64 = new Buffer(64);
|
||||
var DESC = Buffer.allocUnsafe(8);
|
||||
var BUFFER64 = Buffer.allocUnsafe(64);
|
||||
var K, PADDING;
|
||||
var ctx, mctx;
|
||||
|
||||
PADDING = new Buffer(64);
|
||||
PADDING = Buffer.allocUnsafe(64);
|
||||
PADDING.fill(0);
|
||||
PADDING[0] = 0x80;
|
||||
|
||||
@ -60,7 +60,7 @@ function SHA256() {
|
||||
|
||||
this.s = new Array(8);
|
||||
this.w = new Array(64);
|
||||
this.block = new Buffer(64);
|
||||
this.block = Buffer.allocUnsafe(64);
|
||||
this.bytes = 0;
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ SHA256.prototype.update = function update(data) {
|
||||
*/
|
||||
|
||||
SHA256.prototype.finish = function finish() {
|
||||
return this._finish(new Buffer(32));
|
||||
return this._finish(Buffer.allocUnsafe(32));
|
||||
};
|
||||
|
||||
/**
|
||||
@ -367,7 +367,7 @@ function sha256(data) {
|
||||
*/
|
||||
|
||||
function hash256(data) {
|
||||
var out = new Buffer(32);
|
||||
var out = Buffer.allocUnsafe(32);
|
||||
ctx.init();
|
||||
ctx.update(data);
|
||||
ctx._finish(out);
|
||||
|
||||
@ -226,7 +226,7 @@ U64.prototype.rotl = function rotl(b) {
|
||||
};
|
||||
|
||||
U64.prototype.toRaw = function toRaw() {
|
||||
var data = new Buffer(8);
|
||||
var data = Buffer.allocUnsafe(8);
|
||||
data.writeUInt32LE(this.hi, 4, true);
|
||||
data.writeUInt32LE(this.lo, 0, true);
|
||||
return data;
|
||||
|
||||
@ -130,10 +130,10 @@ Iterator.prototype.next = function(callback) {
|
||||
}
|
||||
|
||||
if (key && self.db.bufferKeys)
|
||||
key = new Buffer(key, 'hex');
|
||||
key = Buffer.from(key, 'hex');
|
||||
|
||||
if (value && !Buffer.isBuffer(value) && value.buffer)
|
||||
value = new Buffer(value.buffer);
|
||||
value = Buffer.from(value.buffer);
|
||||
|
||||
callback(err, key, value);
|
||||
});
|
||||
|
||||
@ -410,10 +410,10 @@ LowlevelUp.prototype.compactRange = function compactRange(start, end) {
|
||||
var self = this;
|
||||
|
||||
if (!start)
|
||||
start = new Buffer([0x00]);
|
||||
start = Buffer.from([0x00]);
|
||||
|
||||
if (!end)
|
||||
end = new Buffer([0xff]);
|
||||
end = Buffer.from([0xff]);
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
if (!self.loaded) {
|
||||
@ -580,8 +580,8 @@ LowlevelUp.prototype.dump = co(function* dump() {
|
||||
var i, items, item, key, value;
|
||||
|
||||
items = yield this.range({
|
||||
gte: new Buffer([0x00]),
|
||||
lte: new Buffer([0xff])
|
||||
gte: Buffer.from([0x00]),
|
||||
lte: Buffer.from([0xff])
|
||||
});
|
||||
|
||||
for (i = 0; i < items.length; i++) {
|
||||
@ -605,7 +605,7 @@ LowlevelUp.prototype.checkVersion = co(function* checkVersion(key, version) {
|
||||
var data = yield this.get(key);
|
||||
|
||||
if (!data) {
|
||||
data = new Buffer(4);
|
||||
data = Buffer.allocUnsafe(4);
|
||||
data.writeUInt32LE(version, 0, true);
|
||||
yield this.put(key, data);
|
||||
return;
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
var assert = require('assert');
|
||||
var util = require('../utils/util');
|
||||
var RBT = require('../utils/rbt');
|
||||
var DUMMY = new Buffer(0);
|
||||
var DUMMY = Buffer.alloc(0);
|
||||
|
||||
/**
|
||||
* In memory database for bcoin
|
||||
@ -41,7 +41,7 @@ MemDB.prototype.search = function search(key) {
|
||||
var node;
|
||||
|
||||
if (typeof key === 'string')
|
||||
key = new Buffer(key, 'utf8');
|
||||
key = Buffer.from(key, 'utf8');
|
||||
|
||||
assert(Buffer.isBuffer(key), 'Key must be a Buffer.');
|
||||
|
||||
@ -62,10 +62,10 @@ MemDB.prototype.search = function search(key) {
|
||||
|
||||
MemDB.prototype.insert = function insert(key, value) {
|
||||
if (typeof key === 'string')
|
||||
key = new Buffer(key, 'utf8');
|
||||
key = Buffer.from(key, 'utf8');
|
||||
|
||||
if (typeof value === 'string')
|
||||
value = new Buffer(value, 'utf8');
|
||||
value = Buffer.from(value, 'utf8');
|
||||
|
||||
if (value == null)
|
||||
value = DUMMY;
|
||||
@ -85,7 +85,7 @@ MemDB.prototype.insert = function insert(key, value) {
|
||||
|
||||
MemDB.prototype.remove = function remove(key) {
|
||||
if (typeof key === 'string')
|
||||
key = new Buffer(key, 'utf8');
|
||||
key = Buffer.from(key, 'utf8');
|
||||
|
||||
assert(Buffer.isBuffer(key), 'Key must be a Buffer.');
|
||||
|
||||
@ -102,10 +102,10 @@ MemDB.prototype.remove = function remove(key) {
|
||||
|
||||
MemDB.prototype.range = function range(min, max) {
|
||||
if (typeof min === 'string')
|
||||
min = new Buffer(min, 'utf8');
|
||||
min = Buffer.from(min, 'utf8');
|
||||
|
||||
if (typeof max === 'string')
|
||||
max = new Buffer(max, 'utf8');
|
||||
max = Buffer.from(max, 'utf8');
|
||||
|
||||
assert(!min || Buffer.isBuffer(min), 'Key must be a Buffer.');
|
||||
assert(!max || Buffer.isBuffer(max), 'Key must be a Buffer.');
|
||||
@ -552,7 +552,7 @@ Iterator.prototype.seek = function seek(key) {
|
||||
assert(this.iter, 'Already ended.');
|
||||
|
||||
if (typeof key === 'string')
|
||||
key = new Buffer(key, 'utf8');
|
||||
key = Buffer.from(key, 'utf8');
|
||||
|
||||
assert(Buffer.isBuffer(key), 'Key must be a Buffer.');
|
||||
|
||||
@ -646,13 +646,13 @@ IteratorOptions.prototype.fromOptions = function fromOptions(options) {
|
||||
|
||||
if (this.start != null) {
|
||||
if (typeof this.start === 'string')
|
||||
this.start = new Buffer(this.start, 'utf8');
|
||||
this.start = Buffer.from(this.start, 'utf8');
|
||||
assert(Buffer.isBuffer(this.start), '`start` must be a Buffer.');
|
||||
}
|
||||
|
||||
if (this.end != null) {
|
||||
if (typeof this.end === 'string')
|
||||
this.end = new Buffer(this.end, 'utf8');
|
||||
this.end = Buffer.from(this.end, 'utf8');
|
||||
assert(Buffer.isBuffer(this.end), '`end` must be a Buffer.');
|
||||
}
|
||||
|
||||
|
||||
@ -47,7 +47,7 @@ common.MAX_ENTROPY = 512;
|
||||
* @default
|
||||
*/
|
||||
|
||||
common.SEED_SALT = new Buffer('Bitcoin seed', 'ascii');
|
||||
common.SEED_SALT = Buffer.from('Bitcoin seed', 'ascii');
|
||||
|
||||
/**
|
||||
* LRU cache to avoid deriving keys twice.
|
||||
|
||||
@ -148,8 +148,8 @@ Mnemonic.prototype.toSeed = function toSeed(passphrase) {
|
||||
passwd = nfkd('mnemonic' + passphrase);
|
||||
|
||||
return crypto.pbkdf2(
|
||||
new Buffer(phrase, 'utf8'),
|
||||
new Buffer(passwd, 'utf8'),
|
||||
Buffer.from(phrase, 'utf8'),
|
||||
Buffer.from(passwd, 'utf8'),
|
||||
2048, 64, 'sha512');
|
||||
};
|
||||
|
||||
@ -192,7 +192,7 @@ Mnemonic.prototype.getPhrase = function getPhrase() {
|
||||
// Append the hash to the entropy to
|
||||
// make things easy when grabbing
|
||||
// the checksum bits.
|
||||
entropy = new Buffer(Math.ceil(bits / 8));
|
||||
entropy = Buffer.allocUnsafe(Math.ceil(bits / 8));
|
||||
ent.copy(entropy, 0);
|
||||
crypto.sha256(ent).copy(entropy, ent.length);
|
||||
|
||||
@ -244,7 +244,7 @@ Mnemonic.prototype.fromPhrase = function fromPhrase(phrase) {
|
||||
assert(bits % 32 === 0);
|
||||
assert(cbits !== 0, 'Invalid checksum.');
|
||||
|
||||
ent = new Buffer(Math.ceil((bits + cbits) / 8));
|
||||
ent = Buffer.allocUnsafe(Math.ceil((bits + cbits) / 8));
|
||||
ent.fill(0);
|
||||
|
||||
lang = Mnemonic.getLanguage(words[0]);
|
||||
@ -398,7 +398,7 @@ Mnemonic.prototype.fromJSON = function fromJSON(json) {
|
||||
|
||||
this.bits = json.bits;
|
||||
this.language = json.language;
|
||||
this.entropy = new Buffer(json.entropy, 'hex');
|
||||
this.entropy = Buffer.from(json.entropy, 'hex');
|
||||
this.phrase = json.phrase;
|
||||
this.passphrase = json.passphrase;
|
||||
|
||||
|
||||
@ -476,7 +476,7 @@ HDPrivateKey.prototype.fromSeed = function fromSeed(seed, network) {
|
||||
|
||||
this.network = Network.get(network);
|
||||
this.depth = 0;
|
||||
this.parentFingerPrint = new Buffer([0, 0, 0, 0]);
|
||||
this.parentFingerPrint = Buffer.from([0, 0, 0, 0]);
|
||||
this.childIndex = 0;
|
||||
this.chainCode = right;
|
||||
this.privateKey = left;
|
||||
@ -556,7 +556,7 @@ HDPrivateKey.prototype.fromKey = function fromKey(key, entropy, network) {
|
||||
assert(Buffer.isBuffer(entropy) && entropy.length === 32);
|
||||
this.network = Network.get(network);
|
||||
this.depth = 0;
|
||||
this.parentFingerPrint = new Buffer([0, 0, 0, 0]);
|
||||
this.parentFingerPrint = Buffer.from([0, 0, 0, 0]);
|
||||
this.childIndex = 0;
|
||||
this.chainCode = entropy;
|
||||
this.privateKey = key;
|
||||
|
||||
@ -196,13 +196,13 @@ HTTPBase.prototype.basicAuth = function basicAuth(options) {
|
||||
|
||||
if (user) {
|
||||
if (typeof user === 'string')
|
||||
user = new Buffer(user, 'utf8');
|
||||
user = Buffer.from(user, 'utf8');
|
||||
assert(Buffer.isBuffer(user));
|
||||
user = crypto.hash256(user);
|
||||
}
|
||||
|
||||
if (typeof pass === 'string')
|
||||
pass = new Buffer(pass, 'utf8');
|
||||
pass = Buffer.from(pass, 'utf8');
|
||||
|
||||
assert(Buffer.isBuffer(pass));
|
||||
pass = crypto.hash256(pass);
|
||||
@ -233,21 +233,21 @@ HTTPBase.prototype.basicAuth = function basicAuth(options) {
|
||||
if (parts[0] !== 'Basic')
|
||||
return fail(res);
|
||||
|
||||
auth = new Buffer(parts[1], 'base64').toString('utf8');
|
||||
auth = Buffer.from(parts[1], 'base64').toString('utf8');
|
||||
parts = auth.split(':');
|
||||
|
||||
username = parts.shift();
|
||||
password = parts.join(':');
|
||||
|
||||
if (user) {
|
||||
digest = new Buffer(username, 'utf8');
|
||||
digest = Buffer.from(username, 'utf8');
|
||||
digest = crypto.hash256(digest);
|
||||
|
||||
if (!crypto.ccmp(digest, user))
|
||||
return fail(res);
|
||||
}
|
||||
|
||||
digest = new Buffer(password, 'utf8');
|
||||
digest = Buffer.from(password, 'utf8');
|
||||
digest = crypto.hash256(digest);
|
||||
|
||||
if (!crypto.ccmp(digest, pass))
|
||||
|
||||
@ -142,13 +142,13 @@ RequestOptions.prototype.fromOptions = function fromOptions(options) {
|
||||
|
||||
if (options.json != null) {
|
||||
assert(typeof options.json === 'object');
|
||||
this.body = new Buffer(JSON.stringify(options.json), 'utf8');
|
||||
this.body = Buffer.from(JSON.stringify(options.json), 'utf8');
|
||||
this.type = 'json';
|
||||
}
|
||||
|
||||
if (options.form != null) {
|
||||
assert(typeof options.form === 'object');
|
||||
this.body = new Buffer(qs.stringify(options.form), 'utf8');
|
||||
this.body = Buffer.from(qs.stringify(options.form), 'utf8');
|
||||
this.type = 'form';
|
||||
}
|
||||
|
||||
@ -166,7 +166,7 @@ RequestOptions.prototype.fromOptions = function fromOptions(options) {
|
||||
|
||||
if (options.body != null) {
|
||||
if (typeof options.body === 'string') {
|
||||
this.body = new Buffer(options.body, 'utf8');
|
||||
this.body = Buffer.from(options.body, 'utf8');
|
||||
} else {
|
||||
assert(Buffer.isBuffer(options.body));
|
||||
this.body = options.body;
|
||||
@ -245,7 +245,7 @@ RequestOptions.prototype.getHeaders = function getHeaders() {
|
||||
if (this.auth) {
|
||||
auth = this.auth.username + ':' + this.auth.password;
|
||||
headers['Authorization'] =
|
||||
'Basic ' + new Buffer(auth, 'utf8').toString('base64');
|
||||
'Basic ' + Buffer.from(auth, 'utf8').toString('base64');
|
||||
}
|
||||
|
||||
return headers;
|
||||
|
||||
@ -1127,7 +1127,7 @@ RPC.prototype._createWork = co(function* _createWork() {
|
||||
var ts = attempt.ts;
|
||||
var data, root, head;
|
||||
|
||||
data = new Buffer(128);
|
||||
data = Buffer.allocUnsafe(128);
|
||||
data.fill(0);
|
||||
|
||||
root = attempt.getRoot(n1, n2);
|
||||
@ -2064,7 +2064,7 @@ RPC.prototype.verifyMessage = co(function* verifyMessage(args, help) {
|
||||
|
||||
addr = parseAddress(b58, this.network);
|
||||
|
||||
msg = new Buffer(MAGIC_STRING + msg, 'utf8');
|
||||
msg = Buffer.from(MAGIC_STRING + msg, 'utf8');
|
||||
msg = crypto.hash256(msg);
|
||||
|
||||
key = ec.recover(msg, sig, 0, true);
|
||||
@ -2089,7 +2089,7 @@ RPC.prototype.signMessageWithPrivkey = co(function* signMessageWithPrivkey(args,
|
||||
}
|
||||
|
||||
key = parseSecret(key, this.network);
|
||||
msg = new Buffer(MAGIC_STRING + msg, 'utf8');
|
||||
msg = Buffer.from(MAGIC_STRING + msg, 'utf8');
|
||||
msg = crypto.hash256(msg);
|
||||
|
||||
sig = key.sign(msg);
|
||||
|
||||
@ -844,12 +844,12 @@ HTTPOptions.fromOptions = function fromOptions(options) {
|
||||
|
||||
function hash256(data) {
|
||||
if (typeof data !== 'string')
|
||||
return new Buffer(0);
|
||||
return Buffer.alloc(0);
|
||||
|
||||
if (data.length > 200)
|
||||
return new Buffer(0);
|
||||
return Buffer.alloc(0);
|
||||
|
||||
return crypto.hash256(new Buffer(data, 'utf8'));
|
||||
return crypto.hash256(Buffer.from(data, 'utf8'));
|
||||
}
|
||||
|
||||
function enforce(value, msg) {
|
||||
|
||||
@ -15,11 +15,11 @@
|
||||
|
||||
var layout = {
|
||||
binary: true,
|
||||
R: new Buffer([0x52]),
|
||||
V: new Buffer([0x76]),
|
||||
F: new Buffer([0x46]),
|
||||
R: Buffer.from([0x52]),
|
||||
V: Buffer.from([0x76]),
|
||||
F: Buffer.from([0x46]),
|
||||
e: function e(hash) {
|
||||
var key = new Buffer(33);
|
||||
var key = Buffer.allocUnsafe(33);
|
||||
key[0] = 0x65;
|
||||
write(key, hash, 1);
|
||||
return key;
|
||||
|
||||
@ -2514,7 +2514,7 @@ MempoolCache.prototype.sync = function sync(hash) {
|
||||
if (!this.db)
|
||||
return;
|
||||
|
||||
this.batch.put(layout.R, new Buffer(hash, 'hex'));
|
||||
this.batch.put(layout.R, Buffer.from(hash, 'hex'));
|
||||
};
|
||||
|
||||
MempoolCache.prototype.writeFees = function writeFees(fees) {
|
||||
@ -2541,7 +2541,7 @@ MempoolCache.prototype.flush = co(function* flush() {
|
||||
MempoolCache.prototype.init = co(function* init(hash) {
|
||||
var batch = this.db.batch();
|
||||
batch.put(layout.V, encoding.U32(MempoolCache.VERSION));
|
||||
batch.put(layout.R, new Buffer(hash, 'hex'));
|
||||
batch.put(layout.R, Buffer.from(hash, 'hex'));
|
||||
yield batch.write();
|
||||
});
|
||||
|
||||
@ -2596,7 +2596,7 @@ MempoolCache.prototype.wipe = co(function* wipe() {
|
||||
}
|
||||
|
||||
batch.put(layout.V, encoding.U32(MempoolCache.VERSION));
|
||||
batch.put(layout.R, new Buffer(this.chain.tip.hash, 'hex'));
|
||||
batch.put(layout.R, Buffer.from(this.chain.tip.hash, 'hex'));
|
||||
batch.del(layout.F);
|
||||
|
||||
yield batch.write();
|
||||
|
||||
@ -50,7 +50,7 @@ common.swap32 = function swap32(data) {
|
||||
*/
|
||||
|
||||
common.swap32hex = function swap32hex(str) {
|
||||
var data = new Buffer(str, 'hex');
|
||||
var data = Buffer.from(str, 'hex');
|
||||
return common.swap32(data).toString('hex');
|
||||
};
|
||||
|
||||
|
||||
@ -393,7 +393,7 @@ function MinerOptions(options) {
|
||||
|
||||
this.version = -1;
|
||||
this.addresses = [];
|
||||
this.coinbaseFlags = new Buffer('mined by bcoin', 'ascii');
|
||||
this.coinbaseFlags = Buffer.from('mined by bcoin', 'ascii');
|
||||
this.preverify = false;
|
||||
|
||||
this.minWeight = policy.MIN_BLOCK_WEIGHT;
|
||||
@ -458,7 +458,7 @@ MinerOptions.prototype.fromOptions = function fromOptions(options) {
|
||||
if (options.coinbaseFlags) {
|
||||
flags = options.coinbaseFlags;
|
||||
if (typeof flags === 'string')
|
||||
flags = new Buffer(flags, 'utf8');
|
||||
flags = Buffer.from(flags, 'utf8');
|
||||
assert(Buffer.isBuffer(flags));
|
||||
assert(flags.length <= 20, 'Coinbase flags > 20 bytes.');
|
||||
this.coinbaseFlags = flags;
|
||||
|
||||
@ -23,7 +23,7 @@ var encoding = require('../utils/encoding');
|
||||
var CoinView = require('../coins/coinview');
|
||||
var Script = require('../script/script');
|
||||
var common = require('./common');
|
||||
var DUMMY = new Buffer(0);
|
||||
var DUMMY = Buffer.alloc(0);
|
||||
|
||||
/**
|
||||
* Block Template
|
||||
|
||||
@ -251,7 +251,7 @@ BIP150.prototype.toChallenge = function toChallenge() {
|
||||
*/
|
||||
|
||||
BIP150.prototype.rekey = function rekey(sid, key, req, res) {
|
||||
var seed = new Buffer(130);
|
||||
var seed = Buffer.allocUnsafe(130);
|
||||
sid.copy(seed, 0);
|
||||
key.copy(seed, 32);
|
||||
req.copy(seed, 64);
|
||||
@ -296,7 +296,7 @@ BIP150.prototype.rekeyOutput = function rekeyOutput() {
|
||||
*/
|
||||
|
||||
BIP150.prototype.hash = function hash(sid, ch, key) {
|
||||
var data = new Buffer(66);
|
||||
var data = Buffer.allocUnsafe(66);
|
||||
sid.copy(data, 0);
|
||||
data[32] = ch.charCodeAt(0);
|
||||
key.copy(data, 33);
|
||||
@ -739,7 +739,7 @@ AuthDB.prototype.parseKnown = function parseKnown(text) {
|
||||
}
|
||||
|
||||
key = parts[1].trim();
|
||||
key = new Buffer(key, 'hex');
|
||||
key = Buffer.from(key, 'hex');
|
||||
|
||||
if (key.length !== 33)
|
||||
throw new Error('Invalid key: ' + parts[1]);
|
||||
@ -801,7 +801,7 @@ AuthDB.prototype.parseAuth = function parseAuth(text) {
|
||||
if (/^\s*#/.test(line))
|
||||
continue;
|
||||
|
||||
key = new Buffer(line, 'hex');
|
||||
key = Buffer.from(line, 'hex');
|
||||
|
||||
if (key.length !== 33)
|
||||
throw new Error('Invalid key: ' + line);
|
||||
|
||||
@ -30,10 +30,10 @@ var EncackPacket = packets.EncackPacket;
|
||||
* Constants
|
||||
*/
|
||||
|
||||
var HKDF_SALT = new Buffer('bitcoinecdh', 'ascii');
|
||||
var INFO_KEY1 = new Buffer('BitcoinK1', 'ascii');
|
||||
var INFO_KEY2 = new Buffer('BitcoinK2', 'ascii');
|
||||
var INFO_SID = new Buffer('BitcoinSessionID', 'ascii');
|
||||
var HKDF_SALT = Buffer.from('bitcoinecdh', 'ascii');
|
||||
var INFO_KEY1 = Buffer.from('BitcoinK1', 'ascii');
|
||||
var INFO_KEY2 = Buffer.from('BitcoinK2', 'ascii');
|
||||
var INFO_SID = Buffer.from('BitcoinSessionID', 'ascii');
|
||||
var HIGH_WATERMARK = 1024 * (1 << 20);
|
||||
|
||||
/**
|
||||
@ -78,7 +78,7 @@ function BIP151Stream(cipher) {
|
||||
this.aead = new chachapoly.AEAD();
|
||||
this.tag = null;
|
||||
this.seq = 0;
|
||||
this.iv = new Buffer(8);
|
||||
this.iv = Buffer.allocUnsafe(8);
|
||||
this.iv.fill(0);
|
||||
|
||||
this.processed = 0;
|
||||
@ -148,7 +148,7 @@ BIP151Stream.prototype.rekey = function rekey(k1, k2) {
|
||||
assert(this.prk, 'Cannot rekey before initialization.');
|
||||
|
||||
if (!k1) {
|
||||
seed = new Buffer(64);
|
||||
seed = Buffer.allocUnsafe(64);
|
||||
|
||||
this.sid.copy(seed, 0);
|
||||
|
||||
@ -654,7 +654,7 @@ BIP151.prototype.read = function read(size) {
|
||||
assert(this.total >= size, 'Reading too much.');
|
||||
|
||||
if (size === 0)
|
||||
return new Buffer(0);
|
||||
return Buffer.alloc(0);
|
||||
|
||||
pending = this.pending[0];
|
||||
|
||||
@ -671,7 +671,7 @@ BIP151.prototype.read = function read(size) {
|
||||
return chunk;
|
||||
}
|
||||
|
||||
chunk = new Buffer(size);
|
||||
chunk = Buffer.allocUnsafe(size);
|
||||
off = 0;
|
||||
len = 0;
|
||||
|
||||
|
||||
@ -171,7 +171,7 @@ CompactBlock.prototype.fromRaw = function fromRaw(data) {
|
||||
|
||||
CompactBlock.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new CompactBlock().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -385,7 +385,7 @@ CompactBlock.prototype.sid = function sid(hash) {
|
||||
var lo, hi;
|
||||
|
||||
if (typeof hash === 'string')
|
||||
hash = new Buffer(hash, 'hex');
|
||||
hash = Buffer.from(hash, 'hex');
|
||||
|
||||
hash = siphash(hash, this.sipKey);
|
||||
|
||||
|
||||
@ -40,7 +40,7 @@ Framer.prototype.packet = function packet(cmd, payload, checksum) {
|
||||
assert(cmd.length < 12);
|
||||
assert(payload.length <= 0xffffffff);
|
||||
|
||||
packet = new Buffer(24 + payload.length);
|
||||
packet = Buffer.allocUnsafe(24 + payload.length);
|
||||
|
||||
// Magic value
|
||||
packet.writeUInt32LE(this.network.magic, 0, true);
|
||||
|
||||
@ -25,7 +25,7 @@ var TX = require('../primitives/tx');
|
||||
var BufferReader = require('../utils/reader');
|
||||
var StaticWriter = require('../utils/staticwriter');
|
||||
var encoding = require('../utils/encoding');
|
||||
var DUMMY = new Buffer(0);
|
||||
var DUMMY = Buffer.alloc(0);
|
||||
|
||||
/**
|
||||
* Packet types.
|
||||
@ -350,7 +350,7 @@ VersionPacket.prototype.fromRaw = function fromRaw(data) {
|
||||
|
||||
VersionPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new VersionPacket().fromRaw(data, enc);
|
||||
};
|
||||
|
||||
@ -390,7 +390,7 @@ VerackPacket.fromReader = function fromReader(br) {
|
||||
|
||||
VerackPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new VerackPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -486,7 +486,7 @@ PingPacket.fromReader = function fromReader(br) {
|
||||
|
||||
PingPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new PingPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -579,7 +579,7 @@ PongPacket.fromReader = function fromReader(br) {
|
||||
|
||||
PongPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new PongPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -619,7 +619,7 @@ GetAddrPacket.fromReader = function fromReader(br) {
|
||||
|
||||
GetAddrPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new GetAddrPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -721,7 +721,7 @@ AddrPacket.fromReader = function fromReader(br) {
|
||||
|
||||
AddrPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new AddrPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -836,7 +836,7 @@ InvPacket.fromReader = function fromReader(br) {
|
||||
|
||||
InvPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new InvPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -878,7 +878,7 @@ GetDataPacket.fromReader = function fromReader(br) {
|
||||
|
||||
GetDataPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new GetDataPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -920,7 +920,7 @@ NotFoundPacket.fromReader = function fromReader(br) {
|
||||
|
||||
NotFoundPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new NotFoundPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -1039,7 +1039,7 @@ GetBlocksPacket.prototype.fromRaw = function fromRaw(data) {
|
||||
|
||||
GetBlocksPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new GetBlocksPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -1082,7 +1082,7 @@ GetHeadersPacket.fromReader = function fromReader(br) {
|
||||
|
||||
GetHeadersPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new GetHeadersPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -1193,7 +1193,7 @@ HeadersPacket.prototype.fromRaw = function fromRaw(data) {
|
||||
|
||||
HeadersPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new HeadersPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -1233,7 +1233,7 @@ SendHeadersPacket.fromReader = function fromReader(br) {
|
||||
|
||||
SendHeadersPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new SendHeadersPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -1335,7 +1335,7 @@ BlockPacket.fromReader = function fromReader(br) {
|
||||
|
||||
BlockPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new BlockPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -1437,7 +1437,7 @@ TXPacket.fromReader = function fromReader(br) {
|
||||
|
||||
TXPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new TXPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -1665,7 +1665,7 @@ RejectPacket.fromReader = function fromReader(br) {
|
||||
|
||||
RejectPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new RejectPacket().fromRaw(data, enc);
|
||||
};
|
||||
|
||||
@ -1775,7 +1775,7 @@ MempoolPacket.fromReader = function fromReader(br) {
|
||||
|
||||
MempoolPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new MempoolPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -1867,7 +1867,7 @@ FilterLoadPacket.fromReader = function fromReader(br) {
|
||||
|
||||
FilterLoadPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new FilterLoadPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -1960,7 +1960,7 @@ FilterAddPacket.prototype.fromRaw = function fromRaw(data) {
|
||||
|
||||
FilterAddPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new FilterAddPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -1990,7 +1990,7 @@ FilterClearPacket.prototype.type = exports.types.FILTERCLEAR;
|
||||
|
||||
FilterClearPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new FilterClearPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -2073,7 +2073,7 @@ MerkleBlockPacket.prototype.fromRaw = function fromRaw(data) {
|
||||
|
||||
MerkleBlockPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new MerkleBlockPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -2166,7 +2166,7 @@ FeeFilterPacket.fromReader = function fromReader(br) {
|
||||
|
||||
FeeFilterPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new FeeFilterPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -2274,7 +2274,7 @@ SendCmpctPacket.fromReader = function fromReader(br) {
|
||||
|
||||
SendCmpctPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new SendCmpctPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -2376,7 +2376,7 @@ CmpctBlockPacket.fromReader = function fromReader(br) {
|
||||
|
||||
CmpctBlockPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new CmpctBlockPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -2469,7 +2469,7 @@ GetBlockTxnPacket.fromReader = function fromReader(br) {
|
||||
|
||||
GetBlockTxnPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new GetBlockTxnPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -2571,7 +2571,7 @@ BlockTxnPacket.fromReader = function fromReader(br) {
|
||||
|
||||
BlockTxnPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new BlockTxnPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -2669,7 +2669,7 @@ EncinitPacket.fromReader = function fromReader(br) {
|
||||
|
||||
EncinitPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new EncinitPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -2762,7 +2762,7 @@ EncackPacket.fromReader = function fromReader(br) {
|
||||
|
||||
EncackPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new EncackPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -2855,7 +2855,7 @@ AuthChallengePacket.fromReader = function fromReader(br) {
|
||||
|
||||
AuthChallengePacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new AuthChallengePacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -2948,7 +2948,7 @@ AuthReplyPacket.fromReader = function fromReader(br) {
|
||||
|
||||
AuthReplyPacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new AuthReplyPacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -3041,7 +3041,7 @@ AuthProposePacket.fromReader = function fromReader(br) {
|
||||
|
||||
AuthProposePacket.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new AuthProposePacket().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -3118,7 +3118,7 @@ UnknownPacket.prototype.fromRaw = function fromRaw(cmd, data) {
|
||||
|
||||
UnknownPacket.fromRaw = function fromRaw(cmd, data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new UnknownPacket().fromRaw(cmd, data);
|
||||
};
|
||||
|
||||
|
||||
@ -63,7 +63,7 @@ Parser.prototype.feed = function feed(data) {
|
||||
this.pending.push(data);
|
||||
|
||||
while (this.total >= this.waiting) {
|
||||
chunk = new Buffer(this.waiting);
|
||||
chunk = Buffer.allocUnsafe(this.waiting);
|
||||
off = 0;
|
||||
len = 0;
|
||||
|
||||
|
||||
@ -42,8 +42,8 @@ ProxySocket.prototype._init = function _init() {
|
||||
self.info = info;
|
||||
|
||||
if (info.pow) {
|
||||
self.snonce = new Buffer(info.snonce, 'hex');
|
||||
self.target = new Buffer(info.target, 'hex');
|
||||
self.snonce = Buffer.from(info.snonce, 'hex');
|
||||
self.target = Buffer.from(info.target, 'hex');
|
||||
}
|
||||
|
||||
self.emit('info', info);
|
||||
@ -62,7 +62,7 @@ ProxySocket.prototype._init = function _init() {
|
||||
});
|
||||
|
||||
this.socket.on('tcp data', function(data) {
|
||||
data = new Buffer(data, 'hex');
|
||||
data = Buffer.from(data, 'hex');
|
||||
if (self.paused) {
|
||||
self.recvBuffer.push(data);
|
||||
return;
|
||||
|
||||
@ -257,13 +257,13 @@ SOCKS.prototype.sendHandshake = function sendHandshake() {
|
||||
var packet;
|
||||
|
||||
if (this.username) {
|
||||
packet = new Buffer(4);
|
||||
packet = Buffer.allocUnsafe(4);
|
||||
packet[0] = 0x05;
|
||||
packet[1] = 0x02;
|
||||
packet[2] = 0x00;
|
||||
packet[3] = 0x02;
|
||||
} else {
|
||||
packet = new Buffer(3);
|
||||
packet = Buffer.allocUnsafe(3);
|
||||
packet[0] = 0x05;
|
||||
packet[1] = 0x01;
|
||||
packet[2] = 0x00;
|
||||
@ -389,7 +389,7 @@ SOCKS.prototype.sendProxy = function sendProxy() {
|
||||
break;
|
||||
default:
|
||||
type = 0x03;
|
||||
name = new Buffer(host, 'ascii');
|
||||
name = Buffer.from(host, 'ascii');
|
||||
len = 1 + name.length;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -424,7 +424,7 @@ Config.prototype.buf = function buf(key, fallback) {
|
||||
return value;
|
||||
}
|
||||
|
||||
data = new Buffer(value, 'hex');
|
||||
data = Buffer.from(value, 'hex');
|
||||
|
||||
if (data.length !== value.length / 2)
|
||||
throw new Error(key + ' must be a hex string.');
|
||||
|
||||
@ -279,7 +279,7 @@ Logger.prototype.truncate = co(function* truncate() {
|
||||
|
||||
fd = yield fs.open(this.filename, 'r+');
|
||||
|
||||
data = new Buffer(maxSize);
|
||||
data = Buffer.allocUnsafe(maxSize);
|
||||
yield fs.read(fd, data, 0, maxSize, stat.size - maxSize);
|
||||
yield fs.ftruncate(fd, maxSize);
|
||||
yield fs.write(fd, data, 0, maxSize, 0);
|
||||
|
||||
@ -556,7 +556,7 @@ Address.fromScript = function fromScript(script) {
|
||||
|
||||
Address.prototype.fromHash = function fromHash(hash, type, version, network) {
|
||||
if (typeof hash === 'string')
|
||||
hash = new Buffer(hash, 'hex');
|
||||
hash = Buffer.from(hash, 'hex');
|
||||
|
||||
if (typeof type === 'string') {
|
||||
type = Address.types[type.toUpperCase()];
|
||||
@ -728,7 +728,7 @@ Address.prototype.fromProgram = function fromProgram(version, hash, network) {
|
||||
assert(version >= 0, 'Bad version for witness program.');
|
||||
|
||||
if (typeof hash === 'string')
|
||||
hash = new Buffer(hash, 'hex');
|
||||
hash = Buffer.from(hash, 'hex');
|
||||
|
||||
return this.fromHash(hash, type, version, network);
|
||||
};
|
||||
@ -830,7 +830,7 @@ Address.getHash = function getHash(data, enc, network) {
|
||||
|
||||
if (typeof data === 'string') {
|
||||
if (data.length === 40 || data.length === 64)
|
||||
return enc === 'hex' ? data : new Buffer(data, 'hex');
|
||||
return enc === 'hex' ? data : Buffer.from(data, 'hex');
|
||||
|
||||
hash = Address.fromString(data, network).hash;
|
||||
} else if (Buffer.isBuffer(data)) {
|
||||
|
||||
@ -356,7 +356,7 @@ Block.prototype.createCommitmentHash = function createCommitmentHash(enc) {
|
||||
Block.prototype.getMerkleRoot = function getMerkleRoot(enc) {
|
||||
if (enc === 'hex')
|
||||
return this.merkleRoot;
|
||||
return new Buffer(this.merkleRoot, 'hex');
|
||||
return Buffer.from(this.merkleRoot, 'hex');
|
||||
};
|
||||
|
||||
/**
|
||||
@ -720,7 +720,7 @@ Block.fromReader = function fromReader(data) {
|
||||
|
||||
Block.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new Block().fromRaw(data);
|
||||
};
|
||||
|
||||
|
||||
@ -383,7 +383,7 @@ Coin.fromReader = function fromReader(br) {
|
||||
|
||||
Coin.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new Coin().fromRaw(data);
|
||||
};
|
||||
|
||||
|
||||
@ -114,7 +114,7 @@ Headers.fromReader = function fromReader(br) {
|
||||
|
||||
Headers.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new Headers().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -157,7 +157,7 @@ Headers.fromAbbrReader = function fromAbbrReader(br) {
|
||||
|
||||
Headers.fromAbbr = function fromAbbr(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new Headers().fromAbbr(data);
|
||||
};
|
||||
|
||||
@ -169,7 +169,7 @@ Headers.fromAbbr = function fromAbbr(data, enc) {
|
||||
|
||||
Headers.fromEntry = function fromEntry(entry) {
|
||||
var headers = new Headers(entry);
|
||||
headers._hash = new Buffer(entry.hash, 'hex');
|
||||
headers._hash = Buffer.from(entry.hash, 'hex');
|
||||
return headers;
|
||||
};
|
||||
|
||||
|
||||
@ -404,7 +404,7 @@ Input.fromReader = function fromReader(br) {
|
||||
|
||||
Input.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new Input().fromRaw(data);
|
||||
};
|
||||
|
||||
|
||||
@ -130,7 +130,7 @@ InvItem.fromReader = function fromReader(br) {
|
||||
|
||||
InvItem.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new InvItem().fromRaw(data);
|
||||
};
|
||||
|
||||
|
||||
@ -796,10 +796,10 @@ KeyRing.prototype.fromJSON = function fromJSON(json) {
|
||||
this.nework = Network.get(json.network);
|
||||
this.witness = json.witness;
|
||||
this.nested = json.nested;
|
||||
this.publicKey = new Buffer(json.publicKey, 'hex');
|
||||
this.publicKey = Buffer.from(json.publicKey, 'hex');
|
||||
|
||||
if (json.script)
|
||||
this.script = new Buffer(json.script, 'hex');
|
||||
this.script = Buffer.from(json.script, 'hex');
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
@ -13,7 +13,7 @@ var Block = require('./block');
|
||||
var Script = require('../script/script');
|
||||
var Headers = require('./headers');
|
||||
var BufferReader = require('../utils/reader');
|
||||
var DUMMY = new Buffer(0);
|
||||
var DUMMY = Buffer.alloc(0);
|
||||
|
||||
/**
|
||||
* A block object which is essentially a "placeholder"
|
||||
|
||||
@ -17,7 +17,7 @@ var StaticWriter = require('../utils/staticwriter');
|
||||
var encoding = require('../utils/encoding');
|
||||
var consensus = require('../protocol/consensus');
|
||||
var Headers = require('./headers');
|
||||
var DUMMY = new Buffer([0]);
|
||||
var DUMMY = Buffer.from([0]);
|
||||
|
||||
/**
|
||||
* Represents a merkle (filtered) block.
|
||||
@ -66,7 +66,7 @@ MerkleBlock.prototype.fromOptions = function fromOptions(options) {
|
||||
for (i = 0; i < options.hashes.length; i++) {
|
||||
hash = options.hashes[i];
|
||||
if (typeof hash === 'string')
|
||||
hash = new Buffer(hash, 'hex');
|
||||
hash = Buffer.from(hash, 'hex');
|
||||
this.hashes.push(hash);
|
||||
}
|
||||
}
|
||||
@ -262,7 +262,7 @@ MerkleBlock.prototype.extractTree = function extractTree() {
|
||||
height++;
|
||||
|
||||
if (height > 0)
|
||||
buf = new Buffer(64);
|
||||
buf = Buffer.allocUnsafe(64);
|
||||
|
||||
root = traverse(height, 0);
|
||||
|
||||
@ -427,7 +427,7 @@ MerkleBlock.fromReader = function fromReader(br) {
|
||||
|
||||
MerkleBlock.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new MerkleBlock().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -488,10 +488,10 @@ MerkleBlock.prototype.fromJSON = function fromJSON(json) {
|
||||
|
||||
for (i = 0; i < json.hashes.length; i++) {
|
||||
hash = util.revHex(json.hashes[i]);
|
||||
this.hashes.push(new Buffer(hash, 'hex'));
|
||||
this.hashes.push(Buffer.from(hash, 'hex'));
|
||||
}
|
||||
|
||||
this.flags = new Buffer(json.flags, 'hex');
|
||||
this.flags = Buffer.from(json.flags, 'hex');
|
||||
|
||||
this.totalTX = json.totalTX;
|
||||
|
||||
@ -629,11 +629,11 @@ MerkleBlock.fromMatches = function fromMatches(block, matches) {
|
||||
height++;
|
||||
|
||||
if (height > 0)
|
||||
buf = new Buffer(64);
|
||||
buf = Buffer.allocUnsafe(64);
|
||||
|
||||
traverse(height, 0, leaves, matches);
|
||||
|
||||
flags = new Buffer((bits.length + 7) / 8 | 0);
|
||||
flags = Buffer.allocUnsafe((bits.length + 7) / 8 | 0);
|
||||
flags.fill(0);
|
||||
|
||||
for (p = 0; p < bits.length; p++)
|
||||
|
||||
@ -1392,7 +1392,7 @@ MTX.fromReader = function fromReader(br) {
|
||||
|
||||
MTX.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new MTX().fromRaw(data);
|
||||
};
|
||||
|
||||
|
||||
@ -327,7 +327,7 @@ Output.fromReader = function fromReader(br) {
|
||||
|
||||
Output.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new Output().fromRaw(data);
|
||||
};
|
||||
|
||||
|
||||
@ -2270,7 +2270,7 @@ TX.fromJSON = function fromJSON(json) {
|
||||
|
||||
TX.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new TX().fromRaw(data);
|
||||
};
|
||||
|
||||
|
||||
@ -281,7 +281,7 @@ TXMeta.prototype.fromRaw = function fromRaw(data) {
|
||||
|
||||
TXMeta.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new TXMeta().fromRaw(data);
|
||||
};
|
||||
|
||||
|
||||
@ -298,21 +298,21 @@ exports.typesByVal = util.revMap(exports.types);
|
||||
* @const {Buffer}
|
||||
*/
|
||||
|
||||
exports.STACK_FALSE = new Buffer([]);
|
||||
exports.STACK_FALSE = Buffer.alloc(0);
|
||||
|
||||
/**
|
||||
* True stack return value.
|
||||
* @const {Buffer}
|
||||
*/
|
||||
|
||||
exports.STACK_TRUE = new Buffer([0x01]);
|
||||
exports.STACK_TRUE = Buffer.from([0x01]);
|
||||
|
||||
/**
|
||||
* -1 stack return value.
|
||||
* @const {Buffer}
|
||||
*/
|
||||
|
||||
exports.STACK_NEGATE = new Buffer([0x81]);
|
||||
exports.STACK_NEGATE = Buffer.from([0x81]);
|
||||
|
||||
/**
|
||||
* Test whether the data element is a ripemd160 hash.
|
||||
@ -720,10 +720,10 @@ exports.num = function num(value, flags, size) {
|
||||
* numbers to a little-endian buffer while taking into
|
||||
* account negative zero, minimaldata, etc.
|
||||
* @example
|
||||
* assert.deepEqual(Script.array(0), new Buffer(0));
|
||||
* assert.deepEqual(Script.array(0xffee), new Buffer('eeff00', 'hex'));
|
||||
* assert.deepEqual(Script.array(new BN(0xffee)), new Buffer('eeff00', 'hex'));
|
||||
* assert.deepEqual(Script.array(new BN(0x1e).ineg()), new Buffer('9e', 'hex'));
|
||||
* assert.deepEqual(Script.array(0), Buffer.alloc(0));
|
||||
* assert.deepEqual(Script.array(0xffee), Buffer.from('eeff00', 'hex'));
|
||||
* assert.deepEqual(Script.array(new BN(0xffee)), Buffer.from('eeff00', 'hex'));
|
||||
* assert.deepEqual(Script.array(new BN(0x1e).ineg()), Buffer.from('9e', 'hex'));
|
||||
* @param {Number|BN} value
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
@ -763,7 +763,7 @@ exports.array = function(value) {
|
||||
else if (neg)
|
||||
result[result.length - 1] |= 0x80;
|
||||
|
||||
return new Buffer(result);
|
||||
return Buffer.from(result);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -302,7 +302,7 @@ Opcode.fromSmall = function fromSmall(num) {
|
||||
|
||||
Opcode.fromString = function fromString(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
|
||||
return Opcode.fromData(data);
|
||||
};
|
||||
|
||||
@ -403,7 +403,7 @@ Script.prototype.toJSON = function toJSON() {
|
||||
|
||||
Script.prototype.fromJSON = function fromJSON(json) {
|
||||
assert(typeof json === 'string', 'Code must be a string.');
|
||||
return this.fromRaw(new Buffer(json, 'hex'));
|
||||
return this.fromRaw(Buffer.from(json, 'hex'));
|
||||
};
|
||||
|
||||
/**
|
||||
@ -667,7 +667,7 @@ Script.prototype.execute = function execute(stack, flags, tx, index, value, vers
|
||||
case opcodes.OP_14:
|
||||
case opcodes.OP_15:
|
||||
case opcodes.OP_16: {
|
||||
stack.push(new Buffer([op - 0x50]));
|
||||
stack.push(Buffer.from([op - 0x50]));
|
||||
break;
|
||||
}
|
||||
case opcodes.OP_NOP: {
|
||||
@ -1391,14 +1391,14 @@ Script.prototype.execute = function execute(stack, flags, tx, index, value, vers
|
||||
v2 = stack.top(-1);
|
||||
|
||||
if (v1.length < v2.length) {
|
||||
v3 = new Buffer(v2.length);
|
||||
v3 = Buffer.allocUnsafe(v2.length);
|
||||
v3.fill(0);
|
||||
v1.copy(v3, 0);
|
||||
v1 = v3;
|
||||
}
|
||||
|
||||
if (v2.length < v1.length) {
|
||||
v3 = new Buffer(v1.length);
|
||||
v3 = Buffer.allocUnsafe(v1.length);
|
||||
v3.fill(0);
|
||||
v2.copy(v3, 0);
|
||||
v2 = v3;
|
||||
@ -1478,10 +1478,10 @@ Script.num = function num(value, flags, size) {
|
||||
* numbers to a little-endian buffer while taking into
|
||||
* account negative zero, minimaldata, etc.
|
||||
* @example
|
||||
* assert.deepEqual(Script.array(0), new Buffer(0));
|
||||
* assert.deepEqual(Script.array(0xffee), new Buffer('eeff00', 'hex'));
|
||||
* assert.deepEqual(Script.array(new BN(0xffee)), new Buffer('eeff00', 'hex'));
|
||||
* assert.deepEqual(Script.array(new BN(0x1e).ineg()), new Buffer('9e', 'hex'));
|
||||
* assert.deepEqual(Script.array(0), Buffer.alloc(0));
|
||||
* assert.deepEqual(Script.array(0xffee), Buffer.from('eeff00', 'hex'));
|
||||
* assert.deepEqual(Script.array(new BN(0xffee)), Buffer.from('eeff00', 'hex'));
|
||||
* assert.deepEqual(Script.array(new BN(0x1e).ineg()), Buffer.from('9e', 'hex'));
|
||||
* @param {Number|BN} value
|
||||
* @returns {Buffer}
|
||||
*/
|
||||
@ -1645,7 +1645,7 @@ Script.isCode = function isCode(raw) {
|
||||
Script.prototype.fromPubkey = function fromPubkey(key) {
|
||||
assert(Buffer.isBuffer(key) && key.length >= 33 && key.length <= 65);
|
||||
|
||||
this.raw = new Buffer(1 + key.length + 1);
|
||||
this.raw = Buffer.allocUnsafe(1 + key.length + 1);
|
||||
this.raw[0] = key.length;
|
||||
key.copy(this.raw, 1);
|
||||
this.raw[1 + key.length] = opcodes.OP_CHECKSIG;
|
||||
@ -1677,7 +1677,7 @@ Script.fromPubkey = function fromPubkey(key) {
|
||||
Script.prototype.fromPubkeyhash = function fromPubkeyhash(hash) {
|
||||
assert(Buffer.isBuffer(hash) && hash.length === 20);
|
||||
|
||||
this.raw = new Buffer(25);
|
||||
this.raw = Buffer.allocUnsafe(25);
|
||||
this.raw[0] = opcodes.OP_DUP;
|
||||
this.raw[1] = opcodes.OP_HASH160;
|
||||
this.raw[2] = 0x14;
|
||||
@ -1759,7 +1759,7 @@ Script.fromMultisig = function fromMultisig(m, n, keys) {
|
||||
Script.prototype.fromScripthash = function fromScripthash(hash) {
|
||||
assert(Buffer.isBuffer(hash) && hash.length === 20);
|
||||
|
||||
this.raw = new Buffer(23);
|
||||
this.raw = Buffer.allocUnsafe(23);
|
||||
this.raw[0] = opcodes.OP_HASH160;
|
||||
this.raw[1] = 0x14;
|
||||
hash.copy(this.raw, 2);
|
||||
@ -1824,7 +1824,7 @@ Script.prototype.fromProgram = function fromProgram(version, data) {
|
||||
|
||||
op = Opcode.fromSmall(version);
|
||||
|
||||
this.raw = new Buffer(2 + data.length);
|
||||
this.raw = Buffer.allocUnsafe(2 + data.length);
|
||||
this.raw[0] = op.value;
|
||||
this.raw[1] = data.length;
|
||||
data.copy(this.raw, 2);
|
||||
@ -3141,7 +3141,7 @@ Script.prototype.fromString = function fromString(code) {
|
||||
assert(op.indexOf('0x') === 0, 'Unknown opcode.');
|
||||
op = op.substring(2);
|
||||
assert(util.isHex(op), 'Unknown opcode.');
|
||||
op = new Buffer(op, 'hex');
|
||||
op = Buffer.from(op, 'hex');
|
||||
bw.writeBytes(op);
|
||||
continue;
|
||||
}
|
||||
@ -3607,7 +3607,7 @@ Script.fromReader = function fromReader(br) {
|
||||
|
||||
Script.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new Script().fromRaw(data);
|
||||
};
|
||||
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
|
||||
var assert = require('assert');
|
||||
var ScriptError = require('./common').ScriptError;
|
||||
var EMPTY_ARRAY = new Buffer(0);
|
||||
var EMPTY_ARRAY = Buffer.alloc(0);
|
||||
|
||||
/**
|
||||
* ScriptNum
|
||||
@ -360,7 +360,7 @@ ScriptNum.prototype.toRaw = function toRaw() {
|
||||
}
|
||||
|
||||
// Write number.
|
||||
data = new Buffer(size + offset);
|
||||
data = Buffer.allocUnsafe(size + offset);
|
||||
|
||||
switch (size) {
|
||||
case 6:
|
||||
|
||||
@ -402,7 +402,7 @@ Witness.prototype.toJSON = function toJSON() {
|
||||
|
||||
Witness.prototype.fromJSON = function fromJSON(json) {
|
||||
assert(typeof json === 'string', 'Witness must be a string.');
|
||||
return this.fromRaw(new Buffer(json, 'hex'));
|
||||
return this.fromRaw(Buffer.from(json, 'hex'));
|
||||
};
|
||||
|
||||
/**
|
||||
@ -564,7 +564,7 @@ Witness.encodeItem = function encodeItem(data) {
|
||||
return STACK_FALSE;
|
||||
|
||||
if (data >= opcodes.OP_1 && data <= opcodes.OP_16)
|
||||
return new Buffer([data - 0x50]);
|
||||
return Buffer.from([data - 0x50]);
|
||||
|
||||
throw new Error('Non-push opcode in witness.');
|
||||
}
|
||||
@ -573,7 +573,7 @@ Witness.encodeItem = function encodeItem(data) {
|
||||
return common.array(data);
|
||||
|
||||
if (typeof data === 'string')
|
||||
return new Buffer(data, 'utf8');
|
||||
return Buffer.from(data, 'utf8');
|
||||
|
||||
return data;
|
||||
};
|
||||
@ -622,7 +622,7 @@ Witness.fromReader = function fromReader(br) {
|
||||
|
||||
Witness.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new Witness().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -647,7 +647,7 @@ Witness.prototype.fromString = function fromString(items) {
|
||||
}
|
||||
|
||||
for (i = 0; i < items.length; i++)
|
||||
this.items.push(new Buffer(items[i], 'hex'));
|
||||
this.items.push(Buffer.from(items[i], 'hex'));
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
@ -252,7 +252,7 @@ ASN1.alignBitstr = function(data) {
|
||||
if (shift === 8 || buf.length === 0)
|
||||
return buf;
|
||||
|
||||
out = new Buffer(buf.length);
|
||||
out = Buffer.allocUnsafe(buf.length);
|
||||
out[0] = buf[0] >>> shift;
|
||||
|
||||
for (i = 1; i < buf.length; i++) {
|
||||
|
||||
@ -78,7 +78,7 @@ exports.encode = function(data) {
|
||||
*/
|
||||
|
||||
exports.decode = function decode(str) {
|
||||
var data = new Buffer(str.length * 5 / 8 | 0);
|
||||
var data = Buffer.allocUnsafe(str.length * 5 / 8 | 0);
|
||||
var mode = 0;
|
||||
var left = 0;
|
||||
var j = 0;
|
||||
|
||||
@ -47,7 +47,7 @@ exports.encode = function encode(data) {
|
||||
zeroes++;
|
||||
}
|
||||
|
||||
b58 = new Buffer(((data.length * 138 / 100) | 0) + 1);
|
||||
b58 = Buffer.allocUnsafe(((data.length * 138 / 100) | 0) + 1);
|
||||
b58.fill(0);
|
||||
|
||||
for (; i < data.length; i++) {
|
||||
@ -102,7 +102,7 @@ exports.decode = function decode(str) {
|
||||
zeroes++;
|
||||
}
|
||||
|
||||
b256 = new Buffer(((str.length * 733) / 1000 | 0) + 1);
|
||||
b256 = Buffer.allocUnsafe(((str.length * 733) / 1000 | 0) + 1);
|
||||
b256.fill(0);
|
||||
|
||||
for (; i < str.length; i++) {
|
||||
@ -129,7 +129,7 @@ exports.decode = function decode(str) {
|
||||
while (i < b256.length && b256[i] === 0)
|
||||
i++;
|
||||
|
||||
out = new Buffer(zeroes + (b256.length - i));
|
||||
out = Buffer.allocUnsafe(zeroes + (b256.length - i));
|
||||
|
||||
for (j = 0; j < zeroes; j++)
|
||||
out[j] = 0;
|
||||
|
||||
@ -35,7 +35,7 @@ var native = require('./native').binding;
|
||||
* @module utils/bech32
|
||||
*/
|
||||
|
||||
var POOL65 = new Buffer(65);
|
||||
var POOL65 = Buffer.allocUnsafe(65);
|
||||
var CHARSET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l';
|
||||
var TABLE = [
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
@ -147,7 +147,7 @@ function deserialize(str) {
|
||||
throw new Error('Invalid bech32 data length.');
|
||||
|
||||
dlen -= 6;
|
||||
data = new Buffer(dlen);
|
||||
data = Buffer.allocUnsafe(dlen);
|
||||
|
||||
for (i = 0; i < hlen; i++) {
|
||||
ch = str.charCodeAt(i);
|
||||
|
||||
@ -14,7 +14,7 @@ var StaticWriter = require('./staticwriter');
|
||||
var encoding = require('./encoding');
|
||||
var sum32 = murmur3.sum32;
|
||||
var mul32 = murmur3.mul32;
|
||||
var DUMMY = new Buffer(0);
|
||||
var DUMMY = Buffer.alloc(0);
|
||||
|
||||
/*
|
||||
* Constants
|
||||
@ -125,7 +125,7 @@ Bloom.prototype.fromOptions = function fromOptions(size, n, tweak, update) {
|
||||
|
||||
size -= size % 8;
|
||||
|
||||
filter = new Buffer(size / 8);
|
||||
filter = Buffer.allocUnsafe(size / 8);
|
||||
filter.fill(0);
|
||||
|
||||
if (tweak == null || tweak === -1)
|
||||
@ -197,7 +197,7 @@ Bloom.prototype.add = function add(val, enc) {
|
||||
var i, index;
|
||||
|
||||
if (typeof val === 'string')
|
||||
val = new Buffer(val, enc);
|
||||
val = Buffer.from(val, enc);
|
||||
|
||||
for (i = 0; i < this.n; i++) {
|
||||
index = this.hash(val, i);
|
||||
@ -216,7 +216,7 @@ Bloom.prototype.test = function test(val, enc) {
|
||||
var i, index;
|
||||
|
||||
if (typeof val === 'string')
|
||||
val = new Buffer(val, enc);
|
||||
val = Buffer.from(val, enc);
|
||||
|
||||
for (i = 0; i < this.n; i++) {
|
||||
index = this.hash(val, i);
|
||||
@ -240,7 +240,7 @@ Bloom.prototype.added = function added(val, enc) {
|
||||
var i, index;
|
||||
|
||||
if (typeof val === 'string')
|
||||
val = new Buffer(val, enc);
|
||||
val = Buffer.from(val, enc);
|
||||
|
||||
for (i = 0; i < this.n; i++) {
|
||||
index = this.hash(val, i);
|
||||
@ -380,7 +380,7 @@ Bloom.fromReader = function fromReader(br) {
|
||||
|
||||
Bloom.fromRaw = function fromRaw(data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc);
|
||||
data = Buffer.from(data, enc);
|
||||
return new Bloom().fromRaw(data);
|
||||
};
|
||||
|
||||
@ -442,7 +442,7 @@ RollingFilter.prototype.fromRate = function fromRate(items, rate) {
|
||||
|
||||
tweak = (Math.random() * 0x100000000) >>> 0;
|
||||
|
||||
filter = new Buffer(items * 8);
|
||||
filter = Buffer.allocUnsafe(items * 8);
|
||||
filter.fill(0);
|
||||
|
||||
this.n = n;
|
||||
@ -501,7 +501,7 @@ RollingFilter.prototype.add = function add(val, enc) {
|
||||
var m1, m2, v1, v2, mhi, mlo;
|
||||
|
||||
if (typeof val === 'string')
|
||||
val = new Buffer(val, enc);
|
||||
val = Buffer.from(val, enc);
|
||||
|
||||
if (this.entries === this.limit) {
|
||||
this.entries = 0;
|
||||
@ -565,7 +565,7 @@ RollingFilter.prototype.test = function test(val, enc) {
|
||||
return false;
|
||||
|
||||
if (typeof val === 'string')
|
||||
val = new Buffer(val, enc);
|
||||
val = Buffer.from(val, enc);
|
||||
|
||||
for (i = 0; i < this.n; i++) {
|
||||
hash = this.hash(val, i);
|
||||
@ -599,7 +599,7 @@ RollingFilter.prototype.test = function test(val, enc) {
|
||||
|
||||
RollingFilter.prototype.added = function added(val, enc) {
|
||||
if (typeof val === 'string')
|
||||
val = new Buffer(val, enc);
|
||||
val = Buffer.from(val, enc);
|
||||
|
||||
if (!this.test(val)) {
|
||||
this.add(val);
|
||||
|
||||
@ -51,7 +51,7 @@ encoding.MAX_SAFE_ADDITION = 0xfffffffffffff;
|
||||
* @default
|
||||
*/
|
||||
|
||||
encoding.DUMMY = new Buffer([0]);
|
||||
encoding.DUMMY = Buffer.from([0]);
|
||||
|
||||
/**
|
||||
* A hash of all zeroes with a `1` at the
|
||||
@ -60,7 +60,7 @@ encoding.DUMMY = new Buffer([0]);
|
||||
* @default
|
||||
*/
|
||||
|
||||
encoding.ONE_HASH = new Buffer(
|
||||
encoding.ONE_HASH = Buffer.from(
|
||||
'0100000000000000000000000000000000000000000000000000000000000000',
|
||||
'hex'
|
||||
);
|
||||
@ -71,7 +71,7 @@ encoding.ONE_HASH = new Buffer(
|
||||
* @default
|
||||
*/
|
||||
|
||||
encoding.ZERO_HASH = new Buffer(
|
||||
encoding.ZERO_HASH = Buffer.from(
|
||||
'0000000000000000000000000000000000000000000000000000000000000000',
|
||||
'hex'
|
||||
);
|
||||
@ -82,7 +82,7 @@ encoding.ZERO_HASH = new Buffer(
|
||||
* @default
|
||||
*/
|
||||
|
||||
encoding.MAX_HASH = new Buffer(
|
||||
encoding.MAX_HASH = Buffer.from(
|
||||
'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
||||
'hex'
|
||||
);
|
||||
@ -111,7 +111,7 @@ encoding.HIGH_HASH =
|
||||
* @default
|
||||
*/
|
||||
|
||||
encoding.ZERO_HASH160 = new Buffer(
|
||||
encoding.ZERO_HASH160 = Buffer.from(
|
||||
'0000000000000000000000000000000000000000',
|
||||
'hex'
|
||||
);
|
||||
@ -122,7 +122,7 @@ encoding.ZERO_HASH160 = new Buffer(
|
||||
* @default
|
||||
*/
|
||||
|
||||
encoding.MAX_HASH160 = new Buffer(
|
||||
encoding.MAX_HASH160 = Buffer.from(
|
||||
'ffffffffffffffffffffffffffffffffffffffff',
|
||||
'hex'
|
||||
);
|
||||
@ -149,7 +149,7 @@ encoding.HIGH_HASH160 = 'ffffffffffffffffffffffffffffffffffffffff';
|
||||
* @default
|
||||
*/
|
||||
|
||||
encoding.ZERO_KEY = new Buffer(
|
||||
encoding.ZERO_KEY = Buffer.from(
|
||||
'000000000000000000000000000000000000000000000000000000000000000000',
|
||||
'hex'
|
||||
);
|
||||
@ -160,7 +160,7 @@ encoding.ZERO_KEY = new Buffer(
|
||||
* @default
|
||||
*/
|
||||
|
||||
encoding.ZERO_SIG = new Buffer(''
|
||||
encoding.ZERO_SIG = Buffer.from(''
|
||||
+ '0000000000000000000000000000000000000000000000000000000000000000'
|
||||
+ '0000000000000000000000000000000000000000000000000000000000000000'
|
||||
+ '000000000000000000',
|
||||
@ -173,7 +173,7 @@ encoding.ZERO_SIG = new Buffer(''
|
||||
* @default
|
||||
*/
|
||||
|
||||
encoding.ZERO_SIG64 = new Buffer(''
|
||||
encoding.ZERO_SIG64 = Buffer.from(''
|
||||
+ '0000000000000000000000000000000000000000000000000000000000000000'
|
||||
+ '0000000000000000000000000000000000000000000000000000000000000000',
|
||||
'hex'
|
||||
@ -185,7 +185,7 @@ encoding.ZERO_SIG64 = new Buffer(''
|
||||
* @default
|
||||
*/
|
||||
|
||||
encoding.ZERO_U32 = new Buffer('00000000', 'hex');
|
||||
encoding.ZERO_U32 = Buffer.from('00000000', 'hex');
|
||||
|
||||
/**
|
||||
* 8 zero bytes.
|
||||
@ -193,7 +193,7 @@ encoding.ZERO_U32 = new Buffer('00000000', 'hex');
|
||||
* @default
|
||||
*/
|
||||
|
||||
encoding.ZERO_U64 = new Buffer('0000000000000000', 'hex');
|
||||
encoding.ZERO_U64 = Buffer.from('0000000000000000', 'hex');
|
||||
|
||||
/**
|
||||
* Read uint64 as a js number.
|
||||
@ -987,7 +987,7 @@ encoding.sizeVarint2BN = function sizeVarint2BN(num) {
|
||||
*/
|
||||
|
||||
encoding.U8 = function U8(num) {
|
||||
var data = new Buffer(1);
|
||||
var data = Buffer.allocUnsafe(1);
|
||||
data[0] = num >>> 0;
|
||||
return data;
|
||||
};
|
||||
@ -999,7 +999,7 @@ encoding.U8 = function U8(num) {
|
||||
*/
|
||||
|
||||
encoding.U32 = function U32(num) {
|
||||
var data = new Buffer(4);
|
||||
var data = Buffer.allocUnsafe(4);
|
||||
data.writeUInt32LE(num, 0, true);
|
||||
return data;
|
||||
};
|
||||
@ -1011,7 +1011,7 @@ encoding.U32 = function U32(num) {
|
||||
*/
|
||||
|
||||
encoding.U32BE = function U32BE(num) {
|
||||
var data = new Buffer(4);
|
||||
var data = Buffer.allocUnsafe(4);
|
||||
data.writeUInt32BE(num, 0, true);
|
||||
return data;
|
||||
};
|
||||
|
||||
@ -25,13 +25,13 @@ var IP = exports;
|
||||
* Constants
|
||||
*/
|
||||
|
||||
var ZERO_IP = new Buffer('00000000000000000000000000000000', 'hex');
|
||||
var LOCAL_IP = new Buffer('00000000000000000000000000000001', 'hex');
|
||||
var RFC6052 = new Buffer('0064ff9b0000000000000000', 'hex');
|
||||
var RFC4862 = new Buffer('fe80000000000000', 'hex');
|
||||
var RFC6145 = new Buffer('0000000000000000ffff0000', 'hex');
|
||||
var TOR_ONION = new Buffer('fd87d87eeb43', 'hex');
|
||||
var SHIFTED = new Buffer('00000000000000ffff', 'hex');
|
||||
var ZERO_IP = Buffer.from('00000000000000000000000000000000', 'hex');
|
||||
var LOCAL_IP = Buffer.from('00000000000000000000000000000001', 'hex');
|
||||
var RFC6052 = Buffer.from('0064ff9b0000000000000000', 'hex');
|
||||
var RFC4862 = Buffer.from('fe80000000000000', 'hex');
|
||||
var RFC6145 = Buffer.from('0000000000000000ffff0000', 'hex');
|
||||
var TOR_ONION = Buffer.from('fd87d87eeb43', 'hex');
|
||||
var SHIFTED = Buffer.from('00000000000000ffff', 'hex');
|
||||
|
||||
var IPV4_REGEX = /^(\d{1,3}\.){3}\d{1,3}$/;
|
||||
var IPV6_REGEX =
|
||||
@ -273,7 +273,7 @@ IP.isMapped = function isMapped(raw) {
|
||||
*/
|
||||
|
||||
IP.toBuffer = function toBuffer(str) {
|
||||
var raw = new Buffer(16);
|
||||
var raw = Buffer.allocUnsafe(16);
|
||||
var data;
|
||||
|
||||
assert(typeof str === 'string');
|
||||
|
||||
@ -35,7 +35,7 @@ PEM.parse = function parse(pem) {
|
||||
if (s = /^-----END ([^\-]+)-----/.exec(pem)) {
|
||||
pem = pem.substring(s[0].length);
|
||||
assert(tag === s[1], 'Tag mismatch.');
|
||||
buf = new Buffer(buf, 'base64');
|
||||
buf = Buffer.from(buf, 'base64');
|
||||
type = tag.split(' ')[0].toLowerCase();
|
||||
chunks.push({ tag: tag, type: type, data: buf });
|
||||
buf = '';
|
||||
|
||||
@ -198,7 +198,7 @@ ProtoWriter.prototype.writeVarint = function writeVarint(num) {
|
||||
this.writeU8(value);
|
||||
break;
|
||||
default:
|
||||
value = new Buffer(size);
|
||||
value = Buffer.allocUnsafe(size);
|
||||
exports.writeVarint(value, num, 0);
|
||||
this.writeBytes(value);
|
||||
break;
|
||||
@ -230,7 +230,7 @@ ProtoWriter.prototype.writeFieldBytes = function writeFieldBytes(tag, data) {
|
||||
|
||||
ProtoWriter.prototype.writeFieldString = function writeFieldString(tag, data, enc) {
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, enc || 'utf8');
|
||||
data = Buffer.from(data, enc || 'utf8');
|
||||
this.writeFieldBytes(tag, data);
|
||||
};
|
||||
|
||||
|
||||
@ -138,7 +138,7 @@ BufferReader.prototype.endData = function endData(zeroCopy) {
|
||||
if (this.zeroCopy || zeroCopy)
|
||||
return data.slice(start, end);
|
||||
|
||||
ret = new Buffer(size);
|
||||
ret = Buffer.allocUnsafe(size);
|
||||
data.copy(ret, 0, start, end);
|
||||
|
||||
return ret;
|
||||
@ -584,7 +584,7 @@ BufferReader.prototype.readBytes = function readBytes(size, zeroCopy) {
|
||||
if (this.zeroCopy || zeroCopy) {
|
||||
ret = this.data.slice(this.offset, this.offset + size);
|
||||
} else {
|
||||
ret = new Buffer(size);
|
||||
ret = Buffer.allocUnsafe(size);
|
||||
this.data.copy(ret, 0, this.offset, this.offset + size);
|
||||
}
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ function StaticWriter(size) {
|
||||
if (!(this instanceof StaticWriter))
|
||||
return new StaticWriter(size);
|
||||
|
||||
this.data = new Buffer(size);
|
||||
this.data = Buffer.allocUnsafe(size);
|
||||
this.written = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -88,7 +88,7 @@ util.nop = function() {};
|
||||
*/
|
||||
|
||||
util.copy = function copy(data) {
|
||||
var clone = new Buffer(data.length);
|
||||
var clone = Buffer.allocUnsafe(data.length);
|
||||
data.copy(clone, 0, 0, data.length);
|
||||
return clone;
|
||||
};
|
||||
@ -101,7 +101,7 @@ util.copy = function copy(data) {
|
||||
*/
|
||||
|
||||
util.concat = function concat(a, b) {
|
||||
var data = new Buffer(a.length + b.length);
|
||||
var data = Buffer.allocUnsafe(a.length + b.length);
|
||||
a.copy(data, 0);
|
||||
b.copy(data, a.length);
|
||||
return data;
|
||||
@ -575,14 +575,14 @@ util.nonce = function _nonce(size) {
|
||||
|
||||
switch (size) {
|
||||
case 8:
|
||||
nonce = new Buffer(8);
|
||||
nonce = Buffer.allocUnsafe(8);
|
||||
n = util.random(0, 0x100000000);
|
||||
nonce.writeUInt32LE(n, 0, true);
|
||||
n = util.random(0, 0x100000000);
|
||||
nonce.writeUInt32LE(n, 4, true);
|
||||
break;
|
||||
case 4:
|
||||
nonce = new Buffer(4);
|
||||
nonce = Buffer.allocUnsafe(4);
|
||||
n = util.random(0, 0x100000000);
|
||||
nonce.writeUInt32LE(n, 0, true);
|
||||
break;
|
||||
|
||||
@ -490,7 +490,7 @@ Validator.prototype.buf = function buf(key, fallback, enc) {
|
||||
return value;
|
||||
}
|
||||
|
||||
data = new Buffer(value, enc);
|
||||
data = Buffer.from(value, enc);
|
||||
|
||||
if (data.length !== Buffer.byteLength(value, enc))
|
||||
throw new ValidationError(fmt(key) + ' must be a ' + enc + ' string.');
|
||||
|
||||
@ -70,7 +70,7 @@ function BufferWriter() {
|
||||
*/
|
||||
|
||||
BufferWriter.prototype.render = function render(keep) {
|
||||
var data = new Buffer(this.written);
|
||||
var data = Buffer.allocUnsafe(this.written);
|
||||
var off = 0;
|
||||
var i, op;
|
||||
|
||||
|
||||
@ -338,7 +338,7 @@ function parseEntry(data, enc) {
|
||||
var br, block, hash, height;
|
||||
|
||||
if (typeof data === 'string')
|
||||
data = new Buffer(data, 'hex');
|
||||
data = Buffer.from(data, 'hex');
|
||||
|
||||
block = Headers.fromAbbr(data);
|
||||
|
||||
|
||||
@ -1088,12 +1088,12 @@ HTTPOptions.fromOptions = function fromOptions(options) {
|
||||
|
||||
function hash256(data) {
|
||||
if (typeof data !== 'string')
|
||||
return new Buffer(0);
|
||||
return Buffer.alloc(0);
|
||||
|
||||
if (data.length > 200)
|
||||
return new Buffer(0);
|
||||
return Buffer.alloc(0);
|
||||
|
||||
return crypto.hash256(new Buffer(data, 'utf8'));
|
||||
return crypto.hash256(Buffer.from(data, 'utf8'));
|
||||
}
|
||||
|
||||
function enforce(value, msg) {
|
||||
|
||||
@ -28,7 +28,7 @@ var layouts = exports;
|
||||
layouts.walletdb = {
|
||||
binary: true,
|
||||
p: function p(hash) {
|
||||
var key = new Buffer(1 + (hash.length / 2));
|
||||
var key = Buffer.allocUnsafe(1 + (hash.length / 2));
|
||||
key[0] = 0x70;
|
||||
key.write(hash, 1, 'hex');
|
||||
return key;
|
||||
@ -37,7 +37,7 @@ layouts.walletdb = {
|
||||
return key.toString('hex', 1);
|
||||
},
|
||||
P: function P(wid, hash) {
|
||||
var key = new Buffer(1 + 4 + (hash.length / 2));
|
||||
var key = Buffer.allocUnsafe(1 + 4 + (hash.length / 2));
|
||||
key[0] = 0x50;
|
||||
key.writeUInt32BE(wid, 1, true);
|
||||
key.write(hash, 5, 'hex');
|
||||
@ -47,7 +47,7 @@ layouts.walletdb = {
|
||||
return key.toString('hex', 5);
|
||||
},
|
||||
r: function r(wid, index, hash) {
|
||||
var key = new Buffer(1 + 4 + 4 + (hash.length / 2));
|
||||
var key = Buffer.allocUnsafe(1 + 4 + 4 + (hash.length / 2));
|
||||
key[0] = 0x72;
|
||||
key.writeUInt32BE(wid, 1, true);
|
||||
key.writeUInt32BE(index, 5, true);
|
||||
@ -58,7 +58,7 @@ layouts.walletdb = {
|
||||
return key.toString('hex', 9);
|
||||
},
|
||||
w: function w(wid) {
|
||||
var key = new Buffer(5);
|
||||
var key = Buffer.allocUnsafe(5);
|
||||
key[0] = 0x77;
|
||||
key.writeUInt32BE(wid, 1, true);
|
||||
return key;
|
||||
@ -68,7 +68,7 @@ layouts.walletdb = {
|
||||
},
|
||||
l: function l(id) {
|
||||
var len = Buffer.byteLength(id, 'ascii');
|
||||
var key = new Buffer(1 + len);
|
||||
var key = Buffer.allocUnsafe(1 + len);
|
||||
key[0] = 0x6c;
|
||||
if (len > 0)
|
||||
key.write(id, 1, 'ascii');
|
||||
@ -78,7 +78,7 @@ layouts.walletdb = {
|
||||
return key.toString('ascii', 1);
|
||||
},
|
||||
a: function a(wid, index) {
|
||||
var key = new Buffer(9);
|
||||
var key = Buffer.allocUnsafe(9);
|
||||
key[0] = 0x61;
|
||||
key.writeUInt32BE(wid, 1, true);
|
||||
key.writeUInt32BE(index, 5, true);
|
||||
@ -86,7 +86,7 @@ layouts.walletdb = {
|
||||
},
|
||||
i: function i(wid, name) {
|
||||
var len = Buffer.byteLength(name, 'ascii');
|
||||
var key = new Buffer(5 + len);
|
||||
var key = Buffer.allocUnsafe(5 + len);
|
||||
key[0] = 0x69;
|
||||
key.writeUInt32BE(wid, 1, true);
|
||||
if (len > 0)
|
||||
@ -97,21 +97,21 @@ layouts.walletdb = {
|
||||
return [key.readUInt32BE(1, true), key.toString('ascii', 5)];
|
||||
},
|
||||
n: function n(wid, index) {
|
||||
var key = new Buffer(9);
|
||||
var key = Buffer.allocUnsafe(9);
|
||||
key[0] = 0x6e;
|
||||
key.writeUInt32BE(wid, 1, true);
|
||||
key.writeUInt32BE(index, 5, true);
|
||||
return key;
|
||||
},
|
||||
R: new Buffer([0x52]),
|
||||
R: Buffer.from([0x52]),
|
||||
h: function h(height) {
|
||||
var key = new Buffer(5);
|
||||
var key = Buffer.allocUnsafe(5);
|
||||
key[0] = 0x68;
|
||||
key.writeUInt32BE(height, 1, true);
|
||||
return key;
|
||||
},
|
||||
b: function b(height) {
|
||||
var key = new Buffer(5);
|
||||
var key = Buffer.allocUnsafe(5);
|
||||
key[0] = 0x62;
|
||||
key.writeUInt32BE(height, 1, true);
|
||||
return key;
|
||||
@ -120,7 +120,7 @@ layouts.walletdb = {
|
||||
return key.readUInt32BE(1, true);
|
||||
},
|
||||
o: function o(hash, index) {
|
||||
var key = new Buffer(37);
|
||||
var key = Buffer.allocUnsafe(37);
|
||||
key[0] = 0x6f;
|
||||
key.write(hash, 1, 'hex');
|
||||
key.writeUInt32BE(index, 33, true);
|
||||
@ -152,7 +152,7 @@ layouts.walletdb = {
|
||||
layouts.txdb = {
|
||||
binary: true,
|
||||
prefix: function prefix(wid, key) {
|
||||
var out = new Buffer(5 + key.length);
|
||||
var out = Buffer.allocUnsafe(5 + key.length);
|
||||
out[0] = 0x74;
|
||||
out.writeUInt32BE(wid, 1);
|
||||
key.copy(out, 5);
|
||||
@ -161,9 +161,9 @@ layouts.txdb = {
|
||||
pre: function prefix(key) {
|
||||
return key.readUInt32BE(1, true);
|
||||
},
|
||||
R: new Buffer([0x52]),
|
||||
R: Buffer.from([0x52]),
|
||||
hi: function hi(ch, hash, index) {
|
||||
var key = new Buffer(37);
|
||||
var key = Buffer.allocUnsafe(37);
|
||||
key[0] = ch;
|
||||
key.write(hash, 1, 'hex');
|
||||
key.writeUInt32BE(index, 33, true);
|
||||
@ -174,7 +174,7 @@ layouts.txdb = {
|
||||
return [key.toString('hex', 0, 32), key.readUInt32BE(32, true)];
|
||||
},
|
||||
ih: function ih(ch, index, hash) {
|
||||
var key = new Buffer(37);
|
||||
var key = Buffer.allocUnsafe(37);
|
||||
key[0] = ch;
|
||||
key.writeUInt32BE(index, 1, true);
|
||||
key.write(hash, 5, 'hex');
|
||||
@ -185,7 +185,7 @@ layouts.txdb = {
|
||||
return [key.readUInt32BE(0, true), key.toString('hex', 4, 36)];
|
||||
},
|
||||
iih: function iih(ch, index, num, hash) {
|
||||
var key = new Buffer(41);
|
||||
var key = Buffer.allocUnsafe(41);
|
||||
key[0] = ch;
|
||||
key.writeUInt32BE(index, 1, true);
|
||||
key.writeUInt32BE(num, 5, true);
|
||||
@ -201,7 +201,7 @@ layouts.txdb = {
|
||||
];
|
||||
},
|
||||
ihi: function ihi(ch, index, hash, num) {
|
||||
var key = new Buffer(41);
|
||||
var key = Buffer.allocUnsafe(41);
|
||||
key[0] = ch;
|
||||
key.writeUInt32BE(index, 1, true);
|
||||
key.write(hash, 5, 'hex');
|
||||
@ -217,7 +217,7 @@ layouts.txdb = {
|
||||
];
|
||||
},
|
||||
ha: function ha(ch, hash) {
|
||||
var key = new Buffer(33);
|
||||
var key = Buffer.allocUnsafe(33);
|
||||
key[0] = ch;
|
||||
key.write(hash, 1, 'hex');
|
||||
return key;
|
||||
@ -302,7 +302,7 @@ layouts.txdb = {
|
||||
return this.ha(0x72, hash);
|
||||
},
|
||||
b: function b(height) {
|
||||
var key = new Buffer(5);
|
||||
var key = Buffer.allocUnsafe(5);
|
||||
key[0] = 0x62;
|
||||
key.writeUInt32BE(height, 1, true);
|
||||
return key;
|
||||
|
||||
@ -56,7 +56,7 @@ function MasterKey(options) {
|
||||
* @default
|
||||
*/
|
||||
|
||||
MasterKey.SALT = new Buffer('bcoin', 'ascii');
|
||||
MasterKey.SALT = Buffer.from('bcoin', 'ascii');
|
||||
|
||||
/**
|
||||
* Key derivation algorithms.
|
||||
@ -256,7 +256,7 @@ MasterKey.prototype.derive = co(function* derive(passwd) {
|
||||
var p = this.p;
|
||||
|
||||
if (typeof passwd === 'string')
|
||||
passwd = new Buffer(passwd, 'utf8');
|
||||
passwd = Buffer.from(passwd, 'utf8');
|
||||
|
||||
switch (this.alg) {
|
||||
case MasterKey.alg.PBKDF2:
|
||||
@ -280,7 +280,7 @@ MasterKey.prototype.encipher = function encipher(data, iv) {
|
||||
return;
|
||||
|
||||
if (typeof iv === 'string')
|
||||
iv = new Buffer(iv, 'hex');
|
||||
iv = Buffer.from(iv, 'hex');
|
||||
|
||||
return crypto.encipher(data, this.aesKey, iv.slice(0, 16));
|
||||
};
|
||||
@ -297,7 +297,7 @@ MasterKey.prototype.decipher = function decipher(data, iv) {
|
||||
return;
|
||||
|
||||
if (typeof iv === 'string')
|
||||
iv = new Buffer(iv, 'hex');
|
||||
iv = Buffer.from(iv, 'hex');
|
||||
|
||||
return crypto.decipher(data, this.aesKey, iv.slice(0, 16));
|
||||
};
|
||||
|
||||
@ -125,7 +125,7 @@ BlockMeta.prototype.clone = function clone() {
|
||||
*/
|
||||
|
||||
BlockMeta.prototype.toHash = function toHash() {
|
||||
return new Buffer(this.hash, 'hex');
|
||||
return Buffer.from(this.hash, 'hex');
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -1489,7 +1489,7 @@ RPC.prototype.signMessage = co(function* signMessage(args, help) {
|
||||
if (!wallet.master.key)
|
||||
throw new RPCError(errs.WALLET_UNLOCK_NEEDED, 'Wallet is locked.');
|
||||
|
||||
msg = new Buffer(MAGIC_STRING + msg, 'utf8');
|
||||
msg = Buffer.from(MAGIC_STRING + msg, 'utf8');
|
||||
msg = crypto.hash256(msg);
|
||||
|
||||
sig = ring.sign(msg);
|
||||
|
||||
@ -25,7 +25,7 @@ var Script = require('../script/script');
|
||||
var BlockMapRecord = records.BlockMapRecord;
|
||||
var OutpointMapRecord = records.OutpointMapRecord;
|
||||
var TXRecord = records.TXRecord;
|
||||
var DUMMY = new Buffer([0]);
|
||||
var DUMMY = Buffer.from([0]);
|
||||
|
||||
/**
|
||||
* TXDB
|
||||
@ -629,7 +629,7 @@ TXDB.prototype.addBlock = co(function* addBlock(hash, meta) {
|
||||
data = block.toRaw();
|
||||
}
|
||||
|
||||
block = new Buffer(data.length + 32);
|
||||
block = Buffer.allocUnsafe(data.length + 32);
|
||||
data.copy(block, 0);
|
||||
|
||||
size = block.readUInt32LE(40, true);
|
||||
|
||||
@ -2042,7 +2042,7 @@ Wallet.prototype.getRedeem = co(function* getRedeem(hash) {
|
||||
var ring;
|
||||
|
||||
if (typeof hash === 'string')
|
||||
hash = new Buffer(hash, 'hex');
|
||||
hash = Buffer.from(hash, 'hex');
|
||||
|
||||
ring = yield this.getKey(hash.toString('hex'));
|
||||
|
||||
|
||||
@ -36,7 +36,7 @@ var PathMapRecord = records.PathMapRecord;
|
||||
var OutpointMapRecord = records.OutpointMapRecord;
|
||||
var TXRecord = records.TXRecord;
|
||||
var U32 = encoding.U32;
|
||||
var DUMMY = new Buffer([0]);
|
||||
var DUMMY = Buffer.from([0]);
|
||||
|
||||
/**
|
||||
* WalletDB
|
||||
@ -611,8 +611,8 @@ WalletDB.prototype.wipe = co(function* wipe() {
|
||||
this.logger.warning('I hope you know what you\'re doing.');
|
||||
|
||||
iter = this.db.iterator({
|
||||
gte: new Buffer([0x00]),
|
||||
lte: new Buffer([0xff])
|
||||
gte: Buffer.from([0x00]),
|
||||
lte: Buffer.from([0xff])
|
||||
});
|
||||
|
||||
for (;;) {
|
||||
@ -1008,7 +1008,7 @@ WalletDB.prototype.auth = co(function* auth(wid, token) {
|
||||
if (typeof token === 'string') {
|
||||
if (!util.isHex256(token))
|
||||
throw new Error('WDB: Authentication error.');
|
||||
token = new Buffer(token, 'hex');
|
||||
token = Buffer.from(token, 'hex');
|
||||
}
|
||||
|
||||
// Compare in constant time:
|
||||
@ -1172,7 +1172,7 @@ WalletDB.prototype.saveAccount = function saveAccount(account) {
|
||||
batch.put(layout.i(wid, name), U32(index));
|
||||
|
||||
// Index->Name lookups
|
||||
batch.put(layout.n(wid, index), new Buffer(name, 'ascii'));
|
||||
batch.put(layout.n(wid, index), Buffer.from(name, 'ascii'));
|
||||
|
||||
wallet.accountCache.push(index, account);
|
||||
};
|
||||
@ -1419,7 +1419,7 @@ WalletDB.prototype.encryptKeys = co(function* encryptKeys(wallet, key) {
|
||||
|
||||
assert(!path.encrypted);
|
||||
|
||||
iv = new Buffer(path.hash, 'hex');
|
||||
iv = Buffer.from(path.hash, 'hex');
|
||||
iv = iv.slice(0, 16);
|
||||
|
||||
path = path.clone();
|
||||
@ -1453,7 +1453,7 @@ WalletDB.prototype.decryptKeys = co(function* decryptKeys(wallet, key) {
|
||||
|
||||
assert(path.encrypted);
|
||||
|
||||
iv = new Buffer(path.hash, 'hex');
|
||||
iv = Buffer.from(path.hash, 'hex');
|
||||
iv = iv.slice(0, 16);
|
||||
|
||||
path = path.clone();
|
||||
|
||||
@ -88,7 +88,7 @@ Master.prototype._initWebWorkers = function _initWebWorkers() {
|
||||
data = event.data.buf;
|
||||
data.__proto__ = Buffer.prototype;
|
||||
} else {
|
||||
data = new Buffer(event.data, 'hex');
|
||||
data = Buffer.from(event.data, 'hex');
|
||||
}
|
||||
self.emit('data', data);
|
||||
};
|
||||
|
||||
@ -50,7 +50,7 @@ Parser.prototype.read = function read(size) {
|
||||
assert(this.total >= size, 'Reading too much.');
|
||||
|
||||
if (size === 0)
|
||||
return new Buffer(0);
|
||||
return Buffer.alloc(0);
|
||||
|
||||
pending = this.pending[0];
|
||||
|
||||
@ -67,7 +67,7 @@ Parser.prototype.read = function read(size) {
|
||||
return chunk;
|
||||
}
|
||||
|
||||
chunk = new Buffer(size);
|
||||
chunk = Buffer.allocUnsafe(size);
|
||||
off = 0;
|
||||
len = 0;
|
||||
|
||||
|
||||
@ -516,7 +516,7 @@ Worker.prototype._initWebWorkers = function _initWebWorkers() {
|
||||
data = event.data.buf;
|
||||
data.__proto__ = Buffer.prototype;
|
||||
} else {
|
||||
data = new Buffer(event.data, 'hex');
|
||||
data = Buffer.from(event.data, 'hex');
|
||||
}
|
||||
self.emit('data', data);
|
||||
};
|
||||
|
||||
@ -19,7 +19,7 @@ var db = bcoin.ldb({
|
||||
|
||||
function makeKey(data) {
|
||||
var height = data.readUInt32LE(1, true);
|
||||
var key = new Buffer(5);
|
||||
var key = Buffer.allocUnsafe(5);
|
||||
key[0] = 0x48;
|
||||
key.writeUInt32BE(height, 1, true);
|
||||
return key;
|
||||
@ -64,7 +64,7 @@ var updateState = co(function* updateState() {
|
||||
|
||||
batch.put('R', p);
|
||||
|
||||
ver = new Buffer(4);
|
||||
ver = Buffer.allocUnsafe(4);
|
||||
ver.writeUInt32LE(1, 0, true);
|
||||
batch.put('V', ver);
|
||||
|
||||
@ -82,8 +82,8 @@ var updateEndian = co(function* updateEndian() {
|
||||
console.log('Iterating...');
|
||||
|
||||
iter = db.iterator({
|
||||
gte: new Buffer('4800000000', 'hex'),
|
||||
lte: new Buffer('48ffffffff', 'hex'),
|
||||
gte: Buffer.from('4800000000', 'hex'),
|
||||
lte: Buffer.from('48ffffffff', 'hex'),
|
||||
values: true
|
||||
});
|
||||
|
||||
|
||||
@ -57,7 +57,7 @@ var updateVersion = co(function* updateVersion() {
|
||||
if (ver !== 1)
|
||||
throw Error('DB is version ' + ver + '.');
|
||||
|
||||
ver = new Buffer(4);
|
||||
ver = Buffer.allocUnsafe(4);
|
||||
ver.writeUInt32LE(2, 0, true);
|
||||
batch.put('V', ver);
|
||||
});
|
||||
@ -205,7 +205,7 @@ function write(data, str, off) {
|
||||
}
|
||||
|
||||
function pair(prefix, hash) {
|
||||
var key = new Buffer(33);
|
||||
var key = Buffer.allocUnsafe(33);
|
||||
if (typeof prefix === 'string')
|
||||
prefix = prefix.charCodeAt(0);
|
||||
key[0] = prefix;
|
||||
@ -214,7 +214,7 @@ function pair(prefix, hash) {
|
||||
}
|
||||
|
||||
function ipair(prefix, num) {
|
||||
var key = new Buffer(5);
|
||||
var key = Buffer.allocUnsafe(5);
|
||||
if (typeof prefix === 'string')
|
||||
prefix = prefix.charCodeAt(0);
|
||||
key[0] = prefix;
|
||||
|
||||
@ -7,7 +7,7 @@ var crypto = require('../lib/crypto/crypto');
|
||||
var util = require('../lib/utils/util');
|
||||
var LDB = require('../lib/db/ldb');
|
||||
var BN = require('bn.js');
|
||||
var DUMMY = new Buffer([0]);
|
||||
var DUMMY = Buffer.from([0]);
|
||||
var file = process.argv[2];
|
||||
var db, batch;
|
||||
|
||||
@ -128,7 +128,7 @@ function write(data, str, off) {
|
||||
}
|
||||
|
||||
function pair(prefix, hash) {
|
||||
var key = new Buffer(33);
|
||||
var key = Buffer.allocUnsafe(33);
|
||||
if (typeof prefix === 'string')
|
||||
prefix = prefix.charCodeAt(0);
|
||||
key[0] = prefix;
|
||||
@ -137,7 +137,7 @@ function pair(prefix, hash) {
|
||||
}
|
||||
|
||||
function ipair(prefix, num) {
|
||||
var key = new Buffer(5);
|
||||
var key = Buffer.allocUnsafe(5);
|
||||
if (typeof prefix === 'string')
|
||||
prefix = prefix.charCodeAt(0);
|
||||
key[0] = prefix;
|
||||
|
||||
@ -44,7 +44,7 @@ var updateVersion = co(function* updateVersion() {
|
||||
|
||||
yield db.backup(bak);
|
||||
|
||||
ver = new Buffer(4);
|
||||
ver = Buffer.allocUnsafe(4);
|
||||
ver.writeUInt32LE(3, 0, true);
|
||||
batch.put('V', ver);
|
||||
});
|
||||
@ -123,7 +123,7 @@ var updateAccounts = co(function* updateAccounts() {
|
||||
|
||||
if (account._old) {
|
||||
batch.del(layout.i(account.wid, account._old));
|
||||
buf = new Buffer(4);
|
||||
buf = Buffer.allocUnsafe(4);
|
||||
buf.writeUInt32LE(account.accountIndex, 0, true);
|
||||
batch.put(layout.i(account.wid, account.name), buf);
|
||||
}
|
||||
@ -157,7 +157,7 @@ var updateWallets = co(function* updateWallets() {
|
||||
|
||||
if (wallet._old) {
|
||||
batch.del(layout.l(wallet._old));
|
||||
buf = new Buffer(4);
|
||||
buf = Buffer.allocUnsafe(4);
|
||||
buf.writeUInt32LE(wallet.wid, 0, true);
|
||||
batch.put(layout.l(wallet.id), buf);
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ var updateVersion = co(function* updateVersion() {
|
||||
|
||||
yield db.backup(bak);
|
||||
|
||||
ver = new Buffer(4);
|
||||
ver = Buffer.allocUnsafe(4);
|
||||
ver.writeUInt32LE(4, 0, true);
|
||||
batch.put('V', ver);
|
||||
});
|
||||
@ -55,8 +55,8 @@ var updateTXDB = co(function* updateTXDB() {
|
||||
var i, keys, key, hash, tx, walletdb;
|
||||
|
||||
keys = yield db.keys({
|
||||
gte: new Buffer([0x00]),
|
||||
lte: new Buffer([0xff])
|
||||
gte: Buffer.from([0x00]),
|
||||
lte: Buffer.from([0xff])
|
||||
});
|
||||
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
|
||||
@ -38,7 +38,7 @@ var updateVersion = co(function* updateVersion() {
|
||||
|
||||
yield db.backup(bak);
|
||||
|
||||
ver = new Buffer(4);
|
||||
ver = Buffer.allocUnsafe(4);
|
||||
ver.writeUInt32LE(5, 0, true);
|
||||
batch.put('V', ver);
|
||||
});
|
||||
@ -47,8 +47,8 @@ var updateTXDB = co(function* updateTXDB() {
|
||||
var i, keys, key;
|
||||
|
||||
keys = yield db.keys({
|
||||
gte: new Buffer([0x00]),
|
||||
lte: new Buffer([0xff])
|
||||
gte: Buffer.from([0x00]),
|
||||
lte: Buffer.from([0xff])
|
||||
});
|
||||
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user