Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
take(): string {
const idBuff = this.idGen.next();
return new Uint64BE(idBuff).toString();
}
Writer.prototype.writeUInt64 = function(i){
var b = UInt64(i).toBuffer();
this.write(b);
return this;
};
PacketStream.prototype.__validNonce = function (message, offset) {
var remoteNonce = new Uint64BE(new Buffer(message.subarray(offset, 8).reverse())).toNumber()
if (remoteNonce > this.__remoteNonceCounter || (this.__remoteNonceCounter === 0 && remoteNonce === 0)) {
this.__remoteNonceCounter = remoteNonce
return true
} else {
return false
}
}
export function uint64BEToHex(int64) {
return Uint64BE(int64).toString(16);
}
readUInt64BE() {
const result = (new Uint64BE(this.buffer, this.read_offset)).toNumber();
this.read_offset += 8;
return result;
}
public readUInt64(bigEndian: boolean = false): Uint64LE | Uint64BE {
if (this.canReadBytes(8) === false) {
throw new Error('Data buffer is too small')
}
const res: Uint64LE | Uint64BE = bigEndian ?
new Uint64BE(this.packetData, this.curOffset) :
new Uint64LE(this.packetData, this.curOffset)
this.curOffset += 8
return res
}
static SInt64ToBase64(str: string): string {
return new Uint64BE(str, 10).toBuffer().toString('base64')
}
PacketStream.prototype._createNonceFromCounter = function (prefix) {
this._increaseCounter()
var nonce = new Uint8Array(24)
nonce.set(nacl.util.decodeUTF8(prefix))
var counter = new Uint8Array(new Uint64BE(this.__ourNonceCounter).toBuffer()).reverse()
nonce.set(counter, 16)
return nonce
}
export function int64BufferToPrettyHexStr(buffer) {
const uint = Uint64BE(buffer);
let hex = uint.toString(16);
if (hex.length === 1) hex = `0${hex}`;
const hexParts = hex.match(/.{1,2}/g);
return hexParts.join(' ');
}