@nexusts/crypto 0.7.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.
- package/README.md +41 -0
- package/dist/index.js +457 -0
- package/dist/index.js.map +12 -0
- package/package.json +31 -0
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# @nexusts/crypto
|
|
2
|
+
|
|
3
|
+
> **NexusTS** — Bun-native fullstack framework
|
|
4
|
+
|
|
5
|
+
## Description
|
|
6
|
+
|
|
7
|
+
AES-256-GCM encryption + HMAC + scrypt/argon2.
|
|
8
|
+
|
|
9
|
+
Authenticated encryption, HMAC sign/unsign, password hashing. Internally used by session cookies and CSRF tokens.
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
This module is part of the NexusTS monorepo. Each module is published as its own npm package under the `@nexusts/` scope.
|
|
14
|
+
|
|
15
|
+
Most apps start with just the core:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
bun add @nexusts/core reflect-metadata zod hono
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Then add this module only if you need it:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
bun add @nexusts/crypto
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Peer dependencies
|
|
28
|
+
|
|
29
|
+
None. This module is fully self-contained.
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { /* public API */ } from "@nexusts/crypto";
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
See the [user guide](../../docs/user-guide/crypto.md) and the [example app](../../examples/) for a working demo.
|
|
38
|
+
|
|
39
|
+
## License
|
|
40
|
+
|
|
41
|
+
MIT — see the root [LICENSE](../../LICENSE).
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,457 @@
|
|
|
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
|
+
var __legacyDecorateClassTS = function(decorators, target, key, desc) {
|
|
19
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
20
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
21
|
+
r = Reflect.decorate(decorators, target, key, desc);
|
|
22
|
+
else
|
|
23
|
+
for (var i = decorators.length - 1;i >= 0; i--)
|
|
24
|
+
if (d = decorators[i])
|
|
25
|
+
r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
26
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
27
|
+
};
|
|
28
|
+
var __require = import.meta.require;
|
|
29
|
+
|
|
30
|
+
// packages/crypto/src/encryption.ts
|
|
31
|
+
import {
|
|
32
|
+
createCipheriv,
|
|
33
|
+
createDecipheriv,
|
|
34
|
+
createHmac,
|
|
35
|
+
hkdfSync,
|
|
36
|
+
randomBytes,
|
|
37
|
+
timingSafeEqual
|
|
38
|
+
} from "crypto";
|
|
39
|
+
var VERSION = "v1";
|
|
40
|
+
var IV_BYTES = 12;
|
|
41
|
+
var TAG_BYTES = 16;
|
|
42
|
+
|
|
43
|
+
class EncryptionService {
|
|
44
|
+
aesKey;
|
|
45
|
+
hmacKey;
|
|
46
|
+
constructor(masterKey) {
|
|
47
|
+
const derived = deriveKeys(masterKey);
|
|
48
|
+
this.aesKey = derived.aes;
|
|
49
|
+
this.hmacKey = derived.hmac;
|
|
50
|
+
}
|
|
51
|
+
encrypt(value, options = {}) {
|
|
52
|
+
const iv = randomBytes(IV_BYTES);
|
|
53
|
+
const cipher = createCipheriv("aes-256-gcm", this.aesKey, iv);
|
|
54
|
+
const plaintext = Buffer.from(value, "utf8");
|
|
55
|
+
const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
56
|
+
const tag = cipher.getAuthTag();
|
|
57
|
+
const expiry = encodeExpiry(options.expiresAt);
|
|
58
|
+
const purposeBuf = Buffer.from(options.purpose ?? "", "utf8");
|
|
59
|
+
const mac = this.macOver([VERSION, iv, tag, ciphertext, expiry, purposeBuf]);
|
|
60
|
+
return [
|
|
61
|
+
VERSION,
|
|
62
|
+
b64(iv),
|
|
63
|
+
b64(tag),
|
|
64
|
+
b64(ciphertext),
|
|
65
|
+
b64(expiry),
|
|
66
|
+
b64(purposeBuf),
|
|
67
|
+
b64(mac)
|
|
68
|
+
].join(".");
|
|
69
|
+
}
|
|
70
|
+
decrypt(payload) {
|
|
71
|
+
const parsed = parseV1(payload);
|
|
72
|
+
if (!parsed)
|
|
73
|
+
throw new Error("Encrypted payload is malformed");
|
|
74
|
+
const expectedMac = this.macOver([
|
|
75
|
+
VERSION,
|
|
76
|
+
parsed.iv,
|
|
77
|
+
parsed.tag,
|
|
78
|
+
parsed.ciphertext,
|
|
79
|
+
parsed.expiry,
|
|
80
|
+
parsed.purpose
|
|
81
|
+
]);
|
|
82
|
+
if (!constantTimeEqual(expectedMac, parsed.mac)) {
|
|
83
|
+
throw new Error("Encrypted payload failed integrity check");
|
|
84
|
+
}
|
|
85
|
+
if (parsed.expiry.length > 0) {
|
|
86
|
+
const expiryMs = parseExpiry(parsed.expiry.toString("utf8"));
|
|
87
|
+
if (expiryMs > 0 && Date.now() > expiryMs) {
|
|
88
|
+
throw new Error("Encrypted payload has expired");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
const decipher = createDecipheriv("aes-256-gcm", this.aesKey, parsed.iv);
|
|
92
|
+
decipher.setAuthTag(parsed.tag);
|
|
93
|
+
const plaintext = Buffer.concat([
|
|
94
|
+
decipher.update(parsed.ciphertext),
|
|
95
|
+
decipher.final()
|
|
96
|
+
]);
|
|
97
|
+
return plaintext.toString("utf8");
|
|
98
|
+
}
|
|
99
|
+
isEncrypted(value) {
|
|
100
|
+
if (typeof value !== "string")
|
|
101
|
+
return false;
|
|
102
|
+
return value.startsWith(VERSION + ".");
|
|
103
|
+
}
|
|
104
|
+
sign(value, purpose = "") {
|
|
105
|
+
const mac = createHmac("sha256", this.hmacKey).update(purpose).update("|").update(value).digest();
|
|
106
|
+
return `${b64(Buffer.from(value, "utf8"))}.${b64(mac)}`;
|
|
107
|
+
}
|
|
108
|
+
signRaw(value, purpose = "") {
|
|
109
|
+
const mac = createHmac("sha256", this.hmacKey).update(purpose).update("|").update(value).digest();
|
|
110
|
+
return b64(mac);
|
|
111
|
+
}
|
|
112
|
+
verifyRaw(value, signature, purpose = "") {
|
|
113
|
+
const expected = createHmac("sha256", this.hmacKey).update(purpose).update("|").update(value).digest();
|
|
114
|
+
const given = fromB64(signature);
|
|
115
|
+
if (!given)
|
|
116
|
+
return false;
|
|
117
|
+
return constantTimeEqual(given, expected);
|
|
118
|
+
}
|
|
119
|
+
unsign(signed, purpose = "") {
|
|
120
|
+
const dot = signed.lastIndexOf(".");
|
|
121
|
+
if (dot < 1 || dot === signed.length - 1)
|
|
122
|
+
return null;
|
|
123
|
+
const valueB64 = signed.slice(0, dot);
|
|
124
|
+
const macB64 = signed.slice(dot + 1);
|
|
125
|
+
const value = fromB64(valueB64);
|
|
126
|
+
const mac = fromB64(macB64);
|
|
127
|
+
if (!value || !mac)
|
|
128
|
+
return null;
|
|
129
|
+
const expected = createHmac("sha256", this.hmacKey).update(purpose).update("|").update(value).digest();
|
|
130
|
+
if (!constantTimeEqual(mac, expected))
|
|
131
|
+
return null;
|
|
132
|
+
return value.toString("utf8");
|
|
133
|
+
}
|
|
134
|
+
macOver(parts) {
|
|
135
|
+
const h = createHmac("sha256", this.hmacKey);
|
|
136
|
+
for (const p of parts) {
|
|
137
|
+
h.update("|");
|
|
138
|
+
h.update(p);
|
|
139
|
+
}
|
|
140
|
+
return h.digest();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function b64(buf) {
|
|
144
|
+
return buf.toString("base64url");
|
|
145
|
+
}
|
|
146
|
+
function fromB64(s) {
|
|
147
|
+
try {
|
|
148
|
+
return Buffer.from(s, "base64url");
|
|
149
|
+
} catch {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function constantTimeEqual(a, b) {
|
|
154
|
+
if (a.length !== b.length)
|
|
155
|
+
return false;
|
|
156
|
+
return timingSafeEqual(a, b);
|
|
157
|
+
}
|
|
158
|
+
function encodeExpiry(expiresAt) {
|
|
159
|
+
if (expiresAt === undefined)
|
|
160
|
+
return Buffer.alloc(0);
|
|
161
|
+
let ms;
|
|
162
|
+
if (typeof expiresAt === "number") {
|
|
163
|
+
ms = expiresAt > 1000000000000 ? expiresAt : Date.now() + expiresAt * 1000;
|
|
164
|
+
} else if (typeof expiresAt === "string") {
|
|
165
|
+
const asNum = Number(expiresAt);
|
|
166
|
+
if (!isNaN(asNum) && asNum > 0) {
|
|
167
|
+
ms = asNum > 1000000000000 ? asNum : Date.now() + asNum * 1000;
|
|
168
|
+
} else {
|
|
169
|
+
ms = Date.parse(expiresAt);
|
|
170
|
+
}
|
|
171
|
+
} else {
|
|
172
|
+
ms = expiresAt.getTime();
|
|
173
|
+
}
|
|
174
|
+
if (!isFinite(ms))
|
|
175
|
+
return Buffer.alloc(0);
|
|
176
|
+
return Buffer.from(String(ms), "utf8");
|
|
177
|
+
}
|
|
178
|
+
function parseExpiry(s) {
|
|
179
|
+
const n = Number(s);
|
|
180
|
+
return isFinite(n) ? n : 0;
|
|
181
|
+
}
|
|
182
|
+
function parseV1(s) {
|
|
183
|
+
if (typeof s !== "string" || !s.startsWith(VERSION + "."))
|
|
184
|
+
return null;
|
|
185
|
+
const parts = s.split(".");
|
|
186
|
+
if (parts.length !== 7)
|
|
187
|
+
return null;
|
|
188
|
+
const [, ivB64, tagB64, ctB64, expB64, purposeB64, macB64] = parts;
|
|
189
|
+
const iv = fromB64(ivB64);
|
|
190
|
+
const tag = fromB64(tagB64);
|
|
191
|
+
const ct = fromB64(ctB64);
|
|
192
|
+
const exp = fromB64(expB64);
|
|
193
|
+
const purpose = fromB64(purposeB64);
|
|
194
|
+
const mac = fromB64(macB64);
|
|
195
|
+
if (!iv || !tag || !ct || !exp || !purpose || !mac)
|
|
196
|
+
return null;
|
|
197
|
+
if (iv.length !== IV_BYTES)
|
|
198
|
+
return null;
|
|
199
|
+
if (tag.length !== TAG_BYTES)
|
|
200
|
+
return null;
|
|
201
|
+
return { iv, tag, ciphertext: ct, expiry: exp, purpose, mac };
|
|
202
|
+
}
|
|
203
|
+
function deriveKeys(masterKey) {
|
|
204
|
+
let input;
|
|
205
|
+
try {
|
|
206
|
+
const decoded = Buffer.from(masterKey, "base64");
|
|
207
|
+
if (decoded.length >= 32 && masterKey.length % 4 === 0) {
|
|
208
|
+
input = decoded;
|
|
209
|
+
} else {
|
|
210
|
+
input = Buffer.from(masterKey, "utf8");
|
|
211
|
+
}
|
|
212
|
+
} catch {
|
|
213
|
+
input = Buffer.from(masterKey, "utf8");
|
|
214
|
+
}
|
|
215
|
+
const ikm = input.length < 32 ? padKey(input) : input;
|
|
216
|
+
const out = hkdfSync("sha256", ikm, Buffer.alloc(0), "nexus:crypto:v1", 64);
|
|
217
|
+
const outBuf = Buffer.from(out);
|
|
218
|
+
return {
|
|
219
|
+
aes: Buffer.from(outBuf.subarray(0, 32)),
|
|
220
|
+
hmac: Buffer.from(outBuf.subarray(32, 64))
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function padKey(input) {
|
|
224
|
+
const hash = createHmac("sha256", "nexus:crypto:pad").update(input).digest();
|
|
225
|
+
const out = Buffer.alloc(32);
|
|
226
|
+
input.copy(out, 0, 0, Math.min(input.length, 32));
|
|
227
|
+
hash.copy(out, input.length < 32 ? input.length : 0, 0, 32 - Math.min(input.length, 32));
|
|
228
|
+
return out;
|
|
229
|
+
}
|
|
230
|
+
// packages/crypto/src/hash.ts
|
|
231
|
+
import { scrypt as scryptCb, randomBytes as randomBytes2, timingSafeEqual as timingSafeEqual2 } from "crypto";
|
|
232
|
+
function scrypt(password, salt, keylen, options) {
|
|
233
|
+
return new Promise((resolve, reject) => {
|
|
234
|
+
scryptCb(password, salt, keylen, options, (err, derived) => {
|
|
235
|
+
if (err)
|
|
236
|
+
reject(err);
|
|
237
|
+
else
|
|
238
|
+
resolve(derived);
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
var PREFIX_SCRYPT = "$scrypt$";
|
|
243
|
+
var PREFIX_ARGON2 = "$argon2";
|
|
244
|
+
|
|
245
|
+
class HashService {
|
|
246
|
+
algorithm;
|
|
247
|
+
scryptCost;
|
|
248
|
+
scryptBlockSize;
|
|
249
|
+
scryptParallelization;
|
|
250
|
+
scryptKeyLength;
|
|
251
|
+
argon2MemoryCost;
|
|
252
|
+
argon2TimeCost;
|
|
253
|
+
argon2Parallelism;
|
|
254
|
+
constructor(config = {}) {
|
|
255
|
+
this.algorithm = config.algorithm ?? "scrypt";
|
|
256
|
+
this.scryptCost = config.scryptCost ?? 16384;
|
|
257
|
+
this.scryptBlockSize = config.scryptBlockSize ?? 8;
|
|
258
|
+
this.scryptParallelization = config.scryptParallelization ?? 1;
|
|
259
|
+
this.scryptKeyLength = config.scryptKeyLength ?? 64;
|
|
260
|
+
this.argon2MemoryCost = config.argon2MemoryCost ?? 65536;
|
|
261
|
+
this.argon2TimeCost = config.argon2TimeCost ?? 3;
|
|
262
|
+
this.argon2Parallelism = config.argon2Parallelism ?? 4;
|
|
263
|
+
}
|
|
264
|
+
async hash(password, options = {}) {
|
|
265
|
+
const algo = options.algorithm ?? this.algorithm;
|
|
266
|
+
if (algo === "scrypt")
|
|
267
|
+
return this.hashScrypt(password);
|
|
268
|
+
if (algo === "argon2")
|
|
269
|
+
return this.hashArgon2(password);
|
|
270
|
+
throw new Error(`Unknown hash algorithm: ${algo}`);
|
|
271
|
+
}
|
|
272
|
+
async verify(hashed, password) {
|
|
273
|
+
if (typeof hashed !== "string" || hashed.length === 0)
|
|
274
|
+
return false;
|
|
275
|
+
if (hashed.startsWith(PREFIX_SCRYPT))
|
|
276
|
+
return this.verifyScrypt(hashed, password);
|
|
277
|
+
if (hashed.startsWith(PREFIX_ARGON2))
|
|
278
|
+
return this.verifyArgon2(hashed, password);
|
|
279
|
+
return false;
|
|
280
|
+
}
|
|
281
|
+
needsRehash(hashed) {
|
|
282
|
+
if (typeof hashed !== "string" || !hashed.startsWith(PREFIX_SCRYPT)) {
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
const params = parseScryptParams(hashed);
|
|
286
|
+
if (!params)
|
|
287
|
+
return true;
|
|
288
|
+
if (params.N < this.scryptCost)
|
|
289
|
+
return true;
|
|
290
|
+
if (params.r < this.scryptBlockSize)
|
|
291
|
+
return true;
|
|
292
|
+
if (params.p < this.scryptParallelization)
|
|
293
|
+
return true;
|
|
294
|
+
if (params.keyLen < this.scryptKeyLength)
|
|
295
|
+
return true;
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
async hashScrypt(password) {
|
|
299
|
+
const salt = randomBytes2(16);
|
|
300
|
+
const derived = await scrypt(password, salt, this.scryptKeyLength, {
|
|
301
|
+
N: this.scryptCost,
|
|
302
|
+
r: this.scryptBlockSize,
|
|
303
|
+
p: this.scryptParallelization,
|
|
304
|
+
maxmem: 256 * 1024 * 1024
|
|
305
|
+
});
|
|
306
|
+
return [
|
|
307
|
+
PREFIX_SCRYPT,
|
|
308
|
+
`N=${this.scryptCost},r=${this.scryptBlockSize},p=${this.scryptParallelization},keyLen=${this.scryptKeyLength}`,
|
|
309
|
+
`$${salt.toString("base64url")}`,
|
|
310
|
+
`$${derived.toString("base64url")}`
|
|
311
|
+
].join("");
|
|
312
|
+
}
|
|
313
|
+
async verifyScrypt(hashed, password) {
|
|
314
|
+
const params = parseScryptParams(hashed);
|
|
315
|
+
if (!params)
|
|
316
|
+
return false;
|
|
317
|
+
const [, , , saltB64, hashB64] = hashed.split("$");
|
|
318
|
+
if (!saltB64 || !hashB64)
|
|
319
|
+
return false;
|
|
320
|
+
const salt = Buffer.from(saltB64, "base64url");
|
|
321
|
+
const expected = Buffer.from(hashB64, "base64url");
|
|
322
|
+
const derived = await scrypt(password, salt, expected.length, {
|
|
323
|
+
N: params.N,
|
|
324
|
+
r: params.r,
|
|
325
|
+
p: params.p,
|
|
326
|
+
maxmem: 256 * 1024 * 1024
|
|
327
|
+
});
|
|
328
|
+
if (derived.length !== expected.length)
|
|
329
|
+
return false;
|
|
330
|
+
return timingSafeEqual2(derived, expected);
|
|
331
|
+
}
|
|
332
|
+
async hashArgon2(password) {
|
|
333
|
+
const mod = await loadArgon2();
|
|
334
|
+
const hash = await mod.hash(password, {
|
|
335
|
+
memoryCost: this.argon2MemoryCost,
|
|
336
|
+
timeCost: this.argon2TimeCost,
|
|
337
|
+
parallelism: this.argon2Parallelism
|
|
338
|
+
});
|
|
339
|
+
return hash;
|
|
340
|
+
}
|
|
341
|
+
async verifyArgon2(hashed, password) {
|
|
342
|
+
const mod = await loadArgon2();
|
|
343
|
+
try {
|
|
344
|
+
return await mod.verify(hashed, password);
|
|
345
|
+
} catch {
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
function parseScryptParams(hashed) {
|
|
351
|
+
const parts = hashed.split("$");
|
|
352
|
+
if (parts.length !== 5)
|
|
353
|
+
return null;
|
|
354
|
+
const paramsPart = parts[2];
|
|
355
|
+
if (!paramsPart)
|
|
356
|
+
return null;
|
|
357
|
+
const m = {};
|
|
358
|
+
for (const kv of paramsPart.split(",")) {
|
|
359
|
+
const [k, v] = kv.split("=");
|
|
360
|
+
if (k && v)
|
|
361
|
+
m[k] = Number(v);
|
|
362
|
+
}
|
|
363
|
+
if (!m.N || !m.r || !m.p || !m.keyLen)
|
|
364
|
+
return null;
|
|
365
|
+
return { N: m.N, r: m.r, p: m.p, keyLen: m.keyLen };
|
|
366
|
+
}
|
|
367
|
+
var _argon2;
|
|
368
|
+
async function loadArgon2() {
|
|
369
|
+
if (_argon2 !== undefined) {
|
|
370
|
+
if (_argon2 === null) {
|
|
371
|
+
throw new Error("argon2 is not installed. Install with: bun add @node-rs/argon2");
|
|
372
|
+
}
|
|
373
|
+
return _argon2;
|
|
374
|
+
}
|
|
375
|
+
try {
|
|
376
|
+
const mod = await import("@node-rs/argon2");
|
|
377
|
+
_argon2 = mod.default ?? mod;
|
|
378
|
+
if (!_argon2)
|
|
379
|
+
throw new Error("invalid argon2 module");
|
|
380
|
+
return _argon2;
|
|
381
|
+
} catch {
|
|
382
|
+
_argon2 = null;
|
|
383
|
+
throw new Error("argon2 is not installed. Install with: bun add @node-rs/argon2");
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
// packages/crypto/src/module.ts
|
|
387
|
+
import { Module } from "@nexusts/core/decorators/module.js";
|
|
388
|
+
var ENCRYPTION_SERVICE_TOKEN = Symbol.for("nexus:EncryptionService");
|
|
389
|
+
var HASH_SERVICE_TOKEN = Symbol.for("nexus:HashService");
|
|
390
|
+
|
|
391
|
+
class CryptoModule {
|
|
392
|
+
static forRoot(config = { key: "" }) {
|
|
393
|
+
const fullEncryptionConfig = {
|
|
394
|
+
key: config.key,
|
|
395
|
+
algorithm: config.algorithm ?? "aes-256-gcm",
|
|
396
|
+
defaultExpiresIn: config.defaultExpiresIn
|
|
397
|
+
};
|
|
398
|
+
const fullHashConfig = config.hash ?? {};
|
|
399
|
+
|
|
400
|
+
class ConfiguredCryptoModule {
|
|
401
|
+
}
|
|
402
|
+
ConfiguredCryptoModule = __legacyDecorateClassTS([
|
|
403
|
+
Module({
|
|
404
|
+
providers: [
|
|
405
|
+
{ provide: "ENCRYPTION_CONFIG", useValue: fullEncryptionConfig },
|
|
406
|
+
{ provide: "HASH_CONFIG", useValue: fullHashConfig },
|
|
407
|
+
{
|
|
408
|
+
provide: EncryptionService,
|
|
409
|
+
useFactory: () => new EncryptionService(fullEncryptionConfig.key)
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
provide: HashService,
|
|
413
|
+
useFactory: () => new HashService(fullHashConfig)
|
|
414
|
+
},
|
|
415
|
+
{ provide: ENCRYPTION_SERVICE_TOKEN, useExisting: EncryptionService },
|
|
416
|
+
{ provide: HASH_SERVICE_TOKEN, useExisting: HashService }
|
|
417
|
+
],
|
|
418
|
+
exports: [
|
|
419
|
+
EncryptionService,
|
|
420
|
+
HashService,
|
|
421
|
+
ENCRYPTION_SERVICE_TOKEN,
|
|
422
|
+
HASH_SERVICE_TOKEN
|
|
423
|
+
]
|
|
424
|
+
})
|
|
425
|
+
], ConfiguredCryptoModule);
|
|
426
|
+
Object.defineProperty(ConfiguredCryptoModule, "name", {
|
|
427
|
+
value: "ConfiguredCryptoModule"
|
|
428
|
+
});
|
|
429
|
+
return ConfiguredCryptoModule;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
CryptoModule = __legacyDecorateClassTS([
|
|
433
|
+
Module({
|
|
434
|
+
providers: [
|
|
435
|
+
EncryptionService,
|
|
436
|
+
HashService,
|
|
437
|
+
{ provide: ENCRYPTION_SERVICE_TOKEN, useExisting: EncryptionService },
|
|
438
|
+
{ provide: HASH_SERVICE_TOKEN, useExisting: HashService }
|
|
439
|
+
],
|
|
440
|
+
exports: [
|
|
441
|
+
EncryptionService,
|
|
442
|
+
HashService,
|
|
443
|
+
ENCRYPTION_SERVICE_TOKEN,
|
|
444
|
+
HASH_SERVICE_TOKEN
|
|
445
|
+
]
|
|
446
|
+
})
|
|
447
|
+
], CryptoModule);
|
|
448
|
+
export {
|
|
449
|
+
HashService,
|
|
450
|
+
HASH_SERVICE_TOKEN,
|
|
451
|
+
EncryptionService,
|
|
452
|
+
ENCRYPTION_SERVICE_TOKEN,
|
|
453
|
+
CryptoModule
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
//# debugId=68D8BB427FD50CFB64756E2164756E21
|
|
457
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/encryption.ts", "../src/hash.ts", "../src/module.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
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"
|
|
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,G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;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD,CAAC;AAAA,GACY;",
|
|
10
|
+
"debugId": "68D8BB427FD50CFB64756E2164756E21",
|
|
11
|
+
"names": []
|
|
12
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@nexusts/crypto",
|
|
3
|
+
"version": "0.7.0",
|
|
4
|
+
"description": "AES-256-GCM encryption + HMAC + scrypt/argon2",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "bun run ../../build.ts"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"nexusts",
|
|
24
|
+
"framework",
|
|
25
|
+
"bun"
|
|
26
|
+
],
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@nexusts/core": "^0.7.0"
|
|
30
|
+
}
|
|
31
|
+
}
|