Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
RIPEMD160.prototype._digest = function () {
// create padding and handle blocks
this._block[this._blockOffset++] = 0x80
if (this._blockOffset > 56) {
this._block.fill(0, this._blockOffset, 64)
this._update()
this._blockOffset = 0
}
this._block.fill(0, this._blockOffset, 56)
this._block.writeUInt32LE(this._length[0], 56)
this._block.writeUInt32LE(this._length[1], 60)
this._update()
// produce result
var buffer = Buffer.alloc ? Buffer.alloc(20) : new Buffer(20)
buffer.writeInt32LE(this._a, 0)
buffer.writeInt32LE(this._b, 4)
buffer.writeInt32LE(this._c, 8)
buffer.writeInt32LE(this._d, 12)
buffer.writeInt32LE(this._e, 16)
return buffer
}
const createGetAddressRequest = (path) => {
const apdu = Buffer.alloc(6 + path.length);
// Command: getAddress() (0xe002)
apdu[0] = 0xe0;
apdu[1] = 0x02;
// Ask user for confirmation on device? (boolean)
apdu[2] = 0x00;
// Ask for response to include chain code? (boolean)
apdu[3] = 0x00;
// Path
apdu[4] = 1 + path.length;
apdu[5] = path.length / 4;
Buffer.from(path).copy(apdu, 6, 0, path.length);
return [apdu];
};
Bytes.prototype.__add__ = function(other) {
var types = require('../types')
if (types.isinstance(other, [Bytes])) {
// create a new buffer object of combined length and then write the concatenated string value of both byte objects
let byteBuffer = Buffer.alloc(this.valueOf().length + other.valueOf().length)
byteBuffer.write(this.valueOf().toString() + other.valueOf().toString())
return new Bytes(byteBuffer)
} else if (types.isinstance(other, [types.Bytearray])) {
let byteBuffer = Buffer.alloc(this.valueOf().length + other.valueOf().valueOf().length)
byteBuffer.write(this.valueOf().toString() + other.valueOf().valueOf().toString())
return new Bytes(byteBuffer)
} else if (types.isinstance(other, [
types.Bool,
types.Dict,
types.Int,
types.Float,
types.List,
types.NoneType,
types.Set,
types.Str,
types.Tuple ])) {
module.exports.buildHandshake = torrent => {
const buf = Buffer.alloc(68);
// pstrlen
buf.writeUInt8(19, 0);
// pstr
buf.write('BitTorrent protocol', 1);
// reserved
buf.writeUInt32BE(0, 20);
buf.writeUInt32BE(0, 24);
// info hash
torrentParser.infoHash(torrent).copy(buf, 28);
// peer id
util.genId().copy(buf, 48);
return buf;
};
function serialize(object, options) {
options = options || {};
// Unpack the options
const checkKeys = typeof options.checkKeys === 'boolean' ? options.checkKeys : false;
const serializeFunctions =
typeof options.serializeFunctions === 'boolean' ? options.serializeFunctions : false;
const ignoreUndefined =
typeof options.ignoreUndefined === 'boolean' ? options.ignoreUndefined : true;
const minInternalBufferSize =
typeof options.minInternalBufferSize === 'number' ? options.minInternalBufferSize : MAXSIZE;
// Resize the internal serialization buffer if needed
if (buffer.length < minInternalBufferSize) {
buffer = Buffer.alloc(minInternalBufferSize);
}
// Attempt to serialize
const serializationIndex = internalSerialize(
buffer,
object,
checkKeys,
0,
0,
serializeFunctions,
ignoreUndefined,
[]
);
// Create the final buffer
const finishedBuffer = Buffer.alloc(serializationIndex);
log.info("No content-type given by server, guessing based on file name.");
contenttype = mime.lookup(url);
}
if (name == null) {
name = url.split("/");
name = name[name.length - 1];
}
var size = parseInt(res.headers["content-length"]);
if(isNaN(size)) {
reject("Content-Length was not an integer, which is weird.");
return;
}
var buffer;
if(Buffer.alloc) {//Since 5.10
buffer = Buffer.alloc(size);
}
else {//Deprecated
buffer = new Buffer(size);
}
var bsize = 0;
res.on('data', (d) => {
d.copy(buffer, bsize);
bsize += d.length;
});
res.on('error', () => {
reject("Failed to download.");
});
res.on('end', () => {
resolve(buffer);
});
function ensureBuffer(input) {
if (Buffer.isBuffer(input)) {
return input;
}
var hasNewBufferAPI =
typeof Buffer.alloc === "function" &&
typeof Buffer.from === "function";
if (typeof input === "number") {
return hasNewBufferAPI ? Buffer.alloc(input) : new Buffer(input);
}
else if (typeof input === "string") {
return hasNewBufferAPI ? Buffer.from(input) : new Buffer(input);
}
else {
throw new Error("input must be buffer, number, or string, received " +
typeof input);
}
}
const ffWorkaround = setTimeout(async () => {
log(`Publishing empty message to "${topic}" to resolve subscription request`)
try {
await publish(topic, Buffer.alloc(0), options)
} catch (err) {
log('Failed to publish empty message', err)
}
}, 1000)
encryptData(data) {
if (!this.encryptionKey) {
return data;
}
const sodium = this.sodium;
const result = Buffer.alloc(
sodium.crypto_secretbox_NONCEBYTES +
data.length +
sodium.crypto_secretbox_MACBYTES);
const nonce = result.slice(0, sodium.crypto_secretbox_NONCEBYTES);
const ciphertext = result.slice(nonce.length);
sodium.randombytes_buf(nonce);
sodium.crypto_secretbox_easy(ciphertext, data, nonce,
this.encryptionKey);
return result;
}
function toJose ({ r, s, recoveryParam }) {
const jose = Buffer.alloc(recoverable ? 65 : 64)
Buffer.from(r, 'hex').copy(jose, 0)
Buffer.from(s, 'hex').copy(jose, 32)
if (recoverable) {
if (recoveryParam === undefined) throw new Error('Signer did not return a recoveryParam')
jose[64] = recoveryParam
}
return base64url.encode(jose)
}