Created
August 14, 2023 11:50
-
-
Save bellbind/3890edd52277693241866aa367ebe73f to your computer and use it in GitHub Desktop.
[helia] embedding tracing lines for https://gist.github.com/bellbind/5565c22255ae87a3c8e9948b467ee894
This file has been truncated, but you can view the full file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 __esm = (fn, res) => function __init() { | |
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res; | |
}; | |
var __commonJS = (cb, mod5) => function __require2() { | |
return mod5 || (0, cb[__getOwnPropNames(cb)[0]])((mod5 = { exports: {} }).exports, mod5), mod5.exports; | |
}; | |
var __export = (target, all3) => { | |
for (var name8 in all3) | |
__defProp(target, name8, { get: all3[name8], enumerable: true }); | |
}; | |
var __copyProps = (to, from17, except, desc) => { | |
if (from17 && typeof from17 === "object" || typeof from17 === "function") { | |
for (let key of __getOwnPropNames(from17)) | |
if (!__hasOwnProp.call(to, key) && key !== except) | |
__defProp(to, key, { get: () => from17[key], enumerable: !(desc = __getOwnPropDesc(from17, key)) || desc.enumerable }); | |
} | |
return to; | |
}; | |
var __toESM = (mod5, isNodeMode, target) => (target = mod5 != null ? __create(__getProtoOf(mod5)) : {}, __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 || !mod5 || !mod5.__esModule ? __defProp(target, "default", { value: mod5, enumerable: true }) : target, | |
mod5 | |
)); | |
var __toCommonJS = (mod5) => __copyProps(__defProp({}, "__esModule", { value: true }), mod5); | |
// node_modules/ms/index.js | |
var require_ms = __commonJS({ | |
"node_modules/ms/index.js"(exports2, module2) { | |
var s = 1e3; | |
var m = s * 60; | |
var h = m * 60; | |
var d = h * 24; | |
var w = d * 7; | |
var y = d * 365.25; | |
module2.exports = function(val, options) { | |
options = options || {}; | |
var type = typeof val; | |
if (type === "string" && val.length > 0) { | |
return parse2(val); | |
} else if (type === "number" && isFinite(val)) { | |
return options.long ? fmtLong(val) : fmtShort(val); | |
} | |
throw new Error( | |
"val is not a non-empty string or a valid number. val=" + JSON.stringify(val) | |
); | |
}; | |
function parse2(str) { | |
str = String(str); | |
if (str.length > 100) { | |
return; | |
} | |
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( | |
str | |
); | |
if (!match) { | |
return; | |
} | |
var n = parseFloat(match[1]); | |
var type = (match[2] || "ms").toLowerCase(); | |
switch (type) { | |
case "years": | |
case "year": | |
case "yrs": | |
case "yr": | |
case "y": | |
return n * y; | |
case "weeks": | |
case "week": | |
case "w": | |
return n * w; | |
case "days": | |
case "day": | |
case "d": | |
return n * d; | |
case "hours": | |
case "hour": | |
case "hrs": | |
case "hr": | |
case "h": | |
return n * h; | |
case "minutes": | |
case "minute": | |
case "mins": | |
case "min": | |
case "m": | |
return n * m; | |
case "seconds": | |
case "second": | |
case "secs": | |
case "sec": | |
case "s": | |
return n * s; | |
case "milliseconds": | |
case "millisecond": | |
case "msecs": | |
case "msec": | |
case "ms": | |
return n; | |
default: | |
return void 0; | |
} | |
} | |
function fmtShort(ms) { | |
var msAbs = Math.abs(ms); | |
if (msAbs >= d) { | |
return Math.round(ms / d) + "d"; | |
} | |
if (msAbs >= h) { | |
return Math.round(ms / h) + "h"; | |
} | |
if (msAbs >= m) { | |
return Math.round(ms / m) + "m"; | |
} | |
if (msAbs >= s) { | |
return Math.round(ms / s) + "s"; | |
} | |
return ms + "ms"; | |
} | |
function fmtLong(ms) { | |
var msAbs = Math.abs(ms); | |
if (msAbs >= d) { | |
return plural(ms, msAbs, d, "day"); | |
} | |
if (msAbs >= h) { | |
return plural(ms, msAbs, h, "hour"); | |
} | |
if (msAbs >= m) { | |
return plural(ms, msAbs, m, "minute"); | |
} | |
if (msAbs >= s) { | |
return plural(ms, msAbs, s, "second"); | |
} | |
return ms + " ms"; | |
} | |
function plural(ms, msAbs, n, name8) { | |
var isPlural = msAbs >= n * 1.5; | |
return Math.round(ms / n) + " " + name8 + (isPlural ? "s" : ""); | |
} | |
} | |
}); | |
// node_modules/debug/src/common.js | |
var require_common = __commonJS({ | |
"node_modules/debug/src/common.js"(exports2, module2) { | |
function setup(env) { | |
createDebug.debug = createDebug; | |
createDebug.default = createDebug; | |
createDebug.coerce = coerce11; | |
createDebug.disable = disable; | |
createDebug.enable = enable; | |
createDebug.enabled = enabled; | |
createDebug.humanize = require_ms(); | |
createDebug.destroy = destroy; | |
Object.keys(env).forEach((key) => { | |
createDebug[key] = env[key]; | |
}); | |
createDebug.names = []; | |
createDebug.skips = []; | |
createDebug.formatters = {}; | |
function selectColor(namespace) { | |
let hash3 = 0; | |
for (let i = 0; i < namespace.length; i++) { | |
hash3 = (hash3 << 5) - hash3 + namespace.charCodeAt(i); | |
hash3 |= 0; | |
} | |
return createDebug.colors[Math.abs(hash3) % createDebug.colors.length]; | |
} | |
createDebug.selectColor = selectColor; | |
function createDebug(namespace) { | |
let prevTime; | |
let enableOverride = null; | |
let namespacesCache; | |
let enabledCache; | |
function debug5(...args) { | |
if (!debug5.enabled) { | |
return; | |
} | |
const self2 = debug5; | |
const curr = Number(/* @__PURE__ */ new Date()); | |
const ms = curr - (prevTime || curr); | |
self2.diff = ms; | |
self2.prev = prevTime; | |
self2.curr = curr; | |
prevTime = curr; | |
args[0] = createDebug.coerce(args[0]); | |
if (typeof args[0] !== "string") { | |
args.unshift("%O"); | |
} | |
let index = 0; | |
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format9) => { | |
if (match === "%%") { | |
return "%"; | |
} | |
index++; | |
const formatter = createDebug.formatters[format9]; | |
if (typeof formatter === "function") { | |
const val = args[index]; | |
match = formatter.call(self2, val); | |
args.splice(index, 1); | |
index--; | |
} | |
return match; | |
}); | |
createDebug.formatArgs.call(self2, args); | |
const logFn = self2.log || createDebug.log; | |
logFn.apply(self2, args); | |
} | |
debug5.namespace = namespace; | |
debug5.useColors = createDebug.useColors(); | |
debug5.color = createDebug.selectColor(namespace); | |
debug5.extend = extend; | |
debug5.destroy = createDebug.destroy; | |
Object.defineProperty(debug5, "enabled", { | |
enumerable: true, | |
configurable: false, | |
get: () => { | |
if (enableOverride !== null) { | |
return enableOverride; | |
} | |
if (namespacesCache !== createDebug.namespaces) { | |
namespacesCache = createDebug.namespaces; | |
enabledCache = createDebug.enabled(namespace); | |
} | |
return enabledCache; | |
}, | |
set: (v) => { | |
enableOverride = v; | |
} | |
}); | |
if (typeof createDebug.init === "function") { | |
createDebug.init(debug5); | |
} | |
return debug5; | |
} | |
function extend(namespace, delimiter) { | |
const newDebug = createDebug(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace); | |
newDebug.log = this.log; | |
return newDebug; | |
} | |
function enable(namespaces) { | |
createDebug.save(namespaces); | |
createDebug.namespaces = namespaces; | |
createDebug.names = []; | |
createDebug.skips = []; | |
let i; | |
const split2 = (typeof namespaces === "string" ? namespaces : "").split(/[\s,]+/); | |
const len = split2.length; | |
for (i = 0; i < len; i++) { | |
if (!split2[i]) { | |
continue; | |
} | |
namespaces = split2[i].replace(/\*/g, ".*?"); | |
if (namespaces[0] === "-") { | |
createDebug.skips.push(new RegExp("^" + namespaces.slice(1) + "$")); | |
} else { | |
createDebug.names.push(new RegExp("^" + namespaces + "$")); | |
} | |
} | |
} | |
function disable() { | |
const namespaces = [ | |
...createDebug.names.map(toNamespace), | |
...createDebug.skips.map(toNamespace).map((namespace) => "-" + namespace) | |
].join(","); | |
createDebug.enable(""); | |
return namespaces; | |
} | |
function enabled(name8) { | |
if (name8[name8.length - 1] === "*") { | |
return true; | |
} | |
let i; | |
let len; | |
for (i = 0, len = createDebug.skips.length; i < len; i++) { | |
if (createDebug.skips[i].test(name8)) { | |
return false; | |
} | |
} | |
for (i = 0, len = createDebug.names.length; i < len; i++) { | |
if (createDebug.names[i].test(name8)) { | |
return true; | |
} | |
} | |
return false; | |
} | |
function toNamespace(regexp) { | |
return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, "*"); | |
} | |
function coerce11(val) { | |
if (val instanceof Error) { | |
return val.stack || val.message; | |
} | |
return val; | |
} | |
function destroy() { | |
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."); | |
} | |
createDebug.enable(createDebug.load()); | |
return createDebug; | |
} | |
module2.exports = setup; | |
} | |
}); | |
// node_modules/debug/src/browser.js | |
var require_browser = __commonJS({ | |
"node_modules/debug/src/browser.js"(exports2, module2) { | |
exports2.formatArgs = formatArgs; | |
exports2.save = save; | |
exports2.load = load; | |
exports2.useColors = useColors; | |
exports2.storage = localstorage(); | |
exports2.destroy = (() => { | |
let warned = false; | |
return () => { | |
if (!warned) { | |
warned = true; | |
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."); | |
} | |
}; | |
})(); | |
exports2.colors = [ | |
"#0000CC", | |
"#0000FF", | |
"#0033CC", | |
"#0033FF", | |
"#0066CC", | |
"#0066FF", | |
"#0099CC", | |
"#0099FF", | |
"#00CC00", | |
"#00CC33", | |
"#00CC66", | |
"#00CC99", | |
"#00CCCC", | |
"#00CCFF", | |
"#3300CC", | |
"#3300FF", | |
"#3333CC", | |
"#3333FF", | |
"#3366CC", | |
"#3366FF", | |
"#3399CC", | |
"#3399FF", | |
"#33CC00", | |
"#33CC33", | |
"#33CC66", | |
"#33CC99", | |
"#33CCCC", | |
"#33CCFF", | |
"#6600CC", | |
"#6600FF", | |
"#6633CC", | |
"#6633FF", | |
"#66CC00", | |
"#66CC33", | |
"#9900CC", | |
"#9900FF", | |
"#9933CC", | |
"#9933FF", | |
"#99CC00", | |
"#99CC33", | |
"#CC0000", | |
"#CC0033", | |
"#CC0066", | |
"#CC0099", | |
"#CC00CC", | |
"#CC00FF", | |
"#CC3300", | |
"#CC3333", | |
"#CC3366", | |
"#CC3399", | |
"#CC33CC", | |
"#CC33FF", | |
"#CC6600", | |
"#CC6633", | |
"#CC9900", | |
"#CC9933", | |
"#CCCC00", | |
"#CCCC33", | |
"#FF0000", | |
"#FF0033", | |
"#FF0066", | |
"#FF0099", | |
"#FF00CC", | |
"#FF00FF", | |
"#FF3300", | |
"#FF3333", | |
"#FF3366", | |
"#FF3399", | |
"#FF33CC", | |
"#FF33FF", | |
"#FF6600", | |
"#FF6633", | |
"#FF9900", | |
"#FF9933", | |
"#FFCC00", | |
"#FFCC33" | |
]; | |
function useColors() { | |
if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) { | |
return true; | |
} | |
if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) { | |
return false; | |
} | |
return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773 | |
typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31? | |
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages | |
typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker | |
typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/); | |
} | |
function formatArgs(args) { | |
args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module2.exports.humanize(this.diff); | |
if (!this.useColors) { | |
return; | |
} | |
const c = "color: " + this.color; | |
args.splice(1, 0, c, "color: inherit"); | |
let index = 0; | |
let lastC = 0; | |
args[0].replace(/%[a-zA-Z%]/g, (match) => { | |
if (match === "%%") { | |
return; | |
} | |
index++; | |
if (match === "%c") { | |
lastC = index; | |
} | |
}); | |
args.splice(lastC, 0, c); | |
} | |
exports2.log = console.debug || console.log || (() => { | |
}); | |
function save(namespaces) { | |
try { | |
if (namespaces) { | |
exports2.storage.setItem("debug", namespaces); | |
} else { | |
exports2.storage.removeItem("debug"); | |
} | |
} catch (error) { | |
} | |
} | |
function load() { | |
let r; | |
try { | |
r = exports2.storage.getItem("debug"); | |
} catch (error) { | |
} | |
if (!r && typeof process !== "undefined" && "env" in process) { | |
r = process.env.DEBUG; | |
} | |
return r; | |
} | |
function localstorage() { | |
try { | |
return localStorage; | |
} catch (error) { | |
} | |
} | |
module2.exports = require_common()(exports2); | |
var { formatters } = module2.exports; | |
formatters.j = function(v) { | |
try { | |
return JSON.stringify(v); | |
} catch (error) { | |
return "[UnexpectedJSONParseError]: " + error.message; | |
} | |
}; | |
} | |
}); | |
// node_modules/err-code/index.js | |
var require_err_code = __commonJS({ | |
"node_modules/err-code/index.js"(exports2, module2) { | |
"use strict"; | |
function assign(obj, props) { | |
for (const key in props) { | |
Object.defineProperty(obj, key, { | |
value: props[key], | |
enumerable: true, | |
configurable: true | |
}); | |
} | |
return obj; | |
} | |
function createError(err, code9, props) { | |
if (!err || typeof err === "string") { | |
throw new TypeError("Please pass an Error to err-code"); | |
} | |
if (!props) { | |
props = {}; | |
} | |
if (typeof code9 === "object") { | |
props = code9; | |
code9 = ""; | |
} | |
if (code9) { | |
props.code = code9; | |
} | |
try { | |
return assign(err, props); | |
} catch (_) { | |
props.message = err.message; | |
props.stack = err.stack; | |
const ErrClass = function() { | |
}; | |
ErrClass.prototype = Object.create(Object.getPrototypeOf(err)); | |
const output3 = assign(new ErrClass(), props); | |
return output3; | |
} | |
} | |
module2.exports = createError; | |
} | |
}); | |
// node_modules/varint-decoder/node_modules/varint/encode.js | |
var require_encode = __commonJS({ | |
"node_modules/varint-decoder/node_modules/varint/encode.js"(exports2, module2) { | |
module2.exports = encode39; | |
var MSB11 = 128; | |
var REST11 = 127; | |
var MSBALL10 = ~REST11; | |
var INT10 = Math.pow(2, 31); | |
function encode39(num, out, offset) { | |
out = out || []; | |
offset = offset || 0; | |
var oldOffset = offset; | |
while (num >= INT10) { | |
out[offset++] = num & 255 | MSB11; | |
num /= 128; | |
} | |
while (num & MSBALL10) { | |
out[offset++] = num & 255 | MSB11; | |
num >>>= 7; | |
} | |
out[offset] = num | 0; | |
encode39.bytes = offset - oldOffset + 1; | |
return out; | |
} | |
} | |
}); | |
// node_modules/varint-decoder/node_modules/varint/decode.js | |
var require_decode = __commonJS({ | |
"node_modules/varint-decoder/node_modules/varint/decode.js"(exports2, module2) { | |
module2.exports = read11; | |
var MSB11 = 128; | |
var REST11 = 127; | |
function read11(buf3, offset) { | |
var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf3.length; | |
do { | |
if (counter >= l) { | |
read11.bytes = 0; | |
throw new RangeError("Could not decode varint"); | |
} | |
b = buf3[counter++]; | |
res += shift < 28 ? (b & REST11) << shift : (b & REST11) * Math.pow(2, shift); | |
shift += 7; | |
} while (b >= MSB11); | |
read11.bytes = counter - offset; | |
return res; | |
} | |
} | |
}); | |
// node_modules/varint-decoder/node_modules/varint/length.js | |
var require_length = __commonJS({ | |
"node_modules/varint-decoder/node_modules/varint/length.js"(exports2, module2) { | |
var N111 = Math.pow(2, 7); | |
var N211 = Math.pow(2, 14); | |
var N311 = Math.pow(2, 21); | |
var N411 = Math.pow(2, 28); | |
var N511 = Math.pow(2, 35); | |
var N611 = Math.pow(2, 42); | |
var N711 = Math.pow(2, 49); | |
var N811 = Math.pow(2, 56); | |
var N911 = Math.pow(2, 63); | |
module2.exports = function(value) { | |
return value < N111 ? 1 : value < N211 ? 2 : value < N311 ? 3 : value < N411 ? 4 : value < N511 ? 5 : value < N611 ? 6 : value < N711 ? 7 : value < N811 ? 8 : value < N911 ? 9 : 10; | |
}; | |
} | |
}); | |
// node_modules/varint-decoder/node_modules/varint/index.js | |
var require_varint = __commonJS({ | |
"node_modules/varint-decoder/node_modules/varint/index.js"(exports2, module2) { | |
module2.exports = { | |
encode: require_encode(), | |
decode: require_decode(), | |
encodingLength: require_length() | |
}; | |
} | |
}); | |
// node_modules/varint-decoder/src/index.js | |
var require_src = __commonJS({ | |
"node_modules/varint-decoder/src/index.js"(exports2, module2) { | |
"use strict"; | |
var varint15 = require_varint(); | |
module2.exports = (buf3) => { | |
if (!(buf3 instanceof Uint8Array)) { | |
throw new Error("arg needs to be a Uint8Array"); | |
} | |
const result = []; | |
while (buf3.length > 0) { | |
const num = varint15.decode(buf3); | |
result.push(num); | |
buf3 = buf3.slice(varint15.decode.bytes); | |
} | |
return result; | |
}; | |
} | |
}); | |
// node_modules/varint/encode.js | |
var require_encode2 = __commonJS({ | |
"node_modules/varint/encode.js"(exports2, module2) { | |
module2.exports = encode39; | |
var MSB11 = 128; | |
var REST11 = 127; | |
var MSBALL10 = ~REST11; | |
var INT10 = Math.pow(2, 31); | |
function encode39(num, out, offset) { | |
if (Number.MAX_SAFE_INTEGER && num > Number.MAX_SAFE_INTEGER) { | |
encode39.bytes = 0; | |
throw new RangeError("Could not encode varint"); | |
} | |
out = out || []; | |
offset = offset || 0; | |
var oldOffset = offset; | |
while (num >= INT10) { | |
out[offset++] = num & 255 | MSB11; | |
num /= 128; | |
} | |
while (num & MSBALL10) { | |
out[offset++] = num & 255 | MSB11; | |
num >>>= 7; | |
} | |
out[offset] = num | 0; | |
encode39.bytes = offset - oldOffset + 1; | |
return out; | |
} | |
} | |
}); | |
// node_modules/varint/decode.js | |
var require_decode2 = __commonJS({ | |
"node_modules/varint/decode.js"(exports2, module2) { | |
module2.exports = read11; | |
var MSB11 = 128; | |
var REST11 = 127; | |
function read11(buf3, offset) { | |
var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf3.length; | |
do { | |
if (counter >= l || shift > 49) { | |
read11.bytes = 0; | |
throw new RangeError("Could not decode varint"); | |
} | |
b = buf3[counter++]; | |
res += shift < 28 ? (b & REST11) << shift : (b & REST11) * Math.pow(2, shift); | |
shift += 7; | |
} while (b >= MSB11); | |
read11.bytes = counter - offset; | |
return res; | |
} | |
} | |
}); | |
// node_modules/varint/length.js | |
var require_length2 = __commonJS({ | |
"node_modules/varint/length.js"(exports2, module2) { | |
var N111 = Math.pow(2, 7); | |
var N211 = Math.pow(2, 14); | |
var N311 = Math.pow(2, 21); | |
var N411 = Math.pow(2, 28); | |
var N511 = Math.pow(2, 35); | |
var N611 = Math.pow(2, 42); | |
var N711 = Math.pow(2, 49); | |
var N811 = Math.pow(2, 56); | |
var N911 = Math.pow(2, 63); | |
module2.exports = function(value) { | |
return value < N111 ? 1 : value < N211 ? 2 : value < N311 ? 3 : value < N411 ? 4 : value < N511 ? 5 : value < N611 ? 6 : value < N711 ? 7 : value < N811 ? 8 : value < N911 ? 9 : 10; | |
}; | |
} | |
}); | |
// node_modules/varint/index.js | |
var require_varint2 = __commonJS({ | |
"node_modules/varint/index.js"(exports2, module2) { | |
module2.exports = { | |
encode: require_encode2(), | |
decode: require_decode2(), | |
encodingLength: require_length2() | |
}; | |
} | |
}); | |
// node_modules/@protobufjs/aspromise/index.js | |
var require_aspromise = __commonJS({ | |
"node_modules/@protobufjs/aspromise/index.js"(exports2, module2) { | |
"use strict"; | |
module2.exports = asPromise; | |
function asPromise(fn, ctx) { | |
var params = new Array(arguments.length - 1), offset = 0, index = 2, pending = true; | |
while (index < arguments.length) | |
params[offset++] = arguments[index++]; | |
return new Promise(function executor(resolve6, reject) { | |
params[offset] = function callback(err) { | |
if (pending) { | |
pending = false; | |
if (err) | |
reject(err); | |
else { | |
var params2 = new Array(arguments.length - 1), offset2 = 0; | |
while (offset2 < params2.length) | |
params2[offset2++] = arguments[offset2]; | |
resolve6.apply(null, params2); | |
} | |
} | |
}; | |
try { | |
fn.apply(ctx || null, params); | |
} catch (err) { | |
if (pending) { | |
pending = false; | |
reject(err); | |
} | |
} | |
}); | |
} | |
} | |
}); | |
// node_modules/@protobufjs/base64/index.js | |
var require_base64 = __commonJS({ | |
"node_modules/@protobufjs/base64/index.js"(exports2) { | |
"use strict"; | |
var base647 = exports2; | |
base647.length = function length11(string3) { | |
var p = string3.length; | |
if (!p) | |
return 0; | |
var n = 0; | |
while (--p % 4 > 1 && string3.charAt(p) === "=") | |
++n; | |
return Math.ceil(string3.length * 3) / 4 - n; | |
}; | |
var b64 = new Array(64); | |
var s64 = new Array(123); | |
for (i = 0; i < 64; ) | |
s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++; | |
var i; | |
base647.encode = function encode39(buffer3, start, end) { | |
var parts = null, chunk = []; | |
var i2 = 0, j = 0, t; | |
while (start < end) { | |
var b = buffer3[start++]; | |
switch (j) { | |
case 0: | |
chunk[i2++] = b64[b >> 2]; | |
t = (b & 3) << 4; | |
j = 1; | |
break; | |
case 1: | |
chunk[i2++] = b64[t | b >> 4]; | |
t = (b & 15) << 2; | |
j = 2; | |
break; | |
case 2: | |
chunk[i2++] = b64[t | b >> 6]; | |
chunk[i2++] = b64[b & 63]; | |
j = 0; | |
break; | |
} | |
if (i2 > 8191) { | |
(parts || (parts = [])).push(String.fromCharCode.apply(String, chunk)); | |
i2 = 0; | |
} | |
} | |
if (j) { | |
chunk[i2++] = b64[t]; | |
chunk[i2++] = 61; | |
if (j === 1) | |
chunk[i2++] = 61; | |
} | |
if (parts) { | |
if (i2) | |
parts.push(String.fromCharCode.apply(String, chunk.slice(0, i2))); | |
return parts.join(""); | |
} | |
return String.fromCharCode.apply(String, chunk.slice(0, i2)); | |
}; | |
var invalidEncoding = "invalid encoding"; | |
base647.decode = function decode50(string3, buffer3, offset) { | |
var start = offset; | |
var j = 0, t; | |
for (var i2 = 0; i2 < string3.length; ) { | |
var c = string3.charCodeAt(i2++); | |
if (c === 61 && j > 1) | |
break; | |
if ((c = s64[c]) === void 0) | |
throw Error(invalidEncoding); | |
switch (j) { | |
case 0: | |
t = c; | |
j = 1; | |
break; | |
case 1: | |
buffer3[offset++] = t << 2 | (c & 48) >> 4; | |
t = c; | |
j = 2; | |
break; | |
case 2: | |
buffer3[offset++] = (t & 15) << 4 | (c & 60) >> 2; | |
t = c; | |
j = 3; | |
break; | |
case 3: | |
buffer3[offset++] = (t & 3) << 6 | c; | |
j = 0; | |
break; | |
} | |
} | |
if (j === 1) | |
throw Error(invalidEncoding); | |
return offset - start; | |
}; | |
base647.test = function test(string3) { | |
return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string3); | |
}; | |
} | |
}); | |
// node_modules/@protobufjs/eventemitter/index.js | |
var require_eventemitter = __commonJS({ | |
"node_modules/@protobufjs/eventemitter/index.js"(exports2, module2) { | |
"use strict"; | |
module2.exports = EventEmitter6; | |
function EventEmitter6() { | |
this._listeners = {}; | |
} | |
EventEmitter6.prototype.on = function on(evt, fn, ctx) { | |
(this._listeners[evt] || (this._listeners[evt] = [])).push({ | |
fn, | |
ctx: ctx || this | |
}); | |
return this; | |
}; | |
EventEmitter6.prototype.off = function off(evt, fn) { | |
if (evt === void 0) | |
this._listeners = {}; | |
else { | |
if (fn === void 0) | |
this._listeners[evt] = []; | |
else { | |
var listeners = this._listeners[evt]; | |
for (var i = 0; i < listeners.length; ) | |
if (listeners[i].fn === fn) | |
listeners.splice(i, 1); | |
else | |
++i; | |
} | |
} | |
return this; | |
}; | |
EventEmitter6.prototype.emit = function emit(evt) { | |
var listeners = this._listeners[evt]; | |
if (listeners) { | |
var args = [], i = 1; | |
for (; i < arguments.length; ) | |
args.push(arguments[i++]); | |
for (i = 0; i < listeners.length; ) | |
listeners[i].fn.apply(listeners[i++].ctx, args); | |
} | |
return this; | |
}; | |
} | |
}); | |
// node_modules/@protobufjs/float/index.js | |
var require_float = __commonJS({ | |
"node_modules/@protobufjs/float/index.js"(exports2, module2) { | |
"use strict"; | |
module2.exports = factory(factory); | |
function factory(exports3) { | |
if (typeof Float32Array !== "undefined") | |
(function() { | |
var f32 = new Float32Array([-0]), f8b = new Uint8Array(f32.buffer), le = f8b[3] === 128; | |
function writeFloat_f32_cpy(val, buf3, pos) { | |
f32[0] = val; | |
buf3[pos] = f8b[0]; | |
buf3[pos + 1] = f8b[1]; | |
buf3[pos + 2] = f8b[2]; | |
buf3[pos + 3] = f8b[3]; | |
} | |
function writeFloat_f32_rev(val, buf3, pos) { | |
f32[0] = val; | |
buf3[pos] = f8b[3]; | |
buf3[pos + 1] = f8b[2]; | |
buf3[pos + 2] = f8b[1]; | |
buf3[pos + 3] = f8b[0]; | |
} | |
exports3.writeFloatLE = le ? writeFloat_f32_cpy : writeFloat_f32_rev; | |
exports3.writeFloatBE = le ? writeFloat_f32_rev : writeFloat_f32_cpy; | |
function readFloat_f32_cpy(buf3, pos) { | |
f8b[0] = buf3[pos]; | |
f8b[1] = buf3[pos + 1]; | |
f8b[2] = buf3[pos + 2]; | |
f8b[3] = buf3[pos + 3]; | |
return f32[0]; | |
} | |
function readFloat_f32_rev(buf3, pos) { | |
f8b[3] = buf3[pos]; | |
f8b[2] = buf3[pos + 1]; | |
f8b[1] = buf3[pos + 2]; | |
f8b[0] = buf3[pos + 3]; | |
return f32[0]; | |
} | |
exports3.readFloatLE = le ? readFloat_f32_cpy : readFloat_f32_rev; | |
exports3.readFloatBE = le ? readFloat_f32_rev : readFloat_f32_cpy; | |
})(); | |
else | |
(function() { | |
function writeFloat_ieee754(writeUint, val, buf3, pos) { | |
var sign4 = val < 0 ? 1 : 0; | |
if (sign4) | |
val = -val; | |
if (val === 0) | |
writeUint(1 / val > 0 ? ( | |
/* positive */ | |
0 | |
) : ( | |
/* negative 0 */ | |
2147483648 | |
), buf3, pos); | |
else if (isNaN(val)) | |
writeUint(2143289344, buf3, pos); | |
else if (val > 34028234663852886e22) | |
writeUint((sign4 << 31 | 2139095040) >>> 0, buf3, pos); | |
else if (val < 11754943508222875e-54) | |
writeUint((sign4 << 31 | Math.round(val / 1401298464324817e-60)) >>> 0, buf3, pos); | |
else { | |
var exponent = Math.floor(Math.log(val) / Math.LN2), mantissa = Math.round(val * Math.pow(2, -exponent) * 8388608) & 8388607; | |
writeUint((sign4 << 31 | exponent + 127 << 23 | mantissa) >>> 0, buf3, pos); | |
} | |
} | |
exports3.writeFloatLE = writeFloat_ieee754.bind(null, writeUintLE); | |
exports3.writeFloatBE = writeFloat_ieee754.bind(null, writeUintBE); | |
function readFloat_ieee754(readUint, buf3, pos) { | |
var uint = readUint(buf3, pos), sign4 = (uint >> 31) * 2 + 1, exponent = uint >>> 23 & 255, mantissa = uint & 8388607; | |
return exponent === 255 ? mantissa ? NaN : sign4 * Infinity : exponent === 0 ? sign4 * 1401298464324817e-60 * mantissa : sign4 * Math.pow(2, exponent - 150) * (mantissa + 8388608); | |
} | |
exports3.readFloatLE = readFloat_ieee754.bind(null, readUintLE); | |
exports3.readFloatBE = readFloat_ieee754.bind(null, readUintBE); | |
})(); | |
if (typeof Float64Array !== "undefined") | |
(function() { | |
var f64 = new Float64Array([-0]), f8b = new Uint8Array(f64.buffer), le = f8b[7] === 128; | |
function writeDouble_f64_cpy(val, buf3, pos) { | |
f64[0] = val; | |
buf3[pos] = f8b[0]; | |
buf3[pos + 1] = f8b[1]; | |
buf3[pos + 2] = f8b[2]; | |
buf3[pos + 3] = f8b[3]; | |
buf3[pos + 4] = f8b[4]; | |
buf3[pos + 5] = f8b[5]; | |
buf3[pos + 6] = f8b[6]; | |
buf3[pos + 7] = f8b[7]; | |
} | |
function writeDouble_f64_rev(val, buf3, pos) { | |
f64[0] = val; | |
buf3[pos] = f8b[7]; | |
buf3[pos + 1] = f8b[6]; | |
buf3[pos + 2] = f8b[5]; | |
buf3[pos + 3] = f8b[4]; | |
buf3[pos + 4] = f8b[3]; | |
buf3[pos + 5] = f8b[2]; | |
buf3[pos + 6] = f8b[1]; | |
buf3[pos + 7] = f8b[0]; | |
} | |
exports3.writeDoubleLE = le ? writeDouble_f64_cpy : writeDouble_f64_rev; | |
exports3.writeDoubleBE = le ? writeDouble_f64_rev : writeDouble_f64_cpy; | |
function readDouble_f64_cpy(buf3, pos) { | |
f8b[0] = buf3[pos]; | |
f8b[1] = buf3[pos + 1]; | |
f8b[2] = buf3[pos + 2]; | |
f8b[3] = buf3[pos + 3]; | |
f8b[4] = buf3[pos + 4]; | |
f8b[5] = buf3[pos + 5]; | |
f8b[6] = buf3[pos + 6]; | |
f8b[7] = buf3[pos + 7]; | |
return f64[0]; | |
} | |
function readDouble_f64_rev(buf3, pos) { | |
f8b[7] = buf3[pos]; | |
f8b[6] = buf3[pos + 1]; | |
f8b[5] = buf3[pos + 2]; | |
f8b[4] = buf3[pos + 3]; | |
f8b[3] = buf3[pos + 4]; | |
f8b[2] = buf3[pos + 5]; | |
f8b[1] = buf3[pos + 6]; | |
f8b[0] = buf3[pos + 7]; | |
return f64[0]; | |
} | |
exports3.readDoubleLE = le ? readDouble_f64_cpy : readDouble_f64_rev; | |
exports3.readDoubleBE = le ? readDouble_f64_rev : readDouble_f64_cpy; | |
})(); | |
else | |
(function() { | |
function writeDouble_ieee754(writeUint, off0, off1, val, buf3, pos) { | |
var sign4 = val < 0 ? 1 : 0; | |
if (sign4) | |
val = -val; | |
if (val === 0) { | |
writeUint(0, buf3, pos + off0); | |
writeUint(1 / val > 0 ? ( | |
/* positive */ | |
0 | |
) : ( | |
/* negative 0 */ | |
2147483648 | |
), buf3, pos + off1); | |
} else if (isNaN(val)) { | |
writeUint(0, buf3, pos + off0); | |
writeUint(2146959360, buf3, pos + off1); | |
} else if (val > 17976931348623157e292) { | |
writeUint(0, buf3, pos + off0); | |
writeUint((sign4 << 31 | 2146435072) >>> 0, buf3, pos + off1); | |
} else { | |
var mantissa; | |
if (val < 22250738585072014e-324) { | |
mantissa = val / 5e-324; | |
writeUint(mantissa >>> 0, buf3, pos + off0); | |
writeUint((sign4 << 31 | mantissa / 4294967296) >>> 0, buf3, pos + off1); | |
} else { | |
var exponent = Math.floor(Math.log(val) / Math.LN2); | |
if (exponent === 1024) | |
exponent = 1023; | |
mantissa = val * Math.pow(2, -exponent); | |
writeUint(mantissa * 4503599627370496 >>> 0, buf3, pos + off0); | |
writeUint((sign4 << 31 | exponent + 1023 << 20 | mantissa * 1048576 & 1048575) >>> 0, buf3, pos + off1); | |
} | |
} | |
} | |
exports3.writeDoubleLE = writeDouble_ieee754.bind(null, writeUintLE, 0, 4); | |
exports3.writeDoubleBE = writeDouble_ieee754.bind(null, writeUintBE, 4, 0); | |
function readDouble_ieee754(readUint, off0, off1, buf3, pos) { | |
var lo = readUint(buf3, pos + off0), hi = readUint(buf3, pos + off1); | |
var sign4 = (hi >> 31) * 2 + 1, exponent = hi >>> 20 & 2047, mantissa = 4294967296 * (hi & 1048575) + lo; | |
return exponent === 2047 ? mantissa ? NaN : sign4 * Infinity : exponent === 0 ? sign4 * 5e-324 * mantissa : sign4 * Math.pow(2, exponent - 1075) * (mantissa + 4503599627370496); | |
} | |
exports3.readDoubleLE = readDouble_ieee754.bind(null, readUintLE, 0, 4); | |
exports3.readDoubleBE = readDouble_ieee754.bind(null, readUintBE, 4, 0); | |
})(); | |
return exports3; | |
} | |
function writeUintLE(val, buf3, pos) { | |
buf3[pos] = val & 255; | |
buf3[pos + 1] = val >>> 8 & 255; | |
buf3[pos + 2] = val >>> 16 & 255; | |
buf3[pos + 3] = val >>> 24; | |
} | |
function writeUintBE(val, buf3, pos) { | |
buf3[pos] = val >>> 24; | |
buf3[pos + 1] = val >>> 16 & 255; | |
buf3[pos + 2] = val >>> 8 & 255; | |
buf3[pos + 3] = val & 255; | |
} | |
function readUintLE(buf3, pos) { | |
return (buf3[pos] | buf3[pos + 1] << 8 | buf3[pos + 2] << 16 | buf3[pos + 3] << 24) >>> 0; | |
} | |
function readUintBE(buf3, pos) { | |
return (buf3[pos] << 24 | buf3[pos + 1] << 16 | buf3[pos + 2] << 8 | buf3[pos + 3]) >>> 0; | |
} | |
} | |
}); | |
// node_modules/@protobufjs/inquire/index.js | |
var require_inquire = __commonJS({ | |
"node_modules/@protobufjs/inquire/index.js"(exports, module) { | |
"use strict"; | |
module.exports = inquire; | |
function inquire(moduleName) { | |
try { | |
var mod = eval("quire".replace(/^/, "re"))(moduleName); | |
if (mod && (mod.length || Object.keys(mod).length)) | |
return mod; | |
} catch (e) { | |
} | |
return null; | |
} | |
} | |
}); | |
// node_modules/@protobufjs/utf8/index.js | |
var require_utf8 = __commonJS({ | |
"node_modules/@protobufjs/utf8/index.js"(exports2) { | |
"use strict"; | |
var utf8 = exports2; | |
utf8.length = function utf8_length(string3) { | |
var len = 0, c = 0; | |
for (var i = 0; i < string3.length; ++i) { | |
c = string3.charCodeAt(i); | |
if (c < 128) | |
len += 1; | |
else if (c < 2048) | |
len += 2; | |
else if ((c & 64512) === 55296 && (string3.charCodeAt(i + 1) & 64512) === 56320) { | |
++i; | |
len += 4; | |
} else | |
len += 3; | |
} | |
return len; | |
}; | |
utf8.read = function utf8_read(buffer3, start, end) { | |
var len = end - start; | |
if (len < 1) | |
return ""; | |
var parts = null, chunk = [], i = 0, t; | |
while (start < end) { | |
t = buffer3[start++]; | |
if (t < 128) | |
chunk[i++] = t; | |
else if (t > 191 && t < 224) | |
chunk[i++] = (t & 31) << 6 | buffer3[start++] & 63; | |
else if (t > 239 && t < 365) { | |
t = ((t & 7) << 18 | (buffer3[start++] & 63) << 12 | (buffer3[start++] & 63) << 6 | buffer3[start++] & 63) - 65536; | |
chunk[i++] = 55296 + (t >> 10); | |
chunk[i++] = 56320 + (t & 1023); | |
} else | |
chunk[i++] = (t & 15) << 12 | (buffer3[start++] & 63) << 6 | buffer3[start++] & 63; | |
if (i > 8191) { | |
(parts || (parts = [])).push(String.fromCharCode.apply(String, chunk)); | |
i = 0; | |
} | |
} | |
if (parts) { | |
if (i) | |
parts.push(String.fromCharCode.apply(String, chunk.slice(0, i))); | |
return parts.join(""); | |
} | |
return String.fromCharCode.apply(String, chunk.slice(0, i)); | |
}; | |
utf8.write = function utf8_write(string3, buffer3, offset) { | |
var start = offset, c1, c2; | |
for (var i = 0; i < string3.length; ++i) { | |
c1 = string3.charCodeAt(i); | |
if (c1 < 128) { | |
buffer3[offset++] = c1; | |
} else if (c1 < 2048) { | |
buffer3[offset++] = c1 >> 6 | 192; | |
buffer3[offset++] = c1 & 63 | 128; | |
} else if ((c1 & 64512) === 55296 && ((c2 = string3.charCodeAt(i + 1)) & 64512) === 56320) { | |
c1 = 65536 + ((c1 & 1023) << 10) + (c2 & 1023); | |
++i; | |
buffer3[offset++] = c1 >> 18 | 240; | |
buffer3[offset++] = c1 >> 12 & 63 | 128; | |
buffer3[offset++] = c1 >> 6 & 63 | 128; | |
buffer3[offset++] = c1 & 63 | 128; | |
} else { | |
buffer3[offset++] = c1 >> 12 | 224; | |
buffer3[offset++] = c1 >> 6 & 63 | 128; | |
buffer3[offset++] = c1 & 63 | 128; | |
} | |
} | |
return offset - start; | |
}; | |
} | |
}); | |
// node_modules/@protobufjs/pool/index.js | |
var require_pool = __commonJS({ | |
"node_modules/@protobufjs/pool/index.js"(exports2, module2) { | |
"use strict"; | |
module2.exports = pool; | |
function pool(alloc4, slice3, size) { | |
var SIZE = size || 8192; | |
var MAX = SIZE >>> 1; | |
var slab = null; | |
var offset = SIZE; | |
return function pool_alloc(size2) { | |
if (size2 < 1 || size2 > MAX) | |
return alloc4(size2); | |
if (offset + size2 > SIZE) { | |
slab = alloc4(SIZE); | |
offset = 0; | |
} | |
var buf3 = slice3.call(slab, offset, offset += size2); | |
if (offset & 7) | |
offset = (offset | 7) + 1; | |
return buf3; | |
}; | |
} | |
} | |
}); | |
// node_modules/protons-runtime/node_modules/protobufjs/src/util/longbits.js | |
var require_longbits = __commonJS({ | |
"node_modules/protons-runtime/node_modules/protobufjs/src/util/longbits.js"(exports2, module2) { | |
"use strict"; | |
module2.exports = LongBits2; | |
var util2 = require_minimal(); | |
function LongBits2(lo, hi) { | |
this.lo = lo >>> 0; | |
this.hi = hi >>> 0; | |
} | |
var zero = LongBits2.zero = new LongBits2(0, 0); | |
zero.toNumber = function() { | |
return 0; | |
}; | |
zero.zzEncode = zero.zzDecode = function() { | |
return this; | |
}; | |
zero.length = function() { | |
return 1; | |
}; | |
var zeroHash = LongBits2.zeroHash = "\0\0\0\0\0\0\0\0"; | |
LongBits2.fromNumber = function fromNumber(value) { | |
if (value === 0) | |
return zero; | |
var sign4 = value < 0; | |
if (sign4) | |
value = -value; | |
var lo = value >>> 0, hi = (value - lo) / 4294967296 >>> 0; | |
if (sign4) { | |
hi = ~hi >>> 0; | |
lo = ~lo >>> 0; | |
if (++lo > 4294967295) { | |
lo = 0; | |
if (++hi > 4294967295) | |
hi = 0; | |
} | |
} | |
return new LongBits2(lo, hi); | |
}; | |
LongBits2.from = function from17(value) { | |
if (typeof value === "number") | |
return LongBits2.fromNumber(value); | |
if (util2.isString(value)) { | |
if (util2.Long) | |
value = util2.Long.fromString(value); | |
else | |
return LongBits2.fromNumber(parseInt(value, 10)); | |
} | |
return value.low || value.high ? new LongBits2(value.low >>> 0, value.high >>> 0) : zero; | |
}; | |
LongBits2.prototype.toNumber = function toNumber(unsigned2) { | |
if (!unsigned2 && this.hi >>> 31) { | |
var lo = ~this.lo + 1 >>> 0, hi = ~this.hi >>> 0; | |
if (!lo) | |
hi = hi + 1 >>> 0; | |
return -(lo + hi * 4294967296); | |
} | |
return this.lo + this.hi * 4294967296; | |
}; | |
LongBits2.prototype.toLong = function toLong(unsigned2) { | |
return util2.Long ? new util2.Long(this.lo | 0, this.hi | 0, Boolean(unsigned2)) : { low: this.lo | 0, high: this.hi | 0, unsigned: Boolean(unsigned2) }; | |
}; | |
var charCodeAt = String.prototype.charCodeAt; | |
LongBits2.fromHash = function fromHash(hash3) { | |
if (hash3 === zeroHash) | |
return zero; | |
return new LongBits2( | |
(charCodeAt.call(hash3, 0) | charCodeAt.call(hash3, 1) << 8 | charCodeAt.call(hash3, 2) << 16 | charCodeAt.call(hash3, 3) << 24) >>> 0, | |
(charCodeAt.call(hash3, 4) | charCodeAt.call(hash3, 5) << 8 | charCodeAt.call(hash3, 6) << 16 | charCodeAt.call(hash3, 7) << 24) >>> 0 | |
); | |
}; | |
LongBits2.prototype.toHash = function toHash() { | |
return String.fromCharCode( | |
this.lo & 255, | |
this.lo >>> 8 & 255, | |
this.lo >>> 16 & 255, | |
this.lo >>> 24, | |
this.hi & 255, | |
this.hi >>> 8 & 255, | |
this.hi >>> 16 & 255, | |
this.hi >>> 24 | |
); | |
}; | |
LongBits2.prototype.zzEncode = function zzEncode() { | |
var mask = this.hi >> 31; | |
this.hi = ((this.hi << 1 | this.lo >>> 31) ^ mask) >>> 0; | |
this.lo = (this.lo << 1 ^ mask) >>> 0; | |
return this; | |
}; | |
LongBits2.prototype.zzDecode = function zzDecode() { | |
var mask = -(this.lo & 1); | |
this.lo = ((this.lo >>> 1 | this.hi << 31) ^ mask) >>> 0; | |
this.hi = (this.hi >>> 1 ^ mask) >>> 0; | |
return this; | |
}; | |
LongBits2.prototype.length = function length11() { | |
var part0 = this.lo, part1 = (this.lo >>> 28 | this.hi << 4) >>> 0, part2 = this.hi >>> 24; | |
return part2 === 0 ? part1 === 0 ? part0 < 16384 ? part0 < 128 ? 1 : 2 : part0 < 2097152 ? 3 : 4 : part1 < 16384 ? part1 < 128 ? 5 : 6 : part1 < 2097152 ? 7 : 8 : part2 < 128 ? 9 : 10; | |
}; | |
} | |
}); | |
// node_modules/protons-runtime/node_modules/protobufjs/src/util/minimal.js | |
var require_minimal = __commonJS({ | |
"node_modules/protons-runtime/node_modules/protobufjs/src/util/minimal.js"(exports2) { | |
"use strict"; | |
var util2 = exports2; | |
util2.asPromise = require_aspromise(); | |
util2.base64 = require_base64(); | |
util2.EventEmitter = require_eventemitter(); | |
util2.float = require_float(); | |
util2.inquire = require_inquire(); | |
util2.utf8 = require_utf8(); | |
util2.pool = require_pool(); | |
util2.LongBits = require_longbits(); | |
util2.isNode = Boolean(typeof globalThis !== "undefined" && globalThis && globalThis.process && globalThis.process.versions && globalThis.process.versions.node); | |
util2.global = util2.isNode && globalThis || typeof window !== "undefined" && window || typeof self !== "undefined" && self || exports2; | |
util2.emptyArray = Object.freeze ? Object.freeze([]) : ( | |
/* istanbul ignore next */ | |
[] | |
); | |
util2.emptyObject = Object.freeze ? Object.freeze({}) : ( | |
/* istanbul ignore next */ | |
{} | |
); | |
util2.isInteger = Number.isInteger || /* istanbul ignore next */ | |
function isInteger(value) { | |
return typeof value === "number" && isFinite(value) && Math.floor(value) === value; | |
}; | |
util2.isString = function isString(value) { | |
return typeof value === "string" || value instanceof String; | |
}; | |
util2.isObject = function isObject(value) { | |
return value && typeof value === "object"; | |
}; | |
util2.isset = /** | |
* Checks if a property on a message is considered to be present. | |
* @param {Object} obj Plain object or message instance | |
* @param {string} prop Property name | |
* @returns {boolean} `true` if considered to be present, otherwise `false` | |
*/ | |
util2.isSet = function isSet(obj, prop) { | |
var value = obj[prop]; | |
if (value != null && obj.hasOwnProperty(prop)) | |
return typeof value !== "object" || (Array.isArray(value) ? value.length : Object.keys(value).length) > 0; | |
return false; | |
}; | |
util2.Buffer = function() { | |
try { | |
var Buffer2 = util2.inquire("buffer").Buffer; | |
return Buffer2.prototype.utf8Write ? Buffer2 : ( | |
/* istanbul ignore next */ | |
null | |
); | |
} catch (e) { | |
return null; | |
} | |
}(); | |
util2._Buffer_from = null; | |
util2._Buffer_allocUnsafe = null; | |
util2.newBuffer = function newBuffer(sizeOrArray) { | |
return typeof sizeOrArray === "number" ? util2.Buffer ? util2._Buffer_allocUnsafe(sizeOrArray) : new util2.Array(sizeOrArray) : util2.Buffer ? util2._Buffer_from(sizeOrArray) : typeof Uint8Array === "undefined" ? sizeOrArray : new Uint8Array(sizeOrArray); | |
}; | |
util2.Array = typeof Uint8Array !== "undefined" ? Uint8Array : Array; | |
util2.Long = /* istanbul ignore next */ | |
util2.global.dcodeIO && /* istanbul ignore next */ | |
util2.global.dcodeIO.Long || /* istanbul ignore next */ | |
util2.global.Long || util2.inquire("long"); | |
util2.key2Re = /^true|false|0|1$/; | |
util2.key32Re = /^-?(?:0|[1-9][0-9]*)$/; | |
util2.key64Re = /^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/; | |
util2.longToHash = function longToHash(value) { | |
return value ? util2.LongBits.from(value).toHash() : util2.LongBits.zeroHash; | |
}; | |
util2.longFromHash = function longFromHash(hash3, unsigned2) { | |
var bits2 = util2.LongBits.fromHash(hash3); | |
if (util2.Long) | |
return util2.Long.fromBits(bits2.lo, bits2.hi, unsigned2); | |
return bits2.toNumber(Boolean(unsigned2)); | |
}; | |
function merge2(dst, src11, ifNotSet) { | |
for (var keys = Object.keys(src11), i = 0; i < keys.length; ++i) | |
if (dst[keys[i]] === void 0 || !ifNotSet) | |
dst[keys[i]] = src11[keys[i]]; | |
return dst; | |
} | |
util2.merge = merge2; | |
util2.lcFirst = function lcFirst(str) { | |
return str.charAt(0).toLowerCase() + str.substring(1); | |
}; | |
function newError(name8) { | |
function CustomError(message2, properties) { | |
if (!(this instanceof CustomError)) | |
return new CustomError(message2, properties); | |
Object.defineProperty(this, "message", { get: function() { | |
return message2; | |
} }); | |
if (Error.captureStackTrace) | |
Error.captureStackTrace(this, CustomError); | |
else | |
Object.defineProperty(this, "stack", { value: new Error().stack || "" }); | |
if (properties) | |
merge2(this, properties); | |
} | |
CustomError.prototype = Object.create(Error.prototype, { | |
constructor: { | |
value: CustomError, | |
writable: true, | |
enumerable: false, | |
configurable: true | |
}, | |
name: { | |
get: function get() { | |
return name8; | |
}, | |
set: void 0, | |
enumerable: false, | |
// configurable: false would accurately preserve the behavior of | |
// the original, but I'm guessing that was not intentional. | |
// For an actual error subclass, this property would | |
// be configurable. | |
configurable: true | |
}, | |
toString: { | |
value: function value() { | |
return this.name + ": " + this.message; | |
}, | |
writable: true, | |
enumerable: false, | |
configurable: true | |
} | |
}); | |
return CustomError; | |
} | |
util2.newError = newError; | |
util2.ProtocolError = newError("ProtocolError"); | |
util2.oneOfGetter = function getOneOf(fieldNames) { | |
var fieldMap = {}; | |
for (var i = 0; i < fieldNames.length; ++i) | |
fieldMap[fieldNames[i]] = 1; | |
return function() { | |
for (var keys = Object.keys(this), i2 = keys.length - 1; i2 > -1; --i2) | |
if (fieldMap[keys[i2]] === 1 && this[keys[i2]] !== void 0 && this[keys[i2]] !== null) | |
return keys[i2]; | |
}; | |
}; | |
util2.oneOfSetter = function setOneOf(fieldNames) { | |
return function(name8) { | |
for (var i = 0; i < fieldNames.length; ++i) | |
if (fieldNames[i] !== name8) | |
delete this[fieldNames[i]]; | |
}; | |
}; | |
util2.toJSONOptions = { | |
longs: String, | |
enums: String, | |
bytes: String, | |
json: true | |
}; | |
util2._configure = function() { | |
var Buffer2 = util2.Buffer; | |
if (!Buffer2) { | |
util2._Buffer_from = util2._Buffer_allocUnsafe = null; | |
return; | |
} | |
util2._Buffer_from = Buffer2.from !== Uint8Array.from && Buffer2.from || /* istanbul ignore next */ | |
function Buffer_from(value, encoding) { | |
return new Buffer2(value, encoding); | |
}; | |
util2._Buffer_allocUnsafe = Buffer2.allocUnsafe || /* istanbul ignore next */ | |
function Buffer_allocUnsafe(size) { | |
return new Buffer2(size); | |
}; | |
}; | |
} | |
}); | |
// node_modules/protons-runtime/node_modules/protobufjs/src/reader.js | |
var require_reader = __commonJS({ | |
"node_modules/protons-runtime/node_modules/protobufjs/src/reader.js"(exports2, module2) { | |
"use strict"; | |
module2.exports = Reader; | |
var util2 = require_minimal(); | |
var BufferReader; | |
var LongBits2 = util2.LongBits; | |
var utf8 = util2.utf8; | |
function indexOutOfRange(reader3, writeLength) { | |
return RangeError("index out of range: " + reader3.pos + " + " + (writeLength || 1) + " > " + reader3.len); | |
} | |
function Reader(buffer3) { | |
this.buf = buffer3; | |
this.pos = 0; | |
this.len = buffer3.length; | |
} | |
var create_array = typeof Uint8Array !== "undefined" ? function create_typed_array(buffer3) { | |
if (buffer3 instanceof Uint8Array || Array.isArray(buffer3)) | |
return new Reader(buffer3); | |
throw Error("illegal buffer"); | |
} : function create_array2(buffer3) { | |
if (Array.isArray(buffer3)) | |
return new Reader(buffer3); | |
throw Error("illegal buffer"); | |
}; | |
var create13 = function create14() { | |
return util2.Buffer ? function create_buffer_setup(buffer3) { | |
return (Reader.create = function create_buffer(buffer4) { | |
return util2.Buffer.isBuffer(buffer4) ? new BufferReader(buffer4) : create_array(buffer4); | |
})(buffer3); | |
} : create_array; | |
}; | |
Reader.create = create13(); | |
Reader.prototype._slice = util2.Array.prototype.subarray || /* istanbul ignore next */ | |
util2.Array.prototype.slice; | |
Reader.prototype.uint32 = function read_uint32_setup() { | |
var value = 4294967295; | |
return function read_uint32() { | |
value = (this.buf[this.pos] & 127) >>> 0; | |
if (this.buf[this.pos++] < 128) | |
return value; | |
value = (value | (this.buf[this.pos] & 127) << 7) >>> 0; | |
if (this.buf[this.pos++] < 128) | |
return value; | |
value = (value | (this.buf[this.pos] & 127) << 14) >>> 0; | |
if (this.buf[this.pos++] < 128) | |
return value; | |
value = (value | (this.buf[this.pos] & 127) << 21) >>> 0; | |
if (this.buf[this.pos++] < 128) | |
return value; | |
value = (value | (this.buf[this.pos] & 15) << 28) >>> 0; | |
if (this.buf[this.pos++] < 128) | |
return value; | |
if ((this.pos += 5) > this.len) { | |
this.pos = this.len; | |
throw indexOutOfRange(this, 10); | |
} | |
return value; | |
}; | |
}(); | |
Reader.prototype.int32 = function read_int32() { | |
return this.uint32() | 0; | |
}; | |
Reader.prototype.sint32 = function read_sint32() { | |
var value = this.uint32(); | |
return value >>> 1 ^ -(value & 1) | 0; | |
}; | |
function readLongVarint() { | |
var bits2 = new LongBits2(0, 0); | |
var i = 0; | |
if (this.len - this.pos > 4) { | |
for (; i < 4; ++i) { | |
bits2.lo = (bits2.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0; | |
if (this.buf[this.pos++] < 128) | |
return bits2; | |
} | |
bits2.lo = (bits2.lo | (this.buf[this.pos] & 127) << 28) >>> 0; | |
bits2.hi = (bits2.hi | (this.buf[this.pos] & 127) >> 4) >>> 0; | |
if (this.buf[this.pos++] < 128) | |
return bits2; | |
i = 0; | |
} else { | |
for (; i < 3; ++i) { | |
if (this.pos >= this.len) | |
throw indexOutOfRange(this); | |
bits2.lo = (bits2.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0; | |
if (this.buf[this.pos++] < 128) | |
return bits2; | |
} | |
bits2.lo = (bits2.lo | (this.buf[this.pos++] & 127) << i * 7) >>> 0; | |
return bits2; | |
} | |
if (this.len - this.pos > 4) { | |
for (; i < 5; ++i) { | |
bits2.hi = (bits2.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0; | |
if (this.buf[this.pos++] < 128) | |
return bits2; | |
} | |
} else { | |
for (; i < 5; ++i) { | |
if (this.pos >= this.len) | |
throw indexOutOfRange(this); | |
bits2.hi = (bits2.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0; | |
if (this.buf[this.pos++] < 128) | |
return bits2; | |
} | |
} | |
throw Error("invalid varint encoding"); | |
} | |
Reader.prototype.bool = function read_bool() { | |
return this.uint32() !== 0; | |
}; | |
function readFixed32_end(buf3, end) { | |
return (buf3[end - 4] | buf3[end - 3] << 8 | buf3[end - 2] << 16 | buf3[end - 1] << 24) >>> 0; | |
} | |
Reader.prototype.fixed32 = function read_fixed32() { | |
if (this.pos + 4 > this.len) | |
throw indexOutOfRange(this, 4); | |
return readFixed32_end(this.buf, this.pos += 4); | |
}; | |
Reader.prototype.sfixed32 = function read_sfixed32() { | |
if (this.pos + 4 > this.len) | |
throw indexOutOfRange(this, 4); | |
return readFixed32_end(this.buf, this.pos += 4) | 0; | |
}; | |
function readFixed64() { | |
if (this.pos + 8 > this.len) | |
throw indexOutOfRange(this, 8); | |
return new LongBits2(readFixed32_end(this.buf, this.pos += 4), readFixed32_end(this.buf, this.pos += 4)); | |
} | |
Reader.prototype.float = function read_float() { | |
if (this.pos + 4 > this.len) | |
throw indexOutOfRange(this, 4); | |
var value = util2.float.readFloatLE(this.buf, this.pos); | |
this.pos += 4; | |
return value; | |
}; | |
Reader.prototype.double = function read_double() { | |
if (this.pos + 8 > this.len) | |
throw indexOutOfRange(this, 4); | |
var value = util2.float.readDoubleLE(this.buf, this.pos); | |
this.pos += 8; | |
return value; | |
}; | |
Reader.prototype.bytes = function read_bytes() { | |
var length11 = this.uint32(), start = this.pos, end = this.pos + length11; | |
if (end > this.len) | |
throw indexOutOfRange(this, length11); | |
this.pos += length11; | |
if (Array.isArray(this.buf)) | |
return this.buf.slice(start, end); | |
return start === end ? new this.buf.constructor(0) : this._slice.call(this.buf, start, end); | |
}; | |
Reader.prototype.string = function read_string() { | |
var bytes3 = this.bytes(); | |
return utf8.read(bytes3, 0, bytes3.length); | |
}; | |
Reader.prototype.skip = function skip(length11) { | |
if (typeof length11 === "number") { | |
if (this.pos + length11 > this.len) | |
throw indexOutOfRange(this, length11); | |
this.pos += length11; | |
} else { | |
do { | |
if (this.pos >= this.len) | |
throw indexOutOfRange(this); | |
} while (this.buf[this.pos++] & 128); | |
} | |
return this; | |
}; | |
Reader.prototype.skipType = function(wireType) { | |
switch (wireType) { | |
case 0: | |
this.skip(); | |
break; | |
case 1: | |
this.skip(8); | |
break; | |
case 2: | |
this.skip(this.uint32()); | |
break; | |
case 3: | |
while ((wireType = this.uint32() & 7) !== 4) { | |
this.skipType(wireType); | |
} | |
break; | |
case 5: | |
this.skip(4); | |
break; | |
default: | |
throw Error("invalid wire type " + wireType + " at offset " + this.pos); | |
} | |
return this; | |
}; | |
Reader._configure = function(BufferReader_) { | |
BufferReader = BufferReader_; | |
Reader.create = create13(); | |
BufferReader._configure(); | |
var fn = util2.Long ? "toLong" : ( | |
/* istanbul ignore next */ | |
"toNumber" | |
); | |
util2.merge(Reader.prototype, { | |
int64: function read_int64() { | |
return readLongVarint.call(this)[fn](false); | |
}, | |
uint64: function read_uint64() { | |
return readLongVarint.call(this)[fn](true); | |
}, | |
sint64: function read_sint64() { | |
return readLongVarint.call(this).zzDecode()[fn](false); | |
}, | |
fixed64: function read_fixed64() { | |
return readFixed64.call(this)[fn](true); | |
}, | |
sfixed64: function read_sfixed64() { | |
return readFixed64.call(this)[fn](false); | |
} | |
}); | |
}; | |
} | |
}); | |
// node_modules/protons-runtime/node_modules/protobufjs/src/reader_buffer.js | |
var require_reader_buffer = __commonJS({ | |
"node_modules/protons-runtime/node_modules/protobufjs/src/reader_buffer.js"(exports2, module2) { | |
"use strict"; | |
module2.exports = BufferReader; | |
var Reader = require_reader(); | |
(BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader; | |
var util2 = require_minimal(); | |
function BufferReader(buffer3) { | |
Reader.call(this, buffer3); | |
} | |
BufferReader._configure = function() { | |
if (util2.Buffer) | |
BufferReader.prototype._slice = util2.Buffer.prototype.slice; | |
}; | |
BufferReader.prototype.string = function read_string_buffer() { | |
var len = this.uint32(); | |
return this.buf.utf8Slice ? this.buf.utf8Slice(this.pos, this.pos = Math.min(this.pos + len, this.len)) : this.buf.toString("utf-8", this.pos, this.pos = Math.min(this.pos + len, this.len)); | |
}; | |
BufferReader._configure(); | |
} | |
}); | |
// node_modules/protons-runtime/node_modules/protobufjs/src/writer.js | |
var require_writer = __commonJS({ | |
"node_modules/protons-runtime/node_modules/protobufjs/src/writer.js"(exports2, module2) { | |
"use strict"; | |
module2.exports = Writer; | |
var util2 = require_minimal(); | |
var BufferWriter; | |
var LongBits2 = util2.LongBits; | |
var base647 = util2.base64; | |
var utf8 = util2.utf8; | |
function Op(fn, len, val) { | |
this.fn = fn; | |
this.len = len; | |
this.next = void 0; | |
this.val = val; | |
} | |
function noop2() { | |
} | |
function State(writer2) { | |
this.head = writer2.head; | |
this.tail = writer2.tail; | |
this.len = writer2.len; | |
this.next = writer2.states; | |
} | |
function Writer() { | |
this.len = 0; | |
this.head = new Op(noop2, 0, 0); | |
this.tail = this.head; | |
this.states = null; | |
} | |
var create13 = function create14() { | |
return util2.Buffer ? function create_buffer_setup() { | |
return (Writer.create = function create_buffer() { | |
return new BufferWriter(); | |
})(); | |
} : function create_array() { | |
return new Writer(); | |
}; | |
}; | |
Writer.create = create13(); | |
Writer.alloc = function alloc4(size) { | |
return new util2.Array(size); | |
}; | |
if (util2.Array !== Array) | |
Writer.alloc = util2.pool(Writer.alloc, util2.Array.prototype.subarray); | |
Writer.prototype._push = function push(fn, len, val) { | |
this.tail = this.tail.next = new Op(fn, len, val); | |
this.len += len; | |
return this; | |
}; | |
function writeByte(val, buf3, pos) { | |
buf3[pos] = val & 255; | |
} | |
function writeVarint32(val, buf3, pos) { | |
while (val > 127) { | |
buf3[pos++] = val & 127 | 128; | |
val >>>= 7; | |
} | |
buf3[pos] = val; | |
} | |
function VarintOp(len, val) { | |
this.len = len; | |
this.next = void 0; | |
this.val = val; | |
} | |
VarintOp.prototype = Object.create(Op.prototype); | |
VarintOp.prototype.fn = writeVarint32; | |
Writer.prototype.uint32 = function write_uint32(value) { | |
this.len += (this.tail = this.tail.next = new VarintOp( | |
(value = value >>> 0) < 128 ? 1 : value < 16384 ? 2 : value < 2097152 ? 3 : value < 268435456 ? 4 : 5, | |
value | |
)).len; | |
return this; | |
}; | |
Writer.prototype.int32 = function write_int32(value) { | |
return value < 0 ? this._push(writeVarint64, 10, LongBits2.fromNumber(value)) : this.uint32(value); | |
}; | |
Writer.prototype.sint32 = function write_sint32(value) { | |
return this.uint32((value << 1 ^ value >> 31) >>> 0); | |
}; | |
function writeVarint64(val, buf3, pos) { | |
while (val.hi) { | |
buf3[pos++] = val.lo & 127 | 128; | |
val.lo = (val.lo >>> 7 | val.hi << 25) >>> 0; | |
val.hi >>>= 7; | |
} | |
while (val.lo > 127) { | |
buf3[pos++] = val.lo & 127 | 128; | |
val.lo = val.lo >>> 7; | |
} | |
buf3[pos++] = val.lo; | |
} | |
Writer.prototype.uint64 = function write_uint64(value) { | |
var bits2 = LongBits2.from(value); | |
return this._push(writeVarint64, bits2.length(), bits2); | |
}; | |
Writer.prototype.int64 = Writer.prototype.uint64; | |
Writer.prototype.sint64 = function write_sint64(value) { | |
var bits2 = LongBits2.from(value).zzEncode(); | |
return this._push(writeVarint64, bits2.length(), bits2); | |
}; | |
Writer.prototype.bool = function write_bool(value) { | |
return this._push(writeByte, 1, value ? 1 : 0); | |
}; | |
function writeFixed32(val, buf3, pos) { | |
buf3[pos] = val & 255; | |
buf3[pos + 1] = val >>> 8 & 255; | |
buf3[pos + 2] = val >>> 16 & 255; | |
buf3[pos + 3] = val >>> 24; | |
} | |
Writer.prototype.fixed32 = function write_fixed32(value) { | |
return this._push(writeFixed32, 4, value >>> 0); | |
}; | |
Writer.prototype.sfixed32 = Writer.prototype.fixed32; | |
Writer.prototype.fixed64 = function write_fixed64(value) { | |
var bits2 = LongBits2.from(value); | |
return this._push(writeFixed32, 4, bits2.lo)._push(writeFixed32, 4, bits2.hi); | |
}; | |
Writer.prototype.sfixed64 = Writer.prototype.fixed64; | |
Writer.prototype.float = function write_float(value) { | |
return this._push(util2.float.writeFloatLE, 4, value); | |
}; | |
Writer.prototype.double = function write_double(value) { | |
return this._push(util2.float.writeDoubleLE, 8, value); | |
}; | |
var writeBytes = util2.Array.prototype.set ? function writeBytes_set(val, buf3, pos) { | |
buf3.set(val, pos); | |
} : function writeBytes_for(val, buf3, pos) { | |
for (var i = 0; i < val.length; ++i) | |
buf3[pos + i] = val[i]; | |
}; | |
Writer.prototype.bytes = function write_bytes(value) { | |
var len = value.length >>> 0; | |
if (!len) | |
return this._push(writeByte, 1, 0); | |
if (util2.isString(value)) { | |
var buf3 = Writer.alloc(len = base647.length(value)); | |
base647.decode(value, buf3, 0); | |
value = buf3; | |
} | |
return this.uint32(len)._push(writeBytes, len, value); | |
}; | |
Writer.prototype.string = function write_string(value) { | |
var len = utf8.length(value); | |
return len ? this.uint32(len)._push(utf8.write, len, value) : this._push(writeByte, 1, 0); | |
}; | |
Writer.prototype.fork = function fork() { | |
this.states = new State(this); | |
this.head = this.tail = new Op(noop2, 0, 0); | |
this.len = 0; | |
return this; | |
}; | |
Writer.prototype.reset = function reset() { | |
if (this.states) { | |
this.head = this.states.head; | |
this.tail = this.states.tail; | |
this.len = this.states.len; | |
this.states = this.states.next; | |
} else { | |
this.head = this.tail = new Op(noop2, 0, 0); | |
this.len = 0; | |
} | |
return this; | |
}; | |
Writer.prototype.ldelim = function ldelim() { | |
var head = this.head, tail = this.tail, len = this.len; | |
this.reset().uint32(len); | |
if (len) { | |
this.tail.next = head.next; | |
this.tail = tail; | |
this.len += len; | |
} | |
return this; | |
}; | |
Writer.prototype.finish = function finish() { | |
var head = this.head.next, buf3 = this.constructor.alloc(this.len), pos = 0; | |
while (head) { | |
head.fn(head.val, buf3, pos); | |
pos += head.len; | |
head = head.next; | |
} | |
return buf3; | |
}; | |
Writer._configure = function(BufferWriter_) { | |
BufferWriter = BufferWriter_; | |
Writer.create = create13(); | |
BufferWriter._configure(); | |
}; | |
} | |
}); | |
// node_modules/protons-runtime/node_modules/protobufjs/src/writer_buffer.js | |
var require_writer_buffer = __commonJS({ | |
"node_modules/protons-runtime/node_modules/protobufjs/src/writer_buffer.js"(exports2, module2) { | |
"use strict"; | |
module2.exports = BufferWriter; | |
var Writer = require_writer(); | |
(BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter; | |
var util2 = require_minimal(); | |
function BufferWriter() { | |
Writer.call(this); | |
} | |
BufferWriter._configure = function() { | |
BufferWriter.alloc = util2._Buffer_allocUnsafe; | |
BufferWriter.writeBytesBuffer = util2.Buffer && util2.Buffer.prototype instanceof Uint8Array && util2.Buffer.prototype.set.name === "set" ? function writeBytesBuffer_set(val, buf3, pos) { | |
buf3.set(val, pos); | |
} : function writeBytesBuffer_copy(val, buf3, pos) { | |
if (val.copy) | |
val.copy(buf3, pos, 0, val.length); | |
else | |
for (var i = 0; i < val.length; ) | |
buf3[pos++] = val[i++]; | |
}; | |
}; | |
BufferWriter.prototype.bytes = function write_bytes_buffer(value) { | |
if (util2.isString(value)) | |
value = util2._Buffer_from(value, "base64"); | |
var len = value.length >>> 0; | |
this.uint32(len); | |
if (len) | |
this._push(BufferWriter.writeBytesBuffer, len, value); | |
return this; | |
}; | |
function writeStringBuffer(val, buf3, pos) { | |
if (val.length < 40) | |
util2.utf8.write(val, buf3, pos); | |
else if (buf3.utf8Write) | |
buf3.utf8Write(val, pos); | |
else | |
buf3.write(val, pos); | |
} | |
BufferWriter.prototype.string = function write_string_buffer(value) { | |
var len = util2.Buffer.byteLength(value); | |
this.uint32(len); | |
if (len) | |
this._push(writeStringBuffer, len, value); | |
return this; | |
}; | |
BufferWriter._configure(); | |
} | |
}); | |
// node_modules/retimer/time-browser.js | |
var require_time_browser = __commonJS({ | |
"node_modules/retimer/time-browser.js"(exports2, module2) { | |
"use strict"; | |
module2.exports = function getTime() { | |
return Date.now(); | |
}; | |
} | |
}); | |
// node_modules/retimer/retimer.js | |
var require_retimer = __commonJS({ | |
"node_modules/retimer/retimer.js"(exports2, module2) { | |
"use strict"; | |
var getTime = require_time_browser(); | |
var Retimer = class { | |
constructor(callback, timeout, args) { | |
const that = this; | |
this._started = getTime(); | |
this._rescheduled = 0; | |
this._scheduled = timeout; | |
this._args = args; | |
this._triggered = false; | |
this._timerWrapper = () => { | |
if (that._rescheduled > 0) { | |
that._scheduled = that._rescheduled - (getTime() - that._started); | |
that._schedule(that._scheduled); | |
} else { | |
that._triggered = true; | |
callback.apply(null, that._args); | |
} | |
}; | |
this._timer = setTimeout(this._timerWrapper, timeout); | |
} | |
reschedule(timeout) { | |
if (!timeout) { | |
timeout = this._scheduled; | |
} | |
const now = getTime(); | |
if (now + timeout - (this._started + this._scheduled) < 0) { | |
clearTimeout(this._timer); | |
this._schedule(timeout); | |
} else if (!this._triggered) { | |
this._started = now; | |
this._rescheduled = timeout; | |
} else { | |
this._schedule(timeout); | |
} | |
} | |
_schedule(timeout) { | |
this._triggered = false; | |
this._started = getTime(); | |
this._rescheduled = 0; | |
this._scheduled = timeout; | |
this._timer = setTimeout(this._timerWrapper, timeout); | |
} | |
clear() { | |
clearTimeout(this._timer); | |
} | |
}; | |
function retimer() { | |
if (typeof arguments[0] !== "function") { | |
throw new Error("callback needed"); | |
} | |
if (typeof arguments[1] !== "number") { | |
throw new Error("timeout needed"); | |
} | |
let args; | |
if (arguments.length > 0) { | |
args = new Array(arguments.length - 2); | |
for (var i = 0; i < args.length; i++) { | |
args[i] = arguments[i + 2]; | |
} | |
} | |
return new Retimer(arguments[0], arguments[1], args); | |
} | |
module2.exports = retimer; | |
} | |
}); | |
// node_modules/timeout-abort-controller/index.js | |
var require_timeout_abort_controller = __commonJS({ | |
"node_modules/timeout-abort-controller/index.js"(exports2, module2) { | |
"use strict"; | |
var { AbortController: AbortController2 } = globalThis; | |
var retimer = require_retimer(); | |
var TimeoutController2 = class _TimeoutController extends AbortController2 { | |
/** | |
* @constructor | |
* @param {number} ms milliseconds | |
*/ | |
constructor(ms) { | |
super(); | |
this._ms = ms; | |
this._timer = retimer(() => this.abort(), ms); | |
Object.setPrototypeOf(this, _TimeoutController.prototype); | |
} | |
/** | |
* Aborts the controller and clears the timer | |
*/ | |
abort() { | |
this._timer.clear(); | |
return super.abort(); | |
} | |
/** | |
* Clears the timer | |
*/ | |
clear() { | |
this._timer.clear(); | |
} | |
/** | |
* Resets the timer | |
*/ | |
reset() { | |
this._timer.clear(); | |
this._timer = retimer(() => this.abort(), this._ms); | |
} | |
}; | |
module2.exports = { | |
TimeoutController: TimeoutController2 | |
}; | |
} | |
}); | |
// node_modules/events/events.js | |
var require_events = __commonJS({ | |
"node_modules/events/events.js"(exports2, module2) { | |
"use strict"; | |
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 EventEmitter6() { | |
EventEmitter6.init.call(this); | |
} | |
module2.exports = EventEmitter6; | |
module2.exports.once = once; | |
EventEmitter6.EventEmitter = EventEmitter6; | |
EventEmitter6.prototype._events = void 0; | |
EventEmitter6.prototype._eventsCount = 0; | |
EventEmitter6.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(EventEmitter6, "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; | |
} | |
}); | |
EventEmitter6.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; | |
}; | |
EventEmitter6.prototype.setMaxListeners = function setMaxListeners10(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 EventEmitter6.defaultMaxListeners; | |
return that._maxListeners; | |
} | |
EventEmitter6.prototype.getMaxListeners = function getMaxListeners() { | |
return _getMaxListeners(this); | |
}; | |
EventEmitter6.prototype.emit = function emit(type) { | |
var args = []; | |
for (var i = 1; i < arguments.length; i++) | |
args.push(arguments[i]); | |
var doError = type === "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[type]; | |
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, type, 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", | |
type, | |
listener.listener ? listener.listener : listener | |
); | |
events2 = target._events; | |
} | |
existing = events2[type]; | |
} | |
if (existing === void 0) { | |
existing = events2[type] = listener; | |
++target._eventsCount; | |
} else { | |
if (typeof existing === "function") { | |
existing = events2[type] = 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(type) + " listeners added. Use emitter.setMaxListeners() to increase limit"); | |
w.name = "MaxListenersExceededWarning"; | |
w.emitter = target; | |
w.type = type; | |
w.count = existing.length; | |
ProcessEmitWarning(w); | |
} | |
} | |
return target; | |
} | |
EventEmitter6.prototype.addListener = function addListener(type, listener) { | |
return _addListener(this, type, listener, false); | |
}; | |
EventEmitter6.prototype.on = EventEmitter6.prototype.addListener; | |
EventEmitter6.prototype.prependListener = function prependListener(type, listener) { | |
return _addListener(this, type, 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, type, listener) { | |
var state = { fired: false, wrapFn: void 0, target, type, listener }; | |
var wrapped = onceWrapper.bind(state); | |
wrapped.listener = listener; | |
state.wrapFn = wrapped; | |
return wrapped; | |
} | |
EventEmitter6.prototype.once = function once2(type, listener) { | |
checkListener(listener); | |
this.on(type, _onceWrap(this, type, listener)); | |
return this; | |
}; | |
EventEmitter6.prototype.prependOnceListener = function prependOnceListener(type, listener) { | |
checkListener(listener); | |
this.prependListener(type, _onceWrap(this, type, listener)); | |
return this; | |
}; | |
EventEmitter6.prototype.removeListener = function removeListener(type, listener) { | |
var list, events2, position, i, originalListener; | |
checkListener(listener); | |
events2 = this._events; | |
if (events2 === void 0) | |
return this; | |
list = events2[type]; | |
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[type]; | |
if (events2.removeListener) | |
this.emit("removeListener", type, 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[type] = list[0]; | |
if (events2.removeListener !== void 0) | |
this.emit("removeListener", type, originalListener || listener); | |
} | |
return this; | |
}; | |
EventEmitter6.prototype.off = EventEmitter6.prototype.removeListener; | |
EventEmitter6.prototype.removeAllListeners = function removeAllListeners(type) { | |
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[type] !== void 0) { | |
if (--this._eventsCount === 0) | |
this._events = /* @__PURE__ */ Object.create(null); | |
else | |
delete events2[type]; | |
} | |
return this; | |
} | |
if (arguments.length === 0) { | |
var keys = Object.keys(events2); | |
var key; | |
for (i = 0; i < keys.length; ++i) { | |
key = keys[i]; | |
if (key === "removeListener") | |
continue; | |
this.removeAllListeners(key); | |
} | |
this.removeAllListeners("removeListener"); | |
this._events = /* @__PURE__ */ Object.create(null); | |
this._eventsCount = 0; | |
return this; | |
} | |
listeners = events2[type]; | |
if (typeof listeners === "function") { | |
this.removeListener(type, listeners); | |
} else if (listeners !== void 0) { | |
for (i = listeners.length - 1; i >= 0; i--) { | |
this.removeListener(type, listeners[i]); | |
} | |
} | |
return this; | |
}; | |
function _listeners(target, type, unwrap) { | |
var events2 = target._events; | |
if (events2 === void 0) | |
return []; | |
var evlistener = events2[type]; | |
if (evlistener === void 0) | |
return []; | |
if (typeof evlistener === "function") | |
return unwrap ? [evlistener.listener || evlistener] : [evlistener]; | |
return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length); | |
} | |
EventEmitter6.prototype.listeners = function listeners(type) { | |
return _listeners(this, type, true); | |
}; | |
EventEmitter6.prototype.rawListeners = function rawListeners(type) { | |
return _listeners(this, type, false); | |
}; | |
EventEmitter6.listenerCount = function(emitter, type) { | |
if (typeof emitter.listenerCount === "function") { | |
return emitter.listenerCount(type); | |
} else { | |
return listenerCount.call(emitter, type); | |
} | |
}; | |
EventEmitter6.prototype.listenerCount = listenerCount; | |
function listenerCount(type) { | |
var events2 = this._events; | |
if (events2 !== void 0) { | |
var evlistener = events2[type]; | |
if (typeof evlistener === "function") { | |
return 1; | |
} else if (evlistener !== void 0) { | |
return evlistener.length; | |
} | |
} | |
return 0; | |
} | |
EventEmitter6.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, name8) { | |
return new Promise(function(resolve6, reject) { | |
function errorListener(err) { | |
emitter.removeListener(name8, resolver); | |
reject(err); | |
} | |
function resolver() { | |
if (typeof emitter.removeListener === "function") { | |
emitter.removeListener("error", errorListener); | |
} | |
resolve6([].slice.call(arguments)); | |
} | |
; | |
eventTargetAgnosticAddListener(emitter, name8, resolver, { once: true }); | |
if (name8 !== "error") { | |
addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true }); | |
} | |
}); | |
} | |
function addErrorHandlerIfEventEmitter(emitter, handler, flags) { | |
if (typeof emitter.on === "function") { | |
eventTargetAgnosticAddListener(emitter, "error", handler, flags); | |
} | |
} | |
function eventTargetAgnosticAddListener(emitter, name8, listener, flags) { | |
if (typeof emitter.on === "function") { | |
if (flags.once) { | |
emitter.once(name8, listener); | |
} else { | |
emitter.on(name8, listener); | |
} | |
} else if (typeof emitter.addEventListener === "function") { | |
emitter.addEventListener(name8, function wrapListener(arg) { | |
if (flags.once) { | |
emitter.removeEventListener(name8, wrapListener); | |
} | |
listener(arg); | |
}); | |
} else { | |
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter); | |
} | |
} | |
} | |
}); | |
// node_modules/@vascosantos/moving-average/index.js | |
var require_moving_average = __commonJS({ | |
"node_modules/@vascosantos/moving-average/index.js"(exports2, module2) { | |
"use strict"; | |
var exp = Math.exp; | |
exports2 = module2.exports = function MovingAverage2(timespan) { | |
if (typeof timespan !== "number") { | |
throw new Error("must provide a timespan to the moving average constructor"); | |
} | |
if (timespan <= 0) { | |
throw new Error("must provide a timespan > 0 to the moving average constructor"); | |
} | |
let ma; | |
let v = 0; | |
let d = 0; | |
let f = 0; | |
let previousTime; | |
let ret = {}; | |
function alpha(t, pt) { | |
return 1 - exp(-(t - pt) / timespan); | |
} | |
ret.push = function push(time, value) { | |
if (previousTime) { | |
const a = alpha(time, previousTime); | |
const diff = value - ma; | |
const incr = a * diff; | |
ma = a * value + (1 - a) * ma; | |
v = (1 - a) * (v + diff * incr); | |
d = Math.sqrt(v); | |
f = ma + a * diff; | |
} else { | |
ma = value; | |
} | |
previousTime = time; | |
}; | |
ret.movingAverage = function movingAverage() { | |
return ma; | |
}; | |
ret.variance = function variance() { | |
return v; | |
}; | |
ret.deviation = function deviation() { | |
return d; | |
}; | |
ret.forecast = function forecast() { | |
return f; | |
}; | |
return ret; | |
}; | |
} | |
}); | |
// node_modules/eventemitter3/index.js | |
var require_eventemitter3 = __commonJS({ | |
"node_modules/eventemitter3/index.js"(exports2, module2) { | |
"use strict"; | |
var has = Object.prototype.hasOwnProperty; | |
var prefix = "~"; | |
function Events() { | |
} | |
if (Object.create) { | |
Events.prototype = /* @__PURE__ */ Object.create(null); | |
if (!new Events().__proto__) | |
prefix = false; | |
} | |
function EE(fn, context, once) { | |
this.fn = fn; | |
this.context = context; | |
this.once = once || false; | |
} | |
function addListener(emitter, event, fn, context, once) { | |
if (typeof fn !== "function") { | |
throw new TypeError("The listener must be a function"); | |
} | |
var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event; | |
if (!emitter._events[evt]) | |
emitter._events[evt] = listener, emitter._eventsCount++; | |
else if (!emitter._events[evt].fn) | |
emitter._events[evt].push(listener); | |
else | |
emitter._events[evt] = [emitter._events[evt], listener]; | |
return emitter; | |
} | |
function clearEvent(emitter, evt) { | |
if (--emitter._eventsCount === 0) | |
emitter._events = new Events(); | |
else | |
delete emitter._events[evt]; | |
} | |
function EventEmitter6() { | |
this._events = new Events(); | |
this._eventsCount = 0; | |
} | |
EventEmitter6.prototype.eventNames = function eventNames() { | |
var names3 = [], events2, name8; | |
if (this._eventsCount === 0) | |
return names3; | |
for (name8 in events2 = this._events) { | |
if (has.call(events2, name8)) | |
names3.push(prefix ? name8.slice(1) : name8); | |
} | |
if (Object.getOwnPropertySymbols) { | |
return names3.concat(Object.getOwnPropertySymbols(events2)); | |
} | |
return names3; | |
}; | |
EventEmitter6.prototype.listeners = function listeners(event) { | |
var evt = prefix ? prefix + event : event, handlers = this._events[evt]; | |
if (!handlers) | |
return []; | |
if (handlers.fn) | |
return [handlers.fn]; | |
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) { | |
ee[i] = handlers[i].fn; | |
} | |
return ee; | |
}; | |
EventEmitter6.prototype.listenerCount = function listenerCount(event) { | |
var evt = prefix ? prefix + event : event, listeners = this._events[evt]; | |
if (!listeners) | |
return 0; | |
if (listeners.fn) | |
return 1; | |
return listeners.length; | |
}; | |
EventEmitter6.prototype.emit = function emit(event, a1, a2, a3, a4, a5) { | |
var evt = prefix ? prefix + event : event; | |
if (!this._events[evt]) | |
return false; | |
var listeners = this._events[evt], len = arguments.length, args, i; | |
if (listeners.fn) { | |
if (listeners.once) | |
this.removeListener(event, listeners.fn, void 0, true); | |
switch (len) { | |
case 1: | |
return listeners.fn.call(listeners.context), true; | |
case 2: | |
return listeners.fn.call(listeners.context, a1), true; | |
case 3: | |
return listeners.fn.call(listeners.context, a1, a2), true; | |
case 4: | |
return listeners.fn.call(listeners.context, a1, a2, a3), true; | |
case 5: | |
return listeners.fn.call(listeners.context, a1, a2, a3, a4), true; | |
case 6: | |
return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true; | |
} | |
for (i = 1, args = new Array(len - 1); i < len; i++) { | |
args[i - 1] = arguments[i]; | |
} | |
listeners.fn.apply(listeners.context, args); | |
} else { | |
var length11 = listeners.length, j; | |
for (i = 0; i < length11; i++) { | |
if (listeners[i].once) | |
this.removeListener(event, listeners[i].fn, void 0, true); | |
switch (len) { | |
case 1: | |
listeners[i].fn.call(listeners[i].context); | |
break; | |
case 2: | |
listeners[i].fn.call(listeners[i].context, a1); | |
break; | |
case 3: | |
listeners[i].fn.call(listeners[i].context, a1, a2); | |
break; | |
case 4: | |
listeners[i].fn.call(listeners[i].context, a1, a2, a3); | |
break; | |
default: | |
if (!args) | |
for (j = 1, args = new Array(len - 1); j < len; j++) { | |
args[j - 1] = arguments[j]; | |
} | |
listeners[i].fn.apply(listeners[i].context, args); | |
} | |
} | |
} | |
return true; | |
}; | |
EventEmitter6.prototype.on = function on(event, fn, context) { | |
return addListener(this, event, fn, context, false); | |
}; | |
EventEmitter6.prototype.once = function once(event, fn, context) { | |
return addListener(this, event, fn, context, true); | |
}; | |
EventEmitter6.prototype.removeListener = function removeListener(event, fn, context, once) { | |
var evt = prefix ? prefix + event : event; | |
if (!this._events[evt]) | |
return this; | |
if (!fn) { | |
clearEvent(this, evt); | |
return this; | |
} | |
var listeners = this._events[evt]; | |
if (listeners.fn) { | |
if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) { | |
clearEvent(this, evt); | |
} | |
} else { | |
for (var i = 0, events2 = [], length11 = listeners.length; i < length11; i++) { | |
if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) { | |
events2.push(listeners[i]); | |
} | |
} | |
if (events2.length) | |
this._events[evt] = events2.length === 1 ? events2[0] : events2; | |
else | |
clearEvent(this, evt); | |
} | |
return this; | |
}; | |
EventEmitter6.prototype.removeAllListeners = function removeAllListeners(event) { | |
var evt; | |
if (event) { | |
evt = prefix ? prefix + event : event; | |
if (this._events[evt]) | |
clearEvent(this, evt); | |
} else { | |
this._events = new Events(); | |
this._eventsCount = 0; | |
} | |
return this; | |
}; | |
EventEmitter6.prototype.off = EventEmitter6.prototype.removeListener; | |
EventEmitter6.prototype.addListener = EventEmitter6.prototype.on; | |
EventEmitter6.prefixed = prefix; | |
EventEmitter6.EventEmitter = EventEmitter6; | |
if ("undefined" !== typeof module2) { | |
module2.exports = EventEmitter6; | |
} | |
} | |
}); | |
// node_modules/node-forge/lib/forge.js | |
var require_forge = __commonJS({ | |
"node_modules/node-forge/lib/forge.js"(exports2, module2) { | |
module2.exports = { | |
// default options | |
options: { | |
usePureJavaScript: false | |
} | |
}; | |
} | |
}); | |
// node_modules/node-forge/lib/baseN.js | |
var require_baseN = __commonJS({ | |
"node_modules/node-forge/lib/baseN.js"(exports2, module2) { | |
var api = {}; | |
module2.exports = api; | |
var _reverseAlphabets = {}; | |
api.encode = function(input, alphabet5, maxline) { | |
if (typeof alphabet5 !== "string") { | |
throw new TypeError('"alphabet" must be a string.'); | |
} | |
if (maxline !== void 0 && typeof maxline !== "number") { | |
throw new TypeError('"maxline" must be a number.'); | |
} | |
var output3 = ""; | |
if (!(input instanceof Uint8Array)) { | |
output3 = _encodeWithByteBuffer(input, alphabet5); | |
} else { | |
var i = 0; | |
var base14 = alphabet5.length; | |
var first2 = alphabet5.charAt(0); | |
var digits = [0]; | |
for (i = 0; i < input.length; ++i) { | |
for (var j = 0, carry = input[i]; j < digits.length; ++j) { | |
carry += digits[j] << 8; | |
digits[j] = carry % base14; | |
carry = carry / base14 | 0; | |
} | |
while (carry > 0) { | |
digits.push(carry % base14); | |
carry = carry / base14 | 0; | |
} | |
} | |
for (i = 0; input[i] === 0 && i < input.length - 1; ++i) { | |
output3 += first2; | |
} | |
for (i = digits.length - 1; i >= 0; --i) { | |
output3 += alphabet5[digits[i]]; | |
} | |
} | |
if (maxline) { | |
var regex = new RegExp(".{1," + maxline + "}", "g"); | |
output3 = output3.match(regex).join("\r\n"); | |
} | |
return output3; | |
}; | |
api.decode = function(input, alphabet5) { | |
if (typeof input !== "string") { | |
throw new TypeError('"input" must be a string.'); | |
} | |
if (typeof alphabet5 !== "string") { | |
throw new TypeError('"alphabet" must be a string.'); | |
} | |
var table2 = _reverseAlphabets[alphabet5]; | |
if (!table2) { | |
table2 = _reverseAlphabets[alphabet5] = []; | |
for (var i = 0; i < alphabet5.length; ++i) { | |
table2[alphabet5.charCodeAt(i)] = i; | |
} | |
} | |
input = input.replace(/\s/g, ""); | |
var base14 = alphabet5.length; | |
var first2 = alphabet5.charAt(0); | |
var bytes3 = [0]; | |
for (var i = 0; i < input.length; i++) { | |
var value = table2[input.charCodeAt(i)]; | |
if (value === void 0) { | |
return; | |
} | |
for (var j = 0, carry = value; j < bytes3.length; ++j) { | |
carry += bytes3[j] * base14; | |
bytes3[j] = carry & 255; | |
carry >>= 8; | |
} | |
while (carry > 0) { | |
bytes3.push(carry & 255); | |
carry >>= 8; | |
} | |
} | |
for (var k = 0; input[k] === first2 && k < input.length - 1; ++k) { | |
bytes3.push(0); | |
} | |
if (typeof Buffer !== "undefined") { | |
return Buffer.from(bytes3.reverse()); | |
} | |
return new Uint8Array(bytes3.reverse()); | |
}; | |
function _encodeWithByteBuffer(input, alphabet5) { | |
var i = 0; | |
var base14 = alphabet5.length; | |
var first2 = alphabet5.charAt(0); | |
var digits = [0]; | |
for (i = 0; i < input.length(); ++i) { | |
for (var j = 0, carry = input.at(i); j < digits.length; ++j) { | |
carry += digits[j] << 8; | |
digits[j] = carry % base14; | |
carry = carry / base14 | 0; | |
} | |
while (carry > 0) { | |
digits.push(carry % base14); | |
carry = carry / base14 | 0; | |
} | |
} | |
var output3 = ""; | |
for (i = 0; input.at(i) === 0 && i < input.length() - 1; ++i) { | |
output3 += first2; | |
} | |
for (i = digits.length - 1; i >= 0; --i) { | |
output3 += alphabet5[digits[i]]; | |
} | |
return output3; | |
} | |
} | |
}); | |
// node_modules/node-forge/lib/util.js | |
var require_util = __commonJS({ | |
"node_modules/node-forge/lib/util.js"(exports2, module2) { | |
var forge7 = require_forge(); | |
var baseN = require_baseN(); | |
var util2 = module2.exports = forge7.util = forge7.util || {}; | |
(function() { | |
if (typeof process !== "undefined" && process.nextTick && !process.browser) { | |
util2.nextTick = process.nextTick; | |
if (typeof setImmediate === "function") { | |
util2.setImmediate = setImmediate; | |
} else { | |
util2.setImmediate = util2.nextTick; | |
} | |
return; | |
} | |
if (typeof setImmediate === "function") { | |
util2.setImmediate = function() { | |
return setImmediate.apply(void 0, arguments); | |
}; | |
util2.nextTick = function(callback) { | |
return setImmediate(callback); | |
}; | |
return; | |
} | |
util2.setImmediate = function(callback) { | |
setTimeout(callback, 0); | |
}; | |
if (typeof window !== "undefined" && typeof window.postMessage === "function") { | |
let handler2 = function(event) { | |
if (event.source === window && event.data === msg) { | |
event.stopPropagation(); | |
var copy = callbacks.slice(); | |
callbacks.length = 0; | |
copy.forEach(function(callback) { | |
callback(); | |
}); | |
} | |
}; | |
var handler = handler2; | |
var msg = "forge.setImmediate"; | |
var callbacks = []; | |
util2.setImmediate = function(callback) { | |
callbacks.push(callback); | |
if (callbacks.length === 1) { | |
window.postMessage(msg, "*"); | |
} | |
}; | |
window.addEventListener("message", handler2, true); | |
} | |
if (typeof MutationObserver !== "undefined") { | |
var now = Date.now(); | |
var attr = true; | |
var div = document.createElement("div"); | |
var callbacks = []; | |
new MutationObserver(function() { | |
var copy = callbacks.slice(); | |
callbacks.length = 0; | |
copy.forEach(function(callback) { | |
callback(); | |
}); | |
}).observe(div, { attributes: true }); | |
var oldSetImmediate = util2.setImmediate; | |
util2.setImmediate = function(callback) { | |
if (Date.now() - now > 15) { | |
now = Date.now(); | |
oldSetImmediate(callback); | |
} else { | |
callbacks.push(callback); | |
if (callbacks.length === 1) { | |
div.setAttribute("a", attr = !attr); | |
} | |
} | |
}; | |
} | |
util2.nextTick = util2.setImmediate; | |
})(); | |
util2.isNodejs = typeof process !== "undefined" && process.versions && process.versions.node; | |
util2.globalScope = function() { | |
if (util2.isNodejs) { | |
return globalThis; | |
} | |
return typeof self === "undefined" ? window : self; | |
}(); | |
util2.isArray = Array.isArray || function(x) { | |
return Object.prototype.toString.call(x) === "[object Array]"; | |
}; | |
util2.isArrayBuffer = function(x) { | |
return typeof ArrayBuffer !== "undefined" && x instanceof ArrayBuffer; | |
}; | |
util2.isArrayBufferView = function(x) { | |
return x && util2.isArrayBuffer(x.buffer) && x.byteLength !== void 0; | |
}; | |
function _checkBitsParam(n) { | |
if (!(n === 8 || n === 16 || n === 24 || n === 32)) { | |
throw new Error("Only 8, 16, 24, or 32 bits supported: " + n); | |
} | |
} | |
util2.ByteBuffer = ByteStringBuffer; | |
function ByteStringBuffer(b) { | |
this.data = ""; | |
this.read = 0; | |
if (typeof b === "string") { | |
this.data = b; | |
} else if (util2.isArrayBuffer(b) || util2.isArrayBufferView(b)) { | |
if (typeof Buffer !== "undefined" && b instanceof Buffer) { | |
this.data = b.toString("binary"); | |
} else { | |
var arr = new Uint8Array(b); | |
try { | |
this.data = String.fromCharCode.apply(null, arr); | |
} catch (e) { | |
for (var i = 0; i < arr.length; ++i) { | |
this.putByte(arr[i]); | |
} | |
} | |
} | |
} else if (b instanceof ByteStringBuffer || typeof b === "object" && typeof b.data === "string" && typeof b.read === "number") { | |
this.data = b.data; | |
this.read = b.read; | |
} | |
this._constructedStringLength = 0; | |
} | |
util2.ByteStringBuffer = ByteStringBuffer; | |
var _MAX_CONSTRUCTED_STRING_LENGTH = 4096; | |
util2.ByteStringBuffer.prototype._optimizeConstructedString = function(x) { | |
this._constructedStringLength += x; | |
if (this._constructedStringLength > _MAX_CONSTRUCTED_STRING_LENGTH) { | |
this.data.substr(0, 1); | |
this._constructedStringLength = 0; | |
} | |
}; | |
util2.ByteStringBuffer.prototype.length = function() { | |
return this.data.length - this.read; | |
}; | |
util2.ByteStringBuffer.prototype.isEmpty = function() { | |
return this.length() <= 0; | |
}; | |
util2.ByteStringBuffer.prototype.putByte = function(b) { | |
return this.putBytes(String.fromCharCode(b)); | |
}; | |
util2.ByteStringBuffer.prototype.fillWithByte = function(b, n) { | |
b = String.fromCharCode(b); | |
var d = this.data; | |
while (n > 0) { | |
if (n & 1) { | |
d += b; | |
} | |
n >>>= 1; | |
if (n > 0) { | |
b += b; | |
} | |
} | |
this.data = d; | |
this._optimizeConstructedString(n); | |
return this; | |
}; | |
util2.ByteStringBuffer.prototype.putBytes = function(bytes3) { | |
this.data += bytes3; | |
this._optimizeConstructedString(bytes3.length); | |
return this; | |
}; | |
util2.ByteStringBuffer.prototype.putString = function(str) { | |
return this.putBytes(util2.encodeUtf8(str)); | |
}; | |
util2.ByteStringBuffer.prototype.putInt16 = function(i) { | |
return this.putBytes( | |
String.fromCharCode(i >> 8 & 255) + String.fromCharCode(i & 255) | |
); | |
}; | |
util2.ByteStringBuffer.prototype.putInt24 = function(i) { | |
return this.putBytes( | |
String.fromCharCode(i >> 16 & 255) + String.fromCharCode(i >> 8 & 255) + String.fromCharCode(i & 255) | |
); | |
}; | |
util2.ByteStringBuffer.prototype.putInt32 = function(i) { | |
return this.putBytes( | |
String.fromCharCode(i >> 24 & 255) + String.fromCharCode(i >> 16 & 255) + String.fromCharCode(i >> 8 & 255) + String.fromCharCode(i & 255) | |
); | |
}; | |
util2.ByteStringBuffer.prototype.putInt16Le = function(i) { | |
return this.putBytes( | |
String.fromCharCode(i & 255) + String.fromCharCode(i >> 8 & 255) | |
); | |
}; | |
util2.ByteStringBuffer.prototype.putInt24Le = function(i) { | |
return this.putBytes( | |
String.fromCharCode(i & 255) + String.fromCharCode(i >> 8 & 255) + String.fromCharCode(i >> 16 & 255) | |
); | |
}; | |
util2.ByteStringBuffer.prototype.putInt32Le = function(i) { | |
return this.putBytes( | |
String.fromCharCode(i & 255) + String.fromCharCode(i >> 8 & 255) + String.fromCharCode(i >> 16 & 255) + String.fromCharCode(i >> 24 & 255) | |
); | |
}; | |
util2.ByteStringBuffer.prototype.putInt = function(i, n) { | |
_checkBitsParam(n); | |
var bytes3 = ""; | |
do { | |
n -= 8; | |
bytes3 += String.fromCharCode(i >> n & 255); | |
} while (n > 0); | |
return this.putBytes(bytes3); | |
}; | |
util2.ByteStringBuffer.prototype.putSignedInt = function(i, n) { | |
if (i < 0) { | |
i += 2 << n - 1; | |
} | |
return this.putInt(i, n); | |
}; | |
util2.ByteStringBuffer.prototype.putBuffer = function(buffer3) { | |
return this.putBytes(buffer3.getBytes()); | |
}; | |
util2.ByteStringBuffer.prototype.getByte = function() { | |
return this.data.charCodeAt(this.read++); | |
}; | |
util2.ByteStringBuffer.prototype.getInt16 = function() { | |
var rval = this.data.charCodeAt(this.read) << 8 ^ this.data.charCodeAt(this.read + 1); | |
this.read += 2; | |
return rval; | |
}; | |
util2.ByteStringBuffer.prototype.getInt24 = function() { | |
var rval = this.data.charCodeAt(this.read) << 16 ^ this.data.charCodeAt(this.read + 1) << 8 ^ this.data.charCodeAt(this.read + 2); | |
this.read += 3; | |
return rval; | |
}; | |
util2.ByteStringBuffer.prototype.getInt32 = function() { | |
var rval = this.data.charCodeAt(this.read) << 24 ^ this.data.charCodeAt(this.read + 1) << 16 ^ this.data.charCodeAt(this.read + 2) << 8 ^ this.data.charCodeAt(this.read + 3); | |
this.read += 4; | |
return rval; | |
}; | |
util2.ByteStringBuffer.prototype.getInt16Le = function() { | |
var rval = this.data.charCodeAt(this.read) ^ this.data.charCodeAt(this.read + 1) << 8; | |
this.read += 2; | |
return rval; | |
}; | |
util2.ByteStringBuffer.prototype.getInt24Le = function() { | |
var rval = this.data.charCodeAt(this.read) ^ this.data.charCodeAt(this.read + 1) << 8 ^ this.data.charCodeAt(this.read + 2) << 16; | |
this.read += 3; | |
return rval; | |
}; | |
util2.ByteStringBuffer.prototype.getInt32Le = function() { | |
var rval = this.data.charCodeAt(this.read) ^ this.data.charCodeAt(this.read + 1) << 8 ^ this.data.charCodeAt(this.read + 2) << 16 ^ this.data.charCodeAt(this.read + 3) << 24; | |
this.read += 4; | |
return rval; | |
}; | |
util2.ByteStringBuffer.prototype.getInt = function(n) { | |
_checkBitsParam(n); | |
var rval = 0; | |
do { | |
rval = (rval << 8) + this.data.charCodeAt(this.read++); | |
n -= 8; | |
} while (n > 0); | |
return rval; | |
}; | |
util2.ByteStringBuffer.prototype.getSignedInt = function(n) { | |
var x = this.getInt(n); | |
var max = 2 << n - 2; | |
if (x >= max) { | |
x -= max << 1; | |
} | |
return x; | |
}; | |
util2.ByteStringBuffer.prototype.getBytes = function(count) { | |
var rval; | |
if (count) { | |
count = Math.min(this.length(), count); | |
rval = this.data.slice(this.read, this.read + count); | |
this.read += count; | |
} else if (count === 0) { | |
rval = ""; | |
} else { | |
rval = this.read === 0 ? this.data : this.data.slice(this.read); | |
this.clear(); | |
} | |
return rval; | |
}; | |
util2.ByteStringBuffer.prototype.bytes = function(count) { | |
return typeof count === "undefined" ? this.data.slice(this.read) : this.data.slice(this.read, this.read + count); | |
}; | |
util2.ByteStringBuffer.prototype.at = function(i) { | |
return this.data.charCodeAt(this.read + i); | |
}; | |
util2.ByteStringBuffer.prototype.setAt = function(i, b) { | |
this.data = this.data.substr(0, this.read + i) + String.fromCharCode(b) + this.data.substr(this.read + i + 1); | |
return this; | |
}; | |
util2.ByteStringBuffer.prototype.last = function() { | |
return this.data.charCodeAt(this.data.length - 1); | |
}; | |
util2.ByteStringBuffer.prototype.copy = function() { | |
var c = util2.createBuffer(this.data); | |
c.read = this.read; | |
return c; | |
}; | |
util2.ByteStringBuffer.prototype.compact = function() { | |
if (this.read > 0) { | |
this.data = this.data.slice(this.read); | |
this.read = 0; | |
} | |
return this; | |
}; | |
util2.ByteStringBuffer.prototype.clear = function() { | |
this.data = ""; | |
this.read = 0; | |
return this; | |
}; | |
util2.ByteStringBuffer.prototype.truncate = function(count) { | |
var len = Math.max(0, this.length() - count); | |
this.data = this.data.substr(this.read, len); | |
this.read = 0; | |
return this; | |
}; | |
util2.ByteStringBuffer.prototype.toHex = function() { | |
var rval = ""; | |
for (var i = this.read; i < this.data.length; ++i) { | |
var b = this.data.charCodeAt(i); | |
if (b < 16) { | |
rval += "0"; | |
} | |
rval += b.toString(16); | |
} | |
return rval; | |
}; | |
util2.ByteStringBuffer.prototype.toString = function() { | |
return util2.decodeUtf8(this.bytes()); | |
}; | |
function DataBuffer(b, options) { | |
options = options || {}; | |
this.read = options.readOffset || 0; | |
this.growSize = options.growSize || 1024; | |
var isArrayBuffer2 = util2.isArrayBuffer(b); | |
var isArrayBufferView = util2.isArrayBufferView(b); | |
if (isArrayBuffer2 || isArrayBufferView) { | |
if (isArrayBuffer2) { | |
this.data = new DataView(b); | |
} else { | |
this.data = new DataView(b.buffer, b.byteOffset, b.byteLength); | |
} | |
this.write = "writeOffset" in options ? options.writeOffset : this.data.byteLength; | |
return; | |
} | |
this.data = new DataView(new ArrayBuffer(0)); | |
this.write = 0; | |
if (b !== null && b !== void 0) { | |
this.putBytes(b); | |
} | |
if ("writeOffset" in options) { | |
this.write = options.writeOffset; | |
} | |
} | |
util2.DataBuffer = DataBuffer; | |
util2.DataBuffer.prototype.length = function() { | |
return this.write - this.read; | |
}; | |
util2.DataBuffer.prototype.isEmpty = function() { | |
return this.length() <= 0; | |
}; | |
util2.DataBuffer.prototype.accommodate = function(amount, growSize) { | |
if (this.length() >= amount) { | |
return this; | |
} | |
growSize = Math.max(growSize || this.growSize, amount); | |
var src11 = new Uint8Array( | |
this.data.buffer, | |
this.data.byteOffset, | |
this.data.byteLength | |
); | |
var dst = new Uint8Array(this.length() + growSize); | |
dst.set(src11); | |
this.data = new DataView(dst.buffer); | |
return this; | |
}; | |
util2.DataBuffer.prototype.putByte = function(b) { | |
this.accommodate(1); | |
this.data.setUint8(this.write++, b); | |
return this; | |
}; | |
util2.DataBuffer.prototype.fillWithByte = function(b, n) { | |
this.accommodate(n); | |
for (var i = 0; i < n; ++i) { | |
this.data.setUint8(b); | |
} | |
return this; | |
}; | |
util2.DataBuffer.prototype.putBytes = function(bytes3, encoding) { | |
if (util2.isArrayBufferView(bytes3)) { | |
var src11 = new Uint8Array(bytes3.buffer, bytes3.byteOffset, bytes3.byteLength); | |
var len = src11.byteLength - src11.byteOffset; | |
this.accommodate(len); | |
var dst = new Uint8Array(this.data.buffer, this.write); | |
dst.set(src11); | |
this.write += len; | |
return this; | |
} | |
if (util2.isArrayBuffer(bytes3)) { | |
var src11 = new Uint8Array(bytes3); | |
this.accommodate(src11.byteLength); | |
var dst = new Uint8Array(this.data.buffer); | |
dst.set(src11, this.write); | |
this.write += src11.byteLength; | |
return this; | |
} | |
if (bytes3 instanceof util2.DataBuffer || typeof bytes3 === "object" && typeof bytes3.read === "number" && typeof bytes3.write === "number" && util2.isArrayBufferView(bytes3.data)) { | |
var src11 = new Uint8Array(bytes3.data.byteLength, bytes3.read, bytes3.length()); | |
this.accommodate(src11.byteLength); | |
var dst = new Uint8Array(bytes3.data.byteLength, this.write); | |
dst.set(src11); | |
this.write += src11.byteLength; | |
return this; | |
} | |
if (bytes3 instanceof util2.ByteStringBuffer) { | |
bytes3 = bytes3.data; | |
encoding = "binary"; | |
} | |
encoding = encoding || "binary"; | |
if (typeof bytes3 === "string") { | |
var view; | |
if (encoding === "hex") { | |
this.accommodate(Math.ceil(bytes3.length / 2)); | |
view = new Uint8Array(this.data.buffer, this.write); | |
this.write += util2.binary.hex.decode(bytes3, view, this.write); | |
return this; | |
} | |
if (encoding === "base64") { | |
this.accommodate(Math.ceil(bytes3.length / 4) * 3); | |
view = new Uint8Array(this.data.buffer, this.write); | |
this.write += util2.binary.base64.decode(bytes3, view, this.write); | |
return this; | |
} | |
if (encoding === "utf8") { | |
bytes3 = util2.encodeUtf8(bytes3); | |
encoding = "binary"; | |
} | |
if (encoding === "binary" || encoding === "raw") { | |
this.accommodate(bytes3.length); | |
view = new Uint8Array(this.data.buffer, this.write); | |
this.write += util2.binary.raw.decode(view); | |
return this; | |
} | |
if (encoding === "utf16") { | |
this.accommodate(bytes3.length * 2); | |
view = new Uint16Array(this.data.buffer, this.write); | |
this.write += util2.text.utf16.encode(view); | |
return this; | |
} | |
throw new Error("Invalid encoding: " + encoding); | |
} | |
throw Error("Invalid parameter: " + bytes3); | |
}; | |
util2.DataBuffer.prototype.putBuffer = function(buffer3) { | |
this.putBytes(buffer3); | |
buffer3.clear(); | |
return this; | |
}; | |
util2.DataBuffer.prototype.putString = function(str) { | |
return this.putBytes(str, "utf16"); | |
}; | |
util2.DataBuffer.prototype.putInt16 = function(i) { | |
this.accommodate(2); | |
this.data.setInt16(this.write, i); | |
this.write += 2; | |
return this; | |
}; | |
util2.DataBuffer.prototype.putInt24 = function(i) { | |
this.accommodate(3); | |
this.data.setInt16(this.write, i >> 8 & 65535); | |
this.data.setInt8(this.write, i >> 16 & 255); | |
this.write += 3; | |
return this; | |
}; | |
util2.DataBuffer.prototype.putInt32 = function(i) { | |
this.accommodate(4); | |
this.data.setInt32(this.write, i); | |
this.write += 4; | |
return this; | |
}; | |
util2.DataBuffer.prototype.putInt16Le = function(i) { | |
this.accommodate(2); | |
this.data.setInt16(this.write, i, true); | |
this.write += 2; | |
return this; | |
}; | |
util2.DataBuffer.prototype.putInt24Le = function(i) { | |
this.accommodate(3); | |
this.data.setInt8(this.write, i >> 16 & 255); | |
this.data.setInt16(this.write, i >> 8 & 65535, true); | |
this.write += 3; | |
return this; | |
}; | |
util2.DataBuffer.prototype.putInt32Le = function(i) { | |
this.accommodate(4); | |
this.data.setInt32(this.write, i, true); | |
this.write += 4; | |
return this; | |
}; | |
util2.DataBuffer.prototype.putInt = function(i, n) { | |
_checkBitsParam(n); | |
this.accommodate(n / 8); | |
do { | |
n -= 8; | |
this.data.setInt8(this.write++, i >> n & 255); | |
} while (n > 0); | |
return this; | |
}; | |
util2.DataBuffer.prototype.putSignedInt = function(i, n) { | |
_checkBitsParam(n); | |
this.accommodate(n / 8); | |
if (i < 0) { | |
i += 2 << n - 1; | |
} | |
return this.putInt(i, n); | |
}; | |
util2.DataBuffer.prototype.getByte = function() { | |
return this.data.getInt8(this.read++); | |
}; | |
util2.DataBuffer.prototype.getInt16 = function() { | |
var rval = this.data.getInt16(this.read); | |
this.read += 2; | |
return rval; | |
}; | |
util2.DataBuffer.prototype.getInt24 = function() { | |
var rval = this.data.getInt16(this.read) << 8 ^ this.data.getInt8(this.read + 2); | |
this.read += 3; | |
return rval; | |
}; | |
util2.DataBuffer.prototype.getInt32 = function() { | |
var rval = this.data.getInt32(this.read); | |
this.read += 4; | |
return rval; | |
}; | |
util2.DataBuffer.prototype.getInt16Le = function() { | |
var rval = this.data.getInt16(this.read, true); | |
this.read += 2; | |
return rval; | |
}; | |
util2.DataBuffer.prototype.getInt24Le = function() { | |
var rval = this.data.getInt8(this.read) ^ this.data.getInt16(this.read + 1, true) << 8; | |
this.read += 3; | |
return rval; | |
}; | |
util2.DataBuffer.prototype.getInt32Le = function() { | |
var rval = this.data.getInt32(this.read, true); | |
this.read += 4; | |
return rval; | |
}; | |
util2.DataBuffer.prototype.getInt = function(n) { | |
_checkBitsParam(n); | |
var rval = 0; | |
do { | |
rval = (rval << 8) + this.data.getInt8(this.read++); | |
n -= 8; | |
} while (n > 0); | |
return rval; | |
}; | |
util2.DataBuffer.prototype.getSignedInt = function(n) { | |
var x = this.getInt(n); | |
var max = 2 << n - 2; | |
if (x >= max) { | |
x -= max << 1; | |
} | |
return x; | |
}; | |
util2.DataBuffer.prototype.getBytes = function(count) { | |
var rval; | |
if (count) { | |
count = Math.min(this.length(), count); | |
rval = this.data.slice(this.read, this.read + count); | |
this.read += count; | |
} else if (count === 0) { | |
rval = ""; | |
} else { | |
rval = this.read === 0 ? this.data : this.data.slice(this.read); | |
this.clear(); | |
} | |
return rval; | |
}; | |
util2.DataBuffer.prototype.bytes = function(count) { | |
return typeof count === "undefined" ? this.data.slice(this.read) : this.data.slice(this.read, this.read + count); | |
}; | |
util2.DataBuffer.prototype.at = function(i) { | |
return this.data.getUint8(this.read + i); | |
}; | |
util2.DataBuffer.prototype.setAt = function(i, b) { | |
this.data.setUint8(i, b); | |
return this; | |
}; | |
util2.DataBuffer.prototype.last = function() { | |
return this.data.getUint8(this.write - 1); | |
}; | |
util2.DataBuffer.prototype.copy = function() { | |
return new util2.DataBuffer(this); | |
}; | |
util2.DataBuffer.prototype.compact = function() { | |
if (this.read > 0) { | |
var src11 = new Uint8Array(this.data.buffer, this.read); | |
var dst = new Uint8Array(src11.byteLength); | |
dst.set(src11); | |
this.data = new DataView(dst); | |
this.write -= this.read; | |
this.read = 0; | |
} | |
return this; | |
}; | |
util2.DataBuffer.prototype.clear = function() { | |
this.data = new DataView(new ArrayBuffer(0)); | |
this.read = this.write = 0; | |
return this; | |
}; | |
util2.DataBuffer.prototype.truncate = function(count) { | |
this.write = Math.max(0, this.length() - count); | |
this.read = Math.min(this.read, this.write); | |
return this; | |
}; | |
util2.DataBuffer.prototype.toHex = function() { | |
var rval = ""; | |
for (var i = this.read; i < this.data.byteLength; ++i) { | |
var b = this.data.getUint8(i); | |
if (b < 16) { | |
rval += "0"; | |
} | |
rval += b.toString(16); | |
} | |
return rval; | |
}; | |
util2.DataBuffer.prototype.toString = function(encoding) { | |
var view = new Uint8Array(this.data, this.read, this.length()); | |
encoding = encoding || "utf8"; | |
if (encoding === "binary" || encoding === "raw") { | |
return util2.binary.raw.encode(view); | |
} | |
if (encoding === "hex") { | |
return util2.binary.hex.encode(view); | |
} | |
if (encoding === "base64") { | |
return util2.binary.base64.encode(view); | |
} | |
if (encoding === "utf8") { | |
return util2.text.utf8.decode(view); | |
} | |
if (encoding === "utf16") { | |
return util2.text.utf16.decode(view); | |
} | |
throw new Error("Invalid encoding: " + encoding); | |
}; | |
util2.createBuffer = function(input, encoding) { | |
encoding = encoding || "raw"; | |
if (input !== void 0 && encoding === "utf8") { | |
input = util2.encodeUtf8(input); | |
} | |
return new util2.ByteBuffer(input); | |
}; | |
util2.fillString = function(c, n) { | |
var s = ""; | |
while (n > 0) { | |
if (n & 1) { | |
s += c; | |
} | |
n >>>= 1; | |
if (n > 0) { | |
c += c; | |
} | |
} | |
return s; | |
}; | |
util2.xorBytes = function(s1, s2, n) { | |
var s3 = ""; | |
var b = ""; | |
var t = ""; | |
var i = 0; | |
var c = 0; | |
for (; n > 0; --n, ++i) { | |
b = s1.charCodeAt(i) ^ s2.charCodeAt(i); | |
if (c >= 10) { | |
s3 += t; | |
t = ""; | |
c = 0; | |
} | |
t += String.fromCharCode(b); | |
++c; | |
} | |
s3 += t; | |
return s3; | |
}; | |
util2.hexToBytes = function(hex) { | |
var rval = ""; | |
var i = 0; | |
if (hex.length & true) { | |
i = 1; | |
rval += String.fromCharCode(parseInt(hex[0], 16)); | |
} | |
for (; i < hex.length; i += 2) { | |
rval += String.fromCharCode(parseInt(hex.substr(i, 2), 16)); | |
} | |
return rval; | |
}; | |
util2.bytesToHex = function(bytes3) { | |
return util2.createBuffer(bytes3).toHex(); | |
}; | |
util2.int32ToBytes = function(i) { | |
return String.fromCharCode(i >> 24 & 255) + String.fromCharCode(i >> 16 & 255) + String.fromCharCode(i >> 8 & 255) + String.fromCharCode(i & 255); | |
}; | |
var _base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; | |
var _base64Idx = [ | |
/*43 -43 = 0*/ | |
/*'+', 1, 2, 3,'/' */ | |
62, | |
-1, | |
-1, | |
-1, | |
63, | |
/*'0','1','2','3','4','5','6','7','8','9' */ | |
52, | |
53, | |
54, | |
55, | |
56, | |
57, | |
58, | |
59, | |
60, | |
61, | |
/*15, 16, 17,'=', 19, 20, 21 */ | |
-1, | |
-1, | |
-1, | |
64, | |
-1, | |
-1, | |
-1, | |
/*65 - 43 = 22*/ | |
/*'A','B','C','D','E','F','G','H','I','J','K','L','M', */ | |
0, | |
1, | |
2, | |
3, | |
4, | |
5, | |
6, | |
7, | |
8, | |
9, | |
10, | |
11, | |
12, | |
/*'N','O','P','Q','R','S','T','U','V','W','X','Y','Z' */ | |
13, | |
14, | |
15, | |
16, | |
17, | |
18, | |
19, | |
20, | |
21, | |
22, | |
23, | |
24, | |
25, | |
/*91 - 43 = 48 */ | |
/*48, 49, 50, 51, 52, 53 */ | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
-1, | |
/*97 - 43 = 54*/ | |
/*'a','b','c','d','e','f','g','h','i','j','k','l','m' */ | |
26, | |
27, | |
28, | |
29, | |
30, | |
31, | |
32, | |
33, | |
34, | |
35, | |
36, | |
37, | |
38, | |
/*'n','o','p','q','r','s','t','u','v','w','x','y','z' */ | |
39, | |
40, | |
41, | |
42, | |
43, | |
44, | |
45, | |
46, | |
47, | |
48, | |
49, | |
50, | |
51 | |
]; | |
var _base58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; | |
util2.encode64 = function(input, maxline) { | |
var line = ""; | |
var output3 = ""; | |
var chr1, chr2, chr3; | |
var i = 0; | |
while (i < input.length) { | |
chr1 = input.charCodeAt(i++); | |
chr2 = input.charCodeAt(i++); | |
chr3 = input.charCodeAt(i++); | |
line += _base64.charAt(chr1 >> 2); | |
line += _base64.charAt((chr1 & 3) << 4 | chr2 >> 4); | |
if (isNaN(chr2)) { | |
line += "=="; | |
} else { | |
line += _base64.charAt((chr2 & 15) << 2 | chr3 >> 6); | |
line += isNaN(chr3) ? "=" : _base64.charAt(chr3 & 63); | |
} | |
if (maxline && line.length > maxline) { | |
output3 += line.substr(0, maxline) + "\r\n"; | |
line = line.substr(maxline); | |
} | |
} | |
output3 += line; | |
return output3; | |
}; | |
util2.decode64 = function(input) { | |
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); | |
var output3 = ""; | |
var enc1, enc2, enc3, enc4; | |
var i = 0; | |
while (i < input.length) { | |
enc1 = _base64Idx[input.charCodeAt(i++) - 43]; | |
enc2 = _base64Idx[input.charCodeAt(i++) - 43]; | |
enc3 = _base64Idx[input.charCodeAt(i++) - 43]; | |
enc4 = _base64Idx[input.charCodeAt(i++) - 43]; | |
output3 += String.fromCharCode(enc1 << 2 | enc2 >> 4); | |
if (enc3 !== 64) { | |
output3 += String.fromCharCode((enc2 & 15) << 4 | enc3 >> 2); | |
if (enc4 !== 64) { | |
output3 += String.fromCharCode((enc3 & 3) << 6 | enc4); | |
} | |
} | |
} | |
return output3; | |
}; | |
util2.encodeUtf8 = function(str) { | |
return unescape(encodeURIComponent(str)); | |
}; | |
util2.decodeUtf8 = function(str) { | |
return decodeURIComponent(escape(str)); | |
}; | |
util2.binary = { | |
raw: {}, | |
hex: {}, | |
base64: {}, | |
base58: {}, | |
baseN: { | |
encode: baseN.encode, | |
decode: baseN.decode | |
} | |
}; | |
util2.binary.raw.encode = function(bytes3) { | |
return String.fromCharCode.apply(null, bytes3); | |
}; | |
util2.binary.raw.decode = function(str, output3, offset) { | |
var out = output3; | |
if (!out) { | |
out = new Uint8Array(str.length); | |
} | |
offset = offset || 0; | |
var j = offset; | |
for (var i = 0; i < str.length; ++i) { | |
out[j++] = str.charCodeAt(i); | |
} | |
return output3 ? j - offset : out; | |
}; | |
util2.binary.hex.encode = util2.bytesToHex; | |
util2.binary.hex.decode = function(hex, output3, offset) { | |
var out = output3; | |
if (!out) { | |
out = new Uint8Array(Math.ceil(hex.length / 2)); | |
} | |
offset = offset || 0; | |
var i = 0, j = offset; | |
if (hex.length & 1) { | |
i = 1; | |
out[j++] = parseInt(hex[0], 16); | |
} | |
for (; i < hex.length; i += 2) { | |
out[j++] = parseInt(hex.substr(i, 2), 16); | |
} | |
return output3 ? j - offset : out; | |
}; | |
util2.binary.base64.encode = function(input, maxline) { | |
var line = ""; | |
var output3 = ""; | |
var chr1, chr2, chr3; | |
var i = 0; | |
while (i < input.byteLength) { | |
chr1 = input[i++]; | |
chr2 = input[i++]; | |
chr3 = input[i++]; | |
line += _base64.charAt(chr1 >> 2); | |
line += _base64.charAt((chr1 & 3) << 4 | chr2 >> 4); | |
if (isNaN(chr2)) { | |
line += "=="; | |
} else { | |
line += _base64.charAt((chr2 & 15) << 2 | chr3 >> 6); | |
line += isNaN(chr3) ? "=" : _base64.charAt(chr3 & 63); | |
} | |
if (maxline && line.length > maxline) { | |
output3 += line.substr(0, maxline) + "\r\n"; | |
line = line.substr(maxline); | |
} | |
} | |
output3 += line; | |
return output3; | |
}; | |
util2.binary.base64.decode = function(input, output3, offset) { | |
var out = output3; | |
if (!out) { | |
out = new Uint8Array(Math.ceil(input.length / 4) * 3); | |
} | |
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); | |
offset = offset || 0; | |
var enc1, enc2, enc3, enc4; | |
var i = 0, j = offset; | |
while (i < input.length) { | |
enc1 = _base64Idx[input.charCodeAt(i++) - 43]; | |
enc2 = _base64Idx[input.charCodeAt(i++) - 43]; | |
enc3 = _base64Idx[input.charCodeAt(i++) - 43]; | |
enc4 = _base64Idx[input.charCodeAt(i++) - 43]; | |
out[j++] = enc1 << 2 | enc2 >> 4; | |
if (enc3 !== 64) { | |
out[j++] = (enc2 & 15) << 4 | enc3 >> 2; | |
if (enc4 !== 64) { | |
out[j++] = (enc3 & 3) << 6 | enc4; | |
} | |
} | |
} | |
return output3 ? j - offset : out.subarray(0, j); | |
}; | |
util2.binary.base58.encode = function(input, maxline) { | |
return util2.binary.baseN.encode(input, _base58, maxline); | |
}; | |
util2.binary.base58.decode = function(input, maxline) { | |
return util2.binary.baseN.decode(input, _base58, maxline); | |
}; | |
util2.text = { | |
utf8: {}, | |
utf16: {} | |
}; | |
util2.text.utf8.encode = function(str, output3, offset) { | |
str = util2.encodeUtf8(str); | |
var out = output3; | |
if (!out) { | |
out = new Uint8Array(str.length); | |
} | |
offset = offset || 0; | |
var j = offset; | |
for (var i = 0; i < str.length; ++i) { | |
out[j++] = str.charCodeAt(i); | |
} | |
return output3 ? j - offset : out; | |
}; | |
util2.text.utf8.decode = function(bytes3) { | |
return util2.decodeUtf8(String.fromCharCode.apply(null, bytes3)); | |
}; | |
util2.text.utf16.encode = function(str, output3, offset) { | |
var out = output3; | |
if (!out) { | |
out = new Uint8Array(str.length * 2); | |
} | |
var view = new Uint16Array(out.buffer); | |
offset = offset || 0; | |
var j = offset; | |
var k = offset; | |
for (var i = 0; i < str.length; ++i) { | |
view[k++] = str.charCodeAt(i); | |
j += 2; | |
} | |
return output3 ? j - offset : out; | |
}; | |
util2.text.utf16.decode = function(bytes3) { | |
return String.fromCharCode.apply(null, new Uint16Array(bytes3.buffer)); | |
}; | |
util2.deflate = function(api, bytes3, raw) { | |
bytes3 = util2.decode64(api.deflate(util2.encode64(bytes3)).rval); | |
if (raw) { | |
var start = 2; | |
var flg = bytes3.charCodeAt(1); | |
if (flg & 32) { | |
start = 6; | |
} | |
bytes3 = bytes3.substring(start, bytes3.length - 4); | |
} | |
return bytes3; | |
}; | |
util2.inflate = function(api, bytes3, raw) { | |
var rval = api.inflate(util2.encode64(bytes3)).rval; | |
return rval === null ? null : util2.decode64(rval); | |
}; | |
var _setStorageObject = function(api, id, obj) { | |
if (!api) { | |
throw new Error("WebStorage not available."); | |
} | |
var rval; | |
if (obj === null) { | |
rval = api.removeItem(id); | |
} else { | |
obj = util2.encode64(JSON.stringify(obj)); | |
rval = api.setItem(id, obj); | |
} | |
if (typeof rval !== "undefined" && rval.rval !== true) { | |
var error = new Error(rval.error.message); | |
error.id = rval.error.id; | |
error.name = rval.error.name; | |
throw error; | |
} | |
}; | |
var _getStorageObject = function(api, id) { | |
if (!api) { | |
throw new Error("WebStorage not available."); | |
} | |
var rval = api.getItem(id); | |
if (api.init) { | |
if (rval.rval === null) { | |
if (rval.error) { | |
var error = new Error(rval.error.message); | |
error.id = rval.error.id; | |
error.name = rval.error.name; | |
throw error; | |
} | |
rval = null; | |
} else { | |
rval = rval.rval; | |
} | |
} | |
if (rval !== null) { | |
rval = JSON.parse(util2.decode64(rval)); | |
} | |
return rval; | |
}; | |
var _setItem = function(api, id, key, data) { | |
var obj = _getStorageObject(api, id); | |
if (obj === null) { | |
obj = {}; | |
} | |
obj[key] = data; | |
_setStorageObject(api, id, obj); | |
}; | |
var _getItem = function(api, id, key) { | |
var rval = _getStorageObject(api, id); | |
if (rval !== null) { | |
rval = key in rval ? rval[key] : null; | |
} | |
return rval; | |
}; | |
var _removeItem = function(api, id, key) { | |
var obj = _getStorageObject(api, id); | |
if (obj !== null && key in obj) { | |
delete obj[key]; | |
var empty11 = true; | |
for (var prop in obj) { | |
empty11 = false; | |
break; | |
} | |
if (empty11) { | |
obj = null; | |
} | |
_setStorageObject(api, id, obj); | |
} | |
}; | |
var _clearItems = function(api, id) { | |
_setStorageObject(api, id, null); | |
}; | |
var _callStorageFunction = function(func, args, location) { | |
var rval = null; | |
if (typeof location === "undefined") { | |
location = ["web", "flash"]; | |
} | |
var type; | |
var done = false; | |
var exception = null; | |
for (var idx in location) { | |
type = location[idx]; | |
try { | |
if (type === "flash" || type === "both") { | |
if (args[0] === null) { | |
throw new Error("Flash local storage not available."); | |
} | |
rval = func.apply(this, args); | |
done = type === "flash"; | |
} | |
if (type === "web" || type === "both") { | |
args[0] = localStorage; | |
rval = func.apply(this, args); | |
done = true; | |
} | |
} catch (ex) { | |
exception = ex; | |
} | |
if (done) { | |
break; | |
} | |
} | |
if (!done) { | |
throw exception; | |
} | |
return rval; | |
}; | |
util2.setItem = function(api, id, key, data, location) { | |
_callStorageFunction(_setItem, arguments, location); | |
}; | |
util2.getItem = function(api, id, key, location) { | |
return _callStorageFunction(_getItem, arguments, location); | |
}; | |
util2.removeItem = function(api, id, key, location) { | |
_callStorageFunction(_removeItem, arguments, location); | |
}; | |
util2.clearItems = function(api, id, location) { | |
_callStorageFunction(_clearItems, arguments, location); | |
}; | |
util2.isEmpty = function(obj) { | |
for (var prop in obj) { | |
if (obj.hasOwnProperty(prop)) { | |
return false; | |
} | |
} | |
return true; | |
}; | |
util2.format = function(format9) { | |
var re = /%./g; | |
var match; | |
var part; | |
var argi = 0; | |
var parts = []; | |
var last2 = 0; | |
while (match = re.exec(format9)) { | |
part = format9.substring(last2, re.lastIndex - 2); | |
if (part.length > 0) { | |
parts.push(part); | |
} | |
last2 = re.lastIndex; | |
var code9 = match[0][1]; | |
switch (code9) { | |
case "s": | |
case "o": | |
if (argi < arguments.length) { | |
parts.push(arguments[argi++ + 1]); | |
} else { | |
parts.push("<?>"); | |
} | |
break; | |
case "%": | |
parts.push("%"); | |
break; | |
default: | |
parts.push("<%" + code9 + "?>"); | |
} | |
} | |
parts.push(format9.substring(last2)); | |
return parts.join(""); | |
}; | |
util2.formatNumber = function(number3, decimals, dec_point, thousands_sep) { | |
var n = number3, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals; | |
var d = dec_point === void 0 ? "," : dec_point; | |
var t = thousands_sep === void 0 ? "." : thousands_sep, s = n < 0 ? "-" : ""; | |
var i = parseInt(n = Math.abs(+n || 0).toFixed(c), 10) + ""; | |
var j = i.length > 3 ? i.length % 3 : 0; | |
return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); | |
}; | |
util2.formatSize = function(size) { | |
if (size >= 1073741824) { | |
size = util2.formatNumber(size / 1073741824, 2, ".", "") + " GiB"; | |
} else if (size >= 1048576) { | |
size = util2.formatNumber(size / 1048576, 2, ".", "") + " MiB"; | |
} else if (size >= 1024) { | |
size = util2.formatNumber(size / 1024, 0) + " KiB"; | |
} else { | |
size = util2.formatNumber(size, 0) + " bytes"; | |
} | |
return size; | |
}; | |
util2.bytesFromIP = function(ip) { | |
if (ip.indexOf(".") !== -1) { | |
return util2.bytesFromIPv4(ip); | |
} | |
if (ip.indexOf(":") !== -1) { | |
return util2.bytesFromIPv6(ip); | |
} | |
return null; | |
}; | |
util2.bytesFromIPv4 = function(ip) { | |
ip = ip.split("."); | |
if (ip.length !== 4) { | |
return null; | |
} | |
var b = util2.createBuffer(); | |
for (var i = 0; i < ip.length; ++i) { | |
var num = parseInt(ip[i], 10); | |
if (isNaN(num)) { | |
return null; | |
} | |
b.putByte(num); | |
} | |
return b.getBytes(); | |
}; | |
util2.bytesFromIPv6 = function(ip) { | |
var blanks = 0; | |
ip = ip.split(":").filter(function(e) { | |
if (e.length === 0) | |
++blanks; | |
return true; | |
}); | |
var zeros = (8 - ip.length + blanks) * 2; | |
var b = util2.createBuffer(); | |
for (var i = 0; i < 8; ++i) { | |
if (!ip[i] || ip[i].length === 0) { | |
b.fillWithByte(0, zeros); | |
zeros = 0; | |
continue; | |
} | |
var bytes3 = util2.hexToBytes(ip[i]); | |
if (bytes3.length < 2) { | |
b.putByte(0); | |
} | |
b.putBytes(bytes3); | |
} | |
return b.getBytes(); | |
}; | |
util2.bytesToIP = function(bytes3) { | |
if (bytes3.length === 4) { | |
return util2.bytesToIPv4(bytes3); | |
} | |
if (bytes3.length === 16) { | |
return util2.bytesToIPv6(bytes3); | |
} | |
return null; | |
}; | |
util2.bytesToIPv4 = function(bytes3) { | |
if (bytes3.length !== 4) { | |
return null; | |
} | |
var ip = []; | |
for (var i = 0; i < bytes3.length; ++i) { | |
ip.push(bytes3.charCodeAt(i)); | |
} | |
return ip.join("."); | |
}; | |
util2.bytesToIPv6 = function(bytes3) { | |
if (bytes3.length !== 16) { | |
return null; | |
} | |
var ip = []; | |
var zeroGroups = []; | |
var zeroMaxGroup = 0; | |
for (var i = 0; i < bytes3.length; i += 2) { | |
var hex = util2.bytesToHex(bytes3[i] + bytes3[i + 1]); | |
while (hex[0] === "0" && hex !== "0") { | |
hex = hex.substr(1); | |
} | |
if (hex === "0") { | |
var last2 = zeroGroups[zeroGroups.length - 1]; | |
var idx = ip.length; | |
if (!last2 || idx !== last2.end + 1) { | |
zeroGroups.push({ start: idx, end: idx }); | |
} else { | |
last2.end = idx; | |
if (last2.end - last2.start > zeroGroups[zeroMaxGroup].end - zeroGroups[zeroMaxGroup].start) { | |
zeroMaxGroup = zeroGroups.length - 1; | |
} | |
} | |
} | |
ip.push(hex); | |
} | |
if (zeroGroups.length > 0) { | |
var group = zeroGroups[zeroMaxGroup]; | |
if (group.end - group.start > 0) { | |
ip.splice(group.start, group.end - group.start + 1, ""); | |
if (group.start === 0) { | |
ip.unshift(""); | |
} | |
if (group.end === 7) { | |
ip.push(""); | |
} | |
} | |
} | |
return ip.join(":"); | |
}; | |
util2.estimateCores = function(options, callback) { | |
if (typeof options === "function") { | |
callback = options; | |
options = {}; | |
} | |
options = options || {}; | |
if ("cores" in util2 && !options.update) { | |
return callback(null, util2.cores); | |
} | |
if (typeof navigator !== "undefined" && "hardwareConcurrency" in navigator && navigator.hardwareConcurrency > 0) { | |
util2.cores = navigator.hardwareConcurrency; | |
return callback(null, util2.cores); | |
} | |
if (typeof Worker === "undefined") { | |
util2.cores = 1; | |
return callback(null, util2.cores); | |
} | |
if (typeof Blob === "undefined") { | |
util2.cores = 2; | |
return callback(null, util2.cores); | |
} | |
var blobUrl = URL.createObjectURL(new Blob([ | |
"(", | |
function() { | |
self.addEventListener("message", function(e) { | |
var st = Date.now(); | |
var et = st + 4; | |
while (Date.now() < et) | |
; | |
self.postMessage({ st, et }); | |
}); | |
}.toString(), | |
")()" | |
], { type: "application/javascript" })); | |
sample([], 5, 16); | |
function sample(max, samples, numWorkers) { | |
if (samples === 0) { | |
var avg = Math.floor(max.reduce(function(avg2, x) { | |
return avg2 + x; | |
}, 0) / max.length); | |
util2.cores = Math.max(1, avg); | |
URL.revokeObjectURL(blobUrl); | |
return callback(null, util2.cores); | |
} | |
map3(numWorkers, function(err, results) { | |
max.push(reduce2(numWorkers, results)); | |
sample(max, samples - 1, numWorkers); | |
}); | |
} | |
function map3(numWorkers, callback2) { | |
var workers = []; | |
var results = []; | |
for (var i = 0; i < numWorkers; ++i) { | |
var worker = new Worker(blobUrl); | |
worker.addEventListener("message", function(e) { | |
results.push(e.data); | |
if (results.length === numWorkers) { | |
for (var i2 = 0; i2 < numWorkers; ++i2) { | |
workers[i2].terminate(); | |
} | |
callback2(null, results); | |
} | |
}); | |
workers.push(worker); | |
} | |
for (var i = 0; i < numWorkers; ++i) { | |
workers[i].postMessage(i); | |
} | |
} | |
function reduce2(numWorkers, results) { | |
var overlaps = []; | |
for (var n = 0; n < numWorkers; ++n) { | |
var r1 = results[n]; | |
var overlap = overlaps[n] = []; | |
for (var i = 0; i < numWorkers; ++i) { | |
if (n === i) { | |
continue; | |
} | |
var r2 = results[i]; | |
if (r1.st > r2.st && r1.st < r2.et || r2.st > r1.st && r2.st < r1.et) { | |
overlap.push(i); | |
} | |
} | |
} | |
return overlaps.reduce(function(max, overlap2) { | |
return Math.max(max, overlap2.length); | |
}, 0); | |
} | |
}; | |
} | |
}); | |
// node_modules/node-forge/lib/oids.js | |
var require_oids = __commonJS({ | |
"node_modules/node-forge/lib/oids.js"(exports2, module2) { | |
var forge7 = require_forge(); | |
forge7.pki = forge7.pki || {}; | |
var oids = module2.exports = forge7.pki.oids = forge7.oids = forge7.oids || {}; | |
function _IN(id, name8) { | |
oids[id] = name8; | |
oids[name8] = id; | |
} | |
function _I_(id, name8) { | |
oids[id] = name8; | |
} | |
_IN("1.2.840.113549.1.1.1", "rsaEncryption"); | |
_IN("1.2.840.113549.1.1.4", "md5WithRSAEncryption"); | |
_IN("1.2.840.113549.1.1.5", "sha1WithRSAEncryption"); | |
_IN("1.2.840.113549.1.1.7", "RSAES-OAEP"); | |
_IN("1.2.840.113549.1.1.8", "mgf1"); | |
_IN("1.2.840.113549.1.1.9", "pSpecified"); | |
_IN("1.2.840.113549.1.1.10", "RSASSA-PSS"); | |
_IN("1.2.840.113549.1.1.11", "sha256WithRSAEncryption"); | |
_IN("1.2.840.113549.1.1.12", "sha384WithRSAEncryption"); | |
_IN("1.2.840.113549.1.1.13", "sha512WithRSAEncryption"); | |
_IN("1.3.101.112", "EdDSA25519"); | |
_IN("1.2.840.10040.4.3", "dsa-with-sha1"); | |
_IN("1.3.14.3.2.7", "desCBC"); | |
_IN("1.3.14.3.2.26", "sha1"); | |
_IN("1.3.14.3.2.29", "sha1WithRSASignature"); | |
_IN("2.16.840.1.101.3.4.2.1", "sha256"); | |
_IN("2.16.840.1.101.3.4.2.2", "sha384"); | |
_IN("2.16.840.1.101.3.4.2.3", "sha512"); | |
_IN("2.16.840.1.101.3.4.2.4", "sha224"); | |
_IN("2.16.840.1.101.3.4.2.5", "sha512-224"); | |
_IN("2.16.840.1.101.3.4.2.6", "sha512-256"); | |
_IN("1.2.840.113549.2.2", "md2"); | |
_IN("1.2.840.113549.2.5", "md5"); | |
_IN("1.2.840.113549.1.7.1", "data"); | |
_IN("1.2.840.113549.1.7.2", "signedData"); | |
_IN("1.2.840.113549.1.7.3", "envelopedData"); | |
_IN("1.2.840.113549.1.7.4", "signedAndEnvelopedData"); | |
_IN("1.2.840.113549.1.7.5", "digestedData"); | |
_IN("1.2.840.113549.1.7.6", "encryptedData"); | |
_IN("1.2.840.113549.1.9.1", "emailAddress"); | |
_IN("1.2.840.113549.1.9.2", "unstructuredName"); | |
_IN("1.2.840.113549.1.9.3", "contentType"); | |
_IN("1.2.840.113549.1.9.4", "messageDigest"); | |
_IN("1.2.840.113549.1.9.5", "signingTime"); | |
_IN("1.2.840.113549.1.9.6", "counterSignature"); | |
_IN("1.2.840.113549.1.9.7", "challengePassword"); | |
_IN("1.2.840.113549.1.9.8", "unstructuredAddress"); | |
_IN("1.2.840.113549.1.9.14", "extensionRequest"); | |
_IN("1.2.840.113549.1.9.20", "friendlyName"); | |
_IN("1.2.840.113549.1.9.21", "localKeyId"); | |
_IN("1.2.840.113549.1.9.22.1", "x509Certificate"); | |
_IN("1.2.840.113549.1.12.10.1.1", "keyBag"); | |
_IN("1.2.840.113549.1.12.10.1.2", "pkcs8ShroudedKeyBag"); | |
_IN("1.2.840.113549.1.12.10.1.3", "certBag"); | |
_IN("1.2.840.113549.1.12.10.1.4", "crlBag"); | |
_IN("1.2.840.113549.1.12.10.1.5", "secretBag"); | |
_IN("1.2.840.113549.1.12.10.1.6", "safeContentsBag"); | |
_IN("1.2.840.113549.1.5.13", "pkcs5PBES2"); | |
_IN("1.2.840.113549.1.5.12", "pkcs5PBKDF2"); | |
_IN("1.2.840.113549.1.12.1.1", "pbeWithSHAAnd128BitRC4"); | |
_IN("1.2.840.113549.1.12.1.2", "pbeWithSHAAnd40BitRC4"); | |
_IN("1.2.840.113549.1.12.1.3", "pbeWithSHAAnd3-KeyTripleDES-CBC"); | |
_IN("1.2.840.113549.1.12.1.4", "pbeWithSHAAnd2-KeyTripleDES-CBC"); | |
_IN("1.2.840.113549.1.12.1.5", "pbeWithSHAAnd128BitRC2-CBC"); | |
_IN("1.2.840.113549.1.12.1.6", "pbewithSHAAnd40BitRC2-CBC"); | |
_IN("1.2.840.113549.2.7", "hmacWithSHA1"); | |
_IN("1.2.840.113549.2.8", "hmacWithSHA224"); | |
_IN("1.2.840.113549.2.9", "hmacWithSHA256"); | |
_IN("1.2.840.113549.2.10", "hmacWithSHA384"); | |
_IN("1.2.840.113549.2.11", "hmacWithSHA512"); | |
_IN("1.2.840.113549.3.7", "des-EDE3-CBC"); | |
_IN("2.16.840.1.101.3.4.1.2", "aes128-CBC"); | |
_IN("2.16.840.1.101.3.4.1.22", "aes192-CBC"); | |
_IN("2.16.840.1.101.3.4.1.42", "aes256-CBC"); | |
_IN("2.5.4.3", "commonName"); | |
_IN("2.5.4.4", "surname"); | |
_IN("2.5.4.5", "serialNumber"); | |
_IN("2.5.4.6", "countryName"); | |
_IN("2.5.4.7", "localityName"); | |
_IN("2.5.4.8", "stateOrProvinceName"); | |
_IN("2.5.4.9", "streetAddress"); | |
_IN("2.5.4.10", "organizationName"); | |
_IN("2.5.4.11", "organizationalUnitName"); | |
_IN("2.5.4.12", "title"); | |
_IN("2.5.4.13", "description"); | |
_IN("2.5.4.15", "businessCategory"); | |
_IN("2.5.4.17", "postalCode"); | |
_IN("2.5.4.42", "givenName"); | |
_IN("1.3.6.1.4.1.311.60.2.1.2", "jurisdictionOfIncorporationStateOrProvinceName"); | |
_IN("1.3.6.1.4.1.311.60.2.1.3", "jurisdictionOfIncorporationCountryName"); | |
_IN("2.16.840.1.113730.1.1", "nsCertType"); | |
_IN("2.16.840.1.113730.1.13", "nsComment"); | |
_I_("2.5.29.1", "authorityKeyIdentifier"); | |
_I_("2.5.29.2", "keyAttributes"); | |
_I_("2.5.29.3", "certificatePolicies"); | |
_I_("2.5.29.4", "keyUsageRestriction"); | |
_I_("2.5.29.5", "policyMapping"); | |
_I_("2.5.29.6", "subtreesConstraint"); | |
_I_("2.5.29.7", "subjectAltName"); | |
_I_("2.5.29.8", "issuerAltName"); | |
_I_("2.5.29.9", "subjectDirectoryAttributes"); | |
_I_("2.5.29.10", "basicConstraints"); | |
_I_("2.5.29.11", "nameConstraints"); | |
_I_("2.5.29.12", "policyConstraints"); | |
_I_("2.5.29.13", "basicConstraints"); | |
_IN("2.5.29.14", "subjectKeyIdentifier"); | |
_IN("2.5.29.15", "keyUsage"); | |
_I_("2.5.29.16", "privateKeyUsagePeriod"); | |
_IN("2.5.29.17", "subjectAltName"); | |
_IN("2.5.29.18", "issuerAltName"); | |
_IN("2.5.29.19", "basicConstraints"); | |
_I_("2.5.29.20", "cRLNumber"); | |
_I_("2.5.29.21", "cRLReason"); | |
_I_("2.5.29.22", "expirationDate"); | |
_I_("2.5.29.23", "instructionCode"); | |
_I_("2.5.29.24", "invalidityDate"); | |
_I_("2.5.29.25", "cRLDistributionPoints"); | |
_I_("2.5.29.26", "issuingDistributionPoint"); | |
_I_("2.5.29.27", "deltaCRLIndicator"); | |
_I_("2.5.29.28", "issuingDistributionPoint"); | |
_I_("2.5.29.29", "certificateIssuer"); | |
_I_("2.5.29.30", "nameConstraints"); | |
_IN("2.5.29.31", "cRLDistributionPoints"); | |
_IN("2.5.29.32", "certificatePolicies"); | |
_I_("2.5.29.33", "policyMappings"); | |
_I_("2.5.29.34", "policyConstraints"); | |
_IN("2.5.29.35", "authorityKeyIdentifier"); | |
_I_("2.5.29.36", "policyConstraints"); | |
_IN("2.5.29.37", "extKeyUsage"); | |
_I_("2.5.29.46", "freshestCRL"); | |
_I_("2.5.29.54", "inhibitAnyPolicy"); | |
_IN("1.3.6.1.4.1.11129.2.4.2", "timestampList"); | |
_IN("1.3.6.1.5.5.7.1.1", "authorityInfoAccess"); | |
_IN("1.3.6.1.5.5.7.3.1", "serverAuth"); | |
_IN("1.3.6.1.5.5.7.3.2", "clientAuth"); | |
_IN("1.3.6.1.5.5.7.3.3", "codeSigning"); | |
_IN("1.3.6.1.5.5.7.3.4", "emailProtection"); | |
_IN("1.3.6.1.5.5.7.3.8", "timeStamping"); | |
} | |
}); | |
// node_modules/node-forge/lib/asn1.js | |
var require_asn1 = __commonJS({ | |
"node_modules/node-forge/lib/asn1.js"(exports2, module2) { | |
var forge7 = require_forge(); | |
require_util(); | |
require_oids(); | |
var asn1 = module2.exports = forge7.asn1 = forge7.asn1 || {}; | |
asn1.Class = { | |
UNIVERSAL: 0, | |
APPLICATION: 64, | |
CONTEXT_SPECIFIC: 128, | |
PRIVATE: 192 | |
}; | |
asn1.Type = { | |
NONE: 0, | |
BOOLEAN: 1, | |
INTEGER: 2, | |
BITSTRING: 3, | |
OCTETSTRING: 4, | |
NULL: 5, | |
OID: 6, | |
ODESC: 7, | |
EXTERNAL: 8, | |
REAL: 9, | |
ENUMERATED: 10, | |
EMBEDDED: 11, | |
UTF8: 12, | |
ROID: 13, | |
SEQUENCE: 16, | |
SET: 17, | |
PRINTABLESTRING: 19, | |
IA5STRING: 22, | |
UTCTIME: 23, | |
GENERALIZEDTIME: 24, | |
BMPSTRING: 30 | |
}; | |
asn1.create = function(tagClass, type, constructed, value, options) { | |
if (forge7.util.isArray(value)) { | |
var tmp = []; | |
for (var i = 0; i < value.length; ++i) { | |
if (value[i] !== void 0) { | |
tmp.push(value[i]); | |
} | |
} | |
value = tmp; | |
} | |
var obj = { | |
tagClass, | |
type, | |
constructed, | |
composed: constructed || forge7.util.isArray(value), | |
value | |
}; | |
if (options && "bitStringContents" in options) { | |
obj.bitStringContents = options.bitStringContents; | |
obj.original = asn1.copy(obj); | |
} | |
return obj; | |
}; | |
asn1.copy = function(obj, options) { | |
var copy; | |
if (forge7.util.isArray(obj)) { | |
copy = []; | |
for (var i = 0; i < obj.length; ++i) { | |
copy.push(asn1.copy(obj[i], options)); | |
} | |
return copy; | |
} | |
if (typeof obj === "string") { | |
return obj; | |
} | |
copy = { | |
tagClass: obj.tagClass, | |
type: obj.type, | |
constructed: obj.constructed, | |
composed: obj.composed, | |
value: asn1.copy(obj.value, options) | |
}; | |
if (options && !options.excludeBitStringContents) { | |
copy.bitStringContents = obj.bitStringContents; | |
} | |
return copy; | |
}; | |
asn1.equals = function(obj1, obj2, options) { | |
if (forge7.util.isArray(obj1)) { | |
if (!forge7.util.isArray(obj2)) { | |
return false; | |
} | |
if (obj1.length !== obj2.length) { | |
return false; | |
} | |
for (var i = 0; i < obj1.length; ++i) { | |
if (!asn1.equals(obj1[i], obj2[i])) { | |
return false; | |
} | |
} | |
return true; | |
} | |
if (typeof obj1 !== typeof obj2) { | |
return false; | |
} | |
if (typeof obj1 === "string") { | |
return obj1 === obj2; | |
} | |
var equal = obj1.tagClass === obj2.tagClass && obj1.type === obj2.type && obj1.constructed === obj2.constructed && obj1.composed === obj2.composed && asn1.equals(obj1.value, obj2.value); | |
if (options && options.includeBitStringContents) { | |
equal = equal && obj1.bitStringContents === obj2.bitStringContents; | |
} | |
return equal; | |
}; | |
asn1.getBerValueLength = function(b) { | |
var b2 = b.getByte(); | |
if (b2 === 128) { | |
return void 0; | |
} | |
var length11; | |
var longForm = b2 & 128; | |
if (!longForm) { | |
length11 = b2; | |
} else { | |
length11 = b.getInt((b2 & 127) << 3); | |
} | |
return length11; | |
}; | |
function _checkBufferLength(bytes3, remaining, n) { | |
if (n > remaining) { | |
var error = new Error("Too few bytes to parse DER."); | |
error.available = bytes3.length(); | |
error.remaining = remaining; | |
error.requested = n; | |
throw error; | |
} | |
} | |
var _getValueLength = function(bytes3, remaining) { | |
var b2 = bytes3.getByte(); | |
remaining--; | |
if (b2 === 128) { | |
return void 0; | |
} | |
var length11; | |
var longForm = b2 & 128; | |
if (!longForm) { | |
length11 = b2; | |
} else { | |
var longFormBytes = b2 & 127; | |
_checkBufferLength(bytes3, remaining, longFormBytes); | |
length11 = bytes3.getInt(longFormBytes << 3); | |
} | |
if (length11 < 0) { | |
throw new Error("Negative length: " + length11); | |
} | |
return length11; | |
}; | |
asn1.fromDer = function(bytes3, options) { | |
if (options === void 0) { | |
options = { | |
strict: true, | |
parseAllBytes: true, | |
decodeBitStrings: true | |
}; | |
} | |
if (typeof options === "boolean") { | |
options = { | |
strict: options, | |
parseAllBytes: true, | |
decodeBitStrings: true | |
}; | |
} | |
if (!("strict" in options)) { | |
options.strict = true; | |
} | |
if (!("parseAllBytes" in options)) { | |
options.parseAllBytes = true; | |
} | |
if (!("decodeBitStrings" in options)) { | |
options.decodeBitStrings = true; | |
} | |
if (typeof bytes3 === "string") { | |
bytes3 = forge7.util.createBuffer(bytes3); | |
} | |
var byteCount = bytes3.length(); | |
var value = _fromDer(bytes3, bytes3.length(), 0, options); | |
if (options.parseAllBytes && bytes3.length() !== 0) { | |
var error = new Error("Unparsed DER bytes remain after ASN.1 parsing."); | |
error.byteCount = byteCount; | |
error.remaining = bytes3.length(); | |
throw error; | |
} | |
return value; | |
}; | |
function _fromDer(bytes3, remaining, depth, options) { | |
var start; | |
_checkBufferLength(bytes3, remaining, 2); | |
var b1 = bytes3.getByte(); | |
remaining--; | |
var tagClass = b1 & 192; | |
var type = b1 & 31; | |
start = bytes3.length(); | |
var length11 = _getValueLength(bytes3, remaining); | |
remaining -= start - bytes3.length(); | |
if (length11 !== void 0 && length11 > remaining) { | |
if (options.strict) { | |
var error = new Error("Too few bytes to read ASN.1 value."); | |
error.available = bytes3.length(); | |
error.remaining = remaining; | |
error.requested = length11; | |
throw error; | |
} | |
length11 = remaining; | |
} | |
var value; | |
var bitStringContents; | |
var constructed = (b1 & 32) === 32; | |
if (constructed) { | |
value = []; | |
if (length11 === void 0) { | |
for (; ; ) { | |
_checkBufferLength(bytes3, remaining, 2); | |
if (bytes3.bytes(2) === String.fromCharCode(0, 0)) { | |
bytes3.getBytes(2); | |
remaining -= 2; | |
break; | |
} | |
start = bytes3.length(); | |
value.push(_fromDer(bytes3, remaining, depth + 1, options)); | |
remaining -= start - bytes3.length(); | |
} | |
} else { | |
while (length11 > 0) { | |
start = bytes3.length(); | |
value.push(_fromDer(bytes3, length11, depth + 1, options)); | |
remaining -= start - bytes3.length(); | |
length11 -= start - bytes3.length(); | |
} | |
} | |
} | |
if (value === void 0 && tagClass === asn1.Class.UNIVERSAL && type === asn1.Type.BITSTRING) { | |
bitStringContents = bytes3.bytes(length11); | |
} | |
if (value === void 0 && options.decodeBitStrings && tagClass === asn1.Class.UNIVERSAL && // FIXME: OCTET STRINGs not yet supported here | |
// .. other parts of forge expect to decode OCTET STRINGs manually | |
type === asn1.Type.BITSTRING && length11 > 1) { | |
var savedRead = bytes3.read; | |
var savedRemaining = remaining; | |
var unused = 0; | |
if (type === asn1.Type.BITSTRING) { | |
_checkBufferLength(bytes3, remaining, 1); | |
unused = bytes3.getByte(); | |
remaining--; | |
} | |
if (unused === 0) { | |
try { | |
start = bytes3.length(); | |
var subOptions = { | |
// enforce strict mode to avoid parsing ASN.1 from plain data | |
strict: true, | |
decodeBitStrings: true | |
}; | |
var composed = _fromDer(bytes3, remaining, depth + 1, subOptions); | |
var used = start - bytes3.length(); | |
remaining -= used; | |
if (type == asn1.Type.BITSTRING) { | |
used++; | |
} | |
var tc = composed.tagClass; | |
if (used === length11 && (tc === asn1.Class.UNIVERSAL || tc === asn1.Class.CONTEXT_SPECIFIC)) { | |
value = [composed]; | |
} | |
} catch (ex) { | |
} | |
} | |
if (value === void 0) { | |
bytes3.read = savedRead; | |
remaining = savedRemaining; | |
} | |
} | |
if (value === void 0) { | |
if (length11 === void 0) { | |
if (options.strict) { | |
throw new Error("Non-constructed ASN.1 object of indefinite length."); | |
} | |
length11 = remaining; | |
} | |
if (type === asn1.Type.BMPSTRING) { | |
value = ""; | |
for (; length11 > 0; length11 -= 2) { | |
_checkBufferLength(bytes3, remaining, 2); | |
value += String.fromCharCode(bytes3.getInt16()); | |
remaining -= 2; | |
} | |
} else { | |
value = bytes3.getBytes(length11); | |
remaining -= length11; | |
} | |
} | |
var asn1Options = bitStringContents === void 0 ? null : { | |
bitStringContents | |
}; | |
return asn1.create(tagClass, type, constructed, value, asn1Options); | |
} | |
asn1.toDer = function(obj) { | |
var bytes3 = forge7.util.createBuffer(); | |
var b1 = obj.tagClass | obj.type; | |
var value = forge7.util.createBuffer(); | |
var useBitStringContents = false; | |
if ("bitStringContents" in obj) { | |
useBitStringContents = true; | |
if (obj.original) { | |
useBitStringContents = asn1.equals(obj, obj.original); | |
} | |
} | |
if (useBitStringContents) { | |
value.putBytes(obj.bitStringContents); | |
} else if (obj.composed) { | |
if (obj.constructed) { | |
b1 |= 32; | |
} else { | |
value.putByte(0); | |
} | |
for (var i = 0; i < obj.value.length; ++i) { | |
if (obj.value[i] !== void 0) { | |
value.putBuffer(asn1.toDer(obj.value[i])); | |
} | |
} | |
} else { | |
if (obj.type === asn1.Type.BMPSTRING) { | |
for (var i = 0; i < obj.value.length; ++i) { | |
value.putInt16(obj.value.charCodeAt(i)); | |
} | |
} else { | |
if (obj.type === asn1.Type.INTEGER && obj.value.length > 1 && // leading 0x00 for positive integer | |
(obj.value.charCodeAt(0) === 0 && (obj.value.charCodeAt(1) & 128) === 0 || // leading 0xFF for negative integer | |
obj.value.charCodeAt(0) === 255 && (obj.value.charCodeAt(1) & 128) === 128)) { | |
value.putBytes(obj.value.substr(1)); | |
} else { | |
value.putBytes(obj.value); | |
} | |
} | |
} | |
bytes3.putByte(b1); | |
if (value.length() <= 127) { | |
bytes3.putByte(value.length() & 127); | |
} else { | |
var len = value.length(); | |
var lenBytes = ""; | |
do { | |
lenBytes += String.fromCharCode(len & 255); | |
len = len >>> 8; | |
} while (len > 0); | |
bytes3.putByte(lenBytes.length | 128); | |
for (var i = lenBytes.length - 1; i >= 0; --i) { | |
bytes3.putByte(lenBytes.charCodeAt(i)); | |
} | |
} | |
bytes3.putBuffer(value); | |
return bytes3; | |
}; | |
asn1.oidToDer = function(oid) { | |
var values = oid.split("."); | |
var bytes3 = forge7.util.createBuffer(); | |
bytes3.putByte(40 * parseInt(values[0], 10) + parseInt(values[1], 10)); | |
var last2, valueBytes, value, b; | |
for (var i = 2; i < values.length; ++i) { | |
last2 = true; | |
valueBytes = []; | |
value = parseInt(values[i], 10); | |
do { | |
b = value & 127; | |
value = value >>> 7; | |
if (!last2) { | |
b |= 128; | |
} | |
valueBytes.push(b); | |
last2 = false; | |
} while (value > 0); | |
for (var n = valueBytes.length - 1; n >= 0; --n) { | |
bytes3.putByte(valueBytes[n]); | |
} | |
} | |
return bytes3; | |
}; | |
asn1.derToOid = function(bytes3) { | |
var oid; | |
if (typeof bytes3 === "string") { | |
bytes3 = forge7.util.createBuffer(bytes3); | |
} | |
var b = bytes3.getByte(); | |
oid = Math.floor(b / 40) + "." + b % 40; | |
var value = 0; | |
while (bytes3.length() > 0) { | |
b = bytes3.getByte(); | |
value = value << 7; | |
if (b & 128) { | |
value += b & 127; | |
} else { | |
oid += "." + (value + b); | |
value = 0; | |
} | |
} | |
return oid; | |
}; | |
asn1.utcTimeToDate = function(utc) { | |
var date = /* @__PURE__ */ new Date(); | |
var year = parseInt(utc.substr(0, 2), 10); | |
year = year >= 50 ? 1900 + year : 2e3 + year; | |
var MM = parseInt(utc.substr(2, 2), 10) - 1; | |
var DD = parseInt(utc.substr(4, 2), 10); | |
var hh = parseInt(utc.substr(6, 2), 10); | |
var mm = parseInt(utc.substr(8, 2), 10); | |
var ss = 0; | |
if (utc.length > 11) { | |
var c = utc.charAt(10); | |
var end = 10; | |
if (c !== "+" && c !== "-") { | |
ss = parseInt(utc.substr(10, 2), 10); | |
end += 2; | |
} | |
} | |
date.setUTCFullYear(year, MM, DD); | |
date.setUTCHours(hh, mm, ss, 0); | |
if (end) { | |
c = utc.charAt(end); | |
if (c === "+" || c === "-") { | |
var hhoffset = parseInt(utc.substr(end + 1, 2), 10); | |
var mmoffset = parseInt(utc.substr(end + 4, 2), 10); | |
var offset = hhoffset * 60 + mmoffset; | |
offset *= 6e4; | |
if (c === "+") { | |
date.setTime(+date - offset); | |
} else { | |
date.setTime(+date + offset); | |
} | |
} | |
} | |
return date; | |
}; | |
asn1.generalizedTimeToDate = function(gentime) { | |
var date = /* @__PURE__ */ new Date(); | |
var YYYY = parseInt(gentime.substr(0, 4), 10); | |
var MM = parseInt(gentime.substr(4, 2), 10) - 1; | |
var DD = parseInt(gentime.substr(6, 2), 10); | |
var hh = parseInt(gentime.substr(8, 2), 10); | |
var mm = parseInt(gentime.substr(10, 2), 10); | |
var ss = parseInt(gentime.substr(12, 2), 10); | |
var fff = 0; | |
var offset = 0; | |
var isUTC = false; | |
if (gentime.charAt(gentime.length - 1) === "Z") { | |
isUTC = true; | |
} | |
var end = gentime.length - 5, c = gentime.charAt(end); | |
if (c === "+" || c === "-") { | |
var hhoffset = parseInt(gentime.substr(end + 1, 2), 10); | |
var mmoffset = parseInt(gentime.substr(end + 4, 2), 10); | |
offset = hhoffset * 60 + mmoffset; | |
offset *= 6e4; | |
if (c === "+") { | |
offset *= -1; | |
} | |
isUTC = true; | |
} | |
if (gentime.charAt(14) === ".") { | |
fff = parseFloat(gentime.substr(14), 10) * 1e3; | |
} | |
if (isUTC) { | |
date.setUTCFullYear(YYYY, MM, DD); | |
date.setUTCHours(hh, mm, ss, fff); | |
date.setTime(+date + offset); | |
} else { | |
date.setFullYear(YYYY, MM, DD); | |
date.setHours(hh, mm, ss, fff); | |
} | |
return date; | |
}; | |
asn1.dateToUtcTime = function(date) { | |
if (typeof date === "string") { | |
return date; | |
} | |
var rval = ""; | |
var format9 = []; | |
format9.push(("" + date.getUTCFullYear()).substr(2)); | |
format9.push("" + (date.getUTCMonth() + 1)); | |
format9.push("" + date.getUTCDate()); | |
format9.push("" + date.getUTCHours()); | |
format9.push("" + date.getUTCMinutes()); | |
format9.push("" + date.getUTCSeconds()); | |
for (var i = 0; i < format9.length; ++i) { | |
if (format9[i].length < 2) { | |
rval += "0"; | |
} | |
rval += format9[i]; | |
} | |
rval += "Z"; | |
return rval; | |
}; | |
asn1.dateToGeneralizedTime = function(date) { | |
if (typeof date === "string") { | |
return date; | |
} | |
var rval = ""; | |
var format9 = []; | |
format9.push("" + date.getUTCFullYear()); | |
format9.push("" + (date.getUTCMonth() + 1)); | |
format9.push("" + date.getUTCDate()); | |
format9.push("" + date.getUTCHours()); | |
format9.push("" + date.getUTCMinutes()); | |
format9.push("" + date.getUTCSeconds()); | |
for (var i = 0; i < format9.length; ++i) { | |
if (format9[i].length < 2) { | |
rval += "0"; | |
} | |
rval += format9[i]; | |
} | |
rval += "Z"; | |
return rval; | |
}; | |
asn1.integerToDer = function(x) { | |
var rval = forge7.util.createBuffer(); | |
if (x >= -128 && x < 128) { | |
return rval.putSignedInt(x, 8); | |
} | |
if (x >= -32768 && x < 32768) { | |
return rval.putSignedInt(x, 16); | |
} | |
if (x >= -8388608 && x < 8388608) { | |
return rval.putSignedInt(x, 24); | |
} | |
if (x >= -2147483648 && x < 2147483648) { | |
return rval.putSignedInt(x, 32); | |
} | |
var error = new Error("Integer too large; max is 32-bits."); | |
error.integer = x; | |
throw error; | |
}; | |
asn1.derToInteger = function(bytes3) { | |
if (typeof bytes3 === "string") { | |
bytes3 = forge7.util.createBuffer(bytes3); | |
} | |
var n = bytes3.length() * 8; | |
if (n > 32) { | |
throw new Error("Integer too large; max is 32-bits."); | |
} | |
return bytes3.getSignedInt(n); | |
}; | |
asn1.validate = function(obj, v, capture, errors) { | |
var rval = false; | |
if ((obj.tagClass === v.tagClass || typeof v.tagClass === "undefined") && (obj.type === v.type || typeof v.type === "undefined")) { | |
if (obj.constructed === v.constructed || typeof v.constructed === "undefined") { | |
rval = true; | |
if (v.value && forge7.util.isArray(v.value)) { | |
var j = 0; | |
for (var i = 0; rval && i < v.value.length; ++i) { | |
rval = v.value[i].optional || false; | |
if (obj.value[j]) { | |
rval = asn1.validate(obj.value[j], v.value[i], capture, errors); | |
if (rval) { | |
++j; | |
} else if (v.value[i].optional) { | |
rval = true; | |
} | |
} | |
if (!rval && errors) { | |
errors.push( | |
"[" + v.name + '] Tag class "' + v.tagClass + '", type "' + v.type + '" expected value length "' + v.value.length + '", got "' + obj.value.length + '"' | |
); | |
} | |
} | |
} | |
if (rval && capture) { | |
if (v.capture) { | |
capture[v.capture] = obj.value; | |
} | |
if (v.captureAsn1) { | |
capture[v.captureAsn1] = obj; | |
} | |
if (v.captureBitStringContents && "bitStringContents" in obj) { | |
capture[v.captureBitStringContents] = obj.bitStringContents; | |
} | |
if (v.captureBitStringValue && "bitStringContents" in obj) { | |
var value; | |
if (obj.bitStringContents.length < 2) { | |
capture[v.captureBitStringValue] = ""; | |
} else { | |
var unused = obj.bitStringContents.charCodeAt(0); | |
if (unused !== 0) { | |
throw new Error( | |
"captureBitStringValue only supported for zero unused bits" | |
); | |
} | |
capture[v.captureBitStringValue] = obj.bitStringContents.slice(1); | |
} | |
} | |
} | |
} else if (errors) { | |
errors.push( | |
"[" + v.name + '] Expected constructed "' + v.constructed + '", got "' + obj.constructed + '"' | |
); | |
} | |
} else if (errors) { | |
if (obj.tagClass !== v.tagClass) { | |
errors.push( | |
"[" + v.name + '] Expected tag class "' + v.tagClass + '", got "' + obj.tagClass + '"' | |
); | |
} | |
if (obj.type !== v.type) { | |
errors.push( | |
"[" + v.name + '] Expected type "' + v.type + '", got "' + obj.type + '"' | |
); | |
} | |
} | |
return rval; | |
}; | |
var _nonLatinRegex = /[^\\u0000-\\u00ff]/; | |
asn1.prettyPrint = function(obj, level, indentation) { | |
var rval = ""; | |
level = level || 0; | |
indentation = indentation || 2; | |
if (level > 0) { | |
rval += "\n"; | |
} | |
var indent = ""; | |
for (var i = 0; i < level * indentation; ++i) { | |
indent += " "; | |
} | |
rval += indent + "Tag: "; | |
switch (obj.tagClass) { | |
case asn1.Class.UNIVERSAL: | |
rval += "Universal:"; | |
break; | |
case asn1.Class.APPLICATION: | |
rval += "Application:"; | |
break; | |
case asn1.Class.CONTEXT_SPECIFIC: | |
rval += "Context-Specific:"; | |
break; | |
case asn1.Class.PRIVATE: | |
rval += "Private:"; | |
break; | |
} | |
if (obj.tagClass === asn1.Class.UNIVERSAL) { | |
rval += obj.type; | |
switch (obj.type) { | |
case asn1.Type.NONE: | |
rval += " (None)"; | |
break; | |
case asn1.Type.BOOLEAN: | |
rval += " (Boolean)"; | |
break; | |
case asn1.Type.INTEGER: | |
rval += " (Integer)"; | |
break; | |
case asn1.Type.BITSTRING: | |
rval += " (Bit string)"; | |
break; | |
case asn1.Type.OCTETSTRING: | |
rval += " (Octet string)"; | |
break; | |
case asn1.Type.NULL: | |
rval += " (Null)"; | |
break; | |
case asn1.Type.OID: | |
rval += " (Object Identifier)"; | |
break; | |
case asn1.Type.ODESC: | |
rval += " (Object Descriptor)"; | |
break; | |
case asn1.Type.EXTERNAL: | |
rval += " (External or Instance of)"; | |
break; | |
case asn1.Type.REAL: | |
rval += " (Real)"; | |
break; | |
case asn1.Type.ENUMERATED: | |
rval += " (Enumerated)"; | |
break; | |
case asn1.Type.EMBEDDED: | |
rval += " (Embedded PDV)"; | |
break; | |
case asn1.Type.UTF8: | |
rval += " (UTF8)"; | |
break; | |
case asn1.Type.ROID: | |
rval += " (Relative Object Identifier)"; | |
break; | |
case asn1.Type.SEQUENCE: | |
rval += " (Sequence)"; | |
break; | |
case asn1.Type.SET: | |
rval += " (Set)"; | |
break; | |
case asn1.Type.PRINTABLESTRING: | |
rval += " (Printable String)"; | |
break; | |
case asn1.Type.IA5String: | |
rval += " (IA5String (ASCII))"; | |
break; | |
case asn1.Type.UTCTIME: | |
rval += " (UTC time)"; | |
break; | |
case asn1.Type.GENERALIZEDTIME: | |
rval += " (Generalized time)"; | |
break; | |
case asn1.Type.BMPSTRING: | |
rval += " (BMP String)"; | |
break; | |
} | |
} else { | |
rval += obj.type; | |
} | |
rval += "\n"; | |
rval += indent + "Constructed: " + obj.constructed + "\n"; | |
if (obj.composed) { | |
var subvalues = 0; | |
var sub = ""; | |
for (var i = 0; i < obj.value.length; ++i) { | |
if (obj.value[i] !== void 0) { | |
subvalues += 1; | |
sub += asn1.prettyPrint(obj.value[i], level + 1, indentation); | |
if (i + 1 < obj.value.length) { | |
sub += ","; | |
} | |
} | |
} | |
rval += indent + "Sub values: " + subvalues + sub; | |
} else { | |
rval += indent + "Value: "; | |
if (obj.type === asn1.Type.OID) { | |
var oid = asn1.derToOid(obj.value); | |
rval += oid; | |
if (forge7.pki && forge7.pki.oids) { | |
if (oid in forge7.pki.oids) { | |
rval += " (" + forge7.pki.oids[oid] + ") "; | |
} | |
} | |
} | |
if (obj.type === asn1.Type.INTEGER) { | |
try { | |
rval += asn1.derToInteger(obj.value); | |
} catch (ex) { | |
rval += "0x" + forge7.util.bytesToHex(obj.value); | |
} | |
} else if (obj.type === asn1.Type.BITSTRING) { | |
if (obj.value.length > 1) { | |
rval += "0x" + forge7.util.bytesToHex(obj.value.slice(1)); | |
} else { | |
rval += "(none)"; | |
} | |
if (obj.value.length > 0) { | |
var unused = obj.value.charCodeAt(0); | |
if (unused == 1) { | |
rval += " (1 unused bit shown)"; | |
} else if (unused > 1) { | |
rval += " (" + unused + " unused bits shown)"; | |
} | |
} | |
} else if (obj.type === asn1.Type.OCTETSTRING) { | |
if (!_nonLatinRegex.test(obj.value)) { | |
rval += "(" + obj.value + ") "; | |
} | |
rval += "0x" + forge7.util.bytesToHex(obj.value); | |
} else if (obj.type === asn1.Type.UTF8) { | |
try { | |
rval += forge7.util.decodeUtf8(obj.value); | |
} catch (e) { | |
if (e.message === "URI malformed") { | |
rval += "0x" + forge7.util.bytesToHex(obj.value) + " (malformed UTF8)"; | |
} else { | |
throw e; | |
} | |
} | |
} else if (obj.type === asn1.Type.PRINTABLESTRING || obj.type === asn1.Type.IA5String) { | |
rval += obj.value; | |
} else if (_nonLatinRegex.test(obj.value)) { | |
rval += "0x" + forge7.util.bytesToHex(obj.value); | |
} else if (obj.value.length === 0) { | |
rval += "[null]"; | |
} else { | |
rval += obj.value; | |
} | |
} | |
return rval; | |
}; | |
} | |
}); | |
// node_modules/node-forge/lib/cipher.js | |
var require_cipher = __commonJS({ | |
"node_modules/node-forge/lib/cipher.js"(exports2, module2) { | |
var forge7 = require_forge(); | |
require_util(); | |
module2.exports = forge7.cipher = forge7.cipher || {}; | |
forge7.cipher.algorithms = forge7.cipher.algorithms || {}; | |
forge7.cipher.createCipher = function(algorithm, key) { | |
var api = algorithm; | |
if (typeof api === "string") { | |
api = forge7.cipher.getAlgorithm(api); | |
if (api) { | |
api = api(); | |
} | |
} | |
if (!api) { | |
throw new Error("Unsupported algorithm: " + algorithm); | |
} | |
return new forge7.cipher.BlockCipher({ | |
algorithm: api, | |
key, | |
decrypt: false | |
}); | |
}; | |
forge7.cipher.createDecipher = function(algorithm, key) { | |
var api = algorithm; | |
if (typeof api === "string") { | |
api = forge7.cipher.getAlgorithm(api); | |
if (api) { | |
api = api(); | |
} | |
} | |
if (!api) { | |
throw new Error("Unsupported algorithm: " + algorithm); | |
} | |
return new forge7.cipher.BlockCipher({ | |
algorithm: api, | |
key, | |
decrypt: true | |
}); | |
}; | |
forge7.cipher.registerAlgorithm = function(name8, algorithm) { | |
name8 = name8.toUpperCase(); | |
forge7.cipher.algorithms[name8] = algorithm; | |
}; | |
forge7.cipher.getAlgorithm = function(name8) { | |
name8 = name8.toUpperCase(); | |
if (name8 in forge7.cipher.algorithms) { | |
return forge7.cipher.algorithms[name8]; | |
} | |
return null; | |
}; | |
var BlockCipher = forge7.cipher.BlockCipher = function(options) { | |
this.algorithm = options.algorithm; | |
this.mode = this.algorithm.mode; | |
this.blockSize = this.mode.blockSize; | |
this._finish = false; | |
this._input = null; | |
this.output = null; | |
this._op = options.decrypt ? this.mode.decrypt : this.mode.encrypt; | |
this._decrypt = options.decrypt; | |
this.algorithm.initialize(options); | |
}; | |
BlockCipher.prototype.start = function(options) { | |
options = options || {}; | |
var opts = {}; | |
for (var key in options) { | |
opts[key] = options[key]; | |
} | |
opts.decrypt = this._decrypt; | |
this._finish = false; | |
this._input = forge7.util.createBuffer(); | |
this.output = options.output || forge7.util.createBuffer(); | |
this.mode.start(opts); | |
}; | |
BlockCipher.prototype.update = function(input) { | |
if (input) { | |
this._input.putBuffer(input); | |
} | |
while (!this._op.call(this.mode, this._input, this.output, this._finish) && !this._finish) { | |
} | |
this._input.compact(); | |
}; | |
BlockCipher.prototype.finish = function(pad) { | |
if (pad && (this.mode.name === "ECB" || this.mode.name === "CBC")) { | |
this.mode.pad = function(input) { | |
return pad(this.blockSize, input, false); | |
}; | |
this.mode.unpad = function(output3) { | |
return pad(this.blockSize, output3, true); | |
}; | |
} | |
var options = {}; | |
options.decrypt = this._decrypt; | |
options.overflow = this._input.length() % this.blockSize; | |
if (!this._decrypt && this.mode.pad) { | |
if (!this.mode.pad(this._input, options)) { | |
return false; | |
} | |
} | |
this._finish = true; | |
this.update(); | |
if (this._decrypt && this.mode.unpad) { | |
if (!this.mode.unpad(this.output, options)) { | |
return false; | |
} | |
} | |
if (this.mode.afterFinish) { | |
if (!this.mode.afterFinish(this.output, options)) { | |
return false; | |
} | |
} | |
return true; | |
}; | |
} | |
}); | |
// node_modules/node-forge/lib/cipherModes.js | |
var require_cipherModes = __commonJS({ | |
"node_modules/node-forge/lib/cipherModes.js"(exports2, module2) { | |
var forge7 = require_forge(); | |
require_util(); | |
forge7.cipher = forge7.cipher || {}; | |
var modes = module2.exports = forge7.cipher.modes = forge7.cipher.modes || {}; | |
modes.ecb = function(options) { | |
options = options || {}; | |
this.name = "ECB"; | |
this.cipher = options.cipher; | |
this.blockSize = options.blockSize || 16; | |
this._ints = this.blockSize / 4; | |
this._inBlock = new Array(this._ints); | |
this._outBlock = new Array(this._ints); | |
}; | |
modes.ecb.prototype.start = function(options) { | |
}; | |
modes.ecb.prototype.encrypt = function(input, output3, finish) { | |
if (input.length() < this.blockSize && !(finish && input.length() > 0)) { | |
return true; | |
} | |
for (var i = 0; i < this._ints; ++i) { | |
this._inBlock[i] = input.getInt32(); | |
} | |
this.cipher.encrypt(this._inBlock, this._outBlock); | |
for (var i = 0; i < this._ints; ++i) { | |
output3.putInt32(this._outBlock[i]); | |
} | |
}; | |
modes.ecb.prototype.decrypt = function(input, output3, finish) { | |
if (input.length() < this.blockSize && !(finish && input.length() > 0)) { | |
return true; | |
} | |
for (var i = 0; i < this._ints; ++i) { | |
this._inBlock[i] = input.getInt32(); | |
} | |
this.cipher.decrypt(this._inBlock, this._outBlock); | |
for (var i = 0; i < this._ints; ++i) { | |
output3.putInt32(this._outBlock[i]); | |
} | |
}; | |
modes.ecb.prototype.pad = function(input, options) { | |
var padding = input.length() === this.blockSize ? this.blockSize : this.blockSize - input.length(); | |
input.fillWithByte(padding, padding); | |
return true; | |
}; | |
modes.ecb.prototype.unpad = function(output3, options) { | |
if (options.overflow > 0) { | |
return false; | |
} | |
var len = output3.length(); | |
var count = output3.at(len - 1); | |
if (count > this.blockSize << 2) { | |
return false; | |
} | |
output3.truncate(count); | |
return true; | |
}; | |
modes.cbc = function(options) { | |
options = options || {}; | |
this.name = "CBC"; | |
this.cipher = options.cipher; | |
this.blockSize = options.blockSize || 16; | |
this._ints = this.blockSize / 4; | |
this._inBlock = new Array(this._ints); | |
this._outBlock = new Array(this._ints); | |
}; | |
modes.cbc.prototype.start = function(options) { | |
if (options.iv === null) { | |
if (!this._prev) { | |
throw new Error("Invalid IV parameter."); | |
} | |
this._iv = this._prev.slice(0); | |
} else if (!("iv" in options)) { | |
throw new Error("Invalid IV parameter."); | |
} else { | |
this._iv = transformIV(options.iv, this.blockSize); | |
this._prev = this._iv.slice(0); | |
} | |
}; | |
modes.cbc.prototype.encrypt = function(input, output3, finish) { | |
if (input.length() < this.blockSize && !(finish && input.length() > 0)) { | |
return true; | |
} | |
for (var i = 0; i < this._ints; ++i) { | |
this._inBlock[i] = this._prev[i] ^ input.getInt32(); | |
} | |
this.cipher.encrypt(this._inBlock, this._outBlock); | |
for (var i = 0; i < this._ints; ++i) { | |
output3.putInt32(this._outBlock[i]); | |
} | |
this._prev = this._outBlock; | |
}; | |
modes.cbc.prototype.decrypt = function(input, output3, finish) { | |
if (input.length() < this.blockSize && !(finish && input.length() > 0)) { | |
return true; | |
} | |
for (var i = 0; i < this._ints; ++i) { | |
this._inBlock[i] = input.getInt32(); | |
} | |
this.cipher.decrypt(this._inBlock, this._outBlock); | |
for (var i = 0; i < this._ints; ++i) { | |
output3.putInt32(this._prev[i] ^ this._outBlock[i]); | |
} | |
this._prev = this._inBlock.slice(0); | |
}; | |
modes.cbc.prototype.pad = function(input, options) { | |
var padding = input.length() === this.blockSize ? this.blockSize : this.blockSize - input.length(); | |
input.fillWithByte(padding, padding); | |
return true; | |
}; | |
modes.cbc.prototype.unpad = function(output3, options) { | |
if (options.overflow > 0) { | |
return false; | |
} | |
var len = output3.length(); | |
var count = output3.at(len - 1); | |
if (count > this.blockSize << 2) { | |
return false; | |
} | |
output3.truncate(count); | |
return true; | |
}; | |
modes.cfb = function(options) { | |
options = options || {}; | |
this.name = "CFB"; | |
this.cipher = options.cipher; | |
this.blockSize = options.blockSize || 16; | |
this._ints = this.blockSize / 4; | |
this._inBlock = null; | |
this._outBlock = new Array(this._ints); | |
this._partialBlock = new Array(this._ints); | |
this._partialOutput = forge7.util.createBuffer(); | |
this._partialBytes = 0; | |
}; | |
modes.cfb.prototype.start = function(options) { | |
if (!("iv" in options)) { | |
throw new Error("Invalid IV parameter."); | |
} | |
this._iv = transformIV(options.iv, this.blockSize); | |
this._inBlock = this._iv.slice(0); | |
this._partialBytes = 0; | |
}; | |
modes.cfb.prototype.encrypt = function(input, output3, finish) { | |
var inputLength = input.length(); | |
if (inputLength === 0) { | |
return true; | |
} | |
this.cipher.encrypt(this._inBlock, this._outBlock); | |
if (this._partialBytes === 0 && inputLength >= this.blockSize) { | |
for (var i = 0; i < this._ints; ++i) { | |
this._inBlock[i] = input.getInt32() ^ this._outBlock[i]; | |
output3.putInt32(this._inBlock[i]); | |
} | |
return; | |
} | |
var partialBytes = (this.blockSize - inputLength) % this.blockSize; | |
if (partialBytes > 0) { | |
partialBytes = this.blockSize - partialBytes; | |
} | |
this._partialOutput.clear(); | |
for (var i = 0; i < this._ints; ++i) { | |
this._partialBlock[i] = input.getInt32() ^ this._outBlock[i]; | |
this._partialOutput.putInt32(this._partialBlock[i]); | |
} | |
if (partialBytes > 0) { | |
input.read -= this.blockSize; | |
} else { | |
for (var i = 0; i < this._ints; ++i) { | |
this._inBlock[i] = this._partialBlock[i]; | |
} | |
} | |
if (this._partialBytes > 0) { | |
this._partialOutput.getBytes(this._partialBytes); | |
} | |
if (partialBytes > 0 && !finish) { | |
output3.putBytes(this._partialOutput.getBytes( | |
partialBytes - this._partialBytes | |
)); | |
this._partialBytes = partialBytes; | |
return true; | |
} | |
output3.putBytes(this._partialOutput.getBytes( | |
inputLength - this._partialBytes | |
)); | |
this._partialBytes = 0; | |
}; | |
modes.cfb.prototype.decrypt = function(input, output3, finish) { | |
var inputLength = input.length(); | |
if (inputLength === 0) { | |
return true; | |
} | |
this.cipher.encrypt(this._inBlock, this._outBlock); | |
if (this._partialBytes === 0 && inputLength >= this.blockSize) { | |
for (var i = 0; i < this._ints; ++i) { | |
this._inBlock[i] = input.getInt32(); | |
output3.putInt32(this._inBlock[i] ^ this._outBlock[i]); | |
} | |
return; | |
} | |
var partialBytes = (this.blockSize - inputLength) % this.blockSize; | |
if (partialBytes > 0) { | |
partialBytes = this.blockSize - partialBytes; | |
} | |
this._partialOutput.clear(); | |
for (var i = 0; i < this._ints; ++i) { | |
this._partialBlock[i] = input.getInt32(); | |
this._partialOutput.putInt32(this._partialBlock[i] ^ this._outBlock[i]); | |
} | |
if (partialBytes > 0) { | |
input.read -= this.blockSize; | |
} else { | |
for (var i = 0; i < this._ints; ++i) { | |
this._inBlock[i] = this._partialBlock[i]; | |
} | |
} | |
if (this._partialBytes > 0) { | |
this._partialOutput.getBytes(this._partialBytes); | |
} | |
if (partialBytes > 0 && !finish) { | |
output3.putBytes(this._partialOutput.getBytes( | |
partialBytes - this._partialBytes | |
)); | |
this._partialBytes = partialBytes; | |
return true; | |
} | |
output3.putBytes(this._partialOutput.getBytes( | |
inputLength - this._partialBytes | |
)); | |
this._partialBytes = 0; | |
}; | |
modes.ofb = function(options) { | |
options = options || {}; | |
this.name = "OFB"; | |
this.cipher = options.cipher; | |
this.blockSize = options.blockSize || 16; | |
this._ints = this.blockSize / 4; | |
this._inBlock = null; | |
this._outBlock = new Array(this._ints); | |
this._partialOutput = forge7.util.createBuffer(); | |
this._partialBytes = 0; | |
}; | |
modes.ofb.prototype.start = function(options) { | |
if (!("iv" in options)) { | |
throw new Error("Invalid IV parameter."); | |
} | |
this._iv = transformIV(options.iv, this.blockSize); | |
this._inBlock = this._iv.slice(0); | |
this._partialBytes = 0; | |
}; | |
modes.ofb.prototype.encrypt = function(input, output3, finish) { | |
var inputLength = input.length(); | |
if (input.length() === 0) { | |
return true; | |
} | |
this.cipher.encrypt(this._inBlock, this._outBlock); | |
if (this._partialBytes === 0 && inputLength >= this.blockSize) { | |
for (var i = 0; i < this._ints; ++i) { | |
output3.putInt32(input.getInt32() ^ this._outBlock[i]); | |
this._inBlock[i] = this._outBlock[i]; | |
} | |
return; | |
} | |
var partialBytes = (this.blockSize - inputLength) % this.blockSize; | |
if (partialBytes > 0) { | |
partialBytes = this.blockSize - partialBytes; | |
} | |
this._partialOutput.clear(); | |
for (var i = 0; i < this._ints; ++i) { | |
this._partialOutput.putInt32(input.getInt32() ^ this._outBlock[i]); | |
} | |
if (partialBytes > 0) { | |
input.read -= this.blockSize; | |
} else { | |
for (var i = 0; i < this._ints; ++i) { | |
this._inBlock[i] = this._outBlock[i]; | |
} | |
} | |
if (this._partialBytes > 0) { | |
this._partialOutput.getBytes(this._partialBytes); | |
} | |
if (partialBytes > 0 && !finish) { | |
output3.putBytes(this._partialOutput.getBytes( | |
partialBytes - this._partialBytes | |
)); | |
this._partialBytes = partialBytes; | |
return true; | |
} | |
output3.putBytes(this._partialOutput.getBytes( | |
inputLength - this._partialBytes | |
)); | |
this._partialBytes = 0; | |
}; | |
modes.ofb.prototype.decrypt = modes.ofb.prototype.encrypt; | |
modes.ctr = function(options) { | |
options = options || {}; | |
this.name = "CTR"; | |
this.cipher = options.cipher; | |
this.blockSize = options.blockSize || 16; | |
this._ints = this.blockSize / 4; | |
this._inBlock = null; | |
this._outBlock = new Array(this._ints); | |
this._partialOutput = forge7.util.createBuffer(); | |
this._partialBytes = 0; | |
}; | |
modes.ctr.prototype.start = function(options) { | |
if (!("iv" in options)) { | |
throw new Error("Invalid IV parameter."); | |
} | |
this._iv = transformIV(options.iv, this.blockSize); | |
this._inBlock = this._iv.slice(0); | |
this._partialBytes = 0; | |
}; | |
modes.ctr.prototype.encrypt = function(input, output3, finish) { | |
var inputLength = input.length(); | |
if (inputLength === 0) { | |
return true; | |
} | |
this.cipher.encrypt(this._inBlock, this._outBlock); | |
if (this._partialBytes === 0 && inputLength >= this.blockSize) { | |
for (var i = 0; i < this._ints; ++i) { | |
output3.putInt32(input.getInt32() ^ this._outBlock[i]); | |
} | |
} else { | |
var partialBytes = (this.blockSize - inputLength) % this.blockSize; | |
if (partialBytes > 0) { | |
partialBytes = this.blockSize - partialBytes; | |
} | |
this._partialOutput.clear(); | |
for (var i = 0; i < this._ints; ++i) { | |
this._partialOutput.putInt32(input.getInt32() ^ this._outBlock[i]); | |
} | |
if (partialBytes > 0) { | |
input.read -= this.blockSize; | |
} | |
if (this._partialBytes > 0) { | |
this._partialOutput.getBytes(this._partialBytes); | |
} | |
if (partialBytes > 0 && !finish) { | |
output3.putBytes(this._partialOutput.getBytes( | |
partialBytes - this._partialBytes | |
)); | |
this._partialBytes = partialBytes; | |
return true; | |
} | |
output3.putBytes(this._partialOutput.getBytes( | |
inputLength - this._partialBytes | |
)); | |
this._partialBytes = 0; | |
} | |
inc32(this._inBlock); | |
}; | |
modes.ctr.prototype.decrypt = modes.ctr.prototype.encrypt; | |
modes.gcm = function(options) { | |
options = options || {}; | |
this.name = "GCM"; | |
this.cipher = options.cipher; | |
this.blockSize = options.blockSize || 16; | |
this._ints = this.blockSize / 4; | |
this._inBlock = new Array(this._ints); | |
this._outBlock = new Array(this._ints); | |
this._partialOutput = forge7.util.createBuffer(); | |
this._partialBytes = 0; | |
this._R = 3774873600; | |
}; | |
modes.gcm.prototype.start = function(options) { | |
if (!("iv" in options)) { | |
throw new Error("Invalid IV parameter."); | |
} | |
var iv = forge7.util.createBuffer(options.iv); | |
this._cipherLength = 0; | |
var additionalData; | |
if ("additionalData" in options) { | |
additionalData = forge7.util.createBuffer(options.additionalData); | |
} else { | |
additionalData = forge7.util.createBuffer(); | |
} | |
if ("tagLength" in options) { | |
this._tagLength = options.tagLength; | |
} else { | |
this._tagLength = 128; | |
} | |
this._tag = null; | |
if (options.decrypt) { | |
this._tag = forge7.util.createBuffer(options.tag).getBytes(); | |
if (this._tag.length !== this._tagLength / 8) { | |
throw new Error("Authentication tag does not match tag length."); | |
} | |
} | |
this._hashBlock = new Array(this._ints); | |
this.tag = null; | |
this._hashSubkey = new Array(this._ints); | |
this.cipher.encrypt([0, 0, 0, 0], this._hashSubkey); | |
this.componentBits = 4; | |
this._m = this.generateHashTable(this._hashSubkey, this.componentBits); | |
var ivLength = iv.length(); | |
if (ivLength === 12) { | |
this._j0 = [iv.getInt32(), iv.getInt32(), iv.getInt32(), 1]; | |
} else { | |
this._j0 = [0, 0, 0, 0]; | |
while (iv.length() > 0) { | |
this._j0 = this.ghash( | |
this._hashSubkey, | |
this._j0, | |
[iv.getInt32(), iv.getInt32(), iv.getInt32(), iv.getInt32()] | |
); | |
} | |
this._j0 = this.ghash( | |
this._hashSubkey, | |
this._j0, | |
[0, 0].concat(from64To32(ivLength * 8)) | |
); | |
} | |
this._inBlock = this._j0.slice(0); | |
inc32(this._inBlock); | |
this._partialBytes = 0; | |
additionalData = forge7.util.createBuffer(additionalData); | |
this._aDataLength = from64To32(additionalData.length() * 8); | |
var overflow = additionalData.length() % this.blockSize; | |
if (overflow) { | |
additionalData.fillWithByte(0, this.blockSize - overflow); | |
} | |
this._s = [0, 0, 0, 0]; | |
while (additionalData.length() > 0) { | |
this._s = this.ghash(this._hashSubkey, this._s, [ | |
additionalData.getInt32(), | |
additionalData.getInt32(), | |
additionalData.getInt32(), | |
additionalData.getInt32() | |
]); | |
} | |
}; | |
modes.gcm.prototype.encrypt = function(input, output3, finish) { | |
var inputLength = input.length(); | |
if (inputLength === 0) { | |
return true; | |
} | |
this.cipher.encrypt(this._inBlock, this._outBlock); | |
if (this._partialBytes === 0 && inputLength >= this.blockSize) { | |
for (var i = 0; i < this._ints; ++i) { | |
output3.putInt32(this._outBlock[i] ^= input.getInt32()); | |
} | |
this._cipherLength += this.blockSize; | |
} else { | |
var partialBytes = (this.blockSize - inputLength) % this.blockSize; | |
if (partialBytes > 0) { | |
partialBytes = this.blockSize - partialBytes; | |
} | |
this._partialOutput.clear(); | |
for (var i = 0; i < this._ints; ++i) { | |
this._partialOutput.putInt32(input.getInt32() ^ this._outBlock[i]); | |
} | |
if (partialBytes <= 0 || finish) { | |
if (finish) { | |
var overflow = inputLength % this.blockSize; | |
this._cipherLength += overflow; | |
this._partialOutput.truncate(this.blockSize - overflow); | |
} else { | |
this._cipherLength += this.blockSize; | |
} | |
for (var i = 0; i < this._ints; ++i) { | |
this._outBlock[i] = this._partialOutput.getInt32(); | |
} | |
this._partialOutput.read -= this.blockSize; | |
} | |
if (this._partialBytes > 0) { | |
this._partialOutput.getBytes(this._partialBytes); | |
} | |
if (partialBytes > 0 && !finish) { | |
input.read -= this.blockSize; | |
output3.putBytes(this._partialOutput.getBytes( | |
partialBytes - this._partialBytes | |
)); | |
this._partialBytes = partialBytes; | |
return true; | |
} | |
output3.putBytes(this._partialOutput.getBytes( | |
inputLength - this._partialBytes | |
)); | |
this._partialBytes = 0; | |
} | |
this._s = this.ghash(this._hashSubkey, this._s, this._outBlock); | |
inc32(this._inBlock); | |
}; | |
modes.gcm.prototype.decrypt = function(input, output3, finish) { | |
var inputLength = input.length(); | |
if (inputLength < this.blockSize && !(finish && inputLength > 0)) { | |
return true; | |
} | |
this.cipher.encrypt(this._inBlock, this._outBlock); | |
inc32(this._inBlock); | |
this._hashBlock[0] = input.getInt32(); | |
this._hashBlock[1] = input.getInt32(); | |
this._hashBlock[2] = input.getInt32(); | |
this._hashBlock[3] = input.getInt32(); | |
this._s = this.ghash(this._hashSubkey, this._s, this._hashBlock); | |
for (var i = 0; i < this._ints; ++i) { | |
output3.putInt32(this._outBlock[i] ^ this._hashBlock[i]); | |
} | |
if (inputLength < this.blockSize) { | |
this._cipherLength += inputLength % this.blockSize; | |
} else { | |
this._cipherLength += this.blockSize; | |
} | |
}; | |
modes.gcm.prototype.afterFinish = function(output3, options) { | |
var rval = true; | |
if (options.decrypt && options.overflow) { | |
output3.truncate(this.blockSize - options.overflow); | |
} | |
this.tag = forge7.util.createBuffer(); | |
var lengths = this._aDataLength.concat(from64To32(this._cipherLength * 8)); | |
this._s = this.ghash(this._hashSubkey, this._s, lengths); | |
var tag = []; | |
this.cipher.encrypt(this._j0, tag); | |
for (var i = 0; i < this._ints; ++i) { | |
this.tag.putInt32(this._s[i] ^ tag[i]); | |
} | |
this.tag.truncate(this.tag.length() % (this._tagLength / 8)); | |
if (options.decrypt && this.tag.bytes() !== this._tag) { | |
rval = false; | |
} | |
return rval; | |
}; | |
modes.gcm.prototype.multiply = function(x, y) { | |
var z_i = [0, 0, 0, 0]; | |
var v_i = y.slice(0); | |
for (var i = 0; i < 128; ++i) { | |
var x_i = x[i / 32 | 0] & 1 << 31 - i % 32; | |
if (x_i) { | |
z_i[0] ^= v_i[0]; | |
z_i[1] ^= v_i[1]; | |
z_i[2] ^= v_i[2]; | |
z_i[3] ^= v_i[3]; | |
} | |
this.pow(v_i, v_i); | |
} | |
return z_i; | |
}; | |
modes.gcm.prototype.pow = function(x, out) { | |
var lsb = x[3] & 1; | |
for (var i = 3; i > 0; --i) { | |
out[i] = x[i] >>> 1 | (x[i - 1] & 1) << 31; | |
} | |
out[0] = x[0] >>> 1; | |
if (lsb) { | |
out[0] ^= this._R; | |
} | |
}; | |
modes.gcm.prototype.tableMultiply = function(x) { | |
var z = [0, 0, 0, 0]; | |
for (var i = 0; i < 32; ++i) { | |
var idx = i / 8 | 0; | |
var x_i = x[idx] >>> (7 - i % 8) * 4 & 15; | |
var ah = this._m[i][x_i]; | |
z[0] ^= ah[0]; | |
z[1] ^= ah[1]; | |
z[2] ^= ah[2]; | |
z[3] ^= ah[3]; | |
} | |
return z; | |
}; | |
modes.gcm.prototype.ghash = function(h, y, x) { | |
y[0] ^= x[0]; | |
y[1] ^= x[1]; | |
y[2] ^= x[2]; | |
y[3] ^= x[3]; | |
return this.tableMultiply(y); | |
}; | |
modes.gcm.prototype.generateHashTable = function(h, bits2) { | |
var multiplier = 8 / bits2; | |
var perInt = 4 * multiplier; | |
var size = 16 * multiplier; | |
var m = new Array(size); | |
for (var i = 0; i < size; ++i) { | |
var tmp = [0, 0, 0, 0]; | |
var idx = i / perInt | 0; | |
var shft = (perInt - 1 - i % perInt) * bits2; | |
tmp[idx] = 1 << bits2 - 1 << shft; | |
m[i] = this.generateSubHashTable(this.multiply(tmp, h), bits2); | |
} | |
return m; | |
}; | |
modes.gcm.prototype.generateSubHashTable = function(mid, bits2) { | |
var size = 1 << bits2; | |
var half = size >>> 1; | |
var m = new Array(size); | |
m[half] = mid.slice(0); | |
var i = half >>> 1; | |
while (i > 0) { | |
this.pow(m[2 * i], m[i] = []); | |
i >>= 1; | |
} | |
i = 2; | |
while (i < half) { | |
for (var j = 1; j < i; ++j) { | |
var m_i = m[i]; | |
var m_j = m[j]; | |
m[i + j] = [ | |
m_i[0] ^ m_j[0], | |
m_i[1] ^ m_j[1], | |
m_i[2] ^ m_j[2], | |
m_i[3] ^ m_j[3] | |
]; | |
} | |
i *= 2; | |
} | |
m[0] = [0, 0, 0, 0]; | |
for (i = half + 1; i < size; ++i) { | |
var c = m[i ^ half]; | |
m[i] = [mid[0] ^ c[0], mid[1] ^ c[1], mid[2] ^ c[2], mid[3] ^ c[3]]; | |
} | |
return m; | |
}; | |
function transformIV(iv, blockSize) { | |
if (typeof iv === "string") { | |
iv = forge7.util.createBuffer(iv); | |
} | |
if (forge7.util.isArray(iv) && iv.length > 4) { | |
var tmp = iv; | |
iv = forge7.util.createBuffer(); | |
for (var i = 0; i < tmp.length; ++i) { | |
iv.putByte(tmp[i]); | |
} | |
} | |
if (iv.length() < blockSize) { | |
throw new Error( | |
"Invalid IV length; got " + iv.length() + " bytes and expected " + blockSize + " bytes." | |
); | |
} | |
if (!forge7.util.isArray(iv)) { | |
var ints = []; | |
var blocks = blockSize / 4; | |
for (var i = 0; i < blocks; ++i) { | |
ints.push(iv.getInt32()); | |
} | |
iv = ints; | |
} | |
return iv; | |
} | |
function inc32(block) { | |
block[block.length - 1] = block[block.length - 1] + 1 & 4294967295; | |
} | |
function from64To32(num) { | |
return [num / 4294967296 | 0, num & 4294967295]; | |
} | |
} | |
}); | |
// node_modules/node-forge/lib/aes.js | |
var require_aes = __commonJS({ | |
"node_modules/node-forge/lib/aes.js"(exports2, module2) { | |
var forge7 = require_forge(); | |
require_cipher(); | |
require_cipherModes(); | |
require_util(); | |
module2.exports = forge7.aes = forge7.aes || {}; | |
forge7.aes.startEncrypting = function(key, iv, output3, mode) { | |
var cipher = _createCipher({ | |
key, | |
output: output3, | |
decrypt: false, | |
mode | |
}); | |
cipher.start(iv); | |
return cipher; | |
}; | |
forge7.aes.createEncryptionCipher = function(key, mode) { | |
return _createCipher({ | |
key, | |
output: null, | |
decrypt: false, | |
mode | |
}); | |
}; | |
forge7.aes.startDecrypting = function(key, iv, output3, mode) { | |
var cipher = _createCipher({ | |
key, | |
output: output3, | |
decrypt: true, | |
mode | |
}); | |
cipher.start(iv); | |
return cipher; | |
}; | |
forge7.aes.createDecryptionCipher = function(key, mode) { | |
return _createCipher({ | |
key, | |
output: null, | |
decrypt: true, | |
mode | |
}); | |
}; | |
forge7.aes.Algorithm = function(name8, mode) { | |
if (!init) { | |
initialize(); | |
} | |
var self2 = this; | |
self2.name = name8; | |
self2.mode = new mode({ | |
blockSize: 16, | |
cipher: { | |
encrypt: function(inBlock, outBlock) { | |
return _updateBlock(self2._w, inBlock, outBlock, false); | |
}, | |
decrypt: function(inBlock, outBlock) { | |
return _updateBlock(self2._w, inBlock, outBlock, true); | |
} | |
} | |
}); | |
self2._init = false; | |
}; | |
forge7.aes.Algorithm.prototype.initialize = function(options) { | |
if (this._init) { | |
return; | |
} | |
var key = options.key; | |
var tmp; | |
if (typeof key === "string" && (key.length === 16 || key.length === 24 || key.length === 32)) { | |
key = forge7.util.createBuffer(key); | |
} else if (forge7.util.isArray(key) && (key.length === 16 || key.length === 24 || key.length === 32)) { | |
tmp = key; | |
key = forge7.util.createBuffer(); | |
for (var i = 0; i < tmp.length; ++i) { | |
key.putByte(tmp[i]); | |
} | |
} | |
if (!forge7.util.isArray(key)) { | |
tmp = key; | |
key = []; | |
var len = tmp.length(); | |
if (len === 16 || len === 24 || len === 32) { | |
len = len >>> 2; | |
for (var i = 0; i < len; ++i) { | |
key.push(tmp.getInt32()); | |
} | |
} | |
} | |
if (!forge7.util.isArray(key) || !(key.length === 4 || key.length === 6 || key.length === 8)) { | |
throw new Error("Invalid key parameter."); | |
} | |
var mode = this.mode.name; | |
var encryptOp = ["CFB", "OFB", "CTR", "GCM"].indexOf(mode) !== -1; | |
this._w = _expandKey(key, options.decrypt && !encryptOp); | |
this._init = true; | |
}; | |
forge7.aes._expandKey = function(key, decrypt2) { | |
if (!init) { | |
initialize(); | |
} | |
return _expandKey(key, decrypt2); | |
}; | |
forge7.aes._updateBlock = _updateBlock; | |
registerAlgorithm("AES-ECB", forge7.cipher.modes.ecb); | |
registerAlgorithm("AES-CBC", forge7.cipher.modes.cbc); | |
registerAlgorithm("AES-CFB", forge7.cipher.modes.cfb); | |
registerAlgorithm("AES-OFB", forge7.cipher.modes.ofb); | |
registerAlgorithm("AES-CTR", forge7.cipher.modes.ctr); | |
registerAlgorithm("AES-GCM", forge7.cipher.modes.gcm); | |
function registerAlgorithm(name8, mode) { | |
var factory = function() { | |
return new forge7.aes.Algorithm(name8, mode); | |
}; | |
forge7.cipher.registerAlgorithm(name8, factory); | |
} | |
var init = false; | |
var Nb = 4; | |
var sbox; | |
var isbox; | |
var rcon; | |
var mix; | |
var imix; | |
function initialize() { | |
init = true; | |
rcon = [0, 1, 2, 4, 8, 16, 32, 64, 128, 27, 54]; | |
var xtime = new Array(256); | |
for (var i = 0; i < 128; ++i) { | |
xtime[i] = i << 1; | |
xtime[i + 128] = i + 128 << 1 ^ 283; | |
} | |
sbox = new Array(256); | |
isbox = new Array(256); | |
mix = new Array(4); | |
imix = new Array(4); | |
for (var i = 0; i < 4; ++i) { | |
mix[i] = new Array(256); | |
imix[i] = new Array(256); | |
} | |
var e = 0, ei = 0, e2, e4, e8, sx, sx2, me, ime; | |
for (var i = 0; i < 256; ++i) { | |
sx = ei ^ ei << 1 ^ ei << 2 ^ ei << 3 ^ ei << 4; | |
sx = sx >> 8 ^ sx & 255 ^ 99; | |
sbox[e] = sx; | |
isbox[sx] = e; | |
sx2 = xtime[sx]; | |
e2 = xtime[e]; | |
e4 = xtime[e2]; | |
e8 = xtime[e4]; | |
me = sx2 << 24 ^ // 2 | |
sx << 16 ^ // 1 | |
sx << 8 ^ // 1 | |
(sx ^ sx2); | |
ime = (e2 ^ e4 ^ e8) << 24 ^ // E (14) | |
(e ^ e8) << 16 ^ // 9 | |
(e ^ e4 ^ e8) << 8 ^ // D (13) | |
(e ^ e2 ^ e8); | |
for (var n = 0; n < 4; ++n) { | |
mix[n][e] = me; | |
imix[n][sx] = ime; | |
me = me << 24 | me >>> 8; | |
ime = ime << 24 | ime >>> 8; | |
} | |
if (e === 0) { | |
e = ei = 1; | |
} else { | |
e = e2 ^ xtime[xtime[xtime[e2 ^ e8]]]; | |
ei ^= xtime[xtime[ei]]; | |
} | |
} | |
} | |
function _expandKey(key, decrypt2) { | |
var w = key.slice(0); | |
var temp, iNk = 1; | |
var Nk = w.length; | |
var Nr1 = Nk + 6 + 1; | |
var end = Nb * Nr1; | |
for (var i = Nk; i < end; ++i) { | |
temp = w[i - 1]; | |
if (i % Nk === 0) { | |
temp = sbox[temp >>> 16 & 255] << 24 ^ sbox[temp >>> 8 & 255] << 16 ^ sbox[temp & 255] << 8 ^ sbox[temp >>> 24] ^ rcon[iNk] << 24; | |
iNk++; | |
} else if (Nk > 6 && i % Nk === 4) { | |
temp = sbox[temp >>> 24] << 24 ^ sbox[temp >>> 16 & 255] << 16 ^ sbox[temp >>> 8 & 255] << 8 ^ sbox[temp & 255]; | |
} | |
w[i] = w[i - Nk] ^ temp; | |
} | |
if (decrypt2) { | |
var tmp; | |
var m0 = imix[0]; | |
var m1 = imix[1]; | |
var m2 = imix[2]; | |
var m3 = imix[3]; | |
var wnew = w.slice(0); | |
end = w.length; | |
for (var i = 0, wi = end - Nb; i < end; i += Nb, wi -= Nb) { | |
if (i === 0 || i === end - Nb) { | |
wnew[i] = w[wi]; | |
wnew[i + 1] = w[wi + 3]; | |
wnew[i + 2] = w[wi + 2]; | |
wnew[i + 3] = w[wi + 1]; | |
} else { | |
for (var n = 0; n < Nb; ++n) { | |
tmp = w[wi + n]; | |
wnew[i + (3 & -n)] = m0[sbox[tmp >>> 24]] ^ m1[sbox[tmp >>> 16 & 255]] ^ m2[sbox[tmp >>> 8 & 255]] ^ m3[sbox[tmp & 255]]; | |
} | |
} | |
} | |
w = wnew; | |
} | |
return w; | |
} | |
function _updateBlock(w, input, output3, decrypt2) { | |
var Nr = w.length / 4 - 1; | |
var m0, m1, m2, m3, sub; | |
if (decrypt2) { | |
m0 = imix[0]; | |
m1 = imix[1]; | |
m2 = imix[2]; | |
m3 = imix[3]; | |
sub = isbox; | |
} else { | |
m0 = mix[0]; | |
m1 = mix[1]; | |
m2 = mix[2]; | |
m3 = mix[3]; | |
sub = sbox; | |
} | |
var a, b, c, d, a2, b2, c2; | |
a = input[0] ^ w[0]; | |
b = input[decrypt2 ? 3 : 1] ^ w[1]; | |
c = input[2] ^ w[2]; | |
d = input[decrypt2 ? 1 : 3] ^ w[3]; | |
var i = 3; | |
for (var round = 1; round < Nr; ++round) { | |
a2 = m0[a >>> 24] ^ m1[b >>> 16 & 255] ^ m2[c >>> 8 & 255] ^ m3[d & 255] ^ w[++i]; | |
b2 = m0[b >>> 24] ^ m1[c >>> 16 & 255] ^ m2[d >>> 8 & 255] ^ m3[a & 255] ^ w[++i]; | |
c2 = m0[c >>> 24] ^ m1[d >>> 16 & 255] ^ m2[a >>> 8 & 255] ^ m3[b & 255] ^ w[++i]; | |
d = m0[d >>> 24] ^ m1[a >>> 16 & 255] ^ m2[b >>> 8 & 255] ^ m3[c & 255] ^ w[++i]; | |
a = a2; | |
b = b2; | |
c = c2; | |
} | |
output3[0] = sub[a >>> 24] << 24 ^ sub[b >>> 16 & 255] << 16 ^ sub[c >>> 8 & 255] << 8 ^ sub[d & 255] ^ w[++i]; | |
output3[decrypt2 ? 3 : 1] = sub[b >>> 24] << 24 ^ sub[c >>> 16 & 255] << 16 ^ sub[d >>> 8 & 255] << 8 ^ sub[a & 255] ^ w[++i]; | |
output3[2] = sub[c >>> 24] << 24 ^ sub[d >>> 16 & 255] << 16 ^ sub[a >>> 8 & 255] << 8 ^ sub[b & 255] ^ w[++i]; | |
output3[decrypt2 ? 1 : 3] = sub[d >>> 24] << 24 ^ sub[a >>> 16 & 255] << 16 ^ sub[b >>> 8 & 255] << 8 ^ sub[c & 255] ^ w[++i]; | |
} | |
function _createCipher(options) { | |
options = options || {}; | |
var mode = (options.mode || "CBC").toUpperCase(); | |
var algorithm = "AES-" + mode; | |
var cipher; | |
if (options.decrypt) { | |
cipher = forge7.cipher.createDecipher(algorithm, options.key); | |
} else { | |
cipher = forge7.cipher.createCipher(algorithm, options.key); | |
} | |
var start = cipher.start; | |
cipher.start = function(iv, options2) { | |
var output3 = null; | |
if (options2 instanceof forge7.util.ByteBuffer) { | |
output3 = options2; | |
options2 = {}; | |
} | |
options2 = options2 || {}; | |
options2.output = output3; | |
options2.iv = iv; | |
start.call(cipher, options2); | |
}; | |
return cipher; | |
} | |
} | |
}); | |
// node_modules/node-forge/lib/des.js | |
var require_des = __commonJS({ | |
"node_modules/node-forge/lib/des.js"(exports2, module2) { | |
var forge7 = require_forge(); | |
require_cipher(); | |
require_cipherModes(); | |
require_util(); | |
module2.exports = forge7.des = forge7.des || {}; | |
forge7.des.startEncrypting = function(key, iv, output3, mode) { | |
var cipher = _createCipher({ | |
key, | |
output: output3, | |
decrypt: false, | |
mode: mode || (iv === null ? "ECB" : "CBC") | |
}); | |
cipher.start(iv); | |
return cipher; | |
}; | |
forge7.des.createEncryptionCipher = function(key, mode) { | |
return _createCipher({ | |
key, | |
output: null, | |
decrypt: false, | |
mode | |
}); | |
}; | |
forge7.des.startDecrypting = function(key, iv, output3, mode) { | |
var cipher = _createCipher({ | |
key, | |
output: output3, | |
decrypt: true, | |
mode: mode || (iv === null ? "ECB" : "CBC") | |
}); | |
cipher.start(iv); | |
return cipher; | |
}; | |
forge7.des.createDecryptionCipher = function(key, mode) { | |
return _createCipher({ | |
key, | |
output: null, | |
decrypt: true, | |
mode | |
}); | |
}; | |
forge7.des.Algorithm = function(name8, mode) { | |
var self2 = this; | |
self2.name = name8; | |
self2.mode = new mode({ | |
blockSize: 8, | |
cipher: { | |
encrypt: function(inBlock, outBlock) { | |
return _updateBlock(self2._keys, inBlock, outBlock, false); | |
}, | |
decrypt: function(inBlock, outBlock) { | |
return _updateBlock(self2._keys, inBlock, outBlock, true); | |
} | |
} | |
}); | |
self2._init = false; | |
}; | |
forge7.des.Algorithm.prototype.initialize = function(options) { | |
if (this._init) { | |
return; | |
} | |
var key = forge7.util.createBuffer(options.key); | |
if (this.name.indexOf("3DES") === 0) { | |
if (key.length() !== 24) { | |
throw new Error("Invalid Triple-DES key size: " + key.length() * 8); | |
} | |
} | |
this._keys = _createKeys(key); | |
this._init = true; | |
}; | |
registerAlgorithm("DES-ECB", forge7.cipher.modes.ecb); | |
registerAlgorithm("DES-CBC", forge7.cipher.modes.cbc); | |
registerAlgorithm("DES-CFB", forge7.cipher.modes.cfb); | |
registerAlgorithm("DES-OFB", forge7.cipher.modes.ofb); | |
registerAlgorithm("DES-CTR", forge7.cipher.modes.ctr); | |
registerAlgorithm("3DES-ECB", forge7.cipher.modes.ecb); | |
registerAlgorithm("3DES-CBC", forge7.cipher.modes.cbc); | |
registerAlgorithm("3DES-CFB", forge7.cipher.modes.cfb); | |
registerAlgorithm("3DES-OFB", forge7.cipher.modes.ofb); | |
registerAlgorithm("3DES-CTR", forge7.cipher.modes.ctr); | |
function registerAlgorithm(name8, mode) { | |
var factory = function() { | |
return new forge7.des.Algorithm(name8, mode); | |
}; | |
forge7.cipher.registerAlgorithm(name8, factory); | |
} | |
var spfunction1 = [16843776, 0, 65536, 16843780, 16842756, 66564, 4, 65536, 1024, 16843776, 16843780, 1024, 16778244, 16842756, 16777216, 4, 1028, 16778240, 16778240, 66560, 66560, 16842752, 16842752, 16778244, 65540, 16777220, 16777220, 65540, 0, 1028, 66564, 16777216, 65536, 16843780, 4, 16842752, 16843776, 16777216, 16777216, 1024, 16842756, 65536, 66560, 16777220, 1024, 4, 16778244, 66564, 16843780, 65540, 16842752, 16778244, 16777220, 1028, 66564, 16843776, 1028, 16778240, 16778240, 0, 65540, 66560, 0, 16842756]; | |
var spfunction2 = [-2146402272, -2147450880, 32768, 1081376, 1048576, 32, -2146435040, -2147450848, -2147483616, -2146402272, -2146402304, -2147483648, -2147450880, 1048576, 32, -2146435040, 1081344, 1048608, -2147450848, 0, -2147483648, 32768, 1081376, -2146435072, 1048608, -2147483616, 0, 1081344, 32800, -2146402304, -2146435072, 32800, 0, 1081376, -2146435040, 1048576, -2147450848, -2146435072, -2146402304, 32768, -2146435072, -2147450880, 32, -2146402272, 1081376, 32, 32768, -2147483648, 32800, -2146402304, 1048576, -2147483616, 1048608, -2147450848, -2147483616, 1048608, 1081344, 0, -2147450880, 32800, -2147483648, -2146435040, -2146402272, 1081344]; | |
var spfunction3 = [520, 134349312, 0, 134348808, 134218240, 0, 131592, 134218240, 131080, 134217736, 134217736, 131072, 134349320, 131080, 134348800, 520, 134217728, 8, 134349312, 512, 131584, 134348800, 134348808, 131592, 134218248, 131584, 131072, 134218248, 8, 134349320, 512, 134217728, 134349312, 134217728, 131080, 520, 131072, 134349312, 134218240, 0, 512, 131080, 134349320, 134218240, 134217736, 512, 0, 134348808, 134218248, 131072, 134217728, 134349320, 8, 131592, 131584, 134217736, 134348800, 134218248, 520, 134348800, 131592, 8, 134348808, 131584]; | |
var spfunction4 = [8396801, 8321, 8321, 128, 8396928, 8388737, 8388609, 8193, 0, 8396800, 8396800, 8396929, 129, 0, 8388736, 8388609, 1, 8192, 8388608, 8396801, 128, 8388608, 8193, 8320, 8388737, 1, 8320, 8388736, 8192, 8396928, 8396929, 129, 8388736, 8388609, 8396800, 8396929, 129, 0, 0, 8396800, 8320, 8388736, 8388737, 1, 8396801, 8321, 8321, 128, 8396929, 129, 1, 8192, 8388609, 8193, 8396928, 8388737, 8193, 8320, 8388608, 8396801, 128, 8388608, 8192, 8396928]; | |
var spfunction5 = [256, 34078976, 34078720, 1107296512, 524288, 256, 1073741824, 34078720, 1074266368, 524288, 33554688, 1074266368, 1107296512, 1107820544, 524544, 1073741824, 33554432, 1074266112, 1074266112, 0, 1073742080, 1107820800, 1107820800, 33554688, 1107820544, 1073742080, 0, 1107296256, 34078976, 33554432, 1107296256, 524544, 524288, 1107296512, 256, 33554432, 1073741824, 34078720, 1107296512, 1074266368, 33554688, 1073741824, 1107820544, 34078976, 1074266368, 256, 33554432, 1107820544, 1107820800, 524544, 1107296256, 1107820800, 34078720, 0, 1074266112, 1107296256, 524544, 33554688, 1073742080, 524288, 0, 1074266112, 34078976, 1073742080]; | |
var spfunction6 = [536870928, 541065216, 16384, 541081616, 541065216, 16, 541081616, 4194304, 536887296, 4210704, 4194304, 536870928, 4194320, 536887296, 536870912, 16400, 0, 4194320, 536887312, 16384, 4210688, 536887312, 16, 541065232, 541065232, 0, 4210704, 541081600, 16400, 4210688, 541081600, 536870912, 536887296, 16, 541065232, 4210688, 541081616, 4194304, 16400, 536870928, 4194304, 536887296, 536870912, 16400, 536870928, 541081616, 4210688, 541065216, 4210704, 541081600, 0, 541065232, 16, 16384, 541065216, 4210704, 16384, 4194320, 536887312, 0, 541081600, 536870912, 4194320, 536887312]; | |
var spfunction7 = [2097152, 69206018, 67110914, 0, 2048, 67110914, 2099202, 69208064, 69208066, 2097152, 0, 67108866, 2, 67108864, 69206018, 2050, 67110912, 2099202, 2097154, 67110912, 67108866, 69206016, 69208064, 2097154, 69206016, 2048, 2050, 69208066, 2099200, 2, 67108864, 2099200, 67108864, 2099200, 2097152, 67110914, 67110914, 69206018, 69206018, 2, 2097154, 67108864, 67110912, 2097152, 69208064, 2050, 2099202, 69208064, 2050, 67108866, 69208066, 69206016, 2099200, 0, 2, 69208066, 0, 2099202, 69206016, 2048, 67108866, 67110912, 2048, 2097154]; | |
var spfunction8 = [268439616, 4096, 262144, 268701760, 268435456, 268439616, 64, 268435456, 262208, 268697600, 268701760, 266240, 268701696, 266304, 4096, 64, 268697600, 268435520, 268439552, 4160, 266240, 262208, 268697664, 268701696, 4160, 0, 0, 268697664, 268435520, 268439552, 266304, 262144, 266304, 262144, 268701696, 4096, 64, 268697664, 4096, 266304, 268439552, 64, 268435520, 268697600, 268697664, 268435456, 262144, 268439616, 0, 268701760, 262208, 268435520, 268697600, 268439552, 268439616, 0, 268701760, 266240, 266240, 4160, 4160, 262208, 268435456, 268701696]; | |
function _createKeys(key) { | |
var pc2bytes0 = [0, 4, 536870912, 536870916, 65536, 65540, 536936448, 536936452, 512, 516, 536871424, 536871428, 66048, 66052, 536936960, 536936964], pc2bytes1 = [0, 1, 1048576, 1048577, 67108864, 67108865, 68157440, 68157441, 256, 257, 1048832, 1048833, 67109120, 67109121, 68157696, 68157697], pc2bytes2 = [0, 8, 2048, 2056, 16777216, 16777224, 16779264, 16779272, 0, 8, 2048, 2056, 16777216, 16777224, 16779264, 16779272], pc2bytes3 = [0, 2097152, 134217728, 136314880, 8192, 2105344, 134225920, 136323072, 131072, 2228224, 134348800, 136445952, 139264, 2236416, 134356992, 136454144], pc2bytes4 = [0, 262144, 16, 262160, 0, 262144, 16, 262160, 4096, 266240, 4112, 266256, 4096, 266240, 4112, 266256], pc2bytes5 = [0, 1024, 32, 1056, 0, 1024, 32, 1056, 33554432, 33555456, 33554464, 33555488, 33554432, 33555456, 33554464, 33555488], pc2bytes6 = [0, 268435456, 524288, 268959744, 2, 268435458, 524290, 268959746, 0, 268435456, 524288, 268959744, 2, 268435458, 524290, 268959746], pc2bytes7 = [0, 65536, 2048, 67584, 536870912, 536936448, 536872960, 536938496, 131072, 196608, 133120, 198656, 537001984, 537067520, 537004032, 537069568], pc2bytes8 = [0, 262144, 0, 262144, 2, 262146, 2, 262146, 33554432, 33816576, 33554432, 33816576, 33554434, 33816578, 33554434, 33816578], pc2bytes9 = [0, 268435456, 8, 268435464, 0, 268435456, 8, 268435464, 1024, 268436480, 1032, 268436488, 1024, 268436480, 1032, 268436488], pc2bytes10 = [0, 32, 0, 32, 1048576, 1048608, 1048576, 1048608, 8192, 8224, 8192, 8224, 1056768, 1056800, 1056768, 1056800], pc2bytes11 = [0, 16777216, 512, 16777728, 2097152, 18874368, 2097664, 18874880, 67108864, 83886080, 67109376, 83886592, 69206016, 85983232, 69206528, 85983744], pc2bytes12 = [0, 4096, 134217728, 134221824, 524288, 528384, 134742016, 134746112, 16, 4112, 134217744, 134221840, 524304, 528400, 134742032, 134746128], pc2bytes13 = [0, 4, 256, 260, 0, 4, 256, 260, 1, 5, 257, 261, 1, 5, 257, 261]; | |
var iterations = key.length() > 8 ? 3 : 1; | |
var keys = []; | |
var shifts = [0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0]; | |
var n = 0, tmp; | |
for (var j = 0; j < iterations; j++) { | |
var left = key.getInt32(); | |
var right = key.getInt32(); | |
tmp = (left >>> 4 ^ right) & 252645135; | |
right ^= tmp; | |
left ^= tmp << 4; | |
tmp = (right >>> -16 ^ left) & 65535; | |
left ^= tmp; | |
right ^= tmp << -16; | |
tmp = (left >>> 2 ^ right) & 858993459; | |
right ^= tmp; | |
left ^= tmp << 2; | |
tmp = (right >>> -16 ^ left) & 65535; | |
left ^= tmp; | |
right ^= tmp << -16; | |
tmp = (left >>> 1 ^ right) & 1431655765; | |
right ^= tmp; | |
left ^= tmp << 1; | |
tmp = (right >>> 8 ^ left) & 16711935; | |
left ^= tmp; | |
right ^= tmp << 8; | |
tmp = (left >>> 1 ^ right) & 1431655765; | |
right ^= tmp; | |
left ^= tmp << 1; | |
tmp = left << 8 | right >>> 20 & 240; | |
left = right << 24 | right << 8 & 16711680 | right >>> 8 & 65280 | right >>> 24 & 240; | |
right = tmp; | |
for (var i = 0; i < shifts.length; ++i) { | |
if (shifts[i]) { | |
left = left << 2 | left >>> 26; | |
right = right << 2 | right >>> 26; | |
} else { | |
left = left << 1 | left >>> 27; | |
right = right << 1 | right >>> 27; | |
} | |
left &= -15; | |
right &= -15; | |
var lefttmp = pc2bytes0[left >>> 28] | pc2bytes1[left >>> 24 & 15] | pc2bytes2[left >>> 20 & 15] | pc2bytes3[left >>> 16 & 15] | pc2bytes4[left >>> 12 & 15] | pc2bytes5[left >>> 8 & 15] | pc2bytes6[left >>> 4 & 15]; | |
var righttmp = pc2bytes7[right >>> 28] | pc2bytes8[right >>> 24 & 15] | pc2bytes9[right >>> 20 & 15] | pc2bytes10[right >>> 16 & 15] | pc2bytes11[right >>> 12 & 15] | pc2bytes12[right >>> 8 & 15] | pc2bytes13[right >>> 4 & 15]; | |
tmp = (righttmp >>> 16 ^ lefttmp) & 65535; | |
keys[n++] = lefttmp ^ tmp; | |
keys[n++] = righttmp ^ tmp << 16; | |
} | |
} | |
return keys; | |
} | |
function _updateBlock(keys, input, output3, decrypt2) { | |
var iterations = keys.length === 32 ? 3 : 9; | |
var looping; | |
if (iterations === 3) { | |
looping = decrypt2 ? [30, -2, -2] : [0, 32, 2]; | |
} else { | |
looping = decrypt2 ? [94, 62, -2, 32, 64, 2, 30, -2, -2] : [0, 32, 2, 62, 30, -2, 64, 96, 2]; | |
} | |
var tmp; | |
var left = input[0]; | |
var right = input[1]; | |
tmp = (left >>> 4 ^ right) & 252645135; | |
right ^= tmp; | |
left ^= tmp << 4; | |
tmp = (left >>> 16 ^ right) & 65535; | |
right ^= tmp; | |
left ^= tmp << 16; | |
tmp = (right >>> 2 ^ left) & 858993459; | |
left ^= tmp; | |
right ^= tmp << 2; | |
tmp = (right >>> 8 ^ left) & 16711935; | |
left ^= tmp; | |
right ^= tmp << 8; | |
tmp = (left >>> 1 ^ right) & 1431655765; | |
right ^= tmp; | |
left ^= tmp << 1; | |
left = left << 1 | left >>> 31; | |
right = right << 1 | right >>> 31; | |
for (var j = 0; j < iterations; j += 3) { | |
var endloop = looping[j + 1]; | |
var loopinc = looping[j + 2]; | |
for (var i = looping[j]; i != endloop; i += loopinc) { | |
var right1 = right ^ keys[i]; | |
var right2 = (right >>> 4 | right << 28) ^ keys[i + 1]; | |
tmp = left; | |
left = right; | |
right = tmp ^ (spfunction2[right1 >>> 24 & 63] | spfunction4[right1 >>> 16 & 63] | spfunction6[right1 >>> 8 & 63] | spfunction8[right1 & 63] | spfunction1[right2 >>> 24 & 63] | spfunction3[right2 >>> 16 & 63] | spfunction5[right2 >>> 8 & 63] | spfunction7[right2 & 63]); | |
} | |
tmp = left; | |
left = right; | |
right = tmp; | |
} | |
left = left >>> 1 | left << 31; | |
right = right >>> 1 | right << 31; | |
tmp = (left >>> 1 ^ right) & 1431655765; | |
right ^= tmp; | |
left ^= tmp << 1; | |
tmp = (right >>> 8 ^ left) & 16711935; | |
left ^= tmp; | |
right ^= tmp << 8; | |
tmp = (right >>> 2 ^ left) & 858993459; | |
left ^= tmp; | |
right ^= tmp << 2; | |
tmp = (left >>> 16 ^ right) & 65535; | |
right ^= tmp; | |
left ^= tmp << 16; | |
tmp = (left >>> 4 ^ right) & 252645135; | |
right ^= tmp; | |
left ^= tmp << 4; | |
output3[0] = left; | |
output3[1] = right; | |
} | |
function _createCipher(options) { | |
options = options || {}; | |
var mode = (options.mode || "CBC").toUpperCase(); | |
var algorithm = "DES-" + mode; | |
var cipher; | |
if (options.decrypt) { | |
cipher = forge7.cipher.createDecipher(algorithm, options.key); | |
} else { | |
cipher = forge7.cipher.createCipher(algorithm, options.key); | |
} | |
var start = cipher.start; | |
cipher.start = function(iv, options2) { | |
var output3 = null; | |
if (options2 instanceof forge7.util.ByteBuffer) { | |
output3 = options2; | |
options2 = {}; | |
} | |
options2 = options2 || {}; | |
options2.output = output3; | |
options2.iv = iv; | |
start.call(cipher, options2); | |
}; | |
return cipher; | |
} | |
} | |
}); | |
// node_modules/node-forge/lib/md.js | |
var require_md = __commonJS({ | |
"node_modules/node-forge/lib/md.js"(exports2, module2) { | |
var forge7 = require_forge(); | |
module2.exports = forge7.md = forge7.md || {}; | |
forge7.md.algorithms = forge7.md.algorithms || {}; | |
} | |
}); | |
// node_modules/node-forge/lib/hmac.js | |
var require_hmac = __commonJS({ | |
"node_modules/node-forge/lib/hmac.js"(exports2, module2) { | |
var forge7 = require_forge(); | |
require_md(); | |
require_util(); | |
var hmac2 = module2.exports = forge7.hmac = forge7.hmac || {}; | |
hmac2.create = function() { | |
var _key = null; | |
var _md = null; | |
var _ipadding = null; | |
var _opadding = null; | |
var ctx = {}; | |
ctx.start = function(md, key) { | |
if (md !== null) { | |
if (typeof md === "string") { | |
md = md.toLowerCase(); | |
if (md in forge7.md.algorithms) { | |
_md = forge7.md.algorithms[md].create(); | |
} else { | |
throw new Error('Unknown hash algorithm "' + md + '"'); | |
} | |
} else { | |
_md = md; | |
} | |
} | |
if (key === null) { | |
key = _key; | |
} else { | |
if (typeof key === "string") { | |
key = forge7.util.createBuffer(key); | |
} else if (forge7.util.isArray(key)) { | |
var tmp = key; | |
key = forge7.util.createBuffer(); | |
for (var i = 0; i < tmp.length; ++i) { | |
key.putByte(tmp[i]); | |
} | |
} | |
var keylen = key.length(); | |
if (keylen > _md.blockLength) { | |
_md.start(); | |
_md.update(key.bytes()); | |
key = _md.digest(); | |
} | |
_ipadding = forge7.util.createBuffer(); | |
_opadding = forge7.util.createBuffer(); | |
keylen = key.length(); | |
for (var i = 0; i < keylen; ++i) { | |
var tmp = key.at(i); | |
_ipadding.putByte(54 ^ tmp); | |
_opadding.putByte(92 ^ tmp); | |
} | |
if (keylen < _md.blockLength) { | |
var tmp = _md.blockLength - keylen; | |
for (var i = 0; i < tmp; ++i) { | |
_ipadding.putByte(54); | |
_opadding.putByte(92); | |
} | |
} | |
_key = key; | |
_ipadding = _ipadding.bytes(); | |
_opadding = _opadding.bytes(); | |
} | |
_md.start(); | |
_md.update(_ipadding); | |
}; | |
ctx.update = function(bytes3) { | |
_md.update(bytes3); | |
}; | |
ctx.getMac = function() { | |
var inner = _md.digest().bytes(); | |
_md.start(); | |
_md.update(_opadding); | |
_md.update(inner); | |
return _md.digest(); | |
}; | |
ctx.digest = ctx.getMac; | |
return ctx; | |
}; | |
} | |
}); | |
// (disabled):crypto | |
var require_crypto = __commonJS({ | |
"(disabled):crypto"() { | |
} | |
}); | |
// node_modules/node-forge/lib/pbkdf2.js | |
var require_pbkdf2 = __commonJS({ | |
"node_modules/node-forge/lib/pbkdf2.js"(exports2, module2) { | |
var forge7 = require_forge(); | |
require_hmac(); | |
require_md(); | |
require_util(); | |
var pkcs5 = forge7.pkcs5 = forge7.pkcs5 || {}; | |
var crypto5; | |
if (forge7.util.isNodejs && !forge7.options.usePureJavaScript) { | |
crypto5 = require_crypto(); | |
} | |
module2.exports = forge7.pbkdf2 = pkcs5.pbkdf2 = function(p, s, c, dkLen, md, callback) { | |
if (typeof md === "function") { | |
callback = md; | |
md = null; | |
} | |
if (forge7.util.isNodejs && !forge7.options.usePureJavaScript && crypto5.pbkdf2 && (md === null || typeof md !== "object") && (crypto5.pbkdf2Sync.length > 4 || (!md || md === "sha1"))) { | |
if (typeof md !== "string") { | |
md = "sha1"; | |
} | |
p = Buffer.from(p, "binary"); | |
s = Buffer.from(s, "binary"); | |
if (!callback) { | |
if (crypto5.pbkdf2Sync.length === 4) { | |
return crypto5.pbkdf2Sync(p, s, c, dkLen).toString("binary"); | |
} | |
return crypto5.pbkdf2Sync(p, s, c, dkLen, md).toString("binary"); | |
} | |
if (crypto5.pbkdf2Sync.length === 4) { | |
return crypto5.pbkdf2(p, s, c, dkLen, function(err2, key) { | |
if (err2) { | |
return callback(err2); | |
} | |
callback(null, key.toString("binary")); | |
}); | |
} | |
return crypto5.pbkdf2(p, s, c, dkLen, md, function(err2, key) { | |
if (err2) { | |
return callback(err2); | |
} | |
callback(null, key.toString("binary")); | |
}); | |
} | |
if (typeof md === "undefined" || md === null) { | |
md = "sha1"; | |
} | |
if (typeof md === "string") { | |
if (!(md in forge7.md.algorithms)) { | |
throw new Error("Unknown hash algorithm: " + md); | |
} | |
md = forge7.md[md].create(); | |
} | |
var hLen = md.digestLength; | |
if (dkLen > 4294967295 * hLen) { | |
var err = new Error("Derived key is too long."); | |
if (callback) { | |
return callback(err); | |
} | |
throw err; | |
} | |
var len = Math.ceil(dkLen / hLen); | |
var r = dkLen - (len - 1) * hLen; | |
var prf = forge7.hmac.create(); | |
prf.start(md, p); | |
var dk = ""; | |
var xor2, u_c, u_c1; | |
if (!callback) { | |
for (var i = 1; i <= len; ++i) { | |
prf.start(null, null); | |
prf.update(s); | |
prf.update(forge7.util.int32ToBytes(i)); | |
xor2 = u_c1 = prf.digest().getBytes(); | |
for (var j = 2; j <= c; ++j) { | |
prf.start(null, null); | |
prf.update(u_c1); | |
u_c = prf.digest().getBytes(); | |
xor2 = forge7.util.xorBytes(xor2, u_c, hLen); | |
u_c1 = u_c; | |
} | |
dk += i < len ? xor2 : xor2.substr(0, r); | |
} | |
return dk; | |
} | |
var i = 1, j; | |
function outer() { | |
if (i > len) { | |
return callback(null, dk); | |
} | |
prf.start(null, null); | |
prf.update(s); | |
prf.update(forge7.util.int32ToBytes(i)); | |
xor2 = u_c1 = prf.digest().getBytes(); | |
j = 2; | |
inner(); | |
} | |
function inner() { | |
if (j <= c) { | |
prf.start(null, null); | |
prf.update(u_c1); | |
u_c = prf.digest().getBytes(); | |
xor2 = forge7.util.xorBytes(xor2, u_c, hLen); | |
u_c1 = u_c; | |
++j; | |
return forge7.util.setImmediate(inner); | |
} | |
dk += i < len ? xor2 : xor2.substr(0, r); | |
++i; | |
outer(); | |
} | |
outer(); | |
}; | |
} | |
}); | |
// node_modules/node-forge/lib/pem.js | |
var require_pem = __commonJS({ | |
"node_modules/node-forge/lib/pem.js"(exports2, module2) { | |
var forge7 = require_forge(); | |
require_util(); | |
var pem = module2.exports = forge7.pem = forge7.pem || {}; | |
pem.encode = function(msg, options) { | |
options = options || {}; | |
var rval = "-----BEGIN " + msg.type + "-----\r\n"; | |
var header; | |
if (msg.procType) { | |
header = { | |
name: "Proc-Type", | |
values: [String(msg.procType.version), msg.procType.type] | |
}; | |
rval += foldHeader(header); | |
} | |
if (msg.contentDomain) { | |
header = { name: "Content-Domain", values: [msg.contentDomain] }; | |
rval += foldHeader(header); | |
} | |
if (msg.dekInfo) { | |
header = { name: "DEK-Info", values: [msg.dekInfo.algorithm] }; | |
if (msg.dekInfo.parameters) { | |
header.values.push(msg.dekInfo.parameters); | |
} | |
rval += foldHeader(header); | |
} | |
if (msg.headers) { | |
for (var i = 0; i < msg.headers.length; ++i) { | |
rval += foldHeader(msg.headers[i]); | |
} | |
} | |
if (msg.procType) { | |
rval += "\r\n"; | |
} | |
rval += forge7.util.encode64(msg.body, options.maxline || 64) + "\r\n"; | |
rval += "-----END " + msg.type + "-----\r\n"; | |
return rval; | |
}; | |
pem.decode = function(str) { | |
var rval = []; | |
var rMessage = /\s*-----BEGIN ([A-Z0-9- ]+)-----\r?\n?([\x21-\x7e\s]+?(?:\r?\n\r?\n))?([:A-Za-z0-9+\/=\s]+?)-----END \1-----/g; | |
var rHeader = /([\x21-\x7e]+):\s*([\x21-\x7e\s^:]+)/; | |
var rCRLF = /\r?\n/; | |
var match; | |
while (true) { | |
match = rMessage.exec(str); | |
if (!match) { | |
break; | |
} | |
var type = match[1]; | |
if (type === "NEW CERTIFICATE REQUEST") { | |
type = "CERTIFICATE REQUEST"; | |
} | |
var msg = { | |
type, | |
procType: null, | |
contentDomain: null, | |
dekInfo: null, | |
headers: [], | |
body: forge7.util.decode64(match[3]) | |
}; | |
rval.push(msg); | |
if (!match[2]) { | |
continue; | |
} | |
var lines = match[2].split(rCRLF); | |
var li = 0; | |
while (match && li < lines.length) { | |
var line = lines[li].replace(/\s+$/, ""); | |
for (var nl = li + 1; nl < lines.length; ++nl) { | |
var next = lines[nl]; | |
if (!/\s/.test(next[0])) { | |
break; | |
} | |
line += next; | |
li = nl; | |
} | |
match = line.match(rHeader); | |
if (match) { | |
var header = { name: match[1], values: [] }; | |
var values = match[2].split(","); | |
for (var vi = 0; vi < values.length; ++vi) { | |
header.values.push(ltrim(values[vi])); | |
} | |
if (!msg.procType) { | |
if (header.name !== "Proc-Type") { | |
throw new Error('Invalid PEM formatted message. The first encapsulated header must be "Proc-Type".'); | |
} else if (header.values.length !== 2) { | |
throw new Error('Invalid PEM formatted message. The "Proc-Type" header must have two subfields.'); | |
} | |
msg.procType = { version: values[0], type: values[1] }; | |
} else if (!msg.contentDomain && header.name === "Content-Domain") { | |
msg.contentDomain = values[0] || ""; | |
} else if (!msg.dekInfo && header.name === "DEK-Info") { | |
if (header.values.length === 0) { | |
throw new Error('Invalid PEM formatted message. The "DEK-Info" header must have at least one subfield.'); | |
} | |
msg.dekInfo = { algorithm: values[0], parameters: values[1] || null }; | |
} else { | |
msg.headers.push(header); | |
} | |
} | |
++li; | |
} | |
if (msg.procType === "ENCRYPTED" && !msg.dekInfo) { | |
throw new Error('Invalid PEM formatted message. The "DEK-Info" header must be present if "Proc-Type" is "ENCRYPTED".'); | |
} | |
} | |
if (rval.length === 0) { | |
throw new Error("Invalid PEM formatted message."); | |
} | |
return rval; | |
}; | |
function foldHeader(header) { | |
var rval = header.name + ": "; | |
var values = []; | |
var insertSpace = function(match, $1) { | |
return " " + $1; | |
}; | |
for (var i = 0; i < header.values.length; ++i) { | |
values.push(header.values[i].replace(/^(\S+\r\n)/, insertSpace)); | |
} | |
rval += values.join(",") + "\r\n"; | |
var length11 = 0; | |
var candidate = -1; | |
for (var i = 0; i < rval.length; ++i, ++length11) { | |
if (length11 > 65 && candidate !== -1) { | |
var insert = rval[candidate]; | |
if (insert === ",") { | |
++candidate; | |
rval = rval.substr(0, candidate) + "\r\n " + rval.substr(candidate); | |
} else { | |
rval = rval.substr(0, candidate) + "\r\n" + insert + rval.substr(candidate + 1); | |
} | |
length11 = i - candidate - 1; | |
candidate = -1; | |
++i; | |
} else if (rval[i] === " " || rval[i] === " " || rval[i] === ",") { | |
candidate = i; | |
} | |
} | |
return rval; | |
} | |
function ltrim(str) { | |
return str.replace(/^\s+/, ""); | |
} | |
} | |
}); | |
// node_modules/node-forge/lib/sha256.js | |
var require_sha256 = __commonJS({ | |
"node_modules/node-forge/lib/sha256.js"(exports2, module2) { | |
var forge7 = require_forge(); | |
require_md(); | |
require_util(); | |
var sha2567 = module2.exports = forge7.sha256 = forge7.sha256 || {}; | |
forge7.md.sha256 = forge7.md.algorithms.sha256 = sha2567; | |
sha2567.create = function() { | |
if (!_initialized) { | |
_init(); | |
} | |
var _state = null; | |
var _input = forge7.util.createBuffer(); | |
var _w = new Array(64); | |
var md = { | |
algorithm: "sha256", | |
blockLength: 64, | |
digestLength: 32, | |
// 56-bit length of message so far (does not including padding) | |
messageLength: 0, | |
// true message length | |
fullMessageLength: null, | |
// size of message length in bytes | |
messageLengthSize: 8 | |
}; | |
md.start = function() { | |
md.messageLength = 0; | |
md.fullMessageLength = md.messageLength64 = []; | |
var int32s = md.messageLengthSize / 4; | |
for (var i = 0; i < int32s; ++i) { | |
md.fullMessageLength.push(0); | |
} | |
_input = forge7.util.createBuffer(); | |
_state = { | |
h0: 1779033703, | |
h1: 3144134277, | |
h2: 1013904242, | |
h3: 2773480762, | |
h4: 1359893119, | |
h5: 2600822924, | |
h6: 528734635, | |
h7: 1541459225 | |
}; | |
return md; | |
}; | |
md.start(); | |
md.update = function(msg, encoding) { | |
if (encoding === "utf8") { | |
msg = forge7.util.encodeUtf8(msg); | |
} | |
var len = msg.length; | |
md.messageLength += len; | |
len = [len / 4294967296 >>> 0, len >>> 0]; | |
for (var i = md.fullMessageLength.length - 1; i >= 0; --i) { | |
md.fullMessageLength[i] += len[1]; | |
len[1] = len[0] + (md.fullMessageLength[i] / 4294967296 >>> 0); | |
md.fullMessageLength[i] = md.fullMessageLength[i] >>> 0; | |
len[0] = len[1] / 4294967296 >>> 0; | |
} | |
_input.putBytes(msg); | |
_update(_state, _w, _input); | |
if (_input.read > 2048 || _input.length() === 0) { | |
_input.compact(); | |
} | |
return md; | |
}; | |
md.digest = function() { | |
var finalBlock = forge7.util.createBuffer(); | |
finalBlock.putBytes(_input.bytes()); | |
var remaining = md.fullMessageLength[md.fullMessageLength.length - 1] + md.messageLengthSize; | |
var overflow = remaining & md.blockLength - 1; | |
finalBlock.putBytes(_padding.substr(0, md.blockLength - overflow)); | |
var next, carry; | |
var bits2 = md.fullMessageLength[0] * 8; | |
for (var i = 0; i < md.fullMessageLength.length - 1; ++i) { | |
next = md.fullMessageLength[i + 1] * 8; | |
carry = next / 4294967296 >>> 0; | |
bits2 += carry; | |
finalBlock.putInt32(bits2 >>> 0); | |
bits2 = next >>> 0; | |
} | |
finalBlock.putInt32(bits2); | |
var s2 = { | |
h0: _state.h0, | |
h1: _state.h1, | |
h2: _state.h2, | |
h3: _state.h3, | |
h4: _state.h4, | |
h5: _state.h5, | |
h6: _state.h6, | |
h7: _state.h7 | |
}; | |
_update(s2, _w, finalBlock); | |
var rval = forge7.util.createBuffer(); | |
rval.putInt32(s2.h0); | |
rval.putInt32(s2.h1); | |
rval.putInt32(s2.h2); | |
rval.putInt32(s2.h3); | |
rval.putInt32(s2.h4); | |
rval.putInt32(s2.h5); | |
rval.putInt32(s2.h6); | |
rval.putInt32(s2.h7); | |
return rval; | |
}; | |
return md; | |
}; | |
var _padding = null; | |
var _initialized = false; | |
var _k = null; | |
function _init() { | |
_padding = String.fromCharCode(128); | |
_padding += forge7.util.fillString(String.fromCharCode(0), 64); | |
_k = [ | |
1116352408, | |
1899447441, | |
3049323471, | |
3921009573, | |
961987163, | |
1508970993, | |
2453635748, | |
2870763221, | |
3624381080, | |
310598401, | |
607225278, | |
1426881987, | |
1925078388, | |
2162078206, | |
2614888103, | |
3248222580, | |
3835390401, | |
4022224774, | |
264347078, | |
604807628, | |
770255983, | |
1249150122, | |
1555081692, | |
1996064986, | |
2554220882, | |
2821834349, | |
2952996808, | |
3210313671, | |
3336571891, | |
3584528711, | |
113926993, | |
338241895, | |
666307205, | |
773529912, | |
1294757372, | |
1396182291, | |
1695183700, | |
1986661051, | |
2177026350, | |
2456956037, | |
2730485921, | |
2820302411, | |
3259730800, | |
3345764771, | |
3516065817, | |
3600352804, | |
4094571909, | |
275423344, | |
430227734, | |
506948616, | |
659060556, | |
883997877, | |
958139571, | |
1322822218, | |
1537002063, | |
1747873779, | |
1955562222, | |
2024104815, | |
2227730452, | |
2361852424, | |
2428436474, | |
2756734187, | |
3204031479, | |
3329325298 | |
]; | |
_initialized = true; | |
} | |
function _update(s, w, bytes3) { | |
var t1, t2, s0, s1, ch, maj, i, a, b, c, d, e, f, g, h; | |
var len = bytes3.length(); | |
while (len >= 64) { | |
for (i = 0; i < 16; ++i) { | |
w[i] = bytes3.getInt32(); | |
} | |
for (; i < 64; ++i) { | |
t1 = w[i - 2]; | |
t1 = (t1 >>> 17 | t1 << 15) ^ (t1 >>> 19 | t1 << 13) ^ t1 >>> 10; | |
t2 = w[i - 15]; | |
t2 = (t2 >>> 7 | t2 << 25) ^ (t2 >>> 18 | t2 << 14) ^ t2 >>> 3; | |
w[i] = t1 + w[i - 7] + t2 + w[i - 16] | 0; | |
} | |
a = s.h0; | |
b = s.h1; | |
c = s.h2; | |
d = s.h3; | |
e = s.h4; | |
f = s.h5; | |
g = s.h6; | |
h = s.h7; | |
for (i = 0; i < 64; ++i) { | |
s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7); | |
ch = g ^ e & (f ^ g); | |
s0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10); | |
maj = a & b | c & (a ^ b); | |
t1 = h + s1 + ch + _k[i] + w[i]; | |
t2 = s0 + maj; | |
h = g; | |
g = f; | |
f = e; | |
e = d + t1 >>> 0; | |
d = c; | |
c = b; | |
b = a; | |
a = t1 + t2 >>> 0; | |
} | |
s.h0 = s.h0 + a | 0; | |
s.h1 = s.h1 + b | 0; | |
s.h2 = s.h2 + c | 0; | |
s.h3 = s.h3 + d | 0; | |
s.h4 = s.h4 + e | 0; | |
s.h5 = s.h5 + f | 0; | |
s.h6 = s.h6 + g | 0; | |
s.h7 = s.h7 + h | 0; | |
len -= 64; | |
} | |
} | |
} | |
}); | |
// node_modules/node-forge/lib/prng.js | |
var require_prng = __commonJS({ | |
"node_modules/node-forge/lib/prng.js"(exports2, module2) { | |
var forge7 = require_forge(); | |
require_util(); | |
var _crypto = null; | |
if (forge7.util.isNodejs && !forge7.options.usePureJavaScript && !process.versions["node-webkit"]) { | |
_crypto = require_crypto(); | |
} | |
var prng = module2.exports = forge7.prng = forge7.prng || {}; | |
prng.create = function(plugin) { | |
var ctx = { | |
plugin, | |
key: null, | |
seed: null, | |
time: null, | |
// number of reseeds so far | |
reseeds: 0, | |
// amount of data generated so far | |
generated: 0, | |
// no initial key bytes | |
keyBytes: "" | |
}; | |
var md = plugin.md; | |
var pools = new Array(32); | |
for (var i = 0; i < 32; ++i) { | |
pools[i] = md.create(); | |
} | |
ctx.pools = pools; | |
ctx.pool = 0; | |
ctx.generate = function(count, callback) { | |
if (!callback) { | |
return ctx.generateSync(count); | |
} | |
var cipher = ctx.plugin.cipher; | |
var increment = ctx.plugin.increment; | |
var formatKey = ctx.plugin.formatKey; | |
var formatSeed = ctx.plugin.formatSeed; | |
var b = forge7.util.createBuffer(); | |
ctx.key = null; | |
generate(); | |
function generate(err) { | |
if (err) { | |
return callback(err); | |
} | |
if (b.length() >= count) { | |
return callback(null, b.getBytes(count)); | |
} | |
if (ctx.generated > 1048575) { | |
ctx.key = null; | |
} | |
if (ctx.key === null) { | |
return forge7.util.nextTick(function() { | |
_reseed(generate); | |
}); | |
} | |
var bytes3 = cipher(ctx.key, ctx.seed); | |
ctx.generated += bytes3.length; | |
b.putBytes(bytes3); | |
ctx.key = formatKey(cipher(ctx.key, increment(ctx.seed))); | |
ctx.seed = formatSeed(cipher(ctx.key, ctx.seed)); | |
forge7.util.setImmediate(generate); | |
} | |
}; | |
ctx.generateSync = function(count) { | |
var cipher = ctx.plugin.cipher; | |
var increment = ctx.plugin.increment; | |
var formatKey = ctx.plugin.formatKey; | |
var formatSeed = ctx.plugin.formatSeed; | |
ctx.key = null; | |
var b = forge7.util.createBuffer(); | |
while (b.length() < count) { | |
if (ctx.generated > 1048575) { | |
ctx.key = null; | |
} | |
if (ctx.key === null) { | |
_reseedSync(); | |
} | |
var bytes3 = cipher(ctx.key, ctx.seed); | |
ctx.generated += bytes3.length; | |
b.putBytes(bytes3); | |
ctx.key = formatKey(cipher(ctx.key, increment(ctx.seed))); | |
ctx.seed = formatSeed(cipher(ctx.key, ctx.seed)); | |
} | |
return b.getBytes(count); | |
}; | |
function _reseed(callback) { | |
if (ctx.pools[0].messageLength >= 32) { | |
_seed(); | |
return callback(); | |
} | |
var needed = 32 - ctx.pools[0].messageLength << 5; | |
ctx.seedFile(needed, function(err, bytes3) { | |
if (err) { | |
return callback(err); | |
} | |
ctx.collect(bytes3); | |
_seed(); | |
callback(); | |
}); | |
} | |
function _reseedSync() { | |
if (ctx.pools[0].messageLength >= 32) { | |
return _seed(); | |
} | |
var needed = 32 - ctx.pools[0].messageLength << 5; | |
ctx.collect(ctx.seedFileSync(needed)); | |
_seed(); | |
} | |
function _seed() { | |
ctx.reseeds = ctx.reseeds === 4294967295 ? 0 : ctx.reseeds + 1; | |
var md2 = ctx.plugin.md.create(); | |
md2.update(ctx.keyBytes); | |
var _2powK = 1; | |
for (var k = 0; k < 32; ++k) { | |
if (ctx.reseeds % _2powK === 0) { | |
md2.update(ctx.pools[k].digest().getBytes()); | |
ctx.pools[k].start(); | |
} | |
_2powK = _2powK << 1; | |
} | |
ctx.keyBytes = md2.digest().getBytes(); | |
md2.start(); | |
md2.update(ctx.keyBytes); | |
var seedBytes = md2.digest().getBytes(); | |
ctx.key = ctx.plugin.formatKey(ctx.keyBytes); | |
ctx.seed = ctx.plugin.formatSeed(seedBytes); | |
ctx.generated = 0; | |
} | |
function defaultSeedFile(needed) { | |
var getRandomValues = null; | |
var globalScope = forge7.util.globalScope; | |
var _crypto2 = globalScope.crypto || globalScope.msCrypto; | |
if (_crypto2 && _crypto2.getRandomValues) { | |
getRandomValues = function(arr) { | |
return _crypto2.getRandomValues(arr); | |
}; | |
} | |
var b = forge7.util.createBuffer(); | |
if (getRandomValues) { | |
while (b.length() < needed) { | |
var count = Math.max(1, Math.min(needed - b.length(), 65536) / 4); | |
var entropy = new Uint32Array(Math.floor(count)); | |
try { | |
getRandomValues(entropy); | |
for (var i2 = 0; i2 < entropy.length; ++i2) { | |
b.putInt32(entropy[i2]); | |
} | |
} catch (e) { | |
if (!(typeof QuotaExceededError !== "undefined" && e instanceof QuotaExceededError)) { | |
throw e; | |
} | |
} | |
} | |
} | |
if (b.length() < needed) { | |
var hi, lo, next; | |
var seed = Math.floor(Math.random() * 65536); | |
while (b.length() < needed) { | |
lo = 16807 * (seed & 65535); | |
hi = 16807 * (seed >> 16); | |
lo += (hi & 32767) << 16; | |
lo += hi >> 15; | |
lo = (lo & 2147483647) + (lo >> 31); | |
seed = lo & 4294967295; | |
for (var i2 = 0; i2 < 3; ++i2) { | |
next = seed >>> (i2 << 3); | |
next ^= Math.floor(Math.random() * 256); | |
b.putByte(next & 255); | |
} | |
} | |
} | |
return b.getBytes(needed); | |
} | |
if (_crypto) { | |
ctx.seedFile = function(needed, callback) { | |
_crypto.randomBytes(needed, function(err, bytes3) { | |
if (err) { | |
return callback(err); | |
} | |
callback(null, bytes3.toString()); | |
}); | |
}; | |
ctx.seedFileSync = function(needed) { | |
return _crypto.randomBytes(needed).toString(); | |
}; | |
} else { | |
ctx.seedFile = function(needed, callback) { | |
try { | |
callback(null, defaultSeedFile(needed)); | |
} catch (e) { | |
callback(e); | |
} | |
}; | |
ctx.seedFileSync = defaultSeedFile; | |
} | |
ctx.collect = function(bytes3) { | |
var count = bytes3.length; | |
for (var i2 = 0; i2 < count; ++i2) { | |
ctx.pools[ctx.pool].update(bytes3.substr(i2, 1)); | |
ctx.pool = ctx.pool === 31 ? 0 : ctx.pool + 1; | |
} | |
}; | |
ctx.collectInt = function(i2, n) { | |
var bytes3 = ""; | |
for (var x = 0; x < n; x += 8) { | |
bytes3 += String.fromCharCode(i2 >> x & 255); | |
} | |
ctx.collect(bytes3); | |
}; | |
ctx.registerWorker = function(worker) { | |
if (worker === self) { | |
ctx.seedFile = function(needed, callback) { | |
function listener2(e) { | |
var data = e.data; | |
if (data.forge && data.forge.prng) { | |
self.removeEventListener("message", listener2); | |
callback(data.forge.prng.err, data.forge.prng.bytes); | |
} | |
} | |
self.addEventListener("message", listener2); | |
self.postMessage({ forge: { prng: { needed } } }); | |
}; | |
} else { | |
var listener = function(e) { | |
var data = e.data; | |
if (data.forge && data.forge.prng) { | |
ctx.seedFile(data.forge.prng.needed, function(err, bytes3) { | |
worker.postMessage({ forge: { prng: { err, bytes: bytes3 } } }); | |
}); | |
} | |
}; | |
worker.addEventListener("message", listener); | |
} | |
}; | |
return ctx; | |
}; | |
} | |
}); | |
// node_modules/node-forge/lib/random.js | |
var require_random = __commonJS({ | |
"node_modules/node-forge/lib/random.js"(exports2, module2) { | |
var forge7 = require_forge(); | |
require_aes(); | |
require_sha256(); | |
require_prng(); | |
require_util(); | |
(function() { | |
if (forge7.random && forge7.random.getBytes) { | |
module2.exports = forge7.random; | |
return; | |
} | |
(function(jQuery2) { | |
var prng_aes = {}; | |
var _prng_aes_output = new Array(4); | |
var _prng_aes_buffer = forge7.util.createBuffer(); | |
prng_aes.formatKey = function(key2) { | |
var tmp = forge7.util.createBuffer(key2); | |
key2 = new Array(4); | |
key2[0] = tmp.getInt32(); | |
key2[1] = tmp.getInt32(); | |
key2[2] = tmp.getInt32(); | |
key2[3] = tmp.getInt32(); | |
return forge7.aes._expandKey(key2, false); | |
}; | |
prng_aes.formatSeed = function(seed) { | |
var tmp = forge7.util.createBuffer(seed); | |
seed = new Array(4); | |
seed[0] = tmp.getInt32(); | |
seed[1] = tmp.getInt32(); | |
seed[2] = tmp.getInt32(); | |
seed[3] = tmp.getInt32(); | |
return seed; | |
}; | |
prng_aes.cipher = function(key2, seed) { | |
forge7.aes._updateBlock(key2, seed, _prng_aes_output, false); | |
_prng_aes_buffer.putInt32(_prng_aes_output[0]); | |
_prng_aes_buffer.putInt32(_prng_aes_output[1]); | |
_prng_aes_buffer.putInt32(_prng_aes_output[2]); | |
_prng_aes_buffer.putInt32(_prng_aes_output[3]); | |
return _prng_aes_buffer.getBytes(); | |
}; | |
prng_aes.increment = function(seed) { | |
++seed[3]; | |
return seed; | |
}; | |
prng_aes.md = forge7.md.sha256; | |
function spawnPrng() { | |
var ctx = forge7.prng.create(prng_aes); | |
ctx.getBytes = function(count, callback) { | |
return ctx.generate(count, callback); | |
}; | |
ctx.getBytesSync = function(count) { | |
return ctx.generate(count); | |
}; | |
return ctx; | |
} | |
var _ctx = spawnPrng(); | |
var getRandomValues = null; | |
var globalScope = forge7.util.globalScope; | |
var _crypto = globalScope.crypto || globalScope.msCrypto; | |
if (_crypto && _crypto.getRandomValues) { | |
getRandomValues = function(arr) { | |
return _crypto.getRandomValues(arr); | |
}; | |
} | |
if (forge7.options.usePureJavaScript || !forge7.util.isNodejs && !getRandomValues) { | |
if (typeof window === "undefined" || window.document === void 0) { | |
} | |
_ctx.collectInt(+/* @__PURE__ */ new Date(), 32); | |
if (typeof navigator !== "undefined") { | |
var _navBytes = ""; | |
for (var key in navigator) { | |
try { | |
if (typeof navigator[key] == "string") { | |
_navBytes += navigator[key]; | |
} | |
} catch (e) { | |
} | |
} | |
_ctx.collect(_navBytes); | |
_navBytes = null; | |
} | |
if (jQuery2) { | |
jQuery2().mousemove(function(e) { | |
_ctx.collectInt(e.clientX, 16); | |
_ctx.collectInt(e.clientY, 16); | |
}); | |
jQuery2().keypress(function(e) { | |
_ctx.collectInt(e.charCode, 8); | |
}); | |
} | |
} | |
if (!forge7.random) { | |
forge7.random = _ctx; | |
} else { | |
for (var key in _ctx) { | |
forge7.random[key] = _ctx[key]; | |
} | |
} | |
forge7.random.createInstance = spawnPrng; | |
module2.exports = forge7.random; | |
})(typeof jQuery !== "undefined" ? jQuery : null); | |
})(); | |
} | |
}); | |
// node_modules/node-forge/lib/rc2.js | |
var require_rc2 = __commonJS({ | |
"node_modules/node-forge/lib/rc2.js"(exports2, module2) { | |
var forge7 = require_forge(); | |
require_util(); | |
var piTable = [ | |
217, | |
120, | |
249, | |
196, | |
25, | |
221, | |
181, | |
237, | |
40, | |
233, | |
253, | |
121, | |
74, | |
160, | |
216, | |
157, | |
198, | |
126, | |
55, | |
131, | |
43, | |
118, | |
83, | |
142, | |
98, | |
76, | |
100, | |
136, | |
68, | |
139, | |
251, | |
162, | |
23, | |
154, | |
89, | |
245, | |
135, | |
179, | |
79, | |
19, | |
97, | |
69, | |
109, | |
141, | |
9, | |
129, | |
125, | |
50, | |
189, | |
143, | |
64, | |
235, | |
134, | |
183, | |
123, | |
11, | |
240, | |
149, | |
33, | |
34, | |
92, | |
107, | |
78, | |
130, | |
84, | |
214, | |
101, | |
147, | |
206, | |
96, | |
178, | |
28, | |
115, | |
86, | |
192, | |
20, | |
167, | |
140, | |
241, | |
220, | |
18, | |
117, | |
202, | |
31, | |
59, | |
190, | |
228, | |
209, | |
66, | |
61, | |
212, | |
48, | |
163, | |
60, | |
182, | |
38, | |
111, | |
191, | |
14, | |
218, | |
70, | |
105, | |
7, | |
87, | |
39, | |
242, | |
29, | |
155, | |
188, | |
148, | |
67, | |
3, | |
248, | |
17, | |
199, | |
246, | |
144, | |
239, | |
62, | |
231, | |
6, | |
195, | |
213, | |
47, | |
200, | |
102, | |
30, | |
215, | |
8, | |
232, | |
234, | |
222, | |
128, | |
82, | |
238, | |
247, | |
132, | |
170, | |
114, | |
172, | |
53, | |
77, | |
106, | |
42, | |
150, | |
26, | |
210, | |
113, | |
90, | |
21, | |
73, | |
116, | |
75, | |
159, | |
208, | |
94, | |
4, | |
24, | |
164, | |
236, | |
194, | |
224, | |
65, | |
110, | |
15, | |
81, | |
203, | |
204, | |
36, | |
145, | |
175, | |
80, | |
161, | |
244, | |
112, | |
57, | |
153, | |
124, | |
58, | |
133, | |
35, | |
184, | |
180, | |
122, | |
252, | |
2, | |
54, | |
91, | |
37, | |
85, | |
151, | |
49, | |
45, | |
93, | |
250, | |
152, | |
227, | |
138, | |
146, | |
174, | |
5, | |
223, | |
41, | |
16, | |
103, | |
108, | |
186, | |
201, | |
211, | |
0, | |
230, | |
207, | |
225, | |
158, | |
168, | |
44, | |
99, | |
22, | |
1, | |
63, | |
88, | |
226, | |
137, | |
169, | |
13, | |
56, | |
52, | |
27, | |
171, | |
51, | |
255, | |
176, | |
187, | |
72, | |
12, | |
95, | |
185, | |
177, | |
205, | |
46, | |
197, | |
243, | |
219, | |
71, | |
229, | |
165, | |
156, | |
119, | |
10, | |
166, | |
32, | |
104, | |
254, | |
127, | |
193, | |
173 | |
]; | |
var s = [1, 2, 3, 5]; | |
var rol = function(word2, bits2) { | |
return word2 << bits2 & 65535 | (word2 & 65535) >> 16 - bits2; | |
}; | |
var ror = function(word2, bits2) { | |
return (word2 & 65535) >> bits2 | word2 << 16 - bits2 & 65535; | |
}; | |
module2.exports = forge7.rc2 = forge7.rc2 || {}; | |
forge7.rc2.expandKey = function(key, effKeyBits) { | |
if (typeof key === "string") { | |
key = forge7.util.createBuffer(key); | |
} | |
effKeyBits = effKeyBits || 128; | |
var L = key; | |
var T = key.length(); | |
var T1 = effKeyBits; | |
var T8 = Math.ceil(T1 / 8); | |
var TM = 255 >> (T1 & 7); | |
var i; | |
for (i = T; i < 128; i++) { | |
L.putByte(piTable[L.at(i - 1) + L.at(i - T) & 255]); | |
} | |
L.setAt(128 - T8, piTable[L.at(128 - T8) & TM]); | |
for (i = 127 - T8; i >= 0; i--) { | |
L.setAt(i, piTable[L.at(i + 1) ^ L.at(i + T8)]); | |
} | |
return L; | |
}; | |
var createCipher = function(key, bits2, encrypt2) { | |
var _finish = false, _input = null, _output = null, _iv = null; | |
var mixRound, mashRound; | |
var i, j, K2 = []; | |
key = forge7.rc2.expandKey(key, bits2); | |
for (i = 0; i < 64; i++) { | |
K2.push(key.getInt16Le()); | |
} | |
if (encrypt2) { | |
mixRound = function(R) { | |
for (i = 0; i < 4; i++) { | |
R[i] += K2[j] + (R[(i + 3) % 4] & R[(i + 2) % 4]) + (~R[(i + 3) % 4] & R[(i + 1) % 4]); | |
R[i] = rol(R[i], s[i]); | |
j++; | |
} | |
}; | |
mashRound = function(R) { | |
for (i = 0; i < 4; i++) { | |
R[i] += K2[R[(i + 3) % 4] & 63]; | |
} | |
}; | |
} else { | |
mixRound = function(R) { | |
for (i = 3; i >= 0; i--) { | |
R[i] = ror(R[i], s[i]); | |
R[i] -= K2[j] + (R[(i + 3) % 4] & R[(i + 2) % 4]) + (~R[(i + 3) % 4] & R[(i + 1) % 4]); | |
j--; | |
} | |
}; | |
mashRound = function(R) { | |
for (i = 3; i >= 0; i--) { | |
R[i] -= K2[R[(i + 3) % 4] & 63]; | |
} | |
}; | |
} | |
var runPlan = function(plan) { | |
var R = []; | |
for (i = 0; i < 4; i++) { | |
var val = _input.getInt16Le(); | |
if (_iv !== null) { | |
if (encrypt2) { | |
val ^= _iv.getInt16Le(); | |
} else { | |
_iv.putInt16Le(val); | |
} | |
} | |
R.push(val & 65535); | |
} | |
j = encrypt2 ? 0 : 63; | |
for (var ptr = 0; ptr < plan.length; ptr++) { | |
for (var ctr = 0; ctr < plan[ptr][0]; ctr++) { | |
plan[ptr][1](R); | |
} | |
} | |
for (i = 0; i < 4; i++) { | |
if (_iv !== null) { | |
if (encrypt2) { | |
_iv.putInt16Le(R[i]); | |
} else { | |
R[i] ^= _iv.getInt16Le(); | |
} | |
} | |
_output.putInt16Le(R[i]); | |
} | |
}; | |
var cipher = null; | |
cipher = { | |
/** | |
* Starts or restarts the encryption or decryption process, whichever | |
* was previously configured. | |
* | |
* To use the cipher in CBC mode, iv may be given either as a string | |
* of bytes, or as a byte buffer. For ECB mode, give null as iv. | |
* | |
* @param iv the initialization vector to use, null for ECB mode. | |
* @param output the output the buffer to write to, null to create one. | |
*/ | |
start: function(iv, output3) { | |
if (iv) { | |
if (typeof iv === "string") { | |
iv = forge7.util.createBuffer(iv); | |
} | |
} | |
_finish = false; | |
_input = forge7.util.createBuffer(); | |
_output = output3 || new forge7.util.createBuffer(); | |
_iv = iv; | |
cipher.output = _output; | |
}, | |
/** | |
* Updates the next block. | |
* | |
* @param input the buffer to read from. | |
*/ | |
update: function(input) { | |
if (!_finish) { | |
_input.putBuffer(input); | |
} | |
while (_input.length() >= 8) { | |
runPlan([ | |
[5, mixRound], | |
[1, mashRound], | |
[6, mixRound], | |
[1, mashRound], | |
[5, mixRound] | |
]); | |
} | |
}, | |
/** | |
* Finishes encrypting or decrypting. | |
* | |
* @param pad a padding function to use, null for PKCS#7 padding, | |
* signature(blockSize, buffer, decrypt). | |
* | |
* @return true if successful, false on error. | |
*/ | |
finish: function(pad) { | |
var rval = true; | |
if (encrypt2) { | |
if (pad) { | |
rval = pad(8, _input, !encrypt2); | |
} else { | |
var padding = _input.length() === 8 ? 8 : 8 - _input.length(); | |
_input.fillWithByte(padding, padding); | |
} | |
} | |
if (rval) { | |
_finish = true; | |
cipher.update(); | |
} | |
if (!encrypt2) { | |
rval = _input.length() === 0; | |
if (rval) { | |
if (pad) { | |
rval = pad(8, _output, !encrypt2); | |
} else { | |
var len = _output.length(); | |
var count = _output.at(len - 1); | |
if (count > len) { | |
rval = false; | |
} else { | |
_output.truncate(count); | |
} | |
} | |
} | |
} | |
return rval; | |
} | |
}; | |
return cipher; | |
}; | |
forge7.rc2.startEncrypting = function(key, iv, output3) { | |
var cipher = forge7.rc2.createEncryptionCipher(key, 128); | |
cipher.start(iv, output3); | |
return cipher; | |
}; | |
forge7.rc2.createEncryptionCipher = function(key, bits2) { | |
return createCipher(key, bits2, true); | |
}; | |
forge7.rc2.startDecrypting = function(key, iv, output3) { | |
var cipher = forge7.rc2.createDecryptionCipher(key, 128); | |
cipher.start(iv, output3); | |
return cipher; | |
}; | |
forge7.rc2.createDecryptionCipher = function(key, bits2) { | |
return createCipher(key, bits2, false); | |
}; | |
} | |
}); | |
// node_modules/node-forge/lib/jsbn.js | |
var require_jsbn = __commonJS({ | |
"node_modules/node-forge/lib/jsbn.js"(exports2, module2) { | |
var forge7 = require_forge(); | |
module2.exports = forge7.jsbn = forge7.jsbn || {}; | |
var dbits; | |
var canary = 244837814094590; | |
var j_lm = (canary & 16777215) == 15715070; | |
function BigInteger(a, b, c) { | |
this.data = []; | |
if (a != null) | |
if ("number" == typeof a) | |
this.fromNumber(a, b, c); | |
else if (b == null && "string" != typeof a) | |
this.fromString(a, 256); | |
else | |
this.fromString(a, b); | |
} | |
forge7.jsbn.BigInteger = BigInteger; | |
function nbi() { | |
return new BigInteger(null); | |
} | |
function am1(i, x, w, j, c, n) { | |
while (--n >= 0) { | |
var v = x * this.data[i++] + w.data[j] + c; | |
c = Math.floor(v / 67108864); | |
w.data[j++] = v & 67108863; | |
} | |
return c; | |
} | |
function am2(i, x, w, j, c, n) { | |
var xl = x & 32767, xh = x >> 15; | |
while (--n >= 0) { | |
var l = this.data[i] & 32767; | |
var h = this.data[i++] >> 15; | |
var m = xh * l + h * xl; | |
l = xl * l + ((m & 32767) << 15) + w.data[j] + (c & 1073741823); | |
c = (l >>> 30) + (m >>> 15) + xh * h + (c >>> 30); | |
w.data[j++] = l & 1073741823; | |
} | |
return c; | |
} | |
function am3(i, x, w, j, c, n) { | |
var xl = x & 16383, xh = x >> 14; | |
while (--n >= 0) { | |
var l = this.data[i] & 16383; | |
var h = this.data[i++] >> 14; | |
var m = xh * l + h * xl; | |
l = xl * l + ((m & 16383) << 14) + w.data[j] + c; | |
c = (l >> 28) + (m >> 14) + xh * h; | |
w.data[j++] = l & 268435455; | |
} | |
return c; | |
} | |
if (typeof navigator === "undefined") { | |
BigInteger.prototype.am = am3; | |
dbits = 28; | |
} else if (j_lm && navigator.appName == "Microsoft Internet Explorer") { | |
BigInteger.prototype.am = am2; | |
dbits = 30; | |
} else if (j_lm && navigator.appName != "Netscape") { | |
BigInteger.prototype.am = am1; | |
dbits = 26; | |
} else { | |
BigInteger.prototype.am = am3; | |
dbits = 28; | |
} | |
BigInteger.prototype.DB = dbits; | |
BigInteger.prototype.DM = (1 << dbits) - 1; | |
BigInteger.prototype.DV = 1 << dbits; | |
var BI_FP = 52; | |
BigInteger.prototype.FV = Math.pow(2, BI_FP); | |
BigInteger.prototype.F1 = BI_FP - dbits; | |
BigInteger.prototype.F2 = 2 * dbits - BI_FP; | |
var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz"; | |
var BI_RC = new Array(); | |
var rr; | |
var vv; | |
rr = "0".charCodeAt(0); | |
for (vv = 0; vv <= 9; ++vv) | |
BI_RC[rr++] = vv; | |
rr = "a".charCodeAt(0); | |
for (vv = 10; vv < 36; ++vv) | |
BI_RC[rr++] = vv; | |
rr = "A".charCodeAt(0); | |
for (vv = 10; vv < 36; ++vv) | |
BI_RC[rr++] = vv; | |
function int2char(n) { | |
return BI_RM.charAt(n); | |
} | |
function intAt(s, i) { | |
var c = BI_RC[s.charCodeAt(i)]; | |
return c == null ? -1 : c; | |
} | |
function bnpCopyTo(r) { | |
for (var i = this.t - 1; i >= 0; --i) | |
r.data[i] = this.data[i]; | |
r.t = this.t; | |
r.s = this.s; | |
} | |
function bnpFromInt(x) { | |
this.t = 1; | |
this.s = x < 0 ? -1 : 0; | |
if (x > 0) | |
this.data[0] = x; | |
else if (x < -1) | |
this.data[0] = x + this.DV; | |
else | |
this.t = 0; | |
} | |
function nbv(i) { | |
var r = nbi(); | |
r.fromInt(i); | |
return r; | |
} | |
function bnpFromString(s, b) { | |
var k; | |
if (b == 16) | |
k = 4; | |
else if (b == 8) | |
k = 3; | |
else if (b == 256) | |
k = 8; | |
else if (b == 2) | |
k = 1; | |
else if (b == 32) | |
k = 5; | |
else if (b == 4) | |
k = 2; | |
else { | |
this.fromRadix(s, b); | |
return; | |
} | |
this.t = 0; | |
this.s = 0; | |
var i = s.length, mi = false, sh = 0; | |
while (--i >= 0) { | |
var x = k == 8 ? s[i] & 255 : intAt(s, i); | |
if (x < 0) { | |
if (s.charAt(i) == "-") | |
mi = true; | |
continue; | |
} | |
mi = false; | |
if (sh == 0) | |
this.data[this.t++] = x; | |
else if (sh + k > this.DB) { | |
this.data[this.t - 1] |= (x & (1 << this.DB - sh) - 1) << sh; | |
this.data[this.t++] = x >> this.DB - sh; | |
} else | |
this.data[this.t - 1] |= x << sh; | |
sh += k; | |
if (sh >= this.DB) | |
sh -= this.DB; | |
} | |
if (k == 8 && (s[0] & 128) != 0) { | |
this.s = -1; | |
if (sh > 0) | |
this.data[this.t - 1] |= (1 << this.DB - sh) - 1 << sh; | |
} | |
this.clamp(); | |
if (mi) | |
BigInteger.ZERO.subTo(this, this); | |
} | |
function bnpClamp() { | |
var c = this.s & this.DM; | |
while (this.t > 0 && this.data[this.t - 1] == c) | |
--this.t; | |
} | |
function bnToString(b) { | |
if (this.s < 0) | |
return "-" + this.negate().toString(b); | |
var k; | |
if (b == 16) | |
k = 4; | |
else if (b == 8) | |
k = 3; | |
else if (b == 2) | |
k = 1; | |
else if (b == 32) | |
k = 5; | |
else if (b == 4) | |
k = 2; | |
else | |
return this.toRadix(b); | |
var km = (1 << k) - 1, d, m = false, r = "", i = this.t; | |
var p = this.DB - i * this.DB % k; | |
if (i-- > 0) { | |
if (p < this.DB && (d = this.data[i] >> p) > 0) { | |
m = true; | |
r = int2char(d); | |
} | |
while (i >= 0) { | |
if (p < k) { | |
d = (this.data[i] & (1 << p) - 1) << k - p; | |
d |= this.data[--i] >> (p += this.DB - k); | |
} else { | |
d = this.data[i] >> (p -= k) & km; | |
if (p <= 0) { | |
p += this.DB; | |
--i; | |
} | |
} | |
if (d > 0) | |
m = true; | |
if (m) | |
r += int2char(d); | |
} | |
} | |
return m ? r : "0"; | |
} | |
function bnNegate() { | |
var r = nbi(); | |
BigInteger.ZERO.subTo(this, r); | |
return r; | |
} | |
function bnAbs() { | |
return this.s < 0 ? this.negate() : this; | |
} | |
function bnCompareTo(a) { | |
var r = this.s - a.s; | |
if (r != 0) | |
return r; | |
var i = this.t; | |
r = i - a.t; | |
if (r != 0) | |
return this.s < 0 ? -r : r; | |
while (--i >= 0) | |
if ((r = this.data[i] - a.data[i]) != 0) | |
return r; | |
return 0; | |
} | |
function nbits(x) { | |
var r = 1, t; | |
if ((t = x >>> 16) != 0) { | |
x = t; | |
r += 16; | |
} | |
if ((t = x >> 8) != 0) { | |
x = t; | |
r += 8; | |
} | |
if ((t = x >> 4) != 0) { | |
x = t; | |
r += 4; | |
} | |
if ((t = x >> 2) != 0) { | |
x = t; | |
r += 2; | |
} | |
if ((t = x >> 1) != 0) { | |
x = t; | |
r += 1; | |
} | |
return r; | |
} | |
function bnBitLength() { | |
if (this.t <= 0) | |
return 0; | |
return this.DB * (this.t - 1) + nbits(this.data[this.t - 1] ^ this.s & this.DM); | |
} | |
function bnpDLShiftTo(n, r) { | |
var i; | |
for (i = this.t - 1; i >= 0; --i) | |
r.data[i + n] = this.data[i]; | |
for (i = n - 1; i >= 0; --i) | |
r.data[i] = 0; | |
r.t = this.t + n; | |
r.s = this.s; | |
} | |
function bnpDRShiftTo(n, r) { | |
for (var i = n; i < this.t; ++i) | |
r.data[i - n] = this.data[i]; | |
r.t = Math.max(this.t - n, 0); | |
r.s = this.s; | |
} | |
function bnpLShiftTo(n, r) { | |
var bs = n % this.DB; | |
var cbs = this.DB - bs; | |
var bm = (1 << cbs) - 1; | |
var ds = Math.floor(n / this.DB), c = this.s << bs & this.DM, i; | |
for (i = this.t - 1; i >= 0; --i) { | |
r.data[i + ds + 1] = this.data[i] >> cbs | c; | |
c = (this.data[i] & bm) << bs; | |
} | |
for (i = ds - 1; i >= 0; --i) | |
r.data[i] = 0; | |
r.data[ds] = c; | |
r.t = this.t + ds + 1; | |
r.s = this.s; | |
r.clamp(); | |
} | |
function bnpRShiftTo(n, r) { | |
r.s = this.s; | |
var ds = Math.floor(n / this.DB); | |
if (ds >= this.t) { | |
r.t = 0; | |
return; | |
} | |
var bs = n % this.DB; | |
var cbs = this.DB - bs; | |
var bm = (1 << bs) - 1; | |
r.data[0] = this.data[ds] >> bs; | |
for (var i = ds + 1; i < this.t; ++i) { | |
r.data[i - ds - 1] |= (this.data[i] & bm) << cbs; | |
r.data[i - ds] = this.data[i] >> bs; | |
} | |
if (bs > 0) | |
r.data[this.t - ds - 1] |= (this.s & bm) << cbs; | |
r.t = this.t - ds; | |
r.clamp(); | |
} | |
function bnpSubTo(a, r) { | |
var i = 0, c = 0, m = Math.min(a.t, this.t); | |
while (i < m) { | |
c += this.data[i] - a.data[i]; | |
r.data[i++] = c & this.DM; | |
c >>= this.DB; | |
} | |
if (a.t < this.t) { | |
c -= a.s; | |
while (i < this.t) { | |
c += this.data[i]; | |
r.data[i++] = c & this.DM; | |
c >>= this.DB; | |
} | |
c += this.s; | |
} else { | |
c += this.s; | |
while (i < a.t) { | |
c -= a.data[i]; | |
r.data[i++] = c & this.DM; | |
c >>= this.DB; | |
} | |
c -= a.s; | |
} | |
r.s = c < 0 ? -1 : 0; | |
if (c < -1) | |
r.data[i++] = this.DV + c; | |
else if (c > 0) | |
r.data[i++] = c; | |
r.t = i; | |
r.clamp(); | |
} | |
function bnpMultiplyTo(a, r) { | |
var x = this.abs(), y = a.abs(); | |
var i = x.t; | |
r.t = i + y.t; | |
while (--i >= 0) | |
r.data[i] = 0; | |
for (i = 0; i < y.t; ++i) | |
r.data[i + x.t] = x.am(0, y.data[i], r, i, 0, x.t); | |
r.s = 0; | |
r.clamp(); | |
if (this.s != a.s) | |
BigInteger.ZERO.subTo(r, r); | |
} | |
function bnpSquareTo(r) { | |
var x = this.abs(); | |
var i = r.t = 2 * x.t; | |
while (--i >= 0) | |
r.data[i] = 0; | |
for (i = 0; i < x.t - 1; ++i) { | |
var c = x.am(i, x.data[i], r, 2 * i, 0, 1); | |
if ((r.data[i + x.t] += x.am(i + 1, 2 * x.data[i], r, 2 * i + 1, c, x.t - i - 1)) >= x.DV) { | |
r.data[i + x.t] -= x.DV; | |
r.data[i + x.t + 1] = 1; | |
} | |
} | |
if (r.t > 0) | |
r.data[r.t - 1] += x.am(i, x.data[i], r, 2 * i, 0, 1); | |
r.s = 0; | |
r.clamp(); | |
} | |
function bnpDivRemTo(m, q, r) { | |
var pm = m.abs(); | |
if (pm.t <= 0) | |
return; | |
var pt = this.abs(); | |
if (pt.t < pm.t) { | |
if (q != null) | |
q.fromInt(0); | |
if (r != null) | |
this.copyTo(r); | |
return; | |
} | |
if (r == null) | |
r = nbi(); | |
var y = nbi(), ts = this.s, ms = m.s; | |
var nsh = this.DB - nbits(pm.data[pm.t - 1]); | |
if (nsh > 0) { | |
pm.lShiftTo(nsh, y); | |
pt.lShiftTo(nsh, r); | |
} else { | |
pm.copyTo(y); | |
pt.copyTo(r); | |
} | |
var ys = y.t; | |
var y0 = y.data[ys - 1]; | |
if (y0 == 0) | |
return; | |
var yt = y0 * (1 << this.F1) + (ys > 1 ? y.data[ys - 2] >> this.F2 : 0); | |
var d1 = this.FV / yt, d2 = (1 << this.F1) / yt, e = 1 << this.F2; | |
var i = r.t, j = i - ys, t = q == null ? nbi() : q; | |
y.dlShiftTo(j, t); | |
if (r.compareTo(t) >= 0) { | |
r.data[r.t++] = 1; | |
r.subTo(t, r); | |
} | |
BigInteger.ONE.dlShiftTo(ys, t); | |
t.subTo(y, y); | |
while (y.t < ys) | |
y.data[y.t++] = 0; | |
while (--j >= 0) { | |
var qd = r.data[--i] == y0 ? this.DM : Math.floor(r.data[i] * d1 + (r.data[i - 1] + e) * d2); | |
if ((r.data[i] += y.am(0, qd, r, j, 0, ys)) < qd) { | |
y.dlShiftTo(j, t); | |
r.subTo(t, r); | |
while (r.data[i] < --qd) | |
r.subTo(t, r); | |
} | |
} | |
if (q != null) { | |
r.drShiftTo(ys, q); | |
if (ts != ms) | |
BigInteger.ZERO.subTo(q, q); | |
} | |
r.t = ys; | |
r.clamp(); | |
if (nsh > 0) | |
r.rShiftTo(nsh, r); | |
if (ts < 0) | |
BigInteger.ZERO.subTo(r, r); | |
} | |
function bnMod(a) { | |
var r = nbi(); | |
this.abs().divRemTo(a, null, r); | |
if (this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) | |
a.subTo(r, r); | |
return r; | |
} | |
function Classic(m) { | |
this.m = m; | |
} | |
function cConvert(x) { | |
if (x.s < 0 || x.compareTo(this.m) >= 0) | |
return x.mod(this.m); | |
else | |
return x; | |
} | |
function cRevert(x) { | |
return x; | |
} | |
function cReduce(x) { | |
x.divRemTo(this.m, null, x); | |
} | |
function cMulTo(x, y, r) { | |
x.multiplyTo(y, r); | |
this.reduce(r); | |
} | |
function cSqrTo(x, r) { | |
x.squareTo(r); | |
this.reduce(r); | |
} | |
Classic.prototype.convert = cConvert; | |
Classic.prototype.revert = cRevert; | |
Classic.prototype.reduce = cReduce; | |
Classic.prototype.mulTo = cMulTo; | |
Classic.prototype.sqrTo = cSqrTo; | |
function bnpInvDigit() { | |
if (this.t < 1) | |
return 0; | |
var x = this.data[0]; | |
if ((x & 1) == 0) | |
return 0; | |
var y = x & 3; | |
y = y * (2 - (x & 15) * y) & 15; | |
y = y * (2 - (x & 255) * y) & 255; | |
y = y * (2 - ((x & 65535) * y & 65535)) & 65535; | |
y = y * (2 - x * y % this.DV) % this.DV; | |
return y > 0 ? this.DV - y : -y; | |
} | |
function Montgomery(m) { | |
this.m = m; | |
this.mp = m.invDigit(); | |
this.mpl = this.mp & 32767; | |
this.mph = this.mp >> 15; | |
this.um = (1 << m.DB - 15) - 1; | |
this.mt2 = 2 * m.t; | |
} | |
function montConvert(x) { | |
var r = nbi(); | |
x.abs().dlShiftTo(this.m.t, r); | |
r.divRemTo(this.m, null, r); | |
if (x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) | |
this.m.subTo(r, r); | |
return r; | |
} | |
function montRevert(x) { | |
var r = nbi(); | |
x.copyTo(r); | |
this.reduce(r); | |
return r; | |
} | |
function montReduce(x) { | |
while (x.t <= this.mt2) | |
x.data[x.t++] = 0; | |
for (var i = 0; i < this.m.t; ++i) { | |
var j = x.data[i] & 32767; | |
var u0 = j * this.mpl + ((j * this.mph + (x.data[i] >> 15) * this.mpl & this.um) << 15) & x.DM; | |
j = i + this.m.t; | |
x.data[j] += this.m.am(0, u0, x, i, 0, this.m.t); | |
while (x.data[j] >= x.DV) { | |
x.data[j] -= x.DV; | |
x.data[++j]++; | |
} | |
} | |
x.clamp(); | |
x.drShiftTo(this.m.t, x); | |
if (x.compareTo(this.m) >= 0) | |
x.subTo(this.m, x); | |
} | |
function montSqrTo(x, r) { | |
x.squareTo(r); | |
this.reduce(r); | |
} | |
function montMulTo(x, y, r) { | |
x.multiplyTo(y, r); | |
this.reduce(r); | |
} | |
Montgomery.prototype.convert = montConvert; | |
Montgomery.prototype.revert = montRevert; | |
Montgomery.prototype.reduce = montReduce; | |
Montgomery.prototype.mulTo = montMulTo; | |
Montgomery.prototype.sqrTo = montSqrTo; | |
function bnpIsEven() { | |
return (this.t > 0 ? this.data[0] & 1 : this.s) == 0; | |
} | |
function bnpExp(e, z) { | |
if (e > 4294967295 || e < 1) | |
return BigInteger.ONE; | |
var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e) - 1; | |
g.copyTo(r); | |
while (--i >= 0) { | |
z.sqrTo(r, r2); | |
if ((e & 1 << i) > 0) | |
z.mulTo(r2, g, r); | |
else { | |
var t = r; | |
r = r2; | |
r2 = t; | |
} | |
} | |
return z.revert(r); | |
} | |
function bnModPowInt(e, m) { | |
var z; | |
if (e < 256 || m.isEven()) | |
z = new Classic(m); | |
else | |
z = new Montgomery(m); | |
return this.exp(e, z); | |
} | |
BigInteger.prototype.copyTo = bnpCopyTo; | |
BigInteger.prototype.fromInt = bnpFromInt; | |
BigInteger.prototype.fromString = bnpFromString; | |
BigInteger.prototype.clamp = bnpClamp; | |
BigInteger.prototype.dlShiftTo = bnpDLShiftTo; | |
BigInteger.prototype.drShiftTo = bnpDRShiftTo; | |
BigInteger.prototype.lShiftTo = bnpLShiftTo; | |
BigInteger.prototype.rShiftTo = bnpRShiftTo; | |
BigInteger.prototype.subTo = bnpSubTo; | |
BigInteger.prototype.multiplyTo = bnpMultiplyTo; | |
BigInteger.prototype.squareTo = bnpSquareTo; | |
BigInteger.prototype.divRemTo = bnpDivRemTo; | |
BigInteger.prototype.invDigit = bnpInvDigit; | |
BigInteger.prototype.isEven = bnpIsEven; | |
BigInteger.prototype.exp = bnpExp; | |
BigInteger.prototype.toString = bnToString; | |
BigInteger.prototype.negate = bnNegate; | |
BigInteger.prototype.abs = bnAbs; | |
BigInteger.prototype.compareTo = bnCompareTo; | |
BigInteger.prototype.bitLength = bnBitLength; | |
BigInteger.prototype.mod = bnMod; | |
BigInteger.prototype.modPowInt = bnModPowInt; | |
BigInteger.ZERO = nbv(0); | |
BigInteger.ONE = nbv(1); | |
function bnClone() { | |
var r = nbi(); | |
this.copyTo(r); | |
return r; | |
} | |
function bnIntValue() { | |
if (this.s < 0) { | |
if (this.t == 1) | |
return this.data[0] - this.DV; | |
else if (this.t == 0) | |
return -1; | |
} else if (this.t == 1) | |
return this.data[0]; | |
else if (this.t == 0) | |
return 0; | |
return (this.data[1] & (1 << 32 - this.DB) - 1) << this.DB | this.data[0]; | |
} | |
function bnByteValue() { | |
return this.t == 0 ? this.s : this.data[0] << 24 >> 24; | |
} | |
function bnShortValue() { | |
return this.t == 0 ? this.s : this.data[0] << 16 >> 16; | |
} | |
function bnpChunkSize(r) { | |
return Math.floor(Math.LN2 * this.DB / Math.log(r)); | |
} | |
function bnSigNum() { | |
if (this.s < 0) | |
return -1; | |
else if (this.t <= 0 || this.t == 1 && this.data[0] <= 0) | |
return 0; | |
else | |
return 1; | |
} | |
function bnpToRadix(b) { | |
if (b == null) | |
b = 10; | |
if (this.signum() == 0 || b < 2 || b > 36) | |
return "0"; | |
var cs = this.chunkSize(b); | |
var a = Math.pow(b, cs); | |
var d = nbv(a), y = nbi(), z = nbi(), r = ""; | |
this.divRemTo(d, y, z); | |
while (y.signum() > 0) { | |
r = (a + z.intValue()).toString(b).substr(1) + r; | |
y.divRemTo(d, y, z); | |
} | |
return z.intValue().toString(b) + r; | |
} | |
function bnpFromRadix(s, b) { | |
this.fromInt(0); | |
if (b == null) | |
b = 10; | |
var cs = this.chunkSize(b); | |
var d = Math.pow(b, cs), mi = false, j = 0, w = 0; | |
for (var i = 0; i < s.length; ++i) { | |
var x = intAt(s, i); | |
if (x < 0) { | |
if (s.charAt(i) == "-" && this.signum() == 0) | |
mi = true; | |
continue; | |
} | |
w = b * w + x; | |
if (++j >= cs) { | |
this.dMultiply(d); | |
this.dAddOffset(w, 0); | |
j = 0; | |
w = 0; | |
} | |
} | |
if (j > 0) { | |
this.dMultiply(Math.pow(b, j)); | |
this.dAddOffset(w, 0); | |
} | |
if (mi) | |
BigInteger.ZERO.subTo(this, this); | |
} | |
function bnpFromNumber(a, b, c) { | |
if ("number" == typeof b) { | |
if (a < 2) | |
this.fromInt(1); | |
else { | |
this.fromNumber(a, c); | |
if (!this.testBit(a - 1)) | |
this.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, this); | |
if (this.isEven()) | |
this.dAddOffset(1, 0); | |
while (!this.isProbablePrime(b)) { | |
this.dAddOffset(2, 0); | |
if (this.bitLength() > a) | |
this.subTo(BigInteger.ONE.shiftLeft(a - 1), this); | |
} | |
} | |
} else { | |
var x = new Array(), t = a & 7; | |
x.length = (a >> 3) + 1; | |
b.nextBytes(x); | |
if (t > 0) | |
x[0] &= (1 << t) - 1; | |
else | |
x[0] = 0; | |
this.fromString(x, 256); | |
} | |
} | |
function bnToByteArray() { | |
var i = this.t, r = new Array(); | |
r[0] = this.s; | |
var p = this.DB - i * this.DB % 8, d, k = 0; | |
if (i-- > 0) { | |
if (p < this.DB && (d = this.data[i] >> p) != (this.s & this.DM) >> p) | |
r[k++] = d | this.s << this.DB - p; | |
while (i >= 0) { | |
if (p < 8) { | |
d = (this.data[i] & (1 << p) - 1) << 8 - p; | |
d |= this.data[--i] >> (p += this.DB - 8); | |
} else { | |
d = this.data[i] >> (p -= 8) & 255; | |
if (p <= 0) { | |
p += this.DB; | |
--i; | |
} | |
} | |
if ((d & 128) != 0) | |
d |= -256; | |
if (k == 0 && (this.s & 128) != (d & 128)) | |
++k; | |
if (k > 0 || d != this.s) | |
r[k++] = d; | |
} | |
} | |
return r; | |
} | |
function bnEquals(a) { | |
return this.compareTo(a) == 0; | |
} | |
function bnMin(a) { | |
return this.compareTo(a) < 0 ? this : a; | |
} | |
function bnMax(a) { | |
return this.compareTo(a) > 0 ? this : a; | |
} | |
function bnpBitwiseTo(a, op, r) { | |
var i, f, m = Math.min(a.t, this.t); | |
for (i = 0; i < m; ++i) | |
r.data[i] = op(this.data[i], a.data[i]); | |
if (a.t < this.t) { | |
f = a.s & this.DM; | |
for (i = m; i < this.t; ++i) | |
r.data[i] = op(this.data[i], f); | |
r.t = this.t; | |
} else { | |
f = this.s & this.DM; | |
for (i = m; i < a.t; ++i) | |
r.data[i] = op(f, a.data[i]); | |
r.t = a.t; | |
} | |
r.s = op(this.s, a.s); | |
r.clamp(); | |
} | |
function op_and(x, y) { | |
return x & y; | |
} | |
function bnAnd(a) { | |
var r = nbi(); | |
this.bitwiseTo(a, op_and, r); | |
return r; | |
} | |
function op_or(x, y) { | |
return x | y; | |
} | |
function bnOr(a) { | |
var r = nbi(); | |
this.bitwiseTo(a, op_or, r); | |
return r; | |
} | |
function op_xor(x, y) { | |
return x ^ y; | |
} | |
function bnXor(a) { | |
var r = nbi(); | |
this.bitwiseTo(a, op_xor, r); | |
return r; | |
} | |
function op_andnot(x, y) { | |
return x & ~y; | |
} | |
function bnAndNot(a) { | |
var r = nbi(); | |
this.bitwiseTo(a, op_andnot, r); | |
return r; | |
} | |
function bnNot() { | |
var r = nbi(); | |
for (var i = 0; i < this.t; ++i) | |
r.data[i] = this.DM & ~this.data[i]; | |
r.t = this.t; | |
r.s = ~this.s; | |
return r; | |
} | |
function bnShiftLeft(n) { | |
var r = nbi(); | |
if (n < 0) | |
this.rShiftTo(-n, r); | |
else | |
this.lShiftTo(n, r); | |
return r; | |
} | |
function bnShiftRight(n) { | |
var r = nbi(); | |
if (n < 0) | |
this.lShiftTo(-n, r); | |
else | |
this.rShiftTo(n, r); | |
return r; | |
} | |
function lbit(x) { | |
if (x == 0) | |
return -1; | |
var r = 0; | |
if ((x & 65535) == 0) { | |
x >>= 16; | |
r += 16; | |
} | |
if ((x & 255) == 0) { | |
x >>= 8; | |
r += 8; | |
} | |
if ((x & 15) == 0) { | |
x >>= 4; | |
r += 4; | |
} | |
if ((x & 3) == 0) { | |
x >>= 2; | |
r += 2; | |
} | |
if ((x & 1) == 0) | |
++r; | |
return r; | |
} | |
function bnGetLowestSetBit() { | |
for (var i = 0; i < this.t; ++i) | |
if (this.data[i] != 0) | |
return i * this.DB + lbit(this.data[i]); | |
if (this.s < 0) | |
return this.t * this.DB; | |
return -1; | |
} | |
function cbit(x) { | |
var r = 0; | |
while (x != 0) { | |
x &= x - 1; | |
++r; | |
} | |
return r; | |
} | |
function bnBitCount() { | |
var r = 0, x = this.s & this.DM; | |
for (var i = 0; i < this.t; ++i) | |
r += cbit(this.data[i] ^ x); | |
return r; | |
} | |
function bnTestBit(n) { | |
var j = Math.floor(n / this.DB); | |
if (j >= this.t) | |
return this.s != 0; | |
return (this.data[j] & 1 << n % this.DB) != 0; | |
} | |
function bnpChangeBit(n, op) { | |
var r = BigInteger.ONE.shiftLeft(n); | |
this.bitwiseTo(r, op, r); | |
return r; | |
} | |
function bnSetBit(n) { | |
return this.changeBit(n, op_or); | |
} | |
function bnClearBit(n) { | |
return this.changeBit(n, op_andnot); | |
} | |
function bnFlipBit(n) { | |
return this.changeBit(n, op_xor); | |
} | |
function bnpAddTo(a, r) { | |
var i = 0, c = 0, m = Math.min(a.t, this.t); | |
while (i < m) { | |
c += this.data[i] + a.data[i]; | |
r.data[i++] = c & this.DM; | |
c >>= this.DB; | |
} | |
if (a.t < this.t) { | |
c += a.s; | |
while (i < this.t) { | |
c += this.data[i]; | |
r.data[i++] = c & this.DM; | |
c >>= this.DB; | |
} | |
c += this.s; | |
} else { | |
c += this.s; | |
while (i < a.t) { | |
c += a.data[i]; | |
r.data[i++] = c & this.DM; | |
c >>= this.DB; | |
} | |
c += a.s; | |
} | |
r.s = c < 0 ? -1 : 0; | |
if (c > 0) | |
r.data[i++] = c; | |
else if (c < -1) | |
r.data[i++] = this.DV + c; | |
r.t = i; | |
r.clamp(); | |
} | |
function bnAdd(a) { | |
var r = nbi(); | |
this.addTo(a, r); | |
return r; | |
} | |
function bnSubtract(a) { | |
var r = nbi(); | |
this.subTo(a, r); | |
return r; | |
} | |
function bnMultiply(a) { | |
var r = nbi(); | |
this.multiplyTo(a, r); | |
return r; | |
} | |
function bnDivide(a) { | |
var r = nbi(); | |
this.divRemTo(a, r, null); | |
return r; | |
} | |
function bnRemainder(a) { | |
var r = nbi(); | |
this.divRemTo(a, null, r); | |
return r; | |
} | |
function bnDivideAndRemainder(a) { | |
var q = nbi(), r = nbi(); | |
this.divRemTo(a, q, r); | |
return new Array(q, r); | |
} | |
function bnpDMultiply(n) { | |
this.data[this.t] = this.am(0, n - 1, this, 0, 0, this.t); | |
++this.t; | |
this.clamp(); | |
} | |
function bnpDAddOffset(n, w) { | |
if (n == 0) | |
return; | |
while (this.t <= w) | |
this.data[this.t++] = 0; | |
this.data[w] += n; | |
while (this.data[w] >= this.DV) { | |
this.data[w] -= this.DV; | |
if (++w >= this.t) | |
this.data[this.t++] = 0; | |
++this.data[w]; | |
} | |
} | |
function NullExp() { | |
} | |
function nNop(x) { | |
return x; | |
} | |
function nMulTo(x, y, r) { | |
x.multiplyTo(y, r); | |
} | |
function nSqrTo(x, r) { | |
x.squareTo(r); | |
} | |
NullExp.prototype.convert = nNop; | |
NullExp.prototype.revert = nNop; | |
NullExp.prototype.mulTo = nMulTo; | |
NullExp.prototype.sqrTo = nSqrTo; | |
function bnPow(e) { | |
return this.exp(e, new NullExp()); | |
} | |
function bnpMultiplyLowerTo(a, n, r) { | |
var i = Math.min(this.t + a.t, n); | |
r.s = 0; | |
r.t = i; | |
while (i > 0) | |
r.data[--i] = 0; | |
var j; | |
for (j = r.t - this.t; i < j; ++i) | |
r.data[i + this.t] = this.am(0, a.data[i], r, i, 0, this.t); | |
for (j = Math.min(a.t, n); i < j; ++i) | |
this.am(0, a.data[i], r, i, 0, n - i); | |
r.clamp(); | |
} | |
function bnpMultiplyUpperTo(a, n, r) { | |
--n; | |
var i = r.t = this.t + a.t - n; | |
r.s = 0; | |
while (--i >= 0) | |
r.data[i] = 0; | |
for (i = Math.max(n - this.t, 0); i < a.t; ++i) | |
r.data[this.t + i - n] = this.am(n - i, a.data[i], r, 0, 0, this.t + i - n); | |
r.clamp(); | |
r.drShiftTo(1, r); | |
} | |
function Barrett(m) { | |
this.r2 = nbi(); | |
this.q3 = nbi(); | |
BigInteger.ONE.dlShiftTo(2 * m.t, this.r2); | |
this.mu = this.r2.divide(m); | |
this.m = m; | |
} | |
function barrettConvert(x) { | |
if (x.s < 0 || x.t > 2 * this.m.t) | |
return x.mod(this.m); | |
else if (x.compareTo(this.m) < 0) | |
return x; | |
else { | |
var r = nbi(); | |
x.copyTo(r); | |
this.reduce(r); | |
return r; | |
} | |
} | |
function barrettRevert(x) { | |
return x; | |
} | |
function barrettReduce(x) { | |
x.drShiftTo(this.m.t - 1, this.r2); | |
if (x.t > this.m.t + 1) { | |
x.t = this.m.t + 1; | |
x.clamp(); | |
} | |
this.mu.multiplyUpperTo(this.r2, this.m.t + 1, this.q3); | |
this.m.multiplyLowerTo(this.q3, this.m.t + 1, this.r2); | |
while (x.compareTo(this.r2) < 0) | |
x.dAddOffset(1, this.m.t + 1); | |
x.subTo(this.r2, x); | |
while (x.compareTo(this.m) >= 0) | |
x.subTo(this.m, x); | |
} | |
function barrettSqrTo(x, r) { | |
x.squareTo(r); | |
this.reduce(r); | |
} | |
function barrettMulTo(x, y, r) { | |
x.multiplyTo(y, r); | |
this.reduce(r); | |
} | |
Barrett.prototype.convert = barrettConvert; | |
Barrett.prototype.revert = barrettRevert; | |
Barrett.prototype.reduce = barrettReduce; | |
Barrett.prototype.mulTo = barrettMulTo; | |
Barrett.prototype.sqrTo = barrettSqrTo; | |
function bnModPow(e, m) { | |
var i = e.bitLength(), k, r = nbv(1), z; | |
if (i <= 0) | |
return r; | |
else if (i < 18) | |
k = 1; | |
else if (i < 48) | |
k = 3; | |
else if (i < 144) | |
k = 4; | |
else if (i < 768) | |
k = 5; | |
else | |
k = 6; | |
if (i < 8) | |
z = new Classic(m); | |
else if (m.isEven()) | |
z = new Barrett(m); | |
else | |
z = new Montgomery(m); | |
var g = new Array(), n = 3, k1 = k - 1, km = (1 << k) - 1; | |
g[1] = z.convert(this); | |
if (k > 1) { | |
var g2 = nbi(); | |
z.sqrTo(g[1], g2); | |
while (n <= km) { | |
g[n] = nbi(); | |
z.mulTo(g2, g[n - 2], g[n]); | |
n += 2; | |
} | |
} | |
var j = e.t - 1, w, is1 = true, r2 = nbi(), t; | |
i = nbits(e.data[j]) - 1; | |
while (j >= 0) { | |
if (i >= k1) | |
w = e.data[j] >> i - k1 & km; | |
else { | |
w = (e.data[j] & (1 << i + 1) - 1) << k1 - i; | |
if (j > 0) | |
w |= e.data[j - 1] >> this.DB + i - k1; | |
} | |
n = k; | |
while ((w & 1) == 0) { | |
w >>= 1; | |
--n; | |
} | |
if ((i -= n) < 0) { | |
i += this.DB; | |
--j; | |
} | |
if (is1) { | |
g[w].copyTo(r); | |
is1 = false; | |
} else { | |
while (n > 1) { | |
z.sqrTo(r, r2); | |
z.sqrTo(r2, r); | |
n -= 2; | |
} | |
if (n > 0) | |
z.sqrTo(r, r2); | |
else { | |
t = r; | |
r = r2; | |
r2 = t; | |
} | |
z.mulTo(r2, g[w], r); | |
} | |
while (j >= 0 && (e.data[j] & 1 << i) == 0) { | |
z.sqrTo(r, r2); | |
t = r; | |
r = r2; | |
r2 = t; | |
if (--i < 0) { | |
i = this.DB - 1; | |
--j; | |
} | |
} | |
} | |
return z.revert(r); | |
} | |
function bnGCD(a) { | |
var x = this.s < 0 ? this.negate() : this.clone(); | |
var y = a.s < 0 ? a.negate() : a.clone(); | |
if (x.compareTo(y) < 0) { | |
var t = x; | |
x = y; | |
y = t; | |
} | |
var i = x.getLowestSetBit(), g = y.getLowestSetBit(); | |
if (g < 0) | |
return x; | |
if (i < g) | |
g = i; | |
if (g > 0) { | |
x.rShiftTo(g, x); | |
y.rShiftTo(g, y); | |
} | |
while (x.signum() > 0) { | |
if ((i = x.getLowestSetBit()) > 0) | |
x.rShiftTo(i, x); | |
if ((i = y.getLowestSetBit()) > 0) | |
y.rShiftTo(i, y); | |
if (x.compareTo(y) >= 0) { | |
x.subTo(y, x); | |
x.rShiftTo(1, x); | |
} else { | |
y.subTo(x, y); | |
y.rShiftTo(1, y); | |
} | |
} | |
if (g > 0) | |
y.lShiftTo(g, y); | |
return y; | |
} | |
function bnpModInt(n) { | |
if (n <= 0) | |
return 0; | |
var d = this.DV % n, r = this.s < 0 ? n - 1 : 0; | |
if (this.t > 0) | |
if (d == 0) | |
r = this.data[0] % n; | |
else | |
for (var i = this.t - 1; i >= 0; --i) | |
r = (d * r + this.data[i]) % n; | |
return r; | |
} | |
function bnModInverse(m) { | |
var ac = m.isEven(); | |
if (this.isEven() && ac || m.signum() == 0) | |
return BigInteger.ZERO; | |
var u = m.clone(), v = this.clone(); | |
var a = nbv(1), b = nbv(0), c = nbv(0), d = nbv(1); | |
while (u.signum() != 0) { | |
while (u.isEven()) { | |
u.rShiftTo(1, u); | |
if (ac) { | |
if (!a.isEven() || !b.isEven()) { | |
a.addTo(this, a); | |
b.subTo(m, b); | |
} | |
a.rShiftTo(1, a); | |
} else if (!b.isEven()) | |
b.subTo(m, b); | |
b.rShiftTo(1, b); | |
} | |
while (v.isEven()) { | |
v.rShiftTo(1, v); | |
if (ac) { | |
if (!c.isEven() || !d.isEven()) { | |
c.addTo(this, c); | |
d.subTo(m, d); | |
} | |
c.rShiftTo(1, c); | |
} else if (!d.isEven()) | |
d.subTo(m, d); | |
d.rShiftTo(1, d); | |
} | |
if (u.compareTo(v) >= 0) { | |
u.subTo(v, u); | |
if (ac) | |
a.subTo(c, a); | |
b.subTo(d, b); | |
} else { | |
v.subTo(u, v); | |
if (ac) | |
c.subTo(a, c); | |
d.subTo(b, d); | |
} | |
} | |
if (v.compareTo(BigInteger.ONE) != 0) | |
return BigInteger.ZERO; | |
if (d.compareTo(m) >= 0) | |
return d.subtract(m); | |
if (d.signum() < 0) | |
d.addTo(m, d); | |
else | |
return d; | |
if (d.signum() < 0) | |
return d.add(m); | |
else | |
return d; | |
} | |
var lowprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509]; | |
var lplim = (1 << 26) / lowprimes[lowprimes.length - 1]; | |
function bnIsProbablePrime(t) { | |
var i, x = this.abs(); | |
if (x.t == 1 && x.data[0] <= lowprimes[lowprimes.length - 1]) { | |
for (i = 0; i < lowprimes.length; ++i) | |
if (x.data[0] == lowprimes[i]) | |
return true; | |
return false; | |
} | |
if (x.isEven()) | |
return false; | |
i = 1; | |
while (i < lowprimes.length) { | |
var m = lowprimes[i], j = i + 1; | |
while (j < lowprimes.length && m < lplim) | |
m *= lowprimes[j++]; | |
m = x.modInt(m); | |
while (i < j) | |
if (m % lowprimes[i++] == 0) | |
return false; | |
} | |
return x.millerRabin(t); | |
} | |
function bnpMillerRabin(t) { | |
var n1 = this.subtract(BigInteger.ONE); | |
var k = n1.getLowestSetBit(); | |
if (k <= 0) | |
return false; | |
var r = n1.shiftRight(k); | |
var prng = bnGetPrng(); | |
var a; | |
for (var i = 0; i < t; ++i) { | |
do { | |
a = new BigInteger(this.bitLength(), prng); | |
} while (a.compareTo(BigInteger.ONE) <= 0 || a.compareTo(n1) >= 0); | |
var y = a.modPow(r, this); | |
if (y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) { | |
var j = 1; | |
while (j++ < k && y.compareTo(n1) != 0) { | |
y = y.modPowInt(2, this); | |
if (y.compareTo(BigInteger.ONE) == 0) | |
return false; | |
} | |
if (y.compareTo(n1) != 0) | |
return false; | |
} | |
} | |
return true; | |
} | |
function bnGetPrng() { | |
return { | |
// x is an array to fill with bytes | |
nextBytes: function(x) { | |
for (var i = 0; i < x.length; ++i) { | |
x[i] = Math.floor(Math.random() * 256); | |
} | |
} | |
}; | |
} | |
BigInteger.prototype.chunkSize = bnpChunkSize; | |
BigInteger.prototype.toRadix = bnpToRadix; | |
BigInteger.prototype.fromRadix = bnpFromRadix; | |
BigInteger.prototype.fromNumber = bnpFromNumber; | |
BigInteger.prototype.bitwiseTo = bnpBitwiseTo; | |
BigInteger.prototype.changeBit = bnpChangeBit; | |
BigInteger.prototype.addTo = bnpAddTo; | |
BigInteger.prototype.dMultiply = bnpDMultiply; | |
BigInteger.prototype.dAddOffset = bnpDAddOffset; | |
BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo; | |
BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo; | |
BigInteger.prototype.modInt = bnpModInt; | |
BigInteger.prototype.millerRabin = bnpMillerRabin; | |
BigInteger.prototype.clone = bnClone; | |
BigInteger.prototype.intValue = bnIntValue; | |
BigInteger.prototype.byteValue = bnByteValue; | |
BigInteger.prototype.shortValue = bnShortValue; | |
BigInteger.prototype.signum = bnSigNum; | |
BigInteger.prototype.toByteArray = bnToByteArray; | |
BigInteger.prototype.equals = bnEquals; | |
BigInteger.prototype.min = bnMin; | |
BigInteger.prototype.max = bnMax; | |
BigInteger.prototype.and = bnAnd; | |
BigInteger.prototype.or = bnOr; | |
BigInteger.prototype.xor = bnXor; | |
BigInteger.prototype.andNot = bnAndNot; | |
BigInteger.prototype.not = bnNot; | |
BigInteger.prototype.shiftLeft = bnShiftLeft; | |
BigInteger.prototype.shiftRight = bnShiftRight; | |
BigInteger.prototype.getLowestSetBit = bnGetLowestSetBit; | |
BigInteger.prototype.bitCount = bnBitCount; | |
BigInteger.prototype.testBit = bnTestBit; | |
BigInteger.prototype.setBit = bnSetBit; | |
BigInteger.prototype.clearBit = bnClearBit; | |
BigInteger.prototype.flipBit = bnFlipBit; | |
BigInteger.prototype.add = bnAdd; | |
BigInteger.prototype.subtract = bnSubtract; | |
BigInteger.prototype.multiply = bnMultiply; | |
BigInteger.prototype.divide = bnDivide; | |
BigInteger.prototype.remainder = bnRemainder; | |
BigInteger.prototype.divideAndRemainder = bnDivideAndRemainder; | |
BigInteger.prototype.modPow = bnModPow; | |
BigInteger.prototype.modInverse = bnModInverse; | |
BigInteger.prototype.pow = bnPow; | |
BigInteger.prototype.gcd = bnGCD; | |
BigInteger.prototype.isProbablePrime = bnIsProbablePrime; | |
} | |
}); | |
// node_modules/node-forge/lib/sha1.js | |
var require_sha1 = __commonJS({ | |
"node_modules/node-forge/lib/sha1.js"(exports2, module2) { | |
var forge7 = require_forge(); | |
require_md(); | |
require_util(); | |
var sha1 = module2.exports = forge7.sha1 = forge7.sha1 || {}; | |
forge7.md.sha1 = forge7.md.algorithms.sha1 = sha1; | |
sha1.create = function() { | |
if (!_initialized) { | |
_init(); | |
} | |
var _state = null; | |
var _input = forge7.util.createBuffer(); | |
var _w = new Array(80); | |
var md = { | |
algorithm: "sha1", | |
blockLength: 64, | |
digestLength: 20, | |
// 56-bit length of message so far (does not including padding) | |
messageLength: 0, | |
// true message length | |
fullMessageLength: null, | |
// size of message length in bytes | |
messageLengthSize: 8 | |
}; | |
md.start = function() { | |
md.messageLength = 0; | |
md.fullMessageLength = md.messageLength64 = []; | |
var int32s = md.messageLengthSize / 4; | |
for (var i = 0; i < int32s; ++i) { | |
md.fullMessageLength.push(0); | |
} | |
_input = forge7.util.createBuffer(); | |
_state = { | |
h0: 1732584193, | |
h1: 4023233417, | |
h2: 2562383102, | |
h3: 271733878, | |
h4: 3285377520 | |
}; | |
return md; | |
}; | |
md.start(); | |
md.update = function(msg, encoding) { | |
if (encoding === "utf8") { | |
msg = forge7.util.encodeUtf8(msg); | |
} | |
var len = msg.length; | |
md.messageLength += len; | |
len = [len / 4294967296 >>> 0, len >>> 0]; | |
for (var i = md.fullMessageLength.length - 1; i >= 0; --i) { | |
md.fullMessageLength[i] += len[1]; | |
len[1] = len[0] + (md.fullMessageLength[i] / 4294967296 >>> 0); | |
md.fullMessageLength[i] = md.fullMessageLength[i] >>> 0; | |
len[0] = len[1] / 4294967296 >>> 0; | |
} | |
_input.putBytes(msg); | |
_update(_state, _w, _input); | |
if (_input.read > 2048 || _input.length() === 0) { | |
_input.compact(); | |
} | |
return md; | |
}; | |
md.digest = function() { | |
var finalBlock = forge7.util.createBuffer(); | |
finalBlock.putBytes(_input.bytes()); | |
var remaining = md.fullMessageLength[md.fullMessageLength.length - 1] + md.messageLengthSize; | |
var overflow = remaining & md.blockLength - 1; | |
finalBlock.putBytes(_padding.substr(0, md.blockLength - overflow)); | |
var next, carry; | |
var bits2 = md.fullMessageLength[0] * 8; | |
for (var i = 0; i < md.fullMessageLength.length - 1; ++i) { | |
next = md.fullMessageLength[i + 1] * 8; | |
carry = next / 4294967296 >>> 0; | |
bits2 += carry; | |
finalBlock.putInt32(bits2 >>> 0); | |
bits2 = next >>> 0; | |
} | |
finalBlock.putInt32(bits2); | |
var s2 = { | |
h0: _state.h0, | |
h1: _state.h1, | |
h2: _state.h2, | |
h3: _state.h3, | |
h4: _state.h4 | |
}; | |
_update(s2, _w, finalBlock); | |
var rval = forge7.util.createBuffer(); | |
rval.putInt32(s2.h0); | |
rval.putInt32(s2.h1); | |
rval.putInt32(s2.h2); | |
rval.putInt32(s2.h3); | |
rval.putInt32(s2.h4); | |
return rval; | |
}; | |
return md; | |
}; | |
var _padding = null; | |
var _initialized = false; | |
function _init() { | |
_padding = String.fromCharCode(128); | |
_padding += forge7.util.fillString(String.fromCharCode(0), 64); | |
_initialized = true; | |
} | |
function _update(s, w, bytes3) { | |
var t, a, b, c, d, e, f, i; | |
var len = bytes3.length(); | |
while (len >= 64) { | |
a = s.h0; | |
b = s.h1; | |
c = s.h2; | |
d = s.h3; | |
e = s.h4; | |
for (i = 0; i < 16; ++i) { | |
t = bytes3.getInt32(); | |
w[i] = t; | |
f = d ^ b & (c ^ d); | |
t = (a << 5 | a >>> 27) + f + e + 1518500249 + t; | |
e = d; | |
d = c; | |
c = (b << 30 | b >>> 2) >>> 0; | |
b = a; | |
a = t; | |
} | |
for (; i < 20; ++i) { | |
t = w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16]; | |
t = t << 1 | t >>> 31; | |
w[i] = t; | |
f = d ^ b & (c ^ d); | |
t = (a << 5 | a >>> 27) + f + e + 1518500249 + t; | |
e = d; | |
d = c; | |
c = (b << 30 | b >>> 2) >>> 0; | |
b = a; | |
a = t; | |
} | |
for (; i < 32; ++i) { | |
t = w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16]; | |
t = t << 1 | t >>> 31; | |
w[i] = t; | |
f = b ^ c ^ d; | |
t = (a << 5 | a >>> 27) + f + e + 1859775393 + t; | |
e = d; | |
d = c; | |
c = (b << 30 | b >>> 2) >>> 0; | |
b = a; | |
a = t; | |
} | |
for (; i < 40; ++i) { | |
t = w[i - 6] ^ w[i - 16] ^ w[i - 28] ^ w[i - 32]; | |
t = t << 2 | t >>> 30; | |
w[i] = t; | |
f = b ^ c ^ d; | |
t = (a << 5 | a >>> 27) + f + e + 1859775393 + t; | |
e = d; | |
d = c; | |
c = (b << 30 | b >>> 2) >>> 0; | |
b = a; | |
a = t; | |
} | |
for (; i < 60; ++i) { | |
t = w[i - 6] ^ w[i - 16] ^ w[i - 28] ^ w[i - 32]; | |
t = t << 2 | t >>> 30; | |
w[i] = t; | |
f = b & c | d & (b ^ c); | |
t = (a << 5 | a >>> 27) + f + e + 2400959708 + t; | |
e = d; | |
d = c; | |
c = (b << 30 | b >>> 2) >>> 0; | |
b = a; | |
a = t; | |
} | |
for (; i < 80; ++i) { | |
t = w[i - 6] ^ w[i - 16] ^ w[i - 28] ^ w[i - 32]; | |
t = t << 2 | t >>> 30; | |
w[i] = t; | |
f = b ^ c ^ d; | |
t = (a << 5 | a >>> 27) + f + e + 3395469782 + t; | |
e = d; | |
d = c; | |
c = (b << 30 | b >>> 2) >>> 0; | |
b = a; | |
a = t; | |
} | |
s.h0 = s.h0 + a | 0; | |
s.h1 = s.h1 + b | 0; | |
s.h2 = s.h2 + c | 0; | |
s.h3 = s.h3 + d | 0; | |
s.h4 = s.h4 + e | 0; | |
len -= 64; | |
} | |
} | |
} | |
}); | |
// node_modules/node-forge/lib/pkcs1.js | |
var require_pkcs1 = __commonJS({ | |
"node_modules/node-forge/lib/pkcs1.js"(exports2, module2) { | |
var forge7 = require_forge(); | |
require_util(); | |
require_random(); | |
require_sha1(); | |
var pkcs1 = module2.exports = forge7.pkcs1 = forge7.pkcs1 || {}; | |
pkcs1.encode_rsa_oaep = function(key, message2, options) { | |
var label; | |
var seed; | |
var md; | |
var mgf1Md; | |
if (typeof options === "string") { | |
label = options; | |
seed = arguments[3] || void 0; | |
md = arguments[4] || void 0; | |
} else if (options) { | |
label = options.label || void 0; | |
seed = options.seed || void 0; | |
md = options.md || void 0; | |
if (options.mgf1 && options.mgf1.md) { | |
mgf1Md = options.mgf1.md; | |
} | |
} | |
if (!md) { | |
md = forge7.md.sha1.create(); | |
} else { | |
md.start(); | |
} | |
if (!mgf1Md) { | |
mgf1Md = md; | |
} | |
var keyLength = Math.ceil(key.n.bitLength() / 8); | |
var maxLength = keyLength - 2 * md.digestLength - 2; | |
if (message2.length > maxLength) { | |
var error = new Error("RSAES-OAEP input message length is too long."); | |
error.length = message2.length; | |
error.maxLength = maxLength; | |
throw error; | |
} | |
if (!label) { | |
label = ""; | |
} | |
md.update(label, "raw"); | |
var lHash = md.digest(); | |
var PS = ""; | |
var PS_length = maxLength - message2.length; | |
for (var i = 0; i < PS_length; i++) { | |
PS += "\0"; | |
} | |
var DB = lHash.getBytes() + PS + "" + message2; | |
if (!seed) { | |
seed = forge7.random.getBytes(md.digestLength); | |
} else if (seed.length !== md.digestLength) { | |
var error = new Error("Invalid RSAES-OAEP seed. The seed length must match the digest length."); | |
error.seedLength = seed.length; | |
error.digestLength = md.digestLength; | |
throw error; | |
} | |
var dbMask = rsa_mgf1(seed, keyLength - md.digestLength - 1, mgf1Md); | |
var maskedDB = forge7.util.xorBytes(DB, dbMask, DB.length); | |
var seedMask = rsa_mgf1(maskedDB, md.digestLength, mgf1Md); | |
var maskedSeed = forge7.util.xorBytes(seed, seedMask, seed.length); | |
return "\0" + maskedSeed + maskedDB; | |
}; | |
pkcs1.decode_rsa_oaep = function(key, em, options) { | |
var label; | |
var md; | |
var mgf1Md; | |
if (typeof options === "string") { | |
label = options; | |
md = arguments[3] || void 0; | |
} else if (options) { | |
label = options.label || void 0; | |
md = options.md || void 0; | |
if (options.mgf1 && options.mgf1.md) { | |
mgf1Md = options.mgf1.md; | |
} | |
} | |
var keyLength = Math.ceil(key.n.bitLength() / 8); | |
if (em.length !== keyLength) { | |
var error = new Error("RSAES-OAEP encoded message length is invalid."); | |
error.length = em.length; | |
error.expectedLength = keyLength; | |
throw error; | |
} | |
if (md === void 0) { | |
md = forge7.md.sha1.create(); | |
} else { | |
md.start(); | |
} | |
if (!mgf1Md) { | |
mgf1Md = md; | |
} | |
if (keyLength < 2 * md.digestLength + 2) { | |
throw new Error("RSAES-OAEP key is too short for the hash function."); | |
} | |
if (!label) { | |
label = ""; | |
} | |
md.update(label, "raw"); | |
var lHash = md.digest().getBytes(); | |
var y = em.charAt(0); | |
var maskedSeed = em.substring(1, md.digestLength + 1); | |
var maskedDB = em.substring(1 + md.digestLength); | |
var seedMask = rsa_mgf1(maskedDB, md.digestLength, mgf1Md); | |
var seed = forge7.util.xorBytes(maskedSeed, seedMask, maskedSeed.length); | |
var dbMask = rsa_mgf1(seed, keyLength - md.digestLength - 1, mgf1Md); | |
var db = forge7.util.xorBytes(maskedDB, dbMask, maskedDB.length); | |
var lHashPrime = db.substring(0, md.digestLength); | |
var error = y !== "\0"; | |
for (var i = 0; i < md.digestLength; ++i) { | |
error |= lHash.charAt(i) !== lHashPrime.charAt(i); | |
} | |
var in_ps = 1; | |
var index = md.digestLength; | |
for (var j = md.digestLength; j < db.length; j++) { | |
var code9 = db.charCodeAt(j); | |
var is_0 = code9 & 1 ^ 1; | |
var error_mask = in_ps ? 65534 : 0; | |
error |= code9 & error_mask; | |
in_ps = in_ps & is_0; | |
index += in_ps; | |
} | |
if (error || db.charCodeAt(index) !== 1) { | |
throw new Error("Invalid RSAES-OAEP padding."); | |
} | |
return db.substring(index + 1); | |
}; | |
function rsa_mgf1(seed, maskLength, hash3) { | |
if (!hash3) { | |
hash3 = forge7.md.sha1.create(); | |
} | |
var t = ""; | |
var count = Math.ceil(maskLength / hash3.digestLength); | |
for (var i = 0; i < count; ++i) { | |
var c = String.fromCharCode( | |
i >> 24 & 255, | |
i >> 16 & 255, | |
i >> 8 & 255, | |
i & 255 | |
); | |
hash3.start(); | |
hash3.update(seed + c); | |
t += hash3.digest().getBytes(); | |
} | |
return t.substring(0, maskLength); | |
} | |
} | |
}); | |
// node_modules/node-forge/lib/prime.js | |
var require_prime = __commonJS({ | |
"node_modules/node-forge/lib/prime.js"(exports2, module2) { | |
var forge7 = require_forge(); | |
require_util(); | |
require_jsbn(); | |
require_random(); | |
(function() { | |
if (forge7.prime) { | |
module2.exports = forge7.prime; | |
return; | |
} | |
var prime = module2.exports = forge7.prime = forge7.prime || {}; | |
var BigInteger = forge7.jsbn.BigInteger; | |
var GCD_30_DELTA = [6, 4, 2, 4, 2, 4, 6, 2]; | |
var THIRTY = new BigInteger(null); | |
THIRTY.fromInt(30); | |
var op_or = function(x, y) { | |
return x | y; | |
}; | |
prime.generateProbablePrime = function(bits2, options, callback) { | |
if (typeof options === "function") { | |
callback = options; | |
options = {}; | |
} | |
options = options || {}; | |
var algorithm = options.algorithm || "PRIMEINC"; | |
if (typeof algorithm === "string") { | |
algorithm = { name: algorithm }; | |
} | |
algorithm.options = algorithm.options || {}; | |
var prng = options.prng || forge7.random; | |
var rng = { | |
// x is an array to fill with bytes | |
nextBytes: function(x) { | |
var b = prng.getBytesSync(x.length); | |
for (var i = 0; i < x.length; ++i) { | |
x[i] = b.charCodeAt(i); | |
} | |
} | |
}; | |
if (algorithm.name === "PRIMEINC") { | |
return primeincFindPrime(bits2, rng, algorithm.options, callback); | |
} | |
throw new Error("Invalid prime generation algorithm: " + algorithm.name); | |
}; | |
function primeincFindPrime(bits2, rng, options, callback) { | |
if ("workers" in options) { | |
return primeincFindPrimeWithWorkers(bits2, rng, options, callback); | |
} | |
return primeincFindPrimeWithoutWorkers(bits2, rng, options, callback); | |
} | |
function primeincFindPrimeWithoutWorkers(bits2, rng, options, callback) { | |
var num = generateRandom(bits2, rng); | |
var deltaIdx = 0; | |
var mrTests = getMillerRabinTests(num.bitLength()); | |
if ("millerRabinTests" in options) { | |
mrTests = options.millerRabinTests; | |
} | |
var maxBlockTime = 10; | |
if ("maxBlockTime" in options) { | |
maxBlockTime = options.maxBlockTime; | |
} | |
_primeinc(num, bits2, rng, deltaIdx, mrTests, maxBlockTime, callback); | |
} | |
function _primeinc(num, bits2, rng, deltaIdx, mrTests, maxBlockTime, callback) { | |
var start = +/* @__PURE__ */ new Date(); | |
do { | |
if (num.bitLength() > bits2) { | |
num = generateRandom(bits2, rng); | |
} | |
if (num.isProbablePrime(mrTests)) { | |
return callback(null, num); | |
} | |
num.dAddOffset(GCD_30_DELTA[deltaIdx++ % 8], 0); | |
} while (maxBlockTime < 0 || +/* @__PURE__ */ new Date() - start < maxBlockTime); | |
forge7.util.setImmediate(function() { | |
_primeinc(num, bits2, rng, deltaIdx, mrTests, maxBlockTime, callback); | |
}); | |
} | |
function primeincFindPrimeWithWorkers(bits2, rng, options, callback) { | |
if (typeof Worker === "undefined") { | |
return primeincFindPrimeWithoutWorkers(bits2, rng, options, callback); | |
} | |
var num = generateRandom(bits2, rng); | |
var numWorkers = options.workers; | |
var workLoad = options.workLoad || 100; | |
var range = workLoad * 30 / 8; | |
var workerScript = options.workerScript || "forge/prime.worker.js"; | |
if (numWorkers === -1) { | |
return forge7.util.estimateCores(function(err, cores) { | |
if (err) { | |
cores = 2; | |
} | |
numWorkers = cores - 1; | |
generate(); | |
}); | |
} | |
generate(); | |
function generate() { | |
numWorkers = Math.max(1, numWorkers); | |
var workers = []; | |
for (var i = 0; i < numWorkers; ++i) { | |
workers[i] = new Worker(workerScript); | |
} | |
var running = numWorkers; | |
for (var i = 0; i < numWorkers; ++i) { | |
workers[i].addEventListener("message", workerMessage); | |
} | |
var found = false; | |
function workerMessage(e) { | |
if (found) { | |
return; | |
} | |
--running; | |
var data = e.data; | |
if (data.found) { | |
for (var i2 = 0; i2 < workers.length; ++i2) { | |
workers[i2].terminate(); | |
} | |
found = true; | |
return callback(null, new BigInteger(data.prime, 16)); | |
} | |
if (num.bitLength() > bits2) { | |
num = generateRandom(bits2, rng); | |
} | |
var hex = num.toString(16); | |
e.target.postMessage({ | |
hex, | |
workLoad | |
}); | |
num.dAddOffset(range, 0); | |
} | |
} | |
} | |
function generateRandom(bits2, rng) { | |
var num = new BigInteger(bits2, rng); | |
var bits1 = bits2 - 1; | |
if (!num.testBit(bits1)) { | |
num.bitwiseTo(BigInteger.ONE.shiftLeft(bits1), op_or, num); | |
} | |
num.dAddOffset(31 - num.mod(THIRTY).byteValue(), 0); | |
return num; | |
} | |
function getMillerRabinTests(bits2) { | |
if (bits2 <= 100) | |
return 27; | |
if (bits2 <= 150) | |
return 18; | |
if (bits2 <= 200) | |
return 15; | |
if (bits2 <= 250) | |
return 12; | |
if (bits2 <= 300) | |
return 9; | |
if (bits2 <= 350) | |
return 8; | |
if (bits2 <= 400) | |
return 7; | |
if (bits2 <= 500) | |
return 6; | |
if (bits2 <= 600) | |
return 5; | |
if (bits2 <= 800) | |
return 4; | |
if (bits2 <= 1250) | |
return 3; | |
return 2; | |
} | |
})(); | |
} | |
}); | |
// node_modules/node-forge/lib/rsa.js | |
var require_rsa = __commonJS({ | |
"node_modules/node-forge/lib/rsa.js"(exports2, module2) { | |
var forge7 = require_forge(); | |
require_asn1(); | |
require_jsbn(); | |
require_oids(); | |
require_pkcs1(); | |
require_prime(); | |
require_random(); | |
require_util(); | |
if (typeof BigInteger === "undefined") { | |
BigInteger = forge7.jsbn.BigInteger; | |
} | |
var BigInteger; | |
var _crypto = forge7.util.isNodejs ? require_crypto() : null; | |
var asn1 = forge7.asn1; | |
var util2 = forge7.util; | |
forge7.pki = forge7.pki || {}; | |
module2.exports = forge7.pki.rsa = forge7.rsa = forge7.rsa || {}; | |
var pki = forge7.pki; | |
var GCD_30_DELTA = [6, 4, 2, 4, 2, 4, 6, 2]; | |
var privateKeyValidator = { | |
// PrivateKeyInfo | |
name: "PrivateKeyInfo", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.SEQUENCE, | |
constructed: true, | |
value: [{ | |
// Version (INTEGER) | |
name: "PrivateKeyInfo.version", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.INTEGER, | |
constructed: false, | |
capture: "privateKeyVersion" | |
}, { | |
// privateKeyAlgorithm | |
name: "PrivateKeyInfo.privateKeyAlgorithm", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.SEQUENCE, | |
constructed: true, | |
value: [{ | |
name: "AlgorithmIdentifier.algorithm", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.OID, | |
constructed: false, | |
capture: "privateKeyOid" | |
}] | |
}, { | |
// PrivateKey | |
name: "PrivateKeyInfo", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.OCTETSTRING, | |
constructed: false, | |
capture: "privateKey" | |
}] | |
}; | |
var rsaPrivateKeyValidator = { | |
// RSAPrivateKey | |
name: "RSAPrivateKey", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.SEQUENCE, | |
constructed: true, | |
value: [{ | |
// Version (INTEGER) | |
name: "RSAPrivateKey.version", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.INTEGER, | |
constructed: false, | |
capture: "privateKeyVersion" | |
}, { | |
// modulus (n) | |
name: "RSAPrivateKey.modulus", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.INTEGER, | |
constructed: false, | |
capture: "privateKeyModulus" | |
}, { | |
// publicExponent (e) | |
name: "RSAPrivateKey.publicExponent", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.INTEGER, | |
constructed: false, | |
capture: "privateKeyPublicExponent" | |
}, { | |
// privateExponent (d) | |
name: "RSAPrivateKey.privateExponent", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.INTEGER, | |
constructed: false, | |
capture: "privateKeyPrivateExponent" | |
}, { | |
// prime1 (p) | |
name: "RSAPrivateKey.prime1", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.INTEGER, | |
constructed: false, | |
capture: "privateKeyPrime1" | |
}, { | |
// prime2 (q) | |
name: "RSAPrivateKey.prime2", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.INTEGER, | |
constructed: false, | |
capture: "privateKeyPrime2" | |
}, { | |
// exponent1 (d mod (p-1)) | |
name: "RSAPrivateKey.exponent1", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.INTEGER, | |
constructed: false, | |
capture: "privateKeyExponent1" | |
}, { | |
// exponent2 (d mod (q-1)) | |
name: "RSAPrivateKey.exponent2", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.INTEGER, | |
constructed: false, | |
capture: "privateKeyExponent2" | |
}, { | |
// coefficient ((inverse of q) mod p) | |
name: "RSAPrivateKey.coefficient", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.INTEGER, | |
constructed: false, | |
capture: "privateKeyCoefficient" | |
}] | |
}; | |
var rsaPublicKeyValidator = { | |
// RSAPublicKey | |
name: "RSAPublicKey", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.SEQUENCE, | |
constructed: true, | |
value: [{ | |
// modulus (n) | |
name: "RSAPublicKey.modulus", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.INTEGER, | |
constructed: false, | |
capture: "publicKeyModulus" | |
}, { | |
// publicExponent (e) | |
name: "RSAPublicKey.exponent", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.INTEGER, | |
constructed: false, | |
capture: "publicKeyExponent" | |
}] | |
}; | |
var publicKeyValidator = forge7.pki.rsa.publicKeyValidator = { | |
name: "SubjectPublicKeyInfo", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.SEQUENCE, | |
constructed: true, | |
captureAsn1: "subjectPublicKeyInfo", | |
value: [{ | |
name: "SubjectPublicKeyInfo.AlgorithmIdentifier", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.SEQUENCE, | |
constructed: true, | |
value: [{ | |
name: "AlgorithmIdentifier.algorithm", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.OID, | |
constructed: false, | |
capture: "publicKeyOid" | |
}] | |
}, { | |
// subjectPublicKey | |
name: "SubjectPublicKeyInfo.subjectPublicKey", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.BITSTRING, | |
constructed: false, | |
value: [{ | |
// RSAPublicKey | |
name: "SubjectPublicKeyInfo.subjectPublicKey.RSAPublicKey", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.SEQUENCE, | |
constructed: true, | |
optional: true, | |
captureAsn1: "rsaPublicKey" | |
}] | |
}] | |
}; | |
var digestInfoValidator = { | |
name: "DigestInfo", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.SEQUENCE, | |
constructed: true, | |
value: [{ | |
name: "DigestInfo.DigestAlgorithm", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.SEQUENCE, | |
constructed: true, | |
value: [{ | |
name: "DigestInfo.DigestAlgorithm.algorithmIdentifier", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.OID, | |
constructed: false, | |
capture: "algorithmIdentifier" | |
}, { | |
// NULL paramters | |
name: "DigestInfo.DigestAlgorithm.parameters", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.NULL, | |
// captured only to check existence for md2 and md5 | |
capture: "parameters", | |
optional: true, | |
constructed: false | |
}] | |
}, { | |
// digest | |
name: "DigestInfo.digest", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.OCTETSTRING, | |
constructed: false, | |
capture: "digest" | |
}] | |
}; | |
var emsaPkcs1v15encode = function(md) { | |
var oid; | |
if (md.algorithm in pki.oids) { | |
oid = pki.oids[md.algorithm]; | |
} else { | |
var error = new Error("Unknown message digest algorithm."); | |
error.algorithm = md.algorithm; | |
throw error; | |
} | |
var oidBytes = asn1.oidToDer(oid).getBytes(); | |
var digestInfo = asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.SEQUENCE, | |
true, | |
[] | |
); | |
var digestAlgorithm = asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.SEQUENCE, | |
true, | |
[] | |
); | |
digestAlgorithm.value.push(asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.OID, | |
false, | |
oidBytes | |
)); | |
digestAlgorithm.value.push(asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.NULL, | |
false, | |
"" | |
)); | |
var digest5 = asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.OCTETSTRING, | |
false, | |
md.digest().getBytes() | |
); | |
digestInfo.value.push(digestAlgorithm); | |
digestInfo.value.push(digest5); | |
return asn1.toDer(digestInfo).getBytes(); | |
}; | |
var _modPow = function(x, key, pub) { | |
if (pub) { | |
return x.modPow(key.e, key.n); | |
} | |
if (!key.p || !key.q) { | |
return x.modPow(key.d, key.n); | |
} | |
if (!key.dP) { | |
key.dP = key.d.mod(key.p.subtract(BigInteger.ONE)); | |
} | |
if (!key.dQ) { | |
key.dQ = key.d.mod(key.q.subtract(BigInteger.ONE)); | |
} | |
if (!key.qInv) { | |
key.qInv = key.q.modInverse(key.p); | |
} | |
var r; | |
do { | |
r = new BigInteger( | |
forge7.util.bytesToHex(forge7.random.getBytes(key.n.bitLength() / 8)), | |
16 | |
); | |
} while (r.compareTo(key.n) >= 0 || !r.gcd(key.n).equals(BigInteger.ONE)); | |
x = x.multiply(r.modPow(key.e, key.n)).mod(key.n); | |
var xp = x.mod(key.p).modPow(key.dP, key.p); | |
var xq = x.mod(key.q).modPow(key.dQ, key.q); | |
while (xp.compareTo(xq) < 0) { | |
xp = xp.add(key.p); | |
} | |
var y = xp.subtract(xq).multiply(key.qInv).mod(key.p).multiply(key.q).add(xq); | |
y = y.multiply(r.modInverse(key.n)).mod(key.n); | |
return y; | |
}; | |
pki.rsa.encrypt = function(m, key, bt) { | |
var pub = bt; | |
var eb; | |
var k = Math.ceil(key.n.bitLength() / 8); | |
if (bt !== false && bt !== true) { | |
pub = bt === 2; | |
eb = _encodePkcs1_v1_5(m, key, bt); | |
} else { | |
eb = forge7.util.createBuffer(); | |
eb.putBytes(m); | |
} | |
var x = new BigInteger(eb.toHex(), 16); | |
var y = _modPow(x, key, pub); | |
var yhex = y.toString(16); | |
var ed = forge7.util.createBuffer(); | |
var zeros = k - Math.ceil(yhex.length / 2); | |
while (zeros > 0) { | |
ed.putByte(0); | |
--zeros; | |
} | |
ed.putBytes(forge7.util.hexToBytes(yhex)); | |
return ed.getBytes(); | |
}; | |
pki.rsa.decrypt = function(ed, key, pub, ml) { | |
var k = Math.ceil(key.n.bitLength() / 8); | |
if (ed.length !== k) { | |
var error = new Error("Encrypted message length is invalid."); | |
error.length = ed.length; | |
error.expected = k; | |
throw error; | |
} | |
var y = new BigInteger(forge7.util.createBuffer(ed).toHex(), 16); | |
if (y.compareTo(key.n) >= 0) { | |
throw new Error("Encrypted message is invalid."); | |
} | |
var x = _modPow(y, key, pub); | |
var xhex = x.toString(16); | |
var eb = forge7.util.createBuffer(); | |
var zeros = k - Math.ceil(xhex.length / 2); | |
while (zeros > 0) { | |
eb.putByte(0); | |
--zeros; | |
} | |
eb.putBytes(forge7.util.hexToBytes(xhex)); | |
if (ml !== false) { | |
return _decodePkcs1_v1_5(eb.getBytes(), key, pub); | |
} | |
return eb.getBytes(); | |
}; | |
pki.rsa.createKeyPairGenerationState = function(bits2, e, options) { | |
if (typeof bits2 === "string") { | |
bits2 = parseInt(bits2, 10); | |
} | |
bits2 = bits2 || 2048; | |
options = options || {}; | |
var prng = options.prng || forge7.random; | |
var rng = { | |
// x is an array to fill with bytes | |
nextBytes: function(x) { | |
var b = prng.getBytesSync(x.length); | |
for (var i = 0; i < x.length; ++i) { | |
x[i] = b.charCodeAt(i); | |
} | |
} | |
}; | |
var algorithm = options.algorithm || "PRIMEINC"; | |
var rval; | |
if (algorithm === "PRIMEINC") { | |
rval = { | |
algorithm, | |
state: 0, | |
bits: bits2, | |
rng, | |
eInt: e || 65537, | |
e: new BigInteger(null), | |
p: null, | |
q: null, | |
qBits: bits2 >> 1, | |
pBits: bits2 - (bits2 >> 1), | |
pqState: 0, | |
num: null, | |
keys: null | |
}; | |
rval.e.fromInt(rval.eInt); | |
} else { | |
throw new Error("Invalid key generation algorithm: " + algorithm); | |
} | |
return rval; | |
}; | |
pki.rsa.stepKeyPairGenerationState = function(state, n) { | |
if (!("algorithm" in state)) { | |
state.algorithm = "PRIMEINC"; | |
} | |
var THIRTY = new BigInteger(null); | |
THIRTY.fromInt(30); | |
var deltaIdx = 0; | |
var op_or = function(x, y) { | |
return x | y; | |
}; | |
var t1 = +/* @__PURE__ */ new Date(); | |
var t2; | |
var total = 0; | |
while (state.keys === null && (n <= 0 || total < n)) { | |
if (state.state === 0) { | |
var bits2 = state.p === null ? state.pBits : state.qBits; | |
var bits1 = bits2 - 1; | |
if (state.pqState === 0) { | |
state.num = new BigInteger(bits2, state.rng); | |
if (!state.num.testBit(bits1)) { | |
state.num.bitwiseTo( | |
BigInteger.ONE.shiftLeft(bits1), | |
op_or, | |
state.num | |
); | |
} | |
state.num.dAddOffset(31 - state.num.mod(THIRTY).byteValue(), 0); | |
deltaIdx = 0; | |
++state.pqState; | |
} else if (state.pqState === 1) { | |
if (state.num.bitLength() > bits2) { | |
state.pqState = 0; | |
} else if (state.num.isProbablePrime( | |
_getMillerRabinTests(state.num.bitLength()) | |
)) { | |
++state.pqState; | |
} else { | |
state.num.dAddOffset(GCD_30_DELTA[deltaIdx++ % 8], 0); | |
} | |
} else if (state.pqState === 2) { | |
state.pqState = state.num.subtract(BigInteger.ONE).gcd(state.e).compareTo(BigInteger.ONE) === 0 ? 3 : 0; | |
} else if (state.pqState === 3) { | |
state.pqState = 0; | |
if (state.p === null) { | |
state.p = state.num; | |
} else { | |
state.q = state.num; | |
} | |
if (state.p !== null && state.q !== null) { | |
++state.state; | |
} | |
state.num = null; | |
} | |
} else if (state.state === 1) { | |
if (state.p.compareTo(state.q) < 0) { | |
state.num = state.p; | |
state.p = state.q; | |
state.q = state.num; | |
} | |
++state.state; | |
} else if (state.state === 2) { | |
state.p1 = state.p.subtract(BigInteger.ONE); | |
state.q1 = state.q.subtract(BigInteger.ONE); | |
state.phi = state.p1.multiply(state.q1); | |
++state.state; | |
} else if (state.state === 3) { | |
if (state.phi.gcd(state.e).compareTo(BigInteger.ONE) === 0) { | |
++state.state; | |
} else { | |
state.p = null; | |
state.q = null; | |
state.state = 0; | |
} | |
} else if (state.state === 4) { | |
state.n = state.p.multiply(state.q); | |
if (state.n.bitLength() === state.bits) { | |
++state.state; | |
} else { | |
state.q = null; | |
state.state = 0; | |
} | |
} else if (state.state === 5) { | |
var d = state.e.modInverse(state.phi); | |
state.keys = { | |
privateKey: pki.rsa.setPrivateKey( | |
state.n, | |
state.e, | |
d, | |
state.p, | |
state.q, | |
d.mod(state.p1), | |
d.mod(state.q1), | |
state.q.modInverse(state.p) | |
), | |
publicKey: pki.rsa.setPublicKey(state.n, state.e) | |
}; | |
} | |
t2 = +/* @__PURE__ */ new Date(); | |
total += t2 - t1; | |
t1 = t2; | |
} | |
return state.keys !== null; | |
}; | |
pki.rsa.generateKeyPair = function(bits2, e, options, callback) { | |
if (arguments.length === 1) { | |
if (typeof bits2 === "object") { | |
options = bits2; | |
bits2 = void 0; | |
} else if (typeof bits2 === "function") { | |
callback = bits2; | |
bits2 = void 0; | |
} | |
} else if (arguments.length === 2) { | |
if (typeof bits2 === "number") { | |
if (typeof e === "function") { | |
callback = e; | |
e = void 0; | |
} else if (typeof e !== "number") { | |
options = e; | |
e = void 0; | |
} | |
} else { | |
options = bits2; | |
callback = e; | |
bits2 = void 0; | |
e = void 0; | |
} | |
} else if (arguments.length === 3) { | |
if (typeof e === "number") { | |
if (typeof options === "function") { | |
callback = options; | |
options = void 0; | |
} | |
} else { | |
callback = options; | |
options = e; | |
e = void 0; | |
} | |
} | |
options = options || {}; | |
if (bits2 === void 0) { | |
bits2 = options.bits || 2048; | |
} | |
if (e === void 0) { | |
e = options.e || 65537; | |
} | |
if (!forge7.options.usePureJavaScript && !options.prng && bits2 >= 256 && bits2 <= 16384 && (e === 65537 || e === 3)) { | |
if (callback) { | |
if (_detectNodeCrypto("generateKeyPair")) { | |
return _crypto.generateKeyPair("rsa", { | |
modulusLength: bits2, | |
publicExponent: e, | |
publicKeyEncoding: { | |
type: "spki", | |
format: "pem" | |
}, | |
privateKeyEncoding: { | |
type: "pkcs8", | |
format: "pem" | |
} | |
}, function(err, pub, priv) { | |
if (err) { | |
return callback(err); | |
} | |
callback(null, { | |
privateKey: pki.privateKeyFromPem(priv), | |
publicKey: pki.publicKeyFromPem(pub) | |
}); | |
}); | |
} | |
if (_detectSubtleCrypto("generateKey") && _detectSubtleCrypto("exportKey")) { | |
return util2.globalScope.crypto.subtle.generateKey({ | |
name: "RSASSA-PKCS1-v1_5", | |
modulusLength: bits2, | |
publicExponent: _intToUint8Array(e), | |
hash: { name: "SHA-256" } | |
}, true, ["sign", "verify"]).then(function(pair2) { | |
return util2.globalScope.crypto.subtle.exportKey( | |
"pkcs8", | |
pair2.privateKey | |
); | |
}).then(void 0, function(err) { | |
callback(err); | |
}).then(function(pkcs8) { | |
if (pkcs8) { | |
var privateKey = pki.privateKeyFromAsn1( | |
asn1.fromDer(forge7.util.createBuffer(pkcs8)) | |
); | |
callback(null, { | |
privateKey, | |
publicKey: pki.setRsaPublicKey(privateKey.n, privateKey.e) | |
}); | |
} | |
}); | |
} | |
if (_detectSubtleMsCrypto("generateKey") && _detectSubtleMsCrypto("exportKey")) { | |
var genOp = util2.globalScope.msCrypto.subtle.generateKey({ | |
name: "RSASSA-PKCS1-v1_5", | |
modulusLength: bits2, | |
publicExponent: _intToUint8Array(e), | |
hash: { name: "SHA-256" } | |
}, true, ["sign", "verify"]); | |
genOp.oncomplete = function(e2) { | |
var pair2 = e2.target.result; | |
var exportOp = util2.globalScope.msCrypto.subtle.exportKey( | |
"pkcs8", | |
pair2.privateKey | |
); | |
exportOp.oncomplete = function(e3) { | |
var pkcs8 = e3.target.result; | |
var privateKey = pki.privateKeyFromAsn1( | |
asn1.fromDer(forge7.util.createBuffer(pkcs8)) | |
); | |
callback(null, { | |
privateKey, | |
publicKey: pki.setRsaPublicKey(privateKey.n, privateKey.e) | |
}); | |
}; | |
exportOp.onerror = function(err) { | |
callback(err); | |
}; | |
}; | |
genOp.onerror = function(err) { | |
callback(err); | |
}; | |
return; | |
} | |
} else { | |
if (_detectNodeCrypto("generateKeyPairSync")) { | |
var keypair = _crypto.generateKeyPairSync("rsa", { | |
modulusLength: bits2, | |
publicExponent: e, | |
publicKeyEncoding: { | |
type: "spki", | |
format: "pem" | |
}, | |
privateKeyEncoding: { | |
type: "pkcs8", | |
format: "pem" | |
} | |
}); | |
return { | |
privateKey: pki.privateKeyFromPem(keypair.privateKey), | |
publicKey: pki.publicKeyFromPem(keypair.publicKey) | |
}; | |
} | |
} | |
} | |
var state = pki.rsa.createKeyPairGenerationState(bits2, e, options); | |
if (!callback) { | |
pki.rsa.stepKeyPairGenerationState(state, 0); | |
return state.keys; | |
} | |
_generateKeyPair(state, options, callback); | |
}; | |
pki.setRsaPublicKey = pki.rsa.setPublicKey = function(n, e) { | |
var key = { | |
n, | |
e | |
}; | |
key.encrypt = function(data, scheme, schemeOptions) { | |
if (typeof scheme === "string") { | |
scheme = scheme.toUpperCase(); | |
} else if (scheme === void 0) { | |
scheme = "RSAES-PKCS1-V1_5"; | |
} | |
if (scheme === "RSAES-PKCS1-V1_5") { | |
scheme = { | |
encode: function(m, key2, pub) { | |
return _encodePkcs1_v1_5(m, key2, 2).getBytes(); | |
} | |
}; | |
} else if (scheme === "RSA-OAEP" || scheme === "RSAES-OAEP") { | |
scheme = { | |
encode: function(m, key2) { | |
return forge7.pkcs1.encode_rsa_oaep(key2, m, schemeOptions); | |
} | |
}; | |
} else if (["RAW", "NONE", "NULL", null].indexOf(scheme) !== -1) { | |
scheme = { encode: function(e3) { | |
return e3; | |
} }; | |
} else if (typeof scheme === "string") { | |
throw new Error('Unsupported encryption scheme: "' + scheme + '".'); | |
} | |
var e2 = scheme.encode(data, key, true); | |
return pki.rsa.encrypt(e2, key, true); | |
}; | |
key.verify = function(digest5, signature, scheme, options) { | |
if (typeof scheme === "string") { | |
scheme = scheme.toUpperCase(); | |
} else if (scheme === void 0) { | |
scheme = "RSASSA-PKCS1-V1_5"; | |
} | |
if (options === void 0) { | |
options = { | |
_parseAllDigestBytes: true | |
}; | |
} | |
if (!("_parseAllDigestBytes" in options)) { | |
options._parseAllDigestBytes = true; | |
} | |
if (scheme === "RSASSA-PKCS1-V1_5") { | |
scheme = { | |
verify: function(digest6, d2) { | |
d2 = _decodePkcs1_v1_5(d2, key, true); | |
var obj = asn1.fromDer(d2, { | |
parseAllBytes: options._parseAllDigestBytes | |
}); | |
var capture = {}; | |
var errors = []; | |
if (!asn1.validate(obj, digestInfoValidator, capture, errors)) { | |
var error = new Error( | |
"ASN.1 object does not contain a valid RSASSA-PKCS1-v1_5 DigestInfo value." | |
); | |
error.errors = errors; | |
throw error; | |
} | |
var oid = asn1.derToOid(capture.algorithmIdentifier); | |
if (!(oid === forge7.oids.md2 || oid === forge7.oids.md5 || oid === forge7.oids.sha1 || oid === forge7.oids.sha224 || oid === forge7.oids.sha256 || oid === forge7.oids.sha384 || oid === forge7.oids.sha512 || oid === forge7.oids["sha512-224"] || oid === forge7.oids["sha512-256"])) { | |
var error = new Error( | |
"Unknown RSASSA-PKCS1-v1_5 DigestAlgorithm identifier." | |
); | |
error.oid = oid; | |
throw error; | |
} | |
if (oid === forge7.oids.md2 || oid === forge7.oids.md5) { | |
if (!("parameters" in capture)) { | |
throw new Error( | |
"ASN.1 object does not contain a valid RSASSA-PKCS1-v1_5 DigestInfo value. Missing algorithm identifer NULL parameters." | |
); | |
} | |
} | |
return digest6 === capture.digest; | |
} | |
}; | |
} else if (scheme === "NONE" || scheme === "NULL" || scheme === null) { | |
scheme = { | |
verify: function(digest6, d2) { | |
d2 = _decodePkcs1_v1_5(d2, key, true); | |
return digest6 === d2; | |
} | |
}; | |
} | |
var d = pki.rsa.decrypt(signature, key, true, false); | |
return scheme.verify(digest5, d, key.n.bitLength()); | |
}; | |
return key; | |
}; | |
pki.setRsaPrivateKey = pki.rsa.setPrivateKey = function(n, e, d, p, q, dP, dQ, qInv) { | |
var key = { | |
n, | |
e, | |
d, | |
p, | |
q, | |
dP, | |
dQ, | |
qInv | |
}; | |
key.decrypt = function(data, scheme, schemeOptions) { | |
if (typeof scheme === "string") { | |
scheme = scheme.toUpperCase(); | |
} else if (scheme === void 0) { | |
scheme = "RSAES-PKCS1-V1_5"; | |
} | |
var d2 = pki.rsa.decrypt(data, key, false, false); | |
if (scheme === "RSAES-PKCS1-V1_5") { | |
scheme = { decode: _decodePkcs1_v1_5 }; | |
} else if (scheme === "RSA-OAEP" || scheme === "RSAES-OAEP") { | |
scheme = { | |
decode: function(d3, key2) { | |
return forge7.pkcs1.decode_rsa_oaep(key2, d3, schemeOptions); | |
} | |
}; | |
} else if (["RAW", "NONE", "NULL", null].indexOf(scheme) !== -1) { | |
scheme = { decode: function(d3) { | |
return d3; | |
} }; | |
} else { | |
throw new Error('Unsupported encryption scheme: "' + scheme + '".'); | |
} | |
return scheme.decode(d2, key, false); | |
}; | |
key.sign = function(md, scheme) { | |
var bt = false; | |
if (typeof scheme === "string") { | |
scheme = scheme.toUpperCase(); | |
} | |
if (scheme === void 0 || scheme === "RSASSA-PKCS1-V1_5") { | |
scheme = { encode: emsaPkcs1v15encode }; | |
bt = 1; | |
} else if (scheme === "NONE" || scheme === "NULL" || scheme === null) { | |
scheme = { encode: function() { | |
return md; | |
} }; | |
bt = 1; | |
} | |
var d2 = scheme.encode(md, key.n.bitLength()); | |
return pki.rsa.encrypt(d2, key, bt); | |
}; | |
return key; | |
}; | |
pki.wrapRsaPrivateKey = function(rsaKey) { | |
return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [ | |
// version (0) | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.INTEGER, | |
false, | |
asn1.integerToDer(0).getBytes() | |
), | |
// privateKeyAlgorithm | |
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [ | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.OID, | |
false, | |
asn1.oidToDer(pki.oids.rsaEncryption).getBytes() | |
), | |
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, "") | |
]), | |
// PrivateKey | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.OCTETSTRING, | |
false, | |
asn1.toDer(rsaKey).getBytes() | |
) | |
]); | |
}; | |
pki.privateKeyFromAsn1 = function(obj) { | |
var capture = {}; | |
var errors = []; | |
if (asn1.validate(obj, privateKeyValidator, capture, errors)) { | |
obj = asn1.fromDer(forge7.util.createBuffer(capture.privateKey)); | |
} | |
capture = {}; | |
errors = []; | |
if (!asn1.validate(obj, rsaPrivateKeyValidator, capture, errors)) { | |
var error = new Error("Cannot read private key. ASN.1 object does not contain an RSAPrivateKey."); | |
error.errors = errors; | |
throw error; | |
} | |
var n, e, d, p, q, dP, dQ, qInv; | |
n = forge7.util.createBuffer(capture.privateKeyModulus).toHex(); | |
e = forge7.util.createBuffer(capture.privateKeyPublicExponent).toHex(); | |
d = forge7.util.createBuffer(capture.privateKeyPrivateExponent).toHex(); | |
p = forge7.util.createBuffer(capture.privateKeyPrime1).toHex(); | |
q = forge7.util.createBuffer(capture.privateKeyPrime2).toHex(); | |
dP = forge7.util.createBuffer(capture.privateKeyExponent1).toHex(); | |
dQ = forge7.util.createBuffer(capture.privateKeyExponent2).toHex(); | |
qInv = forge7.util.createBuffer(capture.privateKeyCoefficient).toHex(); | |
return pki.setRsaPrivateKey( | |
new BigInteger(n, 16), | |
new BigInteger(e, 16), | |
new BigInteger(d, 16), | |
new BigInteger(p, 16), | |
new BigInteger(q, 16), | |
new BigInteger(dP, 16), | |
new BigInteger(dQ, 16), | |
new BigInteger(qInv, 16) | |
); | |
}; | |
pki.privateKeyToAsn1 = pki.privateKeyToRSAPrivateKey = function(key) { | |
return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [ | |
// version (0 = only 2 primes, 1 multiple primes) | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.INTEGER, | |
false, | |
asn1.integerToDer(0).getBytes() | |
), | |
// modulus (n) | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.INTEGER, | |
false, | |
_bnToBytes(key.n) | |
), | |
// publicExponent (e) | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.INTEGER, | |
false, | |
_bnToBytes(key.e) | |
), | |
// privateExponent (d) | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.INTEGER, | |
false, | |
_bnToBytes(key.d) | |
), | |
// privateKeyPrime1 (p) | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.INTEGER, | |
false, | |
_bnToBytes(key.p) | |
), | |
// privateKeyPrime2 (q) | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.INTEGER, | |
false, | |
_bnToBytes(key.q) | |
), | |
// privateKeyExponent1 (dP) | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.INTEGER, | |
false, | |
_bnToBytes(key.dP) | |
), | |
// privateKeyExponent2 (dQ) | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.INTEGER, | |
false, | |
_bnToBytes(key.dQ) | |
), | |
// coefficient (qInv) | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.INTEGER, | |
false, | |
_bnToBytes(key.qInv) | |
) | |
]); | |
}; | |
pki.publicKeyFromAsn1 = function(obj) { | |
var capture = {}; | |
var errors = []; | |
if (asn1.validate(obj, publicKeyValidator, capture, errors)) { | |
var oid = asn1.derToOid(capture.publicKeyOid); | |
if (oid !== pki.oids.rsaEncryption) { | |
var error = new Error("Cannot read public key. Unknown OID."); | |
error.oid = oid; | |
throw error; | |
} | |
obj = capture.rsaPublicKey; | |
} | |
errors = []; | |
if (!asn1.validate(obj, rsaPublicKeyValidator, capture, errors)) { | |
var error = new Error("Cannot read public key. ASN.1 object does not contain an RSAPublicKey."); | |
error.errors = errors; | |
throw error; | |
} | |
var n = forge7.util.createBuffer(capture.publicKeyModulus).toHex(); | |
var e = forge7.util.createBuffer(capture.publicKeyExponent).toHex(); | |
return pki.setRsaPublicKey( | |
new BigInteger(n, 16), | |
new BigInteger(e, 16) | |
); | |
}; | |
pki.publicKeyToAsn1 = pki.publicKeyToSubjectPublicKeyInfo = function(key) { | |
return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [ | |
// AlgorithmIdentifier | |
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [ | |
// algorithm | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.OID, | |
false, | |
asn1.oidToDer(pki.oids.rsaEncryption).getBytes() | |
), | |
// parameters (null) | |
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, "") | |
]), | |
// subjectPublicKey | |
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.BITSTRING, false, [ | |
pki.publicKeyToRSAPublicKey(key) | |
]) | |
]); | |
}; | |
pki.publicKeyToRSAPublicKey = function(key) { | |
return asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [ | |
// modulus (n) | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.INTEGER, | |
false, | |
_bnToBytes(key.n) | |
), | |
// publicExponent (e) | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.INTEGER, | |
false, | |
_bnToBytes(key.e) | |
) | |
]); | |
}; | |
function _encodePkcs1_v1_5(m, key, bt) { | |
var eb = forge7.util.createBuffer(); | |
var k = Math.ceil(key.n.bitLength() / 8); | |
if (m.length > k - 11) { | |
var error = new Error("Message is too long for PKCS#1 v1.5 padding."); | |
error.length = m.length; | |
error.max = k - 11; | |
throw error; | |
} | |
eb.putByte(0); | |
eb.putByte(bt); | |
var padNum = k - 3 - m.length; | |
var padByte; | |
if (bt === 0 || bt === 1) { | |
padByte = bt === 0 ? 0 : 255; | |
for (var i = 0; i < padNum; ++i) { | |
eb.putByte(padByte); | |
} | |
} else { | |
while (padNum > 0) { | |
var numZeros = 0; | |
var padBytes = forge7.random.getBytes(padNum); | |
for (var i = 0; i < padNum; ++i) { | |
padByte = padBytes.charCodeAt(i); | |
if (padByte === 0) { | |
++numZeros; | |
} else { | |
eb.putByte(padByte); | |
} | |
} | |
padNum = numZeros; | |
} | |
} | |
eb.putByte(0); | |
eb.putBytes(m); | |
return eb; | |
} | |
function _decodePkcs1_v1_5(em, key, pub, ml) { | |
var k = Math.ceil(key.n.bitLength() / 8); | |
var eb = forge7.util.createBuffer(em); | |
var first2 = eb.getByte(); | |
var bt = eb.getByte(); | |
if (first2 !== 0 || pub && bt !== 0 && bt !== 1 || !pub && bt != 2 || pub && bt === 0 && typeof ml === "undefined") { | |
throw new Error("Encryption block is invalid."); | |
} | |
var padNum = 0; | |
if (bt === 0) { | |
padNum = k - 3 - ml; | |
for (var i = 0; i < padNum; ++i) { | |
if (eb.getByte() !== 0) { | |
throw new Error("Encryption block is invalid."); | |
} | |
} | |
} else if (bt === 1) { | |
padNum = 0; | |
while (eb.length() > 1) { | |
if (eb.getByte() !== 255) { | |
--eb.read; | |
break; | |
} | |
++padNum; | |
} | |
} else if (bt === 2) { | |
padNum = 0; | |
while (eb.length() > 1) { | |
if (eb.getByte() === 0) { | |
--eb.read; | |
break; | |
} | |
++padNum; | |
} | |
} | |
var zero = eb.getByte(); | |
if (zero !== 0 || padNum !== k - 3 - eb.length()) { | |
throw new Error("Encryption block is invalid."); | |
} | |
return eb.getBytes(); | |
} | |
function _generateKeyPair(state, options, callback) { | |
if (typeof options === "function") { | |
callback = options; | |
options = {}; | |
} | |
options = options || {}; | |
var opts = { | |
algorithm: { | |
name: options.algorithm || "PRIMEINC", | |
options: { | |
workers: options.workers || 2, | |
workLoad: options.workLoad || 100, | |
workerScript: options.workerScript | |
} | |
} | |
}; | |
if ("prng" in options) { | |
opts.prng = options.prng; | |
} | |
generate(); | |
function generate() { | |
getPrime(state.pBits, function(err, num) { | |
if (err) { | |
return callback(err); | |
} | |
state.p = num; | |
if (state.q !== null) { | |
return finish(err, state.q); | |
} | |
getPrime(state.qBits, finish); | |
}); | |
} | |
function getPrime(bits2, callback2) { | |
forge7.prime.generateProbablePrime(bits2, opts, callback2); | |
} | |
function finish(err, num) { | |
if (err) { | |
return callback(err); | |
} | |
state.q = num; | |
if (state.p.compareTo(state.q) < 0) { | |
var tmp = state.p; | |
state.p = state.q; | |
state.q = tmp; | |
} | |
if (state.p.subtract(BigInteger.ONE).gcd(state.e).compareTo(BigInteger.ONE) !== 0) { | |
state.p = null; | |
generate(); | |
return; | |
} | |
if (state.q.subtract(BigInteger.ONE).gcd(state.e).compareTo(BigInteger.ONE) !== 0) { | |
state.q = null; | |
getPrime(state.qBits, finish); | |
return; | |
} | |
state.p1 = state.p.subtract(BigInteger.ONE); | |
state.q1 = state.q.subtract(BigInteger.ONE); | |
state.phi = state.p1.multiply(state.q1); | |
if (state.phi.gcd(state.e).compareTo(BigInteger.ONE) !== 0) { | |
state.p = state.q = null; | |
generate(); | |
return; | |
} | |
state.n = state.p.multiply(state.q); | |
if (state.n.bitLength() !== state.bits) { | |
state.q = null; | |
getPrime(state.qBits, finish); | |
return; | |
} | |
var d = state.e.modInverse(state.phi); | |
state.keys = { | |
privateKey: pki.rsa.setPrivateKey( | |
state.n, | |
state.e, | |
d, | |
state.p, | |
state.q, | |
d.mod(state.p1), | |
d.mod(state.q1), | |
state.q.modInverse(state.p) | |
), | |
publicKey: pki.rsa.setPublicKey(state.n, state.e) | |
}; | |
callback(null, state.keys); | |
} | |
} | |
function _bnToBytes(b) { | |
var hex = b.toString(16); | |
if (hex[0] >= "8") { | |
hex = "00" + hex; | |
} | |
var bytes3 = forge7.util.hexToBytes(hex); | |
if (bytes3.length > 1 && // leading 0x00 for positive integer | |
(bytes3.charCodeAt(0) === 0 && (bytes3.charCodeAt(1) & 128) === 0 || // leading 0xFF for negative integer | |
bytes3.charCodeAt(0) === 255 && (bytes3.charCodeAt(1) & 128) === 128)) { | |
return bytes3.substr(1); | |
} | |
return bytes3; | |
} | |
function _getMillerRabinTests(bits2) { | |
if (bits2 <= 100) | |
return 27; | |
if (bits2 <= 150) | |
return 18; | |
if (bits2 <= 200) | |
return 15; | |
if (bits2 <= 250) | |
return 12; | |
if (bits2 <= 300) | |
return 9; | |
if (bits2 <= 350) | |
return 8; | |
if (bits2 <= 400) | |
return 7; | |
if (bits2 <= 500) | |
return 6; | |
if (bits2 <= 600) | |
return 5; | |
if (bits2 <= 800) | |
return 4; | |
if (bits2 <= 1250) | |
return 3; | |
return 2; | |
} | |
function _detectNodeCrypto(fn) { | |
return forge7.util.isNodejs && typeof _crypto[fn] === "function"; | |
} | |
function _detectSubtleCrypto(fn) { | |
return typeof util2.globalScope !== "undefined" && typeof util2.globalScope.crypto === "object" && typeof util2.globalScope.crypto.subtle === "object" && typeof util2.globalScope.crypto.subtle[fn] === "function"; | |
} | |
function _detectSubtleMsCrypto(fn) { | |
return typeof util2.globalScope !== "undefined" && typeof util2.globalScope.msCrypto === "object" && typeof util2.globalScope.msCrypto.subtle === "object" && typeof util2.globalScope.msCrypto.subtle[fn] === "function"; | |
} | |
function _intToUint8Array(x) { | |
var bytes3 = forge7.util.hexToBytes(x.toString(16)); | |
var buffer3 = new Uint8Array(bytes3.length); | |
for (var i = 0; i < bytes3.length; ++i) { | |
buffer3[i] = bytes3.charCodeAt(i); | |
} | |
return buffer3; | |
} | |
} | |
}); | |
// node_modules/node-forge/lib/pbe.js | |
var require_pbe = __commonJS({ | |
"node_modules/node-forge/lib/pbe.js"(exports2, module2) { | |
var forge7 = require_forge(); | |
require_aes(); | |
require_asn1(); | |
require_des(); | |
require_md(); | |
require_oids(); | |
require_pbkdf2(); | |
require_pem(); | |
require_random(); | |
require_rc2(); | |
require_rsa(); | |
require_util(); | |
if (typeof BigInteger === "undefined") { | |
BigInteger = forge7.jsbn.BigInteger; | |
} | |
var BigInteger; | |
var asn1 = forge7.asn1; | |
var pki = forge7.pki = forge7.pki || {}; | |
module2.exports = pki.pbe = forge7.pbe = forge7.pbe || {}; | |
var oids = pki.oids; | |
var encryptedPrivateKeyValidator = { | |
name: "EncryptedPrivateKeyInfo", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.SEQUENCE, | |
constructed: true, | |
value: [{ | |
name: "EncryptedPrivateKeyInfo.encryptionAlgorithm", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.SEQUENCE, | |
constructed: true, | |
value: [{ | |
name: "AlgorithmIdentifier.algorithm", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.OID, | |
constructed: false, | |
capture: "encryptionOid" | |
}, { | |
name: "AlgorithmIdentifier.parameters", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.SEQUENCE, | |
constructed: true, | |
captureAsn1: "encryptionParams" | |
}] | |
}, { | |
// encryptedData | |
name: "EncryptedPrivateKeyInfo.encryptedData", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.OCTETSTRING, | |
constructed: false, | |
capture: "encryptedData" | |
}] | |
}; | |
var PBES2AlgorithmsValidator = { | |
name: "PBES2Algorithms", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.SEQUENCE, | |
constructed: true, | |
value: [{ | |
name: "PBES2Algorithms.keyDerivationFunc", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.SEQUENCE, | |
constructed: true, | |
value: [{ | |
name: "PBES2Algorithms.keyDerivationFunc.oid", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.OID, | |
constructed: false, | |
capture: "kdfOid" | |
}, { | |
name: "PBES2Algorithms.params", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.SEQUENCE, | |
constructed: true, | |
value: [{ | |
name: "PBES2Algorithms.params.salt", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.OCTETSTRING, | |
constructed: false, | |
capture: "kdfSalt" | |
}, { | |
name: "PBES2Algorithms.params.iterationCount", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.INTEGER, | |
constructed: false, | |
capture: "kdfIterationCount" | |
}, { | |
name: "PBES2Algorithms.params.keyLength", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.INTEGER, | |
constructed: false, | |
optional: true, | |
capture: "keyLength" | |
}, { | |
// prf | |
name: "PBES2Algorithms.params.prf", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.SEQUENCE, | |
constructed: true, | |
optional: true, | |
value: [{ | |
name: "PBES2Algorithms.params.prf.algorithm", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.OID, | |
constructed: false, | |
capture: "prfOid" | |
}] | |
}] | |
}] | |
}, { | |
name: "PBES2Algorithms.encryptionScheme", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.SEQUENCE, | |
constructed: true, | |
value: [{ | |
name: "PBES2Algorithms.encryptionScheme.oid", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.OID, | |
constructed: false, | |
capture: "encOid" | |
}, { | |
name: "PBES2Algorithms.encryptionScheme.iv", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.OCTETSTRING, | |
constructed: false, | |
capture: "encIv" | |
}] | |
}] | |
}; | |
var pkcs12PbeParamsValidator = { | |
name: "pkcs-12PbeParams", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.SEQUENCE, | |
constructed: true, | |
value: [{ | |
name: "pkcs-12PbeParams.salt", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.OCTETSTRING, | |
constructed: false, | |
capture: "salt" | |
}, { | |
name: "pkcs-12PbeParams.iterations", | |
tagClass: asn1.Class.UNIVERSAL, | |
type: asn1.Type.INTEGER, | |
constructed: false, | |
capture: "iterations" | |
}] | |
}; | |
pki.encryptPrivateKeyInfo = function(obj, password, options) { | |
options = options || {}; | |
options.saltSize = options.saltSize || 8; | |
options.count = options.count || 2048; | |
options.algorithm = options.algorithm || "aes128"; | |
options.prfAlgorithm = options.prfAlgorithm || "sha1"; | |
var salt = forge7.random.getBytesSync(options.saltSize); | |
var count = options.count; | |
var countBytes = asn1.integerToDer(count); | |
var dkLen; | |
var encryptionAlgorithm; | |
var encryptedData; | |
if (options.algorithm.indexOf("aes") === 0 || options.algorithm === "des") { | |
var ivLen, encOid, cipherFn; | |
switch (options.algorithm) { | |
case "aes128": | |
dkLen = 16; | |
ivLen = 16; | |
encOid = oids["aes128-CBC"]; | |
cipherFn = forge7.aes.createEncryptionCipher; | |
break; | |
case "aes192": | |
dkLen = 24; | |
ivLen = 16; | |
encOid = oids["aes192-CBC"]; | |
cipherFn = forge7.aes.createEncryptionCipher; | |
break; | |
case "aes256": | |
dkLen = 32; | |
ivLen = 16; | |
encOid = oids["aes256-CBC"]; | |
cipherFn = forge7.aes.createEncryptionCipher; | |
break; | |
case "des": | |
dkLen = 8; | |
ivLen = 8; | |
encOid = oids["desCBC"]; | |
cipherFn = forge7.des.createEncryptionCipher; | |
break; | |
default: | |
var error = new Error("Cannot encrypt private key. Unknown encryption algorithm."); | |
error.algorithm = options.algorithm; | |
throw error; | |
} | |
var prfAlgorithm = "hmacWith" + options.prfAlgorithm.toUpperCase(); | |
var md = prfAlgorithmToMessageDigest(prfAlgorithm); | |
var dk = forge7.pkcs5.pbkdf2(password, salt, count, dkLen, md); | |
var iv = forge7.random.getBytesSync(ivLen); | |
var cipher = cipherFn(dk); | |
cipher.start(iv); | |
cipher.update(asn1.toDer(obj)); | |
cipher.finish(); | |
encryptedData = cipher.output.getBytes(); | |
var params = createPbkdf2Params(salt, countBytes, dkLen, prfAlgorithm); | |
encryptionAlgorithm = asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.SEQUENCE, | |
true, | |
[ | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.OID, | |
false, | |
asn1.oidToDer(oids["pkcs5PBES2"]).getBytes() | |
), | |
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [ | |
// keyDerivationFunc | |
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [ | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.OID, | |
false, | |
asn1.oidToDer(oids["pkcs5PBKDF2"]).getBytes() | |
), | |
// PBKDF2-params | |
params | |
]), | |
// encryptionScheme | |
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [ | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.OID, | |
false, | |
asn1.oidToDer(encOid).getBytes() | |
), | |
// iv | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.OCTETSTRING, | |
false, | |
iv | |
) | |
]) | |
]) | |
] | |
); | |
} else if (options.algorithm === "3des") { | |
dkLen = 24; | |
var saltBytes = new forge7.util.ByteBuffer(salt); | |
var dk = pki.pbe.generatePkcs12Key(password, saltBytes, 1, count, dkLen); | |
var iv = pki.pbe.generatePkcs12Key(password, saltBytes, 2, count, dkLen); | |
var cipher = forge7.des.createEncryptionCipher(dk); | |
cipher.start(iv); | |
cipher.update(asn1.toDer(obj)); | |
cipher.finish(); | |
encryptedData = cipher.output.getBytes(); | |
encryptionAlgorithm = asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.SEQUENCE, | |
true, | |
[ | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.OID, | |
false, | |
asn1.oidToDer(oids["pbeWithSHAAnd3-KeyTripleDES-CBC"]).getBytes() | |
), | |
// pkcs-12PbeParams | |
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [ | |
// salt | |
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.OCTETSTRING, false, salt), | |
// iteration count | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.INTEGER, | |
false, | |
countBytes.getBytes() | |
) | |
]) | |
] | |
); | |
} else { | |
var error = new Error("Cannot encrypt private key. Unknown encryption algorithm."); | |
error.algorithm = options.algorithm; | |
throw error; | |
} | |
var rval = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [ | |
// encryptionAlgorithm | |
encryptionAlgorithm, | |
// encryptedData | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.OCTETSTRING, | |
false, | |
encryptedData | |
) | |
]); | |
return rval; | |
}; | |
pki.decryptPrivateKeyInfo = function(obj, password) { | |
var rval = null; | |
var capture = {}; | |
var errors = []; | |
if (!asn1.validate(obj, encryptedPrivateKeyValidator, capture, errors)) { | |
var error = new Error("Cannot read encrypted private key. ASN.1 object is not a supported EncryptedPrivateKeyInfo."); | |
error.errors = errors; | |
throw error; | |
} | |
var oid = asn1.derToOid(capture.encryptionOid); | |
var cipher = pki.pbe.getCipher(oid, capture.encryptionParams, password); | |
var encrypted = forge7.util.createBuffer(capture.encryptedData); | |
cipher.update(encrypted); | |
if (cipher.finish()) { | |
rval = asn1.fromDer(cipher.output); | |
} | |
return rval; | |
}; | |
pki.encryptedPrivateKeyToPem = function(epki, maxline) { | |
var msg = { | |
type: "ENCRYPTED PRIVATE KEY", | |
body: asn1.toDer(epki).getBytes() | |
}; | |
return forge7.pem.encode(msg, { maxline }); | |
}; | |
pki.encryptedPrivateKeyFromPem = function(pem) { | |
var msg = forge7.pem.decode(pem)[0]; | |
if (msg.type !== "ENCRYPTED PRIVATE KEY") { | |
var error = new Error('Could not convert encrypted private key from PEM; PEM header type is "ENCRYPTED PRIVATE KEY".'); | |
error.headerType = msg.type; | |
throw error; | |
} | |
if (msg.procType && msg.procType.type === "ENCRYPTED") { | |
throw new Error("Could not convert encrypted private key from PEM; PEM is encrypted."); | |
} | |
return asn1.fromDer(msg.body); | |
}; | |
pki.encryptRsaPrivateKey = function(rsaKey, password, options) { | |
options = options || {}; | |
if (!options.legacy) { | |
var rval = pki.wrapRsaPrivateKey(pki.privateKeyToAsn1(rsaKey)); | |
rval = pki.encryptPrivateKeyInfo(rval, password, options); | |
return pki.encryptedPrivateKeyToPem(rval); | |
} | |
var algorithm; | |
var iv; | |
var dkLen; | |
var cipherFn; | |
switch (options.algorithm) { | |
case "aes128": | |
algorithm = "AES-128-CBC"; | |
dkLen = 16; | |
iv = forge7.random.getBytesSync(16); | |
cipherFn = forge7.aes.createEncryptionCipher; | |
break; | |
case "aes192": | |
algorithm = "AES-192-CBC"; | |
dkLen = 24; | |
iv = forge7.random.getBytesSync(16); | |
cipherFn = forge7.aes.createEncryptionCipher; | |
break; | |
case "aes256": | |
algorithm = "AES-256-CBC"; | |
dkLen = 32; | |
iv = forge7.random.getBytesSync(16); | |
cipherFn = forge7.aes.createEncryptionCipher; | |
break; | |
case "3des": | |
algorithm = "DES-EDE3-CBC"; | |
dkLen = 24; | |
iv = forge7.random.getBytesSync(8); | |
cipherFn = forge7.des.createEncryptionCipher; | |
break; | |
case "des": | |
algorithm = "DES-CBC"; | |
dkLen = 8; | |
iv = forge7.random.getBytesSync(8); | |
cipherFn = forge7.des.createEncryptionCipher; | |
break; | |
default: | |
var error = new Error('Could not encrypt RSA private key; unsupported encryption algorithm "' + options.algorithm + '".'); | |
error.algorithm = options.algorithm; | |
throw error; | |
} | |
var dk = forge7.pbe.opensslDeriveBytes(password, iv.substr(0, 8), dkLen); | |
var cipher = cipherFn(dk); | |
cipher.start(iv); | |
cipher.update(asn1.toDer(pki.privateKeyToAsn1(rsaKey))); | |
cipher.finish(); | |
var msg = { | |
type: "RSA PRIVATE KEY", | |
procType: { | |
version: "4", | |
type: "ENCRYPTED" | |
}, | |
dekInfo: { | |
algorithm, | |
parameters: forge7.util.bytesToHex(iv).toUpperCase() | |
}, | |
body: cipher.output.getBytes() | |
}; | |
return forge7.pem.encode(msg); | |
}; | |
pki.decryptRsaPrivateKey = function(pem, password) { | |
var rval = null; | |
var msg = forge7.pem.decode(pem)[0]; | |
if (msg.type !== "ENCRYPTED PRIVATE KEY" && msg.type !== "PRIVATE KEY" && msg.type !== "RSA PRIVATE KEY") { | |
var error = new Error('Could not convert private key from PEM; PEM header type is not "ENCRYPTED PRIVATE KEY", "PRIVATE KEY", or "RSA PRIVATE KEY".'); | |
error.headerType = error; | |
throw error; | |
} | |
if (msg.procType && msg.procType.type === "ENCRYPTED") { | |
var dkLen; | |
var cipherFn; | |
switch (msg.dekInfo.algorithm) { | |
case "DES-CBC": | |
dkLen = 8; | |
cipherFn = forge7.des.createDecryptionCipher; | |
break; | |
case "DES-EDE3-CBC": | |
dkLen = 24; | |
cipherFn = forge7.des.createDecryptionCipher; | |
break; | |
case "AES-128-CBC": | |
dkLen = 16; | |
cipherFn = forge7.aes.createDecryptionCipher; | |
break; | |
case "AES-192-CBC": | |
dkLen = 24; | |
cipherFn = forge7.aes.createDecryptionCipher; | |
break; | |
case "AES-256-CBC": | |
dkLen = 32; | |
cipherFn = forge7.aes.createDecryptionCipher; | |
break; | |
case "RC2-40-CBC": | |
dkLen = 5; | |
cipherFn = function(key) { | |
return forge7.rc2.createDecryptionCipher(key, 40); | |
}; | |
break; | |
case "RC2-64-CBC": | |
dkLen = 8; | |
cipherFn = function(key) { | |
return forge7.rc2.createDecryptionCipher(key, 64); | |
}; | |
break; | |
case "RC2-128-CBC": | |
dkLen = 16; | |
cipherFn = function(key) { | |
return forge7.rc2.createDecryptionCipher(key, 128); | |
}; | |
break; | |
default: | |
var error = new Error('Could not decrypt private key; unsupported encryption algorithm "' + msg.dekInfo.algorithm + '".'); | |
error.algorithm = msg.dekInfo.algorithm; | |
throw error; | |
} | |
var iv = forge7.util.hexToBytes(msg.dekInfo.parameters); | |
var dk = forge7.pbe.opensslDeriveBytes(password, iv.substr(0, 8), dkLen); | |
var cipher = cipherFn(dk); | |
cipher.start(iv); | |
cipher.update(forge7.util.createBuffer(msg.body)); | |
if (cipher.finish()) { | |
rval = cipher.output.getBytes(); | |
} else { | |
return rval; | |
} | |
} else { | |
rval = msg.body; | |
} | |
if (msg.type === "ENCRYPTED PRIVATE KEY") { | |
rval = pki.decryptPrivateKeyInfo(asn1.fromDer(rval), password); | |
} else { | |
rval = asn1.fromDer(rval); | |
} | |
if (rval !== null) { | |
rval = pki.privateKeyFromAsn1(rval); | |
} | |
return rval; | |
}; | |
pki.pbe.generatePkcs12Key = function(password, salt, id, iter, n, md) { | |
var j, l; | |
if (typeof md === "undefined" || md === null) { | |
if (!("sha1" in forge7.md)) { | |
throw new Error('"sha1" hash algorithm unavailable.'); | |
} | |
md = forge7.md.sha1.create(); | |
} | |
var u = md.digestLength; | |
var v = md.blockLength; | |
var result = new forge7.util.ByteBuffer(); | |
var passBuf = new forge7.util.ByteBuffer(); | |
if (password !== null && password !== void 0) { | |
for (l = 0; l < password.length; l++) { | |
passBuf.putInt16(password.charCodeAt(l)); | |
} | |
passBuf.putInt16(0); | |
} | |
var p = passBuf.length(); | |
var s = salt.length(); | |
var D = new forge7.util.ByteBuffer(); | |
D.fillWithByte(id, v); | |
var Slen = v * Math.ceil(s / v); | |
var S = new forge7.util.ByteBuffer(); | |
for (l = 0; l < Slen; l++) { | |
S.putByte(salt.at(l % s)); | |
} | |
var Plen = v * Math.ceil(p / v); | |
var P = new forge7.util.ByteBuffer(); | |
for (l = 0; l < Plen; l++) { | |
P.putByte(passBuf.at(l % p)); | |
} | |
var I = S; | |
I.putBuffer(P); | |
var c = Math.ceil(n / u); | |
for (var i = 1; i <= c; i++) { | |
var buf3 = new forge7.util.ByteBuffer(); | |
buf3.putBytes(D.bytes()); | |
buf3.putBytes(I.bytes()); | |
for (var round = 0; round < iter; round++) { | |
md.start(); | |
md.update(buf3.getBytes()); | |
buf3 = md.digest(); | |
} | |
var B = new forge7.util.ByteBuffer(); | |
for (l = 0; l < v; l++) { | |
B.putByte(buf3.at(l % u)); | |
} | |
var k = Math.ceil(s / v) + Math.ceil(p / v); | |
var Inew = new forge7.util.ByteBuffer(); | |
for (j = 0; j < k; j++) { | |
var chunk = new forge7.util.ByteBuffer(I.getBytes(v)); | |
var x = 511; | |
for (l = B.length() - 1; l >= 0; l--) { | |
x = x >> 8; | |
x += B.at(l) + chunk.at(l); | |
chunk.setAt(l, x & 255); | |
} | |
Inew.putBuffer(chunk); | |
} | |
I = Inew; | |
result.putBuffer(buf3); | |
} | |
result.truncate(result.length() - n); | |
return result; | |
}; | |
pki.pbe.getCipher = function(oid, params, password) { | |
switch (oid) { | |
case pki.oids["pkcs5PBES2"]: | |
return pki.pbe.getCipherForPBES2(oid, params, password); | |
case pki.oids["pbeWithSHAAnd3-KeyTripleDES-CBC"]: | |
case pki.oids["pbewithSHAAnd40BitRC2-CBC"]: | |
return pki.pbe.getCipherForPKCS12PBE(oid, params, password); | |
default: | |
var error = new Error("Cannot read encrypted PBE data block. Unsupported OID."); | |
error.oid = oid; | |
error.supportedOids = [ | |
"pkcs5PBES2", | |
"pbeWithSHAAnd3-KeyTripleDES-CBC", | |
"pbewithSHAAnd40BitRC2-CBC" | |
]; | |
throw error; | |
} | |
}; | |
pki.pbe.getCipherForPBES2 = function(oid, params, password) { | |
var capture = {}; | |
var errors = []; | |
if (!asn1.validate(params, PBES2AlgorithmsValidator, capture, errors)) { | |
var error = new Error("Cannot read password-based-encryption algorithm parameters. ASN.1 object is not a supported EncryptedPrivateKeyInfo."); | |
error.errors = errors; | |
throw error; | |
} | |
oid = asn1.derToOid(capture.kdfOid); | |
if (oid !== pki.oids["pkcs5PBKDF2"]) { | |
var error = new Error("Cannot read encrypted private key. Unsupported key derivation function OID."); | |
error.oid = oid; | |
error.supportedOids = ["pkcs5PBKDF2"]; | |
throw error; | |
} | |
oid = asn1.derToOid(capture.encOid); | |
if (oid !== pki.oids["aes128-CBC"] && oid !== pki.oids["aes192-CBC"] && oid !== pki.oids["aes256-CBC"] && oid !== pki.oids["des-EDE3-CBC"] && oid !== pki.oids["desCBC"]) { | |
var error = new Error("Cannot read encrypted private key. Unsupported encryption scheme OID."); | |
error.oid = oid; | |
error.supportedOids = [ | |
"aes128-CBC", | |
"aes192-CBC", | |
"aes256-CBC", | |
"des-EDE3-CBC", | |
"desCBC" | |
]; | |
throw error; | |
} | |
var salt = capture.kdfSalt; | |
var count = forge7.util.createBuffer(capture.kdfIterationCount); | |
count = count.getInt(count.length() << 3); | |
var dkLen; | |
var cipherFn; | |
switch (pki.oids[oid]) { | |
case "aes128-CBC": | |
dkLen = 16; | |
cipherFn = forge7.aes.createDecryptionCipher; | |
break; | |
case "aes192-CBC": | |
dkLen = 24; | |
cipherFn = forge7.aes.createDecryptionCipher; | |
break; | |
case "aes256-CBC": | |
dkLen = 32; | |
cipherFn = forge7.aes.createDecryptionCipher; | |
break; | |
case "des-EDE3-CBC": | |
dkLen = 24; | |
cipherFn = forge7.des.createDecryptionCipher; | |
break; | |
case "desCBC": | |
dkLen = 8; | |
cipherFn = forge7.des.createDecryptionCipher; | |
break; | |
} | |
var md = prfOidToMessageDigest(capture.prfOid); | |
var dk = forge7.pkcs5.pbkdf2(password, salt, count, dkLen, md); | |
var iv = capture.encIv; | |
var cipher = cipherFn(dk); | |
cipher.start(iv); | |
return cipher; | |
}; | |
pki.pbe.getCipherForPKCS12PBE = function(oid, params, password) { | |
var capture = {}; | |
var errors = []; | |
if (!asn1.validate(params, pkcs12PbeParamsValidator, capture, errors)) { | |
var error = new Error("Cannot read password-based-encryption algorithm parameters. ASN.1 object is not a supported EncryptedPrivateKeyInfo."); | |
error.errors = errors; | |
throw error; | |
} | |
var salt = forge7.util.createBuffer(capture.salt); | |
var count = forge7.util.createBuffer(capture.iterations); | |
count = count.getInt(count.length() << 3); | |
var dkLen, dIvLen, cipherFn; | |
switch (oid) { | |
case pki.oids["pbeWithSHAAnd3-KeyTripleDES-CBC"]: | |
dkLen = 24; | |
dIvLen = 8; | |
cipherFn = forge7.des.startDecrypting; | |
break; | |
case pki.oids["pbewithSHAAnd40BitRC2-CBC"]: | |
dkLen = 5; | |
dIvLen = 8; | |
cipherFn = function(key2, iv2) { | |
var cipher = forge7.rc2.createDecryptionCipher(key2, 40); | |
cipher.start(iv2, null); | |
return cipher; | |
}; | |
break; | |
default: | |
var error = new Error("Cannot read PKCS #12 PBE data block. Unsupported OID."); | |
error.oid = oid; | |
throw error; | |
} | |
var md = prfOidToMessageDigest(capture.prfOid); | |
var key = pki.pbe.generatePkcs12Key(password, salt, 1, count, dkLen, md); | |
md.start(); | |
var iv = pki.pbe.generatePkcs12Key(password, salt, 2, count, dIvLen, md); | |
return cipherFn(key, iv); | |
}; | |
pki.pbe.opensslDeriveBytes = function(password, salt, dkLen, md) { | |
if (typeof md === "undefined" || md === null) { | |
if (!("md5" in forge7.md)) { | |
throw new Error('"md5" hash algorithm unavailable.'); | |
} | |
md = forge7.md.md5.create(); | |
} | |
if (salt === null) { | |
salt = ""; | |
} | |
var digests = [hash3(md, password + salt)]; | |
for (var length11 = 16, i = 1; length11 < dkLen; ++i, length11 += 16) { | |
digests.push(hash3(md, digests[i - 1] + password + salt)); | |
} | |
return digests.join("").substr(0, dkLen); | |
}; | |
function hash3(md, bytes3) { | |
return md.start().update(bytes3).digest().getBytes(); | |
} | |
function prfOidToMessageDigest(prfOid) { | |
var prfAlgorithm; | |
if (!prfOid) { | |
prfAlgorithm = "hmacWithSHA1"; | |
} else { | |
prfAlgorithm = pki.oids[asn1.derToOid(prfOid)]; | |
if (!prfAlgorithm) { | |
var error = new Error("Unsupported PRF OID."); | |
error.oid = prfOid; | |
error.supported = [ | |
"hmacWithSHA1", | |
"hmacWithSHA224", | |
"hmacWithSHA256", | |
"hmacWithSHA384", | |
"hmacWithSHA512" | |
]; | |
throw error; | |
} | |
} | |
return prfAlgorithmToMessageDigest(prfAlgorithm); | |
} | |
function prfAlgorithmToMessageDigest(prfAlgorithm) { | |
var factory = forge7.md; | |
switch (prfAlgorithm) { | |
case "hmacWithSHA224": | |
factory = forge7.md.sha512; | |
case "hmacWithSHA1": | |
case "hmacWithSHA256": | |
case "hmacWithSHA384": | |
case "hmacWithSHA512": | |
prfAlgorithm = prfAlgorithm.substr(8).toLowerCase(); | |
break; | |
default: | |
var error = new Error("Unsupported PRF algorithm."); | |
error.algorithm = prfAlgorithm; | |
error.supported = [ | |
"hmacWithSHA1", | |
"hmacWithSHA224", | |
"hmacWithSHA256", | |
"hmacWithSHA384", | |
"hmacWithSHA512" | |
]; | |
throw error; | |
} | |
if (!factory || !(prfAlgorithm in factory)) { | |
throw new Error("Unknown hash algorithm: " + prfAlgorithm); | |
} | |
return factory[prfAlgorithm].create(); | |
} | |
function createPbkdf2Params(salt, countBytes, dkLen, prfAlgorithm) { | |
var params = asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [ | |
// salt | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.OCTETSTRING, | |
false, | |
salt | |
), | |
// iteration count | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.INTEGER, | |
false, | |
countBytes.getBytes() | |
) | |
]); | |
if (prfAlgorithm !== "hmacWithSHA1") { | |
params.value.push( | |
// key length | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.INTEGER, | |
false, | |
forge7.util.hexToBytes(dkLen.toString(16)) | |
), | |
// AlgorithmIdentifier | |
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.SEQUENCE, true, [ | |
// algorithm | |
asn1.create( | |
asn1.Class.UNIVERSAL, | |
asn1.Type.OID, | |
false, | |
asn1.oidToDer(pki.oids[prfAlgorithm]).getBytes() | |
), | |
// parameters (null) | |
asn1.create(asn1.Class.UNIVERSAL, asn1.Type.NULL, false, "") | |
]) | |
); | |
} | |
return params; | |
} | |
} | |
}); | |
// node_modules/node-forge/lib/sha512.js | |
var require_sha512 = __commonJS({ | |
"node_modules/node-forge/lib/sha512.js"(exports2, module2) { | |
var forge7 = require_forge(); | |
require_md(); | |
require_util(); | |
var sha5127 = module2.exports = forge7.sha512 = forge7.sha512 || {}; | |
forge7.md.sha512 = forge7.md.algorithms.sha512 = sha5127; | |
var sha3842 = forge7.sha384 = forge7.sha512.sha384 = forge7.sha512.sha384 || {}; | |
sha3842.create = function() { | |
return sha5127.create("SHA-384"); | |
}; | |
forge7.md.sha384 = forge7.md.algorithms.sha384 = sha3842; | |
forge7.sha512.sha256 = forge7.sha512.sha256 || { | |
create: function() { | |
return sha5127.create("SHA-512/256"); | |
} | |
}; | |
forge7.md["sha512/256"] = forge7.md.algorithms["sha512/256"] = forge7.sha512.sha256; | |
forge7.sha512.sha224 = forge7.sha512.sha224 || { | |
create: function() { | |
return sha5127.create("SHA-512/224"); | |
} | |
}; | |
forge7.md["sha512/224"] = forge7.md.algorithms["sha512/224"] = forge7.sha512.sha224; | |
sha5127.create = function(algorithm) { | |
if (!_initialized) { | |
_init(); | |
} | |
if (typeof algorithm === "undefined") { | |
algorithm = "SHA-512"; | |
} | |
if (!(algorithm in _states)) { | |
throw new Error("Invalid SHA-512 algorithm: " + algorithm); | |
} | |
var _state = _states[algorithm]; | |
var _h = null; | |
var _input = forge7.util.createBuffer(); | |
var _w = new Array(80); | |
for (var wi = 0; wi < 80; ++wi) { | |
_w[wi] = new Array(2); | |
} | |
var digestLength = 64; | |
switch (algorithm) { | |
case "SHA-384": | |
digestLength = 48; | |
break; | |
case "SHA-512/256": | |
digestLength = 32; | |
break; | |
case "SHA-512/224": | |
digestLength = 28; | |
break; | |
} | |
var md = { | |
// SHA-512 => sha512 | |
algorithm: algorithm.replace("-", "").toLowerCase(), | |
blockLength: 128, | |
digestLength, | |
// 56-bit length of message so far (does not including padding) | |
messageLength: 0, | |
// true message length | |
fullMessageLength: null, | |
// size of message length in bytes | |
messageLengthSize: 16 | |
}; | |
md.start = function() { | |
md.messageLength = 0; | |
md.fullMessageLength = md.messageLength128 = []; | |
var int32s = md.messageLengthSize / 4; | |
for (var i = 0; i < int32s; ++i) { | |
md.fullMessageLength.push(0); | |
} | |
_input = forge7.util.createBuffer(); | |
_h = new Array(_state.length); | |
for (var i = 0; i < _state.length; ++i) { | |
_h[i] = _state[i].slice(0); | |
} | |
return md; | |
}; | |
md.start(); | |
md.update = function(msg, encoding) { | |
if (encoding === "utf8") { | |
msg = forge7.util.encodeUtf8(msg); | |
} | |
var len = msg.length; | |
md.messageLength += len; | |
len = [len / 4294967296 >>> 0, len >>> 0]; | |
for (var i = md.fullMessageLength.length - 1; i >= 0; --i) { | |
md.fullMessageLength[i] += len[1]; | |
len[1] = len[0] + (md.fullMessageLength[i] / 4294967296 >>> 0); | |
md.fullMessageLength[i] = md.fullMessageLength[i] >>> 0; | |
len[0] = len[1] / 4294967296 >>> 0; | |
} | |
_input.putBytes(msg); | |
_update(_h, _w, _input); | |
if (_input.read > 2048 || _input.length() === 0) { | |
_input.compact(); | |
} | |
return md; | |
}; | |
md.digest = function() { | |
var finalBlock = forge7.util.createBuffer(); | |
finalBlock.putBytes(_input.bytes()); | |
var remaining = md.fullMessageLength[md.fullMessageLength.length - 1] + md.messageLengthSize; | |
var overflow = remaining & md.blockLength - 1; | |
finalBlock.putBytes(_padding.substr(0, md.blockLength - overflow)); | |
var next, carry; | |
var bits2 = md.fullMessageLength[0] * 8; | |
for (var i = 0; i < md.fullMessageLength.length - 1; ++i) { | |
next = md.fullMessageLength[i + 1] * 8; | |
carry = next / 4294967296 >>> 0; | |
bits2 += carry; | |
finalBlock.putInt32(bits2 >>> 0); | |
bits2 = next >>> 0; | |
} | |
finalBlock.putInt32(bits2); | |
var h = new Array(_h.length); | |
for (var i = 0; i < _h.length; ++i) { | |
h[i] = _h[i].slice(0); | |
} | |
_update(h, _w, finalBlock); | |
var rval = forge7.util.createBuffer(); | |
var hlen; | |
if (algorithm === "SHA-512") { | |
hlen = h.length; | |
} else if (algorithm === "SHA-384") { | |
hlen = h.length - 2; | |
} else { | |
hlen = h.length - 4; | |
} | |
for (var i = 0; i < hlen; ++i) { | |
rval.putInt32(h[i][0]); | |
if (i !== hlen - 1 || algorithm !== "SHA-512/224") { | |
rval.putInt32(h[i][1]); | |
} | |
} | |
return rval; | |
}; | |
return md; | |
}; | |
var _padding = null; | |
var _initialized = false; | |
var _k = null; | |
var _states = null; | |
function _init() { | |
_padding = String.fromCharCode(128); | |
_padding += forge7.util.fillString(String.fromCharCode(0), 128); | |
_k = [ | |
[1116352408, 3609767458], | |
[1899447441, 602891725], | |
[3049323471, 3964484399], | |
[3921009573, 2173295548], | |
[961987163, 4081628472], | |
[1508970993, 3053834265], | |
[2453635748, 2937671579], | |
[2870763221, 3664609560], | |
[3624381080, 2734883394], | |
[310598401, 1164996542], | |
[607225278, 1323610764], | |
[1426881987, 3590304994], | |
[1925078388, 4068182383], | |
[2162078206, 991336113], | |
[2614888103, 633803317], | |
[3248222580, 3479774868], | |
[3835390401, 2666613458], | |
[4022224774, 944711139], | |
[264347078, 2341262773], | |
[604807628, 2007800933], | |
[770255983, 1495990901], | |
[1249150122, 1856431235], | |
[1555081692, 3175218132], | |
[1996064986, 2198950837], | |
[2554220882, 3999719339], | |
[2821834349, 766784016], | |
[2952996808, 2566594879], | |
[3210313671, 3203337956], | |
[3336571891, 1034457026], | |
[3584528711, 2466948901], | |
[113926993, 3758326383], | |
[338241895, 168717936], | |
[666307205, 1188179964], | |
[773529912, 1546045734], | |
[1294757372, 1522805485], | |
[1396182291, 2643833823], | |
[1695183700, 2343527390], | |
[1986661051, 1014477480], | |
[2177026350, 1206759142], | |
[2456956037, 344077627], | |
[2730485921, 1290863460], | |
[2820302411, 3158454273], | |
[3259730800, 3505952657], | |
[3345764771, 106217008], | |
[3516065817, 3606008344], | |
[3600352804, 1432725776], | |
[4094571909, 1467031594], | |
[275423344, 851169720], | |
[430227734, 3100823752], | |
[506948616, 1363258195], | |
[659060556, 3750685593], | |
[883997877, 3785050280], | |
[958139571, 3318307427], | |
[1322822218, 3812723403], | |
[1537002063, 2003034995], | |
[1747873779, 3602036899], | |
[1955562222, 1575990012], | |
[2024104815, 1125592928], | |
[2227730452, 2716904306], | |
[2361852424, 442776044], | |
[2428436474, 593698344], | |
[2756734187, 3733110249], | |
[3204031479, 2999351573], | |
[3329325298, 3815920427], | |
[3391569614, 3928383900], | |
[3515267271, 566280711], | |
[3940187606, 3454069534], | |
[4118630271, 4000239992], | |
[116418474, 1914138554], | |
[174292421, 2731055270], | |
[289380356, 3203993006], | |
[460393269, 320620315], | |
[685471733, 587496836], | |
[852142971, 1086792851], | |
[1017036298, 365543100], | |
[1126000580, 2618297676], | |
[1288033470, 3409855158], | |
[1501505948, 4234509866], | |
[1607167915, 987167468], | |
[1816402316, 1246189591] | |
]; | |
_states = {}; | |
_states["SHA-512"] = [ | |
[1779033703, 4089235720], | |
[3144134277, 2227873595], | |
[1013904242, 4271175723], | |
[2773480762, 1595750129], | |
[1359893119, 2917565137], | |
[2600822924, 725511199], | |
[528734635, 4215389547], | |
[1541459225, 327033209] | |
]; | |
_states["SHA-384"] = [ | |
[3418070365, 3238371032], | |
[1654270250, 914150663], | |
[2438529370, 812702999], | |
[355462360, 4144912697], | |
[1731405415, 4290775857], | |
[2394180231, 1750603025], | |
[3675008525, 1694076839], | |
[1203062813, 3204075428] | |
]; | |
_states["SHA-512/256"] = [ | |
[573645204, 4230739756], | |
[2673172387, 3360449730], | |
[596883563, 1867755857], | |
[2520282905, 1497426621], | |
[2519219938, 2827943907], | |
[3193839141, 1401305490], | |
[721525244, 746961066], | |
[246885852, 2177182882] | |
]; | |
_states["SHA-512/224"] = [ | |
[2352822216, 424955298], | |
[1944164710, 2312950998], | |
[502970286, 855612546], | |
[1738396948, 1479516111], | |
[258812777, 2077511080], | |
[2011393907, 79989058], | |
[1067287976, 1780299464], | |
[286451373, 2446758561] | |
]; | |
_initialized = true; | |
} | |
function _update(s, w, bytes3) { | |
var t1_hi, t1_lo; | |
var t2_hi, t2_lo; | |
var s0_hi, s0_lo; | |
var s1_hi, s1_lo; | |
var ch_hi, ch_lo; | |
var maj_hi, maj_lo; | |
var a_hi, a_lo; | |
var b_hi, b_lo; | |
var c_hi, c_lo; | |
var d_hi, d_lo; | |
var e_hi, e_lo; | |
var f_hi, f_lo; | |
var g_hi, g_lo; | |
var h_hi, h_lo; | |
var i, hi, lo, w2, w7, w15, w16; | |
var len = bytes3.length(); | |
while (len >= 128) { | |
for (i = 0; i < 16; ++i) { | |
w[i][0] = bytes3.getInt32() >>> 0; | |
w[i][1] = bytes3.getInt32() >>> 0; | |
} | |
for (; i < 80; ++i) { | |
w2 = w[i - 2]; | |
hi = w2[0]; | |
lo = w2[1]; | |
t1_hi = ((hi >>> 19 | lo << 13) ^ // ROTR 19 | |
(lo >>> 29 | hi << 3) ^ // ROTR 61/(swap + ROTR 29) | |
hi >>> 6) >>> 0; | |
t1_lo = ((hi << 13 | lo >>> 19) ^ // ROTR 19 | |
(lo << 3 | hi >>> 29) ^ // ROTR 61/(swap + ROTR 29) | |
(hi << 26 | lo >>> 6)) >>> 0; | |
w15 = w[i - 15]; | |
hi = w15[0]; | |
lo = w15[1]; | |
t2_hi = ((hi >>> 1 | lo << 31) ^ // ROTR 1 | |
(hi >>> 8 | lo << 24) ^ // ROTR 8 | |
hi >>> 7) >>> 0; | |
t2_lo = ((hi << 31 | lo >>> 1) ^ // ROTR 1 | |
(hi << 24 | lo >>> 8) ^ // ROTR 8 | |
(hi << 25 | lo >>> 7)) >>> 0; | |
w7 = w[i - 7]; | |
w16 = w[i - 16]; | |
lo = t1_lo + w7[1] + t2_lo + w16[1]; | |
w[i][0] = t1_hi + w7[0] + t2_hi + w16[0] + (lo / 4294967296 >>> 0) >>> 0; | |
w[i][1] = lo >>> 0; | |
} | |
a_hi = s[0][0]; | |
a_lo = s[0][1]; | |
b_hi = s[1][0]; | |
b_lo = s[1][1]; | |
c_hi = s[2][0]; | |
c_lo = s[2][1]; | |
d_hi = s[3][0]; | |
d_lo = s[3][1]; | |
e_hi = s[4][0]; | |
e_lo = s[4][1]; | |
f_hi = s[5][0]; | |
f_lo = s[5][1]; | |
g_hi = s[6][0]; | |
g_lo = s[6][1]; | |
h_hi = s[7][0]; | |
h_lo = s[7][1]; | |
for (i = 0; i < 80; ++i) { | |
s1_hi = ((e_hi >>> 14 | e_lo << 18) ^ // ROTR 14 | |
(e_hi >>> 18 | e_lo << 14) ^ // ROTR 18 | |
(e_lo >>> 9 | e_hi << 23)) >>> 0; | |
s1_lo = ((e_hi << 18 | e_lo >>> 14) ^ // ROTR 14 | |
(e_hi << 14 | e_lo >>> 18) ^ // ROTR 18 | |
(e_lo << 23 | e_hi >>> 9)) >>> 0; | |
ch_hi = (g_hi ^ e_hi & (f_hi ^ g_hi)) >>> 0; | |
ch_lo = (g_lo ^ e_lo & (f_lo ^ g_lo)) >>> 0; | |
s0_hi = ((a_hi >>> 28 | a_lo << 4) ^ // ROTR 28 | |
(a_lo >>> 2 | a_hi << 30) ^ // ROTR 34/(swap + ROTR 2) | |
(a_lo >>> 7 | a_hi << 25)) >>> 0; | |
s0_lo = ((a_hi << 4 | a_lo >>> 28) ^ // ROTR 28 | |
(a_lo << 30 | a_hi >>> 2) ^ // ROTR 34/(swap + ROTR 2) | |
(a_lo << 25 | a_hi >>> 7)) >>> 0; | |
maj_hi = (a_hi & b_hi | c_hi & (a_hi ^ b_hi)) >>> 0; | |
maj_lo = (a_lo & b_lo | c_lo & (a_lo ^ b_lo)) >>> 0; | |
lo = h_lo + s1_lo + ch_lo + _k[i][1] + w[i][1]; | |
t1_hi = h_hi + s1_hi + ch_hi + _k[i][0] + w[i][0] + (lo / 4294967296 >>> 0) >>> 0; | |
t1_lo = lo >>> 0; | |
lo = s0_lo + maj_lo; | |
t2_hi = s0_hi + maj_hi + (lo / 4294967296 >>> 0) >>> 0; | |
t2_lo = lo >>> 0; | |
h_hi = g_hi; | |
h_lo = g_lo; | |
g_hi = f_hi; | |
g_lo = f_lo; | |
f_hi = e_hi; | |
f_lo = e_lo; | |
lo = d_lo + t1_lo; | |
e_hi = d_hi + t1_hi + (lo / 4294967296 >>> 0) >>> 0; | |
e_lo = lo >>> 0; | |
d_hi = c_hi; | |
d_lo = c_lo; | |
c_hi = b_hi; | |
c_lo = b_lo; | |
b_hi = a_hi; | |
b_lo = a_lo; | |
lo = t1_lo + t2_lo; | |
a_hi = t1_hi + t2_hi + (lo / 4294967296 >>> 0) >>> 0; | |
a_lo = lo >>> 0; | |
} | |
lo = s[0][1] + a_lo; | |
s[0][0] = s[0][0] + a_hi + (lo / 4294967296 >>> 0) >>> 0; | |
s[0][1] = lo >>> 0; | |
lo = s[1][1] + b_lo; | |
s[1][0] = s[1][0] + b_hi + (lo / 4294967296 >>> 0) >>> 0; | |
s[1][1] = lo >>> 0; | |
lo = s[2][1] + c_lo; | |
s[2][0] = s[2][0] + c_hi + (lo / 4294967296 >>> 0) >>> 0; | |
s[2][1] = lo >>> 0; | |
lo = s[3][1] + d_lo; | |
s[3][0] = s[3][0] + d_hi + (lo / 4294967296 >>> 0) >>> 0; | |
s[3][1] = lo >>> 0; | |
lo = s[4][1] + e_lo; | |
s[4][0] = s[4][0] + e_hi + (lo / 4294967296 >>> 0) >>> 0; | |
s[4][1] = lo >>> 0; | |
lo = s[5][1] + f_lo; | |
s[5][0] = s[5][0] + f_hi + (lo / 4294967296 >>> 0) >>> 0; | |
s[5][1] = lo >>> 0; | |
lo = s[6][1] + g_lo; | |
s[6][0] = s[6][0] + g_hi + (lo / 4294967296 >>> 0) >>> 0; | |
s[6][1] = lo >>> 0; | |
lo = s[7][1] + h_lo; | |
s[7][0] = s[7][0] + h_hi + (lo / 4294967296 >>> 0) >>> 0; | |
s[7][1] = lo >>> 0; | |
len -= 128; | |
} | |
} | |
} | |
}); | |
// node_modules/is-plain-obj/index.js | |
var require_is_plain_obj = __commonJS({ | |
"node_modules/is-plain-obj/index.js"(exports2, module2) { | |
"use strict"; | |
module2.exports = (value) => { | |
if (Object.prototype.toString.call(value) !== "[object Object]") { | |
return false; | |
} | |
const prototype = Object.getPrototypeOf(value); | |
return prototype === null || prototype === Object.prototype; | |
}; | |
} | |
}); | |
// node_modules/merge-options/index.js | |
var require_merge_options = __commonJS({ | |
"node_modules/merge-options/index.js"(exports2, module2) { | |
"use strict"; | |
var isOptionObject = require_is_plain_obj(); | |
var { hasOwnProperty } = Object.prototype; | |
var { propertyIsEnumerable } = Object; | |
var defineProperty = (object, name8, value) => Object.defineProperty(object, name8, { | |
value, | |
writable: true, | |
enumerable: true, | |
configurable: true | |
}); | |
var globalThis2 = exports2; | |
var defaultMergeOptions = { | |
concatArrays: false, | |
ignoreUndefined: false | |
}; | |
var getEnumerableOwnPropertyKeys = (value) => { | |
const keys = []; | |
for (const key in value) { | |
if (hasOwnProperty.call(value, key)) { | |
keys.push(key); | |
} | |
} | |
if (Object.getOwnPropertySymbols) { | |
const symbols = Object.getOwnPropertySymbols(value); | |
for (const symbol7 of symbols) { | |
if (propertyIsEnumerable.call(value, symbol7)) { | |
keys.push(symbol7); | |
} | |
} | |
} | |
return keys; | |
}; | |
function clone(value) { | |
if (Array.isArray(value)) { | |
return cloneArray(value); | |
} | |
if (isOptionObject(value)) { | |
return cloneOptionObject(value); | |
} | |
return value; | |
} | |
function cloneArray(array) { | |
const result = array.slice(0, 0); | |
getEnumerableOwnPropertyKeys(array).forEach((key) => { | |
defineProperty(result, key, clone(array[key])); | |
}); | |
return result; | |
} | |
function cloneOptionObject(object) { | |
const result = Object.getPrototypeOf(object) === null ? /* @__PURE__ */ Object.create(null) : {}; | |
getEnumerableOwnPropertyKeys(object).forEach((key) => { | |
defineProperty(result, key, clone(object[key])); | |
}); | |
return result; | |
} | |
var mergeKeys = (merged, source, keys, config) => { | |
keys.forEach((key) => { | |
if (typeof source[key] === "undefined" && config.ignoreUndefined) { | |
return; | |
} | |
if (key in merged && merged[key] !== Object.getPrototypeOf(merged)) { | |
defineProperty(merged, key, merge2(merged[key], source[key], config)); | |
} else { | |
defineProperty(merged, key, clone(source[key])); | |
} | |
}); | |
return merged; | |
}; | |
var concatArrays = (merged, source, config) => { | |
let result = merged.slice(0, 0); | |
let resultIndex = 0; | |
[merged, source].forEach((array) => { | |
const indices = []; | |
for (let k = 0; k < array.length; k++) { | |
if (!hasOwnProperty.call(array, k)) { | |
continue; | |
} | |
indices.push(String(k)); | |
if (array === merged) { | |
defineProperty(result, resultIndex++, array[k]); | |
} else { | |
defineProperty(result, resultIndex++, clone(array[k])); | |
} | |
} | |
result = mergeKeys(result, array, getEnumerableOwnPropertyKeys(array).filter((key) => !indices.includes(key)), config); | |
}); | |
return result; | |
}; | |
function merge2(merged, source, config) { | |
if (config.concatArrays && Array.isArray(merged) && Array.isArray(source)) { | |
return concatArrays(merged, source, config); | |
} | |
if (!isOptionObject(source) || !isOptionObject(merged)) { | |
return clone(source); | |
} | |
return mergeKeys(merged, source, getEnumerableOwnPropertyKeys(source), config); | |
} | |
module2.exports = function(...options) { | |
const config = merge2(clone(defaultMergeOptions), this !== globalThis2 && this || {}, defaultMergeOptions); | |
let merged = { _: {} }; | |
for (const option of options) { | |
if (option === void 0) { | |
continue; | |
} | |
if (!isOptionObject(option)) { | |
throw new TypeError("`" + option + "` is not an Option Object"); | |
} | |
merged = merge2(merged, { _: option }, config); | |
} | |
return merged._; | |
}; | |
} | |
}); | |
// node_modules/truncate-utf8-bytes/lib/truncate.js | |
var require_truncate = __commonJS({ | |
"node_modules/truncate-utf8-bytes/lib/truncate.js"(exports2, module2) { | |
"use strict"; | |
function isHighSurrogate(codePoint) { | |
return codePoint >= 55296 && codePoint <= 56319; | |
} | |
function isLowSurrogate(codePoint) { | |
return codePoint >= 56320 && codePoint <= 57343; | |
} | |
module2.exports = function truncate(getLength, string3, byteLength) { | |
if (typeof string3 !== "string") { | |
throw new Error("Input must be string"); | |
} | |
var charLength = string3.length; | |
var curByteLength = 0; | |
var codePoint; | |
var segment; | |
for (var i = 0; i < charLength; i += 1) { | |
codePoint = string3.charCodeAt(i); | |
segment = string3[i]; | |
if (isHighSurrogate(codePoint) && isLowSurrogate(string3.charCodeAt(i + 1))) { | |
i += 1; | |
segment += string3[i]; | |
} | |
curByteLength += getLength(segment); | |
if (curByteLength === byteLength) { | |
return string3.slice(0, i + 1); | |
} else if (curByteLength > byteLength) { | |
return string3.slice(0, i - segment.length + 1); | |
} | |
} | |
return string3; | |
}; | |
} | |
}); | |
// node_modules/utf8-byte-length/browser.js | |
var require_browser2 = __commonJS({ | |
"node_modules/utf8-byte-length/browser.js"(exports2, module2) { | |
"use strict"; | |
function isHighSurrogate(codePoint) { | |
return codePoint >= 55296 && codePoint <= 56319; | |
} | |
function isLowSurrogate(codePoint) { | |
return codePoint >= 56320 && codePoint <= 57343; | |
} | |
module2.exports = function getByteLength(string3) { | |
if (typeof string3 !== "string") { | |
throw new Error("Input must be string"); | |
} | |
var charLength = string3.length; | |
var byteLength = 0; | |
var codePoint = null; | |
var prevCodePoint = null; | |
for (var i = 0; i < charLength; i++) { | |
codePoint = string3.charCodeAt(i); | |
if (isLowSurrogate(codePoint)) { | |
if (prevCodePoint != null && isHighSurrogate(prevCodePoint)) { | |
byteLength += 1; | |
} else { | |
byteLength += 3; | |
} | |
} else if (codePoint <= 127) { | |
byteLength += 1; | |
} else if (codePoint >= 128 && codePoint <= 2047) { | |
byteLength += 2; | |
} else if (codePoint >= 2048 && codePoint <= 65535) { | |
byteLength += 3; | |
} | |
prevCodePoint = codePoint; | |
} | |
return byteLength; | |
}; | |
} | |
}); | |
// node_modules/truncate-utf8-bytes/browser.js | |
var require_browser3 = __commonJS({ | |
"node_modules/truncate-utf8-bytes/browser.js"(exports2, module2) { | |
"use strict"; | |
var truncate = require_truncate(); | |
var getLength = require_browser2(); | |
module2.exports = truncate.bind(null, getLength); | |
} | |
}); | |
// node_modules/sanitize-filename/index.js | |
var require_sanitize_filename = __commonJS({ | |
"node_modules/sanitize-filename/index.js"(exports2, module2) { | |
"use strict"; | |
var truncate = require_browser3(); | |
var illegalRe = /[\/\?<>\\:\*\|"]/g; | |
var controlRe = /[\x00-\x1f\x80-\x9f]/g; | |
var reservedRe = /^\.+$/; | |
var windowsReservedRe = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i; | |
var windowsTrailingRe = /[\. ]+$/; | |
function sanitize2(input, replacement) { | |
if (typeof input !== "string") { | |
throw new Error("Input must be string"); | |
} | |
var sanitized = input.replace(illegalRe, replacement).replace(controlRe, replacement).replace(reservedRe, replacement).replace(windowsReservedRe, replacement).replace(windowsTrailingRe, replacement); | |
return truncate(sanitized, 255); | |
} | |
module2.exports = function(input, options) { | |
var replacement = options && options.replacement || ""; | |
var output3 = sanitize2(input, replacement); | |
if (replacement === "") { | |
return output3; | |
} | |
return sanitize2(output3, ""); | |
}; | |
} | |
}); | |
// node_modules/netmask/lib/netmask.js | |
var require_netmask = __commonJS({ | |
"node_modules/netmask/lib/netmask.js"(exports2) { | |
(function() { | |
var Netmask2, atob, chr, chr0, chrA, chra, ip2long, long2ip; | |
long2ip = function(long) { | |
var a, b, c, d; | |
a = (long & 255 << 24) >>> 24; | |
b = (long & 255 << 16) >>> 16; | |
c = (long & 255 << 8) >>> 8; | |
d = long & 255; | |
return [a, b, c, d].join("."); | |
}; | |
ip2long = function(ip) { | |
var b, c, i, j, n, ref; | |
b = []; | |
for (i = j = 0; j <= 3; i = ++j) { | |
if (ip.length === 0) { | |
break; | |
} | |
if (i > 0) { | |
if (ip[0] !== ".") { | |
throw new Error("Invalid IP"); | |
} | |
ip = ip.substring(1); | |
} | |
ref = atob(ip), n = ref[0], c = ref[1]; | |
ip = ip.substring(c); | |
b.push(n); | |
} | |
if (ip.length !== 0) { | |
throw new Error("Invalid IP"); | |
} | |
switch (b.length) { | |
case 1: | |
if (b[0] > 4294967295) { | |
throw new Error("Invalid IP"); | |
} | |
return b[0] >>> 0; | |
case 2: | |
if (b[0] > 255 || b[1] > 16777215) { | |
throw new Error("Invalid IP"); | |
} | |
return (b[0] << 24 | b[1]) >>> 0; | |
case 3: | |
if (b[0] > 255 || b[1] > 255 || b[2] > 65535) { | |
throw new Error("Invalid IP"); | |
} | |
return (b[0] << 24 | b[1] << 16 | b[2]) >>> 0; | |
case 4: | |
if (b[0] > 255 || b[1] > 255 || b[2] > 255 || b[3] > 255) { | |
throw new Error("Invalid IP"); | |
} | |
return (b[0] << 24 | b[1] << 16 | b[2] << 8 | b[3]) >>> 0; | |
default: | |
throw new Error("Invalid IP"); | |
} | |
}; | |
chr = function(b) { | |
return b.charCodeAt(0); | |
}; | |
chr0 = chr("0"); | |
chra = chr("a"); | |
chrA = chr("A"); | |
atob = function(s) { | |
var base14, dmax, i, n, start; | |
n = 0; | |
base14 = 10; | |
dmax = "9"; | |
i = 0; | |
if (s.length > 1 && s[i] === "0") { | |
if (s[i + 1] === "x" || s[i + 1] === "X") { | |
i += 2; | |
base14 = 16; | |
} else if ("0" <= s[i + 1] && s[i + 1] <= "9") { | |
i++; | |
base14 = 8; | |
dmax = "7"; | |
} | |
} | |
start = i; | |
while (i < s.length) { | |
if ("0" <= s[i] && s[i] <= dmax) { | |
n = n * base14 + (chr(s[i]) - chr0) >>> 0; | |
} else if (base14 === 16) { | |
if ("a" <= s[i] && s[i] <= "f") { | |
n = n * base14 + (10 + chr(s[i]) - chra) >>> 0; | |
} else if ("A" <= s[i] && s[i] <= "F") { | |
n = n * base14 + (10 + chr(s[i]) - chrA) >>> 0; | |
} else { | |
break; | |
} | |
} else { | |
break; | |
} | |
if (n > 4294967295) { | |
throw new Error("too large"); | |
} | |
i++; | |
} | |
if (i === start) { | |
throw new Error("empty octet"); | |
} | |
return [n, i]; | |
}; | |
Netmask2 = function() { | |
function Netmask3(net, mask) { | |
var error, i, j, ref; | |
if (typeof net !== "string") { | |
throw new Error("Missing `net' parameter"); | |
} | |
if (!mask) { | |
ref = net.split("/", 2), net = ref[0], mask = ref[1]; | |
} | |
if (!mask) { | |
mask = 32; | |
} | |
if (typeof mask === "string" && mask.indexOf(".") > -1) { | |
try { | |
this.maskLong = ip2long(mask); | |
} catch (error1) { | |
error = error1; | |
throw new Error("Invalid mask: " + mask); | |
} | |
for (i = j = 32; j >= 0; i = --j) { | |
if (this.maskLong === 4294967295 << 32 - i >>> 0) { | |
this.bitmask = i; | |
break; | |
} | |
} | |
} else if (mask || mask === 0) { | |
this.bitmask = parseInt(mask, 10); | |
this.maskLong = 0; | |
if (this.bitmask > 0) { | |
this.maskLong = 4294967295 << 32 - this.bitmask >>> 0; | |
} | |
} else { | |
throw new Error("Invalid mask: empty"); | |
} | |
try { | |
this.netLong = (ip2long(net) & this.maskLong) >>> 0; | |
} catch (error1) { | |
error = error1; | |
throw new Error("Invalid net address: " + net); | |
} | |
if (!(this.bitmask <= 32)) { | |
throw new Error("Invalid mask for ip4: " + mask); | |
} | |
this.size = Math.pow(2, 32 - this.bitmask); | |
this.base = long2ip(this.netLong); | |
this.mask = long2ip(this.maskLong); | |
this.hostmask = long2ip(~this.maskLong); | |
this.first = this.bitmask <= 30 ? long2ip(this.netLong + 1) : this.base; | |
this.last = this.bitmask <= 30 ? long2ip(this.netLong + this.size - 2) : long2ip(this.netLong + this.size - 1); | |
this.broadcast = this.bitmask <= 30 ? long2ip(this.netLong + this.size - 1) : void 0; | |
} | |
Netmask3.prototype.contains = function(ip) { | |
if (typeof ip === "string" && (ip.indexOf("/") > 0 || ip.split(".").length !== 4)) { | |
ip = new Netmask3(ip); | |
} | |
if (ip instanceof Netmask3) { | |
return this.contains(ip.base) && this.contains(ip.broadcast || ip.last); | |
} else { | |
return (ip2long(ip) & this.maskLong) >>> 0 === (this.netLong & this.maskLong) >>> 0; | |
} | |
}; | |
Netmask3.prototype.next = function(count) { | |
if (count == null) { | |
count = 1; | |
} | |
return new Netmask3(long2ip(this.netLong + this.size * count), this.mask); | |
}; | |
Netmask3.prototype.forEach = function(fn) { | |
var index, lastLong, long; | |
long = ip2long(this.first); | |
lastLong = ip2long(this.last); | |
index = 0; | |
while (long <= lastLong) { | |
fn(long2ip(long), long, index); | |
index++; | |
long++; | |
} | |
}; | |
Netmask3.prototype.toString = function() { | |
return this.base + "/" + this.bitmask; | |
}; | |
return Netmask3; | |
}(); | |
exports2.ip2long = ip2long; | |
exports2.long2ip = long2ip; | |
exports2.Netmask = Netmask2; | |
}).call(exports2); | |
} | |
}); | |
// node_modules/ipaddr.js/lib/ipaddr.js | |
var require_ipaddr = __commonJS({ | |
"node_modules/ipaddr.js/lib/ipaddr.js"(exports2, module2) { | |
(function(root) { | |
"use strict"; | |
const ipv4Part = "(0?\\d+|0x[a-f0-9]+)"; | |
const ipv4Regexes = { | |
fourOctet: new RegExp(`^${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}$`, "i"), | |
threeOctet: new RegExp(`^${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}$`, "i"), | |
twoOctet: new RegExp(`^${ipv4Part}\\.${ipv4Part}$`, "i"), | |
longValue: new RegExp(`^${ipv4Part}$`, "i") | |
}; | |
const octalRegex = new RegExp(`^0[0-7]+$`, "i"); | |
const hexRegex = new RegExp(`^0x[a-f0-9]+$`, "i"); | |
const zoneIndex = "%[0-9a-z]{1,}"; | |
const ipv6Part = "(?:[0-9a-f]+::?)+"; | |
const ipv6Regexes = { | |
zoneIndex: new RegExp(zoneIndex, "i"), | |
"native": new RegExp(`^(::)?(${ipv6Part})?([0-9a-f]+)?(::)?(${zoneIndex})?$`, "i"), | |
deprecatedTransitional: new RegExp(`^(?:::)(${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}(${zoneIndex})?)$`, "i"), | |
transitional: new RegExp(`^((?:${ipv6Part})|(?:::)(?:${ipv6Part})?)${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}\\.${ipv4Part}(${zoneIndex})?$`, "i") | |
}; | |
function expandIPv6(string3, parts) { | |
if (string3.indexOf("::") !== string3.lastIndexOf("::")) { | |
return null; | |
} | |
let colonCount = 0; | |
let lastColon = -1; | |
let zoneId = (string3.match(ipv6Regexes.zoneIndex) || [])[0]; | |
let replacement, replacementCount; | |
if (zoneId) { | |
zoneId = zoneId.substring(1); | |
string3 = string3.replace(/%.+$/, ""); | |
} | |
while ((lastColon = string3.indexOf(":", lastColon + 1)) >= 0) { | |
colonCount++; | |
} | |
if (string3.substr(0, 2) === "::") { | |
colonCount--; | |
} | |
if (string3.substr(-2, 2) === "::") { | |
colonCount--; | |
} | |
if (colonCount > parts) { | |
return null; | |
} | |
replacementCount = parts - colonCount; | |
replacement = ":"; | |
while (replacementCount--) { | |
replacement += "0:"; | |
} | |
string3 = string3.replace("::", replacement); | |
if (string3[0] === ":") { | |
string3 = string3.slice(1); | |
} | |
if (string3[string3.length - 1] === ":") { | |
string3 = string3.slice(0, -1); | |
} | |
parts = function() { | |
const ref = string3.split(":"); | |
const results = []; | |
for (let i = 0; i < ref.length; i++) { | |
results.push(parseInt(ref[i], 16)); | |
} | |
return results; | |
}(); | |
return { | |
parts, | |
zoneId | |
}; | |
} | |
function matchCIDR(first2, second4, partSize, cidrBits) { | |
if (first2.length !== second4.length) { | |
throw new Error("ipaddr: cannot match CIDR for objects with different lengths"); | |
} | |
let part = 0; | |
let shift; | |
while (cidrBits > 0) { | |
shift = partSize - cidrBits; | |
if (shift < 0) { | |
shift = 0; | |
} | |
if (first2[part] >> shift !== second4[part] >> shift) { | |
return false; | |
} | |
cidrBits -= partSize; | |
part += 1; | |
} | |
return true; | |
} | |
function parseIntAuto(string3) { | |
if (hexRegex.test(string3)) { | |
return parseInt(string3, 16); | |
} | |
if (string3[0] === "0" && !isNaN(parseInt(string3[1], 10))) { | |
if (octalRegex.test(string3)) { | |
return parseInt(string3, 8); | |
} | |
throw new Error(`ipaddr: cannot parse ${string3} as octal`); | |
} | |
return parseInt(string3, 10); | |
} | |
function padPart(part, length11) { | |
while (part.length < length11) { | |
part = `0${part}`; | |
} | |
return part; | |
} | |
const ipaddr2 = {}; | |
ipaddr2.IPv4 = function() { | |
function IPv4(octets) { | |
if (octets.length !== 4) { | |
throw new Error("ipaddr: ipv4 octet count should be 4"); | |
} | |
let i, octet; | |
for (i = 0; i < octets.length; i++) { | |
octet = octets[i]; | |
if (!(0 <= octet && octet <= 255)) { | |
throw new Error("ipaddr: ipv4 octet should fit in 8 bits"); | |
} | |
} | |
this.octets = octets; | |
} | |
IPv4.prototype.SpecialRanges = { | |
unspecified: [[new IPv4([0, 0, 0, 0]), 8]], | |
broadcast: [[new IPv4([255, 255, 255, 255]), 32]], | |
// RFC3171 | |
multicast: [[new IPv4([224, 0, 0, 0]), 4]], | |
// RFC3927 | |
linkLocal: [[new IPv4([169, 254, 0, 0]), 16]], | |
// RFC5735 | |
loopback: [[new IPv4([127, 0, 0, 0]), 8]], | |
// RFC6598 | |
carrierGradeNat: [[new IPv4([100, 64, 0, 0]), 10]], | |
// RFC1918 | |
"private": [ | |
[new IPv4([10, 0, 0, 0]), 8], | |
[new IPv4([172, 16, 0, 0]), 12], | |
[new IPv4([192, 168, 0, 0]), 16] | |
], | |
// Reserved and testing-only ranges; RFCs 5735, 5737, 2544, 1700 | |
reserved: [ | |
[new IPv4([192, 0, 0, 0]), 24], | |
[new IPv4([192, 0, 2, 0]), 24], | |
[new IPv4([192, 88, 99, 0]), 24], | |
[new IPv4([198, 18, 0, 0]), 15], | |
[new IPv4([198, 51, 100, 0]), 24], | |
[new IPv4([203, 0, 113, 0]), 24], | |
[new IPv4([240, 0, 0, 0]), 4] | |
] | |
}; | |
IPv4.prototype.kind = function() { | |
return "ipv4"; | |
}; | |
IPv4.prototype.match = function(other, cidrRange) { | |
let ref; | |
if (cidrRange === void 0) { | |
ref = other; | |
other = ref[0]; | |
cidrRange = ref[1]; | |
} | |
if (other.kind() !== "ipv4") { | |
throw new Error("ipaddr: cannot match ipv4 address with non-ipv4 one"); | |
} | |
return matchCIDR(this.octets, other.octets, 8, cidrRange); | |
}; | |
IPv4.prototype.prefixLengthFromSubnetMask = function() { | |
let cidr = 0; | |
let stop = false; | |
const zerotable = { | |
0: 8, | |
128: 7, | |
192: 6, | |
224: 5, | |
240: 4, | |
248: 3, | |
252: 2, | |
254: 1, | |
255: 0 | |
}; | |
let i, octet, zeros; | |
for (i = 3; i >= 0; i -= 1) { | |
octet = this.octets[i]; | |
if (octet in zerotable) { | |
zeros = zerotable[octet]; | |
if (stop && zeros !== 0) { | |
return null; | |
} | |
if (zeros !== 8) { | |
stop = true; | |
} | |
cidr += zeros; | |
} else { | |
return null; | |
} | |
} | |
return 32 - cidr; | |
}; | |
IPv4.prototype.range = function() { | |
return ipaddr2.subnetMatch(this, this.SpecialRanges); | |
}; | |
IPv4.prototype.toByteArray = function() { | |
return this.octets.slice(0); | |
}; | |
IPv4.prototype.toIPv4MappedAddress = function() { | |
return ipaddr2.IPv6.parse(`::ffff:${this.toString()}`); | |
}; | |
IPv4.prototype.toNormalizedString = function() { | |
return this.toString(); | |
}; | |
IPv4.prototype.toString = function() { | |
return this.octets.join("."); | |
}; | |
return IPv4; | |
}(); | |
ipaddr2.IPv4.broadcastAddressFromCIDR = function(string3) { | |
try { | |
const cidr = this.parseCIDR(string3); | |
const ipInterfaceOctets = cidr[0].toByteArray(); | |
const subnetMaskOctets = this.subnetMaskFromPrefixLength(cidr[1]).toByteArray(); | |
const octets = []; | |
let i = 0; | |
while (i < 4) { | |
octets.push(parseInt(ipInterfaceOctets[i], 10) | parseInt(subnetMaskOctets[i], 10) ^ 255); | |
i++; | |
} | |
return new this(octets); | |
} catch (e) { | |
throw new Error("ipaddr: the address does not have IPv4 CIDR format"); | |
} | |
}; | |
ipaddr2.IPv4.isIPv4 = function(string3) { | |
return this.parser(string3) !== null; | |
}; | |
ipaddr2.IPv4.isValid = function(string3) { | |
try { | |
new this(this.parser(string3)); | |
return true; | |
} catch (e) { | |
return false; | |
} | |
}; | |
ipaddr2.IPv4.isValidFourPartDecimal = function(string3) { | |
if (ipaddr2.IPv4.isValid(string3) && string3.match(/^(0|[1-9]\d*)(\.(0|[1-9]\d*)){3}$/)) { | |
return true; | |
} else { | |
return false; | |
} | |
}; | |
ipaddr2.IPv4.networkAddressFromCIDR = function(string3) { | |
let cidr, i, ipInterfaceOctets, octets, subnetMaskOctets; | |
try { | |
cidr = this.parseCIDR(string3); | |
ipInterfaceOctets = cidr[0].toByteArray(); | |
subnetMaskOctets = this.subnetMaskFromPrefixLength(cidr[1]).toByteArray(); | |
octets = []; | |
i = 0; | |
while (i < 4) { | |
octets.push(parseInt(ipInterfaceOctets[i], 10) & parseInt(subnetMaskOctets[i], 10)); | |
i++; | |
} | |
return new this(octets); | |
} catch (e) { | |
throw new Error("ipaddr: the address does not have IPv4 CIDR format"); | |
} | |
}; | |
ipaddr2.IPv4.parse = function(string3) { | |
const parts = this.parser(string3); | |
if (parts === null) { | |
throw new Error("ipaddr: string is not formatted like an IPv4 Address"); | |
} | |
return new this(parts); | |
}; | |
ipaddr2.IPv4.parseCIDR = function(string3) { | |
let match; | |
if (match = string3.match(/^(.+)\/(\d+)$/)) { | |
const maskLength = parseInt(match[2]); | |
if (maskLength >= 0 && maskLength <= 32) { | |
const parsed = [this.parse(match[1]), maskLength]; | |
Object.defineProperty(parsed, "toString", { | |
value: function() { | |
return this.join("/"); | |
} | |
}); | |
return parsed; | |
} | |
} | |
throw new Error("ipaddr: string is not formatted like an IPv4 CIDR range"); | |
}; | |
ipaddr2.IPv4.parser = function(string3) { | |
let match, part, value; | |
if (match = string3.match(ipv4Regexes.fourOctet)) { | |
return function() { | |
const ref = match.slice(1, 6); | |
const results = []; | |
for (let i = 0; i < ref.length; i++) { | |
part = ref[i]; | |
results.push(parseIntAuto(part)); | |
} | |
return results; | |
}(); | |
} else if (match = string3.match(ipv4Regexes.longValue)) { | |
value = parseIntAuto(match[1]); | |
if (value > 4294967295 || value < 0) { | |
throw new Error("ipaddr: address outside defined range"); | |
} | |
return function() { | |
const results = []; | |
let shift; | |
for (shift = 0; shift <= 24; shift += 8) { | |
results.push(value >> shift & 255); | |
} | |
return results; | |
}().reverse(); | |
} else if (match = string3.match(ipv4Regexes.twoOctet)) { | |
return function() { | |
const ref = match.slice(1, 4); | |
const results = []; | |
value = parseIntAuto(ref[1]); | |
if (value > 16777215 || value < 0) { | |
throw new Error("ipaddr: address outside defined range"); | |
} | |
results.push(parseIntAuto(ref[0])); | |
results.push(value >> 16 & 255); | |
results.push(value >> 8 & 255); | |
results.push(value & 255); | |
return results; | |
}(); | |
} else if (match = string3.match(ipv4Regexes.threeOctet)) { | |
return function() { | |
const ref = match.slice(1, 5); | |
const results = []; | |
value = parseIntAuto(ref[2]); | |
if (value > 65535 || value < 0) { | |
throw new Error("ipaddr: address outside defined range"); | |
} | |
results.push(parseIntAuto(ref[0])); | |
results.push(parseIntAuto(ref[1])); | |
results.push(value >> 8 & 255); | |
results.push(value & 255); | |
return results; | |
}(); | |
} else { | |
return null; | |
} | |
}; | |
ipaddr2.IPv4.subnetMaskFromPrefixLength = function(prefix) { | |
prefix = parseInt(prefix); | |
if (prefix < 0 || prefix > 32) { | |
throw new Error("ipaddr: invalid IPv4 prefix length"); | |
} | |
const octets = [0, 0, 0, 0]; | |
let j = 0; | |
const filledOctetCount = Math.floor(prefix / 8); | |
while (j < filledOctetCount) { | |
octets[j] = 255; | |
j++; | |
} | |
if (filledOctetCount < 4) { | |
octets[filledOctetCount] = Math.pow(2, prefix % 8) - 1 << 8 - prefix % 8; | |
} | |
return new this(octets); | |
}; | |
ipaddr2.IPv6 = function() { | |
function IPv6(parts, zoneId) { | |
let i, part; | |
if (parts.length === 16) { | |
this.parts = []; | |
for (i = 0; i <= 14; i += 2) { | |
this.parts.push(parts[i] << 8 | parts[i + 1]); | |
} | |
} else if (parts.length === 8) { | |
this.parts = parts; | |
} else { | |
throw new Error("ipaddr: ipv6 part count should be 8 or 16"); | |
} | |
for (i = 0; i < this.parts.length; i++) { | |
part = this.parts[i]; | |
if (!(0 <= part && part <= 65535)) { | |
throw new Error("ipaddr: ipv6 part should fit in 16 bits"); | |
} | |
} | |
if (zoneId) { | |
this.zoneId = zoneId; | |
} | |
} | |
IPv6.prototype.SpecialRanges = { | |
// RFC4291, here and after | |
unspecified: [new IPv6([0, 0, 0, 0, 0, 0, 0, 0]), 128], | |
linkLocal: [new IPv6([65152, 0, 0, 0, 0, 0, 0, 0]), 10], | |
multicast: [new IPv6([65280, 0, 0, 0, 0, 0, 0, 0]), 8], | |
loopback: [new IPv6([0, 0, 0, 0, 0, 0, 0, 1]), 128], | |
uniqueLocal: [new IPv6([64512, 0, 0, 0, 0, 0, 0, 0]), 7], | |
ipv4Mapped: [new IPv6([0, 0, 0, 0, 0, 65535, 0, 0]), 96], | |
// RFC6145 | |
rfc6145: [new IPv6([0, 0, 0, 0, 65535, 0, 0, 0]), 96], | |
// RFC6052 | |
rfc6052: [new IPv6([100, 65435, 0, 0, 0, 0, 0, 0]), 96], | |
// RFC3056 | |
"6to4": [new IPv6([8194, 0, 0, 0, 0, 0, 0, 0]), 16], | |
// RFC6052, RFC6146 | |
teredo: [new IPv6([8193, 0, 0, 0, 0, 0, 0, 0]), 32], | |
// RFC4291 | |
reserved: [[new IPv6([8193, 3512, 0, 0, 0, 0, 0, 0]), 32]], | |
benchmarking: [new IPv6([8193, 2, 0, 0, 0, 0, 0, 0]), 48], | |
amt: [new IPv6([8193, 3, 0, 0, 0, 0, 0, 0]), 32], | |
as112v6: [new IPv6([8193, 4, 274, 0, 0, 0, 0, 0]), 48], | |
deprecated: [new IPv6([8193, 16, 0, 0, 0, 0, 0, 0]), 28], | |
orchid2: [new IPv6([8193, 32, 0, 0, 0, 0, 0, 0]), 28] | |
}; | |
IPv6.prototype.isIPv4MappedAddress = function() { | |
return this.range() === "ipv4Mapped"; | |
}; | |
IPv6.prototype.kind = function() { | |
return "ipv6"; | |
}; | |
IPv6.prototype.match = function(other, cidrRange) { | |
let ref; | |
if (cidrRange === void 0) { | |
ref = other; | |
other = ref[0]; | |
cidrRange = ref[1]; | |
} | |
if (other.kind() !== "ipv6") { | |
throw new Error("ipaddr: cannot match ipv6 address with non-ipv6 one"); | |
} | |
return matchCIDR(this.parts, other.parts, 16, cidrRange); | |
}; | |
IPv6.prototype.prefixLengthFromSubnetMask = function() { | |
let cidr = 0; | |
let stop = false; | |
const zerotable = { | |
0: 16, | |
32768: 15, | |
49152: 14, | |
57344: 13, | |
61440: 12, | |
63488: 11, | |
64512: 10, | |
65024: 9, | |
65280: 8, | |
65408: 7, | |
65472: 6, | |
65504: 5, | |
65520: 4, | |
65528: 3, | |
65532: 2, | |
65534: 1, | |
65535: 0 | |
}; | |
let part, zeros; | |
for (let i = 7; i >= 0; i -= 1) { | |
part = this.parts[i]; | |
if (part in zerotable) { | |
zeros = zerotable[part]; | |
if (stop && zeros !== 0) { | |
return null; | |
} | |
if (zeros !== 16) { | |
stop = true; | |
} | |
cidr += zeros; | |
} else { | |
return null; | |
} | |
} | |
return 128 - cidr; | |
}; | |
IPv6.prototype.range = function() { | |
return ipaddr2.subnetMatch(this, this.SpecialRanges); | |
}; | |
IPv6.prototype.toByteArray = function() { | |
let part; | |
const bytes3 = []; | |
const ref = this.parts; | |
for (let i = 0; i < ref.length; i++) { | |
part = ref[i]; | |
bytes3.push(part >> 8); | |
bytes3.push(part & 255); | |
} | |
return bytes3; | |
}; | |
IPv6.prototype.toFixedLengthString = function() { | |
const addr = function() { | |
const results = []; | |
for (let i = 0; i < this.parts.length; i++) { | |
results.push(padPart(this.parts[i].toString(16), 4)); | |
} | |
return results; | |
}.call(this).join(":"); | |
let suffix = ""; | |
if (this.zoneId) { | |
suffix = `%${this.zoneId}`; | |
} | |
return addr + suffix; | |
}; | |
IPv6.prototype.toIPv4Address = function() { | |
if (!this.isIPv4MappedAddress()) { | |
throw new Error("ipaddr: trying to convert a generic ipv6 address to ipv4"); | |
} | |
const ref = this.parts.slice(-2); | |
const high = ref[0]; | |
const low = ref[1]; | |
return new ipaddr2.IPv4([high >> 8, high & 255, low >> 8, low & 255]); | |
}; | |
IPv6.prototype.toNormalizedString = function() { | |
const addr = function() { | |
const results = []; | |
for (let i = 0; i < this.parts.length; i++) { | |
results.push(this.parts[i].toString(16)); | |
} | |
return results; | |
}.call(this).join(":"); | |
let suffix = ""; | |
if (this.zoneId) { | |
suffix = `%${this.zoneId}`; | |
} | |
return addr + suffix; | |
}; | |
IPv6.prototype.toRFC5952String = function() { | |
const regex = /((^|:)(0(:|$)){2,})/g; | |
const string3 = this.toNormalizedString(); | |
let bestMatchIndex = 0; | |
let bestMatchLength = -1; | |
let match; | |
while (match = regex.exec(string3)) { | |
if (match[0].length > bestMatchLength) { | |
bestMatchIndex = match.index; | |
bestMatchLength = match[0].length; | |
} | |
} | |
if (bestMatchLength < 0) { | |
return string3; | |
} | |
return `${string3.substring(0, bestMatchIndex)}::${string3.substring(bestMatchIndex + bestMatchLength)}`; | |
}; | |
IPv6.prototype.toString = function() { | |
return this.toRFC5952String(); | |
}; | |
return IPv6; | |
}(); | |
ipaddr2.IPv6.broadcastAddressFromCIDR = function(string3) { | |
try { | |
const cidr = this.parseCIDR(string3); | |
const ipInterfaceOctets = cidr[0].toByteArray(); | |
const subnetMaskOctets = this.subnetMaskFromPrefixLength(cidr[1]).toByteArray(); | |
const octets = []; | |
let i = 0; | |
while (i < 16) { | |
octets.push(parseInt(ipInterfaceOctets[i], 10) | parseInt(subnetMaskOctets[i], 10) ^ 255); | |
i++; | |
} | |
return new this(octets); | |
} catch (e) { | |
throw new Error(`ipaddr: the address does not have IPv6 CIDR format (${e})`); | |
} | |
}; | |
ipaddr2.IPv6.isIPv6 = function(string3) { | |
return this.parser(string3) !== null; | |
}; | |
ipaddr2.IPv6.isValid = function(string3) { | |
if (typeof string3 === "string" && string3.indexOf(":") === -1) { | |
return false; | |
} | |
try { | |
const addr = this.parser(string3); | |
new this(addr.parts, addr.zoneId); | |
return true; | |
} catch (e) { | |
return false; | |
} | |
}; | |
ipaddr2.IPv6.networkAddressFromCIDR = function(string3) { | |
let cidr, i, ipInterfaceOctets, octets, subnetMaskOctets; | |
try { | |
cidr = this.parseCIDR(string3); | |
ipInterfaceOctets = cidr[0].toByteArray(); | |
subnetMaskOctets = this.subnetMaskFromPrefixLength(cidr[1]).toByteArray(); | |
octets = []; | |
i = 0; | |
while (i < 16) { | |
octets.push(parseInt(ipInterfaceOctets[i], 10) & parseInt(subnetMaskOctets[i], 10)); | |
i++; | |
} | |
return new this(octets); | |
} catch (e) { | |
throw new Error(`ipaddr: the address does not have IPv6 CIDR format (${e})`); | |
} | |
}; | |
ipaddr2.IPv6.parse = function(string3) { | |
const addr = this.parser(string3); | |
if (addr.parts === null) { | |
throw new Error("ipaddr: string is not formatted like an IPv6 Address"); | |
} | |
return new this(addr.parts, addr.zoneId); | |
}; | |
ipaddr2.IPv6.parseCIDR = function(string3) { | |
let maskLength, match, parsed; | |
if (match = string3.match(/^(.+)\/(\d+)$/)) { | |
maskLength = parseInt(match[2]); | |
if (maskLength >= 0 && maskLength <= 128) { | |
parsed = [this.parse(match[1]), maskLength]; | |
Object.defineProperty(parsed, "toString", { | |
value: function() { | |
return this.join("/"); | |
} | |
}); | |
return parsed; | |
} | |
} | |
throw new Error("ipaddr: string is not formatted like an IPv6 CIDR range"); | |
}; | |
ipaddr2.IPv6.parser = function(string3) { | |
let addr, i, match, octet, octets, zoneId; | |
if (match = string3.match(ipv6Regexes.deprecatedTransitional)) { | |
return this.parser(`::ffff:${match[1]}`); | |
} | |
if (ipv6Regexes.native.test(string3)) { | |
return expandIPv6(string3, 8); | |
} | |
if (match = string3.match(ipv6Regexes.transitional)) { | |
zoneId = match[6] || ""; | |
addr = expandIPv6(match[1].slice(0, -1) + zoneId, 6); | |
if (addr.parts) { | |
octets = [ | |
parseInt(match[2]), | |
parseInt(match[3]), | |
parseInt(match[4]), | |
parseInt(match[5]) | |
]; | |
for (i = 0; i < octets.length; i++) { | |
octet = octets[i]; | |
if (!(0 <= octet && octet <= 255)) { | |
return null; | |
} | |
} | |
addr.parts.push(octets[0] << 8 | octets[1]); | |
addr.parts.push(octets[2] << 8 | octets[3]); | |
return { | |
parts: addr.parts, | |
zoneId: addr.zoneId | |
}; | |
} | |
} | |
return null; | |
}; | |
ipaddr2.IPv6.subnetMaskFromPrefixLength = function(prefix) { | |
prefix = parseInt(prefix); | |
if (prefix < 0 || prefix > 128) { | |
throw new Error("ipaddr: invalid IPv6 prefix length"); | |
} | |
const octets = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; | |
let j = 0; | |
const filledOctetCount = Math.floor(prefix / 8); | |
while (j < filledOctetCount) { | |
octets[j] = 255; | |
j++; | |
} | |
if (filledOctetCount < 16) { | |
octets[filledOctetCount] = Math.pow(2, prefix % 8) - 1 << 8 - prefix % 8; | |
} | |
return new this(octets); | |
}; | |
ipaddr2.fromByteArray = function(bytes3) { | |
const length11 = bytes3.length; | |
if (length11 === 4) { | |
return new ipaddr2.IPv4(bytes3); | |
} else if (length11 === 16) { | |
return new ipaddr2.IPv6(bytes3); | |
} else { | |
throw new Error("ipaddr: the binary input is neither an IPv6 nor IPv4 address"); | |
} | |
}; | |
ipaddr2.isValid = function(string3) { | |
return ipaddr2.IPv6.isValid(string3) || ipaddr2.IPv4.isValid(string3); | |
}; | |
ipaddr2.parse = function(string3) { | |
if (ipaddr2.IPv6.isValid(string3)) { | |
return ipaddr2.IPv6.parse(string3); | |
} else if (ipaddr2.IPv4.isValid(string3)) { | |
return ipaddr2.IPv4.parse(string3); | |
} else { | |
throw new Error("ipaddr: the address has neither IPv6 nor IPv4 format"); | |
} | |
}; | |
ipaddr2.parseCIDR = function(string3) { | |
try { | |
return ipaddr2.IPv6.parseCIDR(string3); | |
} catch (e) { | |
try { | |
return ipaddr2.IPv4.parseCIDR(string3); | |
} catch (e2) { | |
throw new Error("ipaddr: the address has neither IPv6 nor IPv4 CIDR format"); | |
} | |
} | |
}; | |
ipaddr2.process = function(string3) { | |
const addr = this.parse(string3); | |
if (addr.kind() === "ipv6" && addr.isIPv4MappedAddress()) { | |
return addr.toIPv4Address(); | |
} else { | |
return addr; | |
} | |
}; | |
ipaddr2.subnetMatch = function(address, rangeList, defaultName) { | |
let i, rangeName, rangeSubnets, subnet; | |
if (defaultName === void 0 || defaultName === null) { | |
defaultName = "unicast"; | |
} | |
for (rangeName in rangeList) { | |
if (Object.prototype.hasOwnProperty.call(rangeList, rangeName)) { | |
rangeSubnets = rangeList[rangeName]; | |
if (rangeSubnets[0] && !(rangeSubnets[0] instanceof Array)) { | |
rangeSubnets = [rangeSubnets]; | |
} | |
for (i = 0; i < rangeSubnets.length; i++) { | |
subnet = rangeSubnets[i]; | |
if (address.kind() === subnet[0].kind() && address.match.apply(address, subnet)) { | |
return rangeName; | |
} | |
} | |
} | |
} | |
return defaultName; | |
}; | |
if (typeof module2 !== "undefined" && module2.exports) { | |
module2.exports = ipaddr2; | |
} else { | |
root.ipaddr = ipaddr2; | |
} | |
})(exports2); | |
} | |
}); | |
// node_modules/receptacle/index.js | |
var require_receptacle = __commonJS({ | |
"node_modules/receptacle/index.js"(exports2, module2) { | |
"use strict"; | |
module2.exports = Receptacle2; | |
var toMS = require_ms(); | |
var cache10 = Receptacle2.prototype; | |
var counter = /* @__PURE__ */ new Date() % 1e9; | |
function getUID() { | |
return (Math.random() * 1e9 >>> 0) + counter++; | |
} | |
function Receptacle2(options) { | |
options = options || {}; | |
this.id = options.id || getUID(); | |
this.max = options.max || Infinity; | |
this.items = options.items || []; | |
this._lookup = {}; | |
this.size = this.items.length; | |
this.lastModified = new Date(options.lastModified || /* @__PURE__ */ new Date()); | |
for (var item, ttl, i = this.items.length; i--; ) { | |
item = this.items[i]; | |
ttl = new Date(item.expires) - /* @__PURE__ */ new Date(); | |
this._lookup[item.key] = item; | |
if (ttl > 0) | |
this.expire(item.key, ttl); | |
else if (ttl <= 0) | |
this.delete(item.key); | |
} | |
} | |
cache10.has = function(key) { | |
return key in this._lookup; | |
}; | |
cache10.get = function(key) { | |
if (!this.has(key)) | |
return null; | |
var record = this._lookup[key]; | |
if (record.refresh) | |
this.expire(key, record.refresh); | |
this.items.splice(this.items.indexOf(record), 1); | |
this.items.push(record); | |
return record.value; | |
}; | |
cache10.meta = function(key) { | |
if (!this.has(key)) | |
return null; | |
var record = this._lookup[key]; | |
if (!("meta" in record)) | |
return null; | |
return record.meta; | |
}; | |
cache10.set = function(key, value, options) { | |
var oldRecord = this._lookup[key]; | |
var record = this._lookup[key] = { key, value }; | |
this.lastModified = /* @__PURE__ */ new Date(); | |
if (oldRecord) { | |
clearTimeout(oldRecord.timeout); | |
this.items.splice(this.items.indexOf(oldRecord), 1, record); | |
} else { | |
if (this.size >= this.max) | |
this.delete(this.items[0].key); | |
this.items.push(record); | |
this.size++; | |
} | |
if (options) { | |
if ("ttl" in options) | |
this.expire(key, options.ttl); | |
if ("meta" in options) | |
record.meta = options.meta; | |
if (options.refresh) | |
record.refresh = options.ttl; | |
} | |
return this; | |
}; | |
cache10.delete = function(key) { | |
var record = this._lookup[key]; | |
if (!record) | |
return false; | |
this.lastModified = /* @__PURE__ */ new Date(); | |
this.items.splice(this.items.indexOf(record), 1); | |
clearTimeout(record.timeout); | |
delete this._lookup[key]; | |
this.size--; | |
return this; | |
}; | |
cache10.expire = function(key, ttl) { | |
var ms = ttl || 0; | |
var record = this._lookup[key]; | |
if (!record) | |
return this; | |
if (typeof ms === "string") | |
ms = toMS(ttl); | |
if (typeof ms !== "number") | |
throw new TypeError("Expiration time must be a string or number."); | |
clearTimeout(record.timeout); | |
record.timeout = setTimeout(this.delete.bind(this, record.key), ms); | |
record.expires = Number(/* @__PURE__ */ new Date()) + ms; | |
return this; | |
}; | |
cache10.clear = function() { | |
for (var i = this.items.length; i--; ) | |
this.delete(this.items[i].key); | |
return this; | |
}; | |
cache10.toJSON = function() { | |
var items = new Array(this.items.length); | |
var item; | |
for (var i = items.length; i--; ) { | |
item = this.items[i]; | |
items[i] = { | |
key: item.key, | |
meta: item.meta, | |
value: item.value, | |
expires: item.expires, | |
refresh: item.refresh | |
}; | |
} | |
return { | |
id: this.id, | |
max: isFinite(this.max) ? this.max : void 0, | |
lastModified: this.lastModified, | |
items | |
}; | |
}; | |
} | |
}); | |
// node_modules/rate-limiter-flexible/lib/RateLimiterAbstract.js | |
var require_RateLimiterAbstract = __commonJS({ | |
"node_modules/rate-limiter-flexible/lib/RateLimiterAbstract.js"(exports2, module2) { | |
module2.exports = class RateLimiterAbstract { | |
/** | |
* | |
* @param opts Object Defaults { | |
* points: 4, // Number of points | |
* duration: 1, // Per seconds | |
* blockDuration: 0, // Block if consumed more than points in current duration for blockDuration seconds | |
* execEvenly: false, // Execute allowed actions evenly over duration | |
* execEvenlyMinDelayMs: duration * 1000 / points, // ms, works with execEvenly=true option | |
* keyPrefix: 'rlflx', | |
* } | |
*/ | |
constructor(opts = {}) { | |
this.points = opts.points; | |
this.duration = opts.duration; | |
this.blockDuration = opts.blockDuration; | |
this.execEvenly = opts.execEvenly; | |
this.execEvenlyMinDelayMs = opts.execEvenlyMinDelayMs; | |
this.keyPrefix = opts.keyPrefix; | |
} | |
get points() { | |
return this._points; | |
} | |
set points(value) { | |
this._points = value >= 0 ? value : 4; | |
} | |
get duration() { | |
return this._duration; | |
} | |
set duration(value) { | |
this._duration = typeof value === "undefined" ? 1 : value; | |
} | |
get msDuration() { | |
return this.duration * 1e3; | |
} | |
get blockDuration() { | |
return this._blockDuration; | |
} | |
set blockDuration(value) { | |
this._blockDuration = typeof value === "undefined" ? 0 : value; | |
} | |
get msBlockDuration() { | |
return this.blockDuration * 1e3; | |
} | |
get execEvenly() { | |
return this._execEvenly; | |
} | |
set execEvenly(value) { | |
this._execEvenly = typeof value === "undefined" ? false : Boolean(value); | |
} | |
get execEvenlyMinDelayMs() { | |
return this._execEvenlyMinDelayMs; | |
} | |
set execEvenlyMinDelayMs(value) { | |
this._execEvenlyMinDelayMs = typeof value === "undefined" ? Math.ceil(this.msDuration / this.points) : value; | |
} | |
get keyPrefix() { | |
return this._keyPrefix; | |
} | |
set keyPrefix(value) { | |
if (typeof value === "undefined") { | |
value = "rlflx"; | |
} | |
if (typeof value !== "string") { | |
throw new Error("keyPrefix must be string"); | |
} | |
this._keyPrefix = value; | |
} | |
_getKeySecDuration(options = {}) { | |
return options && options.customDuration >= 0 ? options.customDuration : this.duration; | |
} | |
getKey(key) { | |
return this.keyPrefix.length > 0 ? `${this.keyPrefix}:${key}` : key; | |
} | |
parseKey(rlKey) { | |
return rlKey.substring(this.keyPrefix.length); | |
} | |
consume() { | |
throw new Error("You have to implement the method 'consume'!"); | |
} | |
penalty() { | |
throw new Error("You have to implement the method 'penalty'!"); | |
} | |
reward() { | |
throw new Error("You have to implement the method 'reward'!"); | |
} | |
get() { | |
throw new Error("You have to implement the method 'get'!"); | |
} | |
set() { | |
throw new Error("You have to implement the method 'set'!"); | |
} | |
block() { | |
throw new Error("You have to implement the method 'block'!"); | |
} | |
delete() { | |
throw new Error("You have to implement the method 'delete'!"); | |
} | |
}; | |
} | |
}); | |
// node_modules/rate-limiter-flexible/lib/component/BlockedKeys/BlockedKeys.js | |
var require_BlockedKeys = __commonJS({ | |
"node_modules/rate-limiter-flexible/lib/component/BlockedKeys/BlockedKeys.js"(exports2, module2) { | |
module2.exports = class BlockedKeys { | |
constructor() { | |
this._keys = {}; | |
this._addedKeysAmount = 0; | |
} | |
collectExpired() { | |
const now = Date.now(); | |
Object.keys(this._keys).forEach((key) => { | |
if (this._keys[key] <= now) { | |
delete this._keys[key]; | |
} | |
}); | |
this._addedKeysAmount = Object.keys(this._keys).length; | |
} | |
/** | |
* Add new blocked key | |
* | |
* @param key String | |
* @param sec Number | |
*/ | |
add(key, sec) { | |
this.addMs(key, sec * 1e3); | |
} | |
/** | |
* Add new blocked key for ms | |
* | |
* @param key String | |
* @param ms Number | |
*/ | |
addMs(key, ms) { | |
this._keys[key] = Date.now() + ms; | |
this._addedKeysAmount++; | |
if (this._addedKeysAmount > 999) { | |
this.collectExpired(); | |
} | |
} | |
/** | |
* 0 means not blocked | |
* | |
* @param key | |
* @returns {number} | |
*/ | |
msBeforeExpire(key) { | |
const expire = this._keys[key]; | |
if (expire && expire >= Date.now()) { | |
this.collectExpired(); | |
const now = Date.now(); | |
return expire >= now ? expire - now : 0; | |
} | |
return 0; | |
} | |
/** | |
* If key is not given, delete all data in memory | |
* | |
* @param {string|undefined} key | |
*/ | |
delete(key) { | |
if (key) { | |
delete this._keys[key]; | |
} else { | |
Object.keys(this._keys).forEach((key2) => { | |
delete this._keys[key2]; | |
}); | |
} | |
} | |
}; | |
} | |
}); | |
// node_modules/rate-limiter-flexible/lib/component/BlockedKeys/index.js | |
var require_BlockedKeys2 = __commonJS({ | |
"node_modules/rate-limiter-flexible/lib/component/BlockedKeys/index.js"(exports2, module2) { | |
var BlockedKeys = require_BlockedKeys(); | |
module2.exports = BlockedKeys; | |
} | |
}); | |
// node_modules/rate-limiter-flexible/lib/RateLimiterRes.js | |
var require_RateLimiterRes = __commonJS({ | |
"node_modules/rate-limiter-flexible/lib/RateLimiterRes.js"(exports2, module2) { | |
module2.exports = class RateLimiterRes { | |
constructor(remainingPoints, msBeforeNext, consumedPoints, isFirstInDuration) { | |
this.remainingPoints = typeof remainingPoints === "undefined" ? 0 : remainingPoints; | |
this.msBeforeNext = typeof msBeforeNext === "undefined" ? 0 : msBeforeNext; | |
this.consumedPoints = typeof consumedPoints === "undefined" ? 0 : consumedPoints; | |
this.isFirstInDuration = typeof isFirstInDuration === "undefined" ? false : isFirstInDuration; | |
} | |
get msBeforeNext() { | |
return this._msBeforeNext; | |
} | |
set msBeforeNext(ms) { | |
this._msBeforeNext = ms; | |
return this; | |
} | |
get remainingPoints() { | |
return this._remainingPoints; | |
} | |
set remainingPoints(p) { | |
this._remainingPoints = p; | |
return this; | |
} | |
get consumedPoints() { | |
return this._consumedPoints; | |
} | |
set consumedPoints(p) { | |
this._consumedPoints = p; | |
return this; | |
} | |
get isFirstInDuration() { | |
return this._isFirstInDuration; | |
} | |
set isFirstInDuration(value) { | |
this._isFirstInDuration = Boolean(value); | |
} | |
_getDecoratedProperties() { | |
return { | |
remainingPoints: this.remainingPoints, | |
msBeforeNext: this.msBeforeNext, | |
consumedPoints: this.consumedPoints, | |
isFirstInDuration: this.isFirstInDuration | |
}; | |
} | |
[Symbol.for("nodejs.util.inspect.custom")]() { | |
return this._getDecoratedProperties(); | |
} | |
toString() { | |
return JSON.stringify(this._getDecoratedProperties()); | |
} | |
toJSON() { | |
return this._getDecoratedProperties(); | |
} | |
}; | |
} | |
}); | |
// node_modules/rate-limiter-flexible/lib/RateLimiterStoreAbstract.js | |
var require_RateLimiterStoreAbstract = __commonJS({ | |
"node_modules/rate-limiter-flexible/lib/RateLimiterStoreAbstract.js"(exports2, module2) { | |
var RateLimiterAbstract = require_RateLimiterAbstract(); | |
var BlockedKeys = require_BlockedKeys2(); | |
var RateLimiterRes = require_RateLimiterRes(); | |
module2.exports = class RateLimiterStoreAbstract extends RateLimiterAbstract { | |
/** | |
* | |
* @param opts Object Defaults { | |
* ... see other in RateLimiterAbstract | |
* | |
* inMemoryBlockOnConsumed: 40, // Number of points when key is blocked | |
* inMemoryBlockDuration: 10, // Block duration in seconds | |
* insuranceLimiter: RateLimiterAbstract | |
* } | |
*/ | |
constructor(opts = {}) { | |
super(opts); | |
this.inMemoryBlockOnConsumed = opts.inMemoryBlockOnConsumed || opts.inmemoryBlockOnConsumed; | |
this.inMemoryBlockDuration = opts.inMemoryBlockDuration || opts.inmemoryBlockDuration; | |
this.insuranceLimiter = opts.insuranceLimiter; | |
this._inMemoryBlockedKeys = new BlockedKeys(); | |
} | |
get client() { | |
return this._client; | |
} | |
set client(value) { | |
if (typeof value === "undefined") { | |
throw new Error("storeClient is not set"); | |
} | |
this._client = value; | |
} | |
/** | |
* Have to be launched after consume | |
* It blocks key and execute evenly depending on result from store | |
* | |
* It uses _getRateLimiterRes function to prepare RateLimiterRes from store result | |
* | |
* @param resolve | |
* @param reject | |
* @param rlKey | |
* @param changedPoints | |
* @param storeResult | |
* @param {Object} options | |
* @private | |
*/ | |
_afterConsume(resolve6, reject, rlKey, changedPoints, storeResult, options = {}) { | |
const res = this._getRateLimiterRes(rlKey, changedPoints, storeResult); | |
if (this.inMemoryBlockOnConsumed > 0 && !(this.inMemoryBlockDuration > 0) && res.consumedPoints >= this.inMemoryBlockOnConsumed) { | |
this._inMemoryBlockedKeys.addMs(rlKey, res.msBeforeNext); | |
if (res.consumedPoints > this.points) { | |
return reject(res); | |
} else { | |
return resolve6(res); | |
} | |
} else if (res.consumedPoints > this.points) { | |
let blockPromise = Promise.resolve(); | |
if (this.blockDuration > 0 && res.consumedPoints <= this.points + changedPoints) { | |
res.msBeforeNext = this.msBlockDuration; | |
blockPromise = this._block(rlKey, res.consumedPoints, this.msBlockDuration, options); | |
} | |
if (this.inMemoryBlockOnConsumed > 0 && res.consumedPoints >= this.inMemoryBlockOnConsumed) { | |
this._inMemoryBlockedKeys.add(rlKey, this.inMemoryBlockDuration); | |
res.msBeforeNext = this.msInMemoryBlockDuration; | |
} | |
blockPromise.then(() => { | |
reject(res); | |
}).catch((err) => { | |
reject(err); | |
}); | |
} else if (this.execEvenly && res.msBeforeNext > 0 && !res.isFirstInDuration) { | |
let delay = Math.ceil(res.msBeforeNext / (res.remainingPoints + 2)); | |
if (delay < this.execEvenlyMinDelayMs) { | |
delay = res.consumedPoints * this.execEvenlyMinDelayMs; | |
} | |
setTimeout(resolve6, delay, res); | |
} else { | |
resolve6(res); | |
} | |
} | |
_handleError(err, funcName, resolve6, reject, key, data = false, options = {}) { | |
if (!(this.insuranceLimiter instanceof RateLimiterAbstract)) { | |
reject(err); | |
} else { | |
this.insuranceLimiter[funcName](key, data, options).then((res) => { | |
resolve6(res); | |
}).catch((res) => { | |
reject(res); | |
}); | |
} | |
} | |
/** | |
* @deprecated Use camelCase version | |
* @returns {BlockedKeys} | |
* @private | |
*/ | |
get _inmemoryBlockedKeys() { | |
return this._inMemoryBlockedKeys; | |
} | |
/** | |
* @deprecated Use camelCase version | |
* @param rlKey | |
* @returns {number} | |
*/ | |
getInmemoryBlockMsBeforeExpire(rlKey) { | |
return this.getInMemoryBlockMsBeforeExpire(rlKey); | |
} | |
/** | |
* @deprecated Use camelCase version | |
* @returns {number|number} | |
*/ | |
get inmemoryBlockOnConsumed() { | |
return this.inMemoryBlockOnConsumed; | |
} | |
/** | |
* @deprecated Use camelCase version | |
* @param value | |
*/ | |
set inmemoryBlockOnConsumed(value) { | |
this.inMemoryBlockOnConsumed = value; | |
} | |
/** | |
* @deprecated Use camelCase version | |
* @returns {number|number} | |
*/ | |
get inmemoryBlockDuration() { | |
return this.inMemoryBlockDuration; | |
} | |
/** | |
* @deprecated Use camelCase version | |
* @param value | |
*/ | |
set inmemoryBlockDuration(value) { | |
this.inMemoryBlockDuration = value; | |
} | |
/** | |
* @deprecated Use camelCase version | |
* @returns {number} | |
*/ | |
get msInmemoryBlockDuration() { | |
return this.inMemoryBlockDuration * 1e3; | |
} | |
getInMemoryBlockMsBeforeExpire(rlKey) { | |
if (this.inMemoryBlockOnConsumed > 0) { | |
return this._inMemoryBlockedKeys.msBeforeExpire(rlKey); | |
} | |
return 0; | |
} | |
get inMemoryBlockOnConsumed() { | |
return this._inMemoryBlockOnConsumed; | |
} | |
set inMemoryBlockOnConsumed(value) { | |
this._inMemoryBlockOnConsumed = value ? parseInt(value) : 0; | |
if (this.inMemoryBlockOnConsumed > 0 && this.points > this.inMemoryBlockOnConsumed) { | |
throw new Error('inMemoryBlockOnConsumed option must be greater or equal "points" option'); | |
} | |
} | |
get inMemoryBlockDuration() { | |
return this._inMemoryBlockDuration; | |
} | |
set inMemoryBlockDuration(value) { | |
this._inMemoryBlockDuration = value ? parseInt(value) : 0; | |
if (this.inMemoryBlockDuration > 0 && this.inMemoryBlockOnConsumed === 0) { | |
throw new Error("inMemoryBlockOnConsumed option must be set up"); | |
} | |
} | |
get msInMemoryBlockDuration() { | |
return this._inMemoryBlockDuration * 1e3; | |
} | |
get insuranceLimiter() { | |
return this._insuranceLimiter; | |
} | |
set insuranceLimiter(value) { | |
if (typeof value !== "undefined" && !(value instanceof RateLimiterAbstract)) { | |
throw new Error("insuranceLimiter must be instance of RateLimiterAbstract"); | |
} | |
this._insuranceLimiter = value; | |
if (this._insuranceLimiter) { | |
this._insuranceLimiter.blockDuration = this.blockDuration; | |
this._insuranceLimiter.execEvenly = this.execEvenly; | |
} | |
} | |
/** | |
* Block any key for secDuration seconds | |
* | |
* @param key | |
* @param secDuration | |
* @param {Object} options | |
* | |
* @return Promise<RateLimiterRes> | |
*/ | |
block(key, secDuration, options = {}) { | |
const msDuration = secDuration * 1e3; | |
return this._block(this.getKey(key), this.points + 1, msDuration, options); | |
} | |
/** | |
* Set points by key for any duration | |
* | |
* @param key | |
* @param points | |
* @param secDuration | |
* @param {Object} options | |
* | |
* @return Promise<RateLimiterRes> | |
*/ | |
set(key, points, secDuration, options = {}) { | |
const msDuration = (secDuration >= 0 ? secDuration : this.duration) * 1e3; | |
return this._block(this.getKey(key), points, msDuration, options); | |
} | |
/** | |
* | |
* @param key | |
* @param pointsToConsume | |
* @param {Object} options | |
* @returns Promise<RateLimiterRes> | |
*/ | |
consume(key, pointsToConsume = 1, options = {}) { | |
return new Promise((resolve6, reject) => { | |
const rlKey = this.getKey(key); | |
const inMemoryBlockMsBeforeExpire = this.getInMemoryBlockMsBeforeExpire(rlKey); | |
if (inMemoryBlockMsBeforeExpire > 0) { | |
return reject(new RateLimiterRes(0, inMemoryBlockMsBeforeExpire)); | |
} | |
this._upsert(rlKey, pointsToConsume, this._getKeySecDuration(options) * 1e3, false, options).then((res) => { | |
this._afterConsume(resolve6, reject, rlKey, pointsToConsume, res); | |
}).catch((err) => { | |
this._handleError(err, "consume", resolve6, reject, key, pointsToConsume, options); | |
}); | |
}); | |
} | |
/** | |
* | |
* @param key | |
* @param points | |
* @param {Object} options | |
* @returns Promise<RateLimiterRes> | |
*/ | |
penalty(key, points = 1, options = {}) { | |
const rlKey = this.getKey(key); | |
return new Promise((resolve6, reject) => { | |
this._upsert(rlKey, points, this._getKeySecDuration(options) * 1e3, false, options).then((res) => { | |
resolve6(this._getRateLimiterRes(rlKey, points, res)); | |
}).catch((err) => { | |
this._handleError(err, "penalty", resolve6, reject, key, points, options); | |
}); | |
}); | |
} | |
/** | |
* | |
* @param key | |
* @param points | |
* @param {Object} options | |
* @returns Promise<RateLimiterRes> | |
*/ | |
reward(key, points = 1, options = {}) { | |
const rlKey = this.getKey(key); | |
return new Promise((resolve6, reject) => { | |
this._upsert(rlKey, -points, this._getKeySecDuration(options) * 1e3, false, options).then((res) => { | |
resolve6(this._getRateLimiterRes(rlKey, -points, res)); | |
}).catch((err) => { | |
this._handleError(err, "reward", resolve6, reject, key, points, options); | |
}); | |
}); | |
} | |
/** | |
* | |
* @param key | |
* @param {Object} options | |
* @returns Promise<RateLimiterRes>|null | |
*/ | |
get(key, options = {}) { | |
const rlKey = this.getKey(key); | |
return new Promise((resolve6, reject) => { | |
this._get(rlKey, options).then((res) => { | |
if (res === null || typeof res === "undefined") { | |
resolve6(null); | |
} else { | |
resolve6(this._getRateLimiterRes(rlKey, 0, res)); | |
} | |
}).catch((err) => { | |
this._handleError(err, "get", resolve6, reject, key, options); | |
}); | |
}); | |
} | |
/** | |
* | |
* @param key | |
* @param {Object} options | |
* @returns Promise<boolean> | |
*/ | |
delete(key, options = {}) { | |
const rlKey = this.getKey(key); | |
return new Promise((resolve6, reject) => { | |
this._delete(rlKey, options).then((res) => { | |
this._inMemoryBlockedKeys.delete(rlKey); | |
resolve6(res); | |
}).catch((err) => { | |
this._handleError(err, "delete", resolve6, reject, key, options); | |
}); | |
}); | |
} | |
/** | |
* Cleanup keys no-matter expired or not. | |
*/ | |
deleteInMemoryBlockedAll() { | |
this._inMemoryBlockedKeys.delete(); | |
} | |
/** | |
* Get RateLimiterRes object filled depending on storeResult, which specific for exact store | |
* | |
* @param rlKey | |
* @param changedPoints | |
* @param storeResult | |
* @private | |
*/ | |
_getRateLimiterRes(rlKey, changedPoints, storeResult) { | |
throw new Error("You have to implement the method '_getRateLimiterRes'!"); | |
} | |
/** | |
* Block key for this.msBlockDuration milliseconds | |
* Usually, it just prolongs lifetime of key | |
* | |
* @param rlKey | |
* @param initPoints | |
* @param msDuration | |
* @param {Object} options | |
* | |
* @return Promise<any> | |
*/ | |
_block(rlKey, initPoints, msDuration, options = {}) { | |
return new Promise((resolve6, reject) => { | |
this._upsert(rlKey, initPoints, msDuration, true, options).then(() => { | |
resolve6(new RateLimiterRes(0, msDuration > 0 ? msDuration : -1, initPoints)); | |
}).catch((err) => { | |
this._handleError(err, "block", resolve6, reject, this.parseKey(rlKey), msDuration / 1e3, options); | |
}); | |
}); | |
} | |
/** | |
* Have to be implemented in every limiter | |
* Resolve with raw result from Store OR null if rlKey is not set | |
* or Reject with error | |
* | |
* @param rlKey | |
* @param {Object} options | |
* @private | |
* | |
* @return Promise<any> | |
*/ | |
_get(rlKey, options = {}) { | |
throw new Error("You have to implement the method '_get'!"); | |
} | |
/** | |
* Have to be implemented | |
* Resolve with true OR false if rlKey doesn't exist | |
* or Reject with error | |
* | |
* @param rlKey | |
* @param {Object} options | |
* @private | |
* | |
* @return Promise<any> | |
*/ | |
_delete(rlKey, options = {}) { | |
throw new Error("You have to implement the method '_delete'!"); | |
} | |
/** | |
* Have to be implemented | |
* Resolve with object used for {@link _getRateLimiterRes} to generate {@link RateLimiterRes} | |
* | |
* @param {string} rlKey | |
* @param {number} points | |
* @param {number} msDuration | |
* @param {boolean} forceExpire | |
* @param {Object} options | |
* @abstract | |
* | |
* @return Promise<Object> | |
*/ | |
_upsert(rlKey, points, msDuration, forceExpire = false, options = {}) { | |
throw new Error("You have to implement the method '_upsert'!"); | |
} | |
}; | |
} | |
}); | |
// node_modules/rate-limiter-flexible/lib/RateLimiterRedis.js | |
var require_RateLimiterRedis = __commonJS({ | |
"node_modules/rate-limiter-flexible/lib/RateLimiterRedis.js"(exports2, module2) { | |
var RateLimiterStoreAbstract = require_RateLimiterStoreAbstract(); | |
var RateLimiterRes = require_RateLimiterRes(); | |
var incrTtlLuaScript = `redis.call('set', KEYS[1], 0, 'EX', ARGV[2], 'NX') local consumed = redis.call('incrby', KEYS[1], ARGV[1]) local ttl = redis.call('pttl', KEYS[1]) if ttl == -1 then redis.call('expire', KEYS[1], ARGV[2]) ttl = 1000 * ARGV[2] end return {consumed, ttl} `; | |
var RateLimiterRedis = class extends RateLimiterStoreAbstract { | |
/** | |
* | |
* @param {Object} opts | |
* Defaults { | |
* ... see other in RateLimiterStoreAbstract | |
* | |
* redis: RedisClient | |
* rejectIfRedisNotReady: boolean = false - reject / invoke insuranceLimiter immediately when redis connection is not "ready" | |
* } | |
*/ | |
constructor(opts) { | |
super(opts); | |
if (opts.redis) { | |
this.client = opts.redis; | |
} else { | |
this.client = opts.storeClient; | |
} | |
this._rejectIfRedisNotReady = !!opts.rejectIfRedisNotReady; | |
if (typeof this.client.defineCommand === "function") { | |
this.client.defineCommand("rlflxIncr", { | |
numberOfKeys: 1, | |
lua: incrTtlLuaScript | |
}); | |
} | |
} | |
/** | |
* Prevent actual redis call if redis connection is not ready | |
* Because of different connection state checks for ioredis and node-redis, only this clients would be actually checked. | |
* For any other clients all the requests would be passed directly to redis client | |
* @return {boolean} | |
* @private | |
*/ | |
_isRedisReady() { | |
if (!this._rejectIfRedisNotReady) { | |
return true; | |
} | |
if (this.client.status && this.client.status !== "ready") { | |
return false; | |
} | |
if (typeof this.client.isReady === "function" && !this.client.isReady()) { | |
return false; | |
} | |
return true; | |
} | |
_getRateLimiterRes(rlKey, changedPoints, result) { | |
let [consumed, resTtlMs] = result; | |
if (Array.isArray(consumed)) { | |
[, consumed] = consumed; | |
[, resTtlMs] = resTtlMs; | |
} | |
const res = new RateLimiterRes(); | |
res.consumedPoints = parseInt(consumed); | |
res.isFirstInDuration = res.consumedPoints === changedPoints; | |
res.remainingPoints = Math.max(this.points - res.consumedPoints, 0); | |
res.msBeforeNext = resTtlMs; | |
return res; | |
} | |
_upsert(rlKey, points, msDuration, forceExpire = false) { | |
return new Promise((resolve6, reject) => { | |
if (!this._isRedisReady()) { | |
return reject(new Error("Redis connection is not ready")); | |
} | |
const secDuration = Math.floor(msDuration / 1e3); | |
const multi = this.client.multi(); | |
if (forceExpire) { | |
if (secDuration > 0) { | |
multi.set(rlKey, points, "EX", secDuration); | |
} else { | |
multi.set(rlKey, points); | |
} | |
multi.pttl(rlKey).exec((err, res) => { | |
if (err) { | |
return reject(err); | |
} | |
return resolve6(res); | |
}); | |
} else { | |
if (secDuration > 0) { | |
const incrCallback = function(err, result) { | |
if (err) { | |
return reject(err); | |
} | |
return resolve6(result); | |
}; | |
if (typeof this.client.rlflxIncr === "function") { | |
this.client.rlflxIncr(rlKey, points, secDuration, incrCallback); | |
} else { | |
this.client.eval(incrTtlLuaScript, 1, rlKey, points, secDuration, incrCallback); | |
} | |
} else { | |
multi.incrby(rlKey, points).pttl(rlKey).exec((err, res) => { | |
if (err) { | |
return reject(err); | |
} | |
return resolve6(res); | |
}); | |
} | |
} | |
}); | |
} | |
_get(rlKey) { | |
return new Promise((resolve6, reject) => { | |
if (!this._isRedisReady()) { | |
return reject(new Error("Redis connection is not ready")); | |
} | |
this.client.multi().get(rlKey).pttl(rlKey).exec((err, res) => { | |
if (err) { | |
reject(err); | |
} else { | |
const [points] = res; | |
if (points === null) { | |
return resolve6(null); | |
} | |
resolve6(res); | |
} | |
}); | |
}); | |
} | |
_delete(rlKey) { | |
return new Promise((resolve6, reject) => { | |
this.client.del(rlKey, (err, res) => { | |
if (err) { | |
reject(err); | |
} else { | |
resolve6(res > 0); | |
} | |
}); | |
}); | |
} | |
}; | |
module2.exports = RateLimiterRedis; | |
} | |
}); | |
// node_modules/rate-limiter-flexible/lib/RateLimiterMongo.js | |
var require_RateLimiterMongo = __commonJS({ | |
"node_modules/rate-limiter-flexible/lib/RateLimiterMongo.js"(exports2, module2) { | |
var RateLimiterStoreAbstract = require_RateLimiterStoreAbstract(); | |
var RateLimiterRes = require_RateLimiterRes(); | |
function getDriverVersion(client) { | |
try { | |
const _client = client.client ? client.client : client; | |
const { version: version4 } = _client.topology.s.options.metadata.driver; | |
const _v = version4.split(".").map((v) => parseInt(v)); | |
return { | |
major: _v[0], | |
feature: _v[1], | |
patch: _v[2] | |
}; | |
} catch (err) { | |
return { major: 0, feature: 0, patch: 0 }; | |
} | |
} | |
var RateLimiterMongo = class _RateLimiterMongo extends RateLimiterStoreAbstract { | |
/** | |
* | |
* @param {Object} opts | |
* Defaults { | |
* indexKeyPrefix: {attr1: 1, attr2: 1} | |
* ... see other in RateLimiterStoreAbstract | |
* | |
* mongo: MongoClient | |
* } | |
*/ | |
constructor(opts) { | |
super(opts); | |
this.dbName = opts.dbName; | |
this.tableName = opts.tableName; | |
this.indexKeyPrefix = opts.indexKeyPrefix; | |
if (opts.mongo) { | |
this.client = opts.mongo; | |
} else { | |
this.client = opts.storeClient; | |
} | |
if (typeof this.client.then === "function") { | |
this.client.then((conn) => { | |
this.client = conn; | |
this._initCollection(); | |
this._driverVersion = getDriverVersion(this.client); | |
}); | |
} else { | |
this._initCollection(); | |
this._driverVersion = getDriverVersion(this.client); | |
} | |
} | |
get dbName() { | |
return this._dbName; | |
} | |
set dbName(value) { | |
this._dbName = typeof value === "undefined" ? _RateLimiterMongo.getDbName() : value; | |
} | |
static getDbName() { | |
return "node-rate-limiter-flexible"; | |
} | |
get tableName() { | |
return this._tableName; | |
} | |
set tableName(value) { | |
this._tableName = typeof value === "undefined" ? this.keyPrefix : value; | |
} | |
get client() { | |
return this._client; | |
} | |
set client(value) { | |
if (typeof value === "undefined") { | |
throw new Error("mongo is not set"); | |
} | |
this._client = value; | |
} | |
get indexKeyPrefix() { | |
return this._indexKeyPrefix; | |
} | |
set indexKeyPrefix(obj) { | |
this._indexKeyPrefix = obj || {}; | |
} | |
_initCollection() { | |
const db = typeof this.client.db === "function" ? this.client.db(this.dbName) : this.client; | |
const collection = db.collection(this.tableName); | |
collection.createIndex({ expire: -1 }, { expireAfterSeconds: 0 }); | |
collection.createIndex(Object.assign({}, this.indexKeyPrefix, { key: 1 }), { unique: true }); | |
this._collection = collection; | |
} | |
_getRateLimiterRes(rlKey, changedPoints, result) { | |
const res = new RateLimiterRes(); | |
let doc; | |
if (typeof result.value === "undefined") { | |
doc = result; | |
} else { | |
doc = result.value; | |
} | |
res.isFirstInDuration = doc.points === changedPoints; | |
res.consumedPoints = doc.points; | |
res.remainingPoints = Math.max(this.points - res.consumedPoints, 0); | |
res.msBeforeNext = doc.expire !== null ? Math.max(new Date(doc.expire).getTime() - Date.now(), 0) : -1; | |
return res; | |
} | |
_upsert(key, points, msDuration, forceExpire = false, options = {}) { | |
if (!this._collection) { | |
return Promise.reject(Error("Mongo connection is not established")); | |
} | |
const docAttrs = options.attrs || {}; | |
let where; | |
let upsertData; | |
if (forceExpire) { | |
where = { key }; | |
where = Object.assign(where, docAttrs); | |
upsertData = { | |
$set: { | |
key, | |
points, | |
expire: msDuration > 0 ? new Date(Date.now() + msDuration) : null | |
} | |
}; | |
upsertData.$set = Object.assign(upsertData.$set, docAttrs); | |
} else { | |
where = { | |
$or: [ | |
{ expire: { $gt: /* @__PURE__ */ new Date() } }, | |
{ expire: { $eq: null } } | |
], | |
key | |
}; | |
where = Object.assign(where, docAttrs); | |
upsertData = { | |
$setOnInsert: { | |
key, | |
expire: msDuration > 0 ? new Date(Date.now() + msDuration) : null | |
}, | |
$inc: { points } | |
}; | |
upsertData.$setOnInsert = Object.assign(upsertData.$setOnInsert, docAttrs); | |
} | |
const upsertOptions = { | |
upsert: true | |
}; | |
if (this._driverVersion.major >= 4 || (this._driverVersion.major === 3 && this._driverVersion.feature >= 7 || this._driverVersion.feature >= 6 && this._driverVersion.patch >= 7)) { | |
upsertOptions.returnDocument = "after"; | |
} else { | |
upsertOptions.returnOriginal = false; | |
} | |
return new Promise((resolve6, reject) => { | |
this._collection.findOneAndUpdate( | |
where, | |
upsertData, | |
upsertOptions | |
).then((res) => { | |
resolve6(res); | |
}).catch((errUpsert) => { | |
if (errUpsert && errUpsert.code === 11e3) { | |
const replaceWhere = Object.assign({ | |
// try to replace OLD limit doc | |
$or: [ | |
{ expire: { $lte: /* @__PURE__ */ new Date() } }, | |
{ expire: { $eq: null } } | |
], | |
key | |
}, docAttrs); | |
const replaceTo = { | |
$set: Object.assign({ | |
key, | |
points, | |
expire: msDuration > 0 ? new Date(Date.now() + msDuration) : null | |
}, docAttrs) | |
}; | |
this._collection.findOneAndUpdate( | |
replaceWhere, | |
replaceTo, | |
upsertOptions | |
).then((res) => { | |
resolve6(res); | |
}).catch((errReplace) => { | |
if (errReplace && errReplace.code === 11e3) { | |
this._upsert(key, points, msDuration, forceExpire).then((res) => resolve6(res)).catch((err) => reject(err)); | |
} else { | |
reject(errReplace); | |
} | |
}); | |
} else { | |
reject(errUpsert); | |
} | |
}); | |
}); | |
} | |
_get(rlKey, options = {}) { | |
if (!this._collection) { | |
return Promise.reject(Error("Mongo connection is not established")); | |
} | |
const docAttrs = options.attrs || {}; | |
const where = Object.assign({ | |
key: rlKey, | |
$or: [ | |
{ expire: { $gt: /* @__PURE__ */ new Date() } }, | |
{ expire: { $eq: null } } | |
] | |
}, docAttrs); | |
return this._collection.findOne(where); | |
} | |
_delete(rlKey, options = {}) { | |
if (!this._collection) { | |
return Promise.reject(Error("Mongo connection is not established")); | |
} | |
const docAttrs = options.attrs || {}; | |
const where = Object.assign({ key: rlKey }, docAttrs); | |
return this._collection.deleteOne(where).then((res) => res.deletedCount > 0); | |
} | |
}; | |
module2.exports = RateLimiterMongo; | |
} | |
}); | |
// node_modules/rate-limiter-flexible/lib/RateLimiterMySQL.js | |
var require_RateLimiterMySQL = __commonJS({ | |
"node_modules/rate-limiter-flexible/lib/RateLimiterMySQL.js"(exports2, module2) { | |
var RateLimiterStoreAbstract = require_RateLimiterStoreAbstract(); | |
var RateLimiterRes = require_RateLimiterRes(); | |
var RateLimiterMySQL = class extends RateLimiterStoreAbstract { | |
/** | |
* @callback callback | |
* @param {Object} err | |
* | |
* @param {Object} opts | |
* @param {callback} cb | |
* Defaults { | |
* ... see other in RateLimiterStoreAbstract | |
* | |
* storeClient: anySqlClient, | |
* storeType: 'knex', // required only for Knex instance | |
* dbName: 'string', | |
* tableName: 'string', | |
* } | |
*/ | |
constructor(opts, cb = null) { | |
super(opts); | |
this.client = opts.storeClient; | |
this.clientType = opts.storeType; | |
this.dbName = opts.dbName; | |
this.tableName = opts.tableName; | |
this.clearExpiredByTimeout = opts.clearExpiredByTimeout; | |
this.tableCreated = opts.tableCreated; | |
if (!this.tableCreated) { | |
this._createDbAndTable().then(() => { | |
this.tableCreated = true; | |
if (this.clearExpiredByTimeout) { | |
this._clearExpiredHourAgo(); | |
} | |
if (typeof cb === "function") { | |
cb(); | |
} | |
}).catch((err) => { | |
if (typeof cb === "function") { | |
cb(err); | |
} else { | |
throw err; | |
} | |
}); | |
} else { | |
if (this.clearExpiredByTimeout) { | |
this._clearExpiredHourAgo(); | |
} | |
if (typeof cb === "function") { | |
cb(); | |
} | |
} | |
} | |
clearExpired(expire) { | |
return new Promise((resolve6) => { | |
this._getConnection().then((conn) => { | |
conn.query(`DELETE FROM ??.?? WHERE expire < ?`, [this.dbName, this.tableName, expire], () => { | |
this._releaseConnection(conn); | |
resolve6(); | |
}); | |
}).catch(() => { | |
resolve6(); | |
}); | |
}); | |
} | |
_clearExpiredHourAgo() { | |
if (this._clearExpiredTimeoutId) { | |
clearTimeout(this._clearExpiredTimeoutId); | |
} | |
this._clearExpiredTimeoutId = setTimeout(() => { | |
this.clearExpired(Date.now() - 36e5).then(() => { | |
this._clearExpiredHourAgo(); | |
}); | |
}, 3e5); | |
this._clearExpiredTimeoutId.unref(); | |
} | |
/** | |
* | |
* @return Promise<any> | |
* @private | |
*/ | |
_getConnection() { | |
switch (this.clientType) { | |
case "pool": | |
return new Promise((resolve6, reject) => { | |
this.client.getConnection((errConn, conn) => { | |
if (errConn) { | |
return reject(errConn); | |
} | |
resolve6(conn); | |
}); | |
}); | |
case "sequelize": | |
return this.client.connectionManager.getConnection(); | |
case "knex": | |
return this.client.client.acquireConnection(); | |
default: | |
return Promise.resolve(this.client); | |
} | |
} | |
_releaseConnection(conn) { | |
switch (this.clientType) { | |
case "pool": | |
return conn.release(); | |
case "sequelize": | |
return this.client.connectionManager.releaseConnection(conn); | |
case "knex": | |
return this.client.client.releaseConnection(conn); | |
default: | |
return true; | |
} | |
} | |
/** | |
* | |
* @returns {Promise<any>} | |
* @private | |
*/ | |
_createDbAndTable() { | |
return new Promise((resolve6, reject) => { | |
this._getConnection().then((conn) => { | |
conn.query(`CREATE DATABASE IF NOT EXISTS \`${this.dbName}\`;`, (errDb) => { | |
if (errDb) { | |
this._releaseConnection(conn); | |
return reject(errDb); | |
} | |
conn.query(this._getCreateTableStmt(), (err) => { | |
if (err) { | |
this._releaseConnection(conn); | |
return reject(err); | |
} | |
this._releaseConnection(conn); | |
resolve6(); | |
}); | |
}); | |
}).catch((err) => { | |
reject(err); | |
}); | |
}); | |
} | |
_getCreateTableStmt() { | |
return `CREATE TABLE IF NOT EXISTS \`${this.dbName}\`.\`${this.tableName}\` (\`key\` VARCHAR(255) CHARACTER SET utf8 NOT NULL,\`points\` INT(9) NOT NULL default 0,\`expire\` BIGINT UNSIGNED,PRIMARY KEY (\`key\`)) ENGINE = INNODB;`; | |
} | |
get clientType() { | |
return this._clientType; | |
} | |
set clientType(value) { | |
if (typeof value === "undefined") { | |
if (this.client.constructor.name === "Connection") { | |
value = "connection"; | |
} else if (this.client.constructor.name === "Pool") { | |
value = "pool"; | |
} else if (this.client.constructor.name === "Sequelize") { | |
value = "sequelize"; | |
} else { | |
throw new Error("storeType is not defined"); | |
} | |
} | |
this._clientType = value.toLowerCase(); | |
} | |
get dbName() { | |
return this._dbName; | |
} | |
set dbName(value) { | |
this._dbName = typeof value === "undefined" ? "rtlmtrflx" : value; | |
} | |
get tableName() { | |
return this._tableName; | |
} | |
set tableName(value) { | |
this._tableName = typeof value === "undefined" ? this.keyPrefix : value; | |
} | |
get tableCreated() { | |
return this._tableCreated; | |
} | |
set tableCreated(value) { | |
this._tableCreated = typeof value === "undefined" ? false : !!value; | |
} | |
get clearExpiredByTimeout() { | |
return this._clearExpiredByTimeout; | |
} | |
set clearExpiredByTimeout(value) { | |
this._clearExpiredByTimeout = typeof value === "undefined" ? true : Boolean(value); | |
} | |
_getRateLimiterRes(rlKey, changedPoints, result) { | |
const res = new RateLimiterRes(); | |
const [row] = result; | |
res.isFirstInDuration = changedPoints === row.points; | |
res.consumedPoints = res.isFirstInDuration ? changedPoints : row.points; | |
res.remainingPoints = Math.max(this.points - res.consumedPoints, 0); | |
res.msBeforeNext = row.expire ? Math.max(row.expire - Date.now(), 0) : -1; | |
return res; | |
} | |
_upsertTransaction(conn, key, points, msDuration, forceExpire) { | |
return new Promise((resolve6, reject) => { | |
conn.query("BEGIN", (errBegin) => { | |
if (errBegin) { | |
conn.rollback(); | |
return reject(errBegin); | |
} | |
const dateNow = Date.now(); | |
const newExpire = msDuration > 0 ? dateNow + msDuration : null; | |
let q; | |
let values; | |
if (forceExpire) { | |
q = `INSERT INTO ??.?? VALUES (?, ?, ?) | |
ON DUPLICATE KEY UPDATE | |
points = ?, | |
expire = ?;`; | |
values = [ | |
this.dbName, | |
this.tableName, | |
key, | |
points, | |
newExpire, | |
points, | |
newExpire | |
]; | |
} else { | |
q = `INSERT INTO ??.?? VALUES (?, ?, ?) | |
ON DUPLICATE KEY UPDATE | |
points = IF(expire <= ?, ?, points + (?)), | |
expire = IF(expire <= ?, ?, expire);`; | |
values = [ | |
this.dbName, | |
this.tableName, | |
key, | |
points, | |
newExpire, | |
dateNow, | |
points, | |
points, | |
dateNow, | |
newExpire | |
]; | |
} | |
conn.query(q, values, (errUpsert) => { | |
if (errUpsert) { | |
conn.rollback(); | |
return reject(errUpsert); | |
} | |
conn.query("SELECT points, expire FROM ??.?? WHERE `key` = ?;", [this.dbName, this.tableName, key], (errSelect, res) => { | |
if (errSelect) { | |
conn.rollback(); | |
return reject(errSelect); | |
} | |
conn.query("COMMIT", (err) => { | |
if (err) { | |
conn.rollback(); | |
return reject(err); | |
} | |
resolve6(res); | |
}); | |
}); | |
}); | |
}); | |
}); | |
} | |
_upsert(key, points, msDuration, forceExpire = false) { | |
if (!this.tableCreated) { | |
return Promise.reject(Error("Table is not created yet")); | |
} | |
return new Promise((resolve6, reject) => { | |
this._getConnection().then((conn) => { | |
this._upsertTransaction(conn, key, points, msDuration, forceExpire).then((res) => { | |
resolve6(res); | |
this._releaseConnection(conn); | |
}).catch((err) => { | |
reject(err); | |
this._releaseConnection(conn); | |
}); | |
}).catch((err) => { | |
reject(err); | |
}); | |
}); | |
} | |
_get(rlKey) { | |
if (!this.tableCreated) { | |
return Promise.reject(Error("Table is not created yet")); | |
} | |
return new Promise((resolve6, reject) => { | |
this._getConnection().then((conn) => { | |
conn.query( | |
"SELECT points, expire FROM ??.?? WHERE `key` = ? AND (`expire` > ? OR `expire` IS NULL)", | |
[this.dbName, this.tableName, rlKey, Date.now()], | |
(err, res) => { | |
if (err) { | |
reject(err); | |
} else if (res.length === 0) { | |
resolve6(null); | |
} else { | |
resolve6(res); | |
} | |
this._releaseConnection(conn); | |
} | |
// eslint-disable-line | |
); | |
}).catch((err) => { | |
reject(err); | |
}); | |
}); | |
} | |
_delete(rlKey) { | |
if (!this.tableCreated) { | |
return Promise.reject(Error("Table is not created yet")); | |
} | |
return new Promise((resolve6, reject) => { | |
this._getConnection().then((conn) => { | |
conn.query( | |
"DELETE FROM ??.?? WHERE `key` = ?", | |
[this.dbName, this.tableName, rlKey], | |
(err, res) => { | |
if (err) { | |
reject(err); | |
} else { | |
resolve6(res.affectedRows > 0); | |
} | |
this._releaseConnection(conn); | |
} | |
// eslint-disable-line | |
); | |
}).catch((err) => { | |
reject(err); | |
}); | |
}); | |
} | |
}; | |
module2.exports = RateLimiterMySQL; | |
} | |
}); | |
// node_modules/rate-limiter-flexible/lib/RateLimiterPostgres.js | |
var require_RateLimiterPostgres = __commonJS({ | |
"node_modules/rate-limiter-flexible/lib/RateLimiterPostgres.js"(exports2, module2) { | |
var RateLimiterStoreAbstract = require_RateLimiterStoreAbstract(); | |
var RateLimiterRes = require_RateLimiterRes(); | |
var RateLimiterPostgres = class extends RateLimiterStoreAbstract { | |
/** | |
* @callback callback | |
* @param {Object} err | |
* | |
* @param {Object} opts | |
* @param {callback} cb | |
* Defaults { | |
* ... see other in RateLimiterStoreAbstract | |
* | |
* storeClient: postgresClient, | |
* storeType: 'knex', // required only for Knex instance | |
* tableName: 'string', | |
* } | |
*/ | |
constructor(opts, cb = null) { | |
super(opts); | |
this.client = opts.storeClient; | |
this.clientType = opts.storeType; | |
this.tableName = opts.tableName; | |
this.clearExpiredByTimeout = opts.clearExpiredByTimeout; | |
this.tableCreated = opts.tableCreated; | |
if (!this.tableCreated) { | |
this._createTable().then(() => { | |
this.tableCreated = true; | |
if (this.clearExpiredByTimeout) { | |
this._clearExpiredHourAgo(); | |
} | |
if (typeof cb === "function") { | |
cb(); | |
} | |
}).catch((err) => { | |
if (typeof cb === "function") { | |
cb(err); | |
} else { | |
throw err; | |
} | |
}); | |
} else { | |
if (typeof cb === "function") { | |
cb(); | |
} | |
} | |
} | |
clearExpired(expire) { | |
return new Promise((resolve6) => { | |
const q = { | |
name: "rlflx-clear-expired", | |
text: `DELETE FROM ${this.tableName} WHERE expire < $1`, | |
values: [expire] | |
}; | |
this._query(q).then(() => { | |
resolve6(); | |
}).catch(() => { | |
resolve6(); | |
}); | |
}); | |
} | |
/** | |
* Delete all rows expired 1 hour ago once per 5 minutes | |
* | |
* @private | |
*/ | |
_clearExpiredHourAgo() { | |
if (this._clearExpiredTimeoutId) { | |
clearTimeout(this._clearExpiredTimeoutId); | |
} | |
this._clearExpiredTimeoutId = setTimeout(() => { | |
this.clearExpired(Date.now() - 36e5).then(() => { | |
this._clearExpiredHourAgo(); | |
}); | |
}, 3e5); | |
this._clearExpiredTimeoutId.unref(); | |
} | |
/** | |
* | |
* @return Promise<any> | |
* @private | |
*/ | |
_getConnection() { | |
switch (this.clientType) { | |
case "pool": | |
return Promise.resolve(this.client); | |
case "sequelize": | |
return this.client.connectionManager.getConnection(); | |
case "knex": | |
return this.client.client.acquireConnection(); | |
case "typeorm": | |
return Promise.resolve(this.client.driver.master); | |
default: | |
return Promise.resolve(this.client); | |
} | |
} | |
_releaseConnection(conn) { | |
switch (this.clientType) { | |
case "pool": | |
return true; | |
case "sequelize": | |
return this.client.connectionManager.releaseConnection(conn); | |
case "knex": | |
return this.client.client.releaseConnection(conn); | |
case "typeorm": | |
return true; | |
default: | |
return true; | |
} | |
} | |
/** | |
* | |
* @returns {Promise<any>} | |
* @private | |
*/ | |
_createTable() { | |
return new Promise((resolve6, reject) => { | |
this._query({ | |
text: this._getCreateTableStmt() | |
}).then(() => { | |
resolve6(); | |
}).catch((err) => { | |
if (err.code === "23505") { | |
resolve6(); | |
} else { | |
reject(err); | |
} | |
}); | |
}); | |
} | |
_getCreateTableStmt() { | |
return `CREATE TABLE IF NOT EXISTS ${this.tableName} ( | |
key varchar(255) PRIMARY KEY, | |
points integer NOT NULL DEFAULT 0, | |
expire bigint | |
);`; | |
} | |
get clientType() { | |
return this._clientType; | |
} | |
set clientType(value) { | |
const constructorName = this.client.constructor.name; | |
if (typeof value === "undefined") { | |
if (constructorName === "Client") { | |
value = "client"; | |
} else if (constructorName === "Pool" || constructorName === "BoundPool") { | |
value = "pool"; | |
} else if (constructorName === "Sequelize") { | |
value = "sequelize"; | |
} else { | |
throw new Error("storeType is not defined"); | |
} | |
} | |
this._clientType = value.toLowerCase(); | |
} | |
get tableName() { | |
return this._tableName; | |
} | |
set tableName(value) { | |
this._tableName = typeof value === "undefined" ? this.keyPrefix : value; | |
} | |
get tableCreated() { | |
return this._tableCreated; | |
} | |
set tableCreated(value) { | |
this._tableCreated = typeof value === "undefined" ? false : !!value; | |
} | |
get clearExpiredByTimeout() { | |
return this._clearExpiredByTimeout; | |
} | |
set clearExpiredByTimeout(value) { | |
this._clearExpiredByTimeout = typeof value === "undefined" ? true : Boolean(value); | |
} | |
_getRateLimiterRes(rlKey, changedPoints, result) { | |
const res = new RateLimiterRes(); | |
const row = result.rows[0]; | |
res.isFirstInDuration = changedPoints === row.points; | |
res.consumedPoints = res.isFirstInDuration ? changedPoints : row.points; | |
res.remainingPoints = Math.max(this.points - res.consumedPoints, 0); | |
res.msBeforeNext = row.expire ? Math.max(row.expire - Date.now(), 0) : -1; | |
return res; | |
} | |
_query(q) { | |
const prefix = this.tableName.toLowerCase(); | |
const queryObj = { name: `${prefix}:${q.name}`, text: q.text, values: q.values }; | |
return new Promise((resolve6, reject) => { | |
this._getConnection().then((conn) => { | |
conn.query(queryObj).then((res) => { | |
resolve6(res); | |
this._releaseConnection(conn); | |
}).catch((err) => { | |
reject(err); | |
this._releaseConnection(conn); | |
}); | |
}).catch((err) => { | |
reject(err); | |
}); | |
}); | |
} | |
_upsert(key, points, msDuration, forceExpire = false) { | |
if (!this.tableCreated) { | |
return Promise.reject(Error("Table is not created yet")); | |
} | |
const newExpire = msDuration > 0 ? Date.now() + msDuration : null; | |
const expireQ = forceExpire ? " $3 " : ` CASE | |
WHEN ${this.tableName}.expire <= $4 THEN $3 | |
ELSE ${this.tableName}.expire | |
END `; | |
return this._query({ | |
name: forceExpire ? "rlflx-upsert-force" : "rlflx-upsert", | |
text: ` | |
INSERT INTO ${this.tableName} VALUES ($1, $2, $3) | |
ON CONFLICT(key) DO UPDATE SET | |
points = CASE | |
WHEN (${this.tableName}.expire <= $4 OR 1=${forceExpire ? 1 : 0}) THEN $2 | |
ELSE ${this.tableName}.points + ($2) | |
END, | |
expire = ${expireQ} | |
RETURNING points, expire;`, | |
values: [key, points, newExpire, Date.now()] | |
}); | |
} | |
_get(rlKey) { | |
if (!this.tableCreated) { | |
return Promise.reject(Error("Table is not created yet")); | |
} | |
return new Promise((resolve6, reject) => { | |
this._query({ | |
name: "rlflx-get", | |
text: ` | |
SELECT points, expire FROM ${this.tableName} WHERE key = $1 AND (expire > $2 OR expire IS NULL);`, | |
values: [rlKey, Date.now()] | |
}).then((res) => { | |
if (res.rowCount === 0) { | |
res = null; | |
} | |
resolve6(res); | |
}).catch((err) => { | |
reject(err); | |
}); | |
}); | |
} | |
_delete(rlKey) { | |
if (!this.tableCreated) { | |
return Promise.reject(Error("Table is not created yet")); | |
} | |
return this._query({ | |
name: "rlflx-delete", | |
text: `DELETE FROM ${this.tableName} WHERE key = $1`, | |
values: [rlKey] | |
}).then((res) => res.rowCount > 0); | |
} | |
}; | |
module2.exports = RateLimiterPostgres; | |
} | |
}); | |
// (disabled):cluster | |
var require_cluster = __commonJS({ | |
"(disabled):cluster"() { | |
} | |
}); | |
// node_modules/rate-limiter-flexible/lib/component/MemoryStorage/Record.js | |
var require_Record = __commonJS({ | |
"node_modules/rate-limiter-flexible/lib/component/MemoryStorage/Record.js"(exports2, module2) { | |
module2.exports = class Record { | |
/** | |
* | |
* @param value int | |
* @param expiresAt Date|int | |
* @param timeoutId | |
*/ | |
constructor(value, expiresAt, timeoutId = null) { | |
this.value = value; | |
this.expiresAt = expiresAt; | |
this.timeoutId = timeoutId; | |
} | |
get value() { | |
return this._value; | |
} | |
set value(value) { | |
this._value = parseInt(value); | |
} | |
get expiresAt() { | |
return this._expiresAt; | |
} | |
set expiresAt(value) { | |
if (!(value instanceof Date) && Number.isInteger(value)) { | |
value = new Date(value); | |
} | |
this._expiresAt = value; | |
} | |
get timeoutId() { | |
return this._timeoutId; | |
} | |
set timeoutId(value) { | |
this._timeoutId = value; | |
} | |
}; | |
} | |
}); | |
// node_modules/rate-limiter-flexible/lib/component/MemoryStorage/MemoryStorage.js | |
var require_MemoryStorage = __commonJS({ | |
"node_modules/rate-limiter-flexible/lib/component/MemoryStorage/MemoryStorage.js"(exports2, module2) { | |
var Record3 = require_Record(); | |
var RateLimiterRes = require_RateLimiterRes(); | |
module2.exports = class MemoryStorage { | |
constructor() { | |
this._storage = {}; | |
} | |
incrby(key, value, durationSec) { | |
if (this._storage[key]) { | |
const msBeforeExpires = this._storage[key].expiresAt ? this._storage[key].expiresAt.getTime() - (/* @__PURE__ */ new Date()).getTime() : -1; | |
if (msBeforeExpires !== 0) { | |
this._storage[key].value = this._storage[key].value + value; | |
return new RateLimiterRes(0, msBeforeExpires, this._storage[key].value, false); | |
} | |
return this.set(key, value, durationSec); | |
} | |
return this.set(key, value, durationSec); | |
} | |
set(key, value, durationSec) { | |
const durationMs = durationSec * 1e3; | |
if (this._storage[key] && this._storage[key].timeoutId) { | |
clearTimeout(this._storage[key].timeoutId); | |
} | |
this._storage[key] = new Record3( | |
value, | |
durationMs > 0 ? new Date(Date.now() + durationMs) : null | |
); | |
if (durationMs > 0) { | |
this._storage[key].timeoutId = setTimeout(() => { | |
delete this._storage[key]; | |
}, durationMs); | |
if (this._storage[key].timeoutId.unref) { | |
this._storage[key].timeoutId.unref(); | |
} | |
} | |
return new RateLimiterRes(0, durationMs === 0 ? -1 : durationMs, this._storage[key].value, true); | |
} | |
/** | |
* | |
* @param key | |
* @returns {*} | |
*/ | |
get(key) { | |
if (this._storage[key]) { | |
const msBeforeExpires = this._storage[key].expiresAt ? this._storage[key].expiresAt.getTime() - (/* @__PURE__ */ new Date()).getTime() : -1; | |
return new RateLimiterRes(0, msBeforeExpires, this._storage[key].value, false); | |
} | |
return null; | |
} | |
/** | |
* | |
* @param key | |
* @returns {boolean} | |
*/ | |
delete(key) { | |
if (this._storage[key]) { | |
if (this._storage[key].timeoutId) { | |
clearTimeout(this._storage[key].timeoutId); | |
} | |
delete this._storage[key]; | |
return true; | |
} | |
return false; | |
} | |
}; | |
} | |
}); | |
// node_modules/rate-limiter-flexible/lib/RateLimiterMemory.js | |
var require_RateLimiterMemory = __commonJS({ | |
"node_modules/rate-limiter-flexible/lib/RateLimiterMemory.js"(exports2, module2) { | |
var RateLimiterAbstract = require_RateLimiterAbstract(); | |
var MemoryStorage = require_MemoryStorage(); | |
var RateLimiterRes = require_RateLimiterRes(); | |
var RateLimiterMemory3 = class extends RateLimiterAbstract { | |
constructor(opts = {}) { | |
super(opts); | |
this._memoryStorage = new MemoryStorage(); | |
} | |
/** | |
* | |
* @param key | |
* @param pointsToConsume | |
* @param {Object} options | |
* @returns {Promise<RateLimiterRes>} | |
*/ | |
consume(key, pointsToConsume = 1, options = {}) { | |
return new Promise((resolve6, reject) => { | |
const rlKey = this.getKey(key); | |
const secDuration = this._getKeySecDuration(options); | |
let res = this._memoryStorage.incrby(rlKey, pointsToConsume, secDuration); | |
res.remainingPoints = Math.max(this.points - res.consumedPoints, 0); | |
if (res.consumedPoints > this.points) { | |
if (this.blockDuration > 0 && res.consumedPoints <= this.points + pointsToConsume) { | |
res = this._memoryStorage.set(rlKey, res.consumedPoints, this.blockDuration); | |
} | |
reject(res); | |
} else if (this.execEvenly && res.msBeforeNext > 0 && !res.isFirstInDuration) { | |
let delay = Math.ceil(res.msBeforeNext / (res.remainingPoints + 2)); | |
if (delay < this.execEvenlyMinDelayMs) { | |
delay = res.consumedPoints * this.execEvenlyMinDelayMs; | |
} | |
setTimeout(resolve6, delay, res); | |
} else { | |
resolve6(res); | |
} | |
}); | |
} | |
penalty(key, points = 1, options = {}) { | |
const rlKey = this.getKey(key); | |
return new Promise((resolve6) => { | |
const secDuration = this._getKeySecDuration(options); | |
const res = this._memoryStorage.incrby(rlKey, points, secDuration); | |
res.remainingPoints = Math.max(this.points - res.consumedPoints, 0); | |
resolve6(res); | |
}); | |
} | |
reward(key, points = 1, options = {}) { | |
const rlKey = this.getKey(key); | |
return new Promise((resolve6) => { | |
const secDuration = this._getKeySecDuration(options); | |
const res = this._memoryStorage.incrby(rlKey, -points, secDuration); | |
res.remainingPoints = Math.max(this.points - res.consumedPoints, 0); | |
resolve6(res); | |
}); | |
} | |
/** | |
* Block any key for secDuration seconds | |
* | |
* @param key | |
* @param secDuration | |
*/ | |
block(key, secDuration) { | |
const msDuration = secDuration * 1e3; | |
const initPoints = this.points + 1; | |
this._memoryStorage.set(this.getKey(key), initPoints, secDuration); | |
return Promise.resolve( | |
new RateLimiterRes(0, msDuration === 0 ? -1 : msDuration, initPoints) | |
); | |
} | |
set(key, points, secDuration) { | |
const msDuration = (secDuration >= 0 ? secDuration : this.duration) * 1e3; | |
this._memoryStorage.set(this.getKey(key), points, secDuration); | |
return Promise.resolve( | |
new RateLimiterRes(0, msDuration === 0 ? -1 : msDuration, points) | |
); | |
} | |
get(key) { | |
const res = this._memoryStorage.get(this.getKey(key)); | |
if (res !== null) { | |
res.remainingPoints = Math.max(this.points - res.consumedPoints, 0); | |
} | |
return Promise.resolve(res); | |
} | |
delete(key) { | |
return Promise.resolve(this._memoryStorage.delete(this.getKey(key))); | |
} | |
}; | |
module2.exports = RateLimiterMemory3; | |
} | |
}); | |
// node_modules/rate-limiter-flexible/lib/RateLimiterCluster.js | |
var require_RateLimiterCluster = __commonJS({ | |
"node_modules/rate-limiter-flexible/lib/RateLimiterCluster.js"(exports2, module2) { | |
var cluster = require_cluster(); | |
var crypto5 = require_crypto(); | |
var RateLimiterAbstract = require_RateLimiterAbstract(); | |
var RateLimiterMemory3 = require_RateLimiterMemory(); | |
var RateLimiterRes = require_RateLimiterRes(); | |
var channel = "rate_limiter_flexible"; | |
var masterInstance = null; | |
var masterSendToWorker = function(worker, msg, type, res) { | |
let data; | |
if (res === null || res === true || res === false) { | |
data = res; | |
} else { | |
data = { | |
remainingPoints: res.remainingPoints, | |
msBeforeNext: res.msBeforeNext, | |
consumedPoints: res.consumedPoints, | |
isFirstInDuration: res.isFirstInDuration | |
}; | |
} | |
worker.send({ | |
channel, | |
keyPrefix: msg.keyPrefix, | |
// which rate limiter exactly | |
promiseId: msg.promiseId, | |
type, | |
data | |
}); | |
}; | |
var workerWaitInit = function(payload) { | |
setTimeout(() => { | |
if (this._initiated) { | |
process.send(payload); | |
} else if (typeof this._promises[payload.promiseId] !== "undefined") { | |
workerWaitInit.call(this, payload); | |
} | |
}, 30); | |
}; | |
var workerSendToMaster = function(func, promiseId, key, arg, opts) { | |
const payload = { | |
channel, | |
keyPrefix: this.keyPrefix, | |
func, | |
promiseId, | |
data: { | |
key, | |
arg, | |
opts | |
} | |
}; | |
if (!this._initiated) { | |
workerWaitInit.call(this, payload); | |
} else { | |
process.send(payload); | |
} | |
}; | |
var masterProcessMsg = function(worker, msg) { | |
if (!msg || msg.channel !== channel || typeof this._rateLimiters[msg.keyPrefix] === "undefined") { | |
return false; | |
} | |
let promise; | |
switch (msg.func) { | |
case "consume": | |
promise = this._rateLimiters[msg.keyPrefix].consume(msg.data.key, msg.data.arg, msg.data.opts); | |
break; | |
case "penalty": | |
promise = this._rateLimiters[msg.keyPrefix].penalty(msg.data.key, msg.data.arg, msg.data.opts); | |
break; | |
case "reward": | |
promise = this._rateLimiters[msg.keyPrefix].reward(msg.data.key, msg.data.arg, msg.data.opts); | |
break; | |
case "block": | |
promise = this._rateLimiters[msg.keyPrefix].block(msg.data.key, msg.data.arg, msg.data.opts); | |
break; | |
case "get": | |
promise = this._rateLimiters[msg.keyPrefix].get(msg.data.key, msg.data.opts); | |
break; | |
case "delete": | |
promise = this._rateLimiters[msg.keyPrefix].delete(msg.data.key, msg.data.opts); | |
break; | |
default: | |
return false; | |
} | |
if (promise) { | |
promise.then((res) => { | |
masterSendToWorker(worker, msg, "resolve", res); | |
}).catch((rejRes) => { | |
masterSendToWorker(worker, msg, "reject", rejRes); | |
}); | |
} | |
}; | |
var workerProcessMsg = function(msg) { | |
if (!msg || msg.channel !== channel || msg.keyPrefix !== this.keyPrefix) { | |
return false; | |
} | |
if (this._promises[msg.promiseId]) { | |
clearTimeout(this._promises[msg.promiseId].timeoutId); | |
let res; | |
if (msg.data === null || msg.data === true || msg.data === false) { | |
res = msg.data; | |
} else { | |
res = new RateLimiterRes( | |
msg.data.remainingPoints, | |
msg.data.msBeforeNext, | |
msg.data.consumedPoints, | |
msg.data.isFirstInDuration | |
// eslint-disable-line comma-dangle | |
); | |
} | |
switch (msg.type) { | |
case "resolve": | |
this._promises[msg.promiseId].resolve(res); | |
break; | |
case "reject": | |
this._promises[msg.promiseId].reject(res); | |
break; | |
default: | |
throw new Error(`RateLimiterCluster: no such message type '${msg.type}'`); | |
} | |
delete this._promises[msg.promiseId]; | |
} | |
}; | |
var getOpts = function() { | |
return { | |
points: this.points, | |
duration: this.duration, | |
blockDuration: this.blockDuration, | |
execEvenly: this.execEvenly, | |
execEvenlyMinDelayMs: this.execEvenlyMinDelayMs, | |
keyPrefix: this.keyPrefix | |
}; | |
}; | |
var savePromise = function(resolve6, reject) { | |
const hrtime = process.hrtime(); | |
let promiseId = hrtime[0].toString() + hrtime[1].toString(); | |
if (typeof this._promises[promiseId] !== "undefined") { | |
promiseId += crypto5.randomBytes(12).toString("base64"); | |
} | |
this._promises[promiseId] = { | |
resolve: resolve6, | |
reject, | |
timeoutId: setTimeout(() => { | |
delete this._promises[promiseId]; | |
reject(new Error("RateLimiterCluster timeout: no answer from master in time")); | |
}, this.timeoutMs) | |
}; | |
return promiseId; | |
}; | |
var RateLimiterClusterMaster = class { | |
constructor() { | |
if (masterInstance) { | |
return masterInstance; | |
} | |
this._rateLimiters = {}; | |
cluster.setMaxListeners(0); | |
cluster.on("message", (worker, msg) => { | |
if (msg && msg.channel === channel && msg.type === "init") { | |
if (typeof this._rateLimiters[msg.opts.keyPrefix] === "undefined") { | |
this._rateLimiters[msg.opts.keyPrefix] = new RateLimiterMemory3(msg.opts); | |
} | |
worker.send({ | |
channel, | |
type: "init", | |
keyPrefix: msg.opts.keyPrefix | |
}); | |
} else { | |
masterProcessMsg.call(this, worker, msg); | |
} | |
}); | |
masterInstance = this; | |
} | |
}; | |
var RateLimiterClusterMasterPM2 = class { | |
constructor(pm2) { | |
if (masterInstance) { | |
return masterInstance; | |
} | |
this._rateLimiters = {}; | |
pm2.launchBus((err, pm2Bus) => { | |
pm2Bus.on("process:msg", (packet) => { | |
const msg = packet.raw; | |
if (msg && msg.channel === channel && msg.type === "init") { | |
if (typeof this._rateLimiters[msg.opts.keyPrefix] === "undefined") { | |
this._rateLimiters[msg.opts.keyPrefix] = new RateLimiterMemory3(msg.opts); | |
} | |
pm2.sendDataToProcessId(packet.process.pm_id, { | |
data: {}, | |
topic: channel, | |
channel, | |
type: "init", | |
keyPrefix: msg.opts.keyPrefix | |
}, (sendErr, res) => { | |
if (sendErr) { | |
console.log(sendErr, res); | |
} | |
}); | |
} else { | |
const worker = { | |
send: (msgData) => { | |
const pm2Message = msgData; | |
pm2Message.topic = channel; | |
if (typeof pm2Message.data === "undefined") { | |
pm2Message.data = {}; | |
} | |
pm2.sendDataToProcessId(packet.process.pm_id, pm2Message, (sendErr, res) => { | |
if (sendErr) { | |
console.log(sendErr, res); | |
} | |
}); | |
} | |
}; | |
masterProcessMsg.call(this, worker, msg); | |
} | |
}); | |
}); | |
masterInstance = this; | |
} | |
}; | |
var RateLimiterClusterWorker = class extends RateLimiterAbstract { | |
get timeoutMs() { | |
return this._timeoutMs; | |
} | |
set timeoutMs(value) { | |
this._timeoutMs = typeof value === "undefined" ? 5e3 : Math.abs(parseInt(value)); | |
} | |
constructor(opts = {}) { | |
super(opts); | |
process.setMaxListeners(0); | |
this.timeoutMs = opts.timeoutMs; | |
this._initiated = false; | |
process.on("message", (msg) => { | |
if (msg && msg.channel === channel && msg.type === "init" && msg.keyPrefix === this.keyPrefix) { | |
this._initiated = true; | |
} else { | |
workerProcessMsg.call(this, msg); | |
} | |
}); | |
process.send({ | |
channel, | |
type: "init", | |
opts: getOpts.call(this) | |
}); | |
this._promises = {}; | |
} | |
consume(key, pointsToConsume = 1, options = {}) { | |
return new Promise((resolve6, reject) => { | |
const promiseId = savePromise.call(this, resolve6, reject); | |
workerSendToMaster.call(this, "consume", promiseId, key, pointsToConsume, options); | |
}); | |
} | |
penalty(key, points = 1, options = {}) { | |
return new Promise((resolve6, reject) => { | |
const promiseId = savePromise.call(this, resolve6, reject); | |
workerSendToMaster.call(this, "penalty", promiseId, key, points, options); | |
}); | |
} | |
reward(key, points = 1, options = {}) { | |
return new Promise((resolve6, reject) => { | |
const promiseId = savePromise.call(this, resolve6, reject); | |
workerSendToMaster.call(this, "reward", promiseId, key, points, options); | |
}); | |
} | |
block(key, secDuration, options = {}) { | |
return new Promise((resolve6, reject) => { | |
const promiseId = savePromise.call(this, resolve6, reject); | |
workerSendToMaster.call(this, "block", promiseId, key, secDuration, options); | |
}); | |
} | |
get(key, options = {}) { | |
return new Promise((resolve6, reject) => { | |
const promiseId = savePromise.call(this, resolve6, reject); | |
workerSendToMaster.call(this, "get", promiseId, key, options); | |
}); | |
} | |
delete(key, options = {}) { | |
return new Promise((resolve6, reject) => { | |
const promiseId = savePromise.call(this, resolve6, reject); | |
workerSendToMaster.call(this, "delete", promiseId, key, options); | |
}); | |
} | |
}; | |
module2.exports = { | |
RateLimiterClusterMaster, | |
RateLimiterClusterMasterPM2, | |
RateLimiterCluster: RateLimiterClusterWorker | |
}; | |
} | |
}); | |
// node_modules/rate-limiter-flexible/lib/RateLimiterMemcache.js | |
var require_RateLimiterMemcache = __commonJS({ | |
"node_modules/rate-limiter-flexible/lib/RateLimiterMemcache.js"(exports2, module2) { | |
var RateLimiterStoreAbstract = require_RateLimiterStoreAbstract(); | |
var RateLimiterRes = require_RateLimiterRes(); | |
var RateLimiterMemcache = class extends RateLimiterStoreAbstract { | |
/** | |
* | |
* @param {Object} opts | |
* Defaults { | |
* ... see other in RateLimiterStoreAbstract | |
* | |
* storeClient: memcacheClient | |
* } | |
*/ | |
constructor(opts) { | |
super(opts); | |
this.client = opts.storeClient; | |
} | |
_getRateLimiterRes(rlKey, changedPoints, result) { | |
const res = new RateLimiterRes(); | |
res.consumedPoints = parseInt(result.consumedPoints); | |
res.isFirstInDuration = result.consumedPoints === changedPoints; | |
res.remainingPoints = Math.max(this.points - res.consumedPoints, 0); | |
res.msBeforeNext = result.msBeforeNext; | |
return res; | |
} | |
_upsert(rlKey, points, msDuration, forceExpire = false, options = {}) { | |
return new Promise((resolve6, reject) => { | |
const nowMs = Date.now(); | |
const secDuration = Math.floor(msDuration / 1e3); | |
if (forceExpire) { | |
this.client.set(rlKey, points, secDuration, (err) => { | |
if (!err) { | |
this.client.set( | |
`${rlKey}_expire`, | |
secDuration > 0 ? nowMs + secDuration * 1e3 : -1, | |
secDuration, | |
() => { | |
const res = { | |
consumedPoints: points, | |
msBeforeNext: secDuration > 0 ? secDuration * 1e3 : -1 | |
}; | |
resolve6(res); | |
} | |
); | |
} else { | |
reject(err); | |
} | |
}); | |
} else { | |
this.client.incr(rlKey, points, (err, consumedPoints) => { | |
if (err || consumedPoints === false) { | |
this.client.add(rlKey, points, secDuration, (errAddKey, createdNew) => { | |
if (errAddKey || !createdNew) { | |
if (typeof options.attemptNumber === "undefined" || options.attemptNumber < 3) { | |
const nextOptions = Object.assign({}, options); | |
nextOptions.attemptNumber = nextOptions.attemptNumber ? nextOptions.attemptNumber + 1 : 1; | |
this._upsert(rlKey, points, msDuration, forceExpire, nextOptions).then((resUpsert) => resolve6(resUpsert)).catch((errUpsert) => reject(errUpsert)); | |
} else { | |
reject(new Error("Can not add key")); | |
} | |
} else { | |
this.client.add( | |
`${rlKey}_expire`, | |
secDuration > 0 ? nowMs + secDuration * 1e3 : -1, | |
secDuration, | |
() => { | |
const res = { | |
consumedPoints: points, | |
msBeforeNext: secDuration > 0 ? secDuration * 1e3 : -1 | |
}; | |
resolve6(res); | |
} | |
); | |
} | |
}); | |
} else { | |
this.client.get(`${rlKey}_expire`, (errGetExpire, resGetExpireMs) => { | |
if (errGetExpire) { | |
reject(errGetExpire); | |
} else { | |
const expireMs = resGetExpireMs === false ? 0 : resGetExpireMs; | |
const res = { | |
consumedPoints, | |
msBeforeNext: expireMs >= 0 ? Math.max(expireMs - nowMs, 0) : -1 | |
}; | |
resolve6(res); | |
} | |
}); | |
} | |
}); | |
} | |
}); | |
} | |
_get(rlKey) { | |
return new Promise((resolve6, reject) => { | |
const nowMs = Date.now(); | |
this.client.get(rlKey, (err, consumedPoints) => { | |
if (!consumedPoints) { | |
resolve6(null); | |
} else { | |
this.client.get(`${rlKey}_expire`, (errGetExpire, resGetExpireMs) => { | |
if (errGetExpire) { | |
reject(errGetExpire); | |
} else { | |
const expireMs = resGetExpireMs === false ? 0 : resGetExpireMs; | |
const res = { | |
consumedPoints, | |
msBeforeNext: expireMs >= 0 ? Math.max(expireMs - nowMs, 0) : -1 | |
}; | |
resolve6(res); | |
} | |
}); | |
} | |
}); | |
}); | |
} | |
_delete(rlKey) { | |
return new Promise((resolve6, reject) => { | |
this.client.del(rlKey, (err, res) => { | |
if (err) { | |
reject(err); | |
} else if (res === false) { | |
resolve6(res); | |
} else { | |
this.client.del(`${rlKey}_expire`, (errDelExpire) => { | |
if (errDelExpire) { | |
reject(errDelExpire); | |
} else { | |
resolve6(res); | |
} | |
}); | |
} | |
}); | |
}); | |
} | |
}; | |
module2.exports = RateLimiterMemcache; | |
} | |
}); | |
// node_modules/rate-limiter-flexible/lib/RLWrapperBlackAndWhite.js | |
var require_RLWrapperBlackAndWhite = __commonJS({ | |
"node_modules/rate-limiter-flexible/lib/RLWrapperBlackAndWhite.js"(exports2, module2) { | |
var RateLimiterRes = require_RateLimiterRes(); | |
module2.exports = class RLWrapperBlackAndWhite { | |
constructor(opts = {}) { | |
this.limiter = opts.limiter; | |
this.blackList = opts.blackList; | |
this.whiteList = opts.whiteList; | |
this.isBlackListed = opts.isBlackListed; | |
this.isWhiteListed = opts.isWhiteListed; | |
this.runActionAnyway = opts.runActionAnyway; | |
} | |
get limiter() { | |
return this._limiter; | |
} | |
set limiter(value) { | |
if (typeof value === "undefined") { | |
throw new Error("limiter is not set"); | |
} | |
this._limiter = value; | |
} | |
get runActionAnyway() { | |
return this._runActionAnyway; | |
} | |
set runActionAnyway(value) { | |
this._runActionAnyway = typeof value === "undefined" ? false : value; | |
} | |
get blackList() { | |
return this._blackList; | |
} | |
set blackList(value) { | |
this._blackList = Array.isArray(value) ? value : []; | |
} | |
get isBlackListed() { | |
return this._isBlackListed; | |
} | |
set isBlackListed(func) { | |
if (typeof func === "undefined") { | |
func = () => false; | |
} | |
if (typeof func !== "function") { | |
throw new Error("isBlackListed must be function"); | |
} | |
this._isBlackListed = func; | |
} | |
get whiteList() { | |
return this._whiteList; | |
} | |
set whiteList(value) { | |
this._whiteList = Array.isArray(value) ? value : []; | |
} | |
get isWhiteListed() { | |
return this._isWhiteListed; | |
} | |
set isWhiteListed(func) { | |
if (typeof func === "undefined") { | |
func = () => false; | |
} | |
if (typeof func !== "function") { | |
throw new Error("isWhiteListed must be function"); | |
} | |
this._isWhiteListed = func; | |
} | |
isBlackListedSomewhere(key) { | |
return this.blackList.indexOf(key) >= 0 || this.isBlackListed(key); | |
} | |
isWhiteListedSomewhere(key) { | |
return this.whiteList.indexOf(key) >= 0 || this.isWhiteListed(key); | |
} | |
getBlackRes() { | |
return new RateLimiterRes(0, Number.MAX_SAFE_INTEGER, 0, false); | |
} | |
getWhiteRes() { | |
return new RateLimiterRes(Number.MAX_SAFE_INTEGER, 0, 0, false); | |
} | |
rejectBlack() { | |
return Promise.reject(this.getBlackRes()); | |
} | |
resolveBlack() { | |
return Promise.resolve(this.getBlackRes()); | |
} | |
resolveWhite() { | |
return Promise.resolve(this.getWhiteRes()); | |
} | |
consume(key, pointsToConsume = 1) { | |
let res; | |
if (this.isWhiteListedSomewhere(key)) { | |
res = this.resolveWhite(); | |
} else if (this.isBlackListedSomewhere(key)) { | |
res = this.rejectBlack(); | |
} | |
if (typeof res === "undefined") { | |
return this.limiter.consume(key, pointsToConsume); | |
} | |
if (this.runActionAnyway) { | |
this.limiter.consume(key, pointsToConsume).catch(() => { | |
}); | |
} | |
return res; | |
} | |
block(key, secDuration) { | |
let res; | |
if (this.isWhiteListedSomewhere(key)) { | |
res = this.resolveWhite(); | |
} else if (this.isBlackListedSomewhere(key)) { | |
res = this.resolveBlack(); | |
} | |
if (typeof res === "undefined") { | |
return this.limiter.block(key, secDuration); | |
} | |
if (this.runActionAnyway) { | |
this.limiter.block(key, secDuration).catch(() => { | |
}); | |
} | |
return res; | |
} | |
penalty(key, points) { | |
let res; | |
if (this.isWhiteListedSomewhere(key)) { | |
res = this.resolveWhite(); | |
} else if (this.isBlackListedSomewhere(key)) { | |
res = this.resolveBlack(); | |
} | |
if (typeof res === "undefined") { | |
return this.limiter.penalty(key, points); | |
} | |
if (this.runActionAnyway) { | |
this.limiter.penalty(key, points).catch(() => { | |
}); | |
} | |
return res; | |
} | |
reward(key, points) { | |
let res; | |
if (this.isWhiteListedSomewhere(key)) { | |
res = this.resolveWhite(); | |
} else if (this.isBlackListedSomewhere(key)) { | |
res = this.resolveBlack(); | |
} | |
if (typeof res === "undefined") { | |
return this.limiter.reward(key, points); | |
} | |
if (this.runActionAnyway) { | |
this.limiter.reward(key, points).catch(() => { | |
}); | |
} | |
return res; | |
} | |
get(key) { | |
let res; | |
if (this.isWhiteListedSomewhere(key)) { | |
res = this.resolveWhite(); | |
} else if (this.isBlackListedSomewhere(key)) { | |
res = this.resolveBlack(); | |
} | |
if (typeof res === "undefined" || this.runActionAnyway) { | |
return this.limiter.get(key); | |
} | |
return res; | |
} | |
delete(key) { | |
return this.limiter.delete(key); | |
} | |
}; | |
} | |
}); | |
// node_modules/rate-limiter-flexible/lib/RateLimiterUnion.js | |
var require_RateLimiterUnion = __commonJS({ | |
"node_modules/rate-limiter-flexible/lib/RateLimiterUnion.js"(exports2, module2) { | |
var RateLimiterAbstract = require_RateLimiterAbstract(); | |
module2.exports = class RateLimiterUnion { | |
constructor(...limiters) { | |
if (limiters.length < 1) { | |
throw new Error("RateLimiterUnion: at least one limiter have to be passed"); | |
} | |
limiters.forEach((limiter) => { | |
if (!(limiter instanceof RateLimiterAbstract)) { | |
throw new Error("RateLimiterUnion: all limiters have to be instance of RateLimiterAbstract"); | |
} | |
}); | |
this._limiters = limiters; | |
} | |
consume(key, points = 1) { | |
return new Promise((resolve6, reject) => { | |
const promises = []; | |
this._limiters.forEach((limiter) => { | |
promises.push(limiter.consume(key, points).catch((rej) => ({ rejected: true, rej }))); | |
}); | |
Promise.all(promises).then((res) => { | |
const resObj = {}; | |
let rejected = false; | |
res.forEach((item) => { | |
if (item.rejected === true) { | |
rejected = true; | |
} | |
}); | |
for (let i = 0; i < res.length; i++) { | |
if (rejected && res[i].rejected === true) { | |
resObj[this._limiters[i].keyPrefix] = res[i].rej; | |
} else if (!rejected) { | |
resObj[this._limiters[i].keyPrefix] = res[i]; | |
} | |
} | |
if (rejected) { | |
reject(resObj); | |
} else { | |
resolve6(resObj); | |
} | |
}); | |
}); | |
} | |
}; | |
} | |
}); | |
// node_modules/rate-limiter-flexible/lib/component/RateLimiterQueueError.js | |
var require_RateLimiterQueueError = __commonJS({ | |
"node_modules/rate-limiter-flexible/lib/component/RateLimiterQueueError.js"(exports2, module2) { | |
module2.exports = class RateLimiterQueueError extends Error { | |
constructor(message2, extra) { | |
super(); | |
if (Error.captureStackTrace) { | |
Error.captureStackTrace(this, this.constructor); | |
} | |
this.name = "CustomError"; | |
this.message = message2; | |
if (extra) { | |
this.extra = extra; | |
} | |
} | |
}; | |
} | |
}); | |
// node_modules/rate-limiter-flexible/lib/RateLimiterQueue.js | |
var require_RateLimiterQueue = __commonJS({ | |
"node_modules/rate-limiter-flexible/lib/RateLimiterQueue.js"(exports2, module2) { | |
var RateLimiterQueueError = require_RateLimiterQueueError(); | |
var MAX_QUEUE_SIZE = 4294967295; | |
var KEY_DEFAULT = "limiter"; | |
module2.exports = class RateLimiterQueue { | |
constructor(limiterFlexible, opts = { | |
maxQueueSize: MAX_QUEUE_SIZE | |
}) { | |
this._queueLimiters = { | |
KEY_DEFAULT: new RateLimiterQueueInternal(limiterFlexible, opts) | |
}; | |
this._limiterFlexible = limiterFlexible; | |
this._maxQueueSize = opts.maxQueueSize; | |
} | |
getTokensRemaining(key = KEY_DEFAULT) { | |
if (this._queueLimiters[key]) { | |
return this._queueLimiters[key].getTokensRemaining(); | |
} else { | |
return Promise.resolve(this._limiterFlexible.points); | |
} | |
} | |
removeTokens(tokens, key = KEY_DEFAULT) { | |
if (!this._queueLimiters[key]) { | |
this._queueLimiters[key] = new RateLimiterQueueInternal( | |
this._limiterFlexible, | |
{ | |
key, | |
maxQueueSize: this._maxQueueSize | |
} | |
); | |
} | |
return this._queueLimiters[key].removeTokens(tokens); | |
} | |
}; | |
var RateLimiterQueueInternal = class { | |
constructor(limiterFlexible, opts = { | |
maxQueueSize: MAX_QUEUE_SIZE, | |
key: KEY_DEFAULT | |
}) { | |
this._key = opts.key; | |
this._waitTimeout = null; | |
this._queue = []; | |
this._limiterFlexible = limiterFlexible; | |
this._maxQueueSize = opts.maxQueueSize; | |
} | |
getTokensRemaining() { | |
return this._limiterFlexible.get(this._key).then((rlRes) => { | |
return rlRes !== null ? rlRes.remainingPoints : this._limiterFlexible.points; | |
}); | |
} | |
removeTokens(tokens) { | |
const _this = this; | |
return new Promise((resolve6, reject) => { | |
if (tokens > _this._limiterFlexible.points) { | |
reject(new RateLimiterQueueError(`Requested tokens ${tokens} exceeds maximum ${_this._limiterFlexible.points} tokens per interval`)); | |
return; | |
} | |
if (_this._queue.length > 0) { | |
_this._queueRequest.call(_this, resolve6, reject, tokens); | |
} else { | |
_this._limiterFlexible.consume(_this._key, tokens).then((res) => { | |
resolve6(res.remainingPoints); | |
}).catch((rej) => { | |
if (rej instanceof Error) { | |
reject(rej); | |
} else { | |
_this._queueRequest.call(_this, resolve6, reject, tokens); | |
if (_this._waitTimeout === null) { | |
_this._waitTimeout = setTimeout(_this._processFIFO.bind(_this), rej.msBeforeNext); | |
} | |
} | |
}); | |
} | |
}); | |
} | |
_queueRequest(resolve6, reject, tokens) { | |
const _this = this; | |
if (_this._queue.length < _this._maxQueueSize) { | |
_this._queue.push({ resolve: resolve6, reject, tokens }); | |
} else { | |
reject(new RateLimiterQueueError(`Number of requests reached it's maximum ${_this._maxQueueSize}`)); | |
} | |
} | |
_processFIFO() { | |
const _this = this; | |
if (_this._waitTimeout !== null) { | |
clearTimeout(_this._waitTimeout); | |
_this._waitTimeout = null; | |
} | |
if (_this._queue.length === 0) { | |
return; | |
} | |
const item = _this._queue.shift(); | |
_this._limiterFlexible.consume(_this._key, item.tokens).then((res) => { | |
item.resolve(res.remainingPoints); | |
_this._processFIFO.call(_this); | |
}).catch((rej) => { | |
if (rej instanceof Error) { | |
item.reject(rej); | |
_this._processFIFO.call(_this); | |
} else { | |
_this._queue.unshift(item); | |
if (_this._waitTimeout === null) { | |
_this._waitTimeout = setTimeout(_this._processFIFO.bind(_this), rej.msBeforeNext); | |
} | |
} | |
}); | |
} | |
}; | |
} | |
}); | |
// node_modules/rate-limiter-flexible/lib/BurstyRateLimiter.js | |
var require_BurstyRateLimiter = __commonJS({ | |
"node_modules/rate-limiter-flexible/lib/BurstyRateLimiter.js"(exports2, module2) { | |
var RateLimiterRes = require_RateLimiterRes(); | |
module2.exports = class BurstyRateLimiter { | |
constructor(rateLimiter, burstLimiter) { | |
this._rateLimiter = rateLimiter; | |
this._burstLimiter = burstLimiter; | |
} | |
/** | |
* Merge rate limiter response objects. Responses can be null | |
* | |
* @param {RateLimiterRes} [rlRes] Rate limiter response | |
* @param {RateLimiterRes} [blRes] Bursty limiter response | |
*/ | |
_combineRes(rlRes, blRes) { | |
if (!rlRes) { | |
return null; | |
} | |
return new RateLimiterRes( | |
rlRes.remainingPoints, | |
Math.min(rlRes.msBeforeNext, blRes ? blRes.msBeforeNext : 0), | |
rlRes.consumedPoints, | |
rlRes.isFirstInDuration | |
); | |
} | |
/** | |
* @param key | |
* @param pointsToConsume | |
* @param options | |
* @returns {Promise<any>} | |
*/ | |
consume(key, pointsToConsume = 1, options = {}) { | |
return this._rateLimiter.consume(key, pointsToConsume, options).catch((rlRej) => { | |
if (rlRej instanceof RateLimiterRes) { | |
return this._burstLimiter.consume(key, pointsToConsume, options).then((blRes) => { | |
return Promise.resolve(this._combineRes(rlRej, blRes)); | |
}).catch( | |
(blRej) => { | |
if (blRej instanceof RateLimiterRes) { | |
return Promise.reject(this._combineRes(rlRej, blRej)); | |
} else { | |
return Promise.reject(blRej); | |
} | |
} | |
); | |
} else { | |
return Promise.reject(rlRej); | |
} | |
}); | |
} | |
/** | |
* It doesn't expose available points from burstLimiter | |
* | |
* @param key | |
* @returns {Promise<RateLimiterRes>} | |
*/ | |
get(key) { | |
return Promise.all([ | |
this._rateLimiter.get(key), | |
this._burstLimiter.get(key) | |
]).then(([rlRes, blRes]) => { | |
return this._combineRes(rlRes, blRes); | |
}); | |
} | |
get points() { | |
return this._rateLimiter.points; | |
} | |
}; | |
} | |
}); | |
// node_modules/rate-limiter-flexible/index.js | |
var require_rate_limiter_flexible = __commonJS({ | |
"node_modules/rate-limiter-flexible/index.js"(exports2, module2) { | |
var RateLimiterRedis = require_RateLimiterRedis(); | |
var RateLimiterMongo = require_RateLimiterMongo(); | |
var RateLimiterMySQL = require_RateLimiterMySQL(); | |
var RateLimiterPostgres = require_RateLimiterPostgres(); | |
var { RateLimiterClusterMaster, RateLimiterClusterMasterPM2, RateLimiterCluster } = require_RateLimiterCluster(); | |
var RateLimiterMemory3 = require_RateLimiterMemory(); | |
var RateLimiterMemcache = require_RateLimiterMemcache(); | |
var RLWrapperBlackAndWhite = require_RLWrapperBlackAndWhite(); | |
var RateLimiterUnion = require_RateLimiterUnion(); | |
var RateLimiterQueue = require_RateLimiterQueue(); | |
var BurstyRateLimiter = require_BurstyRateLimiter(); | |
var RateLimiterRes = require_RateLimiterRes(); | |
module2.exports = { | |
RateLimiterRedis, | |
RateLimiterMongo, | |
RateLimiterMySQL, | |
RateLimiterPostgres, | |
RateLimiterMemory: RateLimiterMemory3, | |
RateLimiterMemcache, | |
RateLimiterClusterMaster, | |
RateLimiterClusterMasterPM2, | |
RateLimiterCluster, | |
RLWrapperBlackAndWhite, | |
RateLimiterUnion, | |
RateLimiterQueue, | |
BurstyRateLimiter, | |
RateLimiterRes | |
}; | |
} | |
}); | |
// node_modules/protobufjs/src/util/longbits.js | |
var require_longbits2 = __commonJS({ | |
"node_modules/protobufjs/src/util/longbits.js"(exports2, module2) { | |
"use strict"; | |
module2.exports = LongBits2; | |
var util2 = require_minimal2(); | |
function LongBits2(lo, hi) { | |
this.lo = lo >>> 0; | |
this.hi = hi >>> 0; | |
} | |
var zero = LongBits2.zero = new LongBits2(0, 0); | |
zero.toNumber = function() { | |
return 0; | |
}; | |
zero.zzEncode = zero.zzDecode = function() { | |
return this; | |
}; | |
zero.length = function() { | |
return 1; | |
}; | |
var zeroHash = LongBits2.zeroHash = "\0\0\0\0\0\0\0\0"; | |
LongBits2.fromNumber = function fromNumber(value) { | |
if (value === 0) | |
return zero; | |
var sign4 = value < 0; | |
if (sign4) | |
value = -value; | |
var lo = value >>> 0, hi = (value - lo) / 4294967296 >>> 0; | |
if (sign4) { | |
hi = ~hi >>> 0; | |
lo = ~lo >>> 0; | |
if (++lo > 4294967295) { | |
lo = 0; | |
if (++hi > 4294967295) | |
hi = 0; | |
} | |
} | |
return new LongBits2(lo, hi); | |
}; | |
LongBits2.from = function from17(value) { | |
if (typeof value === "number") | |
return LongBits2.fromNumber(value); | |
if (util2.isString(value)) { | |
if (util2.Long) | |
value = util2.Long.fromString(value); | |
else | |
return LongBits2.fromNumber(parseInt(value, 10)); | |
} | |
return value.low || value.high ? new LongBits2(value.low >>> 0, value.high >>> 0) : zero; | |
}; | |
LongBits2.prototype.toNumber = function toNumber(unsigned2) { | |
if (!unsigned2 && this.hi >>> 31) { | |
var lo = ~this.lo + 1 >>> 0, hi = ~this.hi >>> 0; | |
if (!lo) | |
hi = hi + 1 >>> 0; | |
return -(lo + hi * 4294967296); | |
} | |
return this.lo + this.hi * 4294967296; | |
}; | |
LongBits2.prototype.toLong = function toLong(unsigned2) { | |
return util2.Long ? new util2.Long(this.lo | 0, this.hi | 0, Boolean(unsigned2)) : { low: this.lo | 0, high: this.hi | 0, unsigned: Boolean(unsigned2) }; | |
}; | |
var charCodeAt = String.prototype.charCodeAt; | |
LongBits2.fromHash = function fromHash(hash3) { | |
if (hash3 === zeroHash) | |
return zero; | |
return new LongBits2( | |
(charCodeAt.call(hash3, 0) | charCodeAt.call(hash3, 1) << 8 | charCodeAt.call(hash3, 2) << 16 | charCodeAt.call(hash3, 3) << 24) >>> 0, | |
(charCodeAt.call(hash3, 4) | charCodeAt.call(hash3, 5) << 8 | charCodeAt.call(hash3, 6) << 16 | charCodeAt.call(hash3, 7) << 24) >>> 0 | |
); | |
}; | |
LongBits2.prototype.toHash = function toHash() { | |
return String.fromCharCode( | |
this.lo & 255, | |
this.lo >>> 8 & 255, | |
this.lo >>> 16 & 255, | |
this.lo >>> 24, | |
this.hi & 255, | |
this.hi >>> 8 & 255, | |
this.hi >>> 16 & 255, | |
this.hi >>> 24 | |
); | |
}; | |
LongBits2.prototype.zzEncode = function zzEncode() { | |
var mask = this.hi >> 31; | |
this.hi = ((this.hi << 1 | this.lo >>> 31) ^ mask) >>> 0; | |
this.lo = (this.lo << 1 ^ mask) >>> 0; | |
return this; | |
}; | |
LongBits2.prototype.zzDecode = function zzDecode() { | |
var mask = -(this.lo & 1); | |
this.lo = ((this.lo >>> 1 | this.hi << 31) ^ mask) >>> 0; | |
this.hi = (this.hi >>> 1 ^ mask) >>> 0; | |
return this; | |
}; | |
LongBits2.prototype.length = function length11() { | |
var part0 = this.lo, part1 = (this.lo >>> 28 | this.hi << 4) >>> 0, part2 = this.hi >>> 24; | |
return part2 === 0 ? part1 === 0 ? part0 < 16384 ? part0 < 128 ? 1 : 2 : part0 < 2097152 ? 3 : 4 : part1 < 16384 ? part1 < 128 ? 5 : 6 : part1 < 2097152 ? 7 : 8 : part2 < 128 ? 9 : 10; | |
}; | |
} | |
}); | |
// node_modules/protobufjs/src/util/minimal.js | |
var require_minimal2 = __commonJS({ | |
"node_modules/protobufjs/src/util/minimal.js"(exports2) { | |
"use strict"; | |
var util2 = exports2; | |
util2.asPromise = require_aspromise(); | |
util2.base64 = require_base64(); | |
util2.EventEmitter = require_eventemitter(); | |
util2.float = require_float(); | |
util2.inquire = require_inquire(); | |
util2.utf8 = require_utf8(); | |
util2.pool = require_pool(); | |
util2.LongBits = require_longbits2(); | |
util2.isNode = Boolean(typeof globalThis !== "undefined" && globalThis && globalThis.process && globalThis.process.versions && globalThis.process.versions.node); | |
util2.global = util2.isNode && globalThis || typeof window !== "undefined" && window || typeof self !== "undefined" && self || exports2; | |
util2.emptyArray = Object.freeze ? Object.freeze([]) : ( | |
/* istanbul ignore next */ | |
[] | |
); | |
util2.emptyObject = Object.freeze ? Object.freeze({}) : ( | |
/* istanbul ignore next */ | |
{} | |
); | |
util2.isInteger = Number.isInteger || /* istanbul ignore next */ | |
function isInteger(value) { | |
return typeof value === "number" && isFinite(value) && Math.floor(value) === value; | |
}; | |
util2.isString = function isString(value) { | |
return typeof value === "string" || value instanceof String; | |
}; | |
util2.isObject = function isObject(value) { | |
return value && typeof value === "object"; | |
}; | |
util2.isset = /** | |
* Checks if a property on a message is considered to be present. | |
* @param {Object} obj Plain object or message instance | |
* @param {string} prop Property name | |
* @returns {boolean} `true` if considered to be present, otherwise `false` | |
*/ | |
util2.isSet = function isSet(obj, prop) { | |
var value = obj[prop]; | |
if (value != null && obj.hasOwnProperty(prop)) | |
return typeof value !== "object" || (Array.isArray(value) ? value.length : Object.keys(value).length) > 0; | |
return false; | |
}; | |
util2.Buffer = function() { | |
try { | |
var Buffer2 = util2.inquire("buffer").Buffer; | |
return Buffer2.prototype.utf8Write ? Buffer2 : ( | |
/* istanbul ignore next */ | |
null | |
); | |
} catch (e) { | |
return null; | |
} | |
}(); | |
util2._Buffer_from = null; | |
util2._Buffer_allocUnsafe = null; | |
util2.newBuffer = function newBuffer(sizeOrArray) { | |
return typeof sizeOrArray === "number" ? util2.Buffer ? util2._Buffer_allocUnsafe(sizeOrArray) : new util2.Array(sizeOrArray) : util2.Buffer ? util2._Buffer_from(sizeOrArray) : typeof Uint8Array === "undefined" ? sizeOrArray : new Uint8Array(sizeOrArray); | |
}; | |
util2.Array = typeof Uint8Array !== "undefined" ? Uint8Array : Array; | |
util2.Long = /* istanbul ignore next */ | |
util2.global.dcodeIO && /* istanbul ignore next */ | |
util2.global.dcodeIO.Long || /* istanbul ignore next */ | |
util2.global.Long || util2.inquire("long"); | |
util2.key2Re = /^true|false|0|1$/; | |
util2.key32Re = /^-?(?:0|[1-9][0-9]*)$/; | |
util2.key64Re = /^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/; | |
util2.longToHash = function longToHash(value) { | |
return value ? util2.LongBits.from(value).toHash() : util2.LongBits.zeroHash; | |
}; | |
util2.longFromHash = function longFromHash(hash3, unsigned2) { | |
var bits2 = util2.LongBits.fromHash(hash3); | |
if (util2.Long) | |
return util2.Long.fromBits(bits2.lo, bits2.hi, unsigned2); | |
return bits2.toNumber(Boolean(unsigned2)); | |
}; | |
function merge2(dst, src11, ifNotSet) { | |
for (var keys = Object.keys(src11), i = 0; i < keys.length; ++i) | |
if (dst[keys[i]] === void 0 || !ifNotSet) | |
dst[keys[i]] = src11[keys[i]]; | |
return dst; | |
} | |
util2.merge = merge2; | |
util2.lcFirst = function lcFirst(str) { | |
return str.charAt(0).toLowerCase() + str.substring(1); | |
}; | |
function newError(name8) { | |
function CustomError(message2, properties) { | |
if (!(this instanceof CustomError)) | |
return new CustomError(message2, properties); | |
Object.defineProperty(this, "message", { get: function() { | |
return message2; | |
} }); | |
if (Error.captureStackTrace) | |
Error.captureStackTrace(this, CustomError); | |
else | |
Object.defineProperty(this, "stack", { value: new Error().stack || "" }); | |
if (properties) | |
merge2(this, properties); | |
} | |
(CustomError.prototype = Object.create(Error.prototype)).constructor = CustomError; | |
Object.defineProperty(CustomError.prototype, "name", { get: function() { | |
return name8; | |
} }); | |
CustomError.prototype.toString = function toString11() { | |
return this.name + ": " + this.message; | |
}; | |
return CustomError; | |
} | |
util2.newError = newError; | |
util2.ProtocolError = newError("ProtocolError"); | |
util2.oneOfGetter = function getOneOf(fieldNames) { | |
var fieldMap = {}; | |
for (var i = 0; i < fieldNames.length; ++i) | |
fieldMap[fieldNames[i]] = 1; | |
return function() { | |
for (var keys = Object.keys(this), i2 = keys.length - 1; i2 > -1; --i2) | |
if (fieldMap[keys[i2]] === 1 && this[keys[i2]] !== void 0 && this[keys[i2]] !== null) | |
return keys[i2]; | |
}; | |
}; | |
util2.oneOfSetter = function setOneOf(fieldNames) { | |
return function(name8) { | |
for (var i = 0; i < fieldNames.length; ++i) | |
if (fieldNames[i] !== name8) | |
delete this[fieldNames[i]]; | |
}; | |
}; | |
util2.toJSONOptions = { | |
longs: String, | |
enums: String, | |
bytes: String, | |
json: true | |
}; | |
util2._configure = function() { | |
var Buffer2 = util2.Buffer; | |
if (!Buffer2) { | |
util2._Buffer_from = util2._Buffer_allocUnsafe = null; | |
return; | |
} | |
util2._Buffer_from = Buffer2.from !== Uint8Array.from && Buffer2.from || /* istanbul ignore next */ | |
function Buffer_from(value, encoding) { | |
return new Buffer2(value, encoding); | |
}; | |
util2._Buffer_allocUnsafe = Buffer2.allocUnsafe || /* istanbul ignore next */ | |
function Buffer_allocUnsafe(size) { | |
return new Buffer2(size); | |
}; | |
}; | |
} | |
}); | |
// node_modules/protobufjs/src/writer.js | |
var require_writer2 = __commonJS({ | |
"node_modules/protobufjs/src/writer.js"(exports2, module2) { | |
"use strict"; | |
module2.exports = Writer; | |
var util2 = require_minimal2(); | |
var BufferWriter; | |
var LongBits2 = util2.LongBits; | |
var base647 = util2.base64; | |
var utf8 = util2.utf8; | |
function Op(fn, len, val) { | |
this.fn = fn; | |
this.len = len; | |
this.next = void 0; | |
this.val = val; | |
} | |
function noop2() { | |
} | |
function State(writer2) { | |
this.head = writer2.head; | |
this.tail = writer2.tail; | |
this.len = writer2.len; | |
this.next = writer2.states; | |
} | |
function Writer() { | |
this.len = 0; | |
this.head = new Op(noop2, 0, 0); | |
this.tail = this.head; | |
this.states = null; | |
} | |
var create13 = function create14() { | |
return util2.Buffer ? function create_buffer_setup() { | |
return (Writer.create = function create_buffer() { | |
return new BufferWriter(); | |
})(); | |
} : function create_array() { | |
return new Writer(); | |
}; | |
}; | |
Writer.create = create13(); | |
Writer.alloc = function alloc4(size) { | |
return new util2.Array(size); | |
}; | |
if (util2.Array !== Array) | |
Writer.alloc = util2.pool(Writer.alloc, util2.Array.prototype.subarray); | |
Writer.prototype._push = function push(fn, len, val) { | |
this.tail = this.tail.next = new Op(fn, len, val); | |
this.len += len; | |
return this; | |
}; | |
function writeByte(val, buf3, pos) { | |
buf3[pos] = val & 255; | |
} | |
function writeVarint32(val, buf3, pos) { | |
while (val > 127) { | |
buf3[pos++] = val & 127 | 128; | |
val >>>= 7; | |
} | |
buf3[pos] = val; | |
} | |
function VarintOp(len, val) { | |
this.len = len; | |
this.next = void 0; | |
this.val = val; | |
} | |
VarintOp.prototype = Object.create(Op.prototype); | |
VarintOp.prototype.fn = writeVarint32; | |
Writer.prototype.uint32 = function write_uint32(value) { | |
this.len += (this.tail = this.tail.next = new VarintOp( | |
(value = value >>> 0) < 128 ? 1 : value < 16384 ? 2 : value < 2097152 ? 3 : value < 268435456 ? 4 : 5, | |
value | |
)).len; | |
return this; | |
}; | |
Writer.prototype.int32 = function write_int32(value) { | |
return value < 0 ? this._push(writeVarint64, 10, LongBits2.fromNumber(value)) : this.uint32(value); | |
}; | |
Writer.prototype.sint32 = function write_sint32(value) { | |
return this.uint32((value << 1 ^ value >> 31) >>> 0); | |
}; | |
function writeVarint64(val, buf3, pos) { | |
while (val.hi) { | |
buf3[pos++] = val.lo & 127 | 128; | |
val.lo = (val.lo >>> 7 | val.hi << 25) >>> 0; | |
val.hi >>>= 7; | |
} | |
while (val.lo > 127) { | |
buf3[pos++] = val.lo & 127 | 128; | |
val.lo = val.lo >>> 7; | |
} | |
buf3[pos++] = val.lo; | |
} | |
Writer.prototype.uint64 = function write_uint64(value) { | |
var bits2 = LongBits2.from(value); | |
return this._push(writeVarint64, bits2.length(), bits2); | |
}; | |
Writer.prototype.int64 = Writer.prototype.uint64; | |
Writer.prototype.sint64 = function write_sint64(value) { | |
var bits2 = LongBits2.from(value).zzEncode(); | |
return this._push(writeVarint64, bits2.length(), bits2); | |
}; | |
Writer.prototype.bool = function write_bool(value) { | |
return this._push(writeByte, 1, value ? 1 : 0); | |
}; | |
function writeFixed32(val, buf3, pos) { | |
buf3[pos] = val & 255; | |
buf3[pos + 1] = val >>> 8 & 255; | |
buf3[pos + 2] = val >>> 16 & 255; | |
buf3[pos + 3] = val >>> 24; | |
} | |
Writer.prototype.fixed32 = function write_fixed32(value) { | |
return this._push(writeFixed32, 4, value >>> 0); | |
}; | |
Writer.prototype.sfixed32 = Writer.prototype.fixed32; | |
Writer.prototype.fixed64 = function write_fixed64(value) { | |
var bits2 = LongBits2.from(value); | |
return this._push(writeFixed32, 4, bits2.lo)._push(writeFixed32, 4, bits2.hi); | |
}; | |
Writer.prototype.sfixed64 = Writer.prototype.fixed64; | |
Writer.prototype.float = function write_float(value) { | |
return this._push(util2.float.writeFloatLE, 4, value); | |
}; | |
Writer.prototype.double = function write_double(value) { | |
return this._push(util2.float.writeDoubleLE, 8, value); | |
}; | |
var writeBytes = util2.Array.prototype.set ? function writeBytes_set(val, buf3, pos) { | |
buf3.set(val, pos); | |
} : function writeBytes_for(val, buf3, pos) { | |
for (var i = 0; i < val.length; ++i) | |
buf3[pos + i] = val[i]; | |
}; | |
Writer.prototype.bytes = function write_bytes(value) { | |
var len = value.length >>> 0; | |
if (!len) | |
return this._push(writeByte, 1, 0); | |
if (util2.isString(value)) { | |
var buf3 = Writer.alloc(len = base647.length(value)); | |
base647.decode(value, buf3, 0); | |
value = buf3; | |
} | |
return this.uint32(len)._push(writeBytes, len, value); | |
}; | |
Writer.prototype.string = function write_string(value) { | |
var len = utf8.length(value); | |
return len ? this.uint32(len)._push(utf8.write, len, value) : this._push(writeByte, 1, 0); | |
}; | |
Writer.prototype.fork = function fork() { | |
this.states = new State(this); | |
this.head = this.tail = new Op(noop2, 0, 0); | |
this.len = 0; | |
return this; | |
}; | |
Writer.prototype.reset = function reset() { | |
if (this.states) { | |
this.head = this.states.head; | |
this.tail = this.states.tail; | |
this.len = this.states.len; | |
this.states = this.states.next; | |
} else { | |
this.head = this.tail = new Op(noop2, 0, 0); | |
this.len = 0; | |
} | |
return this; | |
}; | |
Writer.prototype.ldelim = function ldelim() { | |
var head = this.head, tail = this.tail, len = this.len; | |
this.reset().uint32(len); | |
if (len) { | |
this.tail.next = head.next; | |
this.tail = tail; | |
this.len += len; | |
} | |
return this; | |
}; | |
Writer.prototype.finish = function finish() { | |
var head = this.head.next, buf3 = this.constructor.alloc(this.len), pos = 0; | |
while (head) { | |
head.fn(head.val, buf3, pos); | |
pos += head.len; | |
head = head.next; | |
} | |
return buf3; | |
}; | |
Writer._configure = function(BufferWriter_) { | |
BufferWriter = BufferWriter_; | |
Writer.create = create13(); | |
BufferWriter._configure(); | |
}; | |
} | |
}); | |
// node_modules/protobufjs/src/writer_buffer.js | |
var require_writer_buffer2 = __commonJS({ | |
"node_modules/protobufjs/src/writer_buffer.js"(exports2, module2) { | |
"use strict"; | |
module2.exports = BufferWriter; | |
var Writer = require_writer2(); | |
(BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter; | |
var util2 = require_minimal2(); | |
function BufferWriter() { | |
Writer.call(this); | |
} | |
BufferWriter._configure = function() { | |
BufferWriter.alloc = util2._Buffer_allocUnsafe; | |
BufferWriter.writeBytesBuffer = util2.Buffer && util2.Buffer.prototype instanceof Uint8Array && util2.Buffer.prototype.set.name === "set" ? function writeBytesBuffer_set(val, buf3, pos) { | |
buf3.set(val, pos); | |
} : function writeBytesBuffer_copy(val, buf3, pos) { | |
if (val.copy) | |
val.copy(buf3, pos, 0, val.length); | |
else | |
for (var i = 0; i < val.length; ) | |
buf3[pos++] = val[i++]; | |
}; | |
}; | |
BufferWriter.prototype.bytes = function write_bytes_buffer(value) { | |
if (util2.isString(value)) | |
value = util2._Buffer_from(value, "base64"); | |
var len = value.length >>> 0; | |
this.uint32(len); | |
if (len) | |
this._push(BufferWriter.writeBytesBuffer, len, value); | |
return this; | |
}; | |
function writeStringBuffer(val, buf3, pos) { | |
if (val.length < 40) | |
util2.utf8.write(val, buf3, pos); | |
else if (buf3.utf8Write) | |
buf3.utf8Write(val, pos); | |
else | |
buf3.write(val, pos); | |
} | |
BufferWriter.prototype.string = function write_string_buffer(value) { | |
var len = util2.Buffer.byteLength(value); | |
this.uint32(len); | |
if (len) | |
this._push(writeStringBuffer, len, value); | |
return this; | |
}; | |
BufferWriter._configure(); | |
} | |
}); | |
// node_modules/protobufjs/src/reader.js | |
var require_reader2 = __commonJS({ | |
"node_modules/protobufjs/src/reader.js"(exports2, module2) { | |
"use strict"; | |
module2.exports = Reader; | |
var util2 = require_minimal2(); | |
var BufferReader; | |
var LongBits2 = util2.LongBits; | |
var utf8 = util2.utf8; | |
function indexOutOfRange(reader3, writeLength) { | |
return RangeError("index out of range: " + reader3.pos + " + " + (writeLength || 1) + " > " + reader3.len); | |
} | |
function Reader(buffer3) { | |
this.buf = buffer3; | |
this.pos = 0; | |
this.len = buffer3.length; | |
} | |
var create_array = typeof Uint8Array !== "undefined" ? function create_typed_array(buffer3) { | |
if (buffer3 instanceof Uint8Array || Array.isArray(buffer3)) | |
return new Reader(buffer3); | |
throw Error("illegal buffer"); | |
} : function create_array2(buffer3) { | |
if (Array.isArray(buffer3)) | |
return new Reader(buffer3); | |
throw Error("illegal buffer"); | |
}; | |
var create13 = function create14() { | |
return util2.Buffer ? function create_buffer_setup(buffer3) { | |
return (Reader.create = function create_buffer(buffer4) { | |
return util2.Buffer.isBuffer(buffer4) ? new BufferReader(buffer4) : create_array(buffer4); | |
})(buffer3); | |
} : create_array; | |
}; | |
Reader.create = create13(); | |
Reader.prototype._slice = util2.Array.prototype.subarray || /* istanbul ignore next */ | |
util2.Array.prototype.slice; | |
Reader.prototype.uint32 = function read_uint32_setup() { | |
var value = 4294967295; | |
return function read_uint32() { | |
value = (this.buf[this.pos] & 127) >>> 0; | |
if (this.buf[this.pos++] < 128) | |
return value; | |
value = (value | (this.buf[this.pos] & 127) << 7) >>> 0; | |
if (this.buf[this.pos++] < 128) | |
return value; | |
value = (value | (this.buf[this.pos] & 127) << 14) >>> 0; | |
if (this.buf[this.pos++] < 128) | |
return value; | |
value = (value | (this.buf[this.pos] & 127) << 21) >>> 0; | |
if (this.buf[this.pos++] < 128) | |
return value; | |
value = (value | (this.buf[this.pos] & 15) << 28) >>> 0; | |
if (this.buf[this.pos++] < 128) | |
return value; | |
if ((this.pos += 5) > this.len) { | |
this.pos = this.len; | |
throw indexOutOfRange(this, 10); | |
} | |
return value; | |
}; | |
}(); | |
Reader.prototype.int32 = function read_int32() { | |
return this.uint32() | 0; | |
}; | |
Reader.prototype.sint32 = function read_sint32() { | |
var value = this.uint32(); | |
return value >>> 1 ^ -(value & 1) | 0; | |
}; | |
function readLongVarint() { | |
var bits2 = new LongBits2(0, 0); | |
var i = 0; | |
if (this.len - this.pos > 4) { | |
for (; i < 4; ++i) { | |
bits2.lo = (bits2.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0; | |
if (this.buf[this.pos++] < 128) | |
return bits2; | |
} | |
bits2.lo = (bits2.lo | (this.buf[this.pos] & 127) << 28) >>> 0; | |
bits2.hi = (bits2.hi | (this.buf[this.pos] & 127) >> 4) >>> 0; | |
if (this.buf[this.pos++] < 128) | |
return bits2; | |
i = 0; | |
} else { | |
for (; i < 3; ++i) { | |
if (this.pos >= this.len) | |
throw indexOutOfRange(this); | |
bits2.lo = (bits2.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0; | |
if (this.buf[this.pos++] < 128) | |
return bits2; | |
} | |
bits2.lo = (bits2.lo | (this.buf[this.pos++] & 127) << i * 7) >>> 0; | |
return bits2; | |
} | |
if (this.len - this.pos > 4) { | |
for (; i < 5; ++i) { | |
bits2.hi = (bits2.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0; | |
if (this.buf[this.pos++] < 128) | |
return bits2; | |
} | |
} else { | |
for (; i < 5; ++i) { | |
if (this.pos >= this.len) | |
throw indexOutOfRange(this); | |
bits2.hi = (bits2.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0; | |
if (this.buf[this.pos++] < 128) | |
return bits2; | |
} | |
} | |
throw Error("invalid varint encoding"); | |
} | |
Reader.prototype.bool = function read_bool() { | |
return this.uint32() !== 0; | |
}; | |
function readFixed32_end(buf3, end) { | |
return (buf3[end - 4] | buf3[end - 3] << 8 | buf3[end - 2] << 16 | buf3[end - 1] << 24) >>> 0; | |
} | |
Reader.prototype.fixed32 = function read_fixed32() { | |
if (this.pos + 4 > this.len) | |
throw indexOutOfRange(this, 4); | |
return readFixed32_end(this.buf, this.pos += 4); | |
}; | |
Reader.prototype.sfixed32 = function read_sfixed32() { | |
if (this.pos + 4 > this.len) | |
throw indexOutOfRange(this, 4); | |
return readFixed32_end(this.buf, this.pos += 4) | 0; | |
}; | |
function readFixed64() { | |
if (this.pos + 8 > this.len) | |
throw indexOutOfRange(this, 8); | |
return new LongBits2(readFixed32_end(this.buf, this.pos += 4), readFixed32_end(this.buf, this.pos += 4)); | |
} | |
Reader.prototype.float = function read_float() { | |
if (this.pos + 4 > this.len) | |
throw indexOutOfRange(this, 4); | |
var value = util2.float.readFloatLE(this.buf, this.pos); | |
this.pos += 4; | |
return value; | |
}; | |
Reader.prototype.double = function read_double() { | |
if (this.pos + 8 > this.len) | |
throw indexOutOfRange(this, 4); | |
var value = util2.float.readDoubleLE(this.buf, this.pos); | |
this.pos += 8; | |
return value; | |
}; | |
Reader.prototype.bytes = function read_bytes() { | |
var length11 = this.uint32(), start = this.pos, end = this.pos + length11; | |
if (end > this.len) | |
throw indexOutOfRange(this, length11); | |
this.pos += length11; | |
if (Array.isArray(this.buf)) | |
return this.buf.slice(start, end); | |
return start === end ? new this.buf.constructor(0) : this._slice.call(this.buf, start, end); | |
}; | |
Reader.prototype.string = function read_string() { | |
var bytes3 = this.bytes(); | |
return utf8.read(bytes3, 0, bytes3.length); | |
}; | |
Reader.prototype.skip = function skip(length11) { | |
if (typeof length11 === "number") { | |
if (this.pos + length11 > this.len) | |
throw indexOutOfRange(this, length11); | |
this.pos += length11; | |
} else { | |
do { | |
if (this.pos >= this.len) | |
throw indexOutOfRange(this); | |
} while (this.buf[this.pos++] & 128); | |
} | |
return this; | |
}; | |
Reader.prototype.skipType = function(wireType) { | |
switch (wireType) { | |
case 0: | |
this.skip(); | |
break; | |
case 1: | |
this.skip(8); | |
break; | |
case 2: | |
this.skip(this.uint32()); | |
break; | |
case 3: | |
while ((wireType = this.uint32() & 7) !== 4) { | |
this.skipType(wireType); | |
} | |
break; | |
case 5: | |
this.skip(4); | |
break; | |
default: | |
throw Error("invalid wire type " + wireType + " at offset " + this.pos); | |
} | |
return this; | |
}; | |
Reader._configure = function(BufferReader_) { | |
BufferReader = BufferReader_; | |
Reader.create = create13(); | |
BufferReader._configure(); | |
var fn = util2.Long ? "toLong" : ( | |
/* istanbul ignore next */ | |
"toNumber" | |
); | |
util2.merge(Reader.prototype, { | |
int64: function read_int64() { | |
return readLongVarint.call(this)[fn](false); | |
}, | |
uint64: function read_uint64() { | |
return readLongVarint.call(this)[fn](true); | |
}, | |
sint64: function read_sint64() { | |
return readLongVarint.call(this).zzDecode()[fn](false); | |
}, | |
fixed64: function read_fixed64() { | |
return readFixed64.call(this)[fn](true); | |
}, | |
sfixed64: function read_sfixed64() { | |
return readFixed64.call(this)[fn](false); | |
} | |
}); | |
}; | |
} | |
}); | |
// node_modules/protobufjs/src/reader_buffer.js | |
var require_reader_buffer2 = __commonJS({ | |
"node_modules/protobufjs/src/reader_buffer.js"(exports2, module2) { | |
"use strict"; | |
module2.exports = BufferReader; | |
var Reader = require_reader2(); | |
(BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader; | |
var util2 = require_minimal2(); | |
function BufferReader(buffer3) { | |
Reader.call(this, buffer3); | |
} | |
BufferReader._configure = function() { | |
if (util2.Buffer) | |
BufferReader.prototype._slice = util2.Buffer.prototype.slice; | |
}; | |
BufferReader.prototype.string = function read_string_buffer() { | |
var len = this.uint32(); | |
return this.buf.utf8Slice ? this.buf.utf8Slice(this.pos, this.pos = Math.min(this.pos + len, this.len)) : this.buf.toString("utf-8", this.pos, this.pos = Math.min(this.pos + len, this.len)); | |
}; | |
BufferReader._configure(); | |
} | |
}); | |
// node_modules/protobufjs/src/rpc/service.js | |
var require_service = __commonJS({ | |
"node_modules/protobufjs/src/rpc/service.js"(exports2, module2) { | |
"use strict"; | |
module2.exports = Service; | |
var util2 = require_minimal2(); | |
(Service.prototype = Object.create(util2.EventEmitter.prototype)).constructor = Service; | |
function Service(rpcImpl, requestDelimited, responseDelimited) { | |
if (typeof rpcImpl !== "function") | |
throw TypeError("rpcImpl must be a function"); | |
util2.EventEmitter.call(this); | |
this.rpcImpl = rpcImpl; | |
this.requestDelimited = Boolean(requestDelimited); | |
this.responseDelimited = Boolean(responseDelimited); | |
} | |
Service.prototype.rpcCall = function rpcCall(method, requestCtor, responseCtor, request2, callback) { | |
if (!request2) | |
throw TypeError("request must be specified"); | |
var self2 = this; | |
if (!callback) | |
return util2.asPromise(rpcCall, self2, method, requestCtor, responseCtor, request2); | |
if (!self2.rpcImpl) { | |
setTimeout(function() { | |
callback(Error("already ended")); | |
}, 0); | |
return void 0; | |
} | |
try { | |
return self2.rpcImpl( | |
method, | |
requestCtor[self2.requestDelimited ? "encodeDelimited" : "encode"](request2).finish(), | |
function rpcCallback(err, response) { | |
if (err) { | |
self2.emit("error", err, method); | |
return callback(err); | |
} | |
if (response === null) { | |
self2.end( | |
/* endedByRPC */ | |
true | |
); | |
return void 0; | |
} | |
if (!(response instanceof responseCtor)) { | |
try { | |
response = responseCtor[self2.responseDelimited ? "decodeDelimited" : "decode"](response); | |
} catch (err2) { | |
self2.emit("error", err2, method); | |
return callback(err2); | |
} | |
} | |
self2.emit("data", response, method); | |
return callback(null, response); | |
} | |
); | |
} catch (err) { | |
self2.emit("error", err, method); | |
setTimeout(function() { | |
callback(err); | |
}, 0); | |
return void 0; | |
} | |
}; | |
Service.prototype.end = function end(endedByRPC) { | |
if (this.rpcImpl) { | |
if (!endedByRPC) | |
this.rpcImpl(null, null, null); | |
this.rpcImpl = null; | |
this.emit("end").off(); | |
} | |
return this; | |
}; | |
} | |
}); | |
// node_modules/protobufjs/src/rpc.js | |
var require_rpc = __commonJS({ | |
"node_modules/protobufjs/src/rpc.js"(exports2) { | |
"use strict"; | |
var rpc = exports2; | |
rpc.Service = require_service(); | |
} | |
}); | |
// node_modules/protobufjs/src/roots.js | |
var require_roots = __commonJS({ | |
"node_modules/protobufjs/src/roots.js"(exports2, module2) { | |
"use strict"; | |
module2.exports = {}; | |
} | |
}); | |
// node_modules/protobufjs/src/index-minimal.js | |
var require_index_minimal = __commonJS({ | |
"node_modules/protobufjs/src/index-minimal.js"(exports2) { | |
"use strict"; | |
var protobuf2 = exports2; | |
protobuf2.build = "minimal"; | |
protobuf2.Writer = require_writer2(); | |
protobuf2.BufferWriter = require_writer_buffer2(); | |
protobuf2.Reader = require_reader2(); | |
protobuf2.BufferReader = require_reader_buffer2(); | |
protobuf2.util = require_minimal2(); | |
protobuf2.rpc = require_rpc(); | |
protobuf2.roots = require_roots(); | |
protobuf2.configure = configure2; | |
function configure2() { | |
protobuf2.util._configure(); | |
protobuf2.Writer._configure(protobuf2.BufferWriter); | |
protobuf2.Reader._configure(protobuf2.BufferReader); | |
} | |
configure2(); | |
} | |
}); | |
// node_modules/protobufjs/minimal.js | |
var require_minimal3 = __commonJS({ | |
"node_modules/protobufjs/minimal.js"(exports2, module2) { | |
"use strict"; | |
module2.exports = require_index_minimal(); | |
} | |
}); | |
// node_modules/@chainsafe/libp2p-gossipsub/dist/src/message/rpc.cjs | |
var require_rpc2 = __commonJS({ | |
"node_modules/@chainsafe/libp2p-gossipsub/dist/src/message/rpc.cjs"(exports2, module2) { | |
(function(global2, factory) { | |
if (typeof define === "function" && define.amd) | |
define(["protobufjs/minimal"], factory); | |
else if (typeof __require === "function" && typeof module2 === "object" && module2 && module2.exports) | |
module2.exports = factory(require_minimal3()); | |
})(exports2, function($protobuf) { | |
"use strict"; | |
var $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util; | |
var $root = $protobuf.roots["default"] || ($protobuf.roots["default"] = {}); | |
$root.RPC = function() { | |
function RPC3(p) { | |
this.subscriptions = []; | |
this.messages = []; | |
if (p) { | |
for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) | |
if (p[ks[i]] != null) | |
this[ks[i]] = p[ks[i]]; | |
} | |
} | |
RPC3.prototype.subscriptions = $util.emptyArray; | |
RPC3.prototype.messages = $util.emptyArray; | |
RPC3.prototype.control = null; | |
var $oneOfFields; | |
Object.defineProperty(RPC3.prototype, "_control", { | |
get: $util.oneOfGetter($oneOfFields = ["control"]), | |
set: $util.oneOfSetter($oneOfFields) | |
}); | |
RPC3.encode = function encode39(m, w) { | |
if (!w) | |
w = $Writer.create(); | |
if (m.subscriptions != null && m.subscriptions.length) { | |
for (var i = 0; i < m.subscriptions.length; ++i) | |
$root.RPC.SubOpts.encode(m.subscriptions[i], w.uint32(10).fork()).ldelim(); | |
} | |
if (m.messages != null && m.messages.length) { | |
for (var i = 0; i < m.messages.length; ++i) | |
$root.RPC.Message.encode(m.messages[i], w.uint32(18).fork()).ldelim(); | |
} | |
if (m.control != null && Object.hasOwnProperty.call(m, "control")) | |
$root.RPC.ControlMessage.encode(m.control, w.uint32(26).fork()).ldelim(); | |
return w; | |
}; | |
RPC3.decode = function decode50(r, l) { | |
if (!(r instanceof $Reader)) | |
r = $Reader.create(r); | |
var c = l === void 0 ? r.len : r.pos + l, m = new $root.RPC(); | |
while (r.pos < c) { | |
var t = r.uint32(); | |
switch (t >>> 3) { | |
case 1: | |
if (!(m.subscriptions && m.subscriptions.length)) | |
m.subscriptions = []; | |
m.subscriptions.push($root.RPC.SubOpts.decode(r, r.uint32())); | |
break; | |
case 2: | |
if (!(m.messages && m.messages.length)) | |
m.messages = []; | |
m.messages.push($root.RPC.Message.decode(r, r.uint32())); | |
break; | |
case 3: | |
m.control = $root.RPC.ControlMessage.decode(r, r.uint32()); | |
break; | |
default: | |
r.skipType(t & 7); | |
break; | |
} | |
} | |
return m; | |
}; | |
RPC3.fromObject = function fromObject(d) { | |
if (d instanceof $root.RPC) | |
return d; | |
var m = new $root.RPC(); | |
if (d.subscriptions) { | |
if (!Array.isArray(d.subscriptions)) | |
throw TypeError(".RPC.subscriptions: array expected"); | |
m.subscriptions = []; | |
for (var i = 0; i < d.subscriptions.length; ++i) { | |
if (typeof d.subscriptions[i] !== "object") | |
throw TypeError(".RPC.subscriptions: object expected"); | |
m.subscriptions[i] = $root.RPC.SubOpts.fromObject(d.subscriptions[i]); | |
} | |
} | |
if (d.messages) { | |
if (!Array.isArray(d.messages)) | |
throw TypeError(".RPC.messages: array expected"); | |
m.messages = []; | |
for (var i = 0; i < d.messages.length; ++i) { | |
if (typeof d.messages[i] !== "object") | |
throw TypeError(".RPC.messages: object expected"); | |
m.messages[i] = $root.RPC.Message.fromObject(d.messages[i]); | |
} | |
} | |
if (d.control != null) { | |
if (typeof d.control !== "object") | |
throw TypeError(".RPC.control: object expected"); | |
m.control = $root.RPC.ControlMessage.fromObject(d.control); | |
} | |
return m; | |
}; | |
RPC3.toObject = function toObject(m, o) { | |
if (!o) | |
o = {}; | |
var d = {}; | |
if (o.arrays || o.defaults) { | |
d.subscriptions = []; | |
d.messages = []; | |
} | |
if (m.subscriptions && m.subscriptions.length) { | |
d.subscriptions = []; | |
for (var j = 0; j < m.subscriptions.length; ++j) { | |
d.subscriptions[j] = $root.RPC.SubOpts.toObject(m.subscriptions[j], o); | |
} | |
} | |
if (m.messages && m.messages.length) { | |
d.messages = []; | |
for (var j = 0; j < m.messages.length; ++j) { | |
d.messages[j] = $root.RPC.Message.toObject(m.messages[j], o); | |
} | |
} | |
if (m.control != null && m.hasOwnProperty("control")) { | |
d.control = $root.RPC.ControlMessage.toObject(m.control, o); | |
if (o.oneofs) | |
d._control = "control"; | |
} | |
return d; | |
}; | |
RPC3.prototype.toJSON = function toJSON() { | |
return this.constructor.toObject(this, $protobuf.util.toJSONOptions); | |
}; | |
RPC3.SubOpts = function() { | |
function SubOpts(p) { | |
if (p) { | |
for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) | |
if (p[ks[i]] != null) | |
this[ks[i]] = p[ks[i]]; | |
} | |
} | |
SubOpts.prototype.subscribe = null; | |
SubOpts.prototype.topic = null; | |
var $oneOfFields2; | |
Object.defineProperty(SubOpts.prototype, "_subscribe", { | |
get: $util.oneOfGetter($oneOfFields2 = ["subscribe"]), | |
set: $util.oneOfSetter($oneOfFields2) | |
}); | |
Object.defineProperty(SubOpts.prototype, "_topic", { | |
get: $util.oneOfGetter($oneOfFields2 = ["topic"]), | |
set: $util.oneOfSetter($oneOfFields2) | |
}); | |
SubOpts.encode = function encode39(m, w) { | |
if (!w) | |
w = $Writer.create(); | |
if (m.subscribe != null && Object.hasOwnProperty.call(m, "subscribe")) | |
w.uint32(8).bool(m.subscribe); | |
if (m.topic != null && Object.hasOwnProperty.call(m, "topic")) | |
w.uint32(18).string(m.topic); | |
return w; | |
}; | |
SubOpts.decode = function decode50(r, l) { | |
if (!(r instanceof $Reader)) | |
r = $Reader.create(r); | |
var c = l === void 0 ? r.len : r.pos + l, m = new $root.RPC.SubOpts(); | |
while (r.pos < c) { | |
var t = r.uint32(); | |
switch (t >>> 3) { | |
case 1: | |
m.subscribe = r.bool(); | |
break; | |
case 2: | |
m.topic = r.string(); | |
break; | |
default: | |
r.skipType(t & 7); | |
break; | |
} | |
} | |
return m; | |
}; | |
SubOpts.fromObject = function fromObject(d) { | |
if (d instanceof $root.RPC.SubOpts) | |
return d; | |
var m = new $root.RPC.SubOpts(); | |
if (d.subscribe != null) { | |
m.subscribe = Boolean(d.subscribe); | |
} | |
if (d.topic != null) { | |
m.topic = String(d.topic); | |
} | |
return m; | |
}; | |
SubOpts.toObject = function toObject(m, o) { | |
if (!o) | |
o = {}; | |
var d = {}; | |
if (m.subscribe != null && m.hasOwnProperty("subscribe")) { | |
d.subscribe = m.subscribe; | |
if (o.oneofs) | |
d._subscribe = "subscribe"; | |
} | |
if (m.topic != null && m.hasOwnProperty("topic")) { | |
d.topic = m.topic; | |
if (o.oneofs) | |
d._topic = "topic"; | |
} | |
return d; | |
}; | |
SubOpts.prototype.toJSON = function toJSON() { | |
return this.constructor.toObject(this, $protobuf.util.toJSONOptions); | |
}; | |
return SubOpts; | |
}(); | |
RPC3.Message = function() { | |
function Message7(p) { | |
if (p) { | |
for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) | |
if (p[ks[i]] != null) | |
this[ks[i]] = p[ks[i]]; | |
} | |
} | |
Message7.prototype.from = null; | |
Message7.prototype.data = null; | |
Message7.prototype.seqno = null; | |
Message7.prototype.topic = ""; | |
Message7.prototype.signature = null; | |
Message7.prototype.key = null; | |
var $oneOfFields2; | |
Object.defineProperty(Message7.prototype, "_from", { | |
get: $util.oneOfGetter($oneOfFields2 = ["from"]), | |
set: $util.oneOfSetter($oneOfFields2) | |
}); | |
Object.defineProperty(Message7.prototype, "_data", { | |
get: $util.oneOfGetter($oneOfFields2 = ["data"]), | |
set: $util.oneOfSetter($oneOfFields2) | |
}); | |
Object.defineProperty(Message7.prototype, "_seqno", { | |
get: $util.oneOfGetter($oneOfFields2 = ["seqno"]), | |
set: $util.oneOfSetter($oneOfFields2) | |
}); | |
Object.defineProperty(Message7.prototype, "_signature", { | |
get: $util.oneOfGetter($oneOfFields2 = ["signature"]), | |
set: $util.oneOfSetter($oneOfFields2) | |
}); | |
Object.defineProperty(Message7.prototype, "_key", { | |
get: $util.oneOfGetter($oneOfFields2 = ["key"]), | |
set: $util.oneOfSetter($oneOfFields2) | |
}); | |
Message7.encode = function encode39(m, w) { | |
if (!w) | |
w = $Writer.create(); | |
if (m.from != null && Object.hasOwnProperty.call(m, "from")) | |
w.uint32(10).bytes(m.from); | |
if (m.data != null && Object.hasOwnProperty.call(m, "data")) | |
w.uint32(18).bytes(m.data); | |
if (m.seqno != null && Object.hasOwnProperty.call(m, "seqno")) | |
w.uint32(26).bytes(m.seqno); | |
w.uint32(34).string(m.topic); | |
if (m.signature != null && Object.hasOwnProperty.call(m, "signature")) | |
w.uint32(42).bytes(m.signature); | |
if (m.key != null && Object.hasOwnProperty.call(m, "key")) | |
w.uint32(50).bytes(m.key); | |
return w; | |
}; | |
Message7.decode = function decode50(r, l) { | |
if (!(r instanceof $Reader)) | |
r = $Reader.create(r); | |
var c = l === void 0 ? r.len : r.pos + l, m = new $root.RPC.Message(); | |
while (r.pos < c) { | |
var t = r.uint32(); | |
switch (t >>> 3) { | |
case 1: | |
m.from = r.bytes(); | |
break; | |
case 2: | |
m.data = r.bytes(); | |
break; | |
case 3: | |
m.seqno = r.bytes(); | |
break; | |
case 4: | |
m.topic = r.string(); | |
break; | |
case 5: | |
m.signature = r.bytes(); | |
break; | |
case 6: | |
m.key = r.bytes(); | |
break; | |
default: | |
r.skipType(t & 7); | |
break; | |
} | |
} | |
if (!m.hasOwnProperty("topic")) | |
throw $util.ProtocolError("missing required 'topic'", { instance: m }); | |
return m; | |
}; | |
Message7.fromObject = function fromObject(d) { | |
if (d instanceof $root.RPC.Message) | |
return d; | |
var m = new $root.RPC.Message(); | |
if (d.from != null) { | |
if (typeof d.from === "string") | |
$util.base64.decode(d.from, m.from = $util.newBuffer($util.base64.length(d.from)), 0); | |
else if (d.from.length) | |
m.from = d.from; | |
} | |
if (d.data != null) { | |
if (typeof d.data === "string") | |
$util.base64.decode(d.data, m.data = $util.newBuffer($util.base64.length(d.data)), 0); | |
else if (d.data.length) | |
m.data = d.data; | |
} | |
if (d.seqno != null) { | |
if (typeof d.seqno === "string") | |
$util.base64.decode(d.seqno, m.seqno = $util.newBuffer($util.base64.length(d.seqno)), 0); | |
else if (d.seqno.length) | |
m.seqno = d.seqno; | |
} | |
if (d.topic != null) { | |
m.topic = String(d.topic); | |
} | |
if (d.signature != null) { | |
if (typeof d.signature === "string") | |
$util.base64.decode(d.signature, m.signature = $util.newBuffer($util.base64.length(d.signature)), 0); | |
else if (d.signature.length) | |
m.signature = d.signature; | |
} | |
if (d.key != null) { | |
if (typeof d.key === "string") | |
$util.base64.decode(d.key, m.key = $util.newBuffer($util.base64.length(d.key)), 0); | |
else if (d.key.length) | |
m.key = d.key; | |
} | |
return m; | |
}; | |
Message7.toObject = function toObject(m, o) { | |
if (!o) | |
o = {}; | |
var d = {}; | |
if (o.defaults) { | |
d.topic = ""; | |
} | |
if (m.from != null && m.hasOwnProperty("from")) { | |
d.from = o.bytes === String ? $util.base64.encode(m.from, 0, m.from.length) : o.bytes === Array ? Array.prototype.slice.call(m.from) : m.from; | |
if (o.oneofs) | |
d._from = "from"; | |
} | |
if (m.data != null && m.hasOwnProperty("data")) { | |
d.data = o.bytes === String ? $util.base64.encode(m.data, 0, m.data.length) : o.bytes === Array ? Array.prototype.slice.call(m.data) : m.data; | |
if (o.oneofs) | |
d._data = "data"; | |
} | |
if (m.seqno != null && m.hasOwnProperty("seqno")) { | |
d.seqno = o.bytes === String ? $util.base64.encode(m.seqno, 0, m.seqno.length) : o.bytes === Array ? Array.prototype.slice.call(m.seqno) : m.seqno; | |
if (o.oneofs) | |
d._seqno = "seqno"; | |
} | |
if (m.topic != null && m.hasOwnProperty("topic")) { | |
d.topic = m.topic; | |
} | |
if (m.signature != null && m.hasOwnProperty("signature")) { | |
d.signature = o.bytes === String ? $util.base64.encode(m.signature, 0, m.signature.length) : o.bytes === Array ? Array.prototype.slice.call(m.signature) : m.signature; | |
if (o.oneofs) | |
d._signature = "signature"; | |
} | |
if (m.key != null && m.hasOwnProperty("key")) { | |
d.key = o.bytes === String ? $util.base64.encode(m.key, 0, m.key.length) : o.bytes === Array ? Array.prototype.slice.call(m.key) : m.key; | |
if (o.oneofs) | |
d._key = "key"; | |
} | |
return d; | |
}; | |
Message7.prototype.toJSON = function toJSON() { | |
return this.constructor.toObject(this, $protobuf.util.toJSONOptions); | |
}; | |
return Message7; | |
}(); | |
RPC3.ControlMessage = function() { | |
function ControlMessage(p) { | |
this.ihave = []; | |
this.iwant = []; | |
this.graft = []; | |
this.prune = []; | |
if (p) { | |
for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) | |
if (p[ks[i]] != null) | |
this[ks[i]] = p[ks[i]]; | |
} | |
} | |
ControlMessage.prototype.ihave = $util.emptyArray; | |
ControlMessage.prototype.iwant = $util.emptyArray; | |
ControlMessage.prototype.graft = $util.emptyArray; | |
ControlMessage.prototype.prune = $util.emptyArray; | |
ControlMessage.encode = function encode39(m, w) { | |
if (!w) | |
w = $Writer.create(); | |
if (m.ihave != null && m.ihave.length) { | |
for (var i = 0; i < m.ihave.length; ++i) | |
$root.RPC.ControlIHave.encode(m.ihave[i], w.uint32(10).fork()).ldelim(); | |
} | |
if (m.iwant != null && m.iwant.length) { | |
for (var i = 0; i < m.iwant.length; ++i) | |
$root.RPC.ControlIWant.encode(m.iwant[i], w.uint32(18).fork()).ldelim(); | |
} | |
if (m.graft != null && m.graft.length) { | |
for (var i = 0; i < m.graft.length; ++i) | |
$root.RPC.ControlGraft.encode(m.graft[i], w.uint32(26).fork()).ldelim(); | |
} | |
if (m.prune != null && m.prune.length) { | |
for (var i = 0; i < m.prune.length; ++i) | |
$root.RPC.ControlPrune.encode(m.prune[i], w.uint32(34).fork()).ldelim(); | |
} | |
return w; | |
}; | |
ControlMessage.decode = function decode50(r, l) { | |
if (!(r instanceof $Reader)) | |
r = $Reader.create(r); | |
var c = l === void 0 ? r.len : r.pos + l, m = new $root.RPC.ControlMessage(); | |
while (r.pos < c) { | |
var t = r.uint32(); | |
switch (t >>> 3) { | |
case 1: | |
if (!(m.ihave && m.ihave.length)) | |
m.ihave = []; | |
m.ihave.push($root.RPC.ControlIHave.decode(r, r.uint32())); | |
break; | |
case 2: | |
if (!(m.iwant && m.iwant.length)) | |
m.iwant = []; | |
m.iwant.push($root.RPC.ControlIWant.decode(r, r.uint32())); | |
break; | |
case 3: | |
if (!(m.graft && m.graft.length)) | |
m.graft = []; | |
m.graft.push($root.RPC.ControlGraft.decode(r, r.uint32())); | |
break; | |
case 4: | |
if (!(m.prune && m.prune.length)) | |
m.prune = []; | |
m.prune.push($root.RPC.ControlPrune.decode(r, r.uint32())); | |
break; | |
default: | |
r.skipType(t & 7); | |
break; | |
} | |
} | |
return m; | |
}; | |
ControlMessage.fromObject = function fromObject(d) { | |
if (d instanceof $root.RPC.ControlMessage) | |
return d; | |
var m = new $root.RPC.ControlMessage(); | |
if (d.ihave) { | |
if (!Array.isArray(d.ihave)) | |
throw TypeError(".RPC.ControlMessage.ihave: array expected"); | |
m.ihave = []; | |
for (var i = 0; i < d.ihave.length; ++i) { | |
if (typeof d.ihave[i] !== "object") | |
throw TypeError(".RPC.ControlMessage.ihave: object expected"); | |
m.ihave[i] = $root.RPC.ControlIHave.fromObject(d.ihave[i]); | |
} | |
} | |
if (d.iwant) { | |
if (!Array.isArray(d.iwant)) | |
throw TypeError(".RPC.ControlMessage.iwant: array expected"); | |
m.iwant = []; | |
for (var i = 0; i < d.iwant.length; ++i) { | |
if (typeof d.iwant[i] !== "object") | |
throw TypeError(".RPC.ControlMessage.iwant: object expected"); | |
m.iwant[i] = $root.RPC.ControlIWant.fromObject(d.iwant[i]); | |
} | |
} | |
if (d.graft) { | |
if (!Array.isArray(d.graft)) | |
throw TypeError(".RPC.ControlMessage.graft: array expected"); | |
m.graft = []; | |
for (var i = 0; i < d.graft.length; ++i) { | |
if (typeof d.graft[i] !== "object") | |
throw TypeError(".RPC.ControlMessage.graft: object expected"); | |
m.graft[i] = $root.RPC.ControlGraft.fromObject(d.graft[i]); | |
} | |
} | |
if (d.prune) { | |
if (!Array.isArray(d.prune)) | |
throw TypeError(".RPC.ControlMessage.prune: array expected"); | |
m.prune = []; | |
for (var i = 0; i < d.prune.length; ++i) { | |
if (typeof d.prune[i] !== "object") | |
throw TypeError(".RPC.ControlMessage.prune: object expected"); | |
m.prune[i] = $root.RPC.ControlPrune.fromObject(d.prune[i]); | |
} | |
} | |
return m; | |
}; | |
ControlMessage.toObject = function toObject(m, o) { | |
if (!o) | |
o = {}; | |
var d = {}; | |
if (o.arrays || o.defaults) { | |
d.ihave = []; | |
d.iwant = []; | |
d.graft = []; | |
d.prune = []; | |
} | |
if (m.ihave && m.ihave.length) { | |
d.ihave = []; | |
for (var j = 0; j < m.ihave.length; ++j) { | |
d.ihave[j] = $root.RPC.ControlIHave.toObject(m.ihave[j], o); | |
} | |
} | |
if (m.iwant && m.iwant.length) { | |
d.iwant = []; | |
for (var j = 0; j < m.iwant.length; ++j) { | |
d.iwant[j] = $root.RPC.ControlIWant.toObject(m.iwant[j], o); | |
} | |
} | |
if (m.graft && m.graft.length) { | |
d.graft = []; | |
for (var j = 0; j < m.graft.length; ++j) { | |
d.graft[j] = $root.RPC.ControlGraft.toObject(m.graft[j], o); | |
} | |
} | |
if (m.prune && m.prune.length) { | |
d.prune = []; | |
for (var j = 0; j < m.prune.length; ++j) { | |
d.prune[j] = $root.RPC.ControlPrune.toObject(m.prune[j], o); | |
} | |
} | |
return d; | |
}; | |
ControlMessage.prototype.toJSON = function toJSON() { | |
return this.constructor.toObject(this, $protobuf.util.toJSONOptions); | |
}; | |
return ControlMessage; | |
}(); | |
RPC3.ControlIHave = function() { | |
function ControlIHave(p) { | |
this.messageIDs = []; | |
if (p) { | |
for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) | |
if (p[ks[i]] != null) | |
this[ks[i]] = p[ks[i]]; | |
} | |
} | |
ControlIHave.prototype.topicID = null; | |
ControlIHave.prototype.messageIDs = $util.emptyArray; | |
var $oneOfFields2; | |
Object.defineProperty(ControlIHave.prototype, "_topicID", { | |
get: $util.oneOfGetter($oneOfFields2 = ["topicID"]), | |
set: $util.oneOfSetter($oneOfFields2) | |
}); | |
ControlIHave.encode = function encode39(m, w) { | |
if (!w) | |
w = $Writer.create(); | |
if (m.topicID != null && Object.hasOwnProperty.call(m, "topicID")) | |
w.uint32(10).string(m.topicID); | |
if (m.messageIDs != null && m.messageIDs.length) { | |
for (var i = 0; i < m.messageIDs.length; ++i) | |
w.uint32(18).bytes(m.messageIDs[i]); | |
} | |
return w; | |
}; | |
ControlIHave.decode = function decode50(r, l) { | |
if (!(r instanceof $Reader)) | |
r = $Reader.create(r); | |
var c = l === void 0 ? r.len : r.pos + l, m = new $root.RPC.ControlIHave(); | |
while (r.pos < c) { | |
var t = r.uint32(); | |
switch (t >>> 3) { | |
case 1: | |
m.topicID = r.string(); | |
break; | |
case 2: | |
if (!(m.messageIDs && m.messageIDs.length)) | |
m.messageIDs = []; | |
m.messageIDs.push(r.bytes()); | |
break; | |
default: | |
r.skipType(t & 7); | |
break; | |
} | |
} | |
return m; | |
}; | |
ControlIHave.fromObject = function fromObject(d) { | |
if (d instanceof $root.RPC.ControlIHave) | |
return d; | |
var m = new $root.RPC.ControlIHave(); | |
if (d.topicID != null) { | |
m.topicID = String(d.topicID); | |
} | |
if (d.messageIDs) { | |
if (!Array.isArray(d.messageIDs)) | |
throw TypeError(".RPC.ControlIHave.messageIDs: array expected"); | |
m.messageIDs = []; | |
for (var i = 0; i < d.messageIDs.length; ++i) { | |
if (typeof d.messageIDs[i] === "string") | |
$util.base64.decode(d.messageIDs[i], m.messageIDs[i] = $util.newBuffer($util.base64.length(d.messageIDs[i])), 0); | |
else if (d.messageIDs[i].length) | |
m.messageIDs[i] = d.messageIDs[i]; | |
} | |
} | |
return m; | |
}; | |
ControlIHave.toObject = function toObject(m, o) { | |
if (!o) | |
o = {}; | |
var d = {}; | |
if (o.arrays || o.defaults) { | |
d.messageIDs = []; | |
} | |
if (m.topicID != null && m.hasOwnProperty("topicID")) { | |
d.topicID = m.topicID; | |
if (o.oneofs) | |
d._topicID = "topicID"; | |
} | |
if (m.messageIDs && m.messageIDs.length) { | |
d.messageIDs = []; | |
for (var j = 0; j < m.messageIDs.length; ++j) { | |
d.messageIDs[j] = o.bytes === String ? $util.base64.encode(m.messageIDs[j], 0, m.messageIDs[j].length) : o.bytes === Array ? Array.prototype.slice.call(m.messageIDs[j]) : m.messageIDs[j]; | |
} | |
} | |
return d; | |
}; | |
ControlIHave.prototype.toJSON = function toJSON() { | |
return this.constructor.toObject(this, $protobuf.util.toJSONOptions); | |
}; | |
return ControlIHave; | |
}(); | |
RPC3.ControlIWant = function() { | |
function ControlIWant(p) { | |
this.messageIDs = []; | |
if (p) { | |
for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) | |
if (p[ks[i]] != null) | |
this[ks[i]] = p[ks[i]]; | |
} | |
} | |
ControlIWant.prototype.messageIDs = $util.emptyArray; | |
ControlIWant.encode = function encode39(m, w) { | |
if (!w) | |
w = $Writer.create(); | |
if (m.messageIDs != null && m.messageIDs.length) { | |
for (var i = 0; i < m.messageIDs.length; ++i) | |
w.uint32(10).bytes(m.messageIDs[i]); | |
} | |
return w; | |
}; | |
ControlIWant.decode = function decode50(r, l) { | |
if (!(r instanceof $Reader)) | |
r = $Reader.create(r); | |
var c = l === void 0 ? r.len : r.pos + l, m = new $root.RPC.ControlIWant(); | |
while (r.pos < c) { | |
var t = r.uint32(); | |
switch (t >>> 3) { | |
case 1: | |
if (!(m.messageIDs && m.messageIDs.length)) | |
m.messageIDs = []; | |
m.messageIDs.push(r.bytes()); | |
break; | |
default: | |
r.skipType(t & 7); | |
break; | |
} | |
} | |
return m; | |
}; | |
ControlIWant.fromObject = function fromObject(d) { | |
if (d instanceof $root.RPC.ControlIWant) | |
return d; | |
var m = new $root.RPC.ControlIWant(); | |
if (d.messageIDs) { | |
if (!Array.isArray(d.messageIDs)) | |
throw TypeError(".RPC.ControlIWant.messageIDs: array expected"); | |
m.messageIDs = []; | |
for (var i = 0; i < d.messageIDs.length; ++i) { | |
if (typeof d.messageIDs[i] === "string") | |
$util.base64.decode(d.messageIDs[i], m.messageIDs[i] = $util.newBuffer($util.base64.length(d.messageIDs[i])), 0); | |
else if (d.messageIDs[i].length) | |
m.messageIDs[i] = d.messageIDs[i]; | |
} | |
} | |
return m; | |
}; | |
ControlIWant.toObject = function toObject(m, o) { | |
if (!o) | |
o = {}; | |
var d = {}; | |
if (o.arrays || o.defaults) { | |
d.messageIDs = []; | |
} | |
if (m.messageIDs && m.messageIDs.length) { | |
d.messageIDs = []; | |
for (var j = 0; j < m.messageIDs.length; ++j) { | |
d.messageIDs[j] = o.bytes === String ? $util.base64.encode(m.messageIDs[j], 0, m.messageIDs[j].length) : o.bytes === Array ? Array.prototype.slice.call(m.messageIDs[j]) : m.messageIDs[j]; | |
} | |
} | |
return d; | |
}; | |
ControlIWant.prototype.toJSON = function toJSON() { | |
return this.constructor.toObject(this, $protobuf.util.toJSONOptions); | |
}; | |
return ControlIWant; | |
}(); | |
RPC3.ControlGraft = function() { | |
function ControlGraft(p) { | |
if (p) { | |
for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) | |
if (p[ks[i]] != null) | |
this[ks[i]] = p[ks[i]]; | |
} | |
} | |
ControlGraft.prototype.topicID = null; | |
var $oneOfFields2; | |
Object.defineProperty(ControlGraft.prototype, "_topicID", { | |
get: $util.oneOfGetter($oneOfFields2 = ["topicID"]), | |
set: $util.oneOfSetter($oneOfFields2) | |
}); | |
ControlGraft.encode = function encode39(m, w) { | |
if (!w) | |
w = $Writer.create(); | |
if (m.topicID != null && Object.hasOwnProperty.call(m, "topicID")) | |
w.uint32(10).string(m.topicID); | |
return w; | |
}; | |
ControlGraft.decode = function decode50(r, l) { | |
if (!(r instanceof $Reader)) | |
r = $Reader.create(r); | |
var c = l === void 0 ? r.len : r.pos + l, m = new $root.RPC.ControlGraft(); | |
while (r.pos < c) { | |
var t = r.uint32(); | |
switch (t >>> 3) { | |
case 1: | |
m.topicID = r.string(); | |
break; | |
default: | |
r.skipType(t & 7); | |
break; | |
} | |
} | |
return m; | |
}; | |
ControlGraft.fromObject = function fromObject(d) { | |
if (d instanceof $root.RPC.ControlGraft) | |
return d; | |
var m = new $root.RPC.ControlGraft(); | |
if (d.topicID != null) { | |
m.topicID = String(d.topicID); | |
} | |
return m; | |
}; | |
ControlGraft.toObject = function toObject(m, o) { | |
if (!o) | |
o = {}; | |
var d = {}; | |
if (m.topicID != null && m.hasOwnProperty("topicID")) { | |
d.topicID = m.topicID; | |
if (o.oneofs) | |
d._topicID = "topicID"; | |
} | |
return d; | |
}; | |
ControlGraft.prototype.toJSON = function toJSON() { | |
return this.constructor.toObject(this, $protobuf.util.toJSONOptions); | |
}; | |
return ControlGraft; | |
}(); | |
RPC3.ControlPrune = function() { | |
function ControlPrune(p) { | |
this.peers = []; | |
if (p) { | |
for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) | |
if (p[ks[i]] != null) | |
this[ks[i]] = p[ks[i]]; | |
} | |
} | |
ControlPrune.prototype.topicID = null; | |
ControlPrune.prototype.peers = $util.emptyArray; | |
ControlPrune.prototype.backoff = null; | |
var $oneOfFields2; | |
Object.defineProperty(ControlPrune.prototype, "_topicID", { | |
get: $util.oneOfGetter($oneOfFields2 = ["topicID"]), | |
set: $util.oneOfSetter($oneOfFields2) | |
}); | |
Object.defineProperty(ControlPrune.prototype, "_backoff", { | |
get: $util.oneOfGetter($oneOfFields2 = ["backoff"]), | |
set: $util.oneOfSetter($oneOfFields2) | |
}); | |
ControlPrune.encode = function encode39(m, w) { | |
if (!w) | |
w = $Writer.create(); | |
if (m.topicID != null && Object.hasOwnProperty.call(m, "topicID")) | |
w.uint32(10).string(m.topicID); | |
if (m.peers != null && m.peers.length) { | |
for (var i = 0; i < m.peers.length; ++i) | |
$root.RPC.PeerInfo.encode(m.peers[i], w.uint32(18).fork()).ldelim(); | |
} | |
if (m.backoff != null && Object.hasOwnProperty.call(m, "backoff")) | |
w.uint32(24).uint64(m.backoff); | |
return w; | |
}; | |
ControlPrune.decode = function decode50(r, l) { | |
if (!(r instanceof $Reader)) | |
r = $Reader.create(r); | |
var c = l === void 0 ? r.len : r.pos + l, m = new $root.RPC.ControlPrune(); | |
while (r.pos < c) { | |
var t = r.uint32(); | |
switch (t >>> 3) { | |
case 1: | |
m.topicID = r.string(); | |
break; | |
case 2: | |
if (!(m.peers && m.peers.length)) | |
m.peers = []; | |
m.peers.push($root.RPC.PeerInfo.decode(r, r.uint32())); | |
break; | |
case 3: | |
m.backoff = r.uint64(); | |
break; | |
default: | |
r.skipType(t & 7); | |
break; | |
} | |
} | |
return m; | |
}; | |
ControlPrune.fromObject = function fromObject(d) { | |
if (d instanceof $root.RPC.ControlPrune) | |
return d; | |
var m = new $root.RPC.ControlPrune(); | |
if (d.topicID != null) { | |
m.topicID = String(d.topicID); | |
} | |
if (d.peers) { | |
if (!Array.isArray(d.peers)) | |
throw TypeError(".RPC.ControlPrune.peers: array expected"); | |
m.peers = []; | |
for (var i = 0; i < d.peers.length; ++i) { | |
if (typeof d.peers[i] !== "object") | |
throw TypeError(".RPC.ControlPrune.peers: object expected"); | |
m.peers[i] = $root.RPC.PeerInfo.fromObject(d.peers[i]); | |
} | |
} | |
if (d.backoff != null) { | |
if ($util.Long) | |
(m.backoff = $util.Long.fromValue(d.backoff)).unsigned = true; | |
else if (typeof d.backoff === "string") | |
m.backoff = parseInt(d.backoff, 10); | |
else if (typeof d.backoff === "number") | |
m.backoff = d.backoff; | |
else if (typeof d.backoff === "object") | |
m.backoff = new $util.LongBits(d.backoff.low >>> 0, d.backoff.high >>> 0).toNumber(true); | |
} | |
return m; | |
}; | |
ControlPrune.toObject = function toObject(m, o) { | |
if (!o) | |
o = {}; | |
var d = {}; | |
if (o.arrays || o.defaults) { | |
d.peers = []; | |
} | |
if (m.topicID != null && m.hasOwnProperty("topicID")) { | |
d.topicID = m.topicID; | |
if (o.oneofs) | |
d._topicID = "topicID"; | |
} | |
if (m.peers && m.peers.length) { | |
d.peers = []; | |
for (var j = 0; j < m.peers.length; ++j) { | |
d.peers[j] = $root.RPC.PeerInfo.toObject(m.peers[j], o); | |
} | |
} | |
if (m.backoff != null && m.hasOwnProperty("backoff")) { | |
if (typeof m.backoff === "number") | |
d.backoff = o.longs === String ? String(m.backoff) : m.backoff; | |
else | |
d.backoff = o.longs === String ? $util.Long.prototype.toString.call(m.backoff) : o.longs === Number ? new $util.LongBits(m.backoff.low >>> 0, m.backoff.high >>> 0).toNumber(true) : m.backoff; | |
if (o.oneofs) | |
d._backoff = "backoff"; | |
} | |
return d; | |
}; | |
ControlPrune.prototype.toJSON = function toJSON() { | |
return this.constructor.toObject(this, $protobuf.util.toJSONOptions); | |
}; | |
return ControlPrune; | |
}(); | |
RPC3.PeerInfo = function() { | |
function PeerInfo(p) { | |
if (p) { | |
for (var ks = Object.keys(p), i = 0; i < ks.length; ++i) | |
if (p[ks[i]] != null) | |
this[ks[i]] = p[ks[i]]; | |
} | |
} | |
PeerInfo.prototype.peerID = null; | |
PeerInfo.prototype.signedPeerRecord = null; | |
var $oneOfFields2; | |
Object.defineProperty(PeerInfo.prototype, "_peerID", { | |
get: $util.oneOfGetter($oneOfFields2 = ["peerID"]), | |
set: $util.oneOfSetter($oneOfFields2) | |
}); | |
Object.defineProperty(PeerInfo.prototype, "_signedPeerRecord", { | |
get: $util.oneOfGetter($oneOfFields2 = ["signedPeerRecord"]), | |
set: $util.oneOfSetter($oneOfFields2) | |
}); | |
PeerInfo.encode = function encode39(m, w) { | |
if (!w) | |
w = $Writer.create(); | |
if (m.peerID != null && Object.hasOwnProperty.call(m, "peerID")) | |
w.uint32(10).bytes(m.peerID); | |
if (m.signedPeerRecord != null && Object.hasOwnProperty.call(m, "signedPeerRecord")) | |
w.uint32(18).bytes(m.signedPeerRecord); | |
return w; | |
}; | |
PeerInfo.decode = function decode50(r, l) { | |
if (!(r instanceof $Reader)) | |
r = $Reader.create(r); | |
var c = l === void 0 ? r.len : r.pos + l, m = new $root.RPC.PeerInfo(); | |
while (r.pos < c) { | |
var t = r.uint32(); | |
switch (t >>> 3) { | |
case 1: | |
m.peerID = r.bytes(); | |
break; | |
case 2: | |
m.signedPeerRecord = r.bytes(); | |
break; | |
default: | |
r.skipType(t & 7); | |
break; | |
} | |
} | |
return m; | |
}; | |
PeerInfo.fromObject = function fromObject(d) { | |
if (d instanceof $root.RPC.PeerInfo) | |
return d; | |
var m = new $root.RPC.PeerInfo(); | |
if (d.peerID != null) { | |
if (typeof d.peerID === "string") | |
$util.base64.decode(d.peerID, m.peerID = $util.newBuffer($util.base64.length(d.peerID)), 0); | |
else if (d.peerID.length) | |
m.peerID = d.peerID; | |
} | |
if (d.signedPeerRecord != null) { | |
if (typeof d.signedPeerRecord === "string") | |
$util.base64.decode(d.signedPeerRecord, m.signedPeerRecord = $util.newBuffer($util.base64.length(d.signedPeerRecord)), 0); | |
else if (d.signedPeerRecord.length) | |
m.signedPeerRecord = d.signedPeerRecord; | |
} | |
return m; | |
}; | |
PeerInfo.toObject = function toObject(m, o) { | |
if (!o) | |
o = {}; | |
var d = {}; | |
if (m.peerID != null && m.hasOwnProperty("peerID")) { | |
d.peerID = o.bytes === String ? $util.base64.encode(m.peerID, 0, m.peerID.length) : o.bytes === Array ? Array.prototype.slice.call(m.peerID) : m.peerID; | |
if (o.oneofs) | |
d._peerID = "peerID"; | |
} | |
if (m.signedPeerRecord != null && m.hasOwnProperty("signedPeerRecord")) { | |
d.signedPeerRecord = o.bytes === String ? $util.base64.encode(m.signedPeerRecord, 0, m.signedPeerRecord.length) : o.bytes === Array ? Array.prototype.slice.call(m.signedPeerRecord) : m.signedPeerRecord; | |
if (o.oneofs) | |
d._signedPeerRecord = "signedPeerRecord"; | |
} | |
return d; | |
}; | |
PeerInfo.prototype.toJSON = function toJSON() { | |
return this.constructor.toObject(this, $protobuf.util.toJSONOptions); | |
}; | |
return PeerInfo; | |
}(); | |
return RPC3; | |
}(); | |
return $root; | |
}); | |
} | |
}); | |
// node_modules/denque/index.js | |
var require_denque = __commonJS({ | |
"node_modules/denque/index.js"(exports2, module2) { | |
"use strict"; | |
function Denque2(array, options) { | |
var options = options || {}; | |
this._head = 0; | |
this._tail = 0; | |
this._capacity = options.capacity; | |
this._capacityMask = 3; | |
this._list = new Array(4); | |
if (Array.isArray(array)) { | |
this._fromArray(array); | |
} | |
} | |
Denque2.prototype.peekAt = function peekAt(index) { | |
var i = index; | |
if (i !== (i | 0)) { | |
return void 0; | |
} | |
var len = this.size(); | |
if (i >= len || i < -len) | |
return void 0; | |
if (i < 0) | |
i += len; | |
i = this._head + i & this._capacityMask; | |
return this._list[i]; | |
}; | |
Denque2.prototype.get = function get(i) { | |
return this.peekAt(i); | |
}; | |
Denque2.prototype.peek = function peek() { | |
if (this._head === this._tail) | |
return void 0; | |
return this._list[this._head]; | |
}; | |
Denque2.prototype.peekFront = function peekFront() { | |
return this.peek(); | |
}; | |
Denque2.prototype.peekBack = function peekBack() { | |
return this.peekAt(-1); | |
}; | |
Object.defineProperty(Denque2.prototype, "length", { | |
get: function length11() { | |
return this.size(); | |
} | |
}); | |
Denque2.prototype.size = function size() { | |
if (this._head === this._tail) | |
return 0; | |
if (this._head < this._tail) | |
return this._tail - this._head; | |
else | |
return this._capacityMask + 1 - (this._head - this._tail); | |
}; | |
Denque2.prototype.unshift = function unshift(item) { | |
if (item === void 0) | |
return this.size(); | |
var len = this._list.length; | |
this._head = this._head - 1 + len & this._capacityMask; | |
this._list[this._head] = item; | |
if (this._tail === this._head) | |
this._growArray(); | |
if (this._capacity && this.size() > this._capacity) | |
this.pop(); | |
if (this._head < this._tail) | |
return this._tail - this._head; | |
else | |
return this._capacityMask + 1 - (this._head - this._tail); | |
}; | |
Denque2.prototype.shift = function shift() { | |
var head = this._head; | |
if (head === this._tail) | |
return void 0; | |
var item = this._list[head]; | |
this._list[head] = void 0; | |
this._head = head + 1 & this._capacityMask; | |
if (head < 2 && this._tail > 1e4 && this._tail <= this._list.length >>> 2) | |
this._shrinkArray(); | |
return item; | |
}; | |
Denque2.prototype.push = function push(item) { | |
if (item === void 0) | |
return this.size(); | |
var tail = this._tail; | |
this._list[tail] = item; | |
this._tail = tail + 1 & this._capacityMask; | |
if (this._tail === this._head) { | |
this._growArray(); | |
} | |
if (this._capacity && this.size() > this._capacity) { | |
this.shift(); | |
} | |
if (this._head < this._tail) | |
return this._tail - this._head; | |
else | |
return this._capacityMask + 1 - (this._head - this._tail); | |
}; | |
Denque2.prototype.pop = function pop() { | |
var tail = this._tail; | |
if (tail === this._head) | |
return void 0; | |
var len = this._list.length; | |
this._tail = tail - 1 + len & this._capacityMask; | |
var item = this._list[this._tail]; | |
this._list[this._tail] = void 0; | |
if (this._head < 2 && tail > 1e4 && tail <= len >>> 2) | |
this._shrinkArray(); | |
return item; | |
}; | |
Denque2.prototype.removeOne = function removeOne(index) { | |
var i = index; | |
if (i !== (i | 0)) { | |
return void 0; | |
} | |
if (this._head === this._tail) | |
return void 0; | |
var size = this.size(); | |
var len = this._list.length; | |
if (i >= size || i < -size) | |
return void 0; | |
if (i < 0) | |
i += size; | |
i = this._head + i & this._capacityMask; | |
var item = this._list[i]; | |
var k; | |
if (index < size / 2) { | |
for (k = index; k > 0; k--) { | |
this._list[i] = this._list[i = i - 1 + len & this._capacityMask]; | |
} | |
this._list[i] = void 0; | |
this._head = this._head + 1 + len & this._capacityMask; | |
} else { | |
for (k = size - 1 - index; k > 0; k--) { | |
this._list[i] = this._list[i = i + 1 + len & this._capacityMask]; | |
} | |
this._list[i] = void 0; | |
this._tail = this._tail - 1 + len & this._capacityMask; | |
} | |
return item; | |
}; | |
Denque2.prototype.remove = function remove(index, count) { | |
var i = index; | |
var removed; | |
var del_count = count; | |
if (i !== (i | 0)) { | |
return void 0; | |
} | |
if (this._head === this._tail) | |
return void 0; | |
var size = this.size(); | |
var len = this._list.length; | |
if (i >= size || i < -size || count < 1) | |
return void 0; | |
if (i < 0) | |
i += size; | |
if (count === 1 || !count) { | |
removed = new Array(1); | |
removed[0] = this.removeOne(i); | |
return removed; | |
} | |
if (i === 0 && i + count >= size) { | |
removed = this.toArray(); | |
this.clear(); | |
return removed; | |
} | |
if (i + count > size) | |
count = size - i; | |
var k; | |
removed = new Array(count); | |
for (k = 0; k < count; k++) { | |
removed[k] = this._list[this._head + i + k & this._capacityMask]; | |
} | |
i = this._head + i & this._capacityMask; | |
if (index + count === size) { | |
this._tail = this._tail - count + len & this._capacityMask; | |
for (k = count; k > 0; k--) { | |
this._list[i = i + 1 + len & this._capacityMask] = void 0; | |
} | |
return removed; | |
} | |
if (index === 0) { | |
this._head = this._head + count + len & this._capacityMask; | |
for (k = count - 1; k > 0; k--) { | |
this._list[i = i + 1 + len & this._capacityMask] = void 0; | |
} | |
return removed; | |
} | |
if (i < size / 2) { | |
this._head = this._head + index + count + len & this._capacityMask; | |
for (k = index; k > 0; k--) { | |
this.unshift(this._list[i = i - 1 + len & this._capacityMask]); | |
} | |
i = this._head - 1 + len & this._capacityMask; | |
while (del_count > 0) { | |
this._list[i = i - 1 + len & this._capacityMask] = void 0; | |
del_count--; | |
} | |
if (index < 0) | |
this._tail = i; | |
} else { | |
this._tail = i; | |
i = i + count + len & this._capacityMask; | |
for (k = size - (count + index); k > 0; k--) { | |
this.push(this._list[i++]); | |
} | |
i = this._tail; | |
while (del_count > 0) { | |
this._list[i = i + 1 + len & this._capacityMask] = void 0; | |
del_count--; | |
} | |
} | |
if (this._head < 2 && this._tail > 1e4 && this._tail <= len >>> 2) | |
this._shrinkArray(); | |
return removed; | |
}; | |
Denque2.prototype.splice = function splice(index, count) { | |
var i = index; | |
if (i !== (i | 0)) { | |
return void 0; | |
} | |
var size = this.size(); | |
if (i < 0) | |
i += size; | |
if (i > size) | |
return void 0; | |
if (arguments.length > 2) { | |
var k; | |
var temp; | |
var removed; | |
var arg_len = arguments.length; | |
var len = this._list.length; | |
var arguments_index = 2; | |
if (!size || i < size / 2) { | |
temp = new Array(i); | |
for (k = 0; k < i; k++) { | |
temp[k] = this._list[this._head + k & this._capacityMask]; | |
} | |
if (count === 0) { | |
removed = []; | |
if (i > 0) { | |
this._head = this._head + i + len & this._capacityMask; | |
} | |
} else { | |
removed = this.remove(i, count); | |
this._head = this._head + i + len & this._capacityMask; | |
} | |
while (arg_len > arguments_index) { | |
this.unshift(arguments[--arg_len]); | |
} | |
for (k = i; k > 0; k--) { | |
this.unshift(temp[k - 1]); | |
} | |
} else { | |
temp = new Array(size - (i + count)); | |
var leng = temp.length; | |
for (k = 0; k < leng; k++) { | |
temp[k] = this._list[this._head + i + count + k & this._capacityMask]; | |
} | |
if (count === 0) { | |
removed = []; | |
if (i != size) { | |
this._tail = this._head + i + len & this._capacityMask; | |
} | |
} else { | |
removed = this.remove(i, count); | |
this._tail = this._tail - leng + len & this._capacityMask; | |
} | |
while (arguments_index < arg_len) { | |
this.push(arguments[arguments_index++]); | |
} | |
for (k = 0; k < leng; k++) { | |
this.push(temp[k]); | |
} | |
} | |
return removed; | |
} else { | |
return this.remove(i, count); | |
} | |
}; | |
Denque2.prototype.clear = function clear() { | |
this._head = 0; | |
this._tail = 0; | |
}; | |
Denque2.prototype.isEmpty = function isEmpty() { | |
return this._head === this._tail; | |
}; | |
Denque2.prototype.toArray = function toArray() { | |
return this._copyArray(false); | |
}; | |
Denque2.prototype._fromArray = function _fromArray(array) { | |
for (var i = 0; i < array.length; i++) | |
this.push(array[i]); | |
}; | |
Denque2.prototype._copyArray = function _copyArray(fullCopy) { | |
var newArray = []; | |
var list = this._list; | |
var len = list.length; | |
var i; | |
if (fullCopy || this._head > this._tail) { | |
for (i = this._head; i < len; i++) | |
newArray.push(list[i]); | |
for (i = 0; i < this._tail; i++) | |
newArray.push(list[i]); | |
} else { | |
for (i = this._head; i < this._tail; i++) | |
newArray.push(list[i]); | |
} | |
return newArray; | |
}; | |
Denque2.prototype._growArray = function _growArray() { | |
if (this._head) { | |
this._list = this._copyArray(true); | |
this._head = 0; | |
} | |
this._tail = this._list.length; | |
this._list.length <<= 1; | |
this._capacityMask = this._capacityMask << 1 | 1; | |
}; | |
Denque2.prototype._shrinkArray = function _shrinkArray() { | |
this._list.length >>>= 1; | |
this._capacityMask >>>= 1; | |
}; | |
module2.exports = Denque2; | |
} | |
}); | |
// node_modules/iterable-ndjson/parse.browser.js | |
var require_parse_browser = __commonJS({ | |
"node_modules/iterable-ndjson/parse.browser.js"(exports2, module2) { | |
module2.exports = (source) => async function* () { | |
const matcher = /\r?\n/; | |
const decoder = new TextDecoder("utf8"); | |
let buffer3 = ""; | |
for await (let chunk of source) { | |
if (typeof chunk === "string") { | |
chunk = new TextEncoder().encode(chunk); | |
} | |
buffer3 += decoder.decode(chunk, { stream: true }); | |
const parts = buffer3.split(matcher); | |
buffer3 = parts.pop(); | |
for (let i = 0; i < parts.length; i++) | |
yield JSON.parse(parts[i]); | |
} | |
buffer3 += decoder.decode(); | |
if (buffer3) | |
yield JSON.parse(buffer3); | |
}(); | |
} | |
}); | |
// node_modules/iterable-ndjson/stringify.js | |
var require_stringify = __commonJS({ | |
"node_modules/iterable-ndjson/stringify.js"(exports2, module2) { | |
module2.exports = (source) => async function* () { | |
for await (const obj of source) { | |
yield JSON.stringify(obj) + "\n"; | |
} | |
}(); | |
} | |
}); | |
// node_modules/iterable-ndjson/browser.js | |
var require_browser4 = __commonJS({ | |
"node_modules/iterable-ndjson/browser.js"(exports2, module2) { | |
module2.exports = require_parse_browser(); | |
module2.exports.parse = require_parse_browser(); | |
module2.exports.stringify = require_stringify(); | |
} | |
}); | |
// node_modules/hashlru/index.js | |
var require_hashlru = __commonJS({ | |
"node_modules/hashlru/index.js"(exports2, module2) { | |
module2.exports = function(max) { | |
if (!max) | |
throw Error("hashlru must have a max value, of type number, greater than 0"); | |
var size = 0, cache10 = /* @__PURE__ */ Object.create(null), _cache = /* @__PURE__ */ Object.create(null); | |
function update(key, value) { | |
cache10[key] = value; | |
size++; | |
if (size >= max) { | |
size = 0; | |
_cache = cache10; | |
cache10 = /* @__PURE__ */ Object.create(null); | |
} | |
} | |
return { | |
has: function(key) { | |
return cache10[key] !== void 0 || _cache[key] !== void 0; | |
}, | |
remove: function(key) { | |
if (cache10[key] !== void 0) | |
cache10[key] = void 0; | |
if (_cache[key] !== void 0) | |
_cache[key] = void 0; | |
}, | |
get: function(key) { | |
var v = cache10[key]; | |
if (v !== void 0) | |
return v; | |
if ((v = _cache[key]) !== void 0) { | |
update(key, v); | |
return v; | |
} | |
}, | |
set: function(key, value) { | |
if (cache10[key] !== void 0) | |
cache10[key] = value; | |
else | |
update(key, value); | |
}, | |
clear: function() { | |
cache10 = /* @__PURE__ */ Object.create(null); | |
_cache = /* @__PURE__ */ Object.create(null); | |
} | |
}; | |
}; | |
} | |
}); | |
// node_modules/@multiformats/base-x/src/index.js | |
var require_src2 = __commonJS({ | |
"node_modules/@multiformats/base-x/src/index.js"(exports2, module2) { | |
"use strict"; | |
function base14(ALPHABET) { | |
if (ALPHABET.length >= 255) { | |
throw new TypeError("Alphabet too long"); | |
} | |
var BASE_MAP = new Uint8Array(256); | |
for (var j = 0; j < BASE_MAP.length; j++) { | |
BASE_MAP[j] = 255; | |
} | |
for (var i = 0; i < ALPHABET.length; i++) { | |
var x = ALPHABET.charAt(i); | |
var xc = x.charCodeAt(0); | |
if (BASE_MAP[xc] !== 255) { | |
throw new TypeError(x + " is ambiguous"); | |
} | |
BASE_MAP[xc] = i; | |
} | |
var BASE = ALPHABET.length; | |
var LEADER = ALPHABET.charAt(0); | |
var FACTOR = Math.log(BASE) / Math.log(256); | |
var iFACTOR = Math.log(256) / Math.log(BASE); | |
function encode39(source) { | |
if (source instanceof Uint8Array) { | |
} else if (ArrayBuffer.isView(source)) { | |
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength); | |
} else if (Array.isArray(source)) { | |
source = Uint8Array.from(source); | |
} | |
if (!(source instanceof Uint8Array)) { | |
throw new TypeError("Expected Uint8Array"); | |
} | |
if (source.length === 0) { | |
return ""; | |
} | |
var zeroes = 0; | |
var length11 = 0; | |
var pbegin = 0; | |
var pend = source.length; | |
while (pbegin !== pend && source[pbegin] === 0) { | |
pbegin++; | |
zeroes++; | |
} | |
var size = (pend - pbegin) * iFACTOR + 1 >>> 0; | |
var b58 = new Uint8Array(size); | |
while (pbegin !== pend) { | |
var carry = source[pbegin]; | |
var i2 = 0; | |
for (var it1 = size - 1; (carry !== 0 || i2 < length11) && it1 !== -1; it1--, i2++) { | |
carry += 256 * b58[it1] >>> 0; | |
b58[it1] = carry % BASE >>> 0; | |
carry = carry / BASE >>> 0; | |
} | |
if (carry !== 0) { | |
throw new Error("Non-zero carry"); | |
} | |
length11 = i2; | |
pbegin++; | |
} | |
var it2 = size - length11; | |
while (it2 !== size && b58[it2] === 0) { | |
it2++; | |
} | |
var str = LEADER.repeat(zeroes); | |
for (; it2 < size; ++it2) { | |
str += ALPHABET.charAt(b58[it2]); | |
} | |
return str; | |
} | |
function decodeUnsafe(source) { | |
if (typeof source !== "string") { | |
throw new TypeError("Expected String"); | |
} | |
if (source.length === 0) { | |
return new Uint8Array(); | |
} | |
var psz = 0; | |
if (source[psz] === " ") { | |
return; | |
} | |
var zeroes = 0; | |
var length11 = 0; | |
while (source[psz] === LEADER) { | |
zeroes++; | |
psz++; | |
} | |
var size = (source.length - psz) * FACTOR + 1 >>> 0; | |
var b256 = new Uint8Array(size); | |
while (source[psz]) { | |
var carry = BASE_MAP[source.charCodeAt(psz)]; | |
if (carry === 255) { | |
return; | |
} | |
var i2 = 0; | |
for (var it3 = size - 1; (carry !== 0 || i2 < length11) && it3 !== -1; it3--, i2++) { | |
carry += BASE * b256[it3] >>> 0; | |
b256[it3] = carry % 256 >>> 0; | |
carry = carry / 256 >>> 0; | |
} | |
if (carry !== 0) { | |
throw new Error("Non-zero carry"); | |
} | |
length11 = i2; | |
psz++; | |
} | |
if (source[psz] === " ") { | |
return; | |
} | |
var it4 = size - length11; | |
while (it4 !== size && b256[it4] === 0) { | |
it4++; | |
} | |
var vch = new Uint8Array(zeroes + (size - it4)); | |
var j2 = zeroes; | |
while (it4 !== size) { | |
vch[j2++] = b256[it4++]; | |
} | |
return vch; | |
} | |
function decode50(string3) { | |
var buffer3 = decodeUnsafe(string3); | |
if (buffer3) { | |
return buffer3; | |
} | |
throw new Error("Non-base" + BASE + " character"); | |
} | |
return { | |
encode: encode39, | |
decodeUnsafe, | |
decode: decode50 | |
}; | |
} | |
module2.exports = base14; | |
} | |
}); | |
// node_modules/multibase/src/util.js | |
var require_util2 = __commonJS({ | |
"node_modules/multibase/src/util.js"(exports2, module2) { | |
"use strict"; | |
var textDecoder8 = new TextDecoder(); | |
var decodeText = (bytes3) => textDecoder8.decode(bytes3); | |
var textEncoder9 = new TextEncoder(); | |
var encodeText = (text) => textEncoder9.encode(text); | |
function concat5(arrs, length11) { | |
const output3 = new Uint8Array(length11); | |
let offset = 0; | |
for (const arr of arrs) { | |
output3.set(arr, offset); | |
offset += arr.length; | |
} | |
return output3; | |
} | |
module2.exports = { decodeText, encodeText, concat: concat5 }; | |
} | |
}); | |
// node_modules/multibase/src/base.js | |
var require_base = __commonJS({ | |
"node_modules/multibase/src/base.js"(exports2, module2) { | |
"use strict"; | |
var { encodeText } = require_util2(); | |
var Base = class { | |
/** | |
* @param {BaseName} name | |
* @param {BaseCode} code | |
* @param {CodecFactory} factory | |
* @param {string} alphabet | |
*/ | |
constructor(name8, code9, factory, alphabet5) { | |
this.name = name8; | |
this.code = code9; | |
this.codeBuf = encodeText(this.code); | |
this.alphabet = alphabet5; | |
this.codec = factory(alphabet5); | |
} | |
/** | |
* @param {Uint8Array} buf | |
* @returns {string} | |
*/ | |
encode(buf3) { | |
return this.codec.encode(buf3); | |
} | |
/** | |
* @param {string} string | |
* @returns {Uint8Array} | |
*/ | |
decode(string3) { | |
for (const char of string3) { | |
if (this.alphabet && this.alphabet.indexOf(char) < 0) { | |
throw new Error(`invalid character '${char}' in '${string3}'`); | |
} | |
} | |
return this.codec.decode(string3); | |
} | |
}; | |
module2.exports = Base; | |
} | |
}); | |
// node_modules/multibase/src/rfc4648.js | |
var require_rfc4648 = __commonJS({ | |
"node_modules/multibase/src/rfc4648.js"(exports2, module2) { | |
"use strict"; | |
var decode50 = (string3, alphabet5, bitsPerChar) => { | |
const codes8 = {}; | |
for (let i = 0; i < alphabet5.length; ++i) { | |
codes8[alphabet5[i]] = i; | |
} | |
let end = string3.length; | |
while (string3[end - 1] === "=") { | |
--end; | |
} | |
const out = new Uint8Array(end * bitsPerChar / 8 | 0); | |
let bits2 = 0; | |
let buffer3 = 0; | |
let written = 0; | |
for (let i = 0; i < end; ++i) { | |
const value = codes8[string3[i]]; | |
if (value === void 0) { | |
throw new SyntaxError("Invalid character " + string3[i]); | |
} | |
buffer3 = buffer3 << bitsPerChar | value; | |
bits2 += bitsPerChar; | |
if (bits2 >= 8) { | |
bits2 -= 8; | |
out[written++] = 255 & buffer3 >> bits2; | |
} | |
} | |
if (bits2 >= bitsPerChar || 255 & buffer3 << 8 - bits2) { | |
throw new SyntaxError("Unexpected end of data"); | |
} | |
return out; | |
}; | |
var encode39 = (data, alphabet5, bitsPerChar) => { | |
const pad = alphabet5[alphabet5.length - 1] === "="; | |
const mask = (1 << bitsPerChar) - 1; | |
let out = ""; | |
let bits2 = 0; | |
let buffer3 = 0; | |
for (let i = 0; i < data.length; ++i) { | |
buffer3 = buffer3 << 8 | data[i]; | |
bits2 += 8; | |
while (bits2 > bitsPerChar) { | |
bits2 -= bitsPerChar; | |
out += alphabet5[mask & buffer3 >> bits2]; | |
} | |
} | |
if (bits2) { | |
out += alphabet5[mask & buffer3 << bitsPerChar - bits2]; | |
} | |
if (pad) { | |
while (out.length * bitsPerChar & 7) { | |
out += "="; | |
} | |
} | |
return out; | |
}; | |
var rfc464811 = (bitsPerChar) => (alphabet5) => { | |
return { | |
/** | |
* @param {Uint8Array} input | |
* @returns {string} | |
*/ | |
encode(input) { | |
return encode39(input, alphabet5, bitsPerChar); | |
}, | |
/** | |
* @param {string} input | |
* @returns {Uint8Array} | |
*/ | |
decode(input) { | |
return decode50(input, alphabet5, bitsPerChar); | |
} | |
}; | |
}; | |
module2.exports = { rfc4648: rfc464811 }; | |
} | |
}); | |
// node_modules/multibase/src/constants.js | |
var require_constants = __commonJS({ | |
"node_modules/multibase/src/constants.js"(exports2, module2) { | |
"use strict"; | |
var baseX11 = require_src2(); | |
var Base = require_base(); | |
var { rfc4648: rfc464811 } = require_rfc4648(); | |
var { decodeText, encodeText } = require_util2(); | |
var identity9 = () => { | |
return { | |
encode: decodeText, | |
decode: encodeText | |
}; | |
}; | |
var constants = [ | |
["identity", "\0", identity9, ""], | |
["base2", "0", rfc464811(1), "01"], | |
["base8", "7", rfc464811(3), "01234567"], | |
["base10", "9", baseX11, "0123456789"], | |
["base16", "f", rfc464811(4), "0123456789abcdef"], | |
["base16upper", "F", rfc464811(4), "0123456789ABCDEF"], | |
["base32hex", "v", rfc464811(5), "0123456789abcdefghijklmnopqrstuv"], | |
["base32hexupper", "V", rfc464811(5), "0123456789ABCDEFGHIJKLMNOPQRSTUV"], | |
["base32hexpad", "t", rfc464811(5), "0123456789abcdefghijklmnopqrstuv="], | |
["base32hexpadupper", "T", rfc464811(5), "0123456789ABCDEFGHIJKLMNOPQRSTUV="], | |
["base32", "b", rfc464811(5), "abcdefghijklmnopqrstuvwxyz234567"], | |
["base32upper", "B", rfc464811(5), "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"], | |
["base32pad", "c", rfc464811(5), "abcdefghijklmnopqrstuvwxyz234567="], | |
["base32padupper", "C", rfc464811(5), "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567="], | |
["base32z", "h", rfc464811(5), "ybndrfg8ejkmcpqxot1uwisza345h769"], | |
["base36", "k", baseX11, "0123456789abcdefghijklmnopqrstuvwxyz"], | |
["base36upper", "K", baseX11, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"], | |
["base58btc", "z", baseX11, "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"], | |
["base58flickr", "Z", baseX11, "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"], | |
["base64", "m", rfc464811(6), "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"], | |
["base64pad", "M", rfc464811(6), "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="], | |
["base64url", "u", rfc464811(6), "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"], | |
["base64urlpad", "U", rfc464811(6), "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_="] | |
]; | |
var names3 = constants.reduce( | |
(prev, tupple) => { | |
prev[tupple[0]] = new Base(tupple[0], tupple[1], tupple[2], tupple[3]); | |
return prev; | |
}, | |
/** @type {Record<BaseName,Base>} */ | |
{} | |
); | |
var codes8 = constants.reduce( | |
(prev, tupple) => { | |
prev[tupple[1]] = names3[tupple[0]]; | |
return prev; | |
}, | |
/** @type {Record<BaseCode,Base>} */ | |
{} | |
); | |
module2.exports = { | |
names: names3, | |
codes: codes8 | |
}; | |
} | |
}); | |
// node_modules/multibase/src/index.js | |
var require_src3 = __commonJS({ | |
"node_modules/multibase/src/index.js"(exports2, module2) { | |
"use strict"; | |
var constants = require_constants(); | |
var { encodeText, decodeText, concat: concat5 } = require_util2(); | |
function multibase(nameOrCode, buf3) { | |
if (!buf3) { | |
throw new Error("requires an encoded Uint8Array"); | |
} | |
const { name: name8, codeBuf } = encoding(nameOrCode); | |
validEncode(name8, buf3); | |
return concat5([codeBuf, buf3], codeBuf.length + buf3.length); | |
} | |
function encode39(nameOrCode, buf3) { | |
const enc = encoding(nameOrCode); | |
const data = encodeText(enc.encode(buf3)); | |
return concat5([enc.codeBuf, data], enc.codeBuf.length + data.length); | |
} | |
function decode50(data) { | |
if (data instanceof Uint8Array) { | |
data = decodeText(data); | |
} | |
const prefix = data[0]; | |
if (["f", "F", "v", "V", "t", "T", "b", "B", "c", "C", "h", "k", "K"].includes(prefix)) { | |
data = data.toLowerCase(); | |
} | |
const enc = encoding( | |
/** @type {BaseCode} */ | |
data[0] | |
); | |
return enc.decode(data.substring(1)); | |
} | |
function isEncoded(data) { | |
if (data instanceof Uint8Array) { | |
data = decodeText(data); | |
} | |
if (Object.prototype.toString.call(data) !== "[object String]") { | |
return false; | |
} | |
try { | |
const enc = encoding( | |
/** @type {BaseCode} */ | |
data[0] | |
); | |
return enc.name; | |
} catch (err) { | |
return false; | |
} | |
} | |
function validEncode(name8, buf3) { | |
const enc = encoding(name8); | |
enc.decode(decodeText(buf3)); | |
} | |
function encoding(nameOrCode) { | |
if (Object.prototype.hasOwnProperty.call( | |
constants.names, | |
/** @type {BaseName} */ | |
nameOrCode | |
)) { | |
return constants.names[ | |
/** @type {BaseName} */ | |
nameOrCode | |
]; | |
} else if (Object.prototype.hasOwnProperty.call( | |
constants.codes, | |
/** @type {BaseCode} */ | |
nameOrCode | |
)) { | |
return constants.codes[ | |
/** @type {BaseCode} */ | |
nameOrCode | |
]; | |
} else { | |
throw new Error(`Unsupported encoding: ${nameOrCode}`); | |
} | |
} | |
function encodingFromData(data) { | |
if (data instanceof Uint8Array) { | |
data = decodeText(data); | |
} | |
return encoding( | |
/** @type {BaseCode} */ | |
data[0] | |
); | |
} | |
exports2 = module2.exports = multibase; | |
exports2.encode = encode39; | |
exports2.decode = decode50; | |
exports2.isEncoded = isEncoded; | |
exports2.encoding = encoding; | |
exports2.encodingFromData = encodingFromData; | |
var names3 = Object.freeze(constants.names); | |
var codes8 = Object.freeze(constants.codes); | |
exports2.names = names3; | |
exports2.codes = codes8; | |
} | |
}); | |
// node_modules/multihashes/node_modules/varint/encode.js | |
var require_encode3 = __commonJS({ | |
"node_modules/multihashes/node_modules/varint/encode.js"(exports2, module2) { | |
module2.exports = encode39; | |
var MSB11 = 128; | |
var REST11 = 127; | |
var MSBALL10 = ~REST11; | |
var INT10 = Math.pow(2, 31); | |
function encode39(num, out, offset) { | |
out = out || []; | |
offset = offset || 0; | |
var oldOffset = offset; | |
while (num >= INT10) { | |
out[offset++] = num & 255 | MSB11; | |
num /= 128; | |
} | |
while (num & MSBALL10) { | |
out[offset++] = num & 255 | MSB11; | |
num >>>= 7; | |
} | |
out[offset] = num | 0; | |
encode39.bytes = offset - oldOffset + 1; | |
return out; | |
} | |
} | |
}); | |
// node_modules/multihashes/node_modules/varint/decode.js | |
var require_decode3 = __commonJS({ | |
"node_modules/multihashes/node_modules/varint/decode.js"(exports2, module2) { | |
module2.exports = read11; | |
var MSB11 = 128; | |
var REST11 = 127; | |
function read11(buf3, offset) { | |
var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf3.length; | |
do { | |
if (counter >= l) { | |
read11.bytes = 0; | |
throw new RangeError("Could not decode varint"); | |
} | |
b = buf3[counter++]; | |
res += shift < 28 ? (b & REST11) << shift : (b & REST11) * Math.pow(2, shift); | |
shift += 7; | |
} while (b >= MSB11); | |
read11.bytes = counter - offset; | |
return res; | |
} | |
} | |
}); | |
// node_modules/multihashes/node_modules/varint/length.js | |
var require_length3 = __commonJS({ | |
"node_modules/multihashes/node_modules/varint/length.js"(exports2, module2) { | |
var N111 = Math.pow(2, 7); | |
var N211 = Math.pow(2, 14); | |
var N311 = Math.pow(2, 21); | |
var N411 = Math.pow(2, 28); | |
var N511 = Math.pow(2, 35); | |
var N611 = Math.pow(2, 42); | |
var N711 = Math.pow(2, 49); | |
var N811 = Math.pow(2, 56); | |
var N911 = Math.pow(2, 63); | |
module2.exports = function(value) { | |
return value < N111 ? 1 : value < N211 ? 2 : value < N311 ? 3 : value < N411 ? 4 : value < N511 ? 5 : value < N611 ? 6 : value < N711 ? 7 : value < N811 ? 8 : value < N911 ? 9 : 10; | |
}; | |
} | |
}); | |
// node_modules/multihashes/node_modules/varint/index.js | |
var require_varint3 = __commonJS({ | |
"node_modules/multihashes/node_modules/varint/index.js"(exports2, module2) { | |
module2.exports = { | |
encode: require_encode3(), | |
decode: require_decode3(), | |
encodingLength: require_length3() | |
}; | |
} | |
}); | |
// node_modules/multihashes/src/constants.js | |
var require_constants2 = __commonJS({ | |
"node_modules/multihashes/src/constants.js"(exports2, module2) { | |
"use strict"; | |
var names3 = Object.freeze({ | |
"identity": 0, | |
"sha1": 17, | |
"sha2-256": 18, | |
"sha2-512": 19, | |
"sha3-512": 20, | |
"sha3-384": 21, | |
"sha3-256": 22, | |
"sha3-224": 23, | |
"shake-128": 24, | |
"shake-256": 25, | |
"keccak-224": 26, | |
"keccak-256": 27, | |
"keccak-384": 28, | |
"keccak-512": 29, | |
"blake3": 30, | |
"murmur3-128": 34, | |
"murmur3-32": 35, | |
"dbl-sha2-256": 86, | |
"md4": 212, | |
"md5": 213, | |
"bmt": 214, | |
"sha2-256-trunc254-padded": 4114, | |
"ripemd-128": 4178, | |
"ripemd-160": 4179, | |
"ripemd-256": 4180, | |
"ripemd-320": 4181, | |
"x11": 4352, | |
"kangarootwelve": 7425, | |
"sm3-256": 21325, | |
"blake2b-8": 45569, | |
"blake2b-16": 45570, | |
"blake2b-24": 45571, | |
"blake2b-32": 45572, | |
"blake2b-40": 45573, | |
"blake2b-48": 45574, | |
"blake2b-56": 45575, | |
"blake2b-64": 45576, | |
"blake2b-72": 45577, | |
"blake2b-80": 45578, | |
"blake2b-88": 45579, | |
"blake2b-96": 45580, | |
"blake2b-104": 45581, | |
"blake2b-112": 45582, | |
"blake2b-120": 45583, | |
"blake2b-128": 45584, | |
"blake2b-136": 45585, | |
"blake2b-144": 45586, | |
"blake2b-152": 45587, | |
"blake2b-160": 45588, | |
"blake2b-168": 45589, | |
"blake2b-176": 45590, | |
"blake2b-184": 45591, | |
"blake2b-192": 45592, | |
"blake2b-200": 45593, | |
"blake2b-208": 45594, | |
"blake2b-216": 45595, | |
"blake2b-224": 45596, | |
"blake2b-232": 45597, | |
"blake2b-240": 45598, | |
"blake2b-248": 45599, | |
"blake2b-256": 45600, | |
"blake2b-264": 45601, | |
"blake2b-272": 45602, | |
"blake2b-280": 45603, | |
"blake2b-288": 45604, | |
"blake2b-296": 45605, | |
"blake2b-304": 45606, | |
"blake2b-312": 45607, | |
"blake2b-320": 45608, | |
"blake2b-328": 45609, | |
"blake2b-336": 45610, | |
"blake2b-344": 45611, | |
"blake2b-352": 45612, | |
"blake2b-360": 45613, | |
"blake2b-368": 45614, | |
"blake2b-376": 45615, | |
"blake2b-384": 45616, | |
"blake2b-392": 45617, | |
"blake2b-400": 45618, | |
"blake2b-408": 45619, | |
"blake2b-416": 45620, | |
"blake2b-424": 45621, | |
"blake2b-432": 45622, | |
"blake2b-440": 45623, | |
"blake2b-448": 45624, | |
"blake2b-456": 45625, | |
"blake2b-464": 45626, | |
"blake2b-472": 45627, | |
"blake2b-480": 45628, | |
"blake2b-488": 45629, | |
"blake2b-496": 45630, | |
"blake2b-504": 45631, | |
"blake2b-512": 45632, | |
"blake2s-8": 45633, | |
"blake2s-16": 45634, | |
"blake2s-24": 45635, | |
"blake2s-32": 45636, | |
"blake2s-40": 45637, | |
"blake2s-48": 45638, | |
"blake2s-56": 45639, | |
"blake2s-64": 45640, | |
"blake2s-72": 45641, | |
"blake2s-80": 45642, | |
"blake2s-88": 45643, | |
"blake2s-96": 45644, | |
"blake2s-104": 45645, | |
"blake2s-112": 45646, | |
"blake2s-120": 45647, | |
"blake2s-128": 45648, | |
"blake2s-136": 45649, | |
"blake2s-144": 45650, | |
"blake2s-152": 45651, | |
"blake2s-160": 45652, | |
"blake2s-168": 45653, | |
"blake2s-176": 45654, | |
"blake2s-184": 45655, | |
"blake2s-192": 45656, | |
"blake2s-200": 45657, | |
"blake2s-208": 45658, | |
"blake2s-216": 45659, | |
"blake2s-224": 45660, | |
"blake2s-232": 45661, | |
"blake2s-240": 45662, | |
"blake2s-248": 45663, | |
"blake2s-256": 45664, | |
"skein256-8": 45825, | |
"skein256-16": 45826, | |
"skein256-24": 45827, | |
"skein256-32": 45828, | |
"skein256-40": 45829, | |
"skein256-48": 45830, | |
"skein256-56": 45831, | |
"skein256-64": 45832, | |
"skein256-72": 45833, | |
"skein256-80": 45834, | |
"skein256-88": 45835, | |
"skein256-96": 45836, | |
"skein256-104": 45837, | |
"skein256-112": 45838, | |
"skein256-120": 45839, | |
"skein256-128": 45840, | |
"skein256-136": 45841, | |
"skein256-144": 45842, | |
"skein256-152": 45843, | |
"skein256-160": 45844, | |
"skein256-168": 45845, | |
"skein256-176": 45846, | |
"skein256-184": 45847, | |
"skein256-192": 45848, | |
"skein256-200": 45849, | |
"skein256-208": 45850, | |
"skein256-216": 45851, | |
"skein256-224": 45852, | |
"skein256-232": 45853, | |
"skein256-240": 45854, | |
"skein256-248": 45855, | |
"skein256-256": 45856, | |
"skein512-8": 45857, | |
"skein512-16": 45858, | |
"skein512-24": 45859, | |
"skein512-32": 45860, | |
"skein512-40": 45861, | |
"skein512-48": 45862, | |
"skein512-56": 45863, | |
"skein512-64": 45864, | |
"skein512-72": 45865, | |
"skein512-80": 45866, | |
"skein512-88": 45867, | |
"skein512-96": 45868, | |
"skein512-104": 45869, | |
"skein512-112": 45870, | |
"skein512-120": 45871, | |
"skein512-128": 45872, | |
"skein512-136": 45873, | |
"skein512-144": 45874, | |
"skein512-152": 45875, | |
"skein512-160": 45876, | |
"skein512-168": 45877, | |
"skein512-176": 45878, | |
"skein512-184": 45879, | |
"skein512-192": 45880, | |
"skein512-200": 45881, | |
"skein512-208": 45882, | |
"skein512-216": 45883, | |
"skein512-224": 45884, | |
"skein512-232": 45885, | |
"skein512-240": 45886, | |
"skein512-248": 45887, | |
"skein512-256": 45888, | |
"skein512-264": 45889, | |
"skein512-272": 45890, | |
"skein512-280": 45891, | |
"skein512-288": 45892, | |
"skein512-296": 45893, | |
"skein512-304": 45894, | |
"skein512-312": 45895, | |
"skein512-320": 45896, | |
"skein512-328": 45897, | |
"skein512-336": 45898, | |
"skein512-344": 45899, | |
"skein512-352": 45900, | |
"skein512-360": 45901, | |
"skein512-368": 45902, | |
"skein512-376": 45903, | |
"skein512-384": 45904, | |
"skein512-392": 45905, | |
"skein512-400": 45906, | |
"skein512-408": 45907, | |
"skein512-416": 45908, | |
"skein512-424": 45909, | |
"skein512-432": 45910, | |
"skein512-440": 45911, | |
"skein512-448": 45912, | |
"skein512-456": 45913, | |
"skein512-464": 45914, | |
"skein512-472": 45915, | |
"skein512-480": 45916, | |
"skein512-488": 45917, | |
"skein512-496": 45918, | |
"skein512-504": 45919, | |
"skein512-512": 45920, | |
"skein1024-8": 45921, | |
"skein1024-16": 45922, | |
"skein1024-24": 45923, | |
"skein1024-32": 45924, | |
"skein1024-40": 45925, | |
"skein1024-48": 45926, | |
"skein1024-56": 45927, | |
"skein1024-64": 45928, | |
"skein1024-72": 45929, | |
"skein1024-80": 45930, | |
"skein1024-88": 45931, | |
"skein1024-96": 45932, | |
"skein1024-104": 45933, | |
"skein1024-112": 45934, | |
"skein1024-120": 45935, | |
"skein1024-128": 45936, | |
"skein1024-136": 45937, | |
"skein1024-144": 45938, | |
"skein1024-152": 45939, | |
"skein1024-160": 45940, | |
"skein1024-168": 45941, | |
"skein1024-176": 45942, | |
"skein1024-184": 45943, | |
"skein1024-192": 45944, | |
"skein1024-200": 45945, | |
"skein1024-208": 45946, | |
"skein1024-216": 45947, | |
"skein1024-224": 45948, | |
"skein1024-232": 45949, | |
"skein1024-240": 45950, | |
"skein1024-248": 45951, | |
"skein1024-256": 45952, | |
"skein1024-264": 45953, | |
"skein1024-272": 45954, | |
"skein1024-280": 45955, | |
"skein1024-288": 45956, | |
"skein1024-296": 45957, | |
"skein1024-304": 45958, | |
"skein1024-312": 45959, | |
"skein1024-320": 45960, | |
"skein1024-328": 45961, | |
"skein1024-336": 45962, | |
"skein1024-344": 45963, | |
"skein1024-352": 45964, | |
"skein1024-360": 45965, | |
"skein1024-368": 45966, | |
"skein1024-376": 45967, | |
"skein1024-384": 45968, | |
"skein1024-392": 45969, | |
"skein1024-400": 45970, | |
"skein1024-408": 45971, | |
"skein1024-416": 45972, | |
"skein1024-424": 45973, | |
"skein1024-432": 45974, | |
"skein1024-440": 45975, | |
"skein1024-448": 45976, | |
"skein1024-456": 45977, | |
"skein1024-464": 45978, | |
"skein1024-472": 45979, | |
"skein1024-480": 45980, | |
"skein1024-488": 45981, | |
"skein1024-496": 45982, | |
"skein1024-504": 45983, | |
"skein1024-512": 45984, | |
"skein1024-520": 45985, | |
"skein1024-528": 45986, | |
"skein1024-536": 45987, | |
"skein1024-544": 45988, | |
"skein1024-552": 45989, | |
"skein1024-560": 45990, | |
"skein1024-568": 45991, | |
"skein1024-576": 45992, | |
"skein1024-584": 45993, | |
"skein1024-592": 45994, | |
"skein1024-600": 45995, | |
"skein1024-608": 45996, | |
"skein1024-616": 45997, | |
"skein1024-624": 45998, | |
"skein1024-632": 45999, | |
"skein1024-640": 46e3, | |
"skein1024-648": 46001, | |
"skein1024-656": 46002, | |
"skein1024-664": 46003, | |
"skein1024-672": 46004, | |
"skein1024-680": 46005, | |
"skein1024-688": 46006, | |
"skein1024-696": 46007, | |
"skein1024-704": 46008, | |
"skein1024-712": 46009, | |
"skein1024-720": 46010, | |
"skein1024-728": 46011, | |
"skein1024-736": 46012, | |
"skein1024-744": 46013, | |
"skein1024-752": 46014, | |
"skein1024-760": 46015, | |
"skein1024-768": 46016, | |
"skein1024-776": 46017, | |
"skein1024-784": 46018, | |
"skein1024-792": 46019, | |
"skein1024-800": 46020, | |
"skein1024-808": 46021, | |
"skein1024-816": 46022, | |
"skein1024-824": 46023, | |
"skein1024-832": 46024, | |
"skein1024-840": 46025, | |
"skein1024-848": 46026, | |
"skein1024-856": 46027, | |
"skein1024-864": 46028, | |
"skein1024-872": 46029, | |
"skein1024-880": 46030, | |
"skein1024-888": 46031, | |
"skein1024-896": 46032, | |
"skein1024-904": 46033, | |
"skein1024-912": 46034, | |
"skein1024-920": 46035, | |
"skein1024-928": 46036, | |
"skein1024-936": 46037, | |
"skein1024-944": 46038, | |
"skein1024-952": 46039, | |
"skein1024-960": 46040, | |
"skein1024-968": 46041, | |
"skein1024-976": 46042, | |
"skein1024-984": 46043, | |
"skein1024-992": 46044, | |
"skein1024-1000": 46045, | |
"skein1024-1008": 46046, | |
"skein1024-1016": 46047, | |
"skein1024-1024": 46048, | |
"poseidon-bls12_381-a2-fc1": 46081, | |
"poseidon-bls12_381-a2-fc1-sc": 46082 | |
}); | |
module2.exports = { names: names3 }; | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/vendor/base-x.js | |
function base11(ALPHABET, name8) { | |
if (ALPHABET.length >= 255) { | |
throw new TypeError("Alphabet too long"); | |
} | |
var BASE_MAP = new Uint8Array(256); | |
for (var j = 0; j < BASE_MAP.length; j++) { | |
BASE_MAP[j] = 255; | |
} | |
for (var i = 0; i < ALPHABET.length; i++) { | |
var x = ALPHABET.charAt(i); | |
var xc = x.charCodeAt(0); | |
if (BASE_MAP[xc] !== 255) { | |
throw new TypeError(x + " is ambiguous"); | |
} | |
BASE_MAP[xc] = i; | |
} | |
var BASE = ALPHABET.length; | |
var LEADER = ALPHABET.charAt(0); | |
var FACTOR = Math.log(BASE) / Math.log(256); | |
var iFACTOR = Math.log(256) / Math.log(BASE); | |
function encode39(source) { | |
if (source instanceof Uint8Array) | |
; | |
else if (ArrayBuffer.isView(source)) { | |
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength); | |
} else if (Array.isArray(source)) { | |
source = Uint8Array.from(source); | |
} | |
if (!(source instanceof Uint8Array)) { | |
throw new TypeError("Expected Uint8Array"); | |
} | |
if (source.length === 0) { | |
return ""; | |
} | |
var zeroes = 0; | |
var length11 = 0; | |
var pbegin = 0; | |
var pend = source.length; | |
while (pbegin !== pend && source[pbegin] === 0) { | |
pbegin++; | |
zeroes++; | |
} | |
var size = (pend - pbegin) * iFACTOR + 1 >>> 0; | |
var b58 = new Uint8Array(size); | |
while (pbegin !== pend) { | |
var carry = source[pbegin]; | |
var i2 = 0; | |
for (var it1 = size - 1; (carry !== 0 || i2 < length11) && it1 !== -1; it1--, i2++) { | |
carry += 256 * b58[it1] >>> 0; | |
b58[it1] = carry % BASE >>> 0; | |
carry = carry / BASE >>> 0; | |
} | |
if (carry !== 0) { | |
throw new Error("Non-zero carry"); | |
} | |
length11 = i2; | |
pbegin++; | |
} | |
var it2 = size - length11; | |
while (it2 !== size && b58[it2] === 0) { | |
it2++; | |
} | |
var str = LEADER.repeat(zeroes); | |
for (; it2 < size; ++it2) { | |
str += ALPHABET.charAt(b58[it2]); | |
} | |
return str; | |
} | |
function decodeUnsafe(source) { | |
if (typeof source !== "string") { | |
throw new TypeError("Expected String"); | |
} | |
if (source.length === 0) { | |
return new Uint8Array(); | |
} | |
var psz = 0; | |
if (source[psz] === " ") { | |
return; | |
} | |
var zeroes = 0; | |
var length11 = 0; | |
while (source[psz] === LEADER) { | |
zeroes++; | |
psz++; | |
} | |
var size = (source.length - psz) * FACTOR + 1 >>> 0; | |
var b256 = new Uint8Array(size); | |
while (source[psz]) { | |
var carry = BASE_MAP[source.charCodeAt(psz)]; | |
if (carry === 255) { | |
return; | |
} | |
var i2 = 0; | |
for (var it3 = size - 1; (carry !== 0 || i2 < length11) && it3 !== -1; it3--, i2++) { | |
carry += BASE * b256[it3] >>> 0; | |
b256[it3] = carry % 256 >>> 0; | |
carry = carry / 256 >>> 0; | |
} | |
if (carry !== 0) { | |
throw new Error("Non-zero carry"); | |
} | |
length11 = i2; | |
psz++; | |
} | |
if (source[psz] === " ") { | |
return; | |
} | |
var it4 = size - length11; | |
while (it4 !== size && b256[it4] === 0) { | |
it4++; | |
} | |
var vch = new Uint8Array(zeroes + (size - it4)); | |
var j2 = zeroes; | |
while (it4 !== size) { | |
vch[j2++] = b256[it4++]; | |
} | |
return vch; | |
} | |
function decode50(string3) { | |
var buffer3 = decodeUnsafe(string3); | |
if (buffer3) { | |
return buffer3; | |
} | |
throw new Error(`Non-${name8} character`); | |
} | |
return { | |
encode: encode39, | |
decodeUnsafe, | |
decode: decode50 | |
}; | |
} | |
var src8, _brrp__multiformats_scope_baseX8, base_x_default8; | |
var init_base_x = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/vendor/base-x.js"() { | |
src8 = base11; | |
_brrp__multiformats_scope_baseX8 = src8; | |
base_x_default8 = _brrp__multiformats_scope_baseX8; | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/src/bytes.js | |
var empty8, equals14, coerce8, fromString6, toString7; | |
var init_bytes = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/src/bytes.js"() { | |
empty8 = new Uint8Array(0); | |
equals14 = (aa, bb) => { | |
if (aa === bb) | |
return true; | |
if (aa.byteLength !== bb.byteLength) { | |
return false; | |
} | |
for (let ii = 0; ii < aa.byteLength; ii++) { | |
if (aa[ii] !== bb[ii]) { | |
return false; | |
} | |
} | |
return true; | |
}; | |
coerce8 = (o) => { | |
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array") | |
return o; | |
if (o instanceof ArrayBuffer) | |
return new Uint8Array(o); | |
if (ArrayBuffer.isView(o)) { | |
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength); | |
} | |
throw new Error("Unknown type, must be binary type"); | |
}; | |
fromString6 = (str) => new TextEncoder().encode(str); | |
toString7 = (b) => new TextDecoder().decode(b); | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/src/bases/base.js | |
var Encoder9, Decoder10, ComposedDecoder8, or9, Codec8, from12, baseX8, decode34, encode29, rfc46488; | |
var init_base = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/src/bases/base.js"() { | |
init_base_x(); | |
init_bytes(); | |
Encoder9 = class { | |
constructor(name8, prefix, baseEncode) { | |
this.name = name8; | |
this.prefix = prefix; | |
this.baseEncode = baseEncode; | |
} | |
encode(bytes3) { | |
if (bytes3 instanceof Uint8Array) { | |
return `${this.prefix}${this.baseEncode(bytes3)}`; | |
} else { | |
throw Error("Unknown type, must be binary type"); | |
} | |
} | |
}; | |
Decoder10 = class { | |
constructor(name8, prefix, baseDecode) { | |
this.name = name8; | |
this.prefix = prefix; | |
if (prefix.codePointAt(0) === void 0) { | |
throw new Error("Invalid prefix character"); | |
} | |
this.prefixCodePoint = prefix.codePointAt(0); | |
this.baseDecode = baseDecode; | |
} | |
decode(text) { | |
if (typeof text === "string") { | |
if (text.codePointAt(0) !== this.prefixCodePoint) { | |
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`); | |
} | |
return this.baseDecode(text.slice(this.prefix.length)); | |
} else { | |
throw Error("Can only multibase decode strings"); | |
} | |
} | |
or(decoder) { | |
return or9(this, decoder); | |
} | |
}; | |
ComposedDecoder8 = class { | |
constructor(decoders2) { | |
this.decoders = decoders2; | |
} | |
or(decoder) { | |
return or9(this, decoder); | |
} | |
decode(input) { | |
const prefix = input[0]; | |
const decoder = this.decoders[prefix]; | |
if (decoder) { | |
return decoder.decode(input); | |
} else { | |
throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`); | |
} | |
} | |
}; | |
or9 = (left, right) => new ComposedDecoder8({ | |
...left.decoders || { [left.prefix]: left }, | |
...right.decoders || { [right.prefix]: right } | |
}); | |
Codec8 = class { | |
constructor(name8, prefix, baseEncode, baseDecode) { | |
this.name = name8; | |
this.prefix = prefix; | |
this.baseEncode = baseEncode; | |
this.baseDecode = baseDecode; | |
this.encoder = new Encoder9(name8, prefix, baseEncode); | |
this.decoder = new Decoder10(name8, prefix, baseDecode); | |
} | |
encode(input) { | |
return this.encoder.encode(input); | |
} | |
decode(input) { | |
return this.decoder.decode(input); | |
} | |
}; | |
from12 = ({ name: name8, prefix, encode: encode39, decode: decode50 }) => new Codec8(name8, prefix, encode39, decode50); | |
baseX8 = ({ prefix, name: name8, alphabet: alphabet5 }) => { | |
const { encode: encode39, decode: decode50 } = base_x_default8(alphabet5, name8); | |
return from12({ | |
prefix, | |
name: name8, | |
encode: encode39, | |
decode: (text) => coerce8(decode50(text)) | |
}); | |
}; | |
decode34 = (string3, alphabet5, bitsPerChar, name8) => { | |
const codes8 = {}; | |
for (let i = 0; i < alphabet5.length; ++i) { | |
codes8[alphabet5[i]] = i; | |
} | |
let end = string3.length; | |
while (string3[end - 1] === "=") { | |
--end; | |
} | |
const out = new Uint8Array(end * bitsPerChar / 8 | 0); | |
let bits2 = 0; | |
let buffer3 = 0; | |
let written = 0; | |
for (let i = 0; i < end; ++i) { | |
const value = codes8[string3[i]]; | |
if (value === void 0) { | |
throw new SyntaxError(`Non-${name8} character`); | |
} | |
buffer3 = buffer3 << bitsPerChar | value; | |
bits2 += bitsPerChar; | |
if (bits2 >= 8) { | |
bits2 -= 8; | |
out[written++] = 255 & buffer3 >> bits2; | |
} | |
} | |
if (bits2 >= bitsPerChar || 255 & buffer3 << 8 - bits2) { | |
throw new SyntaxError("Unexpected end of data"); | |
} | |
return out; | |
}; | |
encode29 = (data, alphabet5, bitsPerChar) => { | |
const pad = alphabet5[alphabet5.length - 1] === "="; | |
const mask = (1 << bitsPerChar) - 1; | |
let out = ""; | |
let bits2 = 0; | |
let buffer3 = 0; | |
for (let i = 0; i < data.length; ++i) { | |
buffer3 = buffer3 << 8 | data[i]; | |
bits2 += 8; | |
while (bits2 > bitsPerChar) { | |
bits2 -= bitsPerChar; | |
out += alphabet5[mask & buffer3 >> bits2]; | |
} | |
} | |
if (bits2) { | |
out += alphabet5[mask & buffer3 << bitsPerChar - bits2]; | |
} | |
if (pad) { | |
while (out.length * bitsPerChar & 7) { | |
out += "="; | |
} | |
} | |
return out; | |
}; | |
rfc46488 = ({ name: name8, prefix, bitsPerChar, alphabet: alphabet5 }) => { | |
return from12({ | |
prefix, | |
name: name8, | |
encode(input) { | |
return encode29(input, alphabet5, bitsPerChar); | |
}, | |
decode(input) { | |
return decode34(input, alphabet5, bitsPerChar, name8); | |
} | |
}); | |
}; | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/src/bases/identity.js | |
var identity_exports7 = {}; | |
__export(identity_exports7, { | |
identity: () => identity7 | |
}); | |
var identity7; | |
var init_identity = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/src/bases/identity.js"() { | |
init_base(); | |
init_bytes(); | |
identity7 = from12({ | |
prefix: "\0", | |
name: "identity", | |
encode: (buf3) => toString7(buf3), | |
decode: (str) => fromString6(str) | |
}); | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/src/bases/base2.js | |
var base2_exports4 = {}; | |
__export(base2_exports4, { | |
base2: () => base25 | |
}); | |
var base25; | |
var init_base2 = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/src/bases/base2.js"() { | |
init_base(); | |
base25 = rfc46488({ | |
prefix: "0", | |
name: "base2", | |
alphabet: "01", | |
bitsPerChar: 1 | |
}); | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/src/bases/base8.js | |
var base8_exports4 = {}; | |
__export(base8_exports4, { | |
base8: () => base84 | |
}); | |
var base84; | |
var init_base8 = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/src/bases/base8.js"() { | |
init_base(); | |
base84 = rfc46488({ | |
prefix: "7", | |
name: "base8", | |
alphabet: "01234567", | |
bitsPerChar: 3 | |
}); | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/src/bases/base10.js | |
var base10_exports4 = {}; | |
__export(base10_exports4, { | |
base10: () => base104 | |
}); | |
var base104; | |
var init_base10 = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/src/bases/base10.js"() { | |
init_base(); | |
base104 = baseX8({ | |
prefix: "9", | |
name: "base10", | |
alphabet: "0123456789" | |
}); | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/src/bases/base16.js | |
var base16_exports4 = {}; | |
__export(base16_exports4, { | |
base16: () => base164, | |
base16upper: () => base16upper4 | |
}); | |
var base164, base16upper4; | |
var init_base16 = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/src/bases/base16.js"() { | |
init_base(); | |
base164 = rfc46488({ | |
prefix: "f", | |
name: "base16", | |
alphabet: "0123456789abcdef", | |
bitsPerChar: 4 | |
}); | |
base16upper4 = rfc46488({ | |
prefix: "F", | |
name: "base16upper", | |
alphabet: "0123456789ABCDEF", | |
bitsPerChar: 4 | |
}); | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/src/bases/base32.js | |
var base32_exports4 = {}; | |
__export(base32_exports4, { | |
base32: () => base328, | |
base32hex: () => base32hex8, | |
base32hexpad: () => base32hexpad8, | |
base32hexpadupper: () => base32hexpadupper8, | |
base32hexupper: () => base32hexupper8, | |
base32pad: () => base32pad8, | |
base32padupper: () => base32padupper8, | |
base32upper: () => base32upper8, | |
base32z: () => base32z8 | |
}); | |
var base328, base32upper8, base32pad8, base32padupper8, base32hex8, base32hexupper8, base32hexpad8, base32hexpadupper8, base32z8; | |
var init_base32 = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/src/bases/base32.js"() { | |
init_base(); | |
base328 = rfc46488({ | |
prefix: "b", | |
name: "base32", | |
alphabet: "abcdefghijklmnopqrstuvwxyz234567", | |
bitsPerChar: 5 | |
}); | |
base32upper8 = rfc46488({ | |
prefix: "B", | |
name: "base32upper", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", | |
bitsPerChar: 5 | |
}); | |
base32pad8 = rfc46488({ | |
prefix: "c", | |
name: "base32pad", | |
alphabet: "abcdefghijklmnopqrstuvwxyz234567=", | |
bitsPerChar: 5 | |
}); | |
base32padupper8 = rfc46488({ | |
prefix: "C", | |
name: "base32padupper", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=", | |
bitsPerChar: 5 | |
}); | |
base32hex8 = rfc46488({ | |
prefix: "v", | |
name: "base32hex", | |
alphabet: "0123456789abcdefghijklmnopqrstuv", | |
bitsPerChar: 5 | |
}); | |
base32hexupper8 = rfc46488({ | |
prefix: "V", | |
name: "base32hexupper", | |
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV", | |
bitsPerChar: 5 | |
}); | |
base32hexpad8 = rfc46488({ | |
prefix: "t", | |
name: "base32hexpad", | |
alphabet: "0123456789abcdefghijklmnopqrstuv=", | |
bitsPerChar: 5 | |
}); | |
base32hexpadupper8 = rfc46488({ | |
prefix: "T", | |
name: "base32hexpadupper", | |
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=", | |
bitsPerChar: 5 | |
}); | |
base32z8 = rfc46488({ | |
prefix: "h", | |
name: "base32z", | |
alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769", | |
bitsPerChar: 5 | |
}); | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/src/bases/base36.js | |
var base36_exports4 = {}; | |
__export(base36_exports4, { | |
base36: () => base364, | |
base36upper: () => base36upper4 | |
}); | |
var base364, base36upper4; | |
var init_base36 = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/src/bases/base36.js"() { | |
init_base(); | |
base364 = baseX8({ | |
prefix: "k", | |
name: "base36", | |
alphabet: "0123456789abcdefghijklmnopqrstuvwxyz" | |
}); | |
base36upper4 = baseX8({ | |
prefix: "K", | |
name: "base36upper", | |
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
}); | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/src/bases/base58.js | |
var base58_exports4 = {}; | |
__export(base58_exports4, { | |
base58btc: () => base58btc8, | |
base58flickr: () => base58flickr8 | |
}); | |
var base58btc8, base58flickr8; | |
var init_base58 = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/src/bases/base58.js"() { | |
init_base(); | |
base58btc8 = baseX8({ | |
name: "base58btc", | |
prefix: "z", | |
alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" | |
}); | |
base58flickr8 = baseX8({ | |
name: "base58flickr", | |
prefix: "Z", | |
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ" | |
}); | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/src/bases/base64.js | |
var base64_exports4 = {}; | |
__export(base64_exports4, { | |
base64: () => base646, | |
base64pad: () => base64pad6, | |
base64url: () => base64url6, | |
base64urlpad: () => base64urlpad6 | |
}); | |
var base646, base64pad6, base64url6, base64urlpad6; | |
var init_base64 = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/src/bases/base64.js"() { | |
init_base(); | |
base646 = rfc46488({ | |
prefix: "m", | |
name: "base64", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", | |
bitsPerChar: 6 | |
}); | |
base64pad6 = rfc46488({ | |
prefix: "M", | |
name: "base64pad", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", | |
bitsPerChar: 6 | |
}); | |
base64url6 = rfc46488({ | |
prefix: "u", | |
name: "base64url", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", | |
bitsPerChar: 6 | |
}); | |
base64urlpad6 = rfc46488({ | |
prefix: "U", | |
name: "base64urlpad", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=", | |
bitsPerChar: 6 | |
}); | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/src/bases/base256emoji.js | |
var base256emoji_exports4 = {}; | |
__export(base256emoji_exports4, { | |
base256emoji: () => base256emoji4 | |
}); | |
function encode30(data) { | |
return data.reduce((p, c) => { | |
p += alphabetBytesToChars4[c]; | |
return p; | |
}, ""); | |
} | |
function decode35(str) { | |
const byts = []; | |
for (const char of str) { | |
const byt = alphabetCharsToBytes4[char.codePointAt(0)]; | |
if (byt === void 0) { | |
throw new Error(`Non-base256emoji character: ${char}`); | |
} | |
byts.push(byt); | |
} | |
return new Uint8Array(byts); | |
} | |
var alphabet4, alphabetBytesToChars4, alphabetCharsToBytes4, base256emoji4; | |
var init_base256emoji = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/src/bases/base256emoji.js"() { | |
init_base(); | |
alphabet4 = Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"); | |
alphabetBytesToChars4 = alphabet4.reduce((p, c, i) => { | |
p[i] = c; | |
return p; | |
}, []); | |
alphabetCharsToBytes4 = alphabet4.reduce((p, c, i) => { | |
p[c.codePointAt(0)] = i; | |
return p; | |
}, []); | |
base256emoji4 = from12({ | |
prefix: "\u{1F680}", | |
name: "base256emoji", | |
encode: encode30, | |
decode: decode35 | |
}); | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/vendor/varint.js | |
function encode31(num, out, offset) { | |
out = out || []; | |
offset = offset || 0; | |
var oldOffset = offset; | |
while (num >= INT7) { | |
out[offset++] = num & 255 | MSB8; | |
num /= 128; | |
} | |
while (num & MSBALL7) { | |
out[offset++] = num & 255 | MSB8; | |
num >>>= 7; | |
} | |
out[offset] = num | 0; | |
encode31.bytes = offset - oldOffset + 1; | |
return out; | |
} | |
function read8(buf3, offset) { | |
var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf3.length; | |
do { | |
if (counter >= l) { | |
read8.bytes = 0; | |
throw new RangeError("Could not decode varint"); | |
} | |
b = buf3[counter++]; | |
res += shift < 28 ? (b & REST$17) << shift : (b & REST$17) * Math.pow(2, shift); | |
shift += 7; | |
} while (b >= MSB$17); | |
read8.bytes = counter - offset; | |
return res; | |
} | |
var encode_17, MSB8, REST8, MSBALL7, INT7, decode36, MSB$17, REST$17, N18, N28, N38, N48, N58, N68, N78, N88, N98, length8, varint12, _brrp_varint7, varint_default7; | |
var init_varint = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/vendor/varint.js"() { | |
encode_17 = encode31; | |
MSB8 = 128; | |
REST8 = 127; | |
MSBALL7 = ~REST8; | |
INT7 = Math.pow(2, 31); | |
decode36 = read8; | |
MSB$17 = 128; | |
REST$17 = 127; | |
N18 = Math.pow(2, 7); | |
N28 = Math.pow(2, 14); | |
N38 = Math.pow(2, 21); | |
N48 = Math.pow(2, 28); | |
N58 = Math.pow(2, 35); | |
N68 = Math.pow(2, 42); | |
N78 = Math.pow(2, 49); | |
N88 = Math.pow(2, 56); | |
N98 = Math.pow(2, 63); | |
length8 = function(value) { | |
return value < N18 ? 1 : value < N28 ? 2 : value < N38 ? 3 : value < N48 ? 4 : value < N58 ? 5 : value < N68 ? 6 : value < N78 ? 7 : value < N88 ? 8 : value < N98 ? 9 : 10; | |
}; | |
varint12 = { | |
encode: encode_17, | |
decode: decode36, | |
encodingLength: length8 | |
}; | |
_brrp_varint7 = varint12; | |
varint_default7 = _brrp_varint7; | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/src/varint.js | |
var decode37, encodeTo7, encodingLength7; | |
var init_varint2 = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/src/varint.js"() { | |
init_varint(); | |
decode37 = (data, offset = 0) => { | |
const code9 = varint_default7.decode(data, offset); | |
return [ | |
code9, | |
varint_default7.decode.bytes | |
]; | |
}; | |
encodeTo7 = (int, target, offset = 0) => { | |
varint_default7.encode(int, target, offset); | |
return target; | |
}; | |
encodingLength7 = (int) => { | |
return varint_default7.encodingLength(int); | |
}; | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/src/hashes/digest.js | |
var create9, decode38, equals15, Digest7; | |
var init_digest = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/src/hashes/digest.js"() { | |
init_bytes(); | |
init_varint2(); | |
create9 = (code9, digest5) => { | |
const size = digest5.byteLength; | |
const sizeOffset = encodingLength7(code9); | |
const digestOffset = sizeOffset + encodingLength7(size); | |
const bytes3 = new Uint8Array(digestOffset + size); | |
encodeTo7(code9, bytes3, 0); | |
encodeTo7(size, bytes3, sizeOffset); | |
bytes3.set(digest5, digestOffset); | |
return new Digest7(code9, size, digest5, bytes3); | |
}; | |
decode38 = (multihash) => { | |
const bytes3 = coerce8(multihash); | |
const [code9, sizeOffset] = decode37(bytes3); | |
const [size, digestOffset] = decode37(bytes3.subarray(sizeOffset)); | |
const digest5 = bytes3.subarray(sizeOffset + digestOffset); | |
if (digest5.byteLength !== size) { | |
throw new Error("Incorrect length"); | |
} | |
return new Digest7(code9, size, digest5, bytes3); | |
}; | |
equals15 = (a, b) => { | |
if (a === b) { | |
return true; | |
} else { | |
return a.code === b.code && a.size === b.size && equals14(a.bytes, b.bytes); | |
} | |
}; | |
Digest7 = class { | |
constructor(code9, size, digest5, bytes3) { | |
this.code = code9; | |
this.size = size; | |
this.digest = digest5; | |
this.bytes = bytes3; | |
} | |
}; | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/src/hashes/hasher.js | |
var from13, Hasher5; | |
var init_hasher = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/src/hashes/hasher.js"() { | |
init_digest(); | |
from13 = ({ name: name8, code: code9, encode: encode39 }) => new Hasher5(name8, code9, encode39); | |
Hasher5 = class { | |
constructor(name8, code9, encode39) { | |
this.name = name8; | |
this.code = code9; | |
this.encode = encode39; | |
} | |
digest(input) { | |
if (input instanceof Uint8Array) { | |
const result = this.encode(input); | |
return result instanceof Uint8Array ? create9(this.code, result) : result.then((digest5) => create9(this.code, digest5)); | |
} else { | |
throw Error("Unknown type, must be binary type"); | |
} | |
} | |
}; | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/src/hashes/sha2-browser.js | |
var sha2_browser_exports4 = {}; | |
__export(sha2_browser_exports4, { | |
sha256: () => sha2566, | |
sha512: () => sha5126 | |
}); | |
var sha5, sha2566, sha5126; | |
var init_sha2_browser = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/src/hashes/sha2-browser.js"() { | |
init_hasher(); | |
sha5 = (name8) => async (data) => new Uint8Array(await crypto.subtle.digest(name8, data)); | |
sha2566 = from13({ | |
name: "sha2-256", | |
code: 18, | |
encode: sha5("SHA-256") | |
}); | |
sha5126 = from13({ | |
name: "sha2-512", | |
code: 19, | |
encode: sha5("SHA-512") | |
}); | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/src/hashes/identity.js | |
var identity_exports8 = {}; | |
__export(identity_exports8, { | |
identity: () => identity8 | |
}); | |
var code7, name6, encode32, digest4, identity8; | |
var init_identity2 = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/src/hashes/identity.js"() { | |
init_bytes(); | |
init_digest(); | |
code7 = 0; | |
name6 = "identity"; | |
encode32 = coerce8; | |
digest4 = (input) => create9(code7, encode32(input)); | |
identity8 = { | |
code: code7, | |
name: name6, | |
encode: encode32, | |
digest: digest4 | |
}; | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/src/codecs/raw.js | |
var init_raw = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/src/codecs/raw.js"() { | |
init_bytes(); | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/src/codecs/json.js | |
var textEncoder7, textDecoder6; | |
var init_json = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/src/codecs/json.js"() { | |
textEncoder7 = new TextEncoder(); | |
textDecoder6 = new TextDecoder(); | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/src/cid.js | |
var CID7, parseCIDtoBytes7, toStringV07, toStringV17, DAG_PB_CODE7, SHA_256_CODE7, encodeCID7, cidSymbol7, readonly, hidden, version, deprecate, IS_CID_DEPRECATION; | |
var init_cid = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/src/cid.js"() { | |
init_varint2(); | |
init_digest(); | |
init_base58(); | |
init_base32(); | |
init_bytes(); | |
CID7 = class _CID { | |
constructor(version4, code9, multihash, bytes3) { | |
this.code = code9; | |
this.version = version4; | |
this.multihash = multihash; | |
this.bytes = bytes3; | |
this.byteOffset = bytes3.byteOffset; | |
this.byteLength = bytes3.byteLength; | |
this.asCID = this; | |
this._baseCache = /* @__PURE__ */ new Map(); | |
Object.defineProperties(this, { | |
byteOffset: hidden, | |
byteLength: hidden, | |
code: readonly, | |
version: readonly, | |
multihash: readonly, | |
bytes: readonly, | |
_baseCache: hidden, | |
asCID: hidden | |
}); | |
} | |
toV0() { | |
switch (this.version) { | |
case 0: { | |
return this; | |
} | |
default: { | |
const { code: code9, multihash } = this; | |
if (code9 !== DAG_PB_CODE7) { | |
throw new Error("Cannot convert a non dag-pb CID to CIDv0"); | |
} | |
if (multihash.code !== SHA_256_CODE7) { | |
throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0"); | |
} | |
return _CID.createV0(multihash); | |
} | |
} | |
} | |
toV1() { | |
switch (this.version) { | |
case 0: { | |
const { code: code9, digest: digest5 } = this.multihash; | |
const multihash = create9(code9, digest5); | |
return _CID.createV1(this.code, multihash); | |
} | |
case 1: { | |
return this; | |
} | |
default: { | |
throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`); | |
} | |
} | |
} | |
equals(other) { | |
return other && this.code === other.code && this.version === other.version && equals15(this.multihash, other.multihash); | |
} | |
toString(base14) { | |
const { bytes: bytes3, version: version4, _baseCache } = this; | |
switch (version4) { | |
case 0: | |
return toStringV07(bytes3, _baseCache, base14 || base58btc8.encoder); | |
default: | |
return toStringV17(bytes3, _baseCache, base14 || base328.encoder); | |
} | |
} | |
toJSON() { | |
return { | |
code: this.code, | |
version: this.version, | |
hash: this.multihash.bytes | |
}; | |
} | |
get [Symbol.toStringTag]() { | |
return "CID"; | |
} | |
[Symbol.for("nodejs.util.inspect.custom")]() { | |
return "CID(" + this.toString() + ")"; | |
} | |
static isCID(value) { | |
deprecate(/^0\.0/, IS_CID_DEPRECATION); | |
return !!(value && (value[cidSymbol7] || value.asCID === value)); | |
} | |
get toBaseEncodedString() { | |
throw new Error("Deprecated, use .toString()"); | |
} | |
get codec() { | |
throw new Error('"codec" property is deprecated, use integer "code" property instead'); | |
} | |
get buffer() { | |
throw new Error("Deprecated .buffer property, use .bytes to get Uint8Array instead"); | |
} | |
get multibaseName() { | |
throw new Error('"multibaseName" property is deprecated'); | |
} | |
get prefix() { | |
throw new Error('"prefix" property is deprecated'); | |
} | |
static asCID(value) { | |
if (value instanceof _CID) { | |
return value; | |
} else if (value != null && value.asCID === value) { | |
const { version: version4, code: code9, multihash, bytes: bytes3 } = value; | |
return new _CID(version4, code9, multihash, bytes3 || encodeCID7(version4, code9, multihash.bytes)); | |
} else if (value != null && value[cidSymbol7] === true) { | |
const { version: version4, multihash, code: code9 } = value; | |
const digest5 = decode38(multihash); | |
return _CID.create(version4, code9, digest5); | |
} else { | |
return null; | |
} | |
} | |
static create(version4, code9, digest5) { | |
if (typeof code9 !== "number") { | |
throw new Error("String codecs are no longer supported"); | |
} | |
switch (version4) { | |
case 0: { | |
if (code9 !== DAG_PB_CODE7) { | |
throw new Error(`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE7}) block encoding`); | |
} else { | |
return new _CID(version4, code9, digest5, digest5.bytes); | |
} | |
} | |
case 1: { | |
const bytes3 = encodeCID7(version4, code9, digest5.bytes); | |
return new _CID(version4, code9, digest5, bytes3); | |
} | |
default: { | |
throw new Error("Invalid version"); | |
} | |
} | |
} | |
static createV0(digest5) { | |
return _CID.create(0, DAG_PB_CODE7, digest5); | |
} | |
static createV1(code9, digest5) { | |
return _CID.create(1, code9, digest5); | |
} | |
static decode(bytes3) { | |
const [cid, remainder] = _CID.decodeFirst(bytes3); | |
if (remainder.length) { | |
throw new Error("Incorrect length"); | |
} | |
return cid; | |
} | |
static decodeFirst(bytes3) { | |
const specs = _CID.inspectBytes(bytes3); | |
const prefixSize = specs.size - specs.multihashSize; | |
const multihashBytes = coerce8(bytes3.subarray(prefixSize, prefixSize + specs.multihashSize)); | |
if (multihashBytes.byteLength !== specs.multihashSize) { | |
throw new Error("Incorrect length"); | |
} | |
const digestBytes = multihashBytes.subarray(specs.multihashSize - specs.digestSize); | |
const digest5 = new Digest7(specs.multihashCode, specs.digestSize, digestBytes, multihashBytes); | |
const cid = specs.version === 0 ? _CID.createV0(digest5) : _CID.createV1(specs.codec, digest5); | |
return [ | |
cid, | |
bytes3.subarray(specs.size) | |
]; | |
} | |
static inspectBytes(initialBytes) { | |
let offset = 0; | |
const next = () => { | |
const [i, length11] = decode37(initialBytes.subarray(offset)); | |
offset += length11; | |
return i; | |
}; | |
let version4 = next(); | |
let codec = DAG_PB_CODE7; | |
if (version4 === 18) { | |
version4 = 0; | |
offset = 0; | |
} else if (version4 === 1) { | |
codec = next(); | |
} | |
if (version4 !== 0 && version4 !== 1) { | |
throw new RangeError(`Invalid CID version ${version4}`); | |
} | |
const prefixSize = offset; | |
const multihashCode = next(); | |
const digestSize = next(); | |
const size = offset + digestSize; | |
const multihashSize = size - prefixSize; | |
return { | |
version: version4, | |
codec, | |
multihashCode, | |
digestSize, | |
multihashSize, | |
size | |
}; | |
} | |
static parse(source, base14) { | |
const [prefix, bytes3] = parseCIDtoBytes7(source, base14); | |
const cid = _CID.decode(bytes3); | |
cid._baseCache.set(prefix, source); | |
return cid; | |
} | |
}; | |
parseCIDtoBytes7 = (source, base14) => { | |
switch (source[0]) { | |
case "Q": { | |
const decoder = base14 || base58btc8; | |
return [ | |
base58btc8.prefix, | |
decoder.decode(`${base58btc8.prefix}${source}`) | |
]; | |
} | |
case base58btc8.prefix: { | |
const decoder = base14 || base58btc8; | |
return [ | |
base58btc8.prefix, | |
decoder.decode(source) | |
]; | |
} | |
case base328.prefix: { | |
const decoder = base14 || base328; | |
return [ | |
base328.prefix, | |
decoder.decode(source) | |
]; | |
} | |
default: { | |
if (base14 == null) { | |
throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided"); | |
} | |
return [ | |
source[0], | |
base14.decode(source) | |
]; | |
} | |
} | |
}; | |
toStringV07 = (bytes3, cache10, base14) => { | |
const { prefix } = base14; | |
if (prefix !== base58btc8.prefix) { | |
throw Error(`Cannot string encode V0 in ${base14.name} encoding`); | |
} | |
const cid = cache10.get(prefix); | |
if (cid == null) { | |
const cid2 = base14.encode(bytes3).slice(1); | |
cache10.set(prefix, cid2); | |
return cid2; | |
} else { | |
return cid; | |
} | |
}; | |
toStringV17 = (bytes3, cache10, base14) => { | |
const { prefix } = base14; | |
const cid = cache10.get(prefix); | |
if (cid == null) { | |
const cid2 = base14.encode(bytes3); | |
cache10.set(prefix, cid2); | |
return cid2; | |
} else { | |
return cid; | |
} | |
}; | |
DAG_PB_CODE7 = 112; | |
SHA_256_CODE7 = 18; | |
encodeCID7 = (version4, code9, multihash) => { | |
const codeOffset = encodingLength7(version4); | |
const hashOffset = codeOffset + encodingLength7(code9); | |
const bytes3 = new Uint8Array(hashOffset + multihash.byteLength); | |
encodeTo7(version4, bytes3, 0); | |
encodeTo7(code9, bytes3, codeOffset); | |
bytes3.set(multihash, hashOffset); | |
return bytes3; | |
}; | |
cidSymbol7 = Symbol.for("@ipld/js-cid/CID"); | |
readonly = { | |
writable: false, | |
configurable: false, | |
enumerable: true | |
}; | |
hidden = { | |
writable: false, | |
enumerable: false, | |
configurable: false | |
}; | |
version = "0.0.0-dev"; | |
deprecate = (range, message2) => { | |
if (range.test(version)) { | |
console.warn(message2); | |
} else { | |
throw new Error(message2); | |
} | |
}; | |
IS_CID_DEPRECATION = `CID.isCID(v) is deprecated and will be removed in the next major release. | |
Following code pattern: | |
if (CID.isCID(value)) { | |
doSomethingWithCID(value) | |
} | |
Is replaced with: | |
const cid = CID.asCID(value) | |
if (cid) { | |
// Make sure to use cid instead of value | |
doSomethingWithCID(cid) | |
} | |
`; | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/src/index.js | |
var init_src = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/src/index.js"() { | |
init_cid(); | |
init_varint2(); | |
init_bytes(); | |
init_hasher(); | |
init_digest(); | |
} | |
}); | |
// node_modules/multihashes/node_modules/multiformats/esm/src/basics.js | |
var bases4, hashes4; | |
var init_basics = __esm({ | |
"node_modules/multihashes/node_modules/multiformats/esm/src/basics.js"() { | |
init_identity(); | |
init_base2(); | |
init_base8(); | |
init_base10(); | |
init_base16(); | |
init_base32(); | |
init_base36(); | |
init_base58(); | |
init_base64(); | |
init_base256emoji(); | |
init_sha2_browser(); | |
init_identity2(); | |
init_raw(); | |
init_json(); | |
init_src(); | |
bases4 = { | |
...identity_exports7, | |
...base2_exports4, | |
...base8_exports4, | |
...base10_exports4, | |
...base16_exports4, | |
...base32_exports4, | |
...base36_exports4, | |
...base58_exports4, | |
...base64_exports4, | |
...base256emoji_exports4 | |
}; | |
hashes4 = { | |
...sha2_browser_exports4, | |
...identity_exports8 | |
}; | |
} | |
}); | |
// node_modules/multihashes/node_modules/uint8arrays/esm/src/util/as-uint8array.js | |
function asUint8Array2(buf3) { | |
if (globalThis.Buffer != null) { | |
return new Uint8Array(buf3.buffer, buf3.byteOffset, buf3.byteLength); | |
} | |
return buf3; | |
} | |
var init_as_uint8array = __esm({ | |
"node_modules/multihashes/node_modules/uint8arrays/esm/src/util/as-uint8array.js"() { | |
} | |
}); | |
// node_modules/multihashes/node_modules/uint8arrays/esm/src/alloc.js | |
function allocUnsafe4(size = 0) { | |
if (globalThis.Buffer != null && globalThis.Buffer.allocUnsafe != null) { | |
return asUint8Array2(globalThis.Buffer.allocUnsafe(size)); | |
} | |
return new Uint8Array(size); | |
} | |
var init_alloc = __esm({ | |
"node_modules/multihashes/node_modules/uint8arrays/esm/src/alloc.js"() { | |
init_as_uint8array(); | |
} | |
}); | |
// node_modules/multihashes/node_modules/uint8arrays/esm/src/util/bases.js | |
function createCodec3(name8, prefix, encode39, decode50) { | |
return { | |
name: name8, | |
prefix, | |
encoder: { | |
name: name8, | |
prefix, | |
encode: encode39 | |
}, | |
decoder: { decode: decode50 } | |
}; | |
} | |
var string2, ascii2, BASES2, bases_default2; | |
var init_bases = __esm({ | |
"node_modules/multihashes/node_modules/uint8arrays/esm/src/util/bases.js"() { | |
init_basics(); | |
init_alloc(); | |
string2 = createCodec3("utf8", "u", (buf3) => { | |
const decoder = new TextDecoder("utf8"); | |
return "u" + decoder.decode(buf3); | |
}, (str) => { | |
const encoder2 = new TextEncoder(); | |
return encoder2.encode(str.substring(1)); | |
}); | |
ascii2 = createCodec3("ascii", "a", (buf3) => { | |
let string3 = "a"; | |
for (let i = 0; i < buf3.length; i++) { | |
string3 += String.fromCharCode(buf3[i]); | |
} | |
return string3; | |
}, (str) => { | |
str = str.substring(1); | |
const buf3 = allocUnsafe4(str.length); | |
for (let i = 0; i < str.length; i++) { | |
buf3[i] = str.charCodeAt(i); | |
} | |
return buf3; | |
}); | |
BASES2 = { | |
utf8: string2, | |
"utf-8": string2, | |
hex: bases4.base16, | |
latin1: ascii2, | |
ascii: ascii2, | |
binary: ascii2, | |
...bases4 | |
}; | |
bases_default2 = BASES2; | |
} | |
}); | |
// node_modules/multihashes/node_modules/uint8arrays/esm/src/to-string.js | |
var to_string_exports = {}; | |
__export(to_string_exports, { | |
toString: () => toString8 | |
}); | |
function toString8(array, encoding = "utf8") { | |
const base14 = bases_default2[encoding]; | |
if (!base14) { | |
throw new Error(`Unsupported encoding "${encoding}"`); | |
} | |
if ((encoding === "utf8" || encoding === "utf-8") && globalThis.Buffer != null && globalThis.Buffer.from != null) { | |
return globalThis.Buffer.from(array.buffer, array.byteOffset, array.byteLength).toString("utf8"); | |
} | |
return base14.encoder.encode(array).substring(1); | |
} | |
var init_to_string = __esm({ | |
"node_modules/multihashes/node_modules/uint8arrays/esm/src/to-string.js"() { | |
init_bases(); | |
} | |
}); | |
// node_modules/multihashes/node_modules/uint8arrays/esm/src/from-string.js | |
var from_string_exports = {}; | |
__export(from_string_exports, { | |
fromString: () => fromString7 | |
}); | |
function fromString7(string3, encoding = "utf8") { | |
const base14 = bases_default2[encoding]; | |
if (!base14) { | |
throw new Error(`Unsupported encoding "${encoding}"`); | |
} | |
if ((encoding === "utf8" || encoding === "utf-8") && globalThis.Buffer != null && globalThis.Buffer.from != null) { | |
return asUint8Array2(globalThis.Buffer.from(string3, "utf-8")); | |
} | |
return base14.decoder.decode(`${base14.prefix}${string3}`); | |
} | |
var init_from_string = __esm({ | |
"node_modules/multihashes/node_modules/uint8arrays/esm/src/from-string.js"() { | |
init_bases(); | |
init_as_uint8array(); | |
} | |
}); | |
// node_modules/multihashes/node_modules/uint8arrays/esm/src/concat.js | |
var concat_exports = {}; | |
__export(concat_exports, { | |
concat: () => concat3 | |
}); | |
function concat3(arrays, length11) { | |
if (!length11) { | |
length11 = arrays.reduce((acc, curr) => acc + curr.length, 0); | |
} | |
const output3 = allocUnsafe4(length11); | |
let offset = 0; | |
for (const arr of arrays) { | |
output3.set(arr, offset); | |
offset += arr.length; | |
} | |
return asUint8Array2(output3); | |
} | |
var init_concat = __esm({ | |
"node_modules/multihashes/node_modules/uint8arrays/esm/src/concat.js"() { | |
init_alloc(); | |
init_as_uint8array(); | |
} | |
}); | |
// node_modules/multihashes/src/index.js | |
var require_src4 = __commonJS({ | |
"node_modules/multihashes/src/index.js"(exports2, module2) { | |
"use strict"; | |
var multibase = require_src3(); | |
var varint15 = require_varint3(); | |
var { names: names3 } = require_constants2(); | |
var { toString: uint8ArrayToString } = (init_to_string(), __toCommonJS(to_string_exports)); | |
var { fromString: uint8ArrayFromString } = (init_from_string(), __toCommonJS(from_string_exports)); | |
var { concat: uint8ArrayConcat } = (init_concat(), __toCommonJS(concat_exports)); | |
var codes8 = ( | |
/** @type {import('./types').CodeNameMap} */ | |
{} | |
); | |
for (const key in names3) { | |
const name8 = ( | |
/** @type {HashName} */ | |
key | |
); | |
codes8[names3[name8]] = name8; | |
} | |
Object.freeze(codes8); | |
function toHexString(hash3) { | |
if (!(hash3 instanceof Uint8Array)) { | |
throw new Error("must be passed a Uint8Array"); | |
} | |
return uint8ArrayToString(hash3, "base16"); | |
} | |
function fromHexString(hash3) { | |
return uint8ArrayFromString(hash3, "base16"); | |
} | |
function toB58String(hash3) { | |
if (!(hash3 instanceof Uint8Array)) { | |
throw new Error("must be passed a Uint8Array"); | |
} | |
return uint8ArrayToString(multibase.encode("base58btc", hash3)).slice(1); | |
} | |
function fromB58String(hash3) { | |
const encoded = hash3 instanceof Uint8Array ? uint8ArrayToString(hash3) : hash3; | |
return multibase.decode("z" + encoded); | |
} | |
function decode50(bytes3) { | |
if (!(bytes3 instanceof Uint8Array)) { | |
throw new Error("multihash must be a Uint8Array"); | |
} | |
if (bytes3.length < 2) { | |
throw new Error("multihash too short. must be > 2 bytes."); | |
} | |
const code9 = ( | |
/** @type {HashCode} */ | |
varint15.decode(bytes3) | |
); | |
if (!isValidCode(code9)) { | |
throw new Error(`multihash unknown function code: 0x${code9.toString(16)}`); | |
} | |
bytes3 = bytes3.slice(varint15.decode.bytes); | |
const len = varint15.decode(bytes3); | |
if (len < 0) { | |
throw new Error(`multihash invalid length: ${len}`); | |
} | |
bytes3 = bytes3.slice(varint15.decode.bytes); | |
if (bytes3.length !== len) { | |
throw new Error(`multihash length inconsistent: 0x${uint8ArrayToString(bytes3, "base16")}`); | |
} | |
return { | |
code: code9, | |
name: codes8[code9], | |
length: len, | |
digest: bytes3 | |
}; | |
} | |
function encode39(digest5, code9, length11) { | |
if (!digest5 || code9 === void 0) { | |
throw new Error("multihash encode requires at least two args: digest, code"); | |
} | |
const hashfn = coerceCode(code9); | |
if (!(digest5 instanceof Uint8Array)) { | |
throw new Error("digest should be a Uint8Array"); | |
} | |
if (length11 == null) { | |
length11 = digest5.length; | |
} | |
if (length11 && digest5.length !== length11) { | |
throw new Error("digest length should be equal to specified length."); | |
} | |
const hash3 = varint15.encode(hashfn); | |
const len = varint15.encode(length11); | |
return uint8ArrayConcat([hash3, len, digest5], hash3.length + len.length + digest5.length); | |
} | |
function coerceCode(name8) { | |
let code9 = name8; | |
if (typeof name8 === "string") { | |
if (names3[name8] === void 0) { | |
throw new Error(`Unrecognized hash function named: ${name8}`); | |
} | |
code9 = names3[name8]; | |
} | |
if (typeof code9 !== "number") { | |
throw new Error(`Hash function code should be a number. Got: ${code9}`); | |
} | |
if (codes8[code9] === void 0 && !isAppCode(code9)) { | |
throw new Error(`Unrecognized function code: ${code9}`); | |
} | |
return code9; | |
} | |
function isAppCode(code9) { | |
return code9 > 0 && code9 < 16; | |
} | |
function isValidCode(code9) { | |
if (isAppCode(code9)) { | |
return true; | |
} | |
if (codes8[code9]) { | |
return true; | |
} | |
return false; | |
} | |
function validate3(multihash) { | |
decode50(multihash); | |
} | |
function prefix(multihash) { | |
validate3(multihash); | |
return multihash.subarray(0, 2); | |
} | |
module2.exports = { | |
names: names3, | |
codes: codes8, | |
toHexString, | |
fromHexString, | |
toB58String, | |
fromB58String, | |
decode: decode50, | |
encode: encode39, | |
coerceCode, | |
isAppCode, | |
validate: validate3, | |
prefix, | |
isValidCode | |
}; | |
} | |
}); | |
// node_modules/event-iterator/lib/event-iterator.js | |
var require_event_iterator = __commonJS({ | |
"node_modules/event-iterator/lib/event-iterator.js"(exports2) { | |
"use strict"; | |
Object.defineProperty(exports2, "__esModule", { value: true }); | |
var EventQueue = class { | |
constructor() { | |
this.pullQueue = []; | |
this.pushQueue = []; | |
this.eventHandlers = {}; | |
this.isPaused = false; | |
this.isStopped = false; | |
} | |
push(value) { | |
if (this.isStopped) | |
return; | |
const resolution = { value, done: false }; | |
if (this.pullQueue.length) { | |
const placeholder = this.pullQueue.shift(); | |
if (placeholder) | |
placeholder.resolve(resolution); | |
} else { | |
this.pushQueue.push(Promise.resolve(resolution)); | |
if (this.highWaterMark !== void 0 && this.pushQueue.length >= this.highWaterMark && !this.isPaused) { | |
this.isPaused = true; | |
if (this.eventHandlers.highWater) { | |
this.eventHandlers.highWater(); | |
} else if (console) { | |
console.warn(`EventIterator queue reached ${this.pushQueue.length} items`); | |
} | |
} | |
} | |
} | |
stop() { | |
if (this.isStopped) | |
return; | |
this.isStopped = true; | |
this.remove(); | |
for (const placeholder of this.pullQueue) { | |
placeholder.resolve({ value: void 0, done: true }); | |
} | |
this.pullQueue.length = 0; | |
} | |
fail(error) { | |
if (this.isStopped) | |
return; | |
this.isStopped = true; | |
this.remove(); | |
if (this.pullQueue.length) { | |
for (const placeholder of this.pullQueue) { | |
placeholder.reject(error); | |
} | |
this.pullQueue.length = 0; | |
} else { | |
const rejection = Promise.reject(error); | |
rejection.catch(() => { | |
}); | |
this.pushQueue.push(rejection); | |
} | |
} | |
remove() { | |
Promise.resolve().then(() => { | |
if (this.removeCallback) | |
this.removeCallback(); | |
}); | |
} | |
[Symbol.asyncIterator]() { | |
return { | |
next: (value) => { | |
const result = this.pushQueue.shift(); | |
if (result) { | |
if (this.lowWaterMark !== void 0 && this.pushQueue.length <= this.lowWaterMark && this.isPaused) { | |
this.isPaused = false; | |
if (this.eventHandlers.lowWater) { | |
this.eventHandlers.lowWater(); | |
} | |
} | |
return result; | |
} else if (this.isStopped) { | |
return Promise.resolve({ value: void 0, done: true }); | |
} else { | |
return new Promise((resolve6, reject) => { | |
this.pullQueue.push({ resolve: resolve6, reject }); | |
}); | |
} | |
}, | |
return: () => { | |
this.isStopped = true; | |
this.pushQueue.length = 0; | |
this.remove(); | |
return Promise.resolve({ value: void 0, done: true }); | |
} | |
}; | |
} | |
}; | |
var EventIterator2 = class { | |
constructor(listen, { highWaterMark = 100, lowWaterMark = 1 } = {}) { | |
const queue = new EventQueue(); | |
queue.highWaterMark = highWaterMark; | |
queue.lowWaterMark = lowWaterMark; | |
queue.removeCallback = listen({ | |
push: (value) => queue.push(value), | |
stop: () => queue.stop(), | |
fail: (error) => queue.fail(error), | |
on: (event, fn) => { | |
queue.eventHandlers[event] = fn; | |
} | |
}) || (() => { | |
}); | |
this[Symbol.asyncIterator] = () => queue[Symbol.asyncIterator](); | |
Object.freeze(this); | |
} | |
}; | |
exports2.EventIterator = EventIterator2; | |
exports2.default = EventIterator2; | |
} | |
}); | |
// node_modules/event-iterator/lib/dom.js | |
var require_dom = __commonJS({ | |
"node_modules/event-iterator/lib/dom.js"(exports2) { | |
"use strict"; | |
Object.defineProperty(exports2, "__esModule", { value: true }); | |
var event_iterator_1 = require_event_iterator(); | |
exports2.EventIterator = event_iterator_1.EventIterator; | |
function subscribe(event, options, evOptions) { | |
return new event_iterator_1.EventIterator(({ push }) => { | |
this.addEventListener(event, push, options); | |
return () => this.removeEventListener(event, push, options); | |
}, evOptions); | |
} | |
exports2.subscribe = subscribe; | |
exports2.default = event_iterator_1.EventIterator; | |
} | |
}); | |
// node_modules/iso-url/src/url-browser.js | |
var require_url_browser = __commonJS({ | |
"node_modules/iso-url/src/url-browser.js"(exports2, module2) { | |
"use strict"; | |
var isReactNative2 = typeof navigator !== "undefined" && navigator.product === "ReactNative"; | |
function getDefaultBase() { | |
if (isReactNative2) { | |
return "http://localhost"; | |
} | |
if (!self.location) { | |
return ""; | |
} | |
return self.location.protocol + "//" + self.location.host; | |
} | |
var URL2 = self.URL; | |
var defaultBase = getDefaultBase(); | |
var URLWithLegacySupport = class { | |
constructor(url = "", base14 = defaultBase) { | |
this.super = new URL2(url, base14); | |
this.path = this.pathname + this.search; | |
this.auth = this.username && this.password ? this.username + ":" + this.password : null; | |
this.query = this.search && this.search.startsWith("?") ? this.search.slice(1) : null; | |
} | |
get hash() { | |
return this.super.hash; | |
} | |
get host() { | |
return this.super.host; | |
} | |
get hostname() { | |
return this.super.hostname; | |
} | |
get href() { | |
return this.super.href; | |
} | |
get origin() { | |
return this.super.origin; | |
} | |
get password() { | |
return this.super.password; | |
} | |
get pathname() { | |
return this.super.pathname; | |
} | |
get port() { | |
return this.super.port; | |
} | |
get protocol() { | |
return this.super.protocol; | |
} | |
get search() { | |
return this.super.search; | |
} | |
get searchParams() { | |
return this.super.searchParams; | |
} | |
get username() { | |
return this.super.username; | |
} | |
set hash(hash3) { | |
this.super.hash = hash3; | |
} | |
set host(host) { | |
this.super.host = host; | |
} | |
set hostname(hostname) { | |
this.super.hostname = hostname; | |
} | |
set href(href) { | |
this.super.href = href; | |
} | |
set password(password) { | |
this.super.password = password; | |
} | |
set pathname(pathname) { | |
this.super.pathname = pathname; | |
} | |
set port(port) { | |
this.super.port = port; | |
} | |
set protocol(protocol) { | |
this.super.protocol = protocol; | |
} | |
set search(search) { | |
this.super.search = search; | |
} | |
set username(username) { | |
this.super.username = username; | |
} | |
/** | |
* @param {any} o | |
*/ | |
static createObjectURL(o) { | |
return URL2.createObjectURL(o); | |
} | |
/** | |
* @param {string} o | |
*/ | |
static revokeObjectURL(o) { | |
URL2.revokeObjectURL(o); | |
} | |
toJSON() { | |
return this.super.toJSON(); | |
} | |
toString() { | |
return this.super.toString(); | |
} | |
format() { | |
return this.toString(); | |
} | |
}; | |
function format9(obj) { | |
if (typeof obj === "string") { | |
const url = new URL2(obj); | |
return url.toString(); | |
} | |
if (!(obj instanceof URL2)) { | |
const userPass = ( | |
// @ts-ignore its not supported in node but we normalise | |
obj.username && obj.password ? `${obj.username}:${obj.password}@` : "" | |
); | |
const auth = obj.auth ? obj.auth + "@" : ""; | |
const port = obj.port ? ":" + obj.port : ""; | |
const protocol = obj.protocol ? obj.protocol + "//" : ""; | |
const host = obj.host || ""; | |
const hostname = obj.hostname || ""; | |
const search = obj.search || (obj.query ? "?" + obj.query : ""); | |
const hash3 = obj.hash || ""; | |
const pathname = obj.pathname || ""; | |
const path = obj.path || pathname + search; | |
return `${protocol}${userPass || auth}${host || hostname + port}${path}${hash3}`; | |
} | |
} | |
module2.exports = { | |
URLWithLegacySupport, | |
URLSearchParams: self.URLSearchParams, | |
defaultBase, | |
format: format9 | |
}; | |
} | |
}); | |
// node_modules/iso-url/src/relative.js | |
var require_relative = __commonJS({ | |
"node_modules/iso-url/src/relative.js"(exports2, module2) { | |
"use strict"; | |
var { URLWithLegacySupport, format: format9 } = require_url_browser(); | |
module2.exports = (url, location = {}, protocolMap = {}, defaultProtocol) => { | |
let protocol = location.protocol ? location.protocol.replace(":", "") : "http"; | |
protocol = (protocolMap[protocol] || defaultProtocol || protocol) + ":"; | |
let urlParsed; | |
try { | |
urlParsed = new URLWithLegacySupport(url); | |
} catch (err) { | |
urlParsed = {}; | |
} | |
const base14 = Object.assign({}, location, { | |
protocol: protocol || urlParsed.protocol, | |
host: location.host || urlParsed.host | |
}); | |
return new URLWithLegacySupport(url, format9(base14)).toString(); | |
}; | |
} | |
}); | |
// node_modules/iso-url/index.js | |
var require_iso_url = __commonJS({ | |
"node_modules/iso-url/index.js"(exports2, module2) { | |
"use strict"; | |
var { | |
URLWithLegacySupport, | |
format: format9, | |
URLSearchParams, | |
defaultBase | |
} = require_url_browser(); | |
var relative2 = require_relative(); | |
module2.exports = { | |
URL: URLWithLegacySupport, | |
URLSearchParams, | |
format: format9, | |
relative: relative2, | |
defaultBase | |
}; | |
} | |
}); | |
// node_modules/is-electron/index.js | |
var require_is_electron = __commonJS({ | |
"node_modules/is-electron/index.js"(exports2, module2) { | |
function isElectron2() { | |
if (typeof window !== "undefined" && typeof window.process === "object" && window.process.type === "renderer") { | |
return true; | |
} | |
if (typeof process !== "undefined" && typeof process.versions === "object" && !!process.versions.electron) { | |
return true; | |
} | |
if (typeof navigator === "object" && typeof navigator.userAgent === "string" && navigator.userAgent.indexOf("Electron") >= 0) { | |
return true; | |
} | |
return false; | |
} | |
module2.exports = isElectron2; | |
} | |
}); | |
// node_modules/retry/lib/retry_operation.js | |
var require_retry_operation = __commonJS({ | |
"node_modules/retry/lib/retry_operation.js"(exports2, module2) { | |
function RetryOperation(timeouts, options) { | |
if (typeof options === "boolean") { | |
options = { forever: options }; | |
} | |
this._originalTimeouts = JSON.parse(JSON.stringify(timeouts)); | |
this._timeouts = timeouts; | |
this._options = options || {}; | |
this._maxRetryTime = options && options.maxRetryTime || Infinity; | |
this._fn = null; | |
this._errors = []; | |
this._attempts = 1; | |
this._operationTimeout = null; | |
this._operationTimeoutCb = null; | |
this._timeout = null; | |
this._operationStart = null; | |
this._timer = null; | |
if (this._options.forever) { | |
this._cachedTimeouts = this._timeouts.slice(0); | |
} | |
} | |
module2.exports = RetryOperation; | |
RetryOperation.prototype.reset = function() { | |
this._attempts = 1; | |
this._timeouts = this._originalTimeouts.slice(0); | |
}; | |
RetryOperation.prototype.stop = function() { | |
if (this._timeout) { | |
clearTimeout(this._timeout); | |
} | |
if (this._timer) { | |
clearTimeout(this._timer); | |
} | |
this._timeouts = []; | |
this._cachedTimeouts = null; | |
}; | |
RetryOperation.prototype.retry = function(err) { | |
if (this._timeout) { | |
clearTimeout(this._timeout); | |
} | |
if (!err) { | |
return false; | |
} | |
var currentTime = (/* @__PURE__ */ new Date()).getTime(); | |
if (err && currentTime - this._operationStart >= this._maxRetryTime) { | |
this._errors.push(err); | |
this._errors.unshift(new Error("RetryOperation timeout occurred")); | |
return false; | |
} | |
this._errors.push(err); | |
var timeout = this._timeouts.shift(); | |
if (timeout === void 0) { | |
if (this._cachedTimeouts) { | |
this._errors.splice(0, this._errors.length - 1); | |
timeout = this._cachedTimeouts.slice(-1); | |
} else { | |
return false; | |
} | |
} | |
var self2 = this; | |
this._timer = setTimeout(function() { | |
self2._attempts++; | |
if (self2._operationTimeoutCb) { | |
self2._timeout = setTimeout(function() { | |
self2._operationTimeoutCb(self2._attempts); | |
}, self2._operationTimeout); | |
if (self2._options.unref) { | |
self2._timeout.unref(); | |
} | |
} | |
self2._fn(self2._attempts); | |
}, timeout); | |
if (this._options.unref) { | |
this._timer.unref(); | |
} | |
return true; | |
}; | |
RetryOperation.prototype.attempt = function(fn, timeoutOps) { | |
this._fn = fn; | |
if (timeoutOps) { | |
if (timeoutOps.timeout) { | |
this._operationTimeout = timeoutOps.timeout; | |
} | |
if (timeoutOps.cb) { | |
this._operationTimeoutCb = timeoutOps.cb; | |
} | |
} | |
var self2 = this; | |
if (this._operationTimeoutCb) { | |
this._timeout = setTimeout(function() { | |
self2._operationTimeoutCb(); | |
}, self2._operationTimeout); | |
} | |
this._operationStart = (/* @__PURE__ */ new Date()).getTime(); | |
this._fn(this._attempts); | |
}; | |
RetryOperation.prototype.try = function(fn) { | |
console.log("Using RetryOperation.try() is deprecated"); | |
this.attempt(fn); | |
}; | |
RetryOperation.prototype.start = function(fn) { | |
console.log("Using RetryOperation.start() is deprecated"); | |
this.attempt(fn); | |
}; | |
RetryOperation.prototype.start = RetryOperation.prototype.try; | |
RetryOperation.prototype.errors = function() { | |
return this._errors; | |
}; | |
RetryOperation.prototype.attempts = function() { | |
return this._attempts; | |
}; | |
RetryOperation.prototype.mainError = function() { | |
if (this._errors.length === 0) { | |
return null; | |
} | |
var counts = {}; | |
var mainError = null; | |
var mainErrorCount = 0; | |
for (var i = 0; i < this._errors.length; i++) { | |
var error = this._errors[i]; | |
var message2 = error.message; | |
var count = (counts[message2] || 0) + 1; | |
counts[message2] = count; | |
if (count >= mainErrorCount) { | |
mainError = error; | |
mainErrorCount = count; | |
} | |
} | |
return mainError; | |
}; | |
} | |
}); | |
// node_modules/retry/lib/retry.js | |
var require_retry = __commonJS({ | |
"node_modules/retry/lib/retry.js"(exports2) { | |
var RetryOperation = require_retry_operation(); | |
exports2.operation = function(options) { | |
var timeouts = exports2.timeouts(options); | |
return new RetryOperation(timeouts, { | |
forever: options && (options.forever || options.retries === Infinity), | |
unref: options && options.unref, | |
maxRetryTime: options && options.maxRetryTime | |
}); | |
}; | |
exports2.timeouts = function(options) { | |
if (options instanceof Array) { | |
return [].concat(options); | |
} | |
var opts = { | |
retries: 10, | |
factor: 2, | |
minTimeout: 1 * 1e3, | |
maxTimeout: Infinity, | |
randomize: false | |
}; | |
for (var key in options) { | |
opts[key] = options[key]; | |
} | |
if (opts.minTimeout > opts.maxTimeout) { | |
throw new Error("minTimeout is greater than maxTimeout"); | |
} | |
var timeouts = []; | |
for (var i = 0; i < opts.retries; i++) { | |
timeouts.push(this.createTimeout(i, opts)); | |
} | |
if (options && options.forever && !timeouts.length) { | |
timeouts.push(this.createTimeout(i, opts)); | |
} | |
timeouts.sort(function(a, b) { | |
return a - b; | |
}); | |
return timeouts; | |
}; | |
exports2.createTimeout = function(attempt, opts) { | |
var random = opts.randomize ? Math.random() + 1 : 1; | |
var timeout = Math.round(random * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt)); | |
timeout = Math.min(timeout, opts.maxTimeout); | |
return timeout; | |
}; | |
exports2.wrap = function(obj, options, methods2) { | |
if (options instanceof Array) { | |
methods2 = options; | |
options = null; | |
} | |
if (!methods2) { | |
methods2 = []; | |
for (var key in obj) { | |
if (typeof obj[key] === "function") { | |
methods2.push(key); | |
} | |
} | |
} | |
for (var i = 0; i < methods2.length; i++) { | |
var method = methods2[i]; | |
var original = obj[method]; | |
obj[method] = function retryWrapper(original2) { | |
var op = exports2.operation(options); | |
var args = Array.prototype.slice.call(arguments, 1); | |
var callback = args.pop(); | |
args.push(function(err) { | |
if (op.retry(err)) { | |
return; | |
} | |
if (err) { | |
arguments[0] = op.mainError(); | |
} | |
callback.apply(this, arguments); | |
}); | |
op.attempt(function() { | |
original2.apply(obj, args); | |
}); | |
}.bind(obj, original); | |
obj[method].options = options; | |
} | |
}; | |
} | |
}); | |
// node_modules/retry/index.js | |
var require_retry2 = __commonJS({ | |
"node_modules/retry/index.js"(exports2, module2) { | |
module2.exports = require_retry(); | |
} | |
}); | |
// node_modules/murmurhash3js-revisited/lib/murmurHash3js.js | |
var require_murmurHash3js = __commonJS({ | |
"node_modules/murmurhash3js-revisited/lib/murmurHash3js.js"(exports2, module2) { | |
(function(root, undefined2) { | |
"use strict"; | |
var library = { | |
"version": "3.0.0", | |
"x86": {}, | |
"x64": {}, | |
"inputValidation": true | |
}; | |
function _validBytes(bytes3) { | |
if (!Array.isArray(bytes3) && !ArrayBuffer.isView(bytes3)) { | |
return false; | |
} | |
for (var i = 0; i < bytes3.length; i++) { | |
if (!Number.isInteger(bytes3[i]) || bytes3[i] < 0 || bytes3[i] > 255) { | |
return false; | |
} | |
} | |
return true; | |
} | |
function _x86Multiply(m, n) { | |
return (m & 65535) * n + (((m >>> 16) * n & 65535) << 16); | |
} | |
function _x86Rotl(m, n) { | |
return m << n | m >>> 32 - n; | |
} | |
function _x86Fmix(h) { | |
h ^= h >>> 16; | |
h = _x86Multiply(h, 2246822507); | |
h ^= h >>> 13; | |
h = _x86Multiply(h, 3266489909); | |
h ^= h >>> 16; | |
return h; | |
} | |
function _x64Add(m, n) { | |
m = [m[0] >>> 16, m[0] & 65535, m[1] >>> 16, m[1] & 65535]; | |
n = [n[0] >>> 16, n[0] & 65535, n[1] >>> 16, n[1] & 65535]; | |
var o = [0, 0, 0, 0]; | |
o[3] += m[3] + n[3]; | |
o[2] += o[3] >>> 16; | |
o[3] &= 65535; | |
o[2] += m[2] + n[2]; | |
o[1] += o[2] >>> 16; | |
o[2] &= 65535; | |
o[1] += m[1] + n[1]; | |
o[0] += o[1] >>> 16; | |
o[1] &= 65535; | |
o[0] += m[0] + n[0]; | |
o[0] &= 65535; | |
return [o[0] << 16 | o[1], o[2] << 16 | o[3]]; | |
} | |
function _x64Multiply(m, n) { | |
m = [m[0] >>> 16, m[0] & 65535, m[1] >>> 16, m[1] & 65535]; | |
n = [n[0] >>> 16, n[0] & 65535, n[1] >>> 16, n[1] & 65535]; | |
var o = [0, 0, 0, 0]; | |
o[3] += m[3] * n[3]; | |
o[2] += o[3] >>> 16; | |
o[3] &= 65535; | |
o[2] += m[2] * n[3]; | |
o[1] += o[2] >>> 16; | |
o[2] &= 65535; | |
o[2] += m[3] * n[2]; | |
o[1] += o[2] >>> 16; | |
o[2] &= 65535; | |
o[1] += m[1] * n[3]; | |
o[0] += o[1] >>> 16; | |
o[1] &= 65535; | |
o[1] += m[2] * n[2]; | |
o[0] += o[1] >>> 16; | |
o[1] &= 65535; | |
o[1] += m[3] * n[1]; | |
o[0] += o[1] >>> 16; | |
o[1] &= 65535; | |
o[0] += m[0] * n[3] + m[1] * n[2] + m[2] * n[1] + m[3] * n[0]; | |
o[0] &= 65535; | |
return [o[0] << 16 | o[1], o[2] << 16 | o[3]]; | |
} | |
function _x64Rotl(m, n) { | |
n %= 64; | |
if (n === 32) { | |
return [m[1], m[0]]; | |
} else if (n < 32) { | |
return [m[0] << n | m[1] >>> 32 - n, m[1] << n | m[0] >>> 32 - n]; | |
} else { | |
n -= 32; | |
return [m[1] << n | m[0] >>> 32 - n, m[0] << n | m[1] >>> 32 - n]; | |
} | |
} | |
function _x64LeftShift(m, n) { | |
n %= 64; | |
if (n === 0) { | |
return m; | |
} else if (n < 32) { | |
return [m[0] << n | m[1] >>> 32 - n, m[1] << n]; | |
} else { | |
return [m[1] << n - 32, 0]; | |
} | |
} | |
function _x64Xor(m, n) { | |
return [m[0] ^ n[0], m[1] ^ n[1]]; | |
} | |
function _x64Fmix(h) { | |
h = _x64Xor(h, [0, h[0] >>> 1]); | |
h = _x64Multiply(h, [4283543511, 3981806797]); | |
h = _x64Xor(h, [0, h[0] >>> 1]); | |
h = _x64Multiply(h, [3301882366, 444984403]); | |
h = _x64Xor(h, [0, h[0] >>> 1]); | |
return h; | |
} | |
library.x86.hash32 = function(bytes3, seed) { | |
if (library.inputValidation && !_validBytes(bytes3)) { | |
return undefined2; | |
} | |
seed = seed || 0; | |
var remainder = bytes3.length % 4; | |
var blocks = bytes3.length - remainder; | |
var h1 = seed; | |
var k1 = 0; | |
var c1 = 3432918353; | |
var c2 = 461845907; | |
for (var i = 0; i < blocks; i = i + 4) { | |
k1 = bytes3[i] | bytes3[i + 1] << 8 | bytes3[i + 2] << 16 | bytes3[i + 3] << 24; | |
k1 = _x86Multiply(k1, c1); | |
k1 = _x86Rotl(k1, 15); | |
k1 = _x86Multiply(k1, c2); | |
h1 ^= k1; | |
h1 = _x86Rotl(h1, 13); | |
h1 = _x86Multiply(h1, 5) + 3864292196; | |
} | |
k1 = 0; | |
switch (remainder) { | |
case 3: | |
k1 ^= bytes3[i + 2] << 16; | |
case 2: | |
k1 ^= bytes3[i + 1] << 8; | |
case 1: | |
k1 ^= bytes3[i]; | |
k1 = _x86Multiply(k1, c1); | |
k1 = _x86Rotl(k1, 15); | |
k1 = _x86Multiply(k1, c2); | |
h1 ^= k1; | |
} | |
h1 ^= bytes3.length; | |
h1 = _x86Fmix(h1); | |
return h1 >>> 0; | |
}; | |
library.x86.hash128 = function(bytes3, seed) { | |
if (library.inputValidation && !_validBytes(bytes3)) { | |
return undefined2; | |
} | |
seed = seed || 0; | |
var remainder = bytes3.length % 16; | |
var blocks = bytes3.length - remainder; | |
var h1 = seed; | |
var h2 = seed; | |
var h3 = seed; | |
var h4 = seed; | |
var k1 = 0; | |
var k2 = 0; | |
var k3 = 0; | |
var k4 = 0; | |
var c1 = 597399067; | |
var c2 = 2869860233; | |
var c3 = 951274213; | |
var c4 = 2716044179; | |
for (var i = 0; i < blocks; i = i + 16) { | |
k1 = bytes3[i] | bytes3[i + 1] << 8 | bytes3[i + 2] << 16 | bytes3[i + 3] << 24; | |
k2 = bytes3[i + 4] | bytes3[i + 5] << 8 | bytes3[i + 6] << 16 | bytes3[i + 7] << 24; | |
k3 = bytes3[i + 8] | bytes3[i + 9] << 8 | bytes3[i + 10] << 16 | bytes3[i + 11] << 24; | |
k4 = bytes3[i + 12] | bytes3[i + 13] << 8 | bytes3[i + 14] << 16 | bytes3[i + 15] << 24; | |
k1 = _x86Multiply(k1, c1); | |
k1 = _x86Rotl(k1, 15); | |
k1 = _x86Multiply(k1, c2); | |
h1 ^= k1; | |
h1 = _x86Rotl(h1, 19); | |
h1 += h2; | |
h1 = _x86Multiply(h1, 5) + 1444728091; | |
k2 = _x86Multiply(k2, c2); | |
k2 = _x86Rotl(k2, 16); | |
k2 = _x86Multiply(k2, c3); | |
h2 ^= k2; | |
h2 = _x86Rotl(h2, 17); | |
h2 += h3; | |
h2 = _x86Multiply(h2, 5) + 197830471; | |
k3 = _x86Multiply(k3, c3); | |
k3 = _x86Rotl(k3, 17); | |
k3 = _x86Multiply(k3, c4); | |
h3 ^= k3; | |
h3 = _x86Rotl(h3, 15); | |
h3 += h4; | |
h3 = _x86Multiply(h3, 5) + 2530024501; | |
k4 = _x86Multiply(k4, c4); | |
k4 = _x86Rotl(k4, 18); | |
k4 = _x86Multiply(k4, c1); | |
h4 ^= k4; | |
h4 = _x86Rotl(h4, 13); | |
h4 += h1; | |
h4 = _x86Multiply(h4, 5) + 850148119; | |
} | |
k1 = 0; | |
k2 = 0; | |
k3 = 0; | |
k4 = 0; | |
switch (remainder) { | |
case 15: | |
k4 ^= bytes3[i + 14] << 16; | |
case 14: | |
k4 ^= bytes3[i + 13] << 8; | |
case 13: | |
k4 ^= bytes3[i + 12]; | |
k4 = _x86Multiply(k4, c4); | |
k4 = _x86Rotl(k4, 18); | |
k4 = _x86Multiply(k4, c1); | |
h4 ^= k4; | |
case 12: | |
k3 ^= bytes3[i + 11] << 24; | |
case 11: | |
k3 ^= bytes3[i + 10] << 16; | |
case 10: | |
k3 ^= bytes3[i + 9] << 8; | |
case 9: | |
k3 ^= bytes3[i + 8]; | |
k3 = _x86Multiply(k3, c3); | |
k3 = _x86Rotl(k3, 17); | |
k3 = _x86Multiply(k3, c4); | |
h3 ^= k3; | |
case 8: | |
k2 ^= bytes3[i + 7] << 24; | |
case 7: | |
k2 ^= bytes3[i + 6] << 16; | |
case 6: | |
k2 ^= bytes3[i + 5] << 8; | |
case 5: | |
k2 ^= bytes3[i + 4]; | |
k2 = _x86Multiply(k2, c2); | |
k2 = _x86Rotl(k2, 16); | |
k2 = _x86Multiply(k2, c3); | |
h2 ^= k2; | |
case 4: | |
k1 ^= bytes3[i + 3] << 24; | |
case 3: | |
k1 ^= bytes3[i + 2] << 16; | |
case 2: | |
k1 ^= bytes3[i + 1] << 8; | |
case 1: | |
k1 ^= bytes3[i]; | |
k1 = _x86Multiply(k1, c1); | |
k1 = _x86Rotl(k1, 15); | |
k1 = _x86Multiply(k1, c2); | |
h1 ^= k1; | |
} | |
h1 ^= bytes3.length; | |
h2 ^= bytes3.length; | |
h3 ^= bytes3.length; | |
h4 ^= bytes3.length; | |
h1 += h2; | |
h1 += h3; | |
h1 += h4; | |
h2 += h1; | |
h3 += h1; | |
h4 += h1; | |
h1 = _x86Fmix(h1); | |
h2 = _x86Fmix(h2); | |
h3 = _x86Fmix(h3); | |
h4 = _x86Fmix(h4); | |
h1 += h2; | |
h1 += h3; | |
h1 += h4; | |
h2 += h1; | |
h3 += h1; | |
h4 += h1; | |
return ("00000000" + (h1 >>> 0).toString(16)).slice(-8) + ("00000000" + (h2 >>> 0).toString(16)).slice(-8) + ("00000000" + (h3 >>> 0).toString(16)).slice(-8) + ("00000000" + (h4 >>> 0).toString(16)).slice(-8); | |
}; | |
library.x64.hash128 = function(bytes3, seed) { | |
if (library.inputValidation && !_validBytes(bytes3)) { | |
return undefined2; | |
} | |
seed = seed || 0; | |
var remainder = bytes3.length % 16; | |
var blocks = bytes3.length - remainder; | |
var h1 = [0, seed]; | |
var h2 = [0, seed]; | |
var k1 = [0, 0]; | |
var k2 = [0, 0]; | |
var c1 = [2277735313, 289559509]; | |
var c2 = [1291169091, 658871167]; | |
for (var i = 0; i < blocks; i = i + 16) { | |
k1 = [bytes3[i + 4] | bytes3[i + 5] << 8 | bytes3[i + 6] << 16 | bytes3[i + 7] << 24, bytes3[i] | bytes3[i + 1] << 8 | bytes3[i + 2] << 16 | bytes3[i + 3] << 24]; | |
k2 = [bytes3[i + 12] | bytes3[i + 13] << 8 | bytes3[i + 14] << 16 | bytes3[i + 15] << 24, bytes3[i + 8] | bytes3[i + 9] << 8 | bytes3[i + 10] << 16 | bytes3[i + 11] << 24]; | |
k1 = _x64Multiply(k1, c1); | |
k1 = _x64Rotl(k1, 31); | |
k1 = _x64Multiply(k1, c2); | |
h1 = _x64Xor(h1, k1); | |
h1 = _x64Rotl(h1, 27); | |
h1 = _x64Add(h1, h2); | |
h1 = _x64Add(_x64Multiply(h1, [0, 5]), [0, 1390208809]); | |
k2 = _x64Multiply(k2, c2); | |
k2 = _x64Rotl(k2, 33); | |
k2 = _x64Multiply(k2, c1); | |
h2 = _x64Xor(h2, k2); | |
h2 = _x64Rotl(h2, 31); | |
h2 = _x64Add(h2, h1); | |
h2 = _x64Add(_x64Multiply(h2, [0, 5]), [0, 944331445]); | |
} | |
k1 = [0, 0]; | |
k2 = [0, 0]; | |
switch (remainder) { | |
case 15: | |
k2 = _x64Xor(k2, _x64LeftShift([0, bytes3[i + 14]], 48)); | |
case 14: | |
k2 = _x64Xor(k2, _x64LeftShift([0, bytes3[i + 13]], 40)); | |
case 13: | |
k2 = _x64Xor(k2, _x64LeftShift([0, bytes3[i + 12]], 32)); | |
case 12: | |
k2 = _x64Xor(k2, _x64LeftShift([0, bytes3[i + 11]], 24)); | |
case 11: | |
k2 = _x64Xor(k2, _x64LeftShift([0, bytes3[i + 10]], 16)); | |
case 10: | |
k2 = _x64Xor(k2, _x64LeftShift([0, bytes3[i + 9]], 8)); | |
case 9: | |
k2 = _x64Xor(k2, [0, bytes3[i + 8]]); | |
k2 = _x64Multiply(k2, c2); | |
k2 = _x64Rotl(k2, 33); | |
k2 = _x64Multiply(k2, c1); | |
h2 = _x64Xor(h2, k2); | |
case 8: | |
k1 = _x64Xor(k1, _x64LeftShift([0, bytes3[i + 7]], 56)); | |
case 7: | |
k1 = _x64Xor(k1, _x64LeftShift([0, bytes3[i + 6]], 48)); | |
case 6: | |
k1 = _x64Xor(k1, _x64LeftShift([0, bytes3[i + 5]], 40)); | |
case 5: | |
k1 = _x64Xor(k1, _x64LeftShift([0, bytes3[i + 4]], 32)); | |
case 4: | |
k1 = _x64Xor(k1, _x64LeftShift([0, bytes3[i + 3]], 24)); | |
case 3: | |
k1 = _x64Xor(k1, _x64LeftShift([0, bytes3[i + 2]], 16)); | |
case 2: | |
k1 = _x64Xor(k1, _x64LeftShift([0, bytes3[i + 1]], 8)); | |
case 1: | |
k1 = _x64Xor(k1, [0, bytes3[i]]); | |
k1 = _x64Multiply(k1, c1); | |
k1 = _x64Rotl(k1, 31); | |
k1 = _x64Multiply(k1, c2); | |
h1 = _x64Xor(h1, k1); | |
} | |
h1 = _x64Xor(h1, [0, bytes3.length]); | |
h2 = _x64Xor(h2, [0, bytes3.length]); | |
h1 = _x64Add(h1, h2); | |
h2 = _x64Add(h2, h1); | |
h1 = _x64Fmix(h1); | |
h2 = _x64Fmix(h2); | |
h1 = _x64Add(h1, h2); | |
h2 = _x64Add(h2, h1); | |
return ("00000000" + (h1[0] >>> 0).toString(16)).slice(-8) + ("00000000" + (h1[1] >>> 0).toString(16)).slice(-8) + ("00000000" + (h2[0] >>> 0).toString(16)).slice(-8) + ("00000000" + (h2[1] >>> 0).toString(16)).slice(-8); | |
}; | |
if (typeof exports2 !== "undefined") { | |
if (typeof module2 !== "undefined" && module2.exports) { | |
exports2 = module2.exports = library; | |
} | |
exports2.murmurHash3 = library; | |
} else if (typeof define === "function" && define.amd) { | |
define([], function() { | |
return library; | |
}); | |
} else { | |
library._murmurHash3 = root.murmurHash3; | |
library.noConflict = function() { | |
root.murmurHash3 = library._murmurHash3; | |
library._murmurHash3 = undefined2; | |
library.noConflict = undefined2; | |
return library; | |
}; | |
root.murmurHash3 = library; | |
} | |
})(exports2); | |
} | |
}); | |
// node_modules/murmurhash3js-revisited/index.js | |
var require_murmurhash3js_revisited = __commonJS({ | |
"node_modules/murmurhash3js-revisited/index.js"(exports2, module2) { | |
module2.exports = require_murmurHash3js(); | |
} | |
}); | |
// node_modules/sparse-array/index.js | |
var require_sparse_array = __commonJS({ | |
"node_modules/sparse-array/index.js"(exports2, module2) { | |
"use strict"; | |
var BITS_PER_BYTE = 7; | |
module2.exports = class SparseArray { | |
constructor() { | |
this._bitArrays = []; | |
this._data = []; | |
this._length = 0; | |
this._changedLength = false; | |
this._changedData = false; | |
} | |
set(index, value) { | |
let pos = this._internalPositionFor(index, false); | |
if (value === void 0) { | |
if (pos !== -1) { | |
this._unsetInternalPos(pos); | |
this._unsetBit(index); | |
this._changedLength = true; | |
this._changedData = true; | |
} | |
} else { | |
let needsSort = false; | |
if (pos === -1) { | |
pos = this._data.length; | |
this._setBit(index); | |
this._changedData = true; | |
} else { | |
needsSort = true; | |
} | |
this._setInternalPos(pos, index, value, needsSort); | |
this._changedLength = true; | |
} | |
} | |
unset(index) { | |
this.set(index, void 0); | |
} | |
get(index) { | |
this._sortData(); | |
const pos = this._internalPositionFor(index, true); | |
if (pos === -1) { | |
return void 0; | |
} | |
return this._data[pos][1]; | |
} | |
push(value) { | |
this.set(this.length, value); | |
return this.length; | |
} | |
get length() { | |
this._sortData(); | |
if (this._changedLength) { | |
const last2 = this._data[this._data.length - 1]; | |
this._length = last2 ? last2[0] + 1 : 0; | |
this._changedLength = false; | |
} | |
return this._length; | |
} | |
forEach(iterator) { | |
let i = 0; | |
while (i < this.length) { | |
iterator(this.get(i), i, this); | |
i++; | |
} | |
} | |
map(iterator) { | |
let i = 0; | |
let mapped = new Array(this.length); | |
while (i < this.length) { | |
mapped[i] = iterator(this.get(i), i, this); | |
i++; | |
} | |
return mapped; | |
} | |
reduce(reducer, initialValue) { | |
let i = 0; | |
let acc = initialValue; | |
while (i < this.length) { | |
const value = this.get(i); | |
acc = reducer(acc, value, i); | |
i++; | |
} | |
return acc; | |
} | |
find(finder) { | |
let i = 0, found, last2; | |
while (i < this.length && !found) { | |
last2 = this.get(i); | |
found = finder(last2); | |
i++; | |
} | |
return found ? last2 : void 0; | |
} | |
_internalPositionFor(index, noCreate) { | |
const bytePos = this._bytePosFor(index, noCreate); | |
if (bytePos >= this._bitArrays.length) { | |
return -1; | |
} | |
const byte = this._bitArrays[bytePos]; | |
const bitPos = index - bytePos * BITS_PER_BYTE; | |
const exists4 = (byte & 1 << bitPos) > 0; | |
if (!exists4) { | |
return -1; | |
} | |
const previousPopCount = this._bitArrays.slice(0, bytePos).reduce(popCountReduce, 0); | |
const mask = ~(4294967295 << bitPos + 1); | |
const bytePopCount = popCount(byte & mask); | |
const arrayPos = previousPopCount + bytePopCount - 1; | |
return arrayPos; | |
} | |
_bytePosFor(index, noCreate) { | |
const bytePos = Math.floor(index / BITS_PER_BYTE); | |
const targetLength = bytePos + 1; | |
while (!noCreate && this._bitArrays.length < targetLength) { | |
this._bitArrays.push(0); | |
} | |
return bytePos; | |
} | |
_setBit(index) { | |
const bytePos = this._bytePosFor(index, false); | |
this._bitArrays[bytePos] |= 1 << index - bytePos * BITS_PER_BYTE; | |
} | |
_unsetBit(index) { | |
const bytePos = this._bytePosFor(index, false); | |
this._bitArrays[bytePos] &= ~(1 << index - bytePos * BITS_PER_BYTE); | |
} | |
_setInternalPos(pos, index, value, needsSort) { | |
const data = this._data; | |
const elem = [index, value]; | |
if (needsSort) { | |
this._sortData(); | |
data[pos] = elem; | |
} else { | |
if (data.length) { | |
if (data[data.length - 1][0] >= index) { | |
data.push(elem); | |
} else if (data[0][0] <= index) { | |
data.unshift(elem); | |
} else { | |
const randomIndex = Math.round(data.length / 2); | |
this._data = data.slice(0, randomIndex).concat(elem).concat(data.slice(randomIndex)); | |
} | |
} else { | |
this._data.push(elem); | |
} | |
this._changedData = true; | |
this._changedLength = true; | |
} | |
} | |
_unsetInternalPos(pos) { | |
this._data.splice(pos, 1); | |
} | |
_sortData() { | |
if (this._changedData) { | |
this._data.sort(sortInternal); | |
} | |
this._changedData = false; | |
} | |
bitField() { | |
const bytes3 = []; | |
let pendingBitsForResultingByte = 8; | |
let pendingBitsForNewByte = 0; | |
let resultingByte = 0; | |
let newByte; | |
const pending = this._bitArrays.slice(); | |
while (pending.length || pendingBitsForNewByte) { | |
if (pendingBitsForNewByte === 0) { | |
newByte = pending.shift(); | |
pendingBitsForNewByte = 7; | |
} | |
const usingBits = Math.min(pendingBitsForNewByte, pendingBitsForResultingByte); | |
const mask = ~(255 << usingBits); | |
const masked = newByte & mask; | |
resultingByte |= masked << 8 - pendingBitsForResultingByte; | |
newByte = newByte >>> usingBits; | |
pendingBitsForNewByte -= usingBits; | |
pendingBitsForResultingByte -= usingBits; | |
if (!pendingBitsForResultingByte || !pendingBitsForNewByte && !pending.length) { | |
bytes3.push(resultingByte); | |
resultingByte = 0; | |
pendingBitsForResultingByte = 8; | |
} | |
} | |
for (var i = bytes3.length - 1; i > 0; i--) { | |
const value = bytes3[i]; | |
if (value === 0) { | |
bytes3.pop(); | |
} else { | |
break; | |
} | |
} | |
return bytes3; | |
} | |
compactArray() { | |
this._sortData(); | |
return this._data.map(valueOnly); | |
} | |
}; | |
function popCountReduce(count, byte) { | |
return count + popCount(byte); | |
} | |
function popCount(_v) { | |
let v = _v; | |
v = v - (v >> 1 & 1431655765); | |
v = (v & 858993459) + (v >> 2 & 858993459); | |
return (v + (v >> 4) & 252645135) * 16843009 >> 24; | |
} | |
function sortInternal(a, b) { | |
return a[0] - b[0]; | |
} | |
function valueOnly(elem) { | |
return elem[1]; | |
} | |
} | |
}); | |
// node_modules/rabin-wasm/src/rabin.js | |
var require_rabin = __commonJS({ | |
"node_modules/rabin-wasm/src/rabin.js"(exports2, module2) { | |
var Rabin = class { | |
/** | |
* Creates an instance of Rabin. | |
* @param { import("./../dist/rabin-wasm") } asModule | |
* @param {number} [bits=12] | |
* @param {number} [min=8 * 1024] | |
* @param {number} [max=32 * 1024] | |
* @param {number} polynomial | |
* @memberof Rabin | |
*/ | |
constructor(asModule, bits2 = 12, min = 8 * 1024, max = 32 * 1024, windowSize = 64, polynomial) { | |
this.bits = bits2; | |
this.min = min; | |
this.max = max; | |
this.asModule = asModule; | |
this.rabin = new asModule.Rabin(bits2, min, max, windowSize, polynomial); | |
this.polynomial = polynomial; | |
} | |
/** | |
* Fingerprints the buffer | |
* | |
* @param {Uint8Array} buf | |
* @returns {Array<number>} | |
* @memberof Rabin | |
*/ | |
fingerprint(buf3) { | |
const { | |
__retain, | |
__release, | |
__allocArray, | |
__getInt32Array, | |
Int32Array_ID, | |
Uint8Array_ID | |
} = this.asModule; | |
const lengths = new Int32Array(Math.ceil(buf3.length / this.min)); | |
const lengthsPtr = __retain(__allocArray(Int32Array_ID, lengths)); | |
const pointer = __retain(__allocArray(Uint8Array_ID, buf3)); | |
const out = this.rabin.fingerprint(pointer, lengthsPtr); | |
const processed = __getInt32Array(out); | |
__release(pointer); | |
__release(lengthsPtr); | |
const end = processed.indexOf(0); | |
return end >= 0 ? processed.subarray(0, end) : processed; | |
} | |
}; | |
module2.exports = Rabin; | |
} | |
}); | |
// node_modules/@assemblyscript/loader/index.js | |
var require_loader = __commonJS({ | |
"node_modules/@assemblyscript/loader/index.js"(exports2) { | |
"use strict"; | |
var ID_OFFSET = -8; | |
var SIZE_OFFSET = -4; | |
var ARRAYBUFFER_ID = 0; | |
var STRING_ID = 1; | |
var ARRAYBUFFERVIEW = 1 << 0; | |
var ARRAY = 1 << 1; | |
var SET = 1 << 2; | |
var MAP = 1 << 3; | |
var VAL_ALIGN_OFFSET = 5; | |
var VAL_ALIGN = 1 << VAL_ALIGN_OFFSET; | |
var VAL_SIGNED = 1 << 10; | |
var VAL_FLOAT = 1 << 11; | |
var VAL_NULLABLE = 1 << 12; | |
var VAL_MANAGED = 1 << 13; | |
var KEY_ALIGN_OFFSET = 14; | |
var KEY_ALIGN = 1 << KEY_ALIGN_OFFSET; | |
var KEY_SIGNED = 1 << 19; | |
var KEY_FLOAT = 1 << 20; | |
var KEY_NULLABLE = 1 << 21; | |
var KEY_MANAGED = 1 << 22; | |
var ARRAYBUFFERVIEW_BUFFER_OFFSET = 0; | |
var ARRAYBUFFERVIEW_DATASTART_OFFSET = 4; | |
var ARRAYBUFFERVIEW_DATALENGTH_OFFSET = 8; | |
var ARRAYBUFFERVIEW_SIZE = 12; | |
var ARRAY_LENGTH_OFFSET = 12; | |
var ARRAY_SIZE = 16; | |
var BIGINT = typeof BigUint64Array !== "undefined"; | |
var THIS = Symbol(); | |
var CHUNKSIZE = 1024; | |
function getStringImpl(buffer3, ptr) { | |
const U32 = new Uint32Array(buffer3); | |
const U16 = new Uint16Array(buffer3); | |
var length11 = U32[ptr + SIZE_OFFSET >>> 2] >>> 1; | |
var offset = ptr >>> 1; | |
if (length11 <= CHUNKSIZE) | |
return String.fromCharCode.apply(String, U16.subarray(offset, offset + length11)); | |
const parts = []; | |
do { | |
const last2 = U16[offset + CHUNKSIZE - 1]; | |
const size = last2 >= 55296 && last2 < 56320 ? CHUNKSIZE - 1 : CHUNKSIZE; | |
parts.push(String.fromCharCode.apply(String, U16.subarray(offset, offset += size))); | |
length11 -= size; | |
} while (length11 > CHUNKSIZE); | |
return parts.join("") + String.fromCharCode.apply(String, U16.subarray(offset, offset + length11)); | |
} | |
function preInstantiate(imports) { | |
const baseModule = {}; | |
function getString(memory, ptr) { | |
if (!memory) | |
return "<yet unknown>"; | |
return getStringImpl(memory.buffer, ptr); | |
} | |
const env = imports.env = imports.env || {}; | |
env.abort = env.abort || function abort(mesg, file, line, colm) { | |
const memory = baseModule.memory || env.memory; | |
throw Error("abort: " + getString(memory, mesg) + " at " + getString(memory, file) + ":" + line + ":" + colm); | |
}; | |
env.trace = env.trace || function trace(mesg, n) { | |
const memory = baseModule.memory || env.memory; | |
console.log("trace: " + getString(memory, mesg) + (n ? " " : "") + Array.prototype.slice.call(arguments, 2, 2 + n).join(", ")); | |
}; | |
imports.Math = imports.Math || Math; | |
imports.Date = imports.Date || Date; | |
return baseModule; | |
} | |
function postInstantiate(baseModule, instance) { | |
const rawExports = instance.exports; | |
const memory = rawExports.memory; | |
const table2 = rawExports.table; | |
const alloc4 = rawExports["__alloc"]; | |
const retain = rawExports["__retain"]; | |
const rttiBase = rawExports["__rtti_base"] || ~0; | |
function getInfo(id) { | |
const U32 = new Uint32Array(memory.buffer); | |
const count = U32[rttiBase >>> 2]; | |
if ((id >>>= 0) >= count) | |
throw Error("invalid id: " + id); | |
return U32[(rttiBase + 4 >>> 2) + id * 2]; | |
} | |
function getBase(id) { | |
const U32 = new Uint32Array(memory.buffer); | |
const count = U32[rttiBase >>> 2]; | |
if ((id >>>= 0) >= count) | |
throw Error("invalid id: " + id); | |
return U32[(rttiBase + 4 >>> 2) + id * 2 + 1]; | |
} | |
function getValueAlign(info) { | |
return 31 - Math.clz32(info >>> VAL_ALIGN_OFFSET & 31); | |
} | |
function getKeyAlign(info) { | |
return 31 - Math.clz32(info >>> KEY_ALIGN_OFFSET & 31); | |
} | |
function __allocString(str) { | |
const length11 = str.length; | |
const ptr = alloc4(length11 << 1, STRING_ID); | |
const U16 = new Uint16Array(memory.buffer); | |
for (var i = 0, p = ptr >>> 1; i < length11; ++i) | |
U16[p + i] = str.charCodeAt(i); | |
return ptr; | |
} | |
baseModule.__allocString = __allocString; | |
function __getString(ptr) { | |
const buffer3 = memory.buffer; | |
const id = new Uint32Array(buffer3)[ptr + ID_OFFSET >>> 2]; | |
if (id !== STRING_ID) | |
throw Error("not a string: " + ptr); | |
return getStringImpl(buffer3, ptr); | |
} | |
baseModule.__getString = __getString; | |
function getView(alignLog2, signed, float) { | |
const buffer3 = memory.buffer; | |
if (float) { | |
switch (alignLog2) { | |
case 2: | |
return new Float32Array(buffer3); | |
case 3: | |
return new Float64Array(buffer3); | |
} | |
} else { | |
switch (alignLog2) { | |
case 0: | |
return new (signed ? Int8Array : Uint8Array)(buffer3); | |
case 1: | |
return new (signed ? Int16Array : Uint16Array)(buffer3); | |
case 2: | |
return new (signed ? Int32Array : Uint32Array)(buffer3); | |
case 3: | |
return new (signed ? BigInt64Array : BigUint64Array)(buffer3); | |
} | |
} | |
throw Error("unsupported align: " + alignLog2); | |
} | |
function __allocArray(id, values) { | |
const info = getInfo(id); | |
if (!(info & (ARRAYBUFFERVIEW | ARRAY))) | |
throw Error("not an array: " + id + " @ " + info); | |
const align = getValueAlign(info); | |
const length11 = values.length; | |
const buf3 = alloc4(length11 << align, ARRAYBUFFER_ID); | |
const arr = alloc4(info & ARRAY ? ARRAY_SIZE : ARRAYBUFFERVIEW_SIZE, id); | |
const U32 = new Uint32Array(memory.buffer); | |
U32[arr + ARRAYBUFFERVIEW_BUFFER_OFFSET >>> 2] = retain(buf3); | |
U32[arr + ARRAYBUFFERVIEW_DATASTART_OFFSET >>> 2] = buf3; | |
U32[arr + ARRAYBUFFERVIEW_DATALENGTH_OFFSET >>> 2] = length11 << align; | |
if (info & ARRAY) | |
U32[arr + ARRAY_LENGTH_OFFSET >>> 2] = length11; | |
const view = getView(align, info & VAL_SIGNED, info & VAL_FLOAT); | |
if (info & VAL_MANAGED) { | |
for (let i = 0; i < length11; ++i) | |
view[(buf3 >>> align) + i] = retain(values[i]); | |
} else { | |
view.set(values, buf3 >>> align); | |
} | |
return arr; | |
} | |
baseModule.__allocArray = __allocArray; | |
function __getArrayView(arr) { | |
const U32 = new Uint32Array(memory.buffer); | |
const id = U32[arr + ID_OFFSET >>> 2]; | |
const info = getInfo(id); | |
if (!(info & ARRAYBUFFERVIEW)) | |
throw Error("not an array: " + id); | |
const align = getValueAlign(info); | |
var buf3 = U32[arr + ARRAYBUFFERVIEW_DATASTART_OFFSET >>> 2]; | |
const length11 = info & ARRAY ? U32[arr + ARRAY_LENGTH_OFFSET >>> 2] : U32[buf3 + SIZE_OFFSET >>> 2] >>> align; | |
return getView(align, info & VAL_SIGNED, info & VAL_FLOAT).subarray(buf3 >>>= align, buf3 + length11); | |
} | |
baseModule.__getArrayView = __getArrayView; | |
function __getArray(arr) { | |
const input = __getArrayView(arr); | |
const len = input.length; | |
const out = new Array(len); | |
for (let i = 0; i < len; i++) | |
out[i] = input[i]; | |
return out; | |
} | |
baseModule.__getArray = __getArray; | |
function __getArrayBuffer(ptr) { | |
const buffer3 = memory.buffer; | |
const length11 = new Uint32Array(buffer3)[ptr + SIZE_OFFSET >>> 2]; | |
return buffer3.slice(ptr, ptr + length11); | |
} | |
baseModule.__getArrayBuffer = __getArrayBuffer; | |
function getTypedArray(Type3, alignLog2, ptr) { | |
return new Type3(getTypedArrayView(Type3, alignLog2, ptr)); | |
} | |
function getTypedArrayView(Type3, alignLog2, ptr) { | |
const buffer3 = memory.buffer; | |
const U32 = new Uint32Array(buffer3); | |
const bufPtr = U32[ptr + ARRAYBUFFERVIEW_DATASTART_OFFSET >>> 2]; | |
return new Type3(buffer3, bufPtr, U32[bufPtr + SIZE_OFFSET >>> 2] >>> alignLog2); | |
} | |
baseModule.__getInt8Array = getTypedArray.bind(null, Int8Array, 0); | |
baseModule.__getInt8ArrayView = getTypedArrayView.bind(null, Int8Array, 0); | |
baseModule.__getUint8Array = getTypedArray.bind(null, Uint8Array, 0); | |
baseModule.__getUint8ArrayView = getTypedArrayView.bind(null, Uint8Array, 0); | |
baseModule.__getUint8ClampedArray = getTypedArray.bind(null, Uint8ClampedArray, 0); | |
baseModule.__getUint8ClampedArrayView = getTypedArrayView.bind(null, Uint8ClampedArray, 0); | |
baseModule.__getInt16Array = getTypedArray.bind(null, Int16Array, 1); | |
baseModule.__getInt16ArrayView = getTypedArrayView.bind(null, Int16Array, 1); | |
baseModule.__getUint16Array = getTypedArray.bind(null, Uint16Array, 1); | |
baseModule.__getUint16ArrayView = getTypedArrayView.bind(null, Uint16Array, 1); | |
baseModule.__getInt32Array = getTypedArray.bind(null, Int32Array, 2); | |
baseModule.__getInt32ArrayView = getTypedArrayView.bind(null, Int32Array, 2); | |
baseModule.__getUint32Array = getTypedArray.bind(null, Uint32Array, 2); | |
baseModule.__getUint32ArrayView = getTypedArrayView.bind(null, Uint32Array, 2); | |
if (BIGINT) { | |
baseModule.__getInt64Array = getTypedArray.bind(null, BigInt64Array, 3); | |
baseModule.__getInt64ArrayView = getTypedArrayView.bind(null, BigInt64Array, 3); | |
baseModule.__getUint64Array = getTypedArray.bind(null, BigUint64Array, 3); | |
baseModule.__getUint64ArrayView = getTypedArrayView.bind(null, BigUint64Array, 3); | |
} | |
baseModule.__getFloat32Array = getTypedArray.bind(null, Float32Array, 2); | |
baseModule.__getFloat32ArrayView = getTypedArrayView.bind(null, Float32Array, 2); | |
baseModule.__getFloat64Array = getTypedArray.bind(null, Float64Array, 3); | |
baseModule.__getFloat64ArrayView = getTypedArrayView.bind(null, Float64Array, 3); | |
function __instanceof(ptr, baseId) { | |
const U32 = new Uint32Array(memory.buffer); | |
var id = U32[ptr + ID_OFFSET >>> 2]; | |
if (id <= U32[rttiBase >>> 2]) { | |
do | |
if (id == baseId) | |
return true; | |
while (id = getBase(id)); | |
} | |
return false; | |
} | |
baseModule.__instanceof = __instanceof; | |
baseModule.memory = baseModule.memory || memory; | |
baseModule.table = baseModule.table || table2; | |
return demangle(rawExports, baseModule); | |
} | |
function isResponse(o) { | |
return typeof Response !== "undefined" && o instanceof Response; | |
} | |
async function instantiate(source, imports) { | |
if (isResponse(source = await source)) | |
return instantiateStreaming(source, imports); | |
return postInstantiate( | |
preInstantiate(imports || (imports = {})), | |
await WebAssembly.instantiate( | |
source instanceof WebAssembly.Module ? source : await WebAssembly.compile(source), | |
imports | |
) | |
); | |
} | |
exports2.instantiate = instantiate; | |
function instantiateSync(source, imports) { | |
return postInstantiate( | |
preInstantiate(imports || (imports = {})), | |
new WebAssembly.Instance( | |
source instanceof WebAssembly.Module ? source : new WebAssembly.Module(source), | |
imports | |
) | |
); | |
} | |
exports2.instantiateSync = instantiateSync; | |
async function instantiateStreaming(source, imports) { | |
if (!WebAssembly.instantiateStreaming) { | |
return instantiate( | |
isResponse(source = await source) ? source.arrayBuffer() : source, | |
imports | |
); | |
} | |
return postInstantiate( | |
preInstantiate(imports || (imports = {})), | |
(await WebAssembly.instantiateStreaming(source, imports)).instance | |
); | |
} | |
exports2.instantiateStreaming = instantiateStreaming; | |
function demangle(exports3, baseModule) { | |
var module3 = baseModule ? Object.create(baseModule) : {}; | |
var setArgumentsLength = exports3["__argumentsLength"] ? function(length11) { | |
exports3["__argumentsLength"].value = length11; | |
} : exports3["__setArgumentsLength"] || exports3["__setargc"] || function() { | |
}; | |
for (let internalName in exports3) { | |
if (!Object.prototype.hasOwnProperty.call(exports3, internalName)) | |
continue; | |
const elem = exports3[internalName]; | |
let parts = internalName.split("."); | |
let curr = module3; | |
while (parts.length > 1) { | |
let part = parts.shift(); | |
if (!Object.prototype.hasOwnProperty.call(curr, part)) | |
curr[part] = {}; | |
curr = curr[part]; | |
} | |
let name8 = parts[0]; | |
let hash3 = name8.indexOf("#"); | |
if (hash3 >= 0) { | |
let className = name8.substring(0, hash3); | |
let classElem = curr[className]; | |
if (typeof classElem === "undefined" || !classElem.prototype) { | |
let ctor = function(...args) { | |
return ctor.wrap(ctor.prototype.constructor(0, ...args)); | |
}; | |
ctor.prototype = { | |
valueOf: function valueOf() { | |
return this[THIS]; | |
} | |
}; | |
ctor.wrap = function(thisValue) { | |
return Object.create(ctor.prototype, { [THIS]: { value: thisValue, writable: false } }); | |
}; | |
if (classElem) | |
Object.getOwnPropertyNames(classElem).forEach( | |
(name9) => Object.defineProperty(ctor, name9, Object.getOwnPropertyDescriptor(classElem, name9)) | |
); | |
curr[className] = ctor; | |
} | |
name8 = name8.substring(hash3 + 1); | |
curr = curr[className].prototype; | |
if (/^(get|set):/.test(name8)) { | |
if (!Object.prototype.hasOwnProperty.call(curr, name8 = name8.substring(4))) { | |
let getter = exports3[internalName.replace("set:", "get:")]; | |
let setter = exports3[internalName.replace("get:", "set:")]; | |
Object.defineProperty(curr, name8, { | |
get: function() { | |
return getter(this[THIS]); | |
}, | |
set: function(value) { | |
setter(this[THIS], value); | |
}, | |
enumerable: true | |
}); | |
} | |
} else { | |
if (name8 === "constructor") { | |
(curr[name8] = (...args) => { | |
setArgumentsLength(args.length); | |
return elem(...args); | |
}).original = elem; | |
} else { | |
(curr[name8] = function(...args) { | |
setArgumentsLength(args.length); | |
return elem(this[THIS], ...args); | |
}).original = elem; | |
} | |
} | |
} else { | |
if (/^(get|set):/.test(name8)) { | |
if (!Object.prototype.hasOwnProperty.call(curr, name8 = name8.substring(4))) { | |
Object.defineProperty(curr, name8, { | |
get: exports3[internalName.replace("set:", "get:")], | |
set: exports3[internalName.replace("get:", "set:")], | |
enumerable: true | |
}); | |
} | |
} else if (typeof elem === "function" && elem !== setArgumentsLength) { | |
(curr[name8] = (...args) => { | |
setArgumentsLength(args.length); | |
return elem(...args); | |
}).original = elem; | |
} else { | |
curr[name8] = elem; | |
} | |
} | |
} | |
return module3; | |
} | |
exports2.demangle = demangle; | |
} | |
}); | |
// node_modules/rabin-wasm/dist/rabin-wasm.js | |
var require_rabin_wasm = __commonJS({ | |
"node_modules/rabin-wasm/dist/rabin-wasm.js"(exports2, module2) { | |
var { instantiate } = require_loader(); | |
loadWebAssembly.supported = typeof WebAssembly !== "undefined"; | |
function loadWebAssembly(imp = {}) { | |
if (!loadWebAssembly.supported) | |
return null; | |
var wasm = new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 78, 14, 96, 2, 127, 126, 0, 96, 1, 127, 1, 126, 96, 2, 127, 127, 0, 96, 1, 127, 1, 127, 96, 1, 127, 0, 96, 2, 127, 127, 1, 127, 96, 3, 127, 127, 127, 1, 127, 96, 0, 0, 96, 3, 127, 127, 127, 0, 96, 0, 1, 127, 96, 4, 127, 127, 127, 127, 0, 96, 5, 127, 127, 127, 127, 127, 1, 127, 96, 1, 126, 1, 127, 96, 2, 126, 126, 1, 126, 2, 13, 1, 3, 101, 110, 118, 5, 97, 98, 111, 114, 116, 0, 10, 3, 54, 53, 2, 2, 8, 9, 3, 5, 2, 8, 6, 5, 3, 4, 2, 6, 9, 12, 13, 2, 5, 11, 3, 2, 3, 2, 3, 2, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 6, 7, 7, 4, 4, 5, 3, 1, 0, 1, 6, 47, 9, 127, 1, 65, 0, 11, 127, 1, 65, 0, 11, 127, 0, 65, 3, 11, 127, 0, 65, 4, 11, 127, 1, 65, 0, 11, 127, 1, 65, 0, 11, 127, 1, 65, 0, 11, 127, 0, 65, 240, 2, 11, 127, 0, 65, 6, 11, 7, 240, 5, 41, 6, 109, 101, 109, 111, 114, 121, 2, 0, 7, 95, 95, 97, 108, 108, 111, 99, 0, 10, 8, 95, 95, 114, 101, 116, 97, 105, 110, 0, 11, 9, 95, 95, 114, 101, 108, 101, 97, 115, 101, 0, 12, 9, 95, 95, 99, 111, 108, 108, 101, 99, 116, 0, 51, 11, 95, 95, 114, 116, 116, 105, 95, 98, 97, 115, 101, 3, 7, 13, 73, 110, 116, 51, 50, 65, 114, 114, 97, 121, 95, 73, 68, 3, 2, 13, 85, 105, 110, 116, 56, 65, 114, 114, 97, 121, 95, 73, 68, 3, 3, 6, 100, 101, 103, 114, 101, 101, 0, 16, 3, 109, 111, 100, 0, 17, 5, 82, 97, 98, 105, 110, 3, 8, 16, 82, 97, 98, 105, 110, 35, 103, 101, 116, 58, 119, 105, 110, 100, 111, 119, 0, 21, 16, 82, 97, 98, 105, 110, 35, 115, 101, 116, 58, 119, 105, 110, 100, 111, 119, 0, 22, 21, 82, 97, 98, 105, 110, 35, 103, 101, 116, 58, 119, 105, 110, 100, 111, 119, 95, 115, 105, 122, 101, 0, 23, 21, 82, 97, 98, 105, 110, 35, 115, 101, 116, 58, 119, 105, 110, 100, 111, 119, 95, 115, 105, 122, 101, 0, 24, 14, 82, 97, 98, 105, 110, 35, 103, 101, 116, 58, 119, 112, 111, 115, 0, 25, 14, 82, 97, 98, 105, 110, 35, 115, 101, 116, 58, 119, 112, 111, 115, 0, 26, 15, 82, 97, 98, 105, 110, 35, 103, 101, 116, 58, 99, 111, 117, 110, 116, 0, 27, 15, 82, 97, 98, 105, 110, 35, 115, 101, 116, 58, 99, 111, 117, 110, 116, 0, 28, 13, 82, 97, 98, 105, 110, 35, 103, 101, 116, 58, 112, 111, 115, 0, 29, 13, 82, 97, 98, 105, 110, 35, 115, 101, 116, 58, 112, 111, 115, 0, 30, 15, 82, 97, 98, 105, 110, 35, 103, 101, 116, 58, 115, 116, 97, 114, 116, 0, 31, 15, 82, 97, 98, 105, 110, 35, 115, 101, 116, 58, 115, 116, 97, 114, 116, 0, 32, 16, 82, 97, 98, 105, 110, 35, 103, 101, 116, 58, 100, 105, 103, 101, 115, 116, 0, 33, 16, 82, 97, 98, 105, 110, 35, 115, 101, 116, 58, 100, 105, 103, 101, 115, 116, 0, 34, 21, 82, 97, 98, 105, 110, 35, 103, 101, 116, 58, 99, 104, 117, 110, 107, 95, 115, 116, 97, 114, 116, 0, 35, 21, 82, 97, 98, 105, 110, 35, 115, 101, 116, 58, 99, 104, 117, 110, 107, 95, 115, 116, 97, 114, 116, 0, 36, 22, 82, 97, 98, 105, 110, 35, 103, 101, 116, 58, 99, 104, 117, 110, 107, 95, 108, 101, 110, 103, 116, 104, 0, 37, 22, 82, 97, 98, 105, 110, 35, 115, 101, 116, 58, 99, 104, 117, 110, 107, 95, 108, 101, 110, 103, 116, 104, 0, 38, 31, 82, 97, 98, 105, 110, 35, 103, 101, 116, 58, 99, 104, 117, 110, 107, 95, 99, 117, 116, 95, 102, 105, 110, 103, 101, 114, 112, 114, 105, 110, 116, 0, 39, 31, 82, 97, 98, 105, 110, 35, 115, 101, 116, 58, 99, 104, 117, 110, 107, 95, 99, 117, 116, 95, 102, 105, 110, 103, 101, 114, 112, 114, 105, 110, 116, 0, 40, 20, 82, 97, 98, 105, 110, 35, 103, 101, 116, 58, 112, 111, 108, 121, 110, 111, 109, 105, 97, 108, 0, 41, 20, 82, 97, 98, 105, 110, 35, 115, 101, 116, 58, 112, 111, 108, 121, 110, 111, 109, 105, 97, 108, 0, 42, 17, 82, 97, 98, 105, 110, 35, 103, 101, 116, 58, 109, 105, 110, 115, 105, 122, 101, 0, 43, 17, 82, 97, 98, 105, 110, 35, 115, 101, 116, 58, 109, 105, 110, 115, 105, 122, 101, 0, 44, 17, 82, 97, 98, 105, 110, 35, 103, 101, 116, 58, 109, 97, 120, 115, 105, 122, 101, 0, 45, 17, 82, 97, 98, 105, 110, 35, 115, 101, 116, 58, 109, 97, 120, 115, 105, 122, 101, 0, 46, 14, 82, 97, 98, 105, 110, 35, 103, 101, 116, 58, 109, 97, 115, 107, 0, 47, 14, 82, 97, 98, 105, 110, 35, 115, 101, 116, 58, 109, 97, 115, 107, 0, 48, 17, 82, 97, 98, 105, 110, 35, 99, 111, 110, 115, 116, 114, 117, 99, 116, 111, 114, 0, 20, 17, 82, 97, 98, 105, 110, 35, 102, 105, 110, 103, 101, 114, 112, 114, 105, 110, 116, 0, 49, 8, 1, 50, 10, 165, 31, 53, 199, 1, 1, 4, 127, 32, 1, 40, 2, 0, 65, 124, 113, 34, 2, 65, 128, 2, 73, 4, 127, 32, 2, 65, 4, 118, 33, 4, 65, 0, 5, 32, 2, 65, 31, 32, 2, 103, 107, 34, 3, 65, 4, 107, 118, 65, 16, 115, 33, 4, 32, 3, 65, 7, 107, 11, 33, 3, 32, 1, 40, 2, 20, 33, 2, 32, 1, 40, 2, 16, 34, 5, 4, 64, 32, 5, 32, 2, 54, 2, 20, 11, 32, 2, 4, 64, 32, 2, 32, 5, 54, 2, 16, 11, 32, 1, 32, 0, 32, 4, 32, 3, 65, 4, 116, 106, 65, 2, 116, 106, 40, 2, 96, 70, 4, 64, 32, 0, 32, 4, 32, 3, 65, 4, 116, 106, 65, 2, 116, 106, 32, 2, 54, 2, 96, 32, 2, 69, 4, 64, 32, 0, 32, 3, 65, 2, 116, 106, 32, 0, 32, 3, 65, 2, 116, 106, 40, 2, 4, 65, 1, 32, 4, 116, 65, 127, 115, 113, 34, 1, 54, 2, 4, 32, 1, 69, 4, 64, 32, 0, 32, 0, 40, 2, 0, 65, 1, 32, 3, 116, 65, 127, 115, 113, 54, 2, 0, 11, 11, 11, 11, 226, 2, 1, 6, 127, 32, 1, 40, 2, 0, 33, 3, 32, 1, 65, 16, 106, 32, 1, 40, 2, 0, 65, 124, 113, 106, 34, 4, 40, 2, 0, 34, 5, 65, 1, 113, 4, 64, 32, 3, 65, 124, 113, 65, 16, 106, 32, 5, 65, 124, 113, 106, 34, 2, 65, 240, 255, 255, 255, 3, 73, 4, 64, 32, 0, 32, 4, 16, 1, 32, 1, 32, 2, 32, 3, 65, 3, 113, 114, 34, 3, 54, 2, 0, 32, 1, 65, 16, 106, 32, 1, 40, 2, 0, 65, 124, 113, 106, 34, 4, 40, 2, 0, 33, 5, 11, 11, 32, 3, 65, 2, 113, 4, 64, 32, 1, 65, 4, 107, 40, 2, 0, 34, 2, 40, 2, 0, 34, 6, 65, 124, 113, 65, 16, 106, 32, 3, 65, 124, 113, 106, 34, 7, 65, 240, 255, 255, 255, 3, 73, 4, 64, 32, 0, 32, 2, 16, 1, 32, 2, 32, 7, 32, 6, 65, 3, 113, 114, 34, 3, 54, 2, 0, 32, 2, 33, 1, 11, 11, 32, 4, 32, 5, 65, 2, 114, 54, 2, 0, 32, 4, 65, 4, 107, 32, 1, 54, 2, 0, 32, 0, 32, 3, 65, 124, 113, 34, 2, 65, 128, 2, 73, 4, 127, 32, 2, 65, 4, 118, 33, 4, 65, 0, 5, 32, 2, 65, 31, 32, 2, 103, 107, 34, 2, 65, 4, 107, 118, 65, 16, 115, 33, 4, 32, 2, 65, 7, 107, 11, 34, 3, 65, 4, 116, 32, 4, 106, 65, 2, 116, 106, 40, 2, 96, 33, 2, 32, 1, 65, 0, 54, 2, 16, 32, 1, 32, 2, 54, 2, 20, 32, 2, 4, 64, 32, 2, 32, 1, 54, 2, 16, 11, 32, 0, 32, 4, 32, 3, 65, 4, 116, 106, 65, 2, 116, 106, 32, 1, 54, 2, 96, 32, 0, 32, 0, 40, 2, 0, 65, 1, 32, 3, 116, 114, 54, 2, 0, 32, 0, 32, 3, 65, 2, 116, 106, 32, 0, 32, 3, 65, 2, 116, 106, 40, 2, 4, 65, 1, 32, 4, 116, 114, 54, 2, 4, 11, 119, 1, 1, 127, 32, 2, 2, 127, 32, 0, 40, 2, 160, 12, 34, 2, 4, 64, 32, 2, 32, 1, 65, 16, 107, 70, 4, 64, 32, 2, 40, 2, 0, 33, 3, 32, 1, 65, 16, 107, 33, 1, 11, 11, 32, 1, 11, 107, 34, 2, 65, 48, 73, 4, 64, 15, 11, 32, 1, 32, 3, 65, 2, 113, 32, 2, 65, 32, 107, 65, 1, 114, 114, 54, 2, 0, 32, 1, 65, 0, 54, 2, 16, 32, 1, 65, 0, 54, 2, 20, 32, 1, 32, 2, 106, 65, 16, 107, 34, 2, 65, 2, 54, 2, 0, 32, 0, 32, 2, 54, 2, 160, 12, 32, 0, 32, 1, 16, 2, 11, 155, 1, 1, 3, 127, 35, 0, 34, 0, 69, 4, 64, 65, 1, 63, 0, 34, 0, 74, 4, 127, 65, 1, 32, 0, 107, 64, 0, 65, 0, 72, 5, 65, 0, 11, 4, 64, 0, 11, 65, 176, 3, 34, 0, 65, 0, 54, 2, 0, 65, 208, 15, 65, 0, 54, 2, 0, 3, 64, 32, 1, 65, 23, 73, 4, 64, 32, 1, 65, 2, 116, 65, 176, 3, 106, 65, 0, 54, 2, 4, 65, 0, 33, 2, 3, 64, 32, 2, 65, 16, 73, 4, 64, 32, 1, 65, 4, 116, 32, 2, 106, 65, 2, 116, 65, 176, 3, 106, 65, 0, 54, 2, 96, 32, 2, 65, 1, 106, 33, 2, 12, 1, 11, 11, 32, 1, 65, 1, 106, 33, 1, 12, 1, 11, 11, 65, 176, 3, 65, 224, 15, 63, 0, 65, 16, 116, 16, 3, 65, 176, 3, 36, 0, 11, 32, 0, 11, 45, 0, 32, 0, 65, 240, 255, 255, 255, 3, 79, 4, 64, 65, 32, 65, 224, 0, 65, 201, 3, 65, 29, 16, 0, 0, 11, 32, 0, 65, 15, 106, 65, 112, 113, 34, 0, 65, 16, 32, 0, 65, 16, 75, 27, 11, 169, 1, 1, 1, 127, 32, 0, 32, 1, 65, 128, 2, 73, 4, 127, 32, 1, 65, 4, 118, 33, 1, 65, 0, 5, 32, 1, 65, 248, 255, 255, 255, 1, 73, 4, 64, 32, 1, 65, 1, 65, 27, 32, 1, 103, 107, 116, 106, 65, 1, 107, 33, 1, 11, 32, 1, 65, 31, 32, 1, 103, 107, 34, 2, 65, 4, 107, 118, 65, 16, 115, 33, 1, 32, 2, 65, 7, 107, 11, 34, 2, 65, 2, 116, 106, 40, 2, 4, 65, 127, 32, 1, 116, 113, 34, 1, 4, 127, 32, 0, 32, 1, 104, 32, 2, 65, 4, 116, 106, 65, 2, 116, 106, 40, 2, 96, 5, 32, 0, 40, 2, 0, 65, 127, 32, 2, 65, 1, 106, 116, 113, 34, 1, 4, 127, 32, 0, 32, 0, 32, 1, 104, 34, 0, 65, 2, 116, 106, 40, 2, 4, 104, 32, 0, 65, 4, 116, 106, 65, 2, 116, 106, 40, 2, 96, 5, 65, 0, 11, 11, 11, 111, 1, 1, 127, 63, 0, 34, 2, 32, 1, 65, 248, 255, 255, 255, 1, 73, 4, 127, 32, 1, 65, 1, 65, 27, 32, 1, 103, 107, 116, 65, 1, 107, 106, 5, 32, 1, 11, 65, 16, 32, 0, 40, 2, 160, 12, 32, 2, 65, 16, 116, 65, 16, 107, 71, 116, 106, 65, 255, 255, 3, 106, 65, 128, 128, 124, 113, 65, 16, 118, 34, 1, 32, 2, 32, 1, 74, 27, 64, 0, 65, 0, 72, 4, 64, 32, 1, 64, 0, 65, 0, 72, 4, 64, 0, 11, 11, 32, 0, 32, 2, 65, 16, 116, 63, 0, 65, 16, 116, 16, 3, 11, 113, 1, 2, 127, 32, 1, 40, 2, 0, 34, 3, 65, 124, 113, 32, 2, 107, 34, 4, 65, 32, 79, 4, 64, 32, 1, 32, 2, 32, 3, 65, 2, 113, 114, 54, 2, 0, 32, 2, 32, 1, 65, 16, 106, 106, 34, 1, 32, 4, 65, 16, 107, 65, 1, 114, 54, 2, 0, 32, 0, 32, 1, 16, 2, 5, 32, 1, 32, 3, 65, 126, 113, 54, 2, 0, 32, 1, 65, 16, 106, 32, 1, 40, 2, 0, 65, 124, 113, 106, 32, 1, 65, 16, 106, 32, 1, 40, 2, 0, 65, 124, 113, 106, 40, 2, 0, 65, 125, 113, 54, 2, 0, 11, 11, 91, 1, 2, 127, 32, 0, 32, 1, 16, 5, 34, 4, 16, 6, 34, 3, 69, 4, 64, 65, 1, 36, 1, 65, 0, 36, 1, 32, 0, 32, 4, 16, 6, 34, 3, 69, 4, 64, 32, 0, 32, 4, 16, 7, 32, 0, 32, 4, 16, 6, 33, 3, 11, 11, 32, 3, 65, 0, 54, 2, 4, 32, 3, 32, 2, 54, 2, 8, 32, 3, 32, 1, 54, 2, 12, 32, 0, 32, 3, 16, 1, 32, 0, 32, 3, 32, 4, 16, 8, 32, 3, 11, 13, 0, 16, 4, 32, 0, 32, 1, 16, 9, 65, 16, 106, 11, 33, 1, 1, 127, 32, 0, 65, 172, 3, 75, 4, 64, 32, 0, 65, 16, 107, 34, 1, 32, 1, 40, 2, 4, 65, 1, 106, 54, 2, 4, 11, 32, 0, 11, 18, 0, 32, 0, 65, 172, 3, 75, 4, 64, 32, 0, 65, 16, 107, 16, 52, 11, 11, 140, 3, 1, 1, 127, 2, 64, 32, 1, 69, 13, 0, 32, 0, 65, 0, 58, 0, 0, 32, 0, 32, 1, 106, 65, 1, 107, 65, 0, 58, 0, 0, 32, 1, 65, 2, 77, 13, 0, 32, 0, 65, 1, 106, 65, 0, 58, 0, 0, 32, 0, 65, 2, 106, 65, 0, 58, 0, 0, 32, 0, 32, 1, 106, 34, 2, 65, 2, 107, 65, 0, 58, 0, 0, 32, 2, 65, 3, 107, 65, 0, 58, 0, 0, 32, 1, 65, 6, 77, 13, 0, 32, 0, 65, 3, 106, 65, 0, 58, 0, 0, 32, 0, 32, 1, 106, 65, 4, 107, 65, 0, 58, 0, 0, 32, 1, 65, 8, 77, 13, 0, 32, 1, 65, 0, 32, 0, 107, 65, 3, 113, 34, 1, 107, 33, 2, 32, 0, 32, 1, 106, 34, 0, 65, 0, 54, 2, 0, 32, 0, 32, 2, 65, 124, 113, 34, 1, 106, 65, 4, 107, 65, 0, 54, 2, 0, 32, 1, 65, 8, 77, 13, 0, 32, 0, 65, 4, 106, 65, 0, 54, 2, 0, 32, 0, 65, 8, 106, 65, 0, 54, 2, 0, 32, 0, 32, 1, 106, 34, 2, 65, 12, 107, 65, 0, 54, 2, 0, 32, 2, 65, 8, 107, 65, 0, 54, 2, 0, 32, 1, 65, 24, 77, 13, 0, 32, 0, 65, 12, 106, 65, 0, 54, 2, 0, 32, 0, 65, 16, 106, 65, 0, 54, 2, 0, 32, 0, 65, 20, 106, 65, 0, 54, 2, 0, 32, 0, 65, 24, 106, 65, 0, 54, 2, 0, 32, 0, 32, 1, 106, 34, 2, 65, 28, 107, 65, 0, 54, 2, 0, 32, 2, 65, 24, 107, 65, 0, 54, 2, 0, 32, 2, 65, 20, 107, 65, 0, 54, 2, 0, 32, 2, 65, 16, 107, 65, 0, 54, 2, 0, 32, 0, 32, 0, 65, 4, 113, 65, 24, 106, 34, 2, 106, 33, 0, 32, 1, 32, 2, 107, 33, 1, 3, 64, 32, 1, 65, 32, 79, 4, 64, 32, 0, 66, 0, 55, 3, 0, 32, 0, 65, 8, 106, 66, 0, 55, 3, 0, 32, 0, 65, 16, 106, 66, 0, 55, 3, 0, 32, 0, 65, 24, 106, 66, 0, 55, 3, 0, 32, 1, 65, 32, 107, 33, 1, 32, 0, 65, 32, 106, 33, 0, 12, 1, 11, 11, 11, 11, 178, 1, 1, 3, 127, 32, 1, 65, 240, 255, 255, 255, 3, 32, 2, 118, 75, 4, 64, 65, 144, 1, 65, 192, 1, 65, 23, 65, 56, 16, 0, 0, 11, 32, 1, 32, 2, 116, 34, 3, 65, 0, 16, 10, 34, 2, 32, 3, 16, 13, 32, 0, 69, 4, 64, 65, 12, 65, 2, 16, 10, 34, 0, 65, 172, 3, 75, 4, 64, 32, 0, 65, 16, 107, 34, 1, 32, 1, 40, 2, 4, 65, 1, 106, 54, 2, 4, 11, 11, 32, 0, 65, 0, 54, 2, 0, 32, 0, 65, 0, 54, 2, 4, 32, 0, 65, 0, 54, 2, 8, 32, 2, 34, 1, 32, 0, 40, 2, 0, 34, 4, 71, 4, 64, 32, 1, 65, 172, 3, 75, 4, 64, 32, 1, 65, 16, 107, 34, 5, 32, 5, 40, 2, 4, 65, 1, 106, 54, 2, 4, 11, 32, 4, 16, 12, 11, 32, 0, 32, 1, 54, 2, 0, 32, 0, 32, 2, 54, 2, 4, 32, 0, 32, 3, 54, 2, 8, 32, 0, 11, 46, 1, 2, 127, 65, 12, 65, 5, 16, 10, 34, 0, 65, 172, 3, 75, 4, 64, 32, 0, 65, 16, 107, 34, 1, 32, 1, 40, 2, 4, 65, 1, 106, 54, 2, 4, 11, 32, 0, 65, 128, 2, 65, 3, 16, 14, 11, 9, 0, 65, 63, 32, 0, 121, 167, 107, 11, 49, 1, 2, 127, 65, 63, 32, 1, 121, 167, 107, 33, 2, 3, 64, 65, 63, 32, 0, 121, 167, 107, 32, 2, 107, 34, 3, 65, 0, 78, 4, 64, 32, 0, 32, 1, 32, 3, 172, 134, 133, 33, 0, 12, 1, 11, 11, 32, 0, 11, 40, 0, 32, 1, 32, 0, 40, 2, 8, 79, 4, 64, 65, 128, 2, 65, 192, 2, 65, 163, 1, 65, 44, 16, 0, 0, 11, 32, 1, 32, 0, 40, 2, 4, 106, 65, 0, 58, 0, 0, 11, 38, 0, 32, 1, 32, 0, 40, 2, 8, 79, 4, 64, 65, 128, 2, 65, 192, 2, 65, 152, 1, 65, 44, 16, 0, 0, 11, 32, 1, 32, 0, 40, 2, 4, 106, 45, 0, 0, 11, 254, 5, 2, 1, 127, 4, 126, 32, 0, 69, 4, 64, 65, 232, 0, 65, 6, 16, 10, 34, 0, 65, 172, 3, 75, 4, 64, 32, 0, 65, 16, 107, 34, 5, 32, 5, 40, 2, 4, 65, 1, 106, 54, 2, 4, 11, 11, 32, 0, 65, 0, 54, 2, 0, 32, 0, 65, 0, 54, 2, 4, 32, 0, 65, 0, 54, 2, 8, 32, 0, 66, 0, 55, 3, 16, 32, 0, 66, 0, 55, 3, 24, 32, 0, 66, 0, 55, 3, 32, 32, 0, 66, 0, 55, 3, 40, 32, 0, 66, 0, 55, 3, 48, 32, 0, 66, 0, 55, 3, 56, 32, 0, 66, 0, 55, 3, 64, 32, 0, 66, 0, 55, 3, 72, 32, 0, 66, 0, 55, 3, 80, 32, 0, 66, 0, 55, 3, 88, 32, 0, 66, 0, 55, 3, 96, 32, 0, 32, 2, 173, 55, 3, 80, 32, 0, 32, 3, 173, 55, 3, 88, 65, 12, 65, 4, 16, 10, 34, 2, 65, 172, 3, 75, 4, 64, 32, 2, 65, 16, 107, 34, 3, 32, 3, 40, 2, 4, 65, 1, 106, 54, 2, 4, 11, 32, 2, 32, 4, 65, 0, 16, 14, 33, 2, 32, 0, 40, 2, 0, 16, 12, 32, 0, 32, 2, 54, 2, 0, 32, 0, 32, 4, 54, 2, 4, 32, 0, 66, 1, 32, 1, 173, 134, 66, 1, 125, 55, 3, 96, 32, 0, 66, 243, 130, 183, 218, 216, 230, 232, 30, 55, 3, 72, 35, 4, 69, 4, 64, 65, 0, 33, 2, 3, 64, 32, 2, 65, 128, 2, 72, 4, 64, 32, 2, 65, 255, 1, 113, 173, 33, 6, 32, 0, 41, 3, 72, 34, 7, 33, 8, 65, 63, 32, 7, 121, 167, 107, 33, 1, 3, 64, 65, 63, 32, 6, 121, 167, 107, 32, 1, 107, 34, 3, 65, 0, 78, 4, 64, 32, 6, 32, 8, 32, 3, 172, 134, 133, 33, 6, 12, 1, 11, 11, 65, 0, 33, 4, 3, 64, 32, 4, 32, 0, 40, 2, 4, 65, 1, 107, 72, 4, 64, 32, 6, 66, 8, 134, 33, 6, 32, 0, 41, 3, 72, 34, 7, 33, 8, 65, 63, 32, 7, 121, 167, 107, 33, 1, 3, 64, 65, 63, 32, 6, 121, 167, 107, 32, 1, 107, 34, 3, 65, 0, 78, 4, 64, 32, 6, 32, 8, 32, 3, 172, 134, 133, 33, 6, 12, 1, 11, 11, 32, 4, 65, 1, 106, 33, 4, 12, 1, 11, 11, 35, 6, 40, 2, 4, 32, 2, 65, 3, 116, 106, 32, 6, 55, 3, 0, 32, 2, 65, 1, 106, 33, 2, 12, 1, 11, 11, 65, 63, 32, 0, 41, 3, 72, 121, 167, 107, 172, 33, 7, 65, 0, 33, 2, 3, 64, 32, 2, 65, 128, 2, 72, 4, 64, 35, 5, 33, 1, 32, 2, 172, 32, 7, 134, 34, 8, 33, 6, 65, 63, 32, 0, 41, 3, 72, 34, 9, 121, 167, 107, 33, 3, 3, 64, 65, 63, 32, 6, 121, 167, 107, 32, 3, 107, 34, 4, 65, 0, 78, 4, 64, 32, 6, 32, 9, 32, 4, 172, 134, 133, 33, 6, 12, 1, 11, 11, 32, 1, 40, 2, 4, 32, 2, 65, 3, 116, 106, 32, 6, 32, 8, 132, 55, 3, 0, 32, 2, 65, 1, 106, 33, 2, 12, 1, 11, 11, 65, 1, 36, 4, 11, 32, 0, 66, 0, 55, 3, 24, 32, 0, 66, 0, 55, 3, 32, 65, 0, 33, 2, 3, 64, 32, 2, 32, 0, 40, 2, 4, 72, 4, 64, 32, 0, 40, 2, 0, 32, 2, 16, 18, 32, 2, 65, 1, 106, 33, 2, 12, 1, 11, 11, 32, 0, 66, 0, 55, 3, 40, 32, 0, 65, 0, 54, 2, 8, 32, 0, 66, 0, 55, 3, 16, 32, 0, 66, 0, 55, 3, 40, 32, 0, 40, 2, 0, 32, 0, 40, 2, 8, 16, 19, 33, 1, 32, 0, 40, 2, 8, 32, 0, 40, 2, 0, 40, 2, 4, 106, 65, 1, 58, 0, 0, 32, 0, 32, 0, 41, 3, 40, 35, 6, 40, 2, 4, 32, 1, 65, 3, 116, 106, 41, 3, 0, 133, 55, 3, 40, 32, 0, 32, 0, 40, 2, 8, 65, 1, 106, 32, 0, 40, 2, 4, 111, 54, 2, 8, 32, 0, 35, 5, 40, 2, 4, 32, 0, 41, 3, 40, 34, 6, 66, 45, 136, 167, 65, 3, 116, 106, 41, 3, 0, 32, 6, 66, 8, 134, 66, 1, 132, 133, 55, 3, 40, 32, 0, 11, 38, 1, 1, 127, 32, 0, 40, 2, 0, 34, 0, 65, 172, 3, 75, 4, 64, 32, 0, 65, 16, 107, 34, 1, 32, 1, 40, 2, 4, 65, 1, 106, 54, 2, 4, 11, 32, 0, 11, 55, 1, 2, 127, 32, 1, 32, 0, 40, 2, 0, 34, 2, 71, 4, 64, 32, 1, 65, 172, 3, 75, 4, 64, 32, 1, 65, 16, 107, 34, 3, 32, 3, 40, 2, 4, 65, 1, 106, 54, 2, 4, 11, 32, 2, 16, 12, 11, 32, 0, 32, 1, 54, 2, 0, 11, 7, 0, 32, 0, 40, 2, 4, 11, 9, 0, 32, 0, 32, 1, 54, 2, 4, 11, 7, 0, 32, 0, 40, 2, 8, 11, 9, 0, 32, 0, 32, 1, 54, 2, 8, 11, 7, 0, 32, 0, 41, 3, 16, 11, 9, 0, 32, 0, 32, 1, 55, 3, 16, 11, 7, 0, 32, 0, 41, 3, 24, 11, 9, 0, 32, 0, 32, 1, 55, 3, 24, 11, 7, 0, 32, 0, 41, 3, 32, 11, 9, 0, 32, 0, 32, 1, 55, 3, 32, 11, 7, 0, 32, 0, 41, 3, 40, 11, 9, 0, 32, 0, 32, 1, 55, 3, 40, 11, 7, 0, 32, 0, 41, 3, 48, 11, 9, 0, 32, 0, 32, 1, 55, 3, 48, 11, 7, 0, 32, 0, 41, 3, 56, 11, 9, 0, 32, 0, 32, 1, 55, 3, 56, 11, 7, 0, 32, 0, 41, 3, 64, 11, 9, 0, 32, 0, 32, 1, 55, 3, 64, 11, 7, 0, 32, 0, 41, 3, 72, 11, 9, 0, 32, 0, 32, 1, 55, 3, 72, 11, 7, 0, 32, 0, 41, 3, 80, 11, 9, 0, 32, 0, 32, 1, 55, 3, 80, 11, 7, 0, 32, 0, 41, 3, 88, 11, 9, 0, 32, 0, 32, 1, 55, 3, 88, 11, 7, 0, 32, 0, 41, 3, 96, 11, 9, 0, 32, 0, 32, 1, 55, 3, 96, 11, 172, 4, 2, 5, 127, 1, 126, 32, 2, 65, 172, 3, 75, 4, 64, 32, 2, 65, 16, 107, 34, 4, 32, 4, 40, 2, 4, 65, 1, 106, 54, 2, 4, 11, 32, 2, 33, 4, 65, 0, 33, 2, 32, 1, 40, 2, 8, 33, 5, 32, 1, 40, 2, 4, 33, 6, 3, 64, 2, 127, 65, 0, 33, 3, 3, 64, 32, 3, 32, 5, 72, 4, 64, 32, 3, 32, 6, 106, 45, 0, 0, 33, 1, 32, 0, 40, 2, 0, 32, 0, 40, 2, 8, 16, 19, 33, 7, 32, 0, 40, 2, 8, 32, 0, 40, 2, 0, 40, 2, 4, 106, 32, 1, 58, 0, 0, 32, 0, 32, 0, 41, 3, 40, 35, 6, 40, 2, 4, 32, 7, 65, 3, 116, 106, 41, 3, 0, 133, 55, 3, 40, 32, 0, 32, 0, 40, 2, 8, 65, 1, 106, 32, 0, 40, 2, 4, 111, 54, 2, 8, 32, 0, 35, 5, 40, 2, 4, 32, 0, 41, 3, 40, 34, 8, 66, 45, 136, 167, 65, 3, 116, 106, 41, 3, 0, 32, 1, 173, 32, 8, 66, 8, 134, 132, 133, 55, 3, 40, 32, 0, 32, 0, 41, 3, 16, 66, 1, 124, 55, 3, 16, 32, 0, 32, 0, 41, 3, 24, 66, 1, 124, 55, 3, 24, 32, 0, 41, 3, 16, 32, 0, 41, 3, 80, 90, 4, 127, 32, 0, 41, 3, 40, 32, 0, 41, 3, 96, 131, 80, 5, 65, 0, 11, 4, 127, 65, 1, 5, 32, 0, 41, 3, 16, 32, 0, 41, 3, 88, 90, 11, 4, 64, 32, 0, 32, 0, 41, 3, 32, 55, 3, 48, 32, 0, 32, 0, 41, 3, 16, 55, 3, 56, 32, 0, 32, 0, 41, 3, 40, 55, 3, 64, 65, 0, 33, 1, 3, 64, 32, 1, 32, 0, 40, 2, 4, 72, 4, 64, 32, 0, 40, 2, 0, 32, 1, 16, 18, 32, 1, 65, 1, 106, 33, 1, 12, 1, 11, 11, 32, 0, 66, 0, 55, 3, 40, 32, 0, 65, 0, 54, 2, 8, 32, 0, 66, 0, 55, 3, 16, 32, 0, 66, 0, 55, 3, 40, 32, 0, 40, 2, 0, 32, 0, 40, 2, 8, 16, 19, 33, 1, 32, 0, 40, 2, 8, 32, 0, 40, 2, 0, 40, 2, 4, 106, 65, 1, 58, 0, 0, 32, 0, 32, 0, 41, 3, 40, 35, 6, 40, 2, 4, 32, 1, 65, 3, 116, 106, 41, 3, 0, 133, 55, 3, 40, 32, 0, 32, 0, 40, 2, 8, 65, 1, 106, 32, 0, 40, 2, 4, 111, 54, 2, 8, 32, 0, 35, 5, 40, 2, 4, 32, 0, 41, 3, 40, 34, 8, 66, 45, 136, 167, 65, 3, 116, 106, 41, 3, 0, 32, 8, 66, 8, 134, 66, 1, 132, 133, 55, 3, 40, 32, 3, 65, 1, 106, 12, 3, 11, 32, 3, 65, 1, 106, 33, 3, 12, 1, 11, 11, 65, 127, 11, 34, 1, 65, 0, 78, 4, 64, 32, 5, 32, 1, 107, 33, 5, 32, 1, 32, 6, 106, 33, 6, 32, 2, 34, 1, 65, 1, 106, 33, 2, 32, 4, 40, 2, 4, 32, 1, 65, 2, 116, 106, 32, 0, 41, 3, 56, 62, 2, 0, 12, 1, 11, 11, 32, 4, 11, 10, 0, 16, 15, 36, 5, 16, 15, 36, 6, 11, 3, 0, 1, 11, 73, 1, 2, 127, 32, 0, 40, 2, 4, 34, 1, 65, 255, 255, 255, 255, 0, 113, 34, 2, 65, 1, 70, 4, 64, 32, 0, 65, 16, 106, 16, 53, 32, 0, 32, 0, 40, 2, 0, 65, 1, 114, 54, 2, 0, 35, 0, 32, 0, 16, 2, 5, 32, 0, 32, 2, 65, 1, 107, 32, 1, 65, 128, 128, 128, 128, 127, 113, 114, 54, 2, 4, 11, 11, 58, 0, 2, 64, 2, 64, 2, 64, 32, 0, 65, 8, 107, 40, 2, 0, 14, 7, 0, 0, 1, 1, 1, 1, 1, 2, 11, 15, 11, 32, 0, 40, 2, 0, 34, 0, 4, 64, 32, 0, 65, 172, 3, 79, 4, 64, 32, 0, 65, 16, 107, 16, 52, 11, 11, 15, 11, 0, 11, 11, 137, 3, 7, 0, 65, 16, 11, 55, 40, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 40, 0, 0, 0, 97, 0, 108, 0, 108, 0, 111, 0, 99, 0, 97, 0, 116, 0, 105, 0, 111, 0, 110, 0, 32, 0, 116, 0, 111, 0, 111, 0, 32, 0, 108, 0, 97, 0, 114, 0, 103, 0, 101, 0, 65, 208, 0, 11, 45, 30, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 30, 0, 0, 0, 126, 0, 108, 0, 105, 0, 98, 0, 47, 0, 114, 0, 116, 0, 47, 0, 116, 0, 108, 0, 115, 0, 102, 0, 46, 0, 116, 0, 115, 0, 65, 128, 1, 11, 43, 28, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 28, 0, 0, 0, 73, 0, 110, 0, 118, 0, 97, 0, 108, 0, 105, 0, 100, 0, 32, 0, 108, 0, 101, 0, 110, 0, 103, 0, 116, 0, 104, 0, 65, 176, 1, 11, 53, 38, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 38, 0, 0, 0, 126, 0, 108, 0, 105, 0, 98, 0, 47, 0, 97, 0, 114, 0, 114, 0, 97, 0, 121, 0, 98, 0, 117, 0, 102, 0, 102, 0, 101, 0, 114, 0, 46, 0, 116, 0, 115, 0, 65, 240, 1, 11, 51, 36, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 36, 0, 0, 0, 73, 0, 110, 0, 100, 0, 101, 0, 120, 0, 32, 0, 111, 0, 117, 0, 116, 0, 32, 0, 111, 0, 102, 0, 32, 0, 114, 0, 97, 0, 110, 0, 103, 0, 101, 0, 65, 176, 2, 11, 51, 36, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 36, 0, 0, 0, 126, 0, 108, 0, 105, 0, 98, 0, 47, 0, 116, 0, 121, 0, 112, 0, 101, 0, 100, 0, 97, 0, 114, 0, 114, 0, 97, 0, 121, 0, 46, 0, 116, 0, 115, 0, 65, 240, 2, 11, 53, 7, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 145, 4, 0, 0, 2, 0, 0, 0, 49, 0, 0, 0, 2, 0, 0, 0, 17, 1, 0, 0, 2, 0, 0, 0, 16, 0, 34, 16, 115, 111, 117, 114, 99, 101, 77, 97, 112, 112, 105, 110, 103, 85, 82, 76, 16, 46, 47, 114, 97, 98, 105, 110, 46, 119, 97, 115, 109, 46, 109, 97, 112]); | |
return instantiate(new Response(new Blob([wasm], { type: "application/wasm" })), imp); | |
} | |
module2.exports = loadWebAssembly; | |
} | |
}); | |
// node_modules/rabin-wasm/src/index.js | |
var require_src5 = __commonJS({ | |
"node_modules/rabin-wasm/src/index.js"(exports2, module2) { | |
var Rabin = require_rabin(); | |
var getRabin = require_rabin_wasm(); | |
var create13 = async (avg, min, max, windowSize, polynomial) => { | |
const compiled = await getRabin(); | |
return new Rabin(compiled, avg, min, max, windowSize, polynomial); | |
}; | |
module2.exports = { | |
Rabin, | |
create: create13 | |
}; | |
} | |
}); | |
// node_modules/@libp2p/logger/dist/src/index.js | |
var import_debug = __toESM(require_browser(), 1); | |
// node_modules/multiformats/src/bases/base58.js | |
var base58_exports = {}; | |
__export(base58_exports, { | |
base58btc: () => base58btc, | |
base58flickr: () => base58flickr | |
}); | |
// node_modules/multiformats/vendor/base-x.js | |
function base(ALPHABET, name8) { | |
if (ALPHABET.length >= 255) { | |
throw new TypeError("Alphabet too long"); | |
} | |
var BASE_MAP = new Uint8Array(256); | |
for (var j = 0; j < BASE_MAP.length; j++) { | |
BASE_MAP[j] = 255; | |
} | |
for (var i = 0; i < ALPHABET.length; i++) { | |
var x = ALPHABET.charAt(i); | |
var xc = x.charCodeAt(0); | |
if (BASE_MAP[xc] !== 255) { | |
throw new TypeError(x + " is ambiguous"); | |
} | |
BASE_MAP[xc] = i; | |
} | |
var BASE = ALPHABET.length; | |
var LEADER = ALPHABET.charAt(0); | |
var FACTOR = Math.log(BASE) / Math.log(256); | |
var iFACTOR = Math.log(256) / Math.log(BASE); | |
function encode39(source) { | |
if (source instanceof Uint8Array) | |
; | |
else if (ArrayBuffer.isView(source)) { | |
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength); | |
} else if (Array.isArray(source)) { | |
source = Uint8Array.from(source); | |
} | |
if (!(source instanceof Uint8Array)) { | |
throw new TypeError("Expected Uint8Array"); | |
} | |
if (source.length === 0) { | |
return ""; | |
} | |
var zeroes = 0; | |
var length11 = 0; | |
var pbegin = 0; | |
var pend = source.length; | |
while (pbegin !== pend && source[pbegin] === 0) { | |
pbegin++; | |
zeroes++; | |
} | |
var size = (pend - pbegin) * iFACTOR + 1 >>> 0; | |
var b58 = new Uint8Array(size); | |
while (pbegin !== pend) { | |
var carry = source[pbegin]; | |
var i2 = 0; | |
for (var it1 = size - 1; (carry !== 0 || i2 < length11) && it1 !== -1; it1--, i2++) { | |
carry += 256 * b58[it1] >>> 0; | |
b58[it1] = carry % BASE >>> 0; | |
carry = carry / BASE >>> 0; | |
} | |
if (carry !== 0) { | |
throw new Error("Non-zero carry"); | |
} | |
length11 = i2; | |
pbegin++; | |
} | |
var it2 = size - length11; | |
while (it2 !== size && b58[it2] === 0) { | |
it2++; | |
} | |
var str = LEADER.repeat(zeroes); | |
for (; it2 < size; ++it2) { | |
str += ALPHABET.charAt(b58[it2]); | |
} | |
return str; | |
} | |
function decodeUnsafe(source) { | |
if (typeof source !== "string") { | |
throw new TypeError("Expected String"); | |
} | |
if (source.length === 0) { | |
return new Uint8Array(); | |
} | |
var psz = 0; | |
if (source[psz] === " ") { | |
return; | |
} | |
var zeroes = 0; | |
var length11 = 0; | |
while (source[psz] === LEADER) { | |
zeroes++; | |
psz++; | |
} | |
var size = (source.length - psz) * FACTOR + 1 >>> 0; | |
var b256 = new Uint8Array(size); | |
while (source[psz]) { | |
var carry = BASE_MAP[source.charCodeAt(psz)]; | |
if (carry === 255) { | |
return; | |
} | |
var i2 = 0; | |
for (var it3 = size - 1; (carry !== 0 || i2 < length11) && it3 !== -1; it3--, i2++) { | |
carry += BASE * b256[it3] >>> 0; | |
b256[it3] = carry % 256 >>> 0; | |
carry = carry / 256 >>> 0; | |
} | |
if (carry !== 0) { | |
throw new Error("Non-zero carry"); | |
} | |
length11 = i2; | |
psz++; | |
} | |
if (source[psz] === " ") { | |
return; | |
} | |
var it4 = size - length11; | |
while (it4 !== size && b256[it4] === 0) { | |
it4++; | |
} | |
var vch = new Uint8Array(zeroes + (size - it4)); | |
var j2 = zeroes; | |
while (it4 !== size) { | |
vch[j2++] = b256[it4++]; | |
} | |
return vch; | |
} | |
function decode50(string3) { | |
var buffer3 = decodeUnsafe(string3); | |
if (buffer3) { | |
return buffer3; | |
} | |
throw new Error(`Non-${name8} character`); | |
} | |
return { | |
encode: encode39, | |
decodeUnsafe, | |
decode: decode50 | |
}; | |
} | |
var src = base; | |
var _brrp__multiformats_scope_baseX = src; | |
var base_x_default = _brrp__multiformats_scope_baseX; | |
// node_modules/multiformats/src/bytes.js | |
var empty = new Uint8Array(0); | |
var equals = (aa, bb) => { | |
if (aa === bb) | |
return true; | |
if (aa.byteLength !== bb.byteLength) { | |
return false; | |
} | |
for (let ii = 0; ii < aa.byteLength; ii++) { | |
if (aa[ii] !== bb[ii]) { | |
return false; | |
} | |
} | |
return true; | |
}; | |
var coerce = (o) => { | |
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array") | |
return o; | |
if (o instanceof ArrayBuffer) | |
return new Uint8Array(o); | |
if (ArrayBuffer.isView(o)) { | |
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength); | |
} | |
throw new Error("Unknown type, must be binary type"); | |
}; | |
var fromString = (str) => new TextEncoder().encode(str); | |
var toString = (b) => new TextDecoder().decode(b); | |
// node_modules/multiformats/src/bases/base.js | |
var Encoder = class { | |
/** | |
* @param {Base} name | |
* @param {Prefix} prefix | |
* @param {(bytes:Uint8Array) => string} baseEncode | |
*/ | |
constructor(name8, prefix, baseEncode) { | |
this.name = name8; | |
this.prefix = prefix; | |
this.baseEncode = baseEncode; | |
} | |
/** | |
* @param {Uint8Array} bytes | |
* @returns {API.Multibase<Prefix>} | |
*/ | |
encode(bytes3) { | |
if (bytes3 instanceof Uint8Array) { | |
return `${this.prefix}${this.baseEncode(bytes3)}`; | |
} else { | |
throw Error("Unknown type, must be binary type"); | |
} | |
} | |
}; | |
var Decoder = class { | |
/** | |
* @param {Base} name | |
* @param {Prefix} prefix | |
* @param {(text:string) => Uint8Array} baseDecode | |
*/ | |
constructor(name8, prefix, baseDecode) { | |
this.name = name8; | |
this.prefix = prefix; | |
if (prefix.codePointAt(0) === void 0) { | |
throw new Error("Invalid prefix character"); | |
} | |
this.prefixCodePoint = /** @type {number} */ | |
prefix.codePointAt(0); | |
this.baseDecode = baseDecode; | |
} | |
/** | |
* @param {string} text | |
*/ | |
decode(text) { | |
if (typeof text === "string") { | |
if (text.codePointAt(0) !== this.prefixCodePoint) { | |
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`); | |
} | |
return this.baseDecode(text.slice(this.prefix.length)); | |
} else { | |
throw Error("Can only multibase decode strings"); | |
} | |
} | |
/** | |
* @template {string} OtherPrefix | |
* @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder | |
* @returns {ComposedDecoder<Prefix|OtherPrefix>} | |
*/ | |
or(decoder) { | |
return or(this, decoder); | |
} | |
}; | |
var ComposedDecoder = class { | |
/** | |
* @param {Decoders<Prefix>} decoders | |
*/ | |
constructor(decoders2) { | |
this.decoders = decoders2; | |
} | |
/** | |
* @template {string} OtherPrefix | |
* @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder | |
* @returns {ComposedDecoder<Prefix|OtherPrefix>} | |
*/ | |
or(decoder) { | |
return or(this, decoder); | |
} | |
/** | |
* @param {string} input | |
* @returns {Uint8Array} | |
*/ | |
decode(input) { | |
const prefix = ( | |
/** @type {Prefix} */ | |
input[0] | |
); | |
const decoder = this.decoders[prefix]; | |
if (decoder) { | |
return decoder.decode(input); | |
} else { | |
throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`); | |
} | |
} | |
}; | |
var or = (left, right) => new ComposedDecoder( | |
/** @type {Decoders<L|R>} */ | |
{ | |
...left.decoders || { [ | |
/** @type API.UnibaseDecoder<L> */ | |
left.prefix | |
]: left }, | |
...right.decoders || { [ | |
/** @type API.UnibaseDecoder<R> */ | |
right.prefix | |
]: right } | |
} | |
); | |
var Codec = class { | |
/** | |
* @param {Base} name | |
* @param {Prefix} prefix | |
* @param {(bytes:Uint8Array) => string} baseEncode | |
* @param {(text:string) => Uint8Array} baseDecode | |
*/ | |
constructor(name8, prefix, baseEncode, baseDecode) { | |
this.name = name8; | |
this.prefix = prefix; | |
this.baseEncode = baseEncode; | |
this.baseDecode = baseDecode; | |
this.encoder = new Encoder(name8, prefix, baseEncode); | |
this.decoder = new Decoder(name8, prefix, baseDecode); | |
} | |
/** | |
* @param {Uint8Array} input | |
*/ | |
encode(input) { | |
return this.encoder.encode(input); | |
} | |
/** | |
* @param {string} input | |
*/ | |
decode(input) { | |
return this.decoder.decode(input); | |
} | |
}; | |
var from = ({ name: name8, prefix, encode: encode39, decode: decode50 }) => new Codec(name8, prefix, encode39, decode50); | |
var baseX = ({ prefix, name: name8, alphabet: alphabet5 }) => { | |
const { encode: encode39, decode: decode50 } = base_x_default(alphabet5, name8); | |
return from({ | |
prefix, | |
name: name8, | |
encode: encode39, | |
/** | |
* @param {string} text | |
*/ | |
decode: (text) => coerce(decode50(text)) | |
}); | |
}; | |
var decode = (string3, alphabet5, bitsPerChar, name8) => { | |
const codes8 = {}; | |
for (let i = 0; i < alphabet5.length; ++i) { | |
codes8[alphabet5[i]] = i; | |
} | |
let end = string3.length; | |
while (string3[end - 1] === "=") { | |
--end; | |
} | |
const out = new Uint8Array(end * bitsPerChar / 8 | 0); | |
let bits2 = 0; | |
let buffer3 = 0; | |
let written = 0; | |
for (let i = 0; i < end; ++i) { | |
const value = codes8[string3[i]]; | |
if (value === void 0) { | |
throw new SyntaxError(`Non-${name8} character`); | |
} | |
buffer3 = buffer3 << bitsPerChar | value; | |
bits2 += bitsPerChar; | |
if (bits2 >= 8) { | |
bits2 -= 8; | |
out[written++] = 255 & buffer3 >> bits2; | |
} | |
} | |
if (bits2 >= bitsPerChar || 255 & buffer3 << 8 - bits2) { | |
throw new SyntaxError("Unexpected end of data"); | |
} | |
return out; | |
}; | |
var encode = (data, alphabet5, bitsPerChar) => { | |
const pad = alphabet5[alphabet5.length - 1] === "="; | |
const mask = (1 << bitsPerChar) - 1; | |
let out = ""; | |
let bits2 = 0; | |
let buffer3 = 0; | |
for (let i = 0; i < data.length; ++i) { | |
buffer3 = buffer3 << 8 | data[i]; | |
bits2 += 8; | |
while (bits2 > bitsPerChar) { | |
bits2 -= bitsPerChar; | |
out += alphabet5[mask & buffer3 >> bits2]; | |
} | |
} | |
if (bits2) { | |
out += alphabet5[mask & buffer3 << bitsPerChar - bits2]; | |
} | |
if (pad) { | |
while (out.length * bitsPerChar & 7) { | |
out += "="; | |
} | |
} | |
return out; | |
}; | |
var rfc4648 = ({ name: name8, prefix, bitsPerChar, alphabet: alphabet5 }) => { | |
return from({ | |
prefix, | |
name: name8, | |
encode(input) { | |
return encode(input, alphabet5, bitsPerChar); | |
}, | |
decode(input) { | |
return decode(input, alphabet5, bitsPerChar, name8); | |
} | |
}); | |
}; | |
// node_modules/multiformats/src/bases/base58.js | |
var base58btc = baseX({ | |
name: "base58btc", | |
prefix: "z", | |
alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" | |
}); | |
var base58flickr = baseX({ | |
name: "base58flickr", | |
prefix: "Z", | |
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ" | |
}); | |
// node_modules/multiformats/src/bases/base32.js | |
var base32_exports = {}; | |
__export(base32_exports, { | |
base32: () => base32, | |
base32hex: () => base32hex, | |
base32hexpad: () => base32hexpad, | |
base32hexpadupper: () => base32hexpadupper, | |
base32hexupper: () => base32hexupper, | |
base32pad: () => base32pad, | |
base32padupper: () => base32padupper, | |
base32upper: () => base32upper, | |
base32z: () => base32z | |
}); | |
var base32 = rfc4648({ | |
prefix: "b", | |
name: "base32", | |
alphabet: "abcdefghijklmnopqrstuvwxyz234567", | |
bitsPerChar: 5 | |
}); | |
var base32upper = rfc4648({ | |
prefix: "B", | |
name: "base32upper", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", | |
bitsPerChar: 5 | |
}); | |
var base32pad = rfc4648({ | |
prefix: "c", | |
name: "base32pad", | |
alphabet: "abcdefghijklmnopqrstuvwxyz234567=", | |
bitsPerChar: 5 | |
}); | |
var base32padupper = rfc4648({ | |
prefix: "C", | |
name: "base32padupper", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=", | |
bitsPerChar: 5 | |
}); | |
var base32hex = rfc4648({ | |
prefix: "v", | |
name: "base32hex", | |
alphabet: "0123456789abcdefghijklmnopqrstuv", | |
bitsPerChar: 5 | |
}); | |
var base32hexupper = rfc4648({ | |
prefix: "V", | |
name: "base32hexupper", | |
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV", | |
bitsPerChar: 5 | |
}); | |
var base32hexpad = rfc4648({ | |
prefix: "t", | |
name: "base32hexpad", | |
alphabet: "0123456789abcdefghijklmnopqrstuv=", | |
bitsPerChar: 5 | |
}); | |
var base32hexpadupper = rfc4648({ | |
prefix: "T", | |
name: "base32hexpadupper", | |
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=", | |
bitsPerChar: 5 | |
}); | |
var base32z = rfc4648({ | |
prefix: "h", | |
name: "base32z", | |
alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769", | |
bitsPerChar: 5 | |
}); | |
// node_modules/multiformats/src/bases/base64.js | |
var base64_exports = {}; | |
__export(base64_exports, { | |
base64: () => base64, | |
base64pad: () => base64pad, | |
base64url: () => base64url, | |
base64urlpad: () => base64urlpad | |
}); | |
var base64 = rfc4648({ | |
prefix: "m", | |
name: "base64", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", | |
bitsPerChar: 6 | |
}); | |
var base64pad = rfc4648({ | |
prefix: "M", | |
name: "base64pad", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", | |
bitsPerChar: 6 | |
}); | |
var base64url = rfc4648({ | |
prefix: "u", | |
name: "base64url", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", | |
bitsPerChar: 6 | |
}); | |
var base64urlpad = rfc4648({ | |
prefix: "U", | |
name: "base64urlpad", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=", | |
bitsPerChar: 6 | |
}); | |
// node_modules/@libp2p/logger/dist/src/index.js | |
import_debug.default.formatters.b = (v) => { | |
return v == null ? "undefined" : base58btc.baseEncode(v); | |
}; | |
import_debug.default.formatters.t = (v) => { | |
return v == null ? "undefined" : base32.baseEncode(v); | |
}; | |
import_debug.default.formatters.m = (v) => { | |
return v == null ? "undefined" : base64.baseEncode(v); | |
}; | |
import_debug.default.formatters.p = (v) => { | |
return v == null ? "undefined" : v.toString(); | |
}; | |
import_debug.default.formatters.c = (v) => { | |
return v == null ? "undefined" : v.toString(); | |
}; | |
import_debug.default.formatters.k = (v) => { | |
return v == null ? "undefined" : v.toString(); | |
}; | |
import_debug.default.formatters.a = (v) => { | |
return v == null ? "undefined" : v.toString(); | |
}; | |
function createDisabledLogger(namespace) { | |
const logger5 = () => { | |
}; | |
logger5.enabled = false; | |
logger5.color = ""; | |
logger5.diff = 0; | |
logger5.log = () => { | |
}; | |
logger5.namespace = namespace; | |
logger5.destroy = () => true; | |
logger5.extend = () => logger5; | |
return logger5; | |
} | |
function logger(name8) { | |
let trace = createDisabledLogger(`${name8}:trace`); | |
if (import_debug.default.enabled(`${name8}:trace`) && import_debug.default.names.map((r) => r.toString()).find((n) => n.includes(":trace")) != null) { | |
trace = (0, import_debug.default)(`${name8}:trace`); | |
} | |
return Object.assign((0, import_debug.default)(name8), { | |
error: (0, import_debug.default)(`${name8}:error`), | |
trace | |
}); | |
} | |
// node_modules/blockstore-core/dist/src/errors.js | |
var errors_exports = {}; | |
__export(errors_exports, { | |
abortedError: () => abortedError, | |
closeFailedError: () => closeFailedError, | |
deleteFailedError: () => deleteFailedError, | |
getFailedError: () => getFailedError, | |
hasFailedError: () => hasFailedError, | |
notFoundError: () => notFoundError, | |
openFailedError: () => openFailedError, | |
putFailedError: () => putFailedError | |
}); | |
var import_err_code = __toESM(require_err_code(), 1); | |
function openFailedError(err) { | |
err = err ?? new Error("Open failed"); | |
return (0, import_err_code.default)(err, "ERR_OPEN_FAILED"); | |
} | |
function closeFailedError(err) { | |
err = err ?? new Error("Close failed"); | |
return (0, import_err_code.default)(err, "ERR_CLOSE_FAILED"); | |
} | |
function putFailedError(err) { | |
err = err ?? new Error("Put failed"); | |
return (0, import_err_code.default)(err, "ERR_PUT_FAILED"); | |
} | |
function getFailedError(err) { | |
err = err ?? new Error("Get failed"); | |
return (0, import_err_code.default)(err, "ERR_GET_FAILED"); | |
} | |
function deleteFailedError(err) { | |
err = err ?? new Error("Delete failed"); | |
return (0, import_err_code.default)(err, "ERR_DELETE_FAILED"); | |
} | |
function hasFailedError(err) { | |
err = err ?? new Error("Has failed"); | |
return (0, import_err_code.default)(err, "ERR_HAS_FAILED"); | |
} | |
function notFoundError(err) { | |
err = err ?? new Error("Not Found"); | |
return (0, import_err_code.default)(err, "ERR_NOT_FOUND"); | |
} | |
function abortedError(err) { | |
err = err ?? new Error("Aborted"); | |
return (0, import_err_code.default)(err, "ERR_ABORTED"); | |
} | |
// node_modules/blockstore-core/dist/src/base.js | |
var BaseBlockstore = class { | |
has(key, options) { | |
return Promise.reject(new Error(".has is not implemented")); | |
} | |
put(key, val, options) { | |
return Promise.reject(new Error(".put is not implemented")); | |
} | |
async *putMany(source, options) { | |
for await (const { cid, block } of source) { | |
await this.put(cid, block, options); | |
yield cid; | |
} | |
} | |
get(key, options) { | |
return Promise.reject(new Error(".get is not implemented")); | |
} | |
async *getMany(source, options) { | |
for await (const key of source) { | |
yield { | |
cid: key, | |
block: await this.get(key, options) | |
}; | |
} | |
} | |
async delete(key, options) { | |
await Promise.reject(new Error(".delete is not implemented")); | |
} | |
async *deleteMany(source, options) { | |
for await (const key of source) { | |
await this.delete(key, options); | |
yield key; | |
} | |
} | |
/** | |
* Extending classes should override `query` or implement this method | |
*/ | |
async *getAll(options) { | |
throw new Error(".getAll is not implemented"); | |
} | |
}; | |
// node_modules/blockstore-core/node_modules/multiformats/vendor/base-x.js | |
function base2(ALPHABET, name8) { | |
if (ALPHABET.length >= 255) { | |
throw new TypeError("Alphabet too long"); | |
} | |
var BASE_MAP = new Uint8Array(256); | |
for (var j = 0; j < BASE_MAP.length; j++) { | |
BASE_MAP[j] = 255; | |
} | |
for (var i = 0; i < ALPHABET.length; i++) { | |
var x = ALPHABET.charAt(i); | |
var xc = x.charCodeAt(0); | |
if (BASE_MAP[xc] !== 255) { | |
throw new TypeError(x + " is ambiguous"); | |
} | |
BASE_MAP[xc] = i; | |
} | |
var BASE = ALPHABET.length; | |
var LEADER = ALPHABET.charAt(0); | |
var FACTOR = Math.log(BASE) / Math.log(256); | |
var iFACTOR = Math.log(256) / Math.log(BASE); | |
function encode39(source) { | |
if (source instanceof Uint8Array) | |
; | |
else if (ArrayBuffer.isView(source)) { | |
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength); | |
} else if (Array.isArray(source)) { | |
source = Uint8Array.from(source); | |
} | |
if (!(source instanceof Uint8Array)) { | |
throw new TypeError("Expected Uint8Array"); | |
} | |
if (source.length === 0) { | |
return ""; | |
} | |
var zeroes = 0; | |
var length11 = 0; | |
var pbegin = 0; | |
var pend = source.length; | |
while (pbegin !== pend && source[pbegin] === 0) { | |
pbegin++; | |
zeroes++; | |
} | |
var size = (pend - pbegin) * iFACTOR + 1 >>> 0; | |
var b58 = new Uint8Array(size); | |
while (pbegin !== pend) { | |
var carry = source[pbegin]; | |
var i2 = 0; | |
for (var it1 = size - 1; (carry !== 0 || i2 < length11) && it1 !== -1; it1--, i2++) { | |
carry += 256 * b58[it1] >>> 0; | |
b58[it1] = carry % BASE >>> 0; | |
carry = carry / BASE >>> 0; | |
} | |
if (carry !== 0) { | |
throw new Error("Non-zero carry"); | |
} | |
length11 = i2; | |
pbegin++; | |
} | |
var it2 = size - length11; | |
while (it2 !== size && b58[it2] === 0) { | |
it2++; | |
} | |
var str = LEADER.repeat(zeroes); | |
for (; it2 < size; ++it2) { | |
str += ALPHABET.charAt(b58[it2]); | |
} | |
return str; | |
} | |
function decodeUnsafe(source) { | |
if (typeof source !== "string") { | |
throw new TypeError("Expected String"); | |
} | |
if (source.length === 0) { | |
return new Uint8Array(); | |
} | |
var psz = 0; | |
if (source[psz] === " ") { | |
return; | |
} | |
var zeroes = 0; | |
var length11 = 0; | |
while (source[psz] === LEADER) { | |
zeroes++; | |
psz++; | |
} | |
var size = (source.length - psz) * FACTOR + 1 >>> 0; | |
var b256 = new Uint8Array(size); | |
while (source[psz]) { | |
var carry = BASE_MAP[source.charCodeAt(psz)]; | |
if (carry === 255) { | |
return; | |
} | |
var i2 = 0; | |
for (var it3 = size - 1; (carry !== 0 || i2 < length11) && it3 !== -1; it3--, i2++) { | |
carry += BASE * b256[it3] >>> 0; | |
b256[it3] = carry % 256 >>> 0; | |
carry = carry / 256 >>> 0; | |
} | |
if (carry !== 0) { | |
throw new Error("Non-zero carry"); | |
} | |
length11 = i2; | |
psz++; | |
} | |
if (source[psz] === " ") { | |
return; | |
} | |
var it4 = size - length11; | |
while (it4 !== size && b256[it4] === 0) { | |
it4++; | |
} | |
var vch = new Uint8Array(zeroes + (size - it4)); | |
var j2 = zeroes; | |
while (it4 !== size) { | |
vch[j2++] = b256[it4++]; | |
} | |
return vch; | |
} | |
function decode50(string3) { | |
var buffer3 = decodeUnsafe(string3); | |
if (buffer3) { | |
return buffer3; | |
} | |
throw new Error(`Non-${name8} character`); | |
} | |
return { | |
encode: encode39, | |
decodeUnsafe, | |
decode: decode50 | |
}; | |
} | |
var src2 = base2; | |
var _brrp__multiformats_scope_baseX2 = src2; | |
var base_x_default2 = _brrp__multiformats_scope_baseX2; | |
// node_modules/blockstore-core/node_modules/multiformats/src/bytes.js | |
var empty2 = new Uint8Array(0); | |
var equals2 = (aa, bb) => { | |
if (aa === bb) | |
return true; | |
if (aa.byteLength !== bb.byteLength) { | |
return false; | |
} | |
for (let ii = 0; ii < aa.byteLength; ii++) { | |
if (aa[ii] !== bb[ii]) { | |
return false; | |
} | |
} | |
return true; | |
}; | |
var coerce2 = (o) => { | |
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array") | |
return o; | |
if (o instanceof ArrayBuffer) | |
return new Uint8Array(o); | |
if (ArrayBuffer.isView(o)) { | |
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength); | |
} | |
throw new Error("Unknown type, must be binary type"); | |
}; | |
// node_modules/blockstore-core/node_modules/multiformats/src/bases/base.js | |
var Encoder2 = class { | |
/** | |
* @param {Base} name | |
* @param {Prefix} prefix | |
* @param {(bytes:Uint8Array) => string} baseEncode | |
*/ | |
constructor(name8, prefix, baseEncode) { | |
this.name = name8; | |
this.prefix = prefix; | |
this.baseEncode = baseEncode; | |
} | |
/** | |
* @param {Uint8Array} bytes | |
* @returns {API.Multibase<Prefix>} | |
*/ | |
encode(bytes3) { | |
if (bytes3 instanceof Uint8Array) { | |
return `${this.prefix}${this.baseEncode(bytes3)}`; | |
} else { | |
throw Error("Unknown type, must be binary type"); | |
} | |
} | |
}; | |
var Decoder2 = class { | |
/** | |
* @param {Base} name | |
* @param {Prefix} prefix | |
* @param {(text:string) => Uint8Array} baseDecode | |
*/ | |
constructor(name8, prefix, baseDecode) { | |
this.name = name8; | |
this.prefix = prefix; | |
if (prefix.codePointAt(0) === void 0) { | |
throw new Error("Invalid prefix character"); | |
} | |
this.prefixCodePoint = /** @type {number} */ | |
prefix.codePointAt(0); | |
this.baseDecode = baseDecode; | |
} | |
/** | |
* @param {string} text | |
*/ | |
decode(text) { | |
if (typeof text === "string") { | |
if (text.codePointAt(0) !== this.prefixCodePoint) { | |
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`); | |
} | |
return this.baseDecode(text.slice(this.prefix.length)); | |
} else { | |
throw Error("Can only multibase decode strings"); | |
} | |
} | |
/** | |
* @template {string} OtherPrefix | |
* @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder | |
* @returns {ComposedDecoder<Prefix|OtherPrefix>} | |
*/ | |
or(decoder) { | |
return or2(this, decoder); | |
} | |
}; | |
var ComposedDecoder2 = class { | |
/** | |
* @param {Decoders<Prefix>} decoders | |
*/ | |
constructor(decoders2) { | |
this.decoders = decoders2; | |
} | |
/** | |
* @template {string} OtherPrefix | |
* @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder | |
* @returns {ComposedDecoder<Prefix|OtherPrefix>} | |
*/ | |
or(decoder) { | |
return or2(this, decoder); | |
} | |
/** | |
* @param {string} input | |
* @returns {Uint8Array} | |
*/ | |
decode(input) { | |
const prefix = ( | |
/** @type {Prefix} */ | |
input[0] | |
); | |
const decoder = this.decoders[prefix]; | |
if (decoder) { | |
return decoder.decode(input); | |
} else { | |
throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`); | |
} | |
} | |
}; | |
var or2 = (left, right) => new ComposedDecoder2( | |
/** @type {Decoders<L|R>} */ | |
{ | |
...left.decoders || { [ | |
/** @type API.UnibaseDecoder<L> */ | |
left.prefix | |
]: left }, | |
...right.decoders || { [ | |
/** @type API.UnibaseDecoder<R> */ | |
right.prefix | |
]: right } | |
} | |
); | |
var Codec2 = class { | |
/** | |
* @param {Base} name | |
* @param {Prefix} prefix | |
* @param {(bytes:Uint8Array) => string} baseEncode | |
* @param {(text:string) => Uint8Array} baseDecode | |
*/ | |
constructor(name8, prefix, baseEncode, baseDecode) { | |
this.name = name8; | |
this.prefix = prefix; | |
this.baseEncode = baseEncode; | |
this.baseDecode = baseDecode; | |
this.encoder = new Encoder2(name8, prefix, baseEncode); | |
this.decoder = new Decoder2(name8, prefix, baseDecode); | |
} | |
/** | |
* @param {Uint8Array} input | |
*/ | |
encode(input) { | |
return this.encoder.encode(input); | |
} | |
/** | |
* @param {string} input | |
*/ | |
decode(input) { | |
return this.decoder.decode(input); | |
} | |
}; | |
var from2 = ({ name: name8, prefix, encode: encode39, decode: decode50 }) => new Codec2(name8, prefix, encode39, decode50); | |
var baseX2 = ({ prefix, name: name8, alphabet: alphabet5 }) => { | |
const { encode: encode39, decode: decode50 } = base_x_default2(alphabet5, name8); | |
return from2({ | |
prefix, | |
name: name8, | |
encode: encode39, | |
/** | |
* @param {string} text | |
*/ | |
decode: (text) => coerce2(decode50(text)) | |
}); | |
}; | |
var decode2 = (string3, alphabet5, bitsPerChar, name8) => { | |
const codes8 = {}; | |
for (let i = 0; i < alphabet5.length; ++i) { | |
codes8[alphabet5[i]] = i; | |
} | |
let end = string3.length; | |
while (string3[end - 1] === "=") { | |
--end; | |
} | |
const out = new Uint8Array(end * bitsPerChar / 8 | 0); | |
let bits2 = 0; | |
let buffer3 = 0; | |
let written = 0; | |
for (let i = 0; i < end; ++i) { | |
const value = codes8[string3[i]]; | |
if (value === void 0) { | |
throw new SyntaxError(`Non-${name8} character`); | |
} | |
buffer3 = buffer3 << bitsPerChar | value; | |
bits2 += bitsPerChar; | |
if (bits2 >= 8) { | |
bits2 -= 8; | |
out[written++] = 255 & buffer3 >> bits2; | |
} | |
} | |
if (bits2 >= bitsPerChar || 255 & buffer3 << 8 - bits2) { | |
throw new SyntaxError("Unexpected end of data"); | |
} | |
return out; | |
}; | |
var encode2 = (data, alphabet5, bitsPerChar) => { | |
const pad = alphabet5[alphabet5.length - 1] === "="; | |
const mask = (1 << bitsPerChar) - 1; | |
let out = ""; | |
let bits2 = 0; | |
let buffer3 = 0; | |
for (let i = 0; i < data.length; ++i) { | |
buffer3 = buffer3 << 8 | data[i]; | |
bits2 += 8; | |
while (bits2 > bitsPerChar) { | |
bits2 -= bitsPerChar; | |
out += alphabet5[mask & buffer3 >> bits2]; | |
} | |
} | |
if (bits2) { | |
out += alphabet5[mask & buffer3 << bitsPerChar - bits2]; | |
} | |
if (pad) { | |
while (out.length * bitsPerChar & 7) { | |
out += "="; | |
} | |
} | |
return out; | |
}; | |
var rfc46482 = ({ name: name8, prefix, bitsPerChar, alphabet: alphabet5 }) => { | |
return from2({ | |
prefix, | |
name: name8, | |
encode(input) { | |
return encode2(input, alphabet5, bitsPerChar); | |
}, | |
decode(input) { | |
return decode2(input, alphabet5, bitsPerChar, name8); | |
} | |
}); | |
}; | |
// node_modules/blockstore-core/node_modules/multiformats/src/bases/base32.js | |
var base322 = rfc46482({ | |
prefix: "b", | |
name: "base32", | |
alphabet: "abcdefghijklmnopqrstuvwxyz234567", | |
bitsPerChar: 5 | |
}); | |
var base32upper2 = rfc46482({ | |
prefix: "B", | |
name: "base32upper", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", | |
bitsPerChar: 5 | |
}); | |
var base32pad2 = rfc46482({ | |
prefix: "c", | |
name: "base32pad", | |
alphabet: "abcdefghijklmnopqrstuvwxyz234567=", | |
bitsPerChar: 5 | |
}); | |
var base32padupper2 = rfc46482({ | |
prefix: "C", | |
name: "base32padupper", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=", | |
bitsPerChar: 5 | |
}); | |
var base32hex2 = rfc46482({ | |
prefix: "v", | |
name: "base32hex", | |
alphabet: "0123456789abcdefghijklmnopqrstuv", | |
bitsPerChar: 5 | |
}); | |
var base32hexupper2 = rfc46482({ | |
prefix: "V", | |
name: "base32hexupper", | |
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV", | |
bitsPerChar: 5 | |
}); | |
var base32hexpad2 = rfc46482({ | |
prefix: "t", | |
name: "base32hexpad", | |
alphabet: "0123456789abcdefghijklmnopqrstuv=", | |
bitsPerChar: 5 | |
}); | |
var base32hexpadupper2 = rfc46482({ | |
prefix: "T", | |
name: "base32hexpadupper", | |
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=", | |
bitsPerChar: 5 | |
}); | |
var base32z2 = rfc46482({ | |
prefix: "h", | |
name: "base32z", | |
alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769", | |
bitsPerChar: 5 | |
}); | |
// node_modules/blockstore-core/node_modules/multiformats/vendor/varint.js | |
var encode_1 = encode3; | |
var MSB = 128; | |
var REST = 127; | |
var MSBALL = ~REST; | |
var INT = Math.pow(2, 31); | |
function encode3(num, out, offset) { | |
out = out || []; | |
offset = offset || 0; | |
var oldOffset = offset; | |
while (num >= INT) { | |
out[offset++] = num & 255 | MSB; | |
num /= 128; | |
} | |
while (num & MSBALL) { | |
out[offset++] = num & 255 | MSB; | |
num >>>= 7; | |
} | |
out[offset] = num | 0; | |
encode3.bytes = offset - oldOffset + 1; | |
return out; | |
} | |
var decode3 = read; | |
var MSB$1 = 128; | |
var REST$1 = 127; | |
function read(buf3, offset) { | |
var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf3.length; | |
do { | |
if (counter >= l) { | |
read.bytes = 0; | |
throw new RangeError("Could not decode varint"); | |
} | |
b = buf3[counter++]; | |
res += shift < 28 ? (b & REST$1) << shift : (b & REST$1) * Math.pow(2, shift); | |
shift += 7; | |
} while (b >= MSB$1); | |
read.bytes = counter - offset; | |
return res; | |
} | |
var N1 = Math.pow(2, 7); | |
var N2 = Math.pow(2, 14); | |
var N3 = Math.pow(2, 21); | |
var N4 = Math.pow(2, 28); | |
var N5 = Math.pow(2, 35); | |
var N6 = Math.pow(2, 42); | |
var N7 = Math.pow(2, 49); | |
var N8 = Math.pow(2, 56); | |
var N9 = Math.pow(2, 63); | |
var length = function(value) { | |
return value < N1 ? 1 : value < N2 ? 2 : value < N3 ? 3 : value < N4 ? 4 : value < N5 ? 5 : value < N6 ? 6 : value < N7 ? 7 : value < N8 ? 8 : value < N9 ? 9 : 10; | |
}; | |
var varint = { | |
encode: encode_1, | |
decode: decode3, | |
encodingLength: length | |
}; | |
var _brrp_varint = varint; | |
var varint_default = _brrp_varint; | |
// node_modules/blockstore-core/node_modules/multiformats/src/varint.js | |
var decode4 = (data, offset = 0) => { | |
const code9 = varint_default.decode(data, offset); | |
return [code9, varint_default.decode.bytes]; | |
}; | |
var encodeTo = (int, target, offset = 0) => { | |
varint_default.encode(int, target, offset); | |
return target; | |
}; | |
var encodingLength = (int) => { | |
return varint_default.encodingLength(int); | |
}; | |
// node_modules/blockstore-core/node_modules/multiformats/src/hashes/digest.js | |
var create = (code9, digest5) => { | |
const size = digest5.byteLength; | |
const sizeOffset = encodingLength(code9); | |
const digestOffset = sizeOffset + encodingLength(size); | |
const bytes3 = new Uint8Array(digestOffset + size); | |
encodeTo(code9, bytes3, 0); | |
encodeTo(size, bytes3, sizeOffset); | |
bytes3.set(digest5, digestOffset); | |
return new Digest(code9, size, digest5, bytes3); | |
}; | |
var decode5 = (multihash) => { | |
const bytes3 = coerce2(multihash); | |
const [code9, sizeOffset] = decode4(bytes3); | |
const [size, digestOffset] = decode4(bytes3.subarray(sizeOffset)); | |
const digest5 = bytes3.subarray(sizeOffset + digestOffset); | |
if (digest5.byteLength !== size) { | |
throw new Error("Incorrect length"); | |
} | |
return new Digest(code9, size, digest5, bytes3); | |
}; | |
var equals3 = (a, b) => { | |
if (a === b) { | |
return true; | |
} else { | |
const data = ( | |
/** @type {{code?:unknown, size?:unknown, bytes?:unknown}} */ | |
b | |
); | |
return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals2(a.bytes, data.bytes); | |
} | |
}; | |
var Digest = class { | |
/** | |
* Creates a multihash digest. | |
* | |
* @param {Code} code | |
* @param {Size} size | |
* @param {Uint8Array} digest | |
* @param {Uint8Array} bytes | |
*/ | |
constructor(code9, size, digest5, bytes3) { | |
this.code = code9; | |
this.size = size; | |
this.digest = digest5; | |
this.bytes = bytes3; | |
} | |
}; | |
// node_modules/blockstore-core/node_modules/multiformats/src/bases/base58.js | |
var base58btc2 = baseX2({ | |
name: "base58btc", | |
prefix: "z", | |
alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" | |
}); | |
var base58flickr2 = baseX2({ | |
name: "base58flickr", | |
prefix: "Z", | |
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ" | |
}); | |
// node_modules/blockstore-core/node_modules/multiformats/src/cid.js | |
var format = (link, base14) => { | |
const { bytes: bytes3, version: version4 } = link; | |
switch (version4) { | |
case 0: | |
return toStringV0( | |
bytes3, | |
baseCache(link), | |
/** @type {API.MultibaseEncoder<"z">} */ | |
base14 || base58btc2.encoder | |
); | |
default: | |
return toStringV1( | |
bytes3, | |
baseCache(link), | |
/** @type {API.MultibaseEncoder<Prefix>} */ | |
base14 || base322.encoder | |
); | |
} | |
}; | |
var cache = /* @__PURE__ */ new WeakMap(); | |
var baseCache = (cid) => { | |
const baseCache9 = cache.get(cid); | |
if (baseCache9 == null) { | |
const baseCache10 = /* @__PURE__ */ new Map(); | |
cache.set(cid, baseCache10); | |
return baseCache10; | |
} | |
return baseCache9; | |
}; | |
var CID = class _CID { | |
/** | |
* @param {Version} version - Version of the CID | |
* @param {Format} code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv | |
* @param {API.MultihashDigest<Alg>} multihash - (Multi)hash of the of the content. | |
* @param {Uint8Array} bytes | |
* | |
*/ | |
constructor(version4, code9, multihash, bytes3) { | |
this.code = code9; | |
this.version = version4; | |
this.multihash = multihash; | |
this.bytes = bytes3; | |
this["/"] = bytes3; | |
} | |
/** | |
* Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes` | |
* please either use `CID.asCID(cid)` or switch to new signalling mechanism | |
* | |
* @deprecated | |
*/ | |
get asCID() { | |
return this; | |
} | |
// ArrayBufferView | |
get byteOffset() { | |
return this.bytes.byteOffset; | |
} | |
// ArrayBufferView | |
get byteLength() { | |
return this.bytes.byteLength; | |
} | |
/** | |
* @returns {CID<Data, API.DAG_PB, API.SHA_256, 0>} | |
*/ | |
toV0() { | |
switch (this.version) { | |
case 0: { | |
return ( | |
/** @type {CID<Data, API.DAG_PB, API.SHA_256, 0>} */ | |
this | |
); | |
} | |
case 1: { | |
const { code: code9, multihash } = this; | |
if (code9 !== DAG_PB_CODE) { | |
throw new Error("Cannot convert a non dag-pb CID to CIDv0"); | |
} | |
if (multihash.code !== SHA_256_CODE) { | |
throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0"); | |
} | |
return ( | |
/** @type {CID<Data, API.DAG_PB, API.SHA_256, 0>} */ | |
_CID.createV0( | |
/** @type {API.MultihashDigest<API.SHA_256>} */ | |
multihash | |
) | |
); | |
} | |
default: { | |
throw Error( | |
`Can not convert CID version ${this.version} to version 0. This is a bug please report` | |
); | |
} | |
} | |
} | |
/** | |
* @returns {CID<Data, Format, Alg, 1>} | |
*/ | |
toV1() { | |
switch (this.version) { | |
case 0: { | |
const { code: code9, digest: digest5 } = this.multihash; | |
const multihash = create(code9, digest5); | |
return ( | |
/** @type {CID<Data, Format, Alg, 1>} */ | |
_CID.createV1(this.code, multihash) | |
); | |
} | |
case 1: { | |
return ( | |
/** @type {CID<Data, Format, Alg, 1>} */ | |
this | |
); | |
} | |
default: { | |
throw Error( | |
`Can not convert CID version ${this.version} to version 1. This is a bug please report` | |
); | |
} | |
} | |
} | |
/** | |
* @param {unknown} other | |
* @returns {other is CID<Data, Format, Alg, Version>} | |
*/ | |
equals(other) { | |
return _CID.equals(this, other); | |
} | |
/** | |
* @template {unknown} Data | |
* @template {number} Format | |
* @template {number} Alg | |
* @template {API.Version} Version | |
* @param {API.Link<Data, Format, Alg, Version>} self | |
* @param {unknown} other | |
* @returns {other is CID} | |
*/ | |
static equals(self2, other) { | |
const unknown = ( | |
/** @type {{code?:unknown, version?:unknown, multihash?:unknown}} */ | |
other | |
); | |
return unknown && self2.code === unknown.code && self2.version === unknown.version && equals3(self2.multihash, unknown.multihash); | |
} | |
/** | |
* @param {API.MultibaseEncoder<string>} [base] | |
* @returns {string} | |
*/ | |
toString(base14) { | |
return format(this, base14); | |
} | |
toJSON() { | |
return { "/": format(this) }; | |
} | |
link() { | |
return this; | |
} | |
get [Symbol.toStringTag]() { | |
return "CID"; | |
} | |
// Legacy | |
[Symbol.for("nodejs.util.inspect.custom")]() { | |
return `CID(${this.toString()})`; | |
} | |
/** | |
* Takes any input `value` and returns a `CID` instance if it was | |
* a `CID` otherwise returns `null`. If `value` is instanceof `CID` | |
* it will return value back. If `value` is not instance of this CID | |
* class, but is compatible CID it will return new instance of this | |
* `CID` class. Otherwise returns null. | |
* | |
* This allows two different incompatible versions of CID library to | |
* co-exist and interop as long as binary interface is compatible. | |
* | |
* @template {unknown} Data | |
* @template {number} Format | |
* @template {number} Alg | |
* @template {API.Version} Version | |
* @template {unknown} U | |
* @param {API.Link<Data, Format, Alg, Version>|U} input | |
* @returns {CID<Data, Format, Alg, Version>|null} | |
*/ | |
static asCID(input) { | |
if (input == null) { | |
return null; | |
} | |
const value = ( | |
/** @type {any} */ | |
input | |
); | |
if (value instanceof _CID) { | |
return value; | |
} else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) { | |
const { version: version4, code: code9, multihash, bytes: bytes3 } = value; | |
return new _CID( | |
version4, | |
code9, | |
/** @type {API.MultihashDigest<Alg>} */ | |
multihash, | |
bytes3 || encodeCID(version4, code9, multihash.bytes) | |
); | |
} else if (value[cidSymbol] === true) { | |
const { version: version4, multihash, code: code9 } = value; | |
const digest5 = ( | |
/** @type {API.MultihashDigest<Alg>} */ | |
decode5(multihash) | |
); | |
return _CID.create(version4, code9, digest5); | |
} else { | |
return null; | |
} | |
} | |
/** | |
* | |
* @template {unknown} Data | |
* @template {number} Format | |
* @template {number} Alg | |
* @template {API.Version} Version | |
* @param {Version} version - Version of the CID | |
* @param {Format} code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv | |
* @param {API.MultihashDigest<Alg>} digest - (Multi)hash of the of the content. | |
* @returns {CID<Data, Format, Alg, Version>} | |
*/ | |
static create(version4, code9, digest5) { | |
if (typeof code9 !== "number") { | |
throw new Error("String codecs are no longer supported"); | |
} | |
if (!(digest5.bytes instanceof Uint8Array)) { | |
throw new Error("Invalid digest"); | |
} | |
switch (version4) { | |
case 0: { | |
if (code9 !== DAG_PB_CODE) { | |
throw new Error( | |
`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE}) block encoding` | |
); | |
} else { | |
return new _CID(version4, code9, digest5, digest5.bytes); | |
} | |
} | |
case 1: { | |
const bytes3 = encodeCID(version4, code9, digest5.bytes); | |
return new _CID(version4, code9, digest5, bytes3); | |
} | |
default: { | |
throw new Error("Invalid version"); | |
} | |
} | |
} | |
/** | |
* Simplified version of `create` for CIDv0. | |
* | |
* @template {unknown} [T=unknown] | |
* @param {API.MultihashDigest<typeof SHA_256_CODE>} digest - Multihash. | |
* @returns {CID<T, typeof DAG_PB_CODE, typeof SHA_256_CODE, 0>} | |
*/ | |
static createV0(digest5) { | |
return _CID.create(0, DAG_PB_CODE, digest5); | |
} | |
/** | |
* Simplified version of `create` for CIDv1. | |
* | |
* @template {unknown} Data | |
* @template {number} Code | |
* @template {number} Alg | |
* @param {Code} code - Content encoding format code. | |
* @param {API.MultihashDigest<Alg>} digest - Miltihash of the content. | |
* @returns {CID<Data, Code, Alg, 1>} | |
*/ | |
static createV1(code9, digest5) { | |
return _CID.create(1, code9, digest5); | |
} | |
/** | |
* Decoded a CID from its binary representation. The byte array must contain | |
* only the CID with no additional bytes. | |
* | |
* An error will be thrown if the bytes provided do not contain a valid | |
* binary representation of a CID. | |
* | |
* @template {unknown} Data | |
* @template {number} Code | |
* @template {number} Alg | |
* @template {API.Version} Ver | |
* @param {API.ByteView<API.Link<Data, Code, Alg, Ver>>} bytes | |
* @returns {CID<Data, Code, Alg, Ver>} | |
*/ | |
static decode(bytes3) { | |
const [cid, remainder] = _CID.decodeFirst(bytes3); | |
if (remainder.length) { | |
throw new Error("Incorrect length"); | |
} | |
return cid; | |
} | |
/** | |
* Decoded a CID from its binary representation at the beginning of a byte | |
* array. | |
* | |
* Returns an array with the first element containing the CID and the second | |
* element containing the remainder of the original byte array. The remainder | |
* will be a zero-length byte array if the provided bytes only contained a | |
* binary CID representation. | |
* | |
* @template {unknown} T | |
* @template {number} C | |
* @template {number} A | |
* @template {API.Version} V | |
* @param {API.ByteView<API.Link<T, C, A, V>>} bytes | |
* @returns {[CID<T, C, A, V>, Uint8Array]} | |
*/ | |
static decodeFirst(bytes3) { | |
const specs = _CID.inspectBytes(bytes3); | |
const prefixSize = specs.size - specs.multihashSize; | |
const multihashBytes = coerce2( | |
bytes3.subarray(prefixSize, prefixSize + specs.multihashSize) | |
); | |
if (multihashBytes.byteLength !== specs.multihashSize) { | |
throw new Error("Incorrect length"); | |
} | |
const digestBytes = multihashBytes.subarray( | |
specs.multihashSize - specs.digestSize | |
); | |
const digest5 = new Digest( | |
specs.multihashCode, | |
specs.digestSize, | |
digestBytes, | |
multihashBytes | |
); | |
const cid = specs.version === 0 ? _CID.createV0( | |
/** @type {API.MultihashDigest<API.SHA_256>} */ | |
digest5 | |
) : _CID.createV1(specs.codec, digest5); | |
return [ | |
/** @type {CID<T, C, A, V>} */ | |
cid, | |
bytes3.subarray(specs.size) | |
]; | |
} | |
/** | |
* Inspect the initial bytes of a CID to determine its properties. | |
* | |
* Involves decoding up to 4 varints. Typically this will require only 4 to 6 | |
* bytes but for larger multicodec code values and larger multihash digest | |
* lengths these varints can be quite large. It is recommended that at least | |
* 10 bytes be made available in the `initialBytes` argument for a complete | |
* inspection. | |
* | |
* @template {unknown} T | |
* @template {number} C | |
* @template {number} A | |
* @template {API.Version} V | |
* @param {API.ByteView<API.Link<T, C, A, V>>} initialBytes | |
* @returns {{ version:V, codec:C, multihashCode:A, digestSize:number, multihashSize:number, size:number }} | |
*/ | |
static inspectBytes(initialBytes) { | |
let offset = 0; | |
const next = () => { | |
const [i, length11] = decode4(initialBytes.subarray(offset)); | |
offset += length11; | |
return i; | |
}; | |
let version4 = ( | |
/** @type {V} */ | |
next() | |
); | |
let codec = ( | |
/** @type {C} */ | |
DAG_PB_CODE | |
); | |
if ( | |
/** @type {number} */ | |
version4 === 18 | |
) { | |
version4 = /** @type {V} */ | |
0; | |
offset = 0; | |
} else { | |
codec = /** @type {C} */ | |
next(); | |
} | |
if (version4 !== 0 && version4 !== 1) { | |
throw new RangeError(`Invalid CID version ${version4}`); | |
} | |
const prefixSize = offset; | |
const multihashCode = ( | |
/** @type {A} */ | |
next() | |
); | |
const digestSize = next(); | |
const size = offset + digestSize; | |
const multihashSize = size - prefixSize; | |
return { version: version4, codec, multihashCode, digestSize, multihashSize, size }; | |
} | |
/** | |
* Takes cid in a string representation and creates an instance. If `base` | |
* decoder is not provided will use a default from the configuration. It will | |
* throw an error if encoding of the CID is not compatible with supplied (or | |
* a default decoder). | |
* | |
* @template {string} Prefix | |
* @template {unknown} Data | |
* @template {number} Code | |
* @template {number} Alg | |
* @template {API.Version} Ver | |
* @param {API.ToString<API.Link<Data, Code, Alg, Ver>, Prefix>} source | |
* @param {API.MultibaseDecoder<Prefix>} [base] | |
* @returns {CID<Data, Code, Alg, Ver>} | |
*/ | |
static parse(source, base14) { | |
const [prefix, bytes3] = parseCIDtoBytes(source, base14); | |
const cid = _CID.decode(bytes3); | |
if (cid.version === 0 && source[0] !== "Q") { | |
throw Error("Version 0 CID string must not include multibase prefix"); | |
} | |
baseCache(cid).set(prefix, source); | |
return cid; | |
} | |
}; | |
var parseCIDtoBytes = (source, base14) => { | |
switch (source[0]) { | |
case "Q": { | |
const decoder = base14 || base58btc2; | |
return [ | |
/** @type {Prefix} */ | |
base58btc2.prefix, | |
decoder.decode(`${base58btc2.prefix}${source}`) | |
]; | |
} | |
case base58btc2.prefix: { | |
const decoder = base14 || base58btc2; | |
return [ | |
/** @type {Prefix} */ | |
base58btc2.prefix, | |
decoder.decode(source) | |
]; | |
} | |
case base322.prefix: { | |
const decoder = base14 || base322; | |
return [ | |
/** @type {Prefix} */ | |
base322.prefix, | |
decoder.decode(source) | |
]; | |
} | |
default: { | |
if (base14 == null) { | |
throw Error( | |
"To parse non base32 or base58btc encoded CID multibase decoder must be provided" | |
); | |
} | |
return [ | |
/** @type {Prefix} */ | |
source[0], | |
base14.decode(source) | |
]; | |
} | |
} | |
}; | |
var toStringV0 = (bytes3, cache10, base14) => { | |
const { prefix } = base14; | |
if (prefix !== base58btc2.prefix) { | |
throw Error(`Cannot string encode V0 in ${base14.name} encoding`); | |
} | |
const cid = cache10.get(prefix); | |
if (cid == null) { | |
const cid2 = base14.encode(bytes3).slice(1); | |
cache10.set(prefix, cid2); | |
return cid2; | |
} else { | |
return cid; | |
} | |
}; | |
var toStringV1 = (bytes3, cache10, base14) => { | |
const { prefix } = base14; | |
const cid = cache10.get(prefix); | |
if (cid == null) { | |
const cid2 = base14.encode(bytes3); | |
cache10.set(prefix, cid2); | |
return cid2; | |
} else { | |
return cid; | |
} | |
}; | |
var DAG_PB_CODE = 112; | |
var SHA_256_CODE = 18; | |
var encodeCID = (version4, code9, multihash) => { | |
const codeOffset = encodingLength(version4); | |
const hashOffset = codeOffset + encodingLength(code9); | |
const bytes3 = new Uint8Array(hashOffset + multihash.byteLength); | |
encodeTo(version4, bytes3, 0); | |
encodeTo(code9, bytes3, codeOffset); | |
bytes3.set(multihash, hashOffset); | |
return bytes3; | |
}; | |
var cidSymbol = Symbol.for("@ipld/js-cid/CID"); | |
// node_modules/blockstore-core/node_modules/multiformats/src/codecs/raw.js | |
var code = 85; | |
// node_modules/blockstore-core/dist/src/memory.js | |
var MemoryBlockstore = class extends BaseBlockstore { | |
data; | |
constructor() { | |
super(); | |
this.data = /* @__PURE__ */ new Map(); | |
} | |
put(key, val) { | |
this.data.set(base322.encode(key.multihash.bytes), val); | |
return key; | |
} | |
get(key) { | |
const buf3 = this.data.get(base322.encode(key.multihash.bytes)); | |
if (buf3 == null) { | |
throw notFoundError(); | |
} | |
return buf3; | |
} | |
has(key) { | |
return this.data.has(base322.encode(key.multihash.bytes)); | |
} | |
async delete(key) { | |
this.data.delete(base322.encode(key.multihash.bytes)); | |
} | |
async *getAll() { | |
for (const [key, value] of this.data.entries()) { | |
yield { | |
cid: CID.createV1(code, decode5(base322.decode(key))), | |
block: value | |
}; | |
} | |
} | |
}; | |
// node_modules/blockstore-core/node_modules/@libp2p/logger/dist/src/index.js | |
var import_debug2 = __toESM(require_browser(), 1); | |
// node_modules/blockstore-core/node_modules/multiformats/src/bases/base64.js | |
var base642 = rfc46482({ | |
prefix: "m", | |
name: "base64", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", | |
bitsPerChar: 6 | |
}); | |
var base64pad2 = rfc46482({ | |
prefix: "M", | |
name: "base64pad", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", | |
bitsPerChar: 6 | |
}); | |
var base64url2 = rfc46482({ | |
prefix: "u", | |
name: "base64url", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", | |
bitsPerChar: 6 | |
}); | |
var base64urlpad2 = rfc46482({ | |
prefix: "U", | |
name: "base64urlpad", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=", | |
bitsPerChar: 6 | |
}); | |
// node_modules/blockstore-core/node_modules/@libp2p/logger/dist/src/index.js | |
import_debug2.default.formatters.b = (v) => { | |
return v == null ? "undefined" : base58btc2.baseEncode(v); | |
}; | |
import_debug2.default.formatters.t = (v) => { | |
return v == null ? "undefined" : base322.baseEncode(v); | |
}; | |
import_debug2.default.formatters.m = (v) => { | |
return v == null ? "undefined" : base642.baseEncode(v); | |
}; | |
import_debug2.default.formatters.p = (v) => { | |
return v == null ? "undefined" : v.toString(); | |
}; | |
import_debug2.default.formatters.c = (v) => { | |
return v == null ? "undefined" : v.toString(); | |
}; | |
import_debug2.default.formatters.k = (v) => { | |
return v == null ? "undefined" : v.toString(); | |
}; | |
import_debug2.default.formatters.a = (v) => { | |
return v == null ? "undefined" : v.toString(); | |
}; | |
function createDisabledLogger2(namespace) { | |
const logger5 = () => { | |
}; | |
logger5.enabled = false; | |
logger5.color = ""; | |
logger5.diff = 0; | |
logger5.log = () => { | |
}; | |
logger5.namespace = namespace; | |
logger5.destroy = () => true; | |
logger5.extend = () => logger5; | |
return logger5; | |
} | |
function logger2(name8) { | |
let trace = createDisabledLogger2(`${name8}:trace`); | |
if (import_debug2.default.enabled(`${name8}:trace`) && import_debug2.default.names.map((r) => r.toString()).find((n) => n.includes(":trace")) != null) { | |
trace = (0, import_debug2.default)(`${name8}:trace`); | |
} | |
return Object.assign((0, import_debug2.default)(name8), { | |
error: (0, import_debug2.default)(`${name8}:error`), | |
trace | |
}); | |
} | |
// node_modules/it-drain/dist/src/index.js | |
function isAsyncIterable(thing) { | |
return thing[Symbol.asyncIterator] != null; | |
} | |
function drain(source) { | |
if (isAsyncIterable(source)) { | |
return (async () => { | |
for await (const _ of source) { | |
} | |
})(); | |
} else { | |
for (const _ of source) { | |
} | |
} | |
} | |
var src_default = drain; | |
// node_modules/it-peekable/dist/src/index.js | |
function peekable(iterable) { | |
const [iterator, symbol7] = iterable[Symbol.asyncIterator] != null ? [iterable[Symbol.asyncIterator](), Symbol.asyncIterator] : [iterable[Symbol.iterator](), Symbol.iterator]; | |
const queue = []; | |
return { | |
peek: () => { | |
return iterator.next(); | |
}, | |
push: (value) => { | |
queue.push(value); | |
}, | |
next: () => { | |
if (queue.length > 0) { | |
return { | |
done: false, | |
value: queue.shift() | |
}; | |
} | |
return iterator.next(); | |
}, | |
[symbol7]() { | |
return this; | |
} | |
}; | |
} | |
var src_default2 = peekable; | |
// node_modules/it-filter/dist/src/index.js | |
function isAsyncIterable2(thing) { | |
return thing[Symbol.asyncIterator] != null; | |
} | |
function filter(source, fn) { | |
if (isAsyncIterable2(source)) { | |
return async function* () { | |
for await (const entry of source) { | |
if (await fn(entry)) { | |
yield entry; | |
} | |
} | |
}(); | |
} | |
const peekable2 = src_default2(source); | |
const { value, done } = peekable2.next(); | |
if (done === true) { | |
return /* @__PURE__ */ function* () { | |
}(); | |
} | |
const res = fn(value); | |
if (typeof res.then === "function") { | |
return async function* () { | |
if (await res) { | |
yield value; | |
} | |
for await (const entry of peekable2) { | |
if (await fn(entry)) { | |
yield entry; | |
} | |
} | |
}(); | |
} | |
const func = fn; | |
return function* () { | |
if (res === true) { | |
yield value; | |
} | |
for (const entry of peekable2) { | |
if (func(entry)) { | |
yield entry; | |
} | |
} | |
}(); | |
} | |
var src_default3 = filter; | |
// node_modules/p-defer/index.js | |
function pDefer() { | |
const deferred = {}; | |
deferred.promise = new Promise((resolve6, reject) => { | |
deferred.resolve = resolve6; | |
deferred.reject = reject; | |
}); | |
return deferred; | |
} | |
// node_modules/it-pushable/dist/src/fifo.js | |
var FixedFIFO = class { | |
buffer; | |
mask; | |
top; | |
btm; | |
next; | |
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; | |
} | |
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 last2 = this.buffer[this.btm]; | |
if (last2 === void 0) { | |
return void 0; | |
} | |
this.buffer[this.btm] = void 0; | |
this.btm = this.btm + 1 & this.mask; | |
return last2; | |
} | |
isEmpty() { | |
return this.buffer[this.btm] === void 0; | |
} | |
}; | |
var FIFO = class { | |
size; | |
hwm; | |
head; | |
tail; | |
constructor(options = {}) { | |
this.hwm = options.splitLimit ?? 16; | |
this.head = new FixedFIFO(this.hwm); | |
this.tail = this.head; | |
this.size = 0; | |
} | |
calculateSize(obj) { | |
if (obj?.byteLength != null) { | |
return obj.byteLength; | |
} | |
return 1; | |
} | |
push(val) { | |
if (val?.value != null) { | |
this.size += this.calculateSize(val.value); | |
} | |
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() { | |
let val = this.tail.shift(); | |
if (val === void 0 && this.tail.next != null) { | |
const next = this.tail.next; | |
this.tail.next = null; | |
this.tail = next; | |
val = this.tail.shift(); | |
} | |
if (val?.value != null) { | |
this.size -= this.calculateSize(val.value); | |
} | |
return val; | |
} | |
isEmpty() { | |
return this.head.isEmpty(); | |
} | |
}; | |
// node_modules/it-pushable/dist/src/index.js | |
var AbortError = class extends Error { | |
type; | |
code; | |
constructor(message2, code9) { | |
super(message2 ?? "The operation was aborted"); | |
this.type = "aborted"; | |
this.code = code9 ?? "ABORT_ERR"; | |
} | |
}; | |
function pushable(options = {}) { | |
const getNext = (buffer3) => { | |
const next = buffer3.shift(); | |
if (next == null) { | |
return { done: true }; | |
} | |
if (next.error != null) { | |
throw next.error; | |
} | |
return { | |
done: next.done === true, | |
// @ts-expect-error if done is false, value will be present | |
value: next.value | |
}; | |
}; | |
return _pushable(getNext, options); | |
} | |
function pushableV(options = {}) { | |
const getNext = (buffer3) => { | |
let next; | |
const values = []; | |
while (!buffer3.isEmpty()) { | |
next = buffer3.shift(); | |
if (next == null) { | |
break; | |
} | |
if (next.error != null) { | |
throw next.error; | |
} | |
if (next.done === false) { | |
values.push(next.value); | |
} | |
} | |
if (next == null) { | |
return { done: true }; | |
} | |
return { | |
done: next.done === true, | |
value: values | |
}; | |
}; | |
return _pushable(getNext, options); | |
} | |
function _pushable(getNext, options) { | |
options = options ?? {}; | |
let onEnd = options.onEnd; | |
let buffer3 = new FIFO(); | |
let pushable2; | |
let onNext; | |
let ended; | |
let drain2 = pDefer(); | |
const waitNext = async () => { | |
try { | |
if (!buffer3.isEmpty()) { | |
return getNext(buffer3); | |
} | |
if (ended) { | |
return { done: true }; | |
} | |
return await new Promise((resolve6, reject) => { | |
onNext = (next) => { | |
onNext = null; | |
buffer3.push(next); | |
try { | |
resolve6(getNext(buffer3)); | |
} catch (err) { | |
reject(err); | |
} | |
return pushable2; | |
}; | |
}); | |
} finally { | |
if (buffer3.isEmpty()) { | |
queueMicrotask(() => { | |
drain2.resolve(); | |
drain2 = pDefer(); | |
}); | |
} | |
} | |
}; | |
const bufferNext = (next) => { | |
if (onNext != null) { | |
return onNext(next); | |
} | |
buffer3.push(next); | |
return pushable2; | |
}; | |
const bufferError = (err) => { | |
buffer3 = new FIFO(); | |
if (onNext != null) { | |
return onNext({ error: err }); | |
} | |
buffer3.push({ error: err }); | |
return pushable2; | |
}; | |
const push = (value) => { | |
if (ended) { | |
return pushable2; | |
} | |
if (options?.objectMode !== true && value?.byteLength == null) { | |
throw new Error("objectMode was not true but tried to push non-Uint8Array value"); | |
} | |
return bufferNext({ done: false, value }); | |
}; | |
const end = (err) => { | |
if (ended) | |
return pushable2; | |
ended = true; | |
return err != null ? bufferError(err) : bufferNext({ done: true }); | |
}; | |
const _return = () => { | |
buffer3 = new FIFO(); | |
end(); | |
return { done: true }; | |
}; | |
const _throw = (err) => { | |
end(err); | |
return { done: true }; | |
}; | |
pushable2 = { | |
[Symbol.asyncIterator]() { | |
return this; | |
}, | |
next: waitNext, | |
return: _return, | |
throw: _throw, | |
push, | |
end, | |
get readableLength() { | |
return buffer3.size; | |
}, | |
onEmpty: async (options2) => { | |
const signal = options2?.signal; | |
signal?.throwIfAborted(); | |
if (buffer3.isEmpty()) { | |
return; | |
} | |
let cancel; | |
let listener; | |
if (signal != null) { | |
cancel = new Promise((resolve6, reject) => { | |
listener = () => { | |
reject(new AbortError()); | |
}; | |
signal.addEventListener("abort", listener); | |
}); | |
} | |
try { | |
await Promise.race([ | |
drain2.promise, | |
cancel | |
]); | |
} finally { | |
if (listener != null && signal != null) { | |
signal?.removeEventListener("abort", listener); | |
} | |
} | |
} | |
}; | |
if (onEnd == null) { | |
return pushable2; | |
} | |
const _pushable2 = pushable2; | |
pushable2 = { | |
[Symbol.asyncIterator]() { | |
return this; | |
}, | |
next() { | |
return _pushable2.next(); | |
}, | |
throw(err) { | |
_pushable2.throw(err); | |
if (onEnd != null) { | |
onEnd(err); | |
onEnd = void 0; | |
} | |
return { done: true }; | |
}, | |
return() { | |
_pushable2.return(); | |
if (onEnd != null) { | |
onEnd(); | |
onEnd = void 0; | |
} | |
return { done: true }; | |
}, | |
push, | |
end(err) { | |
_pushable2.end(err); | |
if (onEnd != null) { | |
onEnd(err); | |
onEnd = void 0; | |
} | |
return pushable2; | |
}, | |
get readableLength() { | |
return _pushable2.readableLength; | |
} | |
}; | |
return pushable2; | |
} | |
// node_modules/it-merge/dist/src/index.js | |
function isAsyncIterable3(thing) { | |
return thing[Symbol.asyncIterator] != null; | |
} | |
function merge(...sources) { | |
const syncSources = []; | |
for (const source of sources) { | |
if (!isAsyncIterable3(source)) { | |
syncSources.push(source); | |
} | |
} | |
if (syncSources.length === sources.length) { | |
return function* () { | |
for (const source of syncSources) { | |
yield* source; | |
} | |
}(); | |
} | |
return async function* () { | |
const output3 = pushable({ | |
objectMode: true | |
}); | |
void Promise.resolve().then(async () => { | |
try { | |
await Promise.all(sources.map(async (source) => { | |
for await (const item of source) { | |
output3.push(item); | |
} | |
})); | |
output3.end(); | |
} catch (err) { | |
output3.end(err); | |
} | |
}); | |
yield* output3; | |
}(); | |
} | |
var src_default4 = merge; | |
// node_modules/blockstore-core/dist/src/tiered.js | |
var log = logger2("blockstore:core:tiered"); | |
// node_modules/blockstore-core/dist/src/index.js | |
var Errors = { | |
...errors_exports | |
}; | |
// node_modules/datastore-core/dist/src/errors.js | |
var import_err_code2 = __toESM(require_err_code(), 1); | |
function notFoundError2(err) { | |
err = err ?? new Error("Not Found"); | |
return (0, import_err_code2.default)(err, "ERR_NOT_FOUND"); | |
} | |
// node_modules/nanoid/index.browser.js | |
var nanoid = (size = 21) => crypto.getRandomValues(new Uint8Array(size)).reduce((id, byte) => { | |
byte &= 63; | |
if (byte < 36) { | |
id += byte.toString(36); | |
} else if (byte < 62) { | |
id += (byte - 26).toString(36).toUpperCase(); | |
} else if (byte > 62) { | |
id += "-"; | |
} else { | |
id += "_"; | |
} | |
return id; | |
}, ""); | |
// node_modules/uint8arrays/dist/src/util/as-uint8array.js | |
function asUint8Array(buf3) { | |
if (globalThis.Buffer != null) { | |
return new Uint8Array(buf3.buffer, buf3.byteOffset, buf3.byteLength); | |
} | |
return buf3; | |
} | |
// node_modules/uint8arrays/node_modules/multiformats/src/bases/identity.js | |
var identity_exports = {}; | |
__export(identity_exports, { | |
identity: () => identity | |
}); | |
// node_modules/uint8arrays/node_modules/multiformats/vendor/base-x.js | |
function base3(ALPHABET, name8) { | |
if (ALPHABET.length >= 255) { | |
throw new TypeError("Alphabet too long"); | |
} | |
var BASE_MAP = new Uint8Array(256); | |
for (var j = 0; j < BASE_MAP.length; j++) { | |
BASE_MAP[j] = 255; | |
} | |
for (var i = 0; i < ALPHABET.length; i++) { | |
var x = ALPHABET.charAt(i); | |
var xc = x.charCodeAt(0); | |
if (BASE_MAP[xc] !== 255) { | |
throw new TypeError(x + " is ambiguous"); | |
} | |
BASE_MAP[xc] = i; | |
} | |
var BASE = ALPHABET.length; | |
var LEADER = ALPHABET.charAt(0); | |
var FACTOR = Math.log(BASE) / Math.log(256); | |
var iFACTOR = Math.log(256) / Math.log(BASE); | |
function encode39(source) { | |
if (source instanceof Uint8Array) | |
; | |
else if (ArrayBuffer.isView(source)) { | |
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength); | |
} else if (Array.isArray(source)) { | |
source = Uint8Array.from(source); | |
} | |
if (!(source instanceof Uint8Array)) { | |
throw new TypeError("Expected Uint8Array"); | |
} | |
if (source.length === 0) { | |
return ""; | |
} | |
var zeroes = 0; | |
var length11 = 0; | |
var pbegin = 0; | |
var pend = source.length; | |
while (pbegin !== pend && source[pbegin] === 0) { | |
pbegin++; | |
zeroes++; | |
} | |
var size = (pend - pbegin) * iFACTOR + 1 >>> 0; | |
var b58 = new Uint8Array(size); | |
while (pbegin !== pend) { | |
var carry = source[pbegin]; | |
var i2 = 0; | |
for (var it1 = size - 1; (carry !== 0 || i2 < length11) && it1 !== -1; it1--, i2++) { | |
carry += 256 * b58[it1] >>> 0; | |
b58[it1] = carry % BASE >>> 0; | |
carry = carry / BASE >>> 0; | |
} | |
if (carry !== 0) { | |
throw new Error("Non-zero carry"); | |
} | |
length11 = i2; | |
pbegin++; | |
} | |
var it2 = size - length11; | |
while (it2 !== size && b58[it2] === 0) { | |
it2++; | |
} | |
var str = LEADER.repeat(zeroes); | |
for (; it2 < size; ++it2) { | |
str += ALPHABET.charAt(b58[it2]); | |
} | |
return str; | |
} | |
function decodeUnsafe(source) { | |
if (typeof source !== "string") { | |
throw new TypeError("Expected String"); | |
} | |
if (source.length === 0) { | |
return new Uint8Array(); | |
} | |
var psz = 0; | |
if (source[psz] === " ") { | |
return; | |
} | |
var zeroes = 0; | |
var length11 = 0; | |
while (source[psz] === LEADER) { | |
zeroes++; | |
psz++; | |
} | |
var size = (source.length - psz) * FACTOR + 1 >>> 0; | |
var b256 = new Uint8Array(size); | |
while (source[psz]) { | |
var carry = BASE_MAP[source.charCodeAt(psz)]; | |
if (carry === 255) { | |
return; | |
} | |
var i2 = 0; | |
for (var it3 = size - 1; (carry !== 0 || i2 < length11) && it3 !== -1; it3--, i2++) { | |
carry += BASE * b256[it3] >>> 0; | |
b256[it3] = carry % 256 >>> 0; | |
carry = carry / 256 >>> 0; | |
} | |
if (carry !== 0) { | |
throw new Error("Non-zero carry"); | |
} | |
length11 = i2; | |
psz++; | |
} | |
if (source[psz] === " ") { | |
return; | |
} | |
var it4 = size - length11; | |
while (it4 !== size && b256[it4] === 0) { | |
it4++; | |
} | |
var vch = new Uint8Array(zeroes + (size - it4)); | |
var j2 = zeroes; | |
while (it4 !== size) { | |
vch[j2++] = b256[it4++]; | |
} | |
return vch; | |
} | |
function decode50(string3) { | |
var buffer3 = decodeUnsafe(string3); | |
if (buffer3) { | |
return buffer3; | |
} | |
throw new Error(`Non-${name8} character`); | |
} | |
return { | |
encode: encode39, | |
decodeUnsafe, | |
decode: decode50 | |
}; | |
} | |
var src3 = base3; | |
var _brrp__multiformats_scope_baseX3 = src3; | |
var base_x_default3 = _brrp__multiformats_scope_baseX3; | |
// node_modules/uint8arrays/node_modules/multiformats/src/bytes.js | |
var empty3 = new Uint8Array(0); | |
var equals4 = (aa, bb) => { | |
if (aa === bb) | |
return true; | |
if (aa.byteLength !== bb.byteLength) { | |
return false; | |
} | |
for (let ii = 0; ii < aa.byteLength; ii++) { | |
if (aa[ii] !== bb[ii]) { | |
return false; | |
} | |
} | |
return true; | |
}; | |
var coerce3 = (o) => { | |
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array") | |
return o; | |
if (o instanceof ArrayBuffer) | |
return new Uint8Array(o); | |
if (ArrayBuffer.isView(o)) { | |
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength); | |
} | |
throw new Error("Unknown type, must be binary type"); | |
}; | |
var fromString2 = (str) => new TextEncoder().encode(str); | |
var toString2 = (b) => new TextDecoder().decode(b); | |
// node_modules/uint8arrays/node_modules/multiformats/src/bases/base.js | |
var Encoder3 = class { | |
/** | |
* @param {Base} name | |
* @param {Prefix} prefix | |
* @param {(bytes:Uint8Array) => string} baseEncode | |
*/ | |
constructor(name8, prefix, baseEncode) { | |
this.name = name8; | |
this.prefix = prefix; | |
this.baseEncode = baseEncode; | |
} | |
/** | |
* @param {Uint8Array} bytes | |
* @returns {API.Multibase<Prefix>} | |
*/ | |
encode(bytes3) { | |
if (bytes3 instanceof Uint8Array) { | |
return `${this.prefix}${this.baseEncode(bytes3)}`; | |
} else { | |
throw Error("Unknown type, must be binary type"); | |
} | |
} | |
}; | |
var Decoder3 = class { | |
/** | |
* @param {Base} name | |
* @param {Prefix} prefix | |
* @param {(text:string) => Uint8Array} baseDecode | |
*/ | |
constructor(name8, prefix, baseDecode) { | |
this.name = name8; | |
this.prefix = prefix; | |
if (prefix.codePointAt(0) === void 0) { | |
throw new Error("Invalid prefix character"); | |
} | |
this.prefixCodePoint = /** @type {number} */ | |
prefix.codePointAt(0); | |
this.baseDecode = baseDecode; | |
} | |
/** | |
* @param {string} text | |
*/ | |
decode(text) { | |
if (typeof text === "string") { | |
if (text.codePointAt(0) !== this.prefixCodePoint) { | |
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`); | |
} | |
return this.baseDecode(text.slice(this.prefix.length)); | |
} else { | |
throw Error("Can only multibase decode strings"); | |
} | |
} | |
/** | |
* @template {string} OtherPrefix | |
* @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder | |
* @returns {ComposedDecoder<Prefix|OtherPrefix>} | |
*/ | |
or(decoder) { | |
return or3(this, decoder); | |
} | |
}; | |
var ComposedDecoder3 = class { | |
/** | |
* @param {Decoders<Prefix>} decoders | |
*/ | |
constructor(decoders2) { | |
this.decoders = decoders2; | |
} | |
/** | |
* @template {string} OtherPrefix | |
* @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder | |
* @returns {ComposedDecoder<Prefix|OtherPrefix>} | |
*/ | |
or(decoder) { | |
return or3(this, decoder); | |
} | |
/** | |
* @param {string} input | |
* @returns {Uint8Array} | |
*/ | |
decode(input) { | |
const prefix = ( | |
/** @type {Prefix} */ | |
input[0] | |
); | |
const decoder = this.decoders[prefix]; | |
if (decoder) { | |
return decoder.decode(input); | |
} else { | |
throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`); | |
} | |
} | |
}; | |
var or3 = (left, right) => new ComposedDecoder3( | |
/** @type {Decoders<L|R>} */ | |
{ | |
...left.decoders || { [ | |
/** @type API.UnibaseDecoder<L> */ | |
left.prefix | |
]: left }, | |
...right.decoders || { [ | |
/** @type API.UnibaseDecoder<R> */ | |
right.prefix | |
]: right } | |
} | |
); | |
var Codec3 = class { | |
/** | |
* @param {Base} name | |
* @param {Prefix} prefix | |
* @param {(bytes:Uint8Array) => string} baseEncode | |
* @param {(text:string) => Uint8Array} baseDecode | |
*/ | |
constructor(name8, prefix, baseEncode, baseDecode) { | |
this.name = name8; | |
this.prefix = prefix; | |
this.baseEncode = baseEncode; | |
this.baseDecode = baseDecode; | |
this.encoder = new Encoder3(name8, prefix, baseEncode); | |
this.decoder = new Decoder3(name8, prefix, baseDecode); | |
} | |
/** | |
* @param {Uint8Array} input | |
*/ | |
encode(input) { | |
return this.encoder.encode(input); | |
} | |
/** | |
* @param {string} input | |
*/ | |
decode(input) { | |
return this.decoder.decode(input); | |
} | |
}; | |
var from3 = ({ name: name8, prefix, encode: encode39, decode: decode50 }) => new Codec3(name8, prefix, encode39, decode50); | |
var baseX3 = ({ prefix, name: name8, alphabet: alphabet5 }) => { | |
const { encode: encode39, decode: decode50 } = base_x_default3(alphabet5, name8); | |
return from3({ | |
prefix, | |
name: name8, | |
encode: encode39, | |
/** | |
* @param {string} text | |
*/ | |
decode: (text) => coerce3(decode50(text)) | |
}); | |
}; | |
var decode6 = (string3, alphabet5, bitsPerChar, name8) => { | |
const codes8 = {}; | |
for (let i = 0; i < alphabet5.length; ++i) { | |
codes8[alphabet5[i]] = i; | |
} | |
let end = string3.length; | |
while (string3[end - 1] === "=") { | |
--end; | |
} | |
const out = new Uint8Array(end * bitsPerChar / 8 | 0); | |
let bits2 = 0; | |
let buffer3 = 0; | |
let written = 0; | |
for (let i = 0; i < end; ++i) { | |
const value = codes8[string3[i]]; | |
if (value === void 0) { | |
throw new SyntaxError(`Non-${name8} character`); | |
} | |
buffer3 = buffer3 << bitsPerChar | value; | |
bits2 += bitsPerChar; | |
if (bits2 >= 8) { | |
bits2 -= 8; | |
out[written++] = 255 & buffer3 >> bits2; | |
} | |
} | |
if (bits2 >= bitsPerChar || 255 & buffer3 << 8 - bits2) { | |
throw new SyntaxError("Unexpected end of data"); | |
} | |
return out; | |
}; | |
var encode4 = (data, alphabet5, bitsPerChar) => { | |
const pad = alphabet5[alphabet5.length - 1] === "="; | |
const mask = (1 << bitsPerChar) - 1; | |
let out = ""; | |
let bits2 = 0; | |
let buffer3 = 0; | |
for (let i = 0; i < data.length; ++i) { | |
buffer3 = buffer3 << 8 | data[i]; | |
bits2 += 8; | |
while (bits2 > bitsPerChar) { | |
bits2 -= bitsPerChar; | |
out += alphabet5[mask & buffer3 >> bits2]; | |
} | |
} | |
if (bits2) { | |
out += alphabet5[mask & buffer3 << bitsPerChar - bits2]; | |
} | |
if (pad) { | |
while (out.length * bitsPerChar & 7) { | |
out += "="; | |
} | |
} | |
return out; | |
}; | |
var rfc46483 = ({ name: name8, prefix, bitsPerChar, alphabet: alphabet5 }) => { | |
return from3({ | |
prefix, | |
name: name8, | |
encode(input) { | |
return encode4(input, alphabet5, bitsPerChar); | |
}, | |
decode(input) { | |
return decode6(input, alphabet5, bitsPerChar, name8); | |
} | |
}); | |
}; | |
// node_modules/uint8arrays/node_modules/multiformats/src/bases/identity.js | |
var identity = from3({ | |
prefix: "\0", | |
name: "identity", | |
encode: (buf3) => toString2(buf3), | |
decode: (str) => fromString2(str) | |
}); | |
// node_modules/uint8arrays/node_modules/multiformats/src/bases/base2.js | |
var base2_exports = {}; | |
__export(base2_exports, { | |
base2: () => base22 | |
}); | |
var base22 = rfc46483({ | |
prefix: "0", | |
name: "base2", | |
alphabet: "01", | |
bitsPerChar: 1 | |
}); | |
// node_modules/uint8arrays/node_modules/multiformats/src/bases/base8.js | |
var base8_exports = {}; | |
__export(base8_exports, { | |
base8: () => base8 | |
}); | |
var base8 = rfc46483({ | |
prefix: "7", | |
name: "base8", | |
alphabet: "01234567", | |
bitsPerChar: 3 | |
}); | |
// node_modules/uint8arrays/node_modules/multiformats/src/bases/base10.js | |
var base10_exports = {}; | |
__export(base10_exports, { | |
base10: () => base10 | |
}); | |
var base10 = baseX3({ | |
prefix: "9", | |
name: "base10", | |
alphabet: "0123456789" | |
}); | |
// node_modules/uint8arrays/node_modules/multiformats/src/bases/base16.js | |
var base16_exports = {}; | |
__export(base16_exports, { | |
base16: () => base16, | |
base16upper: () => base16upper | |
}); | |
var base16 = rfc46483({ | |
prefix: "f", | |
name: "base16", | |
alphabet: "0123456789abcdef", | |
bitsPerChar: 4 | |
}); | |
var base16upper = rfc46483({ | |
prefix: "F", | |
name: "base16upper", | |
alphabet: "0123456789ABCDEF", | |
bitsPerChar: 4 | |
}); | |
// node_modules/uint8arrays/node_modules/multiformats/src/bases/base32.js | |
var base32_exports2 = {}; | |
__export(base32_exports2, { | |
base32: () => base323, | |
base32hex: () => base32hex3, | |
base32hexpad: () => base32hexpad3, | |
base32hexpadupper: () => base32hexpadupper3, | |
base32hexupper: () => base32hexupper3, | |
base32pad: () => base32pad3, | |
base32padupper: () => base32padupper3, | |
base32upper: () => base32upper3, | |
base32z: () => base32z3 | |
}); | |
var base323 = rfc46483({ | |
prefix: "b", | |
name: "base32", | |
alphabet: "abcdefghijklmnopqrstuvwxyz234567", | |
bitsPerChar: 5 | |
}); | |
var base32upper3 = rfc46483({ | |
prefix: "B", | |
name: "base32upper", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", | |
bitsPerChar: 5 | |
}); | |
var base32pad3 = rfc46483({ | |
prefix: "c", | |
name: "base32pad", | |
alphabet: "abcdefghijklmnopqrstuvwxyz234567=", | |
bitsPerChar: 5 | |
}); | |
var base32padupper3 = rfc46483({ | |
prefix: "C", | |
name: "base32padupper", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=", | |
bitsPerChar: 5 | |
}); | |
var base32hex3 = rfc46483({ | |
prefix: "v", | |
name: "base32hex", | |
alphabet: "0123456789abcdefghijklmnopqrstuv", | |
bitsPerChar: 5 | |
}); | |
var base32hexupper3 = rfc46483({ | |
prefix: "V", | |
name: "base32hexupper", | |
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV", | |
bitsPerChar: 5 | |
}); | |
var base32hexpad3 = rfc46483({ | |
prefix: "t", | |
name: "base32hexpad", | |
alphabet: "0123456789abcdefghijklmnopqrstuv=", | |
bitsPerChar: 5 | |
}); | |
var base32hexpadupper3 = rfc46483({ | |
prefix: "T", | |
name: "base32hexpadupper", | |
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=", | |
bitsPerChar: 5 | |
}); | |
var base32z3 = rfc46483({ | |
prefix: "h", | |
name: "base32z", | |
alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769", | |
bitsPerChar: 5 | |
}); | |
// node_modules/uint8arrays/node_modules/multiformats/src/bases/base36.js | |
var base36_exports = {}; | |
__export(base36_exports, { | |
base36: () => base36, | |
base36upper: () => base36upper | |
}); | |
var base36 = baseX3({ | |
prefix: "k", | |
name: "base36", | |
alphabet: "0123456789abcdefghijklmnopqrstuvwxyz" | |
}); | |
var base36upper = baseX3({ | |
prefix: "K", | |
name: "base36upper", | |
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
}); | |
// node_modules/uint8arrays/node_modules/multiformats/src/bases/base58.js | |
var base58_exports2 = {}; | |
__export(base58_exports2, { | |
base58btc: () => base58btc3, | |
base58flickr: () => base58flickr3 | |
}); | |
var base58btc3 = baseX3({ | |
name: "base58btc", | |
prefix: "z", | |
alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" | |
}); | |
var base58flickr3 = baseX3({ | |
name: "base58flickr", | |
prefix: "Z", | |
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ" | |
}); | |
// node_modules/uint8arrays/node_modules/multiformats/src/bases/base64.js | |
var base64_exports2 = {}; | |
__export(base64_exports2, { | |
base64: () => base643, | |
base64pad: () => base64pad3, | |
base64url: () => base64url3, | |
base64urlpad: () => base64urlpad3 | |
}); | |
var base643 = rfc46483({ | |
prefix: "m", | |
name: "base64", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", | |
bitsPerChar: 6 | |
}); | |
var base64pad3 = rfc46483({ | |
prefix: "M", | |
name: "base64pad", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", | |
bitsPerChar: 6 | |
}); | |
var base64url3 = rfc46483({ | |
prefix: "u", | |
name: "base64url", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", | |
bitsPerChar: 6 | |
}); | |
var base64urlpad3 = rfc46483({ | |
prefix: "U", | |
name: "base64urlpad", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=", | |
bitsPerChar: 6 | |
}); | |
// node_modules/uint8arrays/node_modules/multiformats/src/bases/base256emoji.js | |
var base256emoji_exports = {}; | |
__export(base256emoji_exports, { | |
base256emoji: () => base256emoji | |
}); | |
var alphabet = Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"); | |
var alphabetBytesToChars = ( | |
/** @type {string[]} */ | |
alphabet.reduce( | |
(p, c, i) => { | |
p[i] = c; | |
return p; | |
}, | |
/** @type {string[]} */ | |
[] | |
) | |
); | |
var alphabetCharsToBytes = ( | |
/** @type {number[]} */ | |
alphabet.reduce( | |
(p, c, i) => { | |
p[ | |
/** @type {number} */ | |
c.codePointAt(0) | |
] = i; | |
return p; | |
}, | |
/** @type {number[]} */ | |
[] | |
) | |
); | |
function encode5(data) { | |
return data.reduce((p, c) => { | |
p += alphabetBytesToChars[c]; | |
return p; | |
}, ""); | |
} | |
function decode7(str) { | |
const byts = []; | |
for (const char of str) { | |
const byt = alphabetCharsToBytes[ | |
/** @type {number} */ | |
char.codePointAt(0) | |
]; | |
if (byt === void 0) { | |
throw new Error(`Non-base256emoji character: ${char}`); | |
} | |
byts.push(byt); | |
} | |
return new Uint8Array(byts); | |
} | |
var base256emoji = from3({ | |
prefix: "\u{1F680}", | |
name: "base256emoji", | |
encode: encode5, | |
decode: decode7 | |
}); | |
// node_modules/uint8arrays/node_modules/multiformats/src/hashes/sha2-browser.js | |
var sha2_browser_exports = {}; | |
__export(sha2_browser_exports, { | |
sha256: () => sha256, | |
sha512: () => sha512 | |
}); | |
// node_modules/uint8arrays/node_modules/multiformats/vendor/varint.js | |
var encode_12 = encode6; | |
var MSB2 = 128; | |
var REST2 = 127; | |
var MSBALL2 = ~REST2; | |
var INT2 = Math.pow(2, 31); | |
function encode6(num, out, offset) { | |
out = out || []; | |
offset = offset || 0; | |
var oldOffset = offset; | |
while (num >= INT2) { | |
out[offset++] = num & 255 | MSB2; | |
num /= 128; | |
} | |
while (num & MSBALL2) { | |
out[offset++] = num & 255 | MSB2; | |
num >>>= 7; | |
} | |
out[offset] = num | 0; | |
encode6.bytes = offset - oldOffset + 1; | |
return out; | |
} | |
var decode8 = read2; | |
var MSB$12 = 128; | |
var REST$12 = 127; | |
function read2(buf3, offset) { | |
var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf3.length; | |
do { | |
if (counter >= l) { | |
read2.bytes = 0; | |
throw new RangeError("Could not decode varint"); | |
} | |
b = buf3[counter++]; | |
res += shift < 28 ? (b & REST$12) << shift : (b & REST$12) * Math.pow(2, shift); | |
shift += 7; | |
} while (b >= MSB$12); | |
read2.bytes = counter - offset; | |
return res; | |
} | |
var N12 = Math.pow(2, 7); | |
var N22 = Math.pow(2, 14); | |
var N32 = Math.pow(2, 21); | |
var N42 = Math.pow(2, 28); | |
var N52 = Math.pow(2, 35); | |
var N62 = Math.pow(2, 42); | |
var N72 = Math.pow(2, 49); | |
var N82 = Math.pow(2, 56); | |
var N92 = Math.pow(2, 63); | |
var length2 = function(value) { | |
return value < N12 ? 1 : value < N22 ? 2 : value < N32 ? 3 : value < N42 ? 4 : value < N52 ? 5 : value < N62 ? 6 : value < N72 ? 7 : value < N82 ? 8 : value < N92 ? 9 : 10; | |
}; | |
var varint2 = { | |
encode: encode_12, | |
decode: decode8, | |
encodingLength: length2 | |
}; | |
var _brrp_varint2 = varint2; | |
var varint_default2 = _brrp_varint2; | |
// node_modules/uint8arrays/node_modules/multiformats/src/varint.js | |
var decode9 = (data, offset = 0) => { | |
const code9 = varint_default2.decode(data, offset); | |
return [code9, varint_default2.decode.bytes]; | |
}; | |
var encodeTo2 = (int, target, offset = 0) => { | |
varint_default2.encode(int, target, offset); | |
return target; | |
}; | |
var encodingLength2 = (int) => { | |
return varint_default2.encodingLength(int); | |
}; | |
// node_modules/uint8arrays/node_modules/multiformats/src/hashes/digest.js | |
var create2 = (code9, digest5) => { | |
const size = digest5.byteLength; | |
const sizeOffset = encodingLength2(code9); | |
const digestOffset = sizeOffset + encodingLength2(size); | |
const bytes3 = new Uint8Array(digestOffset + size); | |
encodeTo2(code9, bytes3, 0); | |
encodeTo2(size, bytes3, sizeOffset); | |
bytes3.set(digest5, digestOffset); | |
return new Digest2(code9, size, digest5, bytes3); | |
}; | |
var decode10 = (multihash) => { | |
const bytes3 = coerce3(multihash); | |
const [code9, sizeOffset] = decode9(bytes3); | |
const [size, digestOffset] = decode9(bytes3.subarray(sizeOffset)); | |
const digest5 = bytes3.subarray(sizeOffset + digestOffset); | |
if (digest5.byteLength !== size) { | |
throw new Error("Incorrect length"); | |
} | |
return new Digest2(code9, size, digest5, bytes3); | |
}; | |
var equals5 = (a, b) => { | |
if (a === b) { | |
return true; | |
} else { | |
const data = ( | |
/** @type {{code?:unknown, size?:unknown, bytes?:unknown}} */ | |
b | |
); | |
return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals4(a.bytes, data.bytes); | |
} | |
}; | |
var Digest2 = class { | |
/** | |
* Creates a multihash digest. | |
* | |
* @param {Code} code | |
* @param {Size} size | |
* @param {Uint8Array} digest | |
* @param {Uint8Array} bytes | |
*/ | |
constructor(code9, size, digest5, bytes3) { | |
this.code = code9; | |
this.size = size; | |
this.digest = digest5; | |
this.bytes = bytes3; | |
} | |
}; | |
// node_modules/uint8arrays/node_modules/multiformats/src/hashes/hasher.js | |
var from4 = ({ name: name8, code: code9, encode: encode39 }) => new Hasher(name8, code9, encode39); | |
var Hasher = class { | |
/** | |
* | |
* @param {Name} name | |
* @param {Code} code | |
* @param {(input: Uint8Array) => Await<Uint8Array>} encode | |
*/ | |
constructor(name8, code9, encode39) { | |
this.name = name8; | |
this.code = code9; | |
this.encode = encode39; | |
} | |
/** | |
* @param {Uint8Array} input | |
* @returns {Await<Digest.Digest<Code, number>>} | |
*/ | |
digest(input) { | |
if (input instanceof Uint8Array) { | |
const result = this.encode(input); | |
return result instanceof Uint8Array ? create2(this.code, result) : result.then((digest5) => create2(this.code, digest5)); | |
} else { | |
throw Error("Unknown type, must be binary type"); | |
} | |
} | |
}; | |
// node_modules/uint8arrays/node_modules/multiformats/src/hashes/sha2-browser.js | |
var sha = (name8) => ( | |
/** | |
* @param {Uint8Array} data | |
*/ | |
async (data) => new Uint8Array(await crypto.subtle.digest(name8, data)) | |
); | |
var sha256 = from4({ | |
name: "sha2-256", | |
code: 18, | |
encode: sha("SHA-256") | |
}); | |
var sha512 = from4({ | |
name: "sha2-512", | |
code: 19, | |
encode: sha("SHA-512") | |
}); | |
// node_modules/uint8arrays/node_modules/multiformats/src/hashes/identity.js | |
var identity_exports2 = {}; | |
__export(identity_exports2, { | |
identity: () => identity2 | |
}); | |
var code2 = 0; | |
var name = "identity"; | |
var encode7 = coerce3; | |
var digest = (input) => create2(code2, encode7(input)); | |
var identity2 = { code: code2, name, encode: encode7, digest }; | |
// node_modules/uint8arrays/node_modules/multiformats/src/codecs/json.js | |
var textEncoder = new TextEncoder(); | |
var textDecoder = new TextDecoder(); | |
// node_modules/uint8arrays/node_modules/multiformats/src/cid.js | |
var format2 = (link, base14) => { | |
const { bytes: bytes3, version: version4 } = link; | |
switch (version4) { | |
case 0: | |
return toStringV02( | |
bytes3, | |
baseCache2(link), | |
/** @type {API.MultibaseEncoder<"z">} */ | |
base14 || base58btc3.encoder | |
); | |
default: | |
return toStringV12( | |
bytes3, | |
baseCache2(link), | |
/** @type {API.MultibaseEncoder<Prefix>} */ | |
base14 || base323.encoder | |
); | |
} | |
}; | |
var cache2 = /* @__PURE__ */ new WeakMap(); | |
var baseCache2 = (cid) => { | |
const baseCache9 = cache2.get(cid); | |
if (baseCache9 == null) { | |
const baseCache10 = /* @__PURE__ */ new Map(); | |
cache2.set(cid, baseCache10); | |
return baseCache10; | |
} | |
return baseCache9; | |
}; | |
var CID2 = class _CID { | |
/** | |
* @param {Version} version - Version of the CID | |
* @param {Format} code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv | |
* @param {API.MultihashDigest<Alg>} multihash - (Multi)hash of the of the content. | |
* @param {Uint8Array} bytes | |
* | |
*/ | |
constructor(version4, code9, multihash, bytes3) { | |
this.code = code9; | |
this.version = version4; | |
this.multihash = multihash; | |
this.bytes = bytes3; | |
this["/"] = bytes3; | |
} | |
/** | |
* Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes` | |
* please either use `CID.asCID(cid)` or switch to new signalling mechanism | |
* | |
* @deprecated | |
*/ | |
get asCID() { | |
return this; | |
} | |
// ArrayBufferView | |
get byteOffset() { | |
return this.bytes.byteOffset; | |
} | |
// ArrayBufferView | |
get byteLength() { | |
return this.bytes.byteLength; | |
} | |
/** | |
* @returns {CID<Data, API.DAG_PB, API.SHA_256, 0>} | |
*/ | |
toV0() { | |
switch (this.version) { | |
case 0: { | |
return ( | |
/** @type {CID<Data, API.DAG_PB, API.SHA_256, 0>} */ | |
this | |
); | |
} | |
case 1: { | |
const { code: code9, multihash } = this; | |
if (code9 !== DAG_PB_CODE2) { | |
throw new Error("Cannot convert a non dag-pb CID to CIDv0"); | |
} | |
if (multihash.code !== SHA_256_CODE2) { | |
throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0"); | |
} | |
return ( | |
/** @type {CID<Data, API.DAG_PB, API.SHA_256, 0>} */ | |
_CID.createV0( | |
/** @type {API.MultihashDigest<API.SHA_256>} */ | |
multihash | |
) | |
); | |
} | |
default: { | |
throw Error( | |
`Can not convert CID version ${this.version} to version 0. This is a bug please report` | |
); | |
} | |
} | |
} | |
/** | |
* @returns {CID<Data, Format, Alg, 1>} | |
*/ | |
toV1() { | |
switch (this.version) { | |
case 0: { | |
const { code: code9, digest: digest5 } = this.multihash; | |
const multihash = create2(code9, digest5); | |
return ( | |
/** @type {CID<Data, Format, Alg, 1>} */ | |
_CID.createV1(this.code, multihash) | |
); | |
} | |
case 1: { | |
return ( | |
/** @type {CID<Data, Format, Alg, 1>} */ | |
this | |
); | |
} | |
default: { | |
throw Error( | |
`Can not convert CID version ${this.version} to version 1. This is a bug please report` | |
); | |
} | |
} | |
} | |
/** | |
* @param {unknown} other | |
* @returns {other is CID<Data, Format, Alg, Version>} | |
*/ | |
equals(other) { | |
return _CID.equals(this, other); | |
} | |
/** | |
* @template {unknown} Data | |
* @template {number} Format | |
* @template {number} Alg | |
* @template {API.Version} Version | |
* @param {API.Link<Data, Format, Alg, Version>} self | |
* @param {unknown} other | |
* @returns {other is CID} | |
*/ | |
static equals(self2, other) { | |
const unknown = ( | |
/** @type {{code?:unknown, version?:unknown, multihash?:unknown}} */ | |
other | |
); | |
return unknown && self2.code === unknown.code && self2.version === unknown.version && equals5(self2.multihash, unknown.multihash); | |
} | |
/** | |
* @param {API.MultibaseEncoder<string>} [base] | |
* @returns {string} | |
*/ | |
toString(base14) { | |
return format2(this, base14); | |
} | |
toJSON() { | |
return { "/": format2(this) }; | |
} | |
link() { | |
return this; | |
} | |
get [Symbol.toStringTag]() { | |
return "CID"; | |
} | |
// Legacy | |
[Symbol.for("nodejs.util.inspect.custom")]() { | |
return `CID(${this.toString()})`; | |
} | |
/** | |
* Takes any input `value` and returns a `CID` instance if it was | |
* a `CID` otherwise returns `null`. If `value` is instanceof `CID` | |
* it will return value back. If `value` is not instance of this CID | |
* class, but is compatible CID it will return new instance of this | |
* `CID` class. Otherwise returns null. | |
* | |
* This allows two different incompatible versions of CID library to | |
* co-exist and interop as long as binary interface is compatible. | |
* | |
* @template {unknown} Data | |
* @template {number} Format | |
* @template {number} Alg | |
* @template {API.Version} Version | |
* @template {unknown} U | |
* @param {API.Link<Data, Format, Alg, Version>|U} input | |
* @returns {CID<Data, Format, Alg, Version>|null} | |
*/ | |
static asCID(input) { | |
if (input == null) { | |
return null; | |
} | |
const value = ( | |
/** @type {any} */ | |
input | |
); | |
if (value instanceof _CID) { | |
return value; | |
} else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) { | |
const { version: version4, code: code9, multihash, bytes: bytes3 } = value; | |
return new _CID( | |
version4, | |
code9, | |
/** @type {API.MultihashDigest<Alg>} */ | |
multihash, | |
bytes3 || encodeCID2(version4, code9, multihash.bytes) | |
); | |
} else if (value[cidSymbol2] === true) { | |
const { version: version4, multihash, code: code9 } = value; | |
const digest5 = ( | |
/** @type {API.MultihashDigest<Alg>} */ | |
decode10(multihash) | |
); | |
return _CID.create(version4, code9, digest5); | |
} else { | |
return null; | |
} | |
} | |
/** | |
* | |
* @template {unknown} Data | |
* @template {number} Format | |
* @template {number} Alg | |
* @template {API.Version} Version | |
* @param {Version} version - Version of the CID | |
* @param {Format} code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv | |
* @param {API.MultihashDigest<Alg>} digest - (Multi)hash of the of the content. | |
* @returns {CID<Data, Format, Alg, Version>} | |
*/ | |
static create(version4, code9, digest5) { | |
if (typeof code9 !== "number") { | |
throw new Error("String codecs are no longer supported"); | |
} | |
if (!(digest5.bytes instanceof Uint8Array)) { | |
throw new Error("Invalid digest"); | |
} | |
switch (version4) { | |
case 0: { | |
if (code9 !== DAG_PB_CODE2) { | |
throw new Error( | |
`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE2}) block encoding` | |
); | |
} else { | |
return new _CID(version4, code9, digest5, digest5.bytes); | |
} | |
} | |
case 1: { | |
const bytes3 = encodeCID2(version4, code9, digest5.bytes); | |
return new _CID(version4, code9, digest5, bytes3); | |
} | |
default: { | |
throw new Error("Invalid version"); | |
} | |
} | |
} | |
/** | |
* Simplified version of `create` for CIDv0. | |
* | |
* @template {unknown} [T=unknown] | |
* @param {API.MultihashDigest<typeof SHA_256_CODE>} digest - Multihash. | |
* @returns {CID<T, typeof DAG_PB_CODE, typeof SHA_256_CODE, 0>} | |
*/ | |
static createV0(digest5) { | |
return _CID.create(0, DAG_PB_CODE2, digest5); | |
} | |
/** | |
* Simplified version of `create` for CIDv1. | |
* | |
* @template {unknown} Data | |
* @template {number} Code | |
* @template {number} Alg | |
* @param {Code} code - Content encoding format code. | |
* @param {API.MultihashDigest<Alg>} digest - Miltihash of the content. | |
* @returns {CID<Data, Code, Alg, 1>} | |
*/ | |
static createV1(code9, digest5) { | |
return _CID.create(1, code9, digest5); | |
} | |
/** | |
* Decoded a CID from its binary representation. The byte array must contain | |
* only the CID with no additional bytes. | |
* | |
* An error will be thrown if the bytes provided do not contain a valid | |
* binary representation of a CID. | |
* | |
* @template {unknown} Data | |
* @template {number} Code | |
* @template {number} Alg | |
* @template {API.Version} Ver | |
* @param {API.ByteView<API.Link<Data, Code, Alg, Ver>>} bytes | |
* @returns {CID<Data, Code, Alg, Ver>} | |
*/ | |
static decode(bytes3) { | |
const [cid, remainder] = _CID.decodeFirst(bytes3); | |
if (remainder.length) { | |
throw new Error("Incorrect length"); | |
} | |
return cid; | |
} | |
/** | |
* Decoded a CID from its binary representation at the beginning of a byte | |
* array. | |
* | |
* Returns an array with the first element containing the CID and the second | |
* element containing the remainder of the original byte array. The remainder | |
* will be a zero-length byte array if the provided bytes only contained a | |
* binary CID representation. | |
* | |
* @template {unknown} T | |
* @template {number} C | |
* @template {number} A | |
* @template {API.Version} V | |
* @param {API.ByteView<API.Link<T, C, A, V>>} bytes | |
* @returns {[CID<T, C, A, V>, Uint8Array]} | |
*/ | |
static decodeFirst(bytes3) { | |
const specs = _CID.inspectBytes(bytes3); | |
const prefixSize = specs.size - specs.multihashSize; | |
const multihashBytes = coerce3( | |
bytes3.subarray(prefixSize, prefixSize + specs.multihashSize) | |
); | |
if (multihashBytes.byteLength !== specs.multihashSize) { | |
throw new Error("Incorrect length"); | |
} | |
const digestBytes = multihashBytes.subarray( | |
specs.multihashSize - specs.digestSize | |
); | |
const digest5 = new Digest2( | |
specs.multihashCode, | |
specs.digestSize, | |
digestBytes, | |
multihashBytes | |
); | |
const cid = specs.version === 0 ? _CID.createV0( | |
/** @type {API.MultihashDigest<API.SHA_256>} */ | |
digest5 | |
) : _CID.createV1(specs.codec, digest5); | |
return [ | |
/** @type {CID<T, C, A, V>} */ | |
cid, | |
bytes3.subarray(specs.size) | |
]; | |
} | |
/** | |
* Inspect the initial bytes of a CID to determine its properties. | |
* | |
* Involves decoding up to 4 varints. Typically this will require only 4 to 6 | |
* bytes but for larger multicodec code values and larger multihash digest | |
* lengths these varints can be quite large. It is recommended that at least | |
* 10 bytes be made available in the `initialBytes` argument for a complete | |
* inspection. | |
* | |
* @template {unknown} T | |
* @template {number} C | |
* @template {number} A | |
* @template {API.Version} V | |
* @param {API.ByteView<API.Link<T, C, A, V>>} initialBytes | |
* @returns {{ version:V, codec:C, multihashCode:A, digestSize:number, multihashSize:number, size:number }} | |
*/ | |
static inspectBytes(initialBytes) { | |
let offset = 0; | |
const next = () => { | |
const [i, length11] = decode9(initialBytes.subarray(offset)); | |
offset += length11; | |
return i; | |
}; | |
let version4 = ( | |
/** @type {V} */ | |
next() | |
); | |
let codec = ( | |
/** @type {C} */ | |
DAG_PB_CODE2 | |
); | |
if ( | |
/** @type {number} */ | |
version4 === 18 | |
) { | |
version4 = /** @type {V} */ | |
0; | |
offset = 0; | |
} else { | |
codec = /** @type {C} */ | |
next(); | |
} | |
if (version4 !== 0 && version4 !== 1) { | |
throw new RangeError(`Invalid CID version ${version4}`); | |
} | |
const prefixSize = offset; | |
const multihashCode = ( | |
/** @type {A} */ | |
next() | |
); | |
const digestSize = next(); | |
const size = offset + digestSize; | |
const multihashSize = size - prefixSize; | |
return { version: version4, codec, multihashCode, digestSize, multihashSize, size }; | |
} | |
/** | |
* Takes cid in a string representation and creates an instance. If `base` | |
* decoder is not provided will use a default from the configuration. It will | |
* throw an error if encoding of the CID is not compatible with supplied (or | |
* a default decoder). | |
* | |
* @template {string} Prefix | |
* @template {unknown} Data | |
* @template {number} Code | |
* @template {number} Alg | |
* @template {API.Version} Ver | |
* @param {API.ToString<API.Link<Data, Code, Alg, Ver>, Prefix>} source | |
* @param {API.MultibaseDecoder<Prefix>} [base] | |
* @returns {CID<Data, Code, Alg, Ver>} | |
*/ | |
static parse(source, base14) { | |
const [prefix, bytes3] = parseCIDtoBytes2(source, base14); | |
const cid = _CID.decode(bytes3); | |
if (cid.version === 0 && source[0] !== "Q") { | |
throw Error("Version 0 CID string must not include multibase prefix"); | |
} | |
baseCache2(cid).set(prefix, source); | |
return cid; | |
} | |
}; | |
var parseCIDtoBytes2 = (source, base14) => { | |
switch (source[0]) { | |
case "Q": { | |
const decoder = base14 || base58btc3; | |
return [ | |
/** @type {Prefix} */ | |
base58btc3.prefix, | |
decoder.decode(`${base58btc3.prefix}${source}`) | |
]; | |
} | |
case base58btc3.prefix: { | |
const decoder = base14 || base58btc3; | |
return [ | |
/** @type {Prefix} */ | |
base58btc3.prefix, | |
decoder.decode(source) | |
]; | |
} | |
case base323.prefix: { | |
const decoder = base14 || base323; | |
return [ | |
/** @type {Prefix} */ | |
base323.prefix, | |
decoder.decode(source) | |
]; | |
} | |
default: { | |
if (base14 == null) { | |
throw Error( | |
"To parse non base32 or base58btc encoded CID multibase decoder must be provided" | |
); | |
} | |
return [ | |
/** @type {Prefix} */ | |
source[0], | |
base14.decode(source) | |
]; | |
} | |
} | |
}; | |
var toStringV02 = (bytes3, cache10, base14) => { | |
const { prefix } = base14; | |
if (prefix !== base58btc3.prefix) { | |
throw Error(`Cannot string encode V0 in ${base14.name} encoding`); | |
} | |
const cid = cache10.get(prefix); | |
if (cid == null) { | |
const cid2 = base14.encode(bytes3).slice(1); | |
cache10.set(prefix, cid2); | |
return cid2; | |
} else { | |
return cid; | |
} | |
}; | |
var toStringV12 = (bytes3, cache10, base14) => { | |
const { prefix } = base14; | |
const cid = cache10.get(prefix); | |
if (cid == null) { | |
const cid2 = base14.encode(bytes3); | |
cache10.set(prefix, cid2); | |
return cid2; | |
} else { | |
return cid; | |
} | |
}; | |
var DAG_PB_CODE2 = 112; | |
var SHA_256_CODE2 = 18; | |
var encodeCID2 = (version4, code9, multihash) => { | |
const codeOffset = encodingLength2(version4); | |
const hashOffset = codeOffset + encodingLength2(code9); | |
const bytes3 = new Uint8Array(hashOffset + multihash.byteLength); | |
encodeTo2(version4, bytes3, 0); | |
encodeTo2(code9, bytes3, codeOffset); | |
bytes3.set(multihash, hashOffset); | |
return bytes3; | |
}; | |
var cidSymbol2 = Symbol.for("@ipld/js-cid/CID"); | |
// node_modules/uint8arrays/node_modules/multiformats/src/basics.js | |
var bases = { ...identity_exports, ...base2_exports, ...base8_exports, ...base10_exports, ...base16_exports, ...base32_exports2, ...base36_exports, ...base58_exports2, ...base64_exports2, ...base256emoji_exports }; | |
var hashes = { ...sha2_browser_exports, ...identity_exports2 }; | |
// node_modules/uint8arrays/dist/src/alloc.js | |
function alloc(size = 0) { | |
if (globalThis.Buffer?.alloc != null) { | |
return asUint8Array(globalThis.Buffer.alloc(size)); | |
} | |
return new Uint8Array(size); | |
} | |
function allocUnsafe(size = 0) { | |
if (globalThis.Buffer?.allocUnsafe != null) { | |
return asUint8Array(globalThis.Buffer.allocUnsafe(size)); | |
} | |
return new Uint8Array(size); | |
} | |
// node_modules/uint8arrays/dist/src/util/bases.js | |
function createCodec(name8, prefix, encode39, decode50) { | |
return { | |
name: name8, | |
prefix, | |
encoder: { | |
name: name8, | |
prefix, | |
encode: encode39 | |
}, | |
decoder: { | |
decode: decode50 | |
} | |
}; | |
} | |
var string = createCodec("utf8", "u", (buf3) => { | |
const decoder = new TextDecoder("utf8"); | |
return "u" + decoder.decode(buf3); | |
}, (str) => { | |
const encoder2 = new TextEncoder(); | |
return encoder2.encode(str.substring(1)); | |
}); | |
var ascii = createCodec("ascii", "a", (buf3) => { | |
let string3 = "a"; | |
for (let i = 0; i < buf3.length; i++) { | |
string3 += String.fromCharCode(buf3[i]); | |
} | |
return string3; | |
}, (str) => { | |
str = str.substring(1); | |
const buf3 = allocUnsafe(str.length); | |
for (let i = 0; i < str.length; i++) { | |
buf3[i] = str.charCodeAt(i); | |
} | |
return buf3; | |
}); | |
var BASES = { | |
utf8: string, | |
"utf-8": string, | |
hex: bases.base16, | |
latin1: ascii, | |
ascii, | |
binary: ascii, | |
...bases | |
}; | |
var bases_default = BASES; | |
// node_modules/uint8arrays/dist/src/from-string.js | |
function fromString3(string3, encoding = "utf8") { | |
const base14 = bases_default[encoding]; | |
if (base14 == null) { | |
throw new Error(`Unsupported encoding "${encoding}"`); | |
} | |
if ((encoding === "utf8" || encoding === "utf-8") && globalThis.Buffer != null && globalThis.Buffer.from != null) { | |
return asUint8Array(globalThis.Buffer.from(string3, "utf-8")); | |
} | |
return base14.decoder.decode(`${base14.prefix}${string3}`); | |
} | |
// node_modules/uint8arrays/dist/src/to-string.js | |
function toString3(array, encoding = "utf8") { | |
const base14 = bases_default[encoding]; | |
if (base14 == null) { | |
throw new Error(`Unsupported encoding "${encoding}"`); | |
} | |
if ((encoding === "utf8" || encoding === "utf-8") && globalThis.Buffer != null && globalThis.Buffer.from != null) { | |
return globalThis.Buffer.from(array.buffer, array.byteOffset, array.byteLength).toString("utf8"); | |
} | |
return base14.encoder.encode(array).substring(1); | |
} | |
// node_modules/interface-datastore/dist/src/key.js | |
var pathSepS = "/"; | |
var pathSepB = new TextEncoder().encode(pathSepS); | |
var pathSep = pathSepB[0]; | |
var Key = class _Key { | |
_buf; | |
/** | |
* @param {string | Uint8Array} s | |
* @param {boolean} [clean] | |
*/ | |
constructor(s, clean) { | |
if (typeof s === "string") { | |
this._buf = fromString3(s); | |
} else if (s instanceof Uint8Array) { | |
this._buf = s; | |
} else { | |
throw new Error("Invalid key, should be String of Uint8Array"); | |
} | |
if (clean == null) { | |
clean = true; | |
} | |
if (clean) { | |
this.clean(); | |
} | |
if (this._buf.byteLength === 0 || this._buf[0] !== pathSep) { | |
throw new Error("Invalid key"); | |
} | |
} | |
/** | |
* Convert to the string representation | |
* | |
* @param {import('uint8arrays/to-string').SupportedEncodings} [encoding='utf8'] - The encoding to use. | |
* @returns {string} | |
*/ | |
toString(encoding = "utf8") { | |
return toString3(this._buf, encoding); | |
} | |
/** | |
* Return the Uint8Array representation of the key | |
* | |
* @returns {Uint8Array} | |
*/ | |
uint8Array() { | |
return this._buf; | |
} | |
/** | |
* Return string representation of the key | |
* | |
* @returns {string} | |
*/ | |
get [Symbol.toStringTag]() { | |
return `Key(${this.toString()})`; | |
} | |
/** | |
* Constructs a key out of a namespace array. | |
* | |
* @param {Array<string>} list - The array of namespaces | |
* @returns {Key} | |
* | |
* @example | |
* ```js | |
* Key.withNamespaces(['one', 'two']) | |
* // => Key('/one/two') | |
* ``` | |
*/ | |
static withNamespaces(list) { | |
return new _Key(list.join(pathSepS)); | |
} | |
/** | |
* Returns a randomly (uuid) generated key. | |
* | |
* @returns {Key} | |
* | |
* @example | |
* ```js | |
* Key.random() | |
* // => Key('/f98719ea086343f7b71f32ea9d9d521d') | |
* ``` | |
*/ | |
static random() { | |
return new _Key(nanoid().replace(/-/g, "")); | |
} | |
/** | |
* @param {*} other | |
*/ | |
static asKey(other) { | |
if (other instanceof Uint8Array || typeof other === "string") { | |
return new _Key(other); | |
} | |
if (typeof other.uint8Array === "function") { | |
return new _Key(other.uint8Array()); | |
} | |
return null; | |
} | |
/** | |
* Cleanup the current key | |
* | |
* @returns {void} | |
*/ | |
clean() { | |
if (this._buf == null || this._buf.byteLength === 0) { | |
this._buf = pathSepB; | |
} | |
if (this._buf[0] !== pathSep) { | |
const bytes3 = new Uint8Array(this._buf.byteLength + 1); | |
bytes3.fill(pathSep, 0, 1); | |
bytes3.set(this._buf, 1); | |
this._buf = bytes3; | |
} | |
while (this._buf.byteLength > 1 && this._buf[this._buf.byteLength - 1] === pathSep) { | |
this._buf = this._buf.subarray(0, -1); | |
} | |
} | |
/** | |
* Check if the given key is sorted lower than ourself. | |
* | |
* @param {Key} key - The other Key to check against | |
* @returns {boolean} | |
*/ | |
less(key) { | |
const list1 = this.list(); | |
const list2 = key.list(); | |
for (let i = 0; i < list1.length; i++) { | |
if (list2.length < i + 1) { | |
return false; | |
} | |
const c1 = list1[i]; | |
const c2 = list2[i]; | |
if (c1 < c2) { | |
return true; | |
} else if (c1 > c2) { | |
return false; | |
} | |
} | |
return list1.length < list2.length; | |
} | |
/** | |
* Returns the key with all parts in reversed order. | |
* | |
* @returns {Key} | |
* | |
* @example | |
* ```js | |
* new Key('/Comedy/MontyPython/Actor:JohnCleese').reverse() | |
* // => Key('/Actor:JohnCleese/MontyPython/Comedy') | |
* ``` | |
*/ | |
reverse() { | |
return _Key.withNamespaces(this.list().slice().reverse()); | |
} | |
/** | |
* Returns the `namespaces` making up this Key. | |
* | |
* @returns {Array<string>} | |
*/ | |
namespaces() { | |
return this.list(); | |
} | |
/** Returns the "base" namespace of this key. | |
* | |
* @returns {string} | |
* | |
* @example | |
* ```js | |
* new Key('/Comedy/MontyPython/Actor:JohnCleese').baseNamespace() | |
* // => 'Actor:JohnCleese' | |
* ``` | |
*/ | |
baseNamespace() { | |
const ns = this.namespaces(); | |
return ns[ns.length - 1]; | |
} | |
/** | |
* Returns the `list` representation of this key. | |
* | |
* @returns {Array<string>} | |
* | |
* @example | |
* ```js | |
* new Key('/Comedy/MontyPython/Actor:JohnCleese').list() | |
* // => ['Comedy', 'MontyPythong', 'Actor:JohnCleese'] | |
* ``` | |
*/ | |
list() { | |
return this.toString().split(pathSepS).slice(1); | |
} | |
/** | |
* Returns the "type" of this key (value of last namespace). | |
* | |
* @returns {string} | |
* | |
* @example | |
* ```js | |
* new Key('/Comedy/MontyPython/Actor:JohnCleese').type() | |
* // => 'Actor' | |
* ``` | |
*/ | |
type() { | |
return namespaceType(this.baseNamespace()); | |
} | |
/** | |
* Returns the "name" of this key (field of last namespace). | |
* | |
* @returns {string} | |
* | |
* @example | |
* ```js | |
* new Key('/Comedy/MontyPython/Actor:JohnCleese').name() | |
* // => 'JohnCleese' | |
* ``` | |
*/ | |
name() { | |
return namespaceValue(this.baseNamespace()); | |
} | |
/** | |
* Returns an "instance" of this type key (appends value to namespace). | |
* | |
* @param {string} s - The string to append. | |
* @returns {Key} | |
* | |
* @example | |
* ```js | |
* new Key('/Comedy/MontyPython/Actor').instance('JohnClesse') | |
* // => Key('/Comedy/MontyPython/Actor:JohnCleese') | |
* ``` | |
*/ | |
instance(s) { | |
return new _Key(this.toString() + ":" + s); | |
} | |
/** | |
* Returns the "path" of this key (parent + type). | |
* | |
* @returns {Key} | |
* | |
* @example | |
* ```js | |
* new Key('/Comedy/MontyPython/Actor:JohnCleese').path() | |
* // => Key('/Comedy/MontyPython/Actor') | |
* ``` | |
*/ | |
path() { | |
let p = this.parent().toString(); | |
if (!p.endsWith(pathSepS)) { | |
p += pathSepS; | |
} | |
p += this.type(); | |
return new _Key(p); | |
} | |
/** | |
* Returns the `parent` Key of this Key. | |
* | |
* @returns {Key} | |
* | |
* @example | |
* ```js | |
* new Key("/Comedy/MontyPython/Actor:JohnCleese").parent() | |
* // => Key("/Comedy/MontyPython") | |
* ``` | |
*/ | |
parent() { | |
const list = this.list(); | |
if (list.length === 1) { | |
return new _Key(pathSepS); | |
} | |
return new _Key(list.slice(0, -1).join(pathSepS)); | |
} | |
/** | |
* Returns the `child` Key of this Key. | |
* | |
* @param {Key} key - The child Key to add | |
* @returns {Key} | |
* | |
* @example | |
* ```js | |
* new Key('/Comedy/MontyPython').child(new Key('Actor:JohnCleese')) | |
* // => Key('/Comedy/MontyPython/Actor:JohnCleese') | |
* ``` | |
*/ | |
child(key) { | |
if (this.toString() === pathSepS) { | |
return key; | |
} else if (key.toString() === pathSepS) { | |
return this; | |
} | |
return new _Key(this.toString() + key.toString(), false); | |
} | |
/** | |
* Returns whether this key is a prefix of `other` | |
* | |
* @param {Key} other - The other key to test against | |
* @returns {boolean} | |
* | |
* @example | |
* ```js | |
* new Key('/Comedy').isAncestorOf('/Comedy/MontyPython') | |
* // => true | |
* ``` | |
*/ | |
isAncestorOf(other) { | |
if (other.toString() === this.toString()) { | |
return false; | |
} | |
return other.toString().startsWith(this.toString()); | |
} | |
/** | |
* Returns whether this key is a contains another as prefix. | |
* | |
* @param {Key} other - The other Key to test against | |
* @returns {boolean} | |
* | |
* @example | |
* ```js | |
* new Key('/Comedy/MontyPython').isDecendantOf('/Comedy') | |
* // => true | |
* ``` | |
*/ | |
isDecendantOf(other) { | |
if (other.toString() === this.toString()) { | |
return false; | |
} | |
return this.toString().startsWith(other.toString()); | |
} | |
/** | |
* Checks if this key has only one namespace. | |
* | |
* @returns {boolean} | |
*/ | |
isTopLevel() { | |
return this.list().length === 1; | |
} | |
/** | |
* Concats one or more Keys into one new Key. | |
* | |
* @param {Array<Key>} keys - The array of keys to concatenate | |
* @returns {Key} | |
*/ | |
concat(...keys) { | |
return _Key.withNamespaces([...this.namespaces(), ...flatten(keys.map((key) => key.namespaces()))]); | |
} | |
}; | |
function namespaceType(ns) { | |
const parts = ns.split(":"); | |
if (parts.length < 2) { | |
return ""; | |
} | |
return parts.slice(0, -1).join(":"); | |
} | |
function namespaceValue(ns) { | |
const parts = ns.split(":"); | |
return parts[parts.length - 1]; | |
} | |
function flatten(arr) { | |
return [].concat(...arr); | |
} | |
// node_modules/datastore-core/dist/src/shard.js | |
var SHARDING_FN = "SHARDING"; | |
// node_modules/it-all/dist/src/index.js | |
function isAsyncIterable4(thing) { | |
return thing[Symbol.asyncIterator] != null; | |
} | |
function all(source) { | |
if (isAsyncIterable4(source)) { | |
return (async () => { | |
const arr2 = []; | |
for await (const entry of source) { | |
arr2.push(entry); | |
} | |
return arr2; | |
})(); | |
} | |
const arr = []; | |
for (const entry of source) { | |
arr.push(entry); | |
} | |
return arr; | |
} | |
var src_default5 = all; | |
// node_modules/it-sort/dist/src/index.js | |
function isAsyncIterable5(thing) { | |
return thing[Symbol.asyncIterator] != null; | |
} | |
function sort(source, sorter) { | |
if (isAsyncIterable5(source)) { | |
return async function* () { | |
const arr = await src_default5(source); | |
yield* arr.sort(sorter); | |
}(); | |
} | |
return function* () { | |
const arr = src_default5(source); | |
yield* arr.sort(sorter); | |
}(); | |
} | |
var src_default6 = sort; | |
// node_modules/it-take/dist/src/index.js | |
function isAsyncIterable6(thing) { | |
return thing[Symbol.asyncIterator] != null; | |
} | |
function take(source, limit) { | |
if (isAsyncIterable6(source)) { | |
return async function* () { | |
let items = 0; | |
if (limit < 1) { | |
return; | |
} | |
for await (const entry of source) { | |
yield entry; | |
items++; | |
if (items === limit) { | |
return; | |
} | |
} | |
}(); | |
} | |
return function* () { | |
let items = 0; | |
if (limit < 1) { | |
return; | |
} | |
for (const entry of source) { | |
yield entry; | |
items++; | |
if (items === limit) { | |
return; | |
} | |
} | |
}(); | |
} | |
var src_default7 = take; | |
// node_modules/datastore-core/dist/src/base.js | |
var BaseDatastore = class { | |
put(key, val, options) { | |
return Promise.reject(new Error(".put is not implemented")); | |
} | |
get(key, options) { | |
return Promise.reject(new Error(".get is not implemented")); | |
} | |
has(key, options) { | |
return Promise.reject(new Error(".has is not implemented")); | |
} | |
delete(key, options) { | |
return Promise.reject(new Error(".delete is not implemented")); | |
} | |
async *putMany(source, options = {}) { | |
for await (const { key, value } of source) { | |
await this.put(key, value, options); | |
yield key; | |
} | |
} | |
async *getMany(source, options = {}) { | |
for await (const key of source) { | |
yield { | |
key, | |
value: await this.get(key, options) | |
}; | |
} | |
} | |
async *deleteMany(source, options = {}) { | |
for await (const key of source) { | |
await this.delete(key, options); | |
yield key; | |
} | |
} | |
batch() { | |
let puts = []; | |
let dels = []; | |
return { | |
put(key, value) { | |
puts.push({ key, value }); | |
}, | |
delete(key) { | |
dels.push(key); | |
}, | |
commit: async (options) => { | |
await src_default(this.putMany(puts, options)); | |
puts = []; | |
await src_default(this.deleteMany(dels, options)); | |
dels = []; | |
} | |
}; | |
} | |
/** | |
* Extending classes should override `query` or implement this method | |
*/ | |
// eslint-disable-next-line require-yield | |
async *_all(q, options) { | |
throw new Error("._all is not implemented"); | |
} | |
/** | |
* Extending classes should override `queryKeys` or implement this method | |
*/ | |
// eslint-disable-next-line require-yield | |
async *_allKeys(q, options) { | |
throw new Error("._allKeys is not implemented"); | |
} | |
query(q, options) { | |
let it = this._all(q, options); | |
if (q.prefix != null) { | |
const prefix = q.prefix; | |
it = src_default3(it, (e) => e.key.toString().startsWith(prefix)); | |
} | |
if (Array.isArray(q.filters)) { | |
it = q.filters.reduce((it2, f) => src_default3(it2, f), it); | |
} | |
if (Array.isArray(q.orders)) { | |
it = q.orders.reduce((it2, f) => src_default6(it2, f), it); | |
} | |
if (q.offset != null) { | |
let i = 0; | |
const offset = q.offset; | |
it = src_default3(it, () => i++ >= offset); | |
} | |
if (q.limit != null) { | |
it = src_default7(it, q.limit); | |
} | |
return it; | |
} | |
queryKeys(q, options) { | |
let it = this._allKeys(q, options); | |
if (q.prefix != null) { | |
const prefix = q.prefix; | |
it = src_default3(it, (key) => key.toString().startsWith(prefix)); | |
} | |
if (Array.isArray(q.filters)) { | |
it = q.filters.reduce((it2, f) => src_default3(it2, f), it); | |
} | |
if (Array.isArray(q.orders)) { | |
it = q.orders.reduce((it2, f) => src_default6(it2, f), it); | |
} | |
if (q.offset != null) { | |
const offset = q.offset; | |
let i = 0; | |
it = src_default3(it, () => i++ >= offset); | |
} | |
if (q.limit != null) { | |
it = src_default7(it, q.limit); | |
} | |
return it; | |
} | |
}; | |
// node_modules/datastore-core/dist/src/memory.js | |
var MemoryDatastore = class extends BaseDatastore { | |
data; | |
constructor() { | |
super(); | |
this.data = /* @__PURE__ */ new Map(); | |
} | |
put(key, val) { | |
this.data.set(key.toString(), val); | |
return key; | |
} | |
get(key) { | |
const result = this.data.get(key.toString()); | |
if (result == null) { | |
throw notFoundError2(); | |
} | |
return result; | |
} | |
has(key) { | |
return this.data.has(key.toString()); | |
} | |
delete(key) { | |
this.data.delete(key.toString()); | |
} | |
*_all() { | |
for (const [key, value] of this.data.entries()) { | |
yield { key: new Key(key), value }; | |
} | |
} | |
*_allKeys() { | |
for (const key of this.data.keys()) { | |
yield new Key(key); | |
} | |
} | |
}; | |
// node_modules/it-map/dist/src/index.js | |
function isAsyncIterable7(thing) { | |
return thing[Symbol.asyncIterator] != null; | |
} | |
function map(source, func) { | |
if (isAsyncIterable7(source)) { | |
return async function* () { | |
for await (const val of source) { | |
yield func(val); | |
} | |
}(); | |
} | |
const peekable2 = src_default2(source); | |
const { value, done } = peekable2.next(); | |
if (done === true) { | |
return /* @__PURE__ */ function* () { | |
}(); | |
} | |
const res = func(value); | |
if (typeof res.then === "function") { | |
return async function* () { | |
yield await res; | |
for await (const val of peekable2) { | |
yield func(val); | |
} | |
}(); | |
} | |
const fn = func; | |
return function* () { | |
yield res; | |
for (const val of peekable2) { | |
yield fn(val); | |
} | |
}(); | |
} | |
var src_default8 = map; | |
// node_modules/it-pipe/dist/src/index.js | |
function pipe(first2, ...rest) { | |
if (first2 == null) { | |
throw new Error("Empty pipeline"); | |
} | |
if (isDuplex(first2)) { | |
const duplex = first2; | |
first2 = () => duplex.source; | |
} else if (isIterable(first2) || isAsyncIterable8(first2)) { | |
const source = first2; | |
first2 = () => source; | |
} | |
const fns = [first2, ...rest]; | |
if (fns.length > 1) { | |
if (isDuplex(fns[fns.length - 1])) { | |
fns[fns.length - 1] = fns[fns.length - 1].sink; | |
} | |
} | |
if (fns.length > 2) { | |
for (let i = 1; i < fns.length - 1; i++) { | |
if (isDuplex(fns[i])) { | |
fns[i] = duplexPipelineFn(fns[i]); | |
} | |
} | |
} | |
return rawPipe(...fns); | |
} | |
var rawPipe = (...fns) => { | |
let res; | |
while (fns.length > 0) { | |
res = fns.shift()(res); | |
} | |
return res; | |
}; | |
var isAsyncIterable8 = (obj) => { | |
return obj?.[Symbol.asyncIterator] != null; | |
}; | |
var isIterable = (obj) => { | |
return obj?.[Symbol.iterator] != null; | |
}; | |
var isDuplex = (obj) => { | |
if (obj == null) { | |
return false; | |
} | |
return obj.sink != null && obj.source != null; | |
}; | |
var duplexPipelineFn = (duplex) => { | |
return (source) => { | |
const p = duplex.sink(source); | |
if (p?.then != null) { | |
const stream = pushable({ | |
objectMode: true | |
}); | |
p.then(() => { | |
stream.end(); | |
}, (err) => { | |
stream.end(err); | |
}); | |
let sourceWrap; | |
const source2 = duplex.source; | |
if (isAsyncIterable8(source2)) { | |
sourceWrap = async function* () { | |
yield* source2; | |
stream.end(); | |
}; | |
} else if (isIterable(source2)) { | |
sourceWrap = function* () { | |
yield* source2; | |
stream.end(); | |
}; | |
} else { | |
throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable"); | |
} | |
return src_default4(stream, sourceWrap()); | |
} | |
return duplex.source; | |
}; | |
}; | |
// node_modules/datastore-core/dist/src/sharding.js | |
var shardKey = new Key(SHARDING_FN); | |
// node_modules/datastore-core/node_modules/@libp2p/logger/dist/src/index.js | |
var import_debug3 = __toESM(require_browser(), 1); | |
// node_modules/datastore-core/node_modules/multiformats/vendor/base-x.js | |
function base4(ALPHABET, name8) { | |
if (ALPHABET.length >= 255) { | |
throw new TypeError("Alphabet too long"); | |
} | |
var BASE_MAP = new Uint8Array(256); | |
for (var j = 0; j < BASE_MAP.length; j++) { | |
BASE_MAP[j] = 255; | |
} | |
for (var i = 0; i < ALPHABET.length; i++) { | |
var x = ALPHABET.charAt(i); | |
var xc = x.charCodeAt(0); | |
if (BASE_MAP[xc] !== 255) { | |
throw new TypeError(x + " is ambiguous"); | |
} | |
BASE_MAP[xc] = i; | |
} | |
var BASE = ALPHABET.length; | |
var LEADER = ALPHABET.charAt(0); | |
var FACTOR = Math.log(BASE) / Math.log(256); | |
var iFACTOR = Math.log(256) / Math.log(BASE); | |
function encode39(source) { | |
if (source instanceof Uint8Array) | |
; | |
else if (ArrayBuffer.isView(source)) { | |
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength); | |
} else if (Array.isArray(source)) { | |
source = Uint8Array.from(source); | |
} | |
if (!(source instanceof Uint8Array)) { | |
throw new TypeError("Expected Uint8Array"); | |
} | |
if (source.length === 0) { | |
return ""; | |
} | |
var zeroes = 0; | |
var length11 = 0; | |
var pbegin = 0; | |
var pend = source.length; | |
while (pbegin !== pend && source[pbegin] === 0) { | |
pbegin++; | |
zeroes++; | |
} | |
var size = (pend - pbegin) * iFACTOR + 1 >>> 0; | |
var b58 = new Uint8Array(size); | |
while (pbegin !== pend) { | |
var carry = source[pbegin]; | |
var i2 = 0; | |
for (var it1 = size - 1; (carry !== 0 || i2 < length11) && it1 !== -1; it1--, i2++) { | |
carry += 256 * b58[it1] >>> 0; | |
b58[it1] = carry % BASE >>> 0; | |
carry = carry / BASE >>> 0; | |
} | |
if (carry !== 0) { | |
throw new Error("Non-zero carry"); | |
} | |
length11 = i2; | |
pbegin++; | |
} | |
var it2 = size - length11; | |
while (it2 !== size && b58[it2] === 0) { | |
it2++; | |
} | |
var str = LEADER.repeat(zeroes); | |
for (; it2 < size; ++it2) { | |
str += ALPHABET.charAt(b58[it2]); | |
} | |
return str; | |
} | |
function decodeUnsafe(source) { | |
if (typeof source !== "string") { | |
throw new TypeError("Expected String"); | |
} | |
if (source.length === 0) { | |
return new Uint8Array(); | |
} | |
var psz = 0; | |
if (source[psz] === " ") { | |
return; | |
} | |
var zeroes = 0; | |
var length11 = 0; | |
while (source[psz] === LEADER) { | |
zeroes++; | |
psz++; | |
} | |
var size = (source.length - psz) * FACTOR + 1 >>> 0; | |
var b256 = new Uint8Array(size); | |
while (source[psz]) { | |
var carry = BASE_MAP[source.charCodeAt(psz)]; | |
if (carry === 255) { | |
return; | |
} | |
var i2 = 0; | |
for (var it3 = size - 1; (carry !== 0 || i2 < length11) && it3 !== -1; it3--, i2++) { | |
carry += BASE * b256[it3] >>> 0; | |
b256[it3] = carry % 256 >>> 0; | |
carry = carry / 256 >>> 0; | |
} | |
if (carry !== 0) { | |
throw new Error("Non-zero carry"); | |
} | |
length11 = i2; | |
psz++; | |
} | |
if (source[psz] === " ") { | |
return; | |
} | |
var it4 = size - length11; | |
while (it4 !== size && b256[it4] === 0) { | |
it4++; | |
} | |
var vch = new Uint8Array(zeroes + (size - it4)); | |
var j2 = zeroes; | |
while (it4 !== size) { | |
vch[j2++] = b256[it4++]; | |
} | |
return vch; | |
} | |
function decode50(string3) { | |
var buffer3 = decodeUnsafe(string3); | |
if (buffer3) { | |
return buffer3; | |
} | |
throw new Error(`Non-${name8} character`); | |
} | |
return { | |
encode: encode39, | |
decodeUnsafe, | |
decode: decode50 | |
}; | |
} | |
var src4 = base4; | |
var _brrp__multiformats_scope_baseX4 = src4; | |
var base_x_default4 = _brrp__multiformats_scope_baseX4; | |
// node_modules/datastore-core/node_modules/multiformats/src/bytes.js | |
var empty4 = new Uint8Array(0); | |
var coerce4 = (o) => { | |
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array") | |
return o; | |
if (o instanceof ArrayBuffer) | |
return new Uint8Array(o); | |
if (ArrayBuffer.isView(o)) { | |
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength); | |
} | |
throw new Error("Unknown type, must be binary type"); | |
}; | |
// node_modules/datastore-core/node_modules/multiformats/src/bases/base.js | |
var Encoder4 = class { | |
/** | |
* @param {Base} name | |
* @param {Prefix} prefix | |
* @param {(bytes:Uint8Array) => string} baseEncode | |
*/ | |
constructor(name8, prefix, baseEncode) { | |
this.name = name8; | |
this.prefix = prefix; | |
this.baseEncode = baseEncode; | |
} | |
/** | |
* @param {Uint8Array} bytes | |
* @returns {API.Multibase<Prefix>} | |
*/ | |
encode(bytes3) { | |
if (bytes3 instanceof Uint8Array) { | |
return `${this.prefix}${this.baseEncode(bytes3)}`; | |
} else { | |
throw Error("Unknown type, must be binary type"); | |
} | |
} | |
}; | |
var Decoder4 = class { | |
/** | |
* @param {Base} name | |
* @param {Prefix} prefix | |
* @param {(text:string) => Uint8Array} baseDecode | |
*/ | |
constructor(name8, prefix, baseDecode) { | |
this.name = name8; | |
this.prefix = prefix; | |
if (prefix.codePointAt(0) === void 0) { | |
throw new Error("Invalid prefix character"); | |
} | |
this.prefixCodePoint = /** @type {number} */ | |
prefix.codePointAt(0); | |
this.baseDecode = baseDecode; | |
} | |
/** | |
* @param {string} text | |
*/ | |
decode(text) { | |
if (typeof text === "string") { | |
if (text.codePointAt(0) !== this.prefixCodePoint) { | |
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`); | |
} | |
return this.baseDecode(text.slice(this.prefix.length)); | |
} else { | |
throw Error("Can only multibase decode strings"); | |
} | |
} | |
/** | |
* @template {string} OtherPrefix | |
* @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder | |
* @returns {ComposedDecoder<Prefix|OtherPrefix>} | |
*/ | |
or(decoder) { | |
return or4(this, decoder); | |
} | |
}; | |
var ComposedDecoder4 = class { | |
/** | |
* @param {Decoders<Prefix>} decoders | |
*/ | |
constructor(decoders2) { | |
this.decoders = decoders2; | |
} | |
/** | |
* @template {string} OtherPrefix | |
* @param {API.UnibaseDecoder<OtherPrefix>|ComposedDecoder<OtherPrefix>} decoder | |
* @returns {ComposedDecoder<Prefix|OtherPrefix>} | |
*/ | |
or(decoder) { | |
return or4(this, decoder); | |
} | |
/** | |
* @param {string} input | |
* @returns {Uint8Array} | |
*/ | |
decode(input) { | |
const prefix = ( | |
/** @type {Prefix} */ | |
input[0] | |
); | |
const decoder = this.decoders[prefix]; | |
if (decoder) { | |
return decoder.decode(input); | |
} else { | |
throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`); | |
} | |
} | |
}; | |
var or4 = (left, right) => new ComposedDecoder4( | |
/** @type {Decoders<L|R>} */ | |
{ | |
...left.decoders || { [ | |
/** @type API.UnibaseDecoder<L> */ | |
left.prefix | |
]: left }, | |
...right.decoders || { [ | |
/** @type API.UnibaseDecoder<R> */ | |
right.prefix | |
]: right } | |
} | |
); | |
var Codec4 = class { | |
/** | |
* @param {Base} name | |
* @param {Prefix} prefix | |
* @param {(bytes:Uint8Array) => string} baseEncode | |
* @param {(text:string) => Uint8Array} baseDecode | |
*/ | |
constructor(name8, prefix, baseEncode, baseDecode) { | |
this.name = name8; | |
this.prefix = prefix; | |
this.baseEncode = baseEncode; | |
this.baseDecode = baseDecode; | |
this.encoder = new Encoder4(name8, prefix, baseEncode); | |
this.decoder = new Decoder4(name8, prefix, baseDecode); | |
} | |
/** | |
* @param {Uint8Array} input | |
*/ | |
encode(input) { | |
return this.encoder.encode(input); | |
} | |
/** | |
* @param {string} input | |
*/ | |
decode(input) { | |
return this.decoder.decode(input); | |
} | |
}; | |
var from5 = ({ name: name8, prefix, encode: encode39, decode: decode50 }) => new Codec4(name8, prefix, encode39, decode50); | |
var baseX4 = ({ prefix, name: name8, alphabet: alphabet5 }) => { | |
const { encode: encode39, decode: decode50 } = base_x_default4(alphabet5, name8); | |
return from5({ | |
prefix, | |
name: name8, | |
encode: encode39, | |
/** | |
* @param {string} text | |
*/ | |
decode: (text) => coerce4(decode50(text)) | |
}); | |
}; | |
var decode11 = (string3, alphabet5, bitsPerChar, name8) => { | |
const codes8 = {}; | |
for (let i = 0; i < alphabet5.length; ++i) { | |
codes8[alphabet5[i]] = i; | |
} | |
let end = string3.length; | |
while (string3[end - 1] === "=") { | |
--end; | |
} | |
const out = new Uint8Array(end * bitsPerChar / 8 | 0); | |
let bits2 = 0; | |
let buffer3 = 0; | |
let written = 0; | |
for (let i = 0; i < end; ++i) { | |
const value = codes8[string3[i]]; | |
if (value === void 0) { | |
throw new SyntaxError(`Non-${name8} character`); | |
} | |
buffer3 = buffer3 << bitsPerChar | value; | |
bits2 += bitsPerChar; | |
if (bits2 >= 8) { | |
bits2 -= 8; | |
out[written++] = 255 & buffer3 >> bits2; | |
} | |
} | |
if (bits2 >= bitsPerChar || 255 & buffer3 << 8 - bits2) { | |
throw new SyntaxError("Unexpected end of data"); | |
} | |
return out; | |
}; | |
var encode8 = (data, alphabet5, bitsPerChar) => { | |
const pad = alphabet5[alphabet5.length - 1] === "="; | |
const mask = (1 << bitsPerChar) - 1; | |
let out = ""; | |
let bits2 = 0; | |
let buffer3 = 0; | |
for (let i = 0; i < data.length; ++i) { | |
buffer3 = buffer3 << 8 | data[i]; | |
bits2 += 8; | |
while (bits2 > bitsPerChar) { | |
bits2 -= bitsPerChar; | |
out += alphabet5[mask & buffer3 >> bits2]; | |
} | |
} | |
if (bits2) { | |
out += alphabet5[mask & buffer3 << bitsPerChar - bits2]; | |
} | |
if (pad) { | |
while (out.length * bitsPerChar & 7) { | |
out += "="; | |
} | |
} | |
return out; | |
}; | |
var rfc46484 = ({ name: name8, prefix, bitsPerChar, alphabet: alphabet5 }) => { | |
return from5({ | |
prefix, | |
name: name8, | |
encode(input) { | |
return encode8(input, alphabet5, bitsPerChar); | |
}, | |
decode(input) { | |
return decode11(input, alphabet5, bitsPerChar, name8); | |
} | |
}); | |
}; | |
// node_modules/datastore-core/node_modules/multiformats/src/bases/base32.js | |
var base324 = rfc46484({ | |
prefix: "b", | |
name: "base32", | |
alphabet: "abcdefghijklmnopqrstuvwxyz234567", | |
bitsPerChar: 5 | |
}); | |
var base32upper4 = rfc46484({ | |
prefix: "B", | |
name: "base32upper", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567", | |
bitsPerChar: 5 | |
}); | |
var base32pad4 = rfc46484({ | |
prefix: "c", | |
name: "base32pad", | |
alphabet: "abcdefghijklmnopqrstuvwxyz234567=", | |
bitsPerChar: 5 | |
}); | |
var base32padupper4 = rfc46484({ | |
prefix: "C", | |
name: "base32padupper", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=", | |
bitsPerChar: 5 | |
}); | |
var base32hex4 = rfc46484({ | |
prefix: "v", | |
name: "base32hex", | |
alphabet: "0123456789abcdefghijklmnopqrstuv", | |
bitsPerChar: 5 | |
}); | |
var base32hexupper4 = rfc46484({ | |
prefix: "V", | |
name: "base32hexupper", | |
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV", | |
bitsPerChar: 5 | |
}); | |
var base32hexpad4 = rfc46484({ | |
prefix: "t", | |
name: "base32hexpad", | |
alphabet: "0123456789abcdefghijklmnopqrstuv=", | |
bitsPerChar: 5 | |
}); | |
var base32hexpadupper4 = rfc46484({ | |
prefix: "T", | |
name: "base32hexpadupper", | |
alphabet: "0123456789ABCDEFGHIJKLMNOPQRSTUV=", | |
bitsPerChar: 5 | |
}); | |
var base32z4 = rfc46484({ | |
prefix: "h", | |
name: "base32z", | |
alphabet: "ybndrfg8ejkmcpqxot1uwisza345h769", | |
bitsPerChar: 5 | |
}); | |
// node_modules/datastore-core/node_modules/multiformats/src/bases/base58.js | |
var base58btc4 = baseX4({ | |
name: "base58btc", | |
prefix: "z", | |
alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" | |
}); | |
var base58flickr4 = baseX4({ | |
name: "base58flickr", | |
prefix: "Z", | |
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ" | |
}); | |
// node_modules/datastore-core/node_modules/multiformats/src/bases/base64.js | |
var base644 = rfc46484({ | |
prefix: "m", | |
name: "base64", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", | |
bitsPerChar: 6 | |
}); | |
var base64pad4 = rfc46484({ | |
prefix: "M", | |
name: "base64pad", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", | |
bitsPerChar: 6 | |
}); | |
var base64url4 = rfc46484({ | |
prefix: "u", | |
name: "base64url", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_", | |
bitsPerChar: 6 | |
}); | |
var base64urlpad4 = rfc46484({ | |
prefix: "U", | |
name: "base64urlpad", | |
alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=", | |
bitsPerChar: 6 | |
}); | |
// node_modules/datastore-core/node_modules/@libp2p/logger/dist/src/index.js | |
import_debug3.default.formatters.b = (v) => { | |
return v == null ? "undefined" : base58btc4.baseEncode(v); | |
}; | |
import_debug3.default.formatters.t = (v) => { | |
return v == null ? "undefined" : base324.baseEncode(v); | |
}; | |
import_debug3.default.formatters.m = (v) => { | |
return v == null ? "undefined" : base644.baseEncode(v); | |
}; | |
import_debug3.default.formatters.p = (v) => { | |
return v == null ? "undefined" : v.toString(); | |
}; | |
import_debug3.default.formatters.c = (v) => { | |
return v == null ? "undefined" : v.toString(); | |
}; | |
import_debug3.default.formatters.k = (v) => { | |
return v == null ? "undefined" : v.toString(); | |
}; | |
import_debug3.default.formatters.a = (v) => { | |
return v == null ? "undefined" : v.toString(); | |
}; | |
function createDisabledLogger3(namespace) { | |
const logger5 = () => { | |
}; | |
logger5.enabled = false; | |
logger5.color = ""; | |
logger5.diff = 0; | |
logger5.log = () => { | |
}; | |
logger5.namespace = namespace; | |
logger5.destroy = () => true; | |
logger5.extend = () => logger5; | |
return logger5; | |
} | |
function logger3(name8) { | |
let trace = createDisabledLogger3(`${name8}:trace`); | |
if (import_debug3.default.enabled(`${name8}:trace`) && import_debug3.default.names.map((r) => r.toString()).find((n) => n.includes(":trace")) != null) { | |
trace = (0, import_debug3.default)(`${name8}:trace`); | |
} | |
return Object.assign((0, import_debug3.default)(name8), { | |
error: (0, import_debug3.default)(`${name8}:error`), | |
trace | |
}); | |
} | |
// node_modules/datastore-core/dist/src/tiered.js | |
var log2 = logger3("datastore:core:tiered"); | |
// node_modules/any-signal/dist/src/index.js | |
function anySignal(signals) { | |
const controller = new globalThis.AbortController(); | |
function onAbort() { | |
controller.abort(); | |
for (const signal2 of signals) { | |
if (signal2?.removeEventListener != null) { | |
signal2.removeEventListener("abort", onAbort); | |
} | |
} | |
} | |
for (const signal2 of signals) { | |
if (signal2?.aborted === true) { | |
onAbort(); | |
break; | |
} | |
if (signal2?.addEventListener != null) { | |
signal2.addEventListener("abort", onAbort); | |
} | |
} | |
function clear() { | |
for (const signal2 of signals) { | |
if (signal2?.removeEventListener != null) { | |
signal2.removeEventListener("abort", onAbort); | |
} | |
} | |
} | |
const signal = controller.signal; | |
signal.clear = clear; | |
return signal; | |
} | |
// node_modules/it-foreach/dist/src/index.js | |
function isAsyncIterable9(thing) { | |
return thing[Symbol.asyncIterator] != null; | |
} | |
function forEach(source, fn) { | |
if (isAsyncIterable9(source)) { | |
return async function* () { | |
for await (const thing of source) { | |
await fn(thing); | |
yield thing; | |
} | |
}(); | |
} | |
const peekable2 = src_default2(source); | |
const { value, done } = peekable2.next(); | |
if (done === true) { | |
return /* @__PURE__ */ function* () { | |
}(); | |
} | |
const res = fn(value); | |
if (typeof res?.then === "function") { | |
return async function* () { | |
yield value; | |
for await (const val of peekable2) { | |
await fn(val); | |
yield val; | |
} | |
}(); | |
} | |
const func = fn; | |
return function* () { | |
yield value; | |
for (const val of peekable2) { | |
func(val); | |
yield val; | |
} | |
}(); | |
} | |
var src_default9 = forEach; | |
// node_modules/multiformats/vendor/varint.js | |
var encode_13 = encode9; | |
var MSB3 = 128; | |
var REST3 = 127; | |
var MSBALL3 = ~REST3; | |
var INT3 = Math.pow(2, 31); | |
function encode9(num, out, offset) { | |
out = out || []; | |
offset = offset || 0; | |
var oldOffset = offset; | |
while (num >= INT3) { | |
out[offset++] = num & 255 | MSB3; | |
num /= 128; | |
} | |
while (num & MSBALL3) { | |
out[offset++] = num & 255 | MSB3; | |
num >>>= 7; | |
} | |
out[offset] = num | 0; | |
encode9.bytes = offset - oldOffset + 1; | |
return out; | |
} | |
var decode12 = read3; | |
var MSB$13 = 128; | |
var REST$13 = 127; | |
function read3(buf3, offset) { | |
var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf3.length; | |
do { | |
if (counter >= l) { | |
read3.bytes = 0; | |
throw new RangeError("Could not decode varint"); | |
} | |
b = buf3[counter++]; | |
res += shift < 28 ? (b & REST$13) << shift : (b & REST$13) * Math.pow(2, shift); | |
shift += 7; | |
} while (b >= MSB$13); | |
read3.bytes = counter - offset; | |
return res; | |
} | |
var N13 = Math.pow(2, 7); | |
var N23 = Math.pow(2, 14); | |
var N33 = Math.pow(2, 21); | |
var N43 = Math.pow(2, 28); | |
var N53 = Math.pow(2, 35); | |
var N63 = Math.pow(2, 42); | |
var N73 = Math.pow(2, 49); | |
var N83 = Math.pow(2, 56); | |
var N93 = Math.pow(2, 63); | |
var length3 = function(value) { | |
return value < N13 ? 1 : value < N23 ? 2 : value < N33 ? 3 : value < N43 ? 4 : value < N53 ? 5 : value < N63 ? 6 : value < N73 ? 7 : value < N83 ? 8 : value < N93 ? 9 : 10; | |
}; | |
var varint3 = { | |
encode: encode_13, | |
decode: decode12, | |
encodingLength: length3 | |
}; | |
var _brrp_varint3 = varint3; | |
var varint_default3 = _brrp_varint3; | |
// node_modules/multiformats/src/varint.js | |
var decode13 = (data, offset = 0) => { | |
const code9 = varint_default3.decode(data, offset); | |
return [code9, varint_default3.decode.bytes]; | |
}; | |
var encodeTo3 = (int, target, offset = 0) => { | |
varint_default3.encode(int, target, offset); | |
return target; | |
}; | |
var encodingLength3 = (int) => { | |
return varint_default3.encodingLength(int); | |
}; | |
// node_modules/multiformats/src/hashes/digest.js | |
var digest_exports3 = {}; | |
__export(digest_exports3, { | |
Digest: () => Digest3, | |
create: () => create3, | |
decode: () => decode14, | |
equals: () => equals6 | |
}); | |
var create3 = (code9, digest5) => { | |
const size = digest5.byteLength; | |
const sizeOffset = encodingLength3(code9); | |
const digestOffset = sizeOffset + encodingLength3(size); | |
const bytes3 = new Uint8Array(digestOffset + size); | |
encodeTo3(code9, bytes3, 0); | |
encodeTo3(size, bytes3, sizeOffset); | |
bytes3.set(digest5, digestOffset); | |
return new Digest3(code9, size, digest5, bytes3); | |
}; | |
var decode14 = (multihash) => { | |
const bytes3 = coerce(multihash); | |
const [code9, sizeOffset] = decode13(bytes3); | |
const [size, digestOffset] = decode13(bytes3.subarray(sizeOffset)); | |
const digest5 = bytes3.subarray(sizeOffset + digestOffset); | |
if (digest5.byteLength !== size) { | |
throw new Error("Incorrect length"); | |
} | |
return new Digest3(code9, size, digest5, bytes3); | |
}; | |
var equals6 = (a, b) => { | |
if (a === b) { | |
return true; | |
} else { | |
const data = ( | |
/** @type {{code?:unknown, size?:unknown, bytes?:unknown}} */ | |
b | |
); | |
return a.code === data.code && a.size === data.size && data.bytes instanceof Uint8Array && equals(a.bytes, data.bytes); | |
} | |
}; | |
var Digest3 = class { | |
/** | |
* Creates a multihash digest. | |
* | |
* @param {Code} code | |
* @param {Size} size | |
* @param {Uint8Array} digest | |
* @param {Uint8Array} bytes | |
*/ | |
constructor(code9, size, digest5, bytes3) { | |
this.code = code9; | |
this.size = size; | |
this.digest = digest5; | |
this.bytes = bytes3; | |
} | |
}; | |
// node_modules/multiformats/src/cid.js | |
var format3 = (link, base14) => { | |
const { bytes: bytes3, version: version4 } = link; | |
switch (version4) { | |
case 0: | |
return toStringV03( | |
bytes3, | |
baseCache3(link), | |
/** @type {API.MultibaseEncoder<"z">} */ | |
base14 || base58btc.encoder | |
); | |
default: | |
return toStringV13( | |
bytes3, | |
baseCache3(link), | |
/** @type {API.MultibaseEncoder<Prefix>} */ | |
base14 || base32.encoder | |
); | |
} | |
}; | |
var cache3 = /* @__PURE__ */ new WeakMap(); | |
var baseCache3 = (cid) => { | |
const baseCache9 = cache3.get(cid); | |
if (baseCache9 == null) { | |
const baseCache10 = /* @__PURE__ */ new Map(); | |
cache3.set(cid, baseCache10); | |
return baseCache10; | |
} | |
return baseCache9; | |
}; | |
var CID3 = class _CID { | |
/** | |
* @param {Version} version - Version of the CID | |
* @param {Format} code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv | |
* @param {API.MultihashDigest<Alg>} multihash - (Multi)hash of the of the content. | |
* @param {Uint8Array} bytes | |
* | |
*/ | |
constructor(version4, code9, multihash, bytes3) { | |
this.code = code9; | |
this.version = version4; | |
this.multihash = multihash; | |
this.bytes = bytes3; | |
this["/"] = bytes3; | |
} | |
/** | |
* Signalling `cid.asCID === cid` has been replaced with `cid['/'] === cid.bytes` | |
* please either use `CID.asCID(cid)` or switch to new signalling mechanism | |
* | |
* @deprecated | |
*/ | |
get asCID() { | |
return this; | |
} | |
// ArrayBufferView | |
get byteOffset() { | |
return this.bytes.byteOffset; | |
} | |
// ArrayBufferView | |
get byteLength() { | |
return this.bytes.byteLength; | |
} | |
/** | |
* @returns {CID<Data, API.DAG_PB, API.SHA_256, 0>} | |
*/ | |
toV0() { | |
switch (this.version) { | |
case 0: { | |
return ( | |
/** @type {CID<Data, API.DAG_PB, API.SHA_256, 0>} */ | |
this | |
); | |
} | |
case 1: { | |
const { code: code9, multihash } = this; | |
if (code9 !== DAG_PB_CODE3) { | |
throw new Error("Cannot convert a non dag-pb CID to CIDv0"); | |
} | |
if (multihash.code !== SHA_256_CODE3) { | |
throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0"); | |
} | |
return ( | |
/** @type {CID<Data, API.DAG_PB, API.SHA_256, 0>} */ | |
_CID.createV0( | |
/** @type {API.MultihashDigest<API.SHA_256>} */ | |
multihash | |
) | |
); | |
} | |
default: { | |
throw Error( | |
`Can not convert CID version ${this.version} to version 0. This is a bug please report` | |
); | |
} | |
} | |
} | |
/** | |
* @returns {CID<Data, Format, Alg, 1>} | |
*/ | |
toV1() { | |
switch (this.version) { | |
case 0: { | |
const { code: code9, digest: digest5 } = this.multihash; | |
const multihash = create3(code9, digest5); | |
return ( | |
/** @type {CID<Data, Format, Alg, 1>} */ | |
_CID.createV1(this.code, multihash) | |
); | |
} | |
case 1: { | |
return ( | |
/** @type {CID<Data, Format, Alg, 1>} */ | |
this | |
); | |
} | |
default: { | |
throw Error( | |
`Can not convert CID version ${this.version} to version 1. This is a bug please report` | |
); | |
} | |
} | |
} | |
/** | |
* @param {unknown} other | |
* @returns {other is CID<Data, Format, Alg, Version>} | |
*/ | |
equals(other) { | |
return _CID.equals(this, other); | |
} | |
/** | |
* @template {unknown} Data | |
* @template {number} Format | |
* @template {number} Alg | |
* @template {API.Version} Version | |
* @param {API.Link<Data, Format, Alg, Version>} self | |
* @param {unknown} other | |
* @returns {other is CID} | |
*/ | |
static equals(self2, other) { | |
const unknown = ( | |
/** @type {{code?:unknown, version?:unknown, multihash?:unknown}} */ | |
other | |
); | |
return unknown && self2.code === unknown.code && self2.version === unknown.version && equals6(self2.multihash, unknown.multihash); | |
} | |
/** | |
* @param {API.MultibaseEncoder<string>} [base] | |
* @returns {string} | |
*/ | |
toString(base14) { | |
return format3(this, base14); | |
} | |
toJSON() { | |
return { "/": format3(this) }; | |
} | |
link() { | |
return this; | |
} | |
get [Symbol.toStringTag]() { | |
return "CID"; | |
} | |
// Legacy | |
[Symbol.for("nodejs.util.inspect.custom")]() { | |
return `CID(${this.toString()})`; | |
} | |
/** | |
* Takes any input `value` and returns a `CID` instance if it was | |
* a `CID` otherwise returns `null`. If `value` is instanceof `CID` | |
* it will return value back. If `value` is not instance of this CID | |
* class, but is compatible CID it will return new instance of this | |
* `CID` class. Otherwise returns null. | |
* | |
* This allows two different incompatible versions of CID library to | |
* co-exist and interop as long as binary interface is compatible. | |
* | |
* @template {unknown} Data | |
* @template {number} Format | |
* @template {number} Alg | |
* @template {API.Version} Version | |
* @template {unknown} U | |
* @param {API.Link<Data, Format, Alg, Version>|U} input | |
* @returns {CID<Data, Format, Alg, Version>|null} | |
*/ | |
static asCID(input) { | |
if (input == null) { | |
return null; | |
} | |
const value = ( | |
/** @type {any} */ | |
input | |
); | |
if (value instanceof _CID) { | |
return value; | |
} else if (value["/"] != null && value["/"] === value.bytes || value.asCID === value) { | |
const { version: version4, code: code9, multihash, bytes: bytes3 } = value; | |
return new _CID( | |
version4, | |
code9, | |
/** @type {API.MultihashDigest<Alg>} */ | |
multihash, | |
bytes3 || encodeCID3(version4, code9, multihash.bytes) | |
); | |
} else if (value[cidSymbol3] === true) { | |
const { version: version4, multihash, code: code9 } = value; | |
const digest5 = ( | |
/** @type {API.MultihashDigest<Alg>} */ | |
decode14(multihash) | |
); | |
return _CID.create(version4, code9, digest5); | |
} else { | |
return null; | |
} | |
} | |
/** | |
* | |
* @template {unknown} Data | |
* @template {number} Format | |
* @template {number} Alg | |
* @template {API.Version} Version | |
* @param {Version} version - Version of the CID | |
* @param {Format} code - Code of the codec content is encoded in, see https://github.com/multiformats/multicodec/blob/master/table.csv | |
* @param {API.MultihashDigest<Alg>} digest - (Multi)hash of the of the content. | |
* @returns {CID<Data, Format, Alg, Version>} | |
*/ | |
static create(version4, code9, digest5) { | |
if (typeof code9 !== "number") { | |
throw new Error("String codecs are no longer supported"); | |
} | |
if (!(digest5.bytes instanceof Uint8Array)) { | |
throw new Error("Invalid digest"); | |
} | |
switch (version4) { | |
case 0: { | |
if (code9 !== DAG_PB_CODE3) { | |
throw new Error( | |
`Version 0 CID must use dag-pb (code: ${DAG_PB_CODE3}) block encoding` | |
); | |
} else { | |
return new _CID(version4, code9, digest5, digest5.bytes); | |
} | |
} | |
case 1: { | |
const bytes3 = encodeCID3(version4, code9, digest5.bytes); | |
return new _CID(version4, code9, digest5, bytes3); | |
} | |
default: { | |
throw new Error("Invalid version"); | |
} | |
} | |
} | |
/** | |
* Simplified version of `create` for CIDv0. | |
* | |
* @template {unknown} [T=unknown] | |
* @param {API.MultihashDigest<typeof SHA_256_CODE>} digest - Multihash. | |
* @returns {CID<T, typeof DAG_PB_CODE, typeof SHA_256_CODE, 0>} | |
*/ | |
static createV0(digest5) { | |
return _CID.create(0, DAG_PB_CODE3, digest5); | |
} | |
/** | |
* Simplified version of `create` for CIDv1. | |
* | |
* @template {unknown} Data | |
* @template {number} Code | |
* @template {number} Alg | |
* @param {Code} code - Content encoding format code. | |
* @param {API.MultihashDigest<Alg>} digest - Miltihash of the content. | |
* @returns {CID<Data, Code, Alg, 1>} | |
*/ | |
static createV1(code9, digest5) { | |
return _CID.create(1, code9, digest5); | |
} | |
/** | |
* Decoded a CID from its binary representation. The byte array must contain | |
* only the CID with no additional bytes. | |
* | |
* An error will be thrown if the bytes provided do not contain a valid | |
* binary representation of a CID. | |
* | |
* @template {unknown} Data | |
* @template {number} Code | |
* @template {number} Alg | |
* @template {API.Version} Ver | |
* @param {API.ByteView<API.Link<Data, Code, Alg, Ver>>} bytes | |
* @returns {CID<Data, Code, Alg, Ver>} | |
*/ | |
static decode(bytes3) { | |
const [cid, remainder] = _CID.decodeFirst(bytes3); | |
if (remainder.length) { | |
throw new Error("Incorrect length"); | |
} | |
return cid; | |
} | |
/** | |
* Decoded a CID from its binary representation at the beginning of a byte | |
* array. | |
* | |
* Returns an array with the first element containing the CID and the second | |
* element containing the remainder of the original byte array. The remainder | |
* will be a zero-length byte array if the provided bytes only contained a | |
* binary CID representation. | |
* | |
* @template {unknown} T | |
* @template {number} C | |
* @template {number} A | |
* @template {API.Version} V | |
* @param {API.ByteView<API.Link<T, C, A, V>>} bytes | |
* @returns {[CID<T, C, A, V>, Uint8Array]} | |
*/ | |
static decodeFirst(bytes3) { | |
const specs = _CID.inspectBytes(bytes3); | |
const prefixSize = specs.size - specs.multihashSize; | |
const multihashBytes = coerce( | |
bytes3.subarray(prefixSize, prefixSize + specs.multihashSize) | |
); | |
if (multihashBytes.byteLength !== specs.multihashSize) { | |
throw new Error("Incorrect length"); | |
} | |
const digestBytes = multihashBytes.subarray( | |
specs.multihashSize - specs.digestSize | |
); | |
const digest5 = new Digest3( | |
specs.multihashCode, | |
specs.digestSize, | |
digestBytes, | |
multihashBytes | |
); | |
const cid = specs.version === 0 ? _CID.createV0( | |
/** @type {API.MultihashDigest<API.SHA_256>} */ | |
digest5 | |
) : _CID.createV1(specs.codec, digest5); | |
return [ | |
/** @type {CID<T, C, A, V>} */ | |
cid, | |
bytes3.subarray(specs.size) | |
]; | |
} | |
/** | |
* Inspect the initial bytes of a CID to determine its properties. | |
* | |
* Involves decoding up to 4 varints. Typically this will require only 4 to 6 | |
* bytes but for larger multicodec code values and larger multihash digest | |
* lengths these varints can be quite large. It is recommended that at least | |
* 10 bytes be made available in the `initialBytes` argument for a complete | |
* inspection. | |
* | |
* @template {unknown} T | |
* @template {number} C | |
* @template {number} A | |
* @template {API.Version} V | |
* @param {API.ByteView<API.Link<T, C, A, V>>} initialBytes | |
* @returns {{ version:V, codec:C, multihashCode:A, digestSize:number, multihashSize:number, size:number }} | |
*/ | |
static inspectBytes(initialBytes) { | |
let offset = 0; | |
const next = () => { | |
const [i, length11] = decode13(initialBytes.subarray(offset)); | |
offset += length11; | |
return i; | |
}; | |
let version4 = ( | |
/** @type {V} */ | |
next() | |
); | |
let codec = ( | |
/** @type {C} */ | |
DAG_PB_CODE3 | |
); | |
if ( | |
/** @type {number} */ | |
version4 === 18 | |
) { | |
version4 = /** @type {V} */ | |
0; | |
offset = 0; | |
} else { | |
codec = /** @type {C} */ | |
next(); | |
} | |
if (version4 !== 0 && version4 !== 1) { | |
throw new RangeError(`Invalid CID version ${version4}`); | |
} | |
const prefixSize = offset; | |
const multihashCode = ( | |
/** @type {A} */ | |
next() | |
); | |
const digestSize = next(); | |
const size = offset + digestSize; | |
const multihashSize = size - prefixSize; | |
return { version: version4, codec, multihashCode, digestSize, multihashSize, size }; | |
} | |
/** | |
* Takes cid in a string representation and creates an instance. If `base` | |
* decoder is not provided will use a default from the configuration. It will | |
* throw an error if encoding of the CID is not compatible with supplied (or | |
* a default decoder). | |
* | |
* @template {string} Prefix | |
* @template {unknown} Data | |
* @template {number} Code | |
* @template {number} Alg | |
* @template {API.Version} Ver | |
* @param {API.ToString<API.Link<Data, Code, Alg, Ver>, Prefix>} source | |
* @param {API.MultibaseDecoder<Prefix>} [base] | |
* @returns {CID<Data, Code, Alg, Ver>} | |
*/ | |
static parse(source, base14) { | |
const [prefix, bytes3] = parseCIDtoBytes3(source, base14); | |
const cid = _CID.decode(bytes3); | |
if (cid.version === 0 && source[0] !== "Q") { | |
throw Error("Version 0 CID string must not include multibase prefix"); | |
} | |
baseCache3(cid).set(prefix, source); | |
return cid; | |
} | |
}; | |
var parseCIDtoBytes3 = (source, base14) => { | |
switch (source[0]) { | |
case "Q": { | |
const decoder = base14 || base58btc; | |
return [ | |
/** @type {Prefix} */ | |
base58btc.prefix, | |
decoder.decode(`${base58btc.prefix}${source}`) | |
]; | |
} | |
case base58btc.prefix: { | |
const decoder = base14 || base58btc; | |
return [ | |
/** @type {Prefix} */ | |
base58btc.prefix, | |
decoder.decode(source) | |
]; | |
} | |
case base32.prefix: { | |
const decoder = base14 || base32; | |
return [ | |
/** @type {Prefix} */ | |
base32.prefix, | |
decoder.decode(source) | |
]; | |
} | |
default: { | |
if (base14 == null) { | |
throw Error( | |
"To parse non base32 or base58btc encoded CID multibase decoder must be provided" | |
); | |
} | |
return [ | |
/** @type {Prefix} */ | |
source[0], | |
base14.decode(source) | |
]; | |
} | |
} | |
}; | |
var toStringV03 = (bytes3, cache10, base14) => { | |
const { prefix } = base14; | |
if (prefix !== base58btc.prefix) { | |
throw Error(`Cannot string encode V0 in ${base14.name} encoding`); | |
} | |
const cid = cache10.get(prefix); | |
if (cid == null) { | |
const cid2 = base14.encode(bytes3).slice(1); | |
cache10.set(prefix, cid2); | |
return cid2; | |
} else { | |
return cid; | |
} | |
}; | |
var toStringV13 = (bytes3, cache10, base14) => { | |
const { prefix } = base14; | |
const cid = cache10.get(prefix); | |
if (cid == null) { | |
const cid2 = base14.encode(bytes3); | |
cache10.set(prefix, cid2); | |
return cid2; | |
} else { | |
return cid; | |
} | |
}; | |
var DAG_PB_CODE3 = 112; | |
var SHA_256_CODE3 = 18; | |
var encodeCID3 = (version4, code9, multihash) => { | |
const codeOffset = encodingLength3(version4); | |
const hashOffset = codeOffset + encodingLength3(code9); | |
const bytes3 = new Uint8Array(hashOffset + multihash.byteLength); | |
encodeTo3(version4, bytes3, 0); | |
encodeTo3(code9, bytes3, codeOffset); | |
bytes3.set(multihash, hashOffset); | |
return bytes3; | |
}; | |
var cidSymbol3 = Symbol.for("@ipld/js-cid/CID"); | |
// node_modules/@libp2p/tracked-map/dist/src/index.js | |
var TrackedMap = class extends Map { | |
metric; | |
constructor(init) { | |
super(); | |
const { name: name8, metrics } = init; | |
this.metric = metrics.registerMetric(name8); | |
this.updateComponentMetric(); | |
} | |
set(key, value) { | |
super.set(key, value); | |
this.updateComponentMetric(); | |
return this; | |
} | |
delete(key) { | |
const deleted = super.delete(key); | |
this.updateComponentMetric(); | |
return deleted; | |
} | |
clear() { | |
super.clear(); | |
this.updateComponentMetric(); | |
} | |
updateComponentMetric() { | |
this.metric.update(this.size); | |
} | |
}; | |
function trackedMap(config) { | |
const { name: name8, metrics } = config; | |
let map3; | |
if (metrics != null) { | |
map3 = new TrackedMap({ name: name8, metrics }); | |
} else { | |
map3 = /* @__PURE__ */ new Map(); | |
} | |
return map3; | |
} | |
// node_modules/@libp2p/interfaces/dist/src/errors.js | |
var AbortError2 = class _AbortError extends Error { | |
code; | |
type; | |
constructor(message2 = "The operation was aborted") { | |
super(message2); | |
this.code = _AbortError.code; | |
this.type = _AbortError.type; | |
} | |
static code = "ABORT_ERR"; | |
static type = "aborted"; | |
}; | |
var CodeError = class extends Error { | |
code; | |
props; | |
constructor(message2, code9, props) { | |
super(message2); | |
this.code = code9; | |
this.name = props?.name ?? "CodeError"; | |
this.props = props ?? {}; | |
} | |
}; | |
// node_modules/multiformats/src/hashes/sha2-browser.js | |
var sha2_browser_exports2 = {}; | |
__export(sha2_browser_exports2, { | |
sha256: () => sha2562, | |
sha512: () => sha5122 | |
}); | |
// node_modules/multiformats/src/hashes/hasher.js | |
var from6 = ({ name: name8, code: code9, encode: encode39 }) => new Hasher2(name8, code9, encode39); | |
var Hasher2 = class { | |
/** | |
* | |
* @param {Name} name | |
* @param {Code} code | |
* @param {(input: Uint8Array) => Await<Uint8Array>} encode | |
*/ | |
constructor(name8, code9, encode39) { | |
this.name = name8; | |
this.code = code9; | |
this.encode = encode39; | |
} | |
/** | |
* @param {Uint8Array} input | |
* @returns {Await<Digest.Digest<Code, number>>} | |
*/ | |
digest(input) { | |
if (input instanceof Uint8Array) { | |
const result = this.encode(input); | |
return result instanceof Uint8Array ? create3(this.code, result) : result.then((digest5) => create3(this.code, digest5)); | |
} else { | |
throw Error("Unknown type, must be binary type"); | |
} | |
} | |
}; | |
// node_modules/multiformats/src/hashes/sha2-browser.js | |
var sha2 = (name8) => ( | |
/** | |
* @param {Uint8Array} data | |
*/ | |
async (data) => new Uint8Array(await crypto.subtle.digest(name8, data)) | |
); | |
var sha2562 = from6({ | |
name: "sha2-256", | |
code: 18, | |
encode: sha2("SHA-256") | |
}); | |
var sha5122 = from6({ | |
name: "sha2-512", | |
code: 19, | |
encode: sha2("SHA-512") | |
}); | |
// node_modules/ipfs-bitswap/dist/src/message/index.js | |
var import_varint_decoder = __toESM(require_src(), 1); | |
// node_modules/uint8arrays/dist/src/equals.js | |
function equals7(a, b) { | |
if (a === b) { | |
return true; | |
} | |
if (a.byteLength !== b.byteLength) { | |
return false; | |
} | |
for (let i = 0; i < a.byteLength; i++) { | |
if (a[i] !== b[i]) { | |
return false; | |
} | |
} | |
return true; | |
} | |
// node_modules/ipfs-bitswap/dist/src/wantlist/entry.js | |
var WantListEntry = class { | |
_refCounter; | |
cid; | |
priority; | |
wantType; | |
constructor(cid, priority, wantType) { | |
this._refCounter = 1; | |
this.cid = cid; | |
this.priority = priority ?? 1; | |
this.wantType = wantType; | |
} | |
inc() { | |
this._refCounter += 1; | |
} | |
dec() { | |
this._refCounter = Math.max(0, this._refCounter - 1); | |
} | |
hasRefs() { | |
return this._refCounter > 0; | |
} | |
// So that console.log prints a nice description of this object | |
get [Symbol.toStringTag]() { | |
const cidStr = this.cid.toString(base58btc); | |
return `WantlistEntry <key: ${cidStr}, priority: ${this.priority}, refs: ${this._refCounter}>`; | |
} | |
equals(other) { | |
return this._refCounter === other._refCounter && this.cid.equals(other.cid) && this.priority === other.priority && this.wantType === other.wantType; | |
} | |
}; | |
// node_modules/ipfs-bitswap/dist/src/message/entry.js | |
var BitswapMessageEntry = class { | |
entry; | |
cancel; | |
sendDontHave; | |
constructor(cid, priority, wantType, cancel, sendDontHave) { | |
this.entry = new WantListEntry(cid, priority, wantType); | |
this.cancel = Boolean(cancel); | |
this.sendDontHave = Boolean(sendDontHave); | |
} | |
get cid() { | |
return this.entry.cid; | |
} | |
set cid(cid) { | |
this.entry.cid = cid; | |
} | |
get priority() { | |
return this.entry.priority; | |
} | |
set priority(val) { | |
this.entry.priority = val; | |
} | |
get wantType() { | |
return this.entry.wantType; | |
} | |
set wantType(val) { | |
this.entry.wantType = val; | |
} | |
get [Symbol.toStringTag]() { | |
const cidStr = this.cid.toString(base58btc); | |
return `BitswapMessageEntry ${cidStr} <cancel: ${this.cancel}, priority: ${this.priority}>`; | |
} | |
equals(other) { | |
return this.cancel === other.cancel && this.sendDontHave === other.sendDontHave && this.wantType === other.wantType && this.entry.equals(other.entry); | |
} | |
}; | |
// node_modules/ipfs-bitswap/dist/src/uti |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment