@venizia/ignis-helpers 0.4.7-3 → 0.4.7-4

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.
@@ -1,11 +1,14 @@
1
+ import { type TCredentialAlgorithm } from '../common/index.js';
1
2
  /**
2
- * Storing and checking a credential (a password) over `Bun.password`, with the stored format of the
3
- * `bcrypt` package: `hash` writes a bcrypt hash (`$2b$`, 60 characters), and `verify` reads every existing
4
- * bcrypt hash, so a stored password is never rehashed or migrated. Needs Bun: it throws on another runtime.
3
+ * Storing and checking a credential (a password) over `Bun.password`. `hash` writes an argon2id hash with
4
+ * Bun's default parameters unless `algorithm: 'bcrypt'` asks for bcrypt (`$2b$`, 60 characters, the stored
5
+ * format of the `bcrypt` package). `verify` reads every existing bcrypt and argon2 hash, whichever
6
+ * algorithm `hash` wrote, so a stored password is never rehashed or migrated. Needs Bun: it throws on
7
+ * another runtime.
5
8
  *
6
- * Passwords longer than 72 bytes are where Bun and the `bcrypt` package differ. The package keeps only the
7
- * first 72 bytes; Bun keeps all of them, by hashing a longer password before bcrypt sees it. Two things
8
- * follow, and they are the whole truth about "the same format":
9
+ * Passwords longer than 72 bytes are where Bun and the `bcrypt` package differ, and it only matters for
10
+ * bcrypt. The package keeps only the first 72 bytes; Bun keeps all of them, by hashing a longer password
11
+ * before bcrypt sees it. Two things follow, and they are the whole truth about "the same format":
9
12
  *
10
13
  * - A hash `hash` writes for a password longer than 72 bytes is read by Bun only. The `bcrypt` package
11
14
  * cannot verify it, so rolling back to that package, or another service reading the same column, locks
@@ -17,9 +20,14 @@
17
20
  * password followed by anything, the way bcrypt itself always has.
18
21
  */
