4997 lines
177 KiB
JavaScript
4997 lines
177 KiB
JavaScript
var __bare_os_bundle_exports__ = (() => {
|
|
var __create = Object.create;
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __getProtoOf = Object.getPrototypeOf;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
}) : x)(function(x) {
|
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
});
|
|
var __commonJS = (cb, mod) => function __require2() {
|
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
};
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
// file that has been converted to a CommonJS file using a Babel-
|
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
mod
|
|
));
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
|
|
// ../../node_modules/bare-ansi-escapes/index.js
|
|
var require_bare_ansi_escapes = __commonJS({
|
|
"../../node_modules/bare-ansi-escapes/index.js"(exports) {
|
|
var ESC = "\x1B";
|
|
var CSI = ESC + "[";
|
|
var SGR = (n) => CSI + n + "m";
|
|
exports.constants = {
|
|
ESC,
|
|
CSI,
|
|
SGR
|
|
};
|
|
exports.cursorHide = CSI + "?25l";
|
|
exports.cursorShow = CSI + "?25h";
|
|
exports.cursorUp = function cursorUp(n = 1) {
|
|
return CSI + n + "A";
|
|
};
|
|
exports.cursorDown = function cursorDown(n = 1) {
|
|
return CSI + n + "B";
|
|
};
|
|
exports.cursorForward = function cursorForward(n = 1) {
|
|
return CSI + n + "C";
|
|
};
|
|
exports.cursorBack = function cursorBack(n = 1) {
|
|
return CSI + n + "D";
|
|
};
|
|
exports.cursorNextLine = function cursorNextLine(n = 1) {
|
|
return CSI + n + "E";
|
|
};
|
|
exports.cursorPreviousLine = function cursorPreviousLine(n = 1) {
|
|
return CSI + n + "F";
|
|
};
|
|
exports.cursorPosition = function cursorPosition(column, row = 0) {
|
|
if (row === 0) return CSI + (column + 1) + "G";
|
|
return CSI + (row + 1) + ";" + (column + 1) + "H";
|
|
};
|
|
exports.eraseDisplayEnd = CSI + "J";
|
|
exports.eraseDisplayStart = CSI + "1J";
|
|
exports.eraseDisplay = CSI + "2J";
|
|
exports.eraseLineEnd = CSI + "K";
|
|
exports.eraseLineStart = CSI + "1K";
|
|
exports.eraseLine = CSI + "2K";
|
|
exports.scrollUp = function scrollUp(n = 1) {
|
|
return CSI + n + "S";
|
|
};
|
|
exports.scrollDown = function scrollDown(n = 1) {
|
|
return CSI + n + "T";
|
|
};
|
|
exports.modifierReset = SGR(0);
|
|
exports.modifierBold = SGR(1);
|
|
exports.modifierDim = SGR(2);
|
|
exports.modifierItalic = SGR(3);
|
|
exports.modifierUnderline = SGR(4);
|
|
exports.modifierNormal = SGR(22);
|
|
exports.modifierNotItalic = SGR(23);
|
|
exports.modifierNotUnderline = SGR(24);
|
|
exports.colorBlack = SGR(30);
|
|
exports.colorRed = SGR(31);
|
|
exports.colorGreen = SGR(32);
|
|
exports.colorYellow = SGR(33);
|
|
exports.colorBlue = SGR(34);
|
|
exports.colorMagenta = SGR(35);
|
|
exports.colorCyan = SGR(36);
|
|
exports.colorWhite = SGR(37);
|
|
exports.colorDefault = SGR(39);
|
|
exports.colorBrightBlack = SGR(90);
|
|
exports.colorBrightRed = SGR(91);
|
|
exports.colorBrightGreen = SGR(92);
|
|
exports.colorBrightYellow = SGR(93);
|
|
exports.colorBrightBlue = SGR(94);
|
|
exports.colorBrightMagenta = SGR(95);
|
|
exports.colorBrightCyan = SGR(96);
|
|
exports.colorBrightWhite = SGR(97);
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-type/binding.js
|
|
var require_binding = __commonJS({
|
|
"../../node_modules/bare-type/binding.js"(exports, module) {
|
|
module.exports = __require.addon();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-type/index.js
|
|
var require_bare_type = __commonJS({
|
|
"../../node_modules/bare-type/index.js"(exports, module) {
|
|
var binding = require_binding();
|
|
var t = binding.constants;
|
|
var Type = class {
|
|
constructor(type) {
|
|
this._type = type;
|
|
}
|
|
isUndefined() {
|
|
return this._type === t.UNDEFINED;
|
|
}
|
|
isNull() {
|
|
return this._type === t.NULL;
|
|
}
|
|
isBoolean() {
|
|
return this._type === t.BOOLEAN;
|
|
}
|
|
isNumber() {
|
|
return (this._type & 255) === t.NUMBER;
|
|
}
|
|
isInt32() {
|
|
return (this._type & (255 | t.INT32)) === (t.NUMBER | t.INT32);
|
|
}
|
|
isUint32() {
|
|
return (this._type & (255 | t.UINT32)) === (t.NUMBER | t.UINT32);
|
|
}
|
|
isString() {
|
|
return this._type === t.STRING;
|
|
}
|
|
isSymbol() {
|
|
return this._type === t.SYMBOL;
|
|
}
|
|
isObject() {
|
|
return (this._type & 255) === t.OBJECT;
|
|
}
|
|
isArray() {
|
|
return this._type === (t.OBJECT | t.ARRAY);
|
|
}
|
|
isArguments() {
|
|
return this._type === (t.OBJECT | t.ARGUMENTS);
|
|
}
|
|
isDate() {
|
|
return this._type === (t.OBJECT | t.DATE);
|
|
}
|
|
isRegExp() {
|
|
return this._type === (t.OBJECT | t.REGEXP);
|
|
}
|
|
isError() {
|
|
return this._type === (t.OBJECT | t.ERROR);
|
|
}
|
|
isPromise() {
|
|
return this._type === (t.OBJECT | t.PROMISE);
|
|
}
|
|
isProxy() {
|
|
return this._type === (t.OBJECT | t.PROXY);
|
|
}
|
|
isGenerator() {
|
|
return this._type === (t.OBJECT | t.GENERATOR);
|
|
}
|
|
isMap() {
|
|
return this._type === (t.OBJECT | t.MAP);
|
|
}
|
|
isSet() {
|
|
return this._type === (t.OBJECT | t.SET);
|
|
}
|
|
isWeakMap() {
|
|
return this._type === (t.OBJECT | t.WEAK_MAP);
|
|
}
|
|
isWeakSet() {
|
|
return this._type === (t.OBJECT | t.WEAK_SET);
|
|
}
|
|
isWeakRef() {
|
|
return this._type === (t.OBJECT | t.WEAK_REF);
|
|
}
|
|
isArrayBuffer() {
|
|
return this._type === (t.OBJECT | t.ARRAYBUFFER);
|
|
}
|
|
isSharedArrayBuffer() {
|
|
return this._type === (t.OBJECT | t.SHAREDARRAYBUFFER);
|
|
}
|
|
isTypedArray() {
|
|
return (this._type & 65535) === (t.OBJECT | t.TYPEDARRAY);
|
|
}
|
|
isInt8Array() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.INT8ARRAY);
|
|
}
|
|
isUint8Array() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.UINT8ARRAY);
|
|
}
|
|
isUint8ClampedArray() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.UINT8CLAMPEDARRAY);
|
|
}
|
|
isInt16Array() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.INT16ARRAY);
|
|
}
|
|
isUint16Array() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.UINT16ARRAY);
|
|
}
|
|
isInt32Array() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.INT32ARRAY);
|
|
}
|
|
isUint32Array() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.UINT32ARRAY);
|
|
}
|
|
isFloat16Array() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.FLOAT16ARRAY);
|
|
}
|
|
isFloat32Array() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.FLOAT32ARRAY);
|
|
}
|
|
isFloat64Array() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.FLOAT64ARRAY);
|
|
}
|
|
isBigInt64Array() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.BIGINT64ARRAY);
|
|
}
|
|
isBigUint64Array() {
|
|
return this._type === (t.OBJECT | t.TYPEDARRAY | t.BIGUINT64ARRAY);
|
|
}
|
|
isDataView() {
|
|
return this._type === (t.OBJECT | t.DATAVIEW);
|
|
}
|
|
isModuleNamespace() {
|
|
return this._type === (t.OBJECT | t.MODULE_NAMESPACE);
|
|
}
|
|
isFunction() {
|
|
return (this._type & 255) === t.FUNCTION;
|
|
}
|
|
isAsyncFunction() {
|
|
return (this._type & (255 | t.ASYNC_FUNCTION)) === (t.FUNCTION | t.ASYNC_FUNCTION);
|
|
}
|
|
isGeneratorFunction() {
|
|
return (this._type & (255 | t.GENERATOR_FUNCTION)) === (t.FUNCTION | t.GENERATOR_FUNCTION);
|
|
}
|
|
isExternal() {
|
|
return this._type === t.EXTERNAL;
|
|
}
|
|
isBigInt() {
|
|
return this._type === t.BIGINT;
|
|
}
|
|
};
|
|
module.exports = exports = function type(value) {
|
|
switch (typeof value) {
|
|
case "undefined":
|
|
return new Type(t.UNDEFINED);
|
|
case "boolean":
|
|
return new Type(t.BOOLEAN);
|
|
case "number":
|
|
return new Type(
|
|
Number.isSafeInteger(value) ? binding.type(value) : t.NUMBER
|
|
);
|
|
case "string":
|
|
return new Type(t.STRING);
|
|
case "symbol":
|
|
return new Type(t.SYMBOL);
|
|
case "object":
|
|
return new Type(value === null ? t.NULL : binding.type(value));
|
|
case "function":
|
|
return new Type(binding.type(value));
|
|
case "bigint":
|
|
return new Type(t.BIGINT);
|
|
}
|
|
};
|
|
exports.createTag = function createTag(...components) {
|
|
const tag = new Uint32Array(4);
|
|
for (let i = 0; i < 4; i++) tag[i] = components[i] || 0;
|
|
return tag;
|
|
};
|
|
exports.addTag = function addTag(object, tag) {
|
|
binding.addTag(object, tag);
|
|
};
|
|
exports.checkTag = function checkTag(object, tag) {
|
|
return binding.checkTag(object, tag);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-inspect/binding.js
|
|
var require_binding2 = __commonJS({
|
|
"../../node_modules/bare-inspect/binding.js"(exports, module) {
|
|
module.exports = __require.addon();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-inspect/index.js
|
|
var require_bare_inspect = __commonJS({
|
|
"../../node_modules/bare-inspect/index.js"(exports, module) {
|
|
var ansiEscapes = require_bare_ansi_escapes();
|
|
var getType = require_bare_type();
|
|
var binding = require_binding2();
|
|
var PLAIN_KEY = /^[a-zA-Z_][a-zA-Z_0-9]*$/;
|
|
var defaultDepth = 2;
|
|
var defaultBreakLength = 80;
|
|
var defaultMaxArrayLength = 40;
|
|
module.exports = exports = function inspect(value, opts = {}) {
|
|
const {
|
|
colors = false,
|
|
depth = defaultDepth,
|
|
breakLength = defaultBreakLength,
|
|
stylize = defaultStylize(colors)
|
|
} = opts;
|
|
const references = new InspectRefMap();
|
|
const tree = inspectValue(value, 0, {
|
|
colors,
|
|
depth,
|
|
breakLength,
|
|
stylize,
|
|
references
|
|
});
|
|
return tree.toString();
|
|
};
|
|
exports.styles = {
|
|
bigint: ansiEscapes.colorYellow,
|
|
boolean: ansiEscapes.colorYellow,
|
|
date: ansiEscapes.colorMagenta,
|
|
module: ansiEscapes.modifierUnderline,
|
|
name: ansiEscapes.modifierReset,
|
|
null: ansiEscapes.modifierBold,
|
|
number: ansiEscapes.colorYellow,
|
|
regexp: ansiEscapes.colorRed,
|
|
special: ansiEscapes.colorCyan,
|
|
string: ansiEscapes.colorGreen,
|
|
symbol: ansiEscapes.colorGreen,
|
|
undefined: ansiEscapes.colorBrightBlack
|
|
};
|
|
var styles = exports.styles;
|
|
function defaultStylize(colors) {
|
|
return function stylize(value, style) {
|
|
const color = colors && styles[style];
|
|
if (color) return color + value + ansiEscapes.modifierReset;
|
|
return value;
|
|
};
|
|
}
|
|
var InspectRefMap = class {
|
|
constructor() {
|
|
this.refs = /* @__PURE__ */ new WeakMap();
|
|
this.ids = /* @__PURE__ */ new WeakMap();
|
|
this.nextId = 1;
|
|
}
|
|
has(object) {
|
|
return this.refs.has(object);
|
|
}
|
|
get(object) {
|
|
return this.refs.get(object) || null;
|
|
}
|
|
set(object, ref) {
|
|
this.refs.set(object, ref);
|
|
}
|
|
id(object) {
|
|
let id = this.ids.get(object);
|
|
if (id) return id;
|
|
id = this.nextId++;
|
|
this.ids.set(object, id);
|
|
return id;
|
|
}
|
|
};
|
|
var InspectNode = class {
|
|
constructor(depth, length, opts) {
|
|
const { breakLength = defaultBreakLength, breakAlways = false } = opts;
|
|
this.depth = depth;
|
|
this.length = length;
|
|
this.breakLength = breakLength;
|
|
this.breakAlways = breakAlways;
|
|
}
|
|
pad(n, string) {
|
|
return string.padStart(n, " ");
|
|
}
|
|
indent(n, string) {
|
|
return " ".repeat(n) + string;
|
|
}
|
|
};
|
|
var InspectRef = class extends InspectNode {
|
|
constructor(depth, opts) {
|
|
super(depth, "[circular *]".length, opts);
|
|
this.refs = opts.references;
|
|
this.count = 0;
|
|
this.circular = false;
|
|
this.color = opts.colors && styles.special;
|
|
}
|
|
get id() {
|
|
return this.refs.id(this);
|
|
}
|
|
increment() {
|
|
return ++this.count;
|
|
}
|
|
decrement() {
|
|
return --this.count;
|
|
}
|
|
toString(opts = {}) {
|
|
const { offset = 0, pad = 0, indent = 0 } = opts;
|
|
let value = this.pad(pad, "[circular *" + this.id + "]");
|
|
if (this.color) value = this.color + value + ansiEscapes.modifierReset;
|
|
return offset ? value : this.indent(indent, value);
|
|
}
|
|
};
|
|
var InspectLeaf = class extends InspectNode {
|
|
constructor(value, color, depth, opts) {
|
|
const length = value.length;
|
|
if (value.includes("\n")) {
|
|
value = value.replaceAll("\n", "\n" + " ".repeat(depth));
|
|
opts = { ...opts, breakAlways: true };
|
|
}
|
|
super(depth, length, opts);
|
|
this.value = value;
|
|
this.color = opts.colors && color;
|
|
}
|
|
toString(opts = {}) {
|
|
const { offset = 0, pad = 0, indent = 0 } = opts;
|
|
let value = this.pad(pad, this.value);
|
|
if (this.color) value = this.color + value + ansiEscapes.modifierReset;
|
|
return offset ? value : this.indent(indent, value);
|
|
}
|
|
};
|
|
var InspectPair = class extends InspectNode {
|
|
constructor(delim, left, right, depth, opts) {
|
|
const length = left.length + delim.length + right.length;
|
|
if (left.breakAlways || right.breakAlways) {
|
|
opts = { ...opts, breakAlways: true };
|
|
}
|
|
super(depth, length, opts);
|
|
this.delim = delim;
|
|
this.left = left;
|
|
this.right = right;
|
|
}
|
|
toString(opts = {}) {
|
|
const { indent = 0 } = opts;
|
|
return this.indent(
|
|
indent,
|
|
this.left + this.delim + this.right.toString({
|
|
indent,
|
|
offset: this.left.length + this.delim.length
|
|
})
|
|
);
|
|
}
|
|
};
|
|
var InspectSuspension = class extends InspectNode {
|
|
constructor(overflow, depth, opts) {
|
|
const label = `... ${overflow} more`;
|
|
super(depth, label.length, opts);
|
|
this.label = label;
|
|
}
|
|
toString(opts = {}) {
|
|
const { indent = 0 } = opts;
|
|
return this.indent(indent, this.label);
|
|
}
|
|
};
|
|
var InspectSequence = class extends InspectNode {
|
|
constructor(header, footer, delim, values, ref, depth, opts) {
|
|
const { tabulate = false } = opts;
|
|
const length = (ref.circular ? "<ref *>".length + 1 : 0) + header.length + values.reduce(
|
|
(length2, value, i) => length2 + value.length + (i === 0 ? 0 : delim.length),
|
|
0
|
|
) + footer.length;
|
|
if (values.some((value) => value.breakAlways)) {
|
|
opts = { ...opts, breakAlways: true };
|
|
}
|
|
super(depth, length, opts);
|
|
this.header = header;
|
|
this.footer = footer;
|
|
this.delim = delim;
|
|
this.values = values;
|
|
this.ref = ref;
|
|
this.tabulate = tabulate;
|
|
}
|
|
toString(opts = {}) {
|
|
const { offset = 0, indent = 0 } = opts;
|
|
const split = this.breakAlways || this.values.length && (offset + this.length > this.breakLength || indent * 2 + this.length > this.breakLength);
|
|
let header = this.header;
|
|
if (this.ref.circular) {
|
|
header = "<ref *" + this.ref.id + "> " + header;
|
|
}
|
|
if (this.values.length === 0) {
|
|
header = header.trimEnd();
|
|
}
|
|
if (offset === 0) {
|
|
header = this.indent(indent, header);
|
|
}
|
|
if (split) {
|
|
header = header.trimEnd() + "\n";
|
|
}
|
|
let string = header;
|
|
let columns = 1;
|
|
let pad = 0;
|
|
if (this.tabulate) {
|
|
const widest = this.values.reduce(
|
|
(length, value) => value.breakAlways ? length : Math.max(length, value.length),
|
|
0
|
|
);
|
|
if (widest) {
|
|
columns = Math.max(
|
|
columns,
|
|
Math.floor(
|
|
(this.breakLength - indent * 2) / (widest + this.delim.length)
|
|
)
|
|
);
|
|
if (columns > 1) pad = widest;
|
|
}
|
|
}
|
|
for (let i = 0, n = this.values.length, offset2 = 0; i < n; i++) {
|
|
const value = this.values[i];
|
|
if (split) {
|
|
let part;
|
|
if (i % columns === 0 || value.breakAlways) {
|
|
part = value.toString({ indent: indent + 1, pad });
|
|
} else {
|
|
part = value.toString({ pad });
|
|
}
|
|
string += part;
|
|
if (i < n - 1) {
|
|
if (i % columns === columns - 1 || this.values[i + 1].breakAlways) {
|
|
string += this.delim.trimEnd() + "\n";
|
|
} else {
|
|
string += this.delim;
|
|
}
|
|
}
|
|
} else {
|
|
if (i > 0) string += this.delim;
|
|
string += value.toString({ offset: offset2 });
|
|
offset2 += value.length;
|
|
}
|
|
}
|
|
let footer = this.footer;
|
|
if (this.values.length === 0) {
|
|
footer = footer.trimStart();
|
|
}
|
|
if (split) {
|
|
string += "\n" + this.indent(indent, footer.trimStart());
|
|
} else {
|
|
string += footer;
|
|
}
|
|
return string;
|
|
}
|
|
};
|
|
function inspectValue(value, depth, opts) {
|
|
const type = getType(value);
|
|
if (type.isUndefined()) return inspectUndefined(depth, opts);
|
|
if (type.isNull()) return inspectNull(depth, opts);
|
|
if (type.isBoolean()) return inspectBoolean(value, depth, opts);
|
|
if (type.isNumber()) return inspectNumber(value, depth, opts);
|
|
if (type.isBigInt()) return inspectBigInt(value, depth, opts);
|
|
if (type.isString()) return inspectString(value, depth, opts);
|
|
if (type.isSymbol()) return inspectSymbol(value, depth, opts);
|
|
if (type.isObject()) return inspectObject(type, value, depth, opts);
|
|
if (type.isFunction()) return inspectFunction(type, value, depth, opts);
|
|
if (type.isExternal()) return inspectExternal(value, opts, opts);
|
|
}
|
|
function inspectUndefined(depth, opts) {
|
|
return new InspectLeaf("undefined", styles.undefined, depth, opts);
|
|
}
|
|
function inspectNull(depth, opts) {
|
|
return new InspectLeaf("null", styles.null, depth, opts);
|
|
}
|
|
function inspectBoolean(value, depth, opts) {
|
|
return new InspectLeaf(value.toString(), styles.boolean, depth, opts);
|
|
}
|
|
function inspectNumber(value, depth, opts) {
|
|
let string;
|
|
if (Object.is(value, -0)) {
|
|
string = "-0";
|
|
} else {
|
|
string = value.toString(10);
|
|
}
|
|
return new InspectLeaf(string, styles.number, depth, opts);
|
|
}
|
|
function inspectBigInt(value, depth, opts) {
|
|
return new InspectLeaf(value.toString(10) + "n", styles.bigint, depth, opts);
|
|
}
|
|
var STRING_ESCAPES = /[\ud800-\udbff][\udc00-\udfff]|[\u0000-\u001f'\\\ud800-\udfff]/g;
|
|
function inspectString(value, depth, opts) {
|
|
const string = value.replace(STRING_ESCAPES, (match) => {
|
|
if (match.length === 2) return match;
|
|
switch (match) {
|
|
case "'":
|
|
return "\\'";
|
|
case "\\":
|
|
return "\\\\";
|
|
case "\b":
|
|
return "\\b";
|
|
case " ":
|
|
return "\\t";
|
|
case "\n":
|
|
return "\\n";
|
|
case "\f":
|
|
return "\\f";
|
|
case "\r":
|
|
return "\\r";
|
|
default:
|
|
return "\\u" + match.charCodeAt(0).toString(16).padStart(4, "0");
|
|
}
|
|
});
|
|
return new InspectLeaf("'" + string + "'", styles.string, depth, opts);
|
|
}
|
|
function inspectSymbol(value, depth, opts) {
|
|
return new InspectLeaf(value.toString(), styles.symbol, depth, opts);
|
|
}
|
|
function inspectKey(value, depth, opts) {
|
|
if (PLAIN_KEY.test(value)) {
|
|
return new InspectLeaf(value, null, depth, opts);
|
|
} else {
|
|
return inspectValue(value, depth, opts);
|
|
}
|
|
}
|
|
function inspectObject(type, object, depth, opts) {
|
|
const refs = opts.references;
|
|
let ref = refs.get(object);
|
|
if (ref === null) {
|
|
ref = new InspectRef(depth, opts);
|
|
refs.set(object, ref);
|
|
} else if (ref.count) {
|
|
ref.circular = true;
|
|
return ref;
|
|
}
|
|
const maxDepth = typeof opts.depth === "number" ? opts.depth : Infinity;
|
|
if (maxDepth < depth) {
|
|
const constructor = object.constructor;
|
|
return new InspectLeaf(
|
|
"[" + (constructor && constructor.name ? constructor.name : "Object") + "]",
|
|
styles.special,
|
|
depth,
|
|
opts
|
|
);
|
|
}
|
|
const inspect = object[Symbol.for("bare.inspect")] || object[Symbol.for("nodejs.util.inspect.custom")];
|
|
if (typeof inspect === "function") {
|
|
const value = inspect.call(
|
|
object,
|
|
typeof opts.depth === "number" ? opts.depth - depth : null,
|
|
{
|
|
colors: opts.colors,
|
|
breakLength: opts.breakLength,
|
|
stylize: opts.stylize
|
|
},
|
|
exports
|
|
);
|
|
if (typeof value === "object" && value !== null) {
|
|
refs.set(value, ref);
|
|
}
|
|
if (typeof value !== "string") {
|
|
return inspectValue(value, depth, opts);
|
|
}
|
|
return new InspectLeaf(value, null, depth, opts);
|
|
}
|
|
if (type.isArray()) return inspectArray(object, ref, depth, opts);
|
|
if (type.isDate()) return inspectDate(object, ref, depth, opts);
|
|
if (type.isRegExp()) return inspectRegExp(object, ref, depth, opts);
|
|
if (type.isError()) return inspectError(object, ref, depth, opts);
|
|
if (type.isPromise()) return inspectPromise(object, ref, depth, opts);
|
|
if (type.isMap()) return inspectMap(object, ref, depth, opts);
|
|
if (type.isSet()) return inspectSet(object, ref, depth, opts);
|
|
if (type.isWeakMap()) return inspectWeakMap(object, ref, depth, opts);
|
|
if (type.isWeakSet()) return inspectWeakSet(object, ref, depth, opts);
|
|
if (type.isWeakRef()) return inspectWeakRef(object, ref, depth, opts);
|
|
if (type.isArrayBuffer()) return inspectArrayBuffer(object, ref, depth, opts);
|
|
if (type.isSharedArrayBuffer())
|
|
return inspectSharedArrayBuffer(object, ref, depth, opts);
|
|
if (type.isTypedArray()) return inspectTypedArray(object, ref, depth, opts);
|
|
if (type.isDataView()) return inspectDataView(object, ref, depth, opts);
|
|
ref.increment();
|
|
const values = [];
|
|
for (const key in object) {
|
|
if (key === "constructor") continue;
|
|
values.push(
|
|
new InspectPair(
|
|
": ",
|
|
inspectKey(key, depth + 1, opts),
|
|
inspectValue(object[key], depth + 1, opts),
|
|
depth + 1,
|
|
opts
|
|
)
|
|
);
|
|
}
|
|
ref.decrement();
|
|
let header = "{ ";
|
|
const tag = object[Symbol.toStringTag];
|
|
if (tag) header = "[" + tag + "] " + header;
|
|
if (object.constructor) {
|
|
const name = object.constructor.name;
|
|
if (name && name !== "Object") {
|
|
header = object.constructor.name + " " + header;
|
|
}
|
|
}
|
|
return new InspectSequence(header, " }", ", ", values, ref, depth, opts);
|
|
}
|
|
function inspectArray(array, ref, depth, opts) {
|
|
const { maxArrayLength = defaultMaxArrayLength } = opts;
|
|
ref.increment();
|
|
const values = [];
|
|
let remaining = Math.max(maxArrayLength, 0);
|
|
for (let i = 0, n = array.length; i < n; i++) {
|
|
if (remaining-- === 0) {
|
|
values.push(
|
|
new InspectSuspension(array.length - values.length, depth + 1, {
|
|
...opts,
|
|
breakAlways: true
|
|
})
|
|
);
|
|
break;
|
|
}
|
|
values.push(inspectValue(array[i], depth + 1, opts));
|
|
}
|
|
for (const key of binding.getOwnNonIndexPropertyNames(array)) {
|
|
values.push(
|
|
new InspectPair(
|
|
": ",
|
|
inspectKey(key, depth + 1, opts),
|
|
inspectValue(array[key], depth + 1, opts),
|
|
depth + 1,
|
|
{ ...opts, breakAlways: remaining < 0 }
|
|
)
|
|
);
|
|
}
|
|
ref.decrement();
|
|
let header = "[ ";
|
|
if (array.constructor.name !== "Array") {
|
|
header = array.constructor.name + "(" + array.length + ") " + header;
|
|
}
|
|
return new InspectSequence(header, " ]", ", ", values, ref, depth, {
|
|
...opts,
|
|
tabulate: true
|
|
});
|
|
}
|
|
function inspectDate(date, ref, depth, opts) {
|
|
return new InspectLeaf(date.toISOString(), styles.date, depth, opts);
|
|
}
|
|
function inspectRegExp(regExp, ref, depth, opts) {
|
|
return new InspectLeaf(regExp.toString(), styles.regexp, depth, opts);
|
|
}
|
|
function inspectError(error, ref, depth, opts) {
|
|
let header;
|
|
if ("stack" in error) {
|
|
header = error.stack;
|
|
if (depth > 0) {
|
|
header = header.replaceAll("\n", "\n" + " ".repeat(depth));
|
|
}
|
|
} else {
|
|
header = error.toString();
|
|
}
|
|
const builtins = ["cause"];
|
|
if (error.name === "AggregateError") {
|
|
builtins.push("errors");
|
|
} else if (error.name === "SuppressedError") {
|
|
builtins.push("error", "suppressed");
|
|
}
|
|
const values = [];
|
|
for (const key of builtins) {
|
|
if (key in error === false) continue;
|
|
values.push(
|
|
new InspectPair(
|
|
": ",
|
|
new InspectLeaf("[" + key + "]", null, depth + 1, opts),
|
|
inspectValue(error[key], depth + 1, opts),
|
|
depth + 1,
|
|
opts
|
|
)
|
|
);
|
|
}
|
|
for (const key in error) {
|
|
if (key === "constructor" || builtins.includes(key)) continue;
|
|
values.push(
|
|
new InspectPair(
|
|
": ",
|
|
inspectKey(key, depth + 1, opts),
|
|
inspectValue(error[key], depth + 1, opts),
|
|
depth + 1,
|
|
opts
|
|
)
|
|
);
|
|
}
|
|
if (values.length === 0) return new InspectLeaf(header, null, depth, opts);
|
|
return new InspectSequence(
|
|
header + " {",
|
|
" }",
|
|
", ",
|
|
values,
|
|
ref,
|
|
depth,
|
|
opts
|
|
);
|
|
}
|
|
function inspectPromise(promise, ref, depth, opts) {
|
|
ref.increment();
|
|
const state = binding.getPromiseState(promise);
|
|
const values = [];
|
|
switch (state) {
|
|
case 0:
|
|
values.push(new InspectLeaf("<pending>", styles.special, depth, opts));
|
|
break;
|
|
case 1:
|
|
values.push(inspectValue(binding.getPromiseResult(promise), depth, opts));
|
|
break;
|
|
case 2:
|
|
values.push(
|
|
new InspectLeaf("<rejected>", styles.special, depth, opts),
|
|
inspectValue(binding.getPromiseResult(promise), depth, opts)
|
|
);
|
|
}
|
|
ref.decrement();
|
|
const header = promise.constructor.name + " { ";
|
|
return new InspectSequence(header, " }", " ", values, ref, depth, opts);
|
|
}
|
|
function inspectMap(map, ref, depth, opts) {
|
|
const {
|
|
maxArrayLength = defaultMaxArrayLength,
|
|
maxMapLength = maxArrayLength
|
|
} = opts;
|
|
ref.increment();
|
|
const values = [];
|
|
let remaining = maxMapLength;
|
|
for (const entry of map) {
|
|
if (remaining-- === 0) {
|
|
values.push(
|
|
new InspectSuspension(map.size - values.length, depth + 1, {
|
|
...opts,
|
|
breakAlways: true
|
|
})
|
|
);
|
|
break;
|
|
}
|
|
values.push(
|
|
new InspectPair(
|
|
" => ",
|
|
inspectValue(entry[0], depth + 1, opts),
|
|
inspectValue(entry[1], depth + 1, opts),
|
|
depth + 1,
|
|
opts
|
|
)
|
|
);
|
|
}
|
|
for (const key in map) {
|
|
if (key === "constructor") continue;
|
|
const value = inspectValue(map[key], depth + 1, opts);
|
|
values.push(
|
|
new InspectPair(
|
|
": ",
|
|
inspectKey(key, depth + 1, opts),
|
|
value,
|
|
depth + 1,
|
|
{ ...opts, breakAlways: remaining < 0 }
|
|
)
|
|
);
|
|
}
|
|
ref.decrement();
|
|
const header = map.constructor.name + "(" + map.size + ") { ";
|
|
return new InspectSequence(header, " }", ", ", values, ref, depth, {
|
|
...opts,
|
|
tabulate: true
|
|
});
|
|
}
|
|
function inspectSet(set, ref, depth, opts) {
|
|
const {
|
|
maxArrayLength = defaultMaxArrayLength,
|
|
maxSetLength = maxArrayLength
|
|
} = opts;
|
|
ref.increment();
|
|
const values = [];
|
|
let remaining = maxSetLength;
|
|
for (const entry of set) {
|
|
if (remaining-- === 0) {
|
|
values.push(
|
|
new InspectSuspension(set.size - values.length, depth + 1, {
|
|
...opts,
|
|
breakAlways: true
|
|
})
|
|
);
|
|
break;
|
|
}
|
|
values.push(inspectValue(entry, depth + 1, opts));
|
|
}
|
|
for (const key in set) {
|
|
if (key === "constructor") continue;
|
|
const value = inspectValue(set[key], depth + 1, opts);
|
|
values.push(
|
|
new InspectPair(
|
|
": ",
|
|
inspectKey(key, depth + 1, opts),
|
|
value,
|
|
depth + 1,
|
|
{ ...opts, breakAlways: remaining < 0 }
|
|
)
|
|
);
|
|
}
|
|
ref.decrement();
|
|
const header = set.constructor.name + "(" + set.size + ") { ";
|
|
return new InspectSequence(header, " }", ", ", values, ref, depth, {
|
|
...opts,
|
|
tabulate: true
|
|
});
|
|
}
|
|
function inspectWeakMap(weakMap, ref, depth, opts) {
|
|
const header = weakMap.constructor.name + " { ";
|
|
return new InspectSequence(
|
|
header,
|
|
" }",
|
|
" ",
|
|
[new InspectLeaf("<items unknown>", styles.special, depth + 1, opts)],
|
|
ref,
|
|
depth,
|
|
opts
|
|
);
|
|
}
|
|
function inspectWeakSet(weakSet, ref, depth, opts) {
|
|
const header = weakSet.constructor.name + " { ";
|
|
return new InspectSequence(
|
|
header,
|
|
" }",
|
|
" ",
|
|
[new InspectLeaf("<items unknown>", styles.special, depth + 1, opts)],
|
|
ref,
|
|
depth,
|
|
opts
|
|
);
|
|
}
|
|
function inspectWeakRef(weakRef, ref, depth, opts) {
|
|
const target = weakRef.deref();
|
|
let value;
|
|
if (target === void 0) {
|
|
value = new InspectLeaf("<cleared>", styles.special, depth + 1, opts);
|
|
} else {
|
|
value = inspectValue(target, depth + 1, opts);
|
|
}
|
|
const header = weakRef.constructor.name + " { ";
|
|
return new InspectSequence(header, " }", " ", [value], ref, depth, opts);
|
|
}
|
|
function inspectArrayBuffer(arrayBuffer, ref, depth, opts) {
|
|
ref.increment();
|
|
const values = [];
|
|
for (const key of ["byteLength"]) {
|
|
values.push(
|
|
new InspectPair(
|
|
": ",
|
|
inspectKey(key, depth + 1, opts),
|
|
inspectValue(arrayBuffer[key], depth + 1, opts),
|
|
depth + 1,
|
|
opts
|
|
)
|
|
);
|
|
}
|
|
ref.decrement();
|
|
const header = arrayBuffer.constructor.name + " { ";
|
|
return new InspectSequence(header, " }", ", ", values, ref, depth, opts);
|
|
}
|
|
function inspectSharedArrayBuffer(sharedArrayBuffer, ref, depth, opts) {
|
|
ref.increment();
|
|
const values = [];
|
|
for (const key of ["byteLength"]) {
|
|
values.push(
|
|
new InspectPair(
|
|
": ",
|
|
inspectKey(key, depth + 1, opts),
|
|
inspectValue(sharedArrayBuffer[key], depth + 1, opts),
|
|
depth + 1,
|
|
opts
|
|
)
|
|
);
|
|
}
|
|
ref.decrement();
|
|
const header = sharedArrayBuffer.constructor.name + " { ";
|
|
return new InspectSequence(header, " }", ", ", values, ref, depth, opts);
|
|
}
|
|
function inspectTypedArray(typedArray, ref, depth, opts) {
|
|
if (Buffer.isBuffer(typedArray)) {
|
|
return inspectBuffer(typedArray, ref, depth, opts);
|
|
}
|
|
const {
|
|
maxArrayLength = defaultMaxArrayLength,
|
|
maxTypedArrayLength = maxArrayLength
|
|
} = opts;
|
|
ref.increment();
|
|
const values = [];
|
|
let remaining = Math.max(maxTypedArrayLength, 0);
|
|
for (let i = 0, n = typedArray.length; i < n; i++) {
|
|
if (remaining-- === 0) {
|
|
values.push(
|
|
new InspectSuspension(typedArray.length - values.length, depth + 1, {
|
|
...opts,
|
|
breakAlways: true
|
|
})
|
|
);
|
|
break;
|
|
}
|
|
values.push(inspectValue(typedArray[i], depth + 1, opts));
|
|
}
|
|
for (const key of binding.getOwnNonIndexPropertyNames(typedArray)) {
|
|
values.push(
|
|
new InspectPair(
|
|
": ",
|
|
inspectKey(key, depth + 1, opts),
|
|
inspectValue(typedArray[key], depth + 1, opts),
|
|
depth + 1,
|
|
{ ...opts, breakAlways: remaining < 0 }
|
|
)
|
|
);
|
|
}
|
|
ref.decrement();
|
|
const header = typedArray.constructor.name + "(" + typedArray.length + ") [ ";
|
|
return new InspectSequence(header, " ]", ", ", values, ref, depth, {
|
|
...opts,
|
|
tabulate: true
|
|
});
|
|
}
|
|
function inspectBuffer(buffer, ref, depth, opts) {
|
|
const {
|
|
maxArrayLength = defaultMaxArrayLength,
|
|
maxBufferLength = maxArrayLength
|
|
} = opts;
|
|
ref.increment();
|
|
const values = [];
|
|
let remaining = Math.max(maxBufferLength, 0);
|
|
for (let i = 0, n = buffer.byteLength; i < n; i++) {
|
|
if (remaining-- === 0) {
|
|
values.push(
|
|
new InspectSuspension(buffer.length - values.length, depth + 1, {
|
|
...opts,
|
|
breakAlways: true
|
|
})
|
|
);
|
|
break;
|
|
}
|
|
values.push(
|
|
new InspectLeaf(
|
|
buffer[i].toString(16).padStart(2, "0"),
|
|
null,
|
|
depth + 1,
|
|
opts
|
|
)
|
|
);
|
|
}
|
|
for (const key of binding.getOwnNonIndexPropertyNames(buffer)) {
|
|
values.push(
|
|
new InspectPair(
|
|
": ",
|
|
inspectKey(key, depth + 1, opts),
|
|
inspectValue(buffer[key], depth + 1, opts),
|
|
depth + 1,
|
|
{ ...opts, breakAlways: remaining < 0 }
|
|
)
|
|
);
|
|
}
|
|
ref.decrement();
|
|
return new InspectSequence("<Buffer ", ">", " ", values, ref, depth, {
|
|
...opts,
|
|
tabulate: true
|
|
});
|
|
}
|
|
function inspectDataView(dataView, ref, depth, opts) {
|
|
ref.increment();
|
|
const values = [];
|
|
for (const key of ["byteLength", "byteOffset", "buffer"]) {
|
|
values.push(
|
|
new InspectPair(
|
|
": ",
|
|
inspectKey(key, depth + 1, opts),
|
|
inspectValue(dataView[key], depth + 1, opts),
|
|
depth + 1,
|
|
opts
|
|
)
|
|
);
|
|
}
|
|
for (const key of binding.getOwnNonIndexPropertyNames(dataView)) {
|
|
values.push(
|
|
new InspectPair(
|
|
": ",
|
|
inspectKey(key, depth + 1, opts),
|
|
inspectValue(dataView[key], depth + 1, opts),
|
|
depth + 1,
|
|
opts
|
|
)
|
|
);
|
|
}
|
|
ref.decrement();
|
|
const header = dataView.constructor.name + " { ";
|
|
return new InspectSequence(header, " }", ", ", values, ref, depth, opts);
|
|
}
|
|
function inspectFunction(type, fn, depth, opts) {
|
|
if (fn.toString().startsWith("class")) return inspectClass(fn, depth, opts);
|
|
let tag = "function";
|
|
if (type.isGeneratorFunction()) tag = "generator " + tag;
|
|
if (type.isAsyncFunction()) tag = "async " + tag;
|
|
return new InspectLeaf(
|
|
"[" + tag + " " + (fn.name ? fn.name : "(anonymous)") + "]",
|
|
styles.special,
|
|
depth,
|
|
opts
|
|
);
|
|
}
|
|
function inspectClass(ctor, depth, opts) {
|
|
return new InspectLeaf(
|
|
"[class " + (ctor.name ? ctor.name : "(anonymous)") + "]",
|
|
styles.special,
|
|
depth,
|
|
opts
|
|
);
|
|
}
|
|
function inspectExternal(external, depth, opts) {
|
|
return new InspectLeaf(
|
|
"[external 0x" + binding.getExternal(external).toString(16) + "]",
|
|
styles.special,
|
|
depth,
|
|
opts
|
|
);
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-assert/index.js
|
|
var require_bare_assert = __commonJS({
|
|
"../../node_modules/bare-assert/index.js"(exports, module) {
|
|
var inspect = require_bare_inspect();
|
|
var AssertionError = class extends Error {
|
|
constructor(opts = {}) {
|
|
let { message = null, actual, expected, operator } = opts;
|
|
if (message === null) {
|
|
message = `${inspect(actual)} ${operator} ${inspect(expected)}`;
|
|
}
|
|
super(message);
|
|
this.actual = actual;
|
|
this.expected = expected;
|
|
this.operator = operator;
|
|
}
|
|
get name() {
|
|
return "AssertionError";
|
|
}
|
|
get code() {
|
|
"ASSERTION";
|
|
}
|
|
};
|
|
function assertFail(opts, fn) {
|
|
if (opts.message instanceof Error) throw opts.message;
|
|
const err = new AssertionError(opts);
|
|
if (Error.captureStackTrace) Error.captureStackTrace(err, fn);
|
|
throw err;
|
|
}
|
|
module.exports = exports = function assert(actual, message) {
|
|
if (actual) return;
|
|
assertFail({ message, actual, expected: true, operator: "==" }, assert);
|
|
};
|
|
exports.AssertionError = AssertionError;
|
|
exports.fail = function fail(message) {
|
|
if (message === void 0) message = "Failed";
|
|
assertFail({ message, operator: "fail" }, fail);
|
|
};
|
|
exports.ok = function ok(actual, message) {
|
|
if (actual) return;
|
|
assertFail({ message, actual, expected: true, operator: "==" }, ok);
|
|
};
|
|
exports.notOk = function ok(actual, message) {
|
|
if (!actual) return;
|
|
assertFail({ message, actual, expected: false, operator: "==" }, ok);
|
|
};
|
|
exports.equal = function equal(actual, expected, message) {
|
|
if (actual == expected || actual !== actual && expected !== expected) {
|
|
return;
|
|
}
|
|
assertFail({ message, actual, expected, operator: "==" }, equal);
|
|
};
|
|
exports.notEqual = function notEqual(actual, expected, message) {
|
|
if (actual != expected && (actual === actual || expected === expected)) {
|
|
return;
|
|
}
|
|
assertFail({ message, actual, expected, operator: "!=" }, notEqual);
|
|
};
|
|
exports.strictEqual = function strictEqual(actual, expected, message) {
|
|
if (Object.is(actual, expected)) return;
|
|
assertFail(
|
|
{ message, actual, expected, operator: "strictEqual" },
|
|
strictEqual
|
|
);
|
|
};
|
|
exports.notStrictEqual = function notStrictEqual(actual, expected, message) {
|
|
if (!Object.is(actual, expected)) return;
|
|
assertFail(
|
|
{ message, actual, expected, operator: "notStrictEqual" },
|
|
notStrictEqual
|
|
);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-crypto/binding.js
|
|
var require_binding3 = __commonJS({
|
|
"../../node_modules/bare-crypto/binding.js"(exports, module) {
|
|
module.exports = __require.addon();
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-crypto/lib/errors.js
|
|
var require_errors = __commonJS({
|
|
"../../node_modules/bare-crypto/lib/errors.js"(exports, module) {
|
|
module.exports = class CryptoError extends Error {
|
|
constructor(msg, fn = CryptoError, code = fn.name) {
|
|
super(`${code}: ${msg}`);
|
|
this.code = code;
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this, fn);
|
|
}
|
|
}
|
|
get name() {
|
|
return "CryptoError";
|
|
}
|
|
static UNKNOWN_HASH(msg) {
|
|
return new CryptoError(msg, CryptoError.UNKNOWN_HASH);
|
|
}
|
|
static UNKNOWN_CIPHER(msg) {
|
|
return new CryptoError(msg, CryptoError.UNKNOWN_CIPHER);
|
|
}
|
|
static UNKNOWN_KEY_TYPE(msg) {
|
|
return new CryptoError(msg, CryptoError.UNKNOWN_KEY_TYPE);
|
|
}
|
|
static INVALID_ACCESS(msg) {
|
|
return new CryptoError(msg, CryptoError.INVALID_ACCESS);
|
|
}
|
|
static INVALID_DATA(msg) {
|
|
return new CryptoError(msg, CryptoError.INVALID_DATA);
|
|
}
|
|
static OPERATION_ERROR(msg) {
|
|
return new CryptoError(msg, CryptoError.OPERATION_ERROR);
|
|
}
|
|
static NOT_SUPPORTED(msg) {
|
|
return new CryptoError(msg, CryptoError.NOT_SUPPORTED);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-crypto/lib/constants.js
|
|
var require_constants = __commonJS({
|
|
"../../node_modules/bare-crypto/lib/constants.js"(exports, module) {
|
|
var { fail } = require_bare_assert();
|
|
var binding = require_binding3();
|
|
var errors = require_errors();
|
|
module.exports = exports = {
|
|
hash: {
|
|
MD5: binding.MD5,
|
|
SHA1: binding.SHA1,
|
|
SHA256: binding.SHA256,
|
|
SHA384: binding.SHA384,
|
|
SHA512: binding.SHA512,
|
|
BLAKE2B256: binding.BLAKE2B256,
|
|
RIPEMD160: binding.RIPEMD160
|
|
},
|
|
signature: {
|
|
ED25519: binding.ED25519
|
|
},
|
|
cipher: {
|
|
AES128ECB: binding.AES128ECB,
|
|
AES128CBC: binding.AES128CBC,
|
|
AES128CTR: binding.AES128CTR,
|
|
AES128OFB: binding.AES128OFB,
|
|
AES256ECB: binding.AES256ECB,
|
|
AES256CBC: binding.AES256CBC,
|
|
AES256CTR: binding.AES256CTR,
|
|
AES256OFB: binding.AES256OFB,
|
|
AES128GCM: binding.AES128GCM,
|
|
AES256GCM: binding.AES256GCM,
|
|
CHACHA20POLY1305: binding.CHACHA20POLY1305,
|
|
XCHACHA20POLY1305: binding.XCHACHA20POLY1305
|
|
},
|
|
keyType: {
|
|
ED25519: binding.ED25519
|
|
}
|
|
};
|
|
exports.toHash = function toHash(hash) {
|
|
if (typeof hash === "number" && !isNaN(hash)) return hash;
|
|
if (typeof hash === "string") {
|
|
hash = hash.replace(/-/g, "");
|
|
if (hash in exports.hash === false) {
|
|
hash = hash.toUpperCase();
|
|
if (hash in exports.hash === false) {
|
|
throw errors.UNKNOWN_HASH(`Unknown hash '${hash}'`);
|
|
}
|
|
}
|
|
return exports.hash[hash];
|
|
}
|
|
fail(`Hash must be a number or string. Received ${isNaN(hash) ? "NaN" : typeof hash} (${hash})`);
|
|
};
|
|
exports.toCipher = function toCiper(cipher) {
|
|
if (typeof cipher === "number" && !isNaN(cipher)) return cipher;
|
|
if (typeof cipher === "string") {
|
|
cipher = cipher.replace(/-/g, "");
|
|
if (cipher in exports.cipher === false) {
|
|
cipher = cipher.toUpperCase();
|
|
if (cipher in exports.cipher === false) {
|
|
throw errors.UNKNOWN_CIPHER(`Unknown cipher '${cipher}'`);
|
|
}
|
|
}
|
|
return exports.cipher[cipher];
|
|
}
|
|
fail(
|
|
`Cipher must be a number or string. Received ${isNaN(cipher) ? "NaN" : typeof cipher} (${cipher})`
|
|
);
|
|
};
|
|
exports.toKeyType = function toKeyType(type) {
|
|
if (typeof type === "number" && !isNaN(type)) return type;
|
|
if (typeof type === "string") {
|
|
type = type.replace(/-/g, "");
|
|
if (type in exports.keyType === false) {
|
|
type = type.toUpperCase();
|
|
if (type in exports.keyType === false) {
|
|
throw errors.UNKNOWN_KEY_TYPE(`Unknown key type '${type}'`);
|
|
}
|
|
}
|
|
return exports.keyType[type];
|
|
}
|
|
fail(
|
|
`Key type must be a number or string. Received ${isNaN(type) ? "NaN" : typeof type} (${type})`
|
|
);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/events-universal/default.js
|
|
var require_default = __commonJS({
|
|
"../../node_modules/events-universal/default.js"(exports, module) {
|
|
module.exports = __require("events");
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/fast-fifo/fixed-size.js
|
|
var require_fixed_size = __commonJS({
|
|
"../../node_modules/fast-fifo/fixed-size.js"(exports, module) {
|
|
module.exports = class FixedFIFO {
|
|
constructor(hwm) {
|
|
if (!(hwm > 0) || (hwm - 1 & hwm) !== 0) throw new Error("Max size for a FixedFIFO should be a power of two");
|
|
this.buffer = new Array(hwm);
|
|
this.mask = hwm - 1;
|
|
this.top = 0;
|
|
this.btm = 0;
|
|
this.next = null;
|
|
}
|
|
clear() {
|
|
this.top = this.btm = 0;
|
|
this.next = null;
|
|
this.buffer.fill(void 0);
|
|
}
|
|
push(data) {
|
|
if (this.buffer[this.top] !== void 0) return false;
|
|
this.buffer[this.top] = data;
|
|
this.top = this.top + 1 & this.mask;
|
|
return true;
|
|
}
|
|
shift() {
|
|
const last = this.buffer[this.btm];
|
|
if (last === void 0) return void 0;
|
|
this.buffer[this.btm] = void 0;
|
|
this.btm = this.btm + 1 & this.mask;
|
|
return last;
|
|
}
|
|
peek() {
|
|
return this.buffer[this.btm];
|
|
}
|
|
isEmpty() {
|
|
return this.buffer[this.btm] === void 0;
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/fast-fifo/index.js
|
|
var require_fast_fifo = __commonJS({
|
|
"../../node_modules/fast-fifo/index.js"(exports, module) {
|
|
var FixedFIFO = require_fixed_size();
|
|
module.exports = class FastFIFO {
|
|
constructor(hwm) {
|
|
this.hwm = hwm || 16;
|
|
this.head = new FixedFIFO(this.hwm);
|
|
this.tail = this.head;
|
|
this.length = 0;
|
|
}
|
|
clear() {
|
|
this.head = this.tail;
|
|
this.head.clear();
|
|
this.length = 0;
|
|
}
|
|
push(val) {
|
|
this.length++;
|
|
if (!this.head.push(val)) {
|
|
const prev = this.head;
|
|
this.head = prev.next = new FixedFIFO(2 * this.head.buffer.length);
|
|
this.head.push(val);
|
|
}
|
|
}
|
|
shift() {
|
|
if (this.length !== 0) this.length--;
|
|
const val = this.tail.shift();
|
|
if (val === void 0 && this.tail.next) {
|
|
const next = this.tail.next;
|
|
this.tail.next = null;
|
|
this.tail = next;
|
|
return this.tail.shift();
|
|
}
|
|
return val;
|
|
}
|
|
peek() {
|
|
const val = this.tail.peek();
|
|
if (val === void 0 && this.tail.next) return this.tail.next.peek();
|
|
return val;
|
|
}
|
|
isEmpty() {
|
|
return this.length === 0;
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/b4a/index.js
|
|
var require_b4a = __commonJS({
|
|
"../../node_modules/b4a/index.js"(exports, module) {
|
|
function isBuffer(value) {
|
|
return Buffer.isBuffer(value) || value instanceof Uint8Array;
|
|
}
|
|
function isEncoding(encoding) {
|
|
return Buffer.isEncoding(encoding);
|
|
}
|
|
function alloc(size, fill2, encoding) {
|
|
return Buffer.alloc(size, fill2, encoding);
|
|
}
|
|
function allocUnsafe(size) {
|
|
return Buffer.allocUnsafe(size);
|
|
}
|
|
function allocUnsafeSlow(size) {
|
|
return Buffer.allocUnsafeSlow(size);
|
|
}
|
|
function byteLength(string, encoding) {
|
|
return Buffer.byteLength(string, encoding);
|
|
}
|
|
function compare(a, b) {
|
|
return Buffer.compare(a, b);
|
|
}
|
|
function concat(buffers, totalLength) {
|
|
return Buffer.concat(buffers, totalLength);
|
|
}
|
|
function copy(source, target, targetStart, start, end) {
|
|
return toBuffer(source).copy(target, targetStart, start, end);
|
|
}
|
|
function equals(a, b) {
|
|
return toBuffer(a).equals(b);
|
|
}
|
|
function fill(buffer, value, offset, end, encoding) {
|
|
return toBuffer(buffer).fill(value, offset, end, encoding);
|
|
}
|
|
function from(value, encodingOrOffset, length) {
|
|
return Buffer.from(value, encodingOrOffset, length);
|
|
}
|
|
function includes(buffer, value, byteOffset, encoding) {
|
|
return toBuffer(buffer).includes(value, byteOffset, encoding);
|
|
}
|
|
function indexOf(buffer, value, byfeOffset, encoding) {
|
|
return toBuffer(buffer).indexOf(value, byfeOffset, encoding);
|
|
}
|
|
function lastIndexOf(buffer, value, byteOffset, encoding) {
|
|
return toBuffer(buffer).lastIndexOf(value, byteOffset, encoding);
|
|
}
|
|
function swap16(buffer) {
|
|
return toBuffer(buffer).swap16();
|
|
}
|
|
function swap32(buffer) {
|
|
return toBuffer(buffer).swap32();
|
|
}
|
|
function swap64(buffer) {
|
|
return toBuffer(buffer).swap64();
|
|
}
|
|
function toBuffer(buffer) {
|
|
if (Buffer.isBuffer(buffer)) return buffer;
|
|
return Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
}
|
|
function toString(buffer, encoding, start, end) {
|
|
return toBuffer(buffer).toString(encoding, start, end);
|
|
}
|
|
function write(buffer, string, offset, length, encoding) {
|
|
return toBuffer(buffer).write(string, offset, length, encoding);
|
|
}
|
|
function readDoubleBE(buffer, offset) {
|
|
return toBuffer(buffer).readDoubleBE(offset);
|
|
}
|
|
function readDoubleLE(buffer, offset) {
|
|
return toBuffer(buffer).readDoubleLE(offset);
|
|
}
|
|
function readFloatBE(buffer, offset) {
|
|
return toBuffer(buffer).readFloatBE(offset);
|
|
}
|
|
function readFloatLE(buffer, offset) {
|
|
return toBuffer(buffer).readFloatLE(offset);
|
|
}
|
|
function readInt32BE(buffer, offset) {
|
|
return toBuffer(buffer).readInt32BE(offset);
|
|
}
|
|
function readInt32LE(buffer, offset) {
|
|
return toBuffer(buffer).readInt32LE(offset);
|
|
}
|
|
function readUInt32BE(buffer, offset) {
|
|
return toBuffer(buffer).readUInt32BE(offset);
|
|
}
|
|
function readUInt32LE(buffer, offset) {
|
|
return toBuffer(buffer).readUInt32LE(offset);
|
|
}
|
|
function writeDoubleBE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeDoubleBE(value, offset);
|
|
}
|
|
function writeDoubleLE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeDoubleLE(value, offset);
|
|
}
|
|
function writeFloatBE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeFloatBE(value, offset);
|
|
}
|
|
function writeFloatLE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeFloatLE(value, offset);
|
|
}
|
|
function writeInt32BE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeInt32BE(value, offset);
|
|
}
|
|
function writeInt32LE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeInt32LE(value, offset);
|
|
}
|
|
function writeUInt32BE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeUInt32BE(value, offset);
|
|
}
|
|
function writeUInt32LE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeUInt32LE(value, offset);
|
|
}
|
|
module.exports = {
|
|
isBuffer,
|
|
isEncoding,
|
|
alloc,
|
|
allocUnsafe,
|
|
allocUnsafeSlow,
|
|
byteLength,
|
|
compare,
|
|
concat,
|
|
copy,
|
|
equals,
|
|
fill,
|
|
from,
|
|
includes,
|
|
indexOf,
|
|
lastIndexOf,
|
|
swap16,
|
|
swap32,
|
|
swap64,
|
|
toBuffer,
|
|
toString,
|
|
write,
|
|
readDoubleBE,
|
|
readDoubleLE,
|
|
readFloatBE,
|
|
readFloatLE,
|
|
readInt32BE,
|
|
readInt32LE,
|
|
readUInt32BE,
|
|
readUInt32LE,
|
|
writeDoubleBE,
|
|
writeDoubleLE,
|
|
writeFloatBE,
|
|
writeFloatLE,
|
|
writeInt32BE,
|
|
writeInt32LE,
|
|
writeUInt32BE,
|
|
writeUInt32LE
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/text-decoder/lib/pass-through-decoder.js
|
|
var require_pass_through_decoder = __commonJS({
|
|
"../../node_modules/text-decoder/lib/pass-through-decoder.js"(exports, module) {
|
|
var b4a = require_b4a();
|
|
module.exports = class PassThroughDecoder {
|
|
constructor(encoding) {
|
|
this.encoding = encoding;
|
|
}
|
|
get remaining() {
|
|
return 0;
|
|
}
|
|
decode(data) {
|
|
return b4a.toString(data, this.encoding);
|
|
}
|
|
flush() {
|
|
return "";
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/text-decoder/lib/utf8-decoder.js
|
|
var require_utf8_decoder = __commonJS({
|
|
"../../node_modules/text-decoder/lib/utf8-decoder.js"(exports, module) {
|
|
var b4a = require_b4a();
|
|
module.exports = class UTF8Decoder {
|
|
constructor() {
|
|
this._reset();
|
|
}
|
|
get remaining() {
|
|
return this.bytesSeen;
|
|
}
|
|
decode(data) {
|
|
if (data.byteLength === 0) return "";
|
|
if (this.bytesNeeded === 0 && trailingIncomplete(data, 0) === 0) {
|
|
this.bytesSeen = trailingBytesSeen(data);
|
|
return b4a.toString(data, "utf8");
|
|
}
|
|
let result = "";
|
|
let start = 0;
|
|
if (this.bytesNeeded > 0) {
|
|
while (start < data.byteLength) {
|
|
const byte = data[start];
|
|
if (byte < this.lowerBoundary || byte > this.upperBoundary) {
|
|
result += "\uFFFD";
|
|
this._reset();
|
|
break;
|
|
}
|
|
this.lowerBoundary = 128;
|
|
this.upperBoundary = 191;
|
|
this.codePoint = this.codePoint << 6 | byte & 63;
|
|
this.bytesSeen++;
|
|
start++;
|
|
if (this.bytesSeen === this.bytesNeeded) {
|
|
result += String.fromCodePoint(this.codePoint);
|
|
this._reset();
|
|
break;
|
|
}
|
|
}
|
|
if (this.bytesNeeded > 0) return result;
|
|
}
|
|
const trailing = trailingIncomplete(data, start);
|
|
const end = data.byteLength - trailing;
|
|
if (end > start) result += b4a.toString(data, "utf8", start, end);
|
|
for (let i = end; i < data.byteLength; i++) {
|
|
const byte = data[i];
|
|
if (this.bytesNeeded === 0) {
|
|
if (byte <= 127) {
|
|
this.bytesSeen = 0;
|
|
result += String.fromCharCode(byte);
|
|
} else if (byte >= 194 && byte <= 223) {
|
|
this.bytesNeeded = 2;
|
|
this.bytesSeen = 1;
|
|
this.codePoint = byte & 31;
|
|
} else if (byte >= 224 && byte <= 239) {
|
|
if (byte === 224) this.lowerBoundary = 160;
|
|
else if (byte === 237) this.upperBoundary = 159;
|
|
this.bytesNeeded = 3;
|
|
this.bytesSeen = 1;
|
|
this.codePoint = byte & 15;
|
|
} else if (byte >= 240 && byte <= 244) {
|
|
if (byte === 240) this.lowerBoundary = 144;
|
|
else if (byte === 244) this.upperBoundary = 143;
|
|
this.bytesNeeded = 4;
|
|
this.bytesSeen = 1;
|
|
this.codePoint = byte & 7;
|
|
} else {
|
|
this.bytesSeen = 1;
|
|
result += "\uFFFD";
|
|
}
|
|
continue;
|
|
}
|
|
if (byte < this.lowerBoundary || byte > this.upperBoundary) {
|
|
result += "\uFFFD";
|
|
i--;
|
|
this._reset();
|
|
continue;
|
|
}
|
|
this.lowerBoundary = 128;
|
|
this.upperBoundary = 191;
|
|
this.codePoint = this.codePoint << 6 | byte & 63;
|
|
this.bytesSeen++;
|
|
if (this.bytesSeen === this.bytesNeeded) {
|
|
result += String.fromCodePoint(this.codePoint);
|
|
this._reset();
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
flush() {
|
|
const result = this.bytesNeeded > 0 ? "\uFFFD" : "";
|
|
this._reset();
|
|
return result;
|
|
}
|
|
_reset() {
|
|
this.codePoint = 0;
|
|
this.bytesNeeded = 0;
|
|
this.bytesSeen = 0;
|
|
this.lowerBoundary = 128;
|
|
this.upperBoundary = 191;
|
|
}
|
|
};
|
|
function trailingIncomplete(data, start) {
|
|
const len = data.byteLength;
|
|
if (len <= start) return 0;
|
|
const limit = Math.max(start, len - 4);
|
|
let i = len - 1;
|
|
while (i > limit && (data[i] & 192) === 128) i--;
|
|
if (i < start) return 0;
|
|
const byte = data[i];
|
|
let needed;
|
|
if (byte <= 127) return 0;
|
|
if (byte >= 194 && byte <= 223) needed = 2;
|
|
else if (byte >= 224 && byte <= 239) needed = 3;
|
|
else if (byte >= 240 && byte <= 244) needed = 4;
|
|
else return 0;
|
|
const available = len - i;
|
|
return available < needed ? available : 0;
|
|
}
|
|
function trailingBytesSeen(data) {
|
|
const len = data.byteLength;
|
|
if (len === 0) return 0;
|
|
const last = data[len - 1];
|
|
if (last <= 127) return 0;
|
|
if ((last & 192) !== 128) return 1;
|
|
const limit = Math.max(0, len - 4);
|
|
let i = len - 2;
|
|
while (i >= limit && (data[i] & 192) === 128) i--;
|
|
if (i < 0) return 1;
|
|
const first = data[i];
|
|
let needed;
|
|
if (first >= 194 && first <= 223) needed = 2;
|
|
else if (first >= 224 && first <= 239) needed = 3;
|
|
else if (first >= 240 && first <= 244) needed = 4;
|
|
else return 1;
|
|
if (len - i !== needed) return 1;
|
|
if (needed >= 3) {
|
|
const second = data[i + 1];
|
|
if (first === 224 && second < 160) return 1;
|
|
if (first === 237 && second > 159) return 1;
|
|
if (first === 240 && second < 144) return 1;
|
|
if (first === 244 && second > 143) return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/text-decoder/index.js
|
|
var require_text_decoder = __commonJS({
|
|
"../../node_modules/text-decoder/index.js"(exports, module) {
|
|
var PassThroughDecoder = require_pass_through_decoder();
|
|
var UTF8Decoder = require_utf8_decoder();
|
|
module.exports = class TextDecoder {
|
|
constructor(encoding = "utf8") {
|
|
this.encoding = normalizeEncoding(encoding);
|
|
switch (this.encoding) {
|
|
case "utf8":
|
|
this.decoder = new UTF8Decoder();
|
|
break;
|
|
case "utf16le":
|
|
case "base64":
|
|
throw new Error("Unsupported encoding: " + this.encoding);
|
|
default:
|
|
this.decoder = new PassThroughDecoder(this.encoding);
|
|
}
|
|
}
|
|
get remaining() {
|
|
return this.decoder.remaining;
|
|
}
|
|
push(data) {
|
|
if (typeof data === "string") return data;
|
|
return this.decoder.decode(data);
|
|
}
|
|
// For Node.js compatibility
|
|
write(data) {
|
|
return this.push(data);
|
|
}
|
|
end(data) {
|
|
let result = "";
|
|
if (data) result = this.push(data);
|
|
result += this.decoder.flush();
|
|
return result;
|
|
}
|
|
};
|
|
function normalizeEncoding(encoding) {
|
|
encoding = encoding.toLowerCase();
|
|
switch (encoding) {
|
|
case "utf8":
|
|
case "utf-8":
|
|
return "utf8";
|
|
case "ucs2":
|
|
case "ucs-2":
|
|
case "utf16le":
|
|
case "utf-16le":
|
|
return "utf16le";
|
|
case "latin1":
|
|
case "binary":
|
|
return "latin1";
|
|
case "base64":
|
|
case "ascii":
|
|
case "hex":
|
|
return encoding;
|
|
default:
|
|
throw new Error("Unknown encoding: " + encoding);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/streamx/index.js
|
|
var require_streamx = __commonJS({
|
|
"../../node_modules/streamx/index.js"(exports, module) {
|
|
var { EventEmitter } = require_default();
|
|
var STREAM_DESTROYED = new Error("Stream was destroyed");
|
|
var PREMATURE_CLOSE = new Error("Premature close");
|
|
var FIFO = require_fast_fifo();
|
|
var TextDecoder = require_text_decoder();
|
|
var qmt = typeof queueMicrotask === "undefined" ? (fn) => global.process.nextTick(fn) : queueMicrotask;
|
|
var MAX = (1 << 29) - 1;
|
|
var OPENING = 1;
|
|
var PREDESTROYING = 2;
|
|
var DESTROYING = 4;
|
|
var DESTROYED = 8;
|
|
var NOT_OPENING = MAX ^ OPENING;
|
|
var NOT_PREDESTROYING = MAX ^ PREDESTROYING;
|
|
var READ_ACTIVE = 1 << 4;
|
|
var READ_UPDATING = 2 << 4;
|
|
var READ_PRIMARY = 4 << 4;
|
|
var READ_QUEUED = 8 << 4;
|
|
var READ_RESUMED = 16 << 4;
|
|
var READ_PIPE_DRAINED = 32 << 4;
|
|
var READ_ENDING = 64 << 4;
|
|
var READ_EMIT_DATA = 128 << 4;
|
|
var READ_EMIT_READABLE = 256 << 4;
|
|
var READ_EMITTED_READABLE = 512 << 4;
|
|
var READ_DONE = 1024 << 4;
|
|
var READ_NEXT_TICK = 2048 << 4;
|
|
var READ_NEEDS_PUSH = 4096 << 4;
|
|
var READ_READ_AHEAD = 8192 << 4;
|
|
var READ_FLOWING = READ_RESUMED | READ_PIPE_DRAINED;
|
|
var READ_ACTIVE_AND_NEEDS_PUSH = READ_ACTIVE | READ_NEEDS_PUSH;
|
|
var READ_PRIMARY_AND_ACTIVE = READ_PRIMARY | READ_ACTIVE;
|
|
var READ_EMIT_READABLE_AND_QUEUED = READ_EMIT_READABLE | READ_QUEUED;
|
|
var READ_RESUMED_READ_AHEAD = READ_RESUMED | READ_READ_AHEAD;
|
|
var READ_NOT_ACTIVE = MAX ^ READ_ACTIVE;
|
|
var READ_NON_PRIMARY = MAX ^ READ_PRIMARY;
|
|
var READ_NON_PRIMARY_AND_PUSHED = MAX ^ (READ_PRIMARY | READ_NEEDS_PUSH);
|
|
var READ_PUSHED = MAX ^ READ_NEEDS_PUSH;
|
|
var READ_PAUSED = MAX ^ READ_RESUMED;
|
|
var READ_NOT_QUEUED = MAX ^ (READ_QUEUED | READ_EMITTED_READABLE);
|
|
var READ_NOT_ENDING = MAX ^ READ_ENDING;
|
|
var READ_PIPE_NOT_DRAINED = MAX ^ READ_FLOWING;
|
|
var READ_NOT_NEXT_TICK = MAX ^ READ_NEXT_TICK;
|
|
var READ_NOT_UPDATING = MAX ^ READ_UPDATING;
|
|
var READ_NO_READ_AHEAD = MAX ^ READ_READ_AHEAD;
|
|
var READ_PAUSED_NO_READ_AHEAD = MAX ^ READ_RESUMED_READ_AHEAD;
|
|
var WRITE_ACTIVE = 1 << 18;
|
|
var WRITE_UPDATING = 2 << 18;
|
|
var WRITE_PRIMARY = 4 << 18;
|
|
var WRITE_QUEUED = 8 << 18;
|
|
var WRITE_UNDRAINED = 16 << 18;
|
|
var WRITE_DONE = 32 << 18;
|
|
var WRITE_EMIT_DRAIN = 64 << 18;
|
|
var WRITE_NEXT_TICK = 128 << 18;
|
|
var WRITE_WRITING = 256 << 18;
|
|
var WRITE_FINISHING = 512 << 18;
|
|
var WRITE_CORKED = 1024 << 18;
|
|
var WRITE_NOT_ACTIVE = MAX ^ (WRITE_ACTIVE | WRITE_WRITING);
|
|
var WRITE_NON_PRIMARY = MAX ^ WRITE_PRIMARY;
|
|
var WRITE_NOT_FINISHING = MAX ^ (WRITE_ACTIVE | WRITE_FINISHING);
|
|
var WRITE_DRAINED = MAX ^ WRITE_UNDRAINED;
|
|
var WRITE_NOT_QUEUED = MAX ^ WRITE_QUEUED;
|
|
var WRITE_NOT_NEXT_TICK = MAX ^ WRITE_NEXT_TICK;
|
|
var WRITE_NOT_UPDATING = MAX ^ WRITE_UPDATING;
|
|
var WRITE_NOT_CORKED = MAX ^ WRITE_CORKED;
|
|
var ACTIVE = READ_ACTIVE | WRITE_ACTIVE;
|
|
var NOT_ACTIVE = MAX ^ ACTIVE;
|
|
var DONE = READ_DONE | WRITE_DONE;
|
|
var DESTROY_STATUS = DESTROYING | DESTROYED | PREDESTROYING;
|
|
var OPEN_STATUS = DESTROY_STATUS | OPENING;
|
|
var AUTO_DESTROY = DESTROY_STATUS | DONE;
|
|
var NON_PRIMARY = WRITE_NON_PRIMARY & READ_NON_PRIMARY;
|
|
var ACTIVE_OR_TICKING = WRITE_NEXT_TICK | READ_NEXT_TICK;
|
|
var TICKING = ACTIVE_OR_TICKING & NOT_ACTIVE;
|
|
var IS_OPENING = OPEN_STATUS | TICKING;
|
|
var READ_PRIMARY_STATUS = OPEN_STATUS | READ_ENDING | READ_DONE;
|
|
var READ_STATUS = OPEN_STATUS | READ_DONE | READ_QUEUED;
|
|
var READ_ENDING_STATUS = OPEN_STATUS | READ_ENDING | READ_QUEUED;
|
|
var READ_READABLE_STATUS = OPEN_STATUS | READ_EMIT_READABLE | READ_QUEUED | READ_EMITTED_READABLE;
|
|
var SHOULD_NOT_READ = OPEN_STATUS | READ_ACTIVE | READ_ENDING | READ_DONE | READ_NEEDS_PUSH | READ_READ_AHEAD;
|
|
var READ_BACKPRESSURE_STATUS = DESTROY_STATUS | READ_ENDING | READ_DONE;
|
|
var READ_UPDATE_SYNC_STATUS = READ_UPDATING | OPEN_STATUS | READ_NEXT_TICK | READ_PRIMARY;
|
|
var READ_NEXT_TICK_OR_OPENING = READ_NEXT_TICK | OPENING;
|
|
var WRITE_PRIMARY_STATUS = OPEN_STATUS | WRITE_FINISHING | WRITE_DONE;
|
|
var WRITE_QUEUED_AND_UNDRAINED = WRITE_QUEUED | WRITE_UNDRAINED;
|
|
var WRITE_QUEUED_AND_ACTIVE = WRITE_QUEUED | WRITE_ACTIVE;
|
|
var WRITE_DRAIN_STATUS = WRITE_QUEUED | WRITE_UNDRAINED | OPEN_STATUS | WRITE_ACTIVE;
|
|
var WRITE_STATUS = OPEN_STATUS | WRITE_ACTIVE | WRITE_QUEUED | WRITE_CORKED;
|
|
var WRITE_PRIMARY_AND_ACTIVE = WRITE_PRIMARY | WRITE_ACTIVE;
|
|
var WRITE_ACTIVE_AND_WRITING = WRITE_ACTIVE | WRITE_WRITING;
|
|
var WRITE_FINISHING_STATUS = OPEN_STATUS | WRITE_FINISHING | WRITE_QUEUED_AND_ACTIVE | WRITE_DONE;
|
|
var WRITE_BACKPRESSURE_STATUS = WRITE_UNDRAINED | DESTROY_STATUS | WRITE_FINISHING | WRITE_DONE;
|
|
var WRITE_UPDATE_SYNC_STATUS = WRITE_UPDATING | OPEN_STATUS | WRITE_NEXT_TICK | WRITE_PRIMARY;
|
|
var WRITE_DROP_DATA = WRITE_FINISHING | WRITE_DONE | DESTROY_STATUS;
|
|
var asyncIterator = Symbol.asyncIterator || Symbol("asyncIterator");
|
|
var WritableState = class {
|
|
constructor(stream, { highWaterMark = 16384, map = null, mapWritable, byteLength, byteLengthWritable } = {}) {
|
|
this.stream = stream;
|
|
this.queue = new FIFO();
|
|
this.highWaterMark = highWaterMark;
|
|
this.buffered = 0;
|
|
this.error = null;
|
|
this.pipeline = null;
|
|
this.drains = null;
|
|
this.byteLength = byteLengthWritable || byteLength || defaultByteLength;
|
|
this.map = mapWritable || map;
|
|
this.afterWrite = afterWrite.bind(this);
|
|
this.afterUpdateNextTick = updateWriteNT.bind(this);
|
|
}
|
|
get ending() {
|
|
return (this.stream._duplexState & WRITE_FINISHING) !== 0;
|
|
}
|
|
get ended() {
|
|
return (this.stream._duplexState & WRITE_DONE) !== 0;
|
|
}
|
|
push(data) {
|
|
if ((this.stream._duplexState & WRITE_DROP_DATA) !== 0) return false;
|
|
if (this.map !== null) data = this.map(data);
|
|
this.buffered += this.byteLength(data);
|
|
this.queue.push(data);
|
|
if (this.buffered < this.highWaterMark) {
|
|
this.stream._duplexState |= WRITE_QUEUED;
|
|
return true;
|
|
}
|
|
this.stream._duplexState |= WRITE_QUEUED_AND_UNDRAINED;
|
|
return false;
|
|
}
|
|
shift() {
|
|
const data = this.queue.shift();
|
|
this.buffered -= this.byteLength(data);
|
|
if (this.buffered === 0) this.stream._duplexState &= WRITE_NOT_QUEUED;
|
|
return data;
|
|
}
|
|
end(data) {
|
|
if (typeof data === "function") this.stream.once("finish", data);
|
|
else if (data !== void 0 && data !== null) this.push(data);
|
|
this.stream._duplexState = (this.stream._duplexState | WRITE_FINISHING) & WRITE_NON_PRIMARY;
|
|
}
|
|
autoBatch(data, cb) {
|
|
const buffer = [];
|
|
const stream = this.stream;
|
|
buffer.push(data);
|
|
while ((stream._duplexState & WRITE_STATUS) === WRITE_QUEUED_AND_ACTIVE) {
|
|
buffer.push(stream._writableState.shift());
|
|
}
|
|
if ((stream._duplexState & OPEN_STATUS) !== 0) return cb(null);
|
|
stream._writev(buffer, cb);
|
|
}
|
|
update() {
|
|
const stream = this.stream;
|
|
stream._duplexState |= WRITE_UPDATING;
|
|
do {
|
|
while ((stream._duplexState & WRITE_STATUS) === WRITE_QUEUED) {
|
|
const data = this.shift();
|
|
stream._duplexState |= WRITE_ACTIVE_AND_WRITING;
|
|
stream._write(data, this.afterWrite);
|
|
}
|
|
if ((stream._duplexState & WRITE_PRIMARY_AND_ACTIVE) === 0) this.updateNonPrimary();
|
|
} while (this.continueUpdate() === true);
|
|
stream._duplexState &= WRITE_NOT_UPDATING;
|
|
}
|
|
updateNonPrimary() {
|
|
const stream = this.stream;
|
|
if ((stream._duplexState & WRITE_FINISHING_STATUS) === WRITE_FINISHING) {
|
|
stream._duplexState = stream._duplexState | WRITE_ACTIVE;
|
|
stream._final(afterFinal.bind(this));
|
|
return;
|
|
}
|
|
if ((stream._duplexState & DESTROY_STATUS) === DESTROYING) {
|
|
if ((stream._duplexState & ACTIVE_OR_TICKING) === 0) {
|
|
stream._duplexState |= ACTIVE;
|
|
stream._destroy(afterDestroy.bind(this));
|
|
}
|
|
return;
|
|
}
|
|
if ((stream._duplexState & IS_OPENING) === OPENING) {
|
|
stream._duplexState = (stream._duplexState | ACTIVE) & NOT_OPENING;
|
|
stream._open(afterOpen.bind(this));
|
|
}
|
|
}
|
|
continueUpdate() {
|
|
if ((this.stream._duplexState & WRITE_NEXT_TICK) === 0) return false;
|
|
this.stream._duplexState &= WRITE_NOT_NEXT_TICK;
|
|
return true;
|
|
}
|
|
updateCallback() {
|
|
if ((this.stream._duplexState & WRITE_UPDATE_SYNC_STATUS) === WRITE_PRIMARY) this.update();
|
|
else this.updateNextTick();
|
|
}
|
|
updateNextTick() {
|
|
if ((this.stream._duplexState & WRITE_NEXT_TICK) !== 0) return;
|
|
this.stream._duplexState |= WRITE_NEXT_TICK;
|
|
if ((this.stream._duplexState & WRITE_UPDATING) === 0) qmt(this.afterUpdateNextTick);
|
|
}
|
|
};
|
|
var ReadableState = class {
|
|
constructor(stream, { highWaterMark = 16384, map = null, mapReadable, byteLength, byteLengthReadable } = {}) {
|
|
this.stream = stream;
|
|
this.queue = new FIFO();
|
|
this.highWaterMark = highWaterMark === 0 ? 1 : highWaterMark;
|
|
this.buffered = 0;
|
|
this.readAhead = highWaterMark > 0;
|
|
this.error = null;
|
|
this.pipeline = null;
|
|
this.byteLength = byteLengthReadable || byteLength || defaultByteLength;
|
|
this.map = mapReadable || map;
|
|
this.pipeTo = null;
|
|
this.afterRead = afterRead.bind(this);
|
|
this.afterUpdateNextTick = updateReadNT.bind(this);
|
|
}
|
|
get ending() {
|
|
return (this.stream._duplexState & READ_ENDING) !== 0;
|
|
}
|
|
get ended() {
|
|
return (this.stream._duplexState & READ_DONE) !== 0;
|
|
}
|
|
pipe(pipeTo, cb) {
|
|
if (this.pipeTo !== null) throw new Error("Can only pipe to one destination");
|
|
if (typeof cb !== "function") cb = null;
|
|
this.stream._duplexState |= READ_PIPE_DRAINED;
|
|
this.pipeTo = pipeTo;
|
|
this.pipeline = new Pipeline(this.stream, pipeTo, cb);
|
|
if (cb) this.stream.on("error", noop);
|
|
if (isStreamx(pipeTo)) {
|
|
pipeTo._writableState.pipeline = this.pipeline;
|
|
if (cb) pipeTo.on("error", noop);
|
|
pipeTo.on("finish", this.pipeline.finished.bind(this.pipeline));
|
|
} else {
|
|
const onerror = this.pipeline.done.bind(this.pipeline, pipeTo);
|
|
const onclose = this.pipeline.done.bind(this.pipeline, pipeTo, null);
|
|
pipeTo.on("error", onerror);
|
|
pipeTo.on("close", onclose);
|
|
pipeTo.on("finish", this.pipeline.finished.bind(this.pipeline));
|
|
}
|
|
pipeTo.on("drain", afterDrain.bind(this));
|
|
this.stream.emit("piping", pipeTo);
|
|
pipeTo.emit("pipe", this.stream);
|
|
}
|
|
push(data) {
|
|
const stream = this.stream;
|
|
if (data === null) {
|
|
this.highWaterMark = 0;
|
|
stream._duplexState = (stream._duplexState | READ_ENDING) & READ_NON_PRIMARY_AND_PUSHED;
|
|
return false;
|
|
}
|
|
if (this.map !== null) {
|
|
data = this.map(data);
|
|
if (data === null) {
|
|
stream._duplexState &= READ_PUSHED;
|
|
return this.buffered < this.highWaterMark;
|
|
}
|
|
}
|
|
this.buffered += this.byteLength(data);
|
|
this.queue.push(data);
|
|
stream._duplexState = (stream._duplexState | READ_QUEUED) & READ_PUSHED;
|
|
return this.buffered < this.highWaterMark;
|
|
}
|
|
shift() {
|
|
const data = this.queue.shift();
|
|
this.buffered -= this.byteLength(data);
|
|
if (this.buffered === 0) this.stream._duplexState &= READ_NOT_QUEUED;
|
|
return data;
|
|
}
|
|
unshift(data) {
|
|
const pending = [this.map !== null ? this.map(data) : data];
|
|
while (this.buffered > 0) pending.push(this.shift());
|
|
for (let i = 0; i < pending.length - 1; i++) {
|
|
const data2 = pending[i];
|
|
this.buffered += this.byteLength(data2);
|
|
this.queue.push(data2);
|
|
}
|
|
this.push(pending[pending.length - 1]);
|
|
}
|
|
read() {
|
|
const stream = this.stream;
|
|
if ((stream._duplexState & READ_STATUS) === READ_QUEUED) {
|
|
const data = this.shift();
|
|
if (this.pipeTo !== null && this.pipeTo.write(data) === false)
|
|
stream._duplexState &= READ_PIPE_NOT_DRAINED;
|
|
if ((stream._duplexState & READ_EMIT_DATA) !== 0) stream.emit("data", data);
|
|
return data;
|
|
}
|
|
if (this.readAhead === false) {
|
|
stream._duplexState |= READ_READ_AHEAD;
|
|
this.updateNextTick();
|
|
}
|
|
return null;
|
|
}
|
|
drain() {
|
|
const stream = this.stream;
|
|
while ((stream._duplexState & READ_STATUS) === READ_QUEUED && (stream._duplexState & READ_FLOWING) !== 0) {
|
|
const data = this.shift();
|
|
if (this.pipeTo !== null && this.pipeTo.write(data) === false)
|
|
stream._duplexState &= READ_PIPE_NOT_DRAINED;
|
|
if ((stream._duplexState & READ_EMIT_DATA) !== 0) stream.emit("data", data);
|
|
}
|
|
}
|
|
update() {
|
|
const stream = this.stream;
|
|
stream._duplexState |= READ_UPDATING;
|
|
do {
|
|
this.drain();
|
|
while (this.buffered < this.highWaterMark && (stream._duplexState & SHOULD_NOT_READ) === READ_READ_AHEAD) {
|
|
stream._duplexState |= READ_ACTIVE_AND_NEEDS_PUSH;
|
|
stream._read(this.afterRead);
|
|
this.drain();
|
|
}
|
|
if ((stream._duplexState & READ_READABLE_STATUS) === READ_EMIT_READABLE_AND_QUEUED) {
|
|
stream._duplexState |= READ_EMITTED_READABLE;
|
|
stream.emit("readable");
|
|
}
|
|
if ((stream._duplexState & READ_PRIMARY_AND_ACTIVE) === 0) this.updateNonPrimary();
|
|
} while (this.continueUpdate() === true);
|
|
stream._duplexState &= READ_NOT_UPDATING;
|
|
}
|
|
updateNonPrimary() {
|
|
const stream = this.stream;
|
|
if ((stream._duplexState & READ_ENDING_STATUS) === READ_ENDING) {
|
|
stream._duplexState = (stream._duplexState | READ_DONE) & READ_NOT_ENDING;
|
|
stream.emit("end");
|
|
if ((stream._duplexState & AUTO_DESTROY) === DONE) stream._duplexState |= DESTROYING;
|
|
if (this.pipeTo !== null) this.pipeTo.end();
|
|
}
|
|
if ((stream._duplexState & DESTROY_STATUS) === DESTROYING) {
|
|
if ((stream._duplexState & ACTIVE_OR_TICKING) === 0) {
|
|
stream._duplexState |= ACTIVE;
|
|
stream._destroy(afterDestroy.bind(this));
|
|
}
|
|
return;
|
|
}
|
|
if ((stream._duplexState & IS_OPENING) === OPENING) {
|
|
stream._duplexState = (stream._duplexState | ACTIVE) & NOT_OPENING;
|
|
stream._open(afterOpen.bind(this));
|
|
}
|
|
}
|
|
continueUpdate() {
|
|
if ((this.stream._duplexState & READ_NEXT_TICK) === 0) return false;
|
|
this.stream._duplexState &= READ_NOT_NEXT_TICK;
|
|
return true;
|
|
}
|
|
updateCallback() {
|
|
if ((this.stream._duplexState & READ_UPDATE_SYNC_STATUS) === READ_PRIMARY) this.update();
|
|
else this.updateNextTick();
|
|
}
|
|
updateNextTickIfOpen() {
|
|
if ((this.stream._duplexState & READ_NEXT_TICK_OR_OPENING) !== 0) return;
|
|
this.stream._duplexState |= READ_NEXT_TICK;
|
|
if ((this.stream._duplexState & READ_UPDATING) === 0) qmt(this.afterUpdateNextTick);
|
|
}
|
|
updateNextTick() {
|
|
if ((this.stream._duplexState & READ_NEXT_TICK) !== 0) return;
|
|
this.stream._duplexState |= READ_NEXT_TICK;
|
|
if ((this.stream._duplexState & READ_UPDATING) === 0) qmt(this.afterUpdateNextTick);
|
|
}
|
|
};
|
|
var TransformState = class {
|
|
constructor(stream) {
|
|
this.data = null;
|
|
this.afterTransform = afterTransform.bind(stream);
|
|
this.afterFinal = null;
|
|
}
|
|
};
|
|
var Pipeline = class {
|
|
constructor(src, dst, cb) {
|
|
this.from = src;
|
|
this.to = dst;
|
|
this.afterPipe = cb;
|
|
this.error = null;
|
|
this.pipeToFinished = false;
|
|
}
|
|
finished() {
|
|
this.pipeToFinished = true;
|
|
}
|
|
done(stream, err) {
|
|
if (err) this.error = err;
|
|
if (stream === this.to) {
|
|
this.to = null;
|
|
if (this.from !== null) {
|
|
if ((this.from._duplexState & READ_DONE) === 0 || !this.pipeToFinished) {
|
|
this.from.destroy(this.error || new Error("Writable stream closed prematurely"));
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
if (stream === this.from) {
|
|
this.from = null;
|
|
if (this.to !== null) {
|
|
if ((stream._duplexState & READ_DONE) === 0) {
|
|
this.to.destroy(this.error || new Error("Readable stream closed before ending"));
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
if (this.afterPipe !== null) this.afterPipe(this.error);
|
|
this.to = this.from = this.afterPipe = null;
|
|
}
|
|
};
|
|
function afterDrain() {
|
|
this.stream._duplexState |= READ_PIPE_DRAINED;
|
|
this.updateCallback();
|
|
}
|
|
function afterFinal(err) {
|
|
const stream = this.stream;
|
|
if (err) stream.destroy(err);
|
|
if ((stream._duplexState & DESTROY_STATUS) === 0) {
|
|
stream._duplexState |= WRITE_DONE;
|
|
stream.emit("finish");
|
|
}
|
|
if ((stream._duplexState & AUTO_DESTROY) === DONE) {
|
|
stream._duplexState |= DESTROYING;
|
|
}
|
|
stream._duplexState &= WRITE_NOT_FINISHING;
|
|
if ((stream._duplexState & WRITE_UPDATING) === 0) this.update();
|
|
else this.updateNextTick();
|
|
}
|
|
function afterDestroy(err) {
|
|
const stream = this.stream;
|
|
if (!err && this.error !== STREAM_DESTROYED) err = this.error;
|
|
if (err) stream.emit("error", err);
|
|
stream._duplexState |= DESTROYED;
|
|
stream.emit("close");
|
|
const rs = stream._readableState;
|
|
const ws = stream._writableState;
|
|
if (rs !== null && rs.pipeline !== null) rs.pipeline.done(stream, err);
|
|
if (ws !== null) {
|
|
while (ws.drains !== null && ws.drains.length > 0) ws.drains.shift().resolve(false);
|
|
if (ws.pipeline !== null) ws.pipeline.done(stream, err);
|
|
}
|
|
}
|
|
function afterWrite(err) {
|
|
const stream = this.stream;
|
|
if (err) stream.destroy(err);
|
|
stream._duplexState &= WRITE_NOT_ACTIVE;
|
|
if (this.drains !== null) tickDrains(this.drains);
|
|
if ((stream._duplexState & WRITE_DRAIN_STATUS) === WRITE_UNDRAINED) {
|
|
stream._duplexState &= WRITE_DRAINED;
|
|
if ((stream._duplexState & WRITE_EMIT_DRAIN) === WRITE_EMIT_DRAIN) {
|
|
stream.emit("drain");
|
|
}
|
|
}
|
|
this.updateCallback();
|
|
}
|
|
function afterRead(err) {
|
|
if (err) this.stream.destroy(err);
|
|
this.stream._duplexState &= READ_NOT_ACTIVE;
|
|
if (this.readAhead === false && (this.stream._duplexState & READ_RESUMED) === 0)
|
|
this.stream._duplexState &= READ_NO_READ_AHEAD;
|
|
this.updateCallback();
|
|
}
|
|
function updateReadNT() {
|
|
if ((this.stream._duplexState & READ_UPDATING) === 0) {
|
|
this.stream._duplexState &= READ_NOT_NEXT_TICK;
|
|
this.update();
|
|
}
|
|
}
|
|
function updateWriteNT() {
|
|
if ((this.stream._duplexState & WRITE_UPDATING) === 0) {
|
|
this.stream._duplexState &= WRITE_NOT_NEXT_TICK;
|
|
this.update();
|
|
}
|
|
}
|
|
function tickDrains(drains) {
|
|
for (let i = 0; i < drains.length; i++) {
|
|
if (--drains[i].writes === 0) {
|
|
drains.shift().resolve(true);
|
|
i--;
|
|
}
|
|
}
|
|
}
|
|
function afterOpen(err) {
|
|
const stream = this.stream;
|
|
if (err) stream.destroy(err);
|
|
if ((stream._duplexState & DESTROYING) === 0) {
|
|
if ((stream._duplexState & READ_PRIMARY_STATUS) === 0) stream._duplexState |= READ_PRIMARY;
|
|
if ((stream._duplexState & WRITE_PRIMARY_STATUS) === 0) stream._duplexState |= WRITE_PRIMARY;
|
|
stream.emit("open");
|
|
}
|
|
stream._duplexState &= NOT_ACTIVE;
|
|
if (stream._writableState !== null) {
|
|
stream._writableState.updateCallback();
|
|
}
|
|
if (stream._readableState !== null) {
|
|
stream._readableState.updateCallback();
|
|
}
|
|
}
|
|
function afterTransform(err, data) {
|
|
if (data !== void 0 && data !== null) this.push(data);
|
|
this._writableState.afterWrite(err);
|
|
}
|
|
function newListener(name) {
|
|
if (this._readableState !== null) {
|
|
if (name === "data") {
|
|
this._duplexState |= READ_EMIT_DATA | READ_RESUMED_READ_AHEAD;
|
|
this._readableState.updateNextTick();
|
|
}
|
|
if (name === "readable") {
|
|
this._duplexState |= READ_EMIT_READABLE;
|
|
this._readableState.updateNextTick();
|
|
}
|
|
}
|
|
if (this._writableState !== null) {
|
|
if (name === "drain") {
|
|
this._duplexState |= WRITE_EMIT_DRAIN;
|
|
this._writableState.updateNextTick();
|
|
}
|
|
}
|
|
}
|
|
var Stream = class extends EventEmitter {
|
|
constructor(opts) {
|
|
super();
|
|
this._duplexState = 0;
|
|
this._readableState = null;
|
|
this._writableState = null;
|
|
if (opts) {
|
|
if (opts.open) this._open = opts.open;
|
|
if (opts.destroy) this._destroy = opts.destroy;
|
|
if (opts.predestroy) this._predestroy = opts.predestroy;
|
|
if (opts.signal) {
|
|
opts.signal.addEventListener("abort", abort.bind(this));
|
|
}
|
|
}
|
|
this.on("newListener", newListener);
|
|
}
|
|
_open(cb) {
|
|
cb(null);
|
|
}
|
|
_destroy(cb) {
|
|
cb(null);
|
|
}
|
|
_predestroy() {
|
|
}
|
|
get readable() {
|
|
return this._readableState !== null ? true : void 0;
|
|
}
|
|
get writable() {
|
|
return this._writableState !== null ? true : void 0;
|
|
}
|
|
get destroyed() {
|
|
return (this._duplexState & DESTROYED) !== 0;
|
|
}
|
|
get destroying() {
|
|
return (this._duplexState & DESTROY_STATUS) !== 0;
|
|
}
|
|
destroy(err) {
|
|
if ((this._duplexState & DESTROY_STATUS) === 0) {
|
|
if (!err) err = STREAM_DESTROYED;
|
|
this._duplexState = (this._duplexState | DESTROYING) & NON_PRIMARY;
|
|
if (this._readableState !== null) {
|
|
this._readableState.highWaterMark = 0;
|
|
this._readableState.error = err;
|
|
}
|
|
if (this._writableState !== null) {
|
|
this._writableState.highWaterMark = 0;
|
|
this._writableState.error = err;
|
|
}
|
|
this._duplexState |= PREDESTROYING;
|
|
this._predestroy();
|
|
this._duplexState &= NOT_PREDESTROYING;
|
|
if (this._readableState !== null) this._readableState.updateNextTick();
|
|
if (this._writableState !== null) this._writableState.updateNextTick();
|
|
}
|
|
}
|
|
};
|
|
var Readable = class _Readable extends Stream {
|
|
constructor(opts) {
|
|
super(opts);
|
|
this._duplexState |= OPENING | WRITE_DONE | READ_READ_AHEAD;
|
|
this._readableState = new ReadableState(this, opts);
|
|
if (opts) {
|
|
if (this._readableState.readAhead === false) this._duplexState &= READ_NO_READ_AHEAD;
|
|
if (opts.read) this._read = opts.read;
|
|
if (opts.eagerOpen) this._readableState.updateNextTick();
|
|
if (opts.encoding) this.setEncoding(opts.encoding);
|
|
}
|
|
}
|
|
setEncoding(encoding) {
|
|
const dec = new TextDecoder(encoding);
|
|
const map = this._readableState.map || echo;
|
|
this._readableState.map = mapOrSkip;
|
|
return this;
|
|
function mapOrSkip(data) {
|
|
const next = dec.push(data);
|
|
return next === "" && (data.byteLength !== 0 || dec.remaining > 0) ? null : map(next);
|
|
}
|
|
}
|
|
_read(cb) {
|
|
cb(null);
|
|
}
|
|
pipe(dest, cb) {
|
|
this._readableState.updateNextTick();
|
|
this._readableState.pipe(dest, cb);
|
|
return dest;
|
|
}
|
|
read() {
|
|
this._readableState.updateNextTick();
|
|
return this._readableState.read();
|
|
}
|
|
push(data) {
|
|
this._readableState.updateNextTickIfOpen();
|
|
return this._readableState.push(data);
|
|
}
|
|
unshift(data) {
|
|
this._readableState.updateNextTickIfOpen();
|
|
return this._readableState.unshift(data);
|
|
}
|
|
resume() {
|
|
this._duplexState |= READ_RESUMED_READ_AHEAD;
|
|
this._readableState.updateNextTick();
|
|
return this;
|
|
}
|
|
pause() {
|
|
this._duplexState &= this._readableState.readAhead === false ? READ_PAUSED_NO_READ_AHEAD : READ_PAUSED;
|
|
return this;
|
|
}
|
|
static _fromAsyncIterator(ite, opts) {
|
|
let destroy;
|
|
const rs = new _Readable({
|
|
...opts,
|
|
read(cb) {
|
|
ite.next().then(push).then(cb.bind(null, null)).catch(cb);
|
|
},
|
|
predestroy() {
|
|
destroy = ite.return();
|
|
},
|
|
destroy(cb) {
|
|
if (!destroy) return cb(null);
|
|
destroy.then(cb.bind(null, null)).catch(cb);
|
|
}
|
|
});
|
|
return rs;
|
|
function push(data) {
|
|
if (data.done) rs.push(null);
|
|
else rs.push(data.value);
|
|
}
|
|
}
|
|
static from(data, opts) {
|
|
if (isReadStreamx(data)) return data;
|
|
if (data[asyncIterator]) return this._fromAsyncIterator(data[asyncIterator](), opts);
|
|
if (!Array.isArray(data)) data = data === void 0 ? [] : [data];
|
|
let i = 0;
|
|
return new _Readable({
|
|
...opts,
|
|
read(cb) {
|
|
this.push(i === data.length ? null : data[i++]);
|
|
cb(null);
|
|
}
|
|
});
|
|
}
|
|
static isBackpressured(rs) {
|
|
return (rs._duplexState & READ_BACKPRESSURE_STATUS) !== 0 || rs._readableState.buffered >= rs._readableState.highWaterMark;
|
|
}
|
|
static isPaused(rs) {
|
|
return (rs._duplexState & READ_RESUMED) === 0;
|
|
}
|
|
[asyncIterator]() {
|
|
const stream = this;
|
|
let error = null;
|
|
let promiseResolve = null;
|
|
let promiseReject = null;
|
|
this.on("error", (err) => {
|
|
error = err;
|
|
});
|
|
this.on("readable", onreadable);
|
|
this.on("close", onclose);
|
|
return {
|
|
[asyncIterator]() {
|
|
return this;
|
|
},
|
|
next() {
|
|
return new Promise(function(resolve, reject) {
|
|
promiseResolve = resolve;
|
|
promiseReject = reject;
|
|
const data = stream.read();
|
|
if (data !== null) ondata(data);
|
|
else if ((stream._duplexState & DESTROYED) !== 0) ondata(null);
|
|
});
|
|
},
|
|
return() {
|
|
return destroy(null);
|
|
},
|
|
throw(err) {
|
|
return destroy(err);
|
|
}
|
|
};
|
|
function onreadable() {
|
|
if (promiseResolve !== null) ondata(stream.read());
|
|
}
|
|
function onclose() {
|
|
if (promiseResolve !== null) ondata(null);
|
|
}
|
|
function ondata(data) {
|
|
if (promiseReject === null) return;
|
|
if (error) promiseReject(error);
|
|
else if (data === null && (stream._duplexState & READ_DONE) === 0)
|
|
promiseReject(STREAM_DESTROYED);
|
|
else promiseResolve({ value: data, done: data === null });
|
|
promiseReject = promiseResolve = null;
|
|
}
|
|
function destroy(err) {
|
|
stream.destroy(err);
|
|
return new Promise((resolve, reject) => {
|
|
if (stream._duplexState & DESTROYED) return resolve({ value: void 0, done: true });
|
|
stream.once("close", function() {
|
|
if (err) reject(err);
|
|
else resolve({ value: void 0, done: true });
|
|
});
|
|
});
|
|
}
|
|
}
|
|
};
|
|
var Writable = class extends Stream {
|
|
constructor(opts) {
|
|
super(opts);
|
|
this._duplexState |= OPENING | READ_DONE;
|
|
this._writableState = new WritableState(this, opts);
|
|
if (opts) {
|
|
if (opts.writev) this._writev = opts.writev;
|
|
if (opts.write) this._write = opts.write;
|
|
if (opts.final) this._final = opts.final;
|
|
if (opts.eagerOpen) this._writableState.updateNextTick();
|
|
}
|
|
}
|
|
cork() {
|
|
this._duplexState |= WRITE_CORKED;
|
|
}
|
|
uncork() {
|
|
this._duplexState &= WRITE_NOT_CORKED;
|
|
this._writableState.updateNextTick();
|
|
}
|
|
_writev(batch, cb) {
|
|
cb(null);
|
|
}
|
|
_write(data, cb) {
|
|
this._writableState.autoBatch(data, cb);
|
|
}
|
|
_final(cb) {
|
|
cb(null);
|
|
}
|
|
static isBackpressured(ws) {
|
|
return (ws._duplexState & WRITE_BACKPRESSURE_STATUS) !== 0;
|
|
}
|
|
static drained(ws) {
|
|
if (ws.destroyed) return Promise.resolve(false);
|
|
const state = ws._writableState;
|
|
const pending = isWritev(ws) ? Math.min(1, state.queue.length) : state.queue.length;
|
|
const writes = pending + (ws._duplexState & WRITE_WRITING ? 1 : 0);
|
|
if (writes === 0) return Promise.resolve(true);
|
|
if (state.drains === null) state.drains = [];
|
|
return new Promise((resolve) => {
|
|
state.drains.push({ writes, resolve });
|
|
});
|
|
}
|
|
write(data) {
|
|
this._writableState.updateNextTick();
|
|
return this._writableState.push(data);
|
|
}
|
|
end(data) {
|
|
this._writableState.updateNextTick();
|
|
this._writableState.end(data);
|
|
return this;
|
|
}
|
|
};
|
|
var Duplex = class extends Readable {
|
|
// and Writable
|
|
constructor(opts) {
|
|
super(opts);
|
|
this._duplexState = OPENING | this._duplexState & READ_READ_AHEAD;
|
|
this._writableState = new WritableState(this, opts);
|
|
if (opts) {
|
|
if (opts.writev) this._writev = opts.writev;
|
|
if (opts.write) this._write = opts.write;
|
|
if (opts.final) this._final = opts.final;
|
|
}
|
|
}
|
|
cork() {
|
|
this._duplexState |= WRITE_CORKED;
|
|
}
|
|
uncork() {
|
|
this._duplexState &= WRITE_NOT_CORKED;
|
|
this._writableState.updateNextTick();
|
|
}
|
|
_writev(batch, cb) {
|
|
cb(null);
|
|
}
|
|
_write(data, cb) {
|
|
this._writableState.autoBatch(data, cb);
|
|
}
|
|
_final(cb) {
|
|
cb(null);
|
|
}
|
|
write(data) {
|
|
this._writableState.updateNextTick();
|
|
return this._writableState.push(data);
|
|
}
|
|
end(data) {
|
|
this._writableState.updateNextTick();
|
|
this._writableState.end(data);
|
|
return this;
|
|
}
|
|
};
|
|
var Transform = class extends Duplex {
|
|
constructor(opts) {
|
|
super(opts);
|
|
this._transformState = new TransformState(this);
|
|
if (opts) {
|
|
if (opts.transform) this._transform = opts.transform;
|
|
if (opts.flush) this._flush = opts.flush;
|
|
}
|
|
}
|
|
_write(data, cb) {
|
|
if (this._readableState.buffered >= this._readableState.highWaterMark) {
|
|
this._transformState.data = data;
|
|
} else {
|
|
this._transform(data, this._transformState.afterTransform);
|
|
}
|
|
}
|
|
_read(cb) {
|
|
if (this._transformState.data !== null) {
|
|
const data = this._transformState.data;
|
|
this._transformState.data = null;
|
|
cb(null);
|
|
this._transform(data, this._transformState.afterTransform);
|
|
} else {
|
|
cb(null);
|
|
}
|
|
}
|
|
destroy(err) {
|
|
super.destroy(err);
|
|
if (this._transformState.data !== null) {
|
|
this._transformState.data = null;
|
|
this._transformState.afterTransform();
|
|
}
|
|
}
|
|
_transform(data, cb) {
|
|
cb(null, data);
|
|
}
|
|
_flush(cb) {
|
|
cb(null);
|
|
}
|
|
_final(cb) {
|
|
this._transformState.afterFinal = cb;
|
|
this._flush(transformAfterFlush.bind(this));
|
|
}
|
|
};
|
|
var PassThrough = class extends Transform {
|
|
};
|
|
function transformAfterFlush(err, data) {
|
|
const cb = this._transformState.afterFinal;
|
|
if (err) return cb(err);
|
|
if (data !== null && data !== void 0) this.push(data);
|
|
this.push(null);
|
|
cb(null);
|
|
}
|
|
function pipelinePromise(...streams) {
|
|
return new Promise((resolve, reject) => {
|
|
return pipeline(...streams, (err) => {
|
|
if (err) return reject(err);
|
|
resolve();
|
|
});
|
|
});
|
|
}
|
|
function pipeline(stream, ...streams) {
|
|
const all = Array.isArray(stream) ? [...stream, ...streams] : [stream, ...streams];
|
|
const done = all.length && typeof all[all.length - 1] === "function" ? all.pop() : null;
|
|
if (all.length < 2) throw new Error("Pipeline requires at least 2 streams");
|
|
let src = all[0];
|
|
let dest = null;
|
|
let error = null;
|
|
for (let i = 1; i < all.length; i++) {
|
|
dest = all[i];
|
|
if (isStreamx(src)) {
|
|
src.pipe(dest, onerror);
|
|
} else {
|
|
errorHandle(src, true, i > 1, onerror);
|
|
src.pipe(dest);
|
|
}
|
|
src = dest;
|
|
}
|
|
if (done) {
|
|
let fin = false;
|
|
const autoDestroy = isStreamx(dest) || !!(dest._writableState && dest._writableState.autoDestroy);
|
|
dest.on("error", (err) => {
|
|
if (error === null) error = err;
|
|
});
|
|
dest.on("finish", () => {
|
|
fin = true;
|
|
if (!autoDestroy) done(error);
|
|
});
|
|
if (autoDestroy) {
|
|
dest.on("close", () => done(error || (fin ? null : PREMATURE_CLOSE)));
|
|
}
|
|
}
|
|
return dest;
|
|
function errorHandle(s, rd, wr, onerror2) {
|
|
s.on("error", onerror2);
|
|
s.on("close", onclose);
|
|
function onclose() {
|
|
if (rd && s._readableState && !s._readableState.ended) return onerror2(PREMATURE_CLOSE);
|
|
if (wr && s._writableState && !s._writableState.ended) return onerror2(PREMATURE_CLOSE);
|
|
}
|
|
}
|
|
function onerror(err) {
|
|
if (!err || error) return;
|
|
error = err;
|
|
for (const s of all) {
|
|
s.destroy(err);
|
|
}
|
|
}
|
|
}
|
|
function echo(s) {
|
|
return s;
|
|
}
|
|
function isStream(stream) {
|
|
return !!stream._readableState || !!stream._writableState;
|
|
}
|
|
function isStreamx(stream) {
|
|
return typeof stream._duplexState === "number" && isStream(stream);
|
|
}
|
|
function isEnding(stream) {
|
|
return !!stream._readableState && stream._readableState.ending;
|
|
}
|
|
function isEnded(stream) {
|
|
return !!stream._readableState && stream._readableState.ended;
|
|
}
|
|
function isFinishing(stream) {
|
|
return !!stream._writableState && stream._writableState.ending;
|
|
}
|
|
function isFinished(stream) {
|
|
return !!stream._writableState && stream._writableState.ended;
|
|
}
|
|
function getStreamError(stream, opts = {}) {
|
|
const err = stream._readableState && stream._readableState.error || stream._writableState && stream._writableState.error;
|
|
return !opts.all && err === STREAM_DESTROYED ? null : err;
|
|
}
|
|
function isReadStreamx(stream) {
|
|
return isStreamx(stream) && stream.readable;
|
|
}
|
|
function isDisturbed(stream) {
|
|
return (stream._duplexState & OPENING) !== OPENING || (stream._duplexState & DESTROYING) === DESTROYING || (stream._duplexState & ACTIVE_OR_TICKING) !== 0;
|
|
}
|
|
function isTypedArray(data) {
|
|
return typeof data === "object" && data !== null && typeof data.byteLength === "number";
|
|
}
|
|
function defaultByteLength(data) {
|
|
return isTypedArray(data) ? data.byteLength : 1024;
|
|
}
|
|
function noop() {
|
|
}
|
|
function abort() {
|
|
this.destroy(new Error("Stream aborted."));
|
|
}
|
|
function isWritev(s) {
|
|
return s._writev !== Writable.prototype._writev && s._writev !== Duplex.prototype._writev;
|
|
}
|
|
module.exports = {
|
|
pipeline,
|
|
pipelinePromise,
|
|
isStream,
|
|
isStreamx,
|
|
isEnding,
|
|
isEnded,
|
|
isFinishing,
|
|
isFinished,
|
|
isDisturbed,
|
|
getStreamError,
|
|
Stream,
|
|
Writable,
|
|
Readable,
|
|
Duplex,
|
|
Transform,
|
|
// Export PassThrough for compatibility with Node.js core's stream module
|
|
PassThrough
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/teex/index.js
|
|
var require_teex = __commonJS({
|
|
"../../node_modules/teex/index.js"(exports, module) {
|
|
var { Readable } = require_streamx();
|
|
module.exports = function(s, forks = 2) {
|
|
const streams = new Array(forks);
|
|
const status = new Array(forks).fill(true);
|
|
let ended = false;
|
|
for (let i = 0; i < forks; i++) {
|
|
streams[i] = new Readable({
|
|
read(cb) {
|
|
const check = !status[i];
|
|
status[i] = true;
|
|
if (check && allReadable()) s.resume();
|
|
cb(null);
|
|
}
|
|
});
|
|
}
|
|
s.on("end", function() {
|
|
ended = true;
|
|
for (const stream of streams) stream.push(null);
|
|
});
|
|
s.on("error", function(err) {
|
|
for (const stream of streams) stream.destroy(err);
|
|
});
|
|
s.on("close", function() {
|
|
if (ended) return;
|
|
for (const stream of streams) stream.destroy();
|
|
});
|
|
s.on("data", function(data) {
|
|
let needsPause = false;
|
|
for (let i = 0; i < streams.length; i++) {
|
|
if (!(status[i] = streams[i].push(data))) {
|
|
needsPause = true;
|
|
}
|
|
}
|
|
if (needsPause) s.pause();
|
|
});
|
|
return streams;
|
|
function allReadable() {
|
|
for (let j = 0; j < status.length; j++) {
|
|
if (!status[j]) return false;
|
|
}
|
|
return true;
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-stream/web.js
|
|
var require_web = __commonJS({
|
|
"../../node_modules/bare-stream/web.js"(exports) {
|
|
var { Readable, Writable, Transform, getStreamError, isStreamx, isDisturbed } = require_streamx();
|
|
var tee = require_teex();
|
|
var readableKind = Symbol.for("bare.stream.readable.kind");
|
|
var writableKind = Symbol.for("bare.stream.writable.kind");
|
|
var transformKind = Symbol.for("bare.stream.transform.kind");
|
|
exports.ReadableStreamDefaultReader = class ReadableStreamDefaultReader {
|
|
constructor(stream) {
|
|
this._stream = stream;
|
|
this._stream._stream.once("close", onclose).once("error", onerror);
|
|
const closed = Promise.withResolvers();
|
|
closed.promise.catch(noop);
|
|
this._closed = closed;
|
|
function onclose() {
|
|
closed.resolve();
|
|
}
|
|
function onerror(err) {
|
|
closed.reject(err);
|
|
}
|
|
}
|
|
get closed() {
|
|
return this._closed.promise;
|
|
}
|
|
read() {
|
|
const stream = this._stream._stream;
|
|
return new Promise((resolve, reject) => {
|
|
const err = getStreamError(stream);
|
|
if (err) return reject(err);
|
|
if (stream.destroyed) {
|
|
return resolve({ value: void 0, done: true });
|
|
}
|
|
const value = stream.read();
|
|
if (value !== null) {
|
|
return resolve({ value, done: false });
|
|
}
|
|
stream.once("readable", onreadable).once("close", onclose).once("error", onerror);
|
|
function onreadable() {
|
|
const value2 = stream.read();
|
|
ondone(null, value2 === null ? { value: void 0, done: true } : { value: value2, done: false });
|
|
}
|
|
function onclose() {
|
|
ondone(null, { value: void 0, done: true });
|
|
}
|
|
function onerror(err2) {
|
|
ondone(err2, null);
|
|
}
|
|
function ondone(err2, value2) {
|
|
stream.off("readable", onreadable).off("close", onclose).off("error", onerror);
|
|
if (err2) reject(err2);
|
|
else resolve(value2);
|
|
}
|
|
});
|
|
}
|
|
releaseLock() {
|
|
this._closed.reject(new TypeError("Reader was released"));
|
|
this._stream._releaseLock();
|
|
this._stream = null;
|
|
}
|
|
cancel(reason = new TypeError("Stream was cancelled")) {
|
|
const stream = this._stream._stream;
|
|
if (stream.destroyed) return Promise.resolve();
|
|
return new Promise(
|
|
(resolve) => stream.once("close", resolve).once("error", noop).destroy(reason)
|
|
);
|
|
}
|
|
};
|
|
exports.ReadableStreamDefaultController = class ReadableStreamDefaultController {
|
|
constructor(stream) {
|
|
this._stream = stream;
|
|
}
|
|
get desiredSize() {
|
|
const stream = this._stream._stream;
|
|
return stream._readableState.highWaterMark - stream._readableState.buffered;
|
|
}
|
|
enqueue(data) {
|
|
this._stream._stream.push(data);
|
|
}
|
|
close() {
|
|
this._stream._stream.push(null);
|
|
}
|
|
error(err) {
|
|
this._stream._stream.destroy(err);
|
|
}
|
|
};
|
|
var ReadableStream = class _ReadableStream {
|
|
static get [readableKind]() {
|
|
return 0;
|
|
}
|
|
static from(iterable) {
|
|
return new _ReadableStream(Readable.from(iterable));
|
|
}
|
|
constructor(underlyingSource = {}, queuingStrategy) {
|
|
if (isStreamx(underlyingSource)) {
|
|
this._stream = underlyingSource;
|
|
} else {
|
|
if (queuingStrategy === void 0) {
|
|
queuingStrategy = new exports.CountQueuingStrategy();
|
|
}
|
|
const { start, pull, cancel } = underlyingSource;
|
|
const { highWaterMark = 1, size = defaultSize } = queuingStrategy;
|
|
this._stream = new Readable({ highWaterMark, byteLength: size });
|
|
const controller = new exports.ReadableStreamDefaultController(this);
|
|
if (start) {
|
|
this._stream._open = this._open.bind(this, start.call(this, controller));
|
|
}
|
|
if (pull) {
|
|
this._stream._read = this._read.bind(this, pull.bind(this, controller));
|
|
}
|
|
if (cancel) {
|
|
this._stream.once("error", cancel);
|
|
}
|
|
}
|
|
this._reader = null;
|
|
}
|
|
get [readableKind]() {
|
|
return _ReadableStream[readableKind];
|
|
}
|
|
get locked() {
|
|
return this._reader !== null;
|
|
}
|
|
getReader() {
|
|
if (this.locked) throw new TypeError("Stream is locked");
|
|
this._reader = new exports.ReadableStreamDefaultReader(this);
|
|
return this._reader;
|
|
}
|
|
cancel(reason = new TypeError("Stream was cancelled")) {
|
|
const stream = this._stream;
|
|
if (stream.destroyed) return Promise.resolve();
|
|
if (this.locked) return Promise.reject(new TypeError("Stream is locked"));
|
|
return new Promise(
|
|
(resolve) => stream.once("close", resolve).once("error", noop).destroy(reason)
|
|
);
|
|
}
|
|
tee() {
|
|
const [a, b] = tee(this._stream);
|
|
return [new _ReadableStream(a), new _ReadableStream(b)];
|
|
}
|
|
pipeTo(destination) {
|
|
return new Promise(
|
|
(resolve, reject) => this._stream.pipe(destination._stream, (err) => {
|
|
err ? reject(err) : resolve();
|
|
})
|
|
);
|
|
}
|
|
[Symbol.asyncIterator]() {
|
|
return this._stream[Symbol.asyncIterator]();
|
|
}
|
|
_releaseLock() {
|
|
this._reader = null;
|
|
}
|
|
async _open(starting, cb) {
|
|
let err = null;
|
|
try {
|
|
await starting;
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
async _read(pull, cb) {
|
|
let err = null;
|
|
try {
|
|
await pull();
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
};
|
|
function defaultSize() {
|
|
return 1;
|
|
}
|
|
exports.ReadableStream = ReadableStream;
|
|
exports.CountQueuingStrategy = class CountQueuingStrategy {
|
|
constructor(opts = {}) {
|
|
const { highWaterMark = 1 } = opts;
|
|
this.highWaterMark = highWaterMark;
|
|
}
|
|
size(chunk) {
|
|
return 1;
|
|
}
|
|
};
|
|
exports.ByteLengthQueuingStrategy = class ByteLengthQueuingStrategy {
|
|
constructor(opts = {}) {
|
|
const { highWaterMark = 16384 } = opts;
|
|
this.highWaterMark = highWaterMark;
|
|
}
|
|
size(chunk) {
|
|
return chunk.byteLength;
|
|
}
|
|
};
|
|
exports.isReadableStream = function isReadableStream(value) {
|
|
if (value instanceof ReadableStream) return true;
|
|
return typeof value === "object" && value !== null && value[readableKind] === ReadableStream[readableKind];
|
|
};
|
|
exports.isReadableStreamErrored = function isReadableStreamErrored(stream) {
|
|
return getStreamError(stream._stream) !== null;
|
|
};
|
|
exports.isReadableStreamDisturbed = function isReadableStreamDisturbed(stream) {
|
|
return isDisturbed(stream._stream);
|
|
};
|
|
exports.WritableStreamDefaultWriter = class WritableStreamDefaultWriter {
|
|
constructor(stream) {
|
|
this._stream = stream;
|
|
this._stream._stream.once("close", onclose).once("error", onerror);
|
|
const closed = Promise.withResolvers();
|
|
closed.promise.catch(noop);
|
|
this._closed = closed;
|
|
function onclose() {
|
|
closed.resolve();
|
|
}
|
|
function onerror(err) {
|
|
closed.reject(err);
|
|
}
|
|
}
|
|
get desiredSize() {
|
|
const stream = this._stream._stream;
|
|
return stream._writableState.highWaterMark - stream._writableState.buffered;
|
|
}
|
|
get closed() {
|
|
return this._closed.promise;
|
|
}
|
|
get ready() {
|
|
const stream = this._stream._stream;
|
|
if (getStreamError(stream)) return Promise.reject();
|
|
return Writable.drained(stream).then();
|
|
}
|
|
async write(chunk) {
|
|
const stream = this._stream._stream;
|
|
let err = getStreamError(stream);
|
|
if (err) return Promise.reject(err);
|
|
stream.write(chunk);
|
|
await Writable.drained(stream);
|
|
err = getStreamError(stream);
|
|
if (err) return Promise.reject(err);
|
|
}
|
|
releaseLock() {
|
|
this._closed.reject(new TypeError("Writer was released"));
|
|
this._stream._releaseLock();
|
|
this._stream = null;
|
|
}
|
|
close() {
|
|
const stream = this._stream._stream;
|
|
if (stream.destroyed) return Promise.resolve();
|
|
return new Promise((resolve) => stream.once("close", resolve).end());
|
|
}
|
|
abort(reason = new TypeError("Stream was aborted")) {
|
|
const stream = this._stream._stream;
|
|
if (stream.destroyed) return Promise.resolve();
|
|
return new Promise((resolve) => stream.once("close", resolve).destroy(reason));
|
|
}
|
|
};
|
|
exports.WritableStreamDefaultController = class WritableStreamDefaultController {
|
|
constructor(stream) {
|
|
this._stream = stream;
|
|
}
|
|
error(err) {
|
|
this._stream._stream.destroy(err);
|
|
}
|
|
};
|
|
var WritableStream = class _WritableStream {
|
|
static get [writableKind]() {
|
|
return 0;
|
|
}
|
|
constructor(underlyingSink = {}, queuingStrategy = {}) {
|
|
if (isStreamx(underlyingSink)) {
|
|
this._stream = underlyingSink;
|
|
} else {
|
|
if (queuingStrategy === void 0) {
|
|
queuingStrategy = new exports.CountQueuingStrategy();
|
|
}
|
|
const { start, write, close, abort } = underlyingSink;
|
|
const { highWaterMark = 1, size = defaultSize } = queuingStrategy;
|
|
this._stream = new Writable({ highWaterMark, byteLength: size });
|
|
this._controller = new exports.WritableStreamDefaultController(this);
|
|
if (start) {
|
|
this._stream._open = this._open.bind(this, start.call(this, this._controller));
|
|
}
|
|
if (write) {
|
|
this._stream._write = this._write.bind(this, write);
|
|
}
|
|
if (close) {
|
|
this._stream._destroy = this._destroy.bind(this, close.call(this));
|
|
}
|
|
if (abort) {
|
|
this._stream.once("error", abort);
|
|
}
|
|
}
|
|
this._writer = null;
|
|
}
|
|
get [writableKind]() {
|
|
return _WritableStream[writableKind];
|
|
}
|
|
get locked() {
|
|
return this._writer !== null;
|
|
}
|
|
getWriter() {
|
|
if (this.locked) throw new TypeError("Stream is locked");
|
|
this._writer = new exports.WritableStreamDefaultWriter(this);
|
|
return this._writer;
|
|
}
|
|
abort(reason = new TypeError("Stream was aborted")) {
|
|
if (this._stream.destroyed) return Promise.resolve();
|
|
if (this.locked) return Promise.reject(new TypeError("Stream is locked"));
|
|
return new Promise((resolve) => this._stream.once("close", resolve).destroy(reason));
|
|
}
|
|
close() {
|
|
if (this._stream.destroyed) return Promise.resolve();
|
|
if (this.locked) return Promise.reject(new TypeError("Stream is locked"));
|
|
return new Promise((resolve) => this._stream.once("close", resolve).end());
|
|
}
|
|
_releaseLock() {
|
|
this._writer = null;
|
|
}
|
|
async _open(starting, cb) {
|
|
let err = null;
|
|
try {
|
|
await starting;
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
async _write(write, data, cb) {
|
|
let err = null;
|
|
try {
|
|
await write(data, this._controller);
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
async _destroy(closing, cb) {
|
|
let err = null;
|
|
try {
|
|
await closing;
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
};
|
|
exports.WritableStream = WritableStream;
|
|
exports.isWritableStream = function isWritableStream(value) {
|
|
if (value instanceof WritableStream) return true;
|
|
return typeof value === "object" && value !== null && value[writableKind] === WritableStream[writableKind];
|
|
};
|
|
exports.TransformStreamDefaultController = class TransformStreamDefaultController {
|
|
constructor(stream) {
|
|
this._stream = stream;
|
|
}
|
|
get desiredSize() {
|
|
const stream = this._stream._stream;
|
|
return stream._readableState.highWaterMark - stream._readableState.buffered;
|
|
}
|
|
enqueue(data) {
|
|
this._stream._stream.push(data);
|
|
}
|
|
error(err) {
|
|
this._stream._stream.destroy(err);
|
|
}
|
|
terminate() {
|
|
const stream = this._stream._stream;
|
|
stream.push(null);
|
|
stream.destroy(new TypeError("Stream has been terminated"));
|
|
}
|
|
};
|
|
var TransformStream = class _TransformStream {
|
|
static get [transformKind]() {
|
|
return 0;
|
|
}
|
|
constructor(transformer = {}, writableStrategy = {}, readableStrategy = {}) {
|
|
const { start, transform, flush } = transformer;
|
|
this._stream = new Transform({ ...writableStrategy, ...readableStrategy });
|
|
this._writable = new WritableStream(this._stream);
|
|
this._readable = new ReadableStream(this._stream);
|
|
this._controller = new exports.TransformStreamDefaultController(this);
|
|
if (start) {
|
|
this._stream._open = this._open.bind(this, start.call(this, this._controller));
|
|
}
|
|
if (transform) {
|
|
this._stream._write = this._transform.bind(this, transform);
|
|
}
|
|
if (flush) {
|
|
this._stream._flush = this._flush.bind(this, flush.call(this, this._controller));
|
|
}
|
|
}
|
|
get [transformKind]() {
|
|
return _TransformStream[transformKind];
|
|
}
|
|
get writable() {
|
|
return this._writable;
|
|
}
|
|
get readable() {
|
|
return this._readable;
|
|
}
|
|
async _open(starting, cb) {
|
|
let err = null;
|
|
try {
|
|
await starting;
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
async _transform(transform, data, cb) {
|
|
let err = null;
|
|
try {
|
|
await transform(data, this._controller);
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
async _flush(flush, cb) {
|
|
let err = null;
|
|
try {
|
|
await flush;
|
|
} catch (e) {
|
|
err = e;
|
|
}
|
|
cb(err);
|
|
}
|
|
};
|
|
exports.TransformStream = TransformStream;
|
|
exports.isTransformStream = function isTransformStream(value) {
|
|
if (value instanceof TransformStream) return true;
|
|
return typeof value === "object" && value !== null && value[transformKind] === TransformStream[transformKind];
|
|
};
|
|
function noop() {
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-stream/index.js
|
|
var require_bare_stream = __commonJS({
|
|
"../../node_modules/bare-stream/index.js"(exports, module) {
|
|
var stream = require_streamx();
|
|
var { ReadableStream, WritableStream } = require_web();
|
|
var defaultEncoding = "utf8";
|
|
module.exports = exports = stream.Stream;
|
|
exports.pipeline = stream.pipeline;
|
|
exports.isStream = stream.isStream;
|
|
exports.isEnding = stream.isEnding;
|
|
exports.isEnded = stream.isEnded;
|
|
exports.isFinishing = stream.isFinishing;
|
|
exports.isFinished = stream.isFinished;
|
|
exports.isDisturbed = stream.isDisturbed;
|
|
exports.isErrored = function isErrored(stream2) {
|
|
return exports.getStreamError(stream2) !== null;
|
|
};
|
|
exports.isReadable = function isReadable(stream2) {
|
|
return stream2.readable && !stream2.destroying && !exports.isEnded(stream2);
|
|
};
|
|
exports.isWritable = function isWritable(stream2) {
|
|
return stream2.writable && !stream2.destroying && !exports.isFinishing(stream2);
|
|
};
|
|
exports.getStreamError = stream.getStreamError;
|
|
exports.addAbortSignal = function addAbortSignal(signal, stream2) {
|
|
function onAbort() {
|
|
stream2.destroy(signal.reason);
|
|
}
|
|
if (signal.aborted) onAbort();
|
|
else signal.addEventListener("abort", onAbort);
|
|
return stream2;
|
|
};
|
|
exports.Stream = exports;
|
|
exports.Readable = class Readable extends stream.Readable {
|
|
constructor(opts = {}) {
|
|
super({
|
|
...opts,
|
|
byteLength: null,
|
|
byteLengthReadable: null,
|
|
map: null,
|
|
mapReadable: null
|
|
});
|
|
if (this._construct) this._open = this._construct;
|
|
if (this._read !== stream.Readable.prototype._read) {
|
|
this._read = read.bind(this, this._read);
|
|
}
|
|
if (this._destroy !== stream.Stream.prototype._destroy) {
|
|
this._destroy = destroy.bind(this, this._destroy);
|
|
}
|
|
}
|
|
get closed() {
|
|
return !exports.isReadable(this);
|
|
}
|
|
get errored() {
|
|
return stream.getStreamError(this);
|
|
}
|
|
push(chunk, encoding) {
|
|
if (typeof chunk === "string") {
|
|
chunk = Buffer.from(chunk, encoding || defaultEncoding);
|
|
}
|
|
return super.push(chunk);
|
|
}
|
|
unshift(chunk, encoding) {
|
|
if (typeof chunk === "string") {
|
|
chunk = Buffer.from(chunk, encoding || defaultEncoding);
|
|
}
|
|
super.unshift(chunk);
|
|
}
|
|
static fromWeb(readableStream, opts = {}) {
|
|
const stream2 = readableStream._stream;
|
|
if (opts.encoding) stream2.setEncoding(opts.encoding);
|
|
if (opts.signal) exports.addAbortSignal(opts.signal, stream2);
|
|
return stream2;
|
|
}
|
|
static toWeb(readable, opts = {}) {
|
|
return new ReadableStream(readable, opts.strategy);
|
|
}
|
|
async [Symbol.asyncDispose]() {
|
|
if (!this.destroyed) this.destroy();
|
|
await new Promise((resolve) => exports.finished(this, resolve));
|
|
}
|
|
};
|
|
exports.Writable = class Writable extends stream.Writable {
|
|
constructor(opts = {}) {
|
|
super({
|
|
...opts,
|
|
byteLength: null,
|
|
byteLengthWritable,
|
|
map: null,
|
|
mapWritable: null
|
|
});
|
|
if (this._construct) this._open = this._construct;
|
|
if (this._write !== stream.Writable.prototype._write) {
|
|
this._write = write.bind(this, this._write);
|
|
}
|
|
if (this._destroy !== stream.Stream.prototype._destroy) {
|
|
this._destroy = destroy.bind(this, this._destroy);
|
|
}
|
|
}
|
|
get closed() {
|
|
return !exports.isWritable(this);
|
|
}
|
|
get errored() {
|
|
return stream.getStreamError(this);
|
|
}
|
|
write(chunk, encoding, cb) {
|
|
if (typeof encoding === "function") {
|
|
cb = encoding;
|
|
encoding = null;
|
|
}
|
|
if (typeof chunk === "string") {
|
|
encoding = encoding || defaultEncoding;
|
|
chunk = Buffer.from(chunk, encoding);
|
|
} else {
|
|
encoding = "buffer";
|
|
}
|
|
const result = super.write({ chunk, encoding });
|
|
if (cb) stream.Writable.drained(this).then(() => cb(null), cb);
|
|
return result;
|
|
}
|
|
end(chunk, encoding, cb) {
|
|
if (typeof chunk === "function") {
|
|
cb = chunk;
|
|
chunk = null;
|
|
} else if (typeof encoding === "function") {
|
|
cb = encoding;
|
|
encoding = null;
|
|
}
|
|
if (typeof chunk === "string") {
|
|
encoding = encoding || defaultEncoding;
|
|
chunk = Buffer.from(chunk, encoding || defaultEncoding);
|
|
} else {
|
|
encoding = "buffer";
|
|
}
|
|
const result = chunk !== void 0 && chunk !== null ? super.end({ chunk, encoding }) : super.end();
|
|
if (cb) this.once("finish", () => cb(null));
|
|
return result;
|
|
}
|
|
static fromWeb(writableStream, opts = {}) {
|
|
const stream2 = writableStream._stream;
|
|
if (opts.signal) exports.addAbortSignal(opts.signal, stream2);
|
|
return stream2;
|
|
}
|
|
static toWeb(writable) {
|
|
return new WritableStream(writable);
|
|
}
|
|
async [Symbol.asyncDispose]() {
|
|
if (!this.destroyed) this.destroy();
|
|
await new Promise((resolve) => exports.finished(this, resolve));
|
|
}
|
|
};
|
|
exports.Duplex = class Duplex extends stream.Duplex {
|
|
constructor(opts = {}) {
|
|
super({
|
|
...opts,
|
|
byteLength: null,
|
|
byteLengthReadable: null,
|
|
byteLengthWritable,
|
|
map: null,
|
|
mapReadable: null,
|
|
mapWritable: null
|
|
});
|
|
if (this._construct) this._open = this._construct;
|
|
if (this._read !== stream.Readable.prototype._read) {
|
|
this._read = read.bind(this, this._read);
|
|
}
|
|
if (this._write !== stream.Duplex.prototype._write) {
|
|
this._write = write.bind(this, this._write);
|
|
}
|
|
if (this._destroy !== stream.Stream.prototype._destroy) {
|
|
this._destroy = destroy.bind(this, this._destroy);
|
|
}
|
|
}
|
|
push(chunk, encoding) {
|
|
if (typeof chunk === "string") {
|
|
chunk = Buffer.from(chunk, encoding || defaultEncoding);
|
|
}
|
|
return super.push(chunk);
|
|
}
|
|
unshift(chunk, encoding) {
|
|
if (typeof chunk === "string") {
|
|
chunk = Buffer.from(chunk, encoding || defaultEncoding);
|
|
}
|
|
super.unshift(chunk);
|
|
}
|
|
write(chunk, encoding, cb) {
|
|
if (typeof encoding === "function") {
|
|
cb = encoding;
|
|
encoding = null;
|
|
}
|
|
if (typeof chunk === "string") {
|
|
encoding = encoding || defaultEncoding;
|
|
chunk = Buffer.from(chunk, encoding);
|
|
} else {
|
|
encoding = "buffer";
|
|
}
|
|
const result = super.write({ chunk, encoding });
|
|
if (cb) stream.Writable.drained(this).then(() => cb(null), cb);
|
|
return result;
|
|
}
|
|
end(chunk, encoding, cb) {
|
|
if (typeof chunk === "function") {
|
|
cb = chunk;
|
|
chunk = null;
|
|
} else if (typeof encoding === "function") {
|
|
cb = encoding;
|
|
encoding = null;
|
|
}
|
|
if (typeof chunk === "string") {
|
|
encoding = encoding || defaultEncoding;
|
|
chunk = Buffer.from(chunk, encoding);
|
|
} else {
|
|
encoding = "buffer";
|
|
}
|
|
const result = chunk !== void 0 && chunk !== null ? super.end({ chunk, encoding }) : super.end();
|
|
if (cb) this.once("finish", () => cb(null));
|
|
return result;
|
|
}
|
|
static fromWeb({ readable: readableStream, writable: writableStream }, opts) {
|
|
const readable = exports.Readable.fromWeb(readableStream, opts);
|
|
const writable = exports.Readable.fromWeb(writableStream, opts);
|
|
const duplex = new exports.Duplex({
|
|
write(data, encoding, cb) {
|
|
writable.write(data, encoding, cb);
|
|
}
|
|
});
|
|
readable.on("data", (data) => duplex.push(data)).on("end", () => duplex.push(null)).on("error", (err) => duplex.destroy(err));
|
|
writable.on("finish", () => duplex.end()).on("error", (err) => duplex.destroy(err));
|
|
return duplex;
|
|
}
|
|
static toWeb(duplex) {
|
|
const readableStream = exports.Readable.toWeb(duplex);
|
|
const writableStream = exports.Writable.toWeb(duplex);
|
|
return { readable: readableStream, writable: writableStream };
|
|
}
|
|
};
|
|
var DuplexSide = class extends exports.Duplex {
|
|
constructor(opts) {
|
|
super(opts);
|
|
this._otherSide = null;
|
|
this._cb = null;
|
|
}
|
|
_read() {
|
|
const cb = this._cb;
|
|
if (!cb) return;
|
|
this._cb = null;
|
|
cb();
|
|
}
|
|
_write(chunk, encoding, cb) {
|
|
this._otherSide.push(chunk, encoding);
|
|
this._otherSide._cb = cb;
|
|
}
|
|
_final(cb) {
|
|
this._otherSide.on("end", cb);
|
|
this._otherSide.push(null);
|
|
}
|
|
};
|
|
exports.duplexPair = function duplexPair(opts) {
|
|
const sideA = new DuplexSide(opts);
|
|
const sideB = new DuplexSide(opts);
|
|
sideA._otherSide = sideB;
|
|
sideB._otherSide = sideA;
|
|
return [sideA, sideB];
|
|
};
|
|
exports.Transform = class Transform extends stream.Transform {
|
|
constructor(opts = {}) {
|
|
super({
|
|
...opts,
|
|
byteLength: null,
|
|
byteLengthReadable: null,
|
|
byteLengthWritable,
|
|
map: null,
|
|
mapReadable: null,
|
|
mapWritable: null
|
|
});
|
|
if (this._transform !== stream.Transform.prototype._transform) {
|
|
this._transform = transform.bind(this, this._transform);
|
|
} else {
|
|
this._transform = passthrough;
|
|
}
|
|
}
|
|
push(chunk, encoding) {
|
|
if (typeof chunk === "string") {
|
|
chunk = Buffer.from(chunk, encoding || defaultEncoding);
|
|
}
|
|
return super.push(chunk);
|
|
}
|
|
unshift(chunk, encoding) {
|
|
if (typeof chunk === "string") {
|
|
chunk = Buffer.from(chunk, encoding || defaultEncoding);
|
|
}
|
|
super.unshift(chunk);
|
|
}
|
|
write(chunk, encoding, cb) {
|
|
if (typeof encoding === "function") {
|
|
cb = encoding;
|
|
encoding = null;
|
|
}
|
|
if (typeof chunk === "string") {
|
|
encoding = encoding || defaultEncoding;
|
|
chunk = Buffer.from(chunk, encoding);
|
|
} else {
|
|
encoding = "buffer";
|
|
}
|
|
const result = super.write({ chunk, encoding });
|
|
if (cb) stream.Writable.drained(this).then(() => cb(null), cb);
|
|
return result;
|
|
}
|
|
end(chunk, encoding, cb) {
|
|
if (typeof chunk === "function") {
|
|
cb = chunk;
|
|
chunk = null;
|
|
} else if (typeof encoding === "function") {
|
|
cb = encoding;
|
|
encoding = null;
|
|
}
|
|
if (typeof chunk === "string") {
|
|
encoding = encoding || defaultEncoding;
|
|
chunk = Buffer.from(chunk, encoding);
|
|
} else {
|
|
encoding = "buffer";
|
|
}
|
|
const result = chunk !== void 0 && chunk !== null ? super.end({ chunk, encoding }) : super.end();
|
|
if (cb) this.once("finish", () => cb(null));
|
|
return result;
|
|
}
|
|
};
|
|
exports.PassThrough = class PassThrough extends exports.Transform {
|
|
};
|
|
exports.finished = function finished(stream2, opts, cb) {
|
|
if (typeof opts === "function") {
|
|
cb = opts;
|
|
opts = {};
|
|
}
|
|
if (!opts) opts = {};
|
|
const { cleanup = false } = opts;
|
|
const done = () => {
|
|
cb(exports.getStreamError(stream2, { all: true }));
|
|
if (cleanup) detach();
|
|
};
|
|
const detach = () => {
|
|
stream2.off("close", done);
|
|
stream2.off("error", noop);
|
|
};
|
|
if (stream2.destroyed) {
|
|
done();
|
|
} else {
|
|
stream2.on("close", done);
|
|
stream2.on("error", noop);
|
|
}
|
|
return detach;
|
|
};
|
|
function read(read2, cb) {
|
|
read2.call(this, 65536);
|
|
cb(null);
|
|
}
|
|
function write(write2, data, cb) {
|
|
write2.call(this, data.chunk, data.encoding, cb);
|
|
}
|
|
function transform(transform2, data, cb) {
|
|
transform2.call(this, data.chunk, data.encoding, cb);
|
|
}
|
|
function destroy(destroy2, cb) {
|
|
destroy2.call(this, exports.getStreamError(this), cb);
|
|
}
|
|
function passthrough(data, cb) {
|
|
cb(null, data.chunk);
|
|
}
|
|
function byteLengthWritable(data) {
|
|
return data.chunk.byteLength;
|
|
}
|
|
function noop() {
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-crypto/lib/hash.js
|
|
var require_hash = __commonJS({
|
|
"../../node_modules/bare-crypto/lib/hash.js"(exports, module) {
|
|
var { Transform } = require_bare_stream();
|
|
var assert = require_bare_assert();
|
|
var binding = require_binding3();
|
|
var constants = require_constants();
|
|
var {
|
|
hash: { RIPEMD160 }
|
|
} = constants;
|
|
var CryptoDigest = class {
|
|
constructor(algorithm) {
|
|
this._handle = binding.digestInit(algorithm);
|
|
}
|
|
update(data) {
|
|
if (this._handle === null) {
|
|
throw new Error("Digest has already been finalized");
|
|
}
|
|
binding.digestUpdate(this._handle, data.buffer, data.byteOffset, data.byteLength);
|
|
}
|
|
final() {
|
|
if (this._handle === null) {
|
|
throw new Error("Digest has already been finalized");
|
|
}
|
|
const result = Buffer.from(binding.digestFinal(this._handle));
|
|
this._handle = null;
|
|
return result;
|
|
}
|
|
};
|
|
var CryptoRIPEMD160Digest = class {
|
|
constructor() {
|
|
this._handle = binding.ripemd160Init();
|
|
}
|
|
update(data) {
|
|
if (this._handle === null) {
|
|
throw new Error("Digest has already been finalized");
|
|
}
|
|
binding.ripemd160Update(this._handle, data.buffer, data.byteOffset, data.byteLength);
|
|
}
|
|
final() {
|
|
if (this._handle === null) {
|
|
throw new Error("Digest has already been finalized");
|
|
}
|
|
const result = Buffer.from(binding.ripemd160Final(this._handle));
|
|
this._handle = null;
|
|
return result;
|
|
}
|
|
};
|
|
module.exports = class CryptoHash extends Transform {
|
|
constructor(algorithm, opts = {}) {
|
|
super(opts);
|
|
algorithm = constants.toHash(algorithm);
|
|
switch (algorithm) {
|
|
case RIPEMD160:
|
|
this._digest = new CryptoRIPEMD160Digest();
|
|
break;
|
|
default:
|
|
this._digest = new CryptoDigest(algorithm);
|
|
break;
|
|
}
|
|
}
|
|
update(data, encoding = "utf8") {
|
|
if (typeof data === "string") data = Buffer.from(data, encoding);
|
|
assert(ArrayBuffer.isView(data));
|
|
this._digest.update(data);
|
|
return this;
|
|
}
|
|
digest(encoding) {
|
|
const digest = this._digest.final();
|
|
return encoding && encoding !== "buffer" ? digest.toString(encoding) : digest;
|
|
}
|
|
_transform(data, encoding, cb) {
|
|
this.update(data);
|
|
cb(null);
|
|
}
|
|
_flush(cb) {
|
|
this.push(this.digest());
|
|
cb(null);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-crypto/lib/hmac.js
|
|
var require_hmac = __commonJS({
|
|
"../../node_modules/bare-crypto/lib/hmac.js"(exports, module) {
|
|
var { Transform } = require_bare_stream();
|
|
var assert = require_bare_assert();
|
|
var binding = require_binding3();
|
|
var constants = require_constants();
|
|
module.exports = class CryptoHmac extends Transform {
|
|
constructor(algorithm, key, opts = {}) {
|
|
super(opts);
|
|
const { encoding = "utf8" } = opts;
|
|
if (typeof key === "string") key = Buffer.from(key, encoding);
|
|
assert(ArrayBuffer.isView(key));
|
|
this._handle = binding.hmacInit(
|
|
constants.toHash(algorithm),
|
|
key.buffer,
|
|
key.byteOffset,
|
|
key.byteLength
|
|
);
|
|
}
|
|
update(data, encoding = "utf8") {
|
|
if (this._handle === null) {
|
|
throw new Error("Hmac has already been finalized");
|
|
}
|
|
if (typeof data === "string") data = Buffer.from(data, encoding);
|
|
assert(ArrayBuffer.isView(data));
|
|
binding.hmacUpdate(this._handle, data.buffer, data.byteOffset, data.byteLength);
|
|
return this;
|
|
}
|
|
digest(encoding) {
|
|
if (this._handle === null) {
|
|
throw new Error("Hmac has already been finalized");
|
|
}
|
|
const digest = Buffer.from(binding.hmacFinal(this._handle));
|
|
this._handle = null;
|
|
return encoding && encoding !== "buffer" ? digest.toString(encoding) : digest;
|
|
}
|
|
_transform(data, encoding, cb) {
|
|
this.update(data);
|
|
cb(null);
|
|
}
|
|
_flush(cb) {
|
|
this.push(this.digest());
|
|
cb(null);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-crypto/lib/cipher.js
|
|
var require_cipher = __commonJS({
|
|
"../../node_modules/bare-crypto/lib/cipher.js"(exports) {
|
|
var { Transform } = require_bare_stream();
|
|
var assert = require_bare_assert();
|
|
var binding = require_binding3();
|
|
var constants = require_constants();
|
|
var {
|
|
cipher: {
|
|
AES128ECB,
|
|
AES128CBC,
|
|
AES128CTR,
|
|
AES128OFB,
|
|
AES256ECB,
|
|
AES256CBC,
|
|
AES256CTR,
|
|
AES256OFB,
|
|
AES128GCM,
|
|
AES256GCM,
|
|
CHACHA20POLY1305,
|
|
XCHACHA20POLY1305
|
|
}
|
|
} = constants;
|
|
var CryptoCipher = class {
|
|
constructor(algorithm, key, iv, encrypt, opts = {}) {
|
|
const { encoding = "utf8" } = opts;
|
|
if (typeof key === "string") key = Buffer.from(key, encoding);
|
|
if (typeof iv === "string") iv = Buffer.from(iv, encoding);
|
|
assert(ArrayBuffer.isView(key));
|
|
assert(ArrayBuffer.isView(iv));
|
|
if (key.byteLength !== binding.cipherKeyLength(algorithm)) {
|
|
throw new RangeError("Invalid key length");
|
|
}
|
|
if (iv.byteLength < binding.cipherIVLength(algorithm)) {
|
|
throw new RangeError("Invalid iv length");
|
|
}
|
|
this._handle = binding.cipherInit(
|
|
algorithm,
|
|
key.buffer,
|
|
key.byteOffset,
|
|
key.byteLength,
|
|
iv.buffer,
|
|
iv.byteOffset,
|
|
iv.byteLength,
|
|
encrypt
|
|
);
|
|
}
|
|
update(data, inputEncoding = "utf8", outputEncoding) {
|
|
if (this._handle === null) {
|
|
throw new Error("Cipher has already been finalized");
|
|
}
|
|
if (typeof data === "string") data = Buffer.from(data, inputEncoding);
|
|
assert(ArrayBuffer.isView(data));
|
|
const out = new ArrayBuffer(data.byteLength + binding.cipherBlockSize(this._handle));
|
|
const written = binding.cipherUpdate(
|
|
this._handle,
|
|
data.buffer,
|
|
data.byteOffset,
|
|
data.byteLength,
|
|
out
|
|
);
|
|
const result = Buffer.from(out, 0, written);
|
|
return outputEncoding ? result.toString(outputEncoding) : result;
|
|
}
|
|
final(outputEncoding) {
|
|
if (this._handle === null) {
|
|
throw new Error("Cipher has already been finalized");
|
|
}
|
|
const out = new ArrayBuffer(binding.cipherBlockSize(this._handle));
|
|
const written = binding.cipherFinal(this._handle, out);
|
|
this._handle = null;
|
|
const result = Buffer.from(out, 0, written);
|
|
return outputEncoding ? result.toString(outputEncoding) : result;
|
|
}
|
|
setAutoPadding(pad) {
|
|
if (this._handle === null) {
|
|
throw new Error("Cipher has already been finalized");
|
|
}
|
|
binding.cipherSetPadding(this._handle, pad);
|
|
}
|
|
};
|
|
var CryptoAuthenticatedCipher = class {
|
|
constructor(algorithm, key, nonce, opts = {}) {
|
|
const { encoding = "utf8", authTagLength = 16 } = opts;
|
|
if (typeof key === "string") key = Buffer.from(key, encoding);
|
|
if (typeof nonce === "string") nonce = Buffer.from(nonce, encoding);
|
|
assert(ArrayBuffer.isView(key));
|
|
assert(ArrayBuffer.isView(nonce));
|
|
if (key.byteLength !== binding.aeadKeyLength(algorithm)) {
|
|
throw new RangeError("Invalid key length");
|
|
}
|
|
if (nonce.byteLength < binding.aeadNonceLength(algorithm)) {
|
|
throw new RangeError("Invalid nonce length");
|
|
}
|
|
this._buffer = [];
|
|
this._nonce = nonce;
|
|
this._authTag = null;
|
|
this._authTagLength = authTagLength;
|
|
this._additionalData = null;
|
|
this._handle = binding.aeadInit(
|
|
algorithm,
|
|
key.buffer,
|
|
key.byteOffset,
|
|
key.byteLength,
|
|
authTagLength
|
|
);
|
|
}
|
|
update(data, inputEncoding = "utf8", outputEncoding) {
|
|
if (typeof data === "string") data = Buffer.from(data, inputEncoding);
|
|
assert(ArrayBuffer.isView(data));
|
|
this._buffer.push(data);
|
|
return outputEncoding ? "" : Buffer.alloc(0);
|
|
}
|
|
setAAD(buffer, opts = {}) {
|
|
const { encoding = "utf8" } = opts;
|
|
if (typeof buffer === "string") buffer = Buffer.from(buffer, encoding);
|
|
assert(ArrayBuffer.isView(buffer));
|
|
this._additionalData = buffer;
|
|
}
|
|
getAuthTag() {
|
|
return this._authTag;
|
|
}
|
|
setAuthTag(authTag, encoding) {
|
|
if (typeof authTag === "string") authTag = Buffer.from(authTag, encoding);
|
|
assert(ArrayBuffer.isView(authTag));
|
|
this._authTag = authTag;
|
|
}
|
|
};
|
|
var CryptoAuthenticatedSeal = class extends CryptoAuthenticatedCipher {
|
|
final(outputEncoding) {
|
|
if (this._handle === null) {
|
|
throw new Error("Cipher has already been finalized");
|
|
}
|
|
const data = this._buffer.length === 1 ? this._buffer[0] : Buffer.concat(this._buffer);
|
|
const nonce = this._nonce;
|
|
const ad = this._additionalData || Buffer.alloc(0);
|
|
const out = new ArrayBuffer(data.byteLength + binding.aeadMaxOverhead(this._handle));
|
|
const written = binding.aeadSeal(
|
|
this._handle,
|
|
data.buffer,
|
|
data.byteOffset,
|
|
data.byteLength,
|
|
nonce.buffer,
|
|
nonce.byteOffset,
|
|
nonce.byteLength,
|
|
ad.buffer,
|
|
ad.byteOffset,
|
|
ad.byteLength,
|
|
out
|
|
);
|
|
this._handle = null;
|
|
const cipherLength = written - this._authTagLength;
|
|
this._authTag = Buffer.from(out, cipherLength);
|
|
const result = Buffer.from(out, 0, cipherLength);
|
|
return outputEncoding ? result.toString(outputEncoding) : result;
|
|
}
|
|
};
|
|
var CryptoAuthenticatedOpen = class extends CryptoAuthenticatedCipher {
|
|
final(outputEncoding) {
|
|
if (this._handle === null) {
|
|
throw new Error("Decipher has already been finalized");
|
|
}
|
|
this._buffer.push(this._authTag);
|
|
const data = Buffer.concat(this._buffer);
|
|
const nonce = this._nonce;
|
|
const ad = this._additionalData || Buffer.alloc(0);
|
|
const out = new ArrayBuffer(data.byteLength);
|
|
const written = binding.aeadOpen(
|
|
this._handle,
|
|
data.buffer,
|
|
data.byteOffset,
|
|
data.byteLength,
|
|
nonce.buffer,
|
|
nonce.byteOffset,
|
|
nonce.byteLength,
|
|
ad.buffer,
|
|
ad.byteOffset,
|
|
ad.byteLength,
|
|
out
|
|
);
|
|
this._handle = null;
|
|
const result = Buffer.from(out, 0, written);
|
|
return outputEncoding ? result.toString(outputEncoding) : result;
|
|
}
|
|
};
|
|
exports.Cipheriv = class CryptoCipheriv extends Transform {
|
|
constructor(algorithm, key, iv, opts = {}) {
|
|
super(opts);
|
|
algorithm = constants.toCipher(algorithm);
|
|
switch (algorithm) {
|
|
case AES128ECB:
|
|
case AES128CBC:
|
|
case AES128CTR:
|
|
case AES128OFB:
|
|
case AES256ECB:
|
|
case AES256CBC:
|
|
case AES256CTR:
|
|
case AES256OFB:
|
|
this._cipher = new CryptoCipher(algorithm, key, iv, true, opts);
|
|
break;
|
|
case AES128GCM:
|
|
case AES256GCM:
|
|
case CHACHA20POLY1305:
|
|
case XCHACHA20POLY1305:
|
|
this._cipher = new CryptoAuthenticatedSeal(algorithm, key, iv, opts);
|
|
break;
|
|
}
|
|
}
|
|
update(data, inputEncoding, outputEncoding) {
|
|
return this._cipher.update(data, inputEncoding, outputEncoding);
|
|
}
|
|
final(outputEncoding) {
|
|
return this._cipher.final(outputEncoding);
|
|
}
|
|
setAutoPadding(pad) {
|
|
this._cipher.setAutoPadding(pad);
|
|
return this;
|
|
}
|
|
setAAD(buffer, opts) {
|
|
this._cipher.setAAD(buffer, opts);
|
|
return this;
|
|
}
|
|
getAuthTag() {
|
|
return this._cipher.getAuthTag();
|
|
}
|
|
_transform(data, encoding, cb) {
|
|
this.push(this.update(data));
|
|
cb(null);
|
|
}
|
|
_flush(cb) {
|
|
this.push(this.final());
|
|
cb(null);
|
|
}
|
|
};
|
|
exports.Decipheriv = class CryptoDeipheriv extends Transform {
|
|
constructor(algorithm, key, iv, opts = {}) {
|
|
super(opts);
|
|
algorithm = constants.toCipher(algorithm);
|
|
switch (algorithm) {
|
|
case AES128ECB:
|
|
case AES128CBC:
|
|
case AES128CTR:
|
|
case AES128OFB:
|
|
case AES256ECB:
|
|
case AES256CBC:
|
|
case AES256CTR:
|
|
case AES256OFB:
|
|
this._cipher = new CryptoCipher(algorithm, key, iv, false, opts);
|
|
break;
|
|
case AES128GCM:
|
|
case AES256GCM:
|
|
case CHACHA20POLY1305:
|
|
case XCHACHA20POLY1305:
|
|
this._cipher = new CryptoAuthenticatedOpen(algorithm, key, iv, opts);
|
|
break;
|
|
}
|
|
}
|
|
update(data, inputEncoding, outputEncoding) {
|
|
return this._cipher.update(data, inputEncoding, outputEncoding);
|
|
}
|
|
final(outputEncoding) {
|
|
return this._cipher.final(outputEncoding);
|
|
}
|
|
setAutoPadding(pad) {
|
|
this._cipher.setAutoPadding(pad);
|
|
return this;
|
|
}
|
|
setAAD(buffer, opts) {
|
|
this._cipher.setAAD(buffer, opts);
|
|
return this;
|
|
}
|
|
setAuthTag(authTag, encoding) {
|
|
this._cipher.setAuthTag(authTag, encoding);
|
|
return this;
|
|
}
|
|
_transform(data, encoding, cb) {
|
|
this.push(this.update(data));
|
|
cb(null);
|
|
}
|
|
_flush(cb) {
|
|
this.push(this.final());
|
|
cb(null);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-crypto/lib/random.js
|
|
var require_random = __commonJS({
|
|
"../../node_modules/bare-crypto/lib/random.js"(exports) {
|
|
var assert = require_bare_assert();
|
|
var binding = require_binding3();
|
|
exports.randomBytes = function randomBytes(size, cb) {
|
|
assert(typeof size === "number" && !isNaN(size));
|
|
const buffer = Buffer.allocUnsafe(size);
|
|
exports.randomFill(buffer);
|
|
if (cb) queueMicrotask(() => cb(null, buffer));
|
|
else return buffer;
|
|
};
|
|
exports.randomFill = function randomFill(buffer, offset, size, cb) {
|
|
if (typeof offset === "function") {
|
|
cb = offset;
|
|
offset = void 0;
|
|
} else if (typeof size === "function") {
|
|
cb = size;
|
|
size = void 0;
|
|
}
|
|
assert(buffer instanceof ArrayBuffer || ArrayBuffer.isView(buffer));
|
|
assert(size === void 0 || typeof size === "number" && !isNaN(size));
|
|
assert(offset === void 0 || typeof offset === "number" && !isNaN(offset));
|
|
const elementSize = buffer.BYTES_PER_ELEMENT || 1;
|
|
if (offset === void 0) offset = 0;
|
|
else offset *= elementSize;
|
|
if (size === void 0) size = buffer.byteLength - offset;
|
|
else size *= elementSize;
|
|
if (offset < 0 || offset > buffer.byteLength) {
|
|
throw new RangeError("offset is out of range");
|
|
}
|
|
if (size < 0 || size > buffer.byteLength) {
|
|
throw new RangeError("size is out of range");
|
|
}
|
|
if (offset + size > buffer.byteLength) {
|
|
throw new RangeError("offset + size is out of range");
|
|
}
|
|
let arraybuffer;
|
|
if (ArrayBuffer.isView(buffer)) {
|
|
offset += buffer.byteOffset;
|
|
arraybuffer = buffer.buffer;
|
|
} else {
|
|
arraybuffer = buffer;
|
|
}
|
|
binding.randomFill(arraybuffer, offset, size);
|
|
if (cb) queueMicrotask(() => cb(null, buffer));
|
|
else return buffer;
|
|
};
|
|
exports.randomUUID = function randomUUID() {
|
|
const uuid = exports.randomBytes(16);
|
|
uuid[6] = uuid[6] >>> 4 | 64;
|
|
uuid[8] = uuid[8] >>> 2 | 128;
|
|
return uuid.subarray(0, 4).toString("hex") + "-" + uuid.subarray(4, 6).toString("hex") + "-" + uuid.subarray(6, 8).toString("hex") + "-" + uuid.subarray(8, 10).toString("hex") + "-" + uuid.subarray(10, 16).toString("hex");
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-crypto/lib/pbkdf2.js
|
|
var require_pbkdf2 = __commonJS({
|
|
"../../node_modules/bare-crypto/lib/pbkdf2.js"(exports, module) {
|
|
var assert = require_bare_assert();
|
|
var binding = require_binding3();
|
|
var constants = require_constants();
|
|
module.exports = function pbkdf2(password, salt, iterations, keylen, digest, cb) {
|
|
if (iterations <= 0) {
|
|
throw new RangeError("iterations is out of range");
|
|
}
|
|
assert(typeof iterations === "number" && !isNaN(iterations));
|
|
assert(typeof keylen === "number" && !isNaN(keylen));
|
|
if (typeof password === "string") password = Buffer.from(password);
|
|
if (typeof salt === "string") salt = Buffer.from(salt);
|
|
assert(ArrayBuffer.isView(password));
|
|
assert(ArrayBuffer.isView(salt));
|
|
const buffer = Buffer.from(
|
|
binding.pbkdf2(
|
|
password.buffer,
|
|
password.byteOffset,
|
|
password.byteLength,
|
|
salt.buffer,
|
|
salt.byteOffset,
|
|
salt.byteLength,
|
|
iterations,
|
|
constants.toHash(digest),
|
|
keylen
|
|
)
|
|
);
|
|
if (cb) queueMicrotask(() => cb(null, buffer));
|
|
else return buffer;
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-crypto/lib/key.js
|
|
var require_key = __commonJS({
|
|
"../../node_modules/bare-crypto/lib/key.js"(exports) {
|
|
var binding = require_binding3();
|
|
var constants = require_constants();
|
|
var {
|
|
keyType: { ED25519 }
|
|
} = constants;
|
|
var CryptoKey = class {
|
|
constructor(keyType) {
|
|
this._keyType = keyType;
|
|
}
|
|
};
|
|
exports.Key = CryptoKey;
|
|
var CryptoEd25519Key = class extends CryptoKey {
|
|
constructor(key) {
|
|
super(ED25519);
|
|
this._key = key;
|
|
}
|
|
get asymmetricKeyType() {
|
|
return "ed25519";
|
|
}
|
|
};
|
|
var CryptoEd25519PublicKey = class extends CryptoEd25519Key {
|
|
get type() {
|
|
return "public";
|
|
}
|
|
};
|
|
exports.Ed25519PublicKey = CryptoEd25519PublicKey;
|
|
var CryptoEd25519PrivateKey = class extends CryptoEd25519Key {
|
|
get type() {
|
|
return "private";
|
|
}
|
|
};
|
|
exports.Ed25519PrivateKey = CryptoEd25519PrivateKey;
|
|
exports.generateKeyPair = function generateKeyPair(type, opts = {}) {
|
|
type = constants.toKeyType(type);
|
|
switch (type) {
|
|
case ED25519: {
|
|
const { publicKey, privateKey } = binding.ed25519GenerateKeypair();
|
|
return {
|
|
publicKey: new CryptoEd25519PublicKey(publicKey),
|
|
privateKey: new CryptoEd25519PrivateKey(privateKey)
|
|
};
|
|
}
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-crypto/lib/signature.js
|
|
var require_signature = __commonJS({
|
|
"../../node_modules/bare-crypto/lib/signature.js"(exports) {
|
|
var assert = require_bare_assert();
|
|
var binding = require_binding3();
|
|
var { Key } = require_key();
|
|
var constants = require_constants();
|
|
var {
|
|
keyType: { ED25519 }
|
|
} = constants;
|
|
exports.sign = function sign(algorithm, data, key) {
|
|
assert(data instanceof ArrayBuffer || ArrayBuffer.isView(data));
|
|
if (ArrayBuffer.isView(data)) {
|
|
data = Buffer.coerce(data);
|
|
} else {
|
|
data = Buffer.from(data);
|
|
}
|
|
assert(key instanceof Key);
|
|
switch (key._keyType) {
|
|
case ED25519:
|
|
return Buffer.from(
|
|
binding.ed25519Sign(data.buffer, data.byteOffset, data.byteLength, key._key)
|
|
);
|
|
}
|
|
};
|
|
exports.verify = function verify(algorithm, data, key, signature) {
|
|
assert(data instanceof ArrayBuffer || ArrayBuffer.isView(data));
|
|
if (ArrayBuffer.isView(data)) {
|
|
data = Buffer.coerce(data);
|
|
} else {
|
|
data = Buffer.from(data);
|
|
}
|
|
assert(signature instanceof ArrayBuffer || ArrayBuffer.isView(signature));
|
|
if (ArrayBuffer.isView(signature)) {
|
|
signature = Buffer.coerce(signature);
|
|
} else {
|
|
signature = Buffer.from(signature);
|
|
}
|
|
assert(key instanceof Key);
|
|
switch (key._keyType) {
|
|
case ED25519:
|
|
assert(signature.byteLength === 64);
|
|
return binding.ed25519Verify(
|
|
data.buffer,
|
|
data.byteOffset,
|
|
data.byteLength,
|
|
signature.buffer,
|
|
signature.byteOffset,
|
|
key._key
|
|
);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-crypto/lib/web/crypto-key.js
|
|
var require_crypto_key = __commonJS({
|
|
"../../node_modules/bare-crypto/lib/web/crypto-key.js"(exports, module) {
|
|
module.exports = class CryptoKey {
|
|
constructor(type, extractable, algorithm, usages, handle = null) {
|
|
this._type = type;
|
|
this._extractable = extractable;
|
|
this._algorithm = algorithm;
|
|
this._usages = usages;
|
|
this._handle = handle;
|
|
}
|
|
// https://w3c.github.io/webcrypto/#dom-cryptokey-type
|
|
get type() {
|
|
return this._type;
|
|
}
|
|
// https://w3c.github.io/webcrypto/#dom-cryptokey-extractable
|
|
get extractable() {
|
|
return this._extractable;
|
|
}
|
|
// https://w3c.github.io/webcrypto/#dom-cryptokey-algorithm
|
|
get algorithm() {
|
|
return this._algorithm;
|
|
}
|
|
// https://w3c.github.io/webcrypto/#dom-cryptokey-usages
|
|
get usages() {
|
|
return this._usages;
|
|
}
|
|
[Symbol.for("bare.inspect")]() {
|
|
return {
|
|
__proto__: { constructor: CryptoKey },
|
|
type: this.type,
|
|
extractable: this.extractable,
|
|
algorithm: this.algorithm,
|
|
usages: this.usages
|
|
};
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-crypto/lib/web/algorithm/hmac.js
|
|
var require_hmac2 = __commonJS({
|
|
"../../node_modules/bare-crypto/lib/web/algorithm/hmac.js"(exports) {
|
|
var crypto = require_bare_crypto();
|
|
var errors = require_errors();
|
|
var CryptoKey = require_crypto_key();
|
|
exports.sign = function sign(algorithm, key, data) {
|
|
const digest = crypto.createHmac(key.algorithm.hash.name, key._handle).update(data).digest();
|
|
return digest.buffer.slice(0, digest.byteLength);
|
|
};
|
|
exports.verify = function verify(algorithm, key, signature, data) {
|
|
const digest = crypto.createHmac(key.algorithm.hash.name, key._handle).update(data).digest();
|
|
if (ArrayBuffer.isView(signature)) {
|
|
signature = Buffer.coerce(signature);
|
|
} else {
|
|
signature = Buffer.from(signature);
|
|
}
|
|
return signature.equals(digest);
|
|
};
|
|
exports.generateKey = function generateKey(algorithm, extractable, usages) {
|
|
for (const usage of usages) {
|
|
if (usage !== "sign" && usage !== "verify") {
|
|
throw new SyntaxError(`Usage '${usage}' cannot be used for the HMAC generateKey() operation`);
|
|
}
|
|
}
|
|
const { length = exports.getKeyLength(algorithm) } = algorithm.length;
|
|
let hash = algorithm.hash;
|
|
if (typeof hash === "string") hash = { name: hash };
|
|
const key = crypto.createHmac(hash.name, crypto.randomBytes(length)).digest();
|
|
return new CryptoKey(
|
|
"secret",
|
|
extractable,
|
|
{
|
|
name: "HMAC",
|
|
length,
|
|
hash: {
|
|
name: hash.name.toUpperCase()
|
|
}
|
|
},
|
|
usages,
|
|
key
|
|
);
|
|
};
|
|
exports.importKey = function importKey(format, keyData, algorithm, extractable, usages) {
|
|
for (const usage of usages) {
|
|
if (usage !== "sign" && usage !== "verify") {
|
|
throw new SyntaxError(`Invalid usage ${usage}`);
|
|
}
|
|
}
|
|
let hash = algorithm.hash;
|
|
if (typeof hash === "string") hash = { name: hash };
|
|
let data;
|
|
switch (format) {
|
|
case "raw":
|
|
data = keyData;
|
|
break;
|
|
case "jwk":
|
|
const jwk = keyData;
|
|
if (jwk.kty !== "oct") {
|
|
throw errors.INVALID_DATA("JWK key must be an octet sequence");
|
|
}
|
|
data = Buffer.from(jwk.k, "base64url");
|
|
switch (hash.name.toLowerCase()) {
|
|
case "sha-1":
|
|
if (jwk.alg === "HS1") break;
|
|
else throw errors.INVALID_DATA("Invalid JWK key algorithm");
|
|
case "sha-256":
|
|
if (jwk.alg === "HS256") break;
|
|
else throw errors.INVALID_DATA("Invalid JWK key algorithm");
|
|
case "sha-384":
|
|
if (jwk.alg === "HS384") break;
|
|
else throw errors.INVALID_DATA("Invalid JWK key algorithm");
|
|
case "sha-512":
|
|
if (jwk.alg === "HS512") break;
|
|
else throw errors.INVALID_DATA("Invalid JWK key algorithm");
|
|
}
|
|
if (usages.length && "use" in jwk && jwk.use !== "sign") {
|
|
throw errors.INVALID_DATA("JWK cannot be used for signing");
|
|
}
|
|
if ("ext" in jwk && jwk.ext !== extractable && extractable) {
|
|
throw errors.INVALID_DATA("JWK is not extractable");
|
|
}
|
|
break;
|
|
default:
|
|
throw errors.NOT_SUPPORTED(
|
|
`Format '${format}' cannot be used for the HMAC importKey() operation`
|
|
);
|
|
}
|
|
const length = data.byteLength * 8;
|
|
if (length === 0) {
|
|
throw errors.INVALID_DATA("Key cannot be empty");
|
|
}
|
|
return new CryptoKey(
|
|
"secret",
|
|
extractable,
|
|
{
|
|
name: "HMAC",
|
|
length,
|
|
hash: {
|
|
name: hash.name.toUpperCase()
|
|
}
|
|
},
|
|
usages,
|
|
data
|
|
);
|
|
};
|
|
exports.exportKey = function exportKey(format, key) {
|
|
const data = key._handle;
|
|
switch (format) {
|
|
case "raw":
|
|
return data.buffer.slice(0, data.byteLength);
|
|
case "jwk": {
|
|
const jwk = {
|
|
kty: "oct",
|
|
k: data.toString("base64url"),
|
|
alg: null,
|
|
key_ops: key.usages,
|
|
ext: key.extractable
|
|
};
|
|
switch (key.algorithm.hash.name) {
|
|
case "SHA-1":
|
|
jwk.alg = "HS1";
|
|
break;
|
|
case "SHA-256":
|
|
jwk.alg = "HS256";
|
|
break;
|
|
case "SHA-384":
|
|
jwk.alg = "HS384";
|
|
break;
|
|
case "SHA-512":
|
|
jwk.alg = "HS512";
|
|
break;
|
|
}
|
|
return jwk;
|
|
}
|
|
default:
|
|
throw errors.NOT_SUPPORTED(
|
|
`Format '${format}' cannot be used for the HMAC exportKey() operation`
|
|
);
|
|
}
|
|
};
|
|
exports.getKeyLength = function getKeyLength(algorithm) {
|
|
const { length, hash } = algorithm;
|
|
if (length === void 0) {
|
|
if (hash === "SHA-1" || hash === "SHA-256") return 512;
|
|
if (hash === "SHA-512") return 1024;
|
|
throw errors.OPERATION_ERROR(`Invalid hash '${hash}'`);
|
|
}
|
|
if (length === 0) {
|
|
throw errors.OPERATION_ERROR(`Invalid length ${length}`);
|
|
}
|
|
return length;
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-crypto/lib/web/algorithm/pbkdf2.js
|
|
var require_pbkdf22 = __commonJS({
|
|
"../../node_modules/bare-crypto/lib/web/algorithm/pbkdf2.js"(exports) {
|
|
var crypto = require_bare_crypto();
|
|
var errors = require_errors();
|
|
var CryptoKey = require_crypto_key();
|
|
exports.deriveBits = function deriveBits(algorithm, key, length) {
|
|
if (length === void 0 || length % 8) {
|
|
throw errors.OPERATION_ERROR("Length must be multiple of 8");
|
|
}
|
|
if (algorithm.iterations === 0) {
|
|
throw errors.OPERATION_ERROR("Iterations must be non-0");
|
|
}
|
|
if (length === 0) {
|
|
return new ArrayBuffer(0);
|
|
}
|
|
let hash = algorithm.hash;
|
|
if (typeof hash === "string") hash = { name: hash };
|
|
const result = crypto.pbkdf2(
|
|
key._handle,
|
|
algorithm.salt,
|
|
algorithm.iterations,
|
|
length / 8,
|
|
hash.name
|
|
);
|
|
return result.buffer;
|
|
};
|
|
exports.importKey = function importKey(format, keyData, algorithm, extractable, usages) {
|
|
if (format !== "raw") {
|
|
throw errors.NOT_SUPPORTED(
|
|
`Format '${format}' cannot be used for the PBKDF2 importKey() operation`
|
|
);
|
|
}
|
|
for (const usage of usages) {
|
|
if (usage !== "deriveKey" && usage !== "deriveBits") {
|
|
throw new SyntaxError(`Invalid usage ${usage}`);
|
|
}
|
|
}
|
|
if (extractable) {
|
|
throw new SyntaxError("Extractable must be false");
|
|
}
|
|
return new CryptoKey(
|
|
"secret",
|
|
extractable,
|
|
{
|
|
name: "PBKDF2"
|
|
},
|
|
usages,
|
|
keyData
|
|
);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-crypto/lib/web/algorithm/ed25519.js
|
|
var require_ed25519 = __commonJS({
|
|
"../../node_modules/bare-crypto/lib/web/algorithm/ed25519.js"(exports) {
|
|
var crypto = require_bare_crypto();
|
|
var binding = require_binding3();
|
|
var errors = require_errors();
|
|
var { Ed25519PublicKey, Ed25519PrivateKey } = require_key();
|
|
var CryptoKey = require_crypto_key();
|
|
exports.sign = function sign(algorithm, key, data) {
|
|
if (key.type !== "private") {
|
|
throw errors.INVALID_ACCESS("Must pass private key for Ed25519 signing");
|
|
}
|
|
const signature = crypto.sign(null, data, key._handle);
|
|
return signature.buffer.slice(0, signature.byteLength);
|
|
};
|
|
exports.verify = function verify(algorithm, key, signature, data) {
|
|
if (key.type !== "public") {
|
|
throw errors.INVALID_ACCESS("Must pass public key for Ed25519 verification");
|
|
}
|
|
return crypto.verify(null, data, key._handle, signature);
|
|
};
|
|
exports.generateKey = function generateKey(algorithm, extractable, usages) {
|
|
for (const usage of usages) {
|
|
if (usage !== "sign" && usage !== "verify") {
|
|
throw new SyntaxError(
|
|
`Usage '${usage}' cannot be used for the Ed25519 generateKey() operation`
|
|
);
|
|
}
|
|
}
|
|
const keys = crypto.generateKeyPair("ed25519");
|
|
algorithm = { name: "Ed25519" };
|
|
return {
|
|
publicKey: new CryptoKey("public", true, algorithm, ["verify"], keys.publicKey),
|
|
privateKey: new CryptoKey("private", extractable, algorithm, ["sign"], keys.privateKey)
|
|
};
|
|
};
|
|
exports.importKey = function importKey(format, keyData, algorithm, extractable, usages) {
|
|
switch (format) {
|
|
case "spki":
|
|
for (const usage of usages) {
|
|
if (usage !== "verify") {
|
|
throw new SyntaxError(
|
|
`Usage '${usage}' cannot be used for the Ed25519 importKey() operation`
|
|
);
|
|
}
|
|
}
|
|
keyData = binding.ed25519FromSPKI(keyData.buffer, keyData.byteOffset, keyData.byteLength);
|
|
return new CryptoKey(
|
|
"public",
|
|
extractable,
|
|
{
|
|
name: "Ed25519"
|
|
},
|
|
usages,
|
|
new Ed25519PublicKey(keyData)
|
|
);
|
|
case "pkcs8":
|
|
for (const usage of usages) {
|
|
if (usage !== "sign") {
|
|
throw new SyntaxError(
|
|
`Usage '${usage}' cannot be used for the Ed25519 importKey() operation`
|
|
);
|
|
}
|
|
}
|
|
keyData = binding.ed25519FromPKCS8(keyData.buffer, keyData.byteOffset, keyData.byteLength);
|
|
return new CryptoKey(
|
|
"private",
|
|
extractable,
|
|
{
|
|
name: "Ed25519"
|
|
},
|
|
usages,
|
|
new Ed25519PrivateKey(keyData)
|
|
);
|
|
case "raw":
|
|
for (const usage of usages) {
|
|
if (usage !== "verify") {
|
|
throw new SyntaxError(
|
|
`Usage '${usage}' cannot be used for the Ed25519 importKey() operation`
|
|
);
|
|
}
|
|
}
|
|
if (keyData.byteLength * 8 !== 256) {
|
|
throw errors.INVALID_DATA("Key must be 256 bits");
|
|
}
|
|
return new CryptoKey(
|
|
"public",
|
|
extractable,
|
|
{
|
|
name: "Ed25519"
|
|
},
|
|
usages,
|
|
new Ed25519PublicKey(keyData.buffer)
|
|
);
|
|
case "jwk":
|
|
const jwk = keyData;
|
|
if ("d" in jwk) {
|
|
if (usages.some((usage) => usage !== "sign")) {
|
|
throw new SyntaxError("JWK must be valid for signing");
|
|
}
|
|
} else {
|
|
if (usages.some((usage) => usage !== "verify")) {
|
|
throw new SyntaxError("JWK must be valid for verification");
|
|
}
|
|
}
|
|
if (jwk.kty !== "OKP") {
|
|
throw errors.INVALID_DATA("JWK key must be an octet key-pair");
|
|
}
|
|
if (jwk.crv !== "Ed25519") {
|
|
throw errors.INVALID_DATA("JWK must use the Ed25519 curve");
|
|
}
|
|
if ("alg" in jwk && jwk.alg !== "Ed25519" && jwk.alg !== "EdDSA") {
|
|
throw errors.INVALID_DATA("JWK must use the Ed25519 curve");
|
|
}
|
|
if (usages.length && "use" in jwk && jwk.use !== "sig") {
|
|
throw errors.INVALID_DATA("JWK cannot be used for signatures");
|
|
}
|
|
if ("ext" in jwk && jwk.ext !== extractable && extractable) {
|
|
throw errors.INVALID_DATA("JWK is not extractable");
|
|
}
|
|
if ("d" in jwk) {
|
|
const key2 = Buffer.concat([
|
|
Buffer.from(jwk.d, "base64url"),
|
|
Buffer.from(jwk.x, "base64url")
|
|
]);
|
|
if (key2.byteLength * 8 !== 512) {
|
|
throw errors.INVALID_DATA("Key must be 512 bits");
|
|
}
|
|
return new CryptoKey(
|
|
"private",
|
|
extractable,
|
|
{
|
|
name: "Ed25519"
|
|
},
|
|
usages,
|
|
new Ed25519PrivateKey(key2.buffer)
|
|
);
|
|
}
|
|
const key = Buffer.from(jwk.x, "base64url");
|
|
if (key.byteLength * 8 !== 256) {
|
|
throw errors.INVALID_DATA("Key must be 256 bits");
|
|
}
|
|
return new CryptoKey(
|
|
"public",
|
|
extractable,
|
|
{
|
|
name: "Ed25519"
|
|
},
|
|
usages,
|
|
new Ed25519PublicKey(key.buffer)
|
|
);
|
|
default:
|
|
throw errors.NOT_SUPPORTED(
|
|
`Format '${format}' cannot be used for the Ed25519 importKey() operation`
|
|
);
|
|
}
|
|
};
|
|
exports.exportKey = function exportKey(format, key) {
|
|
const data = key._handle;
|
|
switch (format) {
|
|
case "spki":
|
|
if (key.type !== "public") {
|
|
throw errors.INVALID_ACCESS(
|
|
`Key of type '${key.type}' cannot be used for the Ed25519 exportKey() operation`
|
|
);
|
|
}
|
|
return binding.ed25519ToSPKI(data._key);
|
|
case "pkcs8":
|
|
if (key.type !== "private") {
|
|
throw errors.INVALID_ACCESS(
|
|
`Key of type '${key.type}' cannot be used for the Ed25519 exportKey() operation`
|
|
);
|
|
}
|
|
return binding.ed25519ToPKCS8(data._key);
|
|
case "raw": {
|
|
if (key.type !== "public") {
|
|
throw errors.INVALID_ACCESS(
|
|
`Key of type '${key.type}' cannot be used for the Ed25519 exportKey() operation`
|
|
);
|
|
}
|
|
return data._key.slice();
|
|
}
|
|
case "jwk": {
|
|
const buffer = Buffer.from(data._key);
|
|
if (key.type === "private") {
|
|
const d = buffer.subarray(0, 32).toString("base64url");
|
|
const x = buffer.subarray(32).toString("base64url");
|
|
return {
|
|
kty: "OKP",
|
|
alg: "Ed25519",
|
|
crv: "Ed25519",
|
|
x,
|
|
d,
|
|
key_ops: key.usages,
|
|
ext: key.extractable
|
|
};
|
|
}
|
|
return {
|
|
kty: "OKP",
|
|
alg: "Ed25519",
|
|
crv: "Ed25519",
|
|
x: buffer.toString("base64url"),
|
|
key_ops: key.usages,
|
|
ext: key.extractable
|
|
};
|
|
}
|
|
default:
|
|
throw errors.NOT_SUPPORTED(
|
|
`Format '${format}' cannot be used for the HMAC exportKey() operation`
|
|
);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-crypto/lib/web/algorithm/sha.js
|
|
var require_sha = __commonJS({
|
|
"../../node_modules/bare-crypto/lib/web/algorithm/sha.js"(exports) {
|
|
var crypto = require_bare_crypto();
|
|
exports.digest = function digest(name, data) {
|
|
const digest2 = crypto.createHash(name).update(data).digest();
|
|
return digest2.buffer.slice(0, digest2.byteLength);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-crypto/web.js
|
|
var require_web2 = __commonJS({
|
|
"../../node_modules/bare-crypto/web.js"(exports) {
|
|
var crypto = require_bare_crypto();
|
|
var errors = require_errors();
|
|
var CryptoKey = require_crypto_key();
|
|
var hmac = require_hmac2();
|
|
var pbkdf2 = require_pbkdf22();
|
|
var ed25519 = require_ed25519();
|
|
var sha = require_sha();
|
|
exports.CryptoKey = CryptoKey;
|
|
exports.getRandomValues = function getRandomValues(array) {
|
|
return crypto.randomFillSync(array);
|
|
};
|
|
exports.randomUUID = crypto.randomUUID;
|
|
exports.SubtleCrypto = class SubtleCrypto {
|
|
// https://w3c.github.io/webcrypto/#SubtleCrypto-method-generateKey
|
|
async generateKey(algorithm, extractable, usages) {
|
|
if (typeof algorithm === "string") algorithm = { name: algorithm };
|
|
switch (algorithm.name.toLowerCase()) {
|
|
case "hmac":
|
|
return hmac.generateKey(algorithm, extractable, usages);
|
|
case "ed25519":
|
|
return ed25519.generateKey(algorithm, extractable, usages);
|
|
default:
|
|
throw errors.NOT_SUPPORTED(
|
|
`Algorithm '${algorithm.name}' does not support the generateKey() operation`
|
|
);
|
|
}
|
|
}
|
|
// https://w3c.github.io/webcrypto/#SubtleCrypto-method-importKey
|
|
async importKey(format, keyData, algorithm, extractable, usages) {
|
|
if (typeof algorithm === "string") algorithm = { name: algorithm };
|
|
switch (format) {
|
|
case "raw":
|
|
case "pkcs8":
|
|
case "spki":
|
|
if (ArrayBuffer.isView(keyData)) {
|
|
keyData = Buffer.from(keyData);
|
|
} else {
|
|
keyData = Buffer.from(keyData.slice());
|
|
}
|
|
break;
|
|
}
|
|
switch (algorithm.name.toLowerCase()) {
|
|
case "hmac":
|
|
return hmac.importKey(format, keyData, algorithm, extractable, usages);
|
|
case "ed25519":
|
|
return ed25519.importKey(format, keyData, algorithm, extractable, usages);
|
|
case "pbkdf2":
|
|
return pbkdf2.importKey(format, keyData, algorithm, extractable, usages);
|
|
default:
|
|
throw errors.NOT_SUPPORTED(
|
|
`Algorithm '${algorithm.name}' does not support the importKey() operation`
|
|
);
|
|
}
|
|
}
|
|
// https://w3c.github.io/webcrypto/#SubtleCrypto-method-exportKey
|
|
async exportKey(format, key) {
|
|
if (!key.extractable) {
|
|
throw errors.INVALID_ACCESS("Key is not extractable");
|
|
}
|
|
switch (key.algorithm.name.toLowerCase()) {
|
|
case "hmac":
|
|
return hmac.exportKey(format, key);
|
|
case "ed25519":
|
|
return ed25519.exportKey(format, key);
|
|
default:
|
|
throw errors.NOT_SUPPORTED(
|
|
`Algorithm '${key.algorithm.name}' does not support the exportKey() operation`
|
|
);
|
|
}
|
|
}
|
|
// https://w3c.github.io/webcrypto/#SubtleCrypto-method-sign
|
|
async sign(algorithm, key, data) {
|
|
if (typeof algorithm === "string") algorithm = { name: algorithm };
|
|
if (algorithm.name.toLowerCase() !== key.algorithm.name.toLowerCase()) {
|
|
throw errors.INVALID_ACCESS(`Algorithm '${algorithm.name}' does not match key'`);
|
|
}
|
|
if (!key.usages.includes("sign")) {
|
|
throw errors.INVALID_ACCESS("Key cannot be used for signing");
|
|
}
|
|
switch (algorithm.name.toLowerCase()) {
|
|
case "hmac":
|
|
return hmac.sign(algorithm, key, data);
|
|
case "ed25519":
|
|
return ed25519.sign(algorithm, key, data);
|
|
default:
|
|
throw errors.NOT_SUPPORTED(
|
|
`Algorithm '${algorithm.name}' does not support the sign() operation`
|
|
);
|
|
}
|
|
}
|
|
// https://w3c.github.io/webcrypto/#SubtleCrypto-method-verify
|
|
async verify(algorithm, key, signature, data) {
|
|
if (typeof algorithm === "string") algorithm = { name: algorithm };
|
|
if (algorithm.name.toLowerCase() !== key.algorithm.name.toLowerCase()) {
|
|
throw errors.INVALID_ACCESS(`Algorithm '${algorithm.name}' does not match key'`);
|
|
}
|
|
if (!key.usages.includes("verify")) {
|
|
throw errors.INVALID_ACCESS("Key cannot be used for verification");
|
|
}
|
|
switch (algorithm.name.toLowerCase()) {
|
|
case "hmac":
|
|
return hmac.verify(algorithm, key, signature, data);
|
|
case "ed25519":
|
|
return ed25519.verify(algorithm, key, signature, data);
|
|
default:
|
|
throw errors.NOT_SUPPORTED(
|
|
`Algorithm '${algorithm.name}' does not support the verify() operation`
|
|
);
|
|
}
|
|
}
|
|
// https://w3c.github.io/webcrypto/#SubtleCrypto-method-deriveBits
|
|
async deriveBits(algorithm, key, length) {
|
|
if (typeof algorithm === "string") algorithm = { name: algorithm };
|
|
if (algorithm.name.toLowerCase() !== key.algorithm.name.toLowerCase()) {
|
|
throw errors.INVALID_ACCESS(`Algorithm '${algorithm.name}' does not match key'`);
|
|
}
|
|
if (!key.usages.includes("deriveBits")) {
|
|
throw errors.INVALID_ACCESS("Key cannot be used to derive bits");
|
|
}
|
|
switch (algorithm.name.toLowerCase()) {
|
|
case "pbkdf2":
|
|
return pbkdf2.deriveBits(algorithm, key, length);
|
|
default:
|
|
throw errors.NOT_SUPPORTED(
|
|
`Algorithm '${algorithm.name}' does not support the deriveBits() operation`
|
|
);
|
|
}
|
|
}
|
|
// https://w3c.github.io/webcrypto/#SubtleCrypto-method-deriveKey
|
|
async deriveKey(algorithm, baseKey, derivedKeyType, extractable, usages) {
|
|
if (typeof algorithm === "string") algorithm = { name: algorithm };
|
|
if (typeof derivedKeyType === "string") {
|
|
derivedKeyType = { name: derivedKeyType };
|
|
}
|
|
if (algorithm.name.toLowerCase() !== baseKey.algorithm.name.toLowerCase()) {
|
|
throw errors.INVALID_ACCESS(`Algorithm '${algorithm.name}' does not match key'`);
|
|
}
|
|
if (!baseKey.usages.includes("deriveKey")) {
|
|
throw errors.INVALID_ACCESS("Key cannot be used to derive key");
|
|
}
|
|
let length;
|
|
switch (derivedKeyType.name.toLowerCase()) {
|
|
case "hmac":
|
|
length = hmac.getKeyLength(derivedKeyType);
|
|
break;
|
|
default:
|
|
throw errors.NOT_SUPPORTED(
|
|
`Algorithm '${derivedKeyType.name}' does not support the getKeyLength() operation`
|
|
);
|
|
}
|
|
let secret;
|
|
switch (algorithm.name.toLowerCase()) {
|
|
case "pbkdf2":
|
|
secret = pbkdf2.deriveBits(algorithm, baseKey, length);
|
|
break;
|
|
default:
|
|
throw errors.NOT_SUPPORTED(
|
|
`Algorithm '${algorithm.name}' does not support the deriveBits() operation`
|
|
);
|
|
}
|
|
return this.importKey("raw", secret, derivedKeyType, extractable, usages);
|
|
}
|
|
// https://w3c.github.io/webcrypto/#SubtleCrypto-method-digest
|
|
async digest(algorithm, data) {
|
|
if (typeof algorithm === "string") algorithm = { name: algorithm };
|
|
switch (algorithm.name.toLowerCase()) {
|
|
case "sha-1":
|
|
return sha.digest(crypto.constants.hash.SHA1, data);
|
|
case "sha-256":
|
|
return sha.digest(crypto.constants.hash.SHA256, data);
|
|
case "sha-384":
|
|
return sha.digest(crypto.constants.hash.SHA384, data);
|
|
case "sha-512":
|
|
return sha.digest(crypto.constants.hash.SHA512, data);
|
|
default:
|
|
throw errors.NOT_SUPPORTED(
|
|
`Algorithm '${algorithm.name}' does not support the digest() operation`
|
|
);
|
|
}
|
|
}
|
|
};
|
|
exports.subtle = new exports.SubtleCrypto();
|
|
exports.Crypto = class Crypto {
|
|
get subtle() {
|
|
return exports.subtle;
|
|
}
|
|
getRandomValues(array) {
|
|
return exports.getRandomValues(array);
|
|
}
|
|
randomUUID() {
|
|
return exports.randomUUID();
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-crypto/index.js
|
|
var require_bare_crypto = __commonJS({
|
|
"../../node_modules/bare-crypto/index.js"(exports) {
|
|
var constants = require_constants();
|
|
var Hash = require_hash();
|
|
var Hmac = require_hmac();
|
|
var { Cipheriv, Decipheriv } = require_cipher();
|
|
var { randomBytes, randomFill, randomUUID } = require_random();
|
|
var pbkdf2 = require_pbkdf2();
|
|
var { generateKeyPair } = require_key();
|
|
var { sign, verify } = require_signature();
|
|
exports.constants = constants;
|
|
exports.Hash = Hash;
|
|
exports.createHash = function createHash(algorithm, opts) {
|
|
return new Hash(algorithm, opts);
|
|
};
|
|
exports.Hmac = Hmac;
|
|
exports.createHmac = function createHmac(algorithm, key, opts) {
|
|
return new Hmac(algorithm, key, opts);
|
|
};
|
|
exports.Cipheriv = Cipheriv;
|
|
exports.createCipheriv = function createCipheriv(algorithm, key, iv, opts) {
|
|
return new Cipheriv(algorithm, key, iv, opts);
|
|
};
|
|
exports.Decipheriv = Decipheriv;
|
|
exports.createDecipheriv = function createDecipheriv(algorithm, key, iv, opts) {
|
|
return new Decipheriv(algorithm, key, iv, opts);
|
|
};
|
|
exports.randomBytes = randomBytes;
|
|
exports.randomFill = randomFill;
|
|
exports.randomFillSync = function randomFillSync(buffer, offset, size) {
|
|
return exports.randomFill(buffer, offset, size);
|
|
};
|
|
exports.randomUUID = randomUUID;
|
|
exports.pbkdf2 = pbkdf2;
|
|
exports.pbkdf2Sync = function pbkdf2Sync(password, salt, iterations, keylen, digest) {
|
|
return exports.pbkdf2(password, salt, iterations, keylen, digest);
|
|
};
|
|
exports.generateKeyPair = generateKeyPair;
|
|
exports.sign = sign;
|
|
exports.verify = verify;
|
|
exports.webcrypto = require_web2();
|
|
}
|
|
});
|
|
|
|
// ../../bare-lib-entry-bareCrypto.js
|
|
var bare_lib_entry_bareCrypto_exports = {};
|
|
__export(bare_lib_entry_bareCrypto_exports, {
|
|
default: () => bare_lib_entry_bareCrypto_default
|
|
});
|
|
var import_bare_crypto = __toESM(require_bare_crypto());
|
|
var bare_lib_entry_bareCrypto_default = import_bare_crypto.default;
|
|
return __toCommonJS(bare_lib_entry_bareCrypto_exports);
|
|
})();
|
|
;(function(){var g=globalThis;var s="__bare_os_stdlib__";g[s]=g[s]||{};g[s]["bareCrypto"]=typeof __bare_os_bundle_exports__!=="undefined"?__bare_os_bundle_exports__:void 0;})();
|