ssv-keys
Version:
CLI Tool for splitting a validator key into a predefined threshold of shares via Shamir-Secret-Sharing (SSS), and encrypt them with a set of operator keys.
1,667 lines • 2.69 MB
JavaScript
#!/usr/bin/env node
import require$$0$1 from "util";
import require$$0 from "os";
import require$$0$2 from "readline";
import fs$2, { promises } from "fs";
import path$1 from "path";
import crypto$1$1 from "crypto";
var commonjsGlobal$1 = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
function getDefaultExportFromCjs$1(x) {
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
}
var safe = { exports: {} };
var colors$1 = { exports: {} };
var styles = { exports: {} };
var hasRequiredStyles;
function requireStyles() {
if (hasRequiredStyles) return styles.exports;
hasRequiredStyles = 1;
(function(module2) {
var styles2 = {};
module2["exports"] = styles2;
var codes = {
reset: [0, 0],
bold: [1, 22],
dim: [2, 22],
italic: [3, 23],
underline: [4, 24],
inverse: [7, 27],
hidden: [8, 28],
strikethrough: [9, 29],
black: [30, 39],
red: [31, 39],
green: [32, 39],
yellow: [33, 39],
blue: [34, 39],
magenta: [35, 39],
cyan: [36, 39],
white: [37, 39],
gray: [90, 39],
grey: [90, 39],
brightRed: [91, 39],
brightGreen: [92, 39],
brightYellow: [93, 39],
brightBlue: [94, 39],
brightMagenta: [95, 39],
brightCyan: [96, 39],
brightWhite: [97, 39],
bgBlack: [40, 49],
bgRed: [41, 49],
bgGreen: [42, 49],
bgYellow: [43, 49],
bgBlue: [44, 49],
bgMagenta: [45, 49],
bgCyan: [46, 49],
bgWhite: [47, 49],
bgGray: [100, 49],
bgGrey: [100, 49],
bgBrightRed: [101, 49],
bgBrightGreen: [102, 49],
bgBrightYellow: [103, 49],
bgBrightBlue: [104, 49],
bgBrightMagenta: [105, 49],
bgBrightCyan: [106, 49],
bgBrightWhite: [107, 49],
// legacy styles for colors pre v1.0.0
blackBG: [40, 49],
redBG: [41, 49],
greenBG: [42, 49],
yellowBG: [43, 49],
blueBG: [44, 49],
magentaBG: [45, 49],
cyanBG: [46, 49],
whiteBG: [47, 49]
};
Object.keys(codes).forEach(function(key) {
var val = codes[key];
var style2 = styles2[key] = [];
style2.open = "\x1B[" + val[0] + "m";
style2.close = "\x1B[" + val[1] + "m";
});
})(styles);
return styles.exports;
}
var hasFlag;
var hasRequiredHasFlag;
function requireHasFlag() {
if (hasRequiredHasFlag) return hasFlag;
hasRequiredHasFlag = 1;
hasFlag = function(flag, argv) {
argv = argv || process.argv;
var terminatorPos = argv.indexOf("--");
var prefix = /^-{1,2}/.test(flag) ? "" : "--";
var pos = argv.indexOf(prefix + flag);
return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
};
return hasFlag;
}
var supportsColors;
var hasRequiredSupportsColors;
function requireSupportsColors() {
if (hasRequiredSupportsColors) return supportsColors;
hasRequiredSupportsColors = 1;
var os2 = require$$0;
var hasFlag2 = requireHasFlag();
var env2 = process.env;
var forceColor = void 0;
if (hasFlag2("no-color") || hasFlag2("no-colors") || hasFlag2("color=false")) {
forceColor = false;
} else if (hasFlag2("color") || hasFlag2("colors") || hasFlag2("color=true") || hasFlag2("color=always")) {
forceColor = true;
}
if ("FORCE_COLOR" in env2) {
forceColor = env2.FORCE_COLOR.length === 0 || parseInt(env2.FORCE_COLOR, 10) !== 0;
}
function translateLevel(level) {
if (level === 0) {
return false;
}
return {
level,
hasBasic: true,
has256: level >= 2,
has16m: level >= 3
};
}
function supportsColor(stream) {
if (forceColor === false) {
return 0;
}
if (hasFlag2("color=16m") || hasFlag2("color=full") || hasFlag2("color=truecolor")) {
return 3;
}
if (hasFlag2("color=256")) {
return 2;
}
if (stream && !stream.isTTY && forceColor !== true) {
return 0;
}
var min2 = forceColor ? 1 : 0;
if (process.platform === "win32") {
var osRelease = os2.release().split(".");
if (Number(process.versions.node.split(".")[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
return Number(osRelease[2]) >= 14931 ? 3 : 2;
}
return 1;
}
if ("CI" in env2) {
if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI"].some(function(sign2) {
return sign2 in env2;
}) || env2.CI_NAME === "codeship") {
return 1;
}
return min2;
}
if ("TEAMCITY_VERSION" in env2) {
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env2.TEAMCITY_VERSION) ? 1 : 0;
}
if ("TERM_PROGRAM" in env2) {
var version2 = parseInt((env2.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
switch (env2.TERM_PROGRAM) {
case "iTerm.app":
return version2 >= 3 ? 3 : 2;
case "Hyper":
return 3;
case "Apple_Terminal":
return 2;
}
}
if (/-256(color)?$/i.test(env2.TERM)) {
return 2;
}
if (/^screen|^xterm|^vt100|^rxvt|color|ansi|cygwin|linux/i.test(env2.TERM)) {
return 1;
}
if ("COLORTERM" in env2) {
return 1;
}
if (env2.TERM === "dumb") {
return min2;
}
return min2;
}
function getSupportLevel(stream) {
var level = supportsColor(stream);
return translateLevel(level);
}
supportsColors = {
supportsColor: getSupportLevel,
stdout: getSupportLevel(process.stdout),
stderr: getSupportLevel(process.stderr)
};
return supportsColors;
}
var trap = { exports: {} };
var hasRequiredTrap;
function requireTrap() {
if (hasRequiredTrap) return trap.exports;
hasRequiredTrap = 1;
(function(module2) {
module2["exports"] = function runTheTrap(text2, options2) {
var result = "";
text2 = text2 || "Run the trap, drop the bass";
text2 = text2.split("");
var trap2 = {
a: ["@", "Ą", "Ⱥ", "Ʌ", "Δ", "Λ", "Д"],
b: ["ß", "Ɓ", "Ƀ", "ɮ", "β", "฿"],
c: ["©", "Ȼ", "Ͼ"],
d: ["Ð", "Ɗ", "Ԁ", "ԁ", "Ԃ", "ԃ"],
e: [
"Ë",
"ĕ",
"Ǝ",
"ɘ",
"Σ",
"ξ",
"Ҽ",
"੬"
],
f: ["Ӻ"],
g: ["ɢ"],
h: ["Ħ", "ƕ", "Ң", "Һ", "Ӈ", "Ԋ"],
i: ["༏"],
j: ["Ĵ"],
k: ["ĸ", "Ҡ", "Ӄ", "Ԟ"],
l: ["Ĺ"],
m: ["ʍ", "Ӎ", "ӎ", "Ԡ", "ԡ", "൩"],
n: ["Ñ", "ŋ", "Ɲ", "Ͷ", "Π", "Ҋ"],
o: [
"Ø",
"õ",
"ø",
"Ǿ",
"ʘ",
"Ѻ",
"ם",
"",
"๏"
],
p: ["Ƿ", "Ҏ"],
q: ["্"],
r: ["®", "Ʀ", "Ȑ", "Ɍ", "ʀ", "Я"],
s: ["§", "Ϟ", "ϟ", "Ϩ"],
t: ["Ł", "Ŧ", "ͳ"],
u: ["Ʊ", "Ս"],
v: ["ט"],
w: ["Ш", "Ѡ", "Ѽ", "൰"],
x: ["Ҳ", "Ӿ", "Ӽ", "ӽ"],
y: ["¥", "Ұ", "Ӌ"],
z: ["Ƶ", "ɀ"]
};
text2.forEach(function(c) {
c = c.toLowerCase();
var chars = trap2[c] || [" "];
var rand = Math.floor(Math.random() * chars.length);
if (typeof trap2[c] !== "undefined") {
result += trap2[c][rand];
} else {
result += c;
}
});
return result;
};
})(trap);
return trap.exports;
}
var zalgo = { exports: {} };
var hasRequiredZalgo;
function requireZalgo() {
if (hasRequiredZalgo) return zalgo.exports;
hasRequiredZalgo = 1;
(function(module2) {
module2["exports"] = function zalgo2(text2, options2) {
text2 = text2 || " he is here ";
var soul = {
"up": [
"̍",
"̎",
"̄",
"̅",
"̿",
"̑",
"̆",
"̐",
"͒",
"͗",
"͑",
"̇",
"̈",
"̊",
"͂",
"̓",
"̈",
"͊",
"͋",
"͌",
"̃",
"̂",
"̌",
"͐",
"̀",
"́",
"̋",
"̏",
"̒",
"̓",
"̔",
"̽",
"̉",
"ͣ",
"ͤ",
"ͥ",
"ͦ",
"ͧ",
"ͨ",
"ͩ",
"ͪ",
"ͫ",
"ͬ",
"ͭ",
"ͮ",
"ͯ",
"̾",
"͛",
"͆",
"̚"
],
"down": [
"̖",
"̗",
"̘",
"̙",
"̜",
"̝",
"̞",
"̟",
"̠",
"̤",
"̥",
"̦",
"̩",
"̪",
"̫",
"̬",
"̭",
"̮",
"̯",
"̰",
"̱",
"̲",
"̳",
"̹",
"̺",
"̻",
"̼",
"ͅ",
"͇",
"͈",
"͉",
"͍",
"͎",
"͓",
"͔",
"͕",
"͖",
"͙",
"͚",
"̣"
],
"mid": [
"̕",
"̛",
"̀",
"́",
"͘",
"̡",
"̢",
"̧",
"̨",
"̴",
"̵",
"̶",
"͜",
"͝",
"͞",
"͟",
"͠",
"͢",
"̸",
"̷",
"͡",
" ҉"
]
};
var all = [].concat(soul.up, soul.down, soul.mid);
function randomNumber(range2) {
var r = Math.floor(Math.random() * range2);
return r;
}
function isChar(character) {
var bool = false;
all.filter(function(i) {
bool = i === character;
});
return bool;
}
function heComes(text3, options3) {
var result = "";
var counts;
var l;
options3 = options3 || {};
options3["up"] = typeof options3["up"] !== "undefined" ? options3["up"] : true;
options3["mid"] = typeof options3["mid"] !== "undefined" ? options3["mid"] : true;
options3["down"] = typeof options3["down"] !== "undefined" ? options3["down"] : true;
options3["size"] = typeof options3["size"] !== "undefined" ? options3["size"] : "maxi";
text3 = text3.split("");
for (l in text3) {
if (isChar(l)) {
continue;
}
result = result + text3[l];
counts = { "up": 0, "down": 0, "mid": 0 };
switch (options3.size) {
case "mini":
counts.up = randomNumber(8);
counts.mid = randomNumber(2);
counts.down = randomNumber(8);
break;
case "maxi":
counts.up = randomNumber(16) + 3;
counts.mid = randomNumber(4) + 1;
counts.down = randomNumber(64) + 3;
break;
default:
counts.up = randomNumber(8) + 1;
counts.mid = randomNumber(6) / 2;
counts.down = randomNumber(8) + 1;
break;
}
var arr = ["up", "mid", "down"];
for (var d in arr) {
var index = arr[d];
for (var i = 0; i <= counts[index]; i++) {
if (options3[index]) {
result = result + soul[index][randomNumber(soul[index].length)];
}
}
}
}
return result;
}
return heComes(text2, options2);
};
})(zalgo);
return zalgo.exports;
}
var america = { exports: {} };
var hasRequiredAmerica;
function requireAmerica() {
if (hasRequiredAmerica) return america.exports;
hasRequiredAmerica = 1;
(function(module2) {
module2["exports"] = function(colors2) {
return function(letter, i, exploded) {
if (letter === " ") return letter;
switch (i % 3) {
case 0:
return colors2.red(letter);
case 1:
return colors2.white(letter);
case 2:
return colors2.blue(letter);
}
};
};
})(america);
return america.exports;
}
var zebra = { exports: {} };
var hasRequiredZebra;
function requireZebra() {
if (hasRequiredZebra) return zebra.exports;
hasRequiredZebra = 1;
(function(module2) {
module2["exports"] = function(colors2) {
return function(letter, i, exploded) {
return i % 2 === 0 ? letter : colors2.inverse(letter);
};
};
})(zebra);
return zebra.exports;
}
var rainbow = { exports: {} };
var hasRequiredRainbow;
function requireRainbow() {
if (hasRequiredRainbow) return rainbow.exports;
hasRequiredRainbow = 1;
(function(module2) {
module2["exports"] = function(colors2) {
var rainbowColors = ["red", "yellow", "green", "blue", "magenta"];
return function(letter, i, exploded) {
if (letter === " ") {
return letter;
} else {
return colors2[rainbowColors[i++ % rainbowColors.length]](letter);
}
};
};
})(rainbow);
return rainbow.exports;
}
var random$2 = { exports: {} };
var hasRequiredRandom$2;
function requireRandom$2() {
if (hasRequiredRandom$2) return random$2.exports;
hasRequiredRandom$2 = 1;
(function(module2) {
module2["exports"] = function(colors2) {
var available = [
"underline",
"inverse",
"grey",
"yellow",
"red",
"green",
"blue",
"white",
"cyan",
"magenta",
"brightYellow",
"brightRed",
"brightGreen",
"brightBlue",
"brightWhite",
"brightCyan",
"brightMagenta"
];
return function(letter, i, exploded) {
return letter === " " ? letter : colors2[available[Math.round(Math.random() * (available.length - 2))]](letter);
};
};
})(random$2);
return random$2.exports;
}
var hasRequiredColors;
function requireColors() {
if (hasRequiredColors) return colors$1.exports;
hasRequiredColors = 1;
(function(module2) {
var colors2 = {};
module2["exports"] = colors2;
colors2.themes = {};
var util2 = require$$0$1;
var ansiStyles = colors2.styles = requireStyles();
var defineProps = Object.defineProperties;
var newLineRegex = new RegExp(/[\r\n]+/g);
colors2.supportsColor = requireSupportsColors().supportsColor;
if (typeof colors2.enabled === "undefined") {
colors2.enabled = colors2.supportsColor() !== false;
}
colors2.enable = function() {
colors2.enabled = true;
};
colors2.disable = function() {
colors2.enabled = false;
};
colors2.stripColors = colors2.strip = function(str) {
return ("" + str).replace(/\x1B\[\d+m/g, "");
};
colors2.stylize = function stylize(str, style2) {
if (!colors2.enabled) {
return str + "";
}
var styleMap = ansiStyles[style2];
if (!styleMap && style2 in colors2) {
return colors2[style2](str);
}
return styleMap.open + str + styleMap.close;
};
var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
var escapeStringRegexp = function(str) {
if (typeof str !== "string") {
throw new TypeError("Expected a string");
}
return str.replace(matchOperatorsRe, "\\$&");
};
function build(_styles) {
var builder = function builder2() {
return applyStyle.apply(builder2, arguments);
};
builder._styles = _styles;
builder.__proto__ = proto2;
return builder;
}
var styles2 = function() {
var ret = {};
ansiStyles.grey = ansiStyles.gray;
Object.keys(ansiStyles).forEach(function(key) {
ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), "g");
ret[key] = {
get: function() {
return build(this._styles.concat(key));
}
};
});
return ret;
}();
var proto2 = defineProps(function colors3() {
}, styles2);
function applyStyle() {
var args = Array.prototype.slice.call(arguments);
var str = args.map(function(arg) {
if (arg != null && arg.constructor === String) {
return arg;
} else {
return util2.inspect(arg);
}
}).join(" ");
if (!colors2.enabled || !str) {
return str;
}
var newLinesPresent = str.indexOf("\n") != -1;
var nestedStyles = this._styles;
var i = nestedStyles.length;
while (i--) {
var code = ansiStyles[nestedStyles[i]];
str = code.open + str.replace(code.closeRe, code.open) + code.close;
if (newLinesPresent) {
str = str.replace(newLineRegex, function(match) {
return code.close + match + code.open;
});
}
}
return str;
}
colors2.setTheme = function(theme) {
if (typeof theme === "string") {
console.log("colors.setTheme now only accepts an object, not a string. If you are trying to set a theme from a file, it is now your (the caller's) responsibility to require the file. The old syntax looked like colors.setTheme(__dirname + '/../themes/generic-logging.js'); The new syntax looks like colors.setTheme(require(__dirname + '/../themes/generic-logging.js'));");
return;
}
for (var style2 in theme) {
(function(style3) {
colors2[style3] = function(str) {
if (typeof theme[style3] === "object") {
var out = str;
for (var i in theme[style3]) {
out = colors2[theme[style3][i]](out);
}
return out;
}
return colors2[theme[style3]](str);
};
})(style2);
}
};
function init2() {
var ret = {};
Object.keys(styles2).forEach(function(name) {
ret[name] = {
get: function() {
return build([name]);
}
};
});
return ret;
}
var sequencer = function sequencer2(map3, str) {
var exploded = str.split("");
exploded = exploded.map(map3);
return exploded.join("");
};
colors2.trap = requireTrap();
colors2.zalgo = requireZalgo();
colors2.maps = {};
colors2.maps.america = requireAmerica()(colors2);
colors2.maps.zebra = requireZebra()(colors2);
colors2.maps.rainbow = requireRainbow()(colors2);
colors2.maps.random = requireRandom$2()(colors2);
for (var map2 in colors2.maps) {
(function(map3) {
colors2[map3] = function(str) {
return sequencer(colors2.maps[map3], str);
};
})(map2);
}
defineProps(colors2, init2());
})(colors$1);
return colors$1.exports;
}
var hasRequiredSafe;
function requireSafe() {
if (hasRequiredSafe) return safe.exports;
hasRequiredSafe = 1;
(function(module2) {
var colors2 = requireColors();
module2["exports"] = colors2;
})(safe);
return safe.exports;
}
var safeExports = requireSafe();
const colors = /* @__PURE__ */ getDefaultExportFromCjs$1(safeExports);
const version$4 = "2.0.0";
const description = "CLI Tool for splitting a validator key into a predefined threshold of shares via Shamir-Secret-Sharing (SSS), and encrypt them with a set of operator keys.";
const pkg = {
version: version$4,
description
};
var prompts$2 = {};
var kleur;
var hasRequiredKleur;
function requireKleur() {
if (hasRequiredKleur) return kleur;
hasRequiredKleur = 1;
let FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM, isTTY = true;
if (typeof process !== "undefined") {
({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env || {});
isTTY = process.stdout && process.stdout.isTTY;
}
const $ = {
enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== "dumb" && (FORCE_COLOR != null && FORCE_COLOR !== "0" || isTTY),
// modifiers
reset: init2(0, 0),
bold: init2(1, 22),
dim: init2(2, 22),
italic: init2(3, 23),
underline: init2(4, 24),
inverse: init2(7, 27),
hidden: init2(8, 28),
strikethrough: init2(9, 29),
// colors
black: init2(30, 39),
red: init2(31, 39),
green: init2(32, 39),
yellow: init2(33, 39),
blue: init2(34, 39),
magenta: init2(35, 39),
cyan: init2(36, 39),
white: init2(37, 39),
gray: init2(90, 39),
grey: init2(90, 39),
// background colors
bgBlack: init2(40, 49),
bgRed: init2(41, 49),
bgGreen: init2(42, 49),
bgYellow: init2(43, 49),
bgBlue: init2(44, 49),
bgMagenta: init2(45, 49),
bgCyan: init2(46, 49),
bgWhite: init2(47, 49)
};
function run(arr, str) {
let i = 0, tmp, beg = "", end = "";
for (; i < arr.length; i++) {
tmp = arr[i];
beg += tmp.open;
end += tmp.close;
if (!!~str.indexOf(tmp.close)) {
str = str.replace(tmp.rgx, tmp.close + tmp.open);
}
}
return beg + str + end;
}
function chain(has, keys2) {
let ctx = { has, keys: keys2 };
ctx.reset = $.reset.bind(ctx);
ctx.bold = $.bold.bind(ctx);
ctx.dim = $.dim.bind(ctx);
ctx.italic = $.italic.bind(ctx);
ctx.underline = $.underline.bind(ctx);
ctx.inverse = $.inverse.bind(ctx);
ctx.hidden = $.hidden.bind(ctx);
ctx.strikethrough = $.strikethrough.bind(ctx);
ctx.black = $.black.bind(ctx);
ctx.red = $.red.bind(ctx);
ctx.green = $.green.bind(ctx);
ctx.yellow = $.yellow.bind(ctx);
ctx.blue = $.blue.bind(ctx);
ctx.magenta = $.magenta.bind(ctx);
ctx.cyan = $.cyan.bind(ctx);
ctx.white = $.white.bind(ctx);
ctx.gray = $.gray.bind(ctx);
ctx.grey = $.grey.bind(ctx);
ctx.bgBlack = $.bgBlack.bind(ctx);
ctx.bgRed = $.bgRed.bind(ctx);
ctx.bgGreen = $.bgGreen.bind(ctx);
ctx.bgYellow = $.bgYellow.bind(ctx);
ctx.bgBlue = $.bgBlue.bind(ctx);
ctx.bgMagenta = $.bgMagenta.bind(ctx);
ctx.bgCyan = $.bgCyan.bind(ctx);
ctx.bgWhite = $.bgWhite.bind(ctx);
return ctx;
}
function init2(open, close) {
let blk = {
open: `\x1B[${open}m`,
close: `\x1B[${close}m`,
rgx: new RegExp(`\\x1b\\[${close}m`, "g")
};
return function(txt) {
if (this !== void 0 && this.has !== void 0) {
!!~this.has.indexOf(open) || (this.has.push(open), this.keys.push(blk));
return txt === void 0 ? this : $.enabled ? run(this.keys, txt + "") : txt + "";
}
return txt === void 0 ? chain([open], [blk]) : $.enabled ? run([blk], txt + "") : txt + "";
};
}
kleur = $;
return kleur;
}
var action;
var hasRequiredAction;
function requireAction() {
if (hasRequiredAction) return action;
hasRequiredAction = 1;
action = (key, isSelect) => {
if (key.meta && key.name !== "escape") return;
if (key.ctrl) {
if (key.name === "a") return "first";
if (key.name === "c") return "abort";
if (key.name === "d") return "abort";
if (key.name === "e") return "last";
if (key.name === "g") return "reset";
}
if (isSelect) {
if (key.name === "j") return "down";
if (key.name === "k") return "up";
}
if (key.name === "return") return "submit";
if (key.name === "enter") return "submit";
if (key.name === "backspace") return "delete";
if (key.name === "delete") return "deleteForward";
if (key.name === "abort") return "abort";
if (key.name === "escape") return "exit";
if (key.name === "tab") return "next";
if (key.name === "pagedown") return "nextPage";
if (key.name === "pageup") return "prevPage";
if (key.name === "home") return "home";
if (key.name === "end") return "end";
if (key.name === "up") return "up";
if (key.name === "down") return "down";
if (key.name === "right") return "right";
if (key.name === "left") return "left";
return false;
};
return action;
}
var strip;
var hasRequiredStrip;
function requireStrip() {
if (hasRequiredStrip) return strip;
hasRequiredStrip = 1;
strip = (str) => {
const pattern = [
"[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
"(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
].join("|");
const RGX = new RegExp(pattern, "g");
return typeof str === "string" ? str.replace(RGX, "") : str;
};
return strip;
}
var src$1;
var hasRequiredSrc$1;
function requireSrc$1() {
if (hasRequiredSrc$1) return src$1;
hasRequiredSrc$1 = 1;
const ESC = "\x1B";
const CSI = `${ESC}[`;
const beep = "\x07";
const cursor = {
to(x, y) {
if (!y) return `${CSI}${x + 1}G`;
return `${CSI}${y + 1};${x + 1}H`;
},
move(x, y) {
let ret = "";
if (x < 0) ret += `${CSI}${-x}D`;
else if (x > 0) ret += `${CSI}${x}C`;
if (y < 0) ret += `${CSI}${-y}A`;
else if (y > 0) ret += `${CSI}${y}B`;
return ret;
},
up: (count = 1) => `${CSI}${count}A`,
down: (count = 1) => `${CSI}${count}B`,
forward: (count = 1) => `${CSI}${count}C`,
backward: (count = 1) => `${CSI}${count}D`,
nextLine: (count = 1) => `${CSI}E`.repeat(count),
prevLine: (count = 1) => `${CSI}F`.repeat(count),
left: `${CSI}G`,
hide: `${CSI}?25l`,
show: `${CSI}?25h`,
save: `${ESC}7`,
restore: `${ESC}8`
};
const scroll = {
up: (count = 1) => `${CSI}S`.repeat(count),
down: (count = 1) => `${CSI}T`.repeat(count)
};
const erase = {
screen: `${CSI}2J`,
up: (count = 1) => `${CSI}1J`.repeat(count),
down: (count = 1) => `${CSI}J`.repeat(count),
line: `${CSI}2K`,
lineEnd: `${CSI}K`,
lineStart: `${CSI}1K`,
lines(count) {
let clear2 = "";
for (let i = 0; i < count; i++)
clear2 += this.line + (i < count - 1 ? cursor.up() : "");
if (count)
clear2 += cursor.left;
return clear2;
}
};
src$1 = { cursor, scroll, erase, beep };
return src$1;
}
var clear;
var hasRequiredClear;
function requireClear() {
if (hasRequiredClear) return clear;
hasRequiredClear = 1;
const strip2 = requireStrip();
const { erase, cursor } = requireSrc$1();
const width = (str) => [...strip2(str)].length;
clear = function(prompt2, perLine) {
if (!perLine) return erase.line + cursor.to(0);
let rows = 0;
const lines2 = prompt2.split(/\r?\n/);
for (let line of lines2) {
rows += 1 + Math.floor(Math.max(width(line) - 1, 0) / perLine);
}
return erase.lines(rows);
};
return clear;
}
var figures_1;
var hasRequiredFigures;
function requireFigures() {
if (hasRequiredFigures) return figures_1;
hasRequiredFigures = 1;
const main2 = {
arrowUp: "↑",
arrowDown: "↓",
arrowLeft: "←",
arrowRight: "→",
radioOn: "◉",
radioOff: "◯",
tick: "✔",
cross: "✖",
ellipsis: "…",
pointerSmall: "›",
line: "─",
pointer: "❯"
};
const win = {
arrowUp: main2.arrowUp,
arrowDown: main2.arrowDown,
arrowLeft: main2.arrowLeft,
arrowRight: main2.arrowRight,
radioOn: "(*)",
radioOff: "( )",
tick: "√",
cross: "×",
ellipsis: "...",
pointerSmall: "»",
line: "─",
pointer: ">"
};
const figures = process.platform === "win32" ? win : main2;
figures_1 = figures;
return figures_1;
}
var style;
var hasRequiredStyle;
function requireStyle() {
if (hasRequiredStyle) return style;
hasRequiredStyle = 1;
const c = requireKleur();
const figures = requireFigures();
const styles2 = Object.freeze({
password: { scale: 1, render: (input) => "*".repeat(input.length) },
emoji: { scale: 2, render: (input) => "😃".repeat(input.length) },
invisible: { scale: 0, render: (input) => "" },
default: { scale: 1, render: (input) => `${input}` }
});
const render = (type2) => styles2[type2] || styles2.default;
const symbols = Object.freeze({
aborted: c.red(figures.cross),
done: c.green(figures.tick),
exited: c.yellow(figures.cross),
default: c.cyan("?")
});
const symbol = (done, aborted, exited) => aborted ? symbols.aborted : exited ? symbols.exited : done ? symbols.done : symbols.default;
const delimiter = (completing) => c.gray(completing ? figures.ellipsis : figures.pointerSmall);
const item = (expandable, expanded) => c.gray(expandable ? expanded ? figures.pointerSmall : "+" : figures.line);
style = {
styles: styles2,
render,
symbols,
symbol,
delimiter,
item
};
return style;
}
var lines;
var hasRequiredLines;
function requireLines() {
if (hasRequiredLines) return lines;
hasRequiredLines = 1;
const strip2 = requireStrip();
lines = function(msg, perLine) {
let lines2 = String(strip2(msg) || "").split(/\r?\n/);
if (!perLine) return lines2.length;
return lines2.map((l) => Math.ceil(l.length / perLine)).reduce((a, b) => a + b);
};
return lines;
}
var wrap;
var hasRequiredWrap;
function requireWrap() {
if (hasRequiredWrap) return wrap;
hasRequiredWrap = 1;
wrap = (msg, opts = {}) => {
const tab = Number.isSafeInteger(parseInt(opts.margin)) ? new Array(parseInt(opts.margin)).fill(" ").join("") : opts.margin || "";
const width = opts.width;
return (msg || "").split(/\r?\n/g).map((line) => line.split(/\s+/g).reduce((arr, w) => {
if (w.length + tab.length >= width || arr[arr.length - 1].length + w.length + 1 < width)
arr[arr.length - 1] += ` ${w}`;
else arr.push(`${tab}${w}`);
return arr;
}, [tab]).join("\n")).join("\n");
};
return wrap;
}
var entriesToDisplay;
var hasRequiredEntriesToDisplay;
function requireEntriesToDisplay() {
if (hasRequiredEntriesToDisplay) return entriesToDisplay;
hasRequiredEntriesToDisplay = 1;
entriesToDisplay = (cursor, total, maxVisible) => {
maxVisible = maxVisible || total;
let startIndex = Math.min(total - maxVisible, cursor - Math.floor(maxVisible / 2));
if (startIndex < 0) startIndex = 0;
let endIndex = Math.min(startIndex + maxVisible, total);
return { startIndex, endIndex };
};
return entriesToDisplay;
}
var util$5;
var hasRequiredUtil$2;
function requireUtil$2() {
if (hasRequiredUtil$2) return util$5;
hasRequiredUtil$2 = 1;
util$5 = {
action: requireAction(),
clear: requireClear(),
style: requireStyle(),
strip: requireStrip(),
figures: requireFigures(),
lines: requireLines(),
wrap: requireWrap(),
entriesToDisplay: requireEntriesToDisplay()
};
return util$5;
}
var events = { exports: {} };
var hasRequiredEvents;
function requireEvents() {
if (hasRequiredEvents) return events.exports;
hasRequiredEvents = 1;
var R = typeof Reflect === "object" ? Reflect : null;
var ReflectApply = R && typeof R.apply === "function" ? R.apply : function ReflectApply2(target, receiver, args) {
return Function.prototype.apply.call(target, receiver, args);
};
var ReflectOwnKeys;
if (R && typeof R.ownKeys === "function") {
ReflectOwnKeys = R.ownKeys;
} else if (Object.getOwnPropertySymbols) {
ReflectOwnKeys = function ReflectOwnKeys2(target) {
return Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target));
};
} else {
ReflectOwnKeys = function ReflectOwnKeys2(target) {
return Object.getOwnPropertyNames(target);
};
}
function ProcessEmitWarning(warning) {
if (console && console.warn) console.warn(warning);
}
var NumberIsNaN = Number.isNaN || function NumberIsNaN2(value) {
return value !== value;
};
function EventEmitter() {
EventEmitter.init.call(this);
}
events.exports = EventEmitter;
events.exports.once = once;
EventEmitter.EventEmitter = EventEmitter;
EventEmitter.prototype._events = void 0;
EventEmitter.prototype._eventsCount = 0;
EventEmitter.prototype._maxListeners = void 0;
var defaultMaxListeners = 10;
function checkListener(listener) {
if (typeof listener !== "function") {
throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
}
}
Object.defineProperty(EventEmitter, "defaultMaxListeners", {
enumerable: true,
get: function() {
return defaultMaxListeners;
},
set: function(arg) {
if (typeof arg !== "number" || arg < 0 || NumberIsNaN(arg)) {
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + ".");
}
defaultMaxListeners = arg;
}
});
EventEmitter.init = function() {
if (this._events === void 0 || this._events === Object.getPrototypeOf(this)._events) {
this._events = /* @__PURE__ */ Object.create(null);
this._eventsCount = 0;
}
this._maxListeners = this._maxListeners || void 0;
};
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
if (typeof n !== "number" || n < 0 || NumberIsNaN(n)) {
throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + ".");
}
this._maxListeners = n;
return this;
};
function _getMaxListeners(that) {
if (that._maxListeners === void 0)
return EventEmitter.defaultMaxListeners;
return that._maxListeners;
}
EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
return _getMaxListeners(this);
};
EventEmitter.prototype.emit = function emit(type2) {
var args = [];
for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);
var doError = type2 === "error";
var events2 = this._events;
if (events2 !== void 0)
doError = doError && events2.error === void 0;
else if (!doError)
return false;
if (doError) {
var er;
if (args.length > 0)
er = args[0];
if (er instanceof Error) {
throw er;
}
var err = new Error("Unhandled error." + (er ? " (" + er.message + ")" : ""));
err.context = er;
throw err;
}
var handler = events2[type2];
if (handler === void 0)
return false;
if (typeof handler === "function") {
ReflectApply(handler, this, args);
} else {
var len = handler.length;
var listeners = arrayClone(handler, len);
for (var i = 0; i < len; ++i)
ReflectApply(listeners[i], this, args);
}
return true;
};
function _addListener(target, type2, listener, prepend) {
var m;
var events2;
var existing;
checkListener(listener);
events2 = target._events;
if (events2 === void 0) {
events2 = target._events = /* @__PURE__ */ Object.create(null);
target._eventsCount = 0;
} else {
if (events2.newListener !== void 0) {
target.emit(
"newListener",
type2,
listener.listener ? listener.listener : listener
);
events2 = target._events;
}
existing = events2[type2];
}
if (existing === void 0) {
existing = events2[type2] = listener;
++target._eventsCount;
} else {
if (typeof existing === "function") {
existing = events2[type2] = prepend ? [listener, existing] : [existing, listener];
} else if (prepend) {
existing.unshift(listener);
} else {
existing.push(listener);
}
m = _getMaxListeners(target);
if (m > 0 && existing.length > m && !existing.warned) {
existing.warned = true;
var w = new Error("Possible EventEmitter memory leak detected. " + existing.length + " " + String(type2) + " listeners added. Use emitter.setMaxListeners() to increase limit");
w.name = "MaxListenersExceededWarning";
w.emitter = target;
w.type = type2;
w.count = existing.length;
ProcessEmitWarning(w);
}
}
return target;
}
EventEmitter.prototype.addListener = function addListener(type2, listener) {
return _addListener(this, type2, listener, false);
};
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
EventEmitter.prototype.prependListener = function prependListener(type2, listener) {
return _addListener(this, type2, listener, true);
};
function onceWrapper() {
if (!this.fired) {
this.target.removeListener(this.type, this.wrapFn);
this.fired = true;
if (arguments.length === 0)
return this.listener.call(this.target);
return this.listener.apply(this.target, arguments);
}
}
function _onceWrap(target, type2, listener) {
var state = { fired: false, wrapFn: void 0, target, type: type2, listener };
var wrapped = onceWrapper.bind(state);
wrapped.listener = listener;
state.wrapFn = wrapped;
return wrapped;
}
EventEmitter.prototype.once = function once2(type2, listener) {
checkListener(listener);
this.on(type2, _onceWrap(this, type2, listener));
return this;
};
EventEmitter.prototype.prependOnceListener = function prependOnceListener(type2, listener) {
checkListener(listener);
this.prependListener(type2, _onceWrap(this, type2, listener));
return this;
};
EventEmitter.prototype.removeListener = function removeListener(type2, listener) {
var list, events2, position, i, originalListener;
checkListener(listener);
events2 = this._events;
if (events2 === void 0)
return this;
list = events2[type2];
if (list === void 0)
return this;
if (list === listener || list.listener === listener) {
if (--this._eventsCount === 0)
this._events = /* @__PURE__ */ Object.create(null);
else {
delete events2[type2];
if (events2.removeListener)
this.emit("removeListener", type2, list.listener || listener);
}
} else if (typeof list !== "function") {
position = -1;
for (i = list.length - 1; i >= 0; i--) {
if (list[i] === listener || list[i].listener === listener) {
originalListener = list[i].listener;
position = i;
break;
}
}
if (position < 0)
return this;
if (position === 0)
list.shift();
else {
spliceOne(list, position);
}
if (list.length === 1)
events2[type2] = list[0];
if (events2.removeListener !== void 0)
this.emit("removeListener", type2, originalListener || listener);
}
return this;
};
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
EventEmitter.prototype.removeAllListeners = function removeAllListeners(type2) {
var listeners, events2, i;
events2 = this._events;
if (events2 === void 0)
return this;
if (events2.removeListener === void 0) {
if (arguments.length === 0) {
this._events = /* @__PURE__ */ Object.create(null);
this._eventsCount = 0;
} else if (events2[type2] !== void 0) {
if (--this._eventsCount === 0)
this._events = /* @__PURE__ */ Object.create(null);
else
delete events2[type2];
}
return this;
}
if (arguments.length === 0) {
var keys2 = Object.keys(events2);
var key;
for (i = 0; i < keys2.length; ++i) {
key = keys2[i];
if (key === "removeListener") continue;
this.removeAllListeners(key);
}
this.removeAllListeners("removeListener");
this._events = /* @__PURE__ */ Object.create(null);
this._eventsCount = 0;
return this;
}
listeners = events2[type2];
if (typeof listeners === "function") {
this.removeListener(type2, listeners);
} else if (listeners !== void 0) {
for (i = listeners.length - 1; i >= 0; i--) {
this.removeListener(type2, listeners[i]);
}
}
return this;
};
function _listeners(target, type2, unwrap) {
var events2 = target._events;
if (events2 === void 0)
return [];
var evlistener = events2[type2];
if (evlistener === void 0)
return [];
if (typeof evlistener === "function")
return unwrap ? [evlistener.listener || evlistener] : [evlistener];
return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
}
EventEmitter.prototype.listeners = function listeners(type2) {
return _listeners(this, type2, true);
};
EventEmitter.prototype.rawListeners = function rawListeners(type2) {
return _listeners(this, type2, false);
};
EventEmitter.listenerCount = function(emitter, type2) {
if (typeof emitter.listenerCount === "function") {
return emitter.listenerCount(type2);
} else {
return listenerCount.call(emitter, type2);
}
};
EventEmitter.prototype.listenerCount = listenerCount;
function listenerCount(type2) {
var events2 = this._events;
if (events2 !== void 0) {
var evlistener = events2[type2];
if (typeof evlistener === "function") {
return 1;
} else if (evlistener !== void 0) {
return evlistener.length;
}
}
return 0;
}
EventEmitter.prototype.eventNames = function eventNames() {
return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
};
function arrayClone(arr, n) {
var copy = new Array(n);
for (var i = 0; i < n; ++i)
copy[i] = arr[i];
return copy;
}
function spliceOne(list, index) {
for (; index + 1 < list.length; index++)
list[index] = list[index + 1];
list.pop();
}
function unwrapListeners(arr) {
var ret = new Array(arr.length);
for (var i = 0; i < ret.length; ++i) {
ret[i] = arr[i].listener || arr[i];
}
return ret;
}
function once(emitter, name) {
return new Promise(function(resolve, reject) {
function errorListener(err) {
emitter.removeListener(name, resolver);
reject(err);
}
function resolver() {
if (typeof emitter.removeListener === "function") {
emitter.removeListener("error", errorListener);
}
resolve([].slice.call(arguments));
}
eventTargetAgnosticAddListener(emitter, name, resolver, { once: true });
if (name !== "error") {
addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true });
}
});
}
function addErrorHandlerIfEventEmitter(emitter, handler, flags) {
if (typeof emitter.on === "function") {
eventTargetAgnosticAddListener(emitter, "error", handler, flags);
}
}
function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
if (typeof emitter.on === "function") {
if (flags.once) {
emitter.once(name, listener);
} else {
emitter.on(name, listener);
}
} else if (typeof emitter.addEventListener === "function") {
emitter.addEventListener(name, function wrapListener(arg) {
if (flags.once) {
emitter.removeEventListener(name, wrapListener);
}
listener(arg);
});
} else {
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter);
}
}
return events.exports;
}
var prompt;
var hasRequiredPrompt;
function requirePrompt() {
if (hasRequiredPrompt) return prompt;
hasRequiredPrompt = 1;
const readline = require$$0$2;
const { action: action2 } = requireUtil$2();
const EventEmitter = requireEvents();
const { beep, cursor } = requireSrc$1();
const color = requireKleur();
class Prompt extends EventEmitter {
constructor(opts = {}) {
super();
this.firstRender = true;
this.in = opts.stdin || process.stdin;
this.out = opts.stdout || process.stdout;
this.onRender = (opts.onRender || (() => void 0)).bind(this);
const rl = readline.createInterface({ input: this.in, escapeCodeTimeout: 50 });
readline.emitKeypressEvents(this.in, rl);
if (this.in.isTTY) this.in.setRawMode(true);
const isSelect = ["SelectPrompt", "MultiselectPrompt"].indexOf(this.constructor.name) > -1;
const keypress = (str, key) => {
let a = action2(key, isSelect);
if (a === false) {
this._ && this._(str, key);
} else if (typeof this[a] === "function") {
this[a](key);
} else {
this.bell();
}
};
this.close = () => {
this.out.write(cursor.show);
this.in.removeListener("keypress", keypress);
if (this.in.isTTY) this.in.setRawMode(false);
rl.close();
this.emit(this.aborted ? "abort" : this.exited ? "exit" : "submit", this.value);
this.closed = true;
};
this.in.on("keypress", keypress);
}
fire() {
this.emit("state", {
value: this.value,
aborted: !!this.aborted,
exited: !!this.exited
});
}
bell() {
this.out.write(beep);
}
render() {
this.onRender(color);
if (this.firstRender) this.firstRender = false;
}
}
prompt = Prompt;
return prompt;
}
var text;
var hasRequiredText;
function requireText() {
if (hasRequiredText) return text;
hasRequiredText = 1;
const color = requireKleur();
const Prompt = requirePrompt();
const { erase, cursor } = requireSrc$1();
const { style: style2, clear: clear2, lines: lines2, figures } = requireUtil$2();
class TextPrompt extends Prompt {
constructor(opts = {}) {
super(opts);
this.transform = style2.render(opts.style);
this.scale = this.transform.scale;
this.msg = opts.message;
this.initial = opts.initial || ``;
this.validator = opts.validate || (() => true);
this.value = ``;
this.errorMsg = opts.error || `Please Enter A Valid Value`;
this.cursor = Number(!!this.initial);
this.cursorOffset = 0;
this.clear = clear2(``, this.out.columns);
this.render();
}
set value(v) {
if (!v && this.initial) {
this.placeholder = true;
this.rendered = color.gray(this.transform.render(this.initial));
} else {
this.placeholder = false;
this.rendered = this.transform.render(v);
}
this._value = v;
this.fire();
}
get value() {
return this._value;
}
reset() {
this.value = ``;
this.cursor = Number(!!this.initial);
this.cursorOffset = 0;
this.fire();
this.render();
}
exit() {
this.abort();
}
abort() {
this.value = this.value || this.initial;
this.done = this.aborted = true;
this.error = false;
this.red = false;
this.fire();
this.render();
this.out.write("\n");
this.close();
}
async validate() {
let valid2 = await this.validator(this.value);
if (typeof valid2 === `string`) {
this.errorMsg = valid2;
valid2 = false;
}
this.error = !valid2;
}
async submit() {
this.value = this.value || this.initial;
this.cursorOffset = 0;
this.cursor = this.rendered.length;
await this.validate();
if (this.error) {
this.red = true;
this.fire();
this.render();
return;
}
this.done = true;
this.aborted = false;
this.fire();
this.render();
this.out.write("\n");
this.close();
}
next() {
if (!this.placeholder) return this.bell();
this.value = this.initial;
this.cursor = this.rendered.length;
this.fire();
this.render();
}
moveCursor(n) {
if (this.placeholder) return;
this.cursor = this.cursor + n;
this.cursorOffset += n;
}
_(c, key) {
let s1 = this.value.slice(0, this.cursor);
let s2 = this.value.slice(this.cursor);
this.value = `${s1}${c}${s2}`;
this.red = false;
this.cursor = this.placeholder ? 0 : s1.length + 1;
this.render();
}
delete() {
if (this.isCursorAtStart()) return this.bell();
let s1 = this.value.slice(0, this.cursor - 1);
let s2 = this.value.slice(this.cursor);
this.value = `${s1}${s2}`;
this.red = false;
if (this.isCursorAtStart()) {
this.cursorOffset = 0;
} else {
this.cursorOffset++;
this.moveCursor(-1);
}
this.render();
}
deleteForward() {
if (this.cursor * this.scale >= this.rendered.length || this.placeholder) return this.bell();
let s1 = this.value.slice(0, this.cursor);
let s2 = this.value.slice(this.cursor + 1);
this.value = `${s1}${s2}`;
this.red = false;
if (this.isCursorAtEnd()) {
this.cursorOffset = 0;
} else {
this.cursorOffset++;
}
this.render();
}
first() {
this.cursor = 0;
this.render();
}
last() {
this.cursor = this.value.length;
this.render();
}
left() {
if (this.cursor <= 0 || this.placeholder) return this.bell();
this.moveCursor(-1);
this.render();
}
right() {
if (this.cursor * this.scale >= this.rendered.length || this.placeholder) return this.bell();
this.moveCursor(1);
this.render();
}
isCursorAtStart() {
return this.cursor === 0 || this.placeholder && this.cursor === 1;
}
isCursorAtEnd() {
return this.cursor === this.rendered.length || this.placeholder && this.cursor === this.rendered.length + 1;
}
render() {
if (this.closed) return;
if (!this.firstRender) {
if (this.outputError)
this.out.write(cursor.down(lines2(this.outputError, this.out.columns) - 1) + clear2(this.outputError, this.out.columns));
this.out.write(clear2(this.outputText, this.out.columns));
}
super.render();
this.outputError = "";
this.outputText = [
style2.symbol(this.done, this.aborted),
color.bold(this.msg),
style2.delimiter(this.done),
this.red ? color.red(this.rendered) : this.rendered
].join(` `);
if (this.error) {
this.outputError += this.errorMsg.split(`
`).reduce((a, l, i) => a + `
${i ? " " : figures.pointerSmall} ${color.red().italic