@stryker-mutator/dashboard-common 0.20.6 → 0.20.7

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.
@@ -0,0 +1,26 @@
1
+ import type { JWTPayload } from 'jose';
2
+ /**
3
+ * @param secret The secret to derive from, `JWT_SECRET` in practice.
4
+ * @param purpose Names what the key is for, e.g. `'auth-token'`.
5
+ */
6
+ export declare function deriveKey(secret: string, purpose: string): Promise<Uint8Array>;
7
+ /**
8
+ * Creates and reads the authentication tokens handed out to the frontend.
9
+ *
10
+ * These are encrypted JWTs (JWE, RFC 7516) rather than signed ones, because they carry the user's
11
+ * GitHub access token.
12
+ *
13
+ * @note This module deliberately isn't re-exported from the package index, it relies on
14
+ * `node:crypto` and would end up in the frontend bundle.
15
+ */
16
+ export declare class AuthTokenCodec {
17
+ #private;
18
+ /**
19
+ * @param secret The secret to derive the encryption key from, `JWT_SECRET` in practice. A key is
20
+ * derived rather than used as-is, because the same secret also signs the OAuth session cookie.
21
+ */
22
+ constructor(secret: string);
23
+ create(claims: JWTPayload): Promise<string>;
24
+ read<T>(token: string): Promise<T>;
25
+ }
26
+ //# sourceMappingURL=crypto.d.ts.map
@@ -0,0 +1,57 @@
1
+ import { hkdf as hkdfCallback } from 'node:crypto';
2
+ import { promisify } from 'node:util';
3
+ import { EncryptJWT, jwtDecrypt } from 'jose';
4
+ const hkdf = promisify(hkdfCallback);
5
+ const KEY_LENGTH = 32;
6
+ /**
7
+ * @param secret The secret to derive from, `JWT_SECRET` in practice.
8
+ * @param purpose Names what the key is for, e.g. `'auth-token'`.
9
+ */
10
+ export async function deriveKey(secret, purpose) {
11
+ return new Uint8Array(await hkdf('sha256', secret, '', purpose, KEY_LENGTH));
12
+ }
13
+ const KEY_MANAGEMENT_ALGORITHM = 'dir';
14
+ const CONTENT_ENCRYPTION_ALGORITHM = 'A256GCM';
15
+ /** The purpose the encryption key is derived for. */
16
+ const KEY_INFO = 'auth-token';
17
+ const ISSUER = 'stryker';
18
+ const AUDIENCE = 'stryker';
19
+ const EXPIRATION_TIME = '30m';
20
+ /**
21
+ * Creates and reads the authentication tokens handed out to the frontend.
22
+ *
23
+ * These are encrypted JWTs (JWE, RFC 7516) rather than signed ones, because they carry the user's
24
+ * GitHub access token.
25
+ *
26
+ * @note This module deliberately isn't re-exported from the package index, it relies on
27
+ * `node:crypto` and would end up in the frontend bundle.
28
+ */
29
+ export class AuthTokenCodec {
30
+ #key;
31
+ /**
32
+ * @param secret The secret to derive the encryption key from, `JWT_SECRET` in practice. A key is
33
+ * derived rather than used as-is, because the same secret also signs the OAuth session cookie.
34
+ */
35
+ constructor(secret) {
36
+ this.#key = deriveKey(secret, KEY_INFO);
37
+ }
38
+ async create(claims) {
39
+ return new EncryptJWT(claims)
40
+ .setProtectedHeader({ alg: KEY_MANAGEMENT_ALGORITHM, enc: CONTENT_ENCRYPTION_ALGORITHM })
41
+ .setIssuedAt()
42
+ .setIssuer(ISSUER)
43
+ .setAudience(AUDIENCE)
44
+ .setExpirationTime(EXPIRATION_TIME)
45
+ .encrypt(await this.#key);
46
+ }
47
+ async read(token) {
48
+ const { payload } = await jwtDecrypt(token, await this.#key, {
49
+ issuer: ISSUER,
50
+ audience: AUDIENCE,
51
+ keyManagementAlgorithms: [KEY_MANAGEMENT_ALGORITHM],
52
+ contentEncryptionAlgorithms: [CONTENT_ENCRYPTION_ALGORITHM],
53
+ });
54
+ return payload;
55
+ }
56
+ }
57
+ //# sourceMappingURL=crypto.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryker-mutator/dashboard-common",
3
- "version": "0.20.6",
3
+ "version": "0.20.7",
4
4
  "type": "module",
5
5
  "description": "This package contains common utilities to be shared between the different dashboard components.",
6
6
  "scripts": {
@@ -20,11 +20,13 @@
20
20
  "main": "dist/src/index.js",
21
21
  "exports": {
22
22
  ".": "./dist/src/index.js",
23
+ "./crypto": "./dist/src/crypto.js",
23
24
  "./package.json": "./package.json"
24
25
  },
25
26
  "license": "Apache-2.0",
26
27
  "dependencies": {
28
+ "jose": "6.2.8",
27
29
  "mutation-testing-report-schema": "3.9.0"
28
30
  },
29
- "gitHead": "53b9ecc0488216773b479e8eeb1301056474ee1b"
31
+ "gitHead": "619f1930a7f36026245db7c553b80fccbb955345"
30
32
  }