@rpcbase/server 0.567.0 → 0.569.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/dist/index.js +29 -12
- package/dist/index.js.map +1 -1
- package/dist/passwordHashStorage.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4381,12 +4381,22 @@ async function hashPassword(password, salt) {
|
|
|
4381
4381
|
});
|
|
4382
4382
|
return derivedKey;
|
|
4383
4383
|
}
|
|
4384
|
-
const
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4384
|
+
const PRODUCTION_SCRYPT_PARAMS = {
|
|
4385
|
+
N: 8192,
|
|
4386
|
+
r: 8,
|
|
4387
|
+
p: 4,
|
|
4388
|
+
keylen: 64,
|
|
4389
|
+
saltBytes: 16,
|
|
4390
|
+
maxmemBytes: 256 * 1024 * 1024
|
|
4391
|
+
};
|
|
4392
|
+
const DEVELOPMENT_SCRYPT_PARAMS = {
|
|
4393
|
+
N: 1024,
|
|
4394
|
+
r: 8,
|
|
4395
|
+
p: 1,
|
|
4396
|
+
keylen: 64,
|
|
4397
|
+
saltBytes: 16,
|
|
4398
|
+
maxmemBytes: 256 * 1024 * 1024
|
|
4399
|
+
};
|
|
4390
4400
|
const MAX_SCRYPT_MAXMEM_BYTES = 1024 * 1024 * 1024;
|
|
4391
4401
|
const MAX_SCRYPT_N = 1048576;
|
|
4392
4402
|
const MAX_SCRYPT_R = 64;
|
|
@@ -4409,6 +4419,12 @@ const estimateScryptMemoryBytes = ({
|
|
|
4409
4419
|
}) => {
|
|
4410
4420
|
return 128 * r * (N + p);
|
|
4411
4421
|
};
|
|
4422
|
+
const isProductionRuntime = () => {
|
|
4423
|
+
return process.env.NODE_ENV === "production" || globalThis.__rb_env__?.MODE === "production";
|
|
4424
|
+
};
|
|
4425
|
+
const getDefaultScryptParams = () => {
|
|
4426
|
+
return isProductionRuntime() ? PRODUCTION_SCRYPT_PARAMS : DEVELOPMENT_SCRYPT_PARAMS;
|
|
4427
|
+
};
|
|
4412
4428
|
const validateScryptParams = (params) => {
|
|
4413
4429
|
const {
|
|
4414
4430
|
N,
|
|
@@ -4471,7 +4487,7 @@ const validateScryptParams = (params) => {
|
|
|
4471
4487
|
};
|
|
4472
4488
|
const getCurrentMaxmemBytes = (opts) => {
|
|
4473
4489
|
const envMaxmemBytes = parseEnvInt(process.env.RB_PASSWORD_SCRYPT_MAXMEM_BYTES);
|
|
4474
|
-
const maxmemBytes = opts?.maxmemBytes ?? envMaxmemBytes ??
|
|
4490
|
+
const maxmemBytes = opts?.maxmemBytes ?? envMaxmemBytes ?? getDefaultScryptParams().maxmemBytes;
|
|
4475
4491
|
if (!Number.isSafeInteger(maxmemBytes) || maxmemBytes < 16 * 1024 * 1024 || maxmemBytes > MAX_SCRYPT_MAXMEM_BYTES) {
|
|
4476
4492
|
throw new Error("invalid_scrypt_maxmem");
|
|
4477
4493
|
}
|
|
@@ -4483,12 +4499,13 @@ const getCurrentScryptParams = (opts) => {
|
|
|
4483
4499
|
const envP = parseEnvInt(process.env.RB_PASSWORD_SCRYPT_P);
|
|
4484
4500
|
const envKeylen = parseEnvInt(process.env.RB_PASSWORD_SCRYPT_KEYLEN);
|
|
4485
4501
|
const envSaltBytes = parseEnvInt(process.env.RB_PASSWORD_SCRYPT_SALT_BYTES);
|
|
4502
|
+
const defaults = getDefaultScryptParams();
|
|
4486
4503
|
const params = {
|
|
4487
|
-
N: opts?.N ?? envN ??
|
|
4488
|
-
r: opts?.r ?? envR ??
|
|
4489
|
-
p: opts?.p ?? envP ??
|
|
4490
|
-
keylen: opts?.keylen ?? envKeylen ??
|
|
4491
|
-
saltBytes: opts?.saltBytes ?? envSaltBytes ??
|
|
4504
|
+
N: opts?.N ?? envN ?? defaults.N,
|
|
4505
|
+
r: opts?.r ?? envR ?? defaults.r,
|
|
4506
|
+
p: opts?.p ?? envP ?? defaults.p,
|
|
4507
|
+
keylen: opts?.keylen ?? envKeylen ?? defaults.keylen,
|
|
4508
|
+
saltBytes: opts?.saltBytes ?? envSaltBytes ?? defaults.saltBytes,
|
|
4492
4509
|
maxmemBytes: getCurrentMaxmemBytes(opts)
|
|
4493
4510
|
};
|
|
4494
4511
|
const validated = validateScryptParams(params);
|