@twin.org/crypto 0.0.3-next.9 → 0.0.4-next.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 (57) hide show
  1. package/README.md +1 -11
  2. package/dist/es/hashes/argon2id.js +38 -0
  3. package/dist/es/hashes/argon2id.js.map +1 -0
  4. package/dist/es/hashes/pbkdf2.js +9 -1
  5. package/dist/es/hashes/pbkdf2.js.map +1 -1
  6. package/dist/es/helpers/integrityHelper.js +67 -0
  7. package/dist/es/helpers/integrityHelper.js.map +1 -0
  8. package/dist/es/index.js +3 -0
  9. package/dist/es/index.js.map +1 -1
  10. package/dist/es/models/integrityAlgorithm.js +21 -0
  11. package/dist/es/models/integrityAlgorithm.js.map +1 -0
  12. package/dist/es/passwords/passwordGenerator.js +70 -12
  13. package/dist/es/passwords/passwordGenerator.js.map +1 -1
  14. package/dist/es/passwords/passwordValidator.js +68 -4
  15. package/dist/es/passwords/passwordValidator.js.map +1 -1
  16. package/dist/types/hashes/argon2id.d.ts +28 -0
  17. package/dist/types/hashes/pbkdf2.d.ts +2 -0
  18. package/dist/types/helpers/integrityHelper.d.ts +26 -0
  19. package/dist/types/index.d.ts +3 -0
  20. package/dist/types/models/integrityAlgorithm.d.ts +21 -0
  21. package/dist/types/passwords/passwordGenerator.d.ts +13 -2
  22. package/dist/types/passwords/passwordValidator.d.ts +34 -2
  23. package/docs/changelog.md +926 -115
  24. package/docs/examples.md +130 -1
  25. package/docs/reference/classes/Argon2id.md +83 -0
  26. package/docs/reference/classes/Bech32.md +4 -4
  27. package/docs/reference/classes/Bip32Path.md +6 -6
  28. package/docs/reference/classes/Bip39.md +16 -16
  29. package/docs/reference/classes/Bip44.md +6 -6
  30. package/docs/reference/classes/Blake2b.md +9 -9
  31. package/docs/reference/classes/Blake3.md +7 -7
  32. package/docs/reference/classes/ChaCha20Poly1305.md +3 -3
  33. package/docs/reference/classes/Ed25519.md +8 -8
  34. package/docs/reference/classes/HmacSha1.md +4 -4
  35. package/docs/reference/classes/HmacSha256.md +9 -9
  36. package/docs/reference/classes/HmacSha512.md +13 -13
  37. package/docs/reference/classes/Hotp.md +2 -2
  38. package/docs/reference/classes/IntegrityHelper.md +85 -0
  39. package/docs/reference/classes/PasswordGenerator.md +41 -5
  40. package/docs/reference/classes/PasswordValidator.md +116 -3
  41. package/docs/reference/classes/Pbkdf2.md +11 -3
  42. package/docs/reference/classes/PemHelper.md +5 -5
  43. package/docs/reference/classes/Secp256k1.md +6 -6
  44. package/docs/reference/classes/Sha1.md +4 -4
  45. package/docs/reference/classes/Sha256.md +9 -9
  46. package/docs/reference/classes/Sha3.md +13 -13
  47. package/docs/reference/classes/Sha512.md +13 -13
  48. package/docs/reference/classes/Slip0010.md +11 -11
  49. package/docs/reference/classes/Totp.md +12 -12
  50. package/docs/reference/classes/X25519.md +3 -3
  51. package/docs/reference/classes/Zip215.md +2 -2
  52. package/docs/reference/index.md +4 -0
  53. package/docs/reference/type-aliases/IntegrityAlgorithm.md +5 -0
  54. package/docs/reference/variables/IntegrityAlgorithm.md +25 -0
  55. package/docs/reference/variables/KeyType.md +2 -2
  56. package/locales/en.json +3 -0
  57. package/package.json +13 -14
