@nexusts/crypto 0.7.0 → 0.7.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/README.md CHANGED
@@ -15,7 +15,7 @@ This module is part of the NexusTS monorepo. Each module is published as its own
15
15
  Most apps start with just the core:
16
16
 
17
17
  ```bash
18
- bun add @nexusts/core reflect-metadata zod hono
18
+ bun add @nexusts/core
19
19
  ```
20
20
 
21
21
  Then add this module only if you need it:
@@ -26,7 +26,7 @@ bun add @nexusts/crypto
26
26
 
27
27
  ## Peer dependencies
28
28
 
29
- None. This module is fully self-contained.
29
+ **None.** No external dependencies. Uses Node's built-in `crypto` module.
30
30
 
31
31
  ## Usage
32
32
 
@@ -0,0 +1,70 @@
1
+ /**
2
+ * `EncryptionService` — AES-256-GCM symmetric encryption + HMAC
3
+ * sign/unsign helpers.
4
+ *
5
+ * Use cases:
6
+ * - **Encrypt** sensitive data before storing it (e.g. session
7
+ * blobs in cookies or DB).
8
+ * - **Sign** stateless values that need to be tamper-proof (e.g.
9
+ * session IDs, CSRF tokens, password-reset links, signed URLs).
10
+ *
11
+ * The service derives two 32-byte keys from the user's master
12
+ * `key` config: one for AES-GCM, one for HMAC. The keys are
13
+ * distinct (HKDF-SHA256 with a per-purpose salt) so a leak of one
14
+ * doesn't compromise the other.
15
+ *
16
+ * Encrypted format (v1):
17
+ * `v1.<base64url(iv)>.<base64url(tag)>.<base64url(ciphertext)>`
18
+ * where `iv` is 12 bytes and `tag` is 16 bytes (GCM auth tag).
19
+ *
20
+ * Signed format:
21
+ * `<base64url(value)>.<base64url(hmac)>`
22
+ */
23
+ import type { EncryptedValue, EncryptOptions, SignedValue } from "./types.js";
24
+ export declare class EncryptionService {
25
+ private readonly aesKey;
26
+ private readonly hmacKey;
27
+ constructor(masterKey: string);
28
+ /**
29
+ * Encrypt a string. The output is self-describing and includes
30
+ * the IV, auth tag, expiry, and purpose (if any) in the MAC.
31
+ *
32
+ * Format: `v1.<iv>.<tag>.<ciphertext>.<mac>`
33
+ */
34
+ encrypt(value: string, options?: EncryptOptions): EncryptedValue;
35
+ /**
36
+ * Decrypt a value previously produced by `encrypt()`. Throws
37
+ * if the value is malformed, the MAC doesn't match, the
38
+ * purpose doesn't match, or the expiry has passed.
39
+ */
40
+ decrypt<T = string>(payload: string): T;
41
+ /** True if the string was produced by `encrypt()`. */
42
+ isEncrypted(value: string): boolean;
43
+ /**
44
+ * Sign a string with the framework's HMAC key. The output is
45
+ * `<base64url(value)>.<base64url(hmac)>`.
46
+ *
47
+ * Useful for stateless session cookies, CSRF tokens, etc.
48
+ */
49
+ sign(value: string, purpose?: string): SignedValue;
50
+ /**
51
+ * Sign a pre-encoded value (no extra b64-encoding). The output
52
+ * is just the base64url MAC. Useful for cookie / token formats
53
+ * where the value is already b64-encoded.
54
+ *
55
+ * The caller is responsible for joining the value and signature.
56
+ */
57
+ signRaw(value: string, purpose?: string): string;
58
+ /**
59
+ * Verify a raw signature (from `signRaw`) against a pre-encoded
60
+ * value. Returns `true` on match, `false` otherwise.
61
+ */
62
+ verifyRaw(value: string, signature: string, purpose?: string): boolean;
63
+ /**
64
+ * Verify and extract a previously signed value. Returns the
65
+ * original value on success, `null` on failure (malformed,
66
+ * wrong purpose, MAC mismatch).
67
+ */
68
+ unsign(signed: string, purpose?: string): string | null;
69
+ private macOver;
70
+ }
package/dist/hash.d.ts ADDED
@@ -0,0 +1,74 @@
1
+ /**
2
+ * `HashService` — secure password hashing.
3
+ *
4
+ * Algorithms:
5
+ * - `scrypt` (default) — built into Node, no extra deps. Memory-
6
+ * hard and CPU-hard. Recommended for new apps.
7
+ * - `argon2` (optional) — the @node-rs/argon2 package is the
8
+ * reference implementation. Install it as a peer dep:
9
+ *
10
+ * bun add @node-rs/argon2
11
+ *
12
+ * When installed, the service auto-detects it.
13
+ *
14
+ * Output format (scrypt): a base64 string with the cost parameters
15
+ * encoded: `$scrypt$N=16384,r=8,p=1$<saltB64>$<hashB64>`.
16
+ * This is similar to the well-known `passlib` / PHC format and
17
+ * lets us verify hashes that were generated with different
18
+ * parameters.
19
+ */
20
+ import type { HashConfig, HashOptions, HashedPassword } from "./types.js";
21
+ export declare class HashService {
22
+ readonly algorithm: "scrypt" | "argon2";
23
+ private readonly scryptCost;
24
+ private readonly scryptBlockSize;
25
+ private readonly scryptParallelization;
26
+ private readonly scryptKeyLength;
27
+ private readonly argon2MemoryCost;
28
+ private readonly argon2TimeCost;
29
+ private readonly argon2Parallelism;
30
+ constructor(config?: HashConfig);
31
+ /**
32
+ * Hash a password. Returns a self-describing string that
33
+ * includes the algorithm and cost parameters.
34
+ */
35
+ hash(password: string, options?: HashOptions): Promise<HashedPassword>;
36
+ /**
37
+ * Verify a password against a previously generated hash.
38
+ * Returns `true` on match, `false` otherwise.
39
+ */
40
+ verify(hashed: HashedPassword, password: string): Promise<boolean>;
41
+ /**
42
+ * True if a hash was generated with parameters that are below
43
+ * the current security floor. The caller should re-hash and
44
+ * update the stored value.
45
+ */
46
+ needsRehash(hashed: HashedPassword): boolean;
47
+ private hashScrypt;
48
+ private verifyScrypt;
49
+ private hashArgon2;
50
+ private verifyArgon2;
51
+ }
52
+ /**
53
+ * Standalone `hash` function — uses scrypt by default, argon2 if
54
+ * `@node-rs/argon2` is installed.
55
+ *
56
+ * @param password - The plaintext password to hash.
57
+ * @param options - Optional overrides for algorithm + cost params.
58
+ * @returns The encoded hash string (PHC-style).
59
+ */
60
+ export declare function hash(password: string, options?: HashOptions): Promise<string>;
61
+ /**
62
+ * Standalone `verify` function — verifies a plaintext password
63
+ * against a previously encoded hash.
64
+ */
65
+ export declare function verify(hashed: HashedPassword, password: string): Promise<boolean>;
66
+ /**
67
+ * Convenience: scrypt-specific hash. Useful when you want to
68
+ * guarantee the algorithm regardless of installed peer deps.
69
+ */
70
+ export declare function scryptHash(password: string): Promise<string>;
71
+ /**
72
+ * Convenience: scrypt-specific verify.
73
+ */
74
+ export declare function scryptVerify(hashed: string, password: string): Promise<boolean>;
@@ -0,0 +1,57 @@
1
+ /**
2
+ * `nexusjs/crypto` — encryption + password hashing.
3
+ *
4
+ * Public API:
5
+ * - `EncryptionService` — AES-256-GCM + HMAC sign/unsign.
6
+ * - `HashService` — scrypt (default) or argon2 (optional).
7
+ * - `CryptoModule.forRoot({ key })` — wires both into the DI
8
+ * container.
9
+ * - `hash()` / `verify()` — standalone helpers that wrap a
10
+ * `HashService` instance. Useful outside the DI container
11
+ * (CLI scripts, seeders, smoke tests).
12
+ * - `scryptHash()` / `scryptVerify()` — same, but locked to scrypt.
13
+ *
14
+ * Zero external dependencies. All primitives come from Node's
15
+ * built-in `crypto` module.
16
+ *
17
+ * bun add nexus
18
+ * # Optional (only if you use argon2):
19
+ * bun add @node-rs/argon2
20
+ *
21
+ * Quick start:
22
+ *
23
+ * import { Module } from "nexusjs";
24
+ * import { CryptoModule, EncryptionService, HashService } from "nexusjs/crypto";
25
+ *
26
+ * @Module({
27
+ * imports: [CryptoModule.forRoot({ key: process.env.APP_KEY! })],
28
+ * })
29
+ * class AppModule {}
30
+ *
31
+ * @Injectable()
32
+ * class UserService {
33
+ * constructor(
34
+ * @Inject(EncryptionService.TOKEN) private enc: EncryptionService,
35
+ * @Inject(HashService.TOKEN) private hash: HashService,
36
+ * ) {}
37
+ *
38
+ * async createUser(email: string, password: string) {
39
+ * const passwordHash = await this.hash.hash(password);
40
+ * const apiToken = this.enc.sign(email);
41
+ * // ... store
42
+ * }
43
+ *
44
+ * async verifyPassword(plain: string, stored: string) {
45
+ * return this.hash.verify(stored, plain);
46
+ * }
47
+ * }
48
+ *
49
+ * // Or use the standalone helpers without DI:
50
+ * import { scryptHash, scryptVerify } from "nexusjs/crypto";
51
+ * const hash = await scryptHash("hunter2");
52
+ * const ok = await scryptVerify(hash, "hunter2");
53
+ */
54
+ export { EncryptionService } from "./encryption.js";
55
+ export { HashService, hash, verify, scryptHash, scryptVerify } from "./hash.js";
56
+ export { CryptoModule, ENCRYPTION_SERVICE_TOKEN, HASH_SERVICE_TOKEN } from "./module.js";
57
+ export type { EncryptionConfig, EncryptOptions, HashConfig, HashOptions, HashAlgorithm, HmacConfig, EncryptedValue, SignedValue, HashedPassword, } from "./types.js";
package/dist/index.js CHANGED
@@ -1,20 +1,4 @@
1
1
  // @bun
