miqro 6.1.4 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/editor.bundle.js +10 -2
- package/build/esm/editor/components/editor.js +8 -0
- package/build/esm/editor/components/file-editor.js +1 -1
- package/build/esm/editor/components/highlight-text-area.js +2 -1
- package/build/esm/src/common/jwt.d.ts +49 -0
- package/build/esm/src/common/jwt.js +76 -0
- package/build/esm/src/inflate/inflate-sea.js +9 -8
- package/build/esm/src/inflate/setup-http.d.ts +1 -0
- package/build/esm/src/inflate/setup-http.js +8 -0
- package/build/esm/src/lib.d.ts +1 -1
- package/build/esm/src/lib.js +2 -2
- package/build/esm/src/services/app.js +5 -4
- package/build/esm/src/services/globals.js +45 -1
- package/build/esm/src/services/utils/cluster-ws.d.ts +4 -2
- package/build/esm/src/services/utils/cluster-ws.js +10 -1
- package/build/esm/src/services/utils/server-interface.d.ts +4 -30
- package/build/esm/src/services/utils/server-interface.js +44 -64
- package/build/esm/src/services/utils/websocketmanager.d.ts +3 -0
- package/build/esm/src/services/utils/websocketmanager.js +8 -2
- package/build/esm/src/types.d.ts +76 -5
- package/build/lib.cjs +2983 -362
- package/editor/components/editor.tsx +8 -0
- package/editor/components/file-editor.tsx +1 -1
- package/editor/components/highlight-text-area.tsx +2 -1
- package/package.json +4 -3
- package/sea/install-nodejs.sh +1 -1
- package/sea/node.version.tag +1 -1
- package/sea/types.json +1 -1
- package/src/common/jwt.ts +85 -0
- package/src/inflate/inflate-sea.ts +9 -8
- package/src/inflate/setup-http.ts +9 -0
- package/src/lib.ts +2 -2
- package/src/services/app.ts +6 -4
- package/src/services/globals.ts +45 -2
- package/src/services/utils/cluster-ws.ts +6 -1
- package/src/services/utils/server-interface.ts +44 -140
- package/src/services/utils/websocketmanager.ts +10 -2
- package/src/types/cookie.d.ts +2 -0
- package/src/types/jose.d.ts +2 -0
- package/src/types/miqro.d.ts +92 -2
- package/src/types/server.globals.d.ts +4 -29
- package/src/types.ts +78 -5
package/build/lib.cjs
CHANGED
|
@@ -55,7 +55,7 @@ var require_dist = __commonJS({
|
|
|
55
55
|
const len = str.length;
|
|
56
56
|
if (len < 2)
|
|
57
57
|
return obj;
|
|
58
|
-
const dec = options?.decode ||
|
|
58
|
+
const dec = options?.decode || decode2;
|
|
59
59
|
let index = 0;
|
|
60
60
|
do {
|
|
61
61
|
const eqIdx = str.indexOf("=", index);
|
|
@@ -176,7 +176,7 @@ var require_dist = __commonJS({
|
|
|
176
176
|
}
|
|
177
177
|
return str;
|
|
178
178
|
}
|
|
179
|
-
function
|
|
179
|
+
function decode2(str) {
|
|
180
180
|
if (str.indexOf("%") === -1)
|
|
181
181
|
return str;
|
|
182
182
|
try {
|
|
@@ -818,7 +818,7 @@ var require_showdown = __commonJS({
|
|
|
818
818
|
};
|
|
819
819
|
showdown2.helper.encodeEmailAddress = function(mail) {
|
|
820
820
|
"use strict";
|
|
821
|
-
var
|
|
821
|
+
var encode2 = [
|
|
822
822
|
function(ch) {
|
|
823
823
|
return "&#" + ch.charCodeAt(0) + ";";
|
|
824
824
|
},
|
|
@@ -831,10 +831,10 @@ var require_showdown = __commonJS({
|
|
|
831
831
|
];
|
|
832
832
|
mail = mail.replace(/./g, function(ch) {
|
|
833
833
|
if (ch === "@") {
|
|
834
|
-
ch =
|
|
834
|
+
ch = encode2[Math.floor(Math.random() * 2)](ch);
|
|
835
835
|
} else {
|
|
836
836
|
var r = Math.random();
|
|
837
|
-
ch = r > 0.9 ?
|
|
837
|
+
ch = r > 0.9 ? encode2[2](ch) : r > 0.45 ? encode2[1](ch) : encode2[0](ch);
|
|
838
838
|
}
|
|
839
839
|
return ch;
|
|
840
840
|
});
|
|
@@ -4397,11 +4397,11 @@ __export(lib_exports2, {
|
|
|
4397
4397
|
LoggerHandler: () => LoggerHandler,
|
|
4398
4398
|
Miqro: () => Miqro,
|
|
4399
4399
|
Router: () => Router,
|
|
4400
|
-
ServerInterfaceImpl: () => ServerInterfaceImpl,
|
|
4401
4400
|
ServerRequestHandler: () => ServerRequestHandler,
|
|
4402
4401
|
WebSocketManager: () => WebSocketManager,
|
|
4403
4402
|
appendAPIModule: () => appendAPIModule,
|
|
4404
4403
|
assertGlobalTampered: () => assertGlobalTampered,
|
|
4404
|
+
createServerInterface: () => createServerInterface,
|
|
4405
4405
|
initGlobals: () => initGlobals,
|
|
4406
4406
|
migration: () => lib_exports
|
|
4407
4407
|
});
|
|
@@ -4423,8 +4423,8 @@ var import_querystring = require("querystring");
|
|
|
4423
4423
|
|
|
4424
4424
|
// node_modules/@miqro/parser/build/built-in-parsers.js
|
|
4425
4425
|
var ParseOptionsError = class extends Error {
|
|
4426
|
-
constructor(
|
|
4427
|
-
super(
|
|
4426
|
+
constructor(message2 = "BAD REQUEST", argAttr) {
|
|
4427
|
+
super(message2);
|
|
4428
4428
|
this.argAttr = argAttr;
|
|
4429
4429
|
this.name = "ParseOptionsError";
|
|
4430
4430
|
}
|
|
@@ -5190,9 +5190,9 @@ function TextParser(options) {
|
|
|
5190
5190
|
}
|
|
5191
5191
|
};
|
|
5192
5192
|
}
|
|
5193
|
-
function assertNotUndefined(arg,
|
|
5193
|
+
function assertNotUndefined(arg, message2) {
|
|
5194
5194
|
if (arg === void 0) {
|
|
5195
|
-
throw new Error(
|
|
5195
|
+
throw new Error(message2 ? message2 : "arg undefined");
|
|
5196
5196
|
}
|
|
5197
5197
|
return arg;
|
|
5198
5198
|
}
|
|
@@ -6099,28 +6099,28 @@ var Logger = class extends EventTarget {
|
|
|
6099
6099
|
}
|
|
6100
6100
|
}
|
|
6101
6101
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
6102
|
-
debug(
|
|
6103
|
-
return this.write({ level: "debug", message, optionalParams, identifier: this.identifier, meta: [] });
|
|
6102
|
+
debug(message2, ...optionalParams) {
|
|
6103
|
+
return this.write({ level: "debug", message: message2, optionalParams, identifier: this.identifier, meta: [] });
|
|
6104
6104
|
}
|
|
6105
6105
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
6106
|
-
error(
|
|
6107
|
-
return this.write({ level: "error", message, optionalParams, identifier: this.identifier, meta: [] });
|
|
6106
|
+
error(message2, ...optionalParams) {
|
|
6107
|
+
return this.write({ level: "error", message: message2, optionalParams, identifier: this.identifier, meta: [] });
|
|
6108
6108
|
}
|
|
6109
6109
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
6110
|
-
info(
|
|
6111
|
-
return this.write({ level: "info", message, optionalParams, identifier: this.identifier, meta: [] });
|
|
6110
|
+
info(message2, ...optionalParams) {
|
|
6111
|
+
return this.write({ level: "info", message: message2, optionalParams, identifier: this.identifier, meta: [] });
|
|
6112
6112
|
}
|
|
6113
6113
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
6114
|
-
log(
|
|
6115
|
-
return this.write({ level: "info", message, optionalParams, identifier: this.identifier, meta: [] });
|
|
6114
|
+
log(message2, ...optionalParams) {
|
|
6115
|
+
return this.write({ level: "info", message: message2, optionalParams, identifier: this.identifier, meta: [] });
|
|
6116
6116
|
}
|
|
6117
6117
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
6118
|
-
trace(
|
|
6119
|
-
return this.write({ level: "trace", message, optionalParams, identifier: this.identifier, meta: [] });
|
|
6118
|
+
trace(message2, ...optionalParams) {
|
|
6119
|
+
return this.write({ level: "trace", message: message2, optionalParams, identifier: this.identifier, meta: [] });
|
|
6120
6120
|
}
|
|
6121
6121
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
6122
|
-
warn(
|
|
6123
|
-
return this.write({ level: "warn", message, optionalParams, identifier: this.identifier, meta: [] });
|
|
6122
|
+
warn(message2, ...optionalParams) {
|
|
6123
|
+
return this.write({ level: "warn", message: message2, optionalParams, identifier: this.identifier, meta: [] });
|
|
6124
6124
|
}
|
|
6125
6125
|
};
|
|
6126
6126
|
var FILE_TRANSPORT_ENV_VARIABLE = "LOG_FILE";
|
|
@@ -6233,7 +6233,7 @@ var DEFAULT_LOGGER_TRANSPORTS = () => [
|
|
|
6233
6233
|
ConsoleTransport(),
|
|
6234
6234
|
FileTransport()
|
|
6235
6235
|
];
|
|
6236
|
-
var DEFAULT_LOGGER_FORMATTER = ({ identifier, level, message, optionalParams }) => (0, import_node_util.format)(`${(/* @__PURE__ */ new Date()).toISOString()} ${process.pid} ${identifier ? `[${identifier}] ` : ""}${level !== "info" ? level === "error" || level === "warn" ? `[${level.toUpperCase()}] ` : `[${level}] ` : ""}${
|
|
6236
|
+
var DEFAULT_LOGGER_FORMATTER = ({ identifier, level, message: message2, optionalParams }) => (0, import_node_util.format)(`${(/* @__PURE__ */ new Date()).toISOString()} ${process.pid} ${identifier ? `[${identifier}] ` : ""}${level !== "info" ? level === "error" || level === "warn" ? `[${level.toUpperCase()}] ` : `[${level}] ` : ""}${message2}`, ...optionalParams);
|
|
6237
6237
|
var LOG_LEVEL_MAP = {
|
|
6238
6238
|
"none": 0,
|
|
6239
6239
|
"error": 1,
|
|
@@ -6313,20 +6313,20 @@ function routerDefaultLoggerFactory(uuid, req) {
|
|
|
6313
6313
|
return logger;
|
|
6314
6314
|
}
|
|
6315
6315
|
var BadRequestError = class extends Error {
|
|
6316
|
-
constructor(
|
|
6317
|
-
super(
|
|
6316
|
+
constructor(message2 = "BAD REQUEST") {
|
|
6317
|
+
super(message2);
|
|
6318
6318
|
this.name = "BadRequestError";
|
|
6319
6319
|
}
|
|
6320
6320
|
};
|
|
6321
6321
|
var ForbiddenError = class extends Error {
|
|
6322
|
-
constructor(
|
|
6323
|
-
super(
|
|
6322
|
+
constructor(message2 = "FORBIDDEN") {
|
|
6323
|
+
super(message2);
|
|
6324
6324
|
this.name = "ForbiddenError";
|
|
6325
6325
|
}
|
|
6326
6326
|
};
|
|
6327
6327
|
var UnAuthorizedError = class extends Error {
|
|
6328
|
-
constructor(
|
|
6329
|
-
super(
|
|
6328
|
+
constructor(message2 = "UNAUTHORIZED") {
|
|
6329
|
+
super(message2);
|
|
6330
6330
|
this.name = "UnAuthorizedError";
|
|
6331
6331
|
}
|
|
6332
6332
|
};
|
|
@@ -8591,11 +8591,12 @@ var down = {
|
|
|
8591
8591
|
// src/services/utils/cluster-ws.ts
|
|
8592
8592
|
var ClusterWebSocketServer2MessageType = "$$$$ClusterWebSocketServer2Message$$$$$";
|
|
8593
8593
|
var ClusterWebSocketServer2 = class extends WebSocketServer {
|
|
8594
|
-
constructor(name, options) {
|
|
8594
|
+
constructor(name, path, logger, options) {
|
|
8595
8595
|
super({
|
|
8596
8596
|
...options,
|
|
8597
8597
|
validate: (req) => {
|
|
8598
8598
|
if (this.options.maxConnections !== void 0 && this.clients.size + this.remoteClients.size >= this.options.maxConnections) {
|
|
8599
|
+
this.logger?.warn("[%s] max web socket connection reached! connection refused from [%s]", req.uuid, req.socket.remoteAddress);
|
|
8599
8600
|
return false;
|
|
8600
8601
|
} else {
|
|
8601
8602
|
return options.validate ? options.validate(req) : true;
|
|
@@ -8612,6 +8613,8 @@ var ClusterWebSocketServer2 = class extends WebSocketServer {
|
|
|
8612
8613
|
errorMessage: error2.message
|
|
8613
8614
|
});
|
|
8614
8615
|
}
|
|
8616
|
+
this.logger?.error("[%s] error from (%s) error [%s]", req.uuid, req.req.socket.remoteAddress, error2);
|
|
8617
|
+
this.logger?.error(error2);
|
|
8615
8618
|
if (options.onError) {
|
|
8616
8619
|
options.onError(req, error2);
|
|
8617
8620
|
}
|
|
@@ -8626,6 +8629,7 @@ var ClusterWebSocketServer2 = class extends WebSocketServer {
|
|
|
8626
8629
|
clientUUID: req.uuid
|
|
8627
8630
|
});
|
|
8628
8631
|
}
|
|
8632
|
+
this.logger?.log("[%s] new web socket connection from (%s)", req.uuid, req.req.socket.remoteAddress);
|
|
8629
8633
|
if (options.onConnection) {
|
|
8630
8634
|
options.onConnection(req);
|
|
8631
8635
|
}
|
|
@@ -8640,12 +8644,15 @@ var ClusterWebSocketServer2 = class extends WebSocketServer {
|
|
|
8640
8644
|
clientUUID: req.uuid
|
|
8641
8645
|
});
|
|
8642
8646
|
}
|
|
8647
|
+
this.logger?.log("[%s] [%s] web socket disconnection from (%s)", req.uuid, this.path, req.req.socket.remoteAddress);
|
|
8643
8648
|
if (options.onDisconnect) {
|
|
8644
8649
|
options.onDisconnect(req);
|
|
8645
8650
|
}
|
|
8646
8651
|
}
|
|
8647
8652
|
});
|
|
8648
8653
|
this.name = name;
|
|
8654
|
+
this.path = path;
|
|
8655
|
+
this.logger = logger;
|
|
8649
8656
|
this.listener = async (data) => {
|
|
8650
8657
|
try {
|
|
8651
8658
|
const msg = data;
|
|
@@ -9046,10 +9053,12 @@ var WebSocketManager = class {
|
|
|
9046
9053
|
logger = null;
|
|
9047
9054
|
name;
|
|
9048
9055
|
avoidLogSocket;
|
|
9056
|
+
loggerProvider;
|
|
9049
9057
|
constructor(options) {
|
|
9050
9058
|
this.onUpgrade = this.onUpgrade.bind(this);
|
|
9051
9059
|
this.logger = options && options.logger ? options.logger : null;
|
|
9052
9060
|
this.name = options && options.name ? options.name : "WebSocketManager";
|
|
9061
|
+
this.loggerProvider = options.loggerProvider;
|
|
9053
9062
|
this.avoidLogSocket = options && options.avoidLogSocket ? options.avoidLogSocket : false;
|
|
9054
9063
|
}
|
|
9055
9064
|
deleteWS(path) {
|
|
@@ -9074,7 +9083,9 @@ var WebSocketManager = class {
|
|
|
9074
9083
|
throw new Error(`ws on path ${wsConfig.path} already setup!`);
|
|
9075
9084
|
}
|
|
9076
9085
|
this.logger?.debug("setting up websocket on [%s]", wsConfig.path);
|
|
9077
|
-
const
|
|
9086
|
+
const identifier = wsConfig.path.replaceAll("/", "_").toUpperCase();
|
|
9087
|
+
const logger = this.loggerProvider && identifier.length >= 0 ? this.loggerProvider.getLogger(identifier.substring(identifier.charAt(0) === "_" ? 1 : 0)) : this.logger;
|
|
9088
|
+
const server2 = new ClusterWebSocketServer2(this.name + wsConfig.path, wsConfig.path, logger, wsConfig);
|
|
9078
9089
|
this.runningGlobalWSMap.set(wsConfig.path, server2);
|
|
9079
9090
|
}
|
|
9080
9091
|
}
|
|
@@ -9092,7 +9103,9 @@ var WebSocketManager = class {
|
|
|
9092
9103
|
throw new Error(`ws on path ${wsConfig.path} already setup!`);
|
|
9093
9104
|
}
|
|
9094
9105
|
this.logger?.debug("setting up websocket on [%s]", wsConfig.path);
|
|
9095
|
-
const
|
|
9106
|
+
const identifier = wsConfig.path.replaceAll("/", "_").toUpperCase();
|
|
9107
|
+
const logger = this.loggerProvider && identifier.length >= 0 ? this.loggerProvider.getLogger(identifier.substring(identifier.charAt(0) === "_" ? 1 : 0)) : this.logger;
|
|
9108
|
+
const server2 = new ClusterWebSocketServer2(this.name + wsConfig.path, wsConfig.path, logger, wsConfig);
|
|
9096
9109
|
this.runningGlobalWSMap.set(wsConfig.path, server2);
|
|
9097
9110
|
}
|
|
9098
9111
|
}
|
|
@@ -9233,7 +9246,7 @@ var DBManager = class {
|
|
|
9233
9246
|
// src/services/utils/log.ts
|
|
9234
9247
|
var import_node_util2 = require("node:util");
|
|
9235
9248
|
var DEFAULT_ENV_NAME2 = "LOG_LEVEL";
|
|
9236
|
-
var DEFAULT_FORMATTER = ({ identifier, level, message, optionalParams }) => (0, import_node_util2.format)(`${(/* @__PURE__ */ new Date()).toISOString()} PID[${process.pid}] ${identifier ? `[${identifier}] ` : ""}${level !== "info" ? level === "error" || level === "warn" ? `[${level.toUpperCase()}] ` : `[${level}] ` : ""}${
|
|
9249
|
+
var DEFAULT_FORMATTER = ({ identifier, level, message: message2, optionalParams }) => (0, import_node_util2.format)(`${(/* @__PURE__ */ new Date()).toISOString()} PID[${process.pid}] ${identifier ? `[${identifier}] ` : ""}${level !== "info" ? level === "error" || level === "warn" ? `[${level.toUpperCase()}] ` : `[${level}] ` : ""}${message2}`, ...optionalParams);
|
|
9237
9250
|
var LogProvider = class {
|
|
9238
9251
|
options;
|
|
9239
9252
|
constructor(options) {
|
|
@@ -9392,13 +9405,13 @@ var CONTENT_TYPE_MAP = {
|
|
|
9392
9405
|
|
|
9393
9406
|
// node_modules/@miqro/jsx/build/esm/vdom/log.js
|
|
9394
9407
|
var debugLogEnabled = false;
|
|
9395
|
-
function debug(runtime,
|
|
9408
|
+
function debug(runtime, message2, ...args) {
|
|
9396
9409
|
if (debugLogEnabled) {
|
|
9397
|
-
runtime.consoleLog(
|
|
9410
|
+
runtime.consoleLog(message2, ...args);
|
|
9398
9411
|
}
|
|
9399
9412
|
}
|
|
9400
|
-
function error(runtime,
|
|
9401
|
-
runtime.consoleError(
|
|
9413
|
+
function error(runtime, message2, ...args) {
|
|
9414
|
+
runtime.consoleError(message2, ...args);
|
|
9402
9415
|
}
|
|
9403
9416
|
function enableDebugLog() {
|
|
9404
9417
|
debugLogEnabled = true;
|
|
@@ -9795,21 +9808,21 @@ function getDefaultOptions() {
|
|
|
9795
9808
|
|
|
9796
9809
|
// node_modules/@miqro/jsx/build/esm/jsx.js
|
|
9797
9810
|
var Fragment = Symbol("Fragment");
|
|
9798
|
-
function createElement(
|
|
9799
|
-
if (!
|
|
9800
|
-
throw new Error(`cannot call createElement with [${String(
|
|
9811
|
+
function createElement(tag2, attributes, ...children) {
|
|
9812
|
+
if (!tag2) {
|
|
9813
|
+
throw new Error(`cannot call createElement with [${String(tag2)}] `);
|
|
9801
9814
|
}
|
|
9802
|
-
const isFragment =
|
|
9803
|
-
const fAsFragment = typeof
|
|
9804
|
-
const tagName = typeof
|
|
9815
|
+
const isFragment = tag2 === Fragment;
|
|
9816
|
+
const fAsFragment = typeof tag2 === "string" || isFragment ? getDefaultOptions().asFragment : tag2.asFragment !== void 0 ? tag2.asFragment : getDefaultOptions().asFragment;
|
|
9817
|
+
const tagName = typeof tag2 === "string" ? tag2 : isFragment ? "Fragment" : `${!tag2.name ? "no-name" : tag2.name}-component`.toLowerCase();
|
|
9805
9818
|
return isFragment ? {
|
|
9806
9819
|
type: "Fragment",
|
|
9807
9820
|
children
|
|
9808
|
-
} : typeof
|
|
9821
|
+
} : typeof tag2 === "function" ? {
|
|
9809
9822
|
type: fAsFragment ? "FragmentComponent" : "Component",
|
|
9810
9823
|
tagName: !fAsFragment ? tagName : void 0,
|
|
9811
9824
|
props: attributes ? attributes : /* @__PURE__ */ Object.create(null),
|
|
9812
|
-
func:
|
|
9825
|
+
func: tag2,
|
|
9813
9826
|
children
|
|
9814
9827
|
} : {
|
|
9815
9828
|
type: "Element",
|
|
@@ -11194,7 +11207,7 @@ var DEFAULT_BUILD_DIR = (0, import_os.tmpdir)();
|
|
|
11194
11207
|
|
|
11195
11208
|
// src/common/jsx.ts
|
|
11196
11209
|
var import_node_path5 = require("node:path");
|
|
11197
|
-
var
|
|
11210
|
+
var import_node_crypto4 = require("node:crypto");
|
|
11198
11211
|
var import_node_fs6 = require("node:fs");
|
|
11199
11212
|
var import_node_process3 = require("node:process");
|
|
11200
11213
|
|
|
@@ -11556,6 +11569,7 @@ async function esBuild(options, logger) {
|
|
|
11556
11569
|
}
|
|
11557
11570
|
|
|
11558
11571
|
// src/services/globals.ts
|
|
11572
|
+
var import_node_cluster2 = __toESM(require("node:cluster"), 1);
|
|
11559
11573
|
var import_node_assert = require("node:assert");
|
|
11560
11574
|
|
|
11561
11575
|
// src/inflate/md.ts
|
|
@@ -11592,263 +11606,2881 @@ var CLEAR_JSX_CACHE = (process.env["CLEAR_JSX_CACHE"] !== void 0 ? process.env["
|
|
|
11592
11606
|
var EDITOR_CONFIG_KEY = "$$editor$$";
|
|
11593
11607
|
var HOT_RELOAD_PATH = "/hot-reload";
|
|
11594
11608
|
|
|
11595
|
-
//
|
|
11596
|
-
var
|
|
11597
|
-
|
|
11598
|
-
|
|
11599
|
-
|
|
11600
|
-
|
|
11601
|
-
|
|
11602
|
-
|
|
11603
|
-
|
|
11604
|
-
|
|
11605
|
-
|
|
11606
|
-
useContext,
|
|
11607
|
-
useRuntime,
|
|
11608
|
-
createContext,
|
|
11609
|
-
useState,
|
|
11610
|
-
useEffect,
|
|
11611
|
-
useQuery,
|
|
11612
|
-
useRef,
|
|
11613
|
-
useElement,
|
|
11614
|
-
useRefresh,
|
|
11615
|
-
Link,
|
|
11616
|
-
Router: Router2,
|
|
11617
|
-
usePathname,
|
|
11618
|
-
define: function define2() {
|
|
11609
|
+
// node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
11610
|
+
var encoder = new TextEncoder();
|
|
11611
|
+
var decoder = new TextDecoder();
|
|
11612
|
+
var MAX_INT32 = 2 ** 32;
|
|
11613
|
+
function concat(...buffers) {
|
|
11614
|
+
const size = buffers.reduce((acc, { length }) => acc + length, 0);
|
|
11615
|
+
const buf = new Uint8Array(size);
|
|
11616
|
+
let i = 0;
|
|
11617
|
+
for (const buffer of buffers) {
|
|
11618
|
+
buf.set(buffer, i);
|
|
11619
|
+
i += buffer.length;
|
|
11619
11620
|
}
|
|
11620
|
-
|
|
11621
|
-
|
|
11622
|
-
|
|
11621
|
+
return buf;
|
|
11622
|
+
}
|
|
11623
|
+
function writeUInt32BE(buf, value, offset) {
|
|
11624
|
+
if (value < 0 || value >= MAX_INT32) {
|
|
11625
|
+
throw new RangeError(`value must be >= 0 and <= ${MAX_INT32 - 1}. Received ${value}`);
|
|
11623
11626
|
}
|
|
11624
|
-
|
|
11625
|
-
var globalServer = Object.freeze({
|
|
11626
|
-
middleware: Object.freeze({
|
|
11627
|
-
buffer: ReadBuffer,
|
|
11628
|
-
url: URLEncodedParser,
|
|
11629
|
-
json: JSONParser,
|
|
11630
|
-
text: TextParser,
|
|
11631
|
-
cors: CORS,
|
|
11632
|
-
session: SessionHandler
|
|
11633
|
-
}),
|
|
11634
|
-
encodeHTML: HTMLEncode,
|
|
11635
|
-
inflateMDtoHTML: inflateMD2HTML
|
|
11636
|
-
});
|
|
11637
|
-
function browserJSXGlobals(inFile, jsxPath = false, useExport = true) {
|
|
11638
|
-
const PRE = `import { enableDebugLog, useRuntime, Link, usePathname, createContext, useContext, useElement, useRefresh, useQuery, define, Router, useState, useEffect, useRef, createElement, Fragment } from "${jsxPath}";
|
|
11639
|
-
globalThis.JSX = Object.freeze({
|
|
11640
|
-
createElement,
|
|
11641
|
-
Fragment,
|
|
11642
|
-
enableDebugLog
|
|
11643
|
-
});
|
|
11644
|
-
|
|
11645
|
-
globalThis.newParser = () => new Parser();
|
|
11646
|
-
globalThis.jsx = Object.freeze({
|
|
11647
|
-
define,
|
|
11648
|
-
useRuntime,
|
|
11649
|
-
createContext,
|
|
11650
|
-
useContext,
|
|
11651
|
-
useState,
|
|
11652
|
-
useEffect,
|
|
11653
|
-
useQuery,
|
|
11654
|
-
useRef,
|
|
11655
|
-
useElement,
|
|
11656
|
-
useRefresh,
|
|
11657
|
-
usePathname,
|
|
11658
|
-
Link,
|
|
11659
|
-
Router
|
|
11660
|
-
});`;
|
|
11661
|
-
return `${jsxPath ? PRE : ""}
|
|
11662
|
-
${useExport ? `export * from "${inFile}";import * as lib from "${inFile}";export default lib.default;` : `import * as lib from "${inFile}"`}`;
|
|
11627
|
+
buf.set([value >>> 24, value >>> 16, value >>> 8, value & 255], offset);
|
|
11663
11628
|
}
|
|
11664
|
-
function
|
|
11665
|
-
|
|
11666
|
-
|
|
11667
|
-
|
|
11668
|
-
|
|
11629
|
+
function uint64be(value) {
|
|
11630
|
+
const high = Math.floor(value / MAX_INT32);
|
|
11631
|
+
const low = value % MAX_INT32;
|
|
11632
|
+
const buf = new Uint8Array(8);
|
|
11633
|
+
writeUInt32BE(buf, high, 0);
|
|
11634
|
+
writeUInt32BE(buf, low, 4);
|
|
11635
|
+
return buf;
|
|
11669
11636
|
}
|
|
11670
|
-
function
|
|
11671
|
-
|
|
11672
|
-
|
|
11673
|
-
|
|
11674
|
-
(0, import_node_assert.strictEqual)(globalThis.jsx, globaljsx, "globalThis.jsx tamperered");
|
|
11675
|
-
(0, import_node_assert.strictEqual)(globalThis.window, globalWindow, "globalThis.window tamperered");
|
|
11676
|
-
} catch (e) {
|
|
11677
|
-
console.error(e);
|
|
11678
|
-
process.exit(EXIT_CODES.GLOBALS_ALTERED);
|
|
11679
|
-
}
|
|
11637
|
+
function uint32be(value) {
|
|
11638
|
+
const buf = new Uint8Array(4);
|
|
11639
|
+
writeUInt32BE(buf, value);
|
|
11640
|
+
return buf;
|
|
11680
11641
|
}
|
|
11681
11642
|
|
|
11682
|
-
//
|
|
11683
|
-
|
|
11684
|
-
|
|
11685
|
-
|
|
11686
|
-
|
|
11687
|
-
|
|
11688
|
-
|
|
11643
|
+
// node_modules/jose/dist/webapi/lib/base64.js
|
|
11644
|
+
function encodeBase64(input) {
|
|
11645
|
+
if (Uint8Array.prototype.toBase64) {
|
|
11646
|
+
return input.toBase64();
|
|
11647
|
+
}
|
|
11648
|
+
const CHUNK_SIZE = 32768;
|
|
11649
|
+
const arr = [];
|
|
11650
|
+
for (let i = 0; i < input.length; i += CHUNK_SIZE) {
|
|
11651
|
+
arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
|
|
11652
|
+
}
|
|
11653
|
+
return btoa(arr.join(""));
|
|
11689
11654
|
}
|
|
11690
|
-
|
|
11691
|
-
|
|
11692
|
-
|
|
11693
|
-
|
|
11694
|
-
|
|
11695
|
-
|
|
11696
|
-
|
|
11697
|
-
|
|
11698
|
-
|
|
11699
|
-
|
|
11700
|
-
|
|
11701
|
-
|
|
11655
|
+
function decodeBase64(encoded) {
|
|
11656
|
+
if (Uint8Array.fromBase64) {
|
|
11657
|
+
return Uint8Array.fromBase64(encoded);
|
|
11658
|
+
}
|
|
11659
|
+
const binary = atob(encoded);
|
|
11660
|
+
const bytes = new Uint8Array(binary.length);
|
|
11661
|
+
for (let i = 0; i < binary.length; i++) {
|
|
11662
|
+
bytes[i] = binary.charCodeAt(i);
|
|
11663
|
+
}
|
|
11664
|
+
return bytes;
|
|
11665
|
+
}
|
|
11666
|
+
|
|
11667
|
+
// node_modules/jose/dist/webapi/util/base64url.js
|
|
11668
|
+
function decode(input) {
|
|
11669
|
+
if (Uint8Array.fromBase64) {
|
|
11670
|
+
return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), {
|
|
11671
|
+
alphabet: "base64url"
|
|
11672
|
+
});
|
|
11673
|
+
}
|
|
11674
|
+
let encoded = input;
|
|
11675
|
+
if (encoded instanceof Uint8Array) {
|
|
11676
|
+
encoded = decoder.decode(encoded);
|
|
11677
|
+
}
|
|
11678
|
+
encoded = encoded.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
|
|
11702
11679
|
try {
|
|
11703
|
-
|
|
11704
|
-
|
|
11705
|
-
|
|
11706
|
-
});
|
|
11707
|
-
(0, import_node_fs6.writeFileSync)(inFileTmp, browserJSXGlobals(inFile, false, options.useExport));
|
|
11708
|
-
logger?.trace("inflating [%s] from [%s]. to change the import folder set JSX_TMP", (0, import_node_path5.relative)((0, import_node_process3.cwd)(), inFile), (0, import_node_path5.dirname)((0, import_node_path5.relative)(JSX_TMP_DIR, inFileTmp)));
|
|
11709
|
-
const { outputFiles: [{ contents }] } = await esBuild({
|
|
11710
|
-
...DEFAULT_ESOPTION,
|
|
11711
|
-
entryPoints: [inFileTmp],
|
|
11712
|
-
minify: options.minify
|
|
11713
|
-
});
|
|
11714
|
-
if (CLEAR_JSX_CACHE) {
|
|
11715
|
-
logger?.trace("clearing cache at [%s] to change this behaivor set CLEAR_JSX_CACHE to 0", tmpBuildDir);
|
|
11716
|
-
(0, import_node_fs6.unlinkSync)(inFileTmp);
|
|
11717
|
-
(0, import_node_fs6.rmdirSync)(tmpBuildDir);
|
|
11718
|
-
}
|
|
11719
|
-
return contents;
|
|
11720
|
-
} else {
|
|
11721
|
-
(0, import_node_fs6.mkdirSync)(tmpBuildDir, {
|
|
11722
|
-
recursive: true
|
|
11723
|
-
});
|
|
11724
|
-
(0, import_node_fs6.writeFileSync)(inFileTmp, browserJSXGlobals(inFile, jsxJSPath));
|
|
11725
|
-
logger?.trace("inflating [%s] from [%s] with jsx.js embedded. to change the import folder set JSX_TMP", (0, import_node_path5.relative)((0, import_node_process3.cwd)(), inFile), (0, import_node_path5.dirname)((0, import_node_path5.relative)(JSX_TMP_DIR, inFileTmp)));
|
|
11726
|
-
const { outputFiles: [{ contents }] } = await esBuild({
|
|
11727
|
-
...DEFAULT_ESOPTION,
|
|
11728
|
-
entryPoints: [inFileTmp],
|
|
11729
|
-
minify: options.minify
|
|
11730
|
-
});
|
|
11731
|
-
if (CLEAR_JSX_CACHE) {
|
|
11732
|
-
logger?.trace("clearing cache at [%s] to change this behaivor set CLEAR_JSX_CACHE to 0", tmpBuildDir);
|
|
11733
|
-
(0, import_node_fs6.unlinkSync)(inFileTmp);
|
|
11734
|
-
(0, import_node_fs6.rmdirSync)(tmpBuildDir);
|
|
11735
|
-
}
|
|
11736
|
-
return contents;
|
|
11737
|
-
}
|
|
11738
|
-
} catch (e) {
|
|
11739
|
-
logger?.error("error with: " + inFile);
|
|
11740
|
-
logger?.error(e);
|
|
11741
|
-
if (options.embemedJSX) {
|
|
11742
|
-
if (CLEAR_JSX_CACHE) {
|
|
11743
|
-
logger?.trace("clearing cache at [%s] to change this behaivor set CLEAR_JSX_CACHE to 0", tmpBuildDir);
|
|
11744
|
-
(0, import_node_fs6.unlinkSync)(inFileTmp);
|
|
11745
|
-
(0, import_node_fs6.rmdirSync)(tmpBuildDir);
|
|
11746
|
-
} else {
|
|
11747
|
-
logger?.error("error with: %s", inFileTmp);
|
|
11748
|
-
logger?.trace("NOT clearing cache. to change this behaivor set CLEAR_JSX_CACHE to 1", tmpBuildDir);
|
|
11749
|
-
}
|
|
11750
|
-
}
|
|
11751
|
-
throw e;
|
|
11680
|
+
return decodeBase64(encoded);
|
|
11681
|
+
} catch {
|
|
11682
|
+
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
11752
11683
|
}
|
|
11753
11684
|
}
|
|
11754
|
-
|
|
11755
|
-
|
|
11756
|
-
|
|
11757
|
-
|
|
11758
|
-
|
|
11759
|
-
|
|
11760
|
-
|
|
11761
|
-
|
|
11762
|
-
|
|
11763
|
-
|
|
11764
|
-
|
|
11765
|
-
|
|
11766
|
-
|
|
11767
|
-
|
|
11768
|
-
|
|
11769
|
-
|
|
11770
|
-
|
|
11771
|
-
|
|
11772
|
-
|
|
11685
|
+
function encode(input) {
|
|
11686
|
+
let unencoded = input;
|
|
11687
|
+
if (typeof unencoded === "string") {
|
|
11688
|
+
unencoded = encoder.encode(unencoded);
|
|
11689
|
+
}
|
|
11690
|
+
if (Uint8Array.prototype.toBase64) {
|
|
11691
|
+
return unencoded.toBase64({ alphabet: "base64url", omitPadding: true });
|
|
11692
|
+
}
|
|
11693
|
+
return encodeBase64(unencoded).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
11694
|
+
}
|
|
11695
|
+
|
|
11696
|
+
// node_modules/jose/dist/webapi/util/errors.js
|
|
11697
|
+
var JOSEError = class extends Error {
|
|
11698
|
+
static code = "ERR_JOSE_GENERIC";
|
|
11699
|
+
code = "ERR_JOSE_GENERIC";
|
|
11700
|
+
constructor(message2, options) {
|
|
11701
|
+
super(message2, options);
|
|
11702
|
+
this.name = this.constructor.name;
|
|
11703
|
+
Error.captureStackTrace?.(this, this.constructor);
|
|
11773
11704
|
}
|
|
11774
|
-
//mode:"add_extra"
|
|
11775
11705
|
};
|
|
11776
|
-
var
|
|
11777
|
-
|
|
11778
|
-
|
|
11779
|
-
|
|
11780
|
-
|
|
11781
|
-
|
|
11782
|
-
|
|
11706
|
+
var JWTClaimValidationFailed = class extends JOSEError {
|
|
11707
|
+
static code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
11708
|
+
code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
11709
|
+
claim;
|
|
11710
|
+
reason;
|
|
11711
|
+
payload;
|
|
11712
|
+
constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
|
|
11713
|
+
super(message2, { cause: { claim, reason, payload } });
|
|
11714
|
+
this.claim = claim;
|
|
11715
|
+
this.reason = reason;
|
|
11716
|
+
this.payload = payload;
|
|
11783
11717
|
}
|
|
11784
|
-
//mode:"add_extra"
|
|
11785
11718
|
};
|
|
11786
|
-
var
|
|
11787
|
-
|
|
11788
|
-
|
|
11789
|
-
|
|
11790
|
-
|
|
11791
|
-
|
|
11792
|
-
|
|
11719
|
+
var JWTExpired = class extends JOSEError {
|
|
11720
|
+
static code = "ERR_JWT_EXPIRED";
|
|
11721
|
+
code = "ERR_JWT_EXPIRED";
|
|
11722
|
+
claim;
|
|
11723
|
+
reason;
|
|
11724
|
+
payload;
|
|
11725
|
+
constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
|
|
11726
|
+
super(message2, { cause: { claim, reason, payload } });
|
|
11727
|
+
this.claim = claim;
|
|
11728
|
+
this.reason = reason;
|
|
11729
|
+
this.payload = payload;
|
|
11793
11730
|
}
|
|
11794
|
-
//mode:"add_extra"
|
|
11795
11731
|
};
|
|
11796
|
-
var
|
|
11797
|
-
|
|
11798
|
-
|
|
11799
|
-
up: "function",
|
|
11800
|
-
down: "function"
|
|
11801
|
-
},
|
|
11802
|
-
mode: "add_extra"
|
|
11732
|
+
var JOSEAlgNotAllowed = class extends JOSEError {
|
|
11733
|
+
static code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
11734
|
+
code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
11803
11735
|
};
|
|
11804
|
-
var
|
|
11805
|
-
|
|
11806
|
-
|
|
11807
|
-
origins: "string[]?|string?",
|
|
11808
|
-
validate: "function?",
|
|
11809
|
-
methods: "string?",
|
|
11810
|
-
preflightContinue: "boolean?"
|
|
11811
|
-
}
|
|
11812
|
-
//mode:"add_extra"
|
|
11736
|
+
var JOSENotSupported = class extends JOSEError {
|
|
11737
|
+
static code = "ERR_JOSE_NOT_SUPPORTED";
|
|
11738
|
+
code = "ERR_JOSE_NOT_SUPPORTED";
|
|
11813
11739
|
};
|
|
11814
|
-
var
|
|
11815
|
-
|
|
11816
|
-
|
|
11817
|
-
|
|
11818
|
-
|
|
11819
|
-
maxConnections: "number?",
|
|
11820
|
-
validate: "function?",
|
|
11821
|
-
onConnection: "function?",
|
|
11822
|
-
onMessage: "function?",
|
|
11823
|
-
onDisconnect: "function?"
|
|
11740
|
+
var JWEDecryptionFailed = class extends JOSEError {
|
|
11741
|
+
static code = "ERR_JWE_DECRYPTION_FAILED";
|
|
11742
|
+
code = "ERR_JWE_DECRYPTION_FAILED";
|
|
11743
|
+
constructor(message2 = "decryption operation failed", options) {
|
|
11744
|
+
super(message2, options);
|
|
11824
11745
|
}
|
|
11825
|
-
//mode:"add_extra"
|
|
11826
11746
|
};
|
|
11827
|
-
var
|
|
11828
|
-
|
|
11829
|
-
|
|
11830
|
-
url: "string?",
|
|
11831
|
-
disabled: "boolean?",
|
|
11832
|
-
storage: "string?",
|
|
11833
|
-
dialect: "string?",
|
|
11834
|
-
name: "string"
|
|
11835
|
-
}
|
|
11836
|
-
//mode:"add_extra"
|
|
11747
|
+
var JWEInvalid = class extends JOSEError {
|
|
11748
|
+
static code = "ERR_JWE_INVALID";
|
|
11749
|
+
code = "ERR_JWE_INVALID";
|
|
11837
11750
|
};
|
|
11838
|
-
var
|
|
11839
|
-
|
|
11840
|
-
|
|
11841
|
-
|
|
11842
|
-
|
|
11843
|
-
|
|
11844
|
-
|
|
11845
|
-
|
|
11751
|
+
var JWSInvalid = class extends JOSEError {
|
|
11752
|
+
static code = "ERR_JWS_INVALID";
|
|
11753
|
+
code = "ERR_JWS_INVALID";
|
|
11754
|
+
};
|
|
11755
|
+
var JWTInvalid = class extends JOSEError {
|
|
11756
|
+
static code = "ERR_JWT_INVALID";
|
|
11757
|
+
code = "ERR_JWT_INVALID";
|
|
11758
|
+
};
|
|
11759
|
+
var JWSSignatureVerificationFailed = class extends JOSEError {
|
|
11760
|
+
static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
11761
|
+
code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
11762
|
+
constructor(message2 = "signature verification failed", options) {
|
|
11763
|
+
super(message2, options);
|
|
11846
11764
|
}
|
|
11847
|
-
//mode:"add_extra"
|
|
11848
11765
|
};
|
|
11849
|
-
|
|
11850
|
-
|
|
11851
|
-
|
|
11766
|
+
|
|
11767
|
+
// node_modules/jose/dist/webapi/lib/iv.js
|
|
11768
|
+
function bitLength(alg) {
|
|
11769
|
+
switch (alg) {
|
|
11770
|
+
case "A128GCM":
|
|
11771
|
+
case "A128GCMKW":
|
|
11772
|
+
case "A192GCM":
|
|
11773
|
+
case "A192GCMKW":
|
|
11774
|
+
case "A256GCM":
|
|
11775
|
+
case "A256GCMKW":
|
|
11776
|
+
return 96;
|
|
11777
|
+
case "A128CBC-HS256":
|
|
11778
|
+
case "A192CBC-HS384":
|
|
11779
|
+
case "A256CBC-HS512":
|
|
11780
|
+
return 128;
|
|
11781
|
+
default:
|
|
11782
|
+
throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
11783
|
+
}
|
|
11784
|
+
}
|
|
11785
|
+
var iv_default = (alg) => crypto.getRandomValues(new Uint8Array(bitLength(alg) >> 3));
|
|
11786
|
+
|
|
11787
|
+
// node_modules/jose/dist/webapi/lib/check_iv_length.js
|
|
11788
|
+
var check_iv_length_default = (enc, iv) => {
|
|
11789
|
+
if (iv.length << 3 !== bitLength(enc)) {
|
|
11790
|
+
throw new JWEInvalid("Invalid Initialization Vector length");
|
|
11791
|
+
}
|
|
11792
|
+
};
|
|
11793
|
+
|
|
11794
|
+
// node_modules/jose/dist/webapi/lib/check_cek_length.js
|
|
11795
|
+
var check_cek_length_default = (cek, expected) => {
|
|
11796
|
+
const actual = cek.byteLength << 3;
|
|
11797
|
+
if (actual !== expected) {
|
|
11798
|
+
throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
|
|
11799
|
+
}
|
|
11800
|
+
};
|
|
11801
|
+
|
|
11802
|
+
// node_modules/jose/dist/webapi/lib/crypto_key.js
|
|
11803
|
+
function unusable(name, prop = "algorithm.name") {
|
|
11804
|
+
return new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
11805
|
+
}
|
|
11806
|
+
function isAlgorithm(algorithm, name) {
|
|
11807
|
+
return algorithm.name === name;
|
|
11808
|
+
}
|
|
11809
|
+
function getHashLength(hash) {
|
|
11810
|
+
return parseInt(hash.name.slice(4), 10);
|
|
11811
|
+
}
|
|
11812
|
+
function getNamedCurve(alg) {
|
|
11813
|
+
switch (alg) {
|
|
11814
|
+
case "ES256":
|
|
11815
|
+
return "P-256";
|
|
11816
|
+
case "ES384":
|
|
11817
|
+
return "P-384";
|
|
11818
|
+
case "ES512":
|
|
11819
|
+
return "P-521";
|
|
11820
|
+
default:
|
|
11821
|
+
throw new Error("unreachable");
|
|
11822
|
+
}
|
|
11823
|
+
}
|
|
11824
|
+
function checkUsage(key, usage2) {
|
|
11825
|
+
if (usage2 && !key.usages.includes(usage2)) {
|
|
11826
|
+
throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage2}.`);
|
|
11827
|
+
}
|
|
11828
|
+
}
|
|
11829
|
+
function checkSigCryptoKey(key, alg, usage2) {
|
|
11830
|
+
switch (alg) {
|
|
11831
|
+
case "HS256":
|
|
11832
|
+
case "HS384":
|
|
11833
|
+
case "HS512": {
|
|
11834
|
+
if (!isAlgorithm(key.algorithm, "HMAC"))
|
|
11835
|
+
throw unusable("HMAC");
|
|
11836
|
+
const expected = parseInt(alg.slice(2), 10);
|
|
11837
|
+
const actual = getHashLength(key.algorithm.hash);
|
|
11838
|
+
if (actual !== expected)
|
|
11839
|
+
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
11840
|
+
break;
|
|
11841
|
+
}
|
|
11842
|
+
case "RS256":
|
|
11843
|
+
case "RS384":
|
|
11844
|
+
case "RS512": {
|
|
11845
|
+
if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5"))
|
|
11846
|
+
throw unusable("RSASSA-PKCS1-v1_5");
|
|
11847
|
+
const expected = parseInt(alg.slice(2), 10);
|
|
11848
|
+
const actual = getHashLength(key.algorithm.hash);
|
|
11849
|
+
if (actual !== expected)
|
|
11850
|
+
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
11851
|
+
break;
|
|
11852
|
+
}
|
|
11853
|
+
case "PS256":
|
|
11854
|
+
case "PS384":
|
|
11855
|
+
case "PS512": {
|
|
11856
|
+
if (!isAlgorithm(key.algorithm, "RSA-PSS"))
|
|
11857
|
+
throw unusable("RSA-PSS");
|
|
11858
|
+
const expected = parseInt(alg.slice(2), 10);
|
|
11859
|
+
const actual = getHashLength(key.algorithm.hash);
|
|
11860
|
+
if (actual !== expected)
|
|
11861
|
+
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
11862
|
+
break;
|
|
11863
|
+
}
|
|
11864
|
+
case "Ed25519":
|
|
11865
|
+
case "EdDSA": {
|
|
11866
|
+
if (!isAlgorithm(key.algorithm, "Ed25519"))
|
|
11867
|
+
throw unusable("Ed25519");
|
|
11868
|
+
break;
|
|
11869
|
+
}
|
|
11870
|
+
case "ES256":
|
|
11871
|
+
case "ES384":
|
|
11872
|
+
case "ES512": {
|
|
11873
|
+
if (!isAlgorithm(key.algorithm, "ECDSA"))
|
|
11874
|
+
throw unusable("ECDSA");
|
|
11875
|
+
const expected = getNamedCurve(alg);
|
|
11876
|
+
const actual = key.algorithm.namedCurve;
|
|
11877
|
+
if (actual !== expected)
|
|
11878
|
+
throw unusable(expected, "algorithm.namedCurve");
|
|
11879
|
+
break;
|
|
11880
|
+
}
|
|
11881
|
+
default:
|
|
11882
|
+
throw new TypeError("CryptoKey does not support this operation");
|
|
11883
|
+
}
|
|
11884
|
+
checkUsage(key, usage2);
|
|
11885
|
+
}
|
|
11886
|
+
function checkEncCryptoKey(key, alg, usage2) {
|
|
11887
|
+
switch (alg) {
|
|
11888
|
+
case "A128GCM":
|
|
11889
|
+
case "A192GCM":
|
|
11890
|
+
case "A256GCM": {
|
|
11891
|
+
if (!isAlgorithm(key.algorithm, "AES-GCM"))
|
|
11892
|
+
throw unusable("AES-GCM");
|
|
11893
|
+
const expected = parseInt(alg.slice(1, 4), 10);
|
|
11894
|
+
const actual = key.algorithm.length;
|
|
11895
|
+
if (actual !== expected)
|
|
11896
|
+
throw unusable(expected, "algorithm.length");
|
|
11897
|
+
break;
|
|
11898
|
+
}
|
|
11899
|
+
case "A128KW":
|
|
11900
|
+
case "A192KW":
|
|
11901
|
+
case "A256KW": {
|
|
11902
|
+
if (!isAlgorithm(key.algorithm, "AES-KW"))
|
|
11903
|
+
throw unusable("AES-KW");
|
|
11904
|
+
const expected = parseInt(alg.slice(1, 4), 10);
|
|
11905
|
+
const actual = key.algorithm.length;
|
|
11906
|
+
if (actual !== expected)
|
|
11907
|
+
throw unusable(expected, "algorithm.length");
|
|
11908
|
+
break;
|
|
11909
|
+
}
|
|
11910
|
+
case "ECDH": {
|
|
11911
|
+
switch (key.algorithm.name) {
|
|
11912
|
+
case "ECDH":
|
|
11913
|
+
case "X25519":
|
|
11914
|
+
break;
|
|
11915
|
+
default:
|
|
11916
|
+
throw unusable("ECDH or X25519");
|
|
11917
|
+
}
|
|
11918
|
+
break;
|
|
11919
|
+
}
|
|
11920
|
+
case "PBES2-HS256+A128KW":
|
|
11921
|
+
case "PBES2-HS384+A192KW":
|
|
11922
|
+
case "PBES2-HS512+A256KW":
|
|
11923
|
+
if (!isAlgorithm(key.algorithm, "PBKDF2"))
|
|
11924
|
+
throw unusable("PBKDF2");
|
|
11925
|
+
break;
|
|
11926
|
+
case "RSA-OAEP":
|
|
11927
|
+
case "RSA-OAEP-256":
|
|
11928
|
+
case "RSA-OAEP-384":
|
|
11929
|
+
case "RSA-OAEP-512": {
|
|
11930
|
+
if (!isAlgorithm(key.algorithm, "RSA-OAEP"))
|
|
11931
|
+
throw unusable("RSA-OAEP");
|
|
11932
|
+
const expected = parseInt(alg.slice(9), 10) || 1;
|
|
11933
|
+
const actual = getHashLength(key.algorithm.hash);
|
|
11934
|
+
if (actual !== expected)
|
|
11935
|
+
throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
11936
|
+
break;
|
|
11937
|
+
}
|
|
11938
|
+
default:
|
|
11939
|
+
throw new TypeError("CryptoKey does not support this operation");
|
|
11940
|
+
}
|
|
11941
|
+
checkUsage(key, usage2);
|
|
11942
|
+
}
|
|
11943
|
+
|
|
11944
|
+
// node_modules/jose/dist/webapi/lib/invalid_key_input.js
|
|
11945
|
+
function message(msg, actual, ...types) {
|
|
11946
|
+
types = types.filter(Boolean);
|
|
11947
|
+
if (types.length > 2) {
|
|
11948
|
+
const last = types.pop();
|
|
11949
|
+
msg += `one of type ${types.join(", ")}, or ${last}.`;
|
|
11950
|
+
} else if (types.length === 2) {
|
|
11951
|
+
msg += `one of type ${types[0]} or ${types[1]}.`;
|
|
11952
|
+
} else {
|
|
11953
|
+
msg += `of type ${types[0]}.`;
|
|
11954
|
+
}
|
|
11955
|
+
if (actual == null) {
|
|
11956
|
+
msg += ` Received ${actual}`;
|
|
11957
|
+
} else if (typeof actual === "function" && actual.name) {
|
|
11958
|
+
msg += ` Received function ${actual.name}`;
|
|
11959
|
+
} else if (typeof actual === "object" && actual != null) {
|
|
11960
|
+
if (actual.constructor?.name) {
|
|
11961
|
+
msg += ` Received an instance of ${actual.constructor.name}`;
|
|
11962
|
+
}
|
|
11963
|
+
}
|
|
11964
|
+
return msg;
|
|
11965
|
+
}
|
|
11966
|
+
var invalid_key_input_default = (actual, ...types) => {
|
|
11967
|
+
return message("Key must be ", actual, ...types);
|
|
11968
|
+
};
|
|
11969
|
+
function withAlg(alg, actual, ...types) {
|
|
11970
|
+
return message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
11971
|
+
}
|
|
11972
|
+
|
|
11973
|
+
// node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
11974
|
+
function assertCryptoKey(key) {
|
|
11975
|
+
if (!isCryptoKey(key)) {
|
|
11976
|
+
throw new Error("CryptoKey instance expected");
|
|
11977
|
+
}
|
|
11978
|
+
}
|
|
11979
|
+
function isCryptoKey(key) {
|
|
11980
|
+
return key?.[Symbol.toStringTag] === "CryptoKey";
|
|
11981
|
+
}
|
|
11982
|
+
function isKeyObject(key) {
|
|
11983
|
+
return key?.[Symbol.toStringTag] === "KeyObject";
|
|
11984
|
+
}
|
|
11985
|
+
var is_key_like_default = (key) => {
|
|
11986
|
+
return isCryptoKey(key) || isKeyObject(key);
|
|
11987
|
+
};
|
|
11988
|
+
|
|
11989
|
+
// node_modules/jose/dist/webapi/lib/decrypt.js
|
|
11990
|
+
async function timingSafeEqual(a, b) {
|
|
11991
|
+
if (!(a instanceof Uint8Array)) {
|
|
11992
|
+
throw new TypeError("First argument must be a buffer");
|
|
11993
|
+
}
|
|
11994
|
+
if (!(b instanceof Uint8Array)) {
|
|
11995
|
+
throw new TypeError("Second argument must be a buffer");
|
|
11996
|
+
}
|
|
11997
|
+
const algorithm = { name: "HMAC", hash: "SHA-256" };
|
|
11998
|
+
const key = await crypto.subtle.generateKey(algorithm, false, ["sign"]);
|
|
11999
|
+
const aHmac = new Uint8Array(await crypto.subtle.sign(algorithm, key, a));
|
|
12000
|
+
const bHmac = new Uint8Array(await crypto.subtle.sign(algorithm, key, b));
|
|
12001
|
+
let out = 0;
|
|
12002
|
+
let i = -1;
|
|
12003
|
+
while (++i < 32) {
|
|
12004
|
+
out |= aHmac[i] ^ bHmac[i];
|
|
12005
|
+
}
|
|
12006
|
+
return out === 0;
|
|
12007
|
+
}
|
|
12008
|
+
async function cbcDecrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
12009
|
+
if (!(cek instanceof Uint8Array)) {
|
|
12010
|
+
throw new TypeError(invalid_key_input_default(cek, "Uint8Array"));
|
|
12011
|
+
}
|
|
12012
|
+
const keySize = parseInt(enc.slice(1, 4), 10);
|
|
12013
|
+
const encKey = await crypto.subtle.importKey("raw", cek.subarray(keySize >> 3), "AES-CBC", false, ["decrypt"]);
|
|
12014
|
+
const macKey = await crypto.subtle.importKey("raw", cek.subarray(0, keySize >> 3), {
|
|
12015
|
+
hash: `SHA-${keySize << 1}`,
|
|
12016
|
+
name: "HMAC"
|
|
12017
|
+
}, false, ["sign"]);
|
|
12018
|
+
const macData = concat(aad, iv, ciphertext, uint64be(aad.length << 3));
|
|
12019
|
+
const expectedTag = new Uint8Array((await crypto.subtle.sign("HMAC", macKey, macData)).slice(0, keySize >> 3));
|
|
12020
|
+
let macCheckPassed;
|
|
12021
|
+
try {
|
|
12022
|
+
macCheckPassed = await timingSafeEqual(tag2, expectedTag);
|
|
12023
|
+
} catch {
|
|
12024
|
+
}
|
|
12025
|
+
if (!macCheckPassed) {
|
|
12026
|
+
throw new JWEDecryptionFailed();
|
|
12027
|
+
}
|
|
12028
|
+
let plaintext;
|
|
12029
|
+
try {
|
|
12030
|
+
plaintext = new Uint8Array(await crypto.subtle.decrypt({ iv, name: "AES-CBC" }, encKey, ciphertext));
|
|
12031
|
+
} catch {
|
|
12032
|
+
}
|
|
12033
|
+
if (!plaintext) {
|
|
12034
|
+
throw new JWEDecryptionFailed();
|
|
12035
|
+
}
|
|
12036
|
+
return plaintext;
|
|
12037
|
+
}
|
|
12038
|
+
async function gcmDecrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
12039
|
+
let encKey;
|
|
12040
|
+
if (cek instanceof Uint8Array) {
|
|
12041
|
+
encKey = await crypto.subtle.importKey("raw", cek, "AES-GCM", false, ["decrypt"]);
|
|
12042
|
+
} else {
|
|
12043
|
+
checkEncCryptoKey(cek, enc, "decrypt");
|
|
12044
|
+
encKey = cek;
|
|
12045
|
+
}
|
|
12046
|
+
try {
|
|
12047
|
+
return new Uint8Array(await crypto.subtle.decrypt({
|
|
12048
|
+
additionalData: aad,
|
|
12049
|
+
iv,
|
|
12050
|
+
name: "AES-GCM",
|
|
12051
|
+
tagLength: 128
|
|
12052
|
+
}, encKey, concat(ciphertext, tag2)));
|
|
12053
|
+
} catch {
|
|
12054
|
+
throw new JWEDecryptionFailed();
|
|
12055
|
+
}
|
|
12056
|
+
}
|
|
12057
|
+
var decrypt_default = async (enc, cek, ciphertext, iv, tag2, aad) => {
|
|
12058
|
+
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
|
12059
|
+
throw new TypeError(invalid_key_input_default(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
|
|
12060
|
+
}
|
|
12061
|
+
if (!iv) {
|
|
12062
|
+
throw new JWEInvalid("JWE Initialization Vector missing");
|
|
12063
|
+
}
|
|
12064
|
+
if (!tag2) {
|
|
12065
|
+
throw new JWEInvalid("JWE Authentication Tag missing");
|
|
12066
|
+
}
|
|
12067
|
+
check_iv_length_default(enc, iv);
|
|
12068
|
+
switch (enc) {
|
|
12069
|
+
case "A128CBC-HS256":
|
|
12070
|
+
case "A192CBC-HS384":
|
|
12071
|
+
case "A256CBC-HS512":
|
|
12072
|
+
if (cek instanceof Uint8Array)
|
|
12073
|
+
check_cek_length_default(cek, parseInt(enc.slice(-3), 10));
|
|
12074
|
+
return cbcDecrypt(enc, cek, ciphertext, iv, tag2, aad);
|
|
12075
|
+
case "A128GCM":
|
|
12076
|
+
case "A192GCM":
|
|
12077
|
+
case "A256GCM":
|
|
12078
|
+
if (cek instanceof Uint8Array)
|
|
12079
|
+
check_cek_length_default(cek, parseInt(enc.slice(1, 4), 10));
|
|
12080
|
+
return gcmDecrypt(enc, cek, ciphertext, iv, tag2, aad);
|
|
12081
|
+
default:
|
|
12082
|
+
throw new JOSENotSupported("Unsupported JWE Content Encryption Algorithm");
|
|
12083
|
+
}
|
|
12084
|
+
};
|
|
12085
|
+
|
|
12086
|
+
// node_modules/jose/dist/webapi/lib/is_disjoint.js
|
|
12087
|
+
var is_disjoint_default = (...headers) => {
|
|
12088
|
+
const sources = headers.filter(Boolean);
|
|
12089
|
+
if (sources.length === 0 || sources.length === 1) {
|
|
12090
|
+
return true;
|
|
12091
|
+
}
|
|
12092
|
+
let acc;
|
|
12093
|
+
for (const header of sources) {
|
|
12094
|
+
const parameters = Object.keys(header);
|
|
12095
|
+
if (!acc || acc.size === 0) {
|
|
12096
|
+
acc = new Set(parameters);
|
|
12097
|
+
continue;
|
|
12098
|
+
}
|
|
12099
|
+
for (const parameter of parameters) {
|
|
12100
|
+
if (acc.has(parameter)) {
|
|
12101
|
+
return false;
|
|
12102
|
+
}
|
|
12103
|
+
acc.add(parameter);
|
|
12104
|
+
}
|
|
12105
|
+
}
|
|
12106
|
+
return true;
|
|
12107
|
+
};
|
|
12108
|
+
|
|
12109
|
+
// node_modules/jose/dist/webapi/lib/is_object.js
|
|
12110
|
+
function isObjectLike(value) {
|
|
12111
|
+
return typeof value === "object" && value !== null;
|
|
12112
|
+
}
|
|
12113
|
+
var is_object_default = (input) => {
|
|
12114
|
+
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") {
|
|
12115
|
+
return false;
|
|
12116
|
+
}
|
|
12117
|
+
if (Object.getPrototypeOf(input) === null) {
|
|
12118
|
+
return true;
|
|
12119
|
+
}
|
|
12120
|
+
let proto = input;
|
|
12121
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
12122
|
+
proto = Object.getPrototypeOf(proto);
|
|
12123
|
+
}
|
|
12124
|
+
return Object.getPrototypeOf(input) === proto;
|
|
12125
|
+
};
|
|
12126
|
+
|
|
12127
|
+
// node_modules/jose/dist/webapi/lib/aeskw.js
|
|
12128
|
+
function checkKeySize(key, alg) {
|
|
12129
|
+
if (key.algorithm.length !== parseInt(alg.slice(1, 4), 10)) {
|
|
12130
|
+
throw new TypeError(`Invalid key size for alg: ${alg}`);
|
|
12131
|
+
}
|
|
12132
|
+
}
|
|
12133
|
+
function getCryptoKey(key, alg, usage2) {
|
|
12134
|
+
if (key instanceof Uint8Array) {
|
|
12135
|
+
return crypto.subtle.importKey("raw", key, "AES-KW", true, [usage2]);
|
|
12136
|
+
}
|
|
12137
|
+
checkEncCryptoKey(key, alg, usage2);
|
|
12138
|
+
return key;
|
|
12139
|
+
}
|
|
12140
|
+
async function wrap(alg, key, cek) {
|
|
12141
|
+
const cryptoKey = await getCryptoKey(key, alg, "wrapKey");
|
|
12142
|
+
checkKeySize(cryptoKey, alg);
|
|
12143
|
+
const cryptoKeyCek = await crypto.subtle.importKey("raw", cek, { hash: "SHA-256", name: "HMAC" }, true, ["sign"]);
|
|
12144
|
+
return new Uint8Array(await crypto.subtle.wrapKey("raw", cryptoKeyCek, cryptoKey, "AES-KW"));
|
|
12145
|
+
}
|
|
12146
|
+
async function unwrap(alg, key, encryptedKey) {
|
|
12147
|
+
const cryptoKey = await getCryptoKey(key, alg, "unwrapKey");
|
|
12148
|
+
checkKeySize(cryptoKey, alg);
|
|
12149
|
+
const cryptoKeyCek = await crypto.subtle.unwrapKey("raw", encryptedKey, cryptoKey, "AES-KW", { hash: "SHA-256", name: "HMAC" }, true, ["sign"]);
|
|
12150
|
+
return new Uint8Array(await crypto.subtle.exportKey("raw", cryptoKeyCek));
|
|
12151
|
+
}
|
|
12152
|
+
|
|
12153
|
+
// node_modules/jose/dist/webapi/lib/digest.js
|
|
12154
|
+
var digest_default = async (algorithm, data) => {
|
|
12155
|
+
const subtleDigest = `SHA-${algorithm.slice(-3)}`;
|
|
12156
|
+
return new Uint8Array(await crypto.subtle.digest(subtleDigest, data));
|
|
12157
|
+
};
|
|
12158
|
+
|
|
12159
|
+
// node_modules/jose/dist/webapi/lib/ecdhes.js
|
|
12160
|
+
function lengthAndInput(input) {
|
|
12161
|
+
return concat(uint32be(input.length), input);
|
|
12162
|
+
}
|
|
12163
|
+
async function concatKdf(secret, bits, value) {
|
|
12164
|
+
const iterations = Math.ceil((bits >> 3) / 32);
|
|
12165
|
+
const res = new Uint8Array(iterations * 32);
|
|
12166
|
+
for (let iter = 0; iter < iterations; iter++) {
|
|
12167
|
+
const buf = new Uint8Array(4 + secret.length + value.length);
|
|
12168
|
+
buf.set(uint32be(iter + 1));
|
|
12169
|
+
buf.set(secret, 4);
|
|
12170
|
+
buf.set(value, 4 + secret.length);
|
|
12171
|
+
res.set(await digest_default("sha256", buf), iter * 32);
|
|
12172
|
+
}
|
|
12173
|
+
return res.slice(0, bits >> 3);
|
|
12174
|
+
}
|
|
12175
|
+
async function deriveKey(publicKey, privateKey, algorithm, keyLength, apu = new Uint8Array(0), apv = new Uint8Array(0)) {
|
|
12176
|
+
checkEncCryptoKey(publicKey, "ECDH");
|
|
12177
|
+
checkEncCryptoKey(privateKey, "ECDH", "deriveBits");
|
|
12178
|
+
const value = concat(lengthAndInput(encoder.encode(algorithm)), lengthAndInput(apu), lengthAndInput(apv), uint32be(keyLength));
|
|
12179
|
+
let length;
|
|
12180
|
+
if (publicKey.algorithm.name === "X25519") {
|
|
12181
|
+
length = 256;
|
|
12182
|
+
} else {
|
|
12183
|
+
length = Math.ceil(parseInt(publicKey.algorithm.namedCurve.slice(-3), 10) / 8) << 3;
|
|
12184
|
+
}
|
|
12185
|
+
const sharedSecret = new Uint8Array(await crypto.subtle.deriveBits({
|
|
12186
|
+
name: publicKey.algorithm.name,
|
|
12187
|
+
public: publicKey
|
|
12188
|
+
}, privateKey, length));
|
|
12189
|
+
return concatKdf(sharedSecret, keyLength, value);
|
|
12190
|
+
}
|
|
12191
|
+
function allowed(key) {
|
|
12192
|
+
switch (key.algorithm.namedCurve) {
|
|
12193
|
+
case "P-256":
|
|
12194
|
+
case "P-384":
|
|
12195
|
+
case "P-521":
|
|
12196
|
+
return true;
|
|
12197
|
+
default:
|
|
12198
|
+
return key.algorithm.name === "X25519";
|
|
12199
|
+
}
|
|
12200
|
+
}
|
|
12201
|
+
|
|
12202
|
+
// node_modules/jose/dist/webapi/lib/pbes2kw.js
|
|
12203
|
+
function getCryptoKey2(key, alg) {
|
|
12204
|
+
if (key instanceof Uint8Array) {
|
|
12205
|
+
return crypto.subtle.importKey("raw", key, "PBKDF2", false, ["deriveBits"]);
|
|
12206
|
+
}
|
|
12207
|
+
checkEncCryptoKey(key, alg, "deriveBits");
|
|
12208
|
+
return key;
|
|
12209
|
+
}
|
|
12210
|
+
var concatSalt = (alg, p2sInput) => concat(encoder.encode(alg), new Uint8Array([0]), p2sInput);
|
|
12211
|
+
async function deriveKey2(p2s, alg, p2c, key) {
|
|
12212
|
+
if (!(p2s instanceof Uint8Array) || p2s.length < 8) {
|
|
12213
|
+
throw new JWEInvalid("PBES2 Salt Input must be 8 or more octets");
|
|
12214
|
+
}
|
|
12215
|
+
const salt = concatSalt(alg, p2s);
|
|
12216
|
+
const keylen = parseInt(alg.slice(13, 16), 10);
|
|
12217
|
+
const subtleAlg = {
|
|
12218
|
+
hash: `SHA-${alg.slice(8, 11)}`,
|
|
12219
|
+
iterations: p2c,
|
|
12220
|
+
name: "PBKDF2",
|
|
12221
|
+
salt
|
|
12222
|
+
};
|
|
12223
|
+
const cryptoKey = await getCryptoKey2(key, alg);
|
|
12224
|
+
return new Uint8Array(await crypto.subtle.deriveBits(subtleAlg, cryptoKey, keylen));
|
|
12225
|
+
}
|
|
12226
|
+
async function wrap2(alg, key, cek, p2c = 2048, p2s = crypto.getRandomValues(new Uint8Array(16))) {
|
|
12227
|
+
const derived = await deriveKey2(p2s, alg, p2c, key);
|
|
12228
|
+
const encryptedKey = await wrap(alg.slice(-6), derived, cek);
|
|
12229
|
+
return { encryptedKey, p2c, p2s: encode(p2s) };
|
|
12230
|
+
}
|
|
12231
|
+
async function unwrap2(alg, key, encryptedKey, p2c, p2s) {
|
|
12232
|
+
const derived = await deriveKey2(p2s, alg, p2c, key);
|
|
12233
|
+
return unwrap(alg.slice(-6), derived, encryptedKey);
|
|
12234
|
+
}
|
|
12235
|
+
|
|
12236
|
+
// node_modules/jose/dist/webapi/lib/check_key_length.js
|
|
12237
|
+
var check_key_length_default = (alg, key) => {
|
|
12238
|
+
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
12239
|
+
const { modulusLength } = key.algorithm;
|
|
12240
|
+
if (typeof modulusLength !== "number" || modulusLength < 2048) {
|
|
12241
|
+
throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
12242
|
+
}
|
|
12243
|
+
}
|
|
12244
|
+
};
|
|
12245
|
+
|
|
12246
|
+
// node_modules/jose/dist/webapi/lib/rsaes.js
|
|
12247
|
+
var subtleAlgorithm = (alg) => {
|
|
12248
|
+
switch (alg) {
|
|
12249
|
+
case "RSA-OAEP":
|
|
12250
|
+
case "RSA-OAEP-256":
|
|
12251
|
+
case "RSA-OAEP-384":
|
|
12252
|
+
case "RSA-OAEP-512":
|
|
12253
|
+
return "RSA-OAEP";
|
|
12254
|
+
default:
|
|
12255
|
+
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
12256
|
+
}
|
|
12257
|
+
};
|
|
12258
|
+
async function encrypt(alg, key, cek) {
|
|
12259
|
+
checkEncCryptoKey(key, alg, "encrypt");
|
|
12260
|
+
check_key_length_default(alg, key);
|
|
12261
|
+
return new Uint8Array(await crypto.subtle.encrypt(subtleAlgorithm(alg), key, cek));
|
|
12262
|
+
}
|
|
12263
|
+
async function decrypt(alg, key, encryptedKey) {
|
|
12264
|
+
checkEncCryptoKey(key, alg, "decrypt");
|
|
12265
|
+
check_key_length_default(alg, key);
|
|
12266
|
+
return new Uint8Array(await crypto.subtle.decrypt(subtleAlgorithm(alg), key, encryptedKey));
|
|
12267
|
+
}
|
|
12268
|
+
|
|
12269
|
+
// node_modules/jose/dist/webapi/lib/cek.js
|
|
12270
|
+
function bitLength2(alg) {
|
|
12271
|
+
switch (alg) {
|
|
12272
|
+
case "A128GCM":
|
|
12273
|
+
return 128;
|
|
12274
|
+
case "A192GCM":
|
|
12275
|
+
return 192;
|
|
12276
|
+
case "A256GCM":
|
|
12277
|
+
case "A128CBC-HS256":
|
|
12278
|
+
return 256;
|
|
12279
|
+
case "A192CBC-HS384":
|
|
12280
|
+
return 384;
|
|
12281
|
+
case "A256CBC-HS512":
|
|
12282
|
+
return 512;
|
|
12283
|
+
default:
|
|
12284
|
+
throw new JOSENotSupported(`Unsupported JWE Algorithm: ${alg}`);
|
|
12285
|
+
}
|
|
12286
|
+
}
|
|
12287
|
+
var cek_default = (alg) => crypto.getRandomValues(new Uint8Array(bitLength2(alg) >> 3));
|
|
12288
|
+
|
|
12289
|
+
// node_modules/jose/dist/webapi/lib/jwk_to_key.js
|
|
12290
|
+
function subtleMapping(jwk) {
|
|
12291
|
+
let algorithm;
|
|
12292
|
+
let keyUsages;
|
|
12293
|
+
switch (jwk.kty) {
|
|
12294
|
+
case "RSA": {
|
|
12295
|
+
switch (jwk.alg) {
|
|
12296
|
+
case "PS256":
|
|
12297
|
+
case "PS384":
|
|
12298
|
+
case "PS512":
|
|
12299
|
+
algorithm = { name: "RSA-PSS", hash: `SHA-${jwk.alg.slice(-3)}` };
|
|
12300
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
12301
|
+
break;
|
|
12302
|
+
case "RS256":
|
|
12303
|
+
case "RS384":
|
|
12304
|
+
case "RS512":
|
|
12305
|
+
algorithm = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${jwk.alg.slice(-3)}` };
|
|
12306
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
12307
|
+
break;
|
|
12308
|
+
case "RSA-OAEP":
|
|
12309
|
+
case "RSA-OAEP-256":
|
|
12310
|
+
case "RSA-OAEP-384":
|
|
12311
|
+
case "RSA-OAEP-512":
|
|
12312
|
+
algorithm = {
|
|
12313
|
+
name: "RSA-OAEP",
|
|
12314
|
+
hash: `SHA-${parseInt(jwk.alg.slice(-3), 10) || 1}`
|
|
12315
|
+
};
|
|
12316
|
+
keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
12317
|
+
break;
|
|
12318
|
+
default:
|
|
12319
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
12320
|
+
}
|
|
12321
|
+
break;
|
|
12322
|
+
}
|
|
12323
|
+
case "EC": {
|
|
12324
|
+
switch (jwk.alg) {
|
|
12325
|
+
case "ES256":
|
|
12326
|
+
algorithm = { name: "ECDSA", namedCurve: "P-256" };
|
|
12327
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
12328
|
+
break;
|
|
12329
|
+
case "ES384":
|
|
12330
|
+
algorithm = { name: "ECDSA", namedCurve: "P-384" };
|
|
12331
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
12332
|
+
break;
|
|
12333
|
+
case "ES512":
|
|
12334
|
+
algorithm = { name: "ECDSA", namedCurve: "P-521" };
|
|
12335
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
12336
|
+
break;
|
|
12337
|
+
case "ECDH-ES":
|
|
12338
|
+
case "ECDH-ES+A128KW":
|
|
12339
|
+
case "ECDH-ES+A192KW":
|
|
12340
|
+
case "ECDH-ES+A256KW":
|
|
12341
|
+
algorithm = { name: "ECDH", namedCurve: jwk.crv };
|
|
12342
|
+
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
12343
|
+
break;
|
|
12344
|
+
default:
|
|
12345
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
12346
|
+
}
|
|
12347
|
+
break;
|
|
12348
|
+
}
|
|
12349
|
+
case "OKP": {
|
|
12350
|
+
switch (jwk.alg) {
|
|
12351
|
+
case "Ed25519":
|
|
12352
|
+
case "EdDSA":
|
|
12353
|
+
algorithm = { name: "Ed25519" };
|
|
12354
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
12355
|
+
break;
|
|
12356
|
+
case "ECDH-ES":
|
|
12357
|
+
case "ECDH-ES+A128KW":
|
|
12358
|
+
case "ECDH-ES+A192KW":
|
|
12359
|
+
case "ECDH-ES+A256KW":
|
|
12360
|
+
algorithm = { name: jwk.crv };
|
|
12361
|
+
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
12362
|
+
break;
|
|
12363
|
+
default:
|
|
12364
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
12365
|
+
}
|
|
12366
|
+
break;
|
|
12367
|
+
}
|
|
12368
|
+
default:
|
|
12369
|
+
throw new JOSENotSupported('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
|
|
12370
|
+
}
|
|
12371
|
+
return { algorithm, keyUsages };
|
|
12372
|
+
}
|
|
12373
|
+
var jwk_to_key_default = async (jwk) => {
|
|
12374
|
+
if (!jwk.alg) {
|
|
12375
|
+
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
12376
|
+
}
|
|
12377
|
+
const { algorithm, keyUsages } = subtleMapping(jwk);
|
|
12378
|
+
const keyData = { ...jwk };
|
|
12379
|
+
delete keyData.alg;
|
|
12380
|
+
delete keyData.use;
|
|
12381
|
+
return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d ? false : true), jwk.key_ops ?? keyUsages);
|
|
12382
|
+
};
|
|
12383
|
+
|
|
12384
|
+
// node_modules/jose/dist/webapi/key/import.js
|
|
12385
|
+
async function importJWK(jwk, alg, options) {
|
|
12386
|
+
if (!is_object_default(jwk)) {
|
|
12387
|
+
throw new TypeError("JWK must be an object");
|
|
12388
|
+
}
|
|
12389
|
+
let ext;
|
|
12390
|
+
alg ??= jwk.alg;
|
|
12391
|
+
ext ??= options?.extractable ?? jwk.ext;
|
|
12392
|
+
switch (jwk.kty) {
|
|
12393
|
+
case "oct":
|
|
12394
|
+
if (typeof jwk.k !== "string" || !jwk.k) {
|
|
12395
|
+
throw new TypeError('missing "k" (Key Value) Parameter value');
|
|
12396
|
+
}
|
|
12397
|
+
return decode(jwk.k);
|
|
12398
|
+
case "RSA":
|
|
12399
|
+
if ("oth" in jwk && jwk.oth !== void 0) {
|
|
12400
|
+
throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
|
|
12401
|
+
}
|
|
12402
|
+
case "EC":
|
|
12403
|
+
case "OKP":
|
|
12404
|
+
return jwk_to_key_default({ ...jwk, alg, ext });
|
|
12405
|
+
default:
|
|
12406
|
+
throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
|
|
12407
|
+
}
|
|
12408
|
+
}
|
|
12409
|
+
|
|
12410
|
+
// node_modules/jose/dist/webapi/lib/encrypt.js
|
|
12411
|
+
async function cbcEncrypt(enc, plaintext, cek, iv, aad) {
|
|
12412
|
+
if (!(cek instanceof Uint8Array)) {
|
|
12413
|
+
throw new TypeError(invalid_key_input_default(cek, "Uint8Array"));
|
|
12414
|
+
}
|
|
12415
|
+
const keySize = parseInt(enc.slice(1, 4), 10);
|
|
12416
|
+
const encKey = await crypto.subtle.importKey("raw", cek.subarray(keySize >> 3), "AES-CBC", false, ["encrypt"]);
|
|
12417
|
+
const macKey = await crypto.subtle.importKey("raw", cek.subarray(0, keySize >> 3), {
|
|
12418
|
+
hash: `SHA-${keySize << 1}`,
|
|
12419
|
+
name: "HMAC"
|
|
12420
|
+
}, false, ["sign"]);
|
|
12421
|
+
const ciphertext = new Uint8Array(await crypto.subtle.encrypt({
|
|
12422
|
+
iv,
|
|
12423
|
+
name: "AES-CBC"
|
|
12424
|
+
}, encKey, plaintext));
|
|
12425
|
+
const macData = concat(aad, iv, ciphertext, uint64be(aad.length << 3));
|
|
12426
|
+
const tag2 = new Uint8Array((await crypto.subtle.sign("HMAC", macKey, macData)).slice(0, keySize >> 3));
|
|
12427
|
+
return { ciphertext, tag: tag2, iv };
|
|
12428
|
+
}
|
|
12429
|
+
async function gcmEncrypt(enc, plaintext, cek, iv, aad) {
|
|
12430
|
+
let encKey;
|
|
12431
|
+
if (cek instanceof Uint8Array) {
|
|
12432
|
+
encKey = await crypto.subtle.importKey("raw", cek, "AES-GCM", false, ["encrypt"]);
|
|
12433
|
+
} else {
|
|
12434
|
+
checkEncCryptoKey(cek, enc, "encrypt");
|
|
12435
|
+
encKey = cek;
|
|
12436
|
+
}
|
|
12437
|
+
const encrypted = new Uint8Array(await crypto.subtle.encrypt({
|
|
12438
|
+
additionalData: aad,
|
|
12439
|
+
iv,
|
|
12440
|
+
name: "AES-GCM",
|
|
12441
|
+
tagLength: 128
|
|
12442
|
+
}, encKey, plaintext));
|
|
12443
|
+
const tag2 = encrypted.slice(-16);
|
|
12444
|
+
const ciphertext = encrypted.slice(0, -16);
|
|
12445
|
+
return { ciphertext, tag: tag2, iv };
|
|
12446
|
+
}
|
|
12447
|
+
var encrypt_default = async (enc, plaintext, cek, iv, aad) => {
|
|
12448
|
+
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
|
12449
|
+
throw new TypeError(invalid_key_input_default(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
|
|
12450
|
+
}
|
|
12451
|
+
if (iv) {
|
|
12452
|
+
check_iv_length_default(enc, iv);
|
|
12453
|
+
} else {
|
|
12454
|
+
iv = iv_default(enc);
|
|
12455
|
+
}
|
|
12456
|
+
switch (enc) {
|
|
12457
|
+
case "A128CBC-HS256":
|
|
12458
|
+
case "A192CBC-HS384":
|
|
12459
|
+
case "A256CBC-HS512":
|
|
12460
|
+
if (cek instanceof Uint8Array) {
|
|
12461
|
+
check_cek_length_default(cek, parseInt(enc.slice(-3), 10));
|
|
12462
|
+
}
|
|
12463
|
+
return cbcEncrypt(enc, plaintext, cek, iv, aad);
|
|
12464
|
+
case "A128GCM":
|
|
12465
|
+
case "A192GCM":
|
|
12466
|
+
case "A256GCM":
|
|
12467
|
+
if (cek instanceof Uint8Array) {
|
|
12468
|
+
check_cek_length_default(cek, parseInt(enc.slice(1, 4), 10));
|
|
12469
|
+
}
|
|
12470
|
+
return gcmEncrypt(enc, plaintext, cek, iv, aad);
|
|
12471
|
+
default:
|
|
12472
|
+
throw new JOSENotSupported("Unsupported JWE Content Encryption Algorithm");
|
|
12473
|
+
}
|
|
12474
|
+
};
|
|
12475
|
+
|
|
12476
|
+
// node_modules/jose/dist/webapi/lib/aesgcmkw.js
|
|
12477
|
+
async function wrap3(alg, key, cek, iv) {
|
|
12478
|
+
const jweAlgorithm = alg.slice(0, 7);
|
|
12479
|
+
const wrapped = await encrypt_default(jweAlgorithm, cek, key, iv, new Uint8Array(0));
|
|
12480
|
+
return {
|
|
12481
|
+
encryptedKey: wrapped.ciphertext,
|
|
12482
|
+
iv: encode(wrapped.iv),
|
|
12483
|
+
tag: encode(wrapped.tag)
|
|
12484
|
+
};
|
|
12485
|
+
}
|
|
12486
|
+
async function unwrap3(alg, key, encryptedKey, iv, tag2) {
|
|
12487
|
+
const jweAlgorithm = alg.slice(0, 7);
|
|
12488
|
+
return decrypt_default(jweAlgorithm, key, encryptedKey, iv, tag2, new Uint8Array(0));
|
|
12489
|
+
}
|
|
12490
|
+
|
|
12491
|
+
// node_modules/jose/dist/webapi/lib/decrypt_key_management.js
|
|
12492
|
+
var decrypt_key_management_default = async (alg, key, encryptedKey, joseHeader, options) => {
|
|
12493
|
+
switch (alg) {
|
|
12494
|
+
case "dir": {
|
|
12495
|
+
if (encryptedKey !== void 0)
|
|
12496
|
+
throw new JWEInvalid("Encountered unexpected JWE Encrypted Key");
|
|
12497
|
+
return key;
|
|
12498
|
+
}
|
|
12499
|
+
case "ECDH-ES":
|
|
12500
|
+
if (encryptedKey !== void 0)
|
|
12501
|
+
throw new JWEInvalid("Encountered unexpected JWE Encrypted Key");
|
|
12502
|
+
case "ECDH-ES+A128KW":
|
|
12503
|
+
case "ECDH-ES+A192KW":
|
|
12504
|
+
case "ECDH-ES+A256KW": {
|
|
12505
|
+
if (!is_object_default(joseHeader.epk))
|
|
12506
|
+
throw new JWEInvalid(`JOSE Header "epk" (Ephemeral Public Key) missing or invalid`);
|
|
12507
|
+
assertCryptoKey(key);
|
|
12508
|
+
if (!allowed(key))
|
|
12509
|
+
throw new JOSENotSupported("ECDH with the provided key is not allowed or not supported by your javascript runtime");
|
|
12510
|
+
const epk = await importJWK(joseHeader.epk, alg);
|
|
12511
|
+
assertCryptoKey(epk);
|
|
12512
|
+
let partyUInfo;
|
|
12513
|
+
let partyVInfo;
|
|
12514
|
+
if (joseHeader.apu !== void 0) {
|
|
12515
|
+
if (typeof joseHeader.apu !== "string")
|
|
12516
|
+
throw new JWEInvalid(`JOSE Header "apu" (Agreement PartyUInfo) invalid`);
|
|
12517
|
+
try {
|
|
12518
|
+
partyUInfo = decode(joseHeader.apu);
|
|
12519
|
+
} catch {
|
|
12520
|
+
throw new JWEInvalid("Failed to base64url decode the apu");
|
|
12521
|
+
}
|
|
12522
|
+
}
|
|
12523
|
+
if (joseHeader.apv !== void 0) {
|
|
12524
|
+
if (typeof joseHeader.apv !== "string")
|
|
12525
|
+
throw new JWEInvalid(`JOSE Header "apv" (Agreement PartyVInfo) invalid`);
|
|
12526
|
+
try {
|
|
12527
|
+
partyVInfo = decode(joseHeader.apv);
|
|
12528
|
+
} catch {
|
|
12529
|
+
throw new JWEInvalid("Failed to base64url decode the apv");
|
|
12530
|
+
}
|
|
12531
|
+
}
|
|
12532
|
+
const sharedSecret = await deriveKey(epk, key, alg === "ECDH-ES" ? joseHeader.enc : alg, alg === "ECDH-ES" ? bitLength2(joseHeader.enc) : parseInt(alg.slice(-5, -2), 10), partyUInfo, partyVInfo);
|
|
12533
|
+
if (alg === "ECDH-ES")
|
|
12534
|
+
return sharedSecret;
|
|
12535
|
+
if (encryptedKey === void 0)
|
|
12536
|
+
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
12537
|
+
return unwrap(alg.slice(-6), sharedSecret, encryptedKey);
|
|
12538
|
+
}
|
|
12539
|
+
case "RSA-OAEP":
|
|
12540
|
+
case "RSA-OAEP-256":
|
|
12541
|
+
case "RSA-OAEP-384":
|
|
12542
|
+
case "RSA-OAEP-512": {
|
|
12543
|
+
if (encryptedKey === void 0)
|
|
12544
|
+
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
12545
|
+
assertCryptoKey(key);
|
|
12546
|
+
return decrypt(alg, key, encryptedKey);
|
|
12547
|
+
}
|
|
12548
|
+
case "PBES2-HS256+A128KW":
|
|
12549
|
+
case "PBES2-HS384+A192KW":
|
|
12550
|
+
case "PBES2-HS512+A256KW": {
|
|
12551
|
+
if (encryptedKey === void 0)
|
|
12552
|
+
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
12553
|
+
if (typeof joseHeader.p2c !== "number")
|
|
12554
|
+
throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) missing or invalid`);
|
|
12555
|
+
const p2cLimit = options?.maxPBES2Count || 1e4;
|
|
12556
|
+
if (joseHeader.p2c > p2cLimit)
|
|
12557
|
+
throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds`);
|
|
12558
|
+
if (typeof joseHeader.p2s !== "string")
|
|
12559
|
+
throw new JWEInvalid(`JOSE Header "p2s" (PBES2 Salt) missing or invalid`);
|
|
12560
|
+
let p2s;
|
|
12561
|
+
try {
|
|
12562
|
+
p2s = decode(joseHeader.p2s);
|
|
12563
|
+
} catch {
|
|
12564
|
+
throw new JWEInvalid("Failed to base64url decode the p2s");
|
|
12565
|
+
}
|
|
12566
|
+
return unwrap2(alg, key, encryptedKey, joseHeader.p2c, p2s);
|
|
12567
|
+
}
|
|
12568
|
+
case "A128KW":
|
|
12569
|
+
case "A192KW":
|
|
12570
|
+
case "A256KW": {
|
|
12571
|
+
if (encryptedKey === void 0)
|
|
12572
|
+
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
12573
|
+
return unwrap(alg, key, encryptedKey);
|
|
12574
|
+
}
|
|
12575
|
+
case "A128GCMKW":
|
|
12576
|
+
case "A192GCMKW":
|
|
12577
|
+
case "A256GCMKW": {
|
|
12578
|
+
if (encryptedKey === void 0)
|
|
12579
|
+
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
12580
|
+
if (typeof joseHeader.iv !== "string")
|
|
12581
|
+
throw new JWEInvalid(`JOSE Header "iv" (Initialization Vector) missing or invalid`);
|
|
12582
|
+
if (typeof joseHeader.tag !== "string")
|
|
12583
|
+
throw new JWEInvalid(`JOSE Header "tag" (Authentication Tag) missing or invalid`);
|
|
12584
|
+
let iv;
|
|
12585
|
+
try {
|
|
12586
|
+
iv = decode(joseHeader.iv);
|
|
12587
|
+
} catch {
|
|
12588
|
+
throw new JWEInvalid("Failed to base64url decode the iv");
|
|
12589
|
+
}
|
|
12590
|
+
let tag2;
|
|
12591
|
+
try {
|
|
12592
|
+
tag2 = decode(joseHeader.tag);
|
|
12593
|
+
} catch {
|
|
12594
|
+
throw new JWEInvalid("Failed to base64url decode the tag");
|
|
12595
|
+
}
|
|
12596
|
+
return unwrap3(alg, key, encryptedKey, iv, tag2);
|
|
12597
|
+
}
|
|
12598
|
+
default: {
|
|
12599
|
+
throw new JOSENotSupported('Invalid or unsupported "alg" (JWE Algorithm) header value');
|
|
12600
|
+
}
|
|
12601
|
+
}
|
|
12602
|
+
};
|
|
12603
|
+
|
|
12604
|
+
// node_modules/jose/dist/webapi/lib/validate_crit.js
|
|
12605
|
+
var validate_crit_default = (Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) => {
|
|
12606
|
+
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) {
|
|
12607
|
+
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
12608
|
+
}
|
|
12609
|
+
if (!protectedHeader || protectedHeader.crit === void 0) {
|
|
12610
|
+
return /* @__PURE__ */ new Set();
|
|
12611
|
+
}
|
|
12612
|
+
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
|
|
12613
|
+
throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
12614
|
+
}
|
|
12615
|
+
let recognized;
|
|
12616
|
+
if (recognizedOption !== void 0) {
|
|
12617
|
+
recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
|
|
12618
|
+
} else {
|
|
12619
|
+
recognized = recognizedDefault;
|
|
12620
|
+
}
|
|
12621
|
+
for (const parameter of protectedHeader.crit) {
|
|
12622
|
+
if (!recognized.has(parameter)) {
|
|
12623
|
+
throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
|
|
12624
|
+
}
|
|
12625
|
+
if (joseHeader[parameter] === void 0) {
|
|
12626
|
+
throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
12627
|
+
}
|
|
12628
|
+
if (recognized.get(parameter) && protectedHeader[parameter] === void 0) {
|
|
12629
|
+
throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
12630
|
+
}
|
|
12631
|
+
}
|
|
12632
|
+
return new Set(protectedHeader.crit);
|
|
12633
|
+
};
|
|
12634
|
+
|
|
12635
|
+
// node_modules/jose/dist/webapi/lib/validate_algorithms.js
|
|
12636
|
+
var validate_algorithms_default = (option, algorithms) => {
|
|
12637
|
+
if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
|
|
12638
|
+
throw new TypeError(`"${option}" option must be an array of strings`);
|
|
12639
|
+
}
|
|
12640
|
+
if (!algorithms) {
|
|
12641
|
+
return void 0;
|
|
12642
|
+
}
|
|
12643
|
+
return new Set(algorithms);
|
|
12644
|
+
};
|
|
12645
|
+
|
|
12646
|
+
// node_modules/jose/dist/webapi/lib/is_jwk.js
|
|
12647
|
+
function isJWK(key) {
|
|
12648
|
+
return is_object_default(key) && typeof key.kty === "string";
|
|
12649
|
+
}
|
|
12650
|
+
function isPrivateJWK(key) {
|
|
12651
|
+
return key.kty !== "oct" && typeof key.d === "string";
|
|
12652
|
+
}
|
|
12653
|
+
function isPublicJWK(key) {
|
|
12654
|
+
return key.kty !== "oct" && typeof key.d === "undefined";
|
|
12655
|
+
}
|
|
12656
|
+
function isSecretJWK(key) {
|
|
12657
|
+
return key.kty === "oct" && typeof key.k === "string";
|
|
12658
|
+
}
|
|
12659
|
+
|
|
12660
|
+
// node_modules/jose/dist/webapi/lib/normalize_key.js
|
|
12661
|
+
var cache;
|
|
12662
|
+
var handleJWK = async (key, jwk, alg, freeze = false) => {
|
|
12663
|
+
cache ||= /* @__PURE__ */ new WeakMap();
|
|
12664
|
+
let cached = cache.get(key);
|
|
12665
|
+
if (cached?.[alg]) {
|
|
12666
|
+
return cached[alg];
|
|
12667
|
+
}
|
|
12668
|
+
const cryptoKey = await jwk_to_key_default({ ...jwk, alg });
|
|
12669
|
+
if (freeze)
|
|
12670
|
+
Object.freeze(key);
|
|
12671
|
+
if (!cached) {
|
|
12672
|
+
cache.set(key, { [alg]: cryptoKey });
|
|
12673
|
+
} else {
|
|
12674
|
+
cached[alg] = cryptoKey;
|
|
12675
|
+
}
|
|
12676
|
+
return cryptoKey;
|
|
12677
|
+
};
|
|
12678
|
+
var handleKeyObject = (keyObject, alg) => {
|
|
12679
|
+
cache ||= /* @__PURE__ */ new WeakMap();
|
|
12680
|
+
let cached = cache.get(keyObject);
|
|
12681
|
+
if (cached?.[alg]) {
|
|
12682
|
+
return cached[alg];
|
|
12683
|
+
}
|
|
12684
|
+
const isPublic = keyObject.type === "public";
|
|
12685
|
+
const extractable = isPublic ? true : false;
|
|
12686
|
+
let cryptoKey;
|
|
12687
|
+
if (keyObject.asymmetricKeyType === "x25519") {
|
|
12688
|
+
switch (alg) {
|
|
12689
|
+
case "ECDH-ES":
|
|
12690
|
+
case "ECDH-ES+A128KW":
|
|
12691
|
+
case "ECDH-ES+A192KW":
|
|
12692
|
+
case "ECDH-ES+A256KW":
|
|
12693
|
+
break;
|
|
12694
|
+
default:
|
|
12695
|
+
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
12696
|
+
}
|
|
12697
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
|
|
12698
|
+
}
|
|
12699
|
+
if (keyObject.asymmetricKeyType === "ed25519") {
|
|
12700
|
+
if (alg !== "EdDSA" && alg !== "Ed25519") {
|
|
12701
|
+
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
12702
|
+
}
|
|
12703
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [
|
|
12704
|
+
isPublic ? "verify" : "sign"
|
|
12705
|
+
]);
|
|
12706
|
+
}
|
|
12707
|
+
if (keyObject.asymmetricKeyType === "rsa") {
|
|
12708
|
+
let hash;
|
|
12709
|
+
switch (alg) {
|
|
12710
|
+
case "RSA-OAEP":
|
|
12711
|
+
hash = "SHA-1";
|
|
12712
|
+
break;
|
|
12713
|
+
case "RS256":
|
|
12714
|
+
case "PS256":
|
|
12715
|
+
case "RSA-OAEP-256":
|
|
12716
|
+
hash = "SHA-256";
|
|
12717
|
+
break;
|
|
12718
|
+
case "RS384":
|
|
12719
|
+
case "PS384":
|
|
12720
|
+
case "RSA-OAEP-384":
|
|
12721
|
+
hash = "SHA-384";
|
|
12722
|
+
break;
|
|
12723
|
+
case "RS512":
|
|
12724
|
+
case "PS512":
|
|
12725
|
+
case "RSA-OAEP-512":
|
|
12726
|
+
hash = "SHA-512";
|
|
12727
|
+
break;
|
|
12728
|
+
default:
|
|
12729
|
+
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
12730
|
+
}
|
|
12731
|
+
if (alg.startsWith("RSA-OAEP")) {
|
|
12732
|
+
return keyObject.toCryptoKey({
|
|
12733
|
+
name: "RSA-OAEP",
|
|
12734
|
+
hash
|
|
12735
|
+
}, extractable, isPublic ? ["encrypt"] : ["decrypt"]);
|
|
12736
|
+
}
|
|
12737
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
12738
|
+
name: alg.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
|
|
12739
|
+
hash
|
|
12740
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
12741
|
+
}
|
|
12742
|
+
if (keyObject.asymmetricKeyType === "ec") {
|
|
12743
|
+
const nist = /* @__PURE__ */ new Map([
|
|
12744
|
+
["prime256v1", "P-256"],
|
|
12745
|
+
["secp384r1", "P-384"],
|
|
12746
|
+
["secp521r1", "P-521"]
|
|
12747
|
+
]);
|
|
12748
|
+
const namedCurve = nist.get(keyObject.asymmetricKeyDetails?.namedCurve);
|
|
12749
|
+
if (!namedCurve) {
|
|
12750
|
+
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
12751
|
+
}
|
|
12752
|
+
if (alg === "ES256" && namedCurve === "P-256") {
|
|
12753
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
12754
|
+
name: "ECDSA",
|
|
12755
|
+
namedCurve
|
|
12756
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
12757
|
+
}
|
|
12758
|
+
if (alg === "ES384" && namedCurve === "P-384") {
|
|
12759
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
12760
|
+
name: "ECDSA",
|
|
12761
|
+
namedCurve
|
|
12762
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
12763
|
+
}
|
|
12764
|
+
if (alg === "ES512" && namedCurve === "P-521") {
|
|
12765
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
12766
|
+
name: "ECDSA",
|
|
12767
|
+
namedCurve
|
|
12768
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
12769
|
+
}
|
|
12770
|
+
if (alg.startsWith("ECDH-ES")) {
|
|
12771
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
12772
|
+
name: "ECDH",
|
|
12773
|
+
namedCurve
|
|
12774
|
+
}, extractable, isPublic ? [] : ["deriveBits"]);
|
|
12775
|
+
}
|
|
12776
|
+
}
|
|
12777
|
+
if (!cryptoKey) {
|
|
12778
|
+
throw new TypeError("given KeyObject instance cannot be used for this algorithm");
|
|
12779
|
+
}
|
|
12780
|
+
if (!cached) {
|
|
12781
|
+
cache.set(keyObject, { [alg]: cryptoKey });
|
|
12782
|
+
} else {
|
|
12783
|
+
cached[alg] = cryptoKey;
|
|
12784
|
+
}
|
|
12785
|
+
return cryptoKey;
|
|
12786
|
+
};
|
|
12787
|
+
var normalize_key_default = async (key, alg) => {
|
|
12788
|
+
if (key instanceof Uint8Array) {
|
|
12789
|
+
return key;
|
|
12790
|
+
}
|
|
12791
|
+
if (isCryptoKey(key)) {
|
|
12792
|
+
return key;
|
|
12793
|
+
}
|
|
12794
|
+
if (isKeyObject(key)) {
|
|
12795
|
+
if (key.type === "secret") {
|
|
12796
|
+
return key.export();
|
|
12797
|
+
}
|
|
12798
|
+
if ("toCryptoKey" in key && typeof key.toCryptoKey === "function") {
|
|
12799
|
+
try {
|
|
12800
|
+
return handleKeyObject(key, alg);
|
|
12801
|
+
} catch (err) {
|
|
12802
|
+
if (err instanceof TypeError) {
|
|
12803
|
+
throw err;
|
|
12804
|
+
}
|
|
12805
|
+
}
|
|
12806
|
+
}
|
|
12807
|
+
let jwk = key.export({ format: "jwk" });
|
|
12808
|
+
return handleJWK(key, jwk, alg);
|
|
12809
|
+
}
|
|
12810
|
+
if (isJWK(key)) {
|
|
12811
|
+
if (key.k) {
|
|
12812
|
+
return decode(key.k);
|
|
12813
|
+
}
|
|
12814
|
+
return handleJWK(key, key, alg, true);
|
|
12815
|
+
}
|
|
12816
|
+
throw new Error("unreachable");
|
|
12817
|
+
};
|
|
12818
|
+
|
|
12819
|
+
// node_modules/jose/dist/webapi/lib/check_key_type.js
|
|
12820
|
+
var tag = (key) => key?.[Symbol.toStringTag];
|
|
12821
|
+
var jwkMatchesOp = (alg, key, usage2) => {
|
|
12822
|
+
if (key.use !== void 0) {
|
|
12823
|
+
let expected;
|
|
12824
|
+
switch (usage2) {
|
|
12825
|
+
case "sign":
|
|
12826
|
+
case "verify":
|
|
12827
|
+
expected = "sig";
|
|
12828
|
+
break;
|
|
12829
|
+
case "encrypt":
|
|
12830
|
+
case "decrypt":
|
|
12831
|
+
expected = "enc";
|
|
12832
|
+
break;
|
|
12833
|
+
}
|
|
12834
|
+
if (key.use !== expected) {
|
|
12835
|
+
throw new TypeError(`Invalid key for this operation, its "use" must be "${expected}" when present`);
|
|
12836
|
+
}
|
|
12837
|
+
}
|
|
12838
|
+
if (key.alg !== void 0 && key.alg !== alg) {
|
|
12839
|
+
throw new TypeError(`Invalid key for this operation, its "alg" must be "${alg}" when present`);
|
|
12840
|
+
}
|
|
12841
|
+
if (Array.isArray(key.key_ops)) {
|
|
12842
|
+
let expectedKeyOp;
|
|
12843
|
+
switch (true) {
|
|
12844
|
+
case (usage2 === "sign" || usage2 === "verify"):
|
|
12845
|
+
case alg === "dir":
|
|
12846
|
+
case alg.includes("CBC-HS"):
|
|
12847
|
+
expectedKeyOp = usage2;
|
|
12848
|
+
break;
|
|
12849
|
+
case alg.startsWith("PBES2"):
|
|
12850
|
+
expectedKeyOp = "deriveBits";
|
|
12851
|
+
break;
|
|
12852
|
+
case /^A\d{3}(?:GCM)?(?:KW)?$/.test(alg):
|
|
12853
|
+
if (!alg.includes("GCM") && alg.endsWith("KW")) {
|
|
12854
|
+
expectedKeyOp = usage2 === "encrypt" ? "wrapKey" : "unwrapKey";
|
|
12855
|
+
} else {
|
|
12856
|
+
expectedKeyOp = usage2;
|
|
12857
|
+
}
|
|
12858
|
+
break;
|
|
12859
|
+
case (usage2 === "encrypt" && alg.startsWith("RSA")):
|
|
12860
|
+
expectedKeyOp = "wrapKey";
|
|
12861
|
+
break;
|
|
12862
|
+
case usage2 === "decrypt":
|
|
12863
|
+
expectedKeyOp = alg.startsWith("RSA") ? "unwrapKey" : "deriveBits";
|
|
12864
|
+
break;
|
|
12865
|
+
}
|
|
12866
|
+
if (expectedKeyOp && key.key_ops?.includes?.(expectedKeyOp) === false) {
|
|
12867
|
+
throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${expectedKeyOp}" when present`);
|
|
12868
|
+
}
|
|
12869
|
+
}
|
|
12870
|
+
return true;
|
|
12871
|
+
};
|
|
12872
|
+
var symmetricTypeCheck = (alg, key, usage2) => {
|
|
12873
|
+
if (key instanceof Uint8Array)
|
|
12874
|
+
return;
|
|
12875
|
+
if (isJWK(key)) {
|
|
12876
|
+
if (isSecretJWK(key) && jwkMatchesOp(alg, key, usage2))
|
|
12877
|
+
return;
|
|
12878
|
+
throw new TypeError(`JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present`);
|
|
12879
|
+
}
|
|
12880
|
+
if (!is_key_like_default(key)) {
|
|
12881
|
+
throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
|
|
12882
|
+
}
|
|
12883
|
+
if (key.type !== "secret") {
|
|
12884
|
+
throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
|
|
12885
|
+
}
|
|
12886
|
+
};
|
|
12887
|
+
var asymmetricTypeCheck = (alg, key, usage2) => {
|
|
12888
|
+
if (isJWK(key)) {
|
|
12889
|
+
switch (usage2) {
|
|
12890
|
+
case "decrypt":
|
|
12891
|
+
case "sign":
|
|
12892
|
+
if (isPrivateJWK(key) && jwkMatchesOp(alg, key, usage2))
|
|
12893
|
+
return;
|
|
12894
|
+
throw new TypeError(`JSON Web Key for this operation be a private JWK`);
|
|
12895
|
+
case "encrypt":
|
|
12896
|
+
case "verify":
|
|
12897
|
+
if (isPublicJWK(key) && jwkMatchesOp(alg, key, usage2))
|
|
12898
|
+
return;
|
|
12899
|
+
throw new TypeError(`JSON Web Key for this operation be a public JWK`);
|
|
12900
|
+
}
|
|
12901
|
+
}
|
|
12902
|
+
if (!is_key_like_default(key)) {
|
|
12903
|
+
throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
12904
|
+
}
|
|
12905
|
+
if (key.type === "secret") {
|
|
12906
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
12907
|
+
}
|
|
12908
|
+
if (key.type === "public") {
|
|
12909
|
+
switch (usage2) {
|
|
12910
|
+
case "sign":
|
|
12911
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
|
|
12912
|
+
case "decrypt":
|
|
12913
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
12914
|
+
default:
|
|
12915
|
+
break;
|
|
12916
|
+
}
|
|
12917
|
+
}
|
|
12918
|
+
if (key.type === "private") {
|
|
12919
|
+
switch (usage2) {
|
|
12920
|
+
case "verify":
|
|
12921
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
12922
|
+
case "encrypt":
|
|
12923
|
+
throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
12924
|
+
default:
|
|
12925
|
+
break;
|
|
12926
|
+
}
|
|
12927
|
+
}
|
|
12928
|
+
};
|
|
12929
|
+
var check_key_type_default = (alg, key, usage2) => {
|
|
12930
|
+
const symmetric = alg.startsWith("HS") || alg === "dir" || alg.startsWith("PBES2") || /^A(?:128|192|256)(?:GCM)?(?:KW)?$/.test(alg) || /^A(?:128|192|256)CBC-HS(?:256|384|512)$/.test(alg);
|
|
12931
|
+
if (symmetric) {
|
|
12932
|
+
symmetricTypeCheck(alg, key, usage2);
|
|
12933
|
+
} else {
|
|
12934
|
+
asymmetricTypeCheck(alg, key, usage2);
|
|
12935
|
+
}
|
|
12936
|
+
};
|
|
12937
|
+
|
|
12938
|
+
// node_modules/jose/dist/webapi/jwe/flattened/decrypt.js
|
|
12939
|
+
async function flattenedDecrypt(jwe, key, options) {
|
|
12940
|
+
if (!is_object_default(jwe)) {
|
|
12941
|
+
throw new JWEInvalid("Flattened JWE must be an object");
|
|
12942
|
+
}
|
|
12943
|
+
if (jwe.protected === void 0 && jwe.header === void 0 && jwe.unprotected === void 0) {
|
|
12944
|
+
throw new JWEInvalid("JOSE Header missing");
|
|
12945
|
+
}
|
|
12946
|
+
if (jwe.iv !== void 0 && typeof jwe.iv !== "string") {
|
|
12947
|
+
throw new JWEInvalid("JWE Initialization Vector incorrect type");
|
|
12948
|
+
}
|
|
12949
|
+
if (typeof jwe.ciphertext !== "string") {
|
|
12950
|
+
throw new JWEInvalid("JWE Ciphertext missing or incorrect type");
|
|
12951
|
+
}
|
|
12952
|
+
if (jwe.tag !== void 0 && typeof jwe.tag !== "string") {
|
|
12953
|
+
throw new JWEInvalid("JWE Authentication Tag incorrect type");
|
|
12954
|
+
}
|
|
12955
|
+
if (jwe.protected !== void 0 && typeof jwe.protected !== "string") {
|
|
12956
|
+
throw new JWEInvalid("JWE Protected Header incorrect type");
|
|
12957
|
+
}
|
|
12958
|
+
if (jwe.encrypted_key !== void 0 && typeof jwe.encrypted_key !== "string") {
|
|
12959
|
+
throw new JWEInvalid("JWE Encrypted Key incorrect type");
|
|
12960
|
+
}
|
|
12961
|
+
if (jwe.aad !== void 0 && typeof jwe.aad !== "string") {
|
|
12962
|
+
throw new JWEInvalid("JWE AAD incorrect type");
|
|
12963
|
+
}
|
|
12964
|
+
if (jwe.header !== void 0 && !is_object_default(jwe.header)) {
|
|
12965
|
+
throw new JWEInvalid("JWE Shared Unprotected Header incorrect type");
|
|
12966
|
+
}
|
|
12967
|
+
if (jwe.unprotected !== void 0 && !is_object_default(jwe.unprotected)) {
|
|
12968
|
+
throw new JWEInvalid("JWE Per-Recipient Unprotected Header incorrect type");
|
|
12969
|
+
}
|
|
12970
|
+
let parsedProt;
|
|
12971
|
+
if (jwe.protected) {
|
|
12972
|
+
try {
|
|
12973
|
+
const protectedHeader2 = decode(jwe.protected);
|
|
12974
|
+
parsedProt = JSON.parse(decoder.decode(protectedHeader2));
|
|
12975
|
+
} catch {
|
|
12976
|
+
throw new JWEInvalid("JWE Protected Header is invalid");
|
|
12977
|
+
}
|
|
12978
|
+
}
|
|
12979
|
+
if (!is_disjoint_default(parsedProt, jwe.header, jwe.unprotected)) {
|
|
12980
|
+
throw new JWEInvalid("JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint");
|
|
12981
|
+
}
|
|
12982
|
+
const joseHeader = {
|
|
12983
|
+
...parsedProt,
|
|
12984
|
+
...jwe.header,
|
|
12985
|
+
...jwe.unprotected
|
|
12986
|
+
};
|
|
12987
|
+
validate_crit_default(JWEInvalid, /* @__PURE__ */ new Map(), options?.crit, parsedProt, joseHeader);
|
|
12988
|
+
if (joseHeader.zip !== void 0) {
|
|
12989
|
+
throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
|
|
12990
|
+
}
|
|
12991
|
+
const { alg, enc } = joseHeader;
|
|
12992
|
+
if (typeof alg !== "string" || !alg) {
|
|
12993
|
+
throw new JWEInvalid("missing JWE Algorithm (alg) in JWE Header");
|
|
12994
|
+
}
|
|
12995
|
+
if (typeof enc !== "string" || !enc) {
|
|
12996
|
+
throw new JWEInvalid("missing JWE Encryption Algorithm (enc) in JWE Header");
|
|
12997
|
+
}
|
|
12998
|
+
const keyManagementAlgorithms = options && validate_algorithms_default("keyManagementAlgorithms", options.keyManagementAlgorithms);
|
|
12999
|
+
const contentEncryptionAlgorithms = options && validate_algorithms_default("contentEncryptionAlgorithms", options.contentEncryptionAlgorithms);
|
|
13000
|
+
if (keyManagementAlgorithms && !keyManagementAlgorithms.has(alg) || !keyManagementAlgorithms && alg.startsWith("PBES2")) {
|
|
13001
|
+
throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
|
|
13002
|
+
}
|
|
13003
|
+
if (contentEncryptionAlgorithms && !contentEncryptionAlgorithms.has(enc)) {
|
|
13004
|
+
throw new JOSEAlgNotAllowed('"enc" (Encryption Algorithm) Header Parameter value not allowed');
|
|
13005
|
+
}
|
|
13006
|
+
let encryptedKey;
|
|
13007
|
+
if (jwe.encrypted_key !== void 0) {
|
|
13008
|
+
try {
|
|
13009
|
+
encryptedKey = decode(jwe.encrypted_key);
|
|
13010
|
+
} catch {
|
|
13011
|
+
throw new JWEInvalid("Failed to base64url decode the encrypted_key");
|
|
13012
|
+
}
|
|
13013
|
+
}
|
|
13014
|
+
let resolvedKey = false;
|
|
13015
|
+
if (typeof key === "function") {
|
|
13016
|
+
key = await key(parsedProt, jwe);
|
|
13017
|
+
resolvedKey = true;
|
|
13018
|
+
}
|
|
13019
|
+
check_key_type_default(alg === "dir" ? enc : alg, key, "decrypt");
|
|
13020
|
+
const k = await normalize_key_default(key, alg);
|
|
13021
|
+
let cek;
|
|
13022
|
+
try {
|
|
13023
|
+
cek = await decrypt_key_management_default(alg, k, encryptedKey, joseHeader, options);
|
|
13024
|
+
} catch (err) {
|
|
13025
|
+
if (err instanceof TypeError || err instanceof JWEInvalid || err instanceof JOSENotSupported) {
|
|
13026
|
+
throw err;
|
|
13027
|
+
}
|
|
13028
|
+
cek = cek_default(enc);
|
|
13029
|
+
}
|
|
13030
|
+
let iv;
|
|
13031
|
+
let tag2;
|
|
13032
|
+
if (jwe.iv !== void 0) {
|
|
13033
|
+
try {
|
|
13034
|
+
iv = decode(jwe.iv);
|
|
13035
|
+
} catch {
|
|
13036
|
+
throw new JWEInvalid("Failed to base64url decode the iv");
|
|
13037
|
+
}
|
|
13038
|
+
}
|
|
13039
|
+
if (jwe.tag !== void 0) {
|
|
13040
|
+
try {
|
|
13041
|
+
tag2 = decode(jwe.tag);
|
|
13042
|
+
} catch {
|
|
13043
|
+
throw new JWEInvalid("Failed to base64url decode the tag");
|
|
13044
|
+
}
|
|
13045
|
+
}
|
|
13046
|
+
const protectedHeader = encoder.encode(jwe.protected ?? "");
|
|
13047
|
+
let additionalData;
|
|
13048
|
+
if (jwe.aad !== void 0) {
|
|
13049
|
+
additionalData = concat(protectedHeader, encoder.encode("."), encoder.encode(jwe.aad));
|
|
13050
|
+
} else {
|
|
13051
|
+
additionalData = protectedHeader;
|
|
13052
|
+
}
|
|
13053
|
+
let ciphertext;
|
|
13054
|
+
try {
|
|
13055
|
+
ciphertext = decode(jwe.ciphertext);
|
|
13056
|
+
} catch {
|
|
13057
|
+
throw new JWEInvalid("Failed to base64url decode the ciphertext");
|
|
13058
|
+
}
|
|
13059
|
+
const plaintext = await decrypt_default(enc, cek, ciphertext, iv, tag2, additionalData);
|
|
13060
|
+
const result = { plaintext };
|
|
13061
|
+
if (jwe.protected !== void 0) {
|
|
13062
|
+
result.protectedHeader = parsedProt;
|
|
13063
|
+
}
|
|
13064
|
+
if (jwe.aad !== void 0) {
|
|
13065
|
+
try {
|
|
13066
|
+
result.additionalAuthenticatedData = decode(jwe.aad);
|
|
13067
|
+
} catch {
|
|
13068
|
+
throw new JWEInvalid("Failed to base64url decode the aad");
|
|
13069
|
+
}
|
|
13070
|
+
}
|
|
13071
|
+
if (jwe.unprotected !== void 0) {
|
|
13072
|
+
result.sharedUnprotectedHeader = jwe.unprotected;
|
|
13073
|
+
}
|
|
13074
|
+
if (jwe.header !== void 0) {
|
|
13075
|
+
result.unprotectedHeader = jwe.header;
|
|
13076
|
+
}
|
|
13077
|
+
if (resolvedKey) {
|
|
13078
|
+
return { ...result, key: k };
|
|
13079
|
+
}
|
|
13080
|
+
return result;
|
|
13081
|
+
}
|
|
13082
|
+
|
|
13083
|
+
// node_modules/jose/dist/webapi/jwe/compact/decrypt.js
|
|
13084
|
+
async function compactDecrypt(jwe, key, options) {
|
|
13085
|
+
if (jwe instanceof Uint8Array) {
|
|
13086
|
+
jwe = decoder.decode(jwe);
|
|
13087
|
+
}
|
|
13088
|
+
if (typeof jwe !== "string") {
|
|
13089
|
+
throw new JWEInvalid("Compact JWE must be a string or Uint8Array");
|
|
13090
|
+
}
|
|
13091
|
+
const { 0: protectedHeader, 1: encryptedKey, 2: iv, 3: ciphertext, 4: tag2, length } = jwe.split(".");
|
|
13092
|
+
if (length !== 5) {
|
|
13093
|
+
throw new JWEInvalid("Invalid Compact JWE");
|
|
13094
|
+
}
|
|
13095
|
+
const decrypted = await flattenedDecrypt({
|
|
13096
|
+
ciphertext,
|
|
13097
|
+
iv: iv || void 0,
|
|
13098
|
+
protected: protectedHeader,
|
|
13099
|
+
tag: tag2 || void 0,
|
|
13100
|
+
encrypted_key: encryptedKey || void 0
|
|
13101
|
+
}, key, options);
|
|
13102
|
+
const result = { plaintext: decrypted.plaintext, protectedHeader: decrypted.protectedHeader };
|
|
13103
|
+
if (typeof key === "function") {
|
|
13104
|
+
return { ...result, key: decrypted.key };
|
|
13105
|
+
}
|
|
13106
|
+
return result;
|
|
13107
|
+
}
|
|
13108
|
+
|
|
13109
|
+
// node_modules/jose/dist/webapi/lib/private_symbols.js
|
|
13110
|
+
var unprotected = Symbol();
|
|
13111
|
+
|
|
13112
|
+
// node_modules/jose/dist/webapi/lib/key_to_jwk.js
|
|
13113
|
+
async function keyToJWK(key) {
|
|
13114
|
+
if (isKeyObject(key)) {
|
|
13115
|
+
if (key.type === "secret") {
|
|
13116
|
+
key = key.export();
|
|
13117
|
+
} else {
|
|
13118
|
+
return key.export({ format: "jwk" });
|
|
13119
|
+
}
|
|
13120
|
+
}
|
|
13121
|
+
if (key instanceof Uint8Array) {
|
|
13122
|
+
return {
|
|
13123
|
+
kty: "oct",
|
|
13124
|
+
k: encode(key)
|
|
13125
|
+
};
|
|
13126
|
+
}
|
|
13127
|
+
if (!isCryptoKey(key)) {
|
|
13128
|
+
throw new TypeError(invalid_key_input_default(key, "CryptoKey", "KeyObject", "Uint8Array"));
|
|
13129
|
+
}
|
|
13130
|
+
if (!key.extractable) {
|
|
13131
|
+
throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");
|
|
13132
|
+
}
|
|
13133
|
+
const { ext, key_ops, alg, use, ...jwk } = await crypto.subtle.exportKey("jwk", key);
|
|
13134
|
+
return jwk;
|
|
13135
|
+
}
|
|
13136
|
+
|
|
13137
|
+
// node_modules/jose/dist/webapi/key/export.js
|
|
13138
|
+
async function exportJWK(key) {
|
|
13139
|
+
return keyToJWK(key);
|
|
13140
|
+
}
|
|
13141
|
+
|
|
13142
|
+
// node_modules/jose/dist/webapi/lib/encrypt_key_management.js
|
|
13143
|
+
var encrypt_key_management_default = async (alg, enc, key, providedCek, providedParameters = {}) => {
|
|
13144
|
+
let encryptedKey;
|
|
13145
|
+
let parameters;
|
|
13146
|
+
let cek;
|
|
13147
|
+
switch (alg) {
|
|
13148
|
+
case "dir": {
|
|
13149
|
+
cek = key;
|
|
13150
|
+
break;
|
|
13151
|
+
}
|
|
13152
|
+
case "ECDH-ES":
|
|
13153
|
+
case "ECDH-ES+A128KW":
|
|
13154
|
+
case "ECDH-ES+A192KW":
|
|
13155
|
+
case "ECDH-ES+A256KW": {
|
|
13156
|
+
assertCryptoKey(key);
|
|
13157
|
+
if (!allowed(key)) {
|
|
13158
|
+
throw new JOSENotSupported("ECDH with the provided key is not allowed or not supported by your javascript runtime");
|
|
13159
|
+
}
|
|
13160
|
+
const { apu, apv } = providedParameters;
|
|
13161
|
+
let ephemeralKey;
|
|
13162
|
+
if (providedParameters.epk) {
|
|
13163
|
+
ephemeralKey = await normalize_key_default(providedParameters.epk, alg);
|
|
13164
|
+
} else {
|
|
13165
|
+
ephemeralKey = (await crypto.subtle.generateKey(key.algorithm, true, ["deriveBits"])).privateKey;
|
|
13166
|
+
}
|
|
13167
|
+
const { x, y, crv, kty } = await exportJWK(ephemeralKey);
|
|
13168
|
+
const sharedSecret = await deriveKey(key, ephemeralKey, alg === "ECDH-ES" ? enc : alg, alg === "ECDH-ES" ? bitLength2(enc) : parseInt(alg.slice(-5, -2), 10), apu, apv);
|
|
13169
|
+
parameters = { epk: { x, crv, kty } };
|
|
13170
|
+
if (kty === "EC")
|
|
13171
|
+
parameters.epk.y = y;
|
|
13172
|
+
if (apu)
|
|
13173
|
+
parameters.apu = encode(apu);
|
|
13174
|
+
if (apv)
|
|
13175
|
+
parameters.apv = encode(apv);
|
|
13176
|
+
if (alg === "ECDH-ES") {
|
|
13177
|
+
cek = sharedSecret;
|
|
13178
|
+
break;
|
|
13179
|
+
}
|
|
13180
|
+
cek = providedCek || cek_default(enc);
|
|
13181
|
+
const kwAlg = alg.slice(-6);
|
|
13182
|
+
encryptedKey = await wrap(kwAlg, sharedSecret, cek);
|
|
13183
|
+
break;
|
|
13184
|
+
}
|
|
13185
|
+
case "RSA-OAEP":
|
|
13186
|
+
case "RSA-OAEP-256":
|
|
13187
|
+
case "RSA-OAEP-384":
|
|
13188
|
+
case "RSA-OAEP-512": {
|
|
13189
|
+
cek = providedCek || cek_default(enc);
|
|
13190
|
+
assertCryptoKey(key);
|
|
13191
|
+
encryptedKey = await encrypt(alg, key, cek);
|
|
13192
|
+
break;
|
|
13193
|
+
}
|
|
13194
|
+
case "PBES2-HS256+A128KW":
|
|
13195
|
+
case "PBES2-HS384+A192KW":
|
|
13196
|
+
case "PBES2-HS512+A256KW": {
|
|
13197
|
+
cek = providedCek || cek_default(enc);
|
|
13198
|
+
const { p2c, p2s } = providedParameters;
|
|
13199
|
+
({ encryptedKey, ...parameters } = await wrap2(alg, key, cek, p2c, p2s));
|
|
13200
|
+
break;
|
|
13201
|
+
}
|
|
13202
|
+
case "A128KW":
|
|
13203
|
+
case "A192KW":
|
|
13204
|
+
case "A256KW": {
|
|
13205
|
+
cek = providedCek || cek_default(enc);
|
|
13206
|
+
encryptedKey = await wrap(alg, key, cek);
|
|
13207
|
+
break;
|
|
13208
|
+
}
|
|
13209
|
+
case "A128GCMKW":
|
|
13210
|
+
case "A192GCMKW":
|
|
13211
|
+
case "A256GCMKW": {
|
|
13212
|
+
cek = providedCek || cek_default(enc);
|
|
13213
|
+
const { iv } = providedParameters;
|
|
13214
|
+
({ encryptedKey, ...parameters } = await wrap3(alg, key, cek, iv));
|
|
13215
|
+
break;
|
|
13216
|
+
}
|
|
13217
|
+
default: {
|
|
13218
|
+
throw new JOSENotSupported('Invalid or unsupported "alg" (JWE Algorithm) header value');
|
|
13219
|
+
}
|
|
13220
|
+
}
|
|
13221
|
+
return { cek, encryptedKey, parameters };
|
|
13222
|
+
};
|
|
13223
|
+
|
|
13224
|
+
// node_modules/jose/dist/webapi/jwe/flattened/encrypt.js
|
|
13225
|
+
var FlattenedEncrypt = class {
|
|
13226
|
+
#plaintext;
|
|
13227
|
+
#protectedHeader;
|
|
13228
|
+
#sharedUnprotectedHeader;
|
|
13229
|
+
#unprotectedHeader;
|
|
13230
|
+
#aad;
|
|
13231
|
+
#cek;
|
|
13232
|
+
#iv;
|
|
13233
|
+
#keyManagementParameters;
|
|
13234
|
+
constructor(plaintext) {
|
|
13235
|
+
if (!(plaintext instanceof Uint8Array)) {
|
|
13236
|
+
throw new TypeError("plaintext must be an instance of Uint8Array");
|
|
13237
|
+
}
|
|
13238
|
+
this.#plaintext = plaintext;
|
|
13239
|
+
}
|
|
13240
|
+
setKeyManagementParameters(parameters) {
|
|
13241
|
+
if (this.#keyManagementParameters) {
|
|
13242
|
+
throw new TypeError("setKeyManagementParameters can only be called once");
|
|
13243
|
+
}
|
|
13244
|
+
this.#keyManagementParameters = parameters;
|
|
13245
|
+
return this;
|
|
13246
|
+
}
|
|
13247
|
+
setProtectedHeader(protectedHeader) {
|
|
13248
|
+
if (this.#protectedHeader) {
|
|
13249
|
+
throw new TypeError("setProtectedHeader can only be called once");
|
|
13250
|
+
}
|
|
13251
|
+
this.#protectedHeader = protectedHeader;
|
|
13252
|
+
return this;
|
|
13253
|
+
}
|
|
13254
|
+
setSharedUnprotectedHeader(sharedUnprotectedHeader) {
|
|
13255
|
+
if (this.#sharedUnprotectedHeader) {
|
|
13256
|
+
throw new TypeError("setSharedUnprotectedHeader can only be called once");
|
|
13257
|
+
}
|
|
13258
|
+
this.#sharedUnprotectedHeader = sharedUnprotectedHeader;
|
|
13259
|
+
return this;
|
|
13260
|
+
}
|
|
13261
|
+
setUnprotectedHeader(unprotectedHeader) {
|
|
13262
|
+
if (this.#unprotectedHeader) {
|
|
13263
|
+
throw new TypeError("setUnprotectedHeader can only be called once");
|
|
13264
|
+
}
|
|
13265
|
+
this.#unprotectedHeader = unprotectedHeader;
|
|
13266
|
+
return this;
|
|
13267
|
+
}
|
|
13268
|
+
setAdditionalAuthenticatedData(aad) {
|
|
13269
|
+
this.#aad = aad;
|
|
13270
|
+
return this;
|
|
13271
|
+
}
|
|
13272
|
+
setContentEncryptionKey(cek) {
|
|
13273
|
+
if (this.#cek) {
|
|
13274
|
+
throw new TypeError("setContentEncryptionKey can only be called once");
|
|
13275
|
+
}
|
|
13276
|
+
this.#cek = cek;
|
|
13277
|
+
return this;
|
|
13278
|
+
}
|
|
13279
|
+
setInitializationVector(iv) {
|
|
13280
|
+
if (this.#iv) {
|
|
13281
|
+
throw new TypeError("setInitializationVector can only be called once");
|
|
13282
|
+
}
|
|
13283
|
+
this.#iv = iv;
|
|
13284
|
+
return this;
|
|
13285
|
+
}
|
|
13286
|
+
async encrypt(key, options) {
|
|
13287
|
+
if (!this.#protectedHeader && !this.#unprotectedHeader && !this.#sharedUnprotectedHeader) {
|
|
13288
|
+
throw new JWEInvalid("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");
|
|
13289
|
+
}
|
|
13290
|
+
if (!is_disjoint_default(this.#protectedHeader, this.#unprotectedHeader, this.#sharedUnprotectedHeader)) {
|
|
13291
|
+
throw new JWEInvalid("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");
|
|
13292
|
+
}
|
|
13293
|
+
const joseHeader = {
|
|
13294
|
+
...this.#protectedHeader,
|
|
13295
|
+
...this.#unprotectedHeader,
|
|
13296
|
+
...this.#sharedUnprotectedHeader
|
|
13297
|
+
};
|
|
13298
|
+
validate_crit_default(JWEInvalid, /* @__PURE__ */ new Map(), options?.crit, this.#protectedHeader, joseHeader);
|
|
13299
|
+
if (joseHeader.zip !== void 0) {
|
|
13300
|
+
throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
|
|
13301
|
+
}
|
|
13302
|
+
const { alg, enc } = joseHeader;
|
|
13303
|
+
if (typeof alg !== "string" || !alg) {
|
|
13304
|
+
throw new JWEInvalid('JWE "alg" (Algorithm) Header Parameter missing or invalid');
|
|
13305
|
+
}
|
|
13306
|
+
if (typeof enc !== "string" || !enc) {
|
|
13307
|
+
throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');
|
|
13308
|
+
}
|
|
13309
|
+
let encryptedKey;
|
|
13310
|
+
if (this.#cek && (alg === "dir" || alg === "ECDH-ES")) {
|
|
13311
|
+
throw new TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${alg}`);
|
|
13312
|
+
}
|
|
13313
|
+
check_key_type_default(alg === "dir" ? enc : alg, key, "encrypt");
|
|
13314
|
+
let cek;
|
|
13315
|
+
{
|
|
13316
|
+
let parameters;
|
|
13317
|
+
const k = await normalize_key_default(key, alg);
|
|
13318
|
+
({ cek, encryptedKey, parameters } = await encrypt_key_management_default(alg, enc, k, this.#cek, this.#keyManagementParameters));
|
|
13319
|
+
if (parameters) {
|
|
13320
|
+
if (options && unprotected in options) {
|
|
13321
|
+
if (!this.#unprotectedHeader) {
|
|
13322
|
+
this.setUnprotectedHeader(parameters);
|
|
13323
|
+
} else {
|
|
13324
|
+
this.#unprotectedHeader = { ...this.#unprotectedHeader, ...parameters };
|
|
13325
|
+
}
|
|
13326
|
+
} else if (!this.#protectedHeader) {
|
|
13327
|
+
this.setProtectedHeader(parameters);
|
|
13328
|
+
} else {
|
|
13329
|
+
this.#protectedHeader = { ...this.#protectedHeader, ...parameters };
|
|
13330
|
+
}
|
|
13331
|
+
}
|
|
13332
|
+
}
|
|
13333
|
+
let additionalData;
|
|
13334
|
+
let protectedHeader;
|
|
13335
|
+
let aadMember;
|
|
13336
|
+
if (this.#protectedHeader) {
|
|
13337
|
+
protectedHeader = encoder.encode(encode(JSON.stringify(this.#protectedHeader)));
|
|
13338
|
+
} else {
|
|
13339
|
+
protectedHeader = encoder.encode("");
|
|
13340
|
+
}
|
|
13341
|
+
if (this.#aad) {
|
|
13342
|
+
aadMember = encode(this.#aad);
|
|
13343
|
+
additionalData = concat(protectedHeader, encoder.encode("."), encoder.encode(aadMember));
|
|
13344
|
+
} else {
|
|
13345
|
+
additionalData = protectedHeader;
|
|
13346
|
+
}
|
|
13347
|
+
const { ciphertext, tag: tag2, iv } = await encrypt_default(enc, this.#plaintext, cek, this.#iv, additionalData);
|
|
13348
|
+
const jwe = {
|
|
13349
|
+
ciphertext: encode(ciphertext)
|
|
13350
|
+
};
|
|
13351
|
+
if (iv) {
|
|
13352
|
+
jwe.iv = encode(iv);
|
|
13353
|
+
}
|
|
13354
|
+
if (tag2) {
|
|
13355
|
+
jwe.tag = encode(tag2);
|
|
13356
|
+
}
|
|
13357
|
+
if (encryptedKey) {
|
|
13358
|
+
jwe.encrypted_key = encode(encryptedKey);
|
|
13359
|
+
}
|
|
13360
|
+
if (aadMember) {
|
|
13361
|
+
jwe.aad = aadMember;
|
|
13362
|
+
}
|
|
13363
|
+
if (this.#protectedHeader) {
|
|
13364
|
+
jwe.protected = decoder.decode(protectedHeader);
|
|
13365
|
+
}
|
|
13366
|
+
if (this.#sharedUnprotectedHeader) {
|
|
13367
|
+
jwe.unprotected = this.#sharedUnprotectedHeader;
|
|
13368
|
+
}
|
|
13369
|
+
if (this.#unprotectedHeader) {
|
|
13370
|
+
jwe.header = this.#unprotectedHeader;
|
|
13371
|
+
}
|
|
13372
|
+
return jwe;
|
|
13373
|
+
}
|
|
13374
|
+
};
|
|
13375
|
+
|
|
13376
|
+
// node_modules/jose/dist/webapi/lib/subtle_dsa.js
|
|
13377
|
+
var subtle_dsa_default = (alg, algorithm) => {
|
|
13378
|
+
const hash = `SHA-${alg.slice(-3)}`;
|
|
13379
|
+
switch (alg) {
|
|
13380
|
+
case "HS256":
|
|
13381
|
+
case "HS384":
|
|
13382
|
+
case "HS512":
|
|
13383
|
+
return { hash, name: "HMAC" };
|
|
13384
|
+
case "PS256":
|
|
13385
|
+
case "PS384":
|
|
13386
|
+
case "PS512":
|
|
13387
|
+
return { hash, name: "RSA-PSS", saltLength: parseInt(alg.slice(-3), 10) >> 3 };
|
|
13388
|
+
case "RS256":
|
|
13389
|
+
case "RS384":
|
|
13390
|
+
case "RS512":
|
|
13391
|
+
return { hash, name: "RSASSA-PKCS1-v1_5" };
|
|
13392
|
+
case "ES256":
|
|
13393
|
+
case "ES384":
|
|
13394
|
+
case "ES512":
|
|
13395
|
+
return { hash, name: "ECDSA", namedCurve: algorithm.namedCurve };
|
|
13396
|
+
case "Ed25519":
|
|
13397
|
+
case "EdDSA":
|
|
13398
|
+
return { name: "Ed25519" };
|
|
13399
|
+
default:
|
|
13400
|
+
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
13401
|
+
}
|
|
13402
|
+
};
|
|
13403
|
+
|
|
13404
|
+
// node_modules/jose/dist/webapi/lib/get_sign_verify_key.js
|
|
13405
|
+
var get_sign_verify_key_default = async (alg, key, usage2) => {
|
|
13406
|
+
if (key instanceof Uint8Array) {
|
|
13407
|
+
if (!alg.startsWith("HS")) {
|
|
13408
|
+
throw new TypeError(invalid_key_input_default(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
13409
|
+
}
|
|
13410
|
+
return crypto.subtle.importKey("raw", key, { hash: `SHA-${alg.slice(-3)}`, name: "HMAC" }, false, [usage2]);
|
|
13411
|
+
}
|
|
13412
|
+
checkSigCryptoKey(key, alg, usage2);
|
|
13413
|
+
return key;
|
|
13414
|
+
};
|
|
13415
|
+
|
|
13416
|
+
// node_modules/jose/dist/webapi/lib/verify.js
|
|
13417
|
+
var verify_default = async (alg, key, signature, data) => {
|
|
13418
|
+
const cryptoKey = await get_sign_verify_key_default(alg, key, "verify");
|
|
13419
|
+
check_key_length_default(alg, cryptoKey);
|
|
13420
|
+
const algorithm = subtle_dsa_default(alg, cryptoKey.algorithm);
|
|
13421
|
+
try {
|
|
13422
|
+
return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
|
|
13423
|
+
} catch {
|
|
13424
|
+
return false;
|
|
13425
|
+
}
|
|
13426
|
+
};
|
|
13427
|
+
|
|
13428
|
+
// node_modules/jose/dist/webapi/jws/flattened/verify.js
|
|
13429
|
+
async function flattenedVerify(jws, key, options) {
|
|
13430
|
+
if (!is_object_default(jws)) {
|
|
13431
|
+
throw new JWSInvalid("Flattened JWS must be an object");
|
|
13432
|
+
}
|
|
13433
|
+
if (jws.protected === void 0 && jws.header === void 0) {
|
|
13434
|
+
throw new JWSInvalid('Flattened JWS must have either of the "protected" or "header" members');
|
|
13435
|
+
}
|
|
13436
|
+
if (jws.protected !== void 0 && typeof jws.protected !== "string") {
|
|
13437
|
+
throw new JWSInvalid("JWS Protected Header incorrect type");
|
|
13438
|
+
}
|
|
13439
|
+
if (jws.payload === void 0) {
|
|
13440
|
+
throw new JWSInvalid("JWS Payload missing");
|
|
13441
|
+
}
|
|
13442
|
+
if (typeof jws.signature !== "string") {
|
|
13443
|
+
throw new JWSInvalid("JWS Signature missing or incorrect type");
|
|
13444
|
+
}
|
|
13445
|
+
if (jws.header !== void 0 && !is_object_default(jws.header)) {
|
|
13446
|
+
throw new JWSInvalid("JWS Unprotected Header incorrect type");
|
|
13447
|
+
}
|
|
13448
|
+
let parsedProt = {};
|
|
13449
|
+
if (jws.protected) {
|
|
13450
|
+
try {
|
|
13451
|
+
const protectedHeader = decode(jws.protected);
|
|
13452
|
+
parsedProt = JSON.parse(decoder.decode(protectedHeader));
|
|
13453
|
+
} catch {
|
|
13454
|
+
throw new JWSInvalid("JWS Protected Header is invalid");
|
|
13455
|
+
}
|
|
13456
|
+
}
|
|
13457
|
+
if (!is_disjoint_default(parsedProt, jws.header)) {
|
|
13458
|
+
throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
13459
|
+
}
|
|
13460
|
+
const joseHeader = {
|
|
13461
|
+
...parsedProt,
|
|
13462
|
+
...jws.header
|
|
13463
|
+
};
|
|
13464
|
+
const extensions = validate_crit_default(JWSInvalid, /* @__PURE__ */ new Map([["b64", true]]), options?.crit, parsedProt, joseHeader);
|
|
13465
|
+
let b64 = true;
|
|
13466
|
+
if (extensions.has("b64")) {
|
|
13467
|
+
b64 = parsedProt.b64;
|
|
13468
|
+
if (typeof b64 !== "boolean") {
|
|
13469
|
+
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
13470
|
+
}
|
|
13471
|
+
}
|
|
13472
|
+
const { alg } = joseHeader;
|
|
13473
|
+
if (typeof alg !== "string" || !alg) {
|
|
13474
|
+
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
13475
|
+
}
|
|
13476
|
+
const algorithms = options && validate_algorithms_default("algorithms", options.algorithms);
|
|
13477
|
+
if (algorithms && !algorithms.has(alg)) {
|
|
13478
|
+
throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
|
|
13479
|
+
}
|
|
13480
|
+
if (b64) {
|
|
13481
|
+
if (typeof jws.payload !== "string") {
|
|
13482
|
+
throw new JWSInvalid("JWS Payload must be a string");
|
|
13483
|
+
}
|
|
13484
|
+
} else if (typeof jws.payload !== "string" && !(jws.payload instanceof Uint8Array)) {
|
|
13485
|
+
throw new JWSInvalid("JWS Payload must be a string or an Uint8Array instance");
|
|
13486
|
+
}
|
|
13487
|
+
let resolvedKey = false;
|
|
13488
|
+
if (typeof key === "function") {
|
|
13489
|
+
key = await key(parsedProt, jws);
|
|
13490
|
+
resolvedKey = true;
|
|
13491
|
+
}
|
|
13492
|
+
check_key_type_default(alg, key, "verify");
|
|
13493
|
+
const data = concat(encoder.encode(jws.protected ?? ""), encoder.encode("."), typeof jws.payload === "string" ? encoder.encode(jws.payload) : jws.payload);
|
|
13494
|
+
let signature;
|
|
13495
|
+
try {
|
|
13496
|
+
signature = decode(jws.signature);
|
|
13497
|
+
} catch {
|
|
13498
|
+
throw new JWSInvalid("Failed to base64url decode the signature");
|
|
13499
|
+
}
|
|
13500
|
+
const k = await normalize_key_default(key, alg);
|
|
13501
|
+
const verified = await verify_default(alg, k, signature, data);
|
|
13502
|
+
if (!verified) {
|
|
13503
|
+
throw new JWSSignatureVerificationFailed();
|
|
13504
|
+
}
|
|
13505
|
+
let payload;
|
|
13506
|
+
if (b64) {
|
|
13507
|
+
try {
|
|
13508
|
+
payload = decode(jws.payload);
|
|
13509
|
+
} catch {
|
|
13510
|
+
throw new JWSInvalid("Failed to base64url decode the payload");
|
|
13511
|
+
}
|
|
13512
|
+
} else if (typeof jws.payload === "string") {
|
|
13513
|
+
payload = encoder.encode(jws.payload);
|
|
13514
|
+
} else {
|
|
13515
|
+
payload = jws.payload;
|
|
13516
|
+
}
|
|
13517
|
+
const result = { payload };
|
|
13518
|
+
if (jws.protected !== void 0) {
|
|
13519
|
+
result.protectedHeader = parsedProt;
|
|
13520
|
+
}
|
|
13521
|
+
if (jws.header !== void 0) {
|
|
13522
|
+
result.unprotectedHeader = jws.header;
|
|
13523
|
+
}
|
|
13524
|
+
if (resolvedKey) {
|
|
13525
|
+
return { ...result, key: k };
|
|
13526
|
+
}
|
|
13527
|
+
return result;
|
|
13528
|
+
}
|
|
13529
|
+
|
|
13530
|
+
// node_modules/jose/dist/webapi/jws/compact/verify.js
|
|
13531
|
+
async function compactVerify(jws, key, options) {
|
|
13532
|
+
if (jws instanceof Uint8Array) {
|
|
13533
|
+
jws = decoder.decode(jws);
|
|
13534
|
+
}
|
|
13535
|
+
if (typeof jws !== "string") {
|
|
13536
|
+
throw new JWSInvalid("Compact JWS must be a string or Uint8Array");
|
|
13537
|
+
}
|
|
13538
|
+
const { 0: protectedHeader, 1: payload, 2: signature, length } = jws.split(".");
|
|
13539
|
+
if (length !== 3) {
|
|
13540
|
+
throw new JWSInvalid("Invalid Compact JWS");
|
|
13541
|
+
}
|
|
13542
|
+
const verified = await flattenedVerify({ payload, protected: protectedHeader, signature }, key, options);
|
|
13543
|
+
const result = { payload: verified.payload, protectedHeader: verified.protectedHeader };
|
|
13544
|
+
if (typeof key === "function") {
|
|
13545
|
+
return { ...result, key: verified.key };
|
|
13546
|
+
}
|
|
13547
|
+
return result;
|
|
13548
|
+
}
|
|
13549
|
+
|
|
13550
|
+
// node_modules/jose/dist/webapi/lib/epoch.js
|
|
13551
|
+
var epoch_default = (date) => Math.floor(date.getTime() / 1e3);
|
|
13552
|
+
|
|
13553
|
+
// node_modules/jose/dist/webapi/lib/secs.js
|
|
13554
|
+
var minute = 60;
|
|
13555
|
+
var hour = minute * 60;
|
|
13556
|
+
var day = hour * 24;
|
|
13557
|
+
var week = day * 7;
|
|
13558
|
+
var year = day * 365.25;
|
|
13559
|
+
var REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
13560
|
+
var secs_default = (str) => {
|
|
13561
|
+
const matched = REGEX.exec(str);
|
|
13562
|
+
if (!matched || matched[4] && matched[1]) {
|
|
13563
|
+
throw new TypeError("Invalid time period format");
|
|
13564
|
+
}
|
|
13565
|
+
const value = parseFloat(matched[2]);
|
|
13566
|
+
const unit = matched[3].toLowerCase();
|
|
13567
|
+
let numericDate;
|
|
13568
|
+
switch (unit) {
|
|
13569
|
+
case "sec":
|
|
13570
|
+
case "secs":
|
|
13571
|
+
case "second":
|
|
13572
|
+
case "seconds":
|
|
13573
|
+
case "s":
|
|
13574
|
+
numericDate = Math.round(value);
|
|
13575
|
+
break;
|
|
13576
|
+
case "minute":
|
|
13577
|
+
case "minutes":
|
|
13578
|
+
case "min":
|
|
13579
|
+
case "mins":
|
|
13580
|
+
case "m":
|
|
13581
|
+
numericDate = Math.round(value * minute);
|
|
13582
|
+
break;
|
|
13583
|
+
case "hour":
|
|
13584
|
+
case "hours":
|
|
13585
|
+
case "hr":
|
|
13586
|
+
case "hrs":
|
|
13587
|
+
case "h":
|
|
13588
|
+
numericDate = Math.round(value * hour);
|
|
13589
|
+
break;
|
|
13590
|
+
case "day":
|
|
13591
|
+
case "days":
|
|
13592
|
+
case "d":
|
|
13593
|
+
numericDate = Math.round(value * day);
|
|
13594
|
+
break;
|
|
13595
|
+
case "week":
|
|
13596
|
+
case "weeks":
|
|
13597
|
+
case "w":
|
|
13598
|
+
numericDate = Math.round(value * week);
|
|
13599
|
+
break;
|
|
13600
|
+
default:
|
|
13601
|
+
numericDate = Math.round(value * year);
|
|
13602
|
+
break;
|
|
13603
|
+
}
|
|
13604
|
+
if (matched[1] === "-" || matched[4] === "ago") {
|
|
13605
|
+
return -numericDate;
|
|
13606
|
+
}
|
|
13607
|
+
return numericDate;
|
|
13608
|
+
};
|
|
13609
|
+
|
|
13610
|
+
// node_modules/jose/dist/webapi/lib/jwt_claims_set.js
|
|
13611
|
+
function validateInput(label, input) {
|
|
13612
|
+
if (!Number.isFinite(input)) {
|
|
13613
|
+
throw new TypeError(`Invalid ${label} input`);
|
|
13614
|
+
}
|
|
13615
|
+
return input;
|
|
13616
|
+
}
|
|
13617
|
+
var normalizeTyp = (value) => {
|
|
13618
|
+
if (value.includes("/")) {
|
|
13619
|
+
return value.toLowerCase();
|
|
13620
|
+
}
|
|
13621
|
+
return `application/${value.toLowerCase()}`;
|
|
13622
|
+
};
|
|
13623
|
+
var checkAudiencePresence = (audPayload, audOption) => {
|
|
13624
|
+
if (typeof audPayload === "string") {
|
|
13625
|
+
return audOption.includes(audPayload);
|
|
13626
|
+
}
|
|
13627
|
+
if (Array.isArray(audPayload)) {
|
|
13628
|
+
return audOption.some(Set.prototype.has.bind(new Set(audPayload)));
|
|
13629
|
+
}
|
|
13630
|
+
return false;
|
|
13631
|
+
};
|
|
13632
|
+
function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
|
|
13633
|
+
let payload;
|
|
13634
|
+
try {
|
|
13635
|
+
payload = JSON.parse(decoder.decode(encodedPayload));
|
|
13636
|
+
} catch {
|
|
13637
|
+
}
|
|
13638
|
+
if (!is_object_default(payload)) {
|
|
13639
|
+
throw new JWTInvalid("JWT Claims Set must be a top-level JSON object");
|
|
13640
|
+
}
|
|
13641
|
+
const { typ } = options;
|
|
13642
|
+
if (typ && (typeof protectedHeader.typ !== "string" || normalizeTyp(protectedHeader.typ) !== normalizeTyp(typ))) {
|
|
13643
|
+
throw new JWTClaimValidationFailed('unexpected "typ" JWT header value', payload, "typ", "check_failed");
|
|
13644
|
+
}
|
|
13645
|
+
const { requiredClaims = [], issuer, subject, audience, maxTokenAge } = options;
|
|
13646
|
+
const presenceCheck = [...requiredClaims];
|
|
13647
|
+
if (maxTokenAge !== void 0)
|
|
13648
|
+
presenceCheck.push("iat");
|
|
13649
|
+
if (audience !== void 0)
|
|
13650
|
+
presenceCheck.push("aud");
|
|
13651
|
+
if (subject !== void 0)
|
|
13652
|
+
presenceCheck.push("sub");
|
|
13653
|
+
if (issuer !== void 0)
|
|
13654
|
+
presenceCheck.push("iss");
|
|
13655
|
+
for (const claim of new Set(presenceCheck.reverse())) {
|
|
13656
|
+
if (!(claim in payload)) {
|
|
13657
|
+
throw new JWTClaimValidationFailed(`missing required "${claim}" claim`, payload, claim, "missing");
|
|
13658
|
+
}
|
|
13659
|
+
}
|
|
13660
|
+
if (issuer && !(Array.isArray(issuer) ? issuer : [issuer]).includes(payload.iss)) {
|
|
13661
|
+
throw new JWTClaimValidationFailed('unexpected "iss" claim value', payload, "iss", "check_failed");
|
|
13662
|
+
}
|
|
13663
|
+
if (subject && payload.sub !== subject) {
|
|
13664
|
+
throw new JWTClaimValidationFailed('unexpected "sub" claim value', payload, "sub", "check_failed");
|
|
13665
|
+
}
|
|
13666
|
+
if (audience && !checkAudiencePresence(payload.aud, typeof audience === "string" ? [audience] : audience)) {
|
|
13667
|
+
throw new JWTClaimValidationFailed('unexpected "aud" claim value', payload, "aud", "check_failed");
|
|
13668
|
+
}
|
|
13669
|
+
let tolerance;
|
|
13670
|
+
switch (typeof options.clockTolerance) {
|
|
13671
|
+
case "string":
|
|
13672
|
+
tolerance = secs_default(options.clockTolerance);
|
|
13673
|
+
break;
|
|
13674
|
+
case "number":
|
|
13675
|
+
tolerance = options.clockTolerance;
|
|
13676
|
+
break;
|
|
13677
|
+
case "undefined":
|
|
13678
|
+
tolerance = 0;
|
|
13679
|
+
break;
|
|
13680
|
+
default:
|
|
13681
|
+
throw new TypeError("Invalid clockTolerance option type");
|
|
13682
|
+
}
|
|
13683
|
+
const { currentDate } = options;
|
|
13684
|
+
const now = epoch_default(currentDate || /* @__PURE__ */ new Date());
|
|
13685
|
+
if ((payload.iat !== void 0 || maxTokenAge) && typeof payload.iat !== "number") {
|
|
13686
|
+
throw new JWTClaimValidationFailed('"iat" claim must be a number', payload, "iat", "invalid");
|
|
13687
|
+
}
|
|
13688
|
+
if (payload.nbf !== void 0) {
|
|
13689
|
+
if (typeof payload.nbf !== "number") {
|
|
13690
|
+
throw new JWTClaimValidationFailed('"nbf" claim must be a number', payload, "nbf", "invalid");
|
|
13691
|
+
}
|
|
13692
|
+
if (payload.nbf > now + tolerance) {
|
|
13693
|
+
throw new JWTClaimValidationFailed('"nbf" claim timestamp check failed', payload, "nbf", "check_failed");
|
|
13694
|
+
}
|
|
13695
|
+
}
|
|
13696
|
+
if (payload.exp !== void 0) {
|
|
13697
|
+
if (typeof payload.exp !== "number") {
|
|
13698
|
+
throw new JWTClaimValidationFailed('"exp" claim must be a number', payload, "exp", "invalid");
|
|
13699
|
+
}
|
|
13700
|
+
if (payload.exp <= now - tolerance) {
|
|
13701
|
+
throw new JWTExpired('"exp" claim timestamp check failed', payload, "exp", "check_failed");
|
|
13702
|
+
}
|
|
13703
|
+
}
|
|
13704
|
+
if (maxTokenAge) {
|
|
13705
|
+
const age = now - payload.iat;
|
|
13706
|
+
const max = typeof maxTokenAge === "number" ? maxTokenAge : secs_default(maxTokenAge);
|
|
13707
|
+
if (age - tolerance > max) {
|
|
13708
|
+
throw new JWTExpired('"iat" claim timestamp check failed (too far in the past)', payload, "iat", "check_failed");
|
|
13709
|
+
}
|
|
13710
|
+
if (age < 0 - tolerance) {
|
|
13711
|
+
throw new JWTClaimValidationFailed('"iat" claim timestamp check failed (it should be in the past)', payload, "iat", "check_failed");
|
|
13712
|
+
}
|
|
13713
|
+
}
|
|
13714
|
+
return payload;
|
|
13715
|
+
}
|
|
13716
|
+
var JWTClaimsBuilder = class {
|
|
13717
|
+
#payload;
|
|
13718
|
+
constructor(payload) {
|
|
13719
|
+
if (!is_object_default(payload)) {
|
|
13720
|
+
throw new TypeError("JWT Claims Set MUST be an object");
|
|
13721
|
+
}
|
|
13722
|
+
this.#payload = structuredClone(payload);
|
|
13723
|
+
}
|
|
13724
|
+
data() {
|
|
13725
|
+
return encoder.encode(JSON.stringify(this.#payload));
|
|
13726
|
+
}
|
|
13727
|
+
get iss() {
|
|
13728
|
+
return this.#payload.iss;
|
|
13729
|
+
}
|
|
13730
|
+
set iss(value) {
|
|
13731
|
+
this.#payload.iss = value;
|
|
13732
|
+
}
|
|
13733
|
+
get sub() {
|
|
13734
|
+
return this.#payload.sub;
|
|
13735
|
+
}
|
|
13736
|
+
set sub(value) {
|
|
13737
|
+
this.#payload.sub = value;
|
|
13738
|
+
}
|
|
13739
|
+
get aud() {
|
|
13740
|
+
return this.#payload.aud;
|
|
13741
|
+
}
|
|
13742
|
+
set aud(value) {
|
|
13743
|
+
this.#payload.aud = value;
|
|
13744
|
+
}
|
|
13745
|
+
set jti(value) {
|
|
13746
|
+
this.#payload.jti = value;
|
|
13747
|
+
}
|
|
13748
|
+
set nbf(value) {
|
|
13749
|
+
if (typeof value === "number") {
|
|
13750
|
+
this.#payload.nbf = validateInput("setNotBefore", value);
|
|
13751
|
+
} else if (value instanceof Date) {
|
|
13752
|
+
this.#payload.nbf = validateInput("setNotBefore", epoch_default(value));
|
|
13753
|
+
} else {
|
|
13754
|
+
this.#payload.nbf = epoch_default(/* @__PURE__ */ new Date()) + secs_default(value);
|
|
13755
|
+
}
|
|
13756
|
+
}
|
|
13757
|
+
set exp(value) {
|
|
13758
|
+
if (typeof value === "number") {
|
|
13759
|
+
this.#payload.exp = validateInput("setExpirationTime", value);
|
|
13760
|
+
} else if (value instanceof Date) {
|
|
13761
|
+
this.#payload.exp = validateInput("setExpirationTime", epoch_default(value));
|
|
13762
|
+
} else {
|
|
13763
|
+
this.#payload.exp = epoch_default(/* @__PURE__ */ new Date()) + secs_default(value);
|
|
13764
|
+
}
|
|
13765
|
+
}
|
|
13766
|
+
set iat(value) {
|
|
13767
|
+
if (typeof value === "undefined") {
|
|
13768
|
+
this.#payload.iat = epoch_default(/* @__PURE__ */ new Date());
|
|
13769
|
+
} else if (value instanceof Date) {
|
|
13770
|
+
this.#payload.iat = validateInput("setIssuedAt", epoch_default(value));
|
|
13771
|
+
} else if (typeof value === "string") {
|
|
13772
|
+
this.#payload.iat = validateInput("setIssuedAt", epoch_default(/* @__PURE__ */ new Date()) + secs_default(value));
|
|
13773
|
+
} else {
|
|
13774
|
+
this.#payload.iat = validateInput("setIssuedAt", value);
|
|
13775
|
+
}
|
|
13776
|
+
}
|
|
13777
|
+
};
|
|
13778
|
+
|
|
13779
|
+
// node_modules/jose/dist/webapi/jwt/verify.js
|
|
13780
|
+
async function jwtVerify(jwt, key, options) {
|
|
13781
|
+
const verified = await compactVerify(jwt, key, options);
|
|
13782
|
+
if (verified.protectedHeader.crit?.includes("b64") && verified.protectedHeader.b64 === false) {
|
|
13783
|
+
throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
13784
|
+
}
|
|
13785
|
+
const payload = validateClaimsSet(verified.protectedHeader, verified.payload, options);
|
|
13786
|
+
const result = { payload, protectedHeader: verified.protectedHeader };
|
|
13787
|
+
if (typeof key === "function") {
|
|
13788
|
+
return { ...result, key: verified.key };
|
|
13789
|
+
}
|
|
13790
|
+
return result;
|
|
13791
|
+
}
|
|
13792
|
+
|
|
13793
|
+
// node_modules/jose/dist/webapi/jwt/decrypt.js
|
|
13794
|
+
async function jwtDecrypt(jwt, key, options) {
|
|
13795
|
+
const decrypted = await compactDecrypt(jwt, key, options);
|
|
13796
|
+
const payload = validateClaimsSet(decrypted.protectedHeader, decrypted.plaintext, options);
|
|
13797
|
+
const { protectedHeader } = decrypted;
|
|
13798
|
+
if (protectedHeader.iss !== void 0 && protectedHeader.iss !== payload.iss) {
|
|
13799
|
+
throw new JWTClaimValidationFailed('replicated "iss" claim header parameter mismatch', payload, "iss", "mismatch");
|
|
13800
|
+
}
|
|
13801
|
+
if (protectedHeader.sub !== void 0 && protectedHeader.sub !== payload.sub) {
|
|
13802
|
+
throw new JWTClaimValidationFailed('replicated "sub" claim header parameter mismatch', payload, "sub", "mismatch");
|
|
13803
|
+
}
|
|
13804
|
+
if (protectedHeader.aud !== void 0 && JSON.stringify(protectedHeader.aud) !== JSON.stringify(payload.aud)) {
|
|
13805
|
+
throw new JWTClaimValidationFailed('replicated "aud" claim header parameter mismatch', payload, "aud", "mismatch");
|
|
13806
|
+
}
|
|
13807
|
+
const result = { payload, protectedHeader };
|
|
13808
|
+
if (typeof key === "function") {
|
|
13809
|
+
return { ...result, key: decrypted.key };
|
|
13810
|
+
}
|
|
13811
|
+
return result;
|
|
13812
|
+
}
|
|
13813
|
+
|
|
13814
|
+
// node_modules/jose/dist/webapi/jwe/compact/encrypt.js
|
|
13815
|
+
var CompactEncrypt = class {
|
|
13816
|
+
#flattened;
|
|
13817
|
+
constructor(plaintext) {
|
|
13818
|
+
this.#flattened = new FlattenedEncrypt(plaintext);
|
|
13819
|
+
}
|
|
13820
|
+
setContentEncryptionKey(cek) {
|
|
13821
|
+
this.#flattened.setContentEncryptionKey(cek);
|
|
13822
|
+
return this;
|
|
13823
|
+
}
|
|
13824
|
+
setInitializationVector(iv) {
|
|
13825
|
+
this.#flattened.setInitializationVector(iv);
|
|
13826
|
+
return this;
|
|
13827
|
+
}
|
|
13828
|
+
setProtectedHeader(protectedHeader) {
|
|
13829
|
+
this.#flattened.setProtectedHeader(protectedHeader);
|
|
13830
|
+
return this;
|
|
13831
|
+
}
|
|
13832
|
+
setKeyManagementParameters(parameters) {
|
|
13833
|
+
this.#flattened.setKeyManagementParameters(parameters);
|
|
13834
|
+
return this;
|
|
13835
|
+
}
|
|
13836
|
+
async encrypt(key, options) {
|
|
13837
|
+
const jwe = await this.#flattened.encrypt(key, options);
|
|
13838
|
+
return [jwe.protected, jwe.encrypted_key, jwe.iv, jwe.ciphertext, jwe.tag].join(".");
|
|
13839
|
+
}
|
|
13840
|
+
};
|
|
13841
|
+
|
|
13842
|
+
// node_modules/jose/dist/webapi/lib/sign.js
|
|
13843
|
+
var sign_default = async (alg, key, data) => {
|
|
13844
|
+
const cryptoKey = await get_sign_verify_key_default(alg, key, "sign");
|
|
13845
|
+
check_key_length_default(alg, cryptoKey);
|
|
13846
|
+
const signature = await crypto.subtle.sign(subtle_dsa_default(alg, cryptoKey.algorithm), cryptoKey, data);
|
|
13847
|
+
return new Uint8Array(signature);
|
|
13848
|
+
};
|
|
13849
|
+
|
|
13850
|
+
// node_modules/jose/dist/webapi/jws/flattened/sign.js
|
|
13851
|
+
var FlattenedSign = class {
|
|
13852
|
+
#payload;
|
|
13853
|
+
#protectedHeader;
|
|
13854
|
+
#unprotectedHeader;
|
|
13855
|
+
constructor(payload) {
|
|
13856
|
+
if (!(payload instanceof Uint8Array)) {
|
|
13857
|
+
throw new TypeError("payload must be an instance of Uint8Array");
|
|
13858
|
+
}
|
|
13859
|
+
this.#payload = payload;
|
|
13860
|
+
}
|
|
13861
|
+
setProtectedHeader(protectedHeader) {
|
|
13862
|
+
if (this.#protectedHeader) {
|
|
13863
|
+
throw new TypeError("setProtectedHeader can only be called once");
|
|
13864
|
+
}
|
|
13865
|
+
this.#protectedHeader = protectedHeader;
|
|
13866
|
+
return this;
|
|
13867
|
+
}
|
|
13868
|
+
setUnprotectedHeader(unprotectedHeader) {
|
|
13869
|
+
if (this.#unprotectedHeader) {
|
|
13870
|
+
throw new TypeError("setUnprotectedHeader can only be called once");
|
|
13871
|
+
}
|
|
13872
|
+
this.#unprotectedHeader = unprotectedHeader;
|
|
13873
|
+
return this;
|
|
13874
|
+
}
|
|
13875
|
+
async sign(key, options) {
|
|
13876
|
+
if (!this.#protectedHeader && !this.#unprotectedHeader) {
|
|
13877
|
+
throw new JWSInvalid("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
|
|
13878
|
+
}
|
|
13879
|
+
if (!is_disjoint_default(this.#protectedHeader, this.#unprotectedHeader)) {
|
|
13880
|
+
throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
13881
|
+
}
|
|
13882
|
+
const joseHeader = {
|
|
13883
|
+
...this.#protectedHeader,
|
|
13884
|
+
...this.#unprotectedHeader
|
|
13885
|
+
};
|
|
13886
|
+
const extensions = validate_crit_default(JWSInvalid, /* @__PURE__ */ new Map([["b64", true]]), options?.crit, this.#protectedHeader, joseHeader);
|
|
13887
|
+
let b64 = true;
|
|
13888
|
+
if (extensions.has("b64")) {
|
|
13889
|
+
b64 = this.#protectedHeader.b64;
|
|
13890
|
+
if (typeof b64 !== "boolean") {
|
|
13891
|
+
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
13892
|
+
}
|
|
13893
|
+
}
|
|
13894
|
+
const { alg } = joseHeader;
|
|
13895
|
+
if (typeof alg !== "string" || !alg) {
|
|
13896
|
+
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
13897
|
+
}
|
|
13898
|
+
check_key_type_default(alg, key, "sign");
|
|
13899
|
+
let payload = this.#payload;
|
|
13900
|
+
if (b64) {
|
|
13901
|
+
payload = encoder.encode(encode(payload));
|
|
13902
|
+
}
|
|
13903
|
+
let protectedHeader;
|
|
13904
|
+
if (this.#protectedHeader) {
|
|
13905
|
+
protectedHeader = encoder.encode(encode(JSON.stringify(this.#protectedHeader)));
|
|
13906
|
+
} else {
|
|
13907
|
+
protectedHeader = encoder.encode("");
|
|
13908
|
+
}
|
|
13909
|
+
const data = concat(protectedHeader, encoder.encode("."), payload);
|
|
13910
|
+
const k = await normalize_key_default(key, alg);
|
|
13911
|
+
const signature = await sign_default(alg, k, data);
|
|
13912
|
+
const jws = {
|
|
13913
|
+
signature: encode(signature),
|
|
13914
|
+
payload: ""
|
|
13915
|
+
};
|
|
13916
|
+
if (b64) {
|
|
13917
|
+
jws.payload = decoder.decode(payload);
|
|
13918
|
+
}
|
|
13919
|
+
if (this.#unprotectedHeader) {
|
|
13920
|
+
jws.header = this.#unprotectedHeader;
|
|
13921
|
+
}
|
|
13922
|
+
if (this.#protectedHeader) {
|
|
13923
|
+
jws.protected = decoder.decode(protectedHeader);
|
|
13924
|
+
}
|
|
13925
|
+
return jws;
|
|
13926
|
+
}
|
|
13927
|
+
};
|
|
13928
|
+
|
|
13929
|
+
// node_modules/jose/dist/webapi/jws/compact/sign.js
|
|
13930
|
+
var CompactSign = class {
|
|
13931
|
+
#flattened;
|
|
13932
|
+
constructor(payload) {
|
|
13933
|
+
this.#flattened = new FlattenedSign(payload);
|
|
13934
|
+
}
|
|
13935
|
+
setProtectedHeader(protectedHeader) {
|
|
13936
|
+
this.#flattened.setProtectedHeader(protectedHeader);
|
|
13937
|
+
return this;
|
|
13938
|
+
}
|
|
13939
|
+
async sign(key, options) {
|
|
13940
|
+
const jws = await this.#flattened.sign(key, options);
|
|
13941
|
+
if (jws.payload === void 0) {
|
|
13942
|
+
throw new TypeError("use the flattened module for creating JWS with b64: false");
|
|
13943
|
+
}
|
|
13944
|
+
return `${jws.protected}.${jws.payload}.${jws.signature}`;
|
|
13945
|
+
}
|
|
13946
|
+
};
|
|
13947
|
+
|
|
13948
|
+
// node_modules/jose/dist/webapi/jwt/sign.js
|
|
13949
|
+
var SignJWT = class {
|
|
13950
|
+
#protectedHeader;
|
|
13951
|
+
#jwt;
|
|
13952
|
+
constructor(payload = {}) {
|
|
13953
|
+
this.#jwt = new JWTClaimsBuilder(payload);
|
|
13954
|
+
}
|
|
13955
|
+
setIssuer(issuer) {
|
|
13956
|
+
this.#jwt.iss = issuer;
|
|
13957
|
+
return this;
|
|
13958
|
+
}
|
|
13959
|
+
setSubject(subject) {
|
|
13960
|
+
this.#jwt.sub = subject;
|
|
13961
|
+
return this;
|
|
13962
|
+
}
|
|
13963
|
+
setAudience(audience) {
|
|
13964
|
+
this.#jwt.aud = audience;
|
|
13965
|
+
return this;
|
|
13966
|
+
}
|
|
13967
|
+
setJti(jwtId) {
|
|
13968
|
+
this.#jwt.jti = jwtId;
|
|
13969
|
+
return this;
|
|
13970
|
+
}
|
|
13971
|
+
setNotBefore(input) {
|
|
13972
|
+
this.#jwt.nbf = input;
|
|
13973
|
+
return this;
|
|
13974
|
+
}
|
|
13975
|
+
setExpirationTime(input) {
|
|
13976
|
+
this.#jwt.exp = input;
|
|
13977
|
+
return this;
|
|
13978
|
+
}
|
|
13979
|
+
setIssuedAt(input) {
|
|
13980
|
+
this.#jwt.iat = input;
|
|
13981
|
+
return this;
|
|
13982
|
+
}
|
|
13983
|
+
setProtectedHeader(protectedHeader) {
|
|
13984
|
+
this.#protectedHeader = protectedHeader;
|
|
13985
|
+
return this;
|
|
13986
|
+
}
|
|
13987
|
+
async sign(key, options) {
|
|
13988
|
+
const sig = new CompactSign(this.#jwt.data());
|
|
13989
|
+
sig.setProtectedHeader(this.#protectedHeader);
|
|
13990
|
+
if (Array.isArray(this.#protectedHeader?.crit) && this.#protectedHeader.crit.includes("b64") && this.#protectedHeader.b64 === false) {
|
|
13991
|
+
throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
13992
|
+
}
|
|
13993
|
+
return sig.sign(key, options);
|
|
13994
|
+
}
|
|
13995
|
+
};
|
|
13996
|
+
|
|
13997
|
+
// node_modules/jose/dist/webapi/jwt/encrypt.js
|
|
13998
|
+
var EncryptJWT = class {
|
|
13999
|
+
#cek;
|
|
14000
|
+
#iv;
|
|
14001
|
+
#keyManagementParameters;
|
|
14002
|
+
#protectedHeader;
|
|
14003
|
+
#replicateIssuerAsHeader;
|
|
14004
|
+
#replicateSubjectAsHeader;
|
|
14005
|
+
#replicateAudienceAsHeader;
|
|
14006
|
+
#jwt;
|
|
14007
|
+
constructor(payload = {}) {
|
|
14008
|
+
this.#jwt = new JWTClaimsBuilder(payload);
|
|
14009
|
+
}
|
|
14010
|
+
setIssuer(issuer) {
|
|
14011
|
+
this.#jwt.iss = issuer;
|
|
14012
|
+
return this;
|
|
14013
|
+
}
|
|
14014
|
+
setSubject(subject) {
|
|
14015
|
+
this.#jwt.sub = subject;
|
|
14016
|
+
return this;
|
|
14017
|
+
}
|
|
14018
|
+
setAudience(audience) {
|
|
14019
|
+
this.#jwt.aud = audience;
|
|
14020
|
+
return this;
|
|
14021
|
+
}
|
|
14022
|
+
setJti(jwtId) {
|
|
14023
|
+
this.#jwt.jti = jwtId;
|
|
14024
|
+
return this;
|
|
14025
|
+
}
|
|
14026
|
+
setNotBefore(input) {
|
|
14027
|
+
this.#jwt.nbf = input;
|
|
14028
|
+
return this;
|
|
14029
|
+
}
|
|
14030
|
+
setExpirationTime(input) {
|
|
14031
|
+
this.#jwt.exp = input;
|
|
14032
|
+
return this;
|
|
14033
|
+
}
|
|
14034
|
+
setIssuedAt(input) {
|
|
14035
|
+
this.#jwt.iat = input;
|
|
14036
|
+
return this;
|
|
14037
|
+
}
|
|
14038
|
+
setProtectedHeader(protectedHeader) {
|
|
14039
|
+
if (this.#protectedHeader) {
|
|
14040
|
+
throw new TypeError("setProtectedHeader can only be called once");
|
|
14041
|
+
}
|
|
14042
|
+
this.#protectedHeader = protectedHeader;
|
|
14043
|
+
return this;
|
|
14044
|
+
}
|
|
14045
|
+
setKeyManagementParameters(parameters) {
|
|
14046
|
+
if (this.#keyManagementParameters) {
|
|
14047
|
+
throw new TypeError("setKeyManagementParameters can only be called once");
|
|
14048
|
+
}
|
|
14049
|
+
this.#keyManagementParameters = parameters;
|
|
14050
|
+
return this;
|
|
14051
|
+
}
|
|
14052
|
+
setContentEncryptionKey(cek) {
|
|
14053
|
+
if (this.#cek) {
|
|
14054
|
+
throw new TypeError("setContentEncryptionKey can only be called once");
|
|
14055
|
+
}
|
|
14056
|
+
this.#cek = cek;
|
|
14057
|
+
return this;
|
|
14058
|
+
}
|
|
14059
|
+
setInitializationVector(iv) {
|
|
14060
|
+
if (this.#iv) {
|
|
14061
|
+
throw new TypeError("setInitializationVector can only be called once");
|
|
14062
|
+
}
|
|
14063
|
+
this.#iv = iv;
|
|
14064
|
+
return this;
|
|
14065
|
+
}
|
|
14066
|
+
replicateIssuerAsHeader() {
|
|
14067
|
+
this.#replicateIssuerAsHeader = true;
|
|
14068
|
+
return this;
|
|
14069
|
+
}
|
|
14070
|
+
replicateSubjectAsHeader() {
|
|
14071
|
+
this.#replicateSubjectAsHeader = true;
|
|
14072
|
+
return this;
|
|
14073
|
+
}
|
|
14074
|
+
replicateAudienceAsHeader() {
|
|
14075
|
+
this.#replicateAudienceAsHeader = true;
|
|
14076
|
+
return this;
|
|
14077
|
+
}
|
|
14078
|
+
async encrypt(key, options) {
|
|
14079
|
+
const enc = new CompactEncrypt(this.#jwt.data());
|
|
14080
|
+
if (this.#protectedHeader && (this.#replicateIssuerAsHeader || this.#replicateSubjectAsHeader || this.#replicateAudienceAsHeader)) {
|
|
14081
|
+
this.#protectedHeader = {
|
|
14082
|
+
...this.#protectedHeader,
|
|
14083
|
+
iss: this.#replicateIssuerAsHeader ? this.#jwt.iss : void 0,
|
|
14084
|
+
sub: this.#replicateSubjectAsHeader ? this.#jwt.sub : void 0,
|
|
14085
|
+
aud: this.#replicateAudienceAsHeader ? this.#jwt.aud : void 0
|
|
14086
|
+
};
|
|
14087
|
+
}
|
|
14088
|
+
enc.setProtectedHeader(this.#protectedHeader);
|
|
14089
|
+
if (this.#iv) {
|
|
14090
|
+
enc.setInitializationVector(this.#iv);
|
|
14091
|
+
}
|
|
14092
|
+
if (this.#cek) {
|
|
14093
|
+
enc.setContentEncryptionKey(this.#cek);
|
|
14094
|
+
}
|
|
14095
|
+
if (this.#keyManagementParameters) {
|
|
14096
|
+
enc.setKeyManagementParameters(this.#keyManagementParameters);
|
|
14097
|
+
}
|
|
14098
|
+
return enc.encrypt(key, options);
|
|
14099
|
+
}
|
|
14100
|
+
};
|
|
14101
|
+
|
|
14102
|
+
// node_modules/jose/dist/webapi/util/decode_protected_header.js
|
|
14103
|
+
function decodeProtectedHeader(token) {
|
|
14104
|
+
let protectedB64u;
|
|
14105
|
+
if (typeof token === "string") {
|
|
14106
|
+
const parts = token.split(".");
|
|
14107
|
+
if (parts.length === 3 || parts.length === 5) {
|
|
14108
|
+
;
|
|
14109
|
+
[protectedB64u] = parts;
|
|
14110
|
+
}
|
|
14111
|
+
} else if (typeof token === "object" && token) {
|
|
14112
|
+
if ("protected" in token) {
|
|
14113
|
+
protectedB64u = token.protected;
|
|
14114
|
+
} else {
|
|
14115
|
+
throw new TypeError("Token does not contain a Protected Header");
|
|
14116
|
+
}
|
|
14117
|
+
}
|
|
14118
|
+
try {
|
|
14119
|
+
if (typeof protectedB64u !== "string" || !protectedB64u) {
|
|
14120
|
+
throw new Error();
|
|
14121
|
+
}
|
|
14122
|
+
const result = JSON.parse(decoder.decode(decode(protectedB64u)));
|
|
14123
|
+
if (!is_object_default(result)) {
|
|
14124
|
+
throw new Error();
|
|
14125
|
+
}
|
|
14126
|
+
return result;
|
|
14127
|
+
} catch {
|
|
14128
|
+
throw new TypeError("Invalid Token or Protected Header formatting");
|
|
14129
|
+
}
|
|
14130
|
+
}
|
|
14131
|
+
|
|
14132
|
+
// node_modules/jose/dist/webapi/util/decode_jwt.js
|
|
14133
|
+
function decodeJwt(jwt) {
|
|
14134
|
+
if (typeof jwt !== "string")
|
|
14135
|
+
throw new JWTInvalid("JWTs must use Compact JWS serialization, JWT must be a string");
|
|
14136
|
+
const { 1: payload, length } = jwt.split(".");
|
|
14137
|
+
if (length === 5)
|
|
14138
|
+
throw new JWTInvalid("Only JWTs using Compact JWS serialization can be decoded");
|
|
14139
|
+
if (length !== 3)
|
|
14140
|
+
throw new JWTInvalid("Invalid JWT");
|
|
14141
|
+
if (!payload)
|
|
14142
|
+
throw new JWTInvalid("JWTs must contain a payload");
|
|
14143
|
+
let decoded;
|
|
14144
|
+
try {
|
|
14145
|
+
decoded = decode(payload);
|
|
14146
|
+
} catch {
|
|
14147
|
+
throw new JWTInvalid("Failed to base64url decode the payload");
|
|
14148
|
+
}
|
|
14149
|
+
let result;
|
|
14150
|
+
try {
|
|
14151
|
+
result = JSON.parse(decoder.decode(decoded));
|
|
14152
|
+
} catch {
|
|
14153
|
+
throw new JWTInvalid("Failed to parse the decoded payload as JSON");
|
|
14154
|
+
}
|
|
14155
|
+
if (!is_object_default(result))
|
|
14156
|
+
throw new JWTInvalid("Invalid JWT Claims Set");
|
|
14157
|
+
return result;
|
|
14158
|
+
}
|
|
14159
|
+
|
|
14160
|
+
// src/common/jwt.ts
|
|
14161
|
+
async function encryptJWT(payload, secret, options) {
|
|
14162
|
+
const en = new EncryptJWT(payload).setProtectedHeader({
|
|
14163
|
+
alg: options?.alg ? options?.alg : "dir",
|
|
14164
|
+
enc: options?.enc ? options?.enc : "A128CBC-HS256"
|
|
14165
|
+
}).setIssuedAt(options?.iat).setIssuer(options?.iss ? options?.iss : "urn:example:issuer").setAudience(options?.aud ? options?.aud : "urn:example:audience").setExpirationTime(options?.exp ? options?.exp : "2h");
|
|
14166
|
+
return await en.encrypt(secret, options?.options);
|
|
14167
|
+
}
|
|
14168
|
+
async function decryptJWT(jwt, secret, options) {
|
|
14169
|
+
return await jwtDecrypt(jwt, secret, options);
|
|
14170
|
+
}
|
|
14171
|
+
async function verifyJWT(jwt, secret, options) {
|
|
14172
|
+
return await jwtVerify(jwt, secret, options);
|
|
14173
|
+
}
|
|
14174
|
+
async function signJWT(payload, secret, options) {
|
|
14175
|
+
const sign = new SignJWT(payload).setProtectedHeader({
|
|
14176
|
+
alg: options?.alg ? options?.alg : "HS256"
|
|
14177
|
+
}).setIssuedAt(options?.iat).setIssuer(options?.iss ? options?.iss : "urn:example:issuer").setAudience(options?.aud ? options?.aud : "urn:example:audience").setExpirationTime(options?.exp ? options?.exp : "2h");
|
|
14178
|
+
return sign.sign(secret, options?.options);
|
|
14179
|
+
}
|
|
14180
|
+
function decodeProtectedHeaderJWT(token) {
|
|
14181
|
+
return decodeProtectedHeader(token);
|
|
14182
|
+
}
|
|
14183
|
+
function decodeJWT(jwt) {
|
|
14184
|
+
return decodeJwt(jwt);
|
|
14185
|
+
}
|
|
14186
|
+
|
|
14187
|
+
// src/services/globals.ts
|
|
14188
|
+
var import_node_crypto3 = require("node:crypto");
|
|
14189
|
+
var globalJSX = Object.freeze({
|
|
14190
|
+
createElement: (...args) => {
|
|
14191
|
+
const ret = createElement(...args);
|
|
14192
|
+
ret.toString = () => jsx2HTML(ret);
|
|
14193
|
+
return ret;
|
|
14194
|
+
},
|
|
14195
|
+
Fragment,
|
|
14196
|
+
enableDebugLog
|
|
14197
|
+
});
|
|
14198
|
+
var globaljsx = Object.freeze({
|
|
14199
|
+
useContext,
|
|
14200
|
+
useRuntime,
|
|
14201
|
+
createContext,
|
|
14202
|
+
useState,
|
|
14203
|
+
useEffect,
|
|
14204
|
+
useQuery,
|
|
14205
|
+
useRef,
|
|
14206
|
+
useElement,
|
|
14207
|
+
useRefresh,
|
|
14208
|
+
Link,
|
|
14209
|
+
Router: Router2,
|
|
14210
|
+
usePathname,
|
|
14211
|
+
define: function define2() {
|
|
14212
|
+
}
|
|
14213
|
+
});
|
|
14214
|
+
var globalWindow = Object.freeze({
|
|
14215
|
+
addEventListener: function define3() {
|
|
14216
|
+
}
|
|
14217
|
+
});
|
|
14218
|
+
var globalServer = Object.freeze({
|
|
14219
|
+
middleware: Object.freeze({
|
|
14220
|
+
buffer: ReadBuffer,
|
|
14221
|
+
url: URLEncodedParser,
|
|
14222
|
+
json: JSONParser,
|
|
14223
|
+
text: TextParser,
|
|
14224
|
+
cors: CORS,
|
|
14225
|
+
session: SessionHandler
|
|
14226
|
+
}),
|
|
14227
|
+
encodeHTML: HTMLEncode,
|
|
14228
|
+
inflateMDtoHTML: inflateMD2HTML,
|
|
14229
|
+
createSecretKey: import_node_crypto3.createSecretKey,
|
|
14230
|
+
newParser() {
|
|
14231
|
+
return new Parser();
|
|
14232
|
+
},
|
|
14233
|
+
newClusterCache(name, logger) {
|
|
14234
|
+
return new ClusterCache(name, logger);
|
|
14235
|
+
},
|
|
14236
|
+
newLocalCache(name, logger) {
|
|
14237
|
+
return new LocalCache(name, logger);
|
|
14238
|
+
},
|
|
14239
|
+
getWorkerNumber() {
|
|
14240
|
+
return import_node_cluster2.default.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === void 0 ? 0 : parseInt(process.env["CLUSTER_NODE_NUMBER"], 10);
|
|
14241
|
+
},
|
|
14242
|
+
getWorkerCount() {
|
|
14243
|
+
return import_node_cluster2.default.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === void 0 || process.env["CLUSTER_COUNT"] === void 0 ? 1 : parseInt(process.env["CLUSTER_COUNT"], 10);
|
|
14244
|
+
},
|
|
14245
|
+
isPrimaryWorker() {
|
|
14246
|
+
return import_node_cluster2.default.isPrimary || process.env["CLUSTER_NODE_NUMBER"] === "0";
|
|
14247
|
+
},
|
|
14248
|
+
jwt: {
|
|
14249
|
+
decode(jwt) {
|
|
14250
|
+
return decodeJWT(jwt);
|
|
14251
|
+
},
|
|
14252
|
+
decodeProtectedHeader(token) {
|
|
14253
|
+
return decodeProtectedHeaderJWT(token);
|
|
14254
|
+
},
|
|
14255
|
+
decrypt(jwt, secret, options) {
|
|
14256
|
+
return decryptJWT(jwt, secret, options);
|
|
14257
|
+
},
|
|
14258
|
+
encrypt(payload, secret, options) {
|
|
14259
|
+
return encryptJWT(payload, secret, options);
|
|
14260
|
+
},
|
|
14261
|
+
sign(payload, secret, options) {
|
|
14262
|
+
return signJWT(payload, secret, options);
|
|
14263
|
+
},
|
|
14264
|
+
verify(jwt, secret, options) {
|
|
14265
|
+
return verifyJWT(jwt, secret, options);
|
|
14266
|
+
}
|
|
14267
|
+
}
|
|
14268
|
+
});
|
|
14269
|
+
function browserJSXGlobals(inFile, jsxPath = false, useExport = true) {
|
|
14270
|
+
const PRE = `import { enableDebugLog, useRuntime, Link, usePathname, createContext, useContext, useElement, useRefresh, useQuery, define, Router, useState, useEffect, useRef, createElement, Fragment } from "${jsxPath}";
|
|
14271
|
+
globalThis.JSX = Object.freeze({
|
|
14272
|
+
createElement,
|
|
14273
|
+
Fragment,
|
|
14274
|
+
enableDebugLog
|
|
14275
|
+
});
|
|
14276
|
+
|
|
14277
|
+
globalThis.newParser = () => new Parser();
|
|
14278
|
+
globalThis.jsx = Object.freeze({
|
|
14279
|
+
define,
|
|
14280
|
+
useRuntime,
|
|
14281
|
+
createContext,
|
|
14282
|
+
useContext,
|
|
14283
|
+
useState,
|
|
14284
|
+
useEffect,
|
|
14285
|
+
useQuery,
|
|
14286
|
+
useRef,
|
|
14287
|
+
useElement,
|
|
14288
|
+
useRefresh,
|
|
14289
|
+
usePathname,
|
|
14290
|
+
Link,
|
|
14291
|
+
Router
|
|
14292
|
+
});`;
|
|
14293
|
+
return `${jsxPath ? PRE : ""}
|
|
14294
|
+
${useExport ? `export * from "${inFile}";import * as lib from "${inFile}";export default lib.default;` : `import * as lib from "${inFile}"`}`;
|
|
14295
|
+
}
|
|
14296
|
+
function initGlobals() {
|
|
14297
|
+
globalThis.server = globalServer;
|
|
14298
|
+
globalThis.JSX = globalJSX;
|
|
14299
|
+
globalThis.jsx = globaljsx;
|
|
14300
|
+
globalThis.window = globalWindow;
|
|
14301
|
+
}
|
|
14302
|
+
function assertGlobalTampered() {
|
|
14303
|
+
try {
|
|
14304
|
+
(0, import_node_assert.strictEqual)(globalThis.JSX, globalJSX, "globalThis.JSX tamperered");
|
|
14305
|
+
(0, import_node_assert.strictEqual)(globalThis.server, globalServer, "globalThis.server tamperered");
|
|
14306
|
+
(0, import_node_assert.strictEqual)(globalThis.jsx, globaljsx, "globalThis.jsx tamperered");
|
|
14307
|
+
(0, import_node_assert.strictEqual)(globalThis.window, globalWindow, "globalThis.window tamperered");
|
|
14308
|
+
} catch (e) {
|
|
14309
|
+
console.error(e);
|
|
14310
|
+
process.exit(EXIT_CODES.GLOBALS_ALTERED);
|
|
14311
|
+
}
|
|
14312
|
+
}
|
|
14313
|
+
|
|
14314
|
+
// src/common/jsx.ts
|
|
14315
|
+
var jsxJSBuffer = null;
|
|
14316
|
+
var jsxJSBufferChecksumPromise = null;
|
|
14317
|
+
async function initJSXJS(logger) {
|
|
14318
|
+
jsxJSBuffer = jsxJSBuffer ? jsxJSBuffer : Buffer.from(getAsset("jsx.dom.js"));
|
|
14319
|
+
jsxJSBufferChecksumPromise = jsxJSBufferChecksumPromise ? jsxJSBufferChecksumPromise : calculateChecksumFromBuffer(jsxJSBuffer);
|
|
14320
|
+
return initAsset(logger, getJSXJSPath(), jsxJSBuffer, true, jsxJSBufferChecksumPromise, false);
|
|
14321
|
+
}
|
|
14322
|
+
var parser2 = new Parser();
|
|
14323
|
+
var DEFAULT_ESOPTION = {
|
|
14324
|
+
platform: "neutral",
|
|
14325
|
+
bundle: true,
|
|
14326
|
+
jsxFactory: "JSX.createElement",
|
|
14327
|
+
jsxFragment: "JSX.Fragment"
|
|
14328
|
+
};
|
|
14329
|
+
async function inflateJSX(inFile, options) {
|
|
14330
|
+
const tmpBuildDir = (0, import_node_path5.resolve)(JSX_TMP_DIR, String(process.pid), "build", Date.now() + "-" + (0, import_node_crypto4.randomUUID)());
|
|
14331
|
+
const inFileTmp = (0, import_node_path5.resolve)(tmpBuildDir, (0, import_node_path5.basename)(inFile) + ".mjs");
|
|
14332
|
+
const jsxJSPath = getJSXJSPath();
|
|
14333
|
+
const logger = options.logger;
|
|
14334
|
+
try {
|
|
14335
|
+
if (!options.embemedJSX) {
|
|
14336
|
+
(0, import_node_fs6.mkdirSync)(tmpBuildDir, {
|
|
14337
|
+
recursive: true
|
|
14338
|
+
});
|
|
14339
|
+
(0, import_node_fs6.writeFileSync)(inFileTmp, browserJSXGlobals(inFile, false, options.useExport));
|
|
14340
|
+
logger?.trace("inflating [%s] from [%s]. to change the import folder set JSX_TMP", (0, import_node_path5.relative)((0, import_node_process3.cwd)(), inFile), (0, import_node_path5.dirname)((0, import_node_path5.relative)(JSX_TMP_DIR, inFileTmp)));
|
|
14341
|
+
const { outputFiles: [{ contents }] } = await esBuild({
|
|
14342
|
+
...DEFAULT_ESOPTION,
|
|
14343
|
+
entryPoints: [inFileTmp],
|
|
14344
|
+
minify: options.minify
|
|
14345
|
+
});
|
|
14346
|
+
if (CLEAR_JSX_CACHE) {
|
|
14347
|
+
logger?.trace("clearing cache at [%s] to change this behaivor set CLEAR_JSX_CACHE to 0", tmpBuildDir);
|
|
14348
|
+
(0, import_node_fs6.unlinkSync)(inFileTmp);
|
|
14349
|
+
(0, import_node_fs6.rmdirSync)(tmpBuildDir);
|
|
14350
|
+
}
|
|
14351
|
+
return contents;
|
|
14352
|
+
} else {
|
|
14353
|
+
(0, import_node_fs6.mkdirSync)(tmpBuildDir, {
|
|
14354
|
+
recursive: true
|
|
14355
|
+
});
|
|
14356
|
+
(0, import_node_fs6.writeFileSync)(inFileTmp, browserJSXGlobals(inFile, jsxJSPath));
|
|
14357
|
+
logger?.trace("inflating [%s] from [%s] with jsx.js embedded. to change the import folder set JSX_TMP", (0, import_node_path5.relative)((0, import_node_process3.cwd)(), inFile), (0, import_node_path5.dirname)((0, import_node_path5.relative)(JSX_TMP_DIR, inFileTmp)));
|
|
14358
|
+
const { outputFiles: [{ contents }] } = await esBuild({
|
|
14359
|
+
...DEFAULT_ESOPTION,
|
|
14360
|
+
entryPoints: [inFileTmp],
|
|
14361
|
+
minify: options.minify
|
|
14362
|
+
});
|
|
14363
|
+
if (CLEAR_JSX_CACHE) {
|
|
14364
|
+
logger?.trace("clearing cache at [%s] to change this behaivor set CLEAR_JSX_CACHE to 0", tmpBuildDir);
|
|
14365
|
+
(0, import_node_fs6.unlinkSync)(inFileTmp);
|
|
14366
|
+
(0, import_node_fs6.rmdirSync)(tmpBuildDir);
|
|
14367
|
+
}
|
|
14368
|
+
return contents;
|
|
14369
|
+
}
|
|
14370
|
+
} catch (e) {
|
|
14371
|
+
logger?.error("error with: " + inFile);
|
|
14372
|
+
logger?.error(e);
|
|
14373
|
+
if (options.embemedJSX) {
|
|
14374
|
+
if (CLEAR_JSX_CACHE) {
|
|
14375
|
+
logger?.trace("clearing cache at [%s] to change this behaivor set CLEAR_JSX_CACHE to 0", tmpBuildDir);
|
|
14376
|
+
(0, import_node_fs6.unlinkSync)(inFileTmp);
|
|
14377
|
+
(0, import_node_fs6.rmdirSync)(tmpBuildDir);
|
|
14378
|
+
} else {
|
|
14379
|
+
logger?.error("error with: %s", inFileTmp);
|
|
14380
|
+
logger?.trace("NOT clearing cache. to change this behaivor set CLEAR_JSX_CACHE to 1", tmpBuildDir);
|
|
14381
|
+
}
|
|
14382
|
+
}
|
|
14383
|
+
throw e;
|
|
14384
|
+
}
|
|
14385
|
+
}
|
|
14386
|
+
var APIOptionsSchema = {
|
|
14387
|
+
type: "object?",
|
|
14388
|
+
properties: {
|
|
14389
|
+
basePath: "string?",
|
|
14390
|
+
path: "string?|string[]?",
|
|
14391
|
+
method: "string?|string[]?",
|
|
14392
|
+
parser: {
|
|
14393
|
+
type: "object?",
|
|
14394
|
+
properties: {
|
|
14395
|
+
parse: "function"
|
|
14396
|
+
},
|
|
14397
|
+
mode: "add_extra"
|
|
14398
|
+
},
|
|
14399
|
+
middleware: "function[]!?",
|
|
14400
|
+
session: {
|
|
14401
|
+
type: "object?|function?",
|
|
14402
|
+
properties: SessionHandlerOptionsSchema.properties
|
|
14403
|
+
},
|
|
14404
|
+
...RouteOptionsSchema.properties
|
|
14405
|
+
}
|
|
14406
|
+
//mode:"add_extra"
|
|
14407
|
+
};
|
|
14408
|
+
var HTMLModuleSchema = {
|
|
14409
|
+
type: "object",
|
|
14410
|
+
properties: {
|
|
14411
|
+
default: {
|
|
14412
|
+
type: "function|object"
|
|
14413
|
+
},
|
|
14414
|
+
apiOptions: APIOptionsSchema
|
|
14415
|
+
}
|
|
14416
|
+
//mode:"add_extra"
|
|
14417
|
+
};
|
|
14418
|
+
var JSONModuleSchema = {
|
|
14419
|
+
type: "object",
|
|
14420
|
+
properties: {
|
|
14421
|
+
default: {
|
|
14422
|
+
type: "function|object|string"
|
|
14423
|
+
},
|
|
14424
|
+
apiOptions: APIOptionsSchema
|
|
14425
|
+
}
|
|
14426
|
+
//mode:"add_extra"
|
|
14427
|
+
};
|
|
14428
|
+
var MigrationSchema = {
|
|
14429
|
+
type: "object",
|
|
14430
|
+
properties: {
|
|
14431
|
+
up: "function",
|
|
14432
|
+
down: "function"
|
|
14433
|
+
},
|
|
14434
|
+
mode: "add_extra"
|
|
14435
|
+
};
|
|
14436
|
+
var CORSOptionsSchema = {
|
|
14437
|
+
type: "object",
|
|
14438
|
+
properties: {
|
|
14439
|
+
origins: "string[]?|string?",
|
|
14440
|
+
validate: "function?",
|
|
14441
|
+
methods: "string?",
|
|
14442
|
+
preflightContinue: "boolean?"
|
|
14443
|
+
}
|
|
14444
|
+
//mode:"add_extra"
|
|
14445
|
+
};
|
|
14446
|
+
var WSConfigSchema = {
|
|
14447
|
+
type: "object",
|
|
14448
|
+
properties: {
|
|
14449
|
+
path: "string",
|
|
14450
|
+
disabled: "boolean?",
|
|
14451
|
+
maxConnections: "number?",
|
|
14452
|
+
validate: "function?",
|
|
14453
|
+
onConnection: "function?",
|
|
14454
|
+
onMessage: "function?",
|
|
14455
|
+
onDisconnect: "function?"
|
|
14456
|
+
}
|
|
14457
|
+
//mode:"add_extra"
|
|
14458
|
+
};
|
|
14459
|
+
var DBConfigSchema = {
|
|
14460
|
+
type: "object",
|
|
14461
|
+
properties: {
|
|
14462
|
+
url: "string?",
|
|
14463
|
+
disabled: "boolean?",
|
|
14464
|
+
storage: "string?",
|
|
14465
|
+
dialect: "string?",
|
|
14466
|
+
name: "string"
|
|
14467
|
+
}
|
|
14468
|
+
//mode:"add_extra"
|
|
14469
|
+
};
|
|
14470
|
+
var ServerConfigSchema = {
|
|
14471
|
+
type: "object",
|
|
14472
|
+
properties: {
|
|
14473
|
+
preload: "function?",
|
|
14474
|
+
unload: "function?",
|
|
14475
|
+
stop: "function?",
|
|
14476
|
+
start: "function?",
|
|
14477
|
+
load: "function?"
|
|
14478
|
+
}
|
|
14479
|
+
//mode:"add_extra"
|
|
14480
|
+
};
|
|
14481
|
+
var LogConfigSchema = {
|
|
14482
|
+
type: "object",
|
|
14483
|
+
properties: {
|
|
11852
14484
|
level: {
|
|
11853
14485
|
type: "enum?",
|
|
11854
14486
|
enumValues: ["error", "warn", "info", "debug", "trace", "none"]
|
|
@@ -12029,7 +14661,7 @@ async function importJSXFile(inFile, logger) {
|
|
|
12029
14661
|
useExport: true,
|
|
12030
14662
|
logger
|
|
12031
14663
|
});
|
|
12032
|
-
const tmpBuildDir = (0, import_node_path5.resolve)(JSX_TMP_DIR, String(process.pid), "import", Date.now() + "-" + (0,
|
|
14664
|
+
const tmpBuildDir = (0, import_node_path5.resolve)(JSX_TMP_DIR, String(process.pid), "import", Date.now() + "-" + (0, import_node_crypto4.randomUUID)());
|
|
12033
14665
|
const inFileTmp = (0, import_node_path5.resolve)(tmpBuildDir, (0, import_node_path5.basename)(inFile) + ".mjs");
|
|
12034
14666
|
(0, import_node_fs6.mkdirSync)(tmpBuildDir, {
|
|
12035
14667
|
recursive: true
|
|
@@ -12394,6 +15026,7 @@ function createStaticRoute(service, logger, router, dir, file, inflateDir, route
|
|
|
12394
15026
|
path: normalizePath(path)
|
|
12395
15027
|
}],
|
|
12396
15028
|
service,
|
|
15029
|
+
filePath: file.filePath,
|
|
12397
15030
|
previewMethod: "html"
|
|
12398
15031
|
};
|
|
12399
15032
|
if (inflateDir) {
|
|
@@ -12473,6 +15106,7 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
|
|
|
12473
15106
|
routeFileMap[file.filePath] = {
|
|
12474
15107
|
routes,
|
|
12475
15108
|
service,
|
|
15109
|
+
filePath: file.filePath,
|
|
12476
15110
|
previewMethod: "api"
|
|
12477
15111
|
};
|
|
12478
15112
|
const inflatedCode = inflateDir ? await inflateJSX(file.filePath, {
|
|
@@ -12502,6 +15136,7 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
|
|
|
12502
15136
|
routeFileMap[file.filePath] = {
|
|
12503
15137
|
routes,
|
|
12504
15138
|
service,
|
|
15139
|
+
filePath: file.filePath,
|
|
12505
15140
|
previewMethod: "html"
|
|
12506
15141
|
};
|
|
12507
15142
|
for (const r of routes) {
|
|
@@ -12552,6 +15187,7 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
|
|
|
12552
15187
|
const routes = getRoutes((0, import_node_path12.join)("/", (0, import_node_path12.dirname)((0, import_node_path12.relative)(dir, file.filePath))), file.subName + ".html", module2.apiOptions);
|
|
12553
15188
|
routeFileMap[file.filePath] = {
|
|
12554
15189
|
routes,
|
|
15190
|
+
filePath: file.filePath,
|
|
12555
15191
|
service,
|
|
12556
15192
|
previewMethod: "html"
|
|
12557
15193
|
};
|
|
@@ -12617,6 +15253,7 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
|
|
|
12617
15253
|
method: "GET",
|
|
12618
15254
|
path
|
|
12619
15255
|
}],
|
|
15256
|
+
filePath: file.filePath,
|
|
12620
15257
|
service,
|
|
12621
15258
|
previewMethod: "html"
|
|
12622
15259
|
};
|
|
@@ -12666,6 +15303,7 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
|
|
|
12666
15303
|
path
|
|
12667
15304
|
}],
|
|
12668
15305
|
service,
|
|
15306
|
+
filePath: file.filePath,
|
|
12669
15307
|
previewMethod: "html"
|
|
12670
15308
|
};
|
|
12671
15309
|
if (inflateDir) {
|
|
@@ -12723,6 +15361,7 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
|
|
|
12723
15361
|
method: "GET",
|
|
12724
15362
|
path
|
|
12725
15363
|
}],
|
|
15364
|
+
filePath: file.filePath,
|
|
12726
15365
|
service,
|
|
12727
15366
|
previewMethod: "html"
|
|
12728
15367
|
};
|
|
@@ -12774,6 +15413,7 @@ async function createRouterFromDirectory(server2, hotreload, service, logger, di
|
|
|
12774
15413
|
path
|
|
12775
15414
|
}],
|
|
12776
15415
|
service,
|
|
15416
|
+
filePath: file.filePath,
|
|
12777
15417
|
previewMethod: "html"
|
|
12778
15418
|
};
|
|
12779
15419
|
if (inflateDir) {
|
|
@@ -12950,22 +15590,22 @@ async function inflateAppForSea(logger, inflateDir, services) {
|
|
|
12950
15590
|
writeFile(
|
|
12951
15591
|
logger,
|
|
12952
15592
|
(0, import_node_path14.join)(inflateDir, "sea", "app.cjs"),
|
|
12953
|
-
`const {
|
|
15593
|
+
`const { createServerInterface, ServerRequestHandler, WebSocketManager, initGlobals, DBManager, App, LoggerHandler, LogProvider, LocalCache, ClusterCache } = require("./lib.cjs");
|
|
12954
15594
|
|
|
12955
15595
|
async function main() {
|
|
12956
15596
|
const PORT = process.env["PORT"] ? process.env["PORT"] : 8080;
|
|
12957
|
-
const
|
|
15597
|
+
const loggerProvider = new LogProvider();
|
|
12958
15598
|
const localCache = new LocalCache();
|
|
12959
15599
|
const cache = new ClusterCache();
|
|
12960
15600
|
const webSocketManager = new WebSocketManager();
|
|
12961
15601
|
const dbManager = new DBManager();
|
|
12962
15602
|
await initGlobals();
|
|
12963
|
-
const serverInterface =
|
|
15603
|
+
const serverInterface = createServerInterface({
|
|
12964
15604
|
cache,
|
|
12965
15605
|
localCache,
|
|
12966
|
-
|
|
15606
|
+
loggerProvider,
|
|
12967
15607
|
wsManager: webSocketManager,
|
|
12968
|
-
logger:
|
|
15608
|
+
logger: loggerProvider.getLogger("server"),
|
|
12969
15609
|
dbManager,
|
|
12970
15610
|
port: PORT
|
|
12971
15611
|
});
|
|
@@ -13019,9 +15659,10 @@ ${getMiddlewareConfigPath(servicePath) ? `
|
|
|
13019
15659
|
}
|
|
13020
15660
|
}` : ""}
|
|
13021
15661
|
${Object.keys(serviceRouteFileMap).map((filePath) => serviceRouteFileMap[filePath]).filter((data) => data.previewMethod === "api").map((data) => data.routes.map((r) => {
|
|
13022
|
-
const rPath =
|
|
15662
|
+
const rPath = (0, import_node_path14.join)((0, import_node_path14.relative)((0, import_node_process10.cwd)(), (0, import_node_path14.dirname)(data.filePath)), (0, import_node_path14.basename)(data.filePath));
|
|
13023
15663
|
if (rPath) {
|
|
13024
|
-
const
|
|
15664
|
+
const rPathExt = (0, import_node_path14.extname)(rPath);
|
|
15665
|
+
const apiInflatedPath = (0, import_node_path14.join)("..", "..", rPath.substring(0, rPath.length - rPathExt.length) + ".js");
|
|
13025
15666
|
return ` await appendAPIModule(router, "../../${service}/http", "./${apiInflatedPath}", (await import("./${apiInflatedPath}")).default);`;
|
|
13026
15667
|
} else {
|
|
13027
15668
|
return "";
|
|
@@ -13526,15 +16167,15 @@ var ws_default = {
|
|
|
13526
16167
|
path: LOG_SOCKET_PATH,
|
|
13527
16168
|
validate(req) {
|
|
13528
16169
|
const admin = req.editor;
|
|
13529
|
-
const
|
|
13530
|
-
const KEY =
|
|
16170
|
+
const cache2 = admin ? admin.getCache() : req.server.cache;
|
|
16171
|
+
const KEY = cache2.get("AUTH_KEY");
|
|
13531
16172
|
const cookieToken = req.cookies["auth"];
|
|
13532
16173
|
return cookieToken === KEY ? true : false;
|
|
13533
16174
|
}
|
|
13534
16175
|
};
|
|
13535
16176
|
|
|
13536
16177
|
// editor/server.ts
|
|
13537
|
-
var
|
|
16178
|
+
var import_node_crypto5 = require("node:crypto");
|
|
13538
16179
|
init_constants();
|
|
13539
16180
|
var import_node_fs17 = require("node:fs");
|
|
13540
16181
|
var import_node_path18 = require("node:path");
|
|
@@ -13585,28 +16226,28 @@ var ADMIN_EDITOR_BROWSER_OPEN_KEY = "ADMIN_EDITOR_BROWSER_OPEN_KEY$$";
|
|
|
13585
16226
|
var server_default = {
|
|
13586
16227
|
preload: (serverInterface, adminInterface) => {
|
|
13587
16228
|
if (serverInterface?.isPrimaryWorker()) {
|
|
13588
|
-
const
|
|
13589
|
-
if (!
|
|
16229
|
+
const cache2 = adminInterface ? adminInterface.getCache() : serverInterface.cache;
|
|
16230
|
+
if (!cache2.has(ADMIN_EDITOR_AUTH_KEY)) {
|
|
13590
16231
|
const adminKEYPath = (0, import_node_path18.resolve)(".admin_key");
|
|
13591
16232
|
if ((0, import_node_fs17.existsSync)(adminKEYPath)) {
|
|
13592
16233
|
serverInterface.logger.warn("loading static ADMIN_KEY from [%s]", (0, import_node_path18.relative)(process.cwd(), adminKEYPath));
|
|
13593
|
-
|
|
16234
|
+
cache2.set(ADMIN_EDITOR_AUTH_KEY, (0, import_node_fs17.readFileSync)(adminKEYPath).toString().trim());
|
|
13594
16235
|
} else {
|
|
13595
|
-
|
|
16236
|
+
cache2.set(ADMIN_EDITOR_AUTH_KEY, (0, import_node_crypto5.randomUUID)());
|
|
13596
16237
|
}
|
|
13597
16238
|
}
|
|
13598
16239
|
}
|
|
13599
16240
|
},
|
|
13600
16241
|
start: (serverInterface, adminInterface) => {
|
|
13601
|
-
const
|
|
13602
|
-
if (!
|
|
13603
|
-
const KEY =
|
|
16242
|
+
const cache2 = adminInterface ? adminInterface.getCache() : serverInterface.cache;
|
|
16243
|
+
if (!cache2.has(ADMIN_EDITOR_BROWSER_OPEN_KEY)) {
|
|
16244
|
+
const KEY = cache2.get(ADMIN_EDITOR_AUTH_KEY);
|
|
13604
16245
|
const adminPath = `${BASEEDITOR_PATH}?${ADMIN_EDITOR_AUTH_QUERY}=${KEY}`;
|
|
13605
16246
|
if (serverInterface?.isPrimaryWorker()) {
|
|
13606
16247
|
serverInterface.logger.log("\n\n ADMIN_EDITOR\n\n %s\n\n", adminPath);
|
|
13607
16248
|
}
|
|
13608
16249
|
if (serverInterface.isPrimaryWorker()) {
|
|
13609
|
-
|
|
16250
|
+
cache2.set(ADMIN_EDITOR_BROWSER_OPEN_KEY, true);
|
|
13610
16251
|
try {
|
|
13611
16252
|
serverInterface.openBrowser(`${BASEEDITOR_PATH}?${ADMIN_EDITOR_AUTH_QUERY}=${KEY}`);
|
|
13612
16253
|
} catch (e) {
|
|
@@ -13917,47 +16558,21 @@ async function inflateDBMigrations(logger, service, dbName, inflateDir, errors)
|
|
|
13917
16558
|
}
|
|
13918
16559
|
|
|
13919
16560
|
// src/services/utils/server-interface.ts
|
|
13920
|
-
var import_node_cluster2 = __toESM(require("node:cluster"), 1);
|
|
13921
16561
|
var import_node_child_process2 = require("node:child_process");
|
|
13922
|
-
|
|
13923
|
-
|
|
13924
|
-
|
|
13925
|
-
|
|
13926
|
-
|
|
13927
|
-
|
|
13928
|
-
|
|
13929
|
-
|
|
13930
|
-
|
|
13931
|
-
constructor(options) {
|
|
13932
|
-
this.cache = options.cache;
|
|
13933
|
-
this.localCache = options.localCache;
|
|
13934
|
-
this.logger = options.logger ? options.logger : options.loggerProvider ? options.loggerProvider.getLogger("server") : void 0;
|
|
13935
|
-
this.port = options.port;
|
|
13936
|
-
const dbManager = options.dbManager;
|
|
13937
|
-
const wsManager = options.wsManager;
|
|
13938
|
-
this.loggerProvider = options.loggerProvider;
|
|
13939
|
-
const app = options.app;
|
|
13940
|
-
this.openBrowser = (path) => {
|
|
13941
|
-
const PORT2 = this.port;
|
|
13942
|
-
const URL2 = `http://localhost${PORT2 ? `:${PORT2}` : ""}${path}`;
|
|
13943
|
-
const DEFAULT_OPEN = process.platform === "win32" ? "explorer" : process.platform === "darwin" ? "open" : "xdg-open";
|
|
13944
|
-
const OPEN = app.options.browser !== void 0 && String(app.options.browser).toUpperCase() !== "TRUE" && String(app.options.browser).toUpperCase() !== "1" ? String(app.options.browser).toUpperCase() !== "0" && String(app.options.browser).toUpperCase() !== "FALSE" && String(app.options.browser).toUpperCase() !== "NONE" && app.options.browser ? app.options.browser : false : process.env["BROWSER"] ? process.env["BROWSER"] === "none" ? false : process.env["BROWSER"] : DEFAULT_OPEN;
|
|
13945
|
-
if (OPEN) {
|
|
13946
|
-
const openCMD = `${OPEN} "${URL2}"`;
|
|
13947
|
-
this.logger?.info("opening browser with [%s]", openCMD);
|
|
13948
|
-
(0, import_node_child_process2.execSync)(openCMD);
|
|
13949
|
-
} else {
|
|
13950
|
-
this.logger?.warn("ignoring browser [%s]", OPEN);
|
|
13951
|
-
}
|
|
13952
|
-
};
|
|
13953
|
-
this.db = Object.freeze({
|
|
13954
|
-
get: (name) => {
|
|
13955
|
-
return dbManager.getDB(name);
|
|
16562
|
+
function createServerInterface(options) {
|
|
16563
|
+
initGlobals();
|
|
16564
|
+
return Object.freeze({
|
|
16565
|
+
cache: options.cache,
|
|
16566
|
+
localCache: options.localCache,
|
|
16567
|
+
logger: options.logger,
|
|
16568
|
+
db: {
|
|
16569
|
+
get(name) {
|
|
16570
|
+
return options.dbManager.getDB(name);
|
|
13956
16571
|
},
|
|
13957
|
-
getMigrations
|
|
13958
|
-
if (app?.inflated) {
|
|
16572
|
+
getMigrations() {
|
|
16573
|
+
if (options.app?.inflated) {
|
|
13959
16574
|
const ret = [];
|
|
13960
|
-
for (const d of app?.inflated.dbList) {
|
|
16575
|
+
for (const d of options.app?.inflated.dbList) {
|
|
13961
16576
|
ret.push(...d.migrations.map((m) => {
|
|
13962
16577
|
return {
|
|
13963
16578
|
name: m.name,
|
|
@@ -13970,32 +16585,37 @@ var ServerInterfaceImpl = class {
|
|
|
13970
16585
|
}
|
|
13971
16586
|
return [];
|
|
13972
16587
|
},
|
|
13973
|
-
migrate
|
|
13974
|
-
return app?.migrate(
|
|
16588
|
+
migrate(migrateOptions) {
|
|
16589
|
+
return options?.app?.migrate(migrateOptions);
|
|
13975
16590
|
}
|
|
13976
|
-
}
|
|
13977
|
-
|
|
16591
|
+
},
|
|
16592
|
+
ws: {
|
|
13978
16593
|
get: (name) => {
|
|
13979
|
-
return
|
|
16594
|
+
return options?.webSocketManager?.getWS(name);
|
|
13980
16595
|
},
|
|
13981
16596
|
disconnectAll: (path) => {
|
|
13982
|
-
return
|
|
16597
|
+
return options?.webSocketManager?.disconnectAllButLOGSocket();
|
|
13983
16598
|
}
|
|
13984
|
-
}
|
|
13985
|
-
|
|
13986
|
-
|
|
13987
|
-
|
|
13988
|
-
|
|
13989
|
-
|
|
13990
|
-
|
|
13991
|
-
|
|
13992
|
-
|
|
13993
|
-
|
|
13994
|
-
|
|
13995
|
-
|
|
13996
|
-
|
|
13997
|
-
|
|
13998
|
-
|
|
16599
|
+
},
|
|
16600
|
+
openBrowser(path) {
|
|
16601
|
+
const PORT2 = options.port;
|
|
16602
|
+
const URL2 = `http://localhost${PORT2 ? `:${PORT2}` : ""}${path}`;
|
|
16603
|
+
const DEFAULT_OPEN = process.platform === "win32" ? "explorer" : process.platform === "darwin" ? "open" : "xdg-open";
|
|
16604
|
+
const OPEN = options?.app?.options.browser !== void 0 && String(options?.app?.options.browser).toUpperCase() !== "TRUE" && String(options?.app?.options.browser).toUpperCase() !== "1" ? String(options?.app.options.browser).toUpperCase() !== "0" && String(options?.app?.options.browser).toUpperCase() !== "FALSE" && String(options?.app?.options.browser).toUpperCase() !== "NONE" && options?.app?.options.browser ? options?.app.options.browser : false : process.env["BROWSER"] ? process.env["BROWSER"] === "none" ? false : process.env["BROWSER"] : DEFAULT_OPEN;
|
|
16605
|
+
if (OPEN) {
|
|
16606
|
+
const openCMD = `${OPEN} "${URL2}"`;
|
|
16607
|
+
options?.logger?.info("opening browser with [%s]", openCMD);
|
|
16608
|
+
(0, import_node_child_process2.execSync)(openCMD);
|
|
16609
|
+
} else {
|
|
16610
|
+
options?.logger?.warn("ignoring browser [%s]", OPEN);
|
|
16611
|
+
}
|
|
16612
|
+
},
|
|
16613
|
+
getLogger(identifier, loggerOptions) {
|
|
16614
|
+
return options?.loggerProvider?.getLogger(identifier, loggerOptions);
|
|
16615
|
+
},
|
|
16616
|
+
...server
|
|
16617
|
+
});
|
|
16618
|
+
}
|
|
13999
16619
|
|
|
14000
16620
|
// src/common/arguments.ts
|
|
14001
16621
|
var import_node_fs26 = require("node:fs");
|
|
@@ -14202,6 +16822,7 @@ var Miqro = class _Miqro {
|
|
|
14202
16822
|
this.localCache = new LocalCache(`MiqroApplicationLocalCache[${this.options.name}]`, this.logger);
|
|
14203
16823
|
this.webSocketManager = new WebSocketManager({
|
|
14204
16824
|
logger: this.logger,
|
|
16825
|
+
loggerProvider: this.loggerProvider,
|
|
14205
16826
|
name: `MiqroApplicationWebsocketManager[${this.options.name}]`,
|
|
14206
16827
|
avoidLogSocket: this.options.editor
|
|
14207
16828
|
});
|
|
@@ -14210,11 +16831,11 @@ var Miqro = class _Miqro {
|
|
|
14210
16831
|
loggerProvider: this.loggerProvider,
|
|
14211
16832
|
logger: this.logger
|
|
14212
16833
|
});
|
|
14213
|
-
this.serverInterface =
|
|
16834
|
+
this.serverInterface = createServerInterface({
|
|
14214
16835
|
cache: this.cache,
|
|
14215
|
-
localCache: this.localCache,
|
|
14216
16836
|
dbManager: this.dbManager,
|
|
14217
|
-
|
|
16837
|
+
localCache: this.localCache,
|
|
16838
|
+
webSocketManager: this.webSocketManager,
|
|
14218
16839
|
app: this,
|
|
14219
16840
|
logger: this.logger,
|
|
14220
16841
|
loggerProvider: this.loggerProvider,
|
|
@@ -14652,11 +17273,11 @@ async function appendAPIModule(router, dir, filePath, module2) {
|
|
|
14652
17273
|
LoggerHandler,
|
|
14653
17274
|
Miqro,
|
|
14654
17275
|
Router,
|
|
14655
|
-
ServerInterfaceImpl,
|
|
14656
17276
|
ServerRequestHandler,
|
|
14657
17277
|
WebSocketManager,
|
|
14658
17278
|
appendAPIModule,
|
|
14659
17279
|
assertGlobalTampered,
|
|
17280
|
+
createServerInterface,
|
|
14660
17281
|
initGlobals,
|
|
14661
17282
|
migration
|
|
14662
17283
|
});
|