19
22
  export declare class CredentialHelper {
20
- /** A bcrypt hash of `password`; `cost` (4 to 31, default 10) is the work factor, `2 ** cost` rounds. */
23
+ /**
24
+ * A hash of `password`: argon2id by default (Bun's default parameters), bcrypt with `algorithm: 'bcrypt'`.
25
+ * For bcrypt, `cost` (4 to 31, default 10) is the work factor, `2 ** cost` rounds. `cost` with argon2id
26
+ * is refused rather than ignored: a caller who tuned a cost is told the default changed.
27
+ */
21
28
  static hash(opts: {
22
29
  password: string;
30
+ algorithm?: TCredentialAlgorithm;
23
31
  cost?: number;
24
32
  }): Promise<string>;
25
33
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"credential.algorithm.d.ts","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/credential.algorithm.ts"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,gBAAgB;IAC3B,wGAAwG;WAC3F,IAAI,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAoB7E;;;;OAIG;WACU,MAAM,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC;mBA+B1D,UAAU;IAmB/B,OAAO,CAAC,MAAM,CAAC,SAAS;CAQzB"}
1
+ {"version":3,"file":"credential.algorithm.d.ts","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/credential.algorithm.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,WAAW,CAAC;AAWnB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,gBAAgB;IAC3B;;;;OAIG;WACU,IAAI,CAAC,IAAI,EAAE;QACtB,QAAQ,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,oBAAoB,CAAC;QACjC,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,GAAG,OAAO,CAAC,MAAM,CAAC;IAsCnB;;;;OAIG;WACU,MAAM,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC;mBA+B1D,UAAU;IAmB/B,OAAO,CAAC,MAAM,CAAC,SAAS;CAQzB"}
@@ -1,5 +1,6 @@
1
1
  import { HTTP } from '../../../common/constants/index.js';
2
2
  import { getError } from '../../error/index.js';
3
+ import { CredentialAlgorithms, DEFAULT_CREDENTIAL_ALGORITHM, } from '../common/index.js';
3
4
  /** The bcrypt versions the `bcrypt` package writes. */
4
5
  const BCRYPT_PREFIX = /^\$2[aby]\$/;
5
6
  /** bcrypt reads only the first 72 bytes of a password. */
@@ -8,13 +9,15 @@ const MIN_COST = 4;
8
9
  const MAX_COST = 31;
9
10
  const DEFAULT_COST = 10;
10
11
  /**
11
- * Storing and checking a credential (a password) over `Bun.password`, with the stored format of the
12
- * `bcrypt` package: `hash` writes a bcrypt hash (`$2b$`, 60 characters), and `verify` reads every existing
13
- * bcrypt hash, so a stored password is never rehashed or migrated. Needs Bun: it throws on another runtime.
12
+ * Storing and checking a credential (a password) over `Bun.password`. `hash` writes an argon2id hash with
13
+ * Bun's default parameters unless `algorithm: 'bcrypt'` asks for bcrypt (`$2b$`, 60 characters, the stored
14
+ * format of the `bcrypt` package). `verify` reads every existing bcrypt and argon2 hash, whichever
15
+ * algorithm `hash` wrote, so a stored password is never rehashed or migrated. Needs Bun: it throws on
16
+ * another runtime.
14
17
  *
15
- * Passwords longer than 72 bytes are where Bun and the `bcrypt` package differ. The package keeps only the
16
- * first 72 bytes; Bun keeps all of them, by hashing a longer password before bcrypt sees it. Two things
17
- * follow, and they are the whole truth about "the same format":
18
+ * Passwords longer than 72 bytes are where Bun and the `bcrypt` package differ, and it only matters for
19
+ * bcrypt. The package keeps only the first 72 bytes; Bun keeps all of them, by hashing a longer password
20
+ * before bcrypt sees it. Two things follow, and they are the whole truth about "the same format":
18
21
  *
19
22
  * - A hash `hash` writes for a password longer than 72 bytes is read by Bun only. The `bcrypt` package
20
23
  * cannot verify it, so rolling back to that package, or another service reading the same column, locks
@@ -26,21 +29,39 @@ const DEFAULT_COST = 10;
26
29
  * password followed by anything, the way bcrypt itself always has.
27
30
  */
28
31
  export class CredentialHelper {
29
- /** A bcrypt hash of `password`; `cost` (4 to 31, default 10) is the work factor, `2 ** cost` rounds. */
32
+ /**
33
+ * A hash of `password`: argon2id by default (Bun's default parameters), bcrypt with `algorithm: 'bcrypt'`.
34
+ * For bcrypt, `cost` (4 to 31, default 10) is the work factor, `2 ** cost` rounds. `cost` with argon2id
35
+ * is refused rather than ignored: a caller who tuned a cost is told the default changed.
36
+ */
30
37
  static async hash(opts) {
31
- const { password, cost = DEFAULT_COST } = opts;
38
+ const { password, algorithm = DEFAULT_CREDENTIAL_ALGORITHM, cost } = opts;
32
39
  CredentialHelper.assertBun({ caller: 'hash' });
33
40
  if (typeof password !== 'string' || password.length === 0) {
34
41
  throw getError({
35
42
  message: '[CredentialHelper.hash] Invalid password | Expected a non-empty string',
36
43
  });
37
44
  }
38
- if (!Number.isInteger(cost) || cost < MIN_COST || cost > MAX_COST) {
45
+ if (typeof algorithm !== 'string' || !CredentialAlgorithms.isValid(algorithm)) {
46
+ throw getError({
47
+ message: `[CredentialHelper.hash] Invalid algorithm | Expected one of ${[...CredentialAlgorithms.SCHEME_SET].join(', ')} | Got: ${String(algorithm)}`,
48
+ });
49
+ }
50
+ if (algorithm === CredentialAlgorithms.ARGON2ID) {
51
+ if (cost !== undefined && cost !== null) {
52
+ throw getError({
53
+ message: `[CredentialHelper.hash] Invalid cost | cost applies to bcrypt only | Pass algorithm: 'bcrypt' to keep a bcrypt cost, or drop cost for argon2id`,
54
+ });
55
+ }
56
+ return Bun.password.hash(password, { algorithm: 'argon2id' });
57
+ }
58
+ const bcryptCost = cost ?? DEFAULT_COST;
59
+ if (!Number.isInteger(bcryptCost) || bcryptCost < MIN_COST || bcryptCost > MAX_COST) {
39
60
  throw getError({
40
- message: `[CredentialHelper.hash] Invalid cost | Expected an integer from ${MIN_COST} to ${MAX_COST} | Got: ${cost}`,
61
+ message: `[CredentialHelper.hash] Invalid cost | Expected an integer from ${MIN_COST} to ${MAX_COST} | Got: ${bcryptCost}`,
41
62
  });
42
63
  }
43
- return Bun.password.hash(password, { algorithm: 'bcrypt', cost });
64
+ return Bun.password.hash(password, { algorithm: 'bcrypt', cost: bcryptCost });
44
65
  }
45
66
  /**
46
67
  * Whether `password` matches `hash`. Nothing to match is `false`: an empty or non-string password, an empty
@@ -1 +1 @@
1
- {"version":3,"file":"credential.algorithm.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/credential.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAE3C,uDAAuD;AACvD,MAAM,aAAa,GAAG,aAAa,CAAC;AAEpC,0DAA0D;AAC1D,MAAM,yBAAyB,GAAG,EAAE,CAAC;AACrC,MAAM,QAAQ,GAAG,CAAC,CAAC;AACnB,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,YAAY,GAAG,EAAE,CAAC;AAExB;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,gBAAgB;IAC3B,wGAAwG;IACxG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAyC;QACzD,MAAM,EAAE,QAAQ,EAAE,IAAI,GAAG,YAAY,EAAE,GAAG,IAAI,CAAC;QAE/C,gBAAgB,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;QAE/C,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC1D,MAAM,QAAQ,CAAC;gBACb,OAAO,EAAE,wEAAwE;aAClF,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,QAAQ,IAAI,IAAI,GAAG,QAAQ,EAAE,CAAC;YAClE,MAAM,QAAQ,CAAC;gBACb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U,CAAC,IAG/B;QACC,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;QAEhC,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,MAAM,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;YAE1D,OAAO,OAAO,CAAC;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,QAAQ,CAAC;gBACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;gBACrD,OAAO,EAAE,kFAAkF;gBAC3F,KAAK,EAAE,KAAK;aACb,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,SAAS,CAAC,IAAwB;QAC/C,IAAI,OAAO,GAAG,KAAK,WAAW,EAAE,CAAC;YAC/B,MAAM,QAAQ,CAAC;gBACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;gBACrD,OAAO,EAAE,qBAAqB,IAAI,CAAC,MAAM,6DAA6D;aACvG,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF","sourcesContent":["import { HTTP } from '@/common/constants';\nimport { getError } from '@/modules/error';\n\n/** The bcrypt versions the `bcrypt` package writes. */\nconst BCRYPT_PREFIX = /^\\$2[aby]\\$/;\n\n/** bcrypt reads only the first 72 bytes of a password. */\nconst BCRYPT_MAX_PASSWORD_BYTES = 72;\nconst MIN_COST = 4;\nconst MAX_COST = 31;\nconst DEFAULT_COST = 10;\n\n/**\n * Storing and checking a credential (a password) over `Bun.password`, with the stored format of the\n * `bcrypt` package: `hash` writes a bcrypt hash (`$2b$`, 60 characters), and `verify` reads every existing\n * bcrypt hash, so a stored password is never rehashed or migrated. Needs Bun: it throws on another runtime.\n *\n * Passwords longer than 72 bytes are where Bun and the `bcrypt` package differ. The package keeps only the\n * first 72 bytes; Bun keeps all of them, by hashing a longer password before bcrypt sees it. Two things\n * follow, and they are the whole truth about \"the same format\":\n *\n * - A hash `hash` writes for a password longer than 72 bytes is read by Bun only. The `bcrypt` package\n * cannot verify it, so rolling back to that package, or another service reading the same column, locks\n * those users out. Up to 72 bytes the two read each other's hashes.\n * - A hash the `bcrypt` package wrote for a longer password fails a plain `Bun.password.verify` with the full\n * password. `verify` therefore retries a bcrypt hash with the first 72 bytes when the password is longer.\n * That retry is for the legacy hashes. A hash `hash` wrote never needs it, because Bun reads its own hash on\n * the first attempt. The retry has one price: a hash of a password of exactly 72 bytes also accepts that\n * password followed by anything, the way bcrypt itself always has.\n */\nexport class CredentialHelper {\n /** A bcrypt hash of `password`; `cost` (4 to 31, default 10) is the work factor, `2 ** cost` rounds. */\n static async hash(opts: { password: string; cost?: number }): Promise<string> {\n const { password, cost = DEFAULT_COST } = opts;\n\n CredentialHelper.assertBun({ caller: 'hash' });\n\n if (typeof password !== 'string' || password.length === 0) {\n throw getError({\n message: '[CredentialHelper.hash] Invalid password | Expected a non-empty string',\n });\n }\n\n if (!Number.isInteger(cost) || cost < MIN_COST || cost > MAX_COST) {\n throw getError({\n message: `[CredentialHelper.hash] Invalid cost | Expected an integer from ${MIN_COST} to ${MAX_COST} | Got: ${cost}`,\n });\n }\n\n return Bun.password.hash(password, { algorithm: 'bcrypt', cost });\n }\n\n /**\n * Whether `password` matches `hash`. Nothing to match is `false`: an empty or non-string password, an empty\n * or non-string hash. A stored value that is not a password hash is a server fault (500), so a corrupt row is\n * never answered like a wrong password, and the runtime's own message stays out of it.\n */\n static async verify(opts: { password: string; hash: string }): Promise<boolean> {\n const { password, hash } = opts;\n\n CredentialHelper.assertBun({ caller: 'verify' });\n\n if (typeof password !== 'string' || password.length === 0) {\n return false;\n }\n\n if (typeof hash !== 'string' || hash.length === 0) {\n return false;\n }\n\n const matched = await CredentialHelper.verifyHash({ password, hash });\n\n if (matched || !BCRYPT_PREFIX.test(hash)) {\n return matched;\n }\n\n const bytes = Buffer.from(password, 'utf8');\n\n if (bytes.length <= BCRYPT_MAX_PASSWORD_BYTES) {\n return false;\n }\n\n return CredentialHelper.verifyHash({\n password: bytes.subarray(0, BCRYPT_MAX_PASSWORD_BYTES),\n hash,\n });\n }\n\n private static async verifyHash(opts: {\n password: string | Uint8Array;\n hash: string;\n }): Promise<boolean> {\n const { password, hash } = opts;\n\n try {\n const matched = await Bun.password.verify(password, hash);\n\n return matched;\n } catch (error) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[CredentialHelper.verify] Invalid hash | The stored value is not a password hash',\n cause: error,\n });\n }\n }\n\n private static assertBun(opts: { caller: string }): void {\n if (typeof Bun === 'undefined') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[CredentialHelper.${opts.caller}] Unsupported runtime | CredentialHelper needs Bun.password`,\n });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"credential.algorithm.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/algorithms/credential.algorithm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EACL,oBAAoB,EACpB,4BAA4B,GAE7B,MAAM,WAAW,CAAC;AAEnB,uDAAuD;AACvD,MAAM,aAAa,GAAG,aAAa,CAAC;AAEpC,0DAA0D;AAC1D,MAAM,yBAAyB,GAAG,EAAE,CAAC;AACrC,MAAM,QAAQ,GAAG,CAAC,CAAC;AACnB,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,MAAM,YAAY,GAAG,EAAE,CAAC;AAExB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,OAAO,gBAAgB;IAC3B;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAIjB;QACC,MAAM,EAAE,QAAQ,EAAE,SAAS,GAAG,4BAA4B,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;QAE1E,gBAAgB,CAAC,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C;YAE1D,OAAO,OAAO,CAAC;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,QAAQ,CAAC;gBACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;gBACrD,OAAO,EAAE,kFAAkF;gBAC3F,KAAK,EAAE,KAAK;aACb,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,SAAS,CAAC,IAAwB;QAC/C,IAAI,OAAO,GAAG,KAAK,WAAW,EAAE,CAAC;YAC/B,MAAM,QAAQ,CAAC;gBACb,UAAU,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,mBAAmB;gBACrD,OAAO,EAAE,qBAAqB,IAAI,CAAC,MAAM,6DAA6D;aACvG,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF","sourcesContent":["import { HTTP } from '@/common/constants';\nimport { getError } from '@/modules/error';\nimport {\n CredentialAlgorithms,\n DEFAULT_CREDENTIAL_ALGORITHM,\n type TCredentialAlgorithm,\n} from '../common';\n\n/** The bcrypt versions the `bcrypt` package writes. */\nconst BCRYPT_PREFIX = /^\\$2[aby]\\$/;\n\n/** bcrypt reads only the first 72 bytes of a password. */\nconst BCRYPT_MAX_PASSWORD_BYTES = 72;\nconst MIN_COST = 4;\nconst MAX_COST = 31;\nconst DEFAULT_COST = 10;\n\n/**\n * Storing and checking a credential (a password) over `Bun.password`. `hash` writes an argon2id hash with\n * Bun's default parameters unless `algorithm: 'bcrypt'` asks for bcrypt (`$2b$`, 60 characters, the stored\n * format of the `bcrypt` package). `verify` reads every existing bcrypt and argon2 hash, whichever\n * algorithm `hash` wrote, so a stored password is never rehashed or migrated. Needs Bun: it throws on\n * another runtime.\n *\n * Passwords longer than 72 bytes are where Bun and the `bcrypt` package differ, and it only matters for\n * bcrypt. The package keeps only the first 72 bytes; Bun keeps all of them, by hashing a longer password\n * before bcrypt sees it. Two things follow, and they are the whole truth about \"the same format\":\n *\n * - A hash `hash` writes for a password longer than 72 bytes is read by Bun only. The `bcrypt` package\n * cannot verify it, so rolling back to that package, or another service reading the same column, locks\n * those users out. Up to 72 bytes the two read each other's hashes.\n * - A hash the `bcrypt` package wrote for a longer password fails a plain `Bun.password.verify` with the full\n * password. `verify` therefore retries a bcrypt hash with the first 72 bytes when the password is longer.\n * That retry is for the legacy hashes. A hash `hash` wrote never needs it, because Bun reads its own hash on\n * the first attempt. The retry has one price: a hash of a password of exactly 72 bytes also accepts that\n * password followed by anything, the way bcrypt itself always has.\n */\nexport class CredentialHelper {\n /**\n * A hash of `password`: argon2id by default (Bun's default parameters), bcrypt with `algorithm: 'bcrypt'`.\n * For bcrypt, `cost` (4 to 31, default 10) is the work factor, `2 ** cost` rounds. `cost` with argon2id\n * is refused rather than ignored: a caller who tuned a cost is told the default changed.\n */\n static async hash(opts: {\n password: string;\n algorithm?: TCredentialAlgorithm;\n cost?: number;\n }): Promise<string> {\n const { password, algorithm = DEFAULT_CREDENTIAL_ALGORITHM, cost } = opts;\n\n CredentialHelper.assertBun({ caller: 'hash' });\n\n if (typeof password !== 'string' || password.length === 0) {\n throw getError({\n message: '[CredentialHelper.hash] Invalid password | Expected a non-empty string',\n });\n }\n\n if (typeof algorithm !== 'string' || !CredentialAlgorithms.isValid(algorithm)) {\n throw getError({\n message: `[CredentialHelper.hash] Invalid algorithm | Expected one of ${[...CredentialAlgorithms.SCHEME_SET].join(', ')} | Got: ${String(algorithm)}`,\n });\n }\n\n if (algorithm === CredentialAlgorithms.ARGON2ID) {\n if (cost !== undefined && cost !== null) {\n throw getError({\n message: `[CredentialHelper.hash] Invalid cost | cost applies to bcrypt only | Pass algorithm: 'bcrypt' to keep a bcrypt cost, or drop cost for argon2id`,\n });\n }\n\n return Bun.password.hash(password, { algorithm: 'argon2id' });\n }\n\n const bcryptCost = cost ?? DEFAULT_COST;\n\n if (!Number.isInteger(bcryptCost) || bcryptCost < MIN_COST || bcryptCost > MAX_COST) {\n throw getError({\n message: `[CredentialHelper.hash] Invalid cost | Expected an integer from ${MIN_COST} to ${MAX_COST} | Got: ${bcryptCost}`,\n });\n }\n\n return Bun.password.hash(password, { algorithm: 'bcrypt', cost: bcryptCost });\n }\n\n /**\n * Whether `password` matches `hash`. Nothing to match is `false`: an empty or non-string password, an empty\n * or non-string hash. A stored value that is not a password hash is a server fault (500), so a corrupt row is\n * never answered like a wrong password, and the runtime's own message stays out of it.\n */\n static async verify(opts: { password: string; hash: string }): Promise<boolean> {\n const { password, hash } = opts;\n\n CredentialHelper.assertBun({ caller: 'verify' });\n\n if (typeof password !== 'string' || password.length === 0) {\n return false;\n }\n\n if (typeof hash !== 'string' || hash.length === 0) {\n return false;\n }\n\n const matched = await CredentialHelper.verifyHash({ password, hash });\n\n if (matched || !BCRYPT_PREFIX.test(hash)) {\n return matched;\n }\n\n const bytes = Buffer.from(password, 'utf8');\n\n if (bytes.length <= BCRYPT_MAX_PASSWORD_BYTES) {\n return false;\n }\n\n return CredentialHelper.verifyHash({\n password: bytes.subarray(0, BCRYPT_MAX_PASSWORD_BYTES),\n hash,\n });\n }\n\n private static async verifyHash(opts: {\n password: string | Uint8Array;\n hash: string;\n }): Promise<boolean> {\n const { password, hash } = opts;\n\n try {\n const matched = await Bun.password.verify(password, hash);\n\n return matched;\n } catch (error) {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: '[CredentialHelper.verify] Invalid hash | The stored value is not a password hash',\n cause: error,\n });\n }\n }\n\n private static assertBun(opts: { caller: string }): void {\n if (typeof Bun === 'undefined') {\n throw getError({\n statusCode: HTTP.ResultCodes.RS_5.InternalServerError,\n message: `[CredentialHelper.${opts.caller}] Unsupported runtime | CredentialHelper needs Bun.password`,\n });\n }\n }\n}\n"]}
@@ -35,4 +35,13 @@ export declare class HashOutputEncodings {
35
35
  }
36
36
  export type THashOutputEncoding = TConstValue<typeof HashOutputEncodings>;
37
37
  export declare const DEFAULT_HASH_OUTPUT_ENCODING: THashOutputEncoding;
38
+ export declare class CredentialAlgorithms {
39
+ /** What `Bun.password` writes by default, with its default parameters. */
40
+ static readonly ARGON2ID = "argon2id";
41
+ static readonly BCRYPT = "bcrypt";
42
+ static readonly SCHEME_SET: Set<string>;
43
+ static isValid(value: string): value is TCredentialAlgorithm;
44
+ }
45
+ export type TCredentialAlgorithm = TConstValue<typeof CredentialAlgorithms>;
46
+ export declare const DEFAULT_CREDENTIAL_ALGORITHM: TCredentialAlgorithm;
38
47
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../../src/modules/crypto/common/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAE5C,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC,oJAAoJ;AACpJ,eAAO,MAAM,eAAe,QAAoB,CAAC;AAEjD;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,sBAAsB,CAAC;AACpD,eAAO,MAAM,sBAAsB,SAAU,CAAC;AAC9C,eAAO,MAAM,kBAAkB,WAAW,CAAC;AAE3C,gGAAgG;AAChG,eAAO,MAAM,sBAAsB,KAAK,CAAC;AAEzC,qDAAqD;AACrD,eAAO,MAAM,wBAAwB,OAAO,CAAC;AAE7C,qBAAa,cAAc;IACzB,gIAAgI;IAChI,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS;IAE5B,gIAAgI;IAChI,MAAM,CAAC,QAAQ,CAAC,IAAI,UAAU;IAE9B,MAAM,CAAC,QAAQ,CAAC,MAAM,YAAY;IAClC,MAAM,CAAC,QAAQ,CAAC,MAAM,YAAY;IAClC,MAAM,CAAC,QAAQ,CAAC,MAAM,YAAY;IAElC,MAAM,CAAC,QAAQ,CAAC,UAAU,cAMvB;IAEH,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,cAAc;CAGvD;AAED,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,OAAO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O,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,cAAc;CAGvD;AAED,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,OAAO,cAAc,CAAC,CAAC;AAEhE,qBAAa,mBAAmB;IAC9B,MAAM,CAAC,QAAQ,CAAC,GAAG,SAAS;IAC5B,MAAM,CAAC,QAAQ,CAAC,MAAM,YAAY;IAClC,MAAM,CAAC,QAAQ,CAAC,SAAS,eAAe;IAExC,MAAM,CAAC,QAAQ,CAAC,UAAU,cAA4D;IAEtF,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,mBAAmB;CAG5D;AAED,MAAM,MAAM,mBAAmB,GAAG,WAAW,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAE1E,eAAO,MAAM,4BAA4B,EAAE,mBAA6C,CAAC;AAEzF,qBAAa,oBAAoB;IAC/B,0EAA0E;IAC1E,MAAM,CAAC,QAAQ,CAAC,QAAQ,cAAc;IACtC,MAAM,CAAC,QAAQ,CAAC,MAAM,YAAY;IAElC,MAAM,CAAC,QAAQ,CAAC,UAAU,cAAiD;IAE3E,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,oBAAoB;CAG7D;AAED,MAAM,MAAM,oBAAoB,GAAG,WAAW,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAE5E,eAAO,MAAM,4BAA4B,EAAE,oBAAoD,CAAC"}
@@ -42,4 +42,14 @@ export class HashOutputEncodings {
42
42
  }
43
43
  }
44
44
  export const DEFAULT_HASH_OUTPUT_ENCODING = HashOutputEncodings.HEX;
45
+ export class CredentialAlgorithms {
46
+ /** What `Bun.password` writes by default, with its default parameters. */
47
+ static { this.ARGON2ID = 'argon2id'; }
48
+ static { this.BCRYPT = 'bcrypt'; }
49
+ static { this.SCHEME_SET = new Set([this.ARGON2ID, this.BCRYPT]); }
50
+ static isValid(value) {
51
+ return this.SCHEME_SET.has(value);
52
+ }
53
+ }
54
+ export const DEFAULT_CREDENTIAL_ALGORITHM = CredentialAlgorithms.ARGON2ID;
45
55
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/common/constants.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEvC,oJAAoJ;AACpJ,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;AAEjD;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,mBAAmB,CAAC;AACpD,MAAM,CAAC,MAAM,sBAAsB,GAAG,OAAO,CAAC;AAC9C,MAAM,CAAC,MAAM,kBAAkB,GAAG,QAAQ,CAAC;AAE3C,gGAAgG;AAChG,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAEzC,qDAAqD;AACrD,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,CAAC;AAE7C,MAAM,OAAO,cAAc;IACzB,gIAAgI;aAChH,QAAG,GAAG,KAAK,CAAC;IAE5B,gIAAgI;aAChH,SAAI,GAAG,MAAM,CAAC;aAEd,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;aAElB,eAAU,GAAG,IAAI,GAAG,CAAS;QAC3C,IAAI,CAAC,GAAG;QACR,IAAI,CAAC,IAAI;QACT,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,MAAM;KACZ,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAKH,MAAM,OAAO,mBAAmB;aACd,QAAG,GAAG,KAAK,CAAC;aACZ,WAAM,GAAG,QAAQ,CAAC;aAClB,cAAS,GAAG,WAAW,CAAC;aAExB,eAAU,GAAG,IAAI,GAAG,CAAS,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAEtF,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAKH,MAAM,CAAC,MAAM,4BAA4B,GAAwB,mBAAmB,CAAC,GAAG,CAAC","sourcesContent":["import type { TConstValue } from '@/common';\n\nexport const DEFAULT_CIPHER_BITS = 256;\n\n/** Legacy padEnd key-stretching char, no longer used - keys now derive via PBKDF2 (`DEFAULT_KDF_*`). Kept only so existing imports do not break. */\nexport const DEFAULT_PAD_END = (0x00).toString();\n\n/**\n * Public and identical across every deployment, so it stops a bare dictionary attack but not a\n * table precomputed against this value - pass `kdfSalt` for per-deployment isolation. Never\n * change this: every ciphertext already encrypted under it becomes undecryptable.\n */\nexport const DEFAULT_KDF_SALT = 'ignis-kdf-salt-v1';\nexport const DEFAULT_KDF_ITERATIONS = 100_000;\nexport const DEFAULT_KDF_DIGEST = 'sha256';\n\n/** NIST SP 800-132 minimum recommended salt size (128 bits) for a caller-supplied `kdfSalt`. */\nexport const MINIMUM_KDF_SALT_BYTES = 16;\n\n/** NIST SP 800-57 Part 1 floor for RSA past 2030. */\nexport const MINIMUM_RSA_MODULUS_BITS = 2048;\n\nexport class HashAlgorithms {\n /** Cryptographically broken - kept only for wire-protocol compatibility (VNPay checksums); never use for security decisions. */\n static readonly MD5 = 'md5';\n\n /** Cryptographically weak - kept for wire-protocol compatibility with legacy integrations; never use for security decisions. */\n static readonly SHA1 = 'sha1';\n\n static readonly SHA256 = 'sha256';\n static readonly SHA384 = 'sha384';\n static readonly SHA512 = 'sha512';\n\n static readonly SCHEME_SET = new Set<string>([\n this.MD5,\n this.SHA1,\n this.SHA256,\n this.SHA384,\n this.SHA512,\n ]);\n\n static isValid(value: string): value is THashAlgorithm {\n return this.SCHEME_SET.has(value);\n }\n}\n\nexport type THashAlgorithm = TConstValue<typeof HashAlgorithms>;\n\nexport class HashOutputEncodings {\n static readonly HEX = 'hex';\n static readonly BASE64 = 'base64';\n static readonly BASE64URL = 'base64url';\n\n static readonly SCHEME_SET = new Set<string>([this.HEX, this.BASE64, this.BASE64URL]);\n\n static isValid(value: string): value is THashOutputEncoding {\n return this.SCHEME_SET.has(value);\n }\n}\n\nexport type THashOutputEncoding = TConstValue<typeof HashOutputEncodings>;\n\nexport const DEFAULT_HASH_OUTPUT_ENCODING: THashOutputEncoding = HashOutputEncodings.HEX;\n"]}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/modules/crypto/common/constants.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEvC,oJAAoJ;AACpJ,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;AAEjD;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,mBAAmB,CAAC;AACpD,MAAM,CAAC,MAAM,sBAAsB,GAAG,OAAO,CAAC;AAC9C,MAAM,CAAC,MAAM,kBAAkB,GAAG,QAAQ,CAAC;AAE3C,gGAAgG;AAChG,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,CAAC;AAEzC,qDAAqD;AACrD,MAAM,CAAC,MAAM,wBAAwB,GAAG,IAAI,CAAC;AAE7C,MAAM,OAAO,cAAc;IACzB,gIAAgI;aAChH,QAAG,GAAG,KAAK,CAAC;IAE5B,gIAAgI;aAChH,SAAI,GAAG,MAAM,CAAC;aAEd,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;aAClB,WAAM,GAAG,QAAQ,CAAC;aAElB,eAAU,GAAG,IAAI,GAAG,CAAS;QAC3C,IAAI,CAAC,GAAG;QACR,IAAI,CAAC,IAAI;QACT,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,MAAM;QACX,IAAI,CAAC,MAAM;KACZ,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAKH,MAAM,OAAO,mBAAmB;aACd,QAAG,GAAG,KAAK,CAAC;aACZ,WAAM,GAAG,QAAQ,CAAC;aAClB,cAAS,GAAG,WAAW,CAAC;aAExB,eAAU,GAAG,IAAI,GAAG,CAAS,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;IAEtF,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAKH,MAAM,CAAC,MAAM,4BAA4B,GAAwB,mBAAmB,CAAC,GAAG,CAAC;AAEzF,MAAM,OAAO,oBAAoB;IAC/B,0EAA0E;aAC1D,aAAQ,GAAG,UAAU,CAAC;aACtB,WAAM,GAAG,QAAQ,CAAC;aAElB,eAAU,GAAG,IAAI,GAAG,CAAS,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IAE3E,MAAM,CAAC,OAAO,CAAC,KAAa;QAC1B,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;;AAKH,MAAM,CAAC,MAAM,4BAA4B,GAAyB,oBAAoB,CAAC,QAAQ,CAAC","sourcesContent":["import type { TConstValue } from '@/common';\n\nexport const DEFAULT_CIPHER_BITS = 256;\n\n/** Legacy padEnd key-stretching char, no longer used - keys now derive via PBKDF2 (`DEFAULT_KDF_*`). Kept only so existing imports do not break. */\nexport const DEFAULT_PAD_END = (0x00).toString();\n\n/**\n * Public and identical across every deployment, so it stops a bare dictionary attack but not a\n * table precomputed against this value - pass `kdfSalt` for per-deployment isolation. Never\n * change this: every ciphertext already encrypted under it becomes undecryptable.\n */\nexport const DEFAULT_KDF_SALT = 'ignis-kdf-salt-v1';\nexport const DEFAULT_KDF_ITERATIONS = 100_000;\nexport const DEFAULT_KDF_DIGEST = 'sha256';\n\n/** NIST SP 800-132 minimum recommended salt size (128 bits) for a caller-supplied `kdfSalt`. */\nexport const MINIMUM_KDF_SALT_BYTES = 16;\n\n/** NIST SP 800-57 Part 1 floor for RSA past 2030. */\nexport const MINIMUM_RSA_MODULUS_BITS = 2048;\n\nexport class HashAlgorithms {\n /** Cryptographically broken - kept only for wire-protocol compatibility (VNPay checksums); never use for security decisions. */\n static readonly MD5 = 'md5';\n\n /** Cryptographically weak - kept for wire-protocol compatibility with legacy integrations; never use for security decisions. */\n static readonly SHA1 = 'sha1';\n\n static readonly SHA256 = 'sha256';\n static readonly SHA384 = 'sha384';\n static readonly SHA512 = 'sha512';\n\n static readonly SCHEME_SET = new Set<string>([\n this.MD5,\n this.SHA1,\n this.SHA256,\n this.SHA384,\n this.SHA512,\n ]);\n\n static isValid(value: string): value is THashAlgorithm {\n return this.SCHEME_SET.has(value);\n }\n}\n\nexport type THashAlgorithm = TConstValue<typeof HashAlgorithms>;\n\nexport class HashOutputEncodings {\n static readonly HEX = 'hex';\n static readonly BASE64 = 'base64';\n static readonly BASE64URL = 'base64url';\n\n static readonly SCHEME_SET = new Set<string>([this.HEX, this.BASE64, this.BASE64URL]);\n\n static isValid(value: string): value is THashOutputEncoding {\n return this.SCHEME_SET.has(value);\n }\n}\n\nexport type THashOutputEncoding = TConstValue<typeof HashOutputEncodings>;\n\nexport const DEFAULT_HASH_OUTPUT_ENCODING: THashOutputEncoding = HashOutputEncodings.HEX;\n\nexport class CredentialAlgorithms {\n /** What `Bun.password` writes by default, with its default parameters. */\n static readonly ARGON2ID = 'argon2id';\n static readonly BCRYPT = 'bcrypt';\n\n static readonly SCHEME_SET = new Set<string>([this.ARGON2ID, this.BCRYPT]);\n\n static isValid(value: string): value is TCredentialAlgorithm {\n return this.SCHEME_SET.has(value);\n }\n}\n\nexport type TCredentialAlgorithm = TConstValue<typeof CredentialAlgorithms>;\n\nexport const DEFAULT_CREDENTIAL_ALGORITHM: TCredentialAlgorithm = CredentialAlgorithms.ARGON2ID;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@venizia/ignis-helpers",
3
- "version": "0.4.7-3",
3
+ "version": "0.4.7-4",
4
4
  "description": "Production-ready TypeScript utility library: pluggable logging (winston or pino behind one ILogger contract), Redis single/cluster/sentinel with pub/sub, BullMQ/MQTT/Kafka message queues, MinIO/Disk/Bun-S3 object storage, AES-256/RSA/ECDH cryptography, Snowflake UID generation, cron scheduling, Socket.IO/WebSocket, TCP/TLS/UDP networking, HTTP clients, secrets/Vault, worker thread pools, and environment management. Sub-path imports isolate optional peer dependencies so the root barrel never forces a peer into your bundle.",
5
5
  "keywords": [
6
6
  "aes",
@@ -188,7 +188,7 @@
188
188
  "@socket.io/redis-emitter": "^5.1.0",
189
189
  "@types/bun": "^1.4.3",
190
190
  "@types/luxon": "^3.7.6",
191
- "@venizia/dev-configs": "0.4.7-3",
191
+ "@venizia/dev-configs": "0.4.7-4",
192
192
  "axios": "^1.20.0",
193
193
  "bullmq": "^6.4.0",
194
194
  "cron": "^4.4.0",