@udibo/oauth2 0.33.0 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,20 +2,14 @@
2
2
  * Authenticated-encryption (AES-256-GCM) and key-derivation helpers for sealing
3
3
  * session and token data at rest or in a cookie.
4
4
  *
5
- * Two key-derivation paths, for two different threat models:
6
- *
7
- * - {@link deriveAesKey} hashes a single **server-held** secret (SHA-256) into
8
- * an AES-256-GCM key. Use this for a stateless cookie sealed under one
9
- * configured secret (see `EncryptedCookieSessionStore`), where the secret is
10
- * never persisted.
11
- *
12
- * - {@link deriveSealKey} uses **HKDF** with a domain-separating `info` label so
13
- * a high-entropy *per-session* secret yields an encryption key that is
14
- * independent of any other value derived from the same secret. This is what
15
- * makes "the cookie value is both the lookup credential **and** the decryption
16
- * key" safe: a database can store `sha256(secret)` as a lookup hash while the
17
- * sealing key is `HKDF(secret, info)`, and knowing the stored hash never
18
- * reveals the key. Always pass a distinct `info` per purpose.
5
+ * {@link deriveSealKey} uses **HKDF** with a domain-separating `info` label so a
6
+ * high-entropy secret yields an encryption key that is independent of any other
7
+ * value derived from the same secret. This is what makes "the cookie value is
8
+ * both the lookup credential **and** the decryption key" safe: a database can
9
+ * store `sha256(secret)` as a lookup hash while the sealing key is
10
+ * `HKDF(secret, info)`, and knowing the stored hash never reveals the key. It is
11
+ * also what lets one secret seal two kinds of value without either opening as
12
+ * the other. Always pass a distinct `info` per purpose.
19
13
  *
20
14
  * {@link seal}/{@link unseal} use AES-256-GCM (an AEAD), so tampered ciphertext
21
15
  * fails to unseal (returns `null`) rather than decrypting to garbage.
@@ -79,25 +73,6 @@ export function base64urlDecode(value) {
79
73
  export function randomToken(bytes = 32) {
80
74
  return base64urlEncode(crypto.getRandomValues(new Uint8Array(bytes)));
81
75
  }
82
- /**
83
- * Derive an AES-256-GCM key from a single server-held secret via SHA-256.
84
- *
85
- * Suitable when the secret is a long-lived configuration value that is never
86
- * stored alongside the ciphertext. Do **not** use this when a hash of the same
87
- * secret is persisted (e.g. as a lookup key) — use {@link deriveSealKey} so the
88
- * sealing key is independent of that stored hash.
89
- *
90
- * @throws {Error} if the secret is shorter than 16 bytes. Length is all that is
91
- * checked; supply 32+ bytes of real entropy.
92
- */
93
- export async function deriveAesKey(secret) {
94
- const raw = toBytes(secret);
95
- if (raw.byteLength < 16) {
96
- throw new Error("secret must be at least 16 bytes; 32+ bytes of entropy is recommended.");
97
- }
98
- const digest = await crypto.subtle.digest("SHA-256", toArrayBuffer(raw));
99
- return await crypto.subtle.importKey("raw", digest, { name: "AES-GCM" }, false, ["encrypt", "decrypt"]);
100
- }
101
76
  /**
102
77
  * Derive an AES-256-GCM sealing key from a high-entropy secret via HKDF-SHA-256
103
78
  * with a domain-separating `info` label.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@udibo/oauth2",
3
- "version": "0.33.0",
3
+ "version": "0.35.0",
4
4
  "description": "A flexible OAuth2 toolkit: framework-agnostic authorization & resource servers, a typed client, Hono adapters (including a backend-for-frontend), and React bindings.",
5
5
  "keywords": [
6
6
  "authorization-server",