@server/next 0.45.0 → 0.45.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.
Files changed (2) hide show
  1. package/index.js +23 -29
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -2216,23 +2216,30 @@ import * as crypto2 from "crypto";
2216
2216
  import { getRandomValues } from "crypto";
2217
2217
  import { promisify } from "util";
2218
2218
  async function hash2(password) {
2219
- if ("argon2" in crypto2) {
2220
- const argon23 = promisify(crypto2.argon2);
2221
- const buf = await argon23("argon2id", {
2222
- message: Buffer.from(password),
2223
- nonce: getRandomValues(new Uint8Array(16)),
2224
- parallelism: 4,
2225
- tagLength: 64,
2226
- memory: 65536,
2227
- passes: 3
2219
+ if ("Bun" in globalThis) {
2220
+ return await Bun.password.hash(password, {
2221
+ algorithm: "argon2id",
2222
+ memoryCost: 65536,
2223
+ timeCost: 3
2228
2224
  });
2229
- return buf.toString("base64");
2230
2225
  }
2231
- return await Bun.password.hash(password, {
2232
- algorithm: "argon2id",
2233
- memoryCost: 65536,
2234
- timeCost: 3
2226
+ if (!("argon2" in crypto2)) {
2227
+ throw new Error(
2228
+ "Password hashing needs argon2: run on Bun, or on Node 24+ where node:crypto provides it."
2229
+ );
2230
+ }
2231
+ const nonce = getRandomValues(new Uint8Array(32));
2232
+ const argon23 = promisify(crypto2.argon2);
2233
+ const buf = await argon23("argon2id", {
2234
+ message: Buffer.from(password),
2235
+ nonce,
2236
+ parallelism: 1,
2237
+ tagLength: 32,
2238
+ memory: 65536,
2239
+ passes: 3
2235
2240
  });
2241
+ const b64 = (bytes) => Buffer.from(bytes).toString("base64").replace(/=+$/, "");
2242
+ return `$argon2id$v=19$m=65536,t=3,p=1$${b64(nonce)}$${b64(buf)}`;
2236
2243
  }
2237
2244
 
2238
2245
  // src/helpers/iteratorAsyncToReadable.ts
@@ -2327,16 +2334,6 @@ function toWeb(nodeStream) {
2327
2334
 
2328
2335
  // src/helpers/verify.ts
2329
2336
  import * as crypto3 from "crypto";
2330
- function timingSafeEqual(a, b) {
2331
- const len = Math.max(a.length, b.length);
2332
- let mismatch = a.length ^ b.length;
2333
- for (let i = 0; i < len; i++) {
2334
- const ca = a.charCodeAt(i) || 0;
2335
- const cb = b.charCodeAt(i) || 0;
2336
- mismatch |= ca ^ cb;
2337
- }
2338
- return mismatch === 0;
2339
- }
2340
2337
  async function verify2(password, hash3) {
2341
2338
  if ("Bun" in globalThis) {
2342
2339
  return Bun.password.verify(password, hash3, "argon2id");
@@ -2361,11 +2358,8 @@ async function verify2(password, hash3) {
2361
2358
  },
2362
2359
  (err, derivedKey) => {
2363
2360
  if (err) return reject(err);
2364
- if (derivedKey.length === expected.length && timingSafeEqual(derivedKey, expected)) {
2365
- resolve(true);
2366
- } else {
2367
- resolve(false);
2368
- }
2361
+ if (derivedKey.length !== expected.length) return resolve(false);
2362
+ resolve(crypto3.timingSafeEqual(derivedKey, expected));
2369
2363
  }
2370
2364
  );
2371
2365
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@server/next",
3
- "version": "0.45.0",
3
+ "version": "0.45.1",
4
4
  "description": "A fully-fledged web server with routing, file uploads, sessions, static files, schema validation, websockets, testing, etc.",
5
5
  "homepage": "https://server-js.com/",
6
6
  "repository": "github:franciscop/server-next",