2
- var __create = Object.create;
3
- var __getProtoOf = Object.getPrototypeOf;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __toESM = (mod, isNodeMode, target) => {
8
- target = mod != null ? __create(__getProtoOf(mod)) : {};
9
- const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
- for (let key of __getOwnPropNames(mod))
11
- if (!__hasOwnProp.call(to, key))
12
- __defProp(to, key, {
13
- get: () => mod[key],
14
- enumerable: true
15
- });
16
- return to;
17
- };
18
2
  var __legacyDecorateClassTS = function(decorators, target, key, desc) {
19
3
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
4
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -383,8 +367,22 @@ async function loadArgon2() {
383
367
  throw new Error("argon2 is not installed. Install with: bun add @node-rs/argon2");
384
368
  }
385
369
  }
370
+ async function hash(password, options = {}) {
371
+ const svc = new HashService;
372
+ return svc.hash(password, options);
373
+ }
374
+ async function verify(hashed, password) {
375
+ const svc = new HashService;
376
+ return svc.verify(hashed, password);
377
+ }
378
+ async function scryptHash(password) {
379
+ return hash(password, { algorithm: "scrypt" });
380
+ }
381
+ async function scryptVerify(hashed, password) {
382
+ return verify(hashed, password);
383
+ }
386
384
  // packages/crypto/src/module.ts
387
- import { Module } from "@nexusts/core/decorators/module.js";
385
+ import { Module } from "@nexusts/core";
388
386
  var ENCRYPTION_SERVICE_TOKEN = Symbol.for("nexus:EncryptionService");
389
387
  var HASH_SERVICE_TOKEN = Symbol.for("nexus:HashService");
390
388
 
@@ -446,6 +444,10 @@ CryptoModule = __legacyDecorateClassTS([
446
444
  })
447
445
  ], CryptoModule);
