cas-typescript-sdk 1.0.22 → 1.0.23

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 (50) hide show
  1. package/README.md +7 -5
  2. package/lib/asymmetric/RSAWrapper.d.ts +31 -1
  3. package/lib/asymmetric/RSAWrapper.js +33 -3
  4. package/lib/digital-signature/digital-siganture-sha-512.d.ts +25 -0
  5. package/lib/digital-signature/digital-siganture-sha-512.js +25 -0
  6. package/lib/digital-signature/digital-signature-factory.d.ts +5 -0
  7. package/lib/digital-signature/digital-signature-factory.js +5 -0
  8. package/lib/digital-signature/digital-signaturte-sha-256.d.ts +25 -0
  9. package/lib/digital-signature/digital-signaturte-sha-256.js +25 -0
  10. package/lib/hashers/hasher-factory.d.ts +5 -0
  11. package/lib/hashers/hasher-factory.js +5 -0
  12. package/lib/hashers/sha-wrapper.d.ts +22 -0
  13. package/lib/hashers/sha-wrapper.js +22 -0
  14. package/lib/hybrid/hybrid-encryption-wrapper.d.ts +12 -0
  15. package/lib/hybrid/hybrid-encryption-wrapper.js +12 -0
  16. package/lib/hybrid/types/aes-rsa-hybrid-initializer.d.ts +5 -0
  17. package/lib/hybrid/types/aes-rsa-hybrid-initializer.js +5 -0
  18. package/lib/key_exchange/x25519.d.ts +13 -1
  19. package/lib/key_exchange/x25519.js +12 -0
  20. package/lib/password-hashers/argon2-wrapper.d.ts +22 -0
  21. package/lib/password-hashers/argon2-wrapper.js +22 -0
  22. package/lib/password-hashers/bcrypt-wrapper.d.ts +22 -0
  23. package/lib/password-hashers/bcrypt-wrapper.js +22 -0
  24. package/lib/password-hashers/password-hasher-factory.d.ts +5 -0
  25. package/lib/password-hashers/password-hasher-factory.js +5 -0
  26. package/lib/password-hashers/scrypt-wrapper.d.ts +22 -0
  27. package/lib/password-hashers/scrypt-wrapper.js +22 -0
  28. package/lib/sponges/ascon-wrapper.d.ts +22 -0
  29. package/lib/sponges/ascon-wrapper.js +22 -0
  30. package/lib/symmetric/aes-wrapper.d.ts +42 -12
  31. package/lib/symmetric/aes-wrapper.js +42 -12
  32. package/package.json +1 -1
  33. package/src-ts/asymmetric/RSAWrapper.ts +36 -3
  34. package/src-ts/digital-signature/digital-siganture-sha-512.ts +26 -1
  35. package/src-ts/digital-signature/digital-signature-factory.ts +6 -0
  36. package/src-ts/digital-signature/digital-signaturte-sha-256.ts +25 -0
  37. package/src-ts/hashers/hasher-factory.ts +5 -0
  38. package/src-ts/hashers/sha-wrapper.ts +22 -0
  39. package/src-ts/hybrid/hybrid-encryption-wrapper.ts +12 -0
  40. package/src-ts/hybrid/types/aes-rsa-hybrid-initializer.ts +5 -0
  41. package/src-ts/key_exchange/x25519.ts +13 -1
  42. package/src-ts/password-hashers/argon2-wrapper.ts +22 -0
  43. package/src-ts/password-hashers/bcrypt-wrapper.ts +22 -0
  44. package/src-ts/password-hashers/password-hasher-factory.ts +5 -0
  45. package/src-ts/password-hashers/scrypt-wrapper.ts +22 -0
  46. package/src-ts/sponges/ascon-wrapper.ts +22 -0
  47. package/src-ts/symmetric/aes-wrapper.ts +43 -12
  48. package/lib/helpers/nonce-generator.d.ts +0 -3
  49. package/lib/helpers/nonce-generator.js +0 -34
  50. package/src-ts/helpers/nonce-generator.ts +0 -9
package/README.md CHANGED
@@ -2,23 +2,25 @@
2
2
 
