@teammy/server 0.2.23 → 0.2.25

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.
Files changed (166) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +11 -7
  3. package/dist/main.js +21235 -13704
  4. package/dist/native-pi-entry.js +815 -19
  5. package/dist/project-pi-entry.js +818 -22
  6. package/dist/runtime/en/shared/system.md +9 -0
  7. package/dist/runtime/en/shared/tools.json +22 -0
  8. package/dist/runtime/en/workflows/directory-analysis/prompt.md +11 -0
  9. package/dist/runtime/en/workflows/file-summary/prompt.md +7 -0
  10. package/dist/runtime/en/workflows/session-handoff/prompt.md +31 -0
  11. package/dist/runtime/en/workflows/session-overview/prompt.md +26 -0
  12. package/dist/runtime/en/workflows/task-bootstrap/prompt.md +84 -0
  13. package/dist/runtime/shared/system.md +1 -1
  14. package/dist/runtime/workflows/session-handoff/prompt.md +1 -1
  15. package/dist/runtime/workflows/session-overview/prompt.md +1 -1
  16. package/dist/web/THIRD-PARTY-LICENSES.md +2025 -0
  17. package/dist/web/assets/Assistant-C-GBv5St.js +1 -0
  18. package/dist/web/assets/Computers-B-FvcufX.js +14 -0
  19. package/dist/web/assets/{Computers-BtcIsnDD.css → Computers-BJKv9oJv.css} +1 -1
  20. package/dist/web/assets/Conversation-Dzr18Rmq.js +1 -0
  21. package/dist/web/assets/Dashboard-5ksfc6l9.js +1 -0
  22. package/dist/web/assets/Files-DqrIDBJI.js +1 -0
  23. package/dist/web/assets/Help-JsdkpQ8l.js +2413 -0
  24. package/dist/web/assets/MessageComposer-DOJ1PYXg.js +1 -0
  25. package/dist/web/assets/MessageComposer-DqcbXBIG.css +1 -0
  26. package/dist/web/assets/ResourceLibrary--aVsAt6m.js +6 -0
  27. package/dist/web/assets/TerminalPane-jJa53g04.js +22 -0
  28. package/dist/web/assets/WorkspaceTree-CuwIu3vj.js +1 -0
  29. package/dist/web/assets/file-links-BnaVOi2G.js +1 -0
  30. package/dist/web/assets/index-B9gF6reY.css +1 -0
  31. package/dist/web/assets/index-Ck_8bv0N.js +40 -0
  32. package/dist/web/assets/project-links-CodATITq.js +105 -0
  33. package/dist/web/assets/workflow-DR-M8YZx.svg +111 -0
  34. package/dist/web/downloads/teammy-inbox-skill.zip +0 -0
  35. package/dist/web/downloads/teammy-skill.zip +0 -0
  36. package/dist/web/index.html +4 -4
  37. package/dist/web/notification-worker.js +2 -10
  38. package/node_modules/i18next/LICENSE +21 -0
  39. package/node_modules/i18next/README.md +77 -0
  40. package/node_modules/i18next/dist/cjs/i18next.js +2495 -0
  41. package/node_modules/i18next/dist/esm/i18next.js +2505 -0
  42. package/node_modules/i18next/dist/esm/package.json +1 -0
  43. package/node_modules/i18next/dist/umd/i18next.js +2501 -0
  44. package/node_modules/i18next/dist/umd/i18next.min.js +1 -0
  45. package/node_modules/i18next/i18next.js +2501 -0
  46. package/node_modules/i18next/i18next.min.js +1 -0
  47. package/node_modules/i18next/index.d.mts +71 -0
  48. package/node_modules/i18next/index.d.ts +739 -0
  49. package/node_modules/i18next/package.json +125 -0
  50. package/node_modules/i18next/typescript/helpers.d.ts +73 -0
  51. package/node_modules/i18next/typescript/options.d.ts +871 -0
  52. package/node_modules/i18next/typescript/t.d.ts +1449 -0
  53. package/node_modules/jose/LICENSE.md +21 -0
  54. package/node_modules/jose/README.md +150 -0
  55. package/node_modules/jose/dist/types/index.d.ts +55 -0
  56. package/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +25 -0
  57. package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +40 -0
  58. package/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +25 -0
  59. package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +46 -0
  60. package/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +29 -0
  61. package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +51 -0
  62. package/node_modules/jose/dist/types/jwk/embedded.d.ts +10 -0
  63. package/node_modules/jose/dist/types/jwk/thumbprint.d.ts +15 -0
  64. package/node_modules/jose/dist/types/jwks/local.d.ts +17 -0
  65. package/node_modules/jose/dist/types/jwks/remote.d.ts +94 -0
  66. package/node_modules/jose/dist/types/jws/compact/sign.d.ts +21 -0
  67. package/node_modules/jose/dist/types/jws/compact/verify.d.ts +25 -0
  68. package/node_modules/jose/dist/types/jws/flattened/sign.d.ts +23 -0
  69. package/node_modules/jose/dist/types/jws/flattened/verify.d.ts +26 -0
  70. package/node_modules/jose/dist/types/jws/general/sign.d.ts +41 -0
  71. package/node_modules/jose/dist/types/jws/general/verify.d.ts +31 -0
  72. package/node_modules/jose/dist/types/jwt/decrypt.d.ts +38 -0
  73. package/node_modules/jose/dist/types/jwt/encrypt.d.ts +57 -0
  74. package/node_modules/jose/dist/types/jwt/sign.d.ts +21 -0
  75. package/node_modules/jose/dist/types/jwt/unsecured.d.ts +21 -0
  76. package/node_modules/jose/dist/types/jwt/verify.d.ts +36 -0
  77. package/node_modules/jose/dist/types/key/export.d.ts +19 -0
  78. package/node_modules/jose/dist/types/key/generate_key_pair.d.ts +33 -0
  79. package/node_modules/jose/dist/types/key/generate_secret.d.ts +30 -0
  80. package/node_modules/jose/dist/types/key/import.d.ts +67 -0
  81. package/node_modules/jose/dist/types/types.d.ts +802 -0
  82. package/node_modules/jose/dist/types/util/base64url.d.ts +16 -0
  83. package/node_modules/jose/dist/types/util/decode_jwt.d.ts +9 -0
  84. package/node_modules/jose/dist/types/util/decode_protected_header.d.ts +10 -0
  85. package/node_modules/jose/dist/types/util/errors.d.ts +182 -0
  86. package/node_modules/jose/dist/webapi/index.js +70 -0
  87. package/node_modules/jose/dist/webapi/jwe/compact/decrypt.js +7 -0
  88. package/node_modules/jose/dist/webapi/jwe/compact/encrypt.js +26 -0
  89. package/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +15 -0
  90. package/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +35 -0
  91. package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +41 -0
  92. package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +105 -0
  93. package/node_modules/jose/dist/webapi/jwk/embedded.js +30 -0
  94. package/node_modules/jose/dist/webapi/jwk/thumbprint.js +55 -0
  95. package/node_modules/jose/dist/webapi/jwks/local.js +60 -0
  96. package/node_modules/jose/dist/webapi/jwks/remote.js +103 -0
  97. package/node_modules/jose/dist/webapi/jws/compact/sign.js +20 -0
  98. package/node_modules/jose/dist/webapi/jws/compact/verify.js +8 -0
  99. package/node_modules/jose/dist/webapi/jws/flattened/sign.js +23 -0
  100. package/node_modules/jose/dist/webapi/jws/flattened/verify.js +12 -0
  101. package/node_modules/jose/dist/webapi/jws/general/sign.js +58 -0
  102. package/node_modules/jose/dist/webapi/jws/general/verify.js +42 -0
  103. package/node_modules/jose/dist/webapi/jwt/decrypt.js +13 -0
  104. package/node_modules/jose/dist/webapi/jwt/encrypt.js +42 -0
  105. package/node_modules/jose/dist/webapi/jwt/sign.js +19 -0
  106. package/node_modules/jose/dist/webapi/jwt/unsecured.js +34 -0
  107. package/node_modules/jose/dist/webapi/jwt/verify.js +13 -0
  108. package/node_modules/jose/dist/webapi/key/export.js +35 -0
  109. package/node_modules/jose/dist/webapi/key/generate_key_pair.js +35 -0
  110. package/node_modules/jose/dist/webapi/key/generate_secret.js +36 -0
  111. package/node_modules/jose/dist/webapi/key/import.js +53 -0
  112. package/node_modules/jose/dist/webapi/lib/asn1.js +138 -0
  113. package/node_modules/jose/dist/webapi/lib/buffer_utils.js +75 -0
  114. package/node_modules/jose/dist/webapi/lib/content_encryption.js +90 -0
  115. package/node_modules/jose/dist/webapi/lib/deflate.js +41 -0
  116. package/node_modules/jose/dist/webapi/lib/jwe_algorithms.js +116 -0
  117. package/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +190 -0
  118. package/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +75 -0
  119. package/node_modules/jose/dist/webapi/lib/jws_algorithms.js +74 -0
  120. package/node_modules/jose/dist/webapi/lib/jws_sign.js +46 -0
  121. package/node_modules/jose/dist/webapi/lib/jws_verify.js +89 -0
  122. package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +150 -0
  123. package/node_modules/jose/dist/webapi/lib/key.js +157 -0
  124. package/node_modules/jose/dist/webapi/lib/key_algorithm.js +15 -0
  125. package/node_modules/jose/dist/webapi/lib/key_descriptor.js +9 -0
  126. package/node_modules/jose/dist/webapi/lib/key_management.js +195 -0
  127. package/node_modules/jose/dist/webapi/lib/validate.js +122 -0
  128. package/node_modules/jose/dist/webapi/util/base64url.js +16 -0
  129. package/node_modules/jose/dist/webapi/util/decode_jwt.js +33 -0
  130. package/node_modules/jose/dist/webapi/util/decode_protected_header.js +19 -0
  131. package/node_modules/jose/dist/webapi/util/errors.js +109 -0
  132. package/node_modules/jose/package.json +134 -0
  133. package/node_modules/oauth4webapi/LICENSE.md +21 -0
  134. package/node_modules/oauth4webapi/README.md +104 -0
  135. package/node_modules/oauth4webapi/build/index.d.ts +3046 -0
  136. package/node_modules/oauth4webapi/build/index.js +2530 -0
  137. package/node_modules/oauth4webapi/build/index.js.map +1 -0
  138. package/node_modules/oauth4webapi/package.json +112 -0
  139. package/node_modules/openid-client/LICENSE.md +21 -0
  140. package/node_modules/openid-client/README.md +258 -0
  141. package/node_modules/openid-client/build/index.d.ts +2478 -0
  142. package/node_modules/openid-client/build/index.js +1347 -0
  143. package/node_modules/openid-client/build/index.js.map +1 -0
  144. package/node_modules/openid-client/build/passport.d.ts +258 -0
  145. package/node_modules/openid-client/build/passport.js +264 -0
  146. package/node_modules/openid-client/build/passport.js.map +1 -0
  147. package/node_modules/openid-client/package.json +130 -0
  148. package/package.json +5 -1
  149. package/dist/web/assets/Assistant-Dks48Y5w.js +0 -1
  150. package/dist/web/assets/Computers-CaCzZeCc.js +0 -13
  151. package/dist/web/assets/Conversation-kAMzKADw.js +0 -1
  152. package/dist/web/assets/Dashboard-ComNJNOg.js +0 -1
  153. package/dist/web/assets/Dropdown-DGFI68Vd.js +0 -55
  154. package/dist/web/assets/Files-Blsq_C-B.js +0 -1
  155. package/dist/web/assets/Help-BM23uS-t.js +0 -1079
  156. package/dist/web/assets/Markdown-CXnZDm5J.js +0 -29
  157. package/dist/web/assets/MessageComposer-BoOgfyPA.js +0 -1
  158. package/dist/web/assets/MessageComposer-hKEluJsT.css +0 -1
  159. package/dist/web/assets/ResourceLibrary-C12_47kE.js +0 -6
  160. package/dist/web/assets/TerminalPane-BTRM-36z.js +0 -22
  161. package/dist/web/assets/WorkspaceTree-Co7XG2RG.js +0 -1
  162. package/dist/web/assets/file-links-CoVqmrXg.js +0 -1
  163. package/dist/web/assets/index-CeKzFsxV.css +0 -1
  164. package/dist/web/assets/index-mhJ33-bH.js +0 -10
  165. package/dist/web/assets/task-links-BE36-8mc.js +0 -1
  166. /package/dist/web/assets/{Dropdown-ktgqMqAD.css → project-links-ktgqMqAD.css} +0 -0
