apeframework 0.0.0-dev.26 → 0.0.0-dev.28

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.
@@ -0,0 +1,6 @@
1
+ declare enum Algorithm {
2
+ ARGON2D = 0,
3
+ ARGON2I = 1,
4
+ ARGON2ID = 2
5
+ }
6
+ export { Algorithm, };
@@ -0,0 +1,7 @@
1
+ var Algorithm;
2
+ (function (Algorithm) {
3
+ Algorithm[Algorithm["ARGON2D"] = 0] = "ARGON2D";
4
+ Algorithm[Algorithm["ARGON2I"] = 1] = "ARGON2I";
5
+ Algorithm[Algorithm["ARGON2ID"] = 2] = "ARGON2ID";
6
+ })(Algorithm || (Algorithm = {}));
7
+ export { Algorithm, };
package/dist/pwd/Pwd.d.ts CHANGED
@@ -1,7 +1,16 @@
1
+ import type { Algorithm } from './Algorithm.js';
1
2
  declare class Pwd {
2
- private readonly hashRounds;
3
+ private readonly algorithm;
4
+ private readonly hashLength;
5
+ private readonly timeCost;
6
+ private readonly memoryCost;
7
+ private readonly parallelism;
3
8
  constructor(params: {
4
- hashRounds: number;
9
+ algorithm?: Algorithm;
10
+ hashLength?: number;
11
+ timeCost?: number;
12
+ memoryCost?: number;
13
+ parallelism?: number;
5
14
  });
6
15
  hashPassword(password: string): Promise<string>;
7
16
  verifyPassword(password: string, hash: string): Promise<boolean>;
package/dist/pwd/Pwd.js CHANGED
@@ -1,16 +1,36 @@
1
- import bcrypt from 'bcryptjs';
2
- import { validateHashRounds } from './validateHashRounds.js';
1
+ import argon2 from 'argon2';
2
+ import { validateHashLength } from './validateHashLength.js';
3
+ import { validateMemoryCost } from './validateMemoryCost.js';
4
+ import { validateParallelism } from './validateParallelism.js';
5
+ import { validateTimeCost } from './validateTimeCost.js';
3
6
  class Pwd {
4
- hashRounds;
7
+ algorithm;
8
+ hashLength;
9
+ timeCost;
10
+ memoryCost;
11
+ parallelism;
5
12
  constructor(params) {
6
- validateHashRounds(params.hashRounds);
7
- this.hashRounds = params.hashRounds;
13
+ this.algorithm = params.algorithm;
14
+ validateHashLength(params.hashLength);
15
+ this.hashLength = params.hashLength;
16
+ validateTimeCost(params.timeCost);
17
+ this.timeCost = params.timeCost;
18
+ validateMemoryCost(params.memoryCost);
19
+ this.memoryCost = params.memoryCost;
20
+ validateParallelism(params.parallelism);
21
+ this.parallelism = params.parallelism;
8
22
  }
9
23
  async hashPassword(password) {
10
- return bcrypt.hashSync(password, this.hashRounds);
24
+ return argon2.hash(password, {
25
+ ...this.algorithm ? { type: this.algorithm } : {},
26
+ hashLength: this.hashLength,
27
+ timeCost: this.timeCost,
28
+ memoryCost: this.memoryCost,
29
+ parallelism: this.parallelism,
30
+ });
11
31
  }
12
32
  async verifyPassword(password, hash) {
13
- return bcrypt.compareSync(password, hash);
33
+ return argon2.verify(hash, password);
14
34
  }
15
35
  }
16
36
  export { Pwd, };
@@ -0,0 +1,5 @@
1
+ import { BaseError } from '../../error/BaseError.js';
2
+ declare class HashLengthError extends BaseError {
3
+ constructor(hashLength: number);
4
+ }
5
+ export { HashLengthError, };
@@ -0,0 +1,7 @@
1
+ import { BaseError } from '../../error/BaseError.js';
2
+ class HashLengthError extends BaseError {
3
+ constructor(hashLength) {
4
+ super(`invalid hash length "${hashLength}"`);
5
+ }
6
+ }
7
+ export { HashLengthError, };
@@ -0,0 +1,5 @@
1
+ import { BaseError } from '../../error/BaseError.js';
2
+ declare class MemoryCostError extends BaseError {
3
+ constructor(memoryCost: number);
4
+ }
5
+ export { MemoryCostError, };
@@ -0,0 +1,7 @@
1
+ import { BaseError } from '../../error/BaseError.js';
2
+ class MemoryCostError extends BaseError {
3
+ constructor(memoryCost) {
4
+ super(`invalid memory cost "${memoryCost}"`);
5
+ }
6
+ }
7
+ export { MemoryCostError, };
@@ -0,0 +1,5 @@
1
+ import { BaseError } from '../../error/BaseError.js';
2
+ declare class ParallelismError extends BaseError {
3
+ constructor(parallelism: number);
4
+ }
5
+ export { ParallelismError, };
@@ -0,0 +1,7 @@
1
+ import { BaseError } from '../../error/BaseError.js';
2
+ class ParallelismError extends BaseError {
3
+ constructor(parallelism) {
4
+ super(`invalid parallelism "${parallelism}"`);
5
+ }
6
+ }
7
+ export { ParallelismError, };
@@ -0,0 +1,5 @@
1
+ import { BaseError } from '../../error/BaseError.js';
2
+ declare class TimeCostError extends BaseError {
3
+ constructor(timeCost: number);
4
+ }
5
+ export { TimeCostError, };
@@ -0,0 +1,7 @@
1
+ import { BaseError } from '../../error/BaseError.js';
2
+ class TimeCostError extends BaseError {
3
+ constructor(timeCost) {
4
+ super(`invalid time cost "${timeCost}"`);
5
+ }
6
+ }
7
+ export { TimeCostError, };
@@ -0,0 +1,2 @@
1
+ declare const validateHashLength: (hashLength?: number) => void;
2
+ export { validateHashLength, };
@@ -0,0 +1,7 @@
1
+ import { HashLengthError } from './errors/HashLengthError.js';
2
+ const validateHashLength = (hashLength) => {
3
+ if (hashLength && hashLength < 4) {
4
+ throw new HashLengthError(hashLength);
5
+ }
6
+ };
7
+ export { validateHashLength, };
@@ -0,0 +1,2 @@
1
+ declare const validateMemoryCost: (memoryCost?: number) => void;
2
+ export { validateMemoryCost, };
@@ -0,0 +1,7 @@
1
+ import { MemoryCostError } from './errors/MemoryCostError.js';
2
+ const validateMemoryCost = (memoryCost) => {
3
+ if (memoryCost && memoryCost < 1024) {
4
+ throw new MemoryCostError(memoryCost);
5
+ }
6
+ };
7
+ export { validateMemoryCost, };
@@ -0,0 +1,2 @@
1
+ declare const validateParallelism: (parallelism?: number) => void;
2
+ export { validateParallelism, };
@@ -0,0 +1,7 @@
1
+ import { ParallelismError } from './errors/ParallelismError.js';
2
+ const validateParallelism = (parallelism) => {
3
+ if (parallelism && parallelism < 1) {
4
+ throw new ParallelismError(parallelism);
5
+ }
6
+ };
7
+ export { validateParallelism, };
@@ -0,0 +1,2 @@
1
+ declare const validateTimeCost: (timeCost?: number) => void;
2
+ export { validateTimeCost, };
@@ -0,0 +1,7 @@
1
+ import { TimeCostError } from './errors/TimeCostError.js';
2
+ const validateTimeCost = (timeCost) => {
3
+ if (timeCost && timeCost < 2) {
4
+ throw new TimeCostError(timeCost);
5
+ }
6
+ };
7
+ export { validateTimeCost, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "apeframework",
3
- "version": "0.0.0-dev.26",
3
+ "version": "0.0.0-dev.28",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -30,7 +30,7 @@
30
30
  "@types/nodemailer": "^6.4",
31
31
  "@types/yargs-parser": "^21.0",
32
32
  "ajv": "^8.17",
33
- "bcryptjs": "^3.0",
33
+ "argon2": "^0.41",
34
34
  "bullmq": "^5.49",
35
35
  "dotenv": "^16.5",
36
36
  "fast-uri": "^3.0",
@@ -518,22 +518,64 @@
518
518
  "default": "./dist/parser/parseString.js"
519
519
  }
520
520
  },