3
3
  [![image](https://img.shields.io/badge/Discord-5865F2?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/7bXXCQj45q)
4
4
 
5
- Ever wanted all of your most useful cryptographic operations in one module and not have to surf documentation for various packages?
5
+ Ever wanted all of your most useful cryptographic operations in one module and not had to surf documentation for various packages?
6
6
  CAS is here to provide a unified development experience as an abstract layer to the RustCrypto and Dalek-Cryptography suite of algorithms.
7
7
  The official NPM page can be found [here](https://www.npmjs.com/package/cas-typescript-sdk).
8
8
 
9
- ## [Examples](./docs/EXAMPLES.md)
10
-
11
- ## Consuming Library Documentation
12
9
  **Note: All work is experimental and we understand some benchmarks might not be the most optimal.**
13
10
 
14
- This Node.js NPM module is dependent on our Rust layer [here](./src) that contains methods to run industry standard cryptographic operations sequentially, on threads, and the thread pool.
11
+
12
+
15
13
 
16
14
  ## Consuming Library Documentation
15
+ This Node.js NPM module is dependent on our Rust layer [here](./src) that contains methods to run industry-standard cryptographic operations sequentially, on threads, and the thread pool.
16
+
17
17
  We utilize some smart people's existing work and we believe their documentation should be reviewed when possible.
18
18
  - [Spin Research](https://github.com/SpinResearch)
19
19
  - [Dalek-Cryptography](https://github.com/dalek-cryptography)
20
20
  - [Rust Crypto](https://github.com/RustCrypto)
21
21
  - [Rayon](https://github.com/rayon-rs/rayon)
22
22
 
23
+ ## [Examples](./docs/EXAMPLES.md)
24
+
23
25
  ## Disclaimer
24
26
  Many of the cryptographic crates that are utilized in our core FFI [layer](./src) have never had a security audit performed. Utilize this SDK at your own risk.
@@ -1,8 +1,38 @@
1
1
  import { RsaKeyPairResult } from "../../index";
2
2
  export declare class RSAWrapper {
3
+ /**
4
+ * Generates an RSA key pair based of parameter sent in 1024, 2048, and 4096 are supported.
5
+ * @param keySize
6
+ * @returns RsaKeyPairResult
7
+ */
3
8
  generateKeys(keySize: number): RsaKeyPairResult;
9
+ /**
10
+ * Encrypts a plaintext byte array with a RSA public key
11
+ * @param publicKey
12
+ * @param plaintext
13
+ * @returns Array<number>
14
+ */
4
15
  encrypt(publicKey: string, plaintext: Array<number>): Array<number>;
16
+ /**
17
+ * Decrypts a ciphertext with an RSA private key.
18
+ * @param privateKey
19
+ * @param ciphertext
20
+ * @returns Array<number>
21
+ */
5
22
  decrypt(privateKey: string, ciphertext: Array<number>): Array<number>;
6
- sign(privateKey: string, hash: Array<number>): Array<number>;
23
+ /**
24
+ * Signs a byte array with an RSA private key for verification.
25
+ * @param privateKey
26
+ * @param hash
27
+ * @returns Array<number>
28
+ */
29
+ sign(privateKey: string, dataToSign: Array<number>): Array<number>;
30
+ /**
31
+ * Verifies signed data by the corresponding private key with an RSA public key.
32
+ * @param publicKey
33
+ * @param hash
34
+ * @param signature
35
+ * @returns boolean
36
+ */
7
37
  verify(publicKey: string, hash: Array<number>, signature: Array<number>): boolean;
8
38
  }
@@ -3,12 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RSAWrapper = void 0;
4
4
  const index_1 = require("../../index");
5
5
  class RSAWrapper {
6
+ /**
7
+ * Generates an RSA key pair based of parameter sent in 1024, 2048, and 4096 are supported.
8
+ * @param keySize
9
+ * @returns RsaKeyPairResult
10
+ */
6
11
  generateKeys(keySize) {
7
12
  if (keySize !== 1024 && keySize !== 2048 && keySize !== 4096) {
8
13
  throw new Error("You must provide an appropriate key size to generate RSA keys");
9
14
  }
10
15
  return (0, index_1.generateRsaKeys)(keySize);
11
16
  }
17
+ /**
18
+ * Encrypts a plaintext byte array with a RSA public key
19
+ * @param publicKey
20
+ * @param plaintext
21
+ * @returns Array<number>
22
+ */
12
23
  encrypt(publicKey, plaintext) {
13
24
  if (!publicKey) {
14
25
  throw new Error("You must provide a public key to encrypt with RSA");
@@ -18,6 +29,12 @@ class RSAWrapper {
18
29
  }
19
30
  return (0, index_1.encryptPlaintextRsa)(publicKey, plaintext);
20
31
  }
32
+ /**
33
+ * Decrypts a ciphertext with an RSA private key.
34
+ * @param privateKey
35
+ * @param ciphertext
36
+ * @returns Array<number>
37
+ */
21
38
  decrypt(privateKey, ciphertext) {
22
39
  if (!privateKey) {
23
40
  throw new Error("You must provide a private key to encrypt with RSA");
@@ -27,15 +44,28 @@ class RSAWrapper {
27
44
  }
28
45
  return (0, index_1.decryptCiphertextRsa)(privateKey, ciphertext);
29
46
  }
30
- sign(privateKey, hash) {
47
+ /**
48
+ * Signs a byte array with an RSA private key for verification.
49
+ * @param privateKey
50
+ * @param hash
51
+ * @returns Array<number>
52
+ */
53
+ sign(privateKey, dataToSign) {
31
54
  if (!privateKey) {
32
55
  throw new Error("You must provide a private key to sign with RSA");
33
56
  }
34
- if (!hash || hash.length === 0) {
57
+ if (!dataToSign || dataToSign.length === 0) {
35
58
  throw new Error("You must provide an allocated hash to sign with RSA");
36
59
  }
37
- return (0, index_1.signRsa)(privateKey, hash);
60
+ return (0, index_1.signRsa)(privateKey, dataToSign);
38
61
  }
62
+ /**
63
+ * Verifies signed data by the corresponding private key with an RSA public key.
64
+ * @param publicKey
65
+ * @param hash
66
+ * @param signature
67
+ * @returns boolean
68
+ */
39
69
  verify(publicKey, hash, signature) {
40
70
  if (!publicKey) {
41
71
  throw new Error("You must provide a public key to verify with RSA");
@@ -1,8 +1,33 @@
1
1
  import { RsaDigitalSignatureResult, SHAED25519DalekDigitalSignatureResult } from "../../index";
2
2
  import { IDigitalSignature } from "./digital-signature-base";
3
3
  export declare class DigitalSignatureSHA512Wrapper implements IDigitalSignature {
4
+ /**
5
+ * Creates an ED25519 siganture from an array of bytes with SHA3-512.
6
+ * @param dataToSign
7
+ * @returns SHAED25519DalekDigitalSignatureResult
8
+ */
4
9
  createED25519(dataToSign: number[]): SHAED25519DalekDigitalSignatureResult;
10
+ /**
11
+ * Verifies an ED25519 signature with the public key generated from running createED25519() with SHA3-512
12
+ * @param publicKey
13
+ * @param dataToVerify
14
+ * @param signature
15
+ * @returns boolean
16
+ */
5
17
  verifyED25519(publicKey: number[], dataToVerify: number[], signature: number[]): boolean;
18
+ /**
19
+ * Generates and RSA digital signature with SHA3-512
20
+ * @param rsa_key_size
21
+ * @param data_to_sign
22
+ * @returns RsaDigitalSignatureResult
23
+ */
6
24
  createRsa(rsa_key_size: number, data_to_sign: number[]): RsaDigitalSignatureResult;
25
+ /**
26
+ * Verifies a digital signature created with the RSA public key.
27
+ * @param public_key
28
+ * @param data_to_verify
29
+ * @param signature
30
+ * @returns boolean
31
+ */
7
32
  verifyRSa(public_key: string, data_to_verify: number[], signature: number[]): boolean;
8
33
  }
@@ -3,12 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DigitalSignatureSHA512Wrapper = void 0;
4
4
  const index_1 = require("../../index");
5
5
  class DigitalSignatureSHA512Wrapper {
6
+ /**
7
+ * Creates an ED25519 siganture from an array of bytes with SHA3-512.
8
+ * @param dataToSign
9
+ * @returns SHAED25519DalekDigitalSignatureResult
10
+ */
6
11
  createED25519(dataToSign) {
7
12
  if (dataToSign?.length === 0) {
8
13
  throw new Error("Must provide allocated data to sign");
9
14
  }
10
15
  return (0, index_1.sha512Ed25519DigitalSignature)(dataToSign);
11
16
  }
17
+ /**
18
+ * Verifies an ED25519 signature with the public key generated from running createED25519() with SHA3-512
19
+ * @param publicKey
20
+ * @param dataToVerify
21
+ * @param signature
22
+ * @returns boolean
23
+ */
12
24
  verifyED25519(publicKey, dataToVerify, signature) {
13
25
  if (!publicKey) {
14
26
  throw new Error("You must provide a public key for verify with ED25519");
@@ -21,6 +33,12 @@ class DigitalSignatureSHA512Wrapper {
21
33
  }
22
34
  return (0, index_1.sha512Ed25519DigitalSignatureVerify)(publicKey, dataToVerify, signature);
23
35
  }
36
+ /**
37
+ * Generates and RSA digital signature with SHA3-512
38
+ * @param rsa_key_size
39
+ * @param data_to_sign
40
+ * @returns RsaDigitalSignatureResult
41
+ */
24
42
  createRsa(rsa_key_size, data_to_sign) {
25
43
  if (rsa_key_size !== 1024 && rsa_key_size !== 2048 && rsa_key_size !== 4096) {
26
44
  throw new Error("You need to provide an appropriate RSA key size.");
@@ -30,6 +48,13 @@ class DigitalSignatureSHA512Wrapper {
30
48
  }
31
49
  return (0, index_1.sha512RsaDigitalSignature)(rsa_key_size, data_to_sign);
32
50
  }
51
+ /**
52
+ * Verifies a digital signature created with the RSA public key.
53
+ * @param public_key
54
+ * @param data_to_verify
55
+ * @param signature
56
+ * @returns boolean
57
+ */
33
58
  verifyRSa(public_key, data_to_verify, signature) {
34
59
  if (!public_key) {
35
60
  throw new Error("Must provide a public key");
@@ -4,5 +4,10 @@ export declare enum DigitalSignatureType {
4
4
  SHA256 = 2
5
5
  }
6
6
  export declare class DigitalSignatureFactory {
7
+ /**
8
+ * Get the appropriate digital signature wrapper based upon the type passed in.
9
+ * @param type
10
+ * @returns
11
+ */
7
12
  static get(type: DigitalSignatureType): DigitalSignatureSHA512Wrapper;
8
13
  }
@@ -9,6 +9,11 @@ var DigitalSignatureType;
9
9
  DigitalSignatureType[DigitalSignatureType["SHA256"] = 2] = "SHA256";
10
10
  })(DigitalSignatureType || (exports.DigitalSignatureType = DigitalSignatureType = {}));
11
11
  class DigitalSignatureFactory {
12
+ /**
13
+ * Get the appropriate digital signature wrapper based upon the type passed in.
14
+ * @param type
15
+ * @returns
16
+ */
12
17
  static get(type) {
13
18
  let ds = new digital_siganture_sha_512_1.DigitalSignatureSHA512Wrapper();
14
19
  switch (type) {
@@ -1,8 +1,33 @@
1
1
  import { RsaDigitalSignatureResult, Shaed25519DalekDigitalSignatureResult } from "../../index";
2
2
  import { IDigitalSignature } from "./digital-signature-base";
3
3
  export declare class DigitalSignatureSHA256Wrapper implements IDigitalSignature {
4
+ /**
5
+ * Creates an ED25519 siganture from an array of bytes with SHA3-512.
6
+ * @param dataToSign
7
+ * @returns SHAED25519DalekDigitalSignatureResult
8
+ */
4
9
  createED25519(dataToSign: number[]): Shaed25519DalekDigitalSignatureResult;
10
+ /**
11
+ * Verifies an ED25519 signature with the public key generated from running createED25519() with SHA3-512
12
+ * @param publicKey
13
+ * @param dataToVerify
14
+ * @param signature
15
+ * @returns boolean
16
+ */
5
17
  verifyED25519(publicKey: number[], dataToVerify: number[], signature: number[]): boolean;
18
+ /**
19
+ * Generates and RSA digital signature with SHA3-512
20
+ * @param rsa_key_size
21
+ * @param data_to_sign
22
+ * @returns RsaDigitalSignatureResult
23
+ */
6
24
  createRsa(rsa_key_size: number, data_to_sign: number[]): RsaDigitalSignatureResult;
25
+ /**
26
+ * Verifies a digital signature created with the RSA public key.
27
+ * @param public_key
28
+ * @param data_to_verify
29
+ * @param signature
30
+ * @returns boolean
31
+ */
7
32
  verifyRSa(public_key: string, data_to_verify: number[], signature: number[]): boolean;
8
33
  }
@@ -3,12 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DigitalSignatureSHA256Wrapper = void 0;
4
4
  const index_1 = require("../../index");
5
5
  class DigitalSignatureSHA256Wrapper {
6
+ /**
7
+ * Creates an ED25519 siganture from an array of bytes with SHA3-512.
8
+ * @param dataToSign
9
+ * @returns SHAED25519DalekDigitalSignatureResult
10
+ */
6
11
  createED25519(dataToSign) {
7
12
  if (dataToSign?.length === 0) {
8
13
  throw new Error("Must provide allocated data to sign");
9
14
  }
10
15
  return (0, index_1.sha256Ed25519DigitalSignature)(dataToSign);
11
16
  }
17
+ /**
18
+ * Verifies an ED25519 signature with the public key generated from running createED25519() with SHA3-512
19
+ * @param publicKey
20
+ * @param dataToVerify
21
+ * @param signature
22
+ * @returns boolean
23
+ */
12
24
  verifyED25519(publicKey, dataToVerify, signature) {
13
25
  if (!publicKey) {
14
26
  throw new Error("You must provide a public key for verify with ED25519");
@@ -21,6 +33,12 @@ class DigitalSignatureSHA256Wrapper {
21
33
  }
22
34
  return (0, index_1.sha256Ed25519DigitalSignatureVerify)(publicKey, dataToVerify, signature);
23
35
  }
36
+ /**
37
+ * Generates and RSA digital signature with SHA3-512
38
+ * @param rsa_key_size
39
+ * @param data_to_sign
40
+ * @returns RsaDigitalSignatureResult
41
+ */
24
42
  createRsa(rsa_key_size, data_to_sign) {
25
43
  if (rsa_key_size !== 1024 && rsa_key_size !== 2048 && rsa_key_size !== 4096) {
26
44
  throw new Error("You need to provide an appropriate RSA key size.");
@@ -30,6 +48,13 @@ class DigitalSignatureSHA256Wrapper {
30
48
  }
31
49
  return (0, index_1.sha256RsaDigitalSignature)(rsa_key_size, data_to_sign);
32
50
  }
51
+ /**
52
+ * Verifies a digital signature created with the RSA public key.
53
+ * @param public_key
54
+ * @param data_to_verify
55
+ * @param signature
56
+ * @returns boolean
57
+ */
33
58
  verifyRSa(public_key, data_to_verify, signature) {
34
59
  if (!public_key) {
35
60
  throw new Error("Must provide a public key");
@@ -1,4 +1,9 @@
1
1
  import { HasherType } from "./hasher-type";
2
2
  export declare class HasherFactory {
3
+ /**
4
+ * Get the appropriate hasher wrapper based upon the type based in.
5
+ * @param type
6
+ * @returns
7
+ */
3
8
  getHasher(type: HasherType): any;
4
9
  }
@@ -3,6 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HasherFactory = void 0;
4
4
  const sha_wrapper_1 = require("./sha-wrapper");
5
5
  class HasherFactory {
6
+ /**
7
+ * Get the appropriate hasher wrapper based upon the type based in.
8
+ * @param type
9
+ * @returns
10
+ */
6
11
  getHasher(type) {
7
12
  let result = new sha_wrapper_1.SHAWrapper();
8
13
  switch (type) {
@@ -1,7 +1,29 @@
1
1
  import { IHasherBase } from "./hasher-base";
2
2
  export declare class SHAWrapper implements IHasherBase {
3
+ /**
4
+ * Hashes a byte array with SHA3-512.
5
+ * @param dataToHash
6
+ * @returns number[]
7
+ */
3
8
  hash512(dataToHash: number[]): number[];
9
+ /**
10
+ * Verifies unsigned data against an SHA3-512 hash.
11
+ * @param dataToHash
12
+ * @param dataToVerify
13
+ * @returns boolean
14
+ */
4
15
  verify512(dataToHash: number[], dataToVerify: number[]): boolean;
16
+ /**
17
+ * Hashes a byte array with SHA3-256.
18
+ * @param dataToHash
19
+ * @returns number[]
20
+ */
5
21
  hash256(dataToHash: number[]): number[];
22
+ /**
23
+ * Verifies unsigned data against an SHA3-256 hash.
24
+ * @param dataToHash
25
+ * @param dataToVerify
26
+ * @returns boolean
27
+ */
6
28
  verify256(dataToHash: number[], dataToVerify: number[]): boolean;
7
29
  }
@@ -3,12 +3,23 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SHAWrapper = void 0;
4
4
  const index_1 = require("../../index");
5
5
  class SHAWrapper {
6
+ /**
7
+ * Hashes a byte array with SHA3-512.
8
+ * @param dataToHash
9
+ * @returns number[]
10
+ */
6
11
  hash512(dataToHash) {
7
12
  if (!dataToHash || dataToHash.length === 0) {
8
13
  throw new Error("You must provide an allocated array of data");
9
14
  }
10
15
  return (0, index_1.sha512)(dataToHash);
11
16
  }
17
+ /**
18
+ * Verifies unsigned data against an SHA3-512 hash.
19
+ * @param dataToHash
20
+ * @param dataToVerify
21
+ * @returns boolean
22
+ */
12
23
  verify512(dataToHash, dataToVerify) {
13
24
  if (!dataToHash || dataToHash.length === 0) {
14
25
  throw new Error("You must provide an allocated array of data");
@@ -18,12 +29,23 @@ class SHAWrapper {
18
29
  }
19
30
  return (0, index_1.sha512Verify)(dataToHash, dataToVerify);
20
31
  }
32
+ /**
33
+ * Hashes a byte array with SHA3-256.
34
+ * @param dataToHash
35
+ * @returns number[]
36
+ */
21
37
  hash256(dataToHash) {
22
38
  if (!dataToHash || dataToHash.length === 0) {
23
39
  throw new Error("You must provide an allocated array of data");
24
40
  }
25
41
  return (0, index_1.sha256)(dataToHash);
26
42
  }
43
+ /**
44
+ * Verifies unsigned data against an SHA3-256 hash.
45
+ * @param dataToHash
46
+ * @param dataToVerify
47
+ * @returns boolean
48
+ */
27
49
  verify256(dataToHash, dataToVerify) {
28
50
  if (!dataToHash || dataToHash.length === 0) {
29
51
  throw new Error("You must provide an allocated array of data");
@@ -4,6 +4,18 @@ export declare class HybridEncryptionWrapper {
4
4
  private aesWrapper;
5
5
  private rsaWrapper;
6
6
  constructor();
7
+ /**
8
+ * Encrypts data with RSA/AES hybrid encryption. The data is encrypted with AES-GCM and the AES key is encrypted with the RSA public key.
9
+ * @param dataToEncrypt
10
+ * @param initalizer
11
+ * @returns AesRsaHybridEncryptResult
12
+ */
7
13
  encrypt(dataToEncrypt: Array<number>, initalizer: AESRSAHybridInitializer): AesRsaHybridEncryptResult;
14
+ /**
15
+ * Decrypts data with RSA/AES hybrid encryption. The RSA private key decrypts the AES key and then the data is decrypted with AES-GCM.
16
+ * @param dataToEncrypt
17
+ * @param initalizer
18
+ * @returns AesRsaHybridEncryptResult
19
+ */
8
20
  decrypt(privateKey: string, encryptResult: AesRsaHybridEncryptResult): Array<number>;
9
21
  }
@@ -11,6 +11,12 @@ class HybridEncryptionWrapper {
11
11
  this.aesWrapper = new symmetric_1.AESWrapper();
12
12
  this.rsaWrapper = new asymmetric_1.RSAWrapper();
13
13
  }
14
+ /**
15
+ * Encrypts data with RSA/AES hybrid encryption. The data is encrypted with AES-GCM and the AES key is encrypted with the RSA public key.
16
+ * @param dataToEncrypt
17
+ * @param initalizer
18
+ * @returns AesRsaHybridEncryptResult
19
+ */
14
20
  encrypt(dataToEncrypt, initalizer) {
15
21
  let encryptedData = (initalizer.aesType === 128)
16
22
  ? this.aesWrapper.aes128Encrypt(initalizer.aesKey, initalizer.aesNonce, dataToEncrypt)
@@ -19,6 +25,12 @@ class HybridEncryptionWrapper {
19
25
  let result = new aes_rsa_hybird_encrypt_result_1.AesRsaHybridEncryptResult(encryptedData, encryptedAesKey, initalizer.aesType, initalizer.aesNonce);
20
26
  return result;
21
27
  }
28
+ /**
29
+ * Decrypts data with RSA/AES hybrid encryption. The RSA private key decrypts the AES key and then the data is decrypted with AES-GCM.
30
+ * @param dataToEncrypt
31
+ * @param initalizer
32
+ * @returns AesRsaHybridEncryptResult
33
+ */
22
34
  decrypt(privateKey, encryptResult) {
23
35
  let plaintextAesKey = this.rsaWrapper.decrypt(privateKey, encryptResult.encryptedAesKey);
24
36
  let plaintext = (encryptResult.aesType === 128)
@@ -4,5 +4,10 @@ export declare class AESRSAHybridInitializer {
4
4
  aesKey: Array<number>;
5
5
  aesNonce: Array<number>;
6
6
  rsaKeyPair: RsaKeyPairResult;
7
+ /**
8
+ * Constructs an initalizer to use with Hybrid Encryption wrapper. Generates your RSA key pair, AES nonce, and AES key based on the parameters passed in.
9
+ * @param aesType
10
+ * @param rsaSize
11
+ */
7
12
  constructor(aesType: number, rsaSize: number);
8
13
  }
@@ -8,6 +8,11 @@ class AESRSAHybridInitializer {
8
8
  aesKey;
9
9
  aesNonce;
10
10
  rsaKeyPair;
11
+ /**
12
+ * Constructs an initalizer to use with Hybrid Encryption wrapper. Generates your RSA key pair, AES nonce, and AES key based on the parameters passed in.
13
+ * @param aesType
14
+ * @param rsaSize
15
+ */
11
16
  constructor(aesType, rsaSize) {
12
17
  if (aesType !== 128 && aesType !== 256) {
13
18
  throw new Error("Need an appropriate AES size to generate a hybrid initalizer");
@@ -1,5 +1,17 @@
1
1
  import { X25519SecretPublicKeyResult } from "../../index";
2
2
  export declare class X25519Wrapper {
3
+ /**
4
+ * Generates and secret and public key to be used to create a shared secret with Diffie Hellman.
5
+ * User should share their public key with the other user and take the other user's public key and they can generate a Shared Secret.
6
+ * @returns X25519SecretPublicKeyResult
7
+ */
3
8
  generateSecretAndPublicKey(): X25519SecretPublicKeyResult;
4
- generateSharedSecret(secretKey: Array<number>, publicKey: Array<number>): number[];
9
+ /**
10
+ * User takes their secret key and the other user's public key to generate a shared secret.
11
+ * Can be used to derive an AES key over insecure channel.
12
+ * @param secretKey
13
+ * @param publicKey
14
+ * @returns Array<number>
15
+ */
16
+ generateSharedSecret(secretKey: Array<number>, publicKey: Array<number>): Array<number>;
5
17
  }
@@ -3,9 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.X25519Wrapper = void 0;
4
4
  const index_1 = require("../../index");
5
5
  class X25519Wrapper {
6
+ /**
7
+ * Generates and secret and public key to be used to create a shared secret with Diffie Hellman.
8
+ * User should share their public key with the other user and take the other user's public key and they can generate a Shared Secret.
9
+ * @returns X25519SecretPublicKeyResult
10
+ */
6
11
  generateSecretAndPublicKey() {
7
12
  return (0, index_1.x25519GenerateSecretAndPublicKey)();
8
13
  }
14
+ /**
15
+ * User takes their secret key and the other user's public key to generate a shared secret.
16
+ * Can be used to derive an AES key over insecure channel.
17
+ * @param secretKey
18
+ * @param publicKey
19
+ * @returns Array<number>
20
+ */
9
21
  generateSharedSecret(secretKey, publicKey) {
10
22
  return (0, index_1.x25519DiffieHellman)(secretKey, publicKey);
11
23
  }
@@ -1,7 +1,29 @@
1
1
  import { IPasswordHasherBase } from "./password-hasher-base";
2
2
  export declare class Argon2Wrapper implements IPasswordHasherBase {
3
+ /**
4
+ * Verifies a password with Argon2 on the threadpool.
5
+ * @param hashedPassword
6
+ * @param passwordToCheck
7
+ * @returns boolean
8
+ */
3
9
  verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean;
10
+ /**
11
+ * Hashes a password with Argon2 on the threadpool.
12
+ * @param password
13
+ * @returns string
14
+ */
4
15
  hashPasswordThreadPool(password: string): string;
16
+ /**
17
+ * Hashes a password with Argon2
18
+ * @param password
19
+ * @returns string
20
+ */
5
21
  hashPassword(password: string): string;
22
+ /**
23
+ * Verifies that a password is the same as the hashed password with Argon2.
24
+ * @param hashedPassword
25
+ * @param passwordToVerify
26
+ * @returns boolean
27
+ */
6
28
  verify(hashedPassword: string, passwordToVerify: string): boolean;
7
29
  }
@@ -3,6 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Argon2Wrapper = void 0;
4
4
  const index_1 = require("./../../index");
5
5
  class Argon2Wrapper {
6
+ /**
7
+ * Verifies a password with Argon2 on the threadpool.
8
+ * @param hashedPassword
9
+ * @param passwordToCheck
10
+ * @returns boolean
11
+ */
6
12
  verifyThreadPool(hashedPassword, passwordToCheck) {
7
13
  if (!hashedPassword) {
8
14
  throw new Error("You must provide a password to verify with Argon2");
@@ -12,18 +18,34 @@ class Argon2Wrapper {
12
18
  }
13
19
  return (0, index_1.argon2VerifyThreadpool)(hashedPassword, passwordToCheck);
14
20
  }
21
+ /**
22
+ * Hashes a password with Argon2 on the threadpool.
23
+ * @param password
24
+ * @returns string
25
+ */
15
26
  hashPasswordThreadPool(password) {
16
27
  if (!password) {
17
28
  throw new Error("You must provide a password to hash with Argon2");
18
29
  }
19
30
  return (0, index_1.argon2HashThreadPool)(password);
20
31
  }
32
+ /**
33
+ * Hashes a password with Argon2
34
+ * @param password
35
+ * @returns string
36
+ */
21
37
  hashPassword(password) {
22
38
  if (!password) {
23
39
  throw new Error("You must provide a password to hash with Argon2");
24
40
  }
25
41
  return (0, index_1.argon2Hash)(password);
26
42
  }
43
+ /**
44
+ * Verifies that a password is the same as the hashed password with Argon2.
45
+ * @param hashedPassword
46
+ * @param passwordToVerify
47
+ * @returns boolean
48
+ */
27
49
  verify(hashedPassword, passwordToVerify) {
28
50
  if (!hashedPassword || !passwordToVerify) {
29
51
  throw new Error("You must provide a hashed password and a plaintext password to verify with Argon2");
@@ -1,7 +1,29 @@
1
1
  import { IPasswordHasherBase } from "./password-hasher-base";
2
2
  export declare class BCryptWrapper implements IPasswordHasherBase {
3
+ /**
4
+ * Verifies a password with BCrypt on the threadpool.
5
+ * @param hashedPassword
6
+ * @param passwordToCheck
7
+ * @returns boolean
8
+ */
3
9
  verifyThreadPool(hashedPassword: string, passwordToCheck: string): boolean;
10
+ /**
11
+ * Hashes a password with BCrypt on the threadpool.
12
+ * @param password
13
+ * @returns string
14
+ */
4
15
  hashPasswordThreadPool(password: string): string;
16
+ /**
17
+ * Hashes a password with BCrypt
18
+ * @param password
19
+ * @returns string
20
+ */
5
21
  hashPassword(password: string): string;
22
+ /**
23
+ * Verifies that a password is the same as the hashed password with BCrypt.
24
+ * @param hashedPassword
25
+ * @param passwordToVerify
26
+ * @returns boolean
27
+ */
6
28
  verify(hashedPassword: string, passwordToVerify: string): boolean;
7
29
  }