@@ -0,0 +1,60 @@
1
+ import { jwkToKey, snapshotJwk } from "../lib/key.js";
2
+ import { JWS } from "../lib/jws_algorithms.js";
3
+ import { JWKSInvalid, JOSENotSupported, JWKSNoMatchingKey, JWKSMultipleMatchingKeys } from "../util/errors.js";
4
+ import { isJwkSet } from "../lib/validate.js";
5
+ function isUsableJWK(jwk, entry, alg, kid) {
6
+ const { kty, key_ops: keyOps, ext, kid: jwkKid, alg: jwkAlg, use, crv } = jwk;
7
+ 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);
8
+ }
9
+ async function importWithAlgCache(cache, jwk, entry) {
10
+ const cached = cache.get(jwk) || cache.set(jwk, {}).get(jwk), { alg } = entry;
11
+ if (cached[alg] === void 0) {
12
+ const pending = jwkToKey(entry, jwk, !0).then((key) => {
13
+ if (key.type !== "public")
14
+ throw new JWKSInvalid("JSON Web Key Set members must be public keys");
15
+ return cached[alg] = key, key;
16
+ }).catch((error) => {
17
+ throw cached[alg] === pending && delete cached[alg], error;
18
+ });
19
+ cached[alg] = pending;
20
+ }
21
+ return cached[alg];
22
+ }
23
+ function createLocalJWKSet(jwks) {
24
+ let snapshot;
25
+ try {
26
+ snapshot = structuredClone(jwks);
27
+ } catch (cause) {
28
+ throw new JWKSInvalid("JSON Web Key Set malformed", { cause });
29
+ }
30
+ if (!isJwkSet(snapshot))
31
+ throw new JWKSInvalid("JSON Web Key Set malformed");
32
+ const metadata = snapshot.keys.map((jwk) => {
33
+ const normalized = snapshotJwk(jwk);
34
+ return Array.isArray(normalized.key_ops) && (normalized.key_ops = [...normalized.key_ops]), normalized;
35
+ }), cached = /* @__PURE__ */ new WeakMap();
36
+ return Object.defineProperty(async (protectedHeader, token) => {
37
+ const { alg, kid } = { ...protectedHeader, ...token?.header }, entry = typeof alg == "string" ? JWS[alg] : void 0;
38
+ if (!entry || entry.secret)
39
+ throw new JOSENotSupported('Unsupported "alg" value for a JSON Web Key Set');
40
+ const candidates = snapshot.keys.filter((_, index) => isUsableJWK(metadata[index], entry, alg, kid)), { 0: jwk, length } = candidates;
41
+ if (!length)
42
+ throw new JWKSNoMatchingKey();
43
+ if (length !== 1) {
44
+ const error = new JWKSMultipleMatchingKeys();
45
+ throw error[Symbol.asyncIterator] = async function* () {
46
+ for (const jwk2 of candidates)
47
+ try {
48
+ yield await importWithAlgCache(cached, jwk2, entry);
49
+ } catch {
50
+ }
51
+ }, error;
52
+ }
53
+ return importWithAlgCache(cached, jwk, entry);
54
+ }, "jwks", {
55
+ value: () => structuredClone(snapshot)
56
+ });
57
+ }
58
+ export {
59
+ createLocalJWKSet
60
+ };
@@ -0,0 +1,103 @@
1
+ import { JOSEError, JWKSNoMatchingKey, JWKSTimeout } from "../util/errors.js";
2
+ import { createLocalJWKSet } from "./local.js";
3
+ import { isJwkSet } from "../lib/validate.js";
4
+ function isCloudflareWorkers() {
5
+ return typeof WebSocketPair < "u" || typeof navigator < "u" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime < "u" && EdgeRuntime === "vercel";
6
+ }
7
+ let USER_AGENT;
8
+ (typeof navigator > "u" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) && (USER_AGENT = "jose/v6.2.18");
9
+ const customFetch = /* @__PURE__ */ Symbol();
10
+ async function fetchJwks(url, headers, signal, fetchImpl = fetch) {
11
+ const response = await fetchImpl(url, {
12
+ method: "GET",
13
+ signal,
14
+ redirect: "manual",
15
+ headers
16
+ }).catch((err) => {
17
+ throw err.name === "TimeoutError" ? new JWKSTimeout(void 0, { cause: err }) : err;
18
+ });
19
+ if (response.status !== 200)
20
+ throw new JOSEError("Expected 200 OK from the JSON Web Key Set HTTP response");
21
+ try {
22
+ return await response.json();
23
+ } catch (cause) {
24
+ throw signal.aborted ? new JWKSTimeout(void 0, { cause }) : new JOSEError("Failed to parse the JSON Web Key Set HTTP response as JSON", { cause });
25
+ }
26
+ }
27
+ const jwksCache = /* @__PURE__ */ Symbol();
28
+ function isFreshFor(timestamp, duration) {
29
+ return Number.isFinite(timestamp) && Date.now() < timestamp + duration;
30
+ }
31
+ function validateDuration(value, fallback, option) {
32
+ if (Number.isNaN(value))
33
+ throw new TypeError(`"${option}" option must not be NaN`);
34
+ if (typeof value == "number" && value < 0)
35
+ throw new TypeError(`"${option}" option must not be negative`);
36
+ return typeof value == "number" ? value : fallback;
37
+ }
38
+ function createRemoteJWKSet(url, options) {
39
+ if (!(url instanceof URL))
40
+ throw new TypeError("url must be an instance of URL");
41
+ const href = new URL(url.href).href, opts = options ?? {}, timeoutOption = opts.timeoutDuration;
42
+ if (typeof timeoutOption == "number" && (!Number.isInteger(timeoutOption) || timeoutOption < 0))
43
+ throw new TypeError('"timeoutDuration" option must be a non-negative integer');
44
+ const timeoutDuration = typeof timeoutOption == "number" ? timeoutOption : 5e3, cooldownDuration = validateDuration(opts.cooldownDuration, 3e4, "cooldownDuration"), cacheMaxAge = validateDuration(opts.cacheMaxAge, 6e5, "cacheMaxAge"), headers = new Headers(opts.headers);
45
+ USER_AGENT && !headers.has("User-Agent") && headers.set("User-Agent", USER_AGENT), headers.has("accept") || headers.set("accept", "application/json, application/jwk-set+json");
46
+ const fetchImpl = opts[customFetch], cache = opts[jwksCache];
47
+ let jwksTimestamp, pendingFetch, reloadSequence = 0, appliedSequence = 0, local;
48
+ if (cache && typeof cache == "object") {
49
+ const { uat, jwks } = cache;
50
+ isFreshFor(uat, cacheMaxAge) && isJwkSet(jwks) && (jwksTimestamp = uat, local = createLocalJWKSet(jwks));
51
+ }
52
+ const reload = async () => {
53
+ if (pendingFetch && isCloudflareWorkers() && (pendingFetch = void 0), !pendingFetch) {
54
+ const sequence = ++reloadSequence, current = pendingFetch = fetchJwks(href, headers, AbortSignal.timeout(timeoutDuration), fetchImpl).then((json) => {
55
+ const next = createLocalJWKSet(json);
56
+ if (sequence <= appliedSequence)
57
+ return;
58
+ local = next;
59
+ const updatedAt = Date.now();
60
+ cache && (cache.uat = updatedAt, cache.jwks = json), jwksTimestamp = updatedAt, appliedSequence = sequence;
61
+ }).finally(() => {
62
+ pendingFetch === current && (pendingFetch = void 0);
63
+ });
64
+ }
65
+ await pendingFetch;
66
+ };
67
+ return Object.defineProperties(async (protectedHeader, token) => {
68
+ (!local || !isFreshFor(jwksTimestamp, cacheMaxAge)) && await reload();
69
+ try {
70
+ return await local(protectedHeader, token);
71
+ } catch (err) {
72
+ if (err instanceof JWKSNoMatchingKey && !isFreshFor(jwksTimestamp, cooldownDuration))
73
+ return await reload(), local(protectedHeader, token);
74
+ throw err;
75
+ }
76
+ }, {
77
+ coolingDown: {
78
+ get: () => isFreshFor(jwksTimestamp, cooldownDuration),
79
+ enumerable: !0
80
+ },
81
+ fresh: {
82
+ get: () => isFreshFor(jwksTimestamp, cacheMaxAge),
83
+ enumerable: !0
84
+ },
85
+ reload: {
86
+ value: reload,
87
+ enumerable: !0
88
+ },
89
+ reloading: {
90
+ get: () => !!pendingFetch,
91
+ enumerable: !0
92
+ },
93
+ jwks: {
94
+ value: () => local?.jwks(),
95
+ enumerable: !0
96
+ }
97
+ });
98
+ }
99
+ export {
100
+ createRemoteJWKSet,
101
+ customFetch,
102
+ jwksCache
103
+ };
@@ -0,0 +1,20 @@
1
+ import { createCompactSignature } from "../../lib/jws_sign.js";
2
+ import { assertNotSet, assertUint8Array } from "../../lib/validate.js";
3
+ class CompactSign {
4
+ #payload;
5
+ #protectedHeader;
6
+ constructor(payload) {
7
+ assertUint8Array(payload, "payload"), this.#payload = payload;
8
+ }
9
+ setProtectedHeader(protectedHeader) {
10
+ return assertNotSet(this.#protectedHeader, "setProtectedHeader"), this.#protectedHeader = protectedHeader, this;
11
+ }
12
+ async sign(key, options) {
13
+ return createCompactSignature(this.#payload, this.#protectedHeader, options?.crit, key, () => {
14
+ throw new TypeError("use the flattened module for creating JWS with b64: false");
15
+ });
16
+ }
17
+ }
18
+ export {
19
+ CompactSign
20
+ };
@@ -0,0 +1,8 @@
1
+ import { prepareVerify, verifyCompact } from "../../lib/jws_verify.js";
2
+ async function compactVerify(jws, key, options) {
3
+ const [result] = await verifyCompact(jws, prepareVerify(options), key);
4
+ return result;
5
+ }
6
+ export {
7
+ compactVerify
8
+ };
@@ -0,0 +1,23 @@
1
+ import { createSignature } from "../../lib/jws_sign.js";
2
+ import { assertNotSet, assertUint8Array } from "../../lib/validate.js";
3
+ class FlattenedSign {
4
+ #input;
5
+ constructor(payload) {
6
+ assertUint8Array(payload, "payload"), this.#input = [payload];
7
+ }
8
+ setProtectedHeader(protectedHeader) {
9
+ return assertNotSet(this.#input[1], "setProtectedHeader"), this.#input[1] = protectedHeader, this;
10
+ }
11
+ setUnprotectedHeader(unprotectedHeader) {
12
+ return assertNotSet(this.#input[2], "setUnprotectedHeader"), this.#input[2] = unprotectedHeader, this;
13
+ }
14
+ async sign(key, options) {
15
+ const input = [...this.#input];
16
+ input[3] = options?.crit;
17
+ const [jws] = await createSignature(input, key);
18
+ return jws;
19
+ }
20
+ }
21
+ export {
22
+ FlattenedSign
23
+ };
@@ -0,0 +1,12 @@
1
+ import { JWSInvalid } from "../../util/errors.js";
2
+ import { isObject } from "../../lib/validate.js";
3
+ import { encodeJsonUnencodedPayload, prepareVerify, snapshotJws, verifySignature } from "../../lib/jws_verify.js";
4
+ async function flattenedVerify(jws, key, options) {
5
+ if (!isObject(jws))
6
+ throw new JWSInvalid("Flattened JWS must be an object");
7
+ const snapshot = snapshotJws(jws), [result] = await verifySignature(snapshot, prepareVerify(options), key, encodeJsonUnencodedPayload);
8
+ return result;
9
+ }
10
+ export {
11
+ flattenedVerify
12
+ };
@@ -0,0 +1,58 @@
1
+ import { createSignature } from "../../lib/jws_sign.js";
2
+ import { JWSInvalid } from "../../util/errors.js";
3
+ import { assertNotSet, assertUint8Array } from "../../lib/validate.js";
4
+ class IndividualSignature {
5
+ #parent;
6
+ state;
7
+ constructor(sig, key, options) {
8
+ this.#parent = sig, this.state = [void 0, void 0, key, options?.crit];
9
+ }
10
+ setProtectedHeader(protectedHeader) {
11
+ return assertNotSet(this.state[0], "setProtectedHeader"), this.state[0] = protectedHeader, this;
12
+ }
13
+ setUnprotectedHeader(unprotectedHeader) {
14
+ return assertNotSet(this.state[1], "setUnprotectedHeader"), this.state[1] = unprotectedHeader, this;
15
+ }
16
+ addSignature(...args) {
17
+ return this.#parent.addSignature(...args);
18
+ }
19
+ sign(...args) {
20
+ return this.#parent.sign(...args);
21
+ }
22
+ done() {
23
+ return this.#parent;
24
+ }
25
+ }
26
+ class GeneralSign {
27
+ #payload;
28
+ #signatures = [];
29
+ constructor(payload) {
30
+ this.#payload = payload;
31
+ }
32
+ addSignature(key, options) {
33
+ const signature = new IndividualSignature(this, key, options);
34
+ return this.#signatures.push(signature), signature;
35
+ }
36
+ async sign() {
37
+ if (!this.#signatures.length)
38
+ throw new JWSInvalid("at least one signature must be added");
39
+ assertUint8Array(this.#payload, "payload");
40
+ const jws = {
41
+ signatures: [],
42
+ payload: ""
43
+ }, encodedPayloadCache = [];
44
+ let b64;
45
+ for (const signature of this.#signatures) {
46
+ const [protectedHeader, unprotectedHeader, key, crit] = signature.state, [{ payload, ...signatureMembers }, signatureB64] = await createSignature([this.#payload, protectedHeader, unprotectedHeader, crit, encodedPayloadCache], key);
47
+ if (b64 === void 0)
48
+ b64 = signatureB64, jws.payload = payload;
49
+ else if (b64 !== signatureB64)
50
+ throw new JWSInvalid("inconsistent use of JWS Unencoded Payload (RFC7797)");
51
+ jws.signatures.push(signatureMembers);
52
+ }
53
+ return jws;
54
+ }
55
+ }
56
+ export {
57
+ GeneralSign
58
+ };
@@ -0,0 +1,42 @@
1
+ import { encodeJsonUnencodedPayload, parseProtectedHeader, prepareVerify, snapshotJws, verifySignature } from "../../lib/jws_verify.js";
2
+ import { JWSInvalid, JWSSignatureVerificationFailed } from "../../util/errors.js";
3
+ import { isObject } from "../../lib/validate.js";
4
+ function snapshotSignature(signature, payload) {
5
+ try {
6
+ const jws = snapshotJws(signature, [payload]), protectedHeader = parseProtectedHeader(jws.protected), { b64, crit } = protectedHeader;
7
+ return [
8
+ jws,
9
+ protectedHeader,
10
+ Array.isArray(crit) && crit.includes("b64") ? typeof b64 == "boolean" ? b64 ? 1 : 2 : 0 : 1
11
+ ];
12
+ } catch {
13
+ return;
14
+ }
15
+ }
16
+ async function generalVerify(jws, key, options) {
17
+ if (!isObject(jws))
18
+ throw new JWSInvalid("General JWS must be an object");
19
+ const { signatures, payload: inputPayload } = jws;
20
+ if (!Array.isArray(signatures))
21
+ throw new JWSInvalid("JWS Signatures missing or incorrect type");
22
+ const signatureEntries = Array.from(signatures);
23
+ if (!signatureEntries.every(isObject))
24
+ throw new JWSInvalid("JWS Signatures missing or incorrect type");
25
+ if (inputPayload === void 0)
26
+ throw new JWSSignatureVerificationFailed();
27
+ const shared = prepareVerify(options), payload = inputPayload instanceof Uint8Array ? new Uint8Array(inputPayload) : inputPayload, candidates = signatureEntries.map((signature) => snapshotSignature(signature, payload)).filter((candidate) => candidate !== void 0);
28
+ let payloadEncodings = 0;
29
+ for (const [, , payloadEncoding] of candidates)
30
+ if (payloadEncodings |= payloadEncoding, payloadEncodings === 3)
31
+ throw new JWSInvalid("inconsistent use of JWS Unencoded Payload (RFC7797)");
32
+ for (const candidate of candidates)
33
+ try {
34
+ const [result] = await verifySignature(candidate[0], shared, key, encodeJsonUnencodedPayload, candidate[1]);
35
+ return result;
36
+ } catch {
37
+ }
38
+ throw new JWSSignatureVerificationFailed();
39
+ }
40
+ export {
41
+ generalVerify
42
+ };
@@ -0,0 +1,13 @@
1
+ import { prepareDecrypt, decryptCompact } from "../lib/jwe_decrypt.js";
2
+ import { validateClaimsSet } from "../lib/jwt_claims_set.js";
3
+ import { JWTClaimValidationFailed } from "../util/errors.js";
4
+ async function jwtDecrypt(jwt, key, options) {
5
+ const { plaintext, ...result } = await decryptCompact(jwt, prepareDecrypt(options), key), { protectedHeader } = result, payload = validateClaimsSet(protectedHeader, plaintext, options);
6
+ for (const claim of ["iss", "sub", "aud"])
7
+ if (protectedHeader[claim] !== void 0 && (claim === "aud" ? JSON.stringify(protectedHeader.aud) !== JSON.stringify(payload.aud) : protectedHeader[claim] !== payload[claim]))
8
+ throw new JWTClaimValidationFailed(`replicated "${claim}" claim header parameter mismatch`, payload, claim, "mismatch");
9
+ return { payload, ...result };
10
+ }
11
+ export {
12
+ jwtDecrypt
13
+ };
@@ -0,0 +1,42 @@
1
+ import { compactJWE, createJWE } from "../lib/jwe_encrypt.js";
2
+ import { JWTClaimsBuilder, jwtClaim, jwtClaimsSetBytes } from "../lib/jwt_claims_set.js";
3
+ import { assertNotSet } from "../lib/validate.js";
4
+ const EncryptJWT_base = JWTClaimsBuilder;
5
+ class EncryptJWT extends EncryptJWT_base {
6
+ #input = [void 0];
7
+ #replicateIssuerAsHeader;
8
+ #replicateSubjectAsHeader;
9
+ #replicateAudienceAsHeader;
10
+ setProtectedHeader(protectedHeader) {
11
+ return assertNotSet(this.#input[1], "setProtectedHeader"), this.#input[1] = protectedHeader, this;
12
+ }
13
+ setKeyManagementParameters(parameters) {
14
+ return assertNotSet(this.#input[7], "setKeyManagementParameters"), this.#input[7] = parameters, this;
15
+ }
16
+ setContentEncryptionKey(cek) {
17
+ return assertNotSet(this.#input[5], "setContentEncryptionKey"), this.#input[5] = cek, this;
18
+ }
19
+ setInitializationVector(iv) {
20
+ return assertNotSet(this.#input[6], "setInitializationVector"), this.#input[6] = iv, this;
21
+ }
22
+ replicateIssuerAsHeader() {
23
+ return this.#replicateIssuerAsHeader = !0, this;
24
+ }
25
+ replicateSubjectAsHeader() {
26
+ return this.#replicateSubjectAsHeader = !0, this;
27
+ }
28
+ replicateAudienceAsHeader() {
29
+ return this.#replicateAudienceAsHeader = !0, this;
30
+ }
31
+ async encrypt(key, options) {
32
+ const input = [...this.#input];
33
+ if (input[0] = jwtClaimsSetBytes(this), input[1] && (this.#replicateIssuerAsHeader || this.#replicateSubjectAsHeader || this.#replicateAudienceAsHeader)) {
34
+ const header = { ...input[1] };
35
+ this.#replicateIssuerAsHeader && (header.iss = jwtClaim(this, "iss")), this.#replicateSubjectAsHeader && (header.sub = jwtClaim(this, "sub")), this.#replicateAudienceAsHeader && (header.aud = jwtClaim(this, "aud")), input[1] = header;
36
+ }
37
+ return compactJWE(await createJWE(input, key, options));
38
+ }
39
+ }
40
+ export {
41
+ EncryptJWT
42
+ };
@@ -0,0 +1,19 @@
1
+ import { createCompactSignature } from "../lib/jws_sign.js";
2
+ import { JWTInvalid } from "../util/errors.js";
3
+ import { JWTClaimsBuilder, jwtClaimsSetBytes } from "../lib/jwt_claims_set.js";
4
+ import { assertNotSet } from "../lib/validate.js";
5
+ const SignJWT_base = JWTClaimsBuilder;
6
+ class SignJWT extends SignJWT_base {
7
+ #protectedHeader;
8
+ setProtectedHeader(protectedHeader) {
9
+ return assertNotSet(this.#protectedHeader, "setProtectedHeader"), this.#protectedHeader = protectedHeader, this;
10
+ }
11
+ async sign(key, options) {
12
+ return createCompactSignature(jwtClaimsSetBytes(this), this.#protectedHeader, options?.crit, key, () => {
13
+ throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
14
+ });
15
+ }
16
+ }
17
+ export {
18
+ SignJWT
19
+ };
@@ -0,0 +1,34 @@
1
+ import * as b64u from "../util/base64url.js";
2
+ import { decodeBase64url, parseJoseHeader, JWS_RECOGNIZED, validateB64, validateCrit } from "../lib/validate.js";
3
+ import { JWSInvalid, JWTInvalid } from "../util/errors.js";
4
+ import { validateClaimsSet, JWTClaimsBuilder, jwtClaimsSetBytes } from "../lib/jwt_claims_set.js";
5
+ const UnsecuredJWT_base = JWTClaimsBuilder;
6
+ class UnsecuredJWT extends UnsecuredJWT_base {
7
+ encode() {
8
+ const encodedProtectedHeader = b64u.encode(JSON.stringify({ alg: "none" })), encodedPayload = b64u.encode(jwtClaimsSetBytes(this));
9
+ return `${encodedProtectedHeader}.${encodedPayload}.`;
10
+ }
11
+ static decode(jwt, options) {
12
+ if (typeof jwt != "string")
13
+ throw new JWTInvalid("Unsecured JWT must be a string");
14
+ const { 0: encodedHeader, 1: encodedPayload, 2: signature, length } = jwt.split(".");
15
+ if (length !== 3 || signature !== "")
16
+ throw new JWTInvalid("Invalid Unsecured JWT");
17
+ let header, b64;
18
+ try {
19
+ header = parseJoseHeader(encodedHeader, JWSInvalid, "JWS Protected Header is invalid");
20
+ const extensions = validateCrit(JWSInvalid, JWS_RECOGNIZED, void 0, header, header);
21
+ b64 = validateB64(header, extensions);
22
+ } catch (cause) {
23
+ throw cause instanceof JWSInvalid ? new JWTInvalid("Invalid Unsecured JWT", { cause }) : cause;
24
+ }
25
+ if (header.alg !== "none")
26
+ throw new JWTInvalid("Invalid Unsecured JWT");
27
+ if (!b64)
28
+ throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
29
+ return { payload: validateClaimsSet(header, decodeBase64url(encodedPayload, "payload", JWTInvalid), options), header };
30
+ }
31
+ }
32
+ export {
33
+ UnsecuredJWT
34
+ };
@@ -0,0 +1,13 @@
1
+ import { prepareVerify, verifyCompact } from "../lib/jws_verify.js";
2
+ import { validateClaimsSet } from "../lib/jwt_claims_set.js";
3
+ import { JWTInvalid } from "../util/errors.js";
4
+ async function jwtVerify(jwt, key, options) {
5
+ const [verified, b64] = await verifyCompact(jwt, prepareVerify(options), key);
6
+ if (!b64)
7
+ throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
8
+ const payload = validateClaimsSet(verified.protectedHeader, verified.payload, options);
9
+ return { ...verified, payload };
10
+ }
11
+ export {
12
+ jwtVerify
13
+ };
@@ -0,0 +1,35 @@
1
+ import { toSPKI as exportPublic, toPKCS8 as exportPrivate } from "../lib/asn1.js";
2
+ import { invalidKeyInput, isCryptoKey, isKeyObject } from "../lib/key.js";
3
+ import { encode as b64u } from "../util/base64url.js";
4
+ function exportSPKI(key) {
5
+ return exportPublic(key);
6
+ }
7
+ function exportPKCS8(key) {
8
+ return exportPrivate(key);
9
+ }
10
+ async function exportJWK(key) {
11
+ if (isKeyObject(key))
12
+ if (key.type === "secret")
13
+ key = key.export();
14
+ else
15
+ return key.export({ format: "jwk" });
16
+ if (key instanceof Uint8Array)
17
+ return {
18
+ kty: "oct",
19
+ k: b64u(key)
20
+ };
21
+ if (!isCryptoKey(key))
22
+ throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "Uint8Array"));
23
+ if (!key.extractable)
24
+ throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");
25
+ const jwk = await crypto.subtle.exportKey("jwk", key);
26
+ delete jwk.ext, delete jwk.key_ops, delete jwk.use, jwk.kty !== "AKP" && delete jwk.alg;
27
+ for (const parameter of Object.keys(jwk))
28
+ jwk[parameter] === void 0 && delete jwk[parameter];
29
+ return jwk;
30
+ }
31
+ export {
32
+ exportJWK,
33
+ exportPKCS8,
34
+ exportSPKI
35
+ };
@@ -0,0 +1,35 @@
1
+ import { JOSENotSupported } from "../util/errors.js";
2
+ import { validateExtractableOption } from "../lib/key.js";
3
+ import { keyAlgorithm, unsupportedAlg, algArgument } from "../lib/key_algorithm.js";
4
+ function getModulusLengthOption(options) {
5
+ const modulusLength = options?.modulusLength ?? 2048;
6
+ if (typeof modulusLength != "number" || !Number.isInteger(modulusLength) || modulusLength < 2048)
7
+ throw new JOSENotSupported("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");
8
+ return modulusLength;
9
+ }
10
+ async function generateKeyPair(alg, options) {
11
+ const extractable = validateExtractableOption(options?.extractable), entry = keyAlgorithm(alg, algArgument);
12
+ entry.secret && unsupportedAlg(algArgument);
13
+ let algorithm;
14
+ if (entry.resolve) {
15
+ const crv = options?.crv ?? "P-256";
16
+ if (!["P-256", "P-384", "P-521", "X25519"].includes(crv))
17
+ throw new JOSENotSupported("Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, and X25519");
18
+ algorithm = entry.resolve({ crv });
19
+ } else {
20
+ if (entry.crv !== void 0 && options?.crv !== void 0 && options.crv !== entry.crv)
21
+ throw new JOSENotSupported(`Invalid or unsupported crv option provided, the only supported value for ${alg} is ${entry.crv}`);
22
+ algorithm = entry.kty[0] === "RSA" ? {
23
+ ...entry.subtle,
24
+ publicExponent: Uint8Array.of(1, 0, 1),
25
+ modulusLength: getModulusLengthOption(options)
26
+ } : entry.subtle;
27
+ }
28
+ return crypto.subtle.generateKey(algorithm, extractable ?? !1, [
29
+ ...entry.usages[1],
30
+ ...entry.usages[0]
31
+ ]);
32
+ }
33
+ export {
34
+ generateKeyPair
35
+ };
@@ -0,0 +1,36 @@
1
+ import { unsupportedAlg, algArgument } from "../lib/key_algorithm.js";
2
+ import { validateExtractableOption } from "../lib/key.js";
3
+ async function generateSecret(alg, options) {
4
+ const extractable = validateExtractableOption(options?.extractable);
5
+ let keyLengthBits, algorithm, keyUsages;
6
+ switch (alg) {
7
+ case "HS256":
8
+ case "HS384":
9
+ case "HS512":
10
+ keyLengthBits = +alg.slice(-3), algorithm = { name: "HMAC", hash: `SHA-${keyLengthBits}`, length: keyLengthBits }, keyUsages = ["sign", "verify"];
11
+ break;
12
+ case "A128CBC-HS256":
13
+ case "A192CBC-HS384":
14
+ case "A256CBC-HS512":
15
+ return crypto.getRandomValues(new Uint8Array(+alg.slice(-3) >> 3));
16
+ case "A128KW":
17
+ case "A192KW":
18
+ case "A256KW":
19
+ keyLengthBits = +alg.slice(1, 4), algorithm = { name: "AES-KW", length: keyLengthBits }, keyUsages = ["wrapKey", "unwrapKey"];
20
+ break;
21
+ case "A128GCMKW":
22
+ case "A192GCMKW":
23
+ case "A256GCMKW":
24
+ case "A128GCM":
25
+ case "A192GCM":
26
+ case "A256GCM":
27
+ keyLengthBits = +alg.slice(1, 4), algorithm = { name: "AES-GCM", length: keyLengthBits }, keyUsages = ["encrypt", "decrypt"];
28
+ break;
29
+ default:
30
+ unsupportedAlg(algArgument);
31
+ }
32
+ return crypto.subtle.generateKey(algorithm, extractable ?? !1, keyUsages);
33
+ }
34
+ export {
35
+ generateSecret
36
+ };
@@ -0,0 +1,53 @@
1
+ import { decode as decodeBase64URL } from "../util/base64url.js";
2
+ import { fromSPKI, fromPKCS8, fromX509 } from "../lib/asn1.js";
3
+ import { jwkToKey, validateExtractableOption, normalizeJwk } from "../lib/key.js";
4
+ import { keyAlgorithm } from "../lib/key_algorithm.js";
5
+ import { JOSENotSupported } from "../util/errors.js";
6
+ import { isObject } from "../lib/validate.js";
7
+ async function importSPKI(spki, alg, options) {
8
+ if (typeof spki != "string" || spki.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
9
+ throw new TypeError('"spki" must be SPKI formatted string');
10
+ return fromSPKI(spki, alg, options);
11
+ }
12
+ async function importX509(x509, alg, options) {
13
+ if (typeof x509 != "string" || x509.indexOf("-----BEGIN CERTIFICATE-----") !== 0)
14
+ throw new TypeError('"x509" must be X.509 formatted string');
15
+ return fromX509(x509, alg, options);
16
+ }
17
+ async function importPKCS8(pkcs8, alg, options) {
18
+ if (typeof pkcs8 != "string" || pkcs8.indexOf("-----BEGIN PRIVATE KEY-----") !== 0)
19
+ throw new TypeError('"pkcs8" must be PKCS#8 formatted string');
20
+ return fromPKCS8(pkcs8, alg, options);
21
+ }
22
+ async function importJWK(jwk, alg, options) {
23
+ if (!isObject(jwk))
24
+ throw new TypeError("JWK must be an object");
25
+ const normalized = normalizeJwk(jwk), extractable = validateExtractableOption(options?.extractable), { alg: jwkAlg } = normalized;
26
+ if (alg ??= jwkAlg, normalized.kty !== "oct" && !alg)
27
+ throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
28
+ switch (normalized.kty) {
29
+ case "oct":
30
+ if (typeof normalized.k != "string")
31
+ throw new TypeError('missing "k" (Key Value) Parameter value');
32
+ return decodeBase64URL(normalized.k);
33
+ case "AKP": {
34
+ if (typeof jwkAlg != "string" || !jwkAlg)
35
+ throw new TypeError('missing "alg" (Algorithm) Parameter value');
36
+ if (alg !== jwkAlg)
37
+ throw new TypeError("JWK alg and alg option value mismatch");
38
+ return jwkToKey(keyAlgorithm(alg), normalized, extractable);
39
+ }
40
+ case "RSA":
41
+ case "EC":
42
+ case "OKP":
43
+ return jwkToKey(keyAlgorithm(alg), normalized, extractable);
44
+ default:
45
+ throw new JOSENotSupported('Unsupported "kty" (Key Type) Parameter value');
46
+ }
47
+ }
48
+ export {
49
+ importJWK,
50
+ importPKCS8,
51
+ importSPKI,
52
+ importX509
53
+ };