@@ -0,0 +1,21 @@
1
+ /**
2
+ * The names of the integrity algorithms.
3
+ */
4
+ export declare const IntegrityAlgorithm: {
5
+ /**
6
+ * Sha256.
7
+ */
8
+ readonly Sha256: "sha256";
9
+ /**
10
+ * Sha384.
11
+ */
12
+ readonly Sha384: "sha384";
13
+ /**
14
+ * Sha512.
15
+ */
16
+ readonly Sha512: "sha512";
17
+ };
18
+ /**
19
+ * Integrity algorithms.
20
+ */
21
+ export type IntegrityAlgorithm = (typeof IntegrityAlgorithm)[keyof typeof IntegrityAlgorithm];
@@ -2,10 +2,21 @@
2
2
  * Generate random passwords.
3
3
  */
4
4
  export declare class PasswordGenerator {
5
+ /**
6
+ * Runtime name for the class.
7
+ */
8
+ static readonly CLASS_NAME: string;
5
9
  /**
6
10
  * Generate a password of given length.
7
- * @param length The length of the password to generate.
11
+ * @param length The length of the password to generate, default to 15.
8
12
  * @returns The random password.
9
13
  */
10
- static generate(length: number): string;
14
+ static generate(length?: number): string;
15
+ /**
16
+ * Hash the password for the user.
17
+ * @param passwordBytes The password bytes.
18
+ * @param saltBytes The salt bytes.
19
+ * @returns The hashed password.
20
+ */
21
+ static hashPassword(passwordBytes: Uint8Array, saltBytes: Uint8Array): Promise<string>;
11
22
  }
@@ -1,16 +1,20 @@
1
1
  import { type IValidationFailure } from "@twin.org/core";
2
2
  /**
3
3
  * Test password strength.
4
- * Ref https://www.owasp.org/index.php/Authentication_Cheat_Sheet#Implement_Proper_Password_Strength_Controls .
4
+ * @see https://www.owasp.org/index.php/Authentication_Cheat_Sheet#Implement_Proper_Password_Strength_Controls .
5
5
  */
6
6
  export declare class PasswordValidator {
7
+ /**
8
+ * Runtime name for the class.
9
+ */
10
+ static readonly CLASS_NAME: string;
7
11
  /**
8
12
  * Test the strength of the password.
9
13
  * @param property The name of the property.
10
14
  * @param password The password to test.
11
15
  * @param failures The list of failures to add to.
12
16
  * @param options Options to configure the testing.
13
- * @param options.minLength The minimum length of the password, defaults to 8.
17
+ * @param options.minLength The minimum length of the password, defaults to 15, can be 8 if MFA is enabled.
14
18
  * @param options.maxLength The minimum length of the password, defaults to 128.
15
19
  * @param options.minPhraseLength The minimum length of the password for it to be considered a pass phrase.
16
20
  */
@@ -19,4 +23,32 @@ export declare class PasswordValidator {
19
23
  maxLength?: number;
20
24
  minPhraseLength?: number;
21
25
  }): void;
26
+ /**
27
+ * Validate the password against security policy.
28
+ * @param password The password to validate.
29
+ * @param options Options to configure the testing.
30
+ * @param options.minLength The minimum length of the password, defaults to 15.
31
+ * @param options.maxLength The minimum length of the password, defaults to 128.
32
+ * @param options.minPhraseLength The minimum length of the password for it to be considered a pass phrase.
33
+ * @throws Error if the password does not meet the requirements.
34
+ */
35
+ static validatePassword(password: string, options?: {
36
+ minLength?: number;
37
+ maxLength?: number;
38
+ minPhraseLength?: number;
39
+ }): void;
40
+ /**
41
+ * Compare two password byte arrays in constant time to prevent timing attacks.
42
+ * @param hashedPasswordBytes The computed password bytes to compare.
43
+ * @param storedPasswordBytes The stored password bytes to compare against.
44
+ * @returns True if the bytes match, false otherwise.
45
+ */
46
+ static comparePasswordBytes(hashedPasswordBytes: Uint8Array, storedPasswordBytes: Uint8Array): boolean;
47
+ /**
48
+ * Compare two hashed passwords in constant time to prevent timing attacks.
49
+ * @param hashedPassword The computed hash to compare.
50
+ * @param storedPassword The stored hash to compare against.
51
+ * @returns True if the hashes match, false otherwise.
52
+ */
53
+ static comparePasswordHashes(hashedPassword: string, storedPassword: string): boolean;
22
54
  }