New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@chainsafe/lodestar-utils

Package Overview
Dependencies
Maintainers
5
Versions
843
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@chainsafe/lodestar-utils - npm Package Compare versions

Comparing version 0.37.0-dev.11f6d0eea1 to 0.37.0-dev.18c504c016

8

lib/assert.js

@@ -1,5 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AssertionError = exports.assert = void 0;
exports.assert = {
export const assert = {
/**

@@ -69,6 +66,5 @@ * Assert condition is true, otherwise throw AssertionError

};
class AssertionError extends Error {
export class AssertionError extends Error {
}
exports.AssertionError = AssertionError;
AssertionError.code = "ERR_ASSERTION";
//# sourceMappingURL=assert.js.map

@@ -1,7 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fromHex = exports.toHex = exports.bytesToBigInt = exports.bigIntToBytes = exports.bytesToInt = exports.intToBytes = exports.toHexString = void 0;
const bigint_buffer_1 = require("bigint-buffer");
import { toBufferLE, toBigIntLE, toBufferBE, toBigIntBE } from "bigint-buffer";
const hexByByte = [];
function toHexString(bytes) {
export function toHexString(bytes) {
let hex = "0x";

@@ -16,38 +13,33 @@ for (const byte of bytes) {

}
exports.toHexString = toHexString;
/**
* Return a byte array from a number or BigInt
*/
function intToBytes(value, length, endianness = "le") {
export function intToBytes(value, length, endianness = "le") {
return bigIntToBytes(BigInt(value), length, endianness);
}
exports.intToBytes = intToBytes;
/**
* Convert byte array in LE to integer.
*/
function bytesToInt(value, endianness = "le") {
export function bytesToInt(value, endianness = "le") {
return Number(bytesToBigInt(value, endianness));
}
exports.bytesToInt = bytesToInt;
function bigIntToBytes(value, length, endianness = "le") {
export function bigIntToBytes(value, length, endianness = "le") {
if (endianness === "le") {
return (0, bigint_buffer_1.toBufferLE)(value, length);
return toBufferLE(value, length);
}
else if (endianness === "be") {
return (0, bigint_buffer_1.toBufferBE)(value, length);
return toBufferBE(value, length);
}
throw new Error("endianness must be either 'le' or 'be'");
}
exports.bigIntToBytes = bigIntToBytes;
function bytesToBigInt(value, endianness = "le") {
export function bytesToBigInt(value, endianness = "le") {
if (endianness === "le") {
return (0, bigint_buffer_1.toBigIntLE)(value);
return toBigIntLE(value);
}
else if (endianness === "be") {
return (0, bigint_buffer_1.toBigIntBE)(value);
return toBigIntBE(value);
}
throw new Error("endianness must be either 'le' or 'be'");
}
exports.bytesToBigInt = bytesToBigInt;
function toHex(buffer) {
export function toHex(buffer) {
if (Buffer.isBuffer(buffer)) {

@@ -63,8 +55,6 @@ return "0x" + buffer.toString("hex");

}
exports.toHex = toHex;
function fromHex(hex) {
export function fromHex(hex) {
const b = Buffer.from(hex.replace("0x", ""), "hex");
return new Uint8Array(b.buffer, b.byteOffset, b.length);
}
exports.fromHex = fromHex;
//# sourceMappingURL=bytes.js.map

@@ -1,8 +0,5 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extendError = exports.isErrorAborted = exports.TimeoutError = exports.ErrorAborted = exports.LodestarError = void 0;
/**
* Generic Lodestar error with attached metadata
*/
class LodestarError extends Error {
export class LodestarError extends Error {
constructor(type, message) {

@@ -26,7 +23,6 @@ super(message || type.code);

}
exports.LodestarError = LodestarError;
/**
* Throw this error when an upstream abort signal aborts
*/
class ErrorAborted extends Error {
export class ErrorAborted extends Error {
constructor(message) {

@@ -36,7 +32,6 @@ super(`Aborted ${message || ""}`);

}
exports.ErrorAborted = ErrorAborted;
/**
* Throw this error when wrapped timeout expires
*/
class TimeoutError extends Error {
export class TimeoutError extends Error {
constructor(message) {

@@ -46,18 +41,15 @@ super(`Timeout ${message || ""}`);

}
exports.TimeoutError = TimeoutError;
/**
* Returns true if arg `e` is an instance of `ErrorAborted`
*/
function isErrorAborted(e) {
export function isErrorAborted(e) {
return e instanceof ErrorAborted;
}
exports.isErrorAborted = isErrorAborted;
/**
* Extend an existing error by appending a string to its `e.message`
*/
function extendError(e, appendMessage) {
export function extendError(e, appendMessage) {
e.message = `${e.message} - ${appendMessage}`;
return e;
}
exports.extendError = extendError;
//# sourceMappingURL=errors.js.map

@@ -1,5 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.prettyBytes = void 0;
const bytes_1 = require("./bytes");
import { toHexString } from "./bytes.js";
/**

@@ -9,7 +6,6 @@ * Format bytes as `0x1234…1234`

*/
function prettyBytes(root) {
const str = typeof root === "string" ? root : (0, bytes_1.toHexString)(root);
export function prettyBytes(root) {
const str = typeof root === "string" ? root : toHexString(root);
return `${str.slice(0, 6)}…${str.slice(-4)}`;
}
exports.prettyBytes = prettyBytes;
//# sourceMappingURL=format.js.map

@@ -1,15 +0,15 @@

export * from "./logger";
export * from "./yaml";
export * from "./assert";
export * from "./bytes";
export * from "./errors";
export * from "./format";
export * from "./math";
export * from "./objects";
export * from "./notNullish";
export * from "./sleep";
export * from "./sort";
export * from "./timeout";
export { RecursivePartial, bnToNum } from "./types";
export * from "./verifyMerkleBranch";
export * from "./logger/index.js";
export * from "./yaml/index.js";
export * from "./assert.js";
export * from "./bytes.js";
export * from "./errors.js";
export * from "./format.js";
export * from "./math.js";
export * from "./objects.js";
export * from "./notNullish.js";
export * from "./sleep.js";
export * from "./sort.js";
export * from "./timeout.js";
export { RecursivePartial, bnToNum } from "./types.js";
export * from "./verifyMerkleBranch.js";
//# sourceMappingURL=index.d.ts.map

@@ -1,29 +0,15 @@

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.bnToNum = void 0;
__exportStar(require("./logger"), exports);
__exportStar(require("./yaml"), exports);
__exportStar(require("./assert"), exports);
__exportStar(require("./bytes"), exports);
__exportStar(require("./errors"), exports);
__exportStar(require("./format"), exports);
__exportStar(require("./math"), exports);
__exportStar(require("./objects"), exports);
__exportStar(require("./notNullish"), exports);
__exportStar(require("./sleep"), exports);
__exportStar(require("./sort"), exports);
__exportStar(require("./timeout"), exports);
var types_1 = require("./types");
Object.defineProperty(exports, "bnToNum", { enumerable: true, get: function () { return types_1.bnToNum; } });
__exportStar(require("./verifyMerkleBranch"), exports);
export * from "./logger/index.js";
export * from "./yaml/index.js";
export * from "./assert.js";
export * from "./bytes.js";
export * from "./errors.js";
export * from "./format.js";
export * from "./math.js";
export * from "./objects.js";
export * from "./notNullish.js";
export * from "./sleep.js";
export * from "./sort.js";
export * from "./timeout.js";
export { bnToNum } from "./types.js";
export * from "./verifyMerkleBranch.js";
//# sourceMappingURL=index.js.map

@@ -1,6 +0,6 @@

import { format } from "winston";
import { ILoggerOptions } from "./interface";
declare type Format = ReturnType<typeof format.combine>;
import winston from "winston";
import { ILoggerOptions } from "./interface.js";
declare type Format = ReturnType<typeof winston.format.combine>;
export declare function getFormat(opts: ILoggerOptions): Format;
export {};
//# sourceMappingURL=format.d.ts.map

@@ -1,9 +0,7 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getFormat = void 0;
const winston_1 = require("winston");
const json_1 = require("./json");
const interface_1 = require("./interface");
const util_1 = require("./util");
function getFormat(opts) {
import winston from "winston";
import { logCtxToJson, logCtxToString } from "./json.js";
import { TimestampFormatCode } from "./interface.js";
import { formatEpochSlotTime } from "./util.js";
const { format } = winston;
export function getFormat(opts) {
switch (opts.format) {

@@ -17,5 +15,4 @@ case "json":

}
exports.getFormat = getFormat;
function humanReadableLogFormat(opts) {
return winston_1.format.combine(...(opts.hideTimestamp ? [] : [formatTimestamp(opts)]), winston_1.format.colorize(), winston_1.format.printf(humanReadableTemplateFn));
return format.combine(...(opts.hideTimestamp ? [] : [formatTimestamp(opts)]), format.colorize(), format.printf(humanReadableTemplateFn));
}

@@ -25,23 +22,23 @@ function formatTimestamp(opts) {

switch (timestampFormat === null || timestampFormat === void 0 ? void 0 : timestampFormat.format) {
case interface_1.TimestampFormatCode.EpochSlot:
case TimestampFormatCode.EpochSlot:
return {
transform: (info) => {
info.timestamp = (0, util_1.formatEpochSlotTime)(timestampFormat);
info.timestamp = formatEpochSlotTime(timestampFormat);
return info;
},
};
case interface_1.TimestampFormatCode.DateRegular:
case TimestampFormatCode.DateRegular:
default:
return winston_1.format.timestamp({ format: "MMM-DD HH:mm:ss.SSS" });
return format.timestamp({ format: "MMM-DD HH:mm:ss.SSS" });
}
}
function jsonLogFormat(opts) {
return winston_1.format.combine(...(opts.hideTimestamp ? [] : [winston_1.format.timestamp()]),
return format.combine(...(opts.hideTimestamp ? [] : [format.timestamp()]),
// eslint-disable-next-line @typescript-eslint/naming-convention
(0, winston_1.format)((_info) => {
format((_info) => {
const info = _info;
info.context = (0, json_1.logCtxToJson)(info.context);
info.error = (0, json_1.logCtxToJson)(info.error);
info.context = logCtxToJson(info.context);
info.error = logCtxToJson(info.error);
return info;
})(), winston_1.format.json());
})(), format.json());
}

@@ -62,7 +59,7 @@ /**

if (info.context !== undefined)
str += " " + (0, json_1.logCtxToString)(info.context);
str += " " + logCtxToString(info.context);
if (info.error !== undefined)
str += " " + (0, json_1.logCtxToString)(info.error);
str += " " + logCtxToString(info.error);
return str;
}
//# sourceMappingURL=format.js.map
/**
* @module logger
*/
export * from "./interface";
export * from "./format";
export * from "./transport";
export * from "./winston";
export { LogData } from "./json";
export * from "./interface.js";
export * from "./format.js";
export * from "./transport.js";
export * from "./winston.js";
export { LogData } from "./json.js";
//# sourceMappingURL=index.d.ts.map

@@ -1,20 +0,8 @@

"use strict";
/**
* @module logger
*/
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./interface"), exports);
__exportStar(require("./format"), exports);
__exportStar(require("./transport"), exports);
__exportStar(require("./winston"), exports);
export * from "./interface.js";
export * from "./format.js";
export * from "./transport.js";
export * from "./winston.js";
//# sourceMappingURL=index.js.map

@@ -6,3 +6,3 @@ /**

import { Writable } from "node:stream";
import { LogData } from "./json";
import { LogData } from "./json.js";
export declare enum LogLevel {

@@ -9,0 +9,0 @@ error = "error",

@@ -1,8 +0,5 @@

"use strict";
/**
* @module logger
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.TimestampFormatCode = exports.logFormats = exports.defaultLogLevel = exports.customColors = exports.LogLevels = exports.logLevelNum = exports.LogLevel = void 0;
var LogLevel;
export var LogLevel;
(function (LogLevel) {

@@ -15,4 +12,4 @@ LogLevel["error"] = "error";

LogLevel["silly"] = "silly";
})(LogLevel = exports.LogLevel || (exports.LogLevel = {}));
exports.logLevelNum = {
})(LogLevel || (LogLevel = {}));
export const logLevelNum = {
[LogLevel.error]: 0,

@@ -26,4 +23,4 @@ [LogLevel.warn]: 1,

// eslint-disable-next-line @typescript-eslint/naming-convention
exports.LogLevels = Object.values(LogLevel);
exports.customColors = {
export const LogLevels = Object.values(LogLevel);
export const customColors = {
error: "red",

@@ -36,9 +33,9 @@ warn: "yellow",

};
exports.defaultLogLevel = LogLevel.info;
exports.logFormats = ["human", "json"];
var TimestampFormatCode;
export const defaultLogLevel = LogLevel.info;
export const logFormats = ["human", "json"];
export var TimestampFormatCode;
(function (TimestampFormatCode) {
TimestampFormatCode[TimestampFormatCode["DateRegular"] = 0] = "DateRegular";
TimestampFormatCode[TimestampFormatCode["EpochSlot"] = 1] = "EpochSlot";
})(TimestampFormatCode = exports.TimestampFormatCode || (exports.TimestampFormatCode = {}));
})(TimestampFormatCode || (TimestampFormatCode = {}));
//# sourceMappingURL=interface.js.map

@@ -1,7 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.logCtxToString = exports.logCtxToJson = void 0;
const bytes_1 = require("../bytes");
const errors_1 = require("../errors");
const objects_1 = require("../objects");
import { toHexString } from "../bytes.js";
import { LodestarError } from "../errors.js";
import { mapValues } from "../objects.js";
const MAX_DEPTH = 0;

@@ -14,3 +11,3 @@ /**

*/
function logCtxToJson(arg, depth = 0, fromError = false) {
export function logCtxToJson(arg, depth = 0, fromError = false) {
switch (typeof arg) {

@@ -25,3 +22,3 @@ case "bigint":

if (arg instanceof Uint8Array) {
return (0, bytes_1.toHexString)(arg);
return toHexString(arg);
}

@@ -36,3 +33,3 @@ // For any type that may include recursiveness break early at the first level

let metadata;
if (arg instanceof errors_1.LodestarError) {
if (arg instanceof LodestarError) {
if (fromError) {

@@ -56,3 +53,3 @@ return "[LodestarErrorCircular]";

}
return (0, objects_1.mapValues)(arg, (item) => logCtxToJson(item, depth + 1));
return mapValues(arg, (item) => logCtxToJson(item, depth + 1));
// Already valid JSON

@@ -68,3 +65,2 @@ case "number":

}
exports.logCtxToJson = logCtxToJson;
/**

@@ -76,3 +72,3 @@ * Renders any log Context to a string up to one level of depth.

*/
function logCtxToString(arg, depth = 0, fromError = false) {
export function logCtxToString(arg, depth = 0, fromError = false) {
switch (typeof arg) {

@@ -87,3 +83,3 @@ case "bigint":

if (arg instanceof Uint8Array) {
return (0, bytes_1.toHexString)(arg);
return toHexString(arg);
}

@@ -98,3 +94,3 @@ // For any type that may include recursiveness break early at the first level

let metadata;
if (arg instanceof errors_1.LodestarError) {
if (arg instanceof LodestarError) {
if (fromError) {

@@ -127,3 +123,2 @@ return "[LodestarErrorCircular]";

}
exports.logCtxToString = logCtxToString;
//# sourceMappingURL=json.js.map
/// <reference types="node" />
import { LogLevel } from "./interface";
import { LogLevel } from "./interface.js";
import TransportStream from "winston-transport";

@@ -4,0 +4,0 @@ export declare enum TransportType {

@@ -1,10 +0,5 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.fromTransportOpts = exports.TransportType = void 0;
const winston_1 = require("winston");
const winston_daily_rotate_file_1 = __importDefault(require("winston-daily-rotate-file"));
var TransportType;
import winston from "winston";
import DailyRotateFile from "winston-daily-rotate-file";
const { transports } = winston;
export var TransportType;
(function (TransportType) {

@@ -14,7 +9,7 @@ TransportType["console"] = "console";

TransportType["stream"] = "stream";
})(TransportType = exports.TransportType || (exports.TransportType = {}));
function fromTransportOpts(transportOpts) {
})(TransportType || (TransportType = {}));
export function fromTransportOpts(transportOpts) {
switch (transportOpts.type) {
case TransportType.console:
return new winston_1.transports.Console({
return new transports.Console({
debugStdout: true,

@@ -26,3 +21,3 @@ level: transportOpts.level,

return transportOpts.rotate
? new winston_daily_rotate_file_1.default({
? new DailyRotateFile({
level: transportOpts.level,

@@ -35,3 +30,3 @@ //insert the date pattern in filename before the file extension.

})
: new winston_1.transports.File({
: new transports.File({
level: transportOpts.level,

@@ -42,3 +37,3 @@ filename: transportOpts.filename,

case TransportType.stream:
return new winston_1.transports.Stream({
return new transports.Stream({
level: transportOpts.level,

@@ -50,3 +45,2 @@ stream: transportOpts.stream,

}
exports.fromTransportOpts = fromTransportOpts;
//# sourceMappingURL=transport.js.map

@@ -1,2 +0,2 @@

import { EpochSlotOpts } from "./interface";
import { EpochSlotOpts } from "./interface.js";
/**

@@ -3,0 +3,0 @@ * Formats time as: `EPOCH/SLOT_INDEX SECONDS.MILISECONDS

@@ -1,8 +0,5 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatEpochSlotTime = void 0;
/**
* Formats time as: `EPOCH/SLOT_INDEX SECONDS.MILISECONDS
*/
function formatEpochSlotTime(opts, now = Date.now()) {
export function formatEpochSlotTime(opts, now = Date.now()) {
const nowSec = now / 1000;

@@ -17,3 +14,2 @@ const secSinceGenesis = nowSec - opts.genesisTime;

}
exports.formatEpochSlotTime = formatEpochSlotTime;
//# sourceMappingURL=util.js.map

@@ -5,6 +5,6 @@ /**

/// <reference types="node" />
import { ILogger, ILoggerOptions } from "./interface";
import { ILogger, ILoggerOptions } from "./interface.js";
import { Writable } from "node:stream";
import { TransportOpts } from "./transport";
import { LogData } from "./json";
import { TransportOpts } from "./transport.js";
import { LogData } from "./json.js";
export declare class WinstonLogger implements ILogger {

@@ -11,0 +11,0 @@ private winston;

@@ -1,17 +0,12 @@

"use strict";
/**
* @module logger
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.WinstonLogger = void 0;
const winston_1 = require("winston");
const interface_1 = require("./interface");
const chalk_1 = __importDefault(require("chalk"));
const format_1 = require("./format");
const transport_1 = require("./transport");
const defaultTransportOpts = { type: transport_1.TransportType.console };
class WinstonLogger {
import winston from "winston";
import { defaultLogLevel, LogLevel, logLevelNum } from "./interface.js";
import chalk from "chalk";
import { getFormat } from "./format.js";
import { TransportType, fromTransportOpts } from "./transport.js";
const { createLogger } = winston;
const defaultTransportOpts = { type: TransportType.console };
export class WinstonLogger {
constructor(options = {}, transportOptsArr = [defaultTransportOpts]) {

@@ -25,10 +20,10 @@ // `options.level` can override the level in the transport

}
this.winston = (0, winston_1.createLogger)({
level: (options === null || options === void 0 ? void 0 : options.level) || interface_1.defaultLogLevel,
this.winston = createLogger({
level: (options === null || options === void 0 ? void 0 : options.level) || defaultLogLevel,
defaultMeta: { module: (options === null || options === void 0 ? void 0 : options.module) || "" },
format: (0, format_1.getFormat)(options),
transports: transportOptsArr.map((transportOpts) => (0, transport_1.fromTransportOpts)(transportOpts)),
format: getFormat(options),
transports: transportOptsArr.map((transportOpts) => fromTransportOpts(transportOpts)),
exitOnError: false,
});
this._level = minLevel || interface_1.defaultLogLevel;
this._level = minLevel || defaultLogLevel;
// Store for child logger

@@ -39,21 +34,21 @@ this._options = options;

error(message, context, error) {
this.createLogEntry(interface_1.LogLevel.error, message, context, error);
this.createLogEntry(LogLevel.error, message, context, error);
}
warn(message, context, error) {
this.createLogEntry(interface_1.LogLevel.warn, message, context, error);
this.createLogEntry(LogLevel.warn, message, context, error);
}
info(message, context, error) {
this.createLogEntry(interface_1.LogLevel.info, message, context, error);
this.createLogEntry(LogLevel.info, message, context, error);
}
important(message, context, error) {
this.createLogEntry(interface_1.LogLevel.info, chalk_1.default.red(message), context, error);
this.createLogEntry(LogLevel.info, chalk.red(message), context, error);
}
verbose(message, context, error) {
this.createLogEntry(interface_1.LogLevel.verbose, message, context, error);
this.createLogEntry(LogLevel.verbose, message, context, error);
}
debug(message, context, error) {
this.createLogEntry(interface_1.LogLevel.debug, message, context, error);
this.createLogEntry(LogLevel.debug, message, context, error);
}
silly(message, context, error) {
this.createLogEntry(interface_1.LogLevel.silly, message, context, error);
this.createLogEntry(LogLevel.silly, message, context, error);
}

@@ -74,3 +69,3 @@ profile(message, option) {

// don't propagate if silenced or message level is more detailed than logger level
if (interface_1.logLevelNum[level] > interface_1.logLevelNum[this._level]) {
if (logLevelNum[level] > logLevelNum[this._level]) {
return;

@@ -81,3 +76,2 @@ }

}
exports.WinstonLogger = WinstonLogger;
/** Return the min LogLevel from multiple transports */

@@ -88,7 +82,7 @@ function getMinLevel(...levelsArg) {

if (levels.length === 0)
return interface_1.defaultLogLevel;
return defaultLogLevel;
return levels.reduce(
// error: 0, warn: 1, info: 2, ...
(minLevel, level) => (interface_1.logLevelNum[level] > interface_1.logLevelNum[minLevel] ? level : minLevel));
(minLevel, level) => (logLevelNum[level] > logLevelNum[minLevel] ? level : minLevel));
}
//# sourceMappingURL=winston.js.map

@@ -1,29 +0,23 @@

"use strict";
/**
* @module util/math
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.randBetweenBigInt = exports.randBetween = exports.bigIntSqrt = exports.intSqrt = exports.intDiv = exports.bigIntMax = exports.bigIntMin = void 0;
/**
* Return the min number between two big numbers.
*/
function bigIntMin(a, b) {
export function bigIntMin(a, b) {
return a < b ? a : b;
}
exports.bigIntMin = bigIntMin;
/**
* Return the max number between two big numbers.
*/
function bigIntMax(a, b) {
export function bigIntMax(a, b) {
return a > b ? a : b;
}
exports.bigIntMax = bigIntMax;
function intDiv(dividend, divisor) {
export function intDiv(dividend, divisor) {
return Math.floor(dividend / divisor);
}
exports.intDiv = intDiv;
/**
* Calculate the largest integer k such that k**2 <= n.
*/
function intSqrt(n) {
export function intSqrt(n) {
let x = n;

@@ -37,4 +31,3 @@ let y = intDiv(x + 1, 2);

}
exports.intSqrt = intSqrt;
function bigIntSqrt(n) {
export function bigIntSqrt(n) {
let x = n;

@@ -48,10 +41,8 @@ let y = (x + BigInt(1)) / BigInt(2);

}
exports.bigIntSqrt = bigIntSqrt;
/**
* Regenerates a random integer between min (included) and max (excluded).
*/
function randBetween(min, max) {
export function randBetween(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
exports.randBetween = randBetween;
/**

@@ -61,6 +52,5 @@ * Wraps randBetween and returns a bigNumber.

*/
function randBetweenBigInt(min, max) {
export function randBetweenBigInt(min, max) {
return BigInt(randBetween(min, max));
}
exports.randBetweenBigInt = randBetweenBigInt;
//# sourceMappingURL=math.js.map

@@ -1,4 +0,1 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.notNullish = void 0;
/**

@@ -12,6 +9,5 @@ * Type-safe helper to filter out nullist values from an array

*/
function notNullish(value) {
export function notNullish(value) {
return value !== null && value !== undefined;
}
exports.notNullish = notNullish;
//# sourceMappingURL=notNullish.js.map

@@ -1,9 +0,3 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.objectToExpectedCase = exports.mapValues = exports.isPlainObject = exports.toExpectedCase = void 0;
const case_1 = __importDefault(require("case"));
function toExpectedCase(value, expectedCase = "camel", customCasingMap) {
import Case from "case";
export function toExpectedCase(value, expectedCase = "camel", customCasingMap) {
if (expectedCase === "notransform")

@@ -15,14 +9,13 @@ return value;

case "param":
return case_1.default.kebab(value);
return Case.kebab(value);
case "dot":
return case_1.default.lower(value, ".", true);
return Case.lower(value, ".", true);
default:
return case_1.default[expectedCase](value);
return Case[expectedCase](value);
}
}
exports.toExpectedCase = toExpectedCase;
function isObjectObject(val) {
return val != null && typeof val === "object" && Array.isArray(val) === false;
}
function isPlainObject(o) {
export function isPlainObject(o) {
if (isObjectObject(o) === false)

@@ -45,3 +38,2 @@ return false;

}
exports.isPlainObject = isPlainObject;
/**

@@ -54,3 +46,3 @@ * Creates an object with the same keys as object and values generated by running each own enumerable

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function mapValues(obj, iteratee) {
export function mapValues(obj, iteratee) {
const output = {};

@@ -62,4 +54,3 @@ for (const [key, value] of Object.entries(obj)) {

}
exports.mapValues = mapValues;
function objectToExpectedCase(obj, expectedCase = "camel") {
export function objectToExpectedCase(obj, expectedCase = "camel") {
if (Array.isArray(obj)) {

@@ -85,3 +76,2 @@ const newArr = [];

}
exports.objectToExpectedCase = objectToExpectedCase;
//# sourceMappingURL=objects.js.map

@@ -1,2 +0,1 @@

import { AbortSignal } from "@chainsafe/abort-controller";
/**

@@ -3,0 +2,0 @@ * Abortable sleep function. Cleans everything on all cases preventing leaks

@@ -1,5 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sleep = void 0;
const errors_1 = require("./errors");
import { ErrorAborted } from "./errors.js";
/**

@@ -9,3 +6,3 @@ * Abortable sleep function. Cleans everything on all cases preventing leaks

*/
async function sleep(ms, signal) {
export async function sleep(ms, signal) {
if (ms < 0) {

@@ -16,3 +13,3 @@ return;

if (signal && signal.aborted)
return reject(new errors_1.ErrorAborted());
return reject(new ErrorAborted());
// eslint-disable-next-line @typescript-eslint/no-empty-function

@@ -26,3 +23,3 @@ let onDone = () => { };

onDone();
reject(new errors_1.ErrorAborted());
reject(new ErrorAborted());
};

@@ -38,3 +35,2 @@ if (signal)

}
exports.sleep = sleep;
//# sourceMappingURL=sleep.js.map

@@ -1,5 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isSorted = void 0;
function isSorted(indices) {
export function isSorted(indices) {
for (let i = 0, prevIndex = -1; i < indices.length; i++) {

@@ -13,3 +10,2 @@ if (indices[i] <= prevIndex) {

}
exports.isSorted = isSorted;
//# sourceMappingURL=sort.js.map

@@ -1,3 +0,2 @@

import { AbortSignal } from "@chainsafe/abort-controller";
export declare function withTimeout<T>(asyncFn: (timeoutAndParentSignal?: AbortSignal) => Promise<T>, timeoutMs: number, signal?: AbortSignal): Promise<T>;
//# sourceMappingURL=timeout.d.ts.map

@@ -1,14 +0,10 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.withTimeout = void 0;
const abort_controller_1 = require("@chainsafe/abort-controller");
const any_signal_1 = require("any-signal");
const errors_1 = require("./errors");
const sleep_1 = require("./sleep");
async function withTimeout(asyncFn, timeoutMs, signal) {
const timeoutAbortController = new abort_controller_1.AbortController();
const timeoutAndParentSignal = (0, any_signal_1.anySignal)([timeoutAbortController.signal, ...(signal ? [signal] : [])]);
import { anySignal } from "any-signal";
import { TimeoutError } from "./errors.js";
import { sleep } from "./sleep.js";
export async function withTimeout(asyncFn, timeoutMs, signal) {
const timeoutAbortController = new AbortController();
const timeoutAndParentSignal = anySignal([timeoutAbortController.signal, ...(signal ? [signal] : [])]);
async function timeoutPromise(signal) {
await (0, sleep_1.sleep)(timeoutMs, signal);
throw new errors_1.TimeoutError();
await sleep(timeoutMs, signal);
throw new TimeoutError();
}

@@ -22,3 +18,2 @@ try {

}
exports.withTimeout = withTimeout;
//# sourceMappingURL=timeout.js.map

@@ -1,9 +0,5 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.bnToNum = void 0;
/** Type safe wrapper for Number constructor that takes 'any' */
function bnToNum(bn) {
export function bnToNum(bn) {
return Number(bn);
}
exports.bnToNum = bnToNum;
//# sourceMappingURL=types.js.map

@@ -1,9 +0,5 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.verifyMerkleBranch = exports.hash = void 0;
const as_sha256_1 = require("@chainsafe/as-sha256");
function hash(...inputs) {
return (0, as_sha256_1.digest)(Buffer.concat(inputs));
import { digest, digest64 } from "@chainsafe/as-sha256";
export function hash(...inputs) {
return digest(Buffer.concat(inputs));
}
exports.hash = hash;
/**

@@ -13,10 +9,10 @@ * Verify that the given ``leaf`` is on the merkle branch ``proof``

*/
function verifyMerkleBranch(leaf, proof, depth, index, root) {
export function verifyMerkleBranch(leaf, proof, depth, index, root) {
let value = leaf;
for (let i = 0; i < depth; i++) {
if (Math.floor(index / 2 ** i) % 2) {
value = (0, as_sha256_1.digest64)(Buffer.concat([proof[i], value]));
value = digest64(Buffer.concat([proof[i], value]));
}
else {
value = (0, as_sha256_1.digest64)(Buffer.concat([value, proof[i]]));
value = digest64(Buffer.concat([value, proof[i]]));
}

@@ -26,3 +22,2 @@ }

}
exports.verifyMerkleBranch = verifyMerkleBranch;
//# sourceMappingURL=verifyMerkleBranch.js.map

@@ -1,14 +0,10 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.dumpYaml = exports.loadYaml = void 0;
const js_yaml_1 = require("js-yaml");
const schema_1 = require("./schema");
function loadYaml(yaml) {
return (0, js_yaml_1.load)(yaml, { schema: schema_1.schema });
import yaml from "js-yaml";
import { schema } from "./schema.js";
const { load, dump } = yaml;
export function loadYaml(yaml) {
return load(yaml, { schema });
}
exports.loadYaml = loadYaml;
function dumpYaml(yaml) {
return (0, js_yaml_1.dump)(yaml, { schema: schema_1.schema });
export function dumpYaml(yaml) {
return dump(yaml, { schema });
}
exports.dumpYaml = dumpYaml;
//# sourceMappingURL=index.js.map

@@ -1,3 +0,3 @@

import { Type } from "js-yaml";
export declare const intType: Type;
import yaml from "js-yaml";
export declare const intType: yaml.Type;
//# sourceMappingURL=int.d.ts.map

@@ -1,7 +0,5 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.intType = void 0;
// Forked from https://github.com/nodeca/js-yaml/blob/master/lib/js-yaml/type/int.js
// Currently only supports loading ints
const js_yaml_1 = require("js-yaml");
import yaml from "js-yaml";
const { Type } = yaml;
function isHexCode(c) {

@@ -138,3 +136,3 @@ return (

}
exports.intType = new js_yaml_1.Type("tag:yaml.org,2002:int", {
export const intType = new Type("tag:yaml.org,2002:int", {
kind: "scalar",

@@ -141,0 +139,0 @@ resolve: resolveYamlInteger,

@@ -1,3 +0,3 @@

import { Schema } from "js-yaml";
export declare const schema: Schema;
import yaml from "js-yaml";
export declare const schema: yaml.Schema;
//# sourceMappingURL=schema.d.ts.map

@@ -1,26 +0,21 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.schema = void 0;
const js_yaml_1 = require("js-yaml");
import yaml from "js-yaml";
const { Schema } = yaml;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const failsafe_1 = __importDefault(require("js-yaml/lib/js-yaml/schema/failsafe"));
import failsafe from "js-yaml/lib/js-yaml/schema/failsafe.js";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const null_1 = __importDefault(require("js-yaml/lib/js-yaml/type/null"));
import nullType from "js-yaml/lib/js-yaml/type/null.js";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const bool_1 = __importDefault(require("js-yaml/lib/js-yaml/type/bool"));
import boolType from "js-yaml/lib/js-yaml/type/bool.js";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const float_1 = __importDefault(require("js-yaml/lib/js-yaml/type/float"));
const int_1 = require("./int");
exports.schema = new js_yaml_1.Schema({
include: [failsafe_1.default],
implicit: [null_1.default, bool_1.default, int_1.intType, float_1.default],
import floatType from "js-yaml/lib/js-yaml/type/float.js";
import { intType } from "./int.js";
export const schema = new Schema({
include: [failsafe],
implicit: [nullType, boolType, intType, floatType],
explicit: [],
});
//# sourceMappingURL=schema.js.map

@@ -14,4 +14,5 @@ {

},
"version": "0.37.0-dev.11f6d0eea1",
"main": "lib/index.js",
"version": "0.37.0-dev.18c504c016",
"type": "module",
"exports": "./lib/index.js",
"files": [

@@ -31,2 +32,3 @@ "lib/**/*.d.ts",

"build:types:watch": "yarn run build:types --watch",
"check-build": "node -e \"(async function() { await import('./lib/index.js') })()\"",
"check-types": "tsc",

@@ -41,3 +43,2 @@ "lint": "eslint --color --ext .ts src/ test/",

"dependencies": {
"@chainsafe/abort-controller": "^3.0.1",
"@chainsafe/as-sha256": "^0.3.1",

@@ -64,3 +65,3 @@ "any-signal": "2.1.2",

],
"gitHead": "c7a8420014893207d40d1a9102f959cc2e5fecaa"
"gitHead": "e60a26b0fe928d012183c59eae570206aa60c092"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc