cas-typescript-sdk 1.0.14 → 1.0.16

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 (95) hide show
  1. package/.github/workflows/main-pr-linux.yml +28 -0
  2. package/.github/workflows/main-pr-windows.yml +28 -0
  3. package/.github/workflows/main-publish.yml +32 -0
  4. package/Cargo.toml +8 -1
  5. package/README.md +3 -1
  6. package/build.rs +5 -5
  7. package/docs/EXAMPLES.md +39 -0
  8. package/index.d.ts +19 -0
  9. package/index.node +0 -0
  10. package/lib/digital-signature/digital-siganture-sha-512.d.ts +6 -0
  11. package/lib/digital-signature/digital-siganture-sha-512.js +28 -0
  12. package/lib/digital-signature/digital-signature-base.d.ts +5 -0
  13. package/lib/digital-signature/digital-signature-factory.d.ts +8 -0
  14. package/lib/digital-signature/digital-signature-factory.js +22 -0
  15. package/lib/digital-signature/digital-signaturte-sha-256.d.ts +6 -0
  16. package/lib/digital-signature/digital-signaturte-sha-256.js +28 -0
  17. package/lib/digital-signature/index.d.ts +4 -0
  18. package/lib/digital-signature/index.js +8 -0
  19. package/lib/hybrid/hybrid-encryption-wrapper.d.ts +9 -0
  20. package/lib/hybrid/hybrid-encryption-wrapper.js +30 -0
  21. package/lib/hybrid/index.d.ts +4 -0
  22. package/lib/hybrid/index.js +9 -0
  23. package/lib/hybrid/types/aes-rsa-hybird-encrypt-result.d.ts +7 -0
  24. package/lib/hybrid/types/aes-rsa-hybird-encrypt-result.js +16 -0
  25. package/lib/hybrid/types/aes-rsa-hybrid-initializer.d.ts +8 -0
  26. package/lib/hybrid/types/aes-rsa-hybrid-initializer.js +25 -0
  27. package/lib/index.d.ts +3 -2
  28. package/lib/index.js +8 -4
  29. package/package.json +41 -39
  30. package/src/asymmetric/cas_asymmetric_encryption.rs +15 -15
  31. package/src/asymmetric/cas_rsa.rs +88 -80
  32. package/src/digital_signature/cas_digital_signature_rsa.rs +27 -0
  33. package/src/digital_signature/sha_256_rsa.rs +96 -0
  34. package/src/digital_signature/sha_512_ed25519.rs +75 -0
  35. package/src/digital_signature/sha_512_rsa.rs +93 -0
  36. package/src/hashers/blake2.rs +37 -39
  37. package/src/hashers/cas_hasher.rs +8 -8
  38. package/src/hashers/sha.rs +102 -103
  39. package/src/key_exchange/cas_key_exchange.rs +6 -6
  40. package/src/key_exchange/x25519.rs +57 -57
  41. package/src/lib.rs +34 -27
  42. package/src/password_hashers/argon2.rs +65 -64
  43. package/src/password_hashers/bcrypt.rs +50 -51
  44. package/src/password_hashers/cas_password_hasher.rs +4 -4
  45. package/src/password_hashers/scrypt.rs +61 -56
  46. package/src/symmetric/aes.rs +155 -151
  47. package/src/symmetric/cas_symmetric_encryption.rs +14 -14
  48. package/src-ts/asymmetric/RSAWrapper.ts +53 -53
  49. package/src-ts/asymmetric/index.ts +3 -3
  50. package/src-ts/digital-signature/digital-siganture-sha-512.ts +28 -0
  51. package/src-ts/digital-signature/digital-signature-base.ts +6 -0
  52. package/src-ts/digital-signature/digital-signature-factory.ts +19 -0
  53. package/src-ts/digital-signature/digital-signaturte-sha-256.ts +28 -0
  54. package/src-ts/digital-signature/index.ts +4 -0
  55. package/src-ts/global.d.ts +1 -1
  56. package/src-ts/hashers/hasher-base.ts +5 -5
  57. package/src-ts/hashers/hasher-factory.ts +11 -11
  58. package/src-ts/hashers/hasher-type.ts +2 -2
  59. package/src-ts/hashers/index.ts +5 -5
  60. package/src-ts/hashers/sha-wrapper.ts +37 -37
  61. package/src-ts/helpers/nonce-generator.ts +8 -8
  62. package/src-ts/hybrid/hybrid-encryption-wrapper.ts +64 -0
  63. package/src-ts/hybrid/index.ts +9 -0
  64. package/src-ts/hybrid/types/aes-rsa-hybird-encrypt-result.ts +13 -0
  65. package/src-ts/hybrid/types/aes-rsa-hybrid-initializer.ts +24 -0
  66. package/src-ts/index.ts +34 -26
  67. package/src-ts/key_exchange/index.ts +3 -3
  68. package/src-ts/key_exchange/x25519.ts +10 -10
  69. package/src-ts/password-hashers/argon2-wrapper.ts +18 -18
  70. package/src-ts/password-hashers/bcrypt-wrapper.ts +23 -23
  71. package/src-ts/password-hashers/index.ts +14 -14
  72. package/src-ts/password-hashers/password-hasher-base.ts +3 -3
  73. package/src-ts/password-hashers/password-hasher-factory.ts +20 -20
  74. package/src-ts/password-hashers/password-hasher-type.ts +4 -4
  75. package/src-ts/password-hashers/scrypt-wrapper.ts +19 -19
  76. package/src-ts/symmetric/aes-wrapper.ts +50 -50
  77. package/src-ts/symmetric/index.ts +3 -3
  78. package/test-ts/asymmetric.test.spec.ts +27 -27
  79. package/test-ts/digital-signature.test.spec.ts +49 -0
  80. package/test-ts/hasher.test.spec.ts +70 -70
  81. package/test-ts/helpers/array.ts +9 -9
  82. package/test-ts/hybrid.test.spec.ts +33 -0
  83. package/test-ts/insecure-channel.test.spec.ts +50 -50
  84. package/test-ts/key-exchange-test.spec.ts +23 -23
  85. package/test-ts/password-hasher-test.spec.ts +102 -102
  86. package/test-ts/symmetric.test.spec.ts +31 -31
  87. package/tsconfig.json +21 -21
  88. package/lib/cas_core_lib.dll +0 -0
  89. package/lib/hashers/IHasherBase.d.ts +0 -6
  90. package/lib/hashers/SHAWrapper.d.ts +0 -7
  91. package/lib/hashers/SHAWrapper.js +0 -37
  92. package/lib/libcas_core_lib.so +0 -0
  93. package/lib/password-hashers/types/argon2-hash-thread-result.d.ts +0 -3
  94. package/lib/password-hashers/types/argon2-hash-thread-result.js +0 -11
  95. /package/lib/{hashers/IHasherBase.js → digital-signature/digital-signature-base.js} +0 -0
@@ -0,0 +1,4 @@
1
+ export enum DigitalSignatureType {
2
+ SHA512 = 1,
3
+ SHA256 = 2
4
+ }
@@ -1,2 +1,2 @@
1
- declare var pathToWindowsDll: string;
1
+ declare var pathToWindowsDll: string;
2
2
  declare var pathToLinuxSO: string;
@@ -1,6 +1,6 @@
1
- export interface IHasherBase {
2
- hash_512(dataToHash: number[]): number[];
3
- verify_512(dataToHash: number[], dataToVerify: number[]): boolean;
4
- hash_256(dataToHash: number[]): number[];
5
- verify_256(dataToHash: number[], dataToVerify: number[]): boolean;
1
+ export interface IHasherBase {
2
+ hash_512(dataToHash: number[]): number[];
3
+ verify_512(dataToHash: number[], dataToVerify: number[]): boolean;
4
+ hash_256(dataToHash: number[]): number[];
5
+ verify_256(dataToHash: number[], dataToVerify: number[]): boolean;
6
6
  }
@@ -1,12 +1,12 @@
1
- import { HasherType } from "./hasher-type";
2
- import { SHAWrapper } from "./sha-wrapper";
3
-
4
- export class HasherFactory {
5
- getHasher(type: HasherType): any {
6
- let result: SHAWrapper = new SHAWrapper();
7
- switch(type) {
8
-
9
- }
10
- return result;
11
- }
1
+ import { HasherType } from "./hasher-type";
2
+ import { SHAWrapper } from "./sha-wrapper";
3
+
4
+ export class HasherFactory {
5
+ getHasher(type: HasherType): any {
6
+ let result: SHAWrapper = new SHAWrapper();
7
+ switch(type) {
8
+
9
+ }
10
+ return result;
11
+ }
12
12
  }
@@ -1,3 +1,3 @@
1
- export enum HasherType {
2
- SHA = 1
1
+ export enum HasherType {
2
+ SHA = 1
3
3
  }
@@ -1,5 +1,5 @@
1
- import { HasherFactory } from "./hasher-factory";
2
- import { HasherType } from "./hasher-type";
3
- import { SHAWrapper } from "./sha-wrapper";
4
-
5
- export { SHAWrapper, HasherFactory, HasherType };
1
+ import { HasherFactory } from "./hasher-factory";
2
+ import { HasherType } from "./hasher-type";
3
+ import { SHAWrapper } from "./sha-wrapper";
4
+
5
+ export { SHAWrapper, HasherFactory, HasherType };
@@ -1,38 +1,38 @@
1
- import { sha256, sha256Verify, sha512, sha512Verify } from "../../index";
2
- import { IHasherBase } from "./hasher-base";
3
-
4
- export class SHAWrapper implements IHasherBase {
5
- hash_512(dataToHash: number[]): number[] {
6
- if (!dataToHash || dataToHash.length === 0) {
7
- throw new Error("You must provide an allocated array of data");
8
- }
9
- return sha512(dataToHash);
10
- }
11
-
12
- verify_512(dataToHash: number[], dataToVerify: number[]): boolean {
13
- if (!dataToHash || dataToHash.length === 0) {
14
- throw new Error("You must provide an allocated array of data");
15
- }
16
- if (!dataToVerify || dataToVerify.length === 0) {
17
- throw new Error("You must provide an allocated array of data to verify");
18
- }
19
- return sha512Verify(dataToHash, dataToVerify);
20
- }
21
-
22
- hash_256(dataToHash: number[]): number[] {
23
- if (!dataToHash || dataToHash.length === 0) {
24
- throw new Error("You must provide an allocated array of data");
25
- }
26
- return sha256(dataToHash);
27
- }
28
-
29
- verify_256(dataToHash: number[], dataToVerify: number[]): boolean {
30
- if (!dataToHash || dataToHash.length === 0) {
31
- throw new Error("You must provide an allocated array of data");
32
- }
33
- if (!dataToVerify || dataToVerify.length === 0) {
34
- throw new Error("You must provide an allocated array of data to verify");
35
- }
36
- return sha256Verify(dataToHash, dataToVerify);
37
- }
1
+ import { sha256, sha256Verify, sha512, sha512Verify } from "../../index";
2
+ import { IHasherBase } from "./hasher-base";
3
+
4
+ export class SHAWrapper implements IHasherBase {
5
+ hash_512(dataToHash: number[]): number[] {
6
+ if (!dataToHash || dataToHash.length === 0) {
7
+ throw new Error("You must provide an allocated array of data");
8
+ }
9
+ return sha512(dataToHash);
10
+ }
11
+
12
+ verify_512(dataToHash: number[], dataToVerify: number[]): boolean {
13
+ if (!dataToHash || dataToHash.length === 0) {
14
+ throw new Error("You must provide an allocated array of data");
15
+ }
16
+ if (!dataToVerify || dataToVerify.length === 0) {
17
+ throw new Error("You must provide an allocated array of data to verify");
18
+ }
19
+ return sha512Verify(dataToHash, dataToVerify);
20
+ }
21
+
22
+ hash_256(dataToHash: number[]): number[] {
23
+ if (!dataToHash || dataToHash.length === 0) {
24
+ throw new Error("You must provide an allocated array of data");
25
+ }
26
+ return sha256(dataToHash);
27
+ }
28
+
29
+ verify_256(dataToHash: number[], dataToVerify: number[]): boolean {
30
+ if (!dataToHash || dataToHash.length === 0) {
31
+ throw new Error("You must provide an allocated array of data");
32
+ }
33
+ if (!dataToVerify || dataToVerify.length === 0) {
34
+ throw new Error("You must provide an allocated array of data to verify");
35
+ }
36
+ return sha256Verify(dataToHash, dataToVerify);
37
+ }
38
38
  }
@@ -1,9 +1,9 @@
1
- import * as crypto from "crypto";
2
-
3
- export class NonceGenerator {
4
-
5
- public generateNonce(): string {
6
- const nonceBytes = crypto.randomBytes(12);
7
- return nonceBytes.toString('hex').substring(0, 12);
8
- }
1
+ import * as crypto from "crypto";
2
+
3
+ export class NonceGenerator {
4
+
5
+ public generateNonce(): string {
6
+ const nonceBytes = crypto.randomBytes(12);
7
+ return nonceBytes.toString('hex').substring(0, 12);
8
+ }
9
9
  }
@@ -0,0 +1,64 @@
1
+ import { RSAWrapper } from "../asymmetric";
2
+ import { AESWrapper } from "../symmetric";
3
+ import { AesRsaHybridEncryptResult } from "./types/aes-rsa-hybird-encrypt-result";
4
+ import { AESRSAHybridInitializer } from "./types/aes-rsa-hybrid-initializer";
5
+
6
+ export class HybridEncryptionWrapper {
7
+ private aesWrapper: AESWrapper;
8
+ private rsaWrapper: RSAWrapper;
9
+
10
+ constructor() {
11
+ this.aesWrapper = new AESWrapper();
12
+ this.rsaWrapper = new RSAWrapper();
13
+ }
14
+
15
+ public encrypt(
16
+ dataToEncrypt: Array<number>,
17
+ initalizer: AESRSAHybridInitializer,
18
+ ): AesRsaHybridEncryptResult {
19
+ let encryptedData: Array<number> = (initalizer.aesType === 128)
20
+ ? this.aesWrapper.aes128Encrypt(
21
+ initalizer.aesKey,
22
+ initalizer.aesNonce,
23
+ dataToEncrypt,
24
+ )
25
+ : this.aesWrapper.aes256Encrypt(
26
+ initalizer.aesKey,
27
+ initalizer.aesNonce,
28
+ dataToEncrypt,
29
+ );
30
+ let encryptedAesKey: Array<number> = this.rsaWrapper.encrypt(
31
+ initalizer.rsaKeyPair.publicKey,
32
+ initalizer.aesKey,
33
+ );
34
+ let result: AesRsaHybridEncryptResult = new AesRsaHybridEncryptResult(
35
+ encryptedData,
36
+ encryptedAesKey,
37
+ initalizer.aesType,
38
+ initalizer.aesNonce,
39
+ );
40
+ return result;
41
+ }
42
+
43
+ public decrypt(
44
+ privateKey: string,
45
+ encryptResult: AesRsaHybridEncryptResult,
46
+ ): Array<number> {
47
+ let plaintextAesKey = this.rsaWrapper.decrypt(
48
+ privateKey,
49
+ encryptResult.encryptedAesKey,
50
+ );
51
+ let plaintext = (encryptResult.aesType === 128)
52
+ ? this.aesWrapper.aes128Decrypt(
53
+ plaintextAesKey,
54
+ encryptResult.aesNonce,
55
+ encryptResult.ciphertext,
56
+ )
57
+ : this.aesWrapper.aes256Decrypt(
58
+ plaintextAesKey,
59
+ encryptResult.aesNonce,
60
+ encryptResult.ciphertext,
61
+ );
62
+ return plaintext;
63
+ }
64
+ }
@@ -0,0 +1,9 @@
1
+ import { HybridEncryptionWrapper } from "./hybrid-encryption-wrapper";
2
+ import { AesRsaHybridEncryptResult } from "./types/aes-rsa-hybird-encrypt-result";
3
+ import { AESRSAHybridInitializer } from "./types/aes-rsa-hybrid-initializer";
4
+
5
+ export {
6
+ AesRsaHybridEncryptResult,
7
+ AESRSAHybridInitializer,
8
+ HybridEncryptionWrapper,
9
+ };
@@ -0,0 +1,13 @@
1
+ export class AesRsaHybridEncryptResult {
2
+ ciphertext: Array<number>;
3
+ encryptedAesKey: Array<number>;
4
+ aesType: number;
5
+ aesNonce: Array<number>;
6
+
7
+ constructor(cipherText: Array<number>, encryptAesKey: Array<number>, aesType: number, aesNonce: Array<number>) {
8
+ this.ciphertext = cipherText;
9
+ this.encryptedAesKey = encryptAesKey;
10
+ this.aesType = aesType;
11
+ this.aesNonce = aesNonce;
12
+ }
13
+ }
@@ -0,0 +1,24 @@
1
+ import { RsaKeyPairResult } from "../../..";
2
+ import { RSAWrapper } from "../../asymmetric";
3
+ import { AESWrapper } from "../../symmetric";
4
+
5
+ export class AESRSAHybridInitializer {
6
+ public aesType: number;
7
+ public aesKey: Array<number>;
8
+ public aesNonce: Array<number>;
9
+ public rsaKeyPair: RsaKeyPairResult;
10
+
11
+ constructor(aesType: number, rsaSize: number) {
12
+ if (aesType !== 128 && aesType !== 256) {
13
+ throw new Error("Need an appropriate AES size to generate a hybrid initalizer");
14
+ }
15
+ this.aesType = aesType;
16
+ let aesWrapper = new AESWrapper();
17
+ this.aesKey = (aesType === 128) ? aesWrapper.aes128Key() : aesWrapper.aes256Key();
18
+ this.aesNonce = aesWrapper.aesNonce();
19
+ if (rsaSize !== 1028 && rsaSize !== 2048 && rsaSize !== 4096) {
20
+ throw new Error("You must provide an appropriate RSA Key pair size to generate a hybrid initalizer");
21
+ }
22
+ this.rsaKeyPair = new RSAWrapper().generateKeys(rsaSize);
23
+ }
24
+ }
package/src-ts/index.ts CHANGED
@@ -1,26 +1,34 @@
1
- import {
2
- Argon2Wrapper,
3
- BCryptWrapper,
4
- PasswordHasherFactory,
5
- PasswordHasherType,
6
- ScryptWrapper,
7
- } from "./password-hashers/index";
8
- import { HasherFactory, HasherType, SHAWrapper } from "./hashers/index";
9
- import { X25519Wrapper } from "./key_exchange/index";
10
- import { AESWrapper } from "./symmetric/index";
11
- import { RSAWrapper, RsaKeyPairResult } from "./asymmetric";
12
-
13
- export {
14
- Argon2Wrapper,
15
- BCryptWrapper,
16
- HasherFactory,
17
- HasherType,
18
- PasswordHasherFactory,
19
- PasswordHasherType,
20
- ScryptWrapper,
21
- SHAWrapper,
22
- X25519Wrapper,
23
- AESWrapper,
24
- RSAWrapper,
25
- RsaKeyPairResult
26
- };
1
+ import {
2
+ Argon2Wrapper,
3
+ BCryptWrapper,
4
+ PasswordHasherFactory,
5
+ PasswordHasherType,
6
+ ScryptWrapper,
7
+ } from "./password-hashers/index";
8
+ import { HasherFactory, HasherType, SHAWrapper } from "./hashers/index";
9
+ import { X25519Wrapper } from "./key_exchange/index";
10
+ import { AESWrapper } from "./symmetric/index";
11
+ import { RsaKeyPairResult, RSAWrapper } from "./asymmetric/index";
12
+ import {
13
+ AesRsaHybridEncryptResult,
14
+ AESRSAHybridInitializer,
15
+ HybridEncryptionWrapper,
16
+ } from "./hybrid/index";
17
+
18
+ export {
19
+ AesRsaHybridEncryptResult,
20
+ AESRSAHybridInitializer,
21
+ AESWrapper,
22
+ Argon2Wrapper,
23
+ BCryptWrapper,
24
+ HasherFactory,
25
+ HasherType,
26
+ HybridEncryptionWrapper,
27
+ PasswordHasherFactory,
28
+ PasswordHasherType,
29
+ RsaKeyPairResult,
30
+ RSAWrapper,
31
+ ScryptWrapper,
32
+ SHAWrapper,
33
+ X25519Wrapper,
34
+ };
@@ -1,3 +1,3 @@
1
- import { X25519Wrapper } from "./x25519";
2
-
3
- export { X25519Wrapper };
1
+ import { X25519Wrapper } from "./x25519";
2
+
3
+ export { X25519Wrapper };
@@ -1,11 +1,11 @@
1
- import { x25519DiffieHellman, x25519GenerateSecretAndPublicKey, X25519SecretPublicKeyResult } from "../../index"
2
-
3
- export class X25519Wrapper {
4
- public generateSecretAndPublicKey(): X25519SecretPublicKeyResult {
5
- return x25519GenerateSecretAndPublicKey();
6
- }
7
-
8
- public diffieHellman(secretKey: Array<number>, publicKey: Array<number>) {
9
- return x25519DiffieHellman(secretKey, publicKey);
10
- }
1
+ import { x25519DiffieHellman, x25519GenerateSecretAndPublicKey, X25519SecretPublicKeyResult } from "../../index"
2
+
3
+ export class X25519Wrapper {
4
+ public generateSecretAndPublicKey(): X25519SecretPublicKeyResult {
5
+ return x25519GenerateSecretAndPublicKey();
6
+ }
7
+
8
+ public diffieHellman(secretKey: Array<number>, publicKey: Array<number>) {
9
+ return x25519DiffieHellman(secretKey, publicKey);
10
+ }
11
11
  }
@@ -1,18 +1,18 @@
1
- import {argon2Hash, argon2Verify} from "./../../index";
2
- import { IPasswordHasherBase} from "./password-hasher-base";
3
-
4
- export class Argon2Wrapper implements IPasswordHasherBase {
5
- public hashPassword(password: string): string {
6
- if (!password){
7
- throw new Error("You must provide a password to hash with Argon2");
8
- }
9
- return argon2Hash(password);
10
- }
11
-
12
- public verifyPassword(hashedPassword: string, passwordToVerify: string): boolean {
13
- if (!hashedPassword || !passwordToVerify) {
14
- throw new Error("You must provide a hashed password and a plaintext password to verify with Argon2");
15
- }
16
- return argon2Verify(hashedPassword, passwordToVerify);
17
- }
18
- }
1
+ import {argon2Hash, argon2Verify} from "./../../index";
2
+ import { IPasswordHasherBase} from "./password-hasher-base";
3
+
4
+ export class Argon2Wrapper implements IPasswordHasherBase {
5
+ public hashPassword(password: string): string {
6
+ if (!password){
7
+ throw new Error("You must provide a password to hash with Argon2");
8
+ }
9
+ return argon2Hash(password);
10
+ }
11
+
12
+ public verifyPassword(hashedPassword: string, passwordToVerify: string): boolean {
13
+ if (!hashedPassword || !passwordToVerify) {
14
+ throw new Error("You must provide a hashed password and a plaintext password to verify with Argon2");
15
+ }
16
+ return argon2Verify(hashedPassword, passwordToVerify);
17
+ }
18
+ }
@@ -1,23 +1,23 @@
1
- import { IPasswordHasherBase } from "./password-hasher-base";
2
- import { bcryptHash, bcryptVerify } from "./../../index";
3
-
4
- export class BCryptWrapper implements IPasswordHasherBase {
5
- public hashPassword(password: string): string {
6
- if (!password) {
7
- throw new Error("You must provide a password to hash with Argon2");
8
- }
9
- return bcryptHash(password);
10
- }
11
-
12
- public verifyPassword(
13
- hashedPassword: string,
14
- passwordToVerify: string,
15
- ): boolean {
16
- if (!hashedPassword || !passwordToVerify) {
17
- throw new Error(
18
- "You must provide a hashed password and a plaintext password to verify with Argon2",
19
- );
20
- }
21
- return bcryptVerify(hashedPassword, passwordToVerify);
22
- }
23
- }
1
+ import { IPasswordHasherBase } from "./password-hasher-base";
2
+ import { bcryptHash, bcryptVerify } from "./../../index";
3
+
4
+ export class BCryptWrapper implements IPasswordHasherBase {
5
+ public hashPassword(password: string): string {
6
+ if (!password) {
7
+ throw new Error("You must provide a password to hash with Argon2");
8
+ }
9
+ return bcryptHash(password);
10
+ }
11
+
12
+ public verifyPassword(
13
+ hashedPassword: string,
14
+ passwordToVerify: string,
15
+ ): boolean {
16
+ if (!hashedPassword || !passwordToVerify) {
17
+ throw new Error(
18
+ "You must provide a hashed password and a plaintext password to verify with Argon2",
19
+ );
20
+ }
21
+ return bcryptVerify(hashedPassword, passwordToVerify);
22
+ }
23
+ }
@@ -1,14 +1,14 @@
1
- import { Argon2Wrapper } from "./argon2-wrapper";
2
- import { BCryptWrapper } from "./bcrypt-wrapper";
3
- import { ScryptWrapper } from "./scrypt-wrapper";
4
-
5
- import { PasswordHasherType } from "./password-hasher-type";
6
- import { PasswordHasherFactory } from "./password-hasher-factory";
7
-
8
- export {
9
- Argon2Wrapper,
10
- BCryptWrapper,
11
- PasswordHasherFactory,
12
- PasswordHasherType,
13
- ScryptWrapper,
14
- };
1
+ import { Argon2Wrapper } from "./argon2-wrapper";
2
+ import { BCryptWrapper } from "./bcrypt-wrapper";
3
+ import { ScryptWrapper } from "./scrypt-wrapper";
4
+
5
+ import { PasswordHasherType } from "./password-hasher-type";
6
+ import { PasswordHasherFactory } from "./password-hasher-factory";
7
+
8
+ export {
9
+ Argon2Wrapper,
10
+ BCryptWrapper,
11
+ PasswordHasherFactory,
12
+ PasswordHasherType,
13
+ ScryptWrapper,
14
+ };
@@ -1,4 +1,4 @@
1
- export interface IPasswordHasherBase {
2
- hashPassword(password: string): string;
3
- verifyPassword(hashedPassword: string, passwordToVerify: string): boolean;
1
+ export interface IPasswordHasherBase {
2
+ hashPassword(password: string): string;
3
+ verifyPassword(hashedPassword: string, passwordToVerify: string): boolean;
4
4
  }
@@ -1,20 +1,20 @@
1
- import { Argon2Wrapper } from "./argon2-wrapper";
2
- import { BCryptWrapper } from "./bcrypt-wrapper";
3
- import { PasswordHasherType } from "./password-hasher-type";
4
- import { ScryptWrapper } from "./scrypt-wrapper";
5
-
6
- export class PasswordHasherFactory {
7
- static getHasher(type: PasswordHasherType): any {
8
- // Argon2 by default
9
- let hasher = new Argon2Wrapper();
10
- switch (type) {
11
- case PasswordHasherType.Bcrypt:
12
- hasher = new BCryptWrapper();
13
- break;
14
- case PasswordHasherType.Scrypt:
15
- hasher = new ScryptWrapper();
16
- break;
17
- }
18
- return hasher;
19
- }
20
- }
1
+ import { Argon2Wrapper } from "./argon2-wrapper";
2
+ import { BCryptWrapper } from "./bcrypt-wrapper";
3
+ import { PasswordHasherType } from "./password-hasher-type";
4
+ import { ScryptWrapper } from "./scrypt-wrapper";
5
+
6
+ export class PasswordHasherFactory {
7
+ static getHasher(type: PasswordHasherType): any {
8
+ // Argon2 by default
9
+ let hasher = new Argon2Wrapper();
10
+ switch (type) {
11
+ case PasswordHasherType.Bcrypt:
12
+ hasher = new BCryptWrapper();
13
+ break;
14
+ case PasswordHasherType.Scrypt:
15
+ hasher = new ScryptWrapper();
16
+ break;
17
+ }
18
+ return hasher;
19
+ }
20
+ }
@@ -1,5 +1,5 @@
1
- export enum PasswordHasherType {
2
- Bcrypt = 1,
3
- Scrypt = 2,
4
- Argon2 = 3
1
+ export enum PasswordHasherType {
2
+ Bcrypt = 1,
3
+ Scrypt = 2,
4
+ Argon2 = 3
5
5
  }
@@ -1,20 +1,20 @@
1
- import { scryptHash, scryptVerify } from "../../index";
2
- import { IPasswordHasherBase } from "./password-hasher-base";
3
-
4
- export class ScryptWrapper implements IPasswordHasherBase {
5
-
6
- public hashPassword(password: string): string {
7
- if (!password){
8
- throw new Error("You must provide a password to hash with Scrypt");
9
- }
10
- return scryptHash(password);
11
- }
12
-
13
- public verifyPassword(hashedPassword: string, passwordToVerify: string): boolean {
14
- if (!hashedPassword || !passwordToVerify) {
15
- throw new Error("You must provide a hashed password and a plaintext password to verify with Scrypt");
16
- }
17
- return scryptVerify(hashedPassword, passwordToVerify);
18
- }
19
-
1
+ import { scryptHash, scryptVerify } from "../../index";
2
+ import { IPasswordHasherBase } from "./password-hasher-base";
3
+
4
+ export class ScryptWrapper implements IPasswordHasherBase {
5
+
6
+ public hashPassword(password: string): string {
7
+ if (!password){
8
+ throw new Error("You must provide a password to hash with Scrypt");
9
+ }
10
+ return scryptHash(password);
11
+ }
12
+
13
+ public verifyPassword(hashedPassword: string, passwordToVerify: string): boolean {
14
+ if (!hashedPassword || !passwordToVerify) {
15
+ throw new Error("You must provide a hashed password and a plaintext password to verify with Scrypt");
16
+ }
17
+ return scryptVerify(hashedPassword, passwordToVerify);
18
+ }
19
+
20
20
  }