521
+ "./pwd/Algorithm": {
522
+ "import": {
523
+ "types": "./dist/pwd/Algorithm.d.ts",
524
+ "default": "./dist/pwd/Algorithm.js"
525
+ }
526
+ },
521
527
  "./pwd/Pwd": {
522
528
  "import": {
523
529
  "types": "./dist/pwd/Pwd.d.ts",
524
530
  "default": "./dist/pwd/Pwd.js"
525
531
  }
526
532
  },
527
- "./pwd/errors/HashRoundsError": {
533
+ "./pwd/errors/HashLengthError": {
534
+ "import": {
535
+ "types": "./dist/pwd/errors/HashLengthError.d.ts",
536
+ "default": "./dist/pwd/errors/HashLengthError.js"
537
+ }
538
+ },
539
+ "./pwd/errors/MemoryCostError": {
540
+ "import": {
541
+ "types": "./dist/pwd/errors/MemoryCostError.d.ts",
542
+ "default": "./dist/pwd/errors/MemoryCostError.js"
543
+ }
544
+ },
545
+ "./pwd/errors/ParallelismError": {
546
+ "import": {
547
+ "types": "./dist/pwd/errors/ParallelismError.d.ts",
548
+ "default": "./dist/pwd/errors/ParallelismError.js"
549
+ }
550
+ },
551
+ "./pwd/errors/TimeCostError": {
552
+ "import": {
553
+ "types": "./dist/pwd/errors/TimeCostError.d.ts",
554
+ "default": "./dist/pwd/errors/TimeCostError.js"
555
+ }
556
+ },
557
+ "./pwd/validateHashLength": {
558
+ "import": {
559
+ "types": "./dist/pwd/validateHashLength.d.ts",
560
+ "default": "./dist/pwd/validateHashLength.js"
561
+ }
562
+ },
563
+ "./pwd/validateMemoryCost": {
564
+ "import": {
565
+ "types": "./dist/pwd/validateMemoryCost.d.ts",
566
+ "default": "./dist/pwd/validateMemoryCost.js"
567
+ }
568
+ },
569
+ "./pwd/validateParallelism": {
528
570
  "import": {
529
- "types": "./dist/pwd/errors/HashRoundsError.d.ts",
530
- "default": "./dist/pwd/errors/HashRoundsError.js"
571
+ "types": "./dist/pwd/validateParallelism.d.ts",
572
+ "default": "./dist/pwd/validateParallelism.js"
531
573
  }
532
574
  },
533
- "./pwd/validateHashRounds": {
575
+ "./pwd/validateTimeCost": {
534
576
  "import": {
535
- "types": "./dist/pwd/validateHashRounds.d.ts",
536
- "default": "./dist/pwd/validateHashRounds.js"
577
+ "types": "./dist/pwd/validateTimeCost.d.ts",
578
+ "default": "./dist/pwd/validateTimeCost.js"
537
579
  }
538
580
  },
539
581
  "./server/ErrorHandler": {
@@ -1,5 +0,0 @@
1
- import { BaseError } from '../../error/BaseError.js';
2
- declare class HashRoundsError extends BaseError {
3
- constructor(hashRounds: number);
4
- }
5
- export { HashRoundsError, };
@@ -1,7 +0,0 @@
1
- import { BaseError } from '../../error/BaseError.js';
2
- class HashRoundsError extends BaseError {
3
- constructor(hashRounds) {
4
- super(`invalid hash rounds "${hashRounds}"`);
5
- }
6
- }
7
- export { HashRoundsError, };
@@ -1,2 +0,0 @@
1
- declare const validateHashRounds: (hashRounds: number) => void;
2
- export { validateHashRounds, };
@@ -1,7 +0,0 @@
1
- import { HashRoundsError } from './errors/HashRoundsError.js';
2
- const validateHashRounds = (hashRounds) => {
3
- if (hashRounds < 1) {
4
- throw new HashRoundsError(hashRounds);
5
- }
6
- };
7
- export { validateHashRounds, };