448
446
  export {
447
+ verify,
448
+ scryptVerify,
449
+ scryptHash,
450
+ hash,
449
451
  HashService,
450
452
  HASH_SERVICE_TOKEN,
451
453
  EncryptionService,
@@ -453,5 +455,5 @@ export {
453
455
  CryptoModule
454
456
  };
455
457
 
456
- //# debugId=68D8BB427FD50CFB64756E2164756E21
458
+ //# debugId=4F353992A3BC692264756E2164756E21
457
459
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -3,10 +3,10 @@
3
3
  "sources": ["../src/encryption.ts", "../src/hash.ts", "../src/module.ts"],
4
4
  "sourcesContent": [
5
5
  "/**\n * `EncryptionService` — AES-256-GCM symmetric encryption + HMAC\n * sign/unsign helpers.\n *\n * Use cases:\n * - **Encrypt** sensitive data before storing it (e.g. session\n * blobs in cookies or DB).\n * - **Sign** stateless values that need to be tamper-proof (e.g.\n * session IDs, CSRF tokens, password-reset links, signed URLs).\n *\n * The service derives two 32-byte keys from the user's master\n * `key` config: one for AES-GCM, one for HMAC. The keys are\n * distinct (HKDF-SHA256 with a per-purpose salt) so a leak of one\n * doesn't compromise the other.\n *\n * Encrypted format (v1):\n * `v1.<base64url(iv)>.<base64url(tag)>.<base64url(ciphertext)>`\n * where `iv` is 12 bytes and `tag` is 16 bytes (GCM auth tag).\n *\n * Signed format:\n * `<base64url(value)>.<base64url(hmac)>`\n */\n\nimport {\n\tcreateCipheriv,\n\tcreateDecipheriv,\n\tcreateHmac,\n\thkdfSync,\n\trandomBytes,\n\ttimingSafeEqual,\n} from \"node:crypto\";\nimport type { EncryptedValue, EncryptOptions, SignedValue } from \"./types.js\";\n\nconst VERSION = \"v1\";\nconst IV_BYTES = 12;\nconst TAG_BYTES = 16;\n\nexport class EncryptionService {\n\tprivate readonly aesKey: Buffer;\n\tprivate readonly hmacKey: Buffer;\n\n\tconstructor(masterKey: string) {\n\t\tconst derived = deriveKeys(masterKey);\n\t\tthis.aesKey = derived.aes;\n\t\tthis.hmacKey = derived.hmac;\n\t}\n\n\t/* ---------------- encrypt / decrypt ---------------- */\n\n\t/**\n\t * Encrypt a string. The output is self-describing and includes\n\t * the IV, auth tag, expiry, and purpose (if any) in the MAC.\n\t *\n\t * Format: `v1.<iv>.<tag>.<ciphertext>.<mac>`\n\t */\n\tencrypt(value: string, options: EncryptOptions = {}): EncryptedValue {\n\t\tconst iv = randomBytes(IV_BYTES);\n\t\tconst cipher = createCipheriv(\"aes-256-gcm\", this.aesKey, iv);\n\t\tconst plaintext = Buffer.from(value, \"utf8\");\n\t\tconst ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);\n\t\tconst tag = cipher.getAuthTag();\n\n\t\tconst expiry = encodeExpiry(options.expiresAt);\n\t\tconst purposeBuf = Buffer.from(options.purpose ?? \"\", \"utf8\");\n\t\tconst mac = this.macOver([VERSION, iv, tag, ciphertext, expiry, purposeBuf]);\n\n\t\treturn [\n\t\t\tVERSION,\n\t\t\tb64(iv),\n\t\t\tb64(tag),\n\t\t\tb64(ciphertext),\n\t\t\tb64(expiry),\n\t\t\tb64(purposeBuf),\n\t\t\tb64(mac),\n\t\t].join(\".\");\n\t}\n\n\t/**\n\t * Decrypt a value previously produced by `encrypt()`. Throws\n\t * if the value is malformed, the MAC doesn't match, the\n\t * purpose doesn't match, or the expiry has passed.\n\t */\n\tdecrypt<T = string>(payload: string): T {\n\t\tconst parsed = parseV1(payload);\n\t\tif (!parsed) throw new Error(\"Encrypted payload is malformed\");\n\n\t\t// Verify MAC over the canonical (VERSION, IV, tag, ct, expiry, purpose) tuple.\n\t\tconst expectedMac = this.macOver([\n\t\t\tVERSION,\n\t\t\tparsed.iv,\n\t\t\tparsed.tag,\n\t\t\tparsed.ciphertext,\n\t\t\tparsed.expiry,\n\t\t\tparsed.purpose,\n\t\t]);\n\t\tif (!constantTimeEqual(expectedMac, parsed.mac)) {\n\t\t\tthrow new Error(\"Encrypted payload failed integrity check\");\n\t\t}\n\n\t\t// Check expiry.\n\t\tif (parsed.expiry.length > 0) {\n\t\t\tconst expiryMs = parseExpiry(parsed.expiry.toString(\"utf8\"));\n\t\t\tif (expiryMs > 0 && Date.now() > expiryMs) {\n\t\t\t\tthrow new Error(\"Encrypted payload has expired\");\n\t\t\t}\n\t\t}\n\n\t\tconst decipher = createDecipheriv(\"aes-256-gcm\", this.aesKey, parsed.iv);\n\t\tdecipher.setAuthTag(parsed.tag);\n\t\tconst plaintext = Buffer.concat([\n\t\t\tdecipher.update(parsed.ciphertext),\n\t\t\tdecipher.final(),\n\t\t]);\n\t\treturn plaintext.toString(\"utf8\") as unknown as T;\n\t}\n\n\t/** True if the string was produced by `encrypt()`. */\n\tisEncrypted(value: string): boolean {\n\t\tif (typeof value !== \"string\") return false;\n\t\treturn value.startsWith(VERSION + \".\");\n\t}\n\n\t/* ---------------- HMAC sign / unsign ---------------- */\n\n\t/**\n\t * Sign a string with the framework's HMAC key. The output is\n\t * `<base64url(value)>.<base64url(hmac)>`.\n\t *\n\t * Useful for stateless session cookies, CSRF tokens, etc.\n\t */\n\tsign(value: string, purpose = \"\"): SignedValue {\n\t\tconst mac = createHmac(\"sha256\", this.hmacKey)\n\t\t\t.update(purpose)\n\t\t\t.update(\"|\")\n\t\t\t.update(value)\n\t\t\t.digest();\n\t\treturn `${b64(Buffer.from(value, \"utf8\"))}.${b64(mac)}`;\n\t}\n\n\t/**\n\t * Sign a pre-encoded value (no extra b64-encoding). The output\n\t * is just the base64url MAC. Useful for cookie / token formats\n\t * where the value is already b64-encoded.\n\t *\n\t * The caller is responsible for joining the value and signature.\n\t */\n\tsignRaw(value: string, purpose = \"\"): string {\n\t\tconst mac = createHmac(\"sha256\", this.hmacKey)\n\t\t\t.update(purpose)\n\t\t\t.update(\"|\")\n\t\t\t.update(value)\n\t\t\t.digest();\n\t\treturn b64(mac);\n\t}\n\n\t/**\n\t * Verify a raw signature (from `signRaw`) against a pre-encoded\n\t * value. Returns `true` on match, `false` otherwise.\n\t */\n\tverifyRaw(value: string, signature: string, purpose = \"\"): boolean {\n\t\tconst expected = createHmac(\"sha256\", this.hmacKey)\n\t\t\t.update(purpose)\n\t\t\t.update(\"|\")\n\t\t\t.update(value)\n\t\t\t.digest();\n\t\tconst given = fromB64(signature);\n\t\tif (!given) return false;\n\t\treturn constantTimeEqual(given, expected);\n\t}\n\n\t/**\n\t * Verify and extract a previously signed value. Returns the\n\t * original value on success, `null` on failure (malformed,\n\t * wrong purpose, MAC mismatch).\n\t */\n\tunsign(signed: string, purpose = \"\"): string | null {\n\t\tconst dot = signed.lastIndexOf(\".\");\n\t\tif (dot < 1 || dot === signed.length - 1) return null;\n\t\tconst valueB64 = signed.slice(0, dot);\n\t\tconst macB64 = signed.slice(dot + 1);\n\t\tconst value = fromB64(valueB64);\n\t\tconst mac = fromB64(macB64);\n\t\tif (!value || !mac) return null;\n\t\tconst expected = createHmac(\"sha256\", this.hmacKey)\n\t\t\t.update(purpose)\n\t\t\t.update(\"|\")\n\t\t\t.update(value)\n\t\t\t.digest();\n\t\tif (!constantTimeEqual(mac, expected)) return null;\n\t\treturn value.toString(\"utf8\");\n\t}\n\n\t/* ---------------- internals ---------------- */\n\n\tprivate macOver(parts: Array<Buffer | string>): Buffer {\n\t\tconst h = createHmac(\"sha256\", this.hmacKey);\n\t\tfor (const p of parts) {\n\t\t\th.update(\"|\");\n\t\t\th.update(p as Buffer);\n\t\t}\n\t\treturn h.digest();\n\t}\n}\n\n/* ------------------------------------------------------------------ *\n * Helpers\n * ------------------------------------------------------------------ */\n\nfunction b64(buf: Buffer): string {\n\treturn buf.toString(\"base64url\");\n}\n\nfunction fromB64(s: string): Buffer | null {\n\ttry {\n\t\treturn Buffer.from(s, \"base64url\");\n\t} catch {\n\t\treturn null;\n\t}\n}\n\nfunction constantTimeEqual(a: Buffer, b: Buffer): boolean {\n\tif (a.length !== b.length) return false;\n\treturn timingSafeEqual(a, b);\n}\n\nfunction encodeExpiry(expiresAt: number | string | Date | undefined): Buffer {\n\tif (expiresAt === undefined) return Buffer.alloc(0);\n\tlet ms: number;\n\tif (typeof expiresAt === \"number\") {\n\t\tms = expiresAt > 1e12 ? expiresAt : Date.now() + expiresAt * 1000;\n\t} else if (typeof expiresAt === \"string\") {\n\t\t// Numeric string = seconds from now\n\t\tconst asNum = Number(expiresAt);\n\t\tif (!isNaN(asNum) && asNum > 0) {\n\t\t\tms = asNum > 1e12 ? asNum : Date.now() + asNum * 1000;\n\t\t} else {\n\t\t\tms = Date.parse(expiresAt);\n\t\t}\n\t} else {\n\t\tms = expiresAt.getTime();\n\t}\n\tif (!isFinite(ms)) return Buffer.alloc(0);\n\treturn Buffer.from(String(ms), \"utf8\");\n}\n\nfunction parseExpiry(s: string): number {\n\tconst n = Number(s);\n\treturn isFinite(n) ? n : 0;\n}\n\ninterface ParsedV1 {\n\tiv: Buffer;\n\ttag: Buffer;\n\tciphertext: Buffer;\n\texpiry: Buffer;\n\tpurpose: Buffer;\n\tmac: Buffer;\n}\n\nfunction parseV1(s: string): ParsedV1 | null {\n\tif (typeof s !== \"string\" || !s.startsWith(VERSION + \".\")) return null;\n\tconst parts = s.split(\".\");\n\t// v1, iv, tag, ct, expiry, purpose, mac = 7 parts\n\tif (parts.length !== 7) return null;\n\tconst [, ivB64, tagB64, ctB64, expB64, purposeB64, macB64] = parts;\n\tconst iv = fromB64(ivB64);\n\tconst tag = fromB64(tagB64);\n\tconst ct = fromB64(ctB64);\n\tconst exp = fromB64(expB64);\n\tconst purpose = fromB64(purposeB64);\n\tconst mac = fromB64(macB64);\n\tif (!iv || !tag || !ct || !exp || !purpose || !mac) return null;\n\tif (iv.length !== IV_BYTES) return null;\n\tif (tag.length !== TAG_BYTES) return null;\n\treturn { iv, tag, ciphertext: ct, expiry: exp, purpose, mac };\n}\n\n/* ------------------------------------------------------------------ *\n * Key derivation — HKDF-SHA256, two sub-keys\n * ------------------------------------------------------------------ */\n\nfunction deriveKeys(masterKey: string): { aes: Buffer; hmac: Buffer } {\n\t// Convert the master to bytes. We accept any string; if it\n\t// happens to be base64 and is at least 32 bytes, decode it.\n\tlet input: Buffer;\n\ttry {\n\t\tconst decoded = Buffer.from(masterKey, \"base64\");\n\t\tif (\n\t\t\tdecoded.length >= 32 &&\n\t\t\t// The \"decoded\" path is valid only if the string is\n\t\t\t// actually base64 (would be a real try/catch).\n\t\t\tmasterKey.length % 4 === 0\n\t\t) {\n\t\t\tinput = decoded;\n\t\t} else {\n\t\t\tinput = Buffer.from(masterKey, \"utf8\");\n\t\t}\n\t} catch {\n\t\tinput = Buffer.from(masterKey, \"utf8\");\n\t}\n\n\tconst ikm = input.length < 32 ? padKey(input) : input;\n\tconst out = hkdfSync(\"sha256\", ikm, Buffer.alloc(0), \"nexus:crypto:v1\", 64);\n\tconst outBuf = Buffer.from(out);\n\treturn {\n\t\taes: Buffer.from(outBuf.subarray(0, 32)),\n\t\thmac: Buffer.from(outBuf.subarray(32, 64)),\n\t};\n}\n\nfunction padKey(input: Buffer): Buffer {\n\t// Pad to 32 bytes by appending SHA-256 of the key (so the\n\t// result is deterministic and at least 32 bytes long).\n\tconst hash = createHmac(\"sha256\", \"nexus:crypto:pad\").update(input).digest();\n\tconst out = Buffer.alloc(32);\n\tinput.copy(out, 0, 0, Math.min(input.length, 32));\n\thash.copy(out, input.length < 32 ? input.length : 0, 0, 32 - Math.min(input.length, 32));\n\treturn out;\n}\n",
6
- "/**\n * `HashService` — secure password hashing.\n *\n * Algorithms:\n * - `scrypt` (default) — built into Node, no extra deps. Memory-\n * hard and CPU-hard. Recommended for new apps.\n * - `argon2` (optional) — the @node-rs/argon2 package is the\n * reference implementation. Install it as a peer dep:\n *\n * bun add @node-rs/argon2\n *\n * When installed, the service auto-detects it.\n *\n * Output format (scrypt): a base64 string with the cost parameters\n * encoded: `$scrypt$N=16384,r=8,p=1$<saltB64>$<hashB64>`.\n * This is similar to the well-known `passlib` / PHC format and\n * lets us verify hashes that were generated with different\n * parameters.\n */\n\nimport { scrypt as scryptCb, randomBytes, timingSafeEqual } from \"node:crypto\";\n\n// scrypt's callback signature is (err, derivedKey) but it takes\n// (password, salt, keylen, options) before the callback, so we\n// can't use util.promisify directly. Wrap manually.\nfunction scrypt(\n\tpassword: string | Buffer,\n\tsalt: Buffer,\n\tkeylen: number,\n\toptions: { N: number; r: number; p: number; maxmem?: number },\n): Promise<Buffer> {\n\treturn new Promise((resolve, reject) => {\n\t\tscryptCb(password, salt, keylen, options, (err, derived) => {\n\t\t\tif (err) reject(err);\n\t\t\telse resolve(derived);\n\t\t});\n\t});\n}\nimport type { HashConfig, HashOptions, HashedPassword } from \"./types.js\";\n\nconst PREFIX_SCRYPT = \"$scrypt$\";\nconst PREFIX_ARGON2 = \"$argon2\";\n\nexport class HashService {\n\treadonly algorithm: \"scrypt\" | \"argon2\";\n\tprivate readonly scryptCost: number;\n\tprivate readonly scryptBlockSize: number;\n\tprivate readonly scryptParallelization: number;\n\tprivate readonly scryptKeyLength: number;\n\tprivate readonly argon2MemoryCost: number;\n\tprivate readonly argon2TimeCost: number;\n\tprivate readonly argon2Parallelism: number;\n\n\tconstructor(config: HashConfig = {}) {\n\t\tthis.algorithm = config.algorithm ?? \"scrypt\";\n\t\tthis.scryptCost = config.scryptCost ?? 16384;\n\t\tthis.scryptBlockSize = config.scryptBlockSize ?? 8;\n\t\tthis.scryptParallelization = config.scryptParallelization ?? 1;\n\t\tthis.scryptKeyLength = config.scryptKeyLength ?? 64;\n\t\tthis.argon2MemoryCost = config.argon2MemoryCost ?? 65536;\n\t\tthis.argon2TimeCost = config.argon2TimeCost ?? 3;\n\t\tthis.argon2Parallelism = config.argon2Parallelism ?? 4;\n\t}\n\n\t/**\n\t * Hash a password. Returns a self-describing string that\n\t * includes the algorithm and cost parameters.\n\t */\n\tasync hash(password: string, options: HashOptions = {}): Promise<HashedPassword> {\n\t\tconst algo = options.algorithm ?? this.algorithm;\n\t\tif (algo === \"scrypt\") return this.hashScrypt(password);\n\t\tif (algo === \"argon2\") return this.hashArgon2(password);\n\t\tthrow new Error(`Unknown hash algorithm: ${algo}`);\n\t}\n\n\t/**\n\t * Verify a password against a previously generated hash.\n\t * Returns `true` on match, `false` otherwise.\n\t */\n\tasync verify(hashed: HashedPassword, password: string): Promise<boolean> {\n\t\tif (typeof hashed !== \"string\" || hashed.length === 0) return false;\n\t\tif (hashed.startsWith(PREFIX_SCRYPT)) return this.verifyScrypt(hashed, password);\n\t\tif (hashed.startsWith(PREFIX_ARGON2)) return this.verifyArgon2(hashed, password);\n\t\t// Unknown format — try scrypt with default params for backward-compat\n\t\t// (e.g. raw SHA-256 / bcrypt / etc. — caller should migrate).\n\t\treturn false;\n\t}\n\n\t/**\n\t * True if a hash was generated with parameters that are below\n\t * the current security floor. The caller should re-hash and\n\t * update the stored value.\n\t */\n\tneedsRehash(hashed: HashedPassword): boolean {\n\t\tif (typeof hashed !== \"string\" || !hashed.startsWith(PREFIX_SCRYPT)) {\n\t\t\t// Foreign hash format — always re-hash to bring in the\n\t\t\t// canonical scrypt format.\n\t\t\treturn true;\n\t\t}\n\t\tconst params = parseScryptParams(hashed);\n\t\tif (!params) return true;\n\t\tif (params.N < this.scryptCost) return true;\n\t\tif (params.r < this.scryptBlockSize) return true;\n\t\tif (params.p < this.scryptParallelization) return true;\n\t\tif (params.keyLen < this.scryptKeyLength) return true;\n\t\treturn false;\n\t}\n\n\t/* ---------------- scrypt ---------------- */\n\n\tprivate async hashScrypt(password: string): Promise<string> {\n\t\tconst salt = randomBytes(16);\n\t\tconst derived = (await scrypt(password, salt, this.scryptKeyLength, {\n\t\t\tN: this.scryptCost,\n\t\t\tr: this.scryptBlockSize,\n\t\t\tp: this.scryptParallelization,\n\t\t\tmaxmem: 256 * 1024 * 1024,\n\t\t})) as Buffer;\n\t\treturn [\n\t\t\tPREFIX_SCRYPT,\n\t\t\t`N=${this.scryptCost},r=${this.scryptBlockSize},p=${this.scryptParallelization},keyLen=${this.scryptKeyLength}`,\n\t\t\t`$${salt.toString(\"base64url\")}`,\n\t\t\t`$${derived.toString(\"base64url\")}`,\n\t\t].join(\"\");\n\t}\n\n\tprivate async verifyScrypt(hashed: string, password: string): Promise<boolean> {\n\t\tconst params = parseScryptParams(hashed);\n\t\tif (!params) return false;\n\t\t// Format: \\\\ (split by \\$ gives 5 parts)\n\t\tconst [, , , saltB64, hashB64] = hashed.split(\"$\");\n\t\tif (!saltB64 || !hashB64) return false;\n\t\tconst salt = Buffer.from(saltB64, \"base64url\");\n\t\tconst expected = Buffer.from(hashB64, \"base64url\");\n\t\tconst derived = (await scrypt(password, salt, expected.length, {\n\t\t\tN: params.N,\n\t\t\tr: params.r,\n\t\t\tp: params.p,\n\t\t\tmaxmem: 256 * 1024 * 1024,\n\t\t})) as Buffer;\n\t\tif (derived.length !== expected.length) return false;\n\t\treturn timingSafeEqual(derived, expected);\n\t}\n\n\t/* ---------------- argon2 ---------------- */\n\n\tprivate async hashArgon2(password: string): Promise<string> {\n\t\tconst mod = await loadArgon2();\n\t\tconst hash = await mod.hash(password, {\n\t\t\tmemoryCost: this.argon2MemoryCost,\n\t\t\ttimeCost: this.argon2TimeCost,\n\t\t\tparallelism: this.argon2Parallelism,\n\t\t});\n\t\treturn hash; // argon2 already returns a self-describing string\n\t}\n\n\tprivate async verifyArgon2(hashed: string, password: string): Promise<boolean> {\n\t\tconst mod = await loadArgon2();\n\t\ttry {\n\t\t\treturn await mod.verify(hashed, password);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n}\n\n/* ------------------------------------------------------------------ *\n * Parsing\n * ------------------------------------------------------------------ */\n\nfunction parseScryptParams(hashed: string): {\n\tN: number;\n\tr: number;\n\tp: number;\n\tkeyLen: number;\n} | null {\n\t// $scrypt$N=16384,r=8,p=1,keyLen=64$<salt>$<hash>\n\tconst parts = hashed.split(\"$\");\n\tif (parts.length !== 5) return null;\n\tconst paramsPart = parts[2];\n\tif (!paramsPart) return null;\n\tconst m: Record<string, number> = {};\n\tfor (const kv of paramsPart.split(\",\")) {\n\t\tconst [k, v] = kv.split(\"=\");\n\t\tif (k && v) m[k] = Number(v);\n\t}\n\tif (!m.N || !m.r || !m.p || !m.keyLen) return null;\n\treturn { N: m.N, r: m.r, p: m.p, keyLen: m.keyLen };\n}\n\n/* ------------------------------------------------------------------ *\n * Optional argon2 peer dep\n * ------------------------------------------------------------------ */\n\ninterface Argon2Module {\n\thash(password: string, opts: { memoryCost: number; timeCost: number; parallelism: number }): Promise<string>;\n\tverify(hash: string, password: string): Promise<boolean>;\n}\n\nlet _argon2: Argon2Module | null | undefined; // undefined = not yet loaded\n\nasync function loadArgon2(): Promise<Argon2Module> {\n\tif (_argon2 !== undefined) {\n\t\tif (_argon2 === null) {\n\t\t\tthrow new Error(\n\t\t\t\t\"argon2 is not installed. Install with: bun add @node-rs/argon2\",\n\t\t\t);\n\t\t}\n\t\treturn _argon2;\n\t}\n\ttry {\n\t\t// @ts-ignore - optional peer dep\n\t\tconst mod = await import(\"@node-rs/argon2\");\n\t\t_argon2 = (mod as any).default ?? (mod as any);\n\t\tif (!_argon2) throw new Error(\"invalid argon2 module\");\n\t\treturn _argon2!;\n\t} catch {\n\t\t_argon2 = null;\n\t\tthrow new Error(\n\t\t\t\"argon2 is not installed. Install with: bun add @node-rs/argon2\",\n\t\t);\n\t}\n}\n",
7
- "/**\n * `CryptoModule` — wires `EncryptionService` and `HashService`\n * into the DI container.\n *\n * @Module({\n * imports: [CryptoModule.forRoot({ key: process.env.APP_KEY! })],\n * })\n * class AppModule {}\n *\n * The `key` is required for `EncryptionService` (32 bytes). For\n * `HashService` only the algorithm config is required — there's no\n * shared key.\n *\n * If you only need `HashService` (and don't use encryption), you\n * can pass an empty config:\n *\n * CryptoModule.forRoot({ key: \\\"x\\\" })\n * // Encryption will pad the key to 32 bytes via HKDF.\n */\n\nimport { Module } from \"@nexusts/core/decorators/module.js\";\nimport { EncryptionService } from \"./encryption.js\";\nimport { HashService } from \"./hash.js\";\nimport type { EncryptionConfig, HashConfig } from \"./types.js\";\n\nexport const ENCRYPTION_SERVICE_TOKEN = Symbol.for(\"nexus:EncryptionService\");\nexport const HASH_SERVICE_TOKEN = Symbol.for(\"nexus:HashService\");\n\n@Module({\n\tproviders: [\n\t\tEncryptionService,\n\t\tHashService,\n\t\t{ provide: ENCRYPTION_SERVICE_TOKEN, useExisting: EncryptionService },\n\t\t{ provide: HASH_SERVICE_TOKEN, useExisting: HashService },\n\t],\n\texports: [\n\t\tEncryptionService,\n\t\tHashService,\n\t\tENCRYPTION_SERVICE_TOKEN,\n\t\tHASH_SERVICE_TOKEN,\n\t],\n})\nexport class CryptoModule {\n\tstatic forRoot(config: EncryptionConfig & { hash?: HashConfig } = { key: \"\" }) {\n\t\tconst fullEncryptionConfig = {\n\t\t\tkey: config.key,\n\t\t\talgorithm: config.algorithm ?? \"aes-256-gcm\",\n\t\t\tdefaultExpiresIn: config.defaultExpiresIn,\n\t\t} as Required<EncryptionConfig>;\n\t\tconst fullHashConfig = config.hash ?? {};\n\n\t\t@Module({\n\t\t\tproviders: [\n\t\t\t\t{ provide: \"ENCRYPTION_CONFIG\", useValue: fullEncryptionConfig },\n\t\t\t\t{ provide: \"HASH_CONFIG\", useValue: fullHashConfig },\n\t\t\t\t{\n\t\t\t\t\tprovide: EncryptionService,\n\t\t\t\t\tuseFactory: () => new EncryptionService(fullEncryptionConfig.key),\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tprovide: HashService,\n\t\t\t\t\tuseFactory: () => new HashService(fullHashConfig),\n\t\t\t\t},\n\t\t\t\t{ provide: ENCRYPTION_SERVICE_TOKEN, useExisting: EncryptionService },\n\t\t\t\t{ provide: HASH_SERVICE_TOKEN, useExisting: HashService },\n\t\t\t],\n\t\t\texports: [\n\t\t\t\tEncryptionService,\n\t\t\t\tHashService,\n\t\t\t\tENCRYPTION_SERVICE_TOKEN,\n\t\t\t\tHASH_SERVICE_TOKEN,\n\t\t\t],\n\t\t})\n\t\tclass ConfiguredCryptoModule {}\n\t\tObject.defineProperty(ConfiguredCryptoModule, \"name\", {\n\t\t\tvalue: \"ConfiguredCryptoModule\",\n\t\t});\n\n\t\treturn ConfiguredCryptoModule as unknown as typeof CryptoModule;\n\t}\n}\n"
6
+ "/**\n * `HashService` — secure password hashing.\n *\n * Algorithms:\n * - `scrypt` (default) — built into Node, no extra deps. Memory-\n * hard and CPU-hard. Recommended for new apps.\n * - `argon2` (optional) — the @node-rs/argon2 package is the\n * reference implementation. Install it as a peer dep:\n *\n * bun add @node-rs/argon2\n *\n * When installed, the service auto-detects it.\n *\n * Output format (scrypt): a base64 string with the cost parameters\n * encoded: `$scrypt$N=16384,r=8,p=1$<saltB64>$<hashB64>`.\n * This is similar to the well-known `passlib` / PHC format and\n * lets us verify hashes that were generated with different\n * parameters.\n */\n\nimport { scrypt as scryptCb, randomBytes, timingSafeEqual } from \"node:crypto\";\n\n// scrypt's callback signature is (err, derivedKey) but it takes\n// (password, salt, keylen, options) before the callback, so we\n// can't use util.promisify directly. Wrap manually.\nfunction scrypt(\n\tpassword: string | Buffer,\n\tsalt: Buffer,\n\tkeylen: number,\n\toptions: { N: number; r: number; p: number; maxmem?: number },\n): Promise<Buffer> {\n\treturn new Promise((resolve, reject) => {\n\t\tscryptCb(password, salt, keylen, options, (err, derived) => {\n\t\t\tif (err) reject(err);\n\t\t\telse resolve(derived);\n\t\t});\n\t});\n}\nimport type { HashConfig, HashOptions, HashedPassword } from \"./types.js\";\n\nconst PREFIX_SCRYPT = \"$scrypt$\";\nconst PREFIX_ARGON2 = \"$argon2\";\n\nexport class HashService {\n\treadonly algorithm: \"scrypt\" | \"argon2\";\n\tprivate readonly scryptCost: number;\n\tprivate readonly scryptBlockSize: number;\n\tprivate readonly scryptParallelization: number;\n\tprivate readonly scryptKeyLength: number;\n\tprivate readonly argon2MemoryCost: number;\n\tprivate readonly argon2TimeCost: number;\n\tprivate readonly argon2Parallelism: number;\n\n\tconstructor(config: HashConfig = {}) {\n\t\tthis.algorithm = config.algorithm ?? \"scrypt\";\n\t\tthis.scryptCost = config.scryptCost ?? 16384;\n\t\tthis.scryptBlockSize = config.scryptBlockSize ?? 8;\n\t\tthis.scryptParallelization = config.scryptParallelization ?? 1;\n\t\tthis.scryptKeyLength = config.scryptKeyLength ?? 64;\n\t\tthis.argon2MemoryCost = config.argon2MemoryCost ?? 65536;\n\t\tthis.argon2TimeCost = config.argon2TimeCost ?? 3;\n\t\tthis.argon2Parallelism = config.argon2Parallelism ?? 4;\n\t}\n\n\t/**\n\t * Hash a password. Returns a self-describing string that\n\t * includes the algorithm and cost parameters.\n\t */\n\tasync hash(password: string, options: HashOptions = {}): Promise<HashedPassword> {\n\t\tconst algo = options.algorithm ?? this.algorithm;\n\t\tif (algo === \"scrypt\") return this.hashScrypt(password);\n\t\tif (algo === \"argon2\") return this.hashArgon2(password);\n\t\tthrow new Error(`Unknown hash algorithm: ${algo}`);\n\t}\n\n\t/**\n\t * Verify a password against a previously generated hash.\n\t * Returns `true` on match, `false` otherwise.\n\t */\n\tasync verify(hashed: HashedPassword, password: string): Promise<boolean> {\n\t\tif (typeof hashed !== \"string\" || hashed.length === 0) return false;\n\t\tif (hashed.startsWith(PREFIX_SCRYPT)) return this.verifyScrypt(hashed, password);\n\t\tif (hashed.startsWith(PREFIX_ARGON2)) return this.verifyArgon2(hashed, password);\n\t\t// Unknown format — try scrypt with default params for backward-compat\n\t\t// (e.g. raw SHA-256 / bcrypt / etc. — caller should migrate).\n\t\treturn false;\n\t}\n\n\t/**\n\t * True if a hash was generated with parameters that are below\n\t * the current security floor. The caller should re-hash and\n\t * update the stored value.\n\t */\n\tneedsRehash(hashed: HashedPassword): boolean {\n\t\tif (typeof hashed !== \"string\" || !hashed.startsWith(PREFIX_SCRYPT)) {\n\t\t\t// Foreign hash format — always re-hash to bring in the\n\t\t\t// canonical scrypt format.\n\t\t\treturn true;\n\t\t}\n\t\tconst params = parseScryptParams(hashed);\n\t\tif (!params) return true;\n\t\tif (params.N < this.scryptCost) return true;\n\t\tif (params.r < this.scryptBlockSize) return true;\n\t\tif (params.p < this.scryptParallelization) return true;\n\t\tif (params.keyLen < this.scryptKeyLength) return true;\n\t\treturn false;\n\t}\n\n\t/* ---------------- scrypt ---------------- */\n\n\tprivate async hashScrypt(password: string): Promise<string> {\n\t\tconst salt = randomBytes(16);\n\t\tconst derived = (await scrypt(password, salt, this.scryptKeyLength, {\n\t\t\tN: this.scryptCost,\n\t\t\tr: this.scryptBlockSize,\n\t\t\tp: this.scryptParallelization,\n\t\t\tmaxmem: 256 * 1024 * 1024,\n\t\t})) as Buffer;\n\t\treturn [\n\t\t\tPREFIX_SCRYPT,\n\t\t\t`N=${this.scryptCost},r=${this.scryptBlockSize},p=${this.scryptParallelization},keyLen=${this.scryptKeyLength}`,\n\t\t\t`$${salt.toString(\"base64url\")}`,\n\t\t\t`$${derived.toString(\"base64url\")}`,\n\t\t].join(\"\");\n\t}\n\n\tprivate async verifyScrypt(hashed: string, password: string): Promise<boolean> {\n\t\tconst params = parseScryptParams(hashed);\n\t\tif (!params) return false;\n\t\t// Format: \\\\ (split by \\$ gives 5 parts)\n\t\tconst [, , , saltB64, hashB64] = hashed.split(\"$\");\n\t\tif (!saltB64 || !hashB64) return false;\n\t\tconst salt = Buffer.from(saltB64, \"base64url\");\n\t\tconst expected = Buffer.from(hashB64, \"base64url\");\n\t\tconst derived = (await scrypt(password, salt, expected.length, {\n\t\t\tN: params.N,\n\t\t\tr: params.r,\n\t\t\tp: params.p,\n\t\t\tmaxmem: 256 * 1024 * 1024,\n\t\t})) as Buffer;\n\t\tif (derived.length !== expected.length) return false;\n\t\treturn timingSafeEqual(derived, expected);\n\t}\n\n\t/* ---------------- argon2 ---------------- */\n\n\tprivate async hashArgon2(password: string): Promise<string> {\n\t\tconst mod = await loadArgon2();\n\t\tconst hash = await mod.hash(password, {\n\t\t\tmemoryCost: this.argon2MemoryCost,\n\t\t\ttimeCost: this.argon2TimeCost,\n\t\t\tparallelism: this.argon2Parallelism,\n\t\t});\n\t\treturn hash; // argon2 already returns a self-describing string\n\t}\n\n\tprivate async verifyArgon2(hashed: string, password: string): Promise<boolean> {\n\t\tconst mod = await loadArgon2();\n\t\ttry {\n\t\t\treturn await mod.verify(hashed, password);\n\t\t} catch {\n\t\t\treturn false;\n\t\t}\n\t}\n}\n\n/* ------------------------------------------------------------------ *\n * Parsing\n * ------------------------------------------------------------------ */\n\nfunction parseScryptParams(hashed: string): {\n\tN: number;\n\tr: number;\n\tp: number;\n\tkeyLen: number;\n} | null {\n\t// $scrypt$N=16384,r=8,p=1,keyLen=64$<salt>$<hash>\n\tconst parts = hashed.split(\"$\");\n\tif (parts.length !== 5) return null;\n\tconst paramsPart = parts[2];\n\tif (!paramsPart) return null;\n\tconst m: Record<string, number> = {};\n\tfor (const kv of paramsPart.split(\",\")) {\n\t\tconst [k, v] = kv.split(\"=\");\n\t\tif (k && v) m[k] = Number(v);\n\t}\n\tif (!m.N || !m.r || !m.p || !m.keyLen) return null;\n\treturn { N: m.N, r: m.r, p: m.p, keyLen: m.keyLen };\n}\n\n/* ------------------------------------------------------------------ *\n * Optional argon2 peer dep\n * ------------------------------------------------------------------ */\n\ninterface Argon2Module {\n\thash(password: string, opts: { memoryCost: number; timeCost: number; parallelism: number }): Promise<string>;\n\tverify(hash: string, password: string): Promise<boolean>;\n}\n\nlet _argon2: Argon2Module | null | undefined; // undefined = not yet loaded\n\nasync function loadArgon2(): Promise<Argon2Module> {\n\tif (_argon2 !== undefined) {\n\t\tif (_argon2 === null) {\n\t\t\tthrow new Error(\n\t\t\t\t\"argon2 is not installed. Install with: bun add @node-rs/argon2\",\n\t\t\t);\n\t\t}\n\t\treturn _argon2;\n\t}\n\ttry {\n\t\t// @ts-ignore - optional peer dep\n\t\tconst mod = await import(\"@node-rs/argon2\");\n\t\t_argon2 = (mod as any).default ?? (mod as any);\n\t\tif (!_argon2) throw new Error(\"invalid argon2 module\");\n\t\treturn _argon2!;\n\t} catch {\n\t\t_argon2 = null;\n\t\tthrow new Error(\n\t\t\t\"argon2 is not installed. Install with: bun add @node-rs/argon2\",\n\t\t);\n\t}\n}\n\n// =====================================================================\n// Standalone helpers\n// =====================================================================\n//\n// These mirror the `HashService` API but do not require instantiating\n// the class. Useful for one-off hashing tasks (e.g. CLI scripts,\n// database seeders, smoke tests) where pulling the full DI container\n// is overkill.\n//\n// For production code with a controller or service, prefer the\n// `HashService` class via DI so the algorithm + cost parameters are\n// configured once at the module level.\n\n/**\n * Standalone `hash` function — uses scrypt by default, argon2 if\n * `@node-rs/argon2` is installed.\n *\n * @param password - The plaintext password to hash.\n * @param options - Optional overrides for algorithm + cost params.\n * @returns The encoded hash string (PHC-style).\n */\nexport async function hash(\n\tpassword: string,\n\toptions: HashOptions = {},\n): Promise<string> {\n\tconst svc = new HashService();\n\treturn svc.hash(password, options);\n}\n\n/**\n * Standalone `verify` function — verifies a plaintext password\n * against a previously encoded hash.\n */\nexport async function verify(\n\thashed: HashedPassword,\n\tpassword: string,\n): Promise<boolean> {\n\tconst svc = new HashService();\n\treturn svc.verify(hashed, password);\n}\n\n/**\n * Convenience: scrypt-specific hash. Useful when you want to\n * guarantee the algorithm regardless of installed peer deps.\n */\nexport async function scryptHash(password: string): Promise<string> {\n\treturn hash(password, { algorithm: \"scrypt\" });\n}\n\n/**\n * Convenience: scrypt-specific verify.\n */\nexport async function scryptVerify(\n\thashed: string,\n\tpassword: string,\n): Promise<boolean> {\n\treturn verify(hashed, password);\n}\n",
7
+ "/**\n * `CryptoModule` — wires `EncryptionService` and `HashService`\n * into the DI container.\n *\n * @Module({\n * imports: [CryptoModule.forRoot({ key: process.env.APP_KEY! })],\n * })\n * class AppModule {}\n *\n * The `key` is required for `EncryptionService` (32 bytes). For\n * `HashService` only the algorithm config is required — there's no\n * shared key.\n *\n * If you only need `HashService` (and don't use encryption), you\n * can pass an empty config:\n *\n * CryptoModule.forRoot({ key: \\\"x\\\" })\n * // Encryption will pad the key to 32 bytes via HKDF.\n */\n\nimport { Module } from \"@nexusts/core\";\nimport { EncryptionService } from \"./encryption.js\";\nimport { HashService } from \"./hash.js\";\nimport type { EncryptionConfig, HashConfig } from \"./types.js\";\n\nexport const ENCRYPTION_SERVICE_TOKEN = Symbol.for(\"nexus:EncryptionService\");\nexport const HASH_SERVICE_TOKEN = Symbol.for(\"nexus:HashService\");\n\n@Module({\n\tproviders: [\n\t\tEncryptionService,\n\t\tHashService,\n\t\t{ provide: ENCRYPTION_SERVICE_TOKEN, useExisting: EncryptionService },\n\t\t{ provide: HASH_SERVICE_TOKEN, useExisting: HashService },\n\t],\n\texports: [\n\t\tEncryptionService,\n\t\tHashService,\n\t\tENCRYPTION_SERVICE_TOKEN,\n\t\tHASH_SERVICE_TOKEN,\n\t],\n})\nexport class CryptoModule {\n\tstatic forRoot(config: EncryptionConfig & { hash?: HashConfig } = { key: \"\" }) {\n\t\tconst fullEncryptionConfig = {\n\t\t\tkey: config.key,\n\t\t\talgorithm: config.algorithm ?? \"aes-256-gcm\",\n\t\t\tdefaultExpiresIn: config.defaultExpiresIn,\n\t\t} as Required<EncryptionConfig>;\n\t\tconst fullHashConfig = config.hash ?? {};\n\n\t\t@Module({\n\t\t\tproviders: [\n\t\t\t\t{ provide: \"ENCRYPTION_CONFIG\", useValue: fullEncryptionConfig },\n\t\t\t\t{ provide: \"HASH_CONFIG\", useValue: fullHashConfig },\n\t\t\t\t{\n\t\t\t\t\tprovide: EncryptionService,\n\t\t\t\t\tuseFactory: () => new EncryptionService(fullEncryptionConfig.key),\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tprovide: HashService,\n\t\t\t\t\tuseFactory: () => new HashService(fullHashConfig),\n\t\t\t\t},\n\t\t\t\t{ provide: ENCRYPTION_SERVICE_TOKEN, useExisting: EncryptionService },\n\t\t\t\t{ provide: HASH_SERVICE_TOKEN, useExisting: HashService },\n\t\t\t],\n\t\t\texports: [\n\t\t\t\tEncryptionService,\n\t\t\t\tHashService,\n\t\t\t\tENCRYPTION_SERVICE_TOKEN,\n\t\t\t\tHASH_SERVICE_TOKEN,\n\t\t\t],\n\t\t})\n\t\tclass ConfiguredCryptoModule {}\n\t\tObject.defineProperty(ConfiguredCryptoModule, \"name\", {\n\t\t\tvalue: \"ConfiguredCryptoModule\",\n\t\t});\n\n\t\treturn ConfiguredCryptoModule as unknown as typeof CryptoModule;\n\t}\n}\n"
8
8
  ],
9
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,IAAM,UAAU;AAChB,IAAM,WAAW;AACjB,IAAM,YAAY;AAAA;AAEX,MAAM,kBAAkB;AAAA,EACb;AAAA,EACA;AAAA,EAEjB,WAAW,CAAC,WAAmB;AAAA,IAC9B,MAAM,UAAU,WAAW,SAAS;AAAA,IACpC,KAAK,SAAS,QAAQ;AAAA,IACtB,KAAK,UAAU,QAAQ;AAAA;AAAA,EAWxB,OAAO,CAAC,OAAe,UAA0B,CAAC,GAAmB;AAAA,IACpE,MAAM,KAAK,YAAY,QAAQ;AAAA,IAC/B,MAAM,SAAS,eAAe,eAAe,KAAK,QAAQ,EAAE;AAAA,IAC5D,MAAM,YAAY,OAAO,KAAK,OAAO,MAAM;AAAA,IAC3C,MAAM,aAAa,OAAO,OAAO,CAAC,OAAO,OAAO,SAAS,GAAG,OAAO,MAAM,CAAC,CAAC;AAAA,IAC3E,MAAM,MAAM,OAAO,WAAW;AAAA,IAE9B,MAAM,SAAS,aAAa,QAAQ,SAAS;AAAA,IAC7C,MAAM,aAAa,OAAO,KAAK,QAAQ,WAAW,IAAI,MAAM;AAAA,IAC5D,MAAM,MAAM,KAAK,QAAQ,CAAC,SAAS,IAAI,KAAK,YAAY,QAAQ,UAAU,CAAC;AAAA,IAE3E,OAAO;AAAA,MACN;AAAA,MACA,IAAI,EAAE;AAAA,MACN,IAAI,GAAG;AAAA,MACP,IAAI,UAAU;AAAA,MACd,IAAI,MAAM;AAAA,MACV,IAAI,UAAU;AAAA,MACd,IAAI,GAAG;AAAA,IACR,EAAE,KAAK,GAA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AwB,QAAQ;AAAA,MACrD,OAAO;AAAA,IACR,CAAC;AAAA,IAED,OAAO;AAAA;AAET;AAtCa,eAAN;AAAA,EAdN,OAAO;AAAA,IACP,WAAW;AAAA,MACV;AAAA,MACA;AAAA,MACA,EAAE,SAAS,0BAA0B,aAAa,kBAAkB;AAAA,MACpE,EAAE,SAAS,oBAAoB,aAAa,YAAY;AAAA,IACzD;AAAA,IACA,SAAS;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD,CAAC;AAAA,GACY;",
10
+ "debugId": "4F353992A3BC692264756E2164756E21",
11
11
  "names": []
12
12
  }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * `CryptoModule` — wires `EncryptionService` and `HashService`
