@introspection-ai/recipes 0.25.1 → 0.27.1
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/dist/api/mcp.d.ts +3 -3
- package/dist/api/mcp.d.ts.map +1 -1
- package/dist/api/mcp.js +1 -1
- package/dist/api/mcp.js.map +1 -1
- package/dist/{child-agent-completions.d.ts → child/agent-completions.d.ts} +2 -2
- package/dist/child/agent-completions.d.ts.map +1 -0
- package/dist/{child-agent-completions.js → child/agent-completions.js} +1 -1
- package/dist/child/agent-completions.js.map +1 -0
- package/dist/{child-agent-store.d.ts → child/agent-store.d.ts} +1 -1
- package/dist/child/agent-store.d.ts.map +1 -0
- package/dist/{child-agent-store.js → child/agent-store.js} +1 -1
- package/dist/child/agent-store.js.map +1 -0
- package/dist/{child-agent.d.ts → child/agent.d.ts} +2 -2
- package/dist/child/agent.d.ts.map +1 -0
- package/dist/{child-agent.js → child/agent.js} +5 -5
- package/dist/child/agent.js.map +1 -0
- package/dist/{child-session.d.ts → child/session.d.ts} +4 -4
- package/dist/child/session.d.ts.map +1 -0
- package/dist/{child-session.js → child/session.js} +2 -2
- package/dist/child/session.js.map +1 -0
- package/dist/connector-tools.d.ts +1 -1
- package/dist/connector-tools.js +2 -2
- package/dist/inspect.d.ts +1 -1
- package/dist/inspect.js +1 -1
- package/dist/{mcp-catalog.d.ts → mcp/catalog.d.ts} +3 -3
- package/dist/mcp/catalog.d.ts.map +1 -0
- package/dist/{mcp-catalog.js → mcp/catalog.js} +2 -2
- package/dist/mcp/catalog.js.map +1 -0
- package/dist/{mcp-command-context.d.ts → mcp/cli/command-context.d.ts} +1 -1
- package/dist/mcp/cli/command-context.d.ts.map +1 -0
- package/dist/{mcp-command-context.js → mcp/cli/command-context.js} +1 -1
- package/dist/mcp/cli/command-context.js.map +1 -0
- package/dist/{mcp-cli-core.d.ts → mcp/cli/core.d.ts} +14 -8
- package/dist/mcp/cli/core.d.ts.map +1 -0
- package/dist/{mcp-cli-core.js → mcp/cli/core.js} +105 -146
- package/dist/mcp/cli/core.js.map +1 -0
- package/dist/mcp/cli/help.d.ts +6 -0
- package/dist/mcp/cli/help.d.ts.map +1 -0
- package/dist/mcp/cli/help.js +116 -0
- package/dist/mcp/cli/help.js.map +1 -0
- package/dist/mcp/cli/index.d.ts +3 -0
- package/dist/mcp/cli/index.d.ts.map +1 -0
- package/dist/{mcp-cli.js → mcp/cli/index.js} +4 -4
- package/dist/mcp/cli/index.js.map +1 -0
- package/dist/{mcp-cli-policy.d.ts → mcp/cli/policy.d.ts} +2 -2
- package/dist/mcp/cli/policy.d.ts.map +1 -0
- package/dist/{mcp-cli-policy.js → mcp/cli/policy.js} +2 -2
- package/dist/mcp/cli/policy.js.map +1 -0
- package/dist/mcp/cli/run-worker.d.ts +2 -0
- package/dist/mcp/cli/run-worker.d.ts.map +1 -0
- package/dist/mcp/cli/run-worker.js +54 -0
- package/dist/mcp/cli/run-worker.js.map +1 -0
- package/dist/mcp/client-entry.d.ts +3 -0
- package/dist/mcp/client-entry.d.ts.map +1 -0
- package/dist/{mcp-client.js → mcp/client-entry.js} +3 -3
- package/dist/mcp/client-entry.js.map +1 -0
- package/dist/{mcp-contract.d.ts → mcp/contract.d.ts} +2 -2
- package/dist/mcp/contract.d.ts.map +1 -0
- package/dist/{mcp-contract.js → mcp/contract.js} +1 -1
- package/dist/mcp/contract.js.map +1 -0
- package/dist/{mcp-daemon-client.d.ts → mcp/daemon/client.d.ts} +3 -2
- package/dist/mcp/daemon/client.d.ts.map +1 -0
- package/dist/{mcp-daemon-client.js → mcp/daemon/client.js} +12 -8
- package/dist/mcp/daemon/client.js.map +1 -0
- package/dist/mcp/daemon/index.d.ts +3 -0
- package/dist/mcp/daemon/index.d.ts.map +1 -0
- package/dist/mcp/daemon/index.js +453 -0
- package/dist/{mcp-daemon.js.map → mcp/daemon/index.js.map} +1 -1
- package/dist/{mcp-daemon-protocol.d.ts → mcp/daemon/protocol.d.ts} +2 -2
- package/dist/mcp/daemon/protocol.d.ts.map +1 -0
- package/dist/{mcp-daemon-protocol.js → mcp/daemon/protocol.js} +1 -1
- package/dist/mcp/daemon/protocol.js.map +1 -0
- package/dist/{mcp.d.ts → mcp/index.d.ts} +5 -5
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/{mcp.js → mcp/index.js} +16 -10
- package/dist/mcp/index.js.map +1 -0
- package/dist/{mcp-policy.d.ts → mcp/policy.d.ts} +3 -3
- package/dist/mcp/policy.d.ts.map +1 -0
- package/dist/{mcp-policy.js → mcp/policy.js} +1 -1
- package/dist/mcp/policy.js.map +1 -0
- package/dist/{mcp-tools.d.ts → mcp/tools.d.ts} +4 -4
- package/dist/mcp/tools.d.ts.map +1 -0
- package/dist/{mcp-tools.js → mcp/tools.js} +4 -4
- package/dist/mcp/tools.js.map +1 -0
- package/dist/{mcp-trace-context.d.ts → mcp/trace-context.d.ts} +2 -2
- package/dist/mcp/trace-context.d.ts.map +1 -0
- package/dist/{mcp-trace-context.js → mcp/trace-context.js} +1 -1
- package/dist/mcp/trace-context.js.map +1 -0
- package/dist/mcp-chunks/{auth-command-4WFRNU2I.js → auth-command-GQFV6QYP.js} +24 -27
- package/dist/mcp-chunks/call-arguments-VT7JLNJY.js +16 -0
- package/dist/mcp-chunks/{call-command-JBIKXOGC.js → call-command-LMAREWKD.js} +45 -45
- package/dist/mcp-chunks/{chunk-3JGS7LQB.js → chunk-2HOMVWSA.js} +2 -2
- package/dist/mcp-chunks/{chunk-G6OMDUNG.js → chunk-2P2HVZ3G.js} +1 -1
- package/dist/mcp-chunks/{chunk-ED2WN5BI.js → chunk-34QXE62Y.js} +175 -147
- package/dist/mcp-chunks/{chunk-Y3EDWN2P.js → chunk-5B7GRMUK.js} +1 -1
- package/dist/mcp-chunks/chunk-5BMCVE2J.js +516 -0
- package/dist/mcp-chunks/{chunk-V5AYEKSL.js → chunk-6QZQZXDJ.js} +52 -81
- package/dist/mcp-chunks/{chunk-3R2WK3NB.js → chunk-6RG6AD5X.js} +6 -6
- package/dist/mcp-chunks/{chunk-SNKXMWDB.js → chunk-77BZYP72.js} +1 -1
- package/dist/mcp-chunks/chunk-7PFJCLXL.js +123 -0
- package/dist/mcp-chunks/chunk-7WL4TMON.js +31 -0
- package/dist/mcp-chunks/{chunk-ELA77TDC.js → chunk-C2VLY7ED.js} +4 -4
- package/dist/mcp-chunks/{chunk-FAJPJTOC.js → chunk-CLR6DJV3.js} +1 -1
- package/dist/mcp-chunks/{chunk-ZOAQDFAO.js → chunk-D6B2M5V7.js} +1 -1
- package/dist/mcp-chunks/{chunk-WTMJMM3B.js → chunk-D6SVCPN6.js} +3 -30
- package/dist/mcp-chunks/chunk-FBVRU4Y3.js +1195 -0
- package/dist/mcp-chunks/{chunk-EMSNQHZZ.js → chunk-FONFU4G5.js} +1 -1
- package/dist/mcp-chunks/{chunk-BWW4XRUC.js → chunk-H4KL74PV.js} +303 -161
- package/dist/mcp-chunks/{chunk-ITR7FQM3.js → chunk-H7ARMBV7.js} +4 -9
- package/dist/mcp-chunks/{chunk-EPT4MYOF.js → chunk-HZ2SX5U6.js} +39 -34
- package/dist/mcp-chunks/{chunk-36VIJRYY.js → chunk-I6UMKX5E.js} +4 -4
- package/dist/mcp-chunks/{chunk-ASG4OY3M.js → chunk-IF6LRV3J.js} +21 -28
- package/dist/mcp-chunks/{chunk-KW3ANJ36.js → chunk-JVYCENPP.js} +4 -4
- package/dist/mcp-chunks/{chunk-AIKLVBYU.js → chunk-KOWNVUL2.js} +34 -7
- package/dist/mcp-chunks/{chunk-B2LNXGAP.js → chunk-KQCLM7R7.js} +4 -4
- package/dist/mcp-chunks/{chunk-OP3IW2V6.js → chunk-L6OOGZVA.js} +2 -2
- package/dist/mcp-chunks/{chunk-MOEZ43ZL.js → chunk-LCBDVFVA.js} +1 -1
- package/dist/mcp-chunks/{chunk-ITCCROID.js → chunk-LIEFPSSB.js} +5 -5
- package/dist/mcp-chunks/{chunk-GUXMP7QB.js → chunk-LQIE4PKL.js} +2 -2
- package/dist/mcp-chunks/{chunk-WYLHHXI6.js → chunk-LXHPDKEF.js} +26 -11
- package/dist/mcp-chunks/{chunk-6YZW3XAE.js → chunk-MJFZM5EV.js} +5 -5
- package/dist/mcp-chunks/{chunk-TPHPAEDH.js → chunk-NQW3ES2G.js} +2 -8
- package/dist/mcp-chunks/{chunk-IPNSPKQK.js → chunk-O2VOMKAS.js} +15 -17
- package/dist/mcp-chunks/{chunk-QZUC2T72.js → chunk-O4JIUOWF.js} +2 -2
- package/dist/mcp-chunks/{chunk-C2KNLFZR.js → chunk-P3UVILEW.js} +2 -2
- package/dist/mcp-chunks/{chunk-7WOKCV6Q.js → chunk-P463YBJM.js} +1 -1
- package/dist/mcp-chunks/{chunk-GQ6NSIDS.js → chunk-PJCMJ65D.js} +1175 -718
- package/dist/mcp-chunks/{chunk-CZKDJZER.js → chunk-QALB3DRW.js} +1 -1
- package/dist/mcp-chunks/{chunk-JG4TRUPF.js → chunk-QJNF3A3F.js} +1 -1
- package/dist/mcp-chunks/{chunk-HLRCUHNO.js → chunk-RIHPVCGI.js} +1 -1
- package/dist/mcp-chunks/{chunk-RD7NHCRK.js → chunk-RZIJUJGL.js} +60 -1074
- package/dist/mcp-chunks/{chunk-4ZNBWL65.js → chunk-S2YF442K.js} +2 -2
- package/dist/mcp-chunks/chunk-S5F3HEZZ.js +37060 -0
- package/dist/mcp-chunks/{chunk-TF2YTYE4.js → chunk-S6GJ42I2.js} +1 -1
- package/dist/mcp-chunks/chunk-T4MQCFIK.js +982 -0
- package/dist/mcp-chunks/{chunk-SCOMDV54.js → chunk-TUQGOYK6.js} +1 -1
- package/dist/mcp-chunks/{chunk-YIRGLKDA.js → chunk-TYYSBILI.js} +46 -27
- package/dist/mcp-chunks/{chunk-FS5JIKT6.js → chunk-UHO6KIUJ.js} +6 -6
- package/dist/mcp-chunks/{chunk-RSTKSBVF.js → chunk-UIPG6W7N.js} +2 -2
- package/dist/mcp-chunks/{chunk-IME7DGLJ.js → chunk-UKM35J67.js} +2 -2
- package/dist/mcp-chunks/{chunk-FX5NYWBH.js → chunk-UYJZJXC2.js} +3 -3
- package/dist/mcp-chunks/{chunk-HCOKLSOB.js → chunk-VJIAHZZG.js} +4 -4
- package/dist/mcp-chunks/{chunk-IYWYVHHD.js → chunk-WHJUDBPR.js} +1 -1
- package/dist/mcp-chunks/{chunk-53NRFMB3.js → chunk-XNHGMWN2.js} +46 -25
- package/dist/mcp-chunks/{cli-XU26MUCN.js → cli-JI7MEAAX.js} +111 -79
- package/dist/mcp-chunks/client-QU7ABSNB.js +30 -0
- package/dist/mcp-chunks/{config-command-UQMMIK2U.js → config-command-GRZLKD3R.js} +36 -29
- package/dist/mcp-chunks/daemon-command-3266CYHO.js +30 -0
- package/dist/mcp-chunks/{dist-DM2RXZMU.js → dist-USMCQ22V.js} +105 -47
- package/dist/mcp-chunks/{emit-ts-command-KAOL6DAN.js → emit-ts-command-7VLESP7H.js} +20 -19
- package/dist/mcp-chunks/{generate-cli-runner-AK6XNRTK.js → generate-cli-runner-SSW2B72K.js} +54 -51
- package/dist/mcp-chunks/generated-daemon-runtime-7CFVWLC7.js +30 -0
- package/dist/mcp-chunks/{inspect-cli-command-6FVJO7H2.js → inspect-cli-command-NCGCMOIS.js} +9 -10
- package/dist/mcp-chunks/{launch-EIT73HX4.js → launch-NBONSPNK.js} +1 -1
- package/dist/mcp-chunks/{lifecycle-QH4TUI3K.js → lifecycle-CXAKUCN4.js} +1 -1
- package/dist/mcp-chunks/{list-command-UOB2XZK7.js → list-command-5T4UF4PF.js} +61 -75
- package/dist/mcp-chunks/{output-utils-6YXH23T7.js → output-utils-YFTWQZ5V.js} +3 -3
- package/dist/mcp-chunks/{prompt-CH6TK0bC-ZB6RFAXR.js → prompt-CH6TK0bC-6DI4RA4E.js} +1 -1
- package/dist/mcp-chunks/{record-command-FO5TTERC.js → record-command-TE5O7WBL.js} +5 -5
- package/dist/mcp-chunks/{replay-command-SCBPCGQ7.js → replay-command-QCUL5ASR.js} +6 -6
- package/dist/mcp-chunks/{resource-command-S2J7XEMV.js → resource-command-XMGF7EAK.js} +9 -10
- package/dist/mcp-chunks/{result-utils-OME6HGS6.js → result-utils-HKB42M7Y.js} +3 -4
- package/dist/mcp-chunks/runtime-3X2XVS6X.js +37 -0
- package/dist/mcp-chunks/runtime-wrapper-MI3HF45J.js +10 -0
- package/dist/mcp-chunks/{serve-command-DDBZZSG6.js → serve-command-5HV3ZE25.js} +30 -34
- package/dist/mcp-chunks/{timeouts-HNGNKDQN.js → timeouts-YBFBTLV2.js} +8 -5
- package/dist/mcp-chunks/{vault-command-TJZYS3YI.js → vault-command-FC2PD5U6.js} +4 -6
- package/dist/mcp-chunks/webapi-IFUPO72B.js +2481 -0
- package/dist/mcp-daemon.js +35 -33
- package/dist/mcp-run-worker.js +28 -32
- package/dist/pi-extension.d.ts +1 -1
- package/dist/pi-extension.js +8 -8
- package/dist/pi-extension.js.map +1 -1
- package/dist/{recipe-agent.d.ts → recipe/agent.d.ts} +3 -3
- package/dist/recipe/agent.d.ts.map +1 -0
- package/dist/{recipe-agent.js → recipe/agent.js} +5 -5
- package/dist/recipe/agent.js.map +1 -0
- package/dist/{recipe-extensions.d.ts → recipe/extensions.d.ts} +1 -1
- package/dist/recipe/extensions.d.ts.map +1 -0
- package/dist/{recipe-extensions.js → recipe/extensions.js} +1 -1
- package/dist/recipe/extensions.js.map +1 -0
- package/dist/{recipe-mcp-config.d.ts → recipe/mcp-config.d.ts} +2 -2
- package/dist/recipe/mcp-config.d.ts.map +1 -0
- package/dist/{recipe-mcp-config.js → recipe/mcp-config.js} +1 -1
- package/dist/recipe/mcp-config.js.map +1 -0
- package/dist/{recipe-model.d.ts → recipe/model.d.ts} +1 -1
- package/dist/recipe/model.d.ts.map +1 -0
- package/dist/{recipe-model.js → recipe/model.js} +1 -1
- package/dist/recipe/model.js.map +1 -0
- package/dist/{recipe-package.d.ts → recipe/package.d.ts} +1 -1
- package/dist/recipe/package.d.ts.map +1 -0
- package/dist/{recipe-package.js → recipe/package.js} +1 -1
- package/dist/recipe/package.js.map +1 -0
- package/dist/recipe/resolve.d.ts +6 -6
- package/dist/recipe/resolve.d.ts.map +1 -1
- package/dist/recipe/resolve.js +4 -4
- package/dist/recipe/resolve.js.map +1 -1
- package/dist/{recipe-session.d.ts → recipe/session.d.ts} +1 -1
- package/dist/recipe/session.d.ts.map +1 -0
- package/dist/{recipe-session.js → recipe/session.js} +1 -1
- package/dist/recipe/session.js.map +1 -0
- package/dist/{recipe-skills.d.ts → recipe/skills.d.ts} +1 -1
- package/dist/recipe/skills.d.ts.map +1 -0
- package/dist/{recipe-skills.js → recipe/skills.js} +2 -2
- package/dist/recipe/skills.js.map +1 -0
- package/dist/run-controller.js +2 -2
- package/dist/session.d.ts +1 -1
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js +5 -5
- package/dist/session.js.map +1 -1
- package/docs/channels.md +1 -1
- package/docs/pi-extension.md +1 -1
- package/docs/recipe-format.md +8 -4
- package/docs/recipe-templates.md +46 -0
- package/docs/slack.md +1 -1
- package/package.json +14 -14
- package/dist/child-agent-completions.d.ts.map +0 -1
- package/dist/child-agent-completions.js.map +0 -1
- package/dist/child-agent-store.d.ts.map +0 -1
- package/dist/child-agent-store.js.map +0 -1
- package/dist/child-agent.d.ts.map +0 -1
- package/dist/child-agent.js.map +0 -1
- package/dist/child-session.d.ts.map +0 -1
- package/dist/child-session.js.map +0 -1
- package/dist/mcp-catalog.d.ts.map +0 -1
- package/dist/mcp-catalog.js.map +0 -1
- package/dist/mcp-chunks/call-arguments-4DWPBLQP.js +0 -15
- package/dist/mcp-chunks/chunk-3Z7MFS6K.js +0 -86
- package/dist/mcp-chunks/chunk-AD3FQ73K.js +0 -39
- package/dist/mcp-chunks/chunk-DTZHEVKC.js +0 -12
- package/dist/mcp-chunks/chunk-H3JCYHGS.js +0 -1018
- package/dist/mcp-chunks/chunk-HN7WPMCA.js +0 -18904
- package/dist/mcp-chunks/chunk-I5GI2A2D.js +0 -92
- package/dist/mcp-chunks/chunk-IRTJXFWA.js +0 -28
- package/dist/mcp-chunks/chunk-NTHUNCXJ.js +0 -526
- package/dist/mcp-chunks/chunk-OD3MSMXY.js +0 -15
- package/dist/mcp-chunks/chunk-PZ323CXI.js +0 -17394
- package/dist/mcp-chunks/client-OT34CKRH.js +0 -21
- package/dist/mcp-chunks/daemon-command-YCIOZGPZ.js +0 -35
- package/dist/mcp-chunks/runtime-QIPMLIJI.js +0 -39
- package/dist/mcp-chunks/runtime-wrapper-X4YFKMJI.js +0 -16
- package/dist/mcp-chunks/webapi-4GWO2UBA.js +0 -3508
- package/dist/mcp-cli-core.d.ts.map +0 -1
- package/dist/mcp-cli-core.js.map +0 -1
- package/dist/mcp-cli-help.d.ts +0 -2
- package/dist/mcp-cli-help.d.ts.map +0 -1
- package/dist/mcp-cli-help.js +0 -36
- package/dist/mcp-cli-help.js.map +0 -1
- package/dist/mcp-cli-policy.d.ts.map +0 -1
- package/dist/mcp-cli-policy.js.map +0 -1
- package/dist/mcp-cli.d.ts +0 -3
- package/dist/mcp-cli.d.ts.map +0 -1
- package/dist/mcp-cli.js.map +0 -1
- package/dist/mcp-client.d.ts +0 -3
- package/dist/mcp-client.d.ts.map +0 -1
- package/dist/mcp-client.js.map +0 -1
- package/dist/mcp-command-context.d.ts.map +0 -1
- package/dist/mcp-command-context.js.map +0 -1
- package/dist/mcp-contract.d.ts.map +0 -1
- package/dist/mcp-contract.js.map +0 -1
- package/dist/mcp-daemon-client.d.ts.map +0 -1
- package/dist/mcp-daemon-client.js.map +0 -1
- package/dist/mcp-daemon-protocol.d.ts.map +0 -1
- package/dist/mcp-daemon-protocol.js.map +0 -1
- package/dist/mcp-daemon.d.ts +0 -3
- package/dist/mcp-daemon.d.ts.map +0 -1
- package/dist/mcp-policy.d.ts.map +0 -1
- package/dist/mcp-policy.js.map +0 -1
- package/dist/mcp-run-worker.d.ts +0 -2
- package/dist/mcp-run-worker.d.ts.map +0 -1
- package/dist/mcp-run-worker.js.map +0 -1
- package/dist/mcp-tools.d.ts.map +0 -1
- package/dist/mcp-tools.js.map +0 -1
- package/dist/mcp-trace-context.d.ts.map +0 -1
- package/dist/mcp-trace-context.js.map +0 -1
- package/dist/mcp.d.ts.map +0 -1
- package/dist/mcp.js.map +0 -1
- package/dist/recipe-agent.d.ts.map +0 -1
- package/dist/recipe-agent.js.map +0 -1
- package/dist/recipe-extensions.d.ts.map +0 -1
- package/dist/recipe-extensions.js.map +0 -1
- package/dist/recipe-mcp-config.d.ts.map +0 -1
- package/dist/recipe-mcp-config.js.map +0 -1
- package/dist/recipe-model.d.ts.map +0 -1
- package/dist/recipe-model.js.map +0 -1
- package/dist/recipe-package.d.ts.map +0 -1
- package/dist/recipe-package.js.map +0 -1
- package/dist/recipe-session.d.ts.map +0 -1
- package/dist/recipe-session.js.map +0 -1
- package/dist/recipe-skills.d.ts.map +0 -1
- package/dist/recipe-skills.js.map +0 -1
|
@@ -1,3508 +0,0 @@
|
|
|
1
|
-
import { createRequire as __createRequire } from "node:module"; const require = __createRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
__export
|
|
4
|
-
} from "./chunk-LRKZP7DJ.js";
|
|
5
|
-
|
|
6
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
7
|
-
var encoder = new TextEncoder();
|
|
8
|
-
var decoder = new TextDecoder();
|
|
9
|
-
var strictDecoder = new TextDecoder("utf-8", { fatal: true });
|
|
10
|
-
var MAX_INT32 = 2 ** 32;
|
|
11
|
-
function concat(...buffers) {
|
|
12
|
-
const size = buffers.reduce((acc, { length }) => acc + length, 0);
|
|
13
|
-
const buf = new Uint8Array(size);
|
|
14
|
-
let i = 0;
|
|
15
|
-
for (const buffer of buffers) {
|
|
16
|
-
buf.set(buffer, i);
|
|
17
|
-
i += buffer.length;
|
|
18
|
-
}
|
|
19
|
-
return buf;
|
|
20
|
-
}
|
|
21
|
-
function writeUInt32BE(buf, value, offset) {
|
|
22
|
-
if (value < 0 || value >= MAX_INT32) {
|
|
23
|
-
throw new RangeError(`value must be >= 0 and <= ${MAX_INT32 - 1}. Received ${value}`);
|
|
24
|
-
}
|
|
25
|
-
buf.set([value >>> 24, value >>> 16, value >>> 8, value & 255], offset);
|
|
26
|
-
}
|
|
27
|
-
function uint64be(value) {
|
|
28
|
-
const high = Math.floor(value / MAX_INT32);
|
|
29
|
-
const low = value % MAX_INT32;
|
|
30
|
-
const buf = new Uint8Array(8);
|
|
31
|
-
writeUInt32BE(buf, high, 0);
|
|
32
|
-
writeUInt32BE(buf, low, 4);
|
|
33
|
-
return buf;
|
|
34
|
-
}
|
|
35
|
-
function uint32be(value) {
|
|
36
|
-
const buf = new Uint8Array(4);
|
|
37
|
-
writeUInt32BE(buf, value);
|
|
38
|
-
return buf;
|
|
39
|
-
}
|
|
40
|
-
function encode(string) {
|
|
41
|
-
const bytes = new Uint8Array(string.length);
|
|
42
|
-
for (let i = 0; i < string.length; i++) {
|
|
43
|
-
const code = string.charCodeAt(i);
|
|
44
|
-
if (code > 127) {
|
|
45
|
-
throw new TypeError("non-ASCII string encountered in encode()");
|
|
46
|
-
}
|
|
47
|
-
bytes[i] = code;
|
|
48
|
-
}
|
|
49
|
-
return bytes;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/crypto_key.js
|
|
53
|
-
var unusable = (name, prop = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
54
|
-
function checkUsage(key, usage) {
|
|
55
|
-
if (usage && !key.usages.includes(usage)) {
|
|
56
|
-
throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function checkModulusLength(alg, key) {
|
|
60
|
-
const { modulusLength } = key.algorithm;
|
|
61
|
-
if (typeof modulusLength !== "number" || modulusLength < 2048) {
|
|
62
|
-
throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
function checkCryptoKey(key, expected, usage) {
|
|
66
|
-
const algorithm = key.algorithm;
|
|
67
|
-
if (algorithm.name !== expected.name) {
|
|
68
|
-
throw unusable(expected.name);
|
|
69
|
-
}
|
|
70
|
-
if (expected.hash && algorithm.hash?.name !== expected.hash) {
|
|
71
|
-
throw unusable(expected.hash, "algorithm.hash");
|
|
72
|
-
}
|
|
73
|
-
if (expected.namedCurve && algorithm.namedCurve !== expected.namedCurve) {
|
|
74
|
-
throw unusable(expected.namedCurve, "algorithm.namedCurve");
|
|
75
|
-
}
|
|
76
|
-
if (expected.length !== void 0 && algorithm.length !== expected.length) {
|
|
77
|
-
throw unusable(expected.length, "algorithm.length");
|
|
78
|
-
}
|
|
79
|
-
checkUsage(key, usage);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/invalid_key_input.js
|
|
83
|
-
function message(msg, actual, ...types) {
|
|
84
|
-
if (types.length > 2) {
|
|
85
|
-
const last = types.pop();
|
|
86
|
-
msg += `one of type ${types.join(", ")}, or ${last}.`;
|
|
87
|
-
} else if (types.length === 2) {
|
|
88
|
-
msg += `one of type ${types[0]} or ${types[1]}.`;
|
|
89
|
-
} else {
|
|
90
|
-
msg += `of type ${types[0]}.`;
|
|
91
|
-
}
|
|
92
|
-
if (actual == null) {
|
|
93
|
-
msg += ` Received ${actual}`;
|
|
94
|
-
} else if (typeof actual === "function" && actual.name) {
|
|
95
|
-
msg += ` Received function ${actual.name}`;
|
|
96
|
-
} else if (typeof actual === "object" && actual != null) {
|
|
97
|
-
if (actual.constructor?.name) {
|
|
98
|
-
msg += ` Received an instance of ${actual.constructor.name}`;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return msg;
|
|
102
|
-
}
|
|
103
|
-
var invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
|
|
104
|
-
var withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
105
|
-
|
|
106
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/util/errors.js
|
|
107
|
-
var errors_exports = {};
|
|
108
|
-
__export(errors_exports, {
|
|
109
|
-
JOSEAlgNotAllowed: () => JOSEAlgNotAllowed,
|
|
110
|
-
JOSEError: () => JOSEError,
|
|
111
|
-
JOSENotSupported: () => JOSENotSupported,
|
|
112
|
-
JWEDecryptionFailed: () => JWEDecryptionFailed,
|
|
113
|
-
JWEInvalid: () => JWEInvalid,
|
|
114
|
-
JWKInvalid: () => JWKInvalid,
|
|
115
|
-
JWKSInvalid: () => JWKSInvalid,
|
|
116
|
-
JWKSMultipleMatchingKeys: () => JWKSMultipleMatchingKeys,
|
|
117
|
-
JWKSNoMatchingKey: () => JWKSNoMatchingKey,
|
|
118
|
-
JWKSTimeout: () => JWKSTimeout,
|
|
119
|
-
JWSInvalid: () => JWSInvalid,
|
|
120
|
-
JWSSignatureVerificationFailed: () => JWSSignatureVerificationFailed,
|
|
121
|
-
JWTClaimValidationFailed: () => JWTClaimValidationFailed,
|
|
122
|
-
JWTExpired: () => JWTExpired,
|
|
123
|
-
JWTInvalid: () => JWTInvalid
|
|
124
|
-
});
|
|
125
|
-
var JOSEError = class extends Error {
|
|
126
|
-
static code = "ERR_JOSE_GENERIC";
|
|
127
|
-
code = "ERR_JOSE_GENERIC";
|
|
128
|
-
constructor(message2, options) {
|
|
129
|
-
super(message2, options);
|
|
130
|
-
this.name = this.constructor.name;
|
|
131
|
-
Error.captureStackTrace?.(this, this.constructor);
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
var JWTClaimValidationFailed = class extends JOSEError {
|
|
135
|
-
static code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
136
|
-
code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
137
|
-
claim;
|
|
138
|
-
reason;
|
|
139
|
-
payload;
|
|
140
|
-
constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
|
|
141
|
-
super(message2, { cause: { claim, reason, payload } });
|
|
142
|
-
this.claim = claim;
|
|
143
|
-
this.reason = reason;
|
|
144
|
-
this.payload = payload;
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
var JWTExpired = class extends JOSEError {
|
|
148
|
-
static code = "ERR_JWT_EXPIRED";
|
|
149
|
-
code = "ERR_JWT_EXPIRED";
|
|
150
|
-
claim;
|
|
151
|
-
reason;
|
|
152
|
-
payload;
|
|
153
|
-
constructor(message2, payload, claim = "unspecified", reason = "unspecified") {
|
|
154
|
-
super(message2, { cause: { claim, reason, payload } });
|
|
155
|
-
this.claim = claim;
|
|
156
|
-
this.reason = reason;
|
|
157
|
-
this.payload = payload;
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
var JOSEAlgNotAllowed = class extends JOSEError {
|
|
161
|
-
static code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
162
|
-
code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
163
|
-
};
|
|
164
|
-
var JOSENotSupported = class extends JOSEError {
|
|
165
|
-
static code = "ERR_JOSE_NOT_SUPPORTED";
|
|
166
|
-
code = "ERR_JOSE_NOT_SUPPORTED";
|
|
167
|
-
};
|
|
168
|
-
var JWEDecryptionFailed = class extends JOSEError {
|
|
169
|
-
static code = "ERR_JWE_DECRYPTION_FAILED";
|
|
170
|
-
code = "ERR_JWE_DECRYPTION_FAILED";
|
|
171
|
-
constructor(message2 = "decryption operation failed", options) {
|
|
172
|
-
super(message2, options);
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
var JWEInvalid = class extends JOSEError {
|
|
176
|
-
static code = "ERR_JWE_INVALID";
|
|
177
|
-
code = "ERR_JWE_INVALID";
|
|
178
|
-
};
|
|
179
|
-
var JWSInvalid = class extends JOSEError {
|
|
180
|
-
static code = "ERR_JWS_INVALID";
|
|
181
|
-
code = "ERR_JWS_INVALID";
|
|
182
|
-
};
|
|
183
|
-
var JWTInvalid = class extends JOSEError {
|
|
184
|
-
static code = "ERR_JWT_INVALID";
|
|
185
|
-
code = "ERR_JWT_INVALID";
|
|
186
|
-
};
|
|
187
|
-
var JWKInvalid = class extends JOSEError {
|
|
188
|
-
static code = "ERR_JWK_INVALID";
|
|
189
|
-
code = "ERR_JWK_INVALID";
|
|
190
|
-
};
|
|
191
|
-
var JWKSInvalid = class extends JOSEError {
|
|
192
|
-
static code = "ERR_JWKS_INVALID";
|
|
193
|
-
code = "ERR_JWKS_INVALID";
|
|
194
|
-
};
|
|
195
|
-
var JWKSNoMatchingKey = class extends JOSEError {
|
|
196
|
-
static code = "ERR_JWKS_NO_MATCHING_KEY";
|
|
197
|
-
code = "ERR_JWKS_NO_MATCHING_KEY";
|
|
198
|
-
constructor(message2 = "no applicable key found in the JSON Web Key Set", options) {
|
|
199
|
-
super(message2, options);
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
var JWKSMultipleMatchingKeys = class extends JOSEError {
|
|
203
|
-
[Symbol.asyncIterator] = async function* () {
|
|
204
|
-
};
|
|
205
|
-
static code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
|
|
206
|
-
code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
|
|
207
|
-
constructor(message2 = "multiple matching keys found in the JSON Web Key Set", options) {
|
|
208
|
-
super(message2, options);
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
var JWKSTimeout = class extends JOSEError {
|
|
212
|
-
static code = "ERR_JWKS_TIMEOUT";
|
|
213
|
-
code = "ERR_JWKS_TIMEOUT";
|
|
214
|
-
constructor(message2 = "request timed out", options) {
|
|
215
|
-
super(message2, options);
|
|
216
|
-
}
|
|
217
|
-
};
|
|
218
|
-
var JWSSignatureVerificationFailed = class extends JOSEError {
|
|
219
|
-
static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
220
|
-
code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
221
|
-
constructor(message2 = "signature verification failed", options) {
|
|
222
|
-
super(message2, options);
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
227
|
-
function assertCryptoKey(key) {
|
|
228
|
-
if (!isCryptoKey(key)) {
|
|
229
|
-
throw new Error("CryptoKey instance expected");
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
var isCryptoKey = (key) => {
|
|
233
|
-
if (key?.[Symbol.toStringTag] === "CryptoKey")
|
|
234
|
-
return true;
|
|
235
|
-
try {
|
|
236
|
-
return key instanceof CryptoKey;
|
|
237
|
-
} catch {
|
|
238
|
-
return false;
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
var isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
|
|
242
|
-
var isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
243
|
-
|
|
244
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/content_encryption.js
|
|
245
|
-
var generateCek = (enc) => crypto.getRandomValues(new Uint8Array(enc.cekBits >> 3));
|
|
246
|
-
function checkCekLength(cek, expected) {
|
|
247
|
-
const actual = cek.byteLength << 3;
|
|
248
|
-
if (actual !== expected) {
|
|
249
|
-
throw new JWEInvalid(`Invalid Content Encryption Key length. Expected ${expected} bits, got ${actual} bits`);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
var generateIv = (enc) => crypto.getRandomValues(new Uint8Array(enc.ivBits >> 3));
|
|
253
|
-
function checkIvLength(enc, iv) {
|
|
254
|
-
if (iv.length << 3 !== enc.ivBits) {
|
|
255
|
-
throw new JWEInvalid("Invalid Initialization Vector length");
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
async function cbcKeySetup(enc, cek, usage) {
|
|
259
|
-
if (!(cek instanceof Uint8Array)) {
|
|
260
|
-
throw new TypeError(invalidKeyInput(cek, "Uint8Array"));
|
|
261
|
-
}
|
|
262
|
-
const keySize = enc.cekBits >> 1;
|
|
263
|
-
const encKey = await crypto.subtle.importKey("raw", cek.subarray(keySize >> 3), "AES-CBC", false, [usage]);
|
|
264
|
-
const macKey = await crypto.subtle.importKey("raw", cek.subarray(0, keySize >> 3), {
|
|
265
|
-
hash: `SHA-${keySize << 1}`,
|
|
266
|
-
name: "HMAC"
|
|
267
|
-
}, false, ["sign"]);
|
|
268
|
-
return [encKey, macKey, keySize];
|
|
269
|
-
}
|
|
270
|
-
async function cbcHmacTag(macKey, macData, keySize) {
|
|
271
|
-
return new Uint8Array((await crypto.subtle.sign("HMAC", macKey, macData)).slice(0, keySize >> 3));
|
|
272
|
-
}
|
|
273
|
-
async function cbcEncrypt(enc, plaintext, cek, iv, aad) {
|
|
274
|
-
const [encKey, macKey, keySize] = await cbcKeySetup(enc, cek, "encrypt");
|
|
275
|
-
const ciphertext = new Uint8Array(await crypto.subtle.encrypt({
|
|
276
|
-
iv,
|
|
277
|
-
name: "AES-CBC"
|
|
278
|
-
}, encKey, plaintext));
|
|
279
|
-
const macData = concat(aad, iv, ciphertext, uint64be(aad.length * 8));
|
|
280
|
-
const tag2 = await cbcHmacTag(macKey, macData, keySize);
|
|
281
|
-
return { ciphertext, tag: tag2, iv };
|
|
282
|
-
}
|
|
283
|
-
async function timingSafeEqual(a, b) {
|
|
284
|
-
const algorithm = { name: "HMAC", hash: "SHA-256" };
|
|
285
|
-
const key = await crypto.subtle.generateKey(algorithm, false, ["sign", "verify"]);
|
|
286
|
-
const aHmac = await crypto.subtle.sign(algorithm, key, a);
|
|
287
|
-
return crypto.subtle.verify(algorithm, key, aHmac, b);
|
|
288
|
-
}
|
|
289
|
-
async function cbcDecrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
290
|
-
const [encKey, macKey, keySize] = await cbcKeySetup(enc, cek, "decrypt");
|
|
291
|
-
const macData = concat(aad, iv, ciphertext, uint64be(aad.length * 8));
|
|
292
|
-
const expectedTag = await cbcHmacTag(macKey, macData, keySize);
|
|
293
|
-
try {
|
|
294
|
-
if (await timingSafeEqual(tag2, expectedTag)) {
|
|
295
|
-
return new Uint8Array(await crypto.subtle.decrypt({ iv, name: "AES-CBC" }, encKey, ciphertext));
|
|
296
|
-
}
|
|
297
|
-
} catch {
|
|
298
|
-
}
|
|
299
|
-
throw new JWEDecryptionFailed();
|
|
300
|
-
}
|
|
301
|
-
async function gcmEncrypt(enc, plaintext, cek, iv, aad) {
|
|
302
|
-
const encKey = cek instanceof Uint8Array ? await crypto.subtle.importKey("raw", cek, "AES-GCM", false, [
|
|
303
|
-
"encrypt"
|
|
304
|
-
]) : (checkCryptoKey(cek, enc.subtle, "encrypt"), cek);
|
|
305
|
-
const encrypted = new Uint8Array(await crypto.subtle.encrypt({
|
|
306
|
-
additionalData: aad,
|
|
307
|
-
iv,
|
|
308
|
-
name: "AES-GCM",
|
|
309
|
-
tagLength: 128
|
|
310
|
-
}, encKey, plaintext));
|
|
311
|
-
const tag2 = encrypted.slice(-16);
|
|
312
|
-
const ciphertext = encrypted.slice(0, -16);
|
|
313
|
-
return { ciphertext, tag: tag2, iv };
|
|
314
|
-
}
|
|
315
|
-
async function gcmDecrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
316
|
-
const encKey = cek instanceof Uint8Array ? await crypto.subtle.importKey("raw", cek, "AES-GCM", false, [
|
|
317
|
-
"decrypt"
|
|
318
|
-
]) : (checkCryptoKey(cek, enc.subtle, "decrypt"), cek);
|
|
319
|
-
try {
|
|
320
|
-
return new Uint8Array(await crypto.subtle.decrypt({
|
|
321
|
-
additionalData: aad,
|
|
322
|
-
iv,
|
|
323
|
-
name: "AES-GCM",
|
|
324
|
-
tagLength: 128
|
|
325
|
-
}, encKey, concat(ciphertext, tag2)));
|
|
326
|
-
} catch {
|
|
327
|
-
throw new JWEDecryptionFailed();
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
async function encrypt(enc, plaintext, cek, iv, aad) {
|
|
331
|
-
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
|
332
|
-
throw new TypeError(invalidKeyInput(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
|
|
333
|
-
}
|
|
334
|
-
if (iv) {
|
|
335
|
-
checkIvLength(enc, iv);
|
|
336
|
-
} else {
|
|
337
|
-
iv = generateIv(enc);
|
|
338
|
-
}
|
|
339
|
-
if (cek instanceof Uint8Array) {
|
|
340
|
-
checkCekLength(cek, enc.cekBits);
|
|
341
|
-
}
|
|
342
|
-
return enc.cbc ? cbcEncrypt(enc, plaintext, cek, iv, aad) : gcmEncrypt(enc, plaintext, cek, iv, aad);
|
|
343
|
-
}
|
|
344
|
-
async function decrypt(enc, cek, ciphertext, iv, tag2, aad) {
|
|
345
|
-
if (!isCryptoKey(cek) && !(cek instanceof Uint8Array)) {
|
|
346
|
-
throw new TypeError(invalidKeyInput(cek, "CryptoKey", "KeyObject", "Uint8Array", "JSON Web Key"));
|
|
347
|
-
}
|
|
348
|
-
if (!iv) {
|
|
349
|
-
throw new JWEInvalid("JWE Initialization Vector missing");
|
|
350
|
-
}
|
|
351
|
-
if (!tag2) {
|
|
352
|
-
throw new JWEInvalid("JWE Authentication Tag missing");
|
|
353
|
-
}
|
|
354
|
-
if (!enc.cbc && tag2.length !== 16) {
|
|
355
|
-
throw new JWEInvalid("Invalid Authentication Tag length");
|
|
356
|
-
}
|
|
357
|
-
checkIvLength(enc, iv);
|
|
358
|
-
if (cek instanceof Uint8Array) {
|
|
359
|
-
checkCekLength(cek, enc.cekBits);
|
|
360
|
-
}
|
|
361
|
-
return enc.cbc ? cbcDecrypt(enc, cek, ciphertext, iv, tag2, aad) : gcmDecrypt(enc, cek, ciphertext, iv, tag2, aad);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/util/base64url.js
|
|
365
|
-
var base64url_exports = {};
|
|
366
|
-
__export(base64url_exports, {
|
|
367
|
-
decode: () => decode,
|
|
368
|
-
encode: () => encode2
|
|
369
|
-
});
|
|
370
|
-
|
|
371
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/base64.js
|
|
372
|
-
function encodeBase64(input) {
|
|
373
|
-
if (Uint8Array.prototype.toBase64) {
|
|
374
|
-
return input.toBase64();
|
|
375
|
-
}
|
|
376
|
-
const CHUNK_SIZE = 32768;
|
|
377
|
-
const arr = [];
|
|
378
|
-
for (let i = 0; i < input.length; i += CHUNK_SIZE) {
|
|
379
|
-
arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
|
|
380
|
-
}
|
|
381
|
-
return btoa(arr.join(""));
|
|
382
|
-
}
|
|
383
|
-
function decodeBase64(encoded) {
|
|
384
|
-
if (Uint8Array.fromBase64) {
|
|
385
|
-
return Uint8Array.fromBase64(encoded);
|
|
386
|
-
}
|
|
387
|
-
const binary = atob(encoded);
|
|
388
|
-
const bytes = new Uint8Array(binary.length);
|
|
389
|
-
for (let i = 0; i < binary.length; i++) {
|
|
390
|
-
bytes[i] = binary.charCodeAt(i);
|
|
391
|
-
}
|
|
392
|
-
return bytes;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/util/base64url.js
|
|
396
|
-
var invalid = "The input to be decoded is not correctly encoded.";
|
|
397
|
-
function decode(input) {
|
|
398
|
-
if (Uint8Array.fromBase64) {
|
|
399
|
-
try {
|
|
400
|
-
return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), {
|
|
401
|
-
alphabet: "base64url"
|
|
402
|
-
});
|
|
403
|
-
} catch (cause) {
|
|
404
|
-
throw new TypeError(invalid, { cause });
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
let encoded = input;
|
|
408
|
-
if (encoded instanceof Uint8Array) {
|
|
409
|
-
encoded = decoder.decode(encoded);
|
|
410
|
-
}
|
|
411
|
-
if (encoded.includes("+") || encoded.includes("/")) {
|
|
412
|
-
throw new TypeError(invalid);
|
|
413
|
-
}
|
|
414
|
-
encoded = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
415
|
-
try {
|
|
416
|
-
return decodeBase64(encoded);
|
|
417
|
-
} catch {
|
|
418
|
-
throw new TypeError(invalid);
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
function encode2(input) {
|
|
422
|
-
let unencoded = input;
|
|
423
|
-
if (typeof unencoded === "string") {
|
|
424
|
-
unencoded = encoder.encode(unencoded);
|
|
425
|
-
}
|
|
426
|
-
if (Uint8Array.prototype.toBase64) {
|
|
427
|
-
return unencoded.toBase64({ alphabet: "base64url", omitPadding: true });
|
|
428
|
-
}
|
|
429
|
-
return encodeBase64(unencoded).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/type_checks.js
|
|
433
|
-
function assertUint8Array(input, label) {
|
|
434
|
-
if (!(input instanceof Uint8Array)) {
|
|
435
|
-
throw new TypeError(`${label} must be an instance of Uint8Array`);
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
function isObject(input) {
|
|
439
|
-
if (typeof input !== "object" || input === null || Object.prototype.toString.call(input) !== "[object Object]") {
|
|
440
|
-
return false;
|
|
441
|
-
}
|
|
442
|
-
const prototype = Object.getPrototypeOf(input);
|
|
443
|
-
return prototype === null || Object.getPrototypeOf(prototype) === null;
|
|
444
|
-
}
|
|
445
|
-
function isJwkSet(input) {
|
|
446
|
-
return isObject(input) && Array.isArray(input.keys) && Array.from(input.keys).every(isObject);
|
|
447
|
-
}
|
|
448
|
-
function isDisjoint(...headers) {
|
|
449
|
-
const parameters = /* @__PURE__ */ new Set();
|
|
450
|
-
for (const header of headers) {
|
|
451
|
-
if (!header)
|
|
452
|
-
continue;
|
|
453
|
-
for (const parameter of Object.keys(header)) {
|
|
454
|
-
if (parameters.has(parameter)) {
|
|
455
|
-
return false;
|
|
456
|
-
}
|
|
457
|
-
parameters.add(parameter);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
return true;
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/helpers.js
|
|
464
|
-
var unprotected = /* @__PURE__ */ Symbol();
|
|
465
|
-
function assertNotSet(value, name) {
|
|
466
|
-
if (value !== void 0) {
|
|
467
|
-
throw new TypeError(`${name} can only be called once`);
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
function decodeBase64url(value, label, ErrorClass) {
|
|
471
|
-
try {
|
|
472
|
-
return decode(value);
|
|
473
|
-
} catch {
|
|
474
|
-
throw new ErrorClass(`Failed to base64url decode the ${label}`);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
function encodeBase64url(value, label, ErrorClass) {
|
|
478
|
-
try {
|
|
479
|
-
return encode(value);
|
|
480
|
-
} catch {
|
|
481
|
-
throw new ErrorClass(`The ${label} is not a valid base64url string`);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
async function digest(algorithm, data) {
|
|
485
|
-
const subtleDigest = `SHA-${algorithm.slice(-3)}`;
|
|
486
|
-
return new Uint8Array(await crypto.subtle.digest(subtleDigest, data));
|
|
487
|
-
}
|
|
488
|
-
function parseJoseHeader(b64, ErrorClass, message2) {
|
|
489
|
-
let parsed;
|
|
490
|
-
try {
|
|
491
|
-
parsed = JSON.parse(strictDecoder.decode(decode(b64)));
|
|
492
|
-
} catch {
|
|
493
|
-
throw new ErrorClass(message2);
|
|
494
|
-
}
|
|
495
|
-
if (!isObject(parsed)) {
|
|
496
|
-
throw new ErrorClass(message2);
|
|
497
|
-
}
|
|
498
|
-
return parsed;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/jwk_to_key.js
|
|
502
|
-
async function jwkToKey(entry, jwk) {
|
|
503
|
-
if (jwk.kty === "RSA" && "oth" in jwk && jwk.oth !== void 0) {
|
|
504
|
-
throw new JOSENotSupported('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
|
|
505
|
-
}
|
|
506
|
-
if (!entry.kty.includes(jwk.kty)) {
|
|
507
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
508
|
-
}
|
|
509
|
-
const algorithm = entry.resolve?.({ kty: jwk.kty, crv: jwk.crv }) ?? entry.subtle;
|
|
510
|
-
const isPrivate = !!(jwk.d || jwk.priv);
|
|
511
|
-
const keyData = { ...jwk };
|
|
512
|
-
if (keyData.kty !== "AKP") {
|
|
513
|
-
delete keyData.alg;
|
|
514
|
-
}
|
|
515
|
-
delete keyData.use;
|
|
516
|
-
return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? !isPrivate, jwk.key_ops ?? entry.usages[isPrivate ? 1 : 0]);
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/jwk_metadata.js
|
|
520
|
-
function snapshotJwk(jwk) {
|
|
521
|
-
return { __proto__: null, ...jwk };
|
|
522
|
-
}
|
|
523
|
-
function normalizeJwk(jwk) {
|
|
524
|
-
const normalized = snapshotJwk(jwk);
|
|
525
|
-
if (normalized.ext !== void 0 && typeof normalized.ext !== "boolean") {
|
|
526
|
-
throw new TypeError('"ext" (Extractable) Parameter must be a boolean');
|
|
527
|
-
}
|
|
528
|
-
if (normalized.key_ops !== void 0) {
|
|
529
|
-
const value = normalized.key_ops;
|
|
530
|
-
const keyOps = Array.isArray(value) ? [...value] : void 0;
|
|
531
|
-
if (!keyOps || keyOps.some((operation) => typeof operation !== "string") || new Set(keyOps).size !== keyOps.length) {
|
|
532
|
-
throw new TypeError('"key_ops" (Key Operations) Parameter must be an array of unique strings');
|
|
533
|
-
}
|
|
534
|
-
normalized.key_ops = keyOps;
|
|
535
|
-
}
|
|
536
|
-
return normalized;
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/key.js
|
|
540
|
-
var tag = (key) => key[Symbol.toStringTag];
|
|
541
|
-
var jwkMatchesOp = (entry, key, usage) => {
|
|
542
|
-
const { alg } = entry;
|
|
543
|
-
if (key.use !== void 0) {
|
|
544
|
-
const expected = usage === "sign" || usage === "verify" ? "sig" : "enc";
|
|
545
|
-
if (key.use !== expected) {
|
|
546
|
-
throw new TypeError(`Invalid key for this operation, its "use" must be "${expected}" when present`);
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
if (key.alg !== void 0 && key.alg !== alg) {
|
|
550
|
-
throw new TypeError(`Invalid key for this operation, its "alg" must be "${alg}" when present`);
|
|
551
|
-
}
|
|
552
|
-
if (Array.isArray(key.key_ops)) {
|
|
553
|
-
const expectedKeyOp = usage === "encrypt" || usage === "decrypt" ? entry.ops?.[usage === "encrypt" ? 0 : 1] : usage;
|
|
554
|
-
if (expectedKeyOp && !key.key_ops.includes(expectedKeyOp)) {
|
|
555
|
-
throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${expectedKeyOp}" when present`);
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
};
|
|
559
|
-
function checkKeyType(entry, key, usage) {
|
|
560
|
-
const { alg, secret } = entry;
|
|
561
|
-
const privateKey = usage === "decrypt" || usage === "sign";
|
|
562
|
-
if (secret && key instanceof Uint8Array)
|
|
563
|
-
return [BYTES, key];
|
|
564
|
-
if (isObject(key)) {
|
|
565
|
-
const normalized = normalizeJwk(key);
|
|
566
|
-
if (typeof normalized.kty !== "string") {
|
|
567
|
-
throw new TypeError(secret ? withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array") : withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
568
|
-
}
|
|
569
|
-
const valid = secret ? normalized.kty === "oct" && typeof normalized.k === "string" : normalized.kty !== "oct" && (privateKey ? normalized.kty === "AKP" && typeof normalized.priv === "string" || typeof normalized.d === "string" : normalized.d === void 0 && normalized.priv === void 0);
|
|
570
|
-
if (!valid) {
|
|
571
|
-
throw new TypeError(secret ? `JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present` : `JSON Web Key for this operation must be a ${privateKey ? "private" : "public"} JWK`);
|
|
572
|
-
}
|
|
573
|
-
jwkMatchesOp(entry, normalized, usage);
|
|
574
|
-
return [JWK, key, normalized];
|
|
575
|
-
}
|
|
576
|
-
if (!isKeyLike(key)) {
|
|
577
|
-
throw new TypeError(secret ? withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array") : withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
578
|
-
}
|
|
579
|
-
if (secret) {
|
|
580
|
-
if (key.type !== "secret") {
|
|
581
|
-
throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
|
|
582
|
-
}
|
|
583
|
-
} else {
|
|
584
|
-
if (key.type === "secret") {
|
|
585
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
586
|
-
}
|
|
587
|
-
const expectedType = privateKey ? "private" : "public";
|
|
588
|
-
if ((key.type === "public" || key.type === "private") && key.type !== expectedType) {
|
|
589
|
-
const operation = usage === "sign" ? "signing" : usage === "verify" ? "verifying" : `${usage.slice(0, -1)}tion`;
|
|
590
|
-
throw new TypeError(`${tag(key)} instances for asymmetric algorithm ${operation} must be of type "${expectedType}"`);
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
return isCryptoKey(key) ? [CRYPTO, key] : [KEYOBJECT, key];
|
|
594
|
-
}
|
|
595
|
-
var BYTES = 0;
|
|
596
|
-
var CRYPTO = 1;
|
|
597
|
-
var KEYOBJECT = 2;
|
|
598
|
-
var JWK = 3;
|
|
599
|
-
var cache;
|
|
600
|
-
var nist = {
|
|
601
|
-
__proto__: null,
|
|
602
|
-
prime256v1: "P-256",
|
|
603
|
-
secp384r1: "P-384",
|
|
604
|
-
secp521r1: "P-521"
|
|
605
|
-
};
|
|
606
|
-
function cached(key, alg, value) {
|
|
607
|
-
cache ||= /* @__PURE__ */ new WeakMap();
|
|
608
|
-
const entry = cache.get(key);
|
|
609
|
-
if (value) {
|
|
610
|
-
if (entry) {
|
|
611
|
-
entry[alg] = value;
|
|
612
|
-
} else {
|
|
613
|
-
cache.set(key, { [alg]: value });
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
return value ?? entry?.[alg];
|
|
617
|
-
}
|
|
618
|
-
var handleJWK = async (key, jwk, entry) => cached(key, entry.alg) ?? cached(key, entry.alg, await jwkToKey(entry, { ...jwk, alg: entry.alg }));
|
|
619
|
-
var handleKeyObject = (keyObject, entry) => {
|
|
620
|
-
const hit = cached(keyObject, entry.alg);
|
|
621
|
-
if (hit)
|
|
622
|
-
return hit;
|
|
623
|
-
const isPublic = keyObject.type === "public";
|
|
624
|
-
const usages = entry.usages[isPublic ? 0 : 1];
|
|
625
|
-
const { asymmetricKeyType } = keyObject;
|
|
626
|
-
const crv = nist[keyObject.asymmetricKeyDetails?.namedCurve];
|
|
627
|
-
const params = entry.resolve?.({ crv, asymmetricKeyType }) ?? entry.subtle;
|
|
628
|
-
return cached(keyObject, entry.alg, keyObject.toCryptoKey(params, isPublic, usages));
|
|
629
|
-
};
|
|
630
|
-
async function prepareKey(entry, key, usage) {
|
|
631
|
-
const tagged = checkKeyType(entry, key, usage);
|
|
632
|
-
switch (tagged[0]) {
|
|
633
|
-
case BYTES:
|
|
634
|
-
case CRYPTO:
|
|
635
|
-
return tagged[1];
|
|
636
|
-
case JWK: {
|
|
637
|
-
const key2 = tagged[1];
|
|
638
|
-
const normalized = tagged[2];
|
|
639
|
-
if (normalized.kty === "oct") {
|
|
640
|
-
return decode(normalized.k);
|
|
641
|
-
}
|
|
642
|
-
if (!Object.isFrozen(key2)) {
|
|
643
|
-
const { key_ops } = key2;
|
|
644
|
-
if (Array.isArray(key_ops))
|
|
645
|
-
Object.freeze(key_ops);
|
|
646
|
-
Object.freeze(key2);
|
|
647
|
-
}
|
|
648
|
-
return handleJWK(key2, normalized, entry);
|
|
649
|
-
}
|
|
650
|
-
case KEYOBJECT: {
|
|
651
|
-
const keyObject = tagged[1];
|
|
652
|
-
if (keyObject.type === "secret") {
|
|
653
|
-
return keyObject.export();
|
|
654
|
-
}
|
|
655
|
-
if ("toCryptoKey" in keyObject && typeof keyObject.toCryptoKey === "function") {
|
|
656
|
-
return handleKeyObject(keyObject, entry);
|
|
657
|
-
}
|
|
658
|
-
return handleJWK(keyObject, keyObject.export({ format: "jwk" }), entry);
|
|
659
|
-
}
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/key_descriptor.js
|
|
664
|
-
function table(entries) {
|
|
665
|
-
const out = { __proto__: null };
|
|
666
|
-
for (const alg in entries) {
|
|
667
|
-
out[alg] = { ...entries[alg], alg };
|
|
668
|
-
}
|
|
669
|
-
return out;
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/jwe_algorithms.js
|
|
673
|
-
var wrap = [
|
|
674
|
-
["encrypt", "wrapKey"],
|
|
675
|
-
["decrypt", "unwrapKey"]
|
|
676
|
-
];
|
|
677
|
-
var derive = [[], ["deriveBits"]];
|
|
678
|
-
var none = [[], []];
|
|
679
|
-
function rsaes(bits) {
|
|
680
|
-
return {
|
|
681
|
-
kty: ["RSA"],
|
|
682
|
-
subtle: { name: "RSA-OAEP", hash: `SHA-${bits}` },
|
|
683
|
-
usages: wrap,
|
|
684
|
-
ops: ["wrapKey", "unwrapKey"]
|
|
685
|
-
};
|
|
686
|
-
}
|
|
687
|
-
function ecdh() {
|
|
688
|
-
return {
|
|
689
|
-
kty: ["EC", "OKP"],
|
|
690
|
-
subtle: { name: "ECDH" },
|
|
691
|
-
resolve: ({ kty, crv, asymmetricKeyType }) => {
|
|
692
|
-
if (crv === "X25519" || asymmetricKeyType === "x25519") {
|
|
693
|
-
return { name: "X25519" };
|
|
694
|
-
}
|
|
695
|
-
if (kty === "OKP") {
|
|
696
|
-
throw new JOSENotSupported('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
|
|
697
|
-
}
|
|
698
|
-
return { name: "ECDH", namedCurve: crv };
|
|
699
|
-
},
|
|
700
|
-
usages: derive,
|
|
701
|
-
ops: [void 0, "deriveBits"]
|
|
702
|
-
};
|
|
703
|
-
}
|
|
704
|
-
function aeskw(bits, gcm = false) {
|
|
705
|
-
return {
|
|
706
|
-
kty: ["oct"],
|
|
707
|
-
secret: true,
|
|
708
|
-
subtle: { name: gcm ? "AES-GCM" : "AES-KW", length: bits },
|
|
709
|
-
usages: none,
|
|
710
|
-
ops: gcm ? ["encrypt", "decrypt"] : ["wrapKey", "unwrapKey"]
|
|
711
|
-
};
|
|
712
|
-
}
|
|
713
|
-
function pbes2() {
|
|
714
|
-
return {
|
|
715
|
-
kty: ["oct"],
|
|
716
|
-
secret: true,
|
|
717
|
-
subtle: { name: "PBKDF2" },
|
|
718
|
-
usages: none,
|
|
719
|
-
ops: ["deriveBits", "deriveBits"]
|
|
720
|
-
};
|
|
721
|
-
}
|
|
722
|
-
var JWE = table({
|
|
723
|
-
dir: {
|
|
724
|
-
kty: ["oct"],
|
|
725
|
-
secret: true,
|
|
726
|
-
subtle: { name: "AES-GCM" },
|
|
727
|
-
usages: none,
|
|
728
|
-
ops: ["encrypt", "decrypt"]
|
|
729
|
-
},
|
|
730
|
-
"RSA-OAEP": rsaes(1),
|
|
731
|
-
"RSA-OAEP-256": rsaes(256),
|
|
732
|
-
"RSA-OAEP-384": rsaes(384),
|
|
733
|
-
"RSA-OAEP-512": rsaes(512),
|
|
734
|
-
"ECDH-ES": ecdh(),
|
|
735
|
-
"ECDH-ES+A128KW": ecdh(),
|
|
736
|
-
"ECDH-ES+A192KW": ecdh(),
|
|
737
|
-
"ECDH-ES+A256KW": ecdh(),
|
|
738
|
-
A128KW: aeskw(128),
|
|
739
|
-
A192KW: aeskw(192),
|
|
740
|
-
A256KW: aeskw(256),
|
|
741
|
-
A128GCMKW: aeskw(128, true),
|
|
742
|
-
A192GCMKW: aeskw(192, true),
|
|
743
|
-
A256GCMKW: aeskw(256, true),
|
|
744
|
-
"PBES2-HS256+A128KW": pbes2(),
|
|
745
|
-
"PBES2-HS384+A192KW": pbes2(),
|
|
746
|
-
"PBES2-HS512+A256KW": pbes2()
|
|
747
|
-
});
|
|
748
|
-
var contentOps = ["encrypt", "decrypt"];
|
|
749
|
-
function contentEncryption(bits, cbc = false) {
|
|
750
|
-
return {
|
|
751
|
-
kty: ["oct"],
|
|
752
|
-
secret: true,
|
|
753
|
-
subtle: { name: cbc ? "AES-CBC" : "AES-GCM", length: bits },
|
|
754
|
-
usages: none,
|
|
755
|
-
ops: contentOps,
|
|
756
|
-
cekBits: bits,
|
|
757
|
-
ivBits: cbc ? 128 : 96,
|
|
758
|
-
cbc
|
|
759
|
-
};
|
|
760
|
-
}
|
|
761
|
-
var ENC = table({
|
|
762
|
-
A128GCM: contentEncryption(128),
|
|
763
|
-
A192GCM: contentEncryption(192),
|
|
764
|
-
A256GCM: contentEncryption(256),
|
|
765
|
-
"A128CBC-HS256": contentEncryption(256, true),
|
|
766
|
-
"A192CBC-HS384": contentEncryption(384, true),
|
|
767
|
-
"A256CBC-HS512": contentEncryption(512, true)
|
|
768
|
-
});
|
|
769
|
-
function unsupported(parameter, name) {
|
|
770
|
-
throw new JOSENotSupported(`Invalid or unsupported "${parameter}" (JWE ${name}) header value`);
|
|
771
|
-
}
|
|
772
|
-
function jweAlgorithm(alg) {
|
|
773
|
-
return (typeof alg === "string" ? JWE[alg] : void 0) ?? unsupported("alg", "Algorithm");
|
|
774
|
-
}
|
|
775
|
-
function jweEncryption(enc) {
|
|
776
|
-
return (typeof enc === "string" ? ENC[enc] : void 0) ?? unsupported("enc", "Encryption Algorithm");
|
|
777
|
-
}
|
|
778
|
-
|
|
779
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/key_management.js
|
|
780
|
-
function checkEcdhCryptoKey(key, usage) {
|
|
781
|
-
if (key.algorithm.name !== "ECDH" && key.algorithm.name !== "X25519") {
|
|
782
|
-
throw new TypeError("CryptoKey does not support this operation, its algorithm.name must be ECDH or X25519");
|
|
783
|
-
}
|
|
784
|
-
checkUsage(key, usage);
|
|
785
|
-
}
|
|
786
|
-
async function aeskwCryptoKey(key, alg, usage) {
|
|
787
|
-
const expected = jweAlgorithm(alg).subtle;
|
|
788
|
-
const cryptoKey = key instanceof Uint8Array ? await crypto.subtle.importKey("raw", key, "AES-KW", true, [
|
|
789
|
-
usage
|
|
790
|
-
]) : key;
|
|
791
|
-
checkCryptoKey(cryptoKey, expected, usage);
|
|
792
|
-
return cryptoKey;
|
|
793
|
-
}
|
|
794
|
-
async function aeskwWrap(alg, key, cek) {
|
|
795
|
-
const cryptoKey = await aeskwCryptoKey(key, alg, "wrapKey");
|
|
796
|
-
const cryptoKeyCek = await crypto.subtle.importKey("raw", cek, { hash: "SHA-256", name: "HMAC" }, true, ["sign"]);
|
|
797
|
-
return new Uint8Array(await crypto.subtle.wrapKey("raw", cryptoKeyCek, cryptoKey, "AES-KW"));
|
|
798
|
-
}
|
|
799
|
-
async function aeskwUnwrap(alg, key, encryptedKey) {
|
|
800
|
-
const cryptoKey = await aeskwCryptoKey(key, alg, "unwrapKey");
|
|
801
|
-
const cryptoKeyCek = await crypto.subtle.unwrapKey("raw", encryptedKey, cryptoKey, "AES-KW", { hash: "SHA-256", name: "HMAC" }, true, ["sign"]);
|
|
802
|
-
return new Uint8Array(await crypto.subtle.exportKey("raw", cryptoKeyCek));
|
|
803
|
-
}
|
|
804
|
-
function checkRsaKey(alg, key, usage) {
|
|
805
|
-
checkCryptoKey(key, jweAlgorithm(alg).subtle, usage);
|
|
806
|
-
checkModulusLength(alg, key);
|
|
807
|
-
}
|
|
808
|
-
function pbes2CryptoKey(key, alg) {
|
|
809
|
-
if (key instanceof Uint8Array) {
|
|
810
|
-
return crypto.subtle.importKey("raw", key, "PBKDF2", false, [
|
|
811
|
-
"deriveBits"
|
|
812
|
-
]);
|
|
813
|
-
}
|
|
814
|
-
checkCryptoKey(key, jweAlgorithm(alg).subtle, "deriveBits");
|
|
815
|
-
return key;
|
|
816
|
-
}
|
|
817
|
-
async function deriveKey(p2s, alg, p2c, key) {
|
|
818
|
-
if (!(p2s instanceof Uint8Array) || p2s.length < 8) {
|
|
819
|
-
throw new JWEInvalid("PBES2 Salt Input must be 8 or more octets");
|
|
820
|
-
}
|
|
821
|
-
if (!Number.isSafeInteger(p2c) || Math.sign(p2c) !== 1) {
|
|
822
|
-
throw new JWEInvalid("PBES2 Count Input must be a positive integer");
|
|
823
|
-
}
|
|
824
|
-
const salt = concat(encode(alg), Uint8Array.of(0), p2s);
|
|
825
|
-
const keylen = parseInt(alg.slice(13, 16), 10);
|
|
826
|
-
const subtleAlg = {
|
|
827
|
-
hash: `SHA-${alg.slice(8, 11)}`,
|
|
828
|
-
iterations: p2c,
|
|
829
|
-
name: "PBKDF2",
|
|
830
|
-
salt
|
|
831
|
-
};
|
|
832
|
-
const cryptoKey = await pbes2CryptoKey(key, alg);
|
|
833
|
-
return new Uint8Array(await crypto.subtle.deriveBits(subtleAlg, cryptoKey, keylen));
|
|
834
|
-
}
|
|
835
|
-
function lengthAndInput(input) {
|
|
836
|
-
return concat(uint32be(input.length), input);
|
|
837
|
-
}
|
|
838
|
-
async function concatKdf(Z, L, OtherInfo) {
|
|
839
|
-
const dkLen = L >> 3;
|
|
840
|
-
const hashLen = 32;
|
|
841
|
-
const reps = Math.ceil(dkLen / hashLen);
|
|
842
|
-
const dk = new Uint8Array(reps * hashLen);
|
|
843
|
-
for (let i = 1; i <= reps; i++) {
|
|
844
|
-
const hashResult = await digest("sha256", concat(uint32be(i), Z, OtherInfo));
|
|
845
|
-
dk.set(hashResult, (i - 1) * hashLen);
|
|
846
|
-
}
|
|
847
|
-
return dk.slice(0, dkLen);
|
|
848
|
-
}
|
|
849
|
-
async function ecdhesDeriveKey(publicKey, privateKey, algorithm, keyLength, apu = new Uint8Array(), apv = new Uint8Array()) {
|
|
850
|
-
checkEcdhCryptoKey(publicKey);
|
|
851
|
-
checkEcdhCryptoKey(privateKey, "deriveBits");
|
|
852
|
-
const otherInfo = concat(lengthAndInput(encode(algorithm)), lengthAndInput(apu), lengthAndInput(apv), uint32be(keyLength));
|
|
853
|
-
const Z = new Uint8Array(await crypto.subtle.deriveBits({
|
|
854
|
-
name: publicKey.algorithm.name,
|
|
855
|
-
public: publicKey
|
|
856
|
-
}, privateKey, publicKey.algorithm.name === "X25519" ? 256 : Math.ceil(parseInt(publicKey.algorithm.namedCurve.slice(-3), 10) / 8) << 3));
|
|
857
|
-
return concatKdf(Z, keyLength, otherInfo);
|
|
858
|
-
}
|
|
859
|
-
function assertEcdhKey(key) {
|
|
860
|
-
assertCryptoKey(key);
|
|
861
|
-
const curve = key.algorithm.namedCurve;
|
|
862
|
-
if (curve !== "P-256" && curve !== "P-384" && curve !== "P-521" && key.algorithm.name !== "X25519") {
|
|
863
|
-
throw new JOSENotSupported("ECDH with the provided key is not allowed or not supported by your javascript runtime");
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
function assertEncryptedKey(encryptedKey) {
|
|
867
|
-
if (encryptedKey === void 0)
|
|
868
|
-
throw new JWEInvalid("JWE Encrypted Key missing");
|
|
869
|
-
}
|
|
870
|
-
function assertNoEncryptedKey(encryptedKey) {
|
|
871
|
-
if (encryptedKey !== void 0)
|
|
872
|
-
throw new JWEInvalid("Encountered unexpected JWE Encrypted Key");
|
|
873
|
-
}
|
|
874
|
-
async function decryptKeyManagement(alg, enc, key, encryptedKey, joseHeader, maxPBES2Count) {
|
|
875
|
-
const entry = jweAlgorithm(alg);
|
|
876
|
-
if (alg === "dir") {
|
|
877
|
-
assertNoEncryptedKey(encryptedKey);
|
|
878
|
-
return key;
|
|
879
|
-
}
|
|
880
|
-
switch (entry.subtle.name) {
|
|
881
|
-
case "ECDH": {
|
|
882
|
-
if (alg === "ECDH-ES")
|
|
883
|
-
assertNoEncryptedKey(encryptedKey);
|
|
884
|
-
if (!isObject(joseHeader.epk))
|
|
885
|
-
throw new JWEInvalid(`JOSE Header "epk" (Ephemeral Public Key) missing or invalid`);
|
|
886
|
-
assertEcdhKey(key);
|
|
887
|
-
const epk = await jwkToKey(entry, joseHeader.epk);
|
|
888
|
-
let partyUInfo;
|
|
889
|
-
let partyVInfo;
|
|
890
|
-
if (joseHeader.apu !== void 0) {
|
|
891
|
-
if (typeof joseHeader.apu !== "string")
|
|
892
|
-
throw new JWEInvalid(`JOSE Header "apu" (Agreement PartyUInfo) invalid`);
|
|
893
|
-
partyUInfo = decodeBase64url(joseHeader.apu, "apu", JWEInvalid);
|
|
894
|
-
}
|
|
895
|
-
if (joseHeader.apv !== void 0) {
|
|
896
|
-
if (typeof joseHeader.apv !== "string")
|
|
897
|
-
throw new JWEInvalid(`JOSE Header "apv" (Agreement PartyVInfo) invalid`);
|
|
898
|
-
partyVInfo = decodeBase64url(joseHeader.apv, "apv", JWEInvalid);
|
|
899
|
-
}
|
|
900
|
-
const sharedSecret = await ecdhesDeriveKey(epk, key, alg === "ECDH-ES" ? enc.alg : alg, alg === "ECDH-ES" ? enc.cekBits : parseInt(alg.slice(-5, -2), 10), partyUInfo, partyVInfo);
|
|
901
|
-
if (alg === "ECDH-ES")
|
|
902
|
-
return sharedSecret;
|
|
903
|
-
assertEncryptedKey(encryptedKey);
|
|
904
|
-
return aeskwUnwrap(alg.slice(-6), sharedSecret, encryptedKey);
|
|
905
|
-
}
|
|
906
|
-
case "RSA-OAEP": {
|
|
907
|
-
assertEncryptedKey(encryptedKey);
|
|
908
|
-
assertCryptoKey(key);
|
|
909
|
-
checkRsaKey(alg, key, "decrypt");
|
|
910
|
-
return new Uint8Array(await crypto.subtle.decrypt("RSA-OAEP", key, encryptedKey));
|
|
911
|
-
}
|
|
912
|
-
case "PBKDF2": {
|
|
913
|
-
assertEncryptedKey(encryptedKey);
|
|
914
|
-
if (typeof joseHeader.p2c !== "number")
|
|
915
|
-
throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) missing or invalid`);
|
|
916
|
-
const p2cLimit = maxPBES2Count || 1e4;
|
|
917
|
-
if (joseHeader.p2c > p2cLimit)
|
|
918
|
-
throw new JWEInvalid(`JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds`);
|
|
919
|
-
if (typeof joseHeader.p2s !== "string")
|
|
920
|
-
throw new JWEInvalid(`JOSE Header "p2s" (PBES2 Salt) missing or invalid`);
|
|
921
|
-
const p2s = decodeBase64url(joseHeader.p2s, "p2s", JWEInvalid);
|
|
922
|
-
const derived = await deriveKey(p2s, alg, joseHeader.p2c, key);
|
|
923
|
-
return aeskwUnwrap(alg.slice(-6), derived, encryptedKey);
|
|
924
|
-
}
|
|
925
|
-
case "AES-KW": {
|
|
926
|
-
assertEncryptedKey(encryptedKey);
|
|
927
|
-
return aeskwUnwrap(alg, key, encryptedKey);
|
|
928
|
-
}
|
|
929
|
-
case "AES-GCM": {
|
|
930
|
-
assertEncryptedKey(encryptedKey);
|
|
931
|
-
if (typeof joseHeader.iv !== "string")
|
|
932
|
-
throw new JWEInvalid(`JOSE Header "iv" (Initialization Vector) missing or invalid`);
|
|
933
|
-
if (typeof joseHeader.tag !== "string")
|
|
934
|
-
throw new JWEInvalid(`JOSE Header "tag" (Authentication Tag) missing or invalid`);
|
|
935
|
-
let iv;
|
|
936
|
-
iv = decodeBase64url(joseHeader.iv, "iv", JWEInvalid);
|
|
937
|
-
let tag2;
|
|
938
|
-
tag2 = decodeBase64url(joseHeader.tag, "tag", JWEInvalid);
|
|
939
|
-
return decrypt(jweEncryption(alg.slice(0, -2)), key, encryptedKey, iv, tag2, new Uint8Array());
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
}
|
|
943
|
-
async function encryptKeyManagement(alg, enc, key, providedCek, providedParameters = {}) {
|
|
944
|
-
let encryptedKey;
|
|
945
|
-
let parameters;
|
|
946
|
-
let cek;
|
|
947
|
-
const entry = jweAlgorithm(alg);
|
|
948
|
-
if (alg === "dir")
|
|
949
|
-
return [key, void 0, void 0];
|
|
950
|
-
switch (entry.subtle.name) {
|
|
951
|
-
case "ECDH": {
|
|
952
|
-
assertEcdhKey(key);
|
|
953
|
-
const { apu, apv } = providedParameters;
|
|
954
|
-
if (apu !== void 0) {
|
|
955
|
-
assertUint8Array(apu, '"apu"');
|
|
956
|
-
}
|
|
957
|
-
if (apv !== void 0) {
|
|
958
|
-
assertUint8Array(apv, '"apv"');
|
|
959
|
-
}
|
|
960
|
-
let ephemeralKey;
|
|
961
|
-
if (providedParameters.epk !== void 0) {
|
|
962
|
-
ephemeralKey = await prepareKey(entry, providedParameters.epk, "decrypt");
|
|
963
|
-
} else {
|
|
964
|
-
ephemeralKey = (await crypto.subtle.generateKey(key.algorithm, true, ["deriveBits"])).privateKey;
|
|
965
|
-
}
|
|
966
|
-
const subtle = crypto.subtle;
|
|
967
|
-
let exportableEpk = ephemeralKey;
|
|
968
|
-
if (!exportableEpk.extractable) {
|
|
969
|
-
if (typeof subtle.getPublicKey !== "function") {
|
|
970
|
-
throw new TypeError('CryptoKey for "epk" must be extractable');
|
|
971
|
-
}
|
|
972
|
-
exportableEpk = await subtle.getPublicKey(ephemeralKey, []);
|
|
973
|
-
}
|
|
974
|
-
const { x, y, crv, kty } = await subtle.exportKey("jwk", exportableEpk);
|
|
975
|
-
const sharedSecret = await ecdhesDeriveKey(key, ephemeralKey, alg === "ECDH-ES" ? enc.alg : alg, alg === "ECDH-ES" ? enc.cekBits : parseInt(alg.slice(-5, -2), 10), apu, apv);
|
|
976
|
-
parameters = { epk: { x, crv, kty } };
|
|
977
|
-
if (kty === "EC")
|
|
978
|
-
parameters.epk.y = y;
|
|
979
|
-
if (apu)
|
|
980
|
-
parameters.apu = encode2(apu);
|
|
981
|
-
if (apv)
|
|
982
|
-
parameters.apv = encode2(apv);
|
|
983
|
-
if (alg === "ECDH-ES") {
|
|
984
|
-
cek = sharedSecret;
|
|
985
|
-
break;
|
|
986
|
-
}
|
|
987
|
-
cek = providedCek || generateCek(enc);
|
|
988
|
-
const kwAlg = alg.slice(-6);
|
|
989
|
-
encryptedKey = await aeskwWrap(kwAlg, sharedSecret, cek);
|
|
990
|
-
break;
|
|
991
|
-
}
|
|
992
|
-
case "RSA-OAEP": {
|
|
993
|
-
cek = providedCek || generateCek(enc);
|
|
994
|
-
assertCryptoKey(key);
|
|
995
|
-
checkRsaKey(alg, key, "encrypt");
|
|
996
|
-
encryptedKey = new Uint8Array(await crypto.subtle.encrypt("RSA-OAEP", key, cek));
|
|
997
|
-
break;
|
|
998
|
-
}
|
|
999
|
-
case "PBKDF2": {
|
|
1000
|
-
cek = providedCek || generateCek(enc);
|
|
1001
|
-
const { p2c = 2048, p2s = crypto.getRandomValues(new Uint8Array(16)) } = providedParameters;
|
|
1002
|
-
const derived = await deriveKey(p2s, alg, p2c, key);
|
|
1003
|
-
encryptedKey = await aeskwWrap(alg.slice(-6), derived, cek);
|
|
1004
|
-
parameters = { p2c, p2s: encode2(p2s) };
|
|
1005
|
-
break;
|
|
1006
|
-
}
|
|
1007
|
-
case "AES-KW": {
|
|
1008
|
-
cek = providedCek || generateCek(enc);
|
|
1009
|
-
encryptedKey = await aeskwWrap(alg, key, cek);
|
|
1010
|
-
break;
|
|
1011
|
-
}
|
|
1012
|
-
case "AES-GCM": {
|
|
1013
|
-
cek = providedCek || generateCek(enc);
|
|
1014
|
-
const { iv } = providedParameters;
|
|
1015
|
-
const wrapped = await encrypt(jweEncryption(alg.slice(0, -2)), cek, key, iv, new Uint8Array());
|
|
1016
|
-
encryptedKey = wrapped.ciphertext;
|
|
1017
|
-
parameters = { iv: encode2(wrapped.iv), tag: encode2(wrapped.tag) };
|
|
1018
|
-
break;
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
return [cek, encryptedKey, parameters];
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/options.js
|
|
1025
|
-
var JWS_RECOGNIZED = { __proto__: null, b64: true };
|
|
1026
|
-
var JWE_RECOGNIZED = { __proto__: null };
|
|
1027
|
-
function validateAlgorithms(option, algorithms) {
|
|
1028
|
-
if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) {
|
|
1029
|
-
throw new TypeError(`"${option}" option must be an array of strings`);
|
|
1030
|
-
}
|
|
1031
|
-
if (!algorithms) {
|
|
1032
|
-
return void 0;
|
|
1033
|
-
}
|
|
1034
|
-
return new Set(algorithms);
|
|
1035
|
-
}
|
|
1036
|
-
function validateCritDuplicates(Err, protectedHeader) {
|
|
1037
|
-
const { crit } = protectedHeader ?? {};
|
|
1038
|
-
if (Array.isArray(crit) && new Set(crit).size !== crit.length) {
|
|
1039
|
-
throw new Err('"crit" (Critical) Header Parameter MUST NOT contain duplicate values');
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
1043
|
-
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) {
|
|
1044
|
-
throw new Err('"crit" (Critical) Header Parameter MUST be integrity protected');
|
|
1045
|
-
}
|
|
1046
|
-
if (!protectedHeader || protectedHeader.crit === void 0) {
|
|
1047
|
-
return [];
|
|
1048
|
-
}
|
|
1049
|
-
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) {
|
|
1050
|
-
throw new Err('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
|
|
1051
|
-
}
|
|
1052
|
-
const recognized = recognizedOption === void 0 ? recognizedDefault : { __proto__: null, ...recognizedOption, ...recognizedDefault };
|
|
1053
|
-
for (const parameter of protectedHeader.crit) {
|
|
1054
|
-
if (!(parameter in recognized)) {
|
|
1055
|
-
throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
|
|
1056
|
-
}
|
|
1057
|
-
if (!Object.hasOwn(joseHeader, parameter) || joseHeader[parameter] === void 0) {
|
|
1058
|
-
throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
1059
|
-
}
|
|
1060
|
-
if (recognized[parameter] && (!Object.hasOwn(protectedHeader, parameter) || protectedHeader[parameter] === void 0)) {
|
|
1061
|
-
throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
1062
|
-
}
|
|
1063
|
-
}
|
|
1064
|
-
return protectedHeader.crit;
|
|
1065
|
-
}
|
|
1066
|
-
function validateB64(protectedHeader, extensions) {
|
|
1067
|
-
if (extensions.includes("b64")) {
|
|
1068
|
-
const b64 = protectedHeader.b64;
|
|
1069
|
-
if (typeof b64 !== "boolean") {
|
|
1070
|
-
throw new JWSInvalid('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
|
|
1071
|
-
}
|
|
1072
|
-
return b64;
|
|
1073
|
-
}
|
|
1074
|
-
return true;
|
|
1075
|
-
}
|
|
1076
|
-
function serializeJoseHeader(Err, header) {
|
|
1077
|
-
let serialized;
|
|
1078
|
-
let parsed;
|
|
1079
|
-
try {
|
|
1080
|
-
serialized = JSON.stringify(header);
|
|
1081
|
-
parsed = JSON.parse(serialized);
|
|
1082
|
-
} catch (cause) {
|
|
1083
|
-
throw new Err("JOSE Header is not valid JSON", { cause });
|
|
1084
|
-
}
|
|
1085
|
-
if (!isObject(parsed)) {
|
|
1086
|
-
throw new Err("JOSE Header is not a JSON object");
|
|
1087
|
-
}
|
|
1088
|
-
return [parsed, serialized];
|
|
1089
|
-
}
|
|
1090
|
-
|
|
1091
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/deflate.js
|
|
1092
|
-
function validateZip(joseHeader, protectedHeader) {
|
|
1093
|
-
if (joseHeader.zip !== void 0 && joseHeader.zip !== "DEF") {
|
|
1094
|
-
throw new JOSENotSupported('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value.');
|
|
1095
|
-
}
|
|
1096
|
-
if (joseHeader.zip !== void 0 && !protectedHeader?.zip) {
|
|
1097
|
-
throw new JWEInvalid('JWE "zip" (Compression Algorithm) Header Parameter MUST be in a protected header.');
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
function supported(name) {
|
|
1101
|
-
if (typeof globalThis[name] === "undefined") {
|
|
1102
|
-
throw new JOSENotSupported(`JWE "zip" (Compression Algorithm) Header Parameter requires the ${name} API.`);
|
|
1103
|
-
}
|
|
1104
|
-
}
|
|
1105
|
-
async function compress(input) {
|
|
1106
|
-
supported("CompressionStream");
|
|
1107
|
-
const cs = new CompressionStream("deflate-raw");
|
|
1108
|
-
const writer = cs.writable.getWriter();
|
|
1109
|
-
writer.write(input).catch(() => {
|
|
1110
|
-
});
|
|
1111
|
-
writer.close().catch(() => {
|
|
1112
|
-
});
|
|
1113
|
-
const chunks = [];
|
|
1114
|
-
const reader = cs.readable.getReader();
|
|
1115
|
-
for (; ; ) {
|
|
1116
|
-
const { value, done } = await reader.read();
|
|
1117
|
-
if (done)
|
|
1118
|
-
break;
|
|
1119
|
-
chunks.push(value);
|
|
1120
|
-
}
|
|
1121
|
-
return concat(...chunks);
|
|
1122
|
-
}
|
|
1123
|
-
async function decompress(input, maxLength) {
|
|
1124
|
-
supported("DecompressionStream");
|
|
1125
|
-
const ds = new DecompressionStream("deflate-raw");
|
|
1126
|
-
const writer = ds.writable.getWriter();
|
|
1127
|
-
writer.write(input).catch(() => {
|
|
1128
|
-
});
|
|
1129
|
-
writer.close().catch(() => {
|
|
1130
|
-
});
|
|
1131
|
-
const chunks = [];
|
|
1132
|
-
let length = 0;
|
|
1133
|
-
const reader = ds.readable.getReader();
|
|
1134
|
-
for (; ; ) {
|
|
1135
|
-
const { value, done } = await reader.read();
|
|
1136
|
-
if (done)
|
|
1137
|
-
break;
|
|
1138
|
-
chunks.push(value);
|
|
1139
|
-
length += value.byteLength;
|
|
1140
|
-
if (maxLength !== Infinity && length > maxLength) {
|
|
1141
|
-
throw new JWEInvalid("Decompressed plaintext exceeded the configured limit");
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
return concat(...chunks);
|
|
1145
|
-
}
|
|
1146
|
-
|
|
1147
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/jwe_decrypt.js
|
|
1148
|
-
function snapshotSharedJWE(jwe) {
|
|
1149
|
-
const { aad, ciphertext, iv, protected: encodedProtected, tag: tag2, unprotected: unprotected2 } = jwe;
|
|
1150
|
-
if (iv !== void 0 && typeof iv !== "string") {
|
|
1151
|
-
throw new JWEInvalid("JWE Initialization Vector incorrect type");
|
|
1152
|
-
}
|
|
1153
|
-
if (typeof ciphertext !== "string") {
|
|
1154
|
-
throw new JWEInvalid("JWE Ciphertext missing or incorrect type");
|
|
1155
|
-
}
|
|
1156
|
-
if (tag2 !== void 0 && typeof tag2 !== "string") {
|
|
1157
|
-
throw new JWEInvalid("JWE Authentication Tag incorrect type");
|
|
1158
|
-
}
|
|
1159
|
-
if (encodedProtected !== void 0 && typeof encodedProtected !== "string") {
|
|
1160
|
-
throw new JWEInvalid("JWE Protected Header incorrect type");
|
|
1161
|
-
}
|
|
1162
|
-
if (aad !== void 0 && (typeof aad !== "string" || !aad)) {
|
|
1163
|
-
throw new JWEInvalid("JWE AAD incorrect type");
|
|
1164
|
-
}
|
|
1165
|
-
if (unprotected2 !== void 0 && !isObject(unprotected2)) {
|
|
1166
|
-
throw new JWEInvalid("JWE Shared Unprotected Header incorrect type");
|
|
1167
|
-
}
|
|
1168
|
-
return {
|
|
1169
|
-
aad,
|
|
1170
|
-
ciphertext,
|
|
1171
|
-
iv,
|
|
1172
|
-
protected: encodedProtected,
|
|
1173
|
-
tag: tag2,
|
|
1174
|
-
unprotected: unprotected2 === void 0 ? void 0 : { ...unprotected2 }
|
|
1175
|
-
};
|
|
1176
|
-
}
|
|
1177
|
-
function snapshotRecipientJWE(recipient) {
|
|
1178
|
-
let header;
|
|
1179
|
-
let headerAlg;
|
|
1180
|
-
try {
|
|
1181
|
-
const { header: inputHeader } = recipient;
|
|
1182
|
-
if (isObject(inputHeader)) {
|
|
1183
|
-
headerAlg = inputHeader.alg;
|
|
1184
|
-
const parameters = Object.keys(inputHeader);
|
|
1185
|
-
if (!parameters.includes("alg"))
|
|
1186
|
-
headerAlg = void 0;
|
|
1187
|
-
header = Object.fromEntries(parameters.map((parameter) => [
|
|
1188
|
-
parameter,
|
|
1189
|
-
parameter === "alg" ? headerAlg : inputHeader[parameter]
|
|
1190
|
-
]));
|
|
1191
|
-
} else {
|
|
1192
|
-
header = inputHeader;
|
|
1193
|
-
}
|
|
1194
|
-
} catch (error) {
|
|
1195
|
-
return [void 0, headerAlg, error];
|
|
1196
|
-
}
|
|
1197
|
-
try {
|
|
1198
|
-
const { encrypted_key: encryptedKey } = recipient;
|
|
1199
|
-
return [{ encrypted_key: encryptedKey, header }, headerAlg];
|
|
1200
|
-
} catch (error) {
|
|
1201
|
-
return [void 0, headerAlg, error];
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
function checkRecipient(jwe) {
|
|
1205
|
-
const { encrypted_key: encryptedKey, header } = jwe;
|
|
1206
|
-
if (encryptedKey !== void 0 && typeof encryptedKey !== "string") {
|
|
1207
|
-
throw new JWEInvalid("JWE Encrypted Key incorrect type");
|
|
1208
|
-
}
|
|
1209
|
-
if (header !== void 0) {
|
|
1210
|
-
if (!isObject(header)) {
|
|
1211
|
-
throw new JWEInvalid("JWE Per-Recipient Unprotected Header incorrect type");
|
|
1212
|
-
}
|
|
1213
|
-
}
|
|
1214
|
-
if (jwe.protected === void 0 && header === void 0 && jwe.unprotected === void 0) {
|
|
1215
|
-
throw new JWEInvalid("JOSE Header missing");
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
function shareJWE(jwe) {
|
|
1219
|
-
const { protected: encodedProtected, ciphertext, iv, tag: tag2, aad } = jwe;
|
|
1220
|
-
let parsedProt;
|
|
1221
|
-
if (encodedProtected !== void 0) {
|
|
1222
|
-
parsedProt = parseJoseHeader(encodedProtected, JWEInvalid, "JWE Protected Header is invalid");
|
|
1223
|
-
}
|
|
1224
|
-
const protectedHeader = encodedProtected !== void 0 ? encode(encodedProtected) : new Uint8Array();
|
|
1225
|
-
return [
|
|
1226
|
-
parsedProt,
|
|
1227
|
-
decodeBase64url(ciphertext, "ciphertext", JWEInvalid),
|
|
1228
|
-
iv !== void 0 ? decodeBase64url(iv, "iv", JWEInvalid) : void 0,
|
|
1229
|
-
tag2 !== void 0 ? decodeBase64url(tag2, "tag", JWEInvalid) : void 0,
|
|
1230
|
-
aad !== void 0 ? concat(protectedHeader, encode("."), encodeBase64url(aad, "aad", JWEInvalid)) : protectedHeader
|
|
1231
|
-
];
|
|
1232
|
-
}
|
|
1233
|
-
function decryptResult(jwe, decrypted) {
|
|
1234
|
-
const [plaintext, parsedProt, key, resolvedKey] = decrypted;
|
|
1235
|
-
const { protected: encodedProtected, aad, unprotected: unprotected2, header } = jwe;
|
|
1236
|
-
const result = { plaintext };
|
|
1237
|
-
if (encodedProtected !== void 0) {
|
|
1238
|
-
result.protectedHeader = parsedProt;
|
|
1239
|
-
}
|
|
1240
|
-
if (aad !== void 0) {
|
|
1241
|
-
result.additionalAuthenticatedData = decodeBase64url(aad, "aad", JWEInvalid);
|
|
1242
|
-
}
|
|
1243
|
-
if (unprotected2 !== void 0) {
|
|
1244
|
-
result.sharedUnprotectedHeader = unprotected2;
|
|
1245
|
-
}
|
|
1246
|
-
if (header !== void 0) {
|
|
1247
|
-
result.unprotectedHeader = header;
|
|
1248
|
-
}
|
|
1249
|
-
if (resolvedKey) {
|
|
1250
|
-
return { ...result, key };
|
|
1251
|
-
}
|
|
1252
|
-
return result;
|
|
1253
|
-
}
|
|
1254
|
-
function prepareDecrypt(options) {
|
|
1255
|
-
return [
|
|
1256
|
-
options && validateAlgorithms("keyManagementAlgorithms", options.keyManagementAlgorithms),
|
|
1257
|
-
options && validateAlgorithms("contentEncryptionAlgorithms", options.contentEncryptionAlgorithms),
|
|
1258
|
-
options?.crit,
|
|
1259
|
-
options?.maxPBES2Count,
|
|
1260
|
-
options?.maxDecompressedLength
|
|
1261
|
-
];
|
|
1262
|
-
}
|
|
1263
|
-
async function decryptRecipient(jwe, token, shared, key) {
|
|
1264
|
-
const [parsedProt] = token;
|
|
1265
|
-
const { header, unprotected: unprotected2 } = jwe;
|
|
1266
|
-
let joseHeader;
|
|
1267
|
-
if (header !== void 0 || unprotected2 !== void 0) {
|
|
1268
|
-
if (!isDisjoint(parsedProt, header, unprotected2)) {
|
|
1269
|
-
throw new JWEInvalid("JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint");
|
|
1270
|
-
}
|
|
1271
|
-
joseHeader = { ...parsedProt, ...header, ...unprotected2 };
|
|
1272
|
-
} else {
|
|
1273
|
-
joseHeader = parsedProt ?? {};
|
|
1274
|
-
}
|
|
1275
|
-
return decryptRecipientCore(jwe, token, shared, key, joseHeader);
|
|
1276
|
-
}
|
|
1277
|
-
async function decryptRecipientCore(jwe, token, shared, key, joseHeader) {
|
|
1278
|
-
const [keyManagementAlgorithms, contentEncryptionAlgorithms, crit, maxPBES2Count, maxDecompressedLength] = shared;
|
|
1279
|
-
const [parsedProt, ciphertext, iv, tag2, additionalData] = token;
|
|
1280
|
-
const { encrypted_key: encodedKey } = jwe;
|
|
1281
|
-
validateCrit(JWEInvalid, JWE_RECOGNIZED, crit, parsedProt, joseHeader);
|
|
1282
|
-
validateZip(joseHeader, parsedProt);
|
|
1283
|
-
const { alg, enc } = joseHeader;
|
|
1284
|
-
if (typeof alg !== "string" || !alg) {
|
|
1285
|
-
throw new JWEInvalid("missing JWE Algorithm (alg) in JWE Header");
|
|
1286
|
-
}
|
|
1287
|
-
if (typeof enc !== "string" || !enc) {
|
|
1288
|
-
throw new JWEInvalid("missing JWE Encryption Algorithm (enc) in JWE Header");
|
|
1289
|
-
}
|
|
1290
|
-
if (keyManagementAlgorithms && !keyManagementAlgorithms.has(alg) || !keyManagementAlgorithms && alg.startsWith("PBES2")) {
|
|
1291
|
-
throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
|
|
1292
|
-
}
|
|
1293
|
-
if (contentEncryptionAlgorithms && !contentEncryptionAlgorithms.has(enc)) {
|
|
1294
|
-
throw new JOSEAlgNotAllowed('"enc" (Encryption Algorithm) Header Parameter value not allowed');
|
|
1295
|
-
}
|
|
1296
|
-
const encEntry = jweEncryption(enc);
|
|
1297
|
-
let encryptedKey;
|
|
1298
|
-
if (encodedKey !== void 0) {
|
|
1299
|
-
encryptedKey = decodeBase64url(encodedKey, "encrypted_key", JWEInvalid);
|
|
1300
|
-
}
|
|
1301
|
-
let resolvedKey = false;
|
|
1302
|
-
if (typeof key === "function") {
|
|
1303
|
-
key = await key(parsedProt, jwe);
|
|
1304
|
-
resolvedKey = true;
|
|
1305
|
-
}
|
|
1306
|
-
const algEntry = jweAlgorithm(alg);
|
|
1307
|
-
const k = await prepareKey(alg === "dir" ? encEntry : algEntry, key, "decrypt");
|
|
1308
|
-
let cek;
|
|
1309
|
-
try {
|
|
1310
|
-
cek = await decryptKeyManagement(alg, encEntry, k, encryptedKey, joseHeader, maxPBES2Count);
|
|
1311
|
-
if (encodedKey !== void 0 && cek instanceof Uint8Array && cek.byteLength << 3 !== encEntry.cekBits) {
|
|
1312
|
-
cek = generateCek(encEntry);
|
|
1313
|
-
}
|
|
1314
|
-
} catch (err) {
|
|
1315
|
-
if (err instanceof TypeError || err instanceof JWEInvalid || err instanceof JOSENotSupported) {
|
|
1316
|
-
throw err;
|
|
1317
|
-
}
|
|
1318
|
-
cek = generateCek(encEntry);
|
|
1319
|
-
}
|
|
1320
|
-
let plaintext = await decrypt(encEntry, cek, ciphertext, iv, tag2, additionalData);
|
|
1321
|
-
if (joseHeader.zip === "DEF") {
|
|
1322
|
-
const decompressionLimit = maxDecompressedLength ?? 25e4;
|
|
1323
|
-
if (decompressionLimit === 0) {
|
|
1324
|
-
throw new JOSENotSupported('JWE "zip" (Compression Algorithm) Header Parameter is not supported.');
|
|
1325
|
-
}
|
|
1326
|
-
if (decompressionLimit !== Infinity && (!Number.isSafeInteger(decompressionLimit) || decompressionLimit < 1)) {
|
|
1327
|
-
throw new TypeError("maxDecompressedLength must be 0, a positive safe integer, or Infinity");
|
|
1328
|
-
}
|
|
1329
|
-
plaintext = await decompress(plaintext, decompressionLimit).catch((cause) => {
|
|
1330
|
-
if (cause instanceof JWEInvalid)
|
|
1331
|
-
throw cause;
|
|
1332
|
-
throw new JWEInvalid("Failed to decompress plaintext", { cause });
|
|
1333
|
-
});
|
|
1334
|
-
}
|
|
1335
|
-
return [plaintext, parsedProt, k, resolvedKey];
|
|
1336
|
-
}
|
|
1337
|
-
async function decryptJWE(jwe, shared, key) {
|
|
1338
|
-
return decryptRecipient(jwe, shareJWE(jwe), shared, key);
|
|
1339
|
-
}
|
|
1340
|
-
async function decryptCompact(jwe, shared, key) {
|
|
1341
|
-
if (jwe instanceof Uint8Array) {
|
|
1342
|
-
jwe = decoder.decode(jwe);
|
|
1343
|
-
}
|
|
1344
|
-
if (typeof jwe !== "string") {
|
|
1345
|
-
throw new JWEInvalid("Compact JWE must be a string or Uint8Array");
|
|
1346
|
-
}
|
|
1347
|
-
const { 0: protectedHeader, 1: encryptedKey, 2: iv, 3: ciphertext, 4: tag2, length } = jwe.split(".");
|
|
1348
|
-
if (length !== 5) {
|
|
1349
|
-
throw new JWEInvalid("Invalid Compact JWE");
|
|
1350
|
-
}
|
|
1351
|
-
const flattened = {
|
|
1352
|
-
ciphertext,
|
|
1353
|
-
iv: iv || void 0,
|
|
1354
|
-
protected: protectedHeader,
|
|
1355
|
-
tag: tag2 || void 0,
|
|
1356
|
-
encrypted_key: encryptedKey || void 0
|
|
1357
|
-
};
|
|
1358
|
-
const parsedProt = parseJoseHeader(protectedHeader, JWEInvalid, "JWE Protected Header is invalid");
|
|
1359
|
-
const protectedBytes = encode(protectedHeader);
|
|
1360
|
-
const token = [
|
|
1361
|
-
parsedProt,
|
|
1362
|
-
decodeBase64url(ciphertext, "ciphertext", JWEInvalid),
|
|
1363
|
-
iv ? decodeBase64url(iv, "iv", JWEInvalid) : void 0,
|
|
1364
|
-
tag2 ? decodeBase64url(tag2, "tag", JWEInvalid) : void 0,
|
|
1365
|
-
protectedBytes
|
|
1366
|
-
];
|
|
1367
|
-
return decryptRecipientCore(flattened, token, shared, key, parsedProt);
|
|
1368
|
-
}
|
|
1369
|
-
|
|
1370
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/jwe/compact/decrypt.js
|
|
1371
|
-
async function compactDecrypt(jwe, key, options) {
|
|
1372
|
-
const decrypted = await decryptCompact(jwe, prepareDecrypt(options), key);
|
|
1373
|
-
const result = { plaintext: decrypted[0], protectedHeader: decrypted[1] };
|
|
1374
|
-
if (typeof key === "function") {
|
|
1375
|
-
return { ...result, key: decrypted[2] };
|
|
1376
|
-
}
|
|
1377
|
-
return result;
|
|
1378
|
-
}
|
|
1379
|
-
|
|
1380
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js
|
|
1381
|
-
async function flattenedDecrypt(jwe, key, options) {
|
|
1382
|
-
if (!isObject(jwe)) {
|
|
1383
|
-
throw new JWEInvalid("Flattened JWE must be an object");
|
|
1384
|
-
}
|
|
1385
|
-
const shared = snapshotSharedJWE(jwe);
|
|
1386
|
-
const [recipient, , error] = snapshotRecipientJWE(jwe);
|
|
1387
|
-
if (!recipient)
|
|
1388
|
-
throw error;
|
|
1389
|
-
const snapshot = { ...shared, ...recipient };
|
|
1390
|
-
checkRecipient(snapshot);
|
|
1391
|
-
return decryptResult(snapshot, await decryptJWE(snapshot, prepareDecrypt(options), key));
|
|
1392
|
-
}
|
|
1393
|
-
|
|
1394
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/jwe/general/decrypt.js
|
|
1395
|
-
async function generalDecrypt(jwe, key, options) {
|
|
1396
|
-
if (!isObject(jwe)) {
|
|
1397
|
-
throw new JWEInvalid("General JWE must be an object");
|
|
1398
|
-
}
|
|
1399
|
-
const inputRecipients = jwe.recipients;
|
|
1400
|
-
if (!Array.isArray(inputRecipients)) {
|
|
1401
|
-
throw new JWEInvalid("JWE Recipients missing or incorrect type");
|
|
1402
|
-
}
|
|
1403
|
-
const recipients = Array.from(inputRecipients);
|
|
1404
|
-
if (!recipients.every(isObject)) {
|
|
1405
|
-
throw new JWEInvalid("JWE Recipients missing or incorrect type");
|
|
1406
|
-
}
|
|
1407
|
-
if (!recipients.length) {
|
|
1408
|
-
throw new JWEInvalid("JWE Recipients has no members");
|
|
1409
|
-
}
|
|
1410
|
-
let shared;
|
|
1411
|
-
let sharedJwe;
|
|
1412
|
-
let token;
|
|
1413
|
-
try {
|
|
1414
|
-
shared = prepareDecrypt(options);
|
|
1415
|
-
sharedJwe = snapshotSharedJWE(jwe);
|
|
1416
|
-
token = shareJWE(sharedJwe);
|
|
1417
|
-
} catch {
|
|
1418
|
-
throw new JWEDecryptionFailed();
|
|
1419
|
-
}
|
|
1420
|
-
const recipientSnapshots = recipients.map((recipient) => snapshotRecipientJWE(recipient));
|
|
1421
|
-
if (recipients.length > 1) {
|
|
1422
|
-
for (const [, headerAlg] of recipientSnapshots) {
|
|
1423
|
-
const alg = token[0]?.alg ?? headerAlg ?? sharedJwe.unprotected?.alg;
|
|
1424
|
-
if (alg === "dir" || alg === "ECDH-ES") {
|
|
1425
|
-
throw new JWEInvalid(`"${alg}" alg may only have a single recipient`);
|
|
1426
|
-
}
|
|
1427
|
-
}
|
|
1428
|
-
}
|
|
1429
|
-
for (const [recipient] of recipientSnapshots) {
|
|
1430
|
-
if (!recipient)
|
|
1431
|
-
continue;
|
|
1432
|
-
try {
|
|
1433
|
-
const flattened = { ...sharedJwe, ...recipient };
|
|
1434
|
-
checkRecipient(flattened);
|
|
1435
|
-
return decryptResult(flattened, await decryptRecipient(flattened, token, shared, key));
|
|
1436
|
-
} catch {
|
|
1437
|
-
}
|
|
1438
|
-
}
|
|
1439
|
-
throw new JWEDecryptionFailed();
|
|
1440
|
-
}
|
|
1441
|
-
|
|
1442
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/jwe_encrypt.js
|
|
1443
|
-
function checkDisjoint(protectedHeader, unprotectedHeader, sharedUnprotectedHeader) {
|
|
1444
|
-
if (!isDisjoint(protectedHeader, unprotectedHeader, sharedUnprotectedHeader)) {
|
|
1445
|
-
throw new JWEInvalid("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");
|
|
1446
|
-
}
|
|
1447
|
-
}
|
|
1448
|
-
function checkEncryptHeaders(input) {
|
|
1449
|
-
let [, protectedHeader, unprotectedHeader, sharedUnprotectedHeader, aad, cek, iv, keyManagementParameters, crit] = input;
|
|
1450
|
-
if (aad !== void 0) {
|
|
1451
|
-
assertUint8Array(aad, "JWE Additional Authenticated Data");
|
|
1452
|
-
}
|
|
1453
|
-
if (cek !== void 0) {
|
|
1454
|
-
assertUint8Array(cek, "JWE Content Encryption Key");
|
|
1455
|
-
}
|
|
1456
|
-
if (iv !== void 0) {
|
|
1457
|
-
assertUint8Array(iv, "JWE Initialization Vector");
|
|
1458
|
-
}
|
|
1459
|
-
if (protectedHeader !== void 0) {
|
|
1460
|
-
protectedHeader = serializeJoseHeader(JWEInvalid, protectedHeader)[0];
|
|
1461
|
-
input[1] = protectedHeader;
|
|
1462
|
-
}
|
|
1463
|
-
if (unprotectedHeader !== void 0) {
|
|
1464
|
-
unprotectedHeader = serializeJoseHeader(JWEInvalid, unprotectedHeader)[0];
|
|
1465
|
-
input[2] = unprotectedHeader;
|
|
1466
|
-
}
|
|
1467
|
-
if (sharedUnprotectedHeader !== void 0) {
|
|
1468
|
-
sharedUnprotectedHeader = serializeJoseHeader(JWEInvalid, sharedUnprotectedHeader)[0];
|
|
1469
|
-
input[3] = sharedUnprotectedHeader;
|
|
1470
|
-
}
|
|
1471
|
-
if (keyManagementParameters !== void 0 && !isObject(keyManagementParameters)) {
|
|
1472
|
-
throw new TypeError("JWE Key Management Parameters must be an object");
|
|
1473
|
-
}
|
|
1474
|
-
checkDisjoint(protectedHeader, unprotectedHeader, sharedUnprotectedHeader);
|
|
1475
|
-
const joseHeader = {
|
|
1476
|
-
...protectedHeader,
|
|
1477
|
-
...unprotectedHeader,
|
|
1478
|
-
...sharedUnprotectedHeader
|
|
1479
|
-
};
|
|
1480
|
-
validateCritDuplicates(JWEInvalid, protectedHeader);
|
|
1481
|
-
validateCrit(JWEInvalid, JWE_RECOGNIZED, crit, protectedHeader, joseHeader);
|
|
1482
|
-
validateZip(joseHeader, protectedHeader);
|
|
1483
|
-
const { alg, enc } = joseHeader;
|
|
1484
|
-
if (typeof alg !== "string" || !alg) {
|
|
1485
|
-
throw new JWEInvalid('JWE "alg" (Algorithm) Header Parameter missing or invalid');
|
|
1486
|
-
}
|
|
1487
|
-
if (typeof enc !== "string" || !enc) {
|
|
1488
|
-
throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');
|
|
1489
|
-
}
|
|
1490
|
-
return [joseHeader, alg, enc, jweEncryption(enc)];
|
|
1491
|
-
}
|
|
1492
|
-
async function encryptJWE(input, checked, key) {
|
|
1493
|
-
const [joseHeader, alg, , encEntry] = checked;
|
|
1494
|
-
const [inputPlaintext, inputProtectedHeader, inputUnprotectedHeader, sharedUnprotectedHeader, aad, providedCek, inputIv, keyManagementParameters, , unprotectedParameters] = input;
|
|
1495
|
-
let protectedHeader = inputProtectedHeader;
|
|
1496
|
-
let unprotectedHeader = inputUnprotectedHeader;
|
|
1497
|
-
if (providedCek && (alg === "dir" || alg === "ECDH-ES")) {
|
|
1498
|
-
throw new TypeError(`setContentEncryptionKey cannot be called with JWE "alg" (Algorithm) Header ${alg}`);
|
|
1499
|
-
}
|
|
1500
|
-
const algEntry = jweAlgorithm(alg);
|
|
1501
|
-
const k = await prepareKey(alg === "dir" ? encEntry : algEntry, key, "encrypt");
|
|
1502
|
-
const [cek, encryptedKey, parameters] = await encryptKeyManagement(alg, encEntry, k, providedCek, keyManagementParameters);
|
|
1503
|
-
if (parameters) {
|
|
1504
|
-
if (unprotectedParameters) {
|
|
1505
|
-
unprotectedHeader = unprotectedHeader ? { ...unprotectedHeader, ...parameters } : parameters;
|
|
1506
|
-
} else {
|
|
1507
|
-
protectedHeader = protectedHeader ? { ...protectedHeader, ...parameters } : parameters;
|
|
1508
|
-
}
|
|
1509
|
-
checkDisjoint(protectedHeader, unprotectedHeader, sharedUnprotectedHeader);
|
|
1510
|
-
}
|
|
1511
|
-
let protectedHeaderS;
|
|
1512
|
-
let protectedHeaderB;
|
|
1513
|
-
if (protectedHeader) {
|
|
1514
|
-
protectedHeaderS = encode2(JSON.stringify(protectedHeader));
|
|
1515
|
-
protectedHeaderB = encode(protectedHeaderS);
|
|
1516
|
-
} else {
|
|
1517
|
-
protectedHeaderS = "";
|
|
1518
|
-
protectedHeaderB = new Uint8Array();
|
|
1519
|
-
}
|
|
1520
|
-
let additionalData;
|
|
1521
|
-
let aadMember;
|
|
1522
|
-
if (aad?.byteLength) {
|
|
1523
|
-
aadMember = encode2(aad);
|
|
1524
|
-
additionalData = concat(protectedHeaderB, encode("."), encode(aadMember));
|
|
1525
|
-
} else {
|
|
1526
|
-
additionalData = protectedHeaderB;
|
|
1527
|
-
}
|
|
1528
|
-
let plaintext = inputPlaintext;
|
|
1529
|
-
if (joseHeader.zip === "DEF") {
|
|
1530
|
-
plaintext = await compress(plaintext).catch((cause) => {
|
|
1531
|
-
throw new JWEInvalid("Failed to compress plaintext", { cause });
|
|
1532
|
-
});
|
|
1533
|
-
}
|
|
1534
|
-
const { ciphertext, tag: tag2, iv } = await encrypt(encEntry, plaintext, cek, inputIv, additionalData);
|
|
1535
|
-
const jwe = {
|
|
1536
|
-
ciphertext: encode2(ciphertext)
|
|
1537
|
-
};
|
|
1538
|
-
if (iv) {
|
|
1539
|
-
jwe.iv = encode2(iv);
|
|
1540
|
-
}
|
|
1541
|
-
if (tag2) {
|
|
1542
|
-
jwe.tag = encode2(tag2);
|
|
1543
|
-
}
|
|
1544
|
-
if (encryptedKey) {
|
|
1545
|
-
jwe.encrypted_key = encode2(encryptedKey);
|
|
1546
|
-
}
|
|
1547
|
-
if (aadMember) {
|
|
1548
|
-
jwe.aad = aadMember;
|
|
1549
|
-
}
|
|
1550
|
-
if (protectedHeader) {
|
|
1551
|
-
jwe.protected = protectedHeaderS;
|
|
1552
|
-
}
|
|
1553
|
-
if (sharedUnprotectedHeader) {
|
|
1554
|
-
jwe.unprotected = sharedUnprotectedHeader;
|
|
1555
|
-
}
|
|
1556
|
-
if (unprotectedHeader) {
|
|
1557
|
-
jwe.header = unprotectedHeader;
|
|
1558
|
-
}
|
|
1559
|
-
return jwe;
|
|
1560
|
-
}
|
|
1561
|
-
async function createJWE(input, key, options) {
|
|
1562
|
-
if (!input[1] && !input[2] && !input[3]) {
|
|
1563
|
-
throw new JWEInvalid("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");
|
|
1564
|
-
}
|
|
1565
|
-
if (options !== void 0) {
|
|
1566
|
-
input[8] = options?.crit;
|
|
1567
|
-
input[9] = options ? unprotected in options : false;
|
|
1568
|
-
}
|
|
1569
|
-
return encryptJWE(input, checkEncryptHeaders(input), key);
|
|
1570
|
-
}
|
|
1571
|
-
|
|
1572
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/jwe/general/encrypt.js
|
|
1573
|
-
var IndividualRecipient = class {
|
|
1574
|
-
#parent;
|
|
1575
|
-
state;
|
|
1576
|
-
constructor(enc, key, crit) {
|
|
1577
|
-
this.#parent = enc;
|
|
1578
|
-
this.state = [void 0, void 0, key, crit];
|
|
1579
|
-
}
|
|
1580
|
-
setUnprotectedHeader(unprotectedHeader) {
|
|
1581
|
-
assertNotSet(this.state[0], "setUnprotectedHeader");
|
|
1582
|
-
this.state[0] = unprotectedHeader;
|
|
1583
|
-
return this;
|
|
1584
|
-
}
|
|
1585
|
-
setKeyManagementParameters(parameters) {
|
|
1586
|
-
assertNotSet(this.state[1], "setKeyManagementParameters");
|
|
1587
|
-
this.state[1] = parameters;
|
|
1588
|
-
return this;
|
|
1589
|
-
}
|
|
1590
|
-
addRecipient(...args) {
|
|
1591
|
-
return this.#parent.addRecipient(...args);
|
|
1592
|
-
}
|
|
1593
|
-
encrypt(...args) {
|
|
1594
|
-
return this.#parent.encrypt(...args);
|
|
1595
|
-
}
|
|
1596
|
-
done() {
|
|
1597
|
-
return this.#parent;
|
|
1598
|
-
}
|
|
1599
|
-
};
|
|
1600
|
-
function copyOptionalMembers(flattened, jwe, recipient) {
|
|
1601
|
-
const { aad, protected: protectedHeader, unprotected: unprotected2, header } = flattened;
|
|
1602
|
-
if (aad)
|
|
1603
|
-
jwe.aad = aad;
|
|
1604
|
-
if (protectedHeader)
|
|
1605
|
-
jwe.protected = protectedHeader;
|
|
1606
|
-
if (unprotected2)
|
|
1607
|
-
jwe.unprotected = unprotected2;
|
|
1608
|
-
if (header)
|
|
1609
|
-
recipient.header = header;
|
|
1610
|
-
}
|
|
1611
|
-
var GeneralEncrypt = class {
|
|
1612
|
-
#plaintext;
|
|
1613
|
-
#recipients = [];
|
|
1614
|
-
#protectedHeader;
|
|
1615
|
-
#unprotectedHeader;
|
|
1616
|
-
#aad;
|
|
1617
|
-
constructor(plaintext) {
|
|
1618
|
-
this.#plaintext = plaintext;
|
|
1619
|
-
}
|
|
1620
|
-
addRecipient(key, options) {
|
|
1621
|
-
const recipient = new IndividualRecipient(this, key, options?.crit);
|
|
1622
|
-
this.#recipients.push(recipient);
|
|
1623
|
-
return recipient;
|
|
1624
|
-
}
|
|
1625
|
-
setProtectedHeader(protectedHeader) {
|
|
1626
|
-
assertNotSet(this.#protectedHeader, "setProtectedHeader");
|
|
1627
|
-
this.#protectedHeader = protectedHeader;
|
|
1628
|
-
return this;
|
|
1629
|
-
}
|
|
1630
|
-
setSharedUnprotectedHeader(sharedUnprotectedHeader) {
|
|
1631
|
-
assertNotSet(this.#unprotectedHeader, "setSharedUnprotectedHeader");
|
|
1632
|
-
this.#unprotectedHeader = sharedUnprotectedHeader;
|
|
1633
|
-
return this;
|
|
1634
|
-
}
|
|
1635
|
-
setAdditionalAuthenticatedData(aad) {
|
|
1636
|
-
this.#aad = aad;
|
|
1637
|
-
return this;
|
|
1638
|
-
}
|
|
1639
|
-
async encrypt() {
|
|
1640
|
-
if (!this.#recipients.length) {
|
|
1641
|
-
throw new JWEInvalid("at least one recipient must be added");
|
|
1642
|
-
}
|
|
1643
|
-
assertUint8Array(this.#plaintext, "plaintext");
|
|
1644
|
-
if (this.#recipients.length === 1) {
|
|
1645
|
-
const [unprotectedHeader, keyManagementParameters, key, crit] = this.#recipients[0].state;
|
|
1646
|
-
const flattened = await createJWE([
|
|
1647
|
-
this.#plaintext,
|
|
1648
|
-
this.#protectedHeader,
|
|
1649
|
-
unprotectedHeader,
|
|
1650
|
-
this.#unprotectedHeader,
|
|
1651
|
-
this.#aad,
|
|
1652
|
-
void 0,
|
|
1653
|
-
void 0,
|
|
1654
|
-
keyManagementParameters,
|
|
1655
|
-
crit,
|
|
1656
|
-
false
|
|
1657
|
-
], key);
|
|
1658
|
-
const jwe2 = {
|
|
1659
|
-
ciphertext: flattened.ciphertext,
|
|
1660
|
-
iv: flattened.iv,
|
|
1661
|
-
recipients: [{}],
|
|
1662
|
-
tag: flattened.tag
|
|
1663
|
-
};
|
|
1664
|
-
if (flattened.encrypted_key)
|
|
1665
|
-
jwe2.recipients[0].encrypted_key = flattened.encrypted_key;
|
|
1666
|
-
copyOptionalMembers(flattened, jwe2, jwe2.recipients[0]);
|
|
1667
|
-
return jwe2;
|
|
1668
|
-
}
|
|
1669
|
-
let enc;
|
|
1670
|
-
let protectedHeader = this.#protectedHeader;
|
|
1671
|
-
let sharedUnprotectedHeader = this.#unprotectedHeader;
|
|
1672
|
-
const inputs = [];
|
|
1673
|
-
const checked = [];
|
|
1674
|
-
for (let i = 0; i < this.#recipients.length; i++) {
|
|
1675
|
-
const recipient = this.#recipients[i];
|
|
1676
|
-
const [unprotectedHeader, keyManagementParameters, , crit] = recipient.state;
|
|
1677
|
-
const input = [
|
|
1678
|
-
this.#plaintext,
|
|
1679
|
-
protectedHeader,
|
|
1680
|
-
unprotectedHeader,
|
|
1681
|
-
sharedUnprotectedHeader,
|
|
1682
|
-
this.#aad,
|
|
1683
|
-
void 0,
|
|
1684
|
-
void 0,
|
|
1685
|
-
keyManagementParameters,
|
|
1686
|
-
crit,
|
|
1687
|
-
true
|
|
1688
|
-
];
|
|
1689
|
-
const headers = checkEncryptHeaders(input);
|
|
1690
|
-
inputs.push(input);
|
|
1691
|
-
checked.push(headers);
|
|
1692
|
-
if (i === 0) {
|
|
1693
|
-
protectedHeader = input[1];
|
|
1694
|
-
sharedUnprotectedHeader = input[3];
|
|
1695
|
-
}
|
|
1696
|
-
if (headers[1] === "dir" || headers[1] === "ECDH-ES") {
|
|
1697
|
-
throw new JWEInvalid(`"${headers[1]}" alg may only have a single recipient`);
|
|
1698
|
-
}
|
|
1699
|
-
if (!enc) {
|
|
1700
|
-
enc = headers[2];
|
|
1701
|
-
} else if (enc !== headers[2]) {
|
|
1702
|
-
throw new JWEInvalid('JWE "enc" (Encryption Algorithm) Header Parameter must be the same for all recipients');
|
|
1703
|
-
}
|
|
1704
|
-
}
|
|
1705
|
-
const cek = generateCek(checked[0][3]);
|
|
1706
|
-
const jwe = {
|
|
1707
|
-
ciphertext: "",
|
|
1708
|
-
recipients: []
|
|
1709
|
-
};
|
|
1710
|
-
for (let i = 0; i < this.#recipients.length; i++) {
|
|
1711
|
-
const recipient = this.#recipients[i];
|
|
1712
|
-
const [, keyManagementParameters, key] = recipient.state;
|
|
1713
|
-
const target = {};
|
|
1714
|
-
jwe.recipients.push(target);
|
|
1715
|
-
if (i === 0) {
|
|
1716
|
-
inputs[0][5] = cek;
|
|
1717
|
-
const flattened = await encryptJWE(inputs[0], checked[0], key);
|
|
1718
|
-
jwe.ciphertext = flattened.ciphertext;
|
|
1719
|
-
jwe.iv = flattened.iv;
|
|
1720
|
-
jwe.tag = flattened.tag;
|
|
1721
|
-
target.encrypted_key = flattened.encrypted_key;
|
|
1722
|
-
copyOptionalMembers(flattened, jwe, target);
|
|
1723
|
-
continue;
|
|
1724
|
-
}
|
|
1725
|
-
const [, alg, , encEntry] = checked[i];
|
|
1726
|
-
const unprotectedHeader = inputs[i][2];
|
|
1727
|
-
const k = await prepareKey(jweAlgorithm(alg), key, "encrypt");
|
|
1728
|
-
const [, encryptedKey, parameters] = await encryptKeyManagement(alg, encEntry, k, cek, keyManagementParameters);
|
|
1729
|
-
target.encrypted_key = encode2(encryptedKey);
|
|
1730
|
-
if (unprotectedHeader || parameters) {
|
|
1731
|
-
const header = { ...unprotectedHeader, ...parameters };
|
|
1732
|
-
if (parameters)
|
|
1733
|
-
checkDisjoint(inputs[i][1], header, inputs[i][3]);
|
|
1734
|
-
target.header = header;
|
|
1735
|
-
}
|
|
1736
|
-
}
|
|
1737
|
-
return jwe;
|
|
1738
|
-
}
|
|
1739
|
-
};
|
|
1740
|
-
|
|
1741
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/signing.js
|
|
1742
|
-
async function getSigKey(entry, key, usage) {
|
|
1743
|
-
if (key instanceof Uint8Array) {
|
|
1744
|
-
return crypto.subtle.importKey("raw", key, entry.subtle, false, [
|
|
1745
|
-
usage
|
|
1746
|
-
]);
|
|
1747
|
-
}
|
|
1748
|
-
checkCryptoKey(key, entry.subtle, usage);
|
|
1749
|
-
if (entry.minRsaBits)
|
|
1750
|
-
checkModulusLength(entry.alg, key);
|
|
1751
|
-
return key;
|
|
1752
|
-
}
|
|
1753
|
-
async function sign(entry, key, data) {
|
|
1754
|
-
const cryptoKey = await getSigKey(entry, key, "sign");
|
|
1755
|
-
const signature = await crypto.subtle.sign(entry.signing, cryptoKey, data);
|
|
1756
|
-
return new Uint8Array(signature);
|
|
1757
|
-
}
|
|
1758
|
-
async function verify(entry, key, signature, data) {
|
|
1759
|
-
const cryptoKey = await getSigKey(entry, key, "verify");
|
|
1760
|
-
try {
|
|
1761
|
-
return await crypto.subtle.verify(entry.signing, cryptoKey, signature, data);
|
|
1762
|
-
} catch {
|
|
1763
|
-
return false;
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
|
|
1767
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/jws_algorithms.js
|
|
1768
|
-
var sig = [["verify"], ["sign"]];
|
|
1769
|
-
function hmac(bits) {
|
|
1770
|
-
const subtle = { name: "HMAC", hash: `SHA-${bits}` };
|
|
1771
|
-
return { kty: ["oct"], secret: true, subtle, signing: subtle, usages: sig };
|
|
1772
|
-
}
|
|
1773
|
-
function rsa(bits, saltLength) {
|
|
1774
|
-
const name = saltLength ? "RSA-PSS" : "RSASSA-PKCS1-v1_5";
|
|
1775
|
-
const subtle = { name, hash: `SHA-${bits}` };
|
|
1776
|
-
return {
|
|
1777
|
-
kty: ["RSA"],
|
|
1778
|
-
subtle,
|
|
1779
|
-
signing: saltLength ? { ...subtle, saltLength } : subtle,
|
|
1780
|
-
usages: sig,
|
|
1781
|
-
minRsaBits: 2048
|
|
1782
|
-
};
|
|
1783
|
-
}
|
|
1784
|
-
function ecdsa(crv, bits) {
|
|
1785
|
-
return {
|
|
1786
|
-
kty: ["EC"],
|
|
1787
|
-
crv,
|
|
1788
|
-
subtle: { name: "ECDSA", namedCurve: crv },
|
|
1789
|
-
signing: { name: "ECDSA", hash: `SHA-${bits}` },
|
|
1790
|
-
usages: sig
|
|
1791
|
-
};
|
|
1792
|
-
}
|
|
1793
|
-
function eddsa() {
|
|
1794
|
-
const subtle = { name: "Ed25519" };
|
|
1795
|
-
return {
|
|
1796
|
-
kty: ["OKP"],
|
|
1797
|
-
crv: "Ed25519",
|
|
1798
|
-
subtle,
|
|
1799
|
-
signing: subtle,
|
|
1800
|
-
usages: sig
|
|
1801
|
-
};
|
|
1802
|
-
}
|
|
1803
|
-
function mldsa(bits) {
|
|
1804
|
-
const name = `ML-DSA-${bits}`;
|
|
1805
|
-
const subtle = { name };
|
|
1806
|
-
return {
|
|
1807
|
-
kty: ["AKP"],
|
|
1808
|
-
subtle,
|
|
1809
|
-
signing: subtle,
|
|
1810
|
-
usages: sig
|
|
1811
|
-
};
|
|
1812
|
-
}
|
|
1813
|
-
var JWS = table({
|
|
1814
|
-
HS256: hmac(256),
|
|
1815
|
-
HS384: hmac(384),
|
|
1816
|
-
HS512: hmac(512),
|
|
1817
|
-
RS256: rsa(256),
|
|
1818
|
-
RS384: rsa(384),
|
|
1819
|
-
RS512: rsa(512),
|
|
1820
|
-
PS256: rsa(256, 32),
|
|
1821
|
-
PS384: rsa(384, 48),
|
|
1822
|
-
PS512: rsa(512, 64),
|
|
1823
|
-
ES256: ecdsa("P-256", 256),
|
|
1824
|
-
ES384: ecdsa("P-384", 384),
|
|
1825
|
-
ES512: ecdsa("P-521", 512),
|
|
1826
|
-
EdDSA: eddsa(),
|
|
1827
|
-
Ed25519: eddsa(),
|
|
1828
|
-
"ML-DSA-44": mldsa(44),
|
|
1829
|
-
"ML-DSA-65": mldsa(65),
|
|
1830
|
-
"ML-DSA-87": mldsa(87)
|
|
1831
|
-
});
|
|
1832
|
-
function jwsAlgorithm(alg) {
|
|
1833
|
-
const entry = typeof alg === "string" ? JWS[alg] : void 0;
|
|
1834
|
-
if (!entry) {
|
|
1835
|
-
throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
1836
|
-
}
|
|
1837
|
-
return entry;
|
|
1838
|
-
}
|
|
1839
|
-
|
|
1840
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/jws_verify.js
|
|
1841
|
-
function snapshotJws(jws, sharedPayload) {
|
|
1842
|
-
const encodedProtected = jws.protected;
|
|
1843
|
-
const inputHeader = jws.header;
|
|
1844
|
-
const header = isObject(inputHeader) ? { ...inputHeader } : inputHeader;
|
|
1845
|
-
let payload = sharedPayload ? sharedPayload[0] : jws.payload;
|
|
1846
|
-
if (!sharedPayload && payload instanceof Uint8Array) {
|
|
1847
|
-
payload = new Uint8Array(payload);
|
|
1848
|
-
}
|
|
1849
|
-
const signature = jws.signature;
|
|
1850
|
-
const snapshot = { payload, signature };
|
|
1851
|
-
if (encodedProtected !== void 0)
|
|
1852
|
-
snapshot.protected = encodedProtected;
|
|
1853
|
-
if (inputHeader !== void 0)
|
|
1854
|
-
snapshot.header = header;
|
|
1855
|
-
return snapshot;
|
|
1856
|
-
}
|
|
1857
|
-
function verifyResult(jws, verified) {
|
|
1858
|
-
const [payload, parsedProt, , key, resolvedKey] = verified;
|
|
1859
|
-
const result = { payload };
|
|
1860
|
-
if (jws.protected !== void 0) {
|
|
1861
|
-
result.protectedHeader = parsedProt;
|
|
1862
|
-
}
|
|
1863
|
-
if (jws.header !== void 0) {
|
|
1864
|
-
result.unprotectedHeader = jws.header;
|
|
1865
|
-
}
|
|
1866
|
-
if (resolvedKey) {
|
|
1867
|
-
return { ...result, key };
|
|
1868
|
-
}
|
|
1869
|
-
return result;
|
|
1870
|
-
}
|
|
1871
|
-
function prepareVerify(options) {
|
|
1872
|
-
return [options && validateAlgorithms("algorithms", options.algorithms), options?.crit];
|
|
1873
|
-
}
|
|
1874
|
-
function parseProtectedHeader(encodedProtected, parsedProtected = encodedProtected === void 0 ? {} : parseJoseHeader(encodedProtected, JWSInvalid, "JWS Protected Header is invalid")) {
|
|
1875
|
-
return parsedProtected;
|
|
1876
|
-
}
|
|
1877
|
-
function validateJwsHeaders(parsedProt, joseHeader, shared) {
|
|
1878
|
-
const b64 = validateB64(parsedProt, validateCrit(JWSInvalid, JWS_RECOGNIZED, shared[1], parsedProt, joseHeader));
|
|
1879
|
-
const alg = joseHeader.alg;
|
|
1880
|
-
if (typeof alg !== "string" || !alg) {
|
|
1881
|
-
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
1882
|
-
}
|
|
1883
|
-
if (shared[0] && !shared[0].has(alg)) {
|
|
1884
|
-
throw new JOSEAlgNotAllowed('"alg" (Algorithm) Header Parameter value not allowed');
|
|
1885
|
-
}
|
|
1886
|
-
return [b64, alg];
|
|
1887
|
-
}
|
|
1888
|
-
function parseJwsHeaders(encodedProtected, header, shared, parsedProtected) {
|
|
1889
|
-
const parsedProt = parseProtectedHeader(encodedProtected, parsedProtected);
|
|
1890
|
-
let joseHeader;
|
|
1891
|
-
if (header !== void 0) {
|
|
1892
|
-
if (!isDisjoint(parsedProt, header)) {
|
|
1893
|
-
throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
1894
|
-
}
|
|
1895
|
-
joseHeader = { ...parsedProt, ...header };
|
|
1896
|
-
} else {
|
|
1897
|
-
joseHeader = parsedProt;
|
|
1898
|
-
}
|
|
1899
|
-
return [parsedProt, joseHeader, ...validateJwsHeaders(parsedProt, joseHeader, shared)];
|
|
1900
|
-
}
|
|
1901
|
-
function encodeJsonUnencodedPayload(payload) {
|
|
1902
|
-
const invalid2 = /[\p{Cs}\p{Cn}]/u.exec(payload)?.[0];
|
|
1903
|
-
if (invalid2 !== void 0) {
|
|
1904
|
-
throw new JWSInvalid(new RegExp("\\p{Cs}", "u").test(invalid2) ? "JWS Payload must be a well-formed Unicode string" : "JWS Payload must not contain unassigned Unicode code points");
|
|
1905
|
-
}
|
|
1906
|
-
return encoder.encode(payload);
|
|
1907
|
-
}
|
|
1908
|
-
function encodeCompactUnencodedPayload(payload) {
|
|
1909
|
-
try {
|
|
1910
|
-
return encode(payload);
|
|
1911
|
-
} catch {
|
|
1912
|
-
throw new JWSInvalid("JWS Compact Serialization payload must use only ASCII characters");
|
|
1913
|
-
}
|
|
1914
|
-
}
|
|
1915
|
-
async function verifyPrepared(jws, shared, key, encodedProtected, parsedProt, alg, signingPayload) {
|
|
1916
|
-
let resolvedKey = false;
|
|
1917
|
-
if (typeof key === "function") {
|
|
1918
|
-
key = await key(parsedProt, jws);
|
|
1919
|
-
resolvedKey = true;
|
|
1920
|
-
}
|
|
1921
|
-
const b64 = typeof signingPayload === "string";
|
|
1922
|
-
const entry = jwsAlgorithm(alg);
|
|
1923
|
-
const data = concat(encodedProtected !== void 0 ? encode(encodedProtected) : new Uint8Array(), encode("."), b64 ? shared[2] ??= encodeBase64url(signingPayload, "payload", JWSInvalid) : signingPayload);
|
|
1924
|
-
const signature = decodeBase64url(jws.signature, "signature", JWSInvalid);
|
|
1925
|
-
const k = await prepareKey(entry, key, "verify");
|
|
1926
|
-
if (!await verify(entry, k, signature, data)) {
|
|
1927
|
-
throw new JWSSignatureVerificationFailed();
|
|
1928
|
-
}
|
|
1929
|
-
const payload = b64 ? decodeBase64url(signingPayload, "payload", JWSInvalid) : signingPayload;
|
|
1930
|
-
return [payload, parsedProt, b64, k, resolvedKey];
|
|
1931
|
-
}
|
|
1932
|
-
async function verifySignature(jws, shared, key, encodeUnencodedPayload, parsedProtected) {
|
|
1933
|
-
const { protected: encodedProtected, header, payload: inputPayload } = jws;
|
|
1934
|
-
const [parsedProt, , b64, alg] = parseJwsHeaders(encodedProtected, header, shared, parsedProtected);
|
|
1935
|
-
if (b64) {
|
|
1936
|
-
if (typeof inputPayload !== "string") {
|
|
1937
|
-
throw new JWSInvalid("JWS Payload must be a string");
|
|
1938
|
-
}
|
|
1939
|
-
} else if (typeof inputPayload !== "string" && !(inputPayload instanceof Uint8Array)) {
|
|
1940
|
-
throw new JWSInvalid("JWS Payload must be a string or an Uint8Array instance");
|
|
1941
|
-
}
|
|
1942
|
-
const signingPayload = b64 || typeof inputPayload !== "string" ? inputPayload : encodeUnencodedPayload(inputPayload);
|
|
1943
|
-
return verifyPrepared(jws, shared, key, encodedProtected, parsedProt, alg, signingPayload);
|
|
1944
|
-
}
|
|
1945
|
-
async function verifyCompact(jws, shared, key) {
|
|
1946
|
-
if (jws instanceof Uint8Array) {
|
|
1947
|
-
jws = decoder.decode(jws);
|
|
1948
|
-
}
|
|
1949
|
-
if (typeof jws !== "string") {
|
|
1950
|
-
throw new JWSInvalid("Compact JWS must be a string or Uint8Array");
|
|
1951
|
-
}
|
|
1952
|
-
const { 0: protectedHeader, 1: payload, 2: signature, length } = jws.split(".");
|
|
1953
|
-
if (length !== 3) {
|
|
1954
|
-
throw new JWSInvalid("Invalid Compact JWS");
|
|
1955
|
-
}
|
|
1956
|
-
const compactJws = { payload, protected: protectedHeader, signature };
|
|
1957
|
-
const parsedProt = parseProtectedHeader(protectedHeader);
|
|
1958
|
-
const [b64, alg] = validateJwsHeaders(parsedProt, parsedProt, shared);
|
|
1959
|
-
const signingPayload = b64 ? payload : encodeCompactUnencodedPayload(payload);
|
|
1960
|
-
return verifyPrepared(compactJws, shared, key, protectedHeader, parsedProt, alg, signingPayload);
|
|
1961
|
-
}
|
|
1962
|
-
|
|
1963
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/jws/compact/verify.js
|
|
1964
|
-
async function compactVerify(jws, key, options) {
|
|
1965
|
-
const verified = await verifyCompact(jws, prepareVerify(options), key);
|
|
1966
|
-
const result = { payload: verified[0], protectedHeader: verified[1] };
|
|
1967
|
-
if (typeof key === "function") {
|
|
1968
|
-
return { ...result, key: verified[3] };
|
|
1969
|
-
}
|
|
1970
|
-
return result;
|
|
1971
|
-
}
|
|
1972
|
-
|
|
1973
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/jws/flattened/verify.js
|
|
1974
|
-
async function flattenedVerify(jws, key, options) {
|
|
1975
|
-
if (!isObject(jws)) {
|
|
1976
|
-
throw new JWSInvalid("Flattened JWS must be an object");
|
|
1977
|
-
}
|
|
1978
|
-
const snapshot = snapshotJws(jws);
|
|
1979
|
-
if (snapshot.protected === void 0 && snapshot.header === void 0) {
|
|
1980
|
-
throw new JWSInvalid('Flattened JWS must have either of the "protected" or "header" members');
|
|
1981
|
-
}
|
|
1982
|
-
if (snapshot.protected !== void 0 && typeof snapshot.protected !== "string") {
|
|
1983
|
-
throw new JWSInvalid("JWS Protected Header incorrect type");
|
|
1984
|
-
}
|
|
1985
|
-
if (snapshot.payload === void 0) {
|
|
1986
|
-
throw new JWSInvalid("JWS Payload missing");
|
|
1987
|
-
}
|
|
1988
|
-
if (typeof snapshot.signature !== "string") {
|
|
1989
|
-
throw new JWSInvalid("JWS Signature missing or incorrect type");
|
|
1990
|
-
}
|
|
1991
|
-
if (snapshot.header !== void 0 && !isObject(snapshot.header)) {
|
|
1992
|
-
throw new JWSInvalid("JWS Unprotected Header incorrect type");
|
|
1993
|
-
}
|
|
1994
|
-
return verifyResult(snapshot, await verifySignature(snapshot, prepareVerify(options), key, encodeJsonUnencodedPayload));
|
|
1995
|
-
}
|
|
1996
|
-
|
|
1997
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/jws/general/verify.js
|
|
1998
|
-
function snapshotSignature(signature, payload) {
|
|
1999
|
-
try {
|
|
2000
|
-
const jws = snapshotJws(signature, [payload]);
|
|
2001
|
-
const { protected: encodedProtected, header, signature: encodedSignature } = jws;
|
|
2002
|
-
if (encodedProtected === void 0 && header === void 0)
|
|
2003
|
-
return void 0;
|
|
2004
|
-
if (encodedProtected !== void 0 && typeof encodedProtected !== "string")
|
|
2005
|
-
return void 0;
|
|
2006
|
-
if (typeof encodedSignature !== "string")
|
|
2007
|
-
return void 0;
|
|
2008
|
-
if (header !== void 0 && !isObject(header))
|
|
2009
|
-
return void 0;
|
|
2010
|
-
const protectedHeader = parseProtectedHeader(encodedProtected);
|
|
2011
|
-
const { b64, crit } = protectedHeader;
|
|
2012
|
-
return [
|
|
2013
|
-
jws,
|
|
2014
|
-
protectedHeader,
|
|
2015
|
-
Array.isArray(crit) && crit.includes("b64") ? typeof b64 === "boolean" ? b64 ? 1 : 2 : 0 : 1
|
|
2016
|
-
];
|
|
2017
|
-
} catch {
|
|
2018
|
-
return void 0;
|
|
2019
|
-
}
|
|
2020
|
-
}
|
|
2021
|
-
async function generalVerify(jws, key, options) {
|
|
2022
|
-
if (!isObject(jws)) {
|
|
2023
|
-
throw new JWSInvalid("General JWS must be an object");
|
|
2024
|
-
}
|
|
2025
|
-
const { signatures, payload: inputPayload } = jws;
|
|
2026
|
-
if (!Array.isArray(signatures)) {
|
|
2027
|
-
throw new JWSInvalid("JWS Signatures missing or incorrect type");
|
|
2028
|
-
}
|
|
2029
|
-
const signatureEntries = Array.from(signatures);
|
|
2030
|
-
if (!signatureEntries.every(isObject)) {
|
|
2031
|
-
throw new JWSInvalid("JWS Signatures missing or incorrect type");
|
|
2032
|
-
}
|
|
2033
|
-
let shared;
|
|
2034
|
-
try {
|
|
2035
|
-
if (inputPayload === void 0)
|
|
2036
|
-
throw new Error();
|
|
2037
|
-
shared = prepareVerify(options);
|
|
2038
|
-
} catch {
|
|
2039
|
-
throw new JWSSignatureVerificationFailed();
|
|
2040
|
-
}
|
|
2041
|
-
const payload = inputPayload instanceof Uint8Array ? new Uint8Array(inputPayload) : inputPayload;
|
|
2042
|
-
const candidates = signatureEntries.map((signature) => snapshotSignature(signature, payload)).filter((candidate) => candidate !== void 0);
|
|
2043
|
-
let modes = 0;
|
|
2044
|
-
for (const [, , mode] of candidates) {
|
|
2045
|
-
modes |= mode;
|
|
2046
|
-
if (modes === 3) {
|
|
2047
|
-
throw new JWSInvalid("inconsistent use of JWS Unencoded Payload (RFC7797)");
|
|
2048
|
-
}
|
|
2049
|
-
}
|
|
2050
|
-
for (const candidate of candidates) {
|
|
2051
|
-
try {
|
|
2052
|
-
return verifyResult(candidate[0], await verifySignature(candidate[0], shared, key, encodeJsonUnencodedPayload, candidate[1]));
|
|
2053
|
-
} catch {
|
|
2054
|
-
}
|
|
2055
|
-
}
|
|
2056
|
-
throw new JWSSignatureVerificationFailed();
|
|
2057
|
-
}
|
|
2058
|
-
|
|
2059
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/jwt_claims_set.js
|
|
2060
|
-
var epoch = (date) => Math.floor(date.getTime() / 1e3);
|
|
2061
|
-
var multipliers = {
|
|
2062
|
-
s: 1,
|
|
2063
|
-
m: 60,
|
|
2064
|
-
h: 3600,
|
|
2065
|
-
d: 86400,
|
|
2066
|
-
w: 604800,
|
|
2067
|
-
y: 31557600
|
|
2068
|
-
};
|
|
2069
|
-
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;
|
|
2070
|
-
var checkFailed = "check_failed";
|
|
2071
|
-
function invalidDuration() {
|
|
2072
|
-
throw new TypeError("Invalid time period format");
|
|
2073
|
-
}
|
|
2074
|
-
function secs(str) {
|
|
2075
|
-
if (typeof str !== "string") {
|
|
2076
|
-
invalidDuration();
|
|
2077
|
-
}
|
|
2078
|
-
const matched = REGEX.exec(str);
|
|
2079
|
-
if (!matched || matched[4] && matched[1]) {
|
|
2080
|
-
invalidDuration();
|
|
2081
|
-
}
|
|
2082
|
-
const value = parseFloat(matched[2]);
|
|
2083
|
-
const numericDate2 = Math.round(value * multipliers[matched[3][0].toLowerCase()]);
|
|
2084
|
-
if (!Number.isFinite(numericDate2)) {
|
|
2085
|
-
invalidDuration();
|
|
2086
|
-
}
|
|
2087
|
-
if (matched[1] === "-" || matched[4] === "ago") {
|
|
2088
|
-
return -numericDate2;
|
|
2089
|
-
}
|
|
2090
|
-
return numericDate2;
|
|
2091
|
-
}
|
|
2092
|
-
function validateInput(label, input) {
|
|
2093
|
-
if (!Number.isFinite(input)) {
|
|
2094
|
-
throw new TypeError(`Invalid ${label} input`);
|
|
2095
|
-
}
|
|
2096
|
-
return input;
|
|
2097
|
-
}
|
|
2098
|
-
function validateStringClaim(claim, value) {
|
|
2099
|
-
if (typeof value !== "string") {
|
|
2100
|
-
throw new TypeError(`"${claim}" claim must be a string`);
|
|
2101
|
-
}
|
|
2102
|
-
}
|
|
2103
|
-
function validateAudienceClaim(value) {
|
|
2104
|
-
if (typeof value !== "string" && (!Array.isArray(value) || Array.from(value).some((member) => typeof member !== "string"))) {
|
|
2105
|
-
throw new TypeError('"aud" claim must be a string or an array of strings');
|
|
2106
|
-
}
|
|
2107
|
-
}
|
|
2108
|
-
function numericDate(value, label) {
|
|
2109
|
-
if (typeof value === "number")
|
|
2110
|
-
return validateInput(label, value);
|
|
2111
|
-
if (value instanceof Date)
|
|
2112
|
-
return validateInput(label, epoch(value));
|
|
2113
|
-
return epoch(/* @__PURE__ */ new Date()) + secs(value);
|
|
2114
|
-
}
|
|
2115
|
-
var normalizeTyp = (value) => {
|
|
2116
|
-
const normalized = value.toLowerCase();
|
|
2117
|
-
return value.includes("/") ? normalized : `application/${normalized}`;
|
|
2118
|
-
};
|
|
2119
|
-
var checkAudiencePresence = (audPayload, audOption) => {
|
|
2120
|
-
if (typeof audPayload === "string") {
|
|
2121
|
-
return audOption.includes(audPayload);
|
|
2122
|
-
}
|
|
2123
|
-
if (Array.isArray(audPayload)) {
|
|
2124
|
-
return audOption.some((aud) => audPayload.includes(aud));
|
|
2125
|
-
}
|
|
2126
|
-
return false;
|
|
2127
|
-
};
|
|
2128
|
-
function validateNumericDate(payload, claim, required = false) {
|
|
2129
|
-
const value = payload[claim];
|
|
2130
|
-
if (value === void 0 && !required)
|
|
2131
|
-
return void 0;
|
|
2132
|
-
if (typeof value !== "number") {
|
|
2133
|
-
throw new JWTClaimValidationFailed(`"${claim}" claim must be a number`, payload, claim, "invalid");
|
|
2134
|
-
}
|
|
2135
|
-
return value;
|
|
2136
|
-
}
|
|
2137
|
-
function unexpectedClaim(payload, claim) {
|
|
2138
|
-
throw new JWTClaimValidationFailed(`unexpected "${claim}" claim value`, payload, claim, checkFailed);
|
|
2139
|
-
}
|
|
2140
|
-
function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
|
|
2141
|
-
let payload;
|
|
2142
|
-
try {
|
|
2143
|
-
payload = JSON.parse(strictDecoder.decode(encodedPayload));
|
|
2144
|
-
} catch {
|
|
2145
|
-
}
|
|
2146
|
-
if (!isObject(payload)) {
|
|
2147
|
-
throw new JWTInvalid("JWT Claims Set must be a top-level JSON object");
|
|
2148
|
-
}
|
|
2149
|
-
const { typ } = options;
|
|
2150
|
-
if (typ !== void 0 && (typeof protectedHeader.typ !== "string" || normalizeTyp(protectedHeader.typ) !== normalizeTyp(typ))) {
|
|
2151
|
-
throw new JWTClaimValidationFailed('unexpected "typ" JWT header value', payload, "typ", checkFailed);
|
|
2152
|
-
}
|
|
2153
|
-
const { requiredClaims = [], issuer, subject, audience, maxTokenAge } = options;
|
|
2154
|
-
const presenceCheck = [...requiredClaims];
|
|
2155
|
-
if (maxTokenAge !== void 0)
|
|
2156
|
-
presenceCheck.push("iat");
|
|
2157
|
-
if (audience !== void 0)
|
|
2158
|
-
presenceCheck.push("aud");
|
|
2159
|
-
if (subject !== void 0)
|
|
2160
|
-
presenceCheck.push("sub");
|
|
2161
|
-
if (issuer !== void 0)
|
|
2162
|
-
presenceCheck.push("iss");
|
|
2163
|
-
for (const claim of new Set(presenceCheck.reverse())) {
|
|
2164
|
-
if (!Object.hasOwn(payload, claim)) {
|
|
2165
|
-
throw new JWTClaimValidationFailed(`missing required "${claim}" claim`, payload, claim, "missing");
|
|
2166
|
-
}
|
|
2167
|
-
}
|
|
2168
|
-
if (issuer !== void 0 && !(Array.isArray(issuer) ? issuer : [issuer]).includes(payload.iss)) {
|
|
2169
|
-
unexpectedClaim(payload, "iss");
|
|
2170
|
-
}
|
|
2171
|
-
if (subject !== void 0 && payload.sub !== subject) {
|
|
2172
|
-
unexpectedClaim(payload, "sub");
|
|
2173
|
-
}
|
|
2174
|
-
if (audience !== void 0 && !checkAudiencePresence(payload.aud, typeof audience === "string" ? [audience] : audience)) {
|
|
2175
|
-
unexpectedClaim(payload, "aud");
|
|
2176
|
-
}
|
|
2177
|
-
const { clockTolerance } = options;
|
|
2178
|
-
let tolerance = 0;
|
|
2179
|
-
if (typeof clockTolerance === "string") {
|
|
2180
|
-
tolerance = secs(clockTolerance);
|
|
2181
|
-
} else if (clockTolerance !== void 0) {
|
|
2182
|
-
if (typeof clockTolerance !== "number") {
|
|
2183
|
-
throw new TypeError("Invalid clockTolerance option type");
|
|
2184
|
-
}
|
|
2185
|
-
tolerance = clockTolerance;
|
|
2186
|
-
}
|
|
2187
|
-
validateInput("clockTolerance option", tolerance);
|
|
2188
|
-
const { currentDate } = options;
|
|
2189
|
-
const now = validateInput("currentDate option", epoch(currentDate === void 0 ? /* @__PURE__ */ new Date() : currentDate));
|
|
2190
|
-
const iat = validateNumericDate(payload, "iat", maxTokenAge !== void 0);
|
|
2191
|
-
const nbf = validateNumericDate(payload, "nbf");
|
|
2192
|
-
if (nbf !== void 0) {
|
|
2193
|
-
if (nbf > now + tolerance) {
|
|
2194
|
-
throw new JWTClaimValidationFailed('"nbf" claim timestamp check failed', payload, "nbf", checkFailed);
|
|
2195
|
-
}
|
|
2196
|
-
}
|
|
2197
|
-
const exp = validateNumericDate(payload, "exp");
|
|
2198
|
-
if (exp !== void 0) {
|
|
2199
|
-
if (exp <= now - tolerance) {
|
|
2200
|
-
throw new JWTExpired('"exp" claim timestamp check failed', payload, "exp", checkFailed);
|
|
2201
|
-
}
|
|
2202
|
-
}
|
|
2203
|
-
if (maxTokenAge !== void 0) {
|
|
2204
|
-
const age = now - iat;
|
|
2205
|
-
const max = validateInput("maxTokenAge option", typeof maxTokenAge === "number" ? maxTokenAge : secs(maxTokenAge));
|
|
2206
|
-
if (age - tolerance > max) {
|
|
2207
|
-
throw new JWTExpired('"iat" claim timestamp check failed (too far in the past)', payload, "iat", checkFailed);
|
|
2208
|
-
}
|
|
2209
|
-
if (age < -tolerance) {
|
|
2210
|
-
throw new JWTClaimValidationFailed('"iat" claim timestamp check failed (it should be in the past)', payload, "iat", checkFailed);
|
|
2211
|
-
}
|
|
2212
|
-
}
|
|
2213
|
-
return payload;
|
|
2214
|
-
}
|
|
2215
|
-
var producerPayloads;
|
|
2216
|
-
function producerPayload(producer) {
|
|
2217
|
-
return producerPayloads.get(producer);
|
|
2218
|
-
}
|
|
2219
|
-
function jwtData(producer) {
|
|
2220
|
-
const payload = producerPayload(producer);
|
|
2221
|
-
for (const claim of ["iat", "nbf", "exp"]) {
|
|
2222
|
-
const value = payload[claim];
|
|
2223
|
-
if (typeof value === "number" && !Number.isFinite(value)) {
|
|
2224
|
-
throw new TypeError(`"${claim}" claim must be a finite number`);
|
|
2225
|
-
}
|
|
2226
|
-
}
|
|
2227
|
-
return encoder.encode(JSON.stringify(payload));
|
|
2228
|
-
}
|
|
2229
|
-
function jwtClaim(producer, claim) {
|
|
2230
|
-
return producerPayload(producer)[claim];
|
|
2231
|
-
}
|
|
2232
|
-
var JWTClaimsBuilder = class {
|
|
2233
|
-
constructor(payload = {}) {
|
|
2234
|
-
if (!isObject(payload)) {
|
|
2235
|
-
throw new TypeError("JWT Claims Set MUST be an object");
|
|
2236
|
-
}
|
|
2237
|
-
;
|
|
2238
|
-
(producerPayloads ||= /* @__PURE__ */ new WeakMap()).set(this, structuredClone(payload));
|
|
2239
|
-
}
|
|
2240
|
-
setIssuer(value) {
|
|
2241
|
-
validateStringClaim("iss", value);
|
|
2242
|
-
producerPayload(this).iss = value;
|
|
2243
|
-
return this;
|
|
2244
|
-
}
|
|
2245
|
-
setSubject(value) {
|
|
2246
|
-
validateStringClaim("sub", value);
|
|
2247
|
-
producerPayload(this).sub = value;
|
|
2248
|
-
return this;
|
|
2249
|
-
}
|
|
2250
|
-
setAudience(value) {
|
|
2251
|
-
validateAudienceClaim(value);
|
|
2252
|
-
producerPayload(this).aud = value;
|
|
2253
|
-
return this;
|
|
2254
|
-
}
|
|
2255
|
-
setJti(value) {
|
|
2256
|
-
validateStringClaim("jti", value);
|
|
2257
|
-
producerPayload(this).jti = value;
|
|
2258
|
-
return this;
|
|
2259
|
-
}
|
|
2260
|
-
setNotBefore(value) {
|
|
2261
|
-
producerPayload(this).nbf = numericDate(value, "setNotBefore");
|
|
2262
|
-
return this;
|
|
2263
|
-
}
|
|
2264
|
-
setExpirationTime(value) {
|
|
2265
|
-
producerPayload(this).exp = numericDate(value, "setExpirationTime");
|
|
2266
|
-
return this;
|
|
2267
|
-
}
|
|
2268
|
-
setIssuedAt(value) {
|
|
2269
|
-
const payload = producerPayload(this);
|
|
2270
|
-
if (value === void 0) {
|
|
2271
|
-
payload.iat = epoch(/* @__PURE__ */ new Date());
|
|
2272
|
-
} else if (typeof value === "string") {
|
|
2273
|
-
payload.iat = validateInput("setIssuedAt", epoch(/* @__PURE__ */ new Date()) + secs(value));
|
|
2274
|
-
} else {
|
|
2275
|
-
payload.iat = numericDate(value, "setIssuedAt");
|
|
2276
|
-
}
|
|
2277
|
-
return this;
|
|
2278
|
-
}
|
|
2279
|
-
};
|
|
2280
|
-
|
|
2281
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/jwt/verify.js
|
|
2282
|
-
async function jwtVerify(jwt, key, options) {
|
|
2283
|
-
const verified = await verifyCompact(jwt, prepareVerify(options), key);
|
|
2284
|
-
if (!verified[2]) {
|
|
2285
|
-
throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
2286
|
-
}
|
|
2287
|
-
const payload = validateClaimsSet(verified[1], verified[0], options);
|
|
2288
|
-
const result = { payload, protectedHeader: verified[1] };
|
|
2289
|
-
if (typeof key === "function") {
|
|
2290
|
-
return { ...result, key: verified[3] };
|
|
2291
|
-
}
|
|
2292
|
-
return result;
|
|
2293
|
-
}
|
|
2294
|
-
|
|
2295
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/jwt/decrypt.js
|
|
2296
|
-
async function jwtDecrypt(jwt, key, options) {
|
|
2297
|
-
const decrypted = await decryptCompact(jwt, prepareDecrypt(options), key);
|
|
2298
|
-
const protectedHeader = decrypted[1];
|
|
2299
|
-
const payload = validateClaimsSet(protectedHeader, decrypted[0], options);
|
|
2300
|
-
for (const claim of ["iss", "sub", "aud"]) {
|
|
2301
|
-
if (protectedHeader[claim] !== void 0 && (claim === "aud" ? JSON.stringify(protectedHeader.aud) !== JSON.stringify(payload.aud) : protectedHeader[claim] !== payload[claim])) {
|
|
2302
|
-
throw new JWTClaimValidationFailed(`replicated "${claim}" claim header parameter mismatch`, payload, claim, "mismatch");
|
|
2303
|
-
}
|
|
2304
|
-
}
|
|
2305
|
-
const result = { payload, protectedHeader };
|
|
2306
|
-
if (typeof key === "function") {
|
|
2307
|
-
return { ...result, key: decrypted[2] };
|
|
2308
|
-
}
|
|
2309
|
-
return result;
|
|
2310
|
-
}
|
|
2311
|
-
|
|
2312
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/jwe/compact/encrypt.js
|
|
2313
|
-
var CompactEncrypt = class {
|
|
2314
|
-
#plaintext;
|
|
2315
|
-
#protectedHeader;
|
|
2316
|
-
#cek;
|
|
2317
|
-
#iv;
|
|
2318
|
-
#keyManagementParameters;
|
|
2319
|
-
constructor(plaintext) {
|
|
2320
|
-
assertUint8Array(plaintext, "plaintext");
|
|
2321
|
-
this.#plaintext = plaintext;
|
|
2322
|
-
}
|
|
2323
|
-
setContentEncryptionKey(cek) {
|
|
2324
|
-
assertNotSet(this.#cek, "setContentEncryptionKey");
|
|
2325
|
-
this.#cek = cek;
|
|
2326
|
-
return this;
|
|
2327
|
-
}
|
|
2328
|
-
setInitializationVector(iv) {
|
|
2329
|
-
assertNotSet(this.#iv, "setInitializationVector");
|
|
2330
|
-
this.#iv = iv;
|
|
2331
|
-
return this;
|
|
2332
|
-
}
|
|
2333
|
-
setProtectedHeader(protectedHeader) {
|
|
2334
|
-
assertNotSet(this.#protectedHeader, "setProtectedHeader");
|
|
2335
|
-
this.#protectedHeader = protectedHeader;
|
|
2336
|
-
return this;
|
|
2337
|
-
}
|
|
2338
|
-
setKeyManagementParameters(parameters) {
|
|
2339
|
-
assertNotSet(this.#keyManagementParameters, "setKeyManagementParameters");
|
|
2340
|
-
this.#keyManagementParameters = parameters;
|
|
2341
|
-
return this;
|
|
2342
|
-
}
|
|
2343
|
-
async encrypt(key, options) {
|
|
2344
|
-
const jwe = await createJWE([
|
|
2345
|
-
this.#plaintext,
|
|
2346
|
-
this.#protectedHeader,
|
|
2347
|
-
void 0,
|
|
2348
|
-
void 0,
|
|
2349
|
-
void 0,
|
|
2350
|
-
this.#cek,
|
|
2351
|
-
this.#iv,
|
|
2352
|
-
this.#keyManagementParameters,
|
|
2353
|
-
void 0,
|
|
2354
|
-
false
|
|
2355
|
-
], key, options);
|
|
2356
|
-
return [jwe.protected, jwe.encrypted_key, jwe.iv, jwe.ciphertext, jwe.tag].join(".");
|
|
2357
|
-
}
|
|
2358
|
-
};
|
|
2359
|
-
|
|
2360
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js
|
|
2361
|
-
var FlattenedEncrypt = class {
|
|
2362
|
-
#plaintext;
|
|
2363
|
-
#protectedHeader;
|
|
2364
|
-
#sharedUnprotectedHeader;
|
|
2365
|
-
#unprotectedHeader;
|
|
2366
|
-
#aad;
|
|
2367
|
-
#cek;
|
|
2368
|
-
#iv;
|
|
2369
|
-
#keyManagementParameters;
|
|
2370
|
-
constructor(plaintext) {
|
|
2371
|
-
assertUint8Array(plaintext, "plaintext");
|
|
2372
|
-
this.#plaintext = plaintext;
|
|
2373
|
-
}
|
|
2374
|
-
setKeyManagementParameters(parameters) {
|
|
2375
|
-
assertNotSet(this.#keyManagementParameters, "setKeyManagementParameters");
|
|
2376
|
-
this.#keyManagementParameters = parameters;
|
|
2377
|
-
return this;
|
|
2378
|
-
}
|
|
2379
|
-
setProtectedHeader(protectedHeader) {
|
|
2380
|
-
assertNotSet(this.#protectedHeader, "setProtectedHeader");
|
|
2381
|
-
this.#protectedHeader = protectedHeader;
|
|
2382
|
-
return this;
|
|
2383
|
-
}
|
|
2384
|
-
setSharedUnprotectedHeader(sharedUnprotectedHeader) {
|
|
2385
|
-
assertNotSet(this.#sharedUnprotectedHeader, "setSharedUnprotectedHeader");
|
|
2386
|
-
this.#sharedUnprotectedHeader = sharedUnprotectedHeader;
|
|
2387
|
-
return this;
|
|
2388
|
-
}
|
|
2389
|
-
setUnprotectedHeader(unprotectedHeader) {
|
|
2390
|
-
assertNotSet(this.#unprotectedHeader, "setUnprotectedHeader");
|
|
2391
|
-
this.#unprotectedHeader = unprotectedHeader;
|
|
2392
|
-
return this;
|
|
2393
|
-
}
|
|
2394
|
-
setAdditionalAuthenticatedData(aad) {
|
|
2395
|
-
this.#aad = aad;
|
|
2396
|
-
return this;
|
|
2397
|
-
}
|
|
2398
|
-
setContentEncryptionKey(cek) {
|
|
2399
|
-
assertNotSet(this.#cek, "setContentEncryptionKey");
|
|
2400
|
-
this.#cek = cek;
|
|
2401
|
-
return this;
|
|
2402
|
-
}
|
|
2403
|
-
setInitializationVector(iv) {
|
|
2404
|
-
assertNotSet(this.#iv, "setInitializationVector");
|
|
2405
|
-
this.#iv = iv;
|
|
2406
|
-
return this;
|
|
2407
|
-
}
|
|
2408
|
-
async encrypt(key, options) {
|
|
2409
|
-
return createJWE([
|
|
2410
|
-
this.#plaintext,
|
|
2411
|
-
this.#protectedHeader,
|
|
2412
|
-
this.#unprotectedHeader,
|
|
2413
|
-
this.#sharedUnprotectedHeader,
|
|
2414
|
-
this.#aad,
|
|
2415
|
-
this.#cek,
|
|
2416
|
-
this.#iv,
|
|
2417
|
-
this.#keyManagementParameters,
|
|
2418
|
-
void 0,
|
|
2419
|
-
false
|
|
2420
|
-
], key, options);
|
|
2421
|
-
}
|
|
2422
|
-
};
|
|
2423
|
-
|
|
2424
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/jws_sign.js
|
|
2425
|
-
function serializeProtectedHeader(protectedHeader) {
|
|
2426
|
-
if (protectedHeader === void 0)
|
|
2427
|
-
return [void 0, ""];
|
|
2428
|
-
const normalized = serializeJoseHeader(JWSInvalid, protectedHeader);
|
|
2429
|
-
return [normalized[0], encode2(normalized[1])];
|
|
2430
|
-
}
|
|
2431
|
-
function validateSignatureHeader(protectedHeader, joseHeader, crit) {
|
|
2432
|
-
validateCritDuplicates(JWSInvalid, protectedHeader);
|
|
2433
|
-
return validateB64(protectedHeader, validateCrit(JWSInvalid, JWS_RECOGNIZED, crit, protectedHeader, joseHeader));
|
|
2434
|
-
}
|
|
2435
|
-
function signatureAlgorithm(joseHeader) {
|
|
2436
|
-
const alg = joseHeader.alg;
|
|
2437
|
-
if (typeof alg !== "string" || !alg) {
|
|
2438
|
-
throw new JWSInvalid('JWS "alg" (Algorithm) Header Parameter missing or invalid');
|
|
2439
|
-
}
|
|
2440
|
-
return jwsAlgorithm(alg);
|
|
2441
|
-
}
|
|
2442
|
-
async function signSignature(protectedHeader, payload, entry, key) {
|
|
2443
|
-
const data = concat(encode(protectedHeader), encode("."), payload);
|
|
2444
|
-
const k = await prepareKey(entry, key, "sign");
|
|
2445
|
-
return encode2(await sign(entry, k, data));
|
|
2446
|
-
}
|
|
2447
|
-
async function createSignature(input, key, assertB64) {
|
|
2448
|
-
let { protectedHeader, unprotectedHeader } = input;
|
|
2449
|
-
let protectedHeaderString;
|
|
2450
|
-
[protectedHeader, protectedHeaderString] = serializeProtectedHeader(protectedHeader);
|
|
2451
|
-
if (unprotectedHeader !== void 0) {
|
|
2452
|
-
unprotectedHeader = serializeJoseHeader(JWSInvalid, unprotectedHeader)[0];
|
|
2453
|
-
}
|
|
2454
|
-
if (!protectedHeader && !unprotectedHeader) {
|
|
2455
|
-
throw new JWSInvalid("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
|
|
2456
|
-
}
|
|
2457
|
-
if (!isDisjoint(protectedHeader, unprotectedHeader)) {
|
|
2458
|
-
throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
2459
|
-
}
|
|
2460
|
-
const joseHeader = { ...protectedHeader, ...unprotectedHeader };
|
|
2461
|
-
const b64 = validateSignatureHeader(protectedHeader, joseHeader, input.crit);
|
|
2462
|
-
assertB64?.(b64);
|
|
2463
|
-
const entry = signatureAlgorithm(joseHeader);
|
|
2464
|
-
let payloadS;
|
|
2465
|
-
let payloadB;
|
|
2466
|
-
if (b64) {
|
|
2467
|
-
const encoded = input.encoded ??= [];
|
|
2468
|
-
encoded[0] ??= encode2(input.payload);
|
|
2469
|
-
encoded[1] ??= encode(encoded[0]);
|
|
2470
|
-
payloadS = encoded[0];
|
|
2471
|
-
payloadB = encoded[1];
|
|
2472
|
-
} else {
|
|
2473
|
-
payloadB = input.payload;
|
|
2474
|
-
payloadS = "";
|
|
2475
|
-
}
|
|
2476
|
-
const jws = {
|
|
2477
|
-
signature: await signSignature(protectedHeaderString, payloadB, entry, key),
|
|
2478
|
-
payload: payloadS
|
|
2479
|
-
};
|
|
2480
|
-
if (protectedHeader) {
|
|
2481
|
-
jws.protected = protectedHeaderString;
|
|
2482
|
-
}
|
|
2483
|
-
if (unprotectedHeader) {
|
|
2484
|
-
jws.header = unprotectedHeader;
|
|
2485
|
-
}
|
|
2486
|
-
return [jws, b64];
|
|
2487
|
-
}
|
|
2488
|
-
async function createCompactSignature(payload, inputProtectedHeader, inputCrit, key, rejectUnencoded) {
|
|
2489
|
-
const [protectedHeader, protectedHeaderString] = serializeProtectedHeader(inputProtectedHeader);
|
|
2490
|
-
if (!protectedHeader) {
|
|
2491
|
-
throw new JWSInvalid("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
|
|
2492
|
-
}
|
|
2493
|
-
const b64 = validateSignatureHeader(protectedHeader, protectedHeader, inputCrit);
|
|
2494
|
-
if (!b64)
|
|
2495
|
-
rejectUnencoded();
|
|
2496
|
-
const entry = signatureAlgorithm(protectedHeader);
|
|
2497
|
-
const encodedPayload = encode2(payload);
|
|
2498
|
-
const signature = await signSignature(protectedHeaderString, encode(encodedPayload), entry, key);
|
|
2499
|
-
return `${protectedHeaderString}.${encodedPayload}.${signature}`;
|
|
2500
|
-
}
|
|
2501
|
-
|
|
2502
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/jws/compact/sign.js
|
|
2503
|
-
var CompactSign = class {
|
|
2504
|
-
#payload;
|
|
2505
|
-
#protectedHeader;
|
|
2506
|
-
constructor(payload) {
|
|
2507
|
-
if (!(payload instanceof Uint8Array)) {
|
|
2508
|
-
throw new TypeError("payload must be an instance of Uint8Array");
|
|
2509
|
-
}
|
|
2510
|
-
this.#payload = payload;
|
|
2511
|
-
}
|
|
2512
|
-
setProtectedHeader(protectedHeader) {
|
|
2513
|
-
assertNotSet(this.#protectedHeader, "setProtectedHeader");
|
|
2514
|
-
this.#protectedHeader = protectedHeader;
|
|
2515
|
-
return this;
|
|
2516
|
-
}
|
|
2517
|
-
async sign(key, options) {
|
|
2518
|
-
return createCompactSignature(this.#payload, this.#protectedHeader, options?.crit, key, () => {
|
|
2519
|
-
throw new TypeError("use the flattened module for creating JWS with b64: false");
|
|
2520
|
-
});
|
|
2521
|
-
}
|
|
2522
|
-
};
|
|
2523
|
-
|
|
2524
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/jws/flattened/sign.js
|
|
2525
|
-
var FlattenedSign = class {
|
|
2526
|
-
#payload;
|
|
2527
|
-
#protectedHeader;
|
|
2528
|
-
#unprotectedHeader;
|
|
2529
|
-
constructor(payload) {
|
|
2530
|
-
if (!(payload instanceof Uint8Array)) {
|
|
2531
|
-
throw new TypeError("payload must be an instance of Uint8Array");
|
|
2532
|
-
}
|
|
2533
|
-
this.#payload = payload;
|
|
2534
|
-
}
|
|
2535
|
-
setProtectedHeader(protectedHeader) {
|
|
2536
|
-
assertNotSet(this.#protectedHeader, "setProtectedHeader");
|
|
2537
|
-
this.#protectedHeader = protectedHeader;
|
|
2538
|
-
return this;
|
|
2539
|
-
}
|
|
2540
|
-
setUnprotectedHeader(unprotectedHeader) {
|
|
2541
|
-
assertNotSet(this.#unprotectedHeader, "setUnprotectedHeader");
|
|
2542
|
-
this.#unprotectedHeader = unprotectedHeader;
|
|
2543
|
-
return this;
|
|
2544
|
-
}
|
|
2545
|
-
async sign(key, options) {
|
|
2546
|
-
const [jws] = await createSignature({
|
|
2547
|
-
payload: this.#payload,
|
|
2548
|
-
protectedHeader: this.#protectedHeader,
|
|
2549
|
-
unprotectedHeader: this.#unprotectedHeader,
|
|
2550
|
-
crit: options?.crit
|
|
2551
|
-
}, key);
|
|
2552
|
-
return jws;
|
|
2553
|
-
}
|
|
2554
|
-
};
|
|
2555
|
-
|
|
2556
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/jws/general/sign.js
|
|
2557
|
-
var IndividualSignature = class {
|
|
2558
|
-
#parent;
|
|
2559
|
-
state;
|
|
2560
|
-
constructor(sig2, key, options) {
|
|
2561
|
-
this.#parent = sig2;
|
|
2562
|
-
this.state = [void 0, void 0, key, options?.crit];
|
|
2563
|
-
}
|
|
2564
|
-
setProtectedHeader(protectedHeader) {
|
|
2565
|
-
assertNotSet(this.state[0], "setProtectedHeader");
|
|
2566
|
-
this.state[0] = protectedHeader;
|
|
2567
|
-
return this;
|
|
2568
|
-
}
|
|
2569
|
-
setUnprotectedHeader(unprotectedHeader) {
|
|
2570
|
-
assertNotSet(this.state[1], "setUnprotectedHeader");
|
|
2571
|
-
this.state[1] = unprotectedHeader;
|
|
2572
|
-
return this;
|
|
2573
|
-
}
|
|
2574
|
-
addSignature(...args) {
|
|
2575
|
-
return this.#parent.addSignature(...args);
|
|
2576
|
-
}
|
|
2577
|
-
sign(...args) {
|
|
2578
|
-
return this.#parent.sign(...args);
|
|
2579
|
-
}
|
|
2580
|
-
done() {
|
|
2581
|
-
return this.#parent;
|
|
2582
|
-
}
|
|
2583
|
-
};
|
|
2584
|
-
var GeneralSign = class {
|
|
2585
|
-
#payload;
|
|
2586
|
-
#signatures = [];
|
|
2587
|
-
constructor(payload) {
|
|
2588
|
-
this.#payload = payload;
|
|
2589
|
-
}
|
|
2590
|
-
addSignature(key, options) {
|
|
2591
|
-
const signature = new IndividualSignature(this, key, options);
|
|
2592
|
-
this.#signatures.push(signature);
|
|
2593
|
-
return signature;
|
|
2594
|
-
}
|
|
2595
|
-
async sign() {
|
|
2596
|
-
if (!this.#signatures.length) {
|
|
2597
|
-
throw new JWSInvalid("at least one signature must be added");
|
|
2598
|
-
}
|
|
2599
|
-
if (!(this.#payload instanceof Uint8Array)) {
|
|
2600
|
-
throw new TypeError("payload must be an instance of Uint8Array");
|
|
2601
|
-
}
|
|
2602
|
-
const jws = {
|
|
2603
|
-
signatures: [],
|
|
2604
|
-
payload: ""
|
|
2605
|
-
};
|
|
2606
|
-
const encoded = [];
|
|
2607
|
-
let b64;
|
|
2608
|
-
for (let i = 0; i < this.#signatures.length; i++) {
|
|
2609
|
-
const signature = this.#signatures[i];
|
|
2610
|
-
const [protectedHeader, unprotectedHeader, key, crit] = signature.state;
|
|
2611
|
-
const [{ payload, ...rest }, signatureB64] = await createSignature({
|
|
2612
|
-
payload: this.#payload,
|
|
2613
|
-
protectedHeader,
|
|
2614
|
-
unprotectedHeader,
|
|
2615
|
-
crit,
|
|
2616
|
-
encoded
|
|
2617
|
-
}, key);
|
|
2618
|
-
if (b64 === void 0) {
|
|
2619
|
-
b64 = signatureB64;
|
|
2620
|
-
jws.payload = payload;
|
|
2621
|
-
} else if (b64 !== signatureB64) {
|
|
2622
|
-
throw new JWSInvalid("inconsistent use of JWS Unencoded Payload (RFC7797)");
|
|
2623
|
-
}
|
|
2624
|
-
jws.signatures.push(rest);
|
|
2625
|
-
}
|
|
2626
|
-
return jws;
|
|
2627
|
-
}
|
|
2628
|
-
};
|
|
2629
|
-
|
|
2630
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/jwt/sign.js
|
|
2631
|
-
var SignJWT_base = JWTClaimsBuilder;
|
|
2632
|
-
var SignJWT = class extends SignJWT_base {
|
|
2633
|
-
#protectedHeader;
|
|
2634
|
-
setProtectedHeader(protectedHeader) {
|
|
2635
|
-
assertNotSet(this.#protectedHeader, "setProtectedHeader");
|
|
2636
|
-
this.#protectedHeader = protectedHeader;
|
|
2637
|
-
return this;
|
|
2638
|
-
}
|
|
2639
|
-
async sign(key, options) {
|
|
2640
|
-
return createCompactSignature(jwtData(this), this.#protectedHeader, options?.crit, key, () => {
|
|
2641
|
-
throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
2642
|
-
});
|
|
2643
|
-
}
|
|
2644
|
-
};
|
|
2645
|
-
|
|
2646
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/jwt/encrypt.js
|
|
2647
|
-
var EncryptJWT_base = JWTClaimsBuilder;
|
|
2648
|
-
var EncryptJWT = class extends EncryptJWT_base {
|
|
2649
|
-
#cek;
|
|
2650
|
-
#iv;
|
|
2651
|
-
#keyManagementParameters;
|
|
2652
|
-
#protectedHeader;
|
|
2653
|
-
#replicateIssuerAsHeader;
|
|
2654
|
-
#replicateSubjectAsHeader;
|
|
2655
|
-
#replicateAudienceAsHeader;
|
|
2656
|
-
setProtectedHeader(protectedHeader) {
|
|
2657
|
-
assertNotSet(this.#protectedHeader, "setProtectedHeader");
|
|
2658
|
-
this.#protectedHeader = protectedHeader;
|
|
2659
|
-
return this;
|
|
2660
|
-
}
|
|
2661
|
-
setKeyManagementParameters(parameters) {
|
|
2662
|
-
assertNotSet(this.#keyManagementParameters, "setKeyManagementParameters");
|
|
2663
|
-
this.#keyManagementParameters = parameters;
|
|
2664
|
-
return this;
|
|
2665
|
-
}
|
|
2666
|
-
setContentEncryptionKey(cek) {
|
|
2667
|
-
assertNotSet(this.#cek, "setContentEncryptionKey");
|
|
2668
|
-
this.#cek = cek;
|
|
2669
|
-
return this;
|
|
2670
|
-
}
|
|
2671
|
-
setInitializationVector(iv) {
|
|
2672
|
-
assertNotSet(this.#iv, "setInitializationVector");
|
|
2673
|
-
this.#iv = iv;
|
|
2674
|
-
return this;
|
|
2675
|
-
}
|
|
2676
|
-
replicateIssuerAsHeader() {
|
|
2677
|
-
this.#replicateIssuerAsHeader = true;
|
|
2678
|
-
return this;
|
|
2679
|
-
}
|
|
2680
|
-
replicateSubjectAsHeader() {
|
|
2681
|
-
this.#replicateSubjectAsHeader = true;
|
|
2682
|
-
return this;
|
|
2683
|
-
}
|
|
2684
|
-
replicateAudienceAsHeader() {
|
|
2685
|
-
this.#replicateAudienceAsHeader = true;
|
|
2686
|
-
return this;
|
|
2687
|
-
}
|
|
2688
|
-
async encrypt(key, options) {
|
|
2689
|
-
const plaintext = jwtData(this);
|
|
2690
|
-
if (this.#protectedHeader && (this.#replicateIssuerAsHeader || this.#replicateSubjectAsHeader || this.#replicateAudienceAsHeader)) {
|
|
2691
|
-
this.#protectedHeader = {
|
|
2692
|
-
...this.#protectedHeader,
|
|
2693
|
-
iss: this.#replicateIssuerAsHeader ? jwtClaim(this, "iss") : void 0,
|
|
2694
|
-
sub: this.#replicateSubjectAsHeader ? jwtClaim(this, "sub") : void 0,
|
|
2695
|
-
aud: this.#replicateAudienceAsHeader ? jwtClaim(this, "aud") : void 0
|
|
2696
|
-
};
|
|
2697
|
-
}
|
|
2698
|
-
const jwe = await createJWE([
|
|
2699
|
-
plaintext,
|
|
2700
|
-
this.#protectedHeader,
|
|
2701
|
-
void 0,
|
|
2702
|
-
void 0,
|
|
2703
|
-
void 0,
|
|
2704
|
-
this.#cek,
|
|
2705
|
-
this.#iv,
|
|
2706
|
-
this.#keyManagementParameters,
|
|
2707
|
-
void 0,
|
|
2708
|
-
false
|
|
2709
|
-
], key, options);
|
|
2710
|
-
return [jwe.protected, jwe.encrypted_key, jwe.iv, jwe.ciphertext, jwe.tag].join(".");
|
|
2711
|
-
}
|
|
2712
|
-
};
|
|
2713
|
-
|
|
2714
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/key_algorithm.js
|
|
2715
|
-
var algArgument = '"alg" (Algorithm)';
|
|
2716
|
-
function unsupportedAlg(source = 'JWK "alg" (Algorithm) Parameter') {
|
|
2717
|
-
throw new JOSENotSupported(`Invalid or unsupported ${source} value`);
|
|
2718
|
-
}
|
|
2719
|
-
function keyAlgorithm(alg, source) {
|
|
2720
|
-
return (typeof alg === "string" ? JWS[alg] ?? JWE[alg] : void 0) ?? unsupportedAlg(source);
|
|
2721
|
-
}
|
|
2722
|
-
|
|
2723
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/key_options.js
|
|
2724
|
-
function validateExtractableOption(extractable) {
|
|
2725
|
-
if (extractable !== void 0 && typeof extractable !== "boolean") {
|
|
2726
|
-
throw new TypeError('"extractable" option must be a boolean');
|
|
2727
|
-
}
|
|
2728
|
-
return extractable;
|
|
2729
|
-
}
|
|
2730
|
-
|
|
2731
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/lib/asn1.js
|
|
2732
|
-
var formatPEM = (b64, descriptor) => {
|
|
2733
|
-
const newlined = (b64.match(/.{1,64}/g) || []).join("\n");
|
|
2734
|
-
return `-----BEGIN ${descriptor}-----
|
|
2735
|
-
${newlined}
|
|
2736
|
-
-----END ${descriptor}-----`;
|
|
2737
|
-
};
|
|
2738
|
-
var genericExport = async (keyType, keyFormat, key) => {
|
|
2739
|
-
if (isKeyObject(key)) {
|
|
2740
|
-
if (key.type !== keyType) {
|
|
2741
|
-
throw new TypeError(`key is not a ${keyType} key`);
|
|
2742
|
-
}
|
|
2743
|
-
return key.export({ format: "pem", type: keyFormat });
|
|
2744
|
-
}
|
|
2745
|
-
if (!isCryptoKey(key)) {
|
|
2746
|
-
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject"));
|
|
2747
|
-
}
|
|
2748
|
-
if (!key.extractable) {
|
|
2749
|
-
throw new TypeError("CryptoKey is not extractable");
|
|
2750
|
-
}
|
|
2751
|
-
if (key.type !== keyType) {
|
|
2752
|
-
throw new TypeError(`key is not a ${keyType} key`);
|
|
2753
|
-
}
|
|
2754
|
-
return formatPEM(encodeBase64(new Uint8Array(await crypto.subtle.exportKey(keyFormat, key))), `${keyType.toUpperCase()} KEY`);
|
|
2755
|
-
};
|
|
2756
|
-
var toSPKI = (key) => genericExport("public", "spki", key);
|
|
2757
|
-
var toPKCS8 = (key) => genericExport("private", "pkcs8", key);
|
|
2758
|
-
var bytesEqual = (a, b) => {
|
|
2759
|
-
if (a.byteLength !== b.length)
|
|
2760
|
-
return false;
|
|
2761
|
-
for (let i = 0; i < a.byteLength; i++) {
|
|
2762
|
-
if (a[i] !== b[i])
|
|
2763
|
-
return false;
|
|
2764
|
-
}
|
|
2765
|
-
return true;
|
|
2766
|
-
};
|
|
2767
|
-
var createASN1State = (data) => ({ data, pos: 0 });
|
|
2768
|
-
var readByte = (state) => {
|
|
2769
|
-
const byte = state.data[state.pos++];
|
|
2770
|
-
if (byte === void 0) {
|
|
2771
|
-
throw new Error("Unexpected end of ASN.1 input");
|
|
2772
|
-
}
|
|
2773
|
-
return byte;
|
|
2774
|
-
};
|
|
2775
|
-
var parseLength = (state) => {
|
|
2776
|
-
const first = readByte(state);
|
|
2777
|
-
if (first & 128) {
|
|
2778
|
-
const lengthOfLen = first & 127;
|
|
2779
|
-
let length = 0;
|
|
2780
|
-
for (let i = 0; i < lengthOfLen; i++) {
|
|
2781
|
-
length = length << 8 | readByte(state);
|
|
2782
|
-
}
|
|
2783
|
-
return length;
|
|
2784
|
-
}
|
|
2785
|
-
return first;
|
|
2786
|
-
};
|
|
2787
|
-
var skipElement = (state, count = 1) => {
|
|
2788
|
-
while (count-- > 0) {
|
|
2789
|
-
state.pos++;
|
|
2790
|
-
const length = parseLength(state);
|
|
2791
|
-
state.pos += length;
|
|
2792
|
-
}
|
|
2793
|
-
};
|
|
2794
|
-
var expectTag = (state, expectedTag, errorMessage) => {
|
|
2795
|
-
if (readByte(state) !== expectedTag) {
|
|
2796
|
-
throw new Error(errorMessage);
|
|
2797
|
-
}
|
|
2798
|
-
};
|
|
2799
|
-
var getSubarray = (state, length) => {
|
|
2800
|
-
if (length < 0 || state.pos + length > state.data.length) {
|
|
2801
|
-
throw new Error("Unexpected end of ASN.1 input");
|
|
2802
|
-
}
|
|
2803
|
-
const result = state.data.subarray(state.pos, state.pos + length);
|
|
2804
|
-
state.pos += length;
|
|
2805
|
-
return result;
|
|
2806
|
-
};
|
|
2807
|
-
var parseAlgorithmOID = (state) => {
|
|
2808
|
-
expectTag(state, 6, "Expected algorithm OID");
|
|
2809
|
-
const oidLen = parseLength(state);
|
|
2810
|
-
return getSubarray(state, oidLen);
|
|
2811
|
-
};
|
|
2812
|
-
function parseKeyHeader(state, keyFormat) {
|
|
2813
|
-
expectTag(state, 48, `Invalid ${keyFormat === "spki" ? "SPKI" : "PKCS#8"} structure`);
|
|
2814
|
-
parseLength(state);
|
|
2815
|
-
if (keyFormat === "pkcs8") {
|
|
2816
|
-
expectTag(state, 2, "Expected version field");
|
|
2817
|
-
const length = parseLength(state);
|
|
2818
|
-
state.pos += length;
|
|
2819
|
-
}
|
|
2820
|
-
expectTag(state, 48, "Expected algorithm identifier");
|
|
2821
|
-
parseLength(state);
|
|
2822
|
-
}
|
|
2823
|
-
var parseECAlgorithmIdentifier = (state) => {
|
|
2824
|
-
const algOid = parseAlgorithmOID(state);
|
|
2825
|
-
if (bytesEqual(algOid, [43, 101, 110])) {
|
|
2826
|
-
return "X25519";
|
|
2827
|
-
}
|
|
2828
|
-
if (!bytesEqual(algOid, [42, 134, 72, 206, 61, 2, 1])) {
|
|
2829
|
-
throw new Error("Unsupported key algorithm");
|
|
2830
|
-
}
|
|
2831
|
-
expectTag(state, 6, "Expected curve OID");
|
|
2832
|
-
const curveOidLen = parseLength(state);
|
|
2833
|
-
const curveOid = getSubarray(state, curveOidLen);
|
|
2834
|
-
if (bytesEqual(curveOid, [42, 134, 72, 206, 61, 3, 1, 7]))
|
|
2835
|
-
return "P-256";
|
|
2836
|
-
if (bytesEqual(curveOid, [43, 129, 4, 0, 34]))
|
|
2837
|
-
return "P-384";
|
|
2838
|
-
if (bytesEqual(curveOid, [43, 129, 4, 0, 35]))
|
|
2839
|
-
return "P-521";
|
|
2840
|
-
throw new Error("Unsupported named curve");
|
|
2841
|
-
};
|
|
2842
|
-
var genericImport = async (keyFormat, keyData, alg, options) => {
|
|
2843
|
-
const extractable = validateExtractableOption(options?.extractable);
|
|
2844
|
-
const entry = keyAlgorithm(alg, algArgument);
|
|
2845
|
-
if (entry.secret) {
|
|
2846
|
-
unsupportedAlg(algArgument);
|
|
2847
|
-
}
|
|
2848
|
-
const isPublic = keyFormat === "spki";
|
|
2849
|
-
let algorithm;
|
|
2850
|
-
if (entry.resolve) {
|
|
2851
|
-
try {
|
|
2852
|
-
const state = createASN1State(keyData);
|
|
2853
|
-
parseKeyHeader(state, keyFormat);
|
|
2854
|
-
algorithm = entry.resolve({ crv: parseECAlgorithmIdentifier(state) });
|
|
2855
|
-
} catch {
|
|
2856
|
-
throw new JOSENotSupported("Invalid or unsupported key format");
|
|
2857
|
-
}
|
|
2858
|
-
} else {
|
|
2859
|
-
algorithm = entry.subtle;
|
|
2860
|
-
}
|
|
2861
|
-
return crypto.subtle.importKey(keyFormat, keyData, algorithm, extractable ?? isPublic, entry.usages[isPublic ? 0 : 1]);
|
|
2862
|
-
};
|
|
2863
|
-
var processPEMData = (pem, pattern) => {
|
|
2864
|
-
return decodeBase64(pem.replace(pattern, ""));
|
|
2865
|
-
};
|
|
2866
|
-
var fromPKCS8 = (pem, alg, options) => {
|
|
2867
|
-
const keyData = processPEMData(pem, /(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g);
|
|
2868
|
-
return genericImport("pkcs8", keyData, alg, options);
|
|
2869
|
-
};
|
|
2870
|
-
var fromSPKI = (pem, alg, options) => {
|
|
2871
|
-
const keyData = processPEMData(pem, /(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g);
|
|
2872
|
-
return genericImport("spki", keyData, alg, options);
|
|
2873
|
-
};
|
|
2874
|
-
function spkiFromX509(buf) {
|
|
2875
|
-
const state = createASN1State(buf);
|
|
2876
|
-
expectTag(state, 48, "Invalid certificate structure");
|
|
2877
|
-
const certificateLength = parseLength(state);
|
|
2878
|
-
if (certificateLength < 0 || state.pos + certificateLength > state.data.length) {
|
|
2879
|
-
throw new Error("Unexpected end of ASN.1 input");
|
|
2880
|
-
}
|
|
2881
|
-
expectTag(state, 48, "Invalid tbsCertificate structure");
|
|
2882
|
-
parseLength(state);
|
|
2883
|
-
if (buf[state.pos] === 160) {
|
|
2884
|
-
skipElement(state, 6);
|
|
2885
|
-
} else {
|
|
2886
|
-
skipElement(state, 5);
|
|
2887
|
-
}
|
|
2888
|
-
const spkiStart = state.pos;
|
|
2889
|
-
expectTag(state, 48, "Invalid SPKI structure");
|
|
2890
|
-
const spkiContentLen = parseLength(state);
|
|
2891
|
-
return buf.subarray(spkiStart, spkiStart + spkiContentLen + (state.pos - spkiStart));
|
|
2892
|
-
}
|
|
2893
|
-
var fromX509 = (pem, alg, options) => {
|
|
2894
|
-
let spki;
|
|
2895
|
-
try {
|
|
2896
|
-
const certificate = processPEMData(pem, /(?:-----(?:BEGIN|END) CERTIFICATE-----|\s)/g);
|
|
2897
|
-
spki = spkiFromX509(certificate);
|
|
2898
|
-
} catch (cause) {
|
|
2899
|
-
throw new TypeError("Failed to parse the X.509 certificate", { cause });
|
|
2900
|
-
}
|
|
2901
|
-
return genericImport("spki", spki, alg, options);
|
|
2902
|
-
};
|
|
2903
|
-
|
|
2904
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/key/export.js
|
|
2905
|
-
function omitUndefinedProperties(jwk) {
|
|
2906
|
-
return Object.fromEntries(Object.entries(jwk).filter(([, value]) => value !== void 0));
|
|
2907
|
-
}
|
|
2908
|
-
async function keyToJWK(key) {
|
|
2909
|
-
if (isKeyObject(key)) {
|
|
2910
|
-
if (key.type === "secret") {
|
|
2911
|
-
key = key.export();
|
|
2912
|
-
} else {
|
|
2913
|
-
return key.export({ format: "jwk" });
|
|
2914
|
-
}
|
|
2915
|
-
}
|
|
2916
|
-
if (key instanceof Uint8Array) {
|
|
2917
|
-
return {
|
|
2918
|
-
kty: "oct",
|
|
2919
|
-
k: encode2(key)
|
|
2920
|
-
};
|
|
2921
|
-
}
|
|
2922
|
-
if (!isCryptoKey(key)) {
|
|
2923
|
-
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "Uint8Array"));
|
|
2924
|
-
}
|
|
2925
|
-
if (!key.extractable) {
|
|
2926
|
-
throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");
|
|
2927
|
-
}
|
|
2928
|
-
const { ext, key_ops, alg, use, ...jwk } = omitUndefinedProperties(await crypto.subtle.exportKey("jwk", key));
|
|
2929
|
-
if (jwk.kty === "AKP") {
|
|
2930
|
-
;
|
|
2931
|
-
jwk.alg = alg;
|
|
2932
|
-
}
|
|
2933
|
-
return jwk;
|
|
2934
|
-
}
|
|
2935
|
-
function exportSPKI(key) {
|
|
2936
|
-
return toSPKI(key);
|
|
2937
|
-
}
|
|
2938
|
-
function exportPKCS8(key) {
|
|
2939
|
-
return toPKCS8(key);
|
|
2940
|
-
}
|
|
2941
|
-
function exportJWK(key) {
|
|
2942
|
-
return keyToJWK(key);
|
|
2943
|
-
}
|
|
2944
|
-
|
|
2945
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/jwk/thumbprint.js
|
|
2946
|
-
var check = (value, description) => {
|
|
2947
|
-
if (typeof value !== "string" || !value) {
|
|
2948
|
-
throw new JWKInvalid(`${description} missing or invalid`);
|
|
2949
|
-
}
|
|
2950
|
-
};
|
|
2951
|
-
async function calculateJwkThumbprint(key, digestAlgorithm) {
|
|
2952
|
-
let jwk;
|
|
2953
|
-
if (isObject(key)) {
|
|
2954
|
-
jwk = snapshotJwk(key);
|
|
2955
|
-
if (typeof jwk.kty !== "string") {
|
|
2956
|
-
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
2957
|
-
}
|
|
2958
|
-
} else if (isKeyLike(key)) {
|
|
2959
|
-
jwk = snapshotJwk(await exportJWK(key));
|
|
2960
|
-
} else {
|
|
2961
|
-
throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
2962
|
-
}
|
|
2963
|
-
digestAlgorithm ??= "sha256";
|
|
2964
|
-
if (digestAlgorithm !== "sha256" && digestAlgorithm !== "sha384" && digestAlgorithm !== "sha512") {
|
|
2965
|
-
throw new TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');
|
|
2966
|
-
}
|
|
2967
|
-
let components;
|
|
2968
|
-
switch (jwk.kty) {
|
|
2969
|
-
case "AKP":
|
|
2970
|
-
check(jwk.alg, '"alg" (Algorithm) Parameter');
|
|
2971
|
-
check(jwk.pub, '"pub" (Public key) Parameter');
|
|
2972
|
-
components = { alg: jwk.alg, kty: jwk.kty, pub: jwk.pub };
|
|
2973
|
-
break;
|
|
2974
|
-
case "EC":
|
|
2975
|
-
check(jwk.crv, '"crv" (Curve) Parameter');
|
|
2976
|
-
check(jwk.x, '"x" (X Coordinate) Parameter');
|
|
2977
|
-
check(jwk.y, '"y" (Y Coordinate) Parameter');
|
|
2978
|
-
components = { crv: jwk.crv, kty: jwk.kty, x: jwk.x, y: jwk.y };
|
|
2979
|
-
break;
|
|
2980
|
-
case "OKP":
|
|
2981
|
-
check(jwk.crv, '"crv" (Subtype of Key Pair) Parameter');
|
|
2982
|
-
check(jwk.x, '"x" (Public Key) Parameter');
|
|
2983
|
-
components = { crv: jwk.crv, kty: jwk.kty, x: jwk.x };
|
|
2984
|
-
break;
|
|
2985
|
-
case "RSA":
|
|
2986
|
-
check(jwk.e, '"e" (Exponent) Parameter');
|
|
2987
|
-
check(jwk.n, '"n" (Modulus) Parameter');
|
|
2988
|
-
components = { e: jwk.e, kty: jwk.kty, n: jwk.n };
|
|
2989
|
-
break;
|
|
2990
|
-
case "oct":
|
|
2991
|
-
if (typeof jwk.k !== "string") {
|
|
2992
|
-
throw new JWKInvalid('"k" (Key Value) Parameter missing or invalid');
|
|
2993
|
-
}
|
|
2994
|
-
components = { k: jwk.k, kty: jwk.kty };
|
|
2995
|
-
break;
|
|
2996
|
-
default:
|
|
2997
|
-
throw new JOSENotSupported('"kty" (Key Type) Parameter missing or unsupported');
|
|
2998
|
-
}
|
|
2999
|
-
const data = encode(JSON.stringify(components));
|
|
3000
|
-
return encode2(await digest(digestAlgorithm, data));
|
|
3001
|
-
}
|
|
3002
|
-
async function calculateJwkThumbprintUri(key, digestAlgorithm) {
|
|
3003
|
-
digestAlgorithm ??= "sha256";
|
|
3004
|
-
const thumbprint = await calculateJwkThumbprint(key, digestAlgorithm);
|
|
3005
|
-
return `urn:ietf:params:oauth:jwk-thumbprint:sha-${digestAlgorithm.slice(-3)}:${thumbprint}`;
|
|
3006
|
-
}
|
|
3007
|
-
|
|
3008
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/jwk/embedded.js
|
|
3009
|
-
async function EmbeddedJWK(protectedHeader, token) {
|
|
3010
|
-
const joseHeader = {
|
|
3011
|
-
...protectedHeader,
|
|
3012
|
-
...token?.header
|
|
3013
|
-
};
|
|
3014
|
-
if (!isObject(joseHeader.jwk)) {
|
|
3015
|
-
throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a JSON object');
|
|
3016
|
-
}
|
|
3017
|
-
let jwk;
|
|
3018
|
-
try {
|
|
3019
|
-
jwk = normalizeJwk(joseHeader.jwk);
|
|
3020
|
-
} catch (cause) {
|
|
3021
|
-
throw new JWSInvalid("Invalid Embedded JWK", { cause });
|
|
3022
|
-
}
|
|
3023
|
-
const entry = jwsAlgorithm(joseHeader.alg);
|
|
3024
|
-
if (jwk.use !== void 0 && jwk.use !== "sig") {
|
|
3025
|
-
throw new JWSInvalid('Invalid Embedded JWK, its "use" must be "sig" when present');
|
|
3026
|
-
}
|
|
3027
|
-
if (jwk.alg !== void 0 && jwk.alg !== entry.alg) {
|
|
3028
|
-
throw new JWSInvalid(`Invalid Embedded JWK, its "alg" must be "${entry.alg}" when present`);
|
|
3029
|
-
}
|
|
3030
|
-
const key = await jwkToKey(entry, { ...jwk, ext: true });
|
|
3031
|
-
if (key.type !== "public") {
|
|
3032
|
-
throw new JWSInvalid('"jwk" (JSON Web Key) Header Parameter must be a public key');
|
|
3033
|
-
}
|
|
3034
|
-
return key;
|
|
3035
|
-
}
|
|
3036
|
-
|
|
3037
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/jwks/local.js
|
|
3038
|
-
function isUsableJWK(jwk, entry, alg, kid) {
|
|
3039
|
-
const { kty, key_ops, ext, kid: jwkKid, alg: jwkAlg, use, crv } = snapshotJwk(jwk);
|
|
3040
|
-
const keyOps = Array.isArray(key_ops) ? [...key_ops] : key_ops;
|
|
3041
|
-
return (ext === void 0 || typeof ext === "boolean") && (keyOps === void 0 || Array.isArray(keyOps) && keyOps.every((operation, index) => typeof operation === "string" && keyOps.indexOf(operation) === index) && keyOps.includes("verify")) && entry.kty.includes(kty) && (kid === void 0 || typeof kid === "string" && kid === jwkKid) && (jwkAlg === void 0 ? kty !== "AKP" : alg === jwkAlg) && (use === void 0 || use === "sig") && (!entry.crv || crv === entry.crv);
|
|
3042
|
-
}
|
|
3043
|
-
async function importWithAlgCache(cache2, jwk, entry) {
|
|
3044
|
-
const cached2 = cache2.get(jwk) || cache2.set(jwk, {}).get(jwk);
|
|
3045
|
-
const { alg } = entry;
|
|
3046
|
-
if (cached2[alg] === void 0) {
|
|
3047
|
-
const key = await jwkToKey(entry, { ...jwk, alg, ext: true });
|
|
3048
|
-
if (key.type !== "public") {
|
|
3049
|
-
throw new JWKSInvalid("JSON Web Key Set members must be public keys");
|
|
3050
|
-
}
|
|
3051
|
-
cached2[alg] = key;
|
|
3052
|
-
}
|
|
3053
|
-
return cached2[alg];
|
|
3054
|
-
}
|
|
3055
|
-
function createLocalJWKSet(jwks) {
|
|
3056
|
-
let snapshot;
|
|
3057
|
-
try {
|
|
3058
|
-
snapshot = structuredClone(jwks);
|
|
3059
|
-
} catch {
|
|
3060
|
-
}
|
|
3061
|
-
if (!isJwkSet(snapshot)) {
|
|
3062
|
-
throw new JWKSInvalid("JSON Web Key Set malformed");
|
|
3063
|
-
}
|
|
3064
|
-
const cached2 = /* @__PURE__ */ new WeakMap();
|
|
3065
|
-
const localJWKSet = async (protectedHeader, token) => {
|
|
3066
|
-
const { alg, kid } = { ...protectedHeader, ...token?.header };
|
|
3067
|
-
const entry = typeof alg === "string" ? JWS[alg] : void 0;
|
|
3068
|
-
if (!entry || entry.secret) {
|
|
3069
|
-
throw new JOSENotSupported('Unsupported "alg" value for a JSON Web Key Set');
|
|
3070
|
-
}
|
|
3071
|
-
const candidates = snapshot.keys.filter((jwk2) => isUsableJWK(jwk2, entry, alg, kid));
|
|
3072
|
-
const { 0: jwk, length } = candidates;
|
|
3073
|
-
if (!length) {
|
|
3074
|
-
throw new JWKSNoMatchingKey();
|
|
3075
|
-
}
|
|
3076
|
-
if (length !== 1) {
|
|
3077
|
-
const error = new JWKSMultipleMatchingKeys();
|
|
3078
|
-
error[Symbol.asyncIterator] = async function* () {
|
|
3079
|
-
for (const jwk2 of candidates) {
|
|
3080
|
-
try {
|
|
3081
|
-
yield await importWithAlgCache(cached2, jwk2, entry);
|
|
3082
|
-
} catch {
|
|
3083
|
-
}
|
|
3084
|
-
}
|
|
3085
|
-
};
|
|
3086
|
-
throw error;
|
|
3087
|
-
}
|
|
3088
|
-
return importWithAlgCache(cached2, jwk, entry);
|
|
3089
|
-
};
|
|
3090
|
-
return Object.defineProperty(localJWKSet, "jwks", {
|
|
3091
|
-
value: () => structuredClone(snapshot)
|
|
3092
|
-
});
|
|
3093
|
-
}
|
|
3094
|
-
|
|
3095
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/jwks/remote.js
|
|
3096
|
-
function isCloudflareWorkers() {
|
|
3097
|
-
return typeof WebSocketPair !== "undefined" || typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime !== "undefined" && EdgeRuntime === "vercel";
|
|
3098
|
-
}
|
|
3099
|
-
var USER_AGENT;
|
|
3100
|
-
if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) {
|
|
3101
|
-
const NAME = "jose";
|
|
3102
|
-
const VERSION = "v6.2.10";
|
|
3103
|
-
USER_AGENT = `${NAME}/${VERSION}`;
|
|
3104
|
-
}
|
|
3105
|
-
var customFetch = /* @__PURE__ */ Symbol();
|
|
3106
|
-
async function fetchJwks(url, headers, signal, fetchImpl = fetch) {
|
|
3107
|
-
const response = await fetchImpl(url, {
|
|
3108
|
-
method: "GET",
|
|
3109
|
-
signal,
|
|
3110
|
-
redirect: "manual",
|
|
3111
|
-
headers
|
|
3112
|
-
}).catch((err) => {
|
|
3113
|
-
if (err.name === "TimeoutError") {
|
|
3114
|
-
throw new JWKSTimeout();
|
|
3115
|
-
}
|
|
3116
|
-
throw err;
|
|
3117
|
-
});
|
|
3118
|
-
if (response.status !== 200) {
|
|
3119
|
-
throw new JOSEError("Expected 200 OK from the JSON Web Key Set HTTP response");
|
|
3120
|
-
}
|
|
3121
|
-
try {
|
|
3122
|
-
return await response.json();
|
|
3123
|
-
} catch {
|
|
3124
|
-
throw new JOSEError("Failed to parse the JSON Web Key Set HTTP response as JSON");
|
|
3125
|
-
}
|
|
3126
|
-
}
|
|
3127
|
-
var jwksCache = /* @__PURE__ */ Symbol();
|
|
3128
|
-
function isFreshFor(timestamp, duration) {
|
|
3129
|
-
return Number.isFinite(timestamp) && Date.now() < timestamp + duration;
|
|
3130
|
-
}
|
|
3131
|
-
function validateDuration(value, fallback, option) {
|
|
3132
|
-
if (Number.isNaN(value)) {
|
|
3133
|
-
throw new TypeError(`"${option}" option must not be NaN`);
|
|
3134
|
-
}
|
|
3135
|
-
return typeof value === "number" ? value : fallback;
|
|
3136
|
-
}
|
|
3137
|
-
function createRemoteJWKSet(url, options) {
|
|
3138
|
-
if (!(url instanceof URL)) {
|
|
3139
|
-
throw new TypeError("url must be an instance of URL");
|
|
3140
|
-
}
|
|
3141
|
-
const href = new URL(url.href).href;
|
|
3142
|
-
const opts = options ?? {};
|
|
3143
|
-
const timeoutOption = opts.timeoutDuration;
|
|
3144
|
-
if (typeof timeoutOption === "number" && (!Number.isInteger(timeoutOption) || timeoutOption < 0)) {
|
|
3145
|
-
throw new TypeError('"timeoutDuration" option must be a non-negative integer');
|
|
3146
|
-
}
|
|
3147
|
-
const timeoutDuration = typeof timeoutOption === "number" ? timeoutOption : 5e3;
|
|
3148
|
-
const cooldownDuration = validateDuration(opts.cooldownDuration, 3e4, "cooldownDuration");
|
|
3149
|
-
const cacheMaxAge = validateDuration(opts.cacheMaxAge, 6e5, "cacheMaxAge");
|
|
3150
|
-
const headers = new Headers(opts.headers);
|
|
3151
|
-
if (USER_AGENT && !headers.has("User-Agent")) {
|
|
3152
|
-
headers.set("User-Agent", USER_AGENT);
|
|
3153
|
-
}
|
|
3154
|
-
if (!headers.has("accept")) {
|
|
3155
|
-
headers.set("accept", "application/json, application/jwk-set+json");
|
|
3156
|
-
}
|
|
3157
|
-
const fetchImpl = opts[customFetch];
|
|
3158
|
-
const cache2 = opts[jwksCache];
|
|
3159
|
-
let jwksTimestamp;
|
|
3160
|
-
let pendingFetch;
|
|
3161
|
-
let reloadSequence = 0;
|
|
3162
|
-
let appliedSequence = 0;
|
|
3163
|
-
let local;
|
|
3164
|
-
if (cache2 && typeof cache2 === "object") {
|
|
3165
|
-
const { uat, jwks } = cache2;
|
|
3166
|
-
if (isFreshFor(uat, cacheMaxAge) && isJwkSet(jwks)) {
|
|
3167
|
-
jwksTimestamp = uat;
|
|
3168
|
-
local = createLocalJWKSet(jwks);
|
|
3169
|
-
}
|
|
3170
|
-
}
|
|
3171
|
-
const reload = async () => {
|
|
3172
|
-
if (pendingFetch && isCloudflareWorkers()) {
|
|
3173
|
-
pendingFetch = void 0;
|
|
3174
|
-
}
|
|
3175
|
-
if (!pendingFetch) {
|
|
3176
|
-
const sequence = ++reloadSequence;
|
|
3177
|
-
const current = pendingFetch = fetchJwks(href, headers, AbortSignal.timeout(timeoutDuration), fetchImpl).then((json) => {
|
|
3178
|
-
const next = createLocalJWKSet(json);
|
|
3179
|
-
if (sequence <= appliedSequence) {
|
|
3180
|
-
return;
|
|
3181
|
-
}
|
|
3182
|
-
local = next;
|
|
3183
|
-
const updatedAt = Date.now();
|
|
3184
|
-
if (cache2) {
|
|
3185
|
-
cache2.uat = updatedAt;
|
|
3186
|
-
cache2.jwks = json;
|
|
3187
|
-
}
|
|
3188
|
-
jwksTimestamp = updatedAt;
|
|
3189
|
-
appliedSequence = sequence;
|
|
3190
|
-
}).finally(() => {
|
|
3191
|
-
if (pendingFetch === current) {
|
|
3192
|
-
pendingFetch = void 0;
|
|
3193
|
-
}
|
|
3194
|
-
});
|
|
3195
|
-
}
|
|
3196
|
-
await pendingFetch;
|
|
3197
|
-
};
|
|
3198
|
-
const remoteJWKSet = async (protectedHeader, token) => {
|
|
3199
|
-
if (!local || !isFreshFor(jwksTimestamp, cacheMaxAge)) {
|
|
3200
|
-
await reload();
|
|
3201
|
-
}
|
|
3202
|
-
try {
|
|
3203
|
-
return await local(protectedHeader, token);
|
|
3204
|
-
} catch (err) {
|
|
3205
|
-
if (err instanceof JWKSNoMatchingKey && !isFreshFor(jwksTimestamp, cooldownDuration)) {
|
|
3206
|
-
await reload();
|
|
3207
|
-
return local(protectedHeader, token);
|
|
3208
|
-
}
|
|
3209
|
-
throw err;
|
|
3210
|
-
}
|
|
3211
|
-
};
|
|
3212
|
-
return Object.defineProperties(remoteJWKSet, {
|
|
3213
|
-
coolingDown: {
|
|
3214
|
-
get: () => isFreshFor(jwksTimestamp, cooldownDuration),
|
|
3215
|
-
enumerable: true
|
|
3216
|
-
},
|
|
3217
|
-
fresh: {
|
|
3218
|
-
get: () => isFreshFor(jwksTimestamp, cacheMaxAge),
|
|
3219
|
-
enumerable: true
|
|
3220
|
-
},
|
|
3221
|
-
reload: {
|
|
3222
|
-
value: reload,
|
|
3223
|
-
enumerable: true
|
|
3224
|
-
},
|
|
3225
|
-
reloading: {
|
|
3226
|
-
get: () => !!pendingFetch,
|
|
3227
|
-
enumerable: true
|
|
3228
|
-
},
|
|
3229
|
-
jwks: {
|
|
3230
|
-
value: () => local?.jwks(),
|
|
3231
|
-
enumerable: true
|
|
3232
|
-
}
|
|
3233
|
-
});
|
|
3234
|
-
}
|
|
3235
|
-
|
|
3236
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/jwt/unsecured.js
|
|
3237
|
-
var UnsecuredJWT_base = JWTClaimsBuilder;
|
|
3238
|
-
var UnsecuredJWT = class extends UnsecuredJWT_base {
|
|
3239
|
-
encode() {
|
|
3240
|
-
const header = encode2(JSON.stringify({ alg: "none" }));
|
|
3241
|
-
const payload = encode2(jwtData(this));
|
|
3242
|
-
return `${header}.${payload}.`;
|
|
3243
|
-
}
|
|
3244
|
-
static decode(jwt, options) {
|
|
3245
|
-
if (typeof jwt !== "string") {
|
|
3246
|
-
throw new JWTInvalid("Unsecured JWT must be a string");
|
|
3247
|
-
}
|
|
3248
|
-
const { 0: encodedHeader, 1: encodedPayload, 2: signature, length } = jwt.split(".");
|
|
3249
|
-
if (length !== 3 || signature !== "") {
|
|
3250
|
-
throw new JWTInvalid("Invalid Unsecured JWT");
|
|
3251
|
-
}
|
|
3252
|
-
let header;
|
|
3253
|
-
let b64;
|
|
3254
|
-
try {
|
|
3255
|
-
header = parseJoseHeader(encodedHeader, JWSInvalid, "JWS Protected Header is invalid");
|
|
3256
|
-
const extensions = validateCrit(JWSInvalid, JWS_RECOGNIZED, void 0, header, header);
|
|
3257
|
-
b64 = validateB64(header, extensions);
|
|
3258
|
-
} catch (cause) {
|
|
3259
|
-
if (!(cause instanceof JWSInvalid)) {
|
|
3260
|
-
throw cause;
|
|
3261
|
-
}
|
|
3262
|
-
throw new JWTInvalid("Invalid Unsecured JWT", { cause });
|
|
3263
|
-
}
|
|
3264
|
-
if (header.alg !== "none") {
|
|
3265
|
-
throw new JWTInvalid("Invalid Unsecured JWT");
|
|
3266
|
-
}
|
|
3267
|
-
if (!b64) {
|
|
3268
|
-
throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
3269
|
-
}
|
|
3270
|
-
const payload = validateClaimsSet(header, decodeBase64url(encodedPayload, "payload", JWTInvalid), options);
|
|
3271
|
-
return { payload, header };
|
|
3272
|
-
}
|
|
3273
|
-
};
|
|
3274
|
-
|
|
3275
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/key/import.js
|
|
3276
|
-
async function importSPKI(spki, alg, options) {
|
|
3277
|
-
if (typeof spki !== "string" || spki.indexOf("-----BEGIN PUBLIC KEY-----") !== 0) {
|
|
3278
|
-
throw new TypeError('"spki" must be SPKI formatted string');
|
|
3279
|
-
}
|
|
3280
|
-
return fromSPKI(spki, alg, options);
|
|
3281
|
-
}
|
|
3282
|
-
async function importX509(x509, alg, options) {
|
|
3283
|
-
if (typeof x509 !== "string" || x509.indexOf("-----BEGIN CERTIFICATE-----") !== 0) {
|
|
3284
|
-
throw new TypeError('"x509" must be X.509 formatted string');
|
|
3285
|
-
}
|
|
3286
|
-
return fromX509(x509, alg, options);
|
|
3287
|
-
}
|
|
3288
|
-
async function importPKCS8(pkcs8, alg, options) {
|
|
3289
|
-
if (typeof pkcs8 !== "string" || pkcs8.indexOf("-----BEGIN PRIVATE KEY-----") !== 0) {
|
|
3290
|
-
throw new TypeError('"pkcs8" must be PKCS#8 formatted string');
|
|
3291
|
-
}
|
|
3292
|
-
return fromPKCS8(pkcs8, alg, options);
|
|
3293
|
-
}
|
|
3294
|
-
async function importJWK(jwk, alg, options) {
|
|
3295
|
-
if (!isObject(jwk)) {
|
|
3296
|
-
throw new TypeError("JWK must be an object");
|
|
3297
|
-
}
|
|
3298
|
-
const normalized = normalizeJwk(jwk);
|
|
3299
|
-
const extractable = validateExtractableOption(options?.extractable);
|
|
3300
|
-
const { alg: jwkAlg } = normalized;
|
|
3301
|
-
alg ??= jwkAlg;
|
|
3302
|
-
const ext = extractable ?? normalized.ext;
|
|
3303
|
-
if (normalized.kty !== "oct" && !alg) {
|
|
3304
|
-
throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
|
|
3305
|
-
}
|
|
3306
|
-
switch (normalized.kty) {
|
|
3307
|
-
case "oct":
|
|
3308
|
-
if (typeof normalized.k !== "string") {
|
|
3309
|
-
throw new TypeError('missing "k" (Key Value) Parameter value');
|
|
3310
|
-
}
|
|
3311
|
-
return decode(normalized.k);
|
|
3312
|
-
case "AKP": {
|
|
3313
|
-
if (typeof jwkAlg !== "string" || !jwkAlg) {
|
|
3314
|
-
throw new TypeError('missing "alg" (Algorithm) Parameter value');
|
|
3315
|
-
}
|
|
3316
|
-
if (alg !== jwkAlg) {
|
|
3317
|
-
throw new TypeError("JWK alg and alg option value mismatch");
|
|
3318
|
-
}
|
|
3319
|
-
return jwkToKey(keyAlgorithm(alg), { ...normalized, ext });
|
|
3320
|
-
}
|
|
3321
|
-
case "RSA":
|
|
3322
|
-
case "EC":
|
|
3323
|
-
case "OKP":
|
|
3324
|
-
return jwkToKey(keyAlgorithm(alg), { ...normalized, alg, ext });
|
|
3325
|
-
default:
|
|
3326
|
-
throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
|
|
3327
|
-
}
|
|
3328
|
-
}
|
|
3329
|
-
|
|
3330
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/util/decode_protected_header.js
|
|
3331
|
-
function decodeProtectedHeader(token) {
|
|
3332
|
-
let protectedB64u;
|
|
3333
|
-
if (typeof token === "string") {
|
|
3334
|
-
const parts = token.split(".");
|
|
3335
|
-
if (parts.length === 3 || parts.length === 5) {
|
|
3336
|
-
;
|
|
3337
|
-
[protectedB64u] = parts;
|
|
3338
|
-
}
|
|
3339
|
-
} else if (typeof token === "object" && token) {
|
|
3340
|
-
if ("protected" in token) {
|
|
3341
|
-
protectedB64u = token.protected;
|
|
3342
|
-
} else {
|
|
3343
|
-
throw new TypeError("Token does not contain a Protected Header");
|
|
3344
|
-
}
|
|
3345
|
-
}
|
|
3346
|
-
const invalid2 = "Invalid Token or Protected Header formatting";
|
|
3347
|
-
if (typeof protectedB64u !== "string" || !protectedB64u) {
|
|
3348
|
-
throw new TypeError(invalid2);
|
|
3349
|
-
}
|
|
3350
|
-
return parseJoseHeader(protectedB64u, TypeError, invalid2);
|
|
3351
|
-
}
|
|
3352
|
-
|
|
3353
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/util/decode_jwt.js
|
|
3354
|
-
function decodeJwt(jwt) {
|
|
3355
|
-
if (typeof jwt !== "string")
|
|
3356
|
-
throw new JWTInvalid("JWTs must use Compact JWS serialization, JWT must be a string");
|
|
3357
|
-
const { 1: payload, length } = jwt.split(".");
|
|
3358
|
-
if (length === 5)
|
|
3359
|
-
throw new JWTInvalid("Only JWTs using Compact JWS serialization can be decoded");
|
|
3360
|
-
if (length !== 3)
|
|
3361
|
-
throw new JWTInvalid("Invalid JWT");
|
|
3362
|
-
if (!payload)
|
|
3363
|
-
throw new JWTInvalid("JWTs must contain a payload");
|
|
3364
|
-
let decoded;
|
|
3365
|
-
try {
|
|
3366
|
-
decoded = decode(payload);
|
|
3367
|
-
} catch {
|
|
3368
|
-
throw new JWTInvalid("Failed to base64url decode the payload");
|
|
3369
|
-
}
|
|
3370
|
-
let result;
|
|
3371
|
-
try {
|
|
3372
|
-
result = JSON.parse(strictDecoder.decode(decoded));
|
|
3373
|
-
} catch {
|
|
3374
|
-
throw new JWTInvalid("Failed to parse the decoded payload as JSON");
|
|
3375
|
-
}
|
|
3376
|
-
if (!isObject(result))
|
|
3377
|
-
throw new JWTInvalid("Invalid JWT Claims Set");
|
|
3378
|
-
return result;
|
|
3379
|
-
}
|
|
3380
|
-
|
|
3381
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/key/generate_key_pair.js
|
|
3382
|
-
function getModulusLengthOption(options) {
|
|
3383
|
-
const modulusLength = options?.modulusLength ?? 2048;
|
|
3384
|
-
if (typeof modulusLength !== "number" || !Number.isInteger(modulusLength) || modulusLength < 2048) {
|
|
3385
|
-
throw new JOSENotSupported("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");
|
|
3386
|
-
}
|
|
3387
|
-
return modulusLength;
|
|
3388
|
-
}
|
|
3389
|
-
async function generateKeyPair(alg, options) {
|
|
3390
|
-
const extractable = validateExtractableOption(options?.extractable);
|
|
3391
|
-
const entry = keyAlgorithm(alg, algArgument);
|
|
3392
|
-
if (entry.secret) {
|
|
3393
|
-
unsupportedAlg(algArgument);
|
|
3394
|
-
}
|
|
3395
|
-
let algorithm;
|
|
3396
|
-
if (entry.resolve) {
|
|
3397
|
-
const crv = options?.crv ?? "P-256";
|
|
3398
|
-
switch (crv) {
|
|
3399
|
-
case "P-256":
|
|
3400
|
-
case "P-384":
|
|
3401
|
-
case "P-521":
|
|
3402
|
-
algorithm = { name: "ECDH", namedCurve: crv };
|
|
3403
|
-
break;
|
|
3404
|
-
case "X25519":
|
|
3405
|
-
algorithm = { name: "X25519" };
|
|
3406
|
-
break;
|
|
3407
|
-
default:
|
|
3408
|
-
throw new JOSENotSupported("Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, and X25519");
|
|
3409
|
-
}
|
|
3410
|
-
} else {
|
|
3411
|
-
if (entry.crv !== void 0 && options?.crv !== void 0 && options.crv !== entry.crv) {
|
|
3412
|
-
throw new JOSENotSupported(`Invalid or unsupported crv option provided, the only supported value for ${alg} is ${entry.crv}`);
|
|
3413
|
-
}
|
|
3414
|
-
algorithm = entry.kty[0] === "RSA" ? {
|
|
3415
|
-
...entry.subtle,
|
|
3416
|
-
publicExponent: Uint8Array.of(1, 0, 1),
|
|
3417
|
-
modulusLength: getModulusLengthOption(options)
|
|
3418
|
-
} : entry.subtle;
|
|
3419
|
-
}
|
|
3420
|
-
return crypto.subtle.generateKey(algorithm, extractable ?? false, [
|
|
3421
|
-
...entry.usages[1],
|
|
3422
|
-
...entry.usages[0]
|
|
3423
|
-
]);
|
|
3424
|
-
}
|
|
3425
|
-
|
|
3426
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/key/generate_secret.js
|
|
3427
|
-
async function generateSecret(alg, options) {
|
|
3428
|
-
const extractable = validateExtractableOption(options?.extractable);
|
|
3429
|
-
let length;
|
|
3430
|
-
let algorithm;
|
|
3431
|
-
let keyUsages;
|
|
3432
|
-
switch (alg) {
|
|
3433
|
-
case "HS256":
|
|
3434
|
-
case "HS384":
|
|
3435
|
-
case "HS512":
|
|
3436
|
-
length = +alg.slice(-3);
|
|
3437
|
-
algorithm = { name: "HMAC", hash: `SHA-${length}`, length };
|
|
3438
|
-
keyUsages = ["sign", "verify"];
|
|
3439
|
-
break;
|
|
3440
|
-
case "A128CBC-HS256":
|
|
3441
|
-
case "A192CBC-HS384":
|
|
3442
|
-
case "A256CBC-HS512":
|
|
3443
|
-
return crypto.getRandomValues(new Uint8Array(+alg.slice(-3) >> 3));
|
|
3444
|
-
case "A128KW":
|
|
3445
|
-
case "A192KW":
|
|
3446
|
-
case "A256KW":
|
|
3447
|
-
length = +alg.slice(1, 4);
|
|
3448
|
-
algorithm = { name: "AES-KW", length };
|
|
3449
|
-
keyUsages = ["wrapKey", "unwrapKey"];
|
|
3450
|
-
break;
|
|
3451
|
-
case "A128GCMKW":
|
|
3452
|
-
case "A192GCMKW":
|
|
3453
|
-
case "A256GCMKW":
|
|
3454
|
-
case "A128GCM":
|
|
3455
|
-
case "A192GCM":
|
|
3456
|
-
case "A256GCM":
|
|
3457
|
-
length = +alg.slice(1, 4);
|
|
3458
|
-
algorithm = { name: "AES-GCM", length };
|
|
3459
|
-
keyUsages = ["encrypt", "decrypt"];
|
|
3460
|
-
break;
|
|
3461
|
-
default:
|
|
3462
|
-
unsupportedAlg(algArgument);
|
|
3463
|
-
}
|
|
3464
|
-
return crypto.subtle.generateKey(algorithm, extractable ?? false, keyUsages);
|
|
3465
|
-
}
|
|
3466
|
-
|
|
3467
|
-
// node_modules/.pnpm/jose@6.2.10/node_modules/jose/dist/webapi/index.js
|
|
3468
|
-
var cryptoRuntime = "WebCryptoAPI";
|
|
3469
|
-
export {
|
|
3470
|
-
CompactEncrypt,
|
|
3471
|
-
CompactSign,
|
|
3472
|
-
EmbeddedJWK,
|
|
3473
|
-
EncryptJWT,
|
|
3474
|
-
FlattenedEncrypt,
|
|
3475
|
-
FlattenedSign,
|
|
3476
|
-
GeneralEncrypt,
|
|
3477
|
-
GeneralSign,
|
|
3478
|
-
SignJWT,
|
|
3479
|
-
UnsecuredJWT,
|
|
3480
|
-
base64url_exports as base64url,
|
|
3481
|
-
calculateJwkThumbprint,
|
|
3482
|
-
calculateJwkThumbprintUri,
|
|
3483
|
-
compactDecrypt,
|
|
3484
|
-
compactVerify,
|
|
3485
|
-
createLocalJWKSet,
|
|
3486
|
-
createRemoteJWKSet,
|
|
3487
|
-
cryptoRuntime,
|
|
3488
|
-
customFetch,
|
|
3489
|
-
decodeJwt,
|
|
3490
|
-
decodeProtectedHeader,
|
|
3491
|
-
errors_exports as errors,
|
|
3492
|
-
exportJWK,
|
|
3493
|
-
exportPKCS8,
|
|
3494
|
-
exportSPKI,
|
|
3495
|
-
flattenedDecrypt,
|
|
3496
|
-
flattenedVerify,
|
|
3497
|
-
generalDecrypt,
|
|
3498
|
-
generalVerify,
|
|
3499
|
-
generateKeyPair,
|
|
3500
|
-
generateSecret,
|
|
3501
|
-
importJWK,
|
|
3502
|
-
importPKCS8,
|
|
3503
|
-
importSPKI,
|
|
3504
|
-
importX509,
|
|
3505
|
-
jwksCache,
|
|
3506
|
-
jwtDecrypt,
|
|
3507
|
-
jwtVerify
|
|
3508
|
-
};
|