3
+ * into the DI container.
4
+ *
5
+ * @Module({
6
+ * imports: [CryptoModule.forRoot({ key: process.env.APP_KEY! })],
7
+ * })
8
+ * class AppModule {}
9
+ *
10
+ * The `key` is required for `EncryptionService` (32 bytes). For
11
+ * `HashService` only the algorithm config is required — there's no
12
+ * shared key.
13
+ *
14
+ * If you only need `HashService` (and don't use encryption), you
15
+ * can pass an empty config:
16
+ *
17
+ * CryptoModule.forRoot({ key: \"x\" })
18
+ * // Encryption will pad the key to 32 bytes via HKDF.
19
+ */
20
+ import type { EncryptionConfig, HashConfig } from "./types.js";
21
+ export declare const ENCRYPTION_SERVICE_TOKEN: unique symbol;
22
+ export declare const HASH_SERVICE_TOKEN: unique symbol;
23
+ export declare class CryptoModule {
24
+ static forRoot(config?: EncryptionConfig & {
25
+ hash?: HashConfig;
26
+ }): typeof CryptoModule;
27
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Public types for `nexusjs/crypto`.
3
+ *
4
+ * `nexusjs/crypto` provides:
5
+ * - `EncryptionService` — AES-256-GCM symmetric encryption +
6
+ * HMAC sign/unsign (for stateless session cookies, CSRF tokens,
7
+ * signed URLs, etc.).
8
+ * - `HashService` — scrypt password hashing (argon2 available as
9
+ * an optional peer dep when the user installs `@node-rs/argon2`).
10
+ *
11
+ * No external dependencies. All primitives come from Node's
12
+ * built-in `crypto` module.
13
+ */
14
+ export interface EncryptionConfig {
15
+ /**
16
+ * Master key as a string or base64-encoded bytes. Must be at
17
+ * least 32 bytes after decoding. The framework derives separate
18
+ * 32-byte keys for AES and HMAC from this master.
19
+ *
20
+ * If the key is shorter, the framework pads / hashes it with
21
+ * SHA-256 — but the user is encouraged to provide a 32-byte
22
+ * random value (`openssl rand -base64 32`).
23
+ */
24
+ key: string;
25
+ /**
26
+ * Algorithm. Currently only "aes-256-gcm" is supported.
27
+ * Default: "aes-256-gcm".
28
+ */
29
+ algorithm?: "aes-256-gcm";
30
+ /**
31
+ * Default expiry for encrypted payloads. The decryptor
32
+ * throws if the payload was created with a past `expiresAt`.
33
+ * Default: never.
34
+ */
35
+ defaultExpiresIn?: number | string;
36
+ }
37
+ export interface EncryptOptions {
38
+ /** Expiry in seconds, or a future Date, or an absolute timestamp. */
39
+ expiresAt?: number | string | Date;
40
+ /** Purpose / namespace — included in the MAC, so a payload signed
41
+ * for "session" can't be replayed as a "csrf" token. */
42
+ purpose?: string;
43
+ }
44
+ export interface HmacConfig {
45
+ /** The secret key. Must be at least 16 bytes; longer is better. */
46
+ secret: string;
47
+ /** Algorithm. Default: "sha256". */
48
+ algorithm?: "sha256" | "sha512";
49
+ /** Optional purpose / namespace. */
50
+ purpose?: string;
51
+ }
52
+ export type HashAlgorithm = "scrypt" | "argon2";
53
+ export interface HashConfig {
54
+ /** Algorithm. Default: "scrypt". "argon2" requires the optional peer. */
55
+ algorithm?: HashAlgorithm;
56
+ /** scrypt N cost parameter. Default: 16384. */
57
+ scryptCost?: number;
58
+ /** scrypt block size. Default: 8. */
59
+ scryptBlockSize?: number;
60
+ /** scrypt parallelization. Default: 1. */
61
+ scryptParallelization?: number;
62
+ /** Output key length for scrypt. Default: 64. */
63
+ scryptKeyLength?: number;
64
+ /** Argon2 memory cost (KB). Default: 65536. */
65
+ argon2MemoryCost?: number;
66
+ /** Argon2 time cost. Default: 3. */
67
+ argon2TimeCost?: number;
68
+ /** Argon2 parallelism. Default: 4. */
69
+ argon2Parallelism?: number;
70
+ }
71
+ export interface HashOptions {
72
+ /** Custom algorithm override for this call. */
73
+ algorithm?: HashAlgorithm;
74
+ }
75
+ /** A hashed password in the framework's canonical string format. */
76
+ export type HashedPassword = string;
77
+ /** An encrypted payload — base64url-encoded, self-describing. */
78
+ export type EncryptedValue = string;
79
+ /** A signed value — base64url-encoded `<value>.<signature>`. */
80
+ export type SignedValue = string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexusts/crypto",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "AES-256-GCM encryption + HMAC + scrypt/argon2",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -12,20 +12,15 @@
12
12
  "import": "./dist/index.js"
13
13
  }
14
14
  },
15
- "files": [
16
- "dist",
17
- "README.md"
18
- ],
15
+ "files": ["dist", "README.md"],
19
16
  "scripts": {
20
17
  "build": "bun run ../../build.ts"
21
18
  },
22
- "keywords": [
23
- "nexusts",
24
- "framework",
25
- "bun"
26
- ],
19
+ "keywords": ["nexusts", "framework", "bun"],
27
20
  "license": "MIT",
21
+
22
+
28
23
  "dependencies": {
29
- "@nexusts/core": "^0.7.0"
24
+ "@nexusts/core": "file:../core"
30
25
  }